Skip to content
Myr

Add support for `std*: TransformStream` option (#938)

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

authored by ehmicky · committed by GitHub · parent 6ca44fb · Browse files · 15 files+478 added−64 removed
This commit

State

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

Diff stats

15 files+478 added−64 removed

  • tests:+287 added−33 removed
  • other:+191 added−31 removed

15 files+478 added−64 removed

modified:docs/transform.md+19 added-2 removed
171 unmodified lines
172const {stdout} = await execa('./command.js', {stdout: {transform, final}});173console.log(stdout); // Ends with: 'Number of lines: 54'174```175176## Node.js Duplex/Transform streams176## Duplex/Transform streams177178A Node.js [`Duplex`](https://nodejs.org/api/stream.html#class-streamduplex) or [`Transform`](https://nodejs.org/api/stream.html#class-streamtransform) stream can be used instead of a generator function. A `{transform}` plain object must be passed. The [`objectMode`](#object-mode) transform option can be used, but not the [`binary`](#encoding) nor [`preserveNewlines`](#newlines) options.178A [`Duplex`](https://nodejs.org/api/stream.html#class-streamduplex) stream, Node.js [`Transform`](https://nodejs.org/api/stream.html#class-streamtransform) stream or web [`TransformStream`](https://developer.mozilla.org/en-US/docs/Web/API/TransformStream) can be used instead of a generator function.179180Like generator functions, web `TransformStream` can be passed either directly or as a `{transform}` plain object. But `Duplex` and `Transform` must always be passed as a `{transform}` plain object.181182The [`objectMode`](#object-mode) transform option can be used, but not the [`binary`](#encoding) nor [`preserveNewlines`](#newlines) options.183184```js185import {createGzip} from 'node:zlib';186import {execa} from 'execa';187188const {stdout} = await execa('./run.js', {stdout: {transform: createGzip()}});189console.log(stdout); // `stdout` is compressed with gzip190```191192```js193import {execa} from 'execa';194195const {stdout} = await execa('./run.js', {stdout: new CompressionStream('gzip')});196console.log(stdout); // `stdout` is compressed with gzip197```198199## Combining200201The [`stdin`](../readme.md#stdin), [`stdout`](../readme.md#stdout-1), [`stderr`](../readme.md#stderr-1) and [`stdio`](../readme.md#stdio-1) options can accept an array of values. While this is not specific to transforms, this can be useful with them too. For example, the following transform impacts the value printed by `inherit`.202
6 unmodified lines
209```js210await execa('echo', ['hello'], {stdout: [transform, otherTransform]});211```212213Or saving to files.214215```js216await execa('./run.js', {stdout: [new CompressionStream('gzip'), {file: './output.gz'}]});217```218219## Async iteration220221In some cases, [iterating](../readme.md#iterablereadableoptions) over the subprocess can be an alternative to transforms.222
8 unmodified lines
modified:lib/stdio/async.js+6 added-1 removed
modified:lib/stdio/direction.js+1 added
modified:lib/stdio/generator.js+21 added-4 removed
31 unmodified lines
3233 return sortTransforms(newTransforms, direction);34};3536export const TRANSFORM_TYPES = new Set(['generator', 'duplex']);36export const TRANSFORM_TYPES = new Set(['generator', 'duplex', 'webTransform']);3738const normalizeTransform = ({stdioItem, stdioItem: {type}, index, newTransforms, optionName, direction, encoding}) => type === 'duplex'39 ? normalizeDuplex({stdioItem, optionName})40 : normalizeGenerator({stdioItem, index, newTransforms, direction, encoding});38const normalizeTransform = ({stdioItem, stdioItem: {type}, index, newTransforms, optionName, direction, encoding}) => {39 if (type === 'duplex') {40 return normalizeDuplex({stdioItem, optionName});41 }4243 if (type === 'webTransform') {44 return normalizeTransformStream({stdioItem, index, newTransforms, direction});45 }4647 return normalizeGenerator({stdioItem, index, newTransforms, direction, encoding});48};4950const normalizeDuplex = ({51 stdioItem,52 stdioItem: {53 value: {
17 unmodified lines
71 value: {transform, writableObjectMode, readableObjectMode},72 };73};7475const normalizeTransformStream = ({stdioItem, stdioItem: {value}, index, newTransforms, direction}) => {76 const {transform, objectMode} = isPlainObj(value) ? value : {transform: value};77 const {writableObjectMode, readableObjectMode} = getObjectModes(objectMode, index, newTransforms, direction);78 return ({79 ...stdioItem,80 value: {transform, writableObjectMode, readableObjectMode},81 });82};8384const normalizeGenerator = ({stdioItem, stdioItem: {value}, index, newTransforms, direction, encoding}) => {85 const {86 transform,87 final,
90 unmodified lines
modified:lib/stdio/sync.js+1 added
16 unmodified lines
17const addProperties = {18 generator: forbiddenIfSync,19 webStream: forbiddenIfSync,20 nodeStream: forbiddenIfSync,21 webTransform: forbiddenIfSync,22 duplex: forbiddenIfSync,23 iterable: forbiddenIfSync,24 native() {},25};
57 unmodified lines
modified:lib/stdio/type.js+36 added-10 removed
30 unmodified lines
31 if (isIterableObject(value)) {32 return 'iterable';33 }3435 if (isTransformStream(value)) {36 return getTransformStreamType({transform: value}, optionName);37 }3839 if (isTransformOptions(value)) {40 return getTransformObjectType(value, optionName);41 }4243 return 'native';44};4542const getTransformObjectType = (value, optionName) => isDuplexStream(value.transform, {checkOpen: false})43 ? getDuplexType(value, optionName)44 : getGeneratorObjectType(value, optionName);46const getTransformObjectType = (value, optionName) => {47 if (isDuplexStream(value.transform, {checkOpen: false})) {48 return getDuplexType(value, optionName);49 }5046const getDuplexType = ({final, binary, objectMode}, optionName) => {47 checkUndefinedOption(final, `${optionName}.final`);48 checkUndefinedOption(binary, `${optionName}.binary`);49 checkBooleanOption(objectMode, `${optionName}.objectMode`);51 if (isTransformStream(value.transform)) {52 return getTransformStreamType(value, optionName);53 }5455 return getGeneratorObjectType(value, optionName);56};5758const getDuplexType = (value, optionName) => {59 validateNonGeneratorType(value, optionName, 'Duplex stream');60 return 'duplex';61};6254const checkUndefinedOption = (value, optionName) => {63const getTransformStreamType = (value, optionName) => {64 validateNonGeneratorType(value, optionName, 'web TransformStream');65 return 'webTransform';66};6768const validateNonGeneratorType = ({final, binary, objectMode}, optionName, typeName) => {69 checkUndefinedOption(final, `${optionName}.final`, typeName);70 checkUndefinedOption(binary, `${optionName}.binary`, typeName);71 checkBooleanOption(objectMode, `${optionName}.objectMode`);72};7374const checkUndefinedOption = (value, optionName, typeName) => {75 if (value !== undefined) {56 throw new TypeError(`The \`${optionName}\` option can only be defined when using a generator, not a Duplex stream.`);76 throw new TypeError(`The \`${optionName}\` option can only be defined when using a generator, not a ${typeName}.`);77 }78};7980const getGeneratorObjectType = ({transform, final, binary, objectMode}, optionName) => {81 if (transform !== undefined && !isGenerator(transform)) {62 throw new TypeError(`The \`${optionName}.transform\` option must be a generator or a Duplex stream.`);82 throw new TypeError(`The \`${optionName}.transform\` option must be a generator, a Duplex stream or a web TransformStream.`);83 }8485 if (isDuplexStream(final, {checkOpen: false})) {86 throw new TypeError(`The \`${optionName}.final\` option must not be a Duplex stream.`);87 }8889 if (isTransformStream(final)) {90 throw new TypeError(`The \`${optionName}.final\` option must not be a web TransformStream.`);91 }9293 if (final !== undefined && !isGenerator(final)) {94 throw new TypeError(`The \`${optionName}.final\` option must be a generator.`);95 }96
30 unmodified lines
127128const isReadableStream = value => Object.prototype.toString.call(value) === '[object ReadableStream]';129export const isWritableStream = value => Object.prototype.toString.call(value) === '[object WritableStream]';130const isWebStream = value => isReadableStream(value) || isWritableStream(value);131const isTransformStream = value => isReadableStream(value?.readable) && isWritableStream(value?.writable);132133const isIterableObject = value => typeof value === 'object'134 && value !== null135 && (typeof value[Symbol.asyncIterator] === 'function' || typeof value[Symbol.iterator] === 'function');
4 unmodified lines
140 fileUrl: 'a file URL',141 filePath: 'a file path string',142 webStream: 'a web stream',143 nodeStream: 'a Node.js stream',144 webTransform: 'a web TransformStream',145 duplex: 'a Duplex stream',146 native: 'any value',147 iterable: 'an iterable',148 string: 'a string',
2 unmodified lines
modified:test/helpers/map.js+29 added
25 unmodified lines
26 throwingDuplex,27 appendDuplex,28 timeoutDuplex,29} from './duplex.js';30import {31 addNoopWebTransform,32 noopWebTransform,33 serializeWebTransform,34 uppercaseBufferWebTransform,35 getOutputWebTransform,36 outputObjectWebTransform,37 getOutputsWebTransform,38 noYieldWebTransform,39 multipleYieldWebTransform,40 throwingWebTransform,41 appendWebTransform,42 timeoutWebTransform,43} from './web-transform.js';4445export const generatorsMap = {46 generator: {47 addNoop: addNoopGenerator,
24 unmodified lines
72 throwing: throwingDuplex,73 append: appendDuplex,74 timeout: timeoutDuplex,75 },76 webTransform: {77 addNoop: addNoopWebTransform,78 noop: noopWebTransform,79 serialize: serializeWebTransform,80 uppercaseBuffer: uppercaseBufferWebTransform,81 uppercase: uppercaseBufferWebTransform,82 getOutput: getOutputWebTransform,83 outputObject: outputObjectWebTransform,84 getOutputs: getOutputsWebTransform,85 noYield: noYieldWebTransform,86 multipleYield: multipleYieldWebTransform,87 throwing: throwingWebTransform,88 append: appendWebTransform,89 timeout: timeoutWebTransform,90 },91};
added:test/helpers/web-transform.js+59 added
1import {setTimeout, scheduler} from 'node:timers/promises';2import {foobarObject, foobarString} from './input.js';3import {casedSuffix, prefix, suffix} from './generator.js';45const getWebTransform = transform => objectMode => ({6 transform: new TransformStream({transform}),7 objectMode,8});910export const addNoopWebTransform = (webTransform, addNoopTransform, objectMode) => addNoopTransform11 ? [webTransform, noopWebTransform(objectMode)]12 : [webTransform];1314export const noopWebTransform = getWebTransform((value, controller) => {15 controller.enqueue(value);16});1718export const serializeWebTransform = getWebTransform((object, controller) => {19 controller.enqueue(JSON.stringify(object));20});2122export const getOutputWebTransform = (input, outerObjectMode) => getWebTransform((_, controller) => {23 controller.enqueue(input);24}, undefined, outerObjectMode);2526export const outputObjectWebTransform = () => getOutputWebTransform(foobarObject)(true);2728export const getOutputsWebTransform = inputs => getWebTransform((_, controller) => {29 for (const input of inputs) {30 controller.enqueue(input);31 }32});3334export const noYieldWebTransform = getWebTransform(() => {});3536export const multipleYieldWebTransform = getWebTransform(async (line, controller) => {37 controller.enqueue(prefix);38 await scheduler.yield();39 controller.enqueue(line);40 await scheduler.yield();41 controller.enqueue(suffix);42});4344export const uppercaseBufferWebTransform = getWebTransform((string, controller) => {45 controller.enqueue(string.toString().toUpperCase());46});4748export const throwingWebTransform = getWebTransform(() => {49 throw new Error('Generator error');50});5152export const appendWebTransform = getWebTransform((string, controller) => {53 controller.enqueue(`${string}${casedSuffix}`);54});5556export const timeoutWebTransform = timeout => getWebTransform(async (_, controller) => {57 await setTimeout(timeout);58 controller.enqueue(foobarString);59});
modified:test/stdio/generator.js+112 added-4 removed
22 unmodified lines
23 appendGenerator,24 casedSuffix,25} from '../helpers/generator.js';26import {appendDuplex, uppercaseBufferDuplex} from '../helpers/duplex.js';27import {appendWebTransform, uppercaseBufferWebTransform} from '../helpers/web-transform.js';28import {generatorsMap} from '../helpers/map.js';2930setFixtureDir();31
45 unmodified lines
77test('Can use duplexes with result.stdin, noop transform', testGeneratorInput, 0, false, true, 'duplex');78test('Can use duplexes with result.stdio[*] as input, noop transform', testGeneratorInput, 3, false, true, 'duplex');79test('Can use duplexes with result.stdin, objectMode, noop transform', testGeneratorInput, 0, true, true, 'duplex');80test('Can use duplexes with result.stdio[*] as input, objectMode, noop transform', testGeneratorInput, 3, true, true, 'duplex');81test('Can use webTransforms with result.stdin', testGeneratorInput, 0, false, false, 'webTransform');82test('Can use webTransforms with result.stdio[*] as input', testGeneratorInput, 3, false, false, 'webTransform');83test('Can use webTransforms with result.stdin, objectMode', testGeneratorInput, 0, true, false, 'webTransform');84test('Can use webTransforms with result.stdio[*] as input, objectMode', testGeneratorInput, 3, true, false, 'webTransform');85test('Can use webTransforms with result.stdin, noop transform', testGeneratorInput, 0, false, true, 'webTransform');86test('Can use webTransforms with result.stdio[*] as input, noop transform', testGeneratorInput, 3, false, true, 'webTransform');87test('Can use webTransforms with result.stdin, objectMode, noop transform', testGeneratorInput, 0, true, true, 'webTransform');88test('Can use webTransforms with result.stdio[*] as input, objectMode, noop transform', testGeneratorInput, 3, true, true, 'webTransform');8990// eslint-disable-next-line max-params91const testGeneratorInputPipe = async (t, useShortcutProperty, objectMode, addNoopTransform, type, input) => {92 const {generators, output} = getInputObjectMode(objectMode, addNoopTransform, type);
35 unmodified lines
128test('Can use duplexes with subprocess.stdio[0] and encoding "hex", noop transform', testGeneratorInputPipe, false, false, true, 'duplex', [foobarHex, 'hex']);129test('Can use duplexes with subprocess.stdin and encoding "hex", noop transform', testGeneratorInputPipe, true, false, true, 'duplex', [foobarHex, 'hex']);130test('Can use duplexes with subprocess.stdio[0], objectMode, noop transform', testGeneratorInputPipe, false, true, true, 'duplex', [foobarObject]);131test('Can use duplexes with subprocess.stdin, objectMode, noop transform', testGeneratorInputPipe, true, true, true, 'duplex', [foobarObject]);132test('Can use webTransforms with subprocess.stdio[0] and default encoding', testGeneratorInputPipe, false, false, false, 'webTransform', [foobarString, 'utf8']);133test('Can use webTransforms with subprocess.stdin and default encoding', testGeneratorInputPipe, true, false, false, 'webTransform', [foobarString, 'utf8']);134test('Can use webTransforms with subprocess.stdio[0] and encoding "buffer"', testGeneratorInputPipe, false, false, false, 'webTransform', [foobarBuffer, 'buffer']);135test('Can use webTransforms with subprocess.stdin and encoding "buffer"', testGeneratorInputPipe, true, false, false, 'webTransform', [foobarBuffer, 'buffer']);136test('Can use webTransforms with subprocess.stdio[0] and encoding "hex"', testGeneratorInputPipe, false, false, false, 'webTransform', [foobarHex, 'hex']);137test('Can use webTransforms with subprocess.stdin and encoding "hex"', testGeneratorInputPipe, true, false, false, 'webTransform', [foobarHex, 'hex']);138test('Can use webTransforms with subprocess.stdio[0], objectMode', testGeneratorInputPipe, false, true, false, 'webTransform', [foobarObject]);139test('Can use webTransforms with subprocess.stdin, objectMode', testGeneratorInputPipe, true, true, false, 'webTransform', [foobarObject]);140test('Can use webTransforms with subprocess.stdio[0] and default encoding, noop transform', testGeneratorInputPipe, false, false, true, 'webTransform', [foobarString, 'utf8']);141test('Can use webTransforms with subprocess.stdin and default encoding, noop transform', testGeneratorInputPipe, true, false, true, 'webTransform', [foobarString, 'utf8']);142test('Can use webTransforms with subprocess.stdio[0] and encoding "buffer", noop transform', testGeneratorInputPipe, false, false, true, 'webTransform', [foobarBuffer, 'buffer']);143test('Can use webTransforms with subprocess.stdin and encoding "buffer", noop transform', testGeneratorInputPipe, true, false, true, 'webTransform', [foobarBuffer, 'buffer']);144test('Can use webTransforms with subprocess.stdio[0] and encoding "hex", noop transform', testGeneratorInputPipe, false, false, true, 'webTransform', [foobarHex, 'hex']);145test('Can use webTransforms with subprocess.stdin and encoding "hex", noop transform', testGeneratorInputPipe, true, false, true, 'webTransform', [foobarHex, 'hex']);146test('Can use webTransforms with subprocess.stdio[0], objectMode, noop transform', testGeneratorInputPipe, false, true, true, 'webTransform', [foobarObject]);147test('Can use webTransforms with subprocess.stdin, objectMode, noop transform', testGeneratorInputPipe, true, true, true, 'webTransform', [foobarObject]);148149const testGeneratorStdioInputPipe = async (t, objectMode, addNoopTransform, type) => {150 const {input, generators, output} = getInputObjectMode(objectMode, addNoopTransform, type);151 const subprocess = execa('stdin-fd.js', ['3'], getStdio(3, [[], ...generators]));
9 unmodified lines
161test('Can use duplexes with subprocess.stdio[*] as input', testGeneratorStdioInputPipe, false, false, 'duplex');162test('Can use duplexes with subprocess.stdio[*] as input, objectMode', testGeneratorStdioInputPipe, true, false, 'duplex');163test('Can use duplexes with subprocess.stdio[*] as input, noop transform', testGeneratorStdioInputPipe, false, true, 'duplex');164test('Can use duplexes with subprocess.stdio[*] as input, objectMode, noop transform', testGeneratorStdioInputPipe, true, true, 'duplex');165test('Can use webTransforms with subprocess.stdio[*] as input', testGeneratorStdioInputPipe, false, false, 'webTransform');166test('Can use webTransforms with subprocess.stdio[*] as input, objectMode', testGeneratorStdioInputPipe, true, false, 'webTransform');167test('Can use webTransforms with subprocess.stdio[*] as input, noop transform', testGeneratorStdioInputPipe, false, true, 'webTransform');168test('Can use webTransforms with subprocess.stdio[*] as input, objectMode, noop transform', testGeneratorStdioInputPipe, true, true, 'webTransform');169170// eslint-disable-next-line max-params171const testGeneratorOutput = async (t, fdNumber, reject, useShortcutProperty, objectMode, addNoopTransform, type) => {172 const {generators, output} = getOutputObjectMode(objectMode, addNoopTransform, type);
82 unmodified lines
255test('Can use duplexes with error.stdout, objectMode, noop transform', testGeneratorOutput, 1, false, true, true, true, 'duplex');256test('Can use duplexes with error.stdio[2], objectMode, noop transform', testGeneratorOutput, 2, false, false, true, true, 'duplex');257test('Can use duplexes with error.stderr, objectMode, noop transform', testGeneratorOutput, 2, false, true, true, true, 'duplex');258test('Can use duplexes with error.stdio[*] as output, objectMode, noop transform', testGeneratorOutput, 3, false, false, true, true, 'duplex');259test('Can use webTransforms with result.stdio[1]', testGeneratorOutput, 1, true, false, false, false, 'webTransform');260test('Can use webTransforms with result.stdout', testGeneratorOutput, 1, true, true, false, false, 'webTransform');261test('Can use webTransforms with result.stdio[2]', testGeneratorOutput, 2, true, false, false, false, 'webTransform');262test('Can use webTransforms with result.stderr', testGeneratorOutput, 2, true, true, false, false, 'webTransform');263test('Can use webTransforms with result.stdio[*] as output', testGeneratorOutput, 3, true, false, false, false, 'webTransform');264test('Can use webTransforms with error.stdio[1]', testGeneratorOutput, 1, false, false, false, false, 'webTransform');265test('Can use webTransforms with error.stdout', testGeneratorOutput, 1, false, true, false, false, 'webTransform');266test('Can use webTransforms with error.stdio[2]', testGeneratorOutput, 2, false, false, false, false, 'webTransform');267test('Can use webTransforms with error.stderr', testGeneratorOutput, 2, false, true, false, false, 'webTransform');268test('Can use webTransforms with error.stdio[*] as output', testGeneratorOutput, 3, false, false, false, false, 'webTransform');269test('Can use webTransforms with result.stdio[1], objectMode', testGeneratorOutput, 1, true, false, true, false, 'webTransform');270test('Can use webTransforms with result.stdout, objectMode', testGeneratorOutput, 1, true, true, true, false, 'webTransform');271test('Can use webTransforms with result.stdio[2], objectMode', testGeneratorOutput, 2, true, false, true, false, 'webTransform');272test('Can use webTransforms with result.stderr, objectMode', testGeneratorOutput, 2, true, true, true, false, 'webTransform');273test('Can use webTransforms with result.stdio[*] as output, objectMode', testGeneratorOutput, 3, true, false, true, false, 'webTransform');274test('Can use webTransforms with error.stdio[1], objectMode', testGeneratorOutput, 1, false, false, true, false, 'webTransform');275test('Can use webTransforms with error.stdout, objectMode', testGeneratorOutput, 1, false, true, true, false, 'webTransform');276test('Can use webTransforms with error.stdio[2], objectMode', testGeneratorOutput, 2, false, false, true, false, 'webTransform');277test('Can use webTransforms with error.stderr, objectMode', testGeneratorOutput, 2, false, true, true, false, 'webTransform');278test('Can use webTransforms with error.stdio[*] as output, objectMode', testGeneratorOutput, 3, false, false, true, false, 'webTransform');279test('Can use webTransforms with result.stdio[1], noop transform', testGeneratorOutput, 1, true, false, false, true, 'webTransform');280test('Can use webTransforms with result.stdout, noop transform', testGeneratorOutput, 1, true, true, false, true, 'webTransform');281test('Can use webTransforms with result.stdio[2], noop transform', testGeneratorOutput, 2, true, false, false, true, 'webTransform');282test('Can use webTransforms with result.stderr, noop transform', testGeneratorOutput, 2, true, true, false, true, 'webTransform');283test('Can use webTransforms with result.stdio[*] as output, noop transform', testGeneratorOutput, 3, true, false, false, true, 'webTransform');284test('Can use webTransforms with error.stdio[1], noop transform', testGeneratorOutput, 1, false, false, false, true, 'webTransform');285test('Can use webTransforms with error.stdout, noop transform', testGeneratorOutput, 1, false, true, false, true, 'webTransform');286test('Can use webTransforms with error.stdio[2], noop transform', testGeneratorOutput, 2, false, false, false, true, 'webTransform');287test('Can use webTransforms with error.stderr, noop transform', testGeneratorOutput, 2, false, true, false, true, 'webTransform');288test('Can use webTransforms with error.stdio[*] as output, noop transform', testGeneratorOutput, 3, false, false, false, true, 'webTransform');289test('Can use webTransforms with result.stdio[1], objectMode, noop transform', testGeneratorOutput, 1, true, false, true, true, 'webTransform');290test('Can use webTransforms with result.stdout, objectMode, noop transform', testGeneratorOutput, 1, true, true, true, true, 'webTransform');291test('Can use webTransforms with result.stdio[2], objectMode, noop transform', testGeneratorOutput, 2, true, false, true, true, 'webTransform');292test('Can use webTransforms with result.stderr, objectMode, noop transform', testGeneratorOutput, 2, true, true, true, true, 'webTransform');293test('Can use webTransforms with result.stdio[*] as output, objectMode, noop transform', testGeneratorOutput, 3, true, false, true, true, 'webTransform');294test('Can use webTransforms with error.stdio[1], objectMode, noop transform', testGeneratorOutput, 1, false, false, true, true, 'webTransform');295test('Can use webTransforms with error.stdout, objectMode, noop transform', testGeneratorOutput, 1, false, true, true, true, 'webTransform');296test('Can use webTransforms with error.stdio[2], objectMode, noop transform', testGeneratorOutput, 2, false, false, true, true, 'webTransform');297test('Can use webTransforms with error.stderr, objectMode, noop transform', testGeneratorOutput, 2, false, true, true, true, 'webTransform');298test('Can use webTransforms with error.stdio[*] as output, objectMode, noop transform', testGeneratorOutput, 3, false, false, true, true, 'webTransform');299300// eslint-disable-next-line max-params301const testGeneratorOutputPipe = async (t, fdNumber, useShortcutProperty, objectMode, addNoopTransform, type) => {302 const {generators, output, getStreamMethod} = getOutputObjectMode(objectMode, addNoopTransform, type, true);
42 unmodified lines
345test('Can use duplexes with subprocess.stdout, objectMode, noop transform', testGeneratorOutputPipe, 1, true, true, true, 'duplex');346test('Can use duplexes with subprocess.stdio[2], objectMode, noop transform', testGeneratorOutputPipe, 2, false, true, true, 'duplex');347test('Can use duplexes with subprocess.stderr, objectMode, noop transform', testGeneratorOutputPipe, 2, true, true, true, 'duplex');348test('Can use duplexes with subprocess.stdio[*] as output, objectMode, noop transform', testGeneratorOutputPipe, 3, false, true, true, 'duplex');349test('Can use webTransforms with subprocess.stdio[1]', testGeneratorOutputPipe, 1, false, false, false, 'webTransform');350test('Can use webTransforms with subprocess.stdout', testGeneratorOutputPipe, 1, true, false, false, 'webTransform');351test('Can use webTransforms with subprocess.stdio[2]', testGeneratorOutputPipe, 2, false, false, false, 'webTransform');352test('Can use webTransforms with subprocess.stderr', testGeneratorOutputPipe, 2, true, false, false, 'webTransform');353test('Can use webTransforms with subprocess.stdio[*] as output', testGeneratorOutputPipe, 3, false, false, false, 'webTransform');354test('Can use webTransforms with subprocess.stdio[1], objectMode', testGeneratorOutputPipe, 1, false, true, false, 'webTransform');355test('Can use webTransforms with subprocess.stdout, objectMode', testGeneratorOutputPipe, 1, true, true, false, 'webTransform');356test('Can use webTransforms with subprocess.stdio[2], objectMode', testGeneratorOutputPipe, 2, false, true, false, 'webTransform');357test('Can use webTransforms with subprocess.stderr, objectMode', testGeneratorOutputPipe, 2, true, true, false, 'webTransform');358test('Can use webTransforms with subprocess.stdio[*] as output, objectMode', testGeneratorOutputPipe, 3, false, true, false, 'webTransform');359test('Can use webTransforms with subprocess.stdio[1], noop transform', testGeneratorOutputPipe, 1, false, false, true, 'webTransform');360test('Can use webTransforms with subprocess.stdout, noop transform', testGeneratorOutputPipe, 1, true, false, true, 'webTransform');361test('Can use webTransforms with subprocess.stdio[2], noop transform', testGeneratorOutputPipe, 2, false, false, true, 'webTransform');362test('Can use webTransforms with subprocess.stderr, noop transform', testGeneratorOutputPipe, 2, true, false, true, 'webTransform');363test('Can use webTransforms with subprocess.stdio[*] as output, noop transform', testGeneratorOutputPipe, 3, false, false, true, 'webTransform');364test('Can use webTransforms with subprocess.stdio[1], objectMode, noop transform', testGeneratorOutputPipe, 1, false, true, true, 'webTransform');365test('Can use webTransforms with subprocess.stdout, objectMode, noop transform', testGeneratorOutputPipe, 1, true, true, true, 'webTransform');366test('Can use webTransforms with subprocess.stdio[2], objectMode, noop transform', testGeneratorOutputPipe, 2, false, true, true, 'webTransform');367test('Can use webTransforms with subprocess.stderr, objectMode, noop transform', testGeneratorOutputPipe, 2, true, true, true, 'webTransform');368test('Can use webTransforms with subprocess.stdio[*] as output, objectMode, noop transform', testGeneratorOutputPipe, 3, false, true, true, 'webTransform');369370const getAllStdioOption = (stdioOption, encoding, objectMode) => {371 if (stdioOption) {372 return 'pipe';
93 unmodified lines
466};467468test('Can use generators with input option', testInputOption, 'generator');469test('Can use duplexes with input option', testInputOption, 'duplex');470test('Can use webTransforms with input option', testInputOption, 'webTransform');471472const testInputFile = async (t, getOptions, reversed) => {473 const filePath = tempfile();474 await writeFile(filePath, foobarString);
9 unmodified lines
484test('Can use generators with inputFile option', testInputFile, filePath => ({inputFile: filePath, stdin: uppercaseGenerator()}), false);485test('Can use duplexes with a file as input', testInputFile, filePath => ({stdin: [{file: filePath}, uppercaseBufferDuplex()]}), false);486test('Can use duplexes with a file as input, reversed', testInputFile, filePath => ({stdin: [{file: filePath}, uppercaseBufferDuplex()]}), true);487test('Can use duplexes with inputFile option', testInputFile, filePath => ({inputFile: filePath, stdin: uppercaseBufferDuplex()}), false);488test('Can use webTransforms with a file as input', testInputFile, filePath => ({stdin: [{file: filePath}, uppercaseBufferWebTransform()]}), false);489test('Can use webTransforms with a file as input, reversed', testInputFile, filePath => ({stdin: [{file: filePath}, uppercaseBufferWebTransform()]}), true);490test('Can use webTransforms with inputFile option', testInputFile, filePath => ({inputFile: filePath, stdin: uppercaseBufferWebTransform()}), false);491492const testOutputFile = async (t, reversed, type) => {493 const filePath = tempfile();494 const stdoutOption = [generatorsMap[type].uppercaseBuffer(false, true), {file: filePath}];
7 unmodified lines
502test('Can use generators with a file as output', testOutputFile, false, 'generator');503test('Can use generators with a file as output, reversed', testOutputFile, true, 'generator');504test('Can use duplexes with a file as output', testOutputFile, false, 'duplex');505test('Can use duplexes with a file as output, reversed', testOutputFile, true, 'duplex');506test('Can use webTransforms with a file as output', testOutputFile, false, 'webTransform');507test('Can use webTransforms with a file as output, reversed', testOutputFile, true, 'webTransform');508509const testWritableDestination = async (t, type) => {510 const passThrough = new PassThrough();511 const [{stdout}, streamOutput] = await Promise.all([
5 unmodified lines
517};518519test('Can use generators to a Writable stream', testWritableDestination, 'generator');520test('Can use duplexes to a Writable stream', testWritableDestination, 'duplex');521test('Can use webTransforms to a Writable stream', testWritableDestination, 'webTransform');522523const testReadableSource = async (t, type) => {524 const passThrough = new PassThrough();525 const subprocess = execa('stdin-fd.js', ['0'], {stdin: [passThrough, generatorsMap[type].uppercase()]});
3 unmodified lines
529};530531test('Can use generators from a Readable stream', testReadableSource, 'generator');532test('Can use duplexes from a Readable stream', testReadableSource, 'duplex');533test('Can use webTransforms from a Readable stream', testReadableSource, 'webTransform');534535const testInherit = async (t, type) => {536 const {stdout} = await execa('nested-inherit.js', [type]);537 t.is(stdout, foobarUppercase);538};539540test('Can use generators with "inherit"', testInherit, 'generator');541test('Can use duplexes with "inherit"', testInherit, 'duplex');542test('Can use webTransforms with "inherit"', testInherit, 'webTransform');543544const testAppendInput = async (t, reversed, type) => {545 const stdin = [foobarUint8Array, generatorsMap[type].uppercase(), generatorsMap[type].append()];546 const reversedStdin = reversed ? stdin.reverse() : stdin;
5 unmodified lines
552test('Can use multiple generators as input', testAppendInput, false, 'generator');553test('Can use multiple generators as input, reversed', testAppendInput, true, 'generator');554test('Can use multiple duplexes as input', testAppendInput, false, 'duplex');555test('Can use multiple duplexes as input, reversed', testAppendInput, true, 'duplex');556test('Can use multiple webTransforms as input', testAppendInput, false, 'webTransform');557test('Can use multiple webTransforms as input, reversed', testAppendInput, true, 'webTransform');558559const testAppendOutput = async (t, reversed, type) => {560 const stdoutOption = [generatorsMap[type].uppercase(), generatorsMap[type].append()];561 const reversedStdoutOption = reversed ? stdoutOption.reverse() : stdoutOption;
5 unmodified lines
567test('Can use multiple generators as output', testAppendOutput, false, 'generator');568test('Can use multiple generators as output, reversed', testAppendOutput, true, 'generator');569test('Can use multiple duplexes as output', testAppendOutput, false, 'duplex');570test('Can use multiple duplexes as output, reversed', testAppendOutput, true, 'duplex');571test('Can use multiple webTransforms as output', testAppendOutput, false, 'webTransform');572test('Can use multiple webTransforms as output, reversed', testAppendOutput, true, 'webTransform');573574const testTwoGenerators = async (t, producesTwo, firstGenerator, secondGenerator = firstGenerator) => {575 const {stdout} = await execa('noop-fd.js', ['1', foobarString], {stdout: [firstGenerator, secondGenerator]});576 const expectedSuffix = producesTwo ? `${casedSuffix}${casedSuffix}` : casedSuffix;
2 unmodified lines
579580test('Can use multiple identical generators', testTwoGenerators, true, appendGenerator().transform);581test('Can use multiple identical generators, options object', testTwoGenerators, true, appendGenerator());582test('Ignore duplicate identical duplexes', testTwoGenerators, false, appendDuplex());583test('Ignore duplicate identical webTransforms', testTwoGenerators, false, appendWebTransform());584test('Can use multiple generators with duplexes', testTwoGenerators, true, appendGenerator(false, false, true), appendDuplex());585test('Can use multiple generators with webTransforms', testTwoGenerators, true, appendGenerator(false, false, true), appendWebTransform());586test('Can use multiple duplexes with webTransforms', testTwoGenerators, true, appendDuplex(), appendWebTransform());587483const testGeneratorSyntax = async (t, generator) => {484 const {stdout} = await execa('noop-fd.js', ['1', foobarString], {stdout: generator});588const testGeneratorSyntax = async (t, type, usePlainObject) => {589 const transform = generatorsMap[type].uppercase();590 const {stdout} = await execa('noop-fd.js', ['1', foobarString], {stdout: usePlainObject ? transform : transform.transform});591 t.is(stdout, foobarUppercase);592};593488test('Can pass generators with an options plain object', testGeneratorSyntax, uppercaseGenerator());489test('Can pass generators without an options plain object', testGeneratorSyntax, uppercaseGenerator().transform);594test('Can pass generators with an options plain object', testGeneratorSyntax, 'generator', false);595test('Can pass generators without an options plain object', testGeneratorSyntax, 'generator', true);596test('Can pass webTransforms with an options plain object', testGeneratorSyntax, 'webTransform', true);597test('Can pass webTransforms without an options plain object', testGeneratorSyntax, 'webTransform', false);
modified:test/stdio/transform.js+9 added
87 unmodified lines
88test('Generator can filter "final" by not calling yield', testNoYield, 'generator', false, true, '');89test('Generator can filter "final" by not calling yield, objectMode', testNoYield, 'generator', true, true, []);90test('Duplex can filter by not calling push', testNoYield, 'duplex', false, false, '');91test('Duplex can filter by not calling push, objectMode', testNoYield, 'duplex', true, false, []);92test('WebTransform can filter by not calling push', testNoYield, 'webTransform', false, false, '');93test('WebTransform can filter by not calling push, objectMode', testNoYield, 'webTransform', true, false, []);9495const testMultipleYields = async (t, type, final, binary) => {96 const {stdout} = await execa('noop-fd.js', ['1', foobarString], {stdout: convertTransformToFinal(generatorsMap[type].multipleYield(), final)});97 const newline = binary ? '' : '\n';
2 unmodified lines
100101test('Generator can yield "transform" multiple times at different moments', testMultipleYields, 'generator', false, false);102test('Generator can yield "final" multiple times at different moments', testMultipleYields, 'generator', true, false);103test('Duplex can push multiple times at different moments', testMultipleYields, 'duplex', false, true);104test('WebTransform can push multiple times at different moments', testMultipleYields, 'webTransform', false, true);105106const partsPerChunk = 4;107const chunksPerCall = 10;108const callCount = 5;
36 unmodified lines
145};146147test('Generators take "maxBuffer" into account', testMaxBuffer, 'generator');148test('Duplexes take "maxBuffer" into account', testMaxBuffer, 'duplex');149test('WebTransforms take "maxBuffer" into account', testMaxBuffer, 'webTransform');150151const testMaxBufferObject = async (t, type) => {152 const bigArray = Array.from({length: maxBuffer}).fill('.');153 const {stdout} = await execa('noop.js', {
6 unmodified lines
160};161162test('Generators take "maxBuffer" into account, objectMode', testMaxBufferObject, 'generator');163test('Duplexes take "maxBuffer" into account, objectMode', testMaxBufferObject, 'duplex');164test('WebTransforms take "maxBuffer" into account, objectMode', testMaxBufferObject, 'webTransform');165166const testAsyncGenerators = async (t, type, final) => {167 const {stdout} = await execa('noop.js', {168 stdout: convertTransformToFinal(generatorsMap[type].timeout(1e2)(), final),
3 unmodified lines
172173test('Generators "transform" is awaited on success', testAsyncGenerators, 'generator', false);174test('Generators "final" is awaited on success', testAsyncGenerators, 'generator', true);175test('Duplex is awaited on success', testAsyncGenerators, 'duplex', false);176test('WebTransform is awaited on success', testAsyncGenerators, 'webTransform', false);177178const testThrowingGenerator = async (t, type, final) => {179 await t.throwsAsync(180 execa('noop-fd.js', ['1', foobarString], {stdout: convertTransformToFinal(generatorsMap[type].throwing(), final)}),
3 unmodified lines
184185test('Generators "transform" errors make subprocess fail', testThrowingGenerator, 'generator', false);186test('Generators "final" errors make subprocess fail', testThrowingGenerator, 'generator', true);187test('Duplexes "transform" errors make subprocess fail', testThrowingGenerator, 'duplex', false);188test('WebTransform "transform" errors make subprocess fail', testThrowingGenerator, 'webTransform', false);189190const testSingleErrorOutput = async (t, type) => {191 await t.throwsAsync(192 execa('noop-fd.js', ['1', foobarString], {stdout: [generatorsMap[type].noop(false), generatorsMap[type].throwing(), generatorsMap[type].noop(false)]}),
2 unmodified lines
195};196197test('Generators errors make subprocess fail even when other output generators do not throw', testSingleErrorOutput, 'generator');198test('Duplexes errors make subprocess fail even when other output generators do not throw', testSingleErrorOutput, 'duplex');199test('WebTransform errors make subprocess fail even when other output generators do not throw', testSingleErrorOutput, 'webTransform');200201const testSingleErrorInput = async (t, type) => {202 const subprocess = execa('stdin-fd.js', ['0'], {stdin: [generatorsMap[type].noop(false), generatorsMap[type].throwing(), generatorsMap[type].noop(false)]});203 subprocess.stdin.write('foobar\n');
1 unmodified line
205};206207test('Generators errors make subprocess fail even when other input generators do not throw', testSingleErrorInput, 'generator');208test('Duplexes errors make subprocess fail even when other input generators do not throw', testSingleErrorInput, 'duplex');209test('WebTransform errors make subprocess fail even when other input generators do not throw', testSingleErrorInput, 'webTransform');210211const testGeneratorCancel = async (t, error) => {212 const subprocess = execa('noop.js', {stdout: infiniteGenerator()});213 await once(subprocess.stdout, 'data');
21 unmodified lines
modified:test/stdio/type.js+55 added-29 removed
1 unmodified line
2import {execa, execaSync} from '../../index.js';3import {getStdio} from '../helpers/stdio.js';4import {noopGenerator, uppercaseGenerator} from '../helpers/generator.js';5import {uppercaseBufferDuplex} from '../helpers/duplex.js';6import {uppercaseBufferWebTransform} from '../helpers/web-transform.js';7import {generatorsMap} from '../helpers/map.js';8import {setFixtureDir} from '../helpers/fixtures-dir.js';910setFixtureDir();1112const testInvalidGenerator = (t, fdNumber, stdioOption) => {13 t.throws(() => {14 execa('empty.js', getStdio(fdNumber, {...noopGenerator(), ...stdioOption}));14 }, {message: /must be a generator/});15 }, {message: 'final' in stdioOption ? /must be a generator/ : /must be a generator, a Duplex stream or a web TransformStream/});16};1718test('Cannot use invalid "transform" with stdin', testInvalidGenerator, 0, {transform: true});19test('Cannot use invalid "transform" with stdout', testInvalidGenerator, 1, {transform: true});
21 unmodified lines
41test('Cannot use invalid "objectMode" with stdin, duplexes', testInvalidBinary, 0, 'objectMode', 'duplex');42test('Cannot use invalid "objectMode" with stdout, duplexes', testInvalidBinary, 1, 'objectMode', 'duplex');43test('Cannot use invalid "objectMode" with stderr, duplexes', testInvalidBinary, 2, 'objectMode', 'duplex');44test('Cannot use invalid "objectMode" with stdio[*], duplexes', testInvalidBinary, 3, 'objectMode', 'duplex');45test('Cannot use invalid "objectMode" with stdin, webTransforms', testInvalidBinary, 0, 'objectMode', 'webTransform');46test('Cannot use invalid "objectMode" with stdout, webTransforms', testInvalidBinary, 1, 'objectMode', 'webTransform');47test('Cannot use invalid "objectMode" with stderr, webTransforms', testInvalidBinary, 2, 'objectMode', 'webTransform');48test('Cannot use invalid "objectMode" with stdio[*], webTransforms', testInvalidBinary, 3, 'objectMode', 'webTransform');4950// eslint-disable-next-line max-params45const testUndefinedOption = (t, fdNumber, optionName, optionValue) => {51const testUndefinedOption = (t, fdNumber, optionName, type, optionValue) => {52 t.throws(() => {47 execa('empty.js', getStdio(fdNumber, {...uppercaseBufferDuplex(), [optionName]: optionValue}));53 execa('empty.js', getStdio(fdNumber, {...generatorsMap[type].uppercase(), [optionName]: optionValue}));54 }, {message: /can only be defined when using a generator/});55};5651test('Cannot use "binary" with duplexes and stdin', testUndefinedOption, 0, 'binary', true);52test('Cannot use "binary" with duplexes and stdout', testUndefinedOption, 1, 'binary', true);53test('Cannot use "binary" with duplexes and stderr', testUndefinedOption, 2, 'binary', true);54test('Cannot use "binary" with duplexes and stdio[*]', testUndefinedOption, 3, 'binary', true);55test('Cannot use "final" with duplexes and stdin', testUndefinedOption, 0, 'final', uppercaseBufferDuplex().transform);56test('Cannot use "final" with duplexes and stdout', testUndefinedOption, 1, 'final', uppercaseBufferDuplex().transform);57test('Cannot use "final" with duplexes and stderr', testUndefinedOption, 2, 'final', uppercaseBufferDuplex().transform);58test('Cannot use "final" with duplexes and stdio[*]', testUndefinedOption, 3, 'final', uppercaseBufferDuplex().transform);57test('Cannot use "binary" with duplexes and stdin', testUndefinedOption, 0, 'binary', 'duplex', true);58test('Cannot use "binary" with duplexes and stdout', testUndefinedOption, 1, 'binary', 'duplex', true);59test('Cannot use "binary" with duplexes and stderr', testUndefinedOption, 2, 'binary', 'duplex', true);60test('Cannot use "binary" with duplexes and stdio[*]', testUndefinedOption, 3, 'binary', 'duplex', true);61test('Cannot use "final" with duplexes and stdin', testUndefinedOption, 0, 'final', 'duplex', uppercaseBufferDuplex().transform);62test('Cannot use "final" with duplexes and stdout', testUndefinedOption, 1, 'final', 'duplex', uppercaseBufferDuplex().transform);63test('Cannot use "final" with duplexes and stderr', testUndefinedOption, 2, 'final', 'duplex', uppercaseBufferDuplex().transform);64test('Cannot use "final" with duplexes and stdio[*]', testUndefinedOption, 3, 'final', 'duplex', uppercaseBufferDuplex().transform);65test('Cannot use "binary" with webTransforms and stdin', testUndefinedOption, 0, 'binary', 'webTransform', true);66test('Cannot use "binary" with webTransforms and stdout', testUndefinedOption, 1, 'binary', 'webTransform', true);67test('Cannot use "binary" with webTransforms and stderr', testUndefinedOption, 2, 'binary', 'webTransform', true);68test('Cannot use "binary" with webTransforms and stdio[*]', testUndefinedOption, 3, 'binary', 'webTransform', true);69test('Cannot use "final" with webTransforms and stdin', testUndefinedOption, 0, 'final', 'webTransform', uppercaseBufferWebTransform().transform);70test('Cannot use "final" with webTransforms and stdout', testUndefinedOption, 1, 'final', 'webTransform', uppercaseBufferWebTransform().transform);71test('Cannot use "final" with webTransforms and stderr', testUndefinedOption, 2, 'final', 'webTransform', uppercaseBufferWebTransform().transform);72test('Cannot use "final" with webTransforms and stdio[*]', testUndefinedOption, 3, 'final', 'webTransform', uppercaseBufferWebTransform().transform);7360const testUndefinedFinal = (t, fdNumber, useTransform) => {74const testUndefinedFinal = (t, fdNumber, type, useTransform) => {75 t.throws(() => {76 execa('empty.js', getStdio(fdNumber, {77 transform: useTransform ? uppercaseGenerator().transform : undefined,64 final: uppercaseBufferDuplex().transform,78 final: generatorsMap[type].uppercase().transform,79 }));66 }, {message: /must not be a Duplex/});80 }, {message: type === 'duplex' ? /must not be a Duplex/ : /must not be a web TransformStream/});81};8269test('Cannot use "final" with duplexes and stdin, without transform', testUndefinedFinal, 0, false);70test('Cannot use "final" with duplexes and stdout, without transform', testUndefinedFinal, 1, false);71test('Cannot use "final" with duplexes and stderr, without transform', testUndefinedFinal, 2, false);72test('Cannot use "final" with duplexes and stdio[*], without transform', testUndefinedFinal, 3, false);73test('Cannot use "final" with duplexes and stdin, with transform', testUndefinedFinal, 0, true);74test('Cannot use "final" with duplexes and stdout, with transform', testUndefinedFinal, 1, true);75test('Cannot use "final" with duplexes and stderr, with transform', testUndefinedFinal, 2, true);76test('Cannot use "final" with duplexes and stdio[*], with transform', testUndefinedFinal, 3, true);83test('Cannot use "final" with duplexes and stdin, without transform', testUndefinedFinal, 0, 'duplex', false);84test('Cannot use "final" with duplexes and stdout, without transform', testUndefinedFinal, 1, 'duplex', false);85test('Cannot use "final" with duplexes and stderr, without transform', testUndefinedFinal, 2, 'duplex', false);86test('Cannot use "final" with duplexes and stdio[*], without transform', testUndefinedFinal, 3, 'duplex', false);87test('Cannot use "final" with duplexes and stdin, with transform', testUndefinedFinal, 0, 'duplex', true);88test('Cannot use "final" with duplexes and stdout, with transform', testUndefinedFinal, 1, 'duplex', true);89test('Cannot use "final" with duplexes and stderr, with transform', testUndefinedFinal, 2, 'duplex', true);90test('Cannot use "final" with duplexes and stdio[*], with transform', testUndefinedFinal, 3, 'duplex', true);91test('Cannot use "final" with webTransforms and stdin, without transform', testUndefinedFinal, 0, 'webTransform', false);92test('Cannot use "final" with webTransforms and stdout, without transform', testUndefinedFinal, 1, 'webTransform', false);93test('Cannot use "final" with webTransforms and stderr, without transform', testUndefinedFinal, 2, 'webTransform', false);94test('Cannot use "final" with webTransforms and stdio[*], without transform', testUndefinedFinal, 3, 'webTransform', false);95test('Cannot use "final" with webTransforms and stdin, with transform', testUndefinedFinal, 0, 'webTransform', true);96test('Cannot use "final" with webTransforms and stdout, with transform', testUndefinedFinal, 1, 'webTransform', true);97test('Cannot use "final" with webTransforms and stderr, with transform', testUndefinedFinal, 2, 'webTransform', true);98test('Cannot use "final" with webTransforms and stdio[*], with transform', testUndefinedFinal, 3, 'webTransform', true);99100const testSyncMethodsGenerator = (t, fdNumber) => {101 t.throws(() => {102 execaSync('empty.js', getStdio(fdNumber, uppercaseGenerator()));
4 unmodified lines
107test('Cannot use generators with sync methods and stdout', testSyncMethodsGenerator, 1);108test('Cannot use generators with sync methods and stderr', testSyncMethodsGenerator, 2);109test('Cannot use generators with sync methods and stdio[*]', testSyncMethodsGenerator, 3);11089const testSyncMethodsDuplex = (t, fdNumber) => {111const testSyncMethodsDuplex = (t, fdNumber, type) => {112 t.throws(() => {91 execaSync('empty.js', getStdio(fdNumber, uppercaseBufferDuplex()));92 }, {message: /cannot be a Duplex stream/});113 execaSync('empty.js', getStdio(fdNumber, generatorsMap[type].uppercase()));114 }, {message: type === 'duplex' ? /cannot be a Duplex stream/ : /cannot be a web TransformStream/});115};11695test('Cannot use duplexes with sync methods and stdin', testSyncMethodsDuplex, 0);96test('Cannot use duplexes with sync methods and stdout', testSyncMethodsDuplex, 1);97test('Cannot use duplexes with sync methods and stderr', testSyncMethodsDuplex, 2);98test('Cannot use duplexes with sync methods and stdio[*]', testSyncMethodsDuplex, 3);117test('Cannot use duplexes with sync methods and stdin', testSyncMethodsDuplex, 0, 'duplex');118test('Cannot use duplexes with sync methods and stdout', testSyncMethodsDuplex, 1, 'duplex');119test('Cannot use duplexes with sync methods and stderr', testSyncMethodsDuplex, 2, 'duplex');120test('Cannot use duplexes with sync methods and stdio[*]', testSyncMethodsDuplex, 3, 'duplex');121test('Cannot use webTransforms with sync methods and stdin', testSyncMethodsDuplex, 0, 'webTransform');122test('Cannot use webTransforms with sync methods and stdout', testSyncMethodsDuplex, 1, 'webTransform');123test('Cannot use webTransforms with sync methods and stderr', testSyncMethodsDuplex, 2, 'webTransform');124test('Cannot use webTransforms with sync methods and stdio[*]', testSyncMethodsDuplex, 3, 'webTransform');
added:test/stdio/web-transform.js+23 added
1import {promisify} from 'node:util';2import {gunzip} from 'node:zlib';3import test from 'ava';4import {execa} from '../../index.js';5import {setFixtureDir} from '../helpers/fixtures-dir.js';6import {foobarString, foobarUtf16Uint8Array, foobarUint8Array} from '../helpers/input.js';78setFixtureDir();910test('Can use CompressionStream()', async t => {11 const {stdout} = await execa('noop-fd.js', ['1', foobarString], {stdout: new CompressionStream('gzip'), encoding: 'buffer'});12 const decompressedStdout = await promisify(gunzip)(stdout);13 t.is(decompressedStdout.toString(), foobarString);14});1516test('Can use TextDecoderStream()', async t => {17 const {stdout} = await execa('stdin.js', {18 input: foobarUtf16Uint8Array,19 stdout: new TextDecoderStream('utf-16le'),20 encoding: 'buffer',21 });22 t.deepEqual(stdout, foobarUint8Array);23});
modified:index.d.ts+13 added-6 removed
35 unmodified lines
36 transform: Duplex;37 objectMode?: boolean;38};3940type WebTransform = {41 transform: TransformStream;42 objectMode?: boolean;43};4445type CommonStdioOption<IsSync extends boolean = boolean> =46 | BaseStdioOption47 | 'ipc'48 | number
2 unmodified lines
51 | {file: string}52 | IfAsync<IsSync,53 | GeneratorTransform54 | GeneratorTransformFull50 | DuplexTransform>;55 | DuplexTransform56 | WebTransform57 | TransformStream>;5859type InputStdioOption<IsSync extends boolean = boolean> =60 | Uint8Array61 | Readable
70 unmodified lines
132 ? OutputOptions[number]133 : OutputOptions134>;135129type IsObjectOutputOption<OutputOption extends StdioSingleOption> = OutputOption extends GeneratorTransformFull136type IsObjectOutputOption<OutputOption extends StdioSingleOption> = OutputOption extends GeneratorTransformFull | WebTransform137 ? BooleanObjectMode<OutputOption['objectMode']>138 : OutputOption extends DuplexTransform139 ? DuplexObjectMode<OutputOption>140 : false;141135type BooleanObjectMode<ObjectModeOption extends GeneratorTransformFull['objectMode']> = ObjectModeOption extends true ? true : false;142type BooleanObjectMode<ObjectModeOption extends boolean | undefined> = ObjectModeOption extends true ? true : false;143144type DuplexObjectMode<OutputOption extends DuplexTransform> = OutputOption['objectMode'] extends boolean145 ? OutputOption['objectMode']146 : OutputOption['transform']['readableObjectMode'];
216 unmodified lines
363 - an `Uint8Array`.364365 This can be an [array of values](https://github.com/sindresorhus/execa#redirect-stdinstdoutstderr-to-multiple-destinations) such as `['inherit', 'pipe']` or `[filePath, 'pipe']`.366360 This can also be a generator function or a [`Duplex`](https://nodejs.org/api/stream.html#class-streamduplex) to transform the input. [Learn more.](https://github.com/sindresorhus/execa/tree/main/docs/transform.md)367 This can also be a generator function or a [`Duplex`](https://nodejs.org/api/stream.html#class-streamduplex) or a [web `TransformStream`](https://developer.mozilla.org/en-US/docs/Web/API/TransformStream) to transform the input. [Learn more.](https://github.com/sindresorhus/execa/tree/main/docs/transform.md)368369 @default `inherit` with `$`, `pipe` otherwise370 */371 readonly stdin?: StdinOption<IsSync>;
11 unmodified lines
383 - a web [`WritableStream`](https://developer.mozilla.org/en-US/docs/Web/API/WritableStream).384385 This can be an [array of values](https://github.com/sindresorhus/execa#redirect-stdinstdoutstderr-to-multiple-destinations) such as `['inherit', 'pipe']` or `[filePath, 'pipe']`.386380 This can also be a generator function or a [`Duplex`](https://nodejs.org/api/stream.html#class-streamduplex) to transform the output. [Learn more.](https://github.com/sindresorhus/execa/tree/main/docs/transform.md)387 This can also be a generator function or a [`Duplex`](https://nodejs.org/api/stream.html#class-streamduplex) or a [web `TransformStream`](https://developer.mozilla.org/en-US/docs/Web/API/TransformStream) to transform the output. [Learn more.](https://github.com/sindresorhus/execa/tree/main/docs/transform.md)388389 @default 'pipe'390 */391 readonly stdout?: StdoutStderrOption<IsSync>;
11 unmodified lines
403 - a web [`WritableStream`](https://developer.mozilla.org/en-US/docs/Web/API/WritableStream).404405 This can be an [array of values](https://github.com/sindresorhus/execa#redirect-stdinstdoutstderr-to-multiple-destinations) such as `['inherit', 'pipe']` or `[filePath, 'pipe']`.406400 This can also be a generator function or a [`Duplex`](https://nodejs.org/api/stream.html#class-streamduplex) to transform the output. [Learn more.](https://github.com/sindresorhus/execa/tree/main/docs/transform.md)407 This can also be a generator function or a [`Duplex`](https://nodejs.org/api/stream.html#class-streamduplex) or a [web `TransformStream`](https://developer.mozilla.org/en-US/docs/Web/API/TransformStream) to transform the output. [Learn more.](https://github.com/sindresorhus/execa/tree/main/docs/transform.md)408409 @default 'pipe'410 */411 readonly stderr?: StdoutStderrOption<IsSync>;
1191 unmodified lines
modified:index.test-d.ts+86 added
27 unmodified lines
28const duplexNotObject = {transform: duplexStream as Duplex & {readableObjectMode: false}};29const duplexObjectProperty = {transform: duplexStream, objectMode: true as const};30const duplexNotObjectProperty = {transform: duplexStream, objectMode: false as const};31const duplexTransform = {transform: new Transform()};32const webTransformInstance = new TransformStream();33const webTransform = {transform: webTransformInstance};34const webTransformObject = {transform: webTransformInstance, objectMode: true as const};35const webTransformNotObject = {transform: webTransformInstance, objectMode: false as const};3637type AnySyncChunk = string | Uint8Array | undefined;38type AnyChunk = AnySyncChunk | string[] | unknown[];39expectType<Writable | null>({} as ExecaSubprocess['stdin']);
637 unmodified lines
677 const objectTransformLinesStdoutResult = await execa('unicorns', {lines: true, stdout: {transform: objectGenerator, final: objectFinal, objectMode: true}});678 expectType<unknown[]>(objectTransformLinesStdoutResult.stdout);679 expectType<[undefined, unknown[], string[]]>(objectTransformLinesStdoutResult.stdio);680681 const objectWebTransformStdoutResult = await execa('unicorns', {stdout: webTransformObject});682 expectType<unknown[]>(objectWebTransformStdoutResult.stdout);683 expectType<[undefined, unknown[], string]>(objectWebTransformStdoutResult.stdio);684685 const objectDuplexStdoutResult = await execa('unicorns', {stdout: duplexObject});686 expectType<unknown[]>(objectDuplexStdoutResult.stdout);687 expectType<[undefined, unknown[], string]>(objectDuplexStdoutResult.stdio);688
4 unmodified lines
693 const objectTransformStdoutResult = await execa('unicorns', {stdout: {transform: objectGenerator, final: objectFinal, objectMode: true}});694 expectType<unknown[]>(objectTransformStdoutResult.stdout);695 expectType<[undefined, unknown[], string]>(objectTransformStdoutResult.stdio);696697 const objectWebTransformStderrResult = await execa('unicorns', {stderr: webTransformObject});698 expectType<unknown[]>(objectWebTransformStderrResult.stderr);699 expectType<[undefined, string, unknown[]]>(objectWebTransformStderrResult.stdio);700701 const objectDuplexStderrResult = await execa('unicorns', {stderr: duplexObject});702 expectType<unknown[]>(objectDuplexStderrResult.stderr);703 expectType<[undefined, string, unknown[]]>(objectDuplexStderrResult.stdio);704
4 unmodified lines
709 const objectTransformStderrResult = await execa('unicorns', {stderr: {transform: objectGenerator, final: objectFinal, objectMode: true}});710 expectType<unknown[]>(objectTransformStderrResult.stderr);711 expectType<[undefined, string, unknown[]]>(objectTransformStderrResult.stdio);712713 const objectWebTransformStdioResult = await execa('unicorns', {stdio: ['pipe', 'pipe', webTransformObject]});714 expectType<unknown[]>(objectWebTransformStdioResult.stderr);715 expectType<[undefined, string, unknown[]]>(objectWebTransformStdioResult.stdio);716717 const objectDuplexStdioResult = await execa('unicorns', {stdio: ['pipe', 'pipe', duplexObject]});718 expectType<unknown[]>(objectDuplexStdioResult.stderr);719 expectType<[undefined, string, unknown[]]>(objectDuplexStdioResult.stdio);720
4 unmodified lines
725 const objectTransformStdioResult = await execa('unicorns', {stdio: ['pipe', 'pipe', {transform: objectGenerator, final: objectFinal, objectMode: true}]});726 expectType<unknown[]>(objectTransformStdioResult.stderr);727 expectType<[undefined, string, unknown[]]>(objectTransformStdioResult.stdio);728729 const singleObjectWebTransformStdoutResult = await execa('unicorns', {stdout: [webTransformObject]});730 expectType<unknown[]>(singleObjectWebTransformStdoutResult.stdout);731 expectType<[undefined, unknown[], string]>(singleObjectWebTransformStdoutResult.stdio);732733 const singleObjectDuplexStdoutResult = await execa('unicorns', {stdout: [duplexObject]});734 expectType<unknown[]>(singleObjectDuplexStdoutResult.stdout);735 expectType<[undefined, unknown[], string]>(singleObjectDuplexStdoutResult.stdio);736
4 unmodified lines
741 const singleObjectTransformStdoutResult = await execa('unicorns', {stdout: [{transform: objectGenerator, final: objectFinal, objectMode: true}]});742 expectType<unknown[]>(singleObjectTransformStdoutResult.stdout);743 expectType<[undefined, unknown[], string]>(singleObjectTransformStdoutResult.stdio);744745 const manyObjectWebTransformStdoutResult = await execa('unicorns', {stdout: [webTransformObject, webTransformObject]});746 expectType<unknown[]>(manyObjectWebTransformStdoutResult.stdout);747 expectType<[undefined, unknown[], string]>(manyObjectWebTransformStdoutResult.stdio);748749 const manyObjectDuplexStdoutResult = await execa('unicorns', {stdout: [duplexObject, duplexObject]});750 expectType<unknown[]>(manyObjectDuplexStdoutResult.stdout);751 expectType<[undefined, unknown[], string]>(manyObjectDuplexStdoutResult.stdio);752
4 unmodified lines
757 const manyObjectTransformStdoutResult = await execa('unicorns', {stdout: [{transform: objectGenerator, final: objectFinal, objectMode: true}, {transform: objectGenerator, final: objectFinal, objectMode: true}]});758 expectType<unknown[]>(manyObjectTransformStdoutResult.stdout);759 expectType<[undefined, unknown[], string]>(manyObjectTransformStdoutResult.stdio);760761 const falseObjectWebTransformStdoutResult = await execa('unicorns', {stdout: webTransformNotObject});762 expectType<string>(falseObjectWebTransformStdoutResult.stdout);763 expectType<[undefined, string, string]>(falseObjectWebTransformStdoutResult.stdio);764765 const falseObjectDuplexStdoutResult = await execa('unicorns', {stdout: duplexNotObject});766 expectType<string>(falseObjectDuplexStdoutResult.stdout);767 expectType<[undefined, string, string]>(falseObjectDuplexStdoutResult.stdio);768
4 unmodified lines
773 const falseObjectTransformStdoutResult = await execa('unicorns', {stdout: {transform: objectGenerator, final: objectFinal, objectMode: false}});774 expectType<string>(falseObjectTransformStdoutResult.stdout);775 expectType<[undefined, string, string]>(falseObjectTransformStdoutResult.stdio);776777 const falseObjectWebTransformStderrResult = await execa('unicorns', {stderr: webTransformNotObject});778 expectType<string>(falseObjectWebTransformStderrResult.stderr);779 expectType<[undefined, string, string]>(falseObjectWebTransformStderrResult.stdio);780781 const falseObjectDuplexStderrResult = await execa('unicorns', {stderr: duplexNotObject});782 expectType<string>(falseObjectDuplexStderrResult.stderr);783 expectType<[undefined, string, string]>(falseObjectDuplexStderrResult.stdio);784
4 unmodified lines
789 const falseObjectTransformStderrResult = await execa('unicorns', {stderr: {transform: objectGenerator, final: objectFinal, objectMode: false}});790 expectType<string>(falseObjectTransformStderrResult.stderr);791 expectType<[undefined, string, string]>(falseObjectTransformStderrResult.stdio);792793 const falseObjectWebTransformStdioResult = await execa('unicorns', {stdio: ['pipe', 'pipe', webTransformNotObject]});794 expectType<string>(falseObjectWebTransformStdioResult.stderr);795 expectType<[undefined, string, string]>(falseObjectWebTransformStdioResult.stdio);796797 const falseObjectDuplexStdioResult = await execa('unicorns', {stdio: ['pipe', 'pipe', duplexNotObject]});798 expectType<string>(falseObjectDuplexStdioResult.stderr);799 expectType<[undefined, string, string]>(falseObjectDuplexStdioResult.stdio);800
4 unmodified lines
805 const falseObjectTransformStdioResult = await execa('unicorns', {stdio: ['pipe', 'pipe', {transform: objectGenerator, final: objectFinal, objectMode: false}]});806 expectType<string>(falseObjectTransformStdioResult.stderr);807 expectType<[undefined, string, string]>(falseObjectTransformStdioResult.stdio);808809 const topObjectWebTransformStdoutResult = await execa('unicorns', {stdout: webTransformInstance});810 expectType<string>(topObjectWebTransformStdoutResult.stdout);811 expectType<[undefined, string, string]>(topObjectWebTransformStdoutResult.stdio);812813 const undefinedObjectWebTransformStdoutResult = await execa('unicorns', {stdout: webTransform});814 expectType<string>(undefinedObjectWebTransformStdoutResult.stdout);815 expectType<[undefined, string, string]>(undefinedObjectWebTransformStdoutResult.stdio);816817 const undefinedObjectDuplexStdoutResult = await execa('unicorns', {stdout: duplex});818 expectType<string | unknown[]>(undefinedObjectDuplexStdoutResult.stdout);819 expectType<[undefined, string | unknown[], string]>(undefinedObjectDuplexStdoutResult.stdio);820
501 unmodified lines
1322execa('unicorns', {stdin: [duplexTransform]});1323expectError(execaSync('unicorns', {stdin: [duplexTransform]}));1324expectError(execa('unicorns', {stdin: {...duplex, objectMode: 'true'}}));1325expectError(execaSync('unicorns', {stdin: {...duplex, objectMode: 'true'}}));1326execa('unicorns', {stdin: webTransformInstance});1327expectError(execaSync('unicorns', {stdin: webTransformInstance}));1328execa('unicorns', {stdin: [webTransformInstance]});1329expectError(execaSync('unicorns', {stdin: [webTransformInstance]}));1330execa('unicorns', {stdin: webTransform});1331expectError(execaSync('unicorns', {stdin: webTransform}));1332execa('unicorns', {stdin: [webTransform]});1333expectError(execaSync('unicorns', {stdin: [webTransform]}));1334expectError(execa('unicorns', {stdin: {...webTransform, objectMode: 'true'}}));1335expectError(execaSync('unicorns', {stdin: {...webTransform, objectMode: 'true'}}));1336execa('unicorns', {stdin: unknownGenerator});1337expectError(execaSync('unicorns', {stdin: unknownGenerator}));1338execa('unicorns', {stdin: [unknownGenerator]});1339expectError(execaSync('unicorns', {stdin: [unknownGenerator]}));
105 unmodified lines
1445execa('unicorns', {stdout: [duplexTransform]});1446expectError(execaSync('unicorns', {stdout: [duplexTransform]}));1447expectError(execa('unicorns', {stdout: {...duplex, objectMode: 'true'}}));1448expectError(execaSync('unicorns', {stdout: {...duplex, objectMode: 'true'}}));1449execa('unicorns', {stdout: webTransformInstance});1450expectError(execaSync('unicorns', {stdout: webTransformInstance}));1451execa('unicorns', {stdout: [webTransformInstance]});1452expectError(execaSync('unicorns', {stdout: [webTransformInstance]}));1453execa('unicorns', {stdout: webTransform});1454expectError(execaSync('unicorns', {stdout: webTransform}));1455execa('unicorns', {stdout: [webTransform]});1456expectError(execaSync('unicorns', {stdout: [webTransform]}));1457expectError(execa('unicorns', {stdout: {...webTransform, objectMode: 'true'}}));1458expectError(execaSync('unicorns', {stdout: {...webTransform, objectMode: 'true'}}));1459execa('unicorns', {stdout: unknownGenerator});1460expectError(execaSync('unicorns', {stdout: unknownGenerator}));1461execa('unicorns', {stdout: [unknownGenerator]});1462expectError(execaSync('unicorns', {stdout: [unknownGenerator]}));
105 unmodified lines
1568execa('unicorns', {stderr: [duplexTransform]});1569expectError(execaSync('unicorns', {stderr: [duplexTransform]}));1570expectError(execa('unicorns', {stderr: {...duplex, objectMode: 'true'}}));1571expectError(execaSync('unicorns', {stderr: {...duplex, objectMode: 'true'}}));1572execa('unicorns', {stderr: webTransformInstance});1573expectError(execaSync('unicorns', {stderr: webTransformInstance}));1574execa('unicorns', {stderr: [webTransformInstance]});1575expectError(execaSync('unicorns', {stderr: [webTransformInstance]}));1576execa('unicorns', {stderr: webTransform});1577expectError(execaSync('unicorns', {stderr: webTransform}));1578execa('unicorns', {stderr: [webTransform]});1579expectError(execaSync('unicorns', {stderr: [webTransform]}));1580expectError(execa('unicorns', {stderr: {...webTransform, objectMode: 'true'}}));1581expectError(execaSync('unicorns', {stderr: {...webTransform, objectMode: 'true'}}));1582execa('unicorns', {stderr: unknownGenerator});1583expectError(execaSync('unicorns', {stderr: unknownGenerator}));1584execa('unicorns', {stderr: [unknownGenerator]});1585expectError(execaSync('unicorns', {stderr: [unknownGenerator]}));
83 unmodified lines
1669expectError(execa('unicorns', {stdio: duplex}));1670expectError(execaSync('unicorns', {stdio: duplex}));1671expectError(execa('unicorns', {stdio: duplexTransform}));1672expectError(execaSync('unicorns', {stdio: duplexTransform}));1673expectError(execa('unicorns', {stdio: webTransformInstance}));1674expectError(execaSync('unicorns', {stdio: webTransformInstance}));1675expectError(execa('unicorns', {stdio: webTransform}));1676expectError(execaSync('unicorns', {stdio: webTransform}));1677expectError(execa('unicorns', {stdio: new Writable()}));1678expectError(execaSync('unicorns', {stdio: new Writable()}));1679expectError(execa('unicorns', {stdio: new Readable()}));1680expectError(execaSync('unicorns', {stdio: new Readable()}));
49 unmodified lines
1730 fileUrl,1731 {file: './test'},1732 duplex,1733 duplexTransform,1734 webTransformInstance,1735 webTransform,1736 new Writable(),1737 new Readable(),1738 new WritableStream(),1739 new ReadableStream(),
22 unmodified lines
1762expectError(execaSync('unicorns', {stdio: [unknownGenerator]}));1763expectError(execaSync('unicorns', {stdio: [{transform: unknownGenerator}]}));1764expectError(execaSync('unicorns', {stdio: [duplex]}));1765expectError(execaSync('unicorns', {stdio: [duplexTransform]}));1766expectError(execaSync('unicorns', {stdio: [webTransformInstance]}));1767expectError(execaSync('unicorns', {stdio: [webTransform]}));1768expectError(execaSync('unicorns', {stdio: [new WritableStream()]}));1769expectError(execaSync('unicorns', {stdio: [new ReadableStream()]}));1770expectError(execaSync('unicorns', {stdio: [emptyStringGenerator()]}));1771expectError(execaSync('unicorns', {stdio: [asyncStringGenerator()]}));
17 unmodified lines
1789 [fileUrl],1790 [{file: './test'}],1791 [duplex],1792 [duplexTransform],1793 [webTransformInstance],1794 [webTransform],1795 [new Writable()],1796 [new Readable()],1797 [new WritableStream()],1798 [new ReadableStream()],
26 unmodified lines
1825expectError(execaSync('unicorns', {stdio: [[unknownGenerator]]}));1826expectError(execaSync('unicorns', {stdio: [[{transform: unknownGenerator}]]}));1827expectError(execaSync('unicorns', {stdio: [[duplex]]}));1828expectError(execaSync('unicorns', {stdio: [[duplexTransform]]}));1829expectError(execaSync('unicorns', {stdio: [[webTransformInstance]]}));1830expectError(execaSync('unicorns', {stdio: [[webTransform]]}));1831expectError(execaSync('unicorns', {stdio: [[new WritableStream()]]}));1832expectError(execaSync('unicorns', {stdio: [[new ReadableStream()]]}));1833expectError(execaSync('unicorns', {stdio: [[['foo', 'bar']]]}));1834expectError(execaSync('unicorns', {stdio: [[[new Uint8Array(), new Uint8Array()]]]}));
438 unmodified lines
modified:readme.md+8 added-8 removed
317 unmodified lines
318Same as [`execa()`](#execafile-arguments-options) but synchronous.319320Returns or throws a [`subprocessResult`](#subprocessResult). The [`subprocess`](#subprocess) is not returned: its methods and properties are not available. This includes [`.kill()`](https://nodejs.org/api/child_process.html#subprocesskillsignal), [`.pid`](https://nodejs.org/api/child_process.html#subprocesspid), [`.pipe()`](#pipefile-arguments-options), [`.iterable()`](#iterablereadableoptions), [`.readable()`](#readablereadableoptions), [`.writable()`](#writablewritableoptions), [`.duplex()`](#duplexduplexoptions) and the [`.stdin`/`.stdout`/`.stderr`](https://nodejs.org/api/child_process.html#subprocessstdout) streams.321322Cannot use the following options: [`all`](#all-2), [`cleanup`](#cleanup), [`buffer`](#buffer), [`detached`](#detached), [`ipc`](#ipc), [`serialization`](#serialization), [`cancelSignal`](#cancelsignal), [`forceKillAfterDelay`](#forcekillafterdelay), [`lines`](#lines) and [`verbose: 'full'`](#verbose). Also, the [`stdin`](#stdin), [`stdout`](#stdout-1), [`stderr`](#stderr-1), [`stdio`](#stdio-1) and [`input`](#input) options cannot be an array, [`overlapped`](https://nodejs.org/api/child_process.html#optionsstdio), an iterable, a [transform](docs/transform.md), a [`Duplex`](docs/transform.md#nodejs-duplextransform-streams), or a web stream. Node.js streams [must have a file descriptor](#redirect-a-nodejs-stream-fromto-stdinstdoutstderr) unless the `input` option is used.322Cannot use the following options: [`all`](#all-2), [`cleanup`](#cleanup), [`buffer`](#buffer), [`detached`](#detached), [`ipc`](#ipc), [`serialization`](#serialization), [`cancelSignal`](#cancelsignal), [`forceKillAfterDelay`](#forcekillafterdelay), [`lines`](#lines) and [`verbose: 'full'`](#verbose). Also, the [`stdin`](#stdin), [`stdout`](#stdout-1), [`stderr`](#stderr-1), [`stdio`](#stdio-1) and [`input`](#input) options cannot be an array, [`overlapped`](https://nodejs.org/api/child_process.html#optionsstdio), an iterable, a [transform](docs/transform.md), a [`Duplex`](docs/transform.md#duplextransform-streams), or a web stream. Node.js streams [must have a file descriptor](#redirect-a-nodejs-stream-fromto-stdinstdoutstderr) unless the `input` option is used.323324#### $(file, arguments?, options?)325326`file`: `string | URL`\
542 unmodified lines
869See also the [`input`](#input) and [`stdin`](#stdin) options.870871#### stdin872873Type: `string | number | stream.Readable | ReadableStream | URL | {file: string} | Uint8Array | Iterable<string | Uint8Array | unknown> | AsyncIterable<string | Uint8Array | unknown> | GeneratorFunction<string | Uint8Array | unknown> | AsyncGeneratorFunction<string | Uint8Array | unknown> | {transform: GeneratorFunction | AsyncGeneratorFunction | Duplex}` (or a tuple of those types)\873Type: `string | number | stream.Readable | ReadableStream | TransformStream | URL | {file: string} | Uint8Array | Iterable<string | Uint8Array | unknown> | AsyncIterable<string | Uint8Array | unknown> | GeneratorFunction<string | Uint8Array | unknown> | AsyncGeneratorFunction<string | Uint8Array | unknown> | {transform: GeneratorFunction | AsyncGeneratorFunction | Duplex | TransformStream}` (or a tuple of those types)\874Default: `inherit` with [`$`](#file-arguments-options), `pipe` otherwise875876[How to setup](https://nodejs.org/api/child_process.html#child_process_options_stdio) the subprocess' standard input. This can be:877- `'pipe'`: Sets [`subprocess.stdin`](https://nodejs.org/api/child_process.html#subprocessstdin) stream.
9 unmodified lines
887- an `Uint8Array`.888889This can be an [array of values](#redirect-stdinstdoutstderr-to-multiple-destinations) such as `['inherit', 'pipe']` or `[filePath, 'pipe']`.890891This can also be a generator function or a [`Duplex`](docs/transform.md#nodejs-duplextransform-streams) to transform the input. [Learn more.](docs/transform.md)891This can also be a generator function, a [`Duplex`](docs/transform.md#duplextransform-streams) or a web [`TransformStream`](docs/transform.md#duplextransform-streams) to transform the input. [Learn more.](docs/transform.md)892893#### stdout894895Type: `string | number | stream.Writable | WritableStream | URL | {file: string} | GeneratorFunction<string | Uint8Array | unknown> | AsyncGeneratorFunction<string | Uint8Array | unknown> | {transform: GeneratorFunction | AsyncGeneratorFunction | Duplex}` (or a tuple of those types)\895Type: `string | number | stream.Writable | WritableStream | TransformStream | URL | {file: string} | GeneratorFunction<string | Uint8Array | unknown> | AsyncGeneratorFunction<string | Uint8Array | unknown> | {transform: GeneratorFunction | AsyncGeneratorFunction | Duplex | TransformStream}` (or a tuple of those types)\896Default: `pipe`897898[How to setup](https://nodejs.org/api/child_process.html#child_process_options_stdio) the subprocess' standard output. This can be:899- `'pipe'`: Sets [`subprocessResult.stdout`](#stdout) (as a string or `Uint8Array`) and [`subprocess.stdout`](https://nodejs.org/api/child_process.html#subprocessstdout) (as a stream).
7 unmodified lines
907- a web [`WritableStream`](https://developer.mozilla.org/en-US/docs/Web/API/WritableStream).908909This can be an [array of values](#redirect-stdinstdoutstderr-to-multiple-destinations) such as `['inherit', 'pipe']` or `[filePath, 'pipe']`.910911This can also be a generator function or a [`Duplex`](docs/transform.md#nodejs-duplextransform-streams) to transform the output. [Learn more.](docs/transform.md)911This can also be a generator function, a [`Duplex`](docs/transform.md#duplextransform-streams) or a web [`TransformStream`](docs/transform.md#duplextransform-streams) to transform the output. [Learn more.](docs/transform.md)912913#### stderr914915Type: `string | number | stream.Writable | WritableStream | URL | {file: string} | GeneratorFunction<string | Uint8Array | unknown> | AsyncGeneratorFunction<string | Uint8Array | unknown> | {transform: GeneratorFunction | AsyncGeneratorFunction | Duplex}` (or a tuple of those types)\915Type: `string | number | stream.Writable | WritableStream | TransformStream | URL | {file: string} | GeneratorFunction<string | Uint8Array | unknown> | AsyncGeneratorFunction<string | Uint8Array | unknown> | {transform: GeneratorFunction | AsyncGeneratorFunction | Duplex | TransformStream}` (or a tuple of those types)\916Default: `pipe`917918[How to setup](https://nodejs.org/api/child_process.html#child_process_options_stdio) the subprocess' standard error. This can be:919- `'pipe'`: Sets [`subprocessResult.stderr`](#stderr) (as a string or `Uint8Array`) and [`subprocess.stderr`](https://nodejs.org/api/child_process.html#subprocessstderr) (as a stream).
7 unmodified lines
927- a web [`WritableStream`](https://developer.mozilla.org/en-US/docs/Web/API/WritableStream).928929This can be an [array of values](#redirect-stdinstdoutstderr-to-multiple-destinations) such as `['inherit', 'pipe']` or `[filePath, 'pipe']`.930931This can also be a generator function or a [`Duplex`](docs/transform.md#nodejs-duplextransform-streams) to transform the output. [Learn more.](docs/transform.md)931This can also be a generator function, a [`Duplex`](docs/transform.md#duplextransform-streams) or a web [`TransformStream`](docs/transform.md#duplextransform-streams) to transform the output. [Learn more.](docs/transform.md)932933#### stdio934935Type: `string | Array<string | number | stream.Readable | stream.Writable | ReadableStream | WritableStream | URL | {file: string} | Uint8Array | Iterable<string> | Iterable<Uint8Array> | Iterable<unknown> | AsyncIterable<string | Uint8Array | unknown> | GeneratorFunction<string | Uint8Array | unknown> | AsyncGeneratorFunction<string | Uint8Array | unknown> | {transform: GeneratorFunction | AsyncGeneratorFunction | Duplex}>` (or a tuple of those types)\935Type: `string | Array<string | number | stream.Readable | stream.Writable | ReadableStream | WritableStream | TransformStream | URL | {file: string} | Uint8Array | Iterable<string> | Iterable<Uint8Array> | Iterable<unknown> | AsyncIterable<string | Uint8Array | unknown> | GeneratorFunction<string | Uint8Array | unknown> | AsyncGeneratorFunction<string | Uint8Array | unknown> | {transform: GeneratorFunction | AsyncGeneratorFunction | Duplex | TransformStream}>` (or a tuple of those types)\936Default: `pipe`937938Like 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'}`.939
286 unmodified lines