Skip to content
Myr

Improve the TS types and don't accept `null` in the `stdio` option

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Sindre Sorhus · committed by Sindre Sorhus · parent 10c73dc · Browse files · 6 files+24 added−33 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

6 files+24 added−33 removed

  • tests:+0 added−1 removed
  • other:+24 added−32 removed

6 files+24 added−33 removed

modified:test/stdio.js-1 removed
modified:index.d.ts+10 added-15 removed
8 unmodified lines
9 | 'ignore'10 | 'inherit'11 | Stream12 | number13 | null13 | undefined;1415 interface CommonOptions<EncodingType> {16 /**
26 unmodified lines
43 Child's [stdio](https://nodejs.org/api/child_process.html#child_process_options_stdio) configuration.4445 @default 'pipe'46 */48 readonly stdio?: 'pipe' | 'ignore' | 'inherit' | ReadonlyArray<StdioOption>;47 readonly stdio?: 'pipe' | 'ignore' | 'inherit' | readonly StdioOption[];4849 /**50 Prepare child to run independently of its parent process. Specific behavior [depends on the platform](https://nodejs.org/api/child_process.html#child_process_options_detached).51
230 unmodified lines
282 }283284 interface ExecaChildPromise<StdoutErrorType> {285 catch<ResultType = never>(287 onRejected?:288 | ((289 reason: ExecaError<StdoutErrorType>290 ) => ResultType | PromiseLike<ResultType>)291 | null286 onRejected?: (reason: ExecaError<StdoutErrorType>) => ResultType | PromiseLike<ResultType>287 ): Promise<ExecaReturnValue<StdoutErrorType> | ResultType>;288289 /**290 Cancel the subprocess.
43 unmodified lines
334 ```335 */336 (337 file: string,343 arguments?: ReadonlyArray<string>,338 arguments?: readonly string[],339 options?: execa.Options340 ): execa.ExecaChildProcess;341 (342 file: string,348 arguments?: ReadonlyArray<string>,343 arguments?: readonly string[],344 options?: execa.Options<null>345 ): execa.ExecaChildProcess<Buffer>;346 (file: string, options?: execa.Options): execa.ExecaChildProcess;347 (file: string, options?: execa.Options<null>): execa.ExecaChildProcess<
8 unmodified lines
356 @returns The contents of the executed process' `stdout`.357 */358 stdout(359 file: string,365 arguments?: ReadonlyArray<string>,360 arguments?: readonly string[],361 options?: execa.Options362 ): Promise<string>;363 stdout(364 file: string,370 arguments?: ReadonlyArray<string>,365 arguments?: readonly string[],366 options?: execa.Options<null>367 ): Promise<Buffer>;368 stdout(file: string, options?: execa.Options): Promise<string>;369 stdout(file: string, options?: execa.Options<null>): Promise<Buffer>;
6 unmodified lines
376 @returns The contents of the executed process' `stderr`.377 */378 stderr(379 file: string,385 arguments?: ReadonlyArray<string>,380 arguments?: readonly string[],381 options?: execa.Options382 ): Promise<string>;383 stderr(384 file: string,390 arguments?: ReadonlyArray<string>,385 arguments?: readonly string[],386 options?: execa.Options<null>387 ): Promise<Buffer>;388 stderr(file: string, options?: execa.Options): Promise<string>;389 stderr(file: string, options?: execa.Options<null>): Promise<Buffer>;
53 unmodified lines
443 @returns The same result object as [`child_process.spawnSync`](https://nodejs.org/api/child_process.html#child_process_child_process_spawnsync_command_args_options).444 */445 sync(446 file: string,452 arguments?: ReadonlyArray<string>,447 arguments?: readonly string[],448 options?: execa.SyncOptions449 ): execa.ExecaSyncReturnValue;450 sync(451 file: string,457 arguments?: ReadonlyArray<string>,452 arguments?: readonly string[],453 options?: execa.SyncOptions<null>454 ): execa.ExecaSyncReturnValue<Buffer>;455 sync(file: string, options?: execa.SyncOptions): execa.ExecaSyncReturnValue;456 sync(
45 unmodified lines
modified:index.js+1 added-1 removed
67 unmodified lines
68 return {command, args, options, parsed};69}7071function handleInput(spawned, input) {72 if (input === null || input === undefined) {72 if (input === undefined) {73 return;74 }7576 if (isStream(input)) {
384 unmodified lines
modified:index.test-d.ts+1 added-4 removed
59 unmodified lines
60execa('unicorns', {stdio: 'pipe'});61execa('unicorns', {stdio: 'ignore'});62execa('unicorns', {stdio: 'inherit'});63execa('unicorns', {64 stdio: ['pipe', 'ipc', 'ignore', 'inherit', process.stdin, 1, null, undefined]64 stdio: ['pipe', 'ipc', 'ignore', 'inherit', process.stdin, 1, undefined]65});66execa('unicorns', {detached: true});67execa('unicorns', {uid: 0});68execa('unicorns', {gid: 0});
14 unmodified lines
83execa('unicorns', {stdin: 'ignore'});84execa('unicorns', {stdin: 'inherit'});85execa('unicorns', {stdin: process.stdin});86execa('unicorns', {stdin: 1});87execa('unicorns', {stdin: null});87execa('unicorns', {stdin: undefined});88execa('unicorns', {stderr: 'pipe'});89execa('unicorns', {stderr: 'ipc'});90execa('unicorns', {stderr: 'ignore'});91execa('unicorns', {stderr: 'inherit'});92execa('unicorns', {stderr: process.stderr});93execa('unicorns', {stderr: 1});95execa('unicorns', {stderr: null});94execa('unicorns', {stderr: undefined});95execa('unicorns', {stdout: 'pipe'});96execa('unicorns', {stdout: 'ipc'});97execa('unicorns', {stdout: 'ignore'});98execa('unicorns', {stdout: 'inherit'});99execa('unicorns', {stdout: process.stdout});100execa('unicorns', {stdout: 1});103execa('unicorns', {stdout: null});101execa('unicorns', {stdout: undefined});102execa('unicorns', {windowsVerbatimArguments: true});103104expectType<ExecaChildProcess<string>>(execa('unicorns'));
56 unmodified lines
modified:readme.md+10 added-10 removed
160 unmodified lines
161Returns the same result object as [`child_process.spawnSync`](https://nodejs.org/api/child_process.html#child_process_child_process_spawnsync_command_args_options).162163### options164165Type: `Object`165Type: `object`166167#### cwd168169Type: `string`<br>
2 unmodified lines
172Current working directory of the child process.173174#### env175176Type: `Object`<br>176Type: `object`<br>177Default: `process.env`178179Environment key-value pairs. Extends automatically from `process.env`. Set `extendEnv` to `false` if you don't want this.180
11 unmodified lines
192Explicitly set the value of `argv[0]` sent to the child process. This will be set to `command` or `file` if not specified.193194#### stdio195196Type: `string[]` `string`<br>196Type: `string | string[]`<br>197Default: `pipe`198199Child's [stdio](https://nodejs.org/api/child_process.html#child_process_options_stdio) configuration.200
16 unmodified lines
217Sets the group identity of the process.218219#### shell220221Type: `boolean` `string`<br>221Type: `boolean | string`<br>222Default: `false`223224If `true`, runs `command` inside of a shell. Uses `/bin/sh` on UNIX and `cmd.exe` on Windows. A different shell can be specified as a string. The shell should understand the `-c` switch on UNIX or `/d /s /c` on Windows.225
20 unmodified lines
246Preferred path to find locally installed binaries in (use with `preferLocal`).247248#### input249250Type: `string` `Buffer` `stream.Readable`250Type: `string | Buffer | stream.Readable`251252Write some input to the `stdin` of your binary.<br>253Streams are not allowed when using the synchronous methods.254
12 unmodified lines
267Keep track of the spawned process and `kill` it when the parent process exits.268269#### encoding270271Type: `string` `null`<br>271Type: `string | null`<br>272Default: `utf8`273274Specify the character encoding used to decode the `stdout` and `stderr` output. If set to `null`, then `stdout` and `stderr` will be a `Buffer` instead of a string.275
19 unmodified lines
295Largest amount of data in bytes allowed on `stdout` or `stderr`.296297#### killSignal298299Type: `string` `number`<br>299Type: `string | number`<br>300Default: `SIGTERM`301302Signal value to be used when the spawned process will be killed.303304#### stdin305306Type: `string` `number` `Stream` `undefined` `null`<br>306Type: `string | number | Stream | undefined`<br>307Default: `pipe`308309Same options as [`stdio`](https://nodejs.org/dist/latest-v6.x/docs/api/child_process.html#child_process_options_stdio).310311#### stdout312313Type: `string` `number` `Stream` `undefined` `null`<br>313Type: `string | number | Stream | undefined`<br>314Default: `pipe`315316Same options as [`stdio`](https://nodejs.org/dist/latest-v6.x/docs/api/child_process.html#child_process_options_stdio).317318#### stderr319320Type: `string` `number` `Stream` `undefined` `null`<br>320Type: `string | number | Stream | undefined`<br>321Default: `pipe`322323Same options as [`stdio`](https://nodejs.org/dist/latest-v6.x/docs/api/child_process.html#child_process_options_stdio).324
32 unmodified lines
modified:test.js+2 added-2 removed
74 unmodified lines
75 await t.throwsAsync(execa('fixtures/error-message.js', {stdout: 'inherit', stderr: 'inherit'}), {message: NO_NEWLINES_REGEXP});76});7778test('do not include `stderr` and `stdout` in errors when `stdio` is set to `inherit`', async t => {79 await t.throwsAsync(execa('fixtures/error-message.js', {stdio: [null, 'inherit', 'inherit']}), {message: NO_NEWLINES_REGEXP});79 await t.throwsAsync(execa('fixtures/error-message.js', {stdio: [undefined, 'inherit', 'inherit']}), {message: NO_NEWLINES_REGEXP});80});8182test('do not include `stdout` in errors when set to `inherit`', async t => {83 const err = await t.throwsAsync(execa('fixtures/error-message.js', {stdout: 'inherit'}), {message: /stderr/});
128 unmodified lines
212213test('opts.stdout:ignore - stdout will not collect data', async t => {214 const {stdout} = await execa('stdin', {215 input: 'hello',216 stdio: [null, 'ignore', null]216 stdio: [undefined, 'ignore', undefined]217 });218 t.is(stdout, undefined);219});220
440 unmodified lines