Przeglądaj źródła

fix issue preventing things from working when node_modules or package.json present in ~/

Dax Raad 7 miesięcy temu
rodzic
commit
1254f48135
1 zmienionych plików z 5 dodań i 4 usunięć
  1. 5 4
      packages/opencode/src/bun/index.ts

+ 5 - 4
packages/opencode/src/bun/index.ts

@@ -60,11 +60,12 @@ export namespace BunProc {
   export async function install(pkg: string, version = "latest") {
     const mod = path.join(Global.Path.cache, "node_modules", pkg)
     const pkgjson = Bun.file(path.join(Global.Path.cache, "package.json"))
-    const parsed = await pkgjson.json().catch(() => ({
-      dependencies: {},
-    }))
+    const parsed = await pkgjson.json().catch(async () => {
+      const result = { dependencies: {} }
+      await Bun.write(pkgjson.name!, JSON.stringify(result, null, 2))
+      return result
+    })
     if (parsed.dependencies[pkg] === version) return mod
-    parsed.dependencies[pkg] = version
     await BunProc.run(
       ["add", "--exact", "--cwd", Global.Path.cache, "--registry=https://registry.npmjs.org", pkg + "@" + version],
       {