Execa 2 release — process execution for humans

Today we are releasing a new major version of Execa. This Node.js library enhances child processes with:
- Promises instead of callbacks
- Execution of locally installed binaries
- Better cross-platform support, including shebangs
- Cleanup of child processes when their parent exits
- And more
Thanks to Sindre Sorhus, ehmicky, GMartigny, BendingBender, tomsotte, Malik Ammar Faisal, zokker13, stroncium, Satya Rohith, Brad Lemley, coreyfarrell, Brandon Smith, Thai Pangsakulyanont and Pedro Augusto de Paula Barbosa, the following features are now available:
- TypeScript support
- Interleaved stdout and stderr
- Shell mode updates
- Changes to local binaries execution
- Improved spawning of Node.js scripts
- Graceful exit
- Process cancellation
- Enhanced errors
- Stricter exit codes
- Gulp plugin
- And more updates and bug fixes
TypeScript
We have added TypeScript declarations.

Interleaved stdout and stderr
Node.js returns a child process’s stdout
and stderr
separately. However, those streams are usually connected and intertwined in the console. We made it easy for you to retrieve their combined output.

Avoid the shell option
While it has (very) few legitimate uses, the shell
option should be avoided.
Why? First, it encourages shell-specific syntax (Bash, cmd.exe
) which won’t work on every OS. Almost every shell feature is available directly in Node.js.

Second, it is much slower as it makes every command go through the shell interpreter.
Last but not least, it increases the risk of command injection:

As a consequence, we have removed execa.shell()
and execa.shellSync()
which were merely shortcuts to the shell
option.
Furthermore, execa.command()
and execa.commandSync()
can now be used to specify the command and its arguments as a single string without the shell
option. Nothing needs to be escaped/quoted except for significant spaces (with a backslash).

Changes to local binaries execution
The preferLocal
option now defaults to false
. If you are executing locally installed binaries, you’ll need to specify the preferLocal: true
option.
Improved spawning of Node.js scripts
We have added execa.node()
which (like child_process.fork()
) executes a Node.js script as a child process.
It uses the current Node version and options. This can be overridden using the nodePath
and nodeOptions
flags.

Graceful exit
Some processes handle the SIGTERM
signal in order to cleanup resources and exit gracefully. This might take a long time or even never finish. childProcess.kill()
now sends a SIGKILL
signal after 5 seconds to prevent this. This can be configured using the forceKillAfterTimeout
option.

Process cancellation
Cancelling a child process execution is common, so we added support for it. It behaves like childProcess.kill()
but with better error messages and properties.

Enhanced errors
We have improved error messages and properties. Node.js child process errors contain less information, scattered over several events:

Execa produces better errors:


Stricter exit codes
Previously, the exit code
could either be a number
or a string
. That property was removed in favor of exitCode
(a number
) and exitCodeName
(a string
).
Gulp plugin
Execute commands in Gulp.js with Gulp Execa. This thin wrapper around Execa adds Gulp-specific features related to verbosity, output, errors and streaming.

More breaking changes
Node.js 6 support has been dropped.
The stripEof
option was renamed to stripFinalNewline
and the cmd
property to command
.
execa.stdout()
and execa.stderr()
have been removed since you can directly use the stdout
and stderr
properties of the resolved value.

Other updates
The windowsHide
option is now always true
. This ensures that no window pops up on Windows.
The maxBuffer
option default value has been increased from 10 MB
to 100 MB
.
Several bugs have also been fixed.
For more information, check the full changelog.
