(input: CommandInput)
| 46 | }; |
| 47 | |
| 48 | const runCommand = async (input: CommandInput): Promise<CommandOutput> => { |
| 49 | const proc = Bun.spawn([input.command, ...input.args], { |
| 50 | cwd: input.cwd, |
| 51 | env: process.env, |
| 52 | stdio: input.captureOutput ? ["ignore", "pipe", "pipe"] : ["ignore", "inherit", "inherit"], |
| 53 | }); |
| 54 | |
| 55 | const exitCode = await proc.exited; |
| 56 | const stdout = input.captureOutput && proc.stdout ? await new Response(proc.stdout).text() : ""; |
| 57 | const stderr = input.captureOutput && proc.stderr ? await new Response(proc.stderr).text() : ""; |
| 58 | |
| 59 | if (exitCode !== 0) { |
| 60 | throw new Error( |
| 61 | [ |
| 62 | `${input.command} ${input.args.join(" ")} exited with code ${exitCode}`, |
| 63 | stdout.trim().length > 0 ? `stdout:\n${stdout.trim()}` : null, |
| 64 | stderr.trim().length > 0 ? `stderr:\n${stderr.trim()}` : null, |
| 65 | ] |
| 66 | .filter((part) => part !== null) |
| 67 | .join("\n\n"), |
| 68 | ); |
| 69 | } |
| 70 | |
| 71 | return { |
| 72 | stdout: stdout.trim(), |
| 73 | stderr: stderr.trim(), |
| 74 | }; |
| 75 | }; |
| 76 | |
| 77 | const readVersion = async (): Promise<string> => { |
| 78 | const pkg = (await Bun.file(versionPackagePath).json()) as { version?: string }; |
no test coverage detected