(input: CommandInput)
| 71 | }; |
| 72 | |
| 73 | const runCommand = async (input: CommandInput): Promise<CommandOutput> => { |
| 74 | const proc = Bun.spawn([input.command, ...input.args], { |
| 75 | cwd: input.cwd, |
| 76 | env: process.env, |
| 77 | stdio: input.captureOutput ? ["ignore", "pipe", "pipe"] : ["ignore", "inherit", "inherit"], |
| 78 | }); |
| 79 | |
| 80 | const exitCode = await proc.exited; |
| 81 | const stdout = input.captureOutput && proc.stdout ? await new Response(proc.stdout).text() : ""; |
| 82 | const stderr = input.captureOutput && proc.stderr ? await new Response(proc.stderr).text() : ""; |
| 83 | |
| 84 | if (exitCode !== 0) { |
| 85 | throw new Error( |
| 86 | [ |
| 87 | `${input.command} ${input.args.join(" ")} exited with code ${exitCode}`, |
| 88 | stdout.trim().length > 0 ? `stdout:\n${stdout.trim()}` : null, |
| 89 | stderr.trim().length > 0 ? `stderr:\n${stderr.trim()}` : null, |
| 90 | ] |
| 91 | .filter((part) => part !== null) |
| 92 | .join("\n\n"), |
| 93 | ); |
| 94 | } |
| 95 | |
| 96 | return { |
| 97 | stdout: stdout.trim(), |
| 98 | stderr: stderr.trim(), |
| 99 | }; |
| 100 | }; |
| 101 | |
| 102 | const readVersion = async (): Promise<string> => { |
| 103 | const pkg = (await Bun.file(versionPackagePath).json()) as { version?: string }; |
no test coverage detected