Releases: sindresorhus/execa
v9.0.1
v9.0.0
This major release brings many important features including:
- Split the output into lines, or progressively iterate over them.
- Transform or filter the input/output using simple functions.
- Print the output to the terminal while still retrieving it programmatically.
- Redirect the input/output from/to a file.
- Advanced piping between multiple subprocesses.
- Improved verbose mode, for debugging.
- More detailed errors, including when terminating subprocesses.
- Enhanced template string syntax.
- Global/shared options.
- Web streams and Transform streams support.
- Convert the subprocess to a stream.
- New documentation with many examples.
Please check the release post for a high-level overview! For the full list of breaking changes, features and bug fixes, please read below.
Thanks @younggglcy, @koshic, @am0o0 and @codesmith-emmy for your help!
One of the maintainers @ehmicky is looking for a remote full-time position. Specialized in Node.js back-ends and CLIs, he led Netlify Build, Plugins and Configuration for 2.5 years. Feel free to contact him on his website or on LinkedIn!
Breaking changes (not types)
-
Dropped support for Node.js version
<18.19.0
and20.0.0 - 20.4.0
. (834e372) -
When the
encoding
option is'buffer'
, the output (result.stdout
,result.stderr
,result.all
) is now anUint8Array
instead of aBuffer
. For more information, see this blog post. (by @younggglcy) (#586)
const {stdout} = await execa('node', ['file.js'], {encoding: 'buffer'});
console.log(stdout); // This is now an Uint8Array
- await execa('node', ['file.js'], {encoding: null});
+ await execa('node', ['file.js'], {encoding: 'buffer'});
- await execa('node', ['file.js'], {encoding: 'utf-8'});
+ await execa('node', ['file.js'], {encoding: 'utf8'});
- await execa('node', ['file.js'], {encoding: 'UTF8'});
+ await execa('node', ['file.js'], {encoding: 'utf8'});
- await execa('node', ['file.js'], {encoding: 'utf-16le'});
+ await execa('node', ['file.js'], {encoding: 'utf16le'});
- await execa('node', ['file.js'], {encoding: 'ucs2'});
+ await execa('node', ['file.js'], {encoding: 'utf16le'});
- await execa('node', ['file.js'], {encoding: 'ucs-2'});
+ await execa('node', ['file.js'], {encoding: 'utf16le'});
- await execa('node', ['file.js'], {encoding: 'binary'});
+ await execa('node', ['file.js'], {encoding: 'latin1'});
- Passing a file path to
subprocess.pipeStdout()
,subprocess.pipeStderr()
andsubprocess.pipeAll()
has been removed. Instead, a{file: './path'}
object should be passed to thestdout
orstderr
option. (#752)
- await execa('node', ['file.js']).pipeStdout('output.txt');
+ await execa('node', ['file.js'], {stdout: {file: 'output.txt'}});
- await execa('node', ['file.js']).pipeStderr('output.txt');
+ await execa('node', ['file.js'], {stderr: {file: 'output.txt'}});
- await execa('node', ['file.js']).pipeAll('output.txt');
+ await execa('node', ['file.js'], {
+ stdout: {file: 'output.txt'},
+ stderr: {file: 'output.txt'},
+});
- Passing a writable stream to
subprocess.pipeStdout()
,subprocess.pipeStderr()
andsubprocess.pipeAll()
has been removed. Instead, the stream should be passed to thestdout
orstderr
option. If the stream does not have a file descriptor,['pipe', stream]
should be passed instead. (#752)
- await execa('node', ['file.js']).pipeStdout(stream);
+ await execa('node', ['file.js'], {stdout: ['pipe', stream]});
- await execa('node', ['file.js']).pipeStderr(stream);
+ await execa('node', ['file.js'], {stderr: ['pipe', stream]});
- await execa('node', ['file.js']).pipeAll(stream);
+ await execa('node', ['file.js'], {
+ stdout: ['pipe', stream],
+ stderr: ['pipe', stream],
+});
- The
subprocess.pipeStdout()
,subprocess.pipeStderr()
andsubprocess.pipeAll()
methods have been renamed tosubprocess.pipe()
. The command and its arguments can be passed tosubprocess.pipe()
directly, without callingexeca()
a second time. Thefrom
piping option can specify'stdout'
(the default value),'stderr'
or'all'
. (#757)
- await execa('node', ['file.js']).pipeStdout(execa('node', ['other.js']));
+ await execa('node', ['file.js']).pipe('node', ['other.js']);
- await execa('node', ['file.js']).pipeStderr(execa('node', ['other.js']));
+ await execa('node', ['file.js']).pipe('node', ['other.js'], {from: 'stderr'});
- await execa('node', ['file.js']).pipeAll(execa('node', ['other.js']));
+ await execa('node', ['file.js']).pipe('node', ['other.js'], {from: 'all'});
- Renamed the
signal
option tocancelSignal
. (#880)
- await execa('node', ['file.js'], {signal: abortController.signal});
+ await execa('node', ['file.js'], {cancelSignal: abortController.signal});
- Renamed
error.killed
toerror.isTerminated
. (#625)
try {
await execa('node', ['file.js']);
} catch (error) {
- if (error.killed) {
+ if (error.isTerminated) {
// ...
}
}
subprocess.cancel()
has been removed. Please use eithersubprocess.kill()
or thecancelSignal
option instead. (#711)
- subprocess.cancel();
+ subprocess.kill();
- Renamed the
forceKillAfterTimeout
option toforceKillAfterDelay
. Also, it is now passed toexeca()
instead ofsubprocess.kill()
. (#714, #723)
- const subprocess = execa('node', ['file.js']);
- subprocess.kill('SIGTERM', {forceKillAfterTimeout: 1000});
+ const subprocess = execa('node', ['file.js'], {forceKillAfterDelay: 1000});
+ subprocess.kill('SIGTERM');
- The
verbose
option is now a string enum instead of a boolean.false
has been renamed to'none'
andtrue
has been renamed to'short'
. (#884)
- await execa('node', ['file.js'], {verbose: false});
+ await execa('node', ['file.js'], {verbose: 'none'});
- await execa('node', ['file.js'], {verbose: true});
+ await execa('node', ['file.js'], {verbose: 'short'});
- The
execPath
option has been renamed tonodePath
. It is now a noop unless thenode
option istrue
. Also, it now works even if thepreferLocal
option isfalse
. (#812, #815)
- await execa('node', ['file.js'], {execPath: './path/to/node'});
+ await execa('node', ['file.js'], {nodePath: './path/to/node'});
- The default value for the
serialization
option is now'advanced'
instead of'json'
. In particular, when callingsubprocess.send(object)
with an object that contains functions or symbols, those were previously silently removed. Now this will throw an exception. (#905)
- subprocess.send({example: true, getExample() {}});
+ subprocess.send({example: true});
- If
subprocess.stdout
,subprocess.stderr
orsubprocess.all
is manually piped, the.pipe()
call must now happen as soon assubprocess
is created. Otherwise, the output at the beginning of the subprocess might be missing. (#658, #747)
const subprocess = execa('node', ['file.js']);
- setTimeout(() => {
subprocess.stdout.pipe(process.stdout);
- }, 0);
- Signals passed to
subprocess.kill()
and...
v8.0.1
Fixes
- Fix and document support for the
{encoding: 'buffer'}
option. It is the same as{encoding: null}
, but preferred over it. (#572)
v8.0.0
v7.2.0
v7.1.1
Features
- Improve error message when
$.sync(options)`command`
is used instead of$(options).sync`command`
(#551)
Bug fixes
- Fix argument concatenation when using
$`command argument${value}`
(#553) - Fix default value of the
stdin
option when using$`command`
: it should beinherit
(#550)
v7.1.0
Features
- Add
$
method to write Node.js scripts like zx. For more information, please see this blog post, this section and this page. Thanks @aaronccasanova for this great feature!
import {$} from 'execa';
const branch = await $`git branch --show-current`;
await $`dep deploy --branch=${branch}`;
- Add
.pipeStdout()
,.pipeStderr()
and.pipeAll()
methods to redirectstdout
/stderr
to a file, a stream or another process.
// Similar to `echo unicorns > stdout.txt` in Bash
await execa('echo', ['unicorns']).pipeStdout('stdout.txt');
// Similar to `echo unicorns 2> stdout.txt` in Bash
await execa('echo', ['unicorns']).pipeStderr('stderr.txt');
// Similar to `echo unicorns &> stdout.txt` in Bash
await execa('echo', ['unicorns'], {all: true}).pipeAll('all.txt');
- Add
inputFile
option to use a file asstdin
.
// Similar to `cat < stdin.txt` in Bash
const {stdout} = await execa('cat', {inputFile: 'stdin.txt'});
console.log(stdout);
//=> 'unicorns'
- Add
verbose
option to print each command onstderr
before executing it. This can also be enabled by setting theNODE_DEBUG=execa
environment variable in the current process.
> node file.js
unicorns
rainbows
> NODE_DEBUG=execa node file.js
[16:50:03.305] echo unicorns
unicorns
[16:50:03.308] echo rainbows
rainbows
v7.0.0
v6.1.0
- Support
AbortController
(#490) c6e791a - Allow
cwd
andlocalDir
options to be URLs (#492) 93ab929
v6.0.0
Breaking
- Require Node.js 12.20 (#478) 7707880
- This package is now pure ESM. Please read this.
- Moved from a default export to named exports.
require('execa')
βimport {execa} from 'execa'
require('execa').sync
βimport {execaSync} from 'execa'
require('execa').command
βimport {execaCommand} from 'execa'
require('execa').commandSync
βimport {execaCommandSync} from 'execa'
require('execa').node
βimport {execaNode} from 'execa'