Add support for `std*: duplex` option (#937)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by ehmicky · committed by GitHub · parent 1c12be9 · Browse files · 22 files·+789 added−221 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
22 files+789 added−221 removed
- tests:+548 added−186 removed
- other:+241 added−35 removed
Provenance
- Commit
6ca44fb- Tree
37d208b- Author
ehmicky <ehmicky@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent
1c12be9
22 files changed+789 added−221 removed
modified:docs/transform.md+12 added
171 unmodified lines172 const {stdout} = await execa('./command.js', {stdout: {transform, final}});173 console.log(stdout); // Ends with: 'Number of lines: 54'174 ```175 176+## Node.js Duplex/Transform streams177+178+A 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.179+180+```js181+import {createGzip} from 'node:zlib';182+import {execa} from 'execa';183+184+const {stdout} = await execa('./run.js', {stdout: {transform: createGzip()}});185+console.log(stdout); // `stdout` is compressed with gzip186+```187+188 ## Combining189 190 The [`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`.191 22 unmodified linesmodified:lib/stdio/async.js+4 added-3 removed
4 unmodified lines567899101112133 unmodified lines17181920212223242523 unmodified lines49505152525354555656575859606146 unmodified lines4 unmodified linesimport {isStandardStream, incrementMaxListeners} from '../utils.js';import {handleInput} from './handle.js';import {pipeStreams} from './pipeline.js';import {TYPE_TO_MESSAGE} from './type.js';import {generatorToDuplexStream, pipeTransform} from './generator.js';import {generatorToDuplexStream, pipeTransform, TRANSFORM_TYPES} from './generator.js';
// Handle `input`, `inputFile`, `stdin`, `stdout` and `stderr` options, before spawning, in async modeexport const handleInputAsync = (options, verboseInfo) => handleInput(addPropertiesAsync, options, verboseInfo, false);
3 unmodified lines
const addProperties = { generator: generatorToDuplexStream, nodeStream: ({value}) => ({stream: value}), duplex: ({value: {transform}}) => ({stream: transform}), native() {},};
const addPropertiesAsync = {23 unmodified lines stdioState.subprocess = subprocess; const inputStreamsGroups = {};
for (const {stdioItems, direction, fdNumber} of fileDescriptors) { for (const {stream} of stdioItems.filter(({type}) => type === 'generator')) { for (const {stream} of stdioItems.filter(({type}) => TRANSFORM_TYPES.has(type))) { pipeTransform(subprocess, stream, direction, fdNumber); }
for (const {stream} of stdioItems.filter(({type}) => type !== 'generator')) { for (const {stream} of stdioItems.filter(({type}) => !TRANSFORM_TYPES.has(type))) { pipeStdioItem({subprocess, stream, direction, fdNumber, inputStreamsGroups, controller}); } }
46 unmodified linesmodified:lib/stdio/direction.js+1 added
46 unmodified lines47484950515253545523 unmodified lines46 unmodified lines }
return isNodeWritableStream(value, {checkOpen: false}) ? undefined : 'input'; }, duplex: anyDirection, native(value) { const standardStreamDirection = getStandardStreamDirection(value); if (standardStreamDirection !== undefined) { return standardStreamDirection;23 unmodified linesmodified:lib/stdio/generator.js+40 added-9 removed
5 unmodified lines6 import {pipeStreams} from './pipeline.js';7 import {isAsyncGenerator} from './type.js';8 import {getValidateTransformReturn} from './validate.js';9 10-export const getObjectMode = (stdioItems, direction, options) => {11- const transforms = getTransforms(stdioItems, direction, options);10+export const getObjectMode = (stdioItems, optionName, direction, options) => {11+ const transforms = getTransforms(stdioItems, optionName, direction, options);12 if (transforms.length === 0) {13 return false;14 }15 16 const {value: {readableObjectMode, writableObjectMode}} = transforms.at(-1);17 return direction === 'input' ? writableObjectMode : readableObjectMode;18 };19 20-export const normalizeTransforms = (stdioItems, direction, options) => [21- ...stdioItems.filter(({type}) => type !== 'generator'),22- ...getTransforms(stdioItems, direction, options),20+export const normalizeTransforms = (stdioItems, optionName, direction, options) => [21+ ...stdioItems.filter(({type}) => !TRANSFORM_TYPES.has(type)),22+ ...getTransforms(stdioItems, optionName, direction, options),23 ];24 25-const getTransforms = (stdioItems, direction, {encoding}) => {26- const transforms = stdioItems.filter(({type}) => type === 'generator');25+const getTransforms = (stdioItems, optionName, direction, {encoding}) => {26+ const transforms = stdioItems.filter(({type}) => TRANSFORM_TYPES.has(type));27 const newTransforms = Array.from({length: transforms.length});28 29 for (const [index, stdioItem] of Object.entries(transforms)) {30- newTransforms[index] = normalizeTransform({stdioItem, index: Number(index), newTransforms, direction, encoding});30+ newTransforms[index] = normalizeTransform({stdioItem, index: Number(index), newTransforms, optionName, direction, encoding});31 }32 33 return sortTransforms(newTransforms, direction);34 };35 36+export const TRANSFORM_TYPES = new Set(['generator', 'duplex']);37+38+const normalizeTransform = ({stdioItem, stdioItem: {type}, index, newTransforms, optionName, direction, encoding}) => type === 'duplex'39+ ? normalizeDuplex({stdioItem, optionName})40+ : normalizeGenerator({stdioItem, index, newTransforms, direction, encoding});41+42+const normalizeDuplex = ({43+ stdioItem,44+ stdioItem: {45+ value: {46+ transform,47+ transform: {writableObjectMode, readableObjectMode},48+ objectMode = readableObjectMode,49+ },50+ },51+ optionName,52+}) => {53+ if (objectMode && !readableObjectMode) {54+ throw new TypeError(`The \`${optionName}.objectMode\` option can only be \`true\` if \`new Duplex({objectMode: true})\` is used.`);55+ }56+57+ if (!objectMode && readableObjectMode) {58+ throw new TypeError(`The \`${optionName}.objectMode\` option cannot be \`false\` if \`new Duplex({objectMode: true})\` is used.`);59+ }60+61+ return {62+ ...stdioItem,63+ value: {transform, writableObjectMode, readableObjectMode},64+ };65+};66+36-const normalizeTransform = ({stdioItem, stdioItem: {value}, index, newTransforms, direction, encoding}) => {67+const normalizeGenerator = ({stdioItem, stdioItem: {value}, index, newTransforms, direction, encoding}) => {68 const {69 transform,70 final,71 binary: binaryOption = false,89 unmodified linesmodified:lib/stdio/handle.js+2 added-2 removed
95 unmodified lines96 };97 98 const normalizeStdioItems = ({stdioItems, fdNumber, optionName, addProperties, options, isSync, direction, stdioState, verboseInfo, outputLines}) => {99 const allStdioItems = addInternalStdioItems({stdioItems, fdNumber, optionName, options, isSync, direction, stdioState, verboseInfo, outputLines});100- const normalizedStdioItems = normalizeTransforms(allStdioItems, direction, options);100+ const normalizedStdioItems = normalizeTransforms(allStdioItems, optionName, direction, options);101 return normalizedStdioItems.map(stdioItem => addStreamProperties(stdioItem, addProperties, direction));102 };103 104 const addInternalStdioItems = ({stdioItems, fdNumber, optionName, options, isSync, direction, stdioState, verboseInfo, outputLines}) => {105 if (!willPipeFileDescriptor(stdioItems)) {106 return stdioItems;107 }108 109- const objectMode = getObjectMode(stdioItems, direction, options);109+ const objectMode = getObjectMode(stdioItems, optionName, direction, options);110 return [111 ...stdioItems,112 ...handleStreamsEncoding({options, isSync, direction, optionName, objectMode}),113 ...handleStreamsVerbose({stdioItems, options, isSync, stdioState, verboseInfo, fdNumber, optionName}),11 unmodified linesmodified:lib/stdio/sync.js+1 added
16 unmodified lines17 const addProperties = {18 generator: forbiddenIfSync,19 webStream: forbiddenIfSync,20 nodeStream: forbiddenIfSync,21+ duplex: forbiddenIfSync,22 iterable: forbiddenIfSync,23 native() {},24 };25 56 unmodified linesmodified:lib/stdio/type.js+26 added-3 removed
1-import {isStream as isNodeStream} from 'is-stream';1+import {isStream as isNodeStream, isDuplexStream} from 'is-stream';2 import isPlainObj from 'is-plain-obj';3 import {isUint8Array} from '../utils.js';4 5 // The `stdin`/`stdout`/`stderr` option can be of many types. This detects it.32 unmodified lines38 39 return 'native';40 };41 42+const getTransformObjectType = (value, optionName) => isDuplexStream(value.transform, {checkOpen: false})43+ ? getDuplexType(value, optionName)44+ : getGeneratorObjectType(value, optionName);45+46+const getDuplexType = ({final, binary, objectMode}, optionName) => {47+ checkUndefinedOption(final, `${optionName}.final`);48+ checkUndefinedOption(binary, `${optionName}.binary`);49+ checkBooleanOption(objectMode, `${optionName}.objectMode`);50+51+ return 'duplex';52+};53+54+const checkUndefinedOption = (value, optionName) => {55+ if (value !== undefined) {56+ throw new TypeError(`The \`${optionName}\` option can only be defined when using a generator, not a Duplex stream.`);57+ }58+};59+42-const getTransformObjectType = ({transform, final, binary, objectMode}, optionName) => {60+const getGeneratorObjectType = ({transform, final, binary, objectMode}, optionName) => {61 if (transform !== undefined && !isGenerator(transform)) {44- throw new TypeError(`The \`${optionName}.transform\` option must be a generator.`);62+ throw new TypeError(`The \`${optionName}.transform\` option must be a generator or a Duplex stream.`);63 }64 65+ if (isDuplexStream(final, {checkOpen: false})) {66+ throw new TypeError(`The \`${optionName}.final\` option must not be a Duplex stream.`);67+ }68+69 if (final !== undefined && !isGenerator(final)) {70 throw new TypeError(`The \`${optionName}.final\` option must be a generator.`);71 }72 42 unmodified lines115 fileUrl: 'a file URL',116 filePath: 'a file path string',117 webStream: 'a web stream',118 nodeStream: 'a Node.js stream',119+ duplex: 'a Duplex stream',120 native: 'any value',121 iterable: 'an iterable',122 string: 'a string',123 uint8Array: 'a Uint8Array',1 unmodified linemodified:lib/stream/resolve.js+2 added-1 removed
2 unmodified lines3 import {waitForSuccessfulExit} from '../exit/code.js';4 import {errorSignal} from '../exit/kill.js';5 import {throwOnTimeout} from '../exit/timeout.js';6 import {isStandardStream} from '../utils.js';7+import {TRANSFORM_TYPES} from '../stdio/generator.js';8 import {waitForAllStream} from './all.js';9 import {waitForSubprocessStream, getBufferedData} from './subprocess.js';10 import {waitForExit} from './exit.js';11 import {waitForStream} from './wait.js';57 unmodified lines69 // This makes sure we wait for the completion of those streams, in order to catch any error.70 const waitForCustomStreamsEnd = (fileDescriptors, streamInfo) => fileDescriptors.flatMap(({stdioItems, fdNumber}) => stdioItems71 .filter(({value, stream = value}) => isNodeStream(stream, {checkOpen: false}) && !isStandardStream(stream))72 .map(({type, value, stream = value}) => waitForStream(stream, fdNumber, streamInfo, {72- isSameDirection: type === 'generator',73+ isSameDirection: TRANSFORM_TYPES.has(type),74 stopOnExit: type === 'native',75 })));76 77 const throwOnSubprocessError = async (subprocess, {signal}) => {8 unmodified linesmodified:lib/verbose/output.js+2 added-1 removed
1 import {inspect} from 'node:util';2 import {escapeLines} from '../arguments/escape.js';3 import {BINARY_ENCODINGS} from '../arguments/encoding.js';4 import {PIPED_STDIO_VALUES} from '../stdio/forward.js';5+import {TRANSFORM_TYPES} from '../stdio/generator.js';6 import {verboseLog} from './log.js';7 8 export const handleStreamsVerbose = ({stdioItems, options, isSync, stdioState, verboseInfo, fdNumber, optionName}) => shouldLogOutput({stdioItems, options, isSync, verboseInfo, fdNumber})9 ? [{12 unmodified lines22 && !isSync23 && !BINARY_ENCODINGS.has(encoding)24 && fdUsesVerbose(fdNumber)25 && (stdioItems.some(({type, value}) => type === 'native' && PIPED_STDIO_VALUES.has(value))25- || stdioItems.every(({type}) => type === 'generator'));26+ || stdioItems.every(({type}) => TRANSFORM_TYPES.has(type)));27 28 // Printing input streams would be confusing.29 // Files and streams can produce big outputs, which we don't want to print.30 // We could print `stdio[3+]` but it often is redirected to files and streams, with the same issue.30 unmodified linesmodified:test/fixtures/nested-inherit.js+4 added-2 removed
1 #!/usr/bin/env node2+import process from 'node:process';3 import {execa} from '../../index.js';3-import {uppercaseGenerator} from '../helpers/generator.js';4+import {generatorsMap} from '../helpers/map.js';5 6+const type = process.argv[2];5-await execa('noop-fd.js', ['1'], {stdout: ['inherit', uppercaseGenerator()]});7+await execa('noop-fd.js', ['1'], {stdout: ['inherit', generatorsMap[type].uppercase()]});modified:test/fixtures/nested-transform.js+4 added-3 removed
1 #!/usr/bin/env node2 import process from 'node:process';3 import {execa} from '../../index.js';4-import {uppercaseGenerator} from '../helpers/generator.js';4+import {generatorsMap} from '../helpers/map.js';5 6-const [options, file, ...args] = process.argv.slice(2);7-await execa(file, args, {stdout: uppercaseGenerator(), ...JSON.parse(options)});6+const [optionsString, file, ...args] = process.argv.slice(2);7+const {type, ...options} = JSON.parse(optionsString);8+await execa(file, args, {stdout: generatorsMap[type].uppercase(), ...options});added:test/helpers/duplex.js+59 added
1+import {Transform} from 'node:stream';2+import {setTimeout, scheduler} from 'node:timers/promises';3+import {callbackify} from 'node:util';4+import {foobarObject, foobarString} from './input.js';5+import {casedSuffix, prefix, suffix} from './generator.js';6+7+const getDuplex = (transform, encoding, outerObjectMode) => objectMode => ({8+ transform: new Transform({9+ transform: callbackify(async function (value) {10+ return transform.call(this, value);11+ }),12+ objectMode,13+ encoding,14+ }),15+ objectMode: outerObjectMode,16+});17+18+export const addNoopDuplex = (duplex, addNoopTransform, objectMode) => addNoopTransform19+ ? [duplex, noopDuplex(objectMode)]20+ : [duplex];21+22+export const noopDuplex = getDuplex(value => value);23+24+export const serializeDuplex = getDuplex(object => JSON.stringify(object));25+26+export const getOutputDuplex = (input, outerObjectMode) => getDuplex(() => input, undefined, outerObjectMode);27+28+export const outputObjectDuplex = () => getOutputDuplex(foobarObject)(true);29+30+export const getOutputsDuplex = inputs => getDuplex(function () {31+ for (const input of inputs) {32+ this.push(input);33+ }34+});35+36+export const noYieldDuplex = getDuplex(() => {});37+38+export const multipleYieldDuplex = getDuplex(async function (line) {39+ this.push(prefix);40+ await scheduler.yield();41+ this.push(line);42+ await scheduler.yield();43+ this.push(suffix);44+});45+46+export const uppercaseEncodingDuplex = (encoding, outerObjectMode) => getDuplex(buffer => buffer.toString().toUpperCase(), encoding, outerObjectMode);47+48+export const uppercaseBufferDuplex = uppercaseEncodingDuplex();49+50+export const throwingDuplex = getDuplex(() => {51+ throw new Error('Generator error');52+});53+54+export const appendDuplex = getDuplex(string => `${string}${casedSuffix}`);55+56+export const timeoutDuplex = timeout => getDuplex(async () => {57+ await setTimeout(timeout);58+ return foobarString;59+});modified:test/helpers/input.js+1 added
13 unmodified lines14 export const foobarUtf16Uint8Array = bufferToUint8Array(foobarUtf16Buffer);15 export const foobarDataView = new DataView(foobarArrayBuffer);16 export const foobarHex = foobarBuffer.toString('hex');17 export const foobarUppercase = foobarString.toUpperCase();18+export const foobarUppercaseHex = Buffer.from(foobarUppercase).toString('hex');19 export const foobarObject = {foo: 'bar'};20 export const foobarObjectString = JSON.stringify(foobarObject);added:test/helpers/map.js+62 added
1+import {2+ addNoopGenerator,3+ noopGenerator,4+ serializeGenerator,5+ uppercaseBufferGenerator,6+ uppercaseGenerator,7+ getOutputGenerator,8+ outputObjectGenerator,9+ getOutputsGenerator,10+ noYieldGenerator,11+ multipleYieldGenerator,12+ throwingGenerator,13+ appendGenerator,14+ timeoutGenerator,15+} from './generator.js';16+import {17+ addNoopDuplex,18+ noopDuplex,19+ serializeDuplex,20+ uppercaseBufferDuplex,21+ getOutputDuplex,22+ outputObjectDuplex,23+ getOutputsDuplex,24+ noYieldDuplex,25+ multipleYieldDuplex,26+ throwingDuplex,27+ appendDuplex,28+ timeoutDuplex,29+} from './duplex.js';30+31+export const generatorsMap = {32+ generator: {33+ addNoop: addNoopGenerator,34+ noop: noopGenerator,35+ serialize: serializeGenerator,36+ uppercaseBuffer: uppercaseBufferGenerator,37+ uppercase: uppercaseGenerator,38+ getOutput: getOutputGenerator,39+ outputObject: outputObjectGenerator,40+ getOutputs: getOutputsGenerator,41+ noYield: noYieldGenerator,42+ multipleYield: multipleYieldGenerator,43+ throwing: throwingGenerator,44+ append: appendGenerator,45+ timeout: timeoutGenerator,46+ },47+ duplex: {48+ addNoop: addNoopDuplex,49+ noop: noopDuplex,50+ serialize: serializeDuplex,51+ uppercaseBuffer: uppercaseBufferDuplex,52+ uppercase: uppercaseBufferDuplex,53+ getOutput: getOutputDuplex,54+ outputObject: outputObjectDuplex,55+ getOutputs: getOutputsDuplex,56+ noYield: noYieldDuplex,57+ multipleYield: multipleYieldDuplex,58+ throwing: throwingDuplex,59+ append: appendDuplex,60+ timeout: timeoutDuplex,61+ },62+};added:test/stdio/duplex.js+57 added
1+import {createHash} from 'node:crypto';2+import {promisify} from 'node:util';3+import {createGzip, gunzip} from 'node:zlib';4+import test from 'ava';5+import {execa} from '../../index.js';6+import {setFixtureDir} from '../helpers/fixtures-dir.js';7+import {foobarString, foobarObject, foobarUppercase, foobarUppercaseHex} from '../helpers/input.js';8+import {uppercaseEncodingDuplex, getOutputDuplex} from '../helpers/duplex.js';9+10+setFixtureDir();11+12+test('Can use crypto.createHash()', async t => {13+ const {stdout} = await execa('noop-fd.js', ['1', foobarString], {stdout: {transform: createHash('sha1')}, encoding: 'hex'});14+ const expectedStdout = createHash('sha1').update(foobarString).digest('hex');15+ t.is(stdout, expectedStdout);16+});17+18+test('Can use zlib.createGzip()', async t => {19+ const {stdout} = await execa('noop-fd.js', ['1', foobarString], {stdout: {transform: createGzip()}, encoding: 'buffer'});20+ const decompressedStdout = await promisify(gunzip)(stdout);21+ t.is(decompressedStdout.toString(), foobarString);22+});23+24+test('Can use encoding "hex"', async t => {25+ const {transform} = uppercaseEncodingDuplex('hex')();26+ t.is(transform.readableEncoding, 'hex');27+ const {stdout} = await execa('noop-fd.js', ['1', foobarString], {stdout: {transform}});28+ t.is(stdout, foobarUppercaseHex);29+});30+31+test('Cannot use objectMode: true with duplex.readableObjectMode: false', t => {32+ t.throws(() => {33+ execa('noop-fd.js', ['1', foobarString], {stdout: uppercaseEncodingDuplex(undefined, false)(true)});34+ }, {message: /cannot be `false` if `new Duplex\({objectMode: true}\)`/});35+});36+37+test('Cannot use objectMode: false with duplex.readableObjectMode: true', t => {38+ t.throws(() => {39+ execa('noop-fd.js', ['1', foobarString], {stdout: uppercaseEncodingDuplex(undefined, true)(false)});40+ }, {message: /can only be `true` if `new Duplex\({objectMode: true}\)`/});41+});42+43+const testObjectModeFalse = async (t, objectMode) => {44+ const {stdout} = await execa('noop-fd.js', ['1', foobarString], {stdout: uppercaseEncodingDuplex(undefined, objectMode)(false)});45+ t.is(stdout, foobarUppercase);46+};47+48+test('Can use objectMode: false with duplex.readableObjectMode: false', testObjectModeFalse, false);49+test('Can use objectMode: undefined with duplex.readableObjectMode: false', testObjectModeFalse, undefined);50+51+const testObjectModeTrue = async (t, objectMode) => {52+ const {stdout} = await execa('noop-fd.js', ['1', foobarString], {stdout: getOutputDuplex(foobarObject, objectMode)(true)});53+ t.deepEqual(stdout, [foobarObject]);54+};55+56+test('Can use objectMode: true with duplex.readableObjectMode: true', testObjectModeTrue, true);57+test('Can use objectMode: undefined with duplex.readableObjectMode: true', testObjectModeTrue, undefined);modified:test/stdio/generator.js+242 added-130 removed
15 unmodified lines16 foobarObject,17 foobarObjectString,18 } from '../helpers/input.js';19 import {20- addNoopGenerator,21- serializeGenerator,20 outputObjectGenerator,21 uppercaseGenerator,22 uppercaseBufferGenerator,23 appendGenerator,24 casedSuffix,25 } from '../helpers/generator.js';26+import {appendDuplex, uppercaseBufferDuplex} from '../helpers/duplex.js';27+import {generatorsMap} from '../helpers/map.js';28 29 setFixtureDir();30 31 const textEncoder = new TextEncoder();32 33-const getInputObjectMode = (objectMode, addNoopTransform) => objectMode33+const getInputObjectMode = (objectMode, addNoopTransform, type) => objectMode34 ? {35 input: [foobarObject],36- generators: addNoopGenerator(serializeGenerator(objectMode), addNoopTransform, objectMode),36+ generators: generatorsMap[type].addNoop(generatorsMap[type].serialize(objectMode), addNoopTransform, objectMode),37 output: foobarObjectString,38 }39 : {40 input: foobarUint8Array,41- generators: addNoopGenerator(uppercaseGenerator(objectMode), addNoopTransform, objectMode),41+ generators: generatorsMap[type].addNoop(generatorsMap[type].uppercase(objectMode), addNoopTransform, objectMode),42 output: foobarUppercase,43 };44 45-const getOutputObjectMode = (objectMode, addNoopTransform, binary) => objectMode45+const getOutputObjectMode = (objectMode, addNoopTransform, type, binary) => objectMode46 ? {47- generators: addNoopGenerator(outputObjectGenerator(), addNoopTransform, objectMode, binary),47+ generators: generatorsMap[type].addNoop(generatorsMap[type].outputObject(), addNoopTransform, objectMode, binary),48 output: [foobarObject],49 getStreamMethod: getStreamAsArray,50 }51 : {52- generators: addNoopGenerator(uppercaseBufferGenerator(objectMode, true), addNoopTransform, objectMode, binary),52+ generators: generatorsMap[type].addNoop(generatorsMap[type].uppercaseBuffer(objectMode, true), addNoopTransform, objectMode, binary),53 output: foobarUppercase,54 getStreamMethod: getStream,55 };56 57+// eslint-disable-next-line max-params57-const testGeneratorInput = async (t, fdNumber, objectMode, addNoopTransform) => {58- const {input, generators, output} = getInputObjectMode(objectMode, addNoopTransform);58+const testGeneratorInput = async (t, fdNumber, objectMode, addNoopTransform, type) => {59+ const {input, generators, output} = getInputObjectMode(objectMode, addNoopTransform, type);60 const {stdout} = await execa('stdin-fd.js', [`${fdNumber}`], getStdio(fdNumber, [input, ...generators]));61 t.is(stdout, output);62 };63 63-test('Can use generators with result.stdin', testGeneratorInput, 0, false, false);64-test('Can use generators with result.stdio[*] as input', testGeneratorInput, 3, false, false);65-test('Can use generators with result.stdin, objectMode', testGeneratorInput, 0, true, false);66-test('Can use generators with result.stdio[*] as input, objectMode', testGeneratorInput, 3, true, false);67-test('Can use generators with result.stdin, noop transform', testGeneratorInput, 0, false, true);68-test('Can use generators with result.stdio[*] as input, noop transform', testGeneratorInput, 3, false, true);69-test('Can use generators with result.stdin, objectMode, noop transform', testGeneratorInput, 0, true, true);70-test('Can use generators with result.stdio[*] as input, objectMode, noop transform', testGeneratorInput, 3, true, true);64+test('Can use generators with result.stdin', testGeneratorInput, 0, false, false, 'generator');65+test('Can use generators with result.stdio[*] as input', testGeneratorInput, 3, false, false, 'generator');66+test('Can use generators with result.stdin, objectMode', testGeneratorInput, 0, true, false, 'generator');67+test('Can use generators with result.stdio[*] as input, objectMode', testGeneratorInput, 3, true, false, 'generator');68+test('Can use generators with result.stdin, noop transform', testGeneratorInput, 0, false, true, 'generator');69+test('Can use generators with result.stdio[*] as input, noop transform', testGeneratorInput, 3, false, true, 'generator');70+test('Can use generators with result.stdin, objectMode, noop transform', testGeneratorInput, 0, true, true, 'generator');71+test('Can use generators with result.stdio[*] as input, objectMode, noop transform', testGeneratorInput, 3, true, true, 'generator');72+test('Can use duplexes with result.stdin', testGeneratorInput, 0, false, false, 'duplex');73+test('Can use duplexes with result.stdio[*] as input', testGeneratorInput, 3, false, false, 'duplex');74+test('Can use duplexes with result.stdin, objectMode', testGeneratorInput, 0, true, false, 'duplex');75+test('Can use duplexes with result.stdio[*] as input, objectMode', testGeneratorInput, 3, true, false, 'duplex');76+test('Can use duplexes with result.stdin, noop transform', testGeneratorInput, 0, false, true, 'duplex');77+test('Can use duplexes with result.stdio[*] as input, noop transform', testGeneratorInput, 3, false, true, 'duplex');78+test('Can use duplexes with result.stdin, objectMode, noop transform', testGeneratorInput, 0, true, true, 'duplex');79+test('Can use duplexes with result.stdio[*] as input, objectMode, noop transform', testGeneratorInput, 3, true, true, 'duplex');80 81 // eslint-disable-next-line max-params73-const testGeneratorInputPipe = async (t, useShortcutProperty, objectMode, addNoopTransform, input) => {74- const {generators, output} = getInputObjectMode(objectMode, addNoopTransform);82+const testGeneratorInputPipe = async (t, useShortcutProperty, objectMode, addNoopTransform, type, input) => {83+ const {generators, output} = getInputObjectMode(objectMode, addNoopTransform, type);84 const subprocess = execa('stdin-fd.js', ['0'], getStdio(0, generators));85 const stream = useShortcutProperty ? subprocess.stdin : subprocess.stdio[0];86 stream.end(...input);87 const {stdout} = await subprocess;88 t.is(stdout, output);89 };90 82-test('Can use generators with subprocess.stdio[0] and default encoding', testGeneratorInputPipe, false, false, false, [foobarString, 'utf8']);83-test('Can use generators with subprocess.stdin and default encoding', testGeneratorInputPipe, true, false, false, [foobarString, 'utf8']);84-test('Can use generators with subprocess.stdio[0] and encoding "buffer"', testGeneratorInputPipe, false, false, false, [foobarBuffer, 'buffer']);85-test('Can use generators with subprocess.stdin and encoding "buffer"', testGeneratorInputPipe, true, false, false, [foobarBuffer, 'buffer']);86-test('Can use generators with subprocess.stdio[0] and encoding "hex"', testGeneratorInputPipe, false, false, false, [foobarHex, 'hex']);87-test('Can use generators with subprocess.stdin and encoding "hex"', testGeneratorInputPipe, true, false, false, [foobarHex, 'hex']);88-test('Can use generators with subprocess.stdio[0], objectMode', testGeneratorInputPipe, false, true, false, [foobarObject]);89-test('Can use generators with subprocess.stdin, objectMode', testGeneratorInputPipe, true, true, false, [foobarObject]);90-test('Can use generators with subprocess.stdio[0] and default encoding, noop transform', testGeneratorInputPipe, false, false, true, [foobarString, 'utf8']);91-test('Can use generators with subprocess.stdin and default encoding, noop transform', testGeneratorInputPipe, true, false, true, [foobarString, 'utf8']);92-test('Can use generators with subprocess.stdio[0] and encoding "buffer", noop transform', testGeneratorInputPipe, false, false, true, [foobarBuffer, 'buffer']);93-test('Can use generators with subprocess.stdin and encoding "buffer", noop transform', testGeneratorInputPipe, true, false, true, [foobarBuffer, 'buffer']);94-test('Can use generators with subprocess.stdio[0] and encoding "hex", noop transform', testGeneratorInputPipe, false, false, true, [foobarHex, 'hex']);95-test('Can use generators with subprocess.stdin and encoding "hex", noop transform', testGeneratorInputPipe, true, false, true, [foobarHex, 'hex']);96-test('Can use generators with subprocess.stdio[0], objectMode, noop transform', testGeneratorInputPipe, false, true, true, [foobarObject]);97-test('Can use generators with subprocess.stdin, objectMode, noop transform', testGeneratorInputPipe, true, true, true, [foobarObject]);91+test('Can use generators with subprocess.stdio[0] and default encoding', testGeneratorInputPipe, false, false, false, 'generator', [foobarString, 'utf8']);92+test('Can use generators with subprocess.stdin and default encoding', testGeneratorInputPipe, true, false, false, 'generator', [foobarString, 'utf8']);93+test('Can use generators with subprocess.stdio[0] and encoding "buffer"', testGeneratorInputPipe, false, false, false, 'generator', [foobarBuffer, 'buffer']);94+test('Can use generators with subprocess.stdin and encoding "buffer"', testGeneratorInputPipe, true, false, false, 'generator', [foobarBuffer, 'buffer']);95+test('Can use generators with subprocess.stdio[0] and encoding "hex"', testGeneratorInputPipe, false, false, false, 'generator', [foobarHex, 'hex']);96+test('Can use generators with subprocess.stdin and encoding "hex"', testGeneratorInputPipe, true, false, false, 'generator', [foobarHex, 'hex']);97+test('Can use generators with subprocess.stdio[0], objectMode', testGeneratorInputPipe, false, true, false, 'generator', [foobarObject]);98+test('Can use generators with subprocess.stdin, objectMode', testGeneratorInputPipe, true, true, false, 'generator', [foobarObject]);99+test('Can use generators with subprocess.stdio[0] and default encoding, noop transform', testGeneratorInputPipe, false, false, true, 'generator', [foobarString, 'utf8']);100+test('Can use generators with subprocess.stdin and default encoding, noop transform', testGeneratorInputPipe, true, false, true, 'generator', [foobarString, 'utf8']);101+test('Can use generators with subprocess.stdio[0] and encoding "buffer", noop transform', testGeneratorInputPipe, false, false, true, 'generator', [foobarBuffer, 'buffer']);102+test('Can use generators with subprocess.stdin and encoding "buffer", noop transform', testGeneratorInputPipe, true, false, true, 'generator', [foobarBuffer, 'buffer']);103+test('Can use generators with subprocess.stdio[0] and encoding "hex", noop transform', testGeneratorInputPipe, false, false, true, 'generator', [foobarHex, 'hex']);104+test('Can use generators with subprocess.stdin and encoding "hex", noop transform', testGeneratorInputPipe, true, false, true, 'generator', [foobarHex, 'hex']);105+test('Can use generators with subprocess.stdio[0], objectMode, noop transform', testGeneratorInputPipe, false, true, true, 'generator', [foobarObject]);106+test('Can use generators with subprocess.stdin, objectMode, noop transform', testGeneratorInputPipe, true, true, true, 'generator', [foobarObject]);107+test('Can use duplexes with subprocess.stdio[0] and default encoding', testGeneratorInputPipe, false, false, false, 'duplex', [foobarString, 'utf8']);108+test('Can use duplexes with subprocess.stdin and default encoding', testGeneratorInputPipe, true, false, false, 'duplex', [foobarString, 'utf8']);109+test('Can use duplexes with subprocess.stdio[0] and encoding "buffer"', testGeneratorInputPipe, false, false, false, 'duplex', [foobarBuffer, 'buffer']);110+test('Can use duplexes with subprocess.stdin and encoding "buffer"', testGeneratorInputPipe, true, false, false, 'duplex', [foobarBuffer, 'buffer']);111+test('Can use duplexes with subprocess.stdio[0] and encoding "hex"', testGeneratorInputPipe, false, false, false, 'duplex', [foobarHex, 'hex']);112+test('Can use duplexes with subprocess.stdin and encoding "hex"', testGeneratorInputPipe, true, false, false, 'duplex', [foobarHex, 'hex']);113+test('Can use duplexes with subprocess.stdio[0], objectMode', testGeneratorInputPipe, false, true, false, 'duplex', [foobarObject]);114+test('Can use duplexes with subprocess.stdin, objectMode', testGeneratorInputPipe, true, true, false, 'duplex', [foobarObject]);115+test('Can use duplexes with subprocess.stdio[0] and default encoding, noop transform', testGeneratorInputPipe, false, false, true, 'duplex', [foobarString, 'utf8']);116+test('Can use duplexes with subprocess.stdin and default encoding, noop transform', testGeneratorInputPipe, true, false, true, 'duplex', [foobarString, 'utf8']);117+test('Can use duplexes with subprocess.stdio[0] and encoding "buffer", noop transform', testGeneratorInputPipe, false, false, true, 'duplex', [foobarBuffer, 'buffer']);118+test('Can use duplexes with subprocess.stdin and encoding "buffer", noop transform', testGeneratorInputPipe, true, false, true, 'duplex', [foobarBuffer, 'buffer']);119+test('Can use duplexes with subprocess.stdio[0] and encoding "hex", noop transform', testGeneratorInputPipe, false, false, true, 'duplex', [foobarHex, 'hex']);120+test('Can use duplexes with subprocess.stdin and encoding "hex", noop transform', testGeneratorInputPipe, true, false, true, 'duplex', [foobarHex, 'hex']);121+test('Can use duplexes with subprocess.stdio[0], objectMode, noop transform', testGeneratorInputPipe, false, true, true, 'duplex', [foobarObject]);122+test('Can use duplexes with subprocess.stdin, objectMode, noop transform', testGeneratorInputPipe, true, true, true, 'duplex', [foobarObject]);123 99-const testGeneratorStdioInputPipe = async (t, objectMode, addNoopTransform) => {100- const {input, generators, output} = getInputObjectMode(objectMode, addNoopTransform);124+const testGeneratorStdioInputPipe = async (t, objectMode, addNoopTransform, type) => {125+ const {input, generators, output} = getInputObjectMode(objectMode, addNoopTransform, type);126 const subprocess = execa('stdin-fd.js', ['3'], getStdio(3, [[], ...generators]));127 subprocess.stdio[3].write(Array.isArray(input) ? input[0] : input);128 const {stdout} = await subprocess;129 t.is(stdout, output);130 };131 107-test('Can use generators with subprocess.stdio[*] as input', testGeneratorStdioInputPipe, false, false);108-test('Can use generators with subprocess.stdio[*] as input, objectMode', testGeneratorStdioInputPipe, true, false);109-test('Can use generators with subprocess.stdio[*] as input, noop transform', testGeneratorStdioInputPipe, false, true);110-test('Can use generators with subprocess.stdio[*] as input, objectMode, noop transform', testGeneratorStdioInputPipe, true, true);132+test('Can use generators with subprocess.stdio[*] as input', testGeneratorStdioInputPipe, false, false, 'generator');133+test('Can use generators with subprocess.stdio[*] as input, objectMode', testGeneratorStdioInputPipe, true, false, 'generator');134+test('Can use generators with subprocess.stdio[*] as input, noop transform', testGeneratorStdioInputPipe, false, true, 'generator');135+test('Can use generators with subprocess.stdio[*] as input, objectMode, noop transform', testGeneratorStdioInputPipe, true, true, 'generator');136+test('Can use duplexes with subprocess.stdio[*] as input', testGeneratorStdioInputPipe, false, false, 'duplex');137+test('Can use duplexes with subprocess.stdio[*] as input, objectMode', testGeneratorStdioInputPipe, true, false, 'duplex');138+test('Can use duplexes with subprocess.stdio[*] as input, noop transform', testGeneratorStdioInputPipe, false, true, 'duplex');139+test('Can use duplexes with subprocess.stdio[*] as input, objectMode, noop transform', testGeneratorStdioInputPipe, true, true, 'duplex');140 141 // eslint-disable-next-line max-params113-const testGeneratorOutput = async (t, fdNumber, reject, useShortcutProperty, objectMode, addNoopTransform) => {114- const {generators, output} = getOutputObjectMode(objectMode, addNoopTransform);142+const testGeneratorOutput = async (t, fdNumber, reject, useShortcutProperty, objectMode, addNoopTransform, type) => {143+ const {generators, output} = getOutputObjectMode(objectMode, addNoopTransform, type);144 const fixtureName = reject ? 'noop-fd.js' : 'noop-fail.js';145 const {stdout, stderr, stdio} = await execa(fixtureName, [`${fdNumber}`, foobarString], {...getStdio(fdNumber, generators), reject});146 const result = useShortcutProperty ? [stdout, stderr][fdNumber - 1] : stdio[fdNumber];147 t.deepEqual(result, output);148 };149 121-test('Can use generators with result.stdio[1]', testGeneratorOutput, 1, true, false, false, false);122-test('Can use generators with result.stdout', testGeneratorOutput, 1, true, true, false, false);123-test('Can use generators with result.stdio[2]', testGeneratorOutput, 2, true, false, false, false);124-test('Can use generators with result.stderr', testGeneratorOutput, 2, true, true, false, false);125-test('Can use generators with result.stdio[*] as output', testGeneratorOutput, 3, true, false, false, false);126-test('Can use generators with error.stdio[1]', testGeneratorOutput, 1, false, false, false, false);127-test('Can use generators with error.stdout', testGeneratorOutput, 1, false, true, false, false);128-test('Can use generators with error.stdio[2]', testGeneratorOutput, 2, false, false, false, false);129-test('Can use generators with error.stderr', testGeneratorOutput, 2, false, true, false, false);130-test('Can use generators with error.stdio[*] as output', testGeneratorOutput, 3, false, false, false, false);131-test('Can use generators with result.stdio[1], objectMode', testGeneratorOutput, 1, true, false, true, false);132-test('Can use generators with result.stdout, objectMode', testGeneratorOutput, 1, true, true, true, false);133-test('Can use generators with result.stdio[2], objectMode', testGeneratorOutput, 2, true, false, true, false);134-test('Can use generators with result.stderr, objectMode', testGeneratorOutput, 2, true, true, true, false);135-test('Can use generators with result.stdio[*] as output, objectMode', testGeneratorOutput, 3, true, false, true, false);136-test('Can use generators with error.stdio[1], objectMode', testGeneratorOutput, 1, false, false, true, false);137-test('Can use generators with error.stdout, objectMode', testGeneratorOutput, 1, false, true, true, false);138-test('Can use generators with error.stdio[2], objectMode', testGeneratorOutput, 2, false, false, true, false);139-test('Can use generators with error.stderr, objectMode', testGeneratorOutput, 2, false, true, true, false);140-test('Can use generators with error.stdio[*] as output, objectMode', testGeneratorOutput, 3, false, false, true, false);141-test('Can use generators with result.stdio[1], noop transform', testGeneratorOutput, 1, true, false, false, true);142-test('Can use generators with result.stdout, noop transform', testGeneratorOutput, 1, true, true, false, true);143-test('Can use generators with result.stdio[2], noop transform', testGeneratorOutput, 2, true, false, false, true);144-test('Can use generators with result.stderr, noop transform', testGeneratorOutput, 2, true, true, false, true);145-test('Can use generators with result.stdio[*] as output, noop transform', testGeneratorOutput, 3, true, false, false, true);146-test('Can use generators with error.stdio[1], noop transform', testGeneratorOutput, 1, false, false, false, true);147-test('Can use generators with error.stdout, noop transform', testGeneratorOutput, 1, false, true, false, true);148-test('Can use generators with error.stdio[2], noop transform', testGeneratorOutput, 2, false, false, false, true);149-test('Can use generators with error.stderr, noop transform', testGeneratorOutput, 2, false, true, false, true);150-test('Can use generators with error.stdio[*] as output, noop transform', testGeneratorOutput, 3, false, false, false, true);151-test('Can use generators with result.stdio[1], objectMode, noop transform', testGeneratorOutput, 1, true, false, true, true);152-test('Can use generators with result.stdout, objectMode, noop transform', testGeneratorOutput, 1, true, true, true, true);153-test('Can use generators with result.stdio[2], objectMode, noop transform', testGeneratorOutput, 2, true, false, true, true);154-test('Can use generators with result.stderr, objectMode, noop transform', testGeneratorOutput, 2, true, true, true, true);155-test('Can use generators with result.stdio[*] as output, objectMode, noop transform', testGeneratorOutput, 3, true, false, true, true);156-test('Can use generators with error.stdio[1], objectMode, noop transform', testGeneratorOutput, 1, false, false, true, true);157-test('Can use generators with error.stdout, objectMode, noop transform', testGeneratorOutput, 1, false, true, true, true);158-test('Can use generators with error.stdio[2], objectMode, noop transform', testGeneratorOutput, 2, false, false, true, true);159-test('Can use generators with error.stderr, objectMode, noop transform', testGeneratorOutput, 2, false, true, true, true);160-test('Can use generators with error.stdio[*] as output, objectMode, noop transform', testGeneratorOutput, 3, false, false, true, true);150+test('Can use generators with result.stdio[1]', testGeneratorOutput, 1, true, false, false, false, 'generator');151+test('Can use generators with result.stdout', testGeneratorOutput, 1, true, true, false, false, 'generator');152+test('Can use generators with result.stdio[2]', testGeneratorOutput, 2, true, false, false, false, 'generator');153+test('Can use generators with result.stderr', testGeneratorOutput, 2, true, true, false, false, 'generator');154+test('Can use generators with result.stdio[*] as output', testGeneratorOutput, 3, true, false, false, false, 'generator');155+test('Can use generators with error.stdio[1]', testGeneratorOutput, 1, false, false, false, false, 'generator');156+test('Can use generators with error.stdout', testGeneratorOutput, 1, false, true, false, false, 'generator');157+test('Can use generators with error.stdio[2]', testGeneratorOutput, 2, false, false, false, false, 'generator');158+test('Can use generators with error.stderr', testGeneratorOutput, 2, false, true, false, false, 'generator');159+test('Can use generators with error.stdio[*] as output', testGeneratorOutput, 3, false, false, false, false, 'generator');160+test('Can use generators with result.stdio[1], objectMode', testGeneratorOutput, 1, true, false, true, false, 'generator');161+test('Can use generators with result.stdout, objectMode', testGeneratorOutput, 1, true, true, true, false, 'generator');162+test('Can use generators with result.stdio[2], objectMode', testGeneratorOutput, 2, true, false, true, false, 'generator');163+test('Can use generators with result.stderr, objectMode', testGeneratorOutput, 2, true, true, true, false, 'generator');164+test('Can use generators with result.stdio[*] as output, objectMode', testGeneratorOutput, 3, true, false, true, false, 'generator');165+test('Can use generators with error.stdio[1], objectMode', testGeneratorOutput, 1, false, false, true, false, 'generator');166+test('Can use generators with error.stdout, objectMode', testGeneratorOutput, 1, false, true, true, false, 'generator');167+test('Can use generators with error.stdio[2], objectMode', testGeneratorOutput, 2, false, false, true, false, 'generator');168+test('Can use generators with error.stderr, objectMode', testGeneratorOutput, 2, false, true, true, false, 'generator');169+test('Can use generators with error.stdio[*] as output, objectMode', testGeneratorOutput, 3, false, false, true, false, 'generator');170+test('Can use generators with result.stdio[1], noop transform', testGeneratorOutput, 1, true, false, false, true, 'generator');171+test('Can use generators with result.stdout, noop transform', testGeneratorOutput, 1, true, true, false, true, 'generator');172+test('Can use generators with result.stdio[2], noop transform', testGeneratorOutput, 2, true, false, false, true, 'generator');173+test('Can use generators with result.stderr, noop transform', testGeneratorOutput, 2, true, true, false, true, 'generator');174+test('Can use generators with result.stdio[*] as output, noop transform', testGeneratorOutput, 3, true, false, false, true, 'generator');175+test('Can use generators with error.stdio[1], noop transform', testGeneratorOutput, 1, false, false, false, true, 'generator');176+test('Can use generators with error.stdout, noop transform', testGeneratorOutput, 1, false, true, false, true, 'generator');177+test('Can use generators with error.stdio[2], noop transform', testGeneratorOutput, 2, false, false, false, true, 'generator');178+test('Can use generators with error.stderr, noop transform', testGeneratorOutput, 2, false, true, false, true, 'generator');179+test('Can use generators with error.stdio[*] as output, noop transform', testGeneratorOutput, 3, false, false, false, true, 'generator');180+test('Can use generators with result.stdio[1], objectMode, noop transform', testGeneratorOutput, 1, true, false, true, true, 'generator');181+test('Can use generators with result.stdout, objectMode, noop transform', testGeneratorOutput, 1, true, true, true, true, 'generator');182+test('Can use generators with result.stdio[2], objectMode, noop transform', testGeneratorOutput, 2, true, false, true, true, 'generator');183+test('Can use generators with result.stderr, objectMode, noop transform', testGeneratorOutput, 2, true, true, true, true, 'generator');184+test('Can use generators with result.stdio[*] as output, objectMode, noop transform', testGeneratorOutput, 3, true, false, true, true, 'generator');185+test('Can use generators with error.stdio[1], objectMode, noop transform', testGeneratorOutput, 1, false, false, true, true, 'generator');186+test('Can use generators with error.stdout, objectMode, noop transform', testGeneratorOutput, 1, false, true, true, true, 'generator');187+test('Can use generators with error.stdio[2], objectMode, noop transform', testGeneratorOutput, 2, false, false, true, true, 'generator');188+test('Can use generators with error.stderr, objectMode, noop transform', testGeneratorOutput, 2, false, true, true, true, 'generator');189+test('Can use generators with error.stdio[*] as output, objectMode, noop transform', testGeneratorOutput, 3, false, false, true, true, 'generator');190+test('Can use duplexes with result.stdio[1]', testGeneratorOutput, 1, true, false, false, false, 'duplex');191+test('Can use duplexes with result.stdout', testGeneratorOutput, 1, true, true, false, false, 'duplex');192+test('Can use duplexes with result.stdio[2]', testGeneratorOutput, 2, true, false, false, false, 'duplex');193+test('Can use duplexes with result.stderr', testGeneratorOutput, 2, true, true, false, false, 'duplex');194+test('Can use duplexes with result.stdio[*] as output', testGeneratorOutput, 3, true, false, false, false, 'duplex');195+test('Can use duplexes with error.stdio[1]', testGeneratorOutput, 1, false, false, false, false, 'duplex');196+test('Can use duplexes with error.stdout', testGeneratorOutput, 1, false, true, false, false, 'duplex');197+test('Can use duplexes with error.stdio[2]', testGeneratorOutput, 2, false, false, false, false, 'duplex');198+test('Can use duplexes with error.stderr', testGeneratorOutput, 2, false, true, false, false, 'duplex');199+test('Can use duplexes with error.stdio[*] as output', testGeneratorOutput, 3, false, false, false, false, 'duplex');200+test('Can use duplexes with result.stdio[1], objectMode', testGeneratorOutput, 1, true, false, true, false, 'duplex');201+test('Can use duplexes with result.stdout, objectMode', testGeneratorOutput, 1, true, true, true, false, 'duplex');202+test('Can use duplexes with result.stdio[2], objectMode', testGeneratorOutput, 2, true, false, true, false, 'duplex');203+test('Can use duplexes with result.stderr, objectMode', testGeneratorOutput, 2, true, true, true, false, 'duplex');204+test('Can use duplexes with result.stdio[*] as output, objectMode', testGeneratorOutput, 3, true, false, true, false, 'duplex');205+test('Can use duplexes with error.stdio[1], objectMode', testGeneratorOutput, 1, false, false, true, false, 'duplex');206+test('Can use duplexes with error.stdout, objectMode', testGeneratorOutput, 1, false, true, true, false, 'duplex');207+test('Can use duplexes with error.stdio[2], objectMode', testGeneratorOutput, 2, false, false, true, false, 'duplex');208+test('Can use duplexes with error.stderr, objectMode', testGeneratorOutput, 2, false, true, true, false, 'duplex');209+test('Can use duplexes with error.stdio[*] as output, objectMode', testGeneratorOutput, 3, false, false, true, false, 'duplex');210+test('Can use duplexes with result.stdio[1], noop transform', testGeneratorOutput, 1, true, false, false, true, 'duplex');211+test('Can use duplexes with result.stdout, noop transform', testGeneratorOutput, 1, true, true, false, true, 'duplex');212+test('Can use duplexes with result.stdio[2], noop transform', testGeneratorOutput, 2, true, false, false, true, 'duplex');213+test('Can use duplexes with result.stderr, noop transform', testGeneratorOutput, 2, true, true, false, true, 'duplex');214+test('Can use duplexes with result.stdio[*] as output, noop transform', testGeneratorOutput, 3, true, false, false, true, 'duplex');215+test('Can use duplexes with error.stdio[1], noop transform', testGeneratorOutput, 1, false, false, false, true, 'duplex');216+test('Can use duplexes with error.stdout, noop transform', testGeneratorOutput, 1, false, true, false, true, 'duplex');217+test('Can use duplexes with error.stdio[2], noop transform', testGeneratorOutput, 2, false, false, false, true, 'duplex');218+test('Can use duplexes with error.stderr, noop transform', testGeneratorOutput, 2, false, true, false, true, 'duplex');219+test('Can use duplexes with error.stdio[*] as output, noop transform', testGeneratorOutput, 3, false, false, false, true, 'duplex');220+test('Can use duplexes with result.stdio[1], objectMode, noop transform', testGeneratorOutput, 1, true, false, true, true, 'duplex');221+test('Can use duplexes with result.stdout, objectMode, noop transform', testGeneratorOutput, 1, true, true, true, true, 'duplex');222+test('Can use duplexes with result.stdio[2], objectMode, noop transform', testGeneratorOutput, 2, true, false, true, true, 'duplex');223+test('Can use duplexes with result.stderr, objectMode, noop transform', testGeneratorOutput, 2, true, true, true, true, 'duplex');224+test('Can use duplexes with result.stdio[*] as output, objectMode, noop transform', testGeneratorOutput, 3, true, false, true, true, 'duplex');225+test('Can use duplexes with error.stdio[1], objectMode, noop transform', testGeneratorOutput, 1, false, false, true, true, 'duplex');226+test('Can use duplexes with error.stdout, objectMode, noop transform', testGeneratorOutput, 1, false, true, true, true, 'duplex');227+test('Can use duplexes with error.stdio[2], objectMode, noop transform', testGeneratorOutput, 2, false, false, true, true, 'duplex');228+test('Can use duplexes with error.stderr, objectMode, noop transform', testGeneratorOutput, 2, false, true, true, true, 'duplex');229+test('Can use duplexes with error.stdio[*] as output, objectMode, noop transform', testGeneratorOutput, 3, false, false, true, true, 'duplex');230 231 // eslint-disable-next-line max-params163-const testGeneratorOutputPipe = async (t, fdNumber, useShortcutProperty, objectMode, addNoopTransform) => {164- const {generators, output, getStreamMethod} = getOutputObjectMode(objectMode, addNoopTransform, true);232+const testGeneratorOutputPipe = async (t, fdNumber, useShortcutProperty, objectMode, addNoopTransform, type) => {233+ const {generators, output, getStreamMethod} = getOutputObjectMode(objectMode, addNoopTransform, type, true);234 const subprocess = execa('noop-fd.js', [`${fdNumber}`, foobarString], getStdio(fdNumber, generators));235 const stream = useShortcutProperty ? [subprocess.stdout, subprocess.stderr][fdNumber - 1] : subprocess.stdio[fdNumber];236 const [result] = await Promise.all([getStreamMethod(stream), subprocess]);237 t.deepEqual(result, output);238 };239 171-test('Can use generators with subprocess.stdio[1]', testGeneratorOutputPipe, 1, false, false, false);172-test('Can use generators with subprocess.stdout', testGeneratorOutputPipe, 1, true, false, false);173-test('Can use generators with subprocess.stdio[2]', testGeneratorOutputPipe, 2, false, false, false);174-test('Can use generators with subprocess.stderr', testGeneratorOutputPipe, 2, true, false, false);175-test('Can use generators with subprocess.stdio[*] as output', testGeneratorOutputPipe, 3, false, false, false);176-test('Can use generators with subprocess.stdio[1], objectMode', testGeneratorOutputPipe, 1, false, true, false);177-test('Can use generators with subprocess.stdout, objectMode', testGeneratorOutputPipe, 1, true, true, false);178-test('Can use generators with subprocess.stdio[2], objectMode', testGeneratorOutputPipe, 2, false, true, false);179-test('Can use generators with subprocess.stderr, objectMode', testGeneratorOutputPipe, 2, true, true, false);180-test('Can use generators with subprocess.stdio[*] as output, objectMode', testGeneratorOutputPipe, 3, false, true, false);181-test('Can use generators with subprocess.stdio[1], noop transform', testGeneratorOutputPipe, 1, false, false, true);182-test('Can use generators with subprocess.stdout, noop transform', testGeneratorOutputPipe, 1, true, false, true);183-test('Can use generators with subprocess.stdio[2], noop transform', testGeneratorOutputPipe, 2, false, false, true);184-test('Can use generators with subprocess.stderr, noop transform', testGeneratorOutputPipe, 2, true, false, true);185-test('Can use generators with subprocess.stdio[*] as output, noop transform', testGeneratorOutputPipe, 3, false, false, true);186-test('Can use generators with subprocess.stdio[1], objectMode, noop transform', testGeneratorOutputPipe, 1, false, true, true);187-test('Can use generators with subprocess.stdout, objectMode, noop transform', testGeneratorOutputPipe, 1, true, true, true);188-test('Can use generators with subprocess.stdio[2], objectMode, noop transform', testGeneratorOutputPipe, 2, false, true, true);189-test('Can use generators with subprocess.stderr, objectMode, noop transform', testGeneratorOutputPipe, 2, true, true, true);190-test('Can use generators with subprocess.stdio[*] as output, objectMode, noop transform', testGeneratorOutputPipe, 3, false, true, true);240+test('Can use generators with subprocess.stdio[1]', testGeneratorOutputPipe, 1, false, false, false, 'generator');241+test('Can use generators with subprocess.stdout', testGeneratorOutputPipe, 1, true, false, false, 'generator');242+test('Can use generators with subprocess.stdio[2]', testGeneratorOutputPipe, 2, false, false, false, 'generator');243+test('Can use generators with subprocess.stderr', testGeneratorOutputPipe, 2, true, false, false, 'generator');244+test('Can use generators with subprocess.stdio[*] as output', testGeneratorOutputPipe, 3, false, false, false, 'generator');245+test('Can use generators with subprocess.stdio[1], objectMode', testGeneratorOutputPipe, 1, false, true, false, 'generator');246+test('Can use generators with subprocess.stdout, objectMode', testGeneratorOutputPipe, 1, true, true, false, 'generator');247+test('Can use generators with subprocess.stdio[2], objectMode', testGeneratorOutputPipe, 2, false, true, false, 'generator');248+test('Can use generators with subprocess.stderr, objectMode', testGeneratorOutputPipe, 2, true, true, false, 'generator');249+test('Can use generators with subprocess.stdio[*] as output, objectMode', testGeneratorOutputPipe, 3, false, true, false, 'generator');250+test('Can use generators with subprocess.stdio[1], noop transform', testGeneratorOutputPipe, 1, false, false, true, 'generator');251+test('Can use generators with subprocess.stdout, noop transform', testGeneratorOutputPipe, 1, true, false, true, 'generator');252+test('Can use generators with subprocess.stdio[2], noop transform', testGeneratorOutputPipe, 2, false, false, true, 'generator');253+test('Can use generators with subprocess.stderr, noop transform', testGeneratorOutputPipe, 2, true, false, true, 'generator');254+test('Can use generators with subprocess.stdio[*] as output, noop transform', testGeneratorOutputPipe, 3, false, false, true, 'generator');255+test('Can use generators with subprocess.stdio[1], objectMode, noop transform', testGeneratorOutputPipe, 1, false, true, true, 'generator');256+test('Can use generators with subprocess.stdout, objectMode, noop transform', testGeneratorOutputPipe, 1, true, true, true, 'generator');257+test('Can use generators with subprocess.stdio[2], objectMode, noop transform', testGeneratorOutputPipe, 2, false, true, true, 'generator');258+test('Can use generators with subprocess.stderr, objectMode, noop transform', testGeneratorOutputPipe, 2, true, true, true, 'generator');259+test('Can use generators with subprocess.stdio[*] as output, objectMode, noop transform', testGeneratorOutputPipe, 3, false, true, true, 'generator');260+test('Can use duplexes with subprocess.stdio[1]', testGeneratorOutputPipe, 1, false, false, false, 'duplex');261+test('Can use duplexes with subprocess.stdout', testGeneratorOutputPipe, 1, true, false, false, 'duplex');262+test('Can use duplexes with subprocess.stdio[2]', testGeneratorOutputPipe, 2, false, false, false, 'duplex');263+test('Can use duplexes with subprocess.stderr', testGeneratorOutputPipe, 2, true, false, false, 'duplex');264+test('Can use duplexes with subprocess.stdio[*] as output', testGeneratorOutputPipe, 3, false, false, false, 'duplex');265+test('Can use duplexes with subprocess.stdio[1], objectMode', testGeneratorOutputPipe, 1, false, true, false, 'duplex');266+test('Can use duplexes with subprocess.stdout, objectMode', testGeneratorOutputPipe, 1, true, true, false, 'duplex');267+test('Can use duplexes with subprocess.stdio[2], objectMode', testGeneratorOutputPipe, 2, false, true, false, 'duplex');268+test('Can use duplexes with subprocess.stderr, objectMode', testGeneratorOutputPipe, 2, true, true, false, 'duplex');269+test('Can use duplexes with subprocess.stdio[*] as output, objectMode', testGeneratorOutputPipe, 3, false, true, false, 'duplex');270+test('Can use duplexes with subprocess.stdio[1], noop transform', testGeneratorOutputPipe, 1, false, false, true, 'duplex');271+test('Can use duplexes with subprocess.stdout, noop transform', testGeneratorOutputPipe, 1, true, false, true, 'duplex');272+test('Can use duplexes with subprocess.stdio[2], noop transform', testGeneratorOutputPipe, 2, false, false, true, 'duplex');273+test('Can use duplexes with subprocess.stderr, noop transform', testGeneratorOutputPipe, 2, true, false, true, 'duplex');274+test('Can use duplexes with subprocess.stdio[*] as output, noop transform', testGeneratorOutputPipe, 3, false, false, true, 'duplex');275+test('Can use duplexes with subprocess.stdio[1], objectMode, noop transform', testGeneratorOutputPipe, 1, false, true, true, 'duplex');276+test('Can use duplexes with subprocess.stdout, objectMode, noop transform', testGeneratorOutputPipe, 1, true, true, true, 'duplex');277+test('Can use duplexes with subprocess.stdio[2], objectMode, noop transform', testGeneratorOutputPipe, 2, false, true, true, 'duplex');278+test('Can use duplexes with subprocess.stderr, objectMode, noop transform', testGeneratorOutputPipe, 2, true, true, true, 'duplex');279+test('Can use duplexes with subprocess.stdio[*] as output, objectMode, noop transform', testGeneratorOutputPipe, 3, false, true, true, 'duplex');280 281 const getAllStdioOption = (stdioOption, encoding, objectMode) => {282 if (stdioOption) {283 return 'pipe';86 unmodified lines370 test('Can use generators with error.all = pipe + transform, objectMode, encoding "buffer"', testGeneratorAll, false, 'buffer', true, true, false);371 test('Can use generators with result.all = pipe + transform, objectMode, encoding "hex"', testGeneratorAll, true, 'hex', true, true, false);372 test('Can use generators with error.all = pipe + transform, objectMode, encoding "hex"', testGeneratorAll, false, 'hex', true, true, false);373 285-test('Can use generators with input option', async t => {286- const {stdout} = await execa('stdin-fd.js', ['0'], {stdin: uppercaseGenerator(), input: foobarUint8Array});374+const testInputOption = async (t, type) => {375+ const {stdout} = await execa('stdin-fd.js', ['0'], {stdin: generatorsMap[type].uppercase(), input: foobarUint8Array});376 t.is(stdout, foobarUppercase);288-});377+};378 379+test('Can use generators with input option', testInputOption, 'generator');380+test('Can use duplexes with input option', testInputOption, 'duplex');381+382 const testInputFile = async (t, getOptions, reversed) => {383 const filePath = tempfile();384 await writeFile(filePath, foobarString);385 const {stdin, ...options} = getOptions(filePath);5 unmodified lines391 392 test('Can use generators with a file as input', testInputFile, filePath => ({stdin: [{file: filePath}, uppercaseGenerator()]}), false);393 test('Can use generators with a file as input, reversed', testInputFile, filePath => ({stdin: [{file: filePath}, uppercaseGenerator()]}), true);394 test('Can use generators with inputFile option', testInputFile, filePath => ({inputFile: filePath, stdin: uppercaseGenerator()}), false);395+test('Can use duplexes with a file as input', testInputFile, filePath => ({stdin: [{file: filePath}, uppercaseBufferDuplex()]}), false);396+test('Can use duplexes with a file as input, reversed', testInputFile, filePath => ({stdin: [{file: filePath}, uppercaseBufferDuplex()]}), true);397+test('Can use duplexes with inputFile option', testInputFile, filePath => ({inputFile: filePath, stdin: uppercaseBufferDuplex()}), false);398 304-const testOutputFile = async (t, reversed) => {399+const testOutputFile = async (t, reversed, type) => {400 const filePath = tempfile();306- const stdoutOption = [uppercaseBufferGenerator(false, true), {file: filePath}];401+ const stdoutOption = [generatorsMap[type].uppercaseBuffer(false, true), {file: filePath}];402 const reversedStdoutOption = reversed ? stdoutOption.reverse() : stdoutOption;403 const {stdout} = await execa('noop-fd.js', ['1'], {stdout: reversedStdoutOption});404 t.is(stdout, foobarUppercase);405 t.is(await readFile(filePath, 'utf8'), foobarUppercase);406 await rm(filePath);407 };408 314-test('Can use generators with a file as output', testOutputFile, false);315-test('Can use generators with a file as output, reversed', testOutputFile, true);409+test('Can use generators with a file as output', testOutputFile, false, 'generator');410+test('Can use generators with a file as output, reversed', testOutputFile, true, 'generator');411+test('Can use duplexes with a file as output', testOutputFile, false, 'duplex');412+test('Can use duplexes with a file as output, reversed', testOutputFile, true, 'duplex');413 317-test('Can use generators to a Writable stream', async t => {414+const testWritableDestination = async (t, type) => {415 const passThrough = new PassThrough();416 const [{stdout}, streamOutput] = await Promise.all([320- execa('noop-fd.js', ['1', foobarString], {stdout: [uppercaseBufferGenerator(false, true), passThrough]}),417+ execa('noop-fd.js', ['1', foobarString], {stdout: [generatorsMap[type].uppercaseBuffer(false, true), passThrough]}),418 getStream(passThrough),419 ]);420 t.is(stdout, foobarUppercase);421 t.is(streamOutput, foobarUppercase);325-});422+};423 327-test('Can use generators from a Readable stream', async t => {424+test('Can use generators to a Writable stream', testWritableDestination, 'generator');425+test('Can use duplexes to a Writable stream', testWritableDestination, 'duplex');426+427+const testReadableSource = async (t, type) => {428 const passThrough = new PassThrough();329- const subprocess = execa('stdin-fd.js', ['0'], {stdin: [passThrough, uppercaseGenerator()]});429+ const subprocess = execa('stdin-fd.js', ['0'], {stdin: [passThrough, generatorsMap[type].uppercase()]});430 passThrough.end(foobarString);431 const {stdout} = await subprocess;432 t.is(stdout, foobarUppercase);333-});433+};434 335-test('Can use generators with "inherit"', async t => {336- const {stdout} = await execa('nested-inherit.js');435+test('Can use generators from a Readable stream', testReadableSource, 'generator');436+test('Can use duplexes from a Readable stream', testReadableSource, 'duplex');437+438+const testInherit = async (t, type) => {439+ const {stdout} = await execa('nested-inherit.js', [type]);440 t.is(stdout, foobarUppercase);338-});441+};442 443+test('Can use generators with "inherit"', testInherit, 'generator');444+test('Can use duplexes with "inherit"', testInherit, 'duplex');445+340-const testAppendInput = async (t, reversed) => {341- const stdin = [foobarUint8Array, uppercaseGenerator(), appendGenerator()];446+const testAppendInput = async (t, reversed, type) => {447+ const stdin = [foobarUint8Array, generatorsMap[type].uppercase(), generatorsMap[type].append()];448 const reversedStdin = reversed ? stdin.reverse() : stdin;449 const {stdout} = await execa('stdin-fd.js', ['0'], {stdin: reversedStdin});450 const reversedSuffix = reversed ? casedSuffix.toUpperCase() : casedSuffix;451 t.is(stdout, `${foobarUppercase}${reversedSuffix}`);452 };453 348-test('Can use multiple generators as input', testAppendInput, false);349-test('Can use multiple generators as input, reversed', testAppendInput, true);454+test('Can use multiple generators as input', testAppendInput, false, 'generator');455+test('Can use multiple generators as input, reversed', testAppendInput, true, 'generator');456+test('Can use multiple duplexes as input', testAppendInput, false, 'duplex');457+test('Can use multiple duplexes as input, reversed', testAppendInput, true, 'duplex');458 351-const testAppendOutput = async (t, reversed) => {352- const stdoutOption = [uppercaseGenerator(), appendGenerator()];459+const testAppendOutput = async (t, reversed, type) => {460+ const stdoutOption = [generatorsMap[type].uppercase(), generatorsMap[type].append()];461 const reversedStdoutOption = reversed ? stdoutOption.reverse() : stdoutOption;462 const {stdout} = await execa('noop-fd.js', ['1', foobarString], {stdout: reversedStdoutOption});463 const reversedSuffix = reversed ? casedSuffix.toUpperCase() : casedSuffix;464 t.is(stdout, `${foobarUppercase}${reversedSuffix}`);465 };466 359-test('Can use multiple generators as output', testAppendOutput, false);360-test('Can use multiple generators as output, reversed', testAppendOutput, true);467+test('Can use multiple generators as output', testAppendOutput, false, 'generator');468+test('Can use multiple generators as output, reversed', testAppendOutput, true, 'generator');469+test('Can use multiple duplexes as output', testAppendOutput, false, 'duplex');470+test('Can use multiple duplexes as output, reversed', testAppendOutput, true, 'duplex');471 472 const testTwoGenerators = async (t, producesTwo, firstGenerator, secondGenerator = firstGenerator) => {473 const {stdout} = await execa('noop-fd.js', ['1', foobarString], {stdout: [firstGenerator, secondGenerator]});474 const expectedSuffix = producesTwo ? `${casedSuffix}${casedSuffix}` : casedSuffix;1 unmodified line476 };477 478 test('Can use multiple identical generators', testTwoGenerators, true, appendGenerator().transform);479 test('Can use multiple identical generators, options object', testTwoGenerators, true, appendGenerator());480+test('Ignore duplicate identical duplexes', testTwoGenerators, false, appendDuplex());481+test('Can use multiple generators with duplexes', testTwoGenerators, true, appendGenerator(false, false, true), appendDuplex());482 483 const testGeneratorSyntax = async (t, generator) => {484 const {stdout} = await execa('noop-fd.js', ['1', foobarString], {stdout: generator});485 t.is(stdout, foobarUppercase);4 unmodified linesmodified:test/stdio/transform.js+53 added-38 removed
7 unmodified lines8 import {9 noopGenerator,10 getOutputAsyncGenerator,11 getOutputGenerator,12- getOutputsGenerator,12 infiniteGenerator,13 outputObjectGenerator,15- noYieldGenerator,16- multipleYieldGenerator,14 convertTransformToFinal,15 prefix,16 suffix,20- throwingGenerator,17 GENERATOR_ERROR_REGEXP,22- timeoutGenerator,18 } from '../helpers/generator.js';19+import {generatorsMap} from '../helpers/map.js';20 import {defaultHighWaterMark} from '../helpers/stream.js';21 import {setFixtureDir} from '../helpers/fixtures-dir.js';22 23 setFixtureDir();52 unmodified lines76 test('Synchronous yields are not buffered, line-wise passThrough', testHighWaterMark, true, false, false);77 test('Synchronous yields are not buffered, binary passThrough', testHighWaterMark, true, true, false);78 test('Synchronous yields are not buffered, objectMode as input but not output', testHighWaterMark, false, false, true);79 80+// eslint-disable-next-line max-params84-const testNoYield = async (t, objectMode, final, output) => {85- const {stdout} = await execa('noop.js', {stdout: convertTransformToFinal(noYieldGenerator(objectMode), final)});81+const testNoYield = async (t, type, objectMode, final, output) => {82+ const {stdout} = await execa('noop.js', {stdout: convertTransformToFinal(generatorsMap[type].noYield(objectMode), final)});83 t.deepEqual(stdout, output);84 };85 89-test('Generator can filter "transform" by not calling yield', testNoYield, false, false, '');90-test('Generator can filter "transform" by not calling yield, objectMode', testNoYield, true, false, []);91-test('Generator can filter "final" by not calling yield', testNoYield, false, true, '');92-test('Generator can filter "final" by not calling yield, objectMode', testNoYield, true, true, []);86+test('Generator can filter "transform" by not calling yield', testNoYield, 'generator', false, false, '');87+test('Generator can filter "transform" by not calling yield, objectMode', testNoYield, 'generator', true, false, []);88+test('Generator can filter "final" by not calling yield', testNoYield, 'generator', false, true, '');89+test('Generator can filter "final" by not calling yield, objectMode', testNoYield, 'generator', true, true, []);90+test('Duplex can filter by not calling push', testNoYield, 'duplex', false, false, '');91+test('Duplex can filter by not calling push, objectMode', testNoYield, 'duplex', true, false, []);92 94-const testMultipleYields = async (t, final) => {95- const {stdout} = await execa('noop-fd.js', ['1', foobarString], {stdout: convertTransformToFinal(multipleYieldGenerator(), final)});96- t.is(stdout, `${prefix}\n${foobarString}\n${suffix}`);93+const testMultipleYields = async (t, type, final, binary) => {94+ const {stdout} = await execa('noop-fd.js', ['1', foobarString], {stdout: convertTransformToFinal(generatorsMap[type].multipleYield(), final)});95+ const newline = binary ? '' : '\n';96+ t.is(stdout, `${prefix}${newline}${foobarString}${newline}${suffix}`);97 };98 99-test('Generator can yield "transform" multiple times at different moments', testMultipleYields, false);100-test('Generator can yield "final" multiple times at different moments', testMultipleYields, true);99+test('Generator can yield "transform" multiple times at different moments', testMultipleYields, 'generator', false, false);100+test('Generator can yield "final" multiple times at different moments', testMultipleYields, 'generator', true, false);101+test('Duplex can push multiple times at different moments', testMultipleYields, 'duplex', false, true);102 103 const partsPerChunk = 4;104 const chunksPerCall = 10;105 const callCount = 5;23 unmodified lines129 test('Generator "final" yields are sent right away', testManyYields, true);130 131 const maxBuffer = 10;132 132-test('Generators take "maxBuffer" into account', async t => {133+const testMaxBuffer = async (t, type) => {134 const bigString = '.'.repeat(maxBuffer);135 const {stdout} = await execa('noop.js', {136 maxBuffer,136- stdout: getOutputGenerator(bigString)(false, true),137+ stdout: generatorsMap[type].getOutput(bigString)(false, true),138 });139 t.is(stdout, bigString);140 140- await t.throwsAsync(execa('noop.js', {maxBuffer, stdout: getOutputGenerator(`${bigString}.`)(false)}));141-});141+ await t.throwsAsync(execa('noop.js', {maxBuffer, stdout: generatorsMap[type].getOutput(`${bigString}.`)(false)}));142+};143 143-test('Generators take "maxBuffer" into account, objectMode', async t => {144+test('Generators take "maxBuffer" into account', testMaxBuffer, 'generator');145+test('Duplexes take "maxBuffer" into account', testMaxBuffer, 'duplex');146+147+const testMaxBufferObject = async (t, type) => {148 const bigArray = Array.from({length: maxBuffer}).fill('.');149 const {stdout} = await execa('noop.js', {150 maxBuffer,147- stdout: getOutputsGenerator(bigArray)(true, true),151+ stdout: generatorsMap[type].getOutputs(bigArray)(true, true),152 });153 t.is(stdout.length, maxBuffer);154 151- await t.throwsAsync(execa('noop.js', {maxBuffer, stdout: getOutputsGenerator([...bigArray, ''])(true)}));152-});155+ await t.throwsAsync(execa('noop.js', {maxBuffer, stdout: generatorsMap[type].getOutputs([...bigArray, ''])(true)}));156+};157 158+test('Generators take "maxBuffer" into account, objectMode', testMaxBufferObject, 'generator');159+test('Duplexes take "maxBuffer" into account, objectMode', testMaxBufferObject, 'duplex');160+154-const testAsyncGenerators = async (t, final) => {161+const testAsyncGenerators = async (t, type, final) => {162 const {stdout} = await execa('noop.js', {156- stdout: convertTransformToFinal(timeoutGenerator(1e2)(), final),163+ stdout: convertTransformToFinal(generatorsMap[type].timeout(1e2)(), final),164 });165 t.is(stdout, foobarString);166 };167 161-test('Generators "transform" is awaited on success', testAsyncGenerators, false);162-test('Generators "final" is awaited on success', testAsyncGenerators, true);168+test('Generators "transform" is awaited on success', testAsyncGenerators, 'generator', false);169+test('Generators "final" is awaited on success', testAsyncGenerators, 'generator', true);170+test('Duplex is awaited on success', testAsyncGenerators, 'duplex', false);171 164-const testThrowingGenerator = async (t, final) => {172+const testThrowingGenerator = async (t, type, final) => {173 await t.throwsAsync(166- execa('noop-fd.js', ['1', foobarString], {stdout: convertTransformToFinal(throwingGenerator(), final)}),174+ execa('noop-fd.js', ['1', foobarString], {stdout: convertTransformToFinal(generatorsMap[type].throwing(), final)}),175 {message: GENERATOR_ERROR_REGEXP},176 );177 };178 171-test('Generators "transform" errors make subprocess fail', testThrowingGenerator, false);172-test('Generators "final" errors make subprocess fail', testThrowingGenerator, true);179+test('Generators "transform" errors make subprocess fail', testThrowingGenerator, 'generator', false);180+test('Generators "final" errors make subprocess fail', testThrowingGenerator, 'generator', true);181+test('Duplexes "transform" errors make subprocess fail', testThrowingGenerator, 'duplex', false);182 174-test('Generators errors make subprocess fail even when other output generators do not throw', async t => {183+const testSingleErrorOutput = async (t, type) => {184 await t.throwsAsync(176- execa('noop-fd.js', ['1', foobarString], {stdout: [noopGenerator(false), throwingGenerator(), noopGenerator(false)]}),185+ execa('noop-fd.js', ['1', foobarString], {stdout: [generatorsMap[type].noop(false), generatorsMap[type].throwing(), generatorsMap[type].noop(false)]}),186 {message: GENERATOR_ERROR_REGEXP},187 );179-});188+};189 181-test('Generators errors make subprocess fail even when other input generators do not throw', async t => {182- const subprocess = execa('stdin-fd.js', ['0'], {stdin: [noopGenerator(false), throwingGenerator(), noopGenerator(false)]});190+test('Generators errors make subprocess fail even when other output generators do not throw', testSingleErrorOutput, 'generator');191+test('Duplexes errors make subprocess fail even when other output generators do not throw', testSingleErrorOutput, 'duplex');192+193+const testSingleErrorInput = async (t, type) => {194+ const subprocess = execa('stdin-fd.js', ['0'], {stdin: [generatorsMap[type].noop(false), generatorsMap[type].throwing(), generatorsMap[type].noop(false)]});195 subprocess.stdin.write('foobar\n');196 await t.throwsAsync(subprocess, {message: GENERATOR_ERROR_REGEXP});185-});197+};198 199+test('Generators errors make subprocess fail even when other input generators do not throw', testSingleErrorInput, 'generator');200+test('Duplexes errors make subprocess fail even when other input generators do not throw', testSingleErrorInput, 'duplex');201+202 const testGeneratorCancel = async (t, error) => {203 const subprocess = execa('noop.js', {stdout: infiniteGenerator()});204 await once(subprocess.stdout, 'data');205 subprocess.stdout.destroy(error);20 unmodified linesmodified:test/stdio/type.js+60 added-10 removed
1 import test from 'ava';2 import {execa, execaSync} from '../../index.js';3 import {getStdio} from '../helpers/stdio.js';4 import {noopGenerator, uppercaseGenerator} from '../helpers/generator.js';5+import {uppercaseBufferDuplex} from '../helpers/duplex.js';6+import {generatorsMap} from '../helpers/map.js';7 import {setFixtureDir} from '../helpers/fixtures-dir.js';8 9 setFixtureDir();10 11 unmodified lines22 test('Cannot use invalid "final" with stdout', testInvalidGenerator, 1, {final: true});23 test('Cannot use invalid "final" with stderr', testInvalidGenerator, 2, {final: true});24 test('Cannot use invalid "final" with stdio[*]', testInvalidGenerator, 3, {final: true});25 24-const testInvalidBinary = (t, fdNumber, optionName) => {26+const testInvalidBinary = (t, fdNumber, optionName, type) => {27 t.throws(() => {26- execa('empty.js', getStdio(fdNumber, {...uppercaseGenerator(), [optionName]: 'true'}));28+ execa('empty.js', getStdio(fdNumber, {...generatorsMap[type].uppercase(), [optionName]: 'true'}));29 }, {message: /a boolean/});30 };31 30-test('Cannot use invalid "binary" with stdin', testInvalidBinary, 0, 'binary');31-test('Cannot use invalid "binary" with stdout', testInvalidBinary, 1, 'binary');32-test('Cannot use invalid "binary" with stderr', testInvalidBinary, 2, 'binary');33-test('Cannot use invalid "binary" with stdio[*]', testInvalidBinary, 3, 'binary');34-test('Cannot use invalid "objectMode" with stdin', testInvalidBinary, 0, 'objectMode');35-test('Cannot use invalid "objectMode" with stdout', testInvalidBinary, 1, 'objectMode');36-test('Cannot use invalid "objectMode" with stderr', testInvalidBinary, 2, 'objectMode');37-test('Cannot use invalid "objectMode" with stdio[*]', testInvalidBinary, 3, 'objectMode');32+test('Cannot use invalid "binary" with stdin', testInvalidBinary, 0, 'binary', 'generator');33+test('Cannot use invalid "binary" with stdout', testInvalidBinary, 1, 'binary', 'generator');34+test('Cannot use invalid "binary" with stderr', testInvalidBinary, 2, 'binary', 'generator');35+test('Cannot use invalid "binary" with stdio[*]', testInvalidBinary, 3, 'binary', 'generator');36+test('Cannot use invalid "objectMode" with stdin, generators', testInvalidBinary, 0, 'objectMode', 'generator');37+test('Cannot use invalid "objectMode" with stdout, generators', testInvalidBinary, 1, 'objectMode', 'generator');38+test('Cannot use invalid "objectMode" with stderr, generators', testInvalidBinary, 2, 'objectMode', 'generator');39+test('Cannot use invalid "objectMode" with stdio[*], generators', testInvalidBinary, 3, 'objectMode', 'generator');40+test('Cannot use invalid "objectMode" with stdin, duplexes', testInvalidBinary, 0, 'objectMode', 'duplex');41+test('Cannot use invalid "objectMode" with stdout, duplexes', testInvalidBinary, 1, 'objectMode', 'duplex');42+test('Cannot use invalid "objectMode" with stderr, duplexes', testInvalidBinary, 2, 'objectMode', 'duplex');43+test('Cannot use invalid "objectMode" with stdio[*], duplexes', testInvalidBinary, 3, 'objectMode', 'duplex');44 45+const testUndefinedOption = (t, fdNumber, optionName, optionValue) => {46+ t.throws(() => {47+ execa('empty.js', getStdio(fdNumber, {...uppercaseBufferDuplex(), [optionName]: optionValue}));48+ }, {message: /can only be defined when using a generator/});49+};50+51+test('Cannot use "binary" with duplexes and stdin', testUndefinedOption, 0, 'binary', true);52+test('Cannot use "binary" with duplexes and stdout', testUndefinedOption, 1, 'binary', true);53+test('Cannot use "binary" with duplexes and stderr', testUndefinedOption, 2, 'binary', true);54+test('Cannot use "binary" with duplexes and stdio[*]', testUndefinedOption, 3, 'binary', true);55+test('Cannot use "final" with duplexes and stdin', testUndefinedOption, 0, 'final', uppercaseBufferDuplex().transform);56+test('Cannot use "final" with duplexes and stdout', testUndefinedOption, 1, 'final', uppercaseBufferDuplex().transform);57+test('Cannot use "final" with duplexes and stderr', testUndefinedOption, 2, 'final', uppercaseBufferDuplex().transform);58+test('Cannot use "final" with duplexes and stdio[*]', testUndefinedOption, 3, 'final', uppercaseBufferDuplex().transform);59+60+const testUndefinedFinal = (t, fdNumber, useTransform) => {61+ t.throws(() => {62+ execa('empty.js', getStdio(fdNumber, {63+ transform: useTransform ? uppercaseGenerator().transform : undefined,64+ final: uppercaseBufferDuplex().transform,65+ }));66+ }, {message: /must not be a Duplex/});67+};68+69+test('Cannot use "final" with duplexes and stdin, without transform', testUndefinedFinal, 0, false);70+test('Cannot use "final" with duplexes and stdout, without transform', testUndefinedFinal, 1, false);71+test('Cannot use "final" with duplexes and stderr, without transform', testUndefinedFinal, 2, false);72+test('Cannot use "final" with duplexes and stdio[*], without transform', testUndefinedFinal, 3, false);73+test('Cannot use "final" with duplexes and stdin, with transform', testUndefinedFinal, 0, true);74+test('Cannot use "final" with duplexes and stdout, with transform', testUndefinedFinal, 1, true);75+test('Cannot use "final" with duplexes and stderr, with transform', testUndefinedFinal, 2, true);76+test('Cannot use "final" with duplexes and stdio[*], with transform', testUndefinedFinal, 3, true);77+78 const testSyncMethodsGenerator = (t, fdNumber) => {79 t.throws(() => {80 execaSync('empty.js', getStdio(fdNumber, uppercaseGenerator()));81 }, {message: /cannot be a generator/});2 unmodified lines84 test('Cannot use generators with sync methods and stdin', testSyncMethodsGenerator, 0);85 test('Cannot use generators with sync methods and stdout', testSyncMethodsGenerator, 1);86 test('Cannot use generators with sync methods and stderr', testSyncMethodsGenerator, 2);87 test('Cannot use generators with sync methods and stdio[*]', testSyncMethodsGenerator, 3);88+89+const testSyncMethodsDuplex = (t, fdNumber) => {90+ t.throws(() => {91+ execaSync('empty.js', getStdio(fdNumber, uppercaseBufferDuplex()));92+ }, {message: /cannot be a Duplex stream/});93+};94+95+test('Cannot use duplexes with sync methods and stdin', testSyncMethodsDuplex, 0);96+test('Cannot use duplexes with sync methods and stdout', testSyncMethodsDuplex, 1);97+test('Cannot use duplexes with sync methods and stderr', testSyncMethodsDuplex, 2);98+test('Cannot use duplexes with sync methods and stdio[*]', testSyncMethodsDuplex, 3);modified:test/verbose/output.js+6 added-3 removed
119 unmodified lines120 121 test('Does not change stdout', testStdioSame, 1);122 test('Does not change stderr', testStdioSame, 2);123 124-test('Prints stdout with only transforms', async t => {125- const {stderr} = await nestedExeca('nested-transform.js', 'noop.js', [foobarString], {verbose: 'full'});124+const testOnlyTransforms = async (t, type) => {125+ const {stderr} = await nestedExeca('nested-transform.js', 'noop.js', [foobarString], {verbose: 'full', type});126 t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarString.toUpperCase()}`);127-});127+};128 129+test('Prints stdout with only transforms', testOnlyTransforms, 'generator');130+test('Prints stdout with only duplexes', testOnlyTransforms, 'duplex');131+132 test('Prints stdout with object transforms', async t => {133 const {stderr} = await nestedExeca('nested-object.js', 'noop.js', {verbose: 'full'});134 t.is(getOutputLine(stderr), `${testTimestamp} [0] ${inspect(foobarObject)}`);135 });107 unmodified linesmodified:index.d.ts+19 added-7 removed
30 unmodified lines31 preserveNewlines?: boolean;32 objectMode?: boolean;33 };34 35+type DuplexTransform = {36+ transform: Duplex;37+ objectMode?: boolean;38+};39+40 type CommonStdioOption<IsSync extends boolean = boolean> =41 | BaseStdioOption42 | 'ipc'43 | number1 unmodified line45 | URL46 | {file: string}47 | IfAsync<IsSync,48 | GeneratorTransform44- | GeneratorTransformFull>;49+ | GeneratorTransformFull50+ | DuplexTransform>;51 52 type InputStdioOption<IsSync extends boolean = boolean> =53 | Uint8Array54 | Readable72 unmodified lines127 >;128 129 type IsObjectOutputOption<OutputOption extends StdioSingleOption> = OutputOption extends GeneratorTransformFull130 ? BooleanObjectMode<OutputOption['objectMode']>131+ : OutputOption extends DuplexTransform132+ ? DuplexObjectMode<OutputOption>125- : false;133+ : false;134 135 type BooleanObjectMode<ObjectModeOption extends GeneratorTransformFull['objectMode']> = ObjectModeOption extends true ? true : false;136 137+type DuplexObjectMode<OutputOption extends DuplexTransform> = OutputOption['objectMode'] extends boolean138+ ? OutputOption['objectMode']139+ : OutputOption['transform']['readableObjectMode'];140+141 // Whether `result.stdout|stderr|all` is `undefined`, excluding the `buffer` option142 type IgnoresStreamResult<143 FdNumber extends string,144 OptionsType extends CommonOptions = CommonOptions,211 unmodified lines356 - an `Uint8Array`.357 358 This can be an [array of values](https://github.com/sindresorhus/execa#redirect-stdinstdoutstderr-to-multiple-destinations) such as `['inherit', 'pipe']` or `[filePath, 'pipe']`.359 348- This can also be a generator function to transform the input. [Learn more.](https://github.com/sindresorhus/execa/tree/main/docs/transform.md)360+ 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)361 362 @default `inherit` with `$`, `pipe` otherwise363 */364 readonly stdin?: StdinOption<IsSync>;11 unmodified lines376 - a web [`WritableStream`](https://developer.mozilla.org/en-US/docs/Web/API/WritableStream).377 378 This can be an [array of values](https://github.com/sindresorhus/execa#redirect-stdinstdoutstderr-to-multiple-destinations) such as `['inherit', 'pipe']` or `[filePath, 'pipe']`.379 368- This can also be a generator function to transform the output. [Learn more.](https://github.com/sindresorhus/execa/tree/main/docs/transform.md)380+ 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)381 382 @default 'pipe'383 */384 readonly stdout?: StdoutStderrOption<IsSync>;11 unmodified lines396 - a web [`WritableStream`](https://developer.mozilla.org/en-US/docs/Web/API/WritableStream).397 398 This can be an [array of values](https://github.com/sindresorhus/execa#redirect-stdinstdoutstderr-to-multiple-destinations) such as `['inherit', 'pipe']` or `[filePath, 'pipe']`.399 388- This can also be a generator function to transform the output. [Learn more.](https://github.com/sindresorhus/execa/tree/main/docs/transform.md)400+ 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)401 402 @default 'pipe'403 */404 readonly stderr?: StdoutStderrOption<IsSync>;940 unmodified lines1345 Same as `execa()` but synchronous.1346 1347 Returns or throws a `subprocessResult`. The `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()`, `.iterable()`, `.readable()`, `.writable()`, `.duplex()` and the [`.stdin`/`.stdout`/`.stderr`](https://nodejs.org/api/child_process.html#subprocessstdout) streams.1348 1337-Cannot use the following options: `all`, `cleanup`, `buffer`, `detached`, `ipc`, `serialization`, `cancelSignal`, `forceKillAfterDelay`, `lines` and `verbose: 'full'`. Also, the `stdin`, `stdout`, `stderr`, `stdio` and `input` options cannot be an array, [`overlapped`](https://nodejs.org/api/child_process.html#optionsstdio), an iterable, a transform or a web stream. Node.js streams must have a file descriptor unless the `input` option is used.1349+Cannot use the following options: `all`, `cleanup`, `buffer`, `detached`, `ipc`, `serialization`, `cancelSignal`, `forceKillAfterDelay`, `lines` and `verbose: 'full'`. Also, the `stdin`, `stdout`, `stderr`, `stdio` and `input` options cannot be an array, [`overlapped`](https://nodejs.org/api/child_process.html#optionsstdio), an iterable, a transform, a `Duplex`, or a web stream. Node.js streams must have a file descriptor unless the `input` option is used.1350 1351 @param file - The program/script to execute, as a string or file URL1352 @param arguments - Arguments to pass to `file` on execution.1353 @returns A `subprocessResult` object105 unmodified lines1459 Same as `execaCommand()` but synchronous.1460 1461 Returns or throws a `subprocessResult`. The `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()`, `.iterable()`, `.readable()`, `.writable()`, `.duplex()` and the [`.stdin`/`.stdout`/`.stderr`](https://nodejs.org/api/child_process.html#subprocessstdout) streams.1462 1451-Cannot use the following options: `all`, `cleanup`, `buffer`, `detached`, `ipc`, `serialization`, `cancelSignal`, `forceKillAfterDelay`, `lines` and `verbose: 'full'`. Also, the `stdin`, `stdout`, `stderr`, `stdio` and `input` options cannot be an array, [`overlapped`](https://nodejs.org/api/child_process.html#optionsstdio), an iterable, a transform or a web stream. Node.js streams must have a file descriptor unless the `input` option is used.1463+Cannot use the following options: `all`, `cleanup`, `buffer`, `detached`, `ipc`, `serialization`, `cancelSignal`, `forceKillAfterDelay`, `lines` and `verbose: 'full'`. Also, the `stdin`, `stdout`, `stderr`, `stdio` and `input` options cannot be an array, [`overlapped`](https://nodejs.org/api/child_process.html#optionsstdio), an iterable, a transform, a `Duplex`, or a web stream. Node.js streams must have a file descriptor unless the `input` option is used.1464 1465 @param command - The program/script to execute and its arguments.1466 @returns A `subprocessResult` object1467 @throws A `subprocessResult` error128 unmodified linesmodified:index.test-d.ts+124 added-1 removed
1 // For some reason a default import of `process` causes2 // `process.stdin`, `process.stderr`, and `process.stdout`3 // to get treated as `any` by `@typescript-eslint/no-unsafe-assignment`.4 import * as process from 'node:process';5-import {Readable, Writable, type Duplex} from 'node:stream';5+import {Readable, Writable, Duplex, Transform} from 'node:stream';6 import {createWriteStream} from 'node:fs';7 import {expectType, expectNotType, expectError, expectAssignable, expectNotAssignable} from 'tsd';8 import {9 $,11 unmodified lines21 type ExecaSyncResult,22 } from './index.js';23 24 const fileUrl = new URL('file:///test');25+const duplexStream = new Duplex();26+const duplex = {transform: duplexStream};27+const duplexObject = {transform: duplexStream as Duplex & {readableObjectMode: true}};28+const duplexNotObject = {transform: duplexStream as Duplex & {readableObjectMode: false}};29+const duplexObjectProperty = {transform: duplexStream, objectMode: true as const};30+const duplexNotObjectProperty = {transform: duplexStream, objectMode: false as const};31+const duplexTransform = {transform: new Transform()};32 33 type AnySyncChunk = string | Uint8Array | undefined;34 type AnyChunk = AnySyncChunk | string[] | unknown[];35 expectType<Writable | null>({} as ExecaSubprocess['stdin']);637 unmodified lines673 const objectTransformLinesStdoutResult = await execa('unicorns', {lines: true, stdout: {transform: objectGenerator, final: objectFinal, objectMode: true}});674 expectType<unknown[]>(objectTransformLinesStdoutResult.stdout);675 expectType<[undefined, unknown[], string[]]>(objectTransformLinesStdoutResult.stdio);676 677+ const objectDuplexStdoutResult = await execa('unicorns', {stdout: duplexObject});678+ expectType<unknown[]>(objectDuplexStdoutResult.stdout);679+ expectType<[undefined, unknown[], string]>(objectDuplexStdoutResult.stdio);680+681+ const objectDuplexPropertyStdoutResult = await execa('unicorns', {stdout: duplexObjectProperty});682+ expectType<unknown[]>(objectDuplexPropertyStdoutResult.stdout);683+ expectType<[undefined, unknown[], string]>(objectDuplexPropertyStdoutResult.stdio);684+685 const objectTransformStdoutResult = await execa('unicorns', {stdout: {transform: objectGenerator, final: objectFinal, objectMode: true}});686 expectType<unknown[]>(objectTransformStdoutResult.stdout);687 expectType<[undefined, unknown[], string]>(objectTransformStdoutResult.stdio);688 689+ const objectDuplexStderrResult = await execa('unicorns', {stderr: duplexObject});690+ expectType<unknown[]>(objectDuplexStderrResult.stderr);691+ expectType<[undefined, string, unknown[]]>(objectDuplexStderrResult.stdio);692+693+ const objectDuplexPropertyStderrResult = await execa('unicorns', {stderr: duplexObjectProperty});694+ expectType<unknown[]>(objectDuplexPropertyStderrResult.stderr);695+ expectType<[undefined, string, unknown[]]>(objectDuplexPropertyStderrResult.stdio);696+697 const objectTransformStderrResult = await execa('unicorns', {stderr: {transform: objectGenerator, final: objectFinal, objectMode: true}});698 expectType<unknown[]>(objectTransformStderrResult.stderr);699 expectType<[undefined, string, unknown[]]>(objectTransformStderrResult.stdio);700 701+ const objectDuplexStdioResult = await execa('unicorns', {stdio: ['pipe', 'pipe', duplexObject]});702+ expectType<unknown[]>(objectDuplexStdioResult.stderr);703+ expectType<[undefined, string, unknown[]]>(objectDuplexStdioResult.stdio);704+705+ const objectDuplexPropertyStdioResult = await execa('unicorns', {stdio: ['pipe', 'pipe', duplexObjectProperty]});706+ expectType<unknown[]>(objectDuplexPropertyStdioResult.stderr);707+ expectType<[undefined, string, unknown[]]>(objectDuplexPropertyStdioResult.stdio);708+709 const objectTransformStdioResult = await execa('unicorns', {stdio: ['pipe', 'pipe', {transform: objectGenerator, final: objectFinal, objectMode: true}]});710 expectType<unknown[]>(objectTransformStdioResult.stderr);711 expectType<[undefined, string, unknown[]]>(objectTransformStdioResult.stdio);712 713+ const singleObjectDuplexStdoutResult = await execa('unicorns', {stdout: [duplexObject]});714+ expectType<unknown[]>(singleObjectDuplexStdoutResult.stdout);715+ expectType<[undefined, unknown[], string]>(singleObjectDuplexStdoutResult.stdio);716+717+ const singleObjectDuplexPropertyStdoutResult = await execa('unicorns', {stdout: [duplexObjectProperty]});718+ expectType<unknown[]>(singleObjectDuplexPropertyStdoutResult.stdout);719+ expectType<[undefined, unknown[], string]>(singleObjectDuplexPropertyStdoutResult.stdio);720+721 const singleObjectTransformStdoutResult = await execa('unicorns', {stdout: [{transform: objectGenerator, final: objectFinal, objectMode: true}]});722 expectType<unknown[]>(singleObjectTransformStdoutResult.stdout);723 expectType<[undefined, unknown[], string]>(singleObjectTransformStdoutResult.stdio);724 725+ const manyObjectDuplexStdoutResult = await execa('unicorns', {stdout: [duplexObject, duplexObject]});726+ expectType<unknown[]>(manyObjectDuplexStdoutResult.stdout);727+ expectType<[undefined, unknown[], string]>(manyObjectDuplexStdoutResult.stdio);728+729+ const manyObjectDuplexPropertyStdoutResult = await execa('unicorns', {stdout: [duplexObjectProperty, duplexObjectProperty]});730+ expectType<unknown[]>(manyObjectDuplexPropertyStdoutResult.stdout);731+ expectType<[undefined, unknown[], string]>(manyObjectDuplexPropertyStdoutResult.stdio);732+733 const manyObjectTransformStdoutResult = await execa('unicorns', {stdout: [{transform: objectGenerator, final: objectFinal, objectMode: true}, {transform: objectGenerator, final: objectFinal, objectMode: true}]});734 expectType<unknown[]>(manyObjectTransformStdoutResult.stdout);735 expectType<[undefined, unknown[], string]>(manyObjectTransformStdoutResult.stdio);736 737+ const falseObjectDuplexStdoutResult = await execa('unicorns', {stdout: duplexNotObject});738+ expectType<string>(falseObjectDuplexStdoutResult.stdout);739+ expectType<[undefined, string, string]>(falseObjectDuplexStdoutResult.stdio);740+741+ const falseObjectDuplexPropertyStdoutResult = await execa('unicorns', {stdout: duplexNotObjectProperty});742+ expectType<string>(falseObjectDuplexPropertyStdoutResult.stdout);743+ expectType<[undefined, string, string]>(falseObjectDuplexPropertyStdoutResult.stdio);744+745 const falseObjectTransformStdoutResult = await execa('unicorns', {stdout: {transform: objectGenerator, final: objectFinal, objectMode: false}});746 expectType<string>(falseObjectTransformStdoutResult.stdout);747 expectType<[undefined, string, string]>(falseObjectTransformStdoutResult.stdio);748 749+ const falseObjectDuplexStderrResult = await execa('unicorns', {stderr: duplexNotObject});750+ expectType<string>(falseObjectDuplexStderrResult.stderr);751+ expectType<[undefined, string, string]>(falseObjectDuplexStderrResult.stdio);752+753+ const falseObjectDuplexPropertyStderrResult = await execa('unicorns', {stderr: duplexNotObjectProperty});754+ expectType<string>(falseObjectDuplexPropertyStderrResult.stderr);755+ expectType<[undefined, string, string]>(falseObjectDuplexPropertyStderrResult.stdio);756+757 const falseObjectTransformStderrResult = await execa('unicorns', {stderr: {transform: objectGenerator, final: objectFinal, objectMode: false}});758 expectType<string>(falseObjectTransformStderrResult.stderr);759 expectType<[undefined, string, string]>(falseObjectTransformStderrResult.stdio);760 761+ const falseObjectDuplexStdioResult = await execa('unicorns', {stdio: ['pipe', 'pipe', duplexNotObject]});762+ expectType<string>(falseObjectDuplexStdioResult.stderr);763+ expectType<[undefined, string, string]>(falseObjectDuplexStdioResult.stdio);764+765+ const falseObjectDuplexPropertyStdioResult = await execa('unicorns', {stdio: ['pipe', 'pipe', duplexNotObjectProperty]});766+ expectType<string>(falseObjectDuplexPropertyStdioResult.stderr);767+ expectType<[undefined, string, string]>(falseObjectDuplexPropertyStdioResult.stdio);768+769 const falseObjectTransformStdioResult = await execa('unicorns', {stdio: ['pipe', 'pipe', {transform: objectGenerator, final: objectFinal, objectMode: false}]});770 expectType<string>(falseObjectTransformStdioResult.stderr);771 expectType<[undefined, string, string]>(falseObjectTransformStdioResult.stdio);772 773+ const undefinedObjectDuplexStdoutResult = await execa('unicorns', {stdout: duplex});774+ expectType<string | unknown[]>(undefinedObjectDuplexStdoutResult.stdout);775+ expectType<[undefined, string | unknown[], string]>(undefinedObjectDuplexStdoutResult.stdio);776+777 const undefinedObjectTransformStdoutResult = await execa('unicorns', {stdout: {transform: objectGenerator, final: objectFinal}});778 expectType<string>(undefinedObjectTransformStdoutResult.stdout);779 expectType<[undefined, string, string]>(undefinedObjectTransformStdoutResult.stdio);780 479 unmodified lines1260 execa('unicorns', {stdin: [fileUrl]});1261 execaSync('unicorns', {stdin: [fileUrl]});1262 execa('unicorns', {stdin: {file: './test'}});1263 execaSync('unicorns', {stdin: {file: './test'}});1264+expectError(execa('unicorns', {stdin: {file: fileUrl}}));1265+expectError(execaSync('unicorns', {stdin: {file: fileUrl}}));1266 execa('unicorns', {stdin: [{file: './test'}]});1267 execaSync('unicorns', {stdin: [{file: './test'}]});1268 execa('unicorns', {stdin: 1});1269 execaSync('unicorns', {stdin: 1});1270 execa('unicorns', {stdin: [1]});1271 execaSync('unicorns', {stdin: [1]});1272+execa('unicorns', {stdin: duplex});1273+expectError(execaSync('unicorns', {stdin: duplex}));1274+execa('unicorns', {stdin: [duplex]});1275+expectError(execaSync('unicorns', {stdin: [duplex]}));1276+execa('unicorns', {stdin: duplexTransform});1277+expectError(execaSync('unicorns', {stdin: duplexTransform}));1278+execa('unicorns', {stdin: [duplexTransform]});1279+expectError(execaSync('unicorns', {stdin: [duplexTransform]}));1280+expectError(execa('unicorns', {stdin: {...duplex, objectMode: 'true'}}));1281+expectError(execaSync('unicorns', {stdin: {...duplex, objectMode: 'true'}}));1282 execa('unicorns', {stdin: unknownGenerator});1283 expectError(execaSync('unicorns', {stdin: unknownGenerator}));1284 execa('unicorns', {stdin: [unknownGenerator]});1285 expectError(execaSync('unicorns', {stdin: [unknownGenerator]}));89 unmodified lines1375 execa('unicorns', {stdout: {file: './test'}});1376 execaSync('unicorns', {stdout: {file: './test'}});1377 execa('unicorns', {stdout: [{file: './test'}]});1378 execaSync('unicorns', {stdout: [{file: './test'}]});1379+expectError(execa('unicorns', {stdout: {file: fileUrl}}));1380+expectError(execaSync('unicorns', {stdout: {file: fileUrl}}));1381 execa('unicorns', {stdout: 1});1382 execaSync('unicorns', {stdout: 1});1383 execa('unicorns', {stdout: [1]});1384 execaSync('unicorns', {stdout: [1]});1385+execa('unicorns', {stdout: duplex});1386+expectError(execaSync('unicorns', {stdout: duplex}));1387+execa('unicorns', {stdout: [duplex]});1388+expectError(execaSync('unicorns', {stdout: [duplex]}));1389+execa('unicorns', {stdout: duplexTransform});1390+expectError(execaSync('unicorns', {stdout: duplexTransform}));1391+execa('unicorns', {stdout: [duplexTransform]});1392+expectError(execaSync('unicorns', {stdout: [duplexTransform]}));1393+expectError(execa('unicorns', {stdout: {...duplex, objectMode: 'true'}}));1394+expectError(execaSync('unicorns', {stdout: {...duplex, objectMode: 'true'}}));1395 execa('unicorns', {stdout: unknownGenerator});1396 expectError(execaSync('unicorns', {stdout: unknownGenerator}));1397 execa('unicorns', {stdout: [unknownGenerator]});1398 expectError(execaSync('unicorns', {stdout: [unknownGenerator]}));89 unmodified lines1488 execa('unicorns', {stderr: {file: './test'}});1489 execaSync('unicorns', {stderr: {file: './test'}});1490 execa('unicorns', {stderr: [{file: './test'}]});1491 execaSync('unicorns', {stderr: [{file: './test'}]});1492+expectError(execa('unicorns', {stderr: {file: fileUrl}}));1493+expectError(execaSync('unicorns', {stderr: {file: fileUrl}}));1494 execa('unicorns', {stderr: 1});1495 execaSync('unicorns', {stderr: 1});1496 execa('unicorns', {stderr: [1]});1497 execaSync('unicorns', {stderr: [1]});1498+execa('unicorns', {stderr: duplex});1499+expectError(execaSync('unicorns', {stderr: duplex}));1500+execa('unicorns', {stderr: [duplex]});1501+expectError(execaSync('unicorns', {stderr: [duplex]}));1502+execa('unicorns', {stderr: duplexTransform});1503+expectError(execaSync('unicorns', {stderr: duplexTransform}));1504+execa('unicorns', {stderr: [duplexTransform]});1505+expectError(execaSync('unicorns', {stderr: [duplexTransform]}));1506+expectError(execa('unicorns', {stderr: {...duplex, objectMode: 'true'}}));1507+expectError(execaSync('unicorns', {stderr: {...duplex, objectMode: 'true'}}));1508 execa('unicorns', {stderr: unknownGenerator});1509 expectError(execaSync('unicorns', {stderr: unknownGenerator}));1510 execa('unicorns', {stderr: [unknownGenerator]});1511 expectError(execaSync('unicorns', {stderr: [unknownGenerator]}));79 unmodified lines1591 expectError(execa('unicorns', {stdio: fileUrl}));1592 expectError(execaSync('unicorns', {stdio: fileUrl}));1593 expectError(execa('unicorns', {stdio: {file: './test'}}));1594 expectError(execaSync('unicorns', {stdio: {file: './test'}}));1595+expectError(execa('unicorns', {stdio: duplex}));1596+expectError(execaSync('unicorns', {stdio: duplex}));1597+expectError(execa('unicorns', {stdio: duplexTransform}));1598+expectError(execaSync('unicorns', {stdio: duplexTransform}));1599 expectError(execa('unicorns', {stdio: new Writable()}));1600 expectError(execaSync('unicorns', {stdio: new Writable()}));1601 expectError(execa('unicorns', {stdio: new Readable()}));1602 expectError(execaSync('unicorns', {stdio: new Readable()}));47 unmodified lines1650 {transform: unknownGenerator, final: unknownFinal},1651 undefined,1652 fileUrl,1653 {file: './test'},1654+ duplex,1655+ duplexTransform,1656 new Writable(),1657 new Readable(),1658 new WritableStream(),1659 new ReadableStream(),20 unmodified lines1680 ],1681 });1682 expectError(execaSync('unicorns', {stdio: [unknownGenerator]}));1683 expectError(execaSync('unicorns', {stdio: [{transform: unknownGenerator}]}));1684+expectError(execaSync('unicorns', {stdio: [duplex]}));1685+expectError(execaSync('unicorns', {stdio: [duplexTransform]}));1686 expectError(execaSync('unicorns', {stdio: [new WritableStream()]}));1687 expectError(execaSync('unicorns', {stdio: [new ReadableStream()]}));1688 expectError(execaSync('unicorns', {stdio: [emptyStringGenerator()]}));1689 expectError(execaSync('unicorns', {stdio: [asyncStringGenerator()]}));15 unmodified lines1705 [{transform: unknownGenerator, final: unknownFinal}],1706 [undefined],1707 [fileUrl],1708 [{file: './test'}],1709+ [duplex],1710+ [duplexTransform],1711 [new Writable()],1712 [new Readable()],1713 [new WritableStream()],1714 [new ReadableStream()],24 unmodified lines1739 ],1740 });1741 expectError(execaSync('unicorns', {stdio: [[unknownGenerator]]}));1742 expectError(execaSync('unicorns', {stdio: [[{transform: unknownGenerator}]]}));1743+expectError(execaSync('unicorns', {stdio: [[duplex]]}));1744+expectError(execaSync('unicorns', {stdio: [[duplexTransform]]}));1745 expectError(execaSync('unicorns', {stdio: [[new WritableStream()]]}));1746 expectError(execaSync('unicorns', {stdio: [[new ReadableStream()]]}));1747 expectError(execaSync('unicorns', {stdio: [[['foo', 'bar']]]}));1748 expectError(execaSync('unicorns', {stdio: [[[new Uint8Array(), new Uint8Array()]]]}));438 unmodified linesmodified:readme.md+8 added-8 removed
317 unmodified lines318 Same as [`execa()`](#execafile-arguments-options) but synchronous.319 320 Returns 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.321 322-Cannot 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) or a web stream. Node.js streams [must have a file descriptor](#redirect-a-nodejs-stream-fromto-stdinstdoutstderr) unless the `input` option is used.322+Cannot 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.323 324 #### $(file, arguments?, options?)325 326 `file`: `string | URL`\542 unmodified lines869 See also the [`input`](#input) and [`stdin`](#stdin) options.870 871 #### stdin872 873-Type: `string | number | stream.Readable | ReadableStream | URL | Uint8Array | Iterable<string> | Iterable<Uint8Array> | Iterable<unknown> | AsyncIterable<string> | AsyncIterable<Uint8Array> | AsyncIterable<unknown> | GeneratorFunction<string> | GeneratorFunction<Uint8Array> | GeneratorFunction<unknown>| AsyncGeneratorFunction<string> | AsyncGeneratorFunction<Uint8Array> | AsyncGeneratorFunction<unknown>` (or a tuple of those types)\873+Type: `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)\874 Default: `inherit` with [`$`](#file-arguments-options), `pipe` otherwise875 876 [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 lines887 - an `Uint8Array`.888 889 This can be an [array of values](#redirect-stdinstdoutstderr-to-multiple-destinations) such as `['inherit', 'pipe']` or `[filePath, 'pipe']`.890 891-This can also be a generator function to transform the input. [Learn more.](docs/transform.md)891+This can also be a generator function or a [`Duplex`](docs/transform.md#nodejs-duplextransform-streams) to transform the input. [Learn more.](docs/transform.md)892 893 #### stdout894 895-Type: `string | number | stream.Writable | WritableStream | URL | GeneratorFunction<string> | GeneratorFunction<Uint8Array> | GeneratorFunction<unknown>| AsyncGeneratorFunction<string> | AsyncGeneratorFunction<Uint8Array> | AsyncGeneratorFunction<unknown>` (or a tuple of those types)\895+Type: `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)\896 Default: `pipe`897 898 [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 lines907 - a web [`WritableStream`](https://developer.mozilla.org/en-US/docs/Web/API/WritableStream).908 909 This can be an [array of values](#redirect-stdinstdoutstderr-to-multiple-destinations) such as `['inherit', 'pipe']` or `[filePath, 'pipe']`.910 911-This can also be a generator function to transform the output. [Learn more.](docs/transform.md)911+This can also be a generator function or a [`Duplex`](docs/transform.md#nodejs-duplextransform-streams) to transform the output. [Learn more.](docs/transform.md)912 913 #### stderr914 915-Type: `string | number | stream.Writable | WritableStream | URL | GeneratorFunction<string> | GeneratorFunction<Uint8Array> | GeneratorFunction<unknown>| AsyncGeneratorFunction<string> | AsyncGeneratorFunction<Uint8Array> | AsyncGeneratorFunction<unknown>` (or a tuple of those types)\915+Type: `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)\916 Default: `pipe`917 918 [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 lines927 - a web [`WritableStream`](https://developer.mozilla.org/en-US/docs/Web/API/WritableStream).928 929 This can be an [array of values](#redirect-stdinstdoutstderr-to-multiple-destinations) such as `['inherit', 'pipe']` or `[filePath, 'pipe']`.930 931-This can also be a generator function to transform the output. [Learn more.](docs/transform.md)931+This can also be a generator function or a [`Duplex`](docs/transform.md#nodejs-duplextransform-streams) to transform the output. [Learn more.](docs/transform.md)932 933 #### stdio934 935-Type: `string | Array<string | number | stream.Readable | stream.Writable | ReadableStream | WritableStream | URL | Uint8Array | Iterable<string> | Iterable<Uint8Array> | Iterable<unknown> | AsyncIterable<string> | AsyncIterable<Uint8Array> | AsyncIterable<unknown> | GeneratorFunction<string> | GeneratorFunction<Uint8Array> | GeneratorFunction<unknown>| AsyncGeneratorFunction<string> | AsyncGeneratorFunction<Uint8Array> | AsyncGeneratorFunction<unknown>>` (or a tuple of those types)\935+Type: `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)\936 Default: `pipe`937 938 Like 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