(cmd: string, opts?: { cwd?: string; input?: string })
| 45 | } |
| 46 | |
| 47 | export function runAsync(cmd: string, opts?: { cwd?: string; input?: string }): Promise<string> { |
| 48 | const result = checkIntercept(cmd.split(/\s+/), opts); |
| 49 | if (result?.intercepted) { |
| 50 | if ('error' in result) return Promise.reject(new Error(result.error)); |
| 51 | return Promise.resolve(result.result); |
| 52 | } |
| 53 | return new Promise((resolve, reject) => { |
| 54 | const child = exec(cmd, { cwd: opts?.cwd, encoding: 'utf-8' }, (err, stdout, stderr) => { |
| 55 | if (err) { |
| 56 | reject(new Error(`Command failed: ${cmd}\n${stdout}\n${stderr}`.trim())); |
| 57 | } else { |
| 58 | resolve(stdout.trim()); |
| 59 | } |
| 60 | }); |
| 61 | if (opts?.input) { |
| 62 | child.stdin?.write(opts.input); |
| 63 | child.stdin?.end(); |
| 64 | } |
| 65 | }); |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Run a shell command, streaming its stdout/stderr to the parent process live |
no test coverage detected
searching dependent graphs…