Skip to content
Myr

Document workaround for proper `all` interleaving (#640)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by ehmicky · committed by GitHub · parent f4955ad · Browse files · 1 file+39 added−6 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+39 added−6 removed

  • other:+39 added−6 removed

1 file+39 added−6 removed

modified:readme.md+39 added-6 removed
331 unmodified lines
332#### all333334Type: `ReadableStream | undefined`335336Stream combining/interleaving [`stdout`](https://nodejs.org/api/child_process.html#child_process_subprocess_stdout) and [`stderr`](https://nodejs.org/api/child_process.html#child_process_subprocess_stderr).336Stream [combining/interleaving](#ensuring-all-output-is-interleaved) [`stdout`](https://nodejs.org/api/child_process.html#child_process_subprocess_stdout) and [`stderr`](https://nodejs.org/api/child_process.html#child_process_subprocess_stderr).337338This is `undefined` if either:339- the [`all` option](#all-2) is `false` (the default value)340- the [synchronous methods](#execasyncfile-arguments-options) are used
77 unmodified lines
418#### all419420Type: `string | Uint8Array | undefined`421422The output of the process with `stdout` and `stderr` interleaved.422The output of the process with `stdout` and `stderr` [interleaved](#ensuring-all-output-is-interleaved).423424This is `undefined` if either:425- the [`all` option](#all-2) is `false` (the default value)426- the [synchronous methods](#execasyncfile-arguments-options) are used
212 unmodified lines
639640Type: `boolean`\641Default: `false`642643Add an `.all` property on the [promise](#all) and the [resolved value](#all-1). The property contains the output of the process with `stdout` and `stderr` interleaved.643Add an `.all` property on the [promise](#all) and the [resolved value](#all-1). The property contains the output of the process with `stdout` and `stderr` [interleaved](#ensuring-all-output-is-interleaved).644645#### reject646647Type: `boolean`\
191 unmodified lines
839```840841### Execute the current package's binary842843Execa can be combined with [`get-bin-path`](https://github.com/ehmicky/get-bin-path) to test the current package's binary. As opposed to hard-coding the path to the binary, this validates that the `package.json` `bin` field is correctly set up.844845```js846import {getBinPath} from 'get-bin-path';847848const binPath = await getBinPath();849await execa(binPath);850```851850`execa` can be combined with [`get-bin-path`](https://github.com/ehmicky/get-bin-path) to test the current package's binary. As opposed to hard-coding the path to the binary, this validates that the `package.json` `bin` field is correctly set up.852### Ensuring `all` output is interleaved853854The `all` [stream](#all) and [string/`Uint8Array`](#all-1) properties are guaranteed to interleave [`stdout`](#stdout) and [`stderr`](#stderr).855856However, for performance reasons, the child process might buffer and merge multiple simultaneous writes to `stdout` or `stderr`. This prevents proper interleaving.857858For example, this prints `1 3 2` instead of `1 2 3` because both `console.log()` are merged into a single write.859860```js861import {execa} from 'execa';862863const {all} = await execa('node', ['example.js'], {all: true});864console.log(all);865```866867```js868// example.js869console.log('1'); // writes to stdout870console.error('2'); // writes to stderr871console.log('3'); // writes to stdout872```873874This can be worked around by using `setTimeout()`.875876```js877import {setTimeout} from 'timers/promises';878879console.log('1');880console.error('2');881await setTimeout(0);882console.log('3');883```884885## Related886854- [gulp-execa](https://github.com/ehmicky/gulp-execa) - Gulp plugin for `execa`855- [nvexeca](https://github.com/ehmicky/nvexeca) - Run `execa` using any Node.js version887- [gulp-execa](https://github.com/ehmicky/gulp-execa) - Gulp plugin for Execa888- [nvexeca](https://github.com/ehmicky/nvexeca) - Run Execa using any Node.js version889- [sudo-prompt](https://github.com/jorangreef/sudo-prompt) - Run commands with elevated privileges.890891## Maintainers892
2 unmodified lines