(args: string[], opts?: { cwd?: string; input?: string })
| 142 | |
| 143 | /** Async version of runArgs */ |
| 144 | export function runArgsAsync(args: string[], opts?: { cwd?: string; input?: string }): Promise<string> { |
| 145 | const result = checkIntercept(args, opts); |
| 146 | if (result?.intercepted) { |
| 147 | if ('error' in result) return Promise.reject(new Error(result.error)); |
| 148 | return Promise.resolve(result.result); |
| 149 | } |
| 150 | const [cmd, ...rest] = args; |
| 151 | return new Promise((resolve, reject) => { |
| 152 | const child = execFile(cmd!, rest, { cwd: opts?.cwd, encoding: 'utf-8' }, (err, stdout, stderr) => { |
| 153 | if (err) { |
| 154 | reject(new Error(`Command failed: ${args.join(' ')}\n${stdout}\n${stderr}`.trim())); |
| 155 | } else { |
| 156 | resolve(stdout.trim()); |
| 157 | } |
| 158 | }); |
| 159 | if (opts?.input) { |
| 160 | child.stdin?.write(opts.input); |
| 161 | child.stdin?.end(); |
| 162 | } |
| 163 | }); |
| 164 | } |
| 165 | |
| 166 | /** tryRun equivalent for argument arrays */ |
| 167 | export function tryRunArgs(args: string[], opts?: { cwd?: string }): string | null { |
no test coverage detected
searching dependent graphs…