(
ctx: CliContext,
args: readonly string[],
options: { readonly allowFailure?: boolean } = {},
)
| 43 | }; |
| 44 | |
| 45 | const runCli = async ( |
| 46 | ctx: CliContext, |
| 47 | args: readonly string[], |
| 48 | options: { readonly allowFailure?: boolean } = {}, |
| 49 | ): Promise<CliResult> => { |
| 50 | const proc = Bun.spawn([process.execPath, "run", cliEntrypoint, ...args], { |
| 51 | cwd: repoRoot, |
| 52 | env: { |
| 53 | ...process.env, |
| 54 | EXECUTOR_DEV: "1", |
| 55 | EXECUTOR_DATA_DIR: ctx.dataDir, |
| 56 | EXECUTOR_SCOPE_DIR: ctx.scopeDir, |
| 57 | }, |
| 58 | stdout: "pipe", |
| 59 | stderr: "pipe", |
| 60 | }); |
| 61 | |
| 62 | const [stdout, stderr, exitCode] = await Promise.all([ |
| 63 | new Response(proc.stdout).text(), |
| 64 | new Response(proc.stderr).text(), |
| 65 | proc.exited, |
| 66 | ]); |
| 67 | const result = { stdout, stderr, text: `${stdout}${stderr}`, exitCode }; |
| 68 | |
| 69 | if (exitCode !== 0 && !options.allowFailure) { |
| 70 | throw new Error(`CLI failed (${exitCode}) for ${args.join(" ")}\n${result.text}`); |
| 71 | } |
| 72 | |
| 73 | return result; |
| 74 | }; |
| 75 | |
| 76 | const parseJsonOutput = <T>(result: CliResult): T => { |
| 77 | const start = result.stdout.indexOf("{"); |
no test coverage detected