(command: string, args: string[], options: RunOptions = {})
| 12 | | { ok: false; reason: 'not-found' | 'permission-denied' | 'spawn-error' | 'timeout' | 'signal'; stdout: string; stderr: string } |
| 13 | |
| 14 | export const runCommand = (command: string, args: string[], options: RunOptions = {}): Promise<number> => { |
| 15 | return new Promise((resolve, reject) => { |
| 16 | const child = spawn(command, args, { |
| 17 | cwd: options.cwd, |
| 18 | env: { ...process.env, ...(options.env ?? {}) }, |
| 19 | stdio: options.stdio ?? 'inherit', |
| 20 | shell: false, |
| 21 | }) |
| 22 | |
| 23 | const timer = |
| 24 | typeof options.timeoutMs === 'number' |
| 25 | ? setTimeout(() => { |
| 26 | child.kill('SIGTERM') |
| 27 | }, options.timeoutMs) |
| 28 | : undefined |
| 29 | |
| 30 | child.on('error', reject) |
| 31 | child.on('close', (code) => { |
| 32 | if (timer) { |
| 33 | clearTimeout(timer) |
| 34 | } |
| 35 | |
| 36 | resolve(code ?? 1) |
| 37 | }) |
| 38 | }) |
| 39 | } |
| 40 | |
| 41 | export const runCommandWithOutput = ( |
| 42 | command: string, |
no outgoing calls
no test coverage detected