opencode-agent[bot] 3 месяцев назад
Родитель
Сommit
353532b1c1

+ 3 - 1
packages/opencode/src/installation/index.ts

@@ -136,7 +136,9 @@ export const layer: Layer.Layer<Service, never, HttpClient.HttpClient | ChildPro
         const args = method === "bun" ? ["pm", "view", spec, "version", "--json"] : ["view", spec, "version", "--json"]
         const result = yield* run([method, ...args])
         if (result.code !== 0 || !result.stdout.trim()) {
-          return yield* new UpgradeFailedError({ stderr: result.stderr || result.stdout || `Failed to resolve ${spec}` })
+          return yield* new UpgradeFailedError({
+            stderr: result.stderr || result.stdout || `Failed to resolve ${spec}`,
+          })
         }
         return yield* Schema.decodeUnknownEffect(Schema.fromJsonString(Schema.String))(result.stdout)
       })

+ 16 - 19
packages/opencode/src/npm/index.ts

@@ -110,25 +110,22 @@ export const layer = Layer.effect(
     const flock = yield* EffectFlock.Service
     const spawner = yield* ChildProcessSpawner.ChildProcessSpawner
     const directory = (pkg: string) => path.join(global.cache, "packages", sanitize(pkg))
-    const runView = Effect.fnUntraced(
-      function* (cmd: string[]) {
-        const handle = yield* spawner.spawn(
-          ChildProcess.make(cmd[0], cmd.slice(1), {
-            extendEnv: true,
-          }),
-        )
-        const [stdout, stderr] = yield* Effect.all(
-          [Stream.mkString(Stream.decodeText(handle.stdout)), Stream.mkString(Stream.decodeText(handle.stderr))],
-          { concurrency: 2 },
-        )
-        const code = yield* handle.exitCode
-        if (code !== 0 || !stdout.trim()) {
-          return yield* Effect.fail(stderr || stdout || `Failed to run ${cmd.join(" ")}`)
-        }
-        return yield* Schema.decodeUnknownEffect(Schema.fromJsonString(Schema.String))(stdout)
-      },
-      Effect.scoped,
-    )
+    const runView = Effect.fnUntraced(function* (cmd: string[]) {
+      const handle = yield* spawner.spawn(
+        ChildProcess.make(cmd[0], cmd.slice(1), {
+          extendEnv: true,
+        }),
+      )
+      const [stdout, stderr] = yield* Effect.all(
+        [Stream.mkString(Stream.decodeText(handle.stdout)), Stream.mkString(Stream.decodeText(handle.stderr))],
+        { concurrency: 2 },
+      )
+      const code = yield* handle.exitCode
+      if (code !== 0 || !stdout.trim()) {
+        return yield* Effect.fail(stderr || stdout || `Failed to run ${cmd.join(" ")}`)
+      }
+      return yield* Schema.decodeUnknownEffect(Schema.fromJsonString(Schema.String))(stdout)
+    }, Effect.scoped)
     const viewLatestVersion = Effect.fnUntraced(function* (pkg: string) {
       return yield* runView(["npm", "view", pkg, "dist-tags.latest", "--json"]).pipe(
         Effect.catch(() =>

+ 6 - 2
packages/opencode/test/npm.test.ts

@@ -103,7 +103,9 @@ describe("Npm.outdated", () => {
       return ""
     })
 
-    const result = await Effect.runPromise(Npm.Service.use((svc) => svc.outdated("example", "1.0.0")).pipe(Effect.provide(layer)))
+    const result = await Effect.runPromise(
+      Npm.Service.use((svc) => svc.outdated("example", "1.0.0")).pipe(Effect.provide(layer)),
+    )
 
     expect(result).toBe(true)
     expect(calls).toContainEqual(["npm", "view", "example", "dist-tags.latest", "--json"])
@@ -130,7 +132,9 @@ describe("Npm.outdated", () => {
       return ""
     })
 
-    const result = await Effect.runPromise(Npm.Service.use((svc) => svc.outdated("example", "1.0.0")).pipe(Effect.provide(layer)))
+    const result = await Effect.runPromise(
+      Npm.Service.use((svc) => svc.outdated("example", "1.0.0")).pipe(Effect.provide(layer)),
+    )
 
     expect(result).toBe(true)
     expect(calls).toContainEqual(["npm", "view", "example", "dist-tags.latest", "--json"])