(plain: ExecFunction, allowInheritTTY: boolean)
| 380 | } |
| 381 | |
| 382 | export function plainExecAsPtyExec(plain: ExecFunction, allowInheritTTY: boolean): PtyExecFunction { |
| 383 | return async function (params: PtyExecParameters): Promise<PtyExec> { |
| 384 | const p = await plain({ |
| 385 | ...params, |
| 386 | stdio: allowInheritTTY && params.output !== nullLog ? [ |
| 387 | process.stdin.isTTY ? 'inherit' : 'pipe', |
| 388 | process.stdout.isTTY ? 'inherit' : 'pipe', |
| 389 | process.stderr.isTTY ? 'inherit' : 'pipe', |
| 390 | ] : undefined, |
| 391 | }); |
| 392 | const onDataEmitter = new NodeEventEmitter<string>(); |
| 393 | if (p.stdout) { |
| 394 | const stdoutDecoder = new StringDecoder(); |
| 395 | p.stdout.on('data', data => onDataEmitter.fire(stdoutDecoder.write(data))); |
| 396 | p.stdout.on('close', () => { |
| 397 | const end = stdoutDecoder.end(); |
| 398 | if (end) { |
| 399 | onDataEmitter.fire(end); |
| 400 | } |
| 401 | }); |
| 402 | } |
| 403 | if (p.stderr) { |
| 404 | const stderrDecoder = new StringDecoder(); |
| 405 | p.stderr.on('data', data => onDataEmitter.fire(stderrDecoder.write(data))); |
| 406 | p.stderr.on('close', () => { |
| 407 | const end = stderrDecoder.end(); |
| 408 | if (end) { |
| 409 | onDataEmitter.fire(end); |
| 410 | } |
| 411 | }); |
| 412 | } |
| 413 | return { |
| 414 | onData: onDataEmitter.event, |
| 415 | write: p.stdin ? p.stdin.write.bind(p.stdin) : undefined, |
| 416 | resize: () => {}, |
| 417 | exit: p.exit.then(({ code, signal }) => ({ |
| 418 | code: typeof code === 'number' ? code : undefined, |
| 419 | signal: typeof signal === 'string' ? processSignals[signal] : undefined, |
| 420 | })), |
| 421 | terminate: p.terminate.bind(p), |
| 422 | }; |
| 423 | }; |
| 424 | } |
| 425 | |
| 426 | async function findLocalWindowsExecutable(command: string, cwd = process.cwd(), env: Record<string, string | undefined>, output: Log): Promise<string> { |
| 427 | if (process.platform !== 'win32') { |
no test coverage detected