Skip to content

Commit 6c7f35b

Browse files
authored
effect(format): migrate to AppProcess (anomalyco#27185)
1 parent 6e25720 commit 6c7f35b

1 file changed

Lines changed: 10 additions & 14 deletions

File tree

packages/opencode/src/format/index.ts

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Effect, Layer, Context, Schema } from "effect"
2-
import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process"
3-
import { CrossSpawnSpawner } from "@opencode-ai/core/cross-spawn-spawner"
2+
import { ChildProcess } from "effect/unstable/process"
3+
import { AppProcess } from "@opencode-ai/core/process"
44
import { InstanceState } from "@/effect/instance-state"
55
import path from "path"
66
import { mergeDeep } from "remeda"
@@ -29,7 +29,7 @@ export const layer = Layer.effect(
2929
Service,
3030
Effect.gen(function* () {
3131
const config = yield* Config.Service
32-
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner
32+
const appProcess = yield* AppProcess.Service
3333

3434
const state = yield* InstanceState.make(
3535
Effect.fn("Format.state")(function* (ctx) {
@@ -81,8 +81,8 @@ export const layer = Layer.effect(
8181
log.info("running", { command: cmd })
8282
const replaced = cmd.map((x) => x.replace("$FILE", filepath))
8383
const dir = yield* InstanceState.directory
84-
const code = yield* spawner
85-
.spawn(
84+
const result = yield* appProcess
85+
.run(
8686
ChildProcess.make(replaced[0]!, replaced.slice(1), {
8787
cwd: dir,
8888
env: item.environment,
@@ -93,21 +93,20 @@ export const layer = Layer.effect(
9393
}),
9494
)
9595
.pipe(
96-
Effect.flatMap((handle) => handle.exitCode),
97-
Effect.scoped,
98-
Effect.catch(() =>
96+
Effect.catch((error) =>
9997
Effect.sync(() => {
10098
log.error("failed to format file", {
10199
error: "spawn failed",
102100
command: cmd,
103101
...item.environment,
104102
file: filepath,
103+
cause: error.message,
105104
})
106-
return ChildProcessSpawner.ExitCode(1)
105+
return undefined
107106
}),
108107
),
109108
)
110-
if (code !== 0) {
109+
if (result && result.exitCode !== 0) {
111110
log.error("failed", {
112111
command: cmd,
113112
...item.environment,
@@ -198,9 +197,6 @@ export const layer = Layer.effect(
198197
}),
199198
)
200199

201-
export const defaultLayer = layer.pipe(
202-
Layer.provide(Config.defaultLayer),
203-
Layer.provide(CrossSpawnSpawner.defaultLayer),
204-
)
200+
export const defaultLayer = layer.pipe(Layer.provide(Config.defaultLayer), Layer.provide(AppProcess.defaultLayer))
205201

206202
export * as Format from "."

0 commit comments

Comments
 (0)