Execa 2 release — process execution for humans

By ehmicky

Today we are releasing a new major version of Execa. This Node.js library enhances child processes with:

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:

We have added TypeScript declarations.

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.

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).

The preferLocal option now defaults to false. If you are executing locally installed binaries, you’ll need to specify the preferLocal: true option.

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 nodeOptionsflags.

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.

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.

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

Execa produces better errors:

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).

Execute commands in Gulp.js with Gulp Execa. This thin wrapper around Execa adds Gulp-specific features related to verbosity, output, errors and streaming.

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.

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.