scripts.md
This file
Path
docs/scripts.md
718 lines · 11.5 KiB · Markdown
Last changed by
Print process completion with verbose option (#887)ehmickybefore adoption7264bcf
History of this fileTake it
The walk stopped after 200 commits: lines older than db2ad9a point at it.
Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 1–8why, one step back1# Node.js scripts23With Execa, you can write scripts with Node.js instead of a shell language. It is [secure](#escaping), [performant](#performance), [simple](#simplicity) and [cross-platform](#shell).45```js6import {$} from 'execa';78const {stdout: name} = await $`cat package.json``.pipe()` shortcut for `$` (#840)ehmickybefore adoption316f562
line 9why, one step back9 .pipe`grep name`;Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 10–48why, one step back10console.log(name);1112const branch = await $`git branch --show-current`;13await $`dep deploy --branch=${branch}`;1415await Promise.all([16 $`sleep 1`,17 $`sleep 2`,18 $`sleep 3`,19]);2021const dirName = 'foo bar';22await $`mkdir /tmp/${dirName}`;23```2425## Summary2627This file describes the differences between Bash, Execa, and [zx](https://github.com/google/zx) (which inspired this feature).2829### Flexibility3031Unlike shell languages like Bash, libraries like Execa and zx enable you to write scripts with a more featureful programming language (JavaScript). This allows complex logic (such as [parallel execution](#parallel-commands)) to be expressed easily. This also lets you use [any Node.js package](#builtin-utilities).3233### Shell3435The main difference between Execa and zx is that Execa does not require any shell. Shell-specific keywords and features are [written in JavaScript](#variable-substitution) instead.3637This is more cross-platform. For example, your code works the same on Windows machines without Bash installed.3839Also, there is no shell syntax to remember: everything is just plain JavaScript.4041If you really need a shell though, the [`shell` option](../readme.md#shell) can be used.4243### Simplicity4445Execa's scripting API mostly consists of only two methods: [`` $`command` ``](../readme.md#command) and [`$(options)`](../readme.md#options).4647[No special binary](#main-binary) is recommended, no [global variable](#global-variables) is injected: scripts are regular Node.js files.48Rename `signal` option to `cancelSignal` (#880)ehmickybefore adoption231beaf
line 49why, one step back49Execa is a thin wrapper around the core Node.js [`child_process` module](https://nodejs.org/api/child_process.html). Unlike zx, it lets you use [any of its native features](#background-processes): [`pid`](#pid), [IPC](https://nodejs.org/api/child_process.html#subprocesssendmessage-sendhandle-options-callback), [`unref()`](https://nodejs.org/api/child_process.html#subprocessunref), [`detached`](https://nodejs.org/api/child_process.html#child_processspawncommand-args-options), [`uid`](https://nodejs.org/api/child_process.html#child_processspawncommand-args-options), [`gid`](https://nodejs.org/api/child_process.html#child_processspawncommand-args-options), [`cancelSignal`](https://nodejs.org/api/child_process.html#child_processspawncommand-args-options), etc.Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 50–123why, one step back5051### Modularity5253zx includes many builtin utilities: `fetch()`, `question()`, `sleep()`, `stdin()`, `retry()`, `spinner()`, `chalk`, `fs-extra`, `os`, `path`, `globby`, `yaml`, `minimist`, `which`, Markdown scripts, remote scripts.5455Execa does not include [any utility](#builtin-utilities): it focuses on being small and modular instead. Any Node.js package can be used in your scripts.5657### Performance5859Spawning a shell for every command comes at a performance cost, which Execa avoids.6061Also, [local binaries](#local-binaries) can be directly executed without using `npx`.6263### Debugging6465Child processes can be hard to debug, which is why Execa includes a [`verbose` option](#verbose-mode).6667Also, Execa's error messages and [properties](#errors) are very detailed to make it clear to determine why a process failed.6869Finally, unlike Bash and zx, which are stateful (options, current directory, etc.), Execa is [purely functional](#current-directory), which also helps with debugging.7071## Details7273### Main binary7475```sh76# Bash77bash file.sh78```7980```js81// zx82zx file.js8384// or a shebang can be used:85// #!/usr/bin/env zx86```8788```js89// Execa scripts are just regular Node.js files90node file.js91```9293### Global variables9495```js96// zx97await $`echo example`;98```99100```js101// Execa102import {$} from 'execa';103104await $`echo example`;105```106107### Command execution108109```sh110# Bash111echo example112```113114```js115// zx116await $`echo example`;117```118119```js120// Execa121await $`echo example`;122```123Allow newlines in `$` (#843)ehmickybefore adoption1315486
lines 124–147why, one step back124### Multiline commands125126```sh127# Bash128npm run build \129 --example-flag-one \130 --example-flag-two131```132133```js134// zx135await $`npm run build ${[136 '--example-flag-one',137 '--example-flag-two',138]}`;139```140141```js142// Execa143await $`npm run build144 --example-flag-one145 --example-flag-two`146```147Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
line 148why, one step back148### ConcatenationImprove main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 149–151why, one step back149150```sh151# BashReorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
lines 152–153why, one step back152tmpDir="/tmp"153mkdir "$tmpDir/filename"Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 154–157why, one step back154```155156```js157// zxReorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
lines 158–159why, one step back158const tmpDir = '/tmp'159await $`mkdir ${tmpDir}/filename`;Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 160–163why, one step back160```161162```js163// ExecaReorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
lines 164–165why, one step back164const tmpDir = '/tmp'165await $`mkdir ${tmpDir}/filename`;Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 166–167why, one step back166```167Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
line 168why, one step back168### Variable substitutionFix argument concatenation with `$` (#553)ehmickybefore adoption07585d0
lines 169–171why, one step back169170```sh171# BashReorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
line 172why, one step back172echo $LANGFix argument concatenation with `$` (#553)ehmickybefore adoption07585d0
lines 173–176why, one step back173```174175```js176// zxReorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
line 177why, one step back177await $`echo $LANG`;Fix argument concatenation with `$` (#553)ehmickybefore adoption07585d0
lines 178–181why, one step back178```179180```js181// ExecaReorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
line 182why, one step back182await $`echo ${process.env.LANG}`;Fix argument concatenation with `$` (#553)ehmickybefore adoption07585d0
lines 183–184why, one step back183```184Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
line 185why, one step back185### EscapingImprove main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 186–188why, one step back186187```sh188# BashReorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
line 189why, one step back189echo 'one two'Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 190–193why, one step back190```191192```js193// zxReorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
line 194why, one step back194await $`echo ${'one two'}`;Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 195–198why, one step back195```196197```js198// ExecaReorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
line 199why, one step back199await $`echo ${'one two'}`;Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 200–201why, one step back200```201Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
line 202why, one step back202### Escaping multiple argumentsImprove main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 203–205why, one step back203204```sh205# BashReorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
line 206why, one step back206echo 'one two' '$'Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 207–210why, one step back207```208209```js210// zxReorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
line 211why, one step back211await $`echo ${['one two', '$']}`;Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 212–215why, one step back212```213214```js215// ExecaReorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
line 216why, one step back216await $`echo ${['one two', '$']}`;Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 217–218why, one step back217```218Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
line 219why, one step back219### SubcommandsImprove main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 220–222why, one step back220221```sh222# BashReorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
line 223why, one step back223echo "$(echo example)"Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 224–227why, one step back224```225226```js227// zxReorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
lines 228–229why, one step back228const example = await $`echo example`;229await $`echo ${example}`;Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 230–233why, one step back230```231232```js233// ExecaReorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
lines 234–235why, one step back234const example = await $`echo example`;235await $`echo ${example}`;Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 236–237why, one step back236```237Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
line 238why, one step back238### Serial commandsImprove main method documentation (#545)ehmickybefore adoptiondb2ad9a
line 239why, one step back239Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
lines 240–244why, one step back240```sh241# Bash242echo one && echo two243```244Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 245–246why, one step back245```js246// zxReorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
line 247why, one step back247await $`echo one && echo two`;Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 248–251why, one step back248```249250```js251// ExecaReorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
lines 252–254why, one step back252await $`echo one`;253await $`echo two`;254```Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
line 255why, one step back255Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
lines 256–261why, one step back256### Parallel commands257258```sh259# Bash260echo one &261echo two &Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 262–263why, one step back262```263Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
lines 264–267why, one step back264```js265// zx266await Promise.all([$`echo one`, $`echo two`]);267```Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
line 268why, one step back268Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
lines 269–275why, one step back269```js270// Execa271await Promise.all([$`echo one`, $`echo two`]);272```273274### Global/shared options275Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 276–277why, one step back276```sh277# BashReorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
lines 278–281why, one step back278options="timeout 5"279$options echo one280$options echo two281$options echo threeImprove main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 282–285why, one step back282```283284```js285// zxReorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
lines 286–289why, one step back286const timeout = '5s';287await $`echo one`.timeout(timeout);288await $`echo two`.timeout(timeout);289await $`echo three`.timeout(timeout);Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 290–293why, one step back290```291292```js293// ExecaReorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
lines 294–300why, one step back294import {$ as $_} from 'execa';295296const $ = $_({timeout: 5000});297298await $`echo one`;299await $`echo two`;300await $`echo three`;Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 301–321why, one step back301```302303### Environment variables304305```sh306# Bash307EXAMPLE=1 example_command308```309310```js311// zx312$.env.EXAMPLE = '1';313await $`example_command`;314delete $.env.EXAMPLE;315```316317```js318// Execa319await $({env: {EXAMPLE: '1'}})`example_command`;320```321Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
line 322why, one step back322### Local binariesImprove main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 323–325why, one step back323324```sh325# BashReorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
line 326why, one step back326npx tsc --versionImprove main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 327–330why, one step back327```328329```js330// zxReorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
line 331why, one step back331await $`npx tsc --version`;Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 332–335why, one step back332```333334```js335// ExecaReorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
line 336why, one step back336await $`tsc --version`;Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 337–338why, one step back337```338Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
line 339why, one step back339### Builtin utilitiesImprove main method documentation (#545)ehmickybefore adoptiondb2ad9a
line 340why, one step back340Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
lines 341–354why, one step back341```js342// zx343const content = await stdin();344```345346```js347// Execa348import getStdin from 'get-stdin';349350const content = await getStdin();351```352353### Printing to stdout354Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 355–356why, one step back355```sh356# BashReorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
line 357why, one step back357echo exampleImprove main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 358–361why, one step back358```359360```js361// zxReorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
line 362why, one step back362echo`example`;Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 363–366why, one step back363```364365```js366// ExecaReorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
line 367why, one step back367console.log('example');Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 368–369why, one step back368```369Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
line 370why, one step back370### Silent stderrImprove main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 371–373why, one step back371372```sh373# BashReorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
line 374why, one step back374echo example 2> /dev/nullImprove main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 375–378why, one step back375```376377```js378// zxReorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
line 379why, one step back379await $`echo example`.stdio('inherit', 'pipe', 'ignore');Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 380–382why, one step back380```381382```jsReorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
lines 383–384why, one step back383// Execa does not print stdout/stderr by default384await $`echo example`;Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 385–404why, one step back385```386387### Verbose mode388389```sh390# Bash391set -v392echo example393```394395```js396// zx >=8397await $`echo example`.verbose();398399// or:400$.verbose = true;401```402403```js404// ExecaImprove documentation of global script options (#870)ehmickybefore adoption146fa07
lines 405–406why, one step back405import {$ as $_} from 'execa';406Print output with `verbose` option (#884)ehmickybefore adoption6fda30f
lines 407–408why, one step back407// `verbose: 'short'` is also available408const $ = $_({verbose: 'full'});Improve documentation of global script options (#870)ehmickybefore adoption146fa07
lines 409–410why, one step back409410await $`echo example`;Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 411–418why, one step back411```412413Or:414415```416NODE_DEBUG=execa node file.js417```418Improve `verbose` option (#883)ehmickybefore adoption7d0943f
lines 419–421why, one step back419Which prints:420421```Print output with `verbose` option (#884)ehmickybefore adoption6fda30f
lines 422–423why, one step back422[19:49:00.360] [0] $ echo example423examplePrint process completion with verbose option (#887)ehmickybefore adoption7264bcf
line 424why, one step back424[19:49:00.383] [0] √ (done in 23ms)Improve `verbose` option (#883)ehmickybefore adoption7d0943f
lines 425–426why, one step back425```426Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
line 427why, one step back427### Piping stdout to another commandImprove main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 428–430why, one step back428429```sh430# BashReorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
line 431why, one step back431echo npm run build | sort | head -n2Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 432–435why, one step back432```433434```js435// zxReorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
line 436why, one step back436await $`npm run build | sort | head -n2`;Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 437–440why, one step back437```438439```js440// ExecaReorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
lines 441–443why, one step back441await $`npm run build`442 .pipe`sort`443 .pipe`head -n2`;Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 444–445why, one step back444```445Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
line 446why, one step back446### Piping stdout and stderr to another commandImprove main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 447–449why, one step back447448```sh449# BashReorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
line 450why, one step back450echo example |& catImprove main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 451–454why, one step back451```452453```js454// zxReorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
lines 455–459why, one step back455const echo = $`echo example`;456const cat = $`cat`;457echo.pipe(cat)458echo.stderr.pipe(cat.stdin);459await Promise.all([echo, cat]);Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 460–463why, one step back460```461462```js463// ExecaReorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
lines 464–465why, one step back464await $({all: true})`echo example`465 .pipe({from: 'all'})`cat`;Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 466–467why, one step back466```467Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
line 468why, one step back468### Piping stdout to a fileImprove main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 469–471why, one step back469470```sh471# BashReorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
line 472why, one step back472echo example > file.txtImprove main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 473–476why, one step back473```474475```js476// zxReorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
line 477why, one step back477await $`echo example`.pipe(fs.createWriteStream('file.txt'));Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 478–481why, one step back478```479480```js481// ExecaReorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
line 482why, one step back482await $({stdout: {file: 'file.txt'}})`echo example`;Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 483–484why, one step back483```484Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
line 485why, one step back485### Piping stdin from a fileImprove main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 486–488why, one step back486487```sh488# BashReorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
line 489why, one step back489echo example < file.txtImprove main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 490–493why, one step back490```491492```js493// zxReorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
lines 494–496why, one step back494const cat = $`cat`495fs.createReadStream('file.txt').pipe(cat.stdin)496await catImprove main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 497–500why, one step back497```498499```js500// ExecaReorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
line 501why, one step back501await $({inputFile: 'file.txt'})`cat`Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 502–556why, one step back502```503504### Errors505506```sh507# Bash communicates errors only through the exit code and stderr508timeout 1 sleep 2509echo $?510```511512```js513// zx514const {515 stdout,516 stderr,517 exitCode,518 signal,519} = await $`sleep 2`.timeout('1s');520// file:///home/me/Desktop/node_modules/zx/build/core.js:146521// let output = new ProcessOutput(code, signal, stdout, stderr, combined, message);522// ^523// ProcessOutput [Error]:524// at file:///home/me/Desktop/example.js:2:20525// exit code: null526// signal: SIGTERM527// at ChildProcess.<anonymous> (file:///home/me/Desktop/node_modules/zx/build/core.js:146:26)528// at ChildProcess.emit (node:events:512:28)529// at maybeClose (node:internal/child_process:1098:16)530// at Socket.<anonymous> (node:internal/child_process:456:11)531// at Socket.emit (node:events:512:28)532// at Pipe.<anonymous> (node:net:316:12)533// at Pipe.callbackTrampoline (node:internal/async_hooks:130:17) {534// _code: null,535// _signal: 'SIGTERM',536// _stdout: '',537// _stderr: '',538// _combined: ''539// }540```541542```js543// Execa544const {545 stdout,546 stderr,547 exitCode,548 signal,549 signalDescription,550 originalMessage,551 shortMessage,552 command,553 escapedCommand,554 failed,555 timedOut,556 isCanceled,Fix `error.killed` and rename to `error.isTerminated` (#625)ehmickybefore adoption248349c
line 557why, one step back557 isTerminated,Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 558–577why, one step back558 // and other error-related properties: code, etc.559} = await $({timeout: 1})`sleep 2`;560// file:///home/me/code/execa/lib/kill.js:60561// reject(Object.assign(new Error('Timed out'), {timedOut: true, signal}));562// ^563// Error: Command timed out after 1 milliseconds: sleep 2564// Timed out565// at file:///home/me/Desktop/example.js:2:20566// timedOut: true,567// signal: 'SIGTERM',568// originalMessage: 'Timed out',569// shortMessage: 'Command timed out after 1 milliseconds: sleep 2\nTimed out',570// command: 'sleep 2',571// escapedCommand: 'sleep 2',572// exitCode: undefined,573// signalDescription: 'Termination',574// stdout: '',575// stderr: '',576// failed: true,577// isCanceled: false,Fix `error.killed` and rename to `error.isTerminated` (#625)ehmickybefore adoption248349c
line 578why, one step back578// isTerminated: falseImprove main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 579–581why, one step back579// }580```581Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
line 582why, one step back582### Exit codesImprove main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 583–585why, one step back583584```sh585# BashReorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
lines 586–587why, one step back586false587echo $?Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 588–591why, one step back588```589590```js591// zxReorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
lines 592–593why, one step back592const {exitCode} = await $`false`.nothrow();593echo`${exitCode}`;Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 594–597why, one step back594```595596```js597// ExecaReorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
lines 598–599why, one step back598const {exitCode} = await $({reject: false})`false`;599console.log(exitCode);Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 600–601why, one step back600```601Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
line 602why, one step back602### TimeoutsImprove main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 603–605why, one step back603604```sh605# BashReorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
line 606why, one step back606timeout 5 echo exampleImprove main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 607–609why, one step back607```608609```jsReorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
lines 610–611why, one step back610// zx611await $`echo example`.timeout('5s');Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 612–615why, one step back612```613614```js615// ExecaReorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
line 616why, one step back616await $({timeout: 5000})`echo example`;Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 617–618why, one step back617```618Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
line 619why, one step back619### Current filenameImprove main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 620–622why, one step back620621```sh622# BashReorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
line 623why, one step back623echo "$(basename "$0")"Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 624–627why, one step back624```625626```js627// zxReorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
line 628why, one step back628await $`echo ${__filename}`;Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 629–632why, one step back629```630631```js632// ExecaReorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
lines 633–634why, one step back633import {fileURLToPath} from 'node:url';634import path from 'node:path';Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
line 635why, one step back635Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
line 636why, one step back636const __filename = path.basename(fileURLToPath(import.meta.url));Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
line 637why, one step back637Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
line 638why, one step back638await $`echo ${__filename}`;Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 639–640why, one step back639```640Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
line 641why, one step back641### Current directoryImprove main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 642–644why, one step back642643```sh644# BashReorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
line 645why, one step back645cd projectImprove main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 646–649why, one step back646```647648```js649// zxReorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
lines 650–653why, one step back650cd('project');651652// or:653$.cwd = 'project';Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 654–657why, one step back654```655656```js657// ExecaReorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
line 658why, one step back658const $$ = $({cwd: 'project'});Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 659–660why, one step back659```660Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
line 661why, one step back661### Multiple current directoriesImprove main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 662–664why, one step back662663```sh664# BashReorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
lines 665–668why, one step back665pushd project666pwd667popd668pwdImprove main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 669–672why, one step back669```670671```js672// zxReorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
lines 673–678why, one step back673within(async () => {674 cd('project');675 await $`pwd`;676});677678await $`pwd`;Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 679–682why, one step back679```680681```js682// ExecaReorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
lines 683–684why, one step back683await $({cwd: 'project'})`pwd`;684await $`pwd`;Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 685–686why, one step back685```686Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
line 687why, one step back687### Background processesImprove main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 688–690why, one step back688689```sh690# BashReorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
line 691why, one step back691echo one &Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 692–694why, one step back692```693694```jsReorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
line 695why, one step back695// zx does not allow setting the `detached` optionImprove main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 696–699why, one step back696```697698```js699// ExecaReorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
line 700why, one step back700await $({detached: true})`echo one`;Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 701–702why, one step back701```702Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
line 703why, one step back703### PIDImprove main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 704–706why, one step back704705```sh706# BashReorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
lines 707–708why, one step back707echo example &708echo $!Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 709–711why, one step back709```710711```jsReorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
line 712why, one step back712// zx does not return `childProcess.pid`Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 713–715why, one step back713```714715```jsReorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef
lines 716–717why, one step back716// Execa717const {pid} = $`echo example`;Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
line 718why, one step back718```