Skip to content
Myr

scripts.md

This file

Path

docs/scripts.md

717 lines · 11.4 KiB · Markdown

Last changed by

Print output with `verbose` option (#884)ehmickybefore adoption6fda30f

History of this file

Take it

The walk stopped after 200 commits: lines older than a8d04c4 point at it.

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 1–8why, one step back
1# Node.js scripts
23With 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 back
9 .pipe`grep name`;

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 10–48why, one step back
10console.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.48

Rename `signal` option to `cancelSignal` (#880)ehmickybefore adoption231beaf

line 49why, one step back
49Execa 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.

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 50–123why, one step back
50
51### 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```123

Allow newlines in `$` (#843)ehmickybefore adoption1315486

lines 124–147why, one step back
124### Multiline commands
125126```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```147

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 148why, one step back
148### Concatenation

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 149–151why, one step back
149
150```sh151# Bash

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

lines 152–153why, one step back
152tmpDir="/tmp"
153mkdir "$tmpDir/filename"

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 154–157why, one step back
154```
155156```js157// zx

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

lines 158–159why, one step back
158const tmpDir = '/tmp'
159await $`mkdir ${tmpDir}/filename`;

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 160–163why, one step back
160```
161162```js163// Execa

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

lines 164–165why, one step back
164const tmpDir = '/tmp'
165await $`mkdir ${tmpDir}/filename`;

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 166–167why, one step back
166```
167

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 168why, one step back
168### Variable substitution

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 169–171why, one step back
169
170```sh171# Bash

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 172why, one step back
172echo $LANG

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 173–176why, one step back
173```
174175```js176// zx

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 177why, one step back
177await $`echo $LANG`;

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 178–181why, one step back
178```
179180```js181// Execa

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 182why, one step back
182await $`echo ${process.env.LANG}`;

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 183–184why, one step back
183```
184

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 185why, one step back
185### Escaping

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 186–188why, one step back
186
187```sh188# Bash

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 189why, one step back
189echo 'one two'

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 190–193why, one step back
190```
191192```js193// zx

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 194why, one step back
194await $`echo ${'one two'}`;

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 195–198why, one step back
195```
196197```js198// Execa

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 199why, one step back
199await $`echo ${'one two'}`;

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 200–201why, one step back
200```
201

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 202why, one step back
202### Escaping multiple arguments

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 203–205why, one step back
203
204```sh205# Bash

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 206why, one step back
206echo 'one two' '$'

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 207–210why, one step back
207```
208209```js210// zx

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 211why, one step back
211await $`echo ${['one two', '$']}`;

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 212–215why, one step back
212```
213214```js215// Execa

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 216why, one step back
216await $`echo ${['one two', '$']}`;

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 217–218why, one step back
217```
218

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 219why, one step back
219### Subcommands

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 220–222why, one step back
220
221```sh222# Bash

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 223why, one step back
223echo "$(echo example)"

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 224–227why, one step back
224```
225226```js227// zx

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

lines 228–229why, one step back
228const example = await $`echo example`;
229await $`echo ${example}`;

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 230–233why, one step back
230```
231232```js233// Execa

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

lines 234–235why, one step back
234const example = await $`echo example`;
235await $`echo ${example}`;

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 236–237why, one step back
236```
237

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 238why, one step back
238### Serial commands

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

line 239why, one step back
239

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

lines 240–244why, one step back
240```sh
241# Bash242echo one && echo two243```244

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 245–246why, one step back
245```js
246// zx

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 247why, one step back
247await $`echo one && echo two`;

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 248–251why, one step back
248```
249250```js251// Execa

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

lines 252–254why, one step back
252await $`echo one`;
253await $`echo two`;254```

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

line 255why, one step back
255

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

lines 256–261why, one step back
256### Parallel commands
257258```sh259# Bash260echo one &261echo two &

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 262–263why, one step back
262```
263

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

lines 264–267why, one step back
264```js
265// zx266await Promise.all([$`echo one`, $`echo two`]);267```

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

line 268why, one step back
268

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

lines 269–275why, one step back
269```js
270// Execa271await Promise.all([$`echo one`, $`echo two`]);272```273274### Global/shared options275

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 276–277why, one step back
276```sh
277# Bash

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

lines 278–281why, one step back
278options="timeout 5"
279$options echo one280$options echo two281$options echo three

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 282–285why, one step back
282```
283284```js285// zx

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

lines 286–289why, one step back
286const timeout = '5s';
287await $`echo one`.timeout(timeout);288await $`echo two`.timeout(timeout);289await $`echo three`.timeout(timeout);

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 290–293why, one step back
290```
291292```js293// Execa

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

lines 294–300why, one step back
294import {$ as $_} from 'execa';
295296const $ = $_({timeout: 5000});297298await $`echo one`;299await $`echo two`;300await $`echo three`;

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 301–321why, one step back
301```
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```321

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 322why, one step back
322### Local binaries

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 323–325why, one step back
323
324```sh325# Bash

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 326why, one step back
326npx tsc --version

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 327–330why, one step back
327```
328329```js330// zx

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 331why, one step back
331await $`npx tsc --version`;

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 332–335why, one step back
332```
333334```js335// Execa

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 336why, one step back
336await $`tsc --version`;

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 337–338why, one step back
337```
338

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 339why, one step back
339### Builtin utilities

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

line 340why, one step back
340

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

lines 341–354why, one step back
341```js
342// zx343const content = await stdin();344```345346```js347// Execa348import getStdin from 'get-stdin';349350const content = await getStdin();351```352353### Printing to stdout354

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 355–356why, one step back
355```sh
356# Bash

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 357why, one step back
357echo example

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 358–361why, one step back
358```
359360```js361// zx

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 362why, one step back
362echo`example`;

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 363–366why, one step back
363```
364365```js366// Execa

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 367why, one step back
367console.log('example');

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 368–369why, one step back
368```
369

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 370why, one step back
370### Silent stderr

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 371–373why, one step back
371
372```sh373# Bash

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 374why, one step back
374echo example 2> /dev/null

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 375–378why, one step back
375```
376377```js378// zx

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 379why, one step back
379await $`echo example`.stdio('inherit', 'pipe', 'ignore');

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 380–382why, one step back
380```
381382```js

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

lines 383–384why, one step back
383// Execa does not print stdout/stderr by default
384await $`echo example`;

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 385–404why, one step back
385```
386387### Verbose mode388389```sh390# Bash391set -v392echo example393```394395```js396// zx >=8397await $`echo example`.verbose();398399// or:400$.verbose = true;401```402403```js404// Execa

Improve documentation of global script options (#870)ehmickybefore adoption146fa07

lines 405–406why, one step back
405import {$ as $_} from 'execa';
406

Print output with `verbose` option (#884)ehmickybefore adoption6fda30f

lines 407–408why, one step back
407// `verbose: 'short'` is also available
408const $ = $_({verbose: 'full'});

Improve documentation of global script options (#870)ehmickybefore adoption146fa07

lines 409–410why, one step back
409
410await $`echo example`;

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 411–418why, one step back
411```
412413Or:414415```416NODE_DEBUG=execa node file.js417```418

Improve `verbose` option (#883)ehmickybefore adoption7d0943f

lines 419–421why, one step back
419Which prints:
420421```

Print output with `verbose` option (#884)ehmickybefore adoption6fda30f

lines 422–423why, one step back
422[19:49:00.360] [0] $ echo example
423example

Improve `verbose` option (#883)ehmickybefore adoption7d0943f

lines 424–425why, one step back
424```
425

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 426why, one step back
426### Piping stdout to another command

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 427–429why, one step back
427
428```sh429# Bash

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 430why, one step back
430echo npm run build | sort | head -n2

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 431–434why, one step back
431```
432433```js434// zx

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 435why, one step back
435await $`npm run build | sort | head -n2`;

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 436–439why, one step back
436```
437438```js439// Execa

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

lines 440–442why, one step back
440await $`npm run build`
441 .pipe`sort`442 .pipe`head -n2`;

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 443–444why, one step back
443```
444

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 445why, one step back
445### Piping stdout and stderr to another command

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 446–448why, one step back
446
447```sh448# Bash

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 449why, one step back
449echo example |& cat

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 450–453why, one step back
450```
451452```js453// zx

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

lines 454–458why, one step back
454const echo = $`echo example`;
455const cat = $`cat`;456echo.pipe(cat)457echo.stderr.pipe(cat.stdin);458await Promise.all([echo, cat]);

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 459–462why, one step back
459```
460461```js462// Execa

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

lines 463–464why, one step back
463await $({all: true})`echo example`
464 .pipe({from: 'all'})`cat`;

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 465–466why, one step back
465```
466

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 467why, one step back
467### Piping stdout to a file

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 468–470why, one step back
468
469```sh470# Bash

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 471why, one step back
471echo example > file.txt

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 472–475why, one step back
472```
473474```js475// zx

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 476why, one step back
476await $`echo example`.pipe(fs.createWriteStream('file.txt'));

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 477–480why, one step back
477```
478479```js480// Execa

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 481why, one step back
481await $({stdout: {file: 'file.txt'}})`echo example`;

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 482–483why, one step back
482```
483

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 484why, one step back
484### Piping stdin from a file

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 485–487why, one step back
485
486```sh487# Bash

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 488why, one step back
488echo example < file.txt

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 489–492why, one step back
489```
490491```js492// zx

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

lines 493–495why, one step back
493const cat = $`cat`
494fs.createReadStream('file.txt').pipe(cat.stdin)495await cat

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 496–499why, one step back
496```
497498```js499// Execa

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 500why, one step back
500await $({inputFile: 'file.txt'})`cat`

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 501–555why, one step back
501```
502503### Errors504505```sh506# Bash communicates errors only through the exit code and stderr507timeout 1 sleep 2508echo $?509```510511```js512// zx513const {514 stdout,515 stderr,516 exitCode,517 signal,518} = await $`sleep 2`.timeout('1s');519// file:///home/me/Desktop/node_modules/zx/build/core.js:146520// let output = new ProcessOutput(code, signal, stdout, stderr, combined, message);521// ^522// ProcessOutput [Error]:523// at file:///home/me/Desktop/example.js:2:20524// exit code: null525// signal: SIGTERM526// at ChildProcess.<anonymous> (file:///home/me/Desktop/node_modules/zx/build/core.js:146:26)527// at ChildProcess.emit (node:events:512:28)528// at maybeClose (node:internal/child_process:1098:16)529// at Socket.<anonymous> (node:internal/child_process:456:11)530// at Socket.emit (node:events:512:28)531// at Pipe.<anonymous> (node:net:316:12)532// at Pipe.callbackTrampoline (node:internal/async_hooks:130:17) {533// _code: null,534// _signal: 'SIGTERM',535// _stdout: '',536// _stderr: '',537// _combined: ''538// }539```540541```js542// Execa543const {544 stdout,545 stderr,546 exitCode,547 signal,548 signalDescription,549 originalMessage,550 shortMessage,551 command,552 escapedCommand,553 failed,554 timedOut,555 isCanceled,

Fix `error.killed` and rename to `error.isTerminated` (#625)ehmickybefore adoption248349c

line 556why, one step back
556 isTerminated,

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 557–576why, one step back
557 // and other error-related properties: code, etc.
558} = await $({timeout: 1})`sleep 2`;559// file:///home/me/code/execa/lib/kill.js:60560// reject(Object.assign(new Error('Timed out'), {timedOut: true, signal}));561// ^562// Error: Command timed out after 1 milliseconds: sleep 2563// Timed out564// at file:///home/me/Desktop/example.js:2:20565// timedOut: true,566// signal: 'SIGTERM',567// originalMessage: 'Timed out',568// shortMessage: 'Command timed out after 1 milliseconds: sleep 2\nTimed out',569// command: 'sleep 2',570// escapedCommand: 'sleep 2',571// exitCode: undefined,572// signalDescription: 'Termination',573// stdout: '',574// stderr: '',575// failed: true,576// isCanceled: false,

Fix `error.killed` and rename to `error.isTerminated` (#625)ehmickybefore adoption248349c

line 577why, one step back
577// isTerminated: false

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 578–580why, one step back
578// }
579```580

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 581why, one step back
581### Exit codes

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 582–584why, one step back
582
583```sh584# Bash

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

lines 585–586why, one step back
585false
586echo $?

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 587–590why, one step back
587```
588589```js590// zx

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

lines 591–592why, one step back
591const {exitCode} = await $`false`.nothrow();
592echo`${exitCode}`;

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 593–596why, one step back
593```
594595```js596// Execa

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

lines 597–598why, one step back
597const {exitCode} = await $({reject: false})`false`;
598console.log(exitCode);

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 599–600why, one step back
599```
600

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 601why, one step back
601### Timeouts

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 602–604why, one step back
602
603```sh604# Bash

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 605why, one step back
605timeout 5 echo example

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 606–608why, one step back
606```
607608```js

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

lines 609–610why, one step back
609// zx
610await $`echo example`.timeout('5s');

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 611–614why, one step back
611```
612613```js614// Execa

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 615why, one step back
615await $({timeout: 5000})`echo example`;

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 616–617why, one step back
616```
617

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 618why, one step back
618### Current filename

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 619–621why, one step back
619
620```sh621# Bash

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 622why, one step back
622echo "$(basename "$0")"

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 623–626why, one step back
623```
624625```js626// zx

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 627why, one step back
627await $`echo ${__filename}`;

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 628–631why, one step back
628```
629630```js631// Execa

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

lines 632–633why, one step back
632import {fileURLToPath} from 'node:url';
633import path from 'node:path';

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

line 634why, one step back
634

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 635why, one step back
635const __filename = path.basename(fileURLToPath(import.meta.url));

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

line 636why, one step back
636

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 637why, one step back
637await $`echo ${__filename}`;

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 638–639why, one step back
638```
639

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 640why, one step back
640### Current directory

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 641–643why, one step back
641
642```sh643# Bash

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 644why, one step back
644cd project

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 645–648why, one step back
645```
646647```js648// zx

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

lines 649–652why, one step back
649cd('project');
650651// or:652$.cwd = 'project';

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 653–656why, one step back
653```
654655```js656// Execa

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 657why, one step back
657const $$ = $({cwd: 'project'});

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 658–659why, one step back
658```
659

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 660why, one step back
660### Multiple current directories

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 661–663why, one step back
661
662```sh663# Bash

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

lines 664–667why, one step back
664pushd project
665pwd666popd667pwd

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 668–671why, one step back
668```
669670```js671// zx

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

lines 672–677why, one step back
672within(async () => {
673 cd('project');674 await $`pwd`;675});676677await $`pwd`;

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 678–681why, one step back
678```
679680```js681// Execa

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

lines 682–683why, one step back
682await $({cwd: 'project'})`pwd`;
683await $`pwd`;

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 684–685why, one step back
684```
685

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 686why, one step back
686### Background processes

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 687–689why, one step back
687
688```sh689# Bash

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 690why, one step back
690echo one &

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 691–693why, one step back
691```
692693```js

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 694why, one step back
694// zx does not allow setting the `detached` option

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 695–698why, one step back
695```
696697```js698// Execa

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 699why, one step back
699await $({detached: true})`echo one`;

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 700–701why, one step back
700```
701

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 702why, one step back
702### PID

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 703–705why, one step back
703
704```sh705# Bash

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

lines 706–707why, one step back
706echo example &
707echo $!

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 708–710why, one step back
708```
709710```js

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 711why, one step back
711// zx does not return `childProcess.pid`

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

lines 712–714why, one step back
712```
713714```js

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

lines 715–716why, one step back
715// Execa
716const {pid} = $`echo example`;

Upgrade some dependencies (#582)ehmickybefore adoptiona8d04c4

line 717why, one step back
717```