|
13 | 13 | // limitations under the License.
|
14 | 14 |
|
15 | 15 | import assert from 'node:assert'
|
16 |
| -import { spawn, spawnSync, StdioNull, StdioPipe } from 'node:child_process' |
| 16 | +import { spawn, spawnSync, StdioOptions, IOType } from 'node:child_process' |
17 | 17 | import { AsyncHook, AsyncLocalStorage, createHook } from 'node:async_hooks'
|
18 | 18 | import { Readable, Writable } from 'node:stream'
|
19 | 19 | import { inspect } from 'node:util'
|
@@ -59,6 +59,7 @@ export interface Options {
|
59 | 59 | ac?: AbortController
|
60 | 60 | signal?: AbortSignal
|
61 | 61 | input?: string | Buffer | Readable | ProcessOutput | ProcessPromise
|
| 62 | + stdio: StdioOptions |
62 | 63 | verbose: boolean
|
63 | 64 | sync: boolean
|
64 | 65 | env: NodeJS.ProcessEnv
|
@@ -95,6 +96,7 @@ export const defaults: Options = {
|
95 | 96 | env: process.env,
|
96 | 97 | sync: false,
|
97 | 98 | shell: true,
|
| 99 | + stdio: ['inherit', 'pipe', 'pipe'], |
98 | 100 | nothrow: false,
|
99 | 101 | quiet: false,
|
100 | 102 | prefix: '',
|
@@ -192,15 +194,14 @@ try {
|
192 | 194 | } catch (err) {}
|
193 | 195 |
|
194 | 196 | type Resolve = (out: ProcessOutput) => void
|
195 |
| -type IO = StdioPipe | StdioNull |
196 | 197 |
|
197 | 198 | export class ProcessPromise extends Promise<ProcessOutput> {
|
198 | 199 | private _command = ''
|
199 | 200 | private _from = ''
|
200 | 201 | private _resolve: Resolve = noop
|
201 | 202 | private _reject: Resolve = noop
|
202 | 203 | private _snapshot = getStore()
|
203 |
| - private _stdio: [IO, IO, IO] = ['inherit', 'pipe', 'pipe'] |
| 204 | + private _stdio?: StdioOptions |
204 | 205 | private _nothrow?: boolean
|
205 | 206 | private _quiet?: boolean
|
206 | 207 | private _timeout?: number
|
@@ -245,15 +246,15 @@ export class ProcessPromise extends Promise<ProcessOutput> {
|
245 | 246 |
|
246 | 247 | this._zurk = exec({
|
247 | 248 | input,
|
248 |
| - cmd: $.prefix + this._command + $.postfix, |
| 249 | + cmd: $.prefix + self._command + $.postfix, |
249 | 250 | cwd: $.cwd ?? $[processCwd],
|
250 | 251 | ac: $.ac,
|
251 | 252 | signal: $.signal,
|
252 | 253 | shell: typeof $.shell === 'string' ? $.shell : true,
|
253 | 254 | env: $.env,
|
254 | 255 | spawn: $.spawn,
|
255 | 256 | spawnSync: $.spawnSync,
|
256 |
| - stdio: this._stdio as any, |
| 257 | + stdio: self._stdio ?? $.stdio, |
257 | 258 | sync: $[syncExec],
|
258 | 259 | detached: !isWin,
|
259 | 260 | run: (cb) => cb(),
|
@@ -427,7 +428,11 @@ export class ProcessPromise extends Promise<ProcessOutput> {
|
427 | 428 | return $.kill(this.child.pid, signal)
|
428 | 429 | }
|
429 | 430 |
|
430 |
| - stdio(stdin: IO, stdout: IO = 'pipe', stderr: IO = 'pipe'): ProcessPromise { |
| 431 | + stdio( |
| 432 | + stdin: IOType, |
| 433 | + stdout: IOType = 'pipe', |
| 434 | + stderr: IOType = 'pipe' |
| 435 | + ): ProcessPromise { |
431 | 436 | this._stdio = [stdin, stdout, stderr]
|
432 | 437 | return this
|
433 | 438 | }
|
|
0 commit comments