Document how to pass a Node.js stream to stdin/stdout/stderr (#644)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by ehmicky · committed by GitHub · parent 7efd50c · Browse files · 2 files·+23 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
2 files+23 added−6 removed
- other:+23 added−6 removed
Provenance
- Commit
2500696- Tree
a66a243- Author
ehmicky <ehmicky@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent
7efd50c
2 files changed+23 added−6 removed
modified:index.d.ts+3 added-3 removed
115 unmodified lines116 - `'ignore'`: Do not use `stdin`.117 - `'ipc'`: Sets an [IPC channel](https://nodejs.org/api/child_process.html#subprocesssendmessage-sendhandle-options-callback). You can also use `execaNode()` instead.118 - `'inherit'`: Re-use the current process' `stdin`.119 - an integer: Re-use a specific file descriptor from the current process.120- - a Node.js `Readable` stream. It must have an underlying file or socket, such as the streams created by the `fs`, `net` or `http` core modules.120+ - a Node.js `Readable` stream.121 122 Unless either the synchronous methods, the `input` option or the `inputFile` option is used, the value can also be a:123 - file path. If relative, it must start with `.`.124 - file URL.13 unmodified lines138 - `'ignore'`: Do not use `stdout`.139 - `'ipc'`: Sets an [IPC channel](https://nodejs.org/api/child_process.html#subprocesssendmessage-sendhandle-options-callback). You can also use `execaNode()` instead.140 - `'inherit'`: Re-use the current process' `stdout`.141 - an integer: Re-use a specific file descriptor from the current process.142- - a Node.js `Writable` stream. It must have an underlying file or socket, such as the streams created by the `fs`, `net` or `http` core modules.142+ - a Node.js `Writable` stream.143 144 Unless either synchronous methods, the value can also be a:145 - file path. If relative, it must start with `.`.146 - file URL.12 unmodified lines159 - `'ignore'`: Do not use `stderr`.160 - `'ipc'`: Sets an [IPC channel](https://nodejs.org/api/child_process.html#subprocesssendmessage-sendhandle-options-callback). You can also use `execaNode()` instead.161 - `'inherit'`: Re-use the current process' `stderr`.162 - an integer: Re-use a specific file descriptor from the current process.163- - a Node.js `Writable` stream. It must have an underlying file or socket, such as the streams created by the `fs`, `net` or `http` core modules.163+ - a Node.js `Writable` stream.164 165 Unless either synchronous methods, the value can also be a:166 - file path. If relative, it must start with `.`.167 - file URL.915 unmodified linesmodified:readme.md+20 added-3 removed
577 unmodified lines578 - `'ignore'`: Do not use `stdin`.579 - `'ipc'`: Sets an [IPC channel](https://nodejs.org/api/child_process.html#subprocesssendmessage-sendhandle-options-callback). You can also use [`execaNode()`](#execanodescriptpath-arguments-options) instead.580 - `'inherit'`: Re-use the current process' `stdin`.581 - an integer: Re-use a specific file descriptor from the current process.582-- a Node.js `Readable` stream. It must have an underlying file or socket, such as the streams created by the `fs`, `net` or `http` core modules.582+- a [Node.js `Readable` stream](#redirect-a-nodejs-stream-fromto-stdinstdoutstderr).583 584 Unless either the [synchronous methods](#execasyncfile-arguments-options), the [`input` option](#input) or the [`inputFile` option](#inputfile) is used, the value can also be a:585 - file path. If relative, it must start with `.`.586 - file URL.13 unmodified lines600 - `'ignore'`: Do not use `stdout`.601 - `'ipc'`: Sets an [IPC channel](https://nodejs.org/api/child_process.html#subprocesssendmessage-sendhandle-options-callback). You can also use [`execaNode()`](#execanodescriptpath-arguments-options) instead.602 - `'inherit'`: Re-use the current process' `stdout`.603 - an integer: Re-use a specific file descriptor from the current process.604-- a Node.js `Writable` stream. It must have an underlying file or socket, such as the streams created by the `fs`, `net` or `http` core modules.604+- a [Node.js `Writable` stream](#redirect-a-nodejs-stream-fromto-stdinstdoutstderr).605 606 Unless either [synchronous methods](#execasyncfile-arguments-options), the value can also be a:607 - file path. If relative, it must start with `.`.608 - file URL.12 unmodified lines621 - `'ignore'`: Do not use `stderr`.622 - `'ipc'`: Sets an [IPC channel](https://nodejs.org/api/child_process.html#subprocesssendmessage-sendhandle-options-callback). You can also use [`execaNode()`](#execanodescriptpath-arguments-options) instead.623 - `'inherit'`: Re-use the current process' `stderr`.624 - an integer: Re-use a specific file descriptor from the current process.625-- a Node.js `Writable` stream. It must have an underlying file or socket, such as the streams created by the `fs`, `net` or `http` core modules.625+- a [Node.js `Writable` stream](#redirect-a-nodejs-stream-fromto-stdinstdoutstderr).626 627 Unless either [synchronous methods](#execasyncfile-arguments-options), the value can also be a:628 - file path. If relative, it must start with `.`.629 - file URL.191 unmodified lines821 ```822 823 When combining `inherit` with other values, please note that the child process will not be an interactive TTY, even if the parent process is one.824 825+### Redirect a Node.js stream from/to stdin/stdout/stderr826+827+When passing a Node.js stream to the [`stdin`](#stdin), [`stdout`](#stdout-1) or [`stderr`](#stderr-1) option, Node.js requires that stream to have an underlying file or socket, such as the streams created by the `fs`, `net` or `http` core modules. Otherwise the following error is thrown.828+829+```830+TypeError [ERR_INVALID_ARG_VALUE]: The argument 'stdio' is invalid.831+```832+833+This limitation can be worked around by passing either:834+ - a web stream ([`ReadableStream`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream) or [`WritableStream`](https://developer.mozilla.org/en-US/docs/Web/API/WritableStream))835+ - `[nodeStream, 'pipe']` instead of `nodeStream`836+837+```diff838+- await execa(..., { stdout: nodeStream })839++ await execa(..., { stdout: [nodeStream, 'pipe'] })840+```841+842 ### Retry on error843 844 Gracefully handle failures by using automatic retries and exponential backoff with the [`p-retry`](https://github.com/sindresorhus/p-retry) package:845 84 unmodified lines