Separate core options from execa-specific options (#256)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by ehmicky · committed by Sindre Sorhus · parent 50e3ef4 · Browse files · 3 files·+177 added−173 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+177 added−173 removed
- other:+177 added−173 removed
Provenance
- Commit
76191ae- Tree
6608103- Author
ehmicky <ehmicky@users.noreply.github.com>- Committer
Sindre Sorhus <sindresorhus@gmail.com>- Parent
50e3ef4
3 files changed+177 added−173 removed
modified:index.d.ts+69 added-69 removed
12 unmodified lines13 | undefined;14 15 interface CommonOptions<EncodingType> {16 /**17- Current working directory of the child process.17+ Kill the spawned process when the parent process exits unless either:18+ - the spawned process is [`detached`](https://nodejs.org/api/child_process.html#child_process_options_detached)19+ - the parent process is terminated abruptly, for example, with `SIGKILL` as opposed to `SIGTERM` or a normal exit20 19- @default process.cwd()21+ @default true22 */21- readonly cwd?: string;23+ readonly cleanup?: boolean;24 25 /**24- Environment key-value pairs. Extends automatically from `process.env`. Set `extendEnv` to `false` if you don't want this.26+ Prefer locally installed binaries when looking for a binary to execute.27 26- @default process.env28+ If you `$ npm install foo`, you can then `execa('foo')`.29+30+ @default true31 */28- readonly env?: NodeJS.ProcessEnv;32+ readonly preferLocal?: boolean;33 34 /**31- Set to `false` if you don't want to extend the environment variables when providing the `env` property.35+ Preferred path to find locally installed binaries in (use with `preferLocal`).36 33- @default true37+ @default process.cwd()38 */35- readonly extendEnv?: boolean;39+ readonly localDir?: string;40 41 /**38- Explicitly set the value of `argv[0]` sent to the child process. This will be set to `command` or `file` if not specified.42+ Buffer the output from the spawned process. When buffering is disabled you must consume the output of the `stdout` and `stderr` streams because the promise will not be resolved/rejected until they have completed.43+44+ @default true45 */40- readonly argv0?: string;46+ readonly buffer?: boolean;47 48 /**43- Child's [stdio](https://nodejs.org/api/child_process.html#child_process_options_stdio) configuration.49+ Same options as [`stdio`](https://nodejs.org/dist/latest-v6.x/docs/api/child_process.html#child_process_options_stdio).50 51 @default 'pipe'52 */47- readonly stdio?: 'pipe' | 'ignore' | 'inherit' | readonly StdioOption[];53+ readonly stdin?: StdioOption;54 55 /**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).56+ Same options as [`stdio`](https://nodejs.org/dist/latest-v6.x/docs/api/child_process.html#child_process_options_stdio).57 52- @default false58+ @default 'pipe'59 */54- readonly detached?: boolean;60+ readonly stdout?: StdioOption;61 62 /**57- Sets the user identity of the process.58- */59- readonly uid?: number;63+ Same options as [`stdio`](https://nodejs.org/dist/latest-v6.x/docs/api/child_process.html#child_process_options_stdio).64 61- /**62- Sets the group identity of the process.65+ @default 'pipe'66 */64- readonly gid?: number;67+ readonly stderr?: StdioOption;68 69 /**67- 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.70+ Setting this to `false` resolves the promise with the error instead of rejecting it.71 69- We recommend against using this option since it is:70- - not cross-platform, encouraging shell-specific syntax.71- - slower, because of the additional shell interpretation.72- - unsafe, potentially allowing command injection.73-74- @default false72+ @default true73 */76- readonly shell?: boolean | string;74+ readonly reject?: boolean;75 76 /**77 Strip the final [newline character](https://en.wikipedia.org/wiki/Newline) from the output.78 1 unmodified line80 */81 readonly stripFinalNewline?: boolean;82 83 /**86- Prefer locally installed binaries when looking for a binary to execute.84+ Set to `false` if you don't want to extend the environment variables when providing the `env` property.85 88- If you `$ npm install foo`, you can then `execa('foo')`.89-86 @default true87 */92- readonly preferLocal?: boolean;88+ readonly extendEnv?: boolean;89 90 /**95- Preferred path to find locally installed binaries in (use with `preferLocal`).91+ Current working directory of the child process.92 93 @default process.cwd()94 */99- readonly localDir?: string;95+ readonly cwd?: string;96 97 /**102- Setting this to `false` resolves the promise with the error instead of rejecting it.98+ Environment key-value pairs. Extends automatically from `process.env`. Set `extendEnv` to `false` if you don't want this.99 104- @default true100+ @default process.env101 */106- readonly reject?: boolean;102+ readonly env?: NodeJS.ProcessEnv;103 104 /**109- Kill the spawned process when the parent process exits unless either:110- - the spawned process is [`detached`](https://nodejs.org/api/child_process.html#child_process_options_detached)111- - the parent process is terminated abruptly, for example, with `SIGKILL` as opposed to `SIGTERM` or a normal exit112-113- @default true105+ Explicitly set the value of `argv[0]` sent to the child process. This will be set to `command` or `file` if not specified.106 */115- readonly cleanup?: boolean;107+ readonly argv0?: string;108 109 /**118- 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.110+ Child's [stdio](https://nodejs.org/api/child_process.html#child_process_options_stdio) configuration.111 120- @default 'utf8'112+ @default 'pipe'113 */122- readonly encoding?: EncodingType;114+ readonly stdio?: 'pipe' | 'ignore' | 'inherit' | readonly StdioOption[];115 116 /**125- If `timeout` is greater than `0`, the parent will send the signal identified by the `killSignal` property (the default is `SIGTERM`) if the child runs longer than `timeout` milliseconds.117+ 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).118 127- @default 0119+ @default false120 */129- readonly timeout?: number;121+ readonly detached?: boolean;122 123 /**132- Buffer the output from the spawned process. When buffering is disabled you must consume the output of the `stdout` and `stderr` streams because the promise will not be resolved/rejected until they have completed.124+ Sets the user identity of the process.125+ */126+ readonly uid?: number;127 134- @default true128+ /**129+ Sets the group identity of the process.130 */136- readonly buffer?: boolean;131+ readonly gid?: number;132 133 /**139- Largest amount of data in bytes allowed on `stdout` or `stderr`. Default: 10MB.134+ 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.135 141- @default 10000000136+ We recommend against using this option since it is:137+ - not cross-platform, encouraging shell-specific syntax.138+ - slower, because of the additional shell interpretation.139+ - unsafe, potentially allowing command injection.140+141+ @default false142 */143- readonly maxBuffer?: number;143+ readonly shell?: boolean | string;144 145 /**146- Signal value to be used when the spawned process will be killed.146+ 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.147 148- @default 'SIGTERM'148+ @default 'utf8'149 */150- readonly killSignal?: string | number;150+ readonly encoding?: EncodingType;151 152 /**153- Same options as [`stdio`](https://nodejs.org/dist/latest-v6.x/docs/api/child_process.html#child_process_options_stdio).153+ If `timeout` is greater than `0`, the parent will send the signal identified by the `killSignal` property (the default is `SIGTERM`) if the child runs longer than `timeout` milliseconds.154 155- @default 'pipe'155+ @default 0156 */157- readonly stdin?: StdioOption;157+ readonly timeout?: number;158 159 /**160- Same options as [`stdio`](https://nodejs.org/dist/latest-v6.x/docs/api/child_process.html#child_process_options_stdio).160+ Largest amount of data in bytes allowed on `stdout` or `stderr`. Default: 10MB.161 162- @default 'pipe'162+ @default 10000000163 */164- readonly stdout?: StdioOption;164+ readonly maxBuffer?: number;165 166 /**167- Same options as [`stdio`](https://nodejs.org/dist/latest-v6.x/docs/api/child_process.html#child_process_options_stdio).167+ Signal value to be used when the spawned process will be killed.168 169- @default 'pipe'169+ @default 'SIGTERM'170 */171- readonly stderr?: StdioOption;171+ readonly killSignal?: string | number;172 173 /**174 If `true`, no quoting or escaping of arguments is done on Windows. Ignored on other platforms. This is set to `true` automatically when the `shell` option is `true`.175 198 unmodified linesmodified:index.test-d.ts+25 added-25 removed
67 unmodified lines6869707172737475767778798081828384858687727374909192759495967677787980818213 unmodified lines9697989910010110210310410510610710810911011111211311411511611711811912012111912012112212312412523 unmodified lines67 unmodified lines expectType<boolean>(execaError.killed); expectType<string | undefined>(execaError.signal);}
execa('unicorns', {cwd: '.'});execa('unicorns', {env: {PATH: ''}});execa('unicorns', {extendEnv: false});execa('unicorns', {argv0: ''});execa('unicorns', {stdio: 'pipe'});execa('unicorns', {stdio: 'ignore'});execa('unicorns', {stdio: 'inherit'});execa('unicorns', { stdio: ['pipe', 'ipc', 'ignore', 'inherit', process.stdin, 1, undefined]});execa('unicorns', {detached: true});execa('unicorns', {uid: 0});execa('unicorns', {gid: 0});execa('unicorns', {shell: true});execa('unicorns', {shell: '/bin/sh'});execa('unicorns', {stripFinalNewline: false});execa('unicorns', {cleanup: false});execa('unicorns', {preferLocal: false});execa('unicorns', {localDir: '.'});execa('unicorns', {reject: false});execa('unicorns', {cleanup: false});execa('unicorns', {timeout: 1000});execa('unicorns', {buffer: false});execa('unicorns', {maxBuffer: 1000});execa('unicorns', {killSignal: 'SIGTERM'});execa('unicorns', {killSignal: 9});execa('unicorns', {input: ''});execa('unicorns', {input: Buffer.from('')});execa('unicorns', {input: process.stdin});execa('unicorns', {stdin: 'pipe'});execa('unicorns', {stdin: 'ipc'});execa('unicorns', {stdin: 'ignore'});execa('unicorns', {stdin: 'inherit'});13 unmodified linesexeca('unicorns', {stderr: 'inherit'});execa('unicorns', {stderr: process.stderr});execa('unicorns', {stderr: 1});execa('unicorns', {stderr: undefined});execa('unicorns', {reject: false});execa('unicorns', {stripFinalNewline: false});execa('unicorns', {extendEnv: false});execa('unicorns', {cwd: '.'});execa('unicorns', {env: {PATH: ''}});execa('unicorns', {argv0: ''});execa('unicorns', {stdio: 'pipe'});execa('unicorns', {stdio: 'ignore'});execa('unicorns', {stdio: 'inherit'});execa('unicorns', { stdio: ['pipe', 'ipc', 'ignore', 'inherit', process.stdin, 1, undefined]});execa('unicorns', {detached: true});execa('unicorns', {uid: 0});execa('unicorns', {gid: 0});execa('unicorns', {shell: true});execa('unicorns', {shell: '/bin/sh'});execa('unicorns', {timeout: 1000});execa('unicorns', {maxBuffer: 1000});execa('unicorns', {killSignal: 'SIGTERM'});execa('unicorns', {killSignal: 9});execa('unicorns', {windowsVerbatimArguments: true});execa('unicorns', {input: ''});execa('unicorns', {input: Buffer.from('')});execa('unicorns', {input: process.stdin});
expectType<ExecaChildProcess<string>>(execa('unicorns'));expectType<ExecaReturnValue<string>>(await execa('unicorns'));expectType<ExecaReturnValue<string>>(23 unmodified linesmodified:readme.md+83 added-79 removed
227 unmodified lines228 ### options229 230 Type: `object`231 232-#### cwd232+#### cleanup233 234+Type: `boolean`<br>235+Default: `true`236+237+Kill the spawned process when the parent process exits unless either:238+ - the spawned process is [`detached`](https://nodejs.org/api/child_process.html#child_process_options_detached)239+ - the parent process is terminated abruptly, for example, with `SIGKILL` as opposed to `SIGTERM` or a normal exit240+241+#### preferLocal242+243+Type: `boolean`<br>244+Default: `true`245+246+Prefer locally installed binaries when looking for a binary to execute.<br>247+If you `$ npm install foo`, you can then `execa('foo')`.248+249+#### localDir250+251 Type: `string`<br>252 Default: `process.cwd()`253 237-Current working directory of the child process.254+Preferred path to find locally installed binaries in (use with `preferLocal`).255 239-#### env256+#### buffer257 241-Type: `object`<br>242-Default: `process.env`258+Type: `boolean`<br>259+Default: `true`260 244-Environment key-value pairs. Extends automatically from `process.env`. Set `extendEnv` to `false` if you don't want this.261+Buffer the output from the spawned process. When buffering is disabled you must consume the output of the `stdout` and `stderr` streams because the promise will not be resolved/rejected until they have completed.262 263+#### input264+265+Type: `string | Buffer | stream.Readable`266+267+Write some input to the `stdin` of your binary.<br>268+Streams are not allowed when using the synchronous methods.269+270+#### stdin271+272+Type: `string | number | Stream | undefined`<br>273+Default: `pipe`274+275+Same options as [`stdio`](https://nodejs.org/dist/latest-v6.x/docs/api/child_process.html#child_process_options_stdio).276+277+#### stdout278+279+Type: `string | number | Stream | undefined`<br>280+Default: `pipe`281+282+Same options as [`stdio`](https://nodejs.org/dist/latest-v6.x/docs/api/child_process.html#child_process_options_stdio).283+284+#### stderr285+286+Type: `string | number | Stream | undefined`<br>287+Default: `pipe`288+289+Same options as [`stdio`](https://nodejs.org/dist/latest-v6.x/docs/api/child_process.html#child_process_options_stdio).290+291+#### reject292+293+Type: `boolean`<br>294+Default: `true`295+296+Setting this to `false` resolves the promise with the error instead of rejecting it.297+298+#### stripFinalNewline299+300+Type: `boolean`<br>301+Default: `true`302+303+Strip the final [newline character](https://en.wikipedia.org/wiki/Newline) from the output.304+305 #### extendEnv306 307 Type: `boolean`<br>308 Default: `true`309 310 Set to `false` if you don't want to extend the environment variables when providing the `env` property.311 312+---313+314+Execa also accepts the below options which are the same as the options for [`child_process#spawn()`](https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options)/[`child_process#exec()`](https://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback)315+316+#### cwd317+318+Type: `string`<br>319+Default: `process.cwd()`320+321+Current working directory of the child process.322+323+#### env324+325+Type: `object`<br>326+Default: `process.env`327+328+Environment key-value pairs. Extends automatically from `process.env`. Set [`extendEnv`](#extendenv) to `false` if you don't want this.329+330 #### argv0331 332 Type: `string`333 35 unmodified lines369 - not cross-platform, encouraging shell-specific syntax.370 - slower, because of the additional shell interpretation.371 - unsafe, potentially allowing command injection.372 296-#### stripFinalNewline297-298-Type: `boolean`<br>299-Default: `true`300-301-Strip the final [newline character](https://en.wikipedia.org/wiki/Newline) from the output.302-303-#### preferLocal304-305-Type: `boolean`<br>306-Default: `true`307-308-Prefer locally installed binaries when looking for a binary to execute.<br>309-If you `$ npm install foo`, you can then `execa('foo')`.310-311-#### localDir312-313-Type: `string`<br>314-Default: `process.cwd()`315-316-Preferred path to find locally installed binaries in (use with `preferLocal`).317-318-#### input319-320-Type: `string | Buffer | stream.Readable`321-322-Write some input to the `stdin` of your binary.<br>323-Streams are not allowed when using the synchronous methods.324-325-#### reject326-327-Type: `boolean`<br>328-Default: `true`329-330-Setting this to `false` resolves the promise with the error instead of rejecting it.331-332-#### cleanup333-334-Type: `boolean`<br>335-Default: `true`336-337-Kill the spawned process when the parent process exits unless either:338- - the spawned process is [`detached`](https://nodejs.org/api/child_process.html#child_process_options_detached)339- - the parent process is terminated abruptly, for example, with `SIGKILL` as opposed to `SIGTERM` or a normal exit340-373 #### encoding374 375 Type: `string | null`<br>376 Default: `utf8`6 unmodified lines383 Default: `0`384 385 If timeout is greater than `0`, the parent will send the signal identified by the `killSignal` property (the default is `SIGTERM`) if the child runs longer than timeout milliseconds.386 355-#### buffer356-357-Type: `boolean`<br>358-Default: `true`359-360-Buffer the output from the spawned process. When buffering is disabled you must consume the output of the `stdout` and `stderr` streams because the promise will not be resolved/rejected until they have completed.361-387 #### maxBuffer388 389 Type: `number`<br>390 Default: `10000000` (10MB)6 unmodified lines397 Default: `SIGTERM`398 399 Signal value to be used when the spawned process will be killed.400 376-#### stdin377-378-Type: `string | number | Stream | undefined`<br>379-Default: `pipe`380-381-Same options as [`stdio`](https://nodejs.org/dist/latest-v6.x/docs/api/child_process.html#child_process_options_stdio).382-383-#### stdout384-385-Type: `string | number | Stream | undefined`<br>386-Default: `pipe`387-388-Same options as [`stdio`](https://nodejs.org/dist/latest-v6.x/docs/api/child_process.html#child_process_options_stdio).389-390-#### stderr391-392-Type: `string | number | Stream | undefined`<br>393-Default: `pipe`394-395-Same options as [`stdio`](https://nodejs.org/dist/latest-v6.x/docs/api/child_process.html#child_process_options_stdio).396-401 #### windowsVerbatimArguments402 403 Type: `boolean`<br>404 Default: `false`28 unmodified lines