Add support for `std*: TransformStream` option (#938)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by ehmicky · committed by GitHub · parent 6ca44fb · Browse files · 15 files·+478 added−64 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
15 files+478 added−64 removed
- tests:+287 added−33 removed
- other:+191 added−31 removed
Provenance
- Commit
45824d6- Tree
5b48812- Author
ehmicky <ehmicky@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent
6ca44fb
15 files changed+478 added−64 removed
modified:docs/transform.md+19 added-2 removed
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 streams176+## 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.178+A [`Duplex`](https://nodejs.org/api/stream.html#class-streamduplex) stream, Node.js [`Transform`](https://nodejs.org/api/stream.html#class-streamtransform) stream or web [`TransformStream`](https://developer.mozilla.org/en-US/docs/Web/API/TransformStream) can be used instead of a generator function.179 180+Like generator functions, web `TransformStream` can be passed either directly or as a `{transform}` plain object. But `Duplex` and `Transform` must always be passed as a `{transform}` plain object.181+182+The [`objectMode`](#object-mode) transform option can be used, but not the [`binary`](#encoding) nor [`preserveNewlines`](#newlines) options.183+184 ```js185 import {createGzip} from 'node:zlib';186 import {execa} from 'execa';187 188 const {stdout} = await execa('./run.js', {stdout: {transform: createGzip()}});189 console.log(stdout); // `stdout` is compressed with gzip190 ```191 192+```js193+import {execa} from 'execa';194+195+const {stdout} = await execa('./run.js', {stdout: new CompressionStream('gzip')});196+console.log(stdout); // `stdout` is compressed with gzip197+```198+199 ## Combining200 201 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`.202 6 unmodified lines209 ```js210 await execa('echo', ['hello'], {stdout: [transform, otherTransform]});211 ```212 213+Or saving to files.214+215+```js216+await execa('./run.js', {stdout: [new CompressionStream('gzip'), {file: './output.gz'}]});217+```218+219 ## Async iteration220 221 In some cases, [iterating](../readme.md#iterablereadableoptions) over the subprocess can be an alternative to transforms.222 8 unmodified linesmodified:lib/stdio/async.js+6 added-1 removed
123345679 unmodified lines1718192021222324252627282983 unmodified linesimport {createReadStream, createWriteStream} from 'node:fs';import {Buffer} from 'node:buffer';import {Readable, Writable} from 'node:stream';import {Readable, Writable, Duplex} from 'node:stream';import mergeStreams from '@sindresorhus/merge-streams';import {isStandardStream, incrementMaxListeners} from '../utils.js';import {handleInput} from './handle.js';import {pipeStreams} from './pipeline.js';9 unmodified lines
const addProperties = { generator: generatorToDuplexStream, nodeStream: ({value}) => ({stream: value}), webTransform({value: {transform, writableObjectMode, readableObjectMode}}) { const objectMode = writableObjectMode || readableObjectMode; const stream = Duplex.fromWeb(transform, {objectMode}); return {stream}; }, duplex: ({value: {transform}}) => ({stream: transform}), native() {},};
83 unmodified linesmodified:lib/stdio/direction.js+1 added
46 unmodified lines47484950515253545524 unmodified lines46 unmodified lines }
return isNodeWritableStream(value, {checkOpen: false}) ? undefined : 'input'; }, webTransform: anyDirection, duplex: anyDirection, native(value) { const standardStreamDirection = getStandardStreamDirection(value); if (standardStreamDirection !== undefined) {24 unmodified linesmodified:lib/stdio/generator.js+21 added-4 removed
31 unmodified lines32 33 return sortTransforms(newTransforms, direction);34 };35 36-export const TRANSFORM_TYPES = new Set(['generator', 'duplex']);36+export const TRANSFORM_TYPES = new Set(['generator', 'duplex', 'webTransform']);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});38+const normalizeTransform = ({stdioItem, stdioItem: {type}, index, newTransforms, optionName, direction, encoding}) => {39+ if (type === 'duplex') {40+ return normalizeDuplex({stdioItem, optionName});41+ }42 43+ if (type === 'webTransform') {44+ return normalizeTransformStream({stdioItem, index, newTransforms, direction});45+ }46+47+ return normalizeGenerator({stdioItem, index, newTransforms, direction, encoding});48+};49+50 const normalizeDuplex = ({51 stdioItem,52 stdioItem: {53 value: {17 unmodified lines71 value: {transform, writableObjectMode, readableObjectMode},72 };73 };74 75+const normalizeTransformStream = ({stdioItem, stdioItem: {value}, index, newTransforms, direction}) => {76+ const {transform, objectMode} = isPlainObj(value) ? value : {transform: value};77+ const {writableObjectMode, readableObjectMode} = getObjectModes(objectMode, index, newTransforms, direction);78+ return ({79+ ...stdioItem,80+ value: {transform, writableObjectMode, readableObjectMode},81+ });82+};83+84 const normalizeGenerator = ({stdioItem, stdioItem: {value}, index, newTransforms, direction, encoding}) => {85 const {86 transform,87 final,90 unmodified linesmodified:lib/stdio/sync.js+1 added
16 unmodified lines17 const addProperties = {18 generator: forbiddenIfSync,19 webStream: forbiddenIfSync,20 nodeStream: forbiddenIfSync,21+ webTransform: forbiddenIfSync,22 duplex: forbiddenIfSync,23 iterable: forbiddenIfSync,24 native() {},25 };57 unmodified linesmodified:lib/stdio/type.js+36 added-10 removed
30 unmodified lines31 if (isIterableObject(value)) {32 return 'iterable';33 }34 35+ if (isTransformStream(value)) {36+ return getTransformStreamType({transform: value}, optionName);37+ }38+39 if (isTransformOptions(value)) {40 return getTransformObjectType(value, optionName);41 }42 43 return 'native';44 };45 42-const getTransformObjectType = (value, optionName) => isDuplexStream(value.transform, {checkOpen: false})43- ? getDuplexType(value, optionName)44- : getGeneratorObjectType(value, optionName);46+const getTransformObjectType = (value, optionName) => {47+ if (isDuplexStream(value.transform, {checkOpen: false})) {48+ return getDuplexType(value, optionName);49+ }50 46-const getDuplexType = ({final, binary, objectMode}, optionName) => {47- checkUndefinedOption(final, `${optionName}.final`);48- checkUndefinedOption(binary, `${optionName}.binary`);49- checkBooleanOption(objectMode, `${optionName}.objectMode`);51+ if (isTransformStream(value.transform)) {52+ return getTransformStreamType(value, optionName);53+ }54 55+ return getGeneratorObjectType(value, optionName);56+};57+58+const getDuplexType = (value, optionName) => {59+ validateNonGeneratorType(value, optionName, 'Duplex stream');60 return 'duplex';61 };62 54-const checkUndefinedOption = (value, optionName) => {63+const getTransformStreamType = (value, optionName) => {64+ validateNonGeneratorType(value, optionName, 'web TransformStream');65+ return 'webTransform';66+};67+68+const validateNonGeneratorType = ({final, binary, objectMode}, optionName, typeName) => {69+ checkUndefinedOption(final, `${optionName}.final`, typeName);70+ checkUndefinedOption(binary, `${optionName}.binary`, typeName);71+ checkBooleanOption(objectMode, `${optionName}.objectMode`);72+};73+74+const checkUndefinedOption = (value, optionName, typeName) => {75 if (value !== undefined) {56- throw new TypeError(`The \`${optionName}\` option can only be defined when using a generator, not a Duplex stream.`);76+ throw new TypeError(`The \`${optionName}\` option can only be defined when using a generator, not a ${typeName}.`);77 }78 };79 80 const getGeneratorObjectType = ({transform, final, binary, objectMode}, optionName) => {81 if (transform !== undefined && !isGenerator(transform)) {62- throw new TypeError(`The \`${optionName}.transform\` option must be a generator or a Duplex stream.`);82+ throw new TypeError(`The \`${optionName}.transform\` option must be a generator, a Duplex stream or a web TransformStream.`);83 }84 85 if (isDuplexStream(final, {checkOpen: false})) {86 throw new TypeError(`The \`${optionName}.final\` option must not be a Duplex stream.`);87 }88 89+ if (isTransformStream(final)) {90+ throw new TypeError(`The \`${optionName}.final\` option must not be a web TransformStream.`);91+ }92+93 if (final !== undefined && !isGenerator(final)) {94 throw new TypeError(`The \`${optionName}.final\` option must be a generator.`);95 }96 30 unmodified lines127 128 const isReadableStream = value => Object.prototype.toString.call(value) === '[object ReadableStream]';129 export const isWritableStream = value => Object.prototype.toString.call(value) === '[object WritableStream]';130 const isWebStream = value => isReadableStream(value) || isWritableStream(value);131+const isTransformStream = value => isReadableStream(value?.readable) && isWritableStream(value?.writable);132 133 const isIterableObject = value => typeof value === 'object'134 && value !== null135 && (typeof value[Symbol.asyncIterator] === 'function' || typeof value[Symbol.iterator] === 'function');4 unmodified lines140 fileUrl: 'a file URL',141 filePath: 'a file path string',142 webStream: 'a web stream',143 nodeStream: 'a Node.js stream',144+ webTransform: 'a web TransformStream',145 duplex: 'a Duplex stream',146 native: 'any value',147 iterable: 'an iterable',148 string: 'a string',2 unmodified linesmodified:test/helpers/map.js+29 added
25 unmodified lines26 throwingDuplex,27 appendDuplex,28 timeoutDuplex,29 } from './duplex.js';30+import {31+ addNoopWebTransform,32+ noopWebTransform,33+ serializeWebTransform,34+ uppercaseBufferWebTransform,35+ getOutputWebTransform,36+ outputObjectWebTransform,37+ getOutputsWebTransform,38+ noYieldWebTransform,39+ multipleYieldWebTransform,40+ throwingWebTransform,41+ appendWebTransform,42+ timeoutWebTransform,43+} from './web-transform.js';44 45 export const generatorsMap = {46 generator: {47 addNoop: addNoopGenerator,24 unmodified lines72 throwing: throwingDuplex,73 append: appendDuplex,74 timeout: timeoutDuplex,75 },76+ webTransform: {77+ addNoop: addNoopWebTransform,78+ noop: noopWebTransform,79+ serialize: serializeWebTransform,80+ uppercaseBuffer: uppercaseBufferWebTransform,81+ uppercase: uppercaseBufferWebTransform,82+ getOutput: getOutputWebTransform,83+ outputObject: outputObjectWebTransform,84+ getOutputs: getOutputsWebTransform,85+ noYield: noYieldWebTransform,86+ multipleYield: multipleYieldWebTransform,87+ throwing: throwingWebTransform,88+ append: appendWebTransform,89+ timeout: timeoutWebTransform,90+ },91 };added:test/helpers/web-transform.js+59 added
1+import {setTimeout, scheduler} from 'node:timers/promises';2+import {foobarObject, foobarString} from './input.js';3+import {casedSuffix, prefix, suffix} from './generator.js';4+5+const getWebTransform = transform => objectMode => ({6+ transform: new TransformStream({transform}),7+ objectMode,8+});9+10+export const addNoopWebTransform = (webTransform, addNoopTransform, objectMode) => addNoopTransform11+ ? [webTransform, noopWebTransform(objectMode)]12+ : [webTransform];13+14+export const noopWebTransform = getWebTransform((value, controller) => {15+ controller.enqueue(value);16+});17+18+export const serializeWebTransform = getWebTransform((object, controller) => {19+ controller.enqueue(JSON.stringify(object));20+});21+22+export const getOutputWebTransform = (input, outerObjectMode) => getWebTransform((_, controller) => {23+ controller.enqueue(input);24+}, undefined, outerObjectMode);25+26+export const outputObjectWebTransform = () => getOutputWebTransform(foobarObject)(true);27+28+export const getOutputsWebTransform = inputs => getWebTransform((_, controller) => {29+ for (const input of inputs) {30+ controller.enqueue(input);31+ }32+});33+34+export const noYieldWebTransform = getWebTransform(() => {});35+36+export const multipleYieldWebTransform = getWebTransform(async (line, controller) => {37+ controller.enqueue(prefix);38+ await scheduler.yield();39+ controller.enqueue(line);40+ await scheduler.yield();41+ controller.enqueue(suffix);42+});43+44+export const uppercaseBufferWebTransform = getWebTransform((string, controller) => {45+ controller.enqueue(string.toString().toUpperCase());46+});47+48+export const throwingWebTransform = getWebTransform(() => {49+ throw new Error('Generator error');50+});51+52+export const appendWebTransform = getWebTransform((string, controller) => {53+ controller.enqueue(`${string}${casedSuffix}`);54+});55+56+export const timeoutWebTransform = timeout => getWebTransform(async (_, controller) => {57+ await setTimeout(timeout);58+ controller.enqueue(foobarString);59+});modified:test/stdio/generator.js+112 added-4 removed
22 unmodified lines23 appendGenerator,24 casedSuffix,25 } from '../helpers/generator.js';26 import {appendDuplex, uppercaseBufferDuplex} from '../helpers/duplex.js';27+import {appendWebTransform, uppercaseBufferWebTransform} from '../helpers/web-transform.js';28 import {generatorsMap} from '../helpers/map.js';29 30 setFixtureDir();31 45 unmodified lines77 test('Can use duplexes with result.stdin, noop transform', testGeneratorInput, 0, false, true, 'duplex');78 test('Can use duplexes with result.stdio[*] as input, noop transform', testGeneratorInput, 3, false, true, 'duplex');79 test('Can use duplexes with result.stdin, objectMode, noop transform', testGeneratorInput, 0, true, true, 'duplex');80 test('Can use duplexes with result.stdio[*] as input, objectMode, noop transform', testGeneratorInput, 3, true, true, 'duplex');81+test('Can use webTransforms with result.stdin', testGeneratorInput, 0, false, false, 'webTransform');82+test('Can use webTransforms with result.stdio[*] as input', testGeneratorInput, 3, false, false, 'webTransform');83+test('Can use webTransforms with result.stdin, objectMode', testGeneratorInput, 0, true, false, 'webTransform');84+test('Can use webTransforms with result.stdio[*] as input, objectMode', testGeneratorInput, 3, true, false, 'webTransform');85+test('Can use webTransforms with result.stdin, noop transform', testGeneratorInput, 0, false, true, 'webTransform');86+test('Can use webTransforms with result.stdio[*] as input, noop transform', testGeneratorInput, 3, false, true, 'webTransform');87+test('Can use webTransforms with result.stdin, objectMode, noop transform', testGeneratorInput, 0, true, true, 'webTransform');88+test('Can use webTransforms with result.stdio[*] as input, objectMode, noop transform', testGeneratorInput, 3, true, true, 'webTransform');89 90 // eslint-disable-next-line max-params91 const testGeneratorInputPipe = async (t, useShortcutProperty, objectMode, addNoopTransform, type, input) => {92 const {generators, output} = getInputObjectMode(objectMode, addNoopTransform, type);35 unmodified lines128 test('Can use duplexes with subprocess.stdio[0] and encoding "hex", noop transform', testGeneratorInputPipe, false, false, true, 'duplex', [foobarHex, 'hex']);129 test('Can use duplexes with subprocess.stdin and encoding "hex", noop transform', testGeneratorInputPipe, true, false, true, 'duplex', [foobarHex, 'hex']);130 test('Can use duplexes with subprocess.stdio[0], objectMode, noop transform', testGeneratorInputPipe, false, true, true, 'duplex', [foobarObject]);131 test('Can use duplexes with subprocess.stdin, objectMode, noop transform', testGeneratorInputPipe, true, true, true, 'duplex', [foobarObject]);132+test('Can use webTransforms with subprocess.stdio[0] and default encoding', testGeneratorInputPipe, false, false, false, 'webTransform', [foobarString, 'utf8']);133+test('Can use webTransforms with subprocess.stdin and default encoding', testGeneratorInputPipe, true, false, false, 'webTransform', [foobarString, 'utf8']);134+test('Can use webTransforms with subprocess.stdio[0] and encoding "buffer"', testGeneratorInputPipe, false, false, false, 'webTransform', [foobarBuffer, 'buffer']);135+test('Can use webTransforms with subprocess.stdin and encoding "buffer"', testGeneratorInputPipe, true, false, false, 'webTransform', [foobarBuffer, 'buffer']);136+test('Can use webTransforms with subprocess.stdio[0] and encoding "hex"', testGeneratorInputPipe, false, false, false, 'webTransform', [foobarHex, 'hex']);137+test('Can use webTransforms with subprocess.stdin and encoding "hex"', testGeneratorInputPipe, true, false, false, 'webTransform', [foobarHex, 'hex']);138+test('Can use webTransforms with subprocess.stdio[0], objectMode', testGeneratorInputPipe, false, true, false, 'webTransform', [foobarObject]);139+test('Can use webTransforms with subprocess.stdin, objectMode', testGeneratorInputPipe, true, true, false, 'webTransform', [foobarObject]);140+test('Can use webTransforms with subprocess.stdio[0] and default encoding, noop transform', testGeneratorInputPipe, false, false, true, 'webTransform', [foobarString, 'utf8']);141+test('Can use webTransforms with subprocess.stdin and default encoding, noop transform', testGeneratorInputPipe, true, false, true, 'webTransform', [foobarString, 'utf8']);142+test('Can use webTransforms with subprocess.stdio[0] and encoding "buffer", noop transform', testGeneratorInputPipe, false, false, true, 'webTransform', [foobarBuffer, 'buffer']);143+test('Can use webTransforms with subprocess.stdin and encoding "buffer", noop transform', testGeneratorInputPipe, true, false, true, 'webTransform', [foobarBuffer, 'buffer']);144+test('Can use webTransforms with subprocess.stdio[0] and encoding "hex", noop transform', testGeneratorInputPipe, false, false, true, 'webTransform', [foobarHex, 'hex']);145+test('Can use webTransforms with subprocess.stdin and encoding "hex", noop transform', testGeneratorInputPipe, true, false, true, 'webTransform', [foobarHex, 'hex']);146+test('Can use webTransforms with subprocess.stdio[0], objectMode, noop transform', testGeneratorInputPipe, false, true, true, 'webTransform', [foobarObject]);147+test('Can use webTransforms with subprocess.stdin, objectMode, noop transform', testGeneratorInputPipe, true, true, true, 'webTransform', [foobarObject]);148 149 const testGeneratorStdioInputPipe = async (t, objectMode, addNoopTransform, type) => {150 const {input, generators, output} = getInputObjectMode(objectMode, addNoopTransform, type);151 const subprocess = execa('stdin-fd.js', ['3'], getStdio(3, [[], ...generators]));9 unmodified lines161 test('Can use duplexes with subprocess.stdio[*] as input', testGeneratorStdioInputPipe, false, false, 'duplex');162 test('Can use duplexes with subprocess.stdio[*] as input, objectMode', testGeneratorStdioInputPipe, true, false, 'duplex');163 test('Can use duplexes with subprocess.stdio[*] as input, noop transform', testGeneratorStdioInputPipe, false, true, 'duplex');164 test('Can use duplexes with subprocess.stdio[*] as input, objectMode, noop transform', testGeneratorStdioInputPipe, true, true, 'duplex');165+test('Can use webTransforms with subprocess.stdio[*] as input', testGeneratorStdioInputPipe, false, false, 'webTransform');166+test('Can use webTransforms with subprocess.stdio[*] as input, objectMode', testGeneratorStdioInputPipe, true, false, 'webTransform');167+test('Can use webTransforms with subprocess.stdio[*] as input, noop transform', testGeneratorStdioInputPipe, false, true, 'webTransform');168+test('Can use webTransforms with subprocess.stdio[*] as input, objectMode, noop transform', testGeneratorStdioInputPipe, true, true, 'webTransform');169 170 // eslint-disable-next-line max-params171 const testGeneratorOutput = async (t, fdNumber, reject, useShortcutProperty, objectMode, addNoopTransform, type) => {172 const {generators, output} = getOutputObjectMode(objectMode, addNoopTransform, type);82 unmodified lines255 test('Can use duplexes with error.stdout, objectMode, noop transform', testGeneratorOutput, 1, false, true, true, true, 'duplex');256 test('Can use duplexes with error.stdio[2], objectMode, noop transform', testGeneratorOutput, 2, false, false, true, true, 'duplex');257 test('Can use duplexes with error.stderr, objectMode, noop transform', testGeneratorOutput, 2, false, true, true, true, 'duplex');258 test('Can use duplexes with error.stdio[*] as output, objectMode, noop transform', testGeneratorOutput, 3, false, false, true, true, 'duplex');259+test('Can use webTransforms with result.stdio[1]', testGeneratorOutput, 1, true, false, false, false, 'webTransform');260+test('Can use webTransforms with result.stdout', testGeneratorOutput, 1, true, true, false, false, 'webTransform');261+test('Can use webTransforms with result.stdio[2]', testGeneratorOutput, 2, true, false, false, false, 'webTransform');262+test('Can use webTransforms with result.stderr', testGeneratorOutput, 2, true, true, false, false, 'webTransform');263+test('Can use webTransforms with result.stdio[*] as output', testGeneratorOutput, 3, true, false, false, false, 'webTransform');264+test('Can use webTransforms with error.stdio[1]', testGeneratorOutput, 1, false, false, false, false, 'webTransform');265+test('Can use webTransforms with error.stdout', testGeneratorOutput, 1, false, true, false, false, 'webTransform');266+test('Can use webTransforms with error.stdio[2]', testGeneratorOutput, 2, false, false, false, false, 'webTransform');267+test('Can use webTransforms with error.stderr', testGeneratorOutput, 2, false, true, false, false, 'webTransform');268+test('Can use webTransforms with error.stdio[*] as output', testGeneratorOutput, 3, false, false, false, false, 'webTransform');269+test('Can use webTransforms with result.stdio[1], objectMode', testGeneratorOutput, 1, true, false, true, false, 'webTransform');270+test('Can use webTransforms with result.stdout, objectMode', testGeneratorOutput, 1, true, true, true, false, 'webTransform');271+test('Can use webTransforms with result.stdio[2], objectMode', testGeneratorOutput, 2, true, false, true, false, 'webTransform');272+test('Can use webTransforms with result.stderr, objectMode', testGeneratorOutput, 2, true, true, true, false, 'webTransform');273+test('Can use webTransforms with result.stdio[*] as output, objectMode', testGeneratorOutput, 3, true, false, true, false, 'webTransform');274+test('Can use webTransforms with error.stdio[1], objectMode', testGeneratorOutput, 1, false, false, true, false, 'webTransform');275+test('Can use webTransforms with error.stdout, objectMode', testGeneratorOutput, 1, false, true, true, false, 'webTransform');276+test('Can use webTransforms with error.stdio[2], objectMode', testGeneratorOutput, 2, false, false, true, false, 'webTransform');277+test('Can use webTransforms with error.stderr, objectMode', testGeneratorOutput, 2, false, true, true, false, 'webTransform');278+test('Can use webTransforms with error.stdio[*] as output, objectMode', testGeneratorOutput, 3, false, false, true, false, 'webTransform');279+test('Can use webTransforms with result.stdio[1], noop transform', testGeneratorOutput, 1, true, false, false, true, 'webTransform');280+test('Can use webTransforms with result.stdout, noop transform', testGeneratorOutput, 1, true, true, false, true, 'webTransform');281+test('Can use webTransforms with result.stdio[2], noop transform', testGeneratorOutput, 2, true, false, false, true, 'webTransform');282+test('Can use webTransforms with result.stderr, noop transform', testGeneratorOutput, 2, true, true, false, true, 'webTransform');283+test('Can use webTransforms with result.stdio[*] as output, noop transform', testGeneratorOutput, 3, true, false, false, true, 'webTransform');284+test('Can use webTransforms with error.stdio[1], noop transform', testGeneratorOutput, 1, false, false, false, true, 'webTransform');285+test('Can use webTransforms with error.stdout, noop transform', testGeneratorOutput, 1, false, true, false, true, 'webTransform');286+test('Can use webTransforms with error.stdio[2], noop transform', testGeneratorOutput, 2, false, false, false, true, 'webTransform');287+test('Can use webTransforms with error.stderr, noop transform', testGeneratorOutput, 2, false, true, false, true, 'webTransform');288+test('Can use webTransforms with error.stdio[*] as output, noop transform', testGeneratorOutput, 3, false, false, false, true, 'webTransform');289+test('Can use webTransforms with result.stdio[1], objectMode, noop transform', testGeneratorOutput, 1, true, false, true, true, 'webTransform');290+test('Can use webTransforms with result.stdout, objectMode, noop transform', testGeneratorOutput, 1, true, true, true, true, 'webTransform');291+test('Can use webTransforms with result.stdio[2], objectMode, noop transform', testGeneratorOutput, 2, true, false, true, true, 'webTransform');292+test('Can use webTransforms with result.stderr, objectMode, noop transform', testGeneratorOutput, 2, true, true, true, true, 'webTransform');293+test('Can use webTransforms with result.stdio[*] as output, objectMode, noop transform', testGeneratorOutput, 3, true, false, true, true, 'webTransform');294+test('Can use webTransforms with error.stdio[1], objectMode, noop transform', testGeneratorOutput, 1, false, false, true, true, 'webTransform');295+test('Can use webTransforms with error.stdout, objectMode, noop transform', testGeneratorOutput, 1, false, true, true, true, 'webTransform');296+test('Can use webTransforms with error.stdio[2], objectMode, noop transform', testGeneratorOutput, 2, false, false, true, true, 'webTransform');297+test('Can use webTransforms with error.stderr, objectMode, noop transform', testGeneratorOutput, 2, false, true, true, true, 'webTransform');298+test('Can use webTransforms with error.stdio[*] as output, objectMode, noop transform', testGeneratorOutput, 3, false, false, true, true, 'webTransform');299 300 // eslint-disable-next-line max-params301 const testGeneratorOutputPipe = async (t, fdNumber, useShortcutProperty, objectMode, addNoopTransform, type) => {302 const {generators, output, getStreamMethod} = getOutputObjectMode(objectMode, addNoopTransform, type, true);42 unmodified lines345 test('Can use duplexes with subprocess.stdout, objectMode, noop transform', testGeneratorOutputPipe, 1, true, true, true, 'duplex');346 test('Can use duplexes with subprocess.stdio[2], objectMode, noop transform', testGeneratorOutputPipe, 2, false, true, true, 'duplex');347 test('Can use duplexes with subprocess.stderr, objectMode, noop transform', testGeneratorOutputPipe, 2, true, true, true, 'duplex');348 test('Can use duplexes with subprocess.stdio[*] as output, objectMode, noop transform', testGeneratorOutputPipe, 3, false, true, true, 'duplex');349+test('Can use webTransforms with subprocess.stdio[1]', testGeneratorOutputPipe, 1, false, false, false, 'webTransform');350+test('Can use webTransforms with subprocess.stdout', testGeneratorOutputPipe, 1, true, false, false, 'webTransform');351+test('Can use webTransforms with subprocess.stdio[2]', testGeneratorOutputPipe, 2, false, false, false, 'webTransform');352+test('Can use webTransforms with subprocess.stderr', testGeneratorOutputPipe, 2, true, false, false, 'webTransform');353+test('Can use webTransforms with subprocess.stdio[*] as output', testGeneratorOutputPipe, 3, false, false, false, 'webTransform');354+test('Can use webTransforms with subprocess.stdio[1], objectMode', testGeneratorOutputPipe, 1, false, true, false, 'webTransform');355+test('Can use webTransforms with subprocess.stdout, objectMode', testGeneratorOutputPipe, 1, true, true, false, 'webTransform');356+test('Can use webTransforms with subprocess.stdio[2], objectMode', testGeneratorOutputPipe, 2, false, true, false, 'webTransform');357+test('Can use webTransforms with subprocess.stderr, objectMode', testGeneratorOutputPipe, 2, true, true, false, 'webTransform');358+test('Can use webTransforms with subprocess.stdio[*] as output, objectMode', testGeneratorOutputPipe, 3, false, true, false, 'webTransform');359+test('Can use webTransforms with subprocess.stdio[1], noop transform', testGeneratorOutputPipe, 1, false, false, true, 'webTransform');360+test('Can use webTransforms with subprocess.stdout, noop transform', testGeneratorOutputPipe, 1, true, false, true, 'webTransform');361+test('Can use webTransforms with subprocess.stdio[2], noop transform', testGeneratorOutputPipe, 2, false, false, true, 'webTransform');362+test('Can use webTransforms with subprocess.stderr, noop transform', testGeneratorOutputPipe, 2, true, false, true, 'webTransform');363+test('Can use webTransforms with subprocess.stdio[*] as output, noop transform', testGeneratorOutputPipe, 3, false, false, true, 'webTransform');364+test('Can use webTransforms with subprocess.stdio[1], objectMode, noop transform', testGeneratorOutputPipe, 1, false, true, true, 'webTransform');365+test('Can use webTransforms with subprocess.stdout, objectMode, noop transform', testGeneratorOutputPipe, 1, true, true, true, 'webTransform');366+test('Can use webTransforms with subprocess.stdio[2], objectMode, noop transform', testGeneratorOutputPipe, 2, false, true, true, 'webTransform');367+test('Can use webTransforms with subprocess.stderr, objectMode, noop transform', testGeneratorOutputPipe, 2, true, true, true, 'webTransform');368+test('Can use webTransforms with subprocess.stdio[*] as output, objectMode, noop transform', testGeneratorOutputPipe, 3, false, true, true, 'webTransform');369 370 const getAllStdioOption = (stdioOption, encoding, objectMode) => {371 if (stdioOption) {372 return 'pipe';93 unmodified lines466 };467 468 test('Can use generators with input option', testInputOption, 'generator');469 test('Can use duplexes with input option', testInputOption, 'duplex');470+test('Can use webTransforms with input option', testInputOption, 'webTransform');471 472 const testInputFile = async (t, getOptions, reversed) => {473 const filePath = tempfile();474 await writeFile(filePath, foobarString);9 unmodified lines484 test('Can use generators with inputFile option', testInputFile, filePath => ({inputFile: filePath, stdin: uppercaseGenerator()}), false);485 test('Can use duplexes with a file as input', testInputFile, filePath => ({stdin: [{file: filePath}, uppercaseBufferDuplex()]}), false);486 test('Can use duplexes with a file as input, reversed', testInputFile, filePath => ({stdin: [{file: filePath}, uppercaseBufferDuplex()]}), true);487 test('Can use duplexes with inputFile option', testInputFile, filePath => ({inputFile: filePath, stdin: uppercaseBufferDuplex()}), false);488+test('Can use webTransforms with a file as input', testInputFile, filePath => ({stdin: [{file: filePath}, uppercaseBufferWebTransform()]}), false);489+test('Can use webTransforms with a file as input, reversed', testInputFile, filePath => ({stdin: [{file: filePath}, uppercaseBufferWebTransform()]}), true);490+test('Can use webTransforms with inputFile option', testInputFile, filePath => ({inputFile: filePath, stdin: uppercaseBufferWebTransform()}), false);491 492 const testOutputFile = async (t, reversed, type) => {493 const filePath = tempfile();494 const stdoutOption = [generatorsMap[type].uppercaseBuffer(false, true), {file: filePath}];7 unmodified lines502 test('Can use generators with a file as output', testOutputFile, false, 'generator');503 test('Can use generators with a file as output, reversed', testOutputFile, true, 'generator');504 test('Can use duplexes with a file as output', testOutputFile, false, 'duplex');505 test('Can use duplexes with a file as output, reversed', testOutputFile, true, 'duplex');506+test('Can use webTransforms with a file as output', testOutputFile, false, 'webTransform');507+test('Can use webTransforms with a file as output, reversed', testOutputFile, true, 'webTransform');508 509 const testWritableDestination = async (t, type) => {510 const passThrough = new PassThrough();511 const [{stdout}, streamOutput] = await Promise.all([5 unmodified lines517 };518 519 test('Can use generators to a Writable stream', testWritableDestination, 'generator');520 test('Can use duplexes to a Writable stream', testWritableDestination, 'duplex');521+test('Can use webTransforms to a Writable stream', testWritableDestination, 'webTransform');522 523 const testReadableSource = async (t, type) => {524 const passThrough = new PassThrough();525 const subprocess = execa('stdin-fd.js', ['0'], {stdin: [passThrough, generatorsMap[type].uppercase()]});3 unmodified lines529 };530 531 test('Can use generators from a Readable stream', testReadableSource, 'generator');532 test('Can use duplexes from a Readable stream', testReadableSource, 'duplex');533+test('Can use webTransforms from a Readable stream', testReadableSource, 'webTransform');534 535 const testInherit = async (t, type) => {536 const {stdout} = await execa('nested-inherit.js', [type]);537 t.is(stdout, foobarUppercase);538 };539 540 test('Can use generators with "inherit"', testInherit, 'generator');541 test('Can use duplexes with "inherit"', testInherit, 'duplex');542+test('Can use webTransforms with "inherit"', testInherit, 'webTransform');543 544 const testAppendInput = async (t, reversed, type) => {545 const stdin = [foobarUint8Array, generatorsMap[type].uppercase(), generatorsMap[type].append()];546 const reversedStdin = reversed ? stdin.reverse() : stdin;5 unmodified lines552 test('Can use multiple generators as input', testAppendInput, false, 'generator');553 test('Can use multiple generators as input, reversed', testAppendInput, true, 'generator');554 test('Can use multiple duplexes as input', testAppendInput, false, 'duplex');555 test('Can use multiple duplexes as input, reversed', testAppendInput, true, 'duplex');556+test('Can use multiple webTransforms as input', testAppendInput, false, 'webTransform');557+test('Can use multiple webTransforms as input, reversed', testAppendInput, true, 'webTransform');558 559 const testAppendOutput = async (t, reversed, type) => {560 const stdoutOption = [generatorsMap[type].uppercase(), generatorsMap[type].append()];561 const reversedStdoutOption = reversed ? stdoutOption.reverse() : stdoutOption;5 unmodified lines567 test('Can use multiple generators as output', testAppendOutput, false, 'generator');568 test('Can use multiple generators as output, reversed', testAppendOutput, true, 'generator');569 test('Can use multiple duplexes as output', testAppendOutput, false, 'duplex');570 test('Can use multiple duplexes as output, reversed', testAppendOutput, true, 'duplex');571+test('Can use multiple webTransforms as output', testAppendOutput, false, 'webTransform');572+test('Can use multiple webTransforms as output, reversed', testAppendOutput, true, 'webTransform');573 574 const testTwoGenerators = async (t, producesTwo, firstGenerator, secondGenerator = firstGenerator) => {575 const {stdout} = await execa('noop-fd.js', ['1', foobarString], {stdout: [firstGenerator, secondGenerator]});576 const expectedSuffix = producesTwo ? `${casedSuffix}${casedSuffix}` : casedSuffix;2 unmodified lines579 580 test('Can use multiple identical generators', testTwoGenerators, true, appendGenerator().transform);581 test('Can use multiple identical generators, options object', testTwoGenerators, true, appendGenerator());582 test('Ignore duplicate identical duplexes', testTwoGenerators, false, appendDuplex());583+test('Ignore duplicate identical webTransforms', testTwoGenerators, false, appendWebTransform());584 test('Can use multiple generators with duplexes', testTwoGenerators, true, appendGenerator(false, false, true), appendDuplex());585+test('Can use multiple generators with webTransforms', testTwoGenerators, true, appendGenerator(false, false, true), appendWebTransform());586+test('Can use multiple duplexes with webTransforms', testTwoGenerators, true, appendDuplex(), appendWebTransform());587 483-const testGeneratorSyntax = async (t, generator) => {484- const {stdout} = await execa('noop-fd.js', ['1', foobarString], {stdout: generator});588+const testGeneratorSyntax = async (t, type, usePlainObject) => {589+ const transform = generatorsMap[type].uppercase();590+ const {stdout} = await execa('noop-fd.js', ['1', foobarString], {stdout: usePlainObject ? transform : transform.transform});591 t.is(stdout, foobarUppercase);592 };593 488-test('Can pass generators with an options plain object', testGeneratorSyntax, uppercaseGenerator());489-test('Can pass generators without an options plain object', testGeneratorSyntax, uppercaseGenerator().transform);594+test('Can pass generators with an options plain object', testGeneratorSyntax, 'generator', false);595+test('Can pass generators without an options plain object', testGeneratorSyntax, 'generator', true);596+test('Can pass webTransforms with an options plain object', testGeneratorSyntax, 'webTransform', true);597+test('Can pass webTransforms without an options plain object', testGeneratorSyntax, 'webTransform', false);modified:test/stdio/transform.js+9 added
87 unmodified lines88 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+test('WebTransform can filter by not calling push', testNoYield, 'webTransform', false, false, '');93+test('WebTransform can filter by not calling push, objectMode', testNoYield, 'webTransform', true, false, []);94 95 const testMultipleYields = async (t, type, final, binary) => {96 const {stdout} = await execa('noop-fd.js', ['1', foobarString], {stdout: convertTransformToFinal(generatorsMap[type].multipleYield(), final)});97 const newline = binary ? '' : '\n';2 unmodified lines100 101 test('Generator can yield "transform" multiple times at different moments', testMultipleYields, 'generator', false, false);102 test('Generator can yield "final" multiple times at different moments', testMultipleYields, 'generator', true, false);103 test('Duplex can push multiple times at different moments', testMultipleYields, 'duplex', false, true);104+test('WebTransform can push multiple times at different moments', testMultipleYields, 'webTransform', false, true);105 106 const partsPerChunk = 4;107 const chunksPerCall = 10;108 const callCount = 5;36 unmodified lines145 };146 147 test('Generators take "maxBuffer" into account', testMaxBuffer, 'generator');148 test('Duplexes take "maxBuffer" into account', testMaxBuffer, 'duplex');149+test('WebTransforms take "maxBuffer" into account', testMaxBuffer, 'webTransform');150 151 const testMaxBufferObject = async (t, type) => {152 const bigArray = Array.from({length: maxBuffer}).fill('.');153 const {stdout} = await execa('noop.js', {6 unmodified lines160 };161 162 test('Generators take "maxBuffer" into account, objectMode', testMaxBufferObject, 'generator');163 test('Duplexes take "maxBuffer" into account, objectMode', testMaxBufferObject, 'duplex');164+test('WebTransforms take "maxBuffer" into account, objectMode', testMaxBufferObject, 'webTransform');165 166 const testAsyncGenerators = async (t, type, final) => {167 const {stdout} = await execa('noop.js', {168 stdout: convertTransformToFinal(generatorsMap[type].timeout(1e2)(), final),3 unmodified lines172 173 test('Generators "transform" is awaited on success', testAsyncGenerators, 'generator', false);174 test('Generators "final" is awaited on success', testAsyncGenerators, 'generator', true);175 test('Duplex is awaited on success', testAsyncGenerators, 'duplex', false);176+test('WebTransform is awaited on success', testAsyncGenerators, 'webTransform', false);177 178 const testThrowingGenerator = async (t, type, final) => {179 await t.throwsAsync(180 execa('noop-fd.js', ['1', foobarString], {stdout: convertTransformToFinal(generatorsMap[type].throwing(), final)}),3 unmodified lines184 185 test('Generators "transform" errors make subprocess fail', testThrowingGenerator, 'generator', false);186 test('Generators "final" errors make subprocess fail', testThrowingGenerator, 'generator', true);187 test('Duplexes "transform" errors make subprocess fail', testThrowingGenerator, 'duplex', false);188+test('WebTransform "transform" errors make subprocess fail', testThrowingGenerator, 'webTransform', false);189 190 const testSingleErrorOutput = async (t, type) => {191 await t.throwsAsync(192 execa('noop-fd.js', ['1', foobarString], {stdout: [generatorsMap[type].noop(false), generatorsMap[type].throwing(), generatorsMap[type].noop(false)]}),2 unmodified lines195 };196 197 test('Generators errors make subprocess fail even when other output generators do not throw', testSingleErrorOutput, 'generator');198 test('Duplexes errors make subprocess fail even when other output generators do not throw', testSingleErrorOutput, 'duplex');199+test('WebTransform errors make subprocess fail even when other output generators do not throw', testSingleErrorOutput, 'webTransform');200 201 const testSingleErrorInput = async (t, type) => {202 const subprocess = execa('stdin-fd.js', ['0'], {stdin: [generatorsMap[type].noop(false), generatorsMap[type].throwing(), generatorsMap[type].noop(false)]});203 subprocess.stdin.write('foobar\n');1 unmodified line205 };206 207 test('Generators errors make subprocess fail even when other input generators do not throw', testSingleErrorInput, 'generator');208 test('Duplexes errors make subprocess fail even when other input generators do not throw', testSingleErrorInput, 'duplex');209+test('WebTransform errors make subprocess fail even when other input generators do not throw', testSingleErrorInput, 'webTransform');210 211 const testGeneratorCancel = async (t, error) => {212 const subprocess = execa('noop.js', {stdout: infiniteGenerator()});213 await once(subprocess.stdout, 'data');21 unmodified linesmodified:test/stdio/type.js+55 added-29 removed
1 unmodified line2 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 {uppercaseBufferWebTransform} from '../helpers/web-transform.js';7 import {generatorsMap} from '../helpers/map.js';8 import {setFixtureDir} from '../helpers/fixtures-dir.js';9 10 setFixtureDir();11 12 const testInvalidGenerator = (t, fdNumber, stdioOption) => {13 t.throws(() => {14 execa('empty.js', getStdio(fdNumber, {...noopGenerator(), ...stdioOption}));14- }, {message: /must be a generator/});15+ }, {message: 'final' in stdioOption ? /must be a generator/ : /must be a generator, a Duplex stream or a web TransformStream/});16 };17 18 test('Cannot use invalid "transform" with stdin', testInvalidGenerator, 0, {transform: true});19 test('Cannot use invalid "transform" with stdout', testInvalidGenerator, 1, {transform: true});21 unmodified lines41 test('Cannot use invalid "objectMode" with stdin, duplexes', testInvalidBinary, 0, 'objectMode', 'duplex');42 test('Cannot use invalid "objectMode" with stdout, duplexes', testInvalidBinary, 1, 'objectMode', 'duplex');43 test('Cannot use invalid "objectMode" with stderr, duplexes', testInvalidBinary, 2, 'objectMode', 'duplex');44 test('Cannot use invalid "objectMode" with stdio[*], duplexes', testInvalidBinary, 3, 'objectMode', 'duplex');45+test('Cannot use invalid "objectMode" with stdin, webTransforms', testInvalidBinary, 0, 'objectMode', 'webTransform');46+test('Cannot use invalid "objectMode" with stdout, webTransforms', testInvalidBinary, 1, 'objectMode', 'webTransform');47+test('Cannot use invalid "objectMode" with stderr, webTransforms', testInvalidBinary, 2, 'objectMode', 'webTransform');48+test('Cannot use invalid "objectMode" with stdio[*], webTransforms', testInvalidBinary, 3, 'objectMode', 'webTransform');49 50+// eslint-disable-next-line max-params45-const testUndefinedOption = (t, fdNumber, optionName, optionValue) => {51+const testUndefinedOption = (t, fdNumber, optionName, type, optionValue) => {52 t.throws(() => {47- execa('empty.js', getStdio(fdNumber, {...uppercaseBufferDuplex(), [optionName]: optionValue}));53+ execa('empty.js', getStdio(fdNumber, {...generatorsMap[type].uppercase(), [optionName]: optionValue}));54 }, {message: /can only be defined when using a generator/});55 };56 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);57+test('Cannot use "binary" with duplexes and stdin', testUndefinedOption, 0, 'binary', 'duplex', true);58+test('Cannot use "binary" with duplexes and stdout', testUndefinedOption, 1, 'binary', 'duplex', true);59+test('Cannot use "binary" with duplexes and stderr', testUndefinedOption, 2, 'binary', 'duplex', true);60+test('Cannot use "binary" with duplexes and stdio[*]', testUndefinedOption, 3, 'binary', 'duplex', true);61+test('Cannot use "final" with duplexes and stdin', testUndefinedOption, 0, 'final', 'duplex', uppercaseBufferDuplex().transform);62+test('Cannot use "final" with duplexes and stdout', testUndefinedOption, 1, 'final', 'duplex', uppercaseBufferDuplex().transform);63+test('Cannot use "final" with duplexes and stderr', testUndefinedOption, 2, 'final', 'duplex', uppercaseBufferDuplex().transform);64+test('Cannot use "final" with duplexes and stdio[*]', testUndefinedOption, 3, 'final', 'duplex', uppercaseBufferDuplex().transform);65+test('Cannot use "binary" with webTransforms and stdin', testUndefinedOption, 0, 'binary', 'webTransform', true);66+test('Cannot use "binary" with webTransforms and stdout', testUndefinedOption, 1, 'binary', 'webTransform', true);67+test('Cannot use "binary" with webTransforms and stderr', testUndefinedOption, 2, 'binary', 'webTransform', true);68+test('Cannot use "binary" with webTransforms and stdio[*]', testUndefinedOption, 3, 'binary', 'webTransform', true);69+test('Cannot use "final" with webTransforms and stdin', testUndefinedOption, 0, 'final', 'webTransform', uppercaseBufferWebTransform().transform);70+test('Cannot use "final" with webTransforms and stdout', testUndefinedOption, 1, 'final', 'webTransform', uppercaseBufferWebTransform().transform);71+test('Cannot use "final" with webTransforms and stderr', testUndefinedOption, 2, 'final', 'webTransform', uppercaseBufferWebTransform().transform);72+test('Cannot use "final" with webTransforms and stdio[*]', testUndefinedOption, 3, 'final', 'webTransform', uppercaseBufferWebTransform().transform);73 60-const testUndefinedFinal = (t, fdNumber, useTransform) => {74+const testUndefinedFinal = (t, fdNumber, type, useTransform) => {75 t.throws(() => {76 execa('empty.js', getStdio(fdNumber, {77 transform: useTransform ? uppercaseGenerator().transform : undefined,64- final: uppercaseBufferDuplex().transform,78+ final: generatorsMap[type].uppercase().transform,79 }));66- }, {message: /must not be a Duplex/});80+ }, {message: type === 'duplex' ? /must not be a Duplex/ : /must not be a web TransformStream/});81 };82 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);83+test('Cannot use "final" with duplexes and stdin, without transform', testUndefinedFinal, 0, 'duplex', false);84+test('Cannot use "final" with duplexes and stdout, without transform', testUndefinedFinal, 1, 'duplex', false);85+test('Cannot use "final" with duplexes and stderr, without transform', testUndefinedFinal, 2, 'duplex', false);86+test('Cannot use "final" with duplexes and stdio[*], without transform', testUndefinedFinal, 3, 'duplex', false);87+test('Cannot use "final" with duplexes and stdin, with transform', testUndefinedFinal, 0, 'duplex', true);88+test('Cannot use "final" with duplexes and stdout, with transform', testUndefinedFinal, 1, 'duplex', true);89+test('Cannot use "final" with duplexes and stderr, with transform', testUndefinedFinal, 2, 'duplex', true);90+test('Cannot use "final" with duplexes and stdio[*], with transform', testUndefinedFinal, 3, 'duplex', true);91+test('Cannot use "final" with webTransforms and stdin, without transform', testUndefinedFinal, 0, 'webTransform', false);92+test('Cannot use "final" with webTransforms and stdout, without transform', testUndefinedFinal, 1, 'webTransform', false);93+test('Cannot use "final" with webTransforms and stderr, without transform', testUndefinedFinal, 2, 'webTransform', false);94+test('Cannot use "final" with webTransforms and stdio[*], without transform', testUndefinedFinal, 3, 'webTransform', false);95+test('Cannot use "final" with webTransforms and stdin, with transform', testUndefinedFinal, 0, 'webTransform', true);96+test('Cannot use "final" with webTransforms and stdout, with transform', testUndefinedFinal, 1, 'webTransform', true);97+test('Cannot use "final" with webTransforms and stderr, with transform', testUndefinedFinal, 2, 'webTransform', true);98+test('Cannot use "final" with webTransforms and stdio[*], with transform', testUndefinedFinal, 3, 'webTransform', true);99 100 const testSyncMethodsGenerator = (t, fdNumber) => {101 t.throws(() => {102 execaSync('empty.js', getStdio(fdNumber, uppercaseGenerator()));4 unmodified lines107 test('Cannot use generators with sync methods and stdout', testSyncMethodsGenerator, 1);108 test('Cannot use generators with sync methods and stderr', testSyncMethodsGenerator, 2);109 test('Cannot use generators with sync methods and stdio[*]', testSyncMethodsGenerator, 3);110 89-const testSyncMethodsDuplex = (t, fdNumber) => {111+const testSyncMethodsDuplex = (t, fdNumber, type) => {112 t.throws(() => {91- execaSync('empty.js', getStdio(fdNumber, uppercaseBufferDuplex()));92- }, {message: /cannot be a Duplex stream/});113+ execaSync('empty.js', getStdio(fdNumber, generatorsMap[type].uppercase()));114+ }, {message: type === 'duplex' ? /cannot be a Duplex stream/ : /cannot be a web TransformStream/});115 };116 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);117+test('Cannot use duplexes with sync methods and stdin', testSyncMethodsDuplex, 0, 'duplex');118+test('Cannot use duplexes with sync methods and stdout', testSyncMethodsDuplex, 1, 'duplex');119+test('Cannot use duplexes with sync methods and stderr', testSyncMethodsDuplex, 2, 'duplex');120+test('Cannot use duplexes with sync methods and stdio[*]', testSyncMethodsDuplex, 3, 'duplex');121+test('Cannot use webTransforms with sync methods and stdin', testSyncMethodsDuplex, 0, 'webTransform');122+test('Cannot use webTransforms with sync methods and stdout', testSyncMethodsDuplex, 1, 'webTransform');123+test('Cannot use webTransforms with sync methods and stderr', testSyncMethodsDuplex, 2, 'webTransform');124+test('Cannot use webTransforms with sync methods and stdio[*]', testSyncMethodsDuplex, 3, 'webTransform');added:test/stdio/web-transform.js+23 added
1+import {promisify} from 'node:util';2+import {gunzip} from 'node:zlib';3+import test from 'ava';4+import {execa} from '../../index.js';5+import {setFixtureDir} from '../helpers/fixtures-dir.js';6+import {foobarString, foobarUtf16Uint8Array, foobarUint8Array} from '../helpers/input.js';7+8+setFixtureDir();9+10+test('Can use CompressionStream()', async t => {11+ const {stdout} = await execa('noop-fd.js', ['1', foobarString], {stdout: new CompressionStream('gzip'), encoding: 'buffer'});12+ const decompressedStdout = await promisify(gunzip)(stdout);13+ t.is(decompressedStdout.toString(), foobarString);14+});15+16+test('Can use TextDecoderStream()', async t => {17+ const {stdout} = await execa('stdin.js', {18+ input: foobarUtf16Uint8Array,19+ stdout: new TextDecoderStream('utf-16le'),20+ encoding: 'buffer',21+ });22+ t.deepEqual(stdout, foobarUint8Array);23+});modified:index.d.ts+13 added-6 removed
35 unmodified lines36 transform: Duplex;37 objectMode?: boolean;38 };39 40+type WebTransform = {41+ transform: TransformStream;42+ objectMode?: boolean;43+};44+45 type CommonStdioOption<IsSync extends boolean = boolean> =46 | BaseStdioOption47 | 'ipc'48 | number2 unmodified lines51 | {file: string}52 | IfAsync<IsSync,53 | GeneratorTransform54 | GeneratorTransformFull50- | DuplexTransform>;55+ | DuplexTransform56+ | WebTransform57+ | TransformStream>;58 59 type InputStdioOption<IsSync extends boolean = boolean> =60 | Uint8Array61 | Readable70 unmodified lines132 ? OutputOptions[number]133 : OutputOptions134 >;135 129-type IsObjectOutputOption<OutputOption extends StdioSingleOption> = OutputOption extends GeneratorTransformFull136+type IsObjectOutputOption<OutputOption extends StdioSingleOption> = OutputOption extends GeneratorTransformFull | WebTransform137 ? BooleanObjectMode<OutputOption['objectMode']>138 : OutputOption extends DuplexTransform139 ? DuplexObjectMode<OutputOption>140 : false;141 135-type BooleanObjectMode<ObjectModeOption extends GeneratorTransformFull['objectMode']> = ObjectModeOption extends true ? true : false;142+type BooleanObjectMode<ObjectModeOption extends boolean | undefined> = ObjectModeOption extends true ? true : false;143 144 type DuplexObjectMode<OutputOption extends DuplexTransform> = OutputOption['objectMode'] extends boolean145 ? OutputOption['objectMode']146 : OutputOption['transform']['readableObjectMode'];216 unmodified lines363 - an `Uint8Array`.364 365 This can be an [array of values](https://github.com/sindresorhus/execa#redirect-stdinstdoutstderr-to-multiple-destinations) such as `['inherit', 'pipe']` or `[filePath, 'pipe']`.366 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)367+ This can also be a generator function or a [`Duplex`](https://nodejs.org/api/stream.html#class-streamduplex) or a [web `TransformStream`](https://developer.mozilla.org/en-US/docs/Web/API/TransformStream) to transform the input. [Learn more.](https://github.com/sindresorhus/execa/tree/main/docs/transform.md)368 369 @default `inherit` with `$`, `pipe` otherwise370 */371 readonly stdin?: StdinOption<IsSync>;11 unmodified lines383 - a web [`WritableStream`](https://developer.mozilla.org/en-US/docs/Web/API/WritableStream).384 385 This can be an [array of values](https://github.com/sindresorhus/execa#redirect-stdinstdoutstderr-to-multiple-destinations) such as `['inherit', 'pipe']` or `[filePath, 'pipe']`.386 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)387+ This can also be a generator function or a [`Duplex`](https://nodejs.org/api/stream.html#class-streamduplex) or a [web `TransformStream`](https://developer.mozilla.org/en-US/docs/Web/API/TransformStream) to transform the output. [Learn more.](https://github.com/sindresorhus/execa/tree/main/docs/transform.md)388 389 @default 'pipe'390 */391 readonly stdout?: StdoutStderrOption<IsSync>;11 unmodified lines403 - a web [`WritableStream`](https://developer.mozilla.org/en-US/docs/Web/API/WritableStream).404 405 This can be an [array of values](https://github.com/sindresorhus/execa#redirect-stdinstdoutstderr-to-multiple-destinations) such as `['inherit', 'pipe']` or `[filePath, 'pipe']`.406 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)407+ This can also be a generator function or a [`Duplex`](https://nodejs.org/api/stream.html#class-streamduplex) or a [web `TransformStream`](https://developer.mozilla.org/en-US/docs/Web/API/TransformStream) to transform the output. [Learn more.](https://github.com/sindresorhus/execa/tree/main/docs/transform.md)408 409 @default 'pipe'410 */411 readonly stderr?: StdoutStderrOption<IsSync>;1191 unmodified linesmodified:index.test-d.ts+86 added
27 unmodified lines28 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+const webTransformInstance = new TransformStream();33+const webTransform = {transform: webTransformInstance};34+const webTransformObject = {transform: webTransformInstance, objectMode: true as const};35+const webTransformNotObject = {transform: webTransformInstance, objectMode: false as const};36 37 type AnySyncChunk = string | Uint8Array | undefined;38 type AnyChunk = AnySyncChunk | string[] | unknown[];39 expectType<Writable | null>({} as ExecaSubprocess['stdin']);637 unmodified lines677 const objectTransformLinesStdoutResult = await execa('unicorns', {lines: true, stdout: {transform: objectGenerator, final: objectFinal, objectMode: true}});678 expectType<unknown[]>(objectTransformLinesStdoutResult.stdout);679 expectType<[undefined, unknown[], string[]]>(objectTransformLinesStdoutResult.stdio);680 681+ const objectWebTransformStdoutResult = await execa('unicorns', {stdout: webTransformObject});682+ expectType<unknown[]>(objectWebTransformStdoutResult.stdout);683+ expectType<[undefined, unknown[], string]>(objectWebTransformStdoutResult.stdio);684+685 const objectDuplexStdoutResult = await execa('unicorns', {stdout: duplexObject});686 expectType<unknown[]>(objectDuplexStdoutResult.stdout);687 expectType<[undefined, unknown[], string]>(objectDuplexStdoutResult.stdio);688 4 unmodified lines693 const objectTransformStdoutResult = await execa('unicorns', {stdout: {transform: objectGenerator, final: objectFinal, objectMode: true}});694 expectType<unknown[]>(objectTransformStdoutResult.stdout);695 expectType<[undefined, unknown[], string]>(objectTransformStdoutResult.stdio);696 697+ const objectWebTransformStderrResult = await execa('unicorns', {stderr: webTransformObject});698+ expectType<unknown[]>(objectWebTransformStderrResult.stderr);699+ expectType<[undefined, string, unknown[]]>(objectWebTransformStderrResult.stdio);700+701 const objectDuplexStderrResult = await execa('unicorns', {stderr: duplexObject});702 expectType<unknown[]>(objectDuplexStderrResult.stderr);703 expectType<[undefined, string, unknown[]]>(objectDuplexStderrResult.stdio);704 4 unmodified lines709 const objectTransformStderrResult = await execa('unicorns', {stderr: {transform: objectGenerator, final: objectFinal, objectMode: true}});710 expectType<unknown[]>(objectTransformStderrResult.stderr);711 expectType<[undefined, string, unknown[]]>(objectTransformStderrResult.stdio);712 713+ const objectWebTransformStdioResult = await execa('unicorns', {stdio: ['pipe', 'pipe', webTransformObject]});714+ expectType<unknown[]>(objectWebTransformStdioResult.stderr);715+ expectType<[undefined, string, unknown[]]>(objectWebTransformStdioResult.stdio);716+717 const objectDuplexStdioResult = await execa('unicorns', {stdio: ['pipe', 'pipe', duplexObject]});718 expectType<unknown[]>(objectDuplexStdioResult.stderr);719 expectType<[undefined, string, unknown[]]>(objectDuplexStdioResult.stdio);720 4 unmodified lines725 const objectTransformStdioResult = await execa('unicorns', {stdio: ['pipe', 'pipe', {transform: objectGenerator, final: objectFinal, objectMode: true}]});726 expectType<unknown[]>(objectTransformStdioResult.stderr);727 expectType<[undefined, string, unknown[]]>(objectTransformStdioResult.stdio);728 729+ const singleObjectWebTransformStdoutResult = await execa('unicorns', {stdout: [webTransformObject]});730+ expectType<unknown[]>(singleObjectWebTransformStdoutResult.stdout);731+ expectType<[undefined, unknown[], string]>(singleObjectWebTransformStdoutResult.stdio);732+733 const singleObjectDuplexStdoutResult = await execa('unicorns', {stdout: [duplexObject]});734 expectType<unknown[]>(singleObjectDuplexStdoutResult.stdout);735 expectType<[undefined, unknown[], string]>(singleObjectDuplexStdoutResult.stdio);736 4 unmodified lines741 const singleObjectTransformStdoutResult = await execa('unicorns', {stdout: [{transform: objectGenerator, final: objectFinal, objectMode: true}]});742 expectType<unknown[]>(singleObjectTransformStdoutResult.stdout);743 expectType<[undefined, unknown[], string]>(singleObjectTransformStdoutResult.stdio);744 745+ const manyObjectWebTransformStdoutResult = await execa('unicorns', {stdout: [webTransformObject, webTransformObject]});746+ expectType<unknown[]>(manyObjectWebTransformStdoutResult.stdout);747+ expectType<[undefined, unknown[], string]>(manyObjectWebTransformStdoutResult.stdio);748+749 const manyObjectDuplexStdoutResult = await execa('unicorns', {stdout: [duplexObject, duplexObject]});750 expectType<unknown[]>(manyObjectDuplexStdoutResult.stdout);751 expectType<[undefined, unknown[], string]>(manyObjectDuplexStdoutResult.stdio);752 4 unmodified lines757 const manyObjectTransformStdoutResult = await execa('unicorns', {stdout: [{transform: objectGenerator, final: objectFinal, objectMode: true}, {transform: objectGenerator, final: objectFinal, objectMode: true}]});758 expectType<unknown[]>(manyObjectTransformStdoutResult.stdout);759 expectType<[undefined, unknown[], string]>(manyObjectTransformStdoutResult.stdio);760 761+ const falseObjectWebTransformStdoutResult = await execa('unicorns', {stdout: webTransformNotObject});762+ expectType<string>(falseObjectWebTransformStdoutResult.stdout);763+ expectType<[undefined, string, string]>(falseObjectWebTransformStdoutResult.stdio);764+765 const falseObjectDuplexStdoutResult = await execa('unicorns', {stdout: duplexNotObject});766 expectType<string>(falseObjectDuplexStdoutResult.stdout);767 expectType<[undefined, string, string]>(falseObjectDuplexStdoutResult.stdio);768 4 unmodified lines773 const falseObjectTransformStdoutResult = await execa('unicorns', {stdout: {transform: objectGenerator, final: objectFinal, objectMode: false}});774 expectType<string>(falseObjectTransformStdoutResult.stdout);775 expectType<[undefined, string, string]>(falseObjectTransformStdoutResult.stdio);776 777+ const falseObjectWebTransformStderrResult = await execa('unicorns', {stderr: webTransformNotObject});778+ expectType<string>(falseObjectWebTransformStderrResult.stderr);779+ expectType<[undefined, string, string]>(falseObjectWebTransformStderrResult.stdio);780+781 const falseObjectDuplexStderrResult = await execa('unicorns', {stderr: duplexNotObject});782 expectType<string>(falseObjectDuplexStderrResult.stderr);783 expectType<[undefined, string, string]>(falseObjectDuplexStderrResult.stdio);784 4 unmodified lines789 const falseObjectTransformStderrResult = await execa('unicorns', {stderr: {transform: objectGenerator, final: objectFinal, objectMode: false}});790 expectType<string>(falseObjectTransformStderrResult.stderr);791 expectType<[undefined, string, string]>(falseObjectTransformStderrResult.stdio);792 793+ const falseObjectWebTransformStdioResult = await execa('unicorns', {stdio: ['pipe', 'pipe', webTransformNotObject]});794+ expectType<string>(falseObjectWebTransformStdioResult.stderr);795+ expectType<[undefined, string, string]>(falseObjectWebTransformStdioResult.stdio);796+797 const falseObjectDuplexStdioResult = await execa('unicorns', {stdio: ['pipe', 'pipe', duplexNotObject]});798 expectType<string>(falseObjectDuplexStdioResult.stderr);799 expectType<[undefined, string, string]>(falseObjectDuplexStdioResult.stdio);800 4 unmodified lines805 const falseObjectTransformStdioResult = await execa('unicorns', {stdio: ['pipe', 'pipe', {transform: objectGenerator, final: objectFinal, objectMode: false}]});806 expectType<string>(falseObjectTransformStdioResult.stderr);807 expectType<[undefined, string, string]>(falseObjectTransformStdioResult.stdio);808 809+ const topObjectWebTransformStdoutResult = await execa('unicorns', {stdout: webTransformInstance});810+ expectType<string>(topObjectWebTransformStdoutResult.stdout);811+ expectType<[undefined, string, string]>(topObjectWebTransformStdoutResult.stdio);812+813+ const undefinedObjectWebTransformStdoutResult = await execa('unicorns', {stdout: webTransform});814+ expectType<string>(undefinedObjectWebTransformStdoutResult.stdout);815+ expectType<[undefined, string, string]>(undefinedObjectWebTransformStdoutResult.stdio);816+817 const undefinedObjectDuplexStdoutResult = await execa('unicorns', {stdout: duplex});818 expectType<string | unknown[]>(undefinedObjectDuplexStdoutResult.stdout);819 expectType<[undefined, string | unknown[], string]>(undefinedObjectDuplexStdoutResult.stdio);820 501 unmodified lines1322 execa('unicorns', {stdin: [duplexTransform]});1323 expectError(execaSync('unicorns', {stdin: [duplexTransform]}));1324 expectError(execa('unicorns', {stdin: {...duplex, objectMode: 'true'}}));1325 expectError(execaSync('unicorns', {stdin: {...duplex, objectMode: 'true'}}));1326+execa('unicorns', {stdin: webTransformInstance});1327+expectError(execaSync('unicorns', {stdin: webTransformInstance}));1328+execa('unicorns', {stdin: [webTransformInstance]});1329+expectError(execaSync('unicorns', {stdin: [webTransformInstance]}));1330+execa('unicorns', {stdin: webTransform});1331+expectError(execaSync('unicorns', {stdin: webTransform}));1332+execa('unicorns', {stdin: [webTransform]});1333+expectError(execaSync('unicorns', {stdin: [webTransform]}));1334+expectError(execa('unicorns', {stdin: {...webTransform, objectMode: 'true'}}));1335+expectError(execaSync('unicorns', {stdin: {...webTransform, objectMode: 'true'}}));1336 execa('unicorns', {stdin: unknownGenerator});1337 expectError(execaSync('unicorns', {stdin: unknownGenerator}));1338 execa('unicorns', {stdin: [unknownGenerator]});1339 expectError(execaSync('unicorns', {stdin: [unknownGenerator]}));105 unmodified lines1445 execa('unicorns', {stdout: [duplexTransform]});1446 expectError(execaSync('unicorns', {stdout: [duplexTransform]}));1447 expectError(execa('unicorns', {stdout: {...duplex, objectMode: 'true'}}));1448 expectError(execaSync('unicorns', {stdout: {...duplex, objectMode: 'true'}}));1449+execa('unicorns', {stdout: webTransformInstance});1450+expectError(execaSync('unicorns', {stdout: webTransformInstance}));1451+execa('unicorns', {stdout: [webTransformInstance]});1452+expectError(execaSync('unicorns', {stdout: [webTransformInstance]}));1453+execa('unicorns', {stdout: webTransform});1454+expectError(execaSync('unicorns', {stdout: webTransform}));1455+execa('unicorns', {stdout: [webTransform]});1456+expectError(execaSync('unicorns', {stdout: [webTransform]}));1457+expectError(execa('unicorns', {stdout: {...webTransform, objectMode: 'true'}}));1458+expectError(execaSync('unicorns', {stdout: {...webTransform, objectMode: 'true'}}));1459 execa('unicorns', {stdout: unknownGenerator});1460 expectError(execaSync('unicorns', {stdout: unknownGenerator}));1461 execa('unicorns', {stdout: [unknownGenerator]});1462 expectError(execaSync('unicorns', {stdout: [unknownGenerator]}));105 unmodified lines1568 execa('unicorns', {stderr: [duplexTransform]});1569 expectError(execaSync('unicorns', {stderr: [duplexTransform]}));1570 expectError(execa('unicorns', {stderr: {...duplex, objectMode: 'true'}}));1571 expectError(execaSync('unicorns', {stderr: {...duplex, objectMode: 'true'}}));1572+execa('unicorns', {stderr: webTransformInstance});1573+expectError(execaSync('unicorns', {stderr: webTransformInstance}));1574+execa('unicorns', {stderr: [webTransformInstance]});1575+expectError(execaSync('unicorns', {stderr: [webTransformInstance]}));1576+execa('unicorns', {stderr: webTransform});1577+expectError(execaSync('unicorns', {stderr: webTransform}));1578+execa('unicorns', {stderr: [webTransform]});1579+expectError(execaSync('unicorns', {stderr: [webTransform]}));1580+expectError(execa('unicorns', {stderr: {...webTransform, objectMode: 'true'}}));1581+expectError(execaSync('unicorns', {stderr: {...webTransform, objectMode: 'true'}}));1582 execa('unicorns', {stderr: unknownGenerator});1583 expectError(execaSync('unicorns', {stderr: unknownGenerator}));1584 execa('unicorns', {stderr: [unknownGenerator]});1585 expectError(execaSync('unicorns', {stderr: [unknownGenerator]}));83 unmodified lines1669 expectError(execa('unicorns', {stdio: duplex}));1670 expectError(execaSync('unicorns', {stdio: duplex}));1671 expectError(execa('unicorns', {stdio: duplexTransform}));1672 expectError(execaSync('unicorns', {stdio: duplexTransform}));1673+expectError(execa('unicorns', {stdio: webTransformInstance}));1674+expectError(execaSync('unicorns', {stdio: webTransformInstance}));1675+expectError(execa('unicorns', {stdio: webTransform}));1676+expectError(execaSync('unicorns', {stdio: webTransform}));1677 expectError(execa('unicorns', {stdio: new Writable()}));1678 expectError(execaSync('unicorns', {stdio: new Writable()}));1679 expectError(execa('unicorns', {stdio: new Readable()}));1680 expectError(execaSync('unicorns', {stdio: new Readable()}));49 unmodified lines1730 fileUrl,1731 {file: './test'},1732 duplex,1733 duplexTransform,1734+ webTransformInstance,1735+ webTransform,1736 new Writable(),1737 new Readable(),1738 new WritableStream(),1739 new ReadableStream(),22 unmodified lines1762 expectError(execaSync('unicorns', {stdio: [unknownGenerator]}));1763 expectError(execaSync('unicorns', {stdio: [{transform: unknownGenerator}]}));1764 expectError(execaSync('unicorns', {stdio: [duplex]}));1765 expectError(execaSync('unicorns', {stdio: [duplexTransform]}));1766+expectError(execaSync('unicorns', {stdio: [webTransformInstance]}));1767+expectError(execaSync('unicorns', {stdio: [webTransform]}));1768 expectError(execaSync('unicorns', {stdio: [new WritableStream()]}));1769 expectError(execaSync('unicorns', {stdio: [new ReadableStream()]}));1770 expectError(execaSync('unicorns', {stdio: [emptyStringGenerator()]}));1771 expectError(execaSync('unicorns', {stdio: [asyncStringGenerator()]}));17 unmodified lines1789 [fileUrl],1790 [{file: './test'}],1791 [duplex],1792 [duplexTransform],1793+ [webTransformInstance],1794+ [webTransform],1795 [new Writable()],1796 [new Readable()],1797 [new WritableStream()],1798 [new ReadableStream()],26 unmodified lines1825 expectError(execaSync('unicorns', {stdio: [[unknownGenerator]]}));1826 expectError(execaSync('unicorns', {stdio: [[{transform: unknownGenerator}]]}));1827 expectError(execaSync('unicorns', {stdio: [[duplex]]}));1828 expectError(execaSync('unicorns', {stdio: [[duplexTransform]]}));1829+expectError(execaSync('unicorns', {stdio: [[webTransformInstance]]}));1830+expectError(execaSync('unicorns', {stdio: [[webTransform]]}));1831 expectError(execaSync('unicorns', {stdio: [[new WritableStream()]]}));1832 expectError(execaSync('unicorns', {stdio: [[new ReadableStream()]]}));1833 expectError(execaSync('unicorns', {stdio: [[['foo', 'bar']]]}));1834 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), 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.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#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 | {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)\873+Type: `string | number | stream.Readable | ReadableStream | TransformStream | URL | {file: string} | Uint8Array | Iterable<string | Uint8Array | unknown> | AsyncIterable<string | Uint8Array | unknown> | GeneratorFunction<string | Uint8Array | unknown> | AsyncGeneratorFunction<string | Uint8Array | unknown> | {transform: GeneratorFunction | AsyncGeneratorFunction | Duplex | TransformStream}` (or a tuple of those types)\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 or a [`Duplex`](docs/transform.md#nodejs-duplextransform-streams) to transform the input. [Learn more.](docs/transform.md)891+This can also be a generator function, a [`Duplex`](docs/transform.md#duplextransform-streams) or a web [`TransformStream`](docs/transform.md#duplextransform-streams) to transform the input. [Learn more.](docs/transform.md)892 893 #### stdout894 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)\895+Type: `string | number | stream.Writable | WritableStream | TransformStream | URL | {file: string} | GeneratorFunction<string | Uint8Array | unknown> | AsyncGeneratorFunction<string | Uint8Array | unknown> | {transform: GeneratorFunction | AsyncGeneratorFunction | Duplex | TransformStream}` (or a tuple of those types)\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 or a [`Duplex`](docs/transform.md#nodejs-duplextransform-streams) to transform the output. [Learn more.](docs/transform.md)911+This can also be a generator function, a [`Duplex`](docs/transform.md#duplextransform-streams) or a web [`TransformStream`](docs/transform.md#duplextransform-streams) to transform the output. [Learn more.](docs/transform.md)912 913 #### stderr914 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)\915+Type: `string | number | stream.Writable | WritableStream | TransformStream | URL | {file: string} | GeneratorFunction<string | Uint8Array | unknown> | AsyncGeneratorFunction<string | Uint8Array | unknown> | {transform: GeneratorFunction | AsyncGeneratorFunction | Duplex | TransformStream}` (or a tuple of those types)\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 or a [`Duplex`](docs/transform.md#nodejs-duplextransform-streams) to transform the output. [Learn more.](docs/transform.md)931+This can also be a generator function, a [`Duplex`](docs/transform.md#duplextransform-streams) or a web [`TransformStream`](docs/transform.md#duplextransform-streams) to transform the output. [Learn more.](docs/transform.md)932 933 #### stdio934 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)\935+Type: `string | Array<string | number | stream.Readable | stream.Writable | ReadableStream | WritableStream | TransformStream | URL | {file: string} | Uint8Array | Iterable<string> | Iterable<Uint8Array> | Iterable<unknown> | AsyncIterable<string | Uint8Array | unknown> | GeneratorFunction<string | Uint8Array | unknown> | AsyncGeneratorFunction<string | Uint8Array | unknown> | {transform: GeneratorFunction | AsyncGeneratorFunction | Duplex | TransformStream}>` (or a tuple of those types)\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