Skip to content
Myr

Meta tweaks

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 74c3c49 · Browse files · 2 files+40 added−45 removed
This commit

State

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

Diff stats

2 files+40 added−45 removed

  • other:+40 added−45 removed

2 files+40 added−45 removed

modified:package.json+3 added-2 removed
modified:readme.md+37 added-43 removed
3 unmodified lines
4[![Build Status](https://travis-ci.org/sindresorhus/execa.svg?branch=master)](https://travis-ci.org/sindresorhus/execa) [![Coverage Status](https://coveralls.io/repos/github/sindresorhus/execa/badge.svg?branch=master)](https://coveralls.io/github/sindresorhus/execa?branch=master)56> Process execution for humans788## Why910This package improves [`child_process`](https://nodejs.org/api/child_process.html) methods with:11
7 unmodified lines
19- [Get interleaved output](#all) from `stdout` and `stderr` similar to what is printed on the terminal. [*(Async only)*](#execasyncfile-arguments-options)20- [Can specify file and arguments as a single string without a shell](#execacommandcommand-options)21- More descriptive errors.222423## Install2425```26$ npm install execa27```283129## Usage3031```js32const execa = require('execa');
111 unmodified lines
144 });145}, 1000);146```147151148## API149154### execa(file, arguments, [options])150### execa(file, arguments, options?)151152Execute a file. Think of this as a mix of [`child_process.execFile()`](https://nodejs.org/api/child_process.html#child_process_child_process_execfile_file_args_options_callback) and [`child_process.spawn()`](https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options).153154No escaping/quoting is needed.
3 unmodified lines
158Returns a [`child_process` instance](https://nodejs.org/api/child_process.html#child_process_class_childprocess) which:159 - is also a `Promise` resolving or rejecting with a [`childProcessResult`](#childProcessResult).160 - exposes the following additional methods and properties.161166#### kill([signal], [options])162#### kill(signal?, options?)163164Same as the original [`child_process#kill()`](https://nodejs.org/api/child_process.html#child_process_subprocess_kill_signal) except: if `signal` is `SIGTERM` (the default value) and the child process is not terminated after 5 seconds, force it by sending `SIGKILL`.165166##### options.forceKillAfterTimeout167172Type: `number | false`<br>168Type: `number | false`\169Default: `5000`170171Milliseconds to wait for the child process to terminate before sending `SIGKILL`.172
12 unmodified lines
185This is `undefined` if either:186 - the [`all` option](#all-2) is `false` (the default value)187 - both [`stdout`](#stdout-1) and [`stderr`](#stderr-1) options are set to [`'inherit'`, `'ipc'`, `Stream` or `integer`](https://nodejs.org/dist/latest-v6.x/docs/api/child_process.html#child_process_options_stdio)188193### execa.sync(file, [arguments], [options])189### execa.sync(file, arguments?, options?)190191Execute a file synchronously.192193Returns or throws a [`childProcessResult`](#childProcessResult).194199### execa.command(command, [options])195### execa.command(command, options?)196197Same as [`execa()`](#execafile-arguments-options) except both file and arguments are specified in a single `command` string. For example, `execa('echo', ['unicorns'])` is the same as `execa.command('echo unicorns')`.198199If the file or an argument contains spaces, they must be escaped with backslashes. This matters especially if `command` is not a constant but a variable, for example with `__dirname` or `process.cwd()`. Except for spaces, no escaping/quoting is needed.200201The [`shell` option](#shell) must be used if the `command` uses shell-specific features, as opposed to being a simple `file` followed by its `arguments`.202207### execa.commandSync(command, [options])203### execa.commandSync(command, options?)204205Same as [`execa.command()`](#execacommand-command-options) but synchronous.206207Returns or throws a [`childProcessResult`](#childProcessResult).208213### execa.node(scriptPath, [arguments], [options])209### execa.node(scriptPath, arguments?, options?)210211Execute a Node.js script as a child process.212213Same as `execa('node', [scriptPath, ...arguments], options)` except (like [`child_process#fork()`](https://nodejs.org/api/child_process.html#child_process_child_process_fork_modulepath_args_options)):
101 unmodified lines
315Type: `object`316317#### cleanup318323Type: `boolean`<br>319Type: `boolean`\320Default: `true`321322Kill the spawned process when the parent process exits unless either:323 - the spawned process is [`detached`](https://nodejs.org/api/child_process.html#child_process_options_detached)324 - the parent process is terminated abruptly, for example, with `SIGKILL` as opposed to `SIGTERM` or a normal exit325326#### preferLocal327332Type: `boolean`<br>328Type: `boolean`\329Default: `false`330335Prefer locally installed binaries when looking for a binary to execute.<br>331Prefer locally installed binaries when looking for a binary to execute.\332If you `$ npm install foo`, you can then `execa('foo')`.333334#### localDir335340Type: `string`<br>336Type: `string`\337Default: `process.cwd()`338339Preferred path to find locally installed binaries in (use with `preferLocal`).340341#### execPath342347Type: `string`<br>348Default: `process.execPath` (current Node.js executable)343Type: `string`\344Default: `process.execPath` (Current Node.js executable)345346Path to the Node.js executable to use in child processes.347348This can be either an absolute path or a path relative to the [`cwd` option](#cwd).
3 unmodified lines
352For example, this can be used together with [`get-node`](https://github.com/ehmicky/get-node) to run a specific Node.js version in a child process.353354#### buffer355360Type: `boolean`<br>356Type: `boolean`\357Default: `true`358359Buffer the output from the spawned process. When set to `false`, you must read the output of [`stdout`](#stdout-1) and [`stderr`](#stderr-1) (or [`all`](#all) if the [`all`](#all-2) option is `true`). Otherwise the returned promise will not be resolved/rejected.360
2 unmodified lines
363#### input364365Type: `string | Buffer | stream.Readable`366371Write some input to the `stdin` of your binary.<br>367Write some input to the `stdin` of your binary.\368Streams are not allowed when using the synchronous methods.369370#### stdin371376Type: `string | number | Stream | undefined`<br>372Type: `string | number | Stream | undefined`\373Default: `pipe`374375Same options as [`stdio`](https://nodejs.org/dist/latest-v6.x/docs/api/child_process.html#child_process_options_stdio).376377#### stdout378383Type: `string | number | Stream | undefined`<br>379Type: `string | number | Stream | undefined`\380Default: `pipe`381382Same options as [`stdio`](https://nodejs.org/dist/latest-v6.x/docs/api/child_process.html#child_process_options_stdio).383384#### stderr385390Type: `string | number | Stream | undefined`<br>386Type: `string | number | Stream | undefined`\387Default: `pipe`388389Same options as [`stdio`](https://nodejs.org/dist/latest-v6.x/docs/api/child_process.html#child_process_options_stdio).390391#### all392397Type: `boolean`<br>393Type: `boolean`\394Default: `false`395396Add an `.all` property on the [promise](#all) and the [resolved value](#all-1). The property contains the output of the process with `stdout` and `stderr` interleaved.397398#### reject399404Type: `boolean`<br>400Type: `boolean`\401Default: `true`402403Setting this to `false` resolves the promise with the error instead of rejecting it.404405#### stripFinalNewline406411Type: `boolean`<br>407Type: `boolean`\408Default: `true`409410Strip the final [newline character](https://en.wikipedia.org/wiki/Newline) from the output.411412#### extendEnv413418Type: `boolean`<br>414Type: `boolean`\415Default: `true`416417Set to `false` if you don't want to extend the environment variables when providing the `env` property.418
2 unmodified lines
421Execa 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)422423#### cwd424429Type: `string`<br>425Type: `string`\426Default: `process.cwd()`427428Current working directory of the child process.429430#### env431436Type: `object`<br>432Type: `object`\433Default: `process.env`434435Environment key-value pairs. Extends automatically from `process.env`. Set [`extendEnv`](#extendenv) to `false` if you don't want this.436
4 unmodified lines
441Explicitly set the value of `argv[0]` sent to the child process. This will be set to `file` if not specified.442443#### stdio444449Type: `string | string[]`<br>445Type: `string | string[]`\446Default: `pipe`447448Child's [stdio](https://nodejs.org/api/child_process.html#child_process_options_stdio) configuration.449450#### serialization451456Type: `string`<br>452Type: `string`\453Default: `'json'`454455Specify the kind of serialization used for sending messages between processes when using the [`stdio: 'ipc'`](#stdio) option or [`execa.node()`](#execanodescriptpath-arguments-options):456 - `json`: Uses `JSON.stringify()` and `JSON.parse()`.
22 unmodified lines
479Sets the group identity of the process.480481#### shell482487Type: `boolean | string`<br>483Type: `boolean | string`\484Default: `false`485486If `true`, runs `file` 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.487
3 unmodified lines
491- unsafe, potentially allowing command injection.492493#### encoding494499Type: `string | null`<br>495Type: `string | null`\496Default: `utf8`497498Specify 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.499500#### timeout501506Type: `number`<br>502Type: `number`\503Default: `0`504505If 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.506507#### maxBuffer508513Type: `number`<br>509Type: `number`\510Default: `100_000_000` (100 MB)511512Largest amount of data in bytes allowed on `stdout` or `stderr`.513514#### killSignal515520Type: `string | number`<br>516Type: `string | number`\517Default: `SIGTERM`518519Signal value to be used when the spawned process will be killed.520521#### windowsVerbatimArguments522527Type: `boolean`<br>523Type: `boolean`\524Default: `false`525526If `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`.527528#### windowsHide529534Type: `boolean`<br>530Type: `boolean`\531Default: `true`532533On Windows, do not create a new console window. Please note this also prevents `CTRL-C` [from working](https://github.com/nodejs/node/issues/29837) on Windows.534539#### nodePath *(for `.node()` only)*535#### nodePath *(For `.node()` only)*536541Type: `string`<br>537Type: `string`\538Default: [`process.execPath`](https://nodejs.org/api/process.html#process_process_execpath)539540Node.js executable used to create the child process.541546#### nodeOptions *(for `.node()` only)*542#### nodeOptions *(For `.node()` only)*543548Type: `string[]`<br>544Type: `string[]`\545Default: [`process.execArgv`](https://nodejs.org/api/process.html#process_process_execargv)546547List of [CLI options](https://nodejs.org/api/cli.html#cli_options) passed to the Node.js executable.548
65 unmodified lines
614615- [gulp-execa](https://github.com/ehmicky/gulp-execa) - Gulp plugin for `execa`616- [nvexeca](https://github.com/ehmicky/nvexeca) - Run `execa` using any Node.js version617622618## Maintainers619620- [Sindre Sorhus](https://github.com/sindresorhus)621- [@ehmicky](https://github.com/ehmicky)622628623---624625<div align="center">626 <b>
7 unmodified lines