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
Provenance
- Commit
4692dcd- Tree
c1fbdd1- Author
Sindre Sorhus <sindresorhus@gmail.com>- Committer
Sindre Sorhus <sindresorhus@gmail.com>- Parent
10c73dc
6 files changed+24 added−33 removed
modified:test/stdio.js-1 removed
20 unmodified lines21222324252526272821 unmodified lines20 unmodified lines
macro.title = (providedTitle, input) => providedTitle || util.inspect(input, {colors: true});
test(macro, undefined, undefined);test(macro, null, undefined);
test(macro, {stdio: 'inherit'}, 'inherit');test(macro, {stdio: 'pipe'}, 'pipe');test(macro, {stdio: 'ignore'}, 'ignore');21 unmodified linesmodified:index.d.ts+10 added-15 removed
8 unmodified lines9 | 'ignore'10 | 'inherit'11 | Stream12 | number13- | null13 | undefined;14 15 interface CommonOptions<EncodingType> {16 /**26 unmodified lines43 Child's [stdio](https://nodejs.org/api/child_process.html#child_process_options_stdio) configuration.44 45 @default 'pipe'46 */48- readonly stdio?: 'pipe' | 'ignore' | 'inherit' | ReadonlyArray<StdioOption>;47+ readonly stdio?: 'pipe' | 'ignore' | 'inherit' | readonly StdioOption[];48 49 /**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 lines282 }283 284 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>;288 289 /**290 Cancel the subprocess.43 unmodified lines334 ```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 lines356 @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 lines376 @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 lines443 @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 linesmodified:index.js+1 added-1 removed
67 unmodified lines68 return {command, args, options, parsed};69 }70 71 function handleInput(spawned, input) {72- if (input === null || input === undefined) {72+ if (input === undefined) {73 return;74 }75 76 if (isStream(input)) {384 unmodified linesmodified:index.test-d.ts+1 added-4 removed
59 unmodified lines60 execa('unicorns', {stdio: 'pipe'});61 execa('unicorns', {stdio: 'ignore'});62 execa('unicorns', {stdio: 'inherit'});63 execa('unicorns', {64- stdio: ['pipe', 'ipc', 'ignore', 'inherit', process.stdin, 1, null, undefined]64+ stdio: ['pipe', 'ipc', 'ignore', 'inherit', process.stdin, 1, undefined]65 });66 execa('unicorns', {detached: true});67 execa('unicorns', {uid: 0});68 execa('unicorns', {gid: 0});14 unmodified lines83 execa('unicorns', {stdin: 'ignore'});84 execa('unicorns', {stdin: 'inherit'});85 execa('unicorns', {stdin: process.stdin});86 execa('unicorns', {stdin: 1});87-execa('unicorns', {stdin: null});87 execa('unicorns', {stdin: undefined});88 execa('unicorns', {stderr: 'pipe'});89 execa('unicorns', {stderr: 'ipc'});90 execa('unicorns', {stderr: 'ignore'});91 execa('unicorns', {stderr: 'inherit'});92 execa('unicorns', {stderr: process.stderr});93 execa('unicorns', {stderr: 1});95-execa('unicorns', {stderr: null});94 execa('unicorns', {stderr: undefined});95 execa('unicorns', {stdout: 'pipe'});96 execa('unicorns', {stdout: 'ipc'});97 execa('unicorns', {stdout: 'ignore'});98 execa('unicorns', {stdout: 'inherit'});99 execa('unicorns', {stdout: process.stdout});100 execa('unicorns', {stdout: 1});103-execa('unicorns', {stdout: null});101 execa('unicorns', {stdout: undefined});102 execa('unicorns', {windowsVerbatimArguments: true});103 104 expectType<ExecaChildProcess<string>>(execa('unicorns'));56 unmodified linesmodified:readme.md+10 added-10 removed
160 unmodified lines161 Returns the same result object as [`child_process.spawnSync`](https://nodejs.org/api/child_process.html#child_process_child_process_spawnsync_command_args_options).162 163 ### options164 165-Type: `Object`165+Type: `object`166 167 #### cwd168 169 Type: `string`<br>2 unmodified lines172 Current working directory of the child process.173 174 #### env175 176-Type: `Object`<br>176+Type: `object`<br>177 Default: `process.env`178 179 Environment key-value pairs. Extends automatically from `process.env`. Set `extendEnv` to `false` if you don't want this.180 11 unmodified lines192 Explicitly set the value of `argv[0]` sent to the child process. This will be set to `command` or `file` if not specified.193 194 #### stdio195 196-Type: `string[]` `string`<br>196+Type: `string | string[]`<br>197 Default: `pipe`198 199 Child's [stdio](https://nodejs.org/api/child_process.html#child_process_options_stdio) configuration.200 16 unmodified lines217 Sets the group identity of the process.218 219 #### shell220 221-Type: `boolean` `string`<br>221+Type: `boolean | string`<br>222 Default: `false`223 224 If `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 lines246 Preferred path to find locally installed binaries in (use with `preferLocal`).247 248 #### input249 250-Type: `string` `Buffer` `stream.Readable`250+Type: `string | Buffer | stream.Readable`251 252 Write some input to the `stdin` of your binary.<br>253 Streams are not allowed when using the synchronous methods.254 12 unmodified lines267 Keep track of the spawned process and `kill` it when the parent process exits.268 269 #### encoding270 271-Type: `string` `null`<br>271+Type: `string | null`<br>272 Default: `utf8`273 274 Specify 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 lines295 Largest amount of data in bytes allowed on `stdout` or `stderr`.296 297 #### killSignal298 299-Type: `string` `number`<br>299+Type: `string | number`<br>300 Default: `SIGTERM`301 302 Signal value to be used when the spawned process will be killed.303 304 #### stdin305 306-Type: `string` `number` `Stream` `undefined` `null`<br>306+Type: `string | number | Stream | undefined`<br>307 Default: `pipe`308 309 Same options as [`stdio`](https://nodejs.org/dist/latest-v6.x/docs/api/child_process.html#child_process_options_stdio).310 311 #### stdout312 313-Type: `string` `number` `Stream` `undefined` `null`<br>313+Type: `string | number | Stream | undefined`<br>314 Default: `pipe`315 316 Same options as [`stdio`](https://nodejs.org/dist/latest-v6.x/docs/api/child_process.html#child_process_options_stdio).317 318 #### stderr319 320-Type: `string` `number` `Stream` `undefined` `null`<br>320+Type: `string | number | Stream | undefined`<br>321 Default: `pipe`322 323 Same options as [`stdio`](https://nodejs.org/dist/latest-v6.x/docs/api/child_process.html#child_process_options_stdio).324 32 unmodified linesmodified:test.js+2 added-2 removed
74 unmodified lines75 await t.throwsAsync(execa('fixtures/error-message.js', {stdout: 'inherit', stderr: 'inherit'}), {message: NO_NEWLINES_REGEXP});76 });77 78 test('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 });81 82 test('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 lines212 213 test('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