(command: string[], options?: { cwd?: string; env?: NodeJS.ProcessEnv })
| 19 | import { envWithPath, npmCommand } from "./script-helpers"; |
| 20 | |
| 21 | function run(command: string[], options?: { cwd?: string; env?: NodeJS.ProcessEnv }) { |
| 22 | const proc = Bun.spawnSync(command, { |
| 23 | cwd: options?.cwd, |
| 24 | stdin: "ignore", |
| 25 | stdout: "pipe", |
| 26 | stderr: "pipe", |
| 27 | env: options?.env ?? process.env, |
| 28 | }); |
| 29 | |
| 30 | const stdout = Buffer.from(proc.stdout).toString("utf8"); |
| 31 | const stderr = Buffer.from(proc.stderr).toString("utf8"); |
| 32 | |
| 33 | if (proc.exitCode !== 0) { |
| 34 | throw new Error( |
| 35 | `${command.join(" ")} failed with exit ${proc.exitCode}\n${stderr || stdout}`.trim(), |
| 36 | ); |
| 37 | } |
| 38 | |
| 39 | return { stdout, stderr }; |
| 40 | } |
| 41 | |
| 42 | /** Resolve a command path for a sanitized PATH that still works cross-platform. */ |
| 43 | function commandPath(command: string) { |
no outgoing calls