| 23 | } |
| 24 | |
| 25 | export class Worktrees extends Context.Service<Worktrees, { |
| 26 | readonly resolveRef: (repoRoot: string, ref: string) => Effect.Effect<string, ApiDiffError> |
| 27 | readonly prepareSnapshot: (options: PrepareSnapshotOptions) => Effect.Effect<ApiSnapshot, ApiDiffError> |
| 28 | }>()("@effect/api-diff/Worktrees") { |
| 29 | static readonly layerNoDependencies = Layer.effect( |
| 30 | Worktrees, |
| 31 | Effect.gen(function*() { |
| 32 | const fs = yield* FileSystem.FileSystem |
| 33 | const path = yield* Path.Path |
| 34 | const snapshotter = yield* Snapshotter |
| 35 | const spawner = yield* ChildProcessSpawner.ChildProcessSpawner |
| 36 | |
| 37 | const runCommandScoped = Effect.fnUntraced(function*( |
| 38 | command: string, |
| 39 | args: ReadonlyArray<string>, |
| 40 | cwd: string |
| 41 | ) { |
| 42 | const display = `${command} ${args.join(" ")}` |
| 43 | const handle = yield* spawner.spawn( |
| 44 | ChildProcess.make(command, args, { cwd }) |
| 45 | ).pipe( |
| 46 | Effect.mapError((cause) => |
| 47 | new ApiDiffError({ |
| 48 | message: `Could not start command (${display})`, |
| 49 | cause |
| 50 | }) |
| 51 | ) |
| 52 | ) |
| 53 | const [output, exitCode] = yield* Effect.all([ |
| 54 | Stream.mkString(Stream.decodeText(handle.all)), |
| 55 | handle.exitCode |
| 56 | ], { concurrency: "unbounded" }).pipe( |
| 57 | Effect.mapError((cause) => |
| 58 | new ApiDiffError({ |
| 59 | message: `Could not run command (${display})`, |
| 60 | cause |
| 61 | }) |
| 62 | ) |
| 63 | ) |
| 64 | return { display, exitCode, output } |
| 65 | }) |
| 66 | |
| 67 | const runCommand = ( |
| 68 | command: string, |
| 69 | args: ReadonlyArray<string>, |
| 70 | cwd: string |
| 71 | ): Effect.Effect<{ |
| 72 | readonly display: string |
| 73 | readonly exitCode: ChildProcessSpawner.ExitCode |
| 74 | readonly output: string |
| 75 | }, ApiDiffError> => Effect.scoped(runCommandScoped(command, args, cwd)) |
| 76 | |
| 77 | const runChecked = Effect.fnUntraced(function*( |
| 78 | command: string, |
| 79 | args: ReadonlyArray<string>, |
| 80 | cwd: string |
| 81 | ) { |
| 82 | const result = yield* runCommand(command, args, cwd) |
nothing calls this directly
no test coverage detected