(command: string, opts?: ProcessOptions)
| 302 | } |
| 303 | |
| 304 | private exec(command: string, opts?: ProcessOptions): Promise<ExecResult> { |
| 305 | return new Promise<ExecResult>((resolve, reject) => { |
| 306 | // Run via a POSIX `sh` on every platform (see posixShell) so the adapter's |
| 307 | // single-quote-quoted commands work identically — including native Windows, |
| 308 | // where `shell: true` would be cmd.exe and mangle the quoting. |
| 309 | const child = spawn(posixShell(), ['-c', command], { |
| 310 | cwd: this.resolveCwd(opts?.cwd), |
| 311 | env: this.mergedEnv(opts?.env), |
| 312 | }) |
| 313 | let stdout = '' |
| 314 | let stderr = '' |
| 315 | child.stdout.on('data', (d: Buffer) => (stdout += d.toString('utf8'))) |
| 316 | child.stderr.on('data', (d: Buffer) => (stderr += d.toString('utf8'))) |
| 317 | const onAbort = (): void => { |
| 318 | killTree(child) |
| 319 | } |
| 320 | opts?.signal?.addEventListener('abort', onAbort, { once: true }) |
| 321 | child.on('error', reject) |
| 322 | child.on('close', (code) => { |
| 323 | opts?.signal?.removeEventListener('abort', onAbort) |
| 324 | resolve({ stdout, stderr, exitCode: code ?? 0 }) |
| 325 | }) |
| 326 | }) |
| 327 | } |
| 328 | |
| 329 | private spawnProcess( |
| 330 | command: string, |
no test coverage detected