Skip to content

Commit 4692dcd

Browse files
committed
Improve the TS types and don't accept null in the stdio option
1 parent 10c73dc commit 4692dcd

File tree

6 files changed

+24
-33
lines changed

6 files changed

+24
-33
lines changed

index.d.ts

+10-15
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ declare namespace execa {
1010
| 'inherit'
1111
| Stream
1212
| number
13-
| null
1413
| undefined;
1514

1615
interface CommonOptions<EncodingType> {
@@ -45,7 +44,7 @@ declare namespace execa {
4544
4645
@default 'pipe'
4746
*/
48-
readonly stdio?: 'pipe' | 'ignore' | 'inherit' | ReadonlyArray<StdioOption>;
47+
readonly stdio?: 'pipe' | 'ignore' | 'inherit' | readonly StdioOption[];
4948

5049
/**
5150
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).
@@ -284,11 +283,7 @@ declare namespace execa {
284283

285284
interface ExecaChildPromise<StdoutErrorType> {
286285
catch<ResultType = never>(
287-
onRejected?:
288-
| ((
289-
reason: ExecaError<StdoutErrorType>
290-
) => ResultType | PromiseLike<ResultType>)
291-
| null
286+
onRejected?: (reason: ExecaError<StdoutErrorType>) => ResultType | PromiseLike<ResultType>
292287
): Promise<ExecaReturnValue<StdoutErrorType> | ResultType>;
293288

294289
/**
@@ -340,12 +335,12 @@ declare const execa: {
340335
*/
341336
(
342337
file: string,
343-
arguments?: ReadonlyArray<string>,
338+
arguments?: readonly string[],
344339
options?: execa.Options
345340
): execa.ExecaChildProcess;
346341
(
347342
file: string,
348-
arguments?: ReadonlyArray<string>,
343+
arguments?: readonly string[],
349344
options?: execa.Options<null>
350345
): execa.ExecaChildProcess<Buffer>;
351346
(file: string, options?: execa.Options): execa.ExecaChildProcess;
@@ -362,12 +357,12 @@ declare const execa: {
362357
*/
363358
stdout(
364359
file: string,
365-
arguments?: ReadonlyArray<string>,
360+
arguments?: readonly string[],
366361
options?: execa.Options
367362
): Promise<string>;
368363
stdout(
369364
file: string,
370-
arguments?: ReadonlyArray<string>,
365+
arguments?: readonly string[],
371366
options?: execa.Options<null>
372367
): Promise<Buffer>;
373368
stdout(file: string, options?: execa.Options): Promise<string>;
@@ -382,12 +377,12 @@ declare const execa: {
382377
*/
383378
stderr(
384379
file: string,
385-
arguments?: ReadonlyArray<string>,
380+
arguments?: readonly string[],
386381
options?: execa.Options
387382
): Promise<string>;
388383
stderr(
389384
file: string,
390-
arguments?: ReadonlyArray<string>,
385+
arguments?: readonly string[],
391386
options?: execa.Options<null>
392387
): Promise<Buffer>;
393388
stderr(file: string, options?: execa.Options): Promise<string>;
@@ -449,12 +444,12 @@ declare const execa: {
449444
*/
450445
sync(
451446
file: string,
452-
arguments?: ReadonlyArray<string>,
447+
arguments?: readonly string[],
453448
options?: execa.SyncOptions
454449
): execa.ExecaSyncReturnValue;
455450
sync(
456451
file: string,
457-
arguments?: ReadonlyArray<string>,
452+
arguments?: readonly string[],
458453
options?: execa.SyncOptions<null>
459454
): execa.ExecaSyncReturnValue<Buffer>;
460455
sync(file: string, options?: execa.SyncOptions): execa.ExecaSyncReturnValue;

index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ function handleArgs(command, args, options) {
6969
}
7070

7171
function handleInput(spawned, input) {
72-
if (input === null || input === undefined) {
72+
if (input === undefined) {
7373
return;
7474
}
7575

index.test-d.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ execa('unicorns', {stdio: 'pipe'});
6161
execa('unicorns', {stdio: 'ignore'});
6262
execa('unicorns', {stdio: 'inherit'});
6363
execa('unicorns', {
64-
stdio: ['pipe', 'ipc', 'ignore', 'inherit', process.stdin, 1, null, undefined]
64+
stdio: ['pipe', 'ipc', 'ignore', 'inherit', process.stdin, 1, undefined]
6565
});
6666
execa('unicorns', {detached: true});
6767
execa('unicorns', {uid: 0});
@@ -84,23 +84,20 @@ execa('unicorns', {stdin: 'ignore'});
8484
execa('unicorns', {stdin: 'inherit'});
8585
execa('unicorns', {stdin: process.stdin});
8686
execa('unicorns', {stdin: 1});
87-
execa('unicorns', {stdin: null});
8887
execa('unicorns', {stdin: undefined});
8988
execa('unicorns', {stderr: 'pipe'});
9089
execa('unicorns', {stderr: 'ipc'});
9190
execa('unicorns', {stderr: 'ignore'});
9291
execa('unicorns', {stderr: 'inherit'});
9392
execa('unicorns', {stderr: process.stderr});
9493
execa('unicorns', {stderr: 1});
95-
execa('unicorns', {stderr: null});
9694
execa('unicorns', {stderr: undefined});
9795
execa('unicorns', {stdout: 'pipe'});
9896
execa('unicorns', {stdout: 'ipc'});
9997
execa('unicorns', {stdout: 'ignore'});
10098
execa('unicorns', {stdout: 'inherit'});
10199
execa('unicorns', {stdout: process.stdout});
102100
execa('unicorns', {stdout: 1});
103-
execa('unicorns', {stdout: null});
104101
execa('unicorns', {stdout: undefined});
105102
execa('unicorns', {windowsVerbatimArguments: true});
106103

readme.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ Returns the same result object as [`child_process.spawnSync`](https://nodejs.org
162162

163163
### options
164164

165-
Type: `Object`
165+
Type: `object`
166166

167167
#### cwd
168168

@@ -173,7 +173,7 @@ Current working directory of the child process.
173173

174174
#### env
175175

176-
Type: `Object`<br>
176+
Type: `object`<br>
177177
Default: `process.env`
178178

179179
Environment key-value pairs. Extends automatically from `process.env`. Set `extendEnv` to `false` if you don't want this.
@@ -193,7 +193,7 @@ Explicitly set the value of `argv[0]` sent to the child process. This will be se
193193

194194
#### stdio
195195

196-
Type: `string[]` `string`<br>
196+
Type: `string | string[]`<br>
197197
Default: `pipe`
198198

199199
Child's [stdio](https://nodejs.org/api/child_process.html#child_process_options_stdio) configuration.
@@ -218,7 +218,7 @@ Sets the group identity of the process.
218218

219219
#### shell
220220

221-
Type: `boolean` `string`<br>
221+
Type: `boolean | string`<br>
222222
Default: `false`
223223

224224
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.
@@ -247,7 +247,7 @@ Preferred path to find locally installed binaries in (use with `preferLocal`).
247247

248248
#### input
249249

250-
Type: `string` `Buffer` `stream.Readable`
250+
Type: `string | Buffer | stream.Readable`
251251

252252
Write some input to the `stdin` of your binary.<br>
253253
Streams are not allowed when using the synchronous methods.
@@ -268,7 +268,7 @@ Keep track of the spawned process and `kill` it when the parent process exits.
268268

269269
#### encoding
270270

271-
Type: `string` `null`<br>
271+
Type: `string | null`<br>
272272
Default: `utf8`
273273

274274
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.
@@ -296,28 +296,28 @@ Largest amount of data in bytes allowed on `stdout` or `stderr`.
296296

297297
#### killSignal
298298

299-
Type: `string` `number`<br>
299+
Type: `string | number`<br>
300300
Default: `SIGTERM`
301301

302302
Signal value to be used when the spawned process will be killed.
303303

304304
#### stdin
305305

306-
Type: `string` `number` `Stream` `undefined` `null`<br>
306+
Type: `string | number | Stream | undefined`<br>
307307
Default: `pipe`
308308

309309
Same options as [`stdio`](https://nodejs.org/dist/latest-v6.x/docs/api/child_process.html#child_process_options_stdio).
310310

311311
#### stdout
312312

313-
Type: `string` `number` `Stream` `undefined` `null`<br>
313+
Type: `string | number | Stream | undefined`<br>
314314
Default: `pipe`
315315

316316
Same options as [`stdio`](https://nodejs.org/dist/latest-v6.x/docs/api/child_process.html#child_process_options_stdio).
317317

318318
#### stderr
319319

320-
Type: `string` `number` `Stream` `undefined` `null`<br>
320+
Type: `string | number | Stream | undefined`<br>
321321
Default: `pipe`
322322

323323
Same options as [`stdio`](https://nodejs.org/dist/latest-v6.x/docs/api/child_process.html#child_process_options_stdio).

test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ test('do not include `stderr` and `stdout` in errors when set to `inherit`', asy
7676
});
7777

7878
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});
8080
});
8181

8282
test('do not include `stdout` in errors when set to `inherit`', async t => {
@@ -213,7 +213,7 @@ test('input option can be a Buffer - sync', t => {
213213
test('opts.stdout:ignore - stdout will not collect data', async t => {
214214
const {stdout} = await execa('stdin', {
215215
input: 'hello',
216-
stdio: [null, 'ignore', null]
216+
stdio: [undefined, 'ignore', undefined]
217217
});
218218
t.is(stdout, undefined);
219219
});

test/stdio.js

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ function macro(t, input, expected) {
2222
macro.title = (providedTitle, input) => providedTitle || util.inspect(input, {colors: true});
2323

2424
test(macro, undefined, undefined);
25-
test(macro, null, undefined);
2625

2726
test(macro, {stdio: 'inherit'}, 'inherit');
2827
test(macro, {stdio: 'pipe'}, 'pipe');

0 commit comments

Comments
 (0)