Execa
Helper functions having to do with running commands in a Bash-like TypeScript script.
These functions are based upon the
$
function from the
execa
library, but pass the stdout/stderr to the
console (which is the default behavior of a Bash script).
Functions
$()
Same as execa()
but using script-friendly default options.
When command
is a template string, it includes both the file
and its arguments
.
$(options)
can be used to return a new instance of this method but with different default options
. Consecutive calls are merged to previous ones.
This is the preferred method when executing multiple commands in a script file.
Throws
ExecaError
Examples
import {$} from 'execa';
const branch = await $`git branch --show-current`;
await $`dep deploy --branch=${branch}`;
$ node build.js
Building application...
Done building.
Running tests...
Error: the entrypoint is invalid.
$ NODE_DEBUG=execa node build.js
[00:57:44.581] [0] $ npm run build
[00:57:44.653] [0] Building application...
[00:57:44.653] [0] Done building.
[00:57:44.658] [0] ✔ (done in 78ms)
[00:57:44.658] [1] $ npm run test
[00:57:44.740] [1] Running tests...
[00:57:44.740] [1] Error: the entrypoint is invalid.
[00:57:44.747] [1] ✘ Command failed with exit code 1: npm run test
[00:57:44.747] [1] ✘ (done in 89ms)
Call Signature
function $<NewOptionsType>(options): ExecaScriptMethod<object & NewOptionsType>
Type Parameters
Type Parameter | Default type |
---|---|
NewOptionsType extends CommonOptions | object |
Parameters
Parameter | Type |
---|---|
options | NewOptionsType |
Returns
ExecaScriptMethod
<object
& NewOptionsType
>
Defined in
node_modules/execa/types/methods/script.d.ts:53
Call Signature
function $(...templateString): ResultPromise<object>
Parameters
Parameter | Type |
---|---|
...templateString | readonly [TemplateStringsArray , TemplateExpression ] |
Returns
ResultPromise
<object
>
Defined in
node_modules/execa/types/methods/script.d.ts:53
Call Signature
function $<NewOptionsType>(
file,
arguments?,
options?): ResultPromise<StricterOptions<object & NewOptionsType, Options>>