Skip to content
Myr

Allow `stdin: uint8Array` option (#670)

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

authored by ehmicky · committed by GitHub · parent b11cbcd · Browse files · 10 files+57 added−8 removed
This commit

State

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

Diff stats

10 files+57 added−8 removed

  • tests:+29 added−0 removed
  • other:+28 added−8 removed

10 files+57 added−8 removed

modified:lib/stdio/async.js+7 added-3 removed
modified:lib/stdio/direction.js+2 added-1 removed
modified:lib/stdio/input.js+2 added-2 removed
modified:lib/stdio/sync.js+1 added
33 unmodified lines
34 output: {35 webStream: forbiddenIfSync,36 nodeStream: forbiddenIfSync,37 iterable: forbiddenIfSync,38 uint8Array: forbiddenIfSync,39 native: forbiddenIfStreamSync,40 },41};42
33 unmodified lines
modified:lib/stdio/type.js+5 added
1import {isAbsolute} from 'node:path';2import {isStream as isNodeStream} from 'is-stream';3import {isUint8Array} from './utils.js';45// The `stdin`/`stdout`/`stderr` option can be of many types. This detects it.6export const getStdioOptionType = stdioOption => {7 if (isFileUrl(stdioOption) || isFilePath(stdioOption)) {
7 unmodified lines
15 if (isNodeStream(stdioOption)) {16 return 'native';17 }1819 if (isUint8Array(stdioOption)) {20 return 'uint8Array';21 }2223 if (isIterableObject(stdioOption)) {24 return 'iterable';25 }26
33 unmodified lines
modified:lib/stdio/utils.js+4 added
added:test/stdio/typed-array.js+29 added
modified:index.d.ts+2 added
16 unmodified lines
1718type InputStdioOption =19 | Iterable<string | Uint8Array>20 | AsyncIterable<string | Uint8Array>21 | Uint8Array22 | Readable23 | ReadableStream;2425type OutputStdioOption =
96 unmodified lines
122 - a file path. If relative, it must start with `.`.123 - a file URL.124 - a web [`ReadableStream`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream).125 - an [`Iterable`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_iterable_protocol) or an [`AsyncIterable`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_async_iterator_and_async_iterable_protocols)126 - an `Uint8Array`.127128 This can be an [array of values](https://github.com/sindresorhus/execa#redirect-stdinstdoutstderr-to-multiple-destinations) such as `['inherit', 'pipe']` or `[filePath, 'pipe']`.129130 @default `inherit` with `$`, `pipe` otherwise
953 unmodified lines
modified:index.test-d.ts+2 added
177 unmodified lines
178execa('unicorns', {stdin: new ReadableStream()});179execa('unicorns', {stdin: [new ReadableStream()]});180expectError(execa('unicorns', {stdin: new WritableStream()}));181expectError(execa('unicorns', {stdin: [new WritableStream()]}));182execa('unicorns', {stdin: new Uint8Array()});183execa('unicorns', {stdin: stringGenerator()});184execa('unicorns', {stdin: [stringGenerator()]});185execa('unicorns', {stdin: binaryGenerator()});186execa('unicorns', {stdin: [binaryGenerator()]});
119 unmodified lines
306 new Writable(),307 new Readable(),308 new WritableStream(),309 new ReadableStream(),310 new Uint8Array(),311 stringGenerator(),312 asyncStringGenerator(),313 ],314});
171 unmodified lines
modified:readme.md+3 added-2 removed
570 unmodified lines
571See also the [`input`](#input) and [`stdin`](#stdin) options.572573#### stdin574575Type: `string | number | stream.Readable | ReadableStream | URL | Iterable<string | Uint8Array> | AsyncIterable<string | Uint8Array>` (or a tuple of those types)\575Type: `string | number | stream.Readable | ReadableStream | URL | Uint8Array | Iterable<string | Uint8Array> | AsyncIterable<string | Uint8Array>` (or a tuple of those types)\576Default: `inherit` with [`$`](#command), `pipe` otherwise577578[How to setup](https://nodejs.org/api/child_process.html#child_process_options_stdio) the child process' standard input. This can be:579- `'pipe'`: Sets [`childProcess.stdin`](https://nodejs.org/api/child_process.html#subprocessstdin) stream.
6 unmodified lines
586- a file path. If relative, it must start with `.`.587- a file URL.588- a web [`ReadableStream`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream).589- an [`Iterable`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_iterable_protocol) or an [`AsyncIterable`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_async_iterator_and_async_iterable_protocols)590- an `Uint8Array`.591592This can be an [array of values](#redirect-stdinstdoutstderr-to-multiple-destinations) such as `['inherit', 'pipe']` or `[filePath, 'pipe']`.593594#### stdout
35 unmodified lines
630This can be an [array of values](#redirect-stdinstdoutstderr-to-multiple-destinations) such as `['inherit', 'pipe']` or `[filePath, 'pipe']`.631632#### stdio633633Type: `string | Array<string | number | stream.Readable | stream.Writable | ReadableStream | WritableStream | URL | Iterable<string | Uint8Array> | AsyncIterable<string | Uint8Array>>` (or a tuple of those types)\634Type: `string | Array<string | number | stream.Readable | stream.Writable | ReadableStream | WritableStream | URL | Uint8Array | Iterable<string | Uint8Array> | AsyncIterable<string | Uint8Array>>` (or a tuple of those types)\635Default: `pipe`636637Like the [`stdin`](#stdin), [`stdout`](#stdout-1) and [`stderr`](#stderr-1) options but for all file descriptors at once. For example, `{stdio: ['ignore', 'pipe', 'pipe']}` is the same as `{stdin: 'ignore', stdout: 'pipe', stderr: 'pipe'}`.638
289 unmodified lines