Skip to content
Myr

Simplify transforms syntax (#748)

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

authored by ehmicky · committed by GitHub · parent a510995 · Browse files · 15 files+529 added−435 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+529 added−435 removed

  • tests:+181 added−178 removed
  • other:+348 added−257 removed

15 files+529 added−435 removed

modified:docs/transform.md+49 added-24 removed
modified:lib/stdio/duplex.js+11 added-1 removed
modified:lib/stdio/encoding.js+39 added-36 removed
10 unmodified lines
11 return newStdioStreams;12 }1314 const objectMode = newStdioStreams.findLast(({type}) => type === 'generator')?.value.objectMode === true;15 const encodingEndGenerator = objectMode ? encodingEndObjectGenerator : encodingEndStringGenerator;16 const transform = encodingEndGenerator.bind(undefined, encoding);15 const stringDecoder = new StringDecoder(encoding);16 const generator = objectMode17 ? {18 transform: encodingEndObjectGenerator.bind(undefined, stringDecoder),19 }20 : {21 transform: encodingEndStringGenerator.bind(undefined, stringDecoder),22 final: encodingEndStringFinal.bind(undefined, stringDecoder),23 };24 return [25 ...newStdioStreams,26 {27 ...newStdioStreams[0],28 type: 'generator',22 value: {transform, binary: true, objectMode},29 value: {...generator, binary: true, objectMode},30 encoding: 'buffer',31 },32 ];33};
5 unmodified lines
3940// eslint-disable-next-line unicorn/text-encoding-identifier-case41const IGNORED_ENCODINGS = new Set(['utf8', 'utf-8', 'buffer']);4236const encodingEndStringGenerator = async function * (encoding, chunks) {37 const stringDecoder = new StringDecoder(encoding);43const encodingEndStringGenerator = function * (stringDecoder, chunk) {44 yield stringDecoder.write(chunk);45};4639 for await (const chunk of chunks) {40 yield stringDecoder.write(chunk);41 }4247const encodingEndStringFinal = function * (stringDecoder) {48 const lastChunk = stringDecoder.end();49 if (lastChunk !== '') {50 yield lastChunk;51 }52};5349const encodingEndObjectGenerator = async function * (encoding, chunks) {50 const stringDecoder = new StringDecoder(encoding);5152 for await (const chunk of chunks) {53 yield isUint8Array(chunk) ? stringDecoder.end(chunk) : chunk;54 }54const encodingEndObjectGenerator = function * (stringDecoder, chunk) {55 yield isUint8Array(chunk) ? stringDecoder.end(chunk) : chunk;56};5758/*59When using generators, add an internal generator that converts chunks from `Buffer` to `string` or `Uint8Array`.
6 unmodified lines
66However, those are converted to Buffer:67- on writes: `Duplex.writable` `decodeStrings: true` default option68- on reads: `Duplex.readable` `readableEncoding: null` default option69*/69export const getEncodingStartGenerator = encoding => encoding === 'buffer'70 ? encodingStartBufferGenerator71 : encodingStartStringGenerator;7273const encodingStartBufferGenerator = async function * (chunks) {74 const textEncoder = new TextEncoder();7576 for await (const chunk of chunks) {77 if (Buffer.isBuffer(chunk)) {78 yield new Uint8Array(chunk);79 } else if (typeof chunk === 'string') {80 yield textEncoder.encode(chunk);81 } else {82 yield chunk;83 }70export const getEncodingStartGenerator = encoding => {71 if (encoding === 'buffer') {72 return {transform: encodingStartBufferGenerator.bind(undefined, new TextEncoder())};73 }85};7487const encodingStartStringGenerator = async function * (chunks) {75 const textDecoder = new TextDecoder();76 return {77 transform: encodingStartStringGenerator.bind(undefined, textDecoder),78 final: encodingStartStringFinal.bind(undefined, textDecoder),79 };80};8190 for await (const chunk of chunks) {91 yield Buffer.isBuffer(chunk) || isUint8Array(chunk)92 ? textDecoder.decode(chunk, {stream: true})93 : chunk;82const encodingStartBufferGenerator = function * (textEncoder, chunk) {83 if (Buffer.isBuffer(chunk)) {84 yield new Uint8Array(chunk);85 } else if (typeof chunk === 'string') {86 yield textEncoder.encode(chunk);87 } else {88 yield chunk;89 }90};9192const encodingStartStringGenerator = function * (textDecoder, chunk) {93 yield Buffer.isBuffer(chunk) || isUint8Array(chunk)94 ? textDecoder.decode(chunk, {stream: true})95 : chunk;96};9798const encodingStartStringFinal = function * (textDecoder) {99 const lastChunk = textDecoder.decode();100 if (lastChunk !== '') {101 yield lastChunk;102 }
1 unmodified line
modified:lib/stdio/generator.js+17 added-21 removed
16 unmodified lines
17 return [...nonGenerators, ...sortGenerators(newGenerators)];18};1920const normalizeGenerator = ({value, ...stdioStream}, index, newGenerators) => {21 const {transform, binary = false, objectMode = false} = isGeneratorOptions(value) ? value : {transform: value};21 const {transform, final, binary = false, objectMode = false} = isGeneratorOptions(value) ? value : {transform: value};22 const objectModes = stdioStream.direction === 'output'23 ? getOutputObjectModes(objectMode, index, newGenerators)24 : getInputObjectModes(objectMode, index, newGenerators);25 return {...stdioStream, value: {transform, binary, ...objectModes}};25 return {...stdioStream, value: {transform, final, binary, ...objectModes}};26};2728/*29`objectMode` determines the return value's type, i.e. the `readableObjectMode`.
23 unmodified lines
53/*54Generators can be used to transform/filter standard streams.5556Generators have a simple syntax, yet allows all of the following:57- Sharing state between chunks, by using logic before the `for` loop58- Flushing logic, by using logic after the `for` loop57- Sharing `state` between chunks58- Flushing logic, by using a `final` function59- Asynchronous logic60- Emitting multiple chunks from a single source chunk, even if spaced in time, by using multiple `yield`61- Filtering, by using no `yield`62
3 unmodified lines
6667Chunks are currently processed serially. We could add a `concurrency` option to parallelize in the future.68*/69export const generatorToDuplexStream = ({70 value: {transform, binary, writableObjectMode, readableObjectMode},70 value: {transform, final, binary, writableObjectMode, readableObjectMode},71 encoding,72 optionName,73}) => {74 const generators = [75 getEncodingStartGenerator(encoding),76 getLinesGenerator(encoding, binary),77 transform,78 getValidateTransformReturn(readableObjectMode, optionName),77 {transform, final},78 {transform: getValidateTransformReturn(readableObjectMode, optionName)},79 ].filter(Boolean);80 const duplexStream = generatorsToDuplex(generators, {writableObjectMode, readableObjectMode});81 return {value: duplexStream};82};
1 unmodified line
84const getValidateTransformReturn = (readableObjectMode, optionName) => readableObjectMode85 ? validateObjectTransformReturn.bind(undefined, optionName)86 : validateStringTransformReturn.bind(undefined, optionName);8788const validateObjectTransformReturn = async function * (optionName, chunks) {89 for await (const chunk of chunks) {90 if (chunk === null) {91 throw new Error(`The \`${optionName}\` option's function must not return null.`);92 }9394 yield chunk;88const validateObjectTransformReturn = function * (optionName, chunk) {89 if (chunk === null) {90 throw new TypeError(`The \`${optionName}\` option's function must not return null.`);91 }9293 yield chunk;94};9598const validateStringTransformReturn = async function * (optionName, chunks) {99 for await (const chunk of chunks) {100 if (typeof chunk !== 'string' && !isBinary(chunk)) {101 throw new Error(`The \`${optionName}\` option's function must return a string or an Uint8Array, not ${typeof chunk}.`);102 }103104 yield chunk;96const validateStringTransformReturn = function * (optionName, chunk) {97 if (typeof chunk !== 'string' && !isBinary(chunk)) {98 throw new TypeError(`The \`${optionName}\` option's function must return a string or an Uint8Array, not ${typeof chunk}.`);99 }100101 yield chunk;102};103104// `childProcess.stdin|stdout|stderr|stdio` is directly mutated.105export const pipeGenerator = (spawned, {value, direction, index}) => {
15 unmodified lines
modified:lib/stdio/lines.js+43 added-43 removed
17 unmodified lines
18 && lines19 && !isSync20 && willPipeStreams(stdioStreams);2122const linesEndGenerator = async function * (chunks) {23 yield * chunks;22const linesEndGenerator = function * (chunk) {23 yield chunk;24};2526// Split chunks line-wise for generators passed to the `std*` options27export const getLinesGenerator = (encoding, binary) => {28 if (binary) {29 return;30 }3132 return encoding === 'buffer' ? linesUint8ArrayGenerator : linesStringGenerator;32 const info = encoding === 'buffer' ? linesUint8ArrayInfo : linesStringInfo;33 const state = {previousChunks: info.emptyValue};34 return {35 transform: linesGenerator.bind(undefined, state, info),36 final: linesFinal.bind(undefined, state),37 };38};3935const linesUint8ArrayGenerator = async function * (chunks) {36 yield * linesGenerator({37 chunks,38 emptyValue: new Uint8Array(0),39 newline: 0x0A,40 concat: concatUint8Array,41 isValidType: isUint8Array,42 });43};4440const concatUint8Array = (firstChunk, secondChunk) => {41 const chunk = new Uint8Array(firstChunk.length + secondChunk.length);42 chunk.set(firstChunk, 0);43 chunk.set(secondChunk, firstChunk.length);44 return chunk;45};4652const linesStringGenerator = async function * (chunks) {53 yield * linesGenerator({54 chunks,55 emptyValue: '',56 newline: '\n',57 concat: concatString,58 isValidType: isString,59 });47const linesUint8ArrayInfo = {48 emptyValue: new Uint8Array(0),49 newline: 0x0A,50 concat: concatUint8Array,51 isValidType: isUint8Array,52};5354const concatString = (firstChunk, secondChunk) => `${firstChunk}${secondChunk}`;55const isString = chunk => typeof chunk === 'string';5657const linesStringInfo = {58 emptyValue: '',59 newline: '\n',60 concat: concatString,61 isValidType: isString,62};6364// This imperative logic is much faster than using `String.split()` and uses very low memory.65// Also, it allows sharing it with `Uint8Array`.67const linesGenerator = async function * ({chunks, emptyValue, newline, concat, isValidType}) {68 let previousChunks = emptyValue;66const linesGenerator = function * (state, {emptyValue, newline, concat, isValidType}, chunk) {67 if (!isValidType(chunk)) {68 yield chunk;69 return;70 }7170 for await (const chunk of chunks) {71 if (!isValidType(chunk)) {72 yield chunk;73 continue;74 }72 let {previousChunks} = state;73 let start = -1;7476 let start = -1;75 for (let end = 0; end < chunk.length; end += 1) {76 if (chunk[end] === newline) {77 let line = chunk.slice(start + 1, end + 1);7878 for (let end = 0; end < chunk.length; end += 1) {79 if (chunk[end] === newline) {80 let line = chunk.slice(start + 1, end + 1);8182 if (previousChunks.length > 0) {83 line = concat(previousChunks, line);84 previousChunks = emptyValue;79 if (previousChunks.length > 0) {80 line = concat(previousChunks, line);81 previousChunks = emptyValue;85 }8687 yield line;88 start = end;82 }90 }8392 if (start !== chunk.length - 1) {93 previousChunks = concat(previousChunks, chunk.slice(start + 1));84 yield line;85 start = end;86 }87 }8889 if (start !== chunk.length - 1) {90 previousChunks = concat(previousChunks, chunk.slice(start + 1));91 }9293 state.previousChunks = previousChunks;94};9596const linesFinal = function * ({previousChunks}) {97 if (previousChunks.length > 0) {98 yield previousChunks;99 }100};
modified:lib/stdio/type.js+10 added-10 removed
1 unmodified line
2import {isUint8Array} from './utils.js';34// The `stdin`/`stdout`/`stderr` option can be of many types. This detects it.5export const getStdioOptionType = (stdioOption, optionName) => {6 if (isAsyncGenerator(stdioOption)) {6 if (isGenerator(stdioOption)) {7 return 'generator';8 }910 if (isSyncGenerator(stdioOption)) {11 throw new TypeError(`The \`${optionName}\` option must use an asynchronous generator, not a synchronous one.`);12 }1310 if (isUrl(stdioOption)) {11 return 'fileUrl';12 }13
23 unmodified lines
3738 return 'native';39};4045const getGeneratorObjectType = ({transform, binary, objectMode}, optionName) => {46 if (!isAsyncGenerator(transform)) {47 throw new TypeError(`The \`${optionName}.transform\` option must use an asynchronous generator.`);41const getGeneratorObjectType = ({transform, final, binary, objectMode}, optionName) => {42 if (!isGenerator(transform)) {43 throw new TypeError(`The \`${optionName}.transform\` option must be a generator.`);44 }4546 if (final !== undefined && !isGenerator(final)) {47 throw new TypeError(`The \`${optionName}.final\` option must be a generator.`);48 }4950 checkBooleanOption(binary, `${optionName}.binary`);51 checkBooleanOption(objectMode, `${optionName}.objectMode`);5253 return 'generator';
4 unmodified lines
58 throw new TypeError(`The \`${optionName}\` option must use a boolean.`);59 }60};6162const isAsyncGenerator = stdioOption => Object.prototype.toString.call(stdioOption) === '[object AsyncGeneratorFunction]';63const isSyncGenerator = stdioOption => Object.prototype.toString.call(stdioOption) === '[object GeneratorFunction]';62const isGenerator = stdioOption => Object.prototype.toString.call(stdioOption) === '[object AsyncGeneratorFunction]'63 || Object.prototype.toString.call(stdioOption) === '[object GeneratorFunction]';64export const isGeneratorOptions = stdioOption => typeof stdioOption === 'object'65 && stdioOption !== null66 && stdioOption.transform !== undefined;67
32 unmodified lines
modified:lib/stream.js+2 added-2 removed
39 unmodified lines
40 ? all.pipe(generatorToDuplexStream({value: allStreamGenerator, encoding}).value)41 : all;4243const allStreamGenerator = {44 async * transform(chunks) {45 yield * chunks;44 * transform(chunk) {45 yield chunk;46 },47 binary: true,48 writableObjectMode: true,49 readableObjectMode: true,
133 unmodified lines
modified:test/fixtures/nested-inherit.js+2 added-4 removed
modified:test/helpers/generator.js+31 added-25 removed
1import {setImmediate} from 'node:timers/promises';2import {foobarObject} from './input.js';34export const noopGenerator = objectMode => ({5 async * transform(lines) {6 yield * lines;4export const noopGenerator = (objectMode, binary) => ({5 * transform(line) {6 yield line;7 },8 objectMode,9 binary,10});1112export const serializeGenerator = {12 async * transform(objects) {13 for await (const object of objects) {14 yield JSON.stringify(object);15 }13 * transform(object) {14 yield JSON.stringify(object);15 },16 objectMode: true,17};1819export const getOutputsGenerator = (inputs, objectMode) => ({21 async * transform(lines) {22 // eslint-disable-next-line no-unused-vars23 for await (const line of lines) {24 yield * inputs;25 }20 * transform() {21 yield * inputs;22 },23 objectMode,24});2526export const getOutputGenerator = (input, objectMode) => ({31 async * transform(lines) {32 // eslint-disable-next-line no-unused-vars33 for await (const line of lines) {34 yield input;35 }27 * transform() {28 yield input;29 },30 objectMode,31});3233export const outputObjectGenerator = getOutputGenerator(foobarObject, true);3435export const getChunksGenerator = (chunks, objectMode, binary) => ({43 async * transform(lines) {44 // eslint-disable-next-line no-unused-vars45 for await (const line of lines) {46 for (const chunk of chunks) {47 yield chunk;48 // eslint-disable-next-line no-await-in-loop49 await setImmediate();36 async * transform() {37 for (const chunk of chunks) {38 yield chunk;39 // eslint-disable-next-line no-await-in-loop40 await setImmediate();50 }41 }42 },43 objectMode,44 binary,45});4647const noYieldTransform = function * () {};4849export const noYieldGenerator = objectMode => ({50 transform: noYieldTransform,51 objectMode,52});5354export const convertTransformToFinal = (transform, final) => {55 if (!final) {56 return transform;57 }5859 const generatorOptions = typeof transform === 'function' ? {transform} : transform;60 return ({...generatorOptions, transform: noYieldTransform, final: generatorOptions.transform});61};
modified:test/stdio/encoding.js+4 added-2 removed
126 unmodified lines
127test('can pass encoding "base64" to stdio[*] - sync', checkEncoding, 'base64', 3, execaSync);128test('can pass encoding "base64url" to stdio[*] - sync', checkEncoding, 'base64url', 3, execaSync);129/* eslint-enable unicorn/text-encoding-identifier-case */130131test('validate unknown encodings', async t => {132 await t.throwsAsync(execa('noop.js', {encoding: 'unknownEncoding'}), {code: 'ERR_UNKNOWN_ENCODING'});131test('validate unknown encodings', t => {132 t.throws(() => {133 execa('noop.js', {encoding: 'unknownEncoding'});134 }, {code: 'ERR_UNKNOWN_ENCODING'});135});136137const foobarArray = ['fo', 'ob', 'ar', '..'];138
58 unmodified lines
modified:test/stdio/generator.js+136 added-134 removed
7 unmodified lines
8import {execa, execaSync} from '../../index.js';9import {setFixtureDir} from '../helpers/fixtures-dir.js';10import {getStdio} from '../helpers/stdio.js';11import {foobarString, foobarUint8Array, foobarBuffer, foobarObject, foobarObjectString} from '../helpers/input.js';12import {serializeGenerator, noopGenerator, getOutputsGenerator, getOutputGenerator, outputObjectGenerator} from '../helpers/generator.js';12import {13 serializeGenerator,14 noopGenerator,15 getOutputsGenerator,16 getOutputGenerator,17 outputObjectGenerator,18 noYieldGenerator,19 convertTransformToFinal,20} from '../helpers/generator.js';2122setFixtureDir();2324const textEncoder = new TextEncoder();
1 unmodified line
2627const foobarUppercase = foobarString.toUpperCase();28const foobarHex = foobarBuffer.toString('hex');2922const uppercaseGenerator = async function * (lines) {23 for await (const line of lines) {24 yield line.toUpperCase();25 }30const uppercaseGenerator = function * (line) {31 yield line.toUpperCase();32};3328const uppercaseBufferGenerator = async function * (lines) {29 for await (const line of lines) {30 yield textDecoder.decode(line).toUpperCase();31 }34const uppercaseBufferGenerator = function * (line) {35 yield textDecoder.decode(line).toUpperCase();36};3738const getInputObjectMode = objectMode => objectMode39 ? {input: [foobarObject], generator: serializeGenerator, output: foobarObjectString}
67 unmodified lines
107test('Generators with result.stdin cannot return null if in objectMode', testGeneratorReturn, 0, inputNullGenerator(true), 'stdin-fd.js', true);108test('Generators with result.stdout cannot return null if not in objectMode', testGeneratorReturn, 1, outputNullGenerator(false), 'noop-fd.js', false);109test('Generators with result.stdout cannot return null if in objectMode', testGeneratorReturn, 1, outputNullGenerator(true), 'noop-fd.js', true);110111const testGeneratorFinal = async (t, fixtureName) => {112 const {stdout} = await execa(fixtureName, {stdout: convertTransformToFinal(getOutputGenerator(foobarString), true)});113 t.is(stdout, foobarString);114};115116test('Generators "final" can be used', testGeneratorFinal, 'noop.js');117test('Generators "final" is used even on empty streams', testGeneratorFinal, 'empty.js');118119test('Generators "final" return value is validated', async t => {120 const childProcess = execa('noop.js', {stdout: convertTransformToFinal(outputNullGenerator(true), true)});121 await t.throwsAsync(childProcess, {message: /not return null/});122});123124// eslint-disable-next-line max-params125const testGeneratorOutput = async (t, index, reject, useShortcutProperty, objectMode) => {126 const {generator, output} = getOutputObjectMode(objectMode);127 const fixtureName = reject ? 'noop-fd.js' : 'noop-fail.js';
122 unmodified lines
250 const {stdout} = await execa('stdin-fd.js', ['0'], {stdin: uppercaseGenerator, input: foobarUint8Array});251 t.is(stdout, foobarUppercase);252});253237const syncGenerator = function * () {};238254const testInvalidGenerator = (t, index, stdioOption) => {255 t.throws(() => {241 execa('empty.js', getStdio(index, stdioOption));242 }, {message: /asynchronous generator/});256 execa('empty.js', getStdio(index, {...noopGenerator(), ...stdioOption}));257 }, {message: /must be a generator/});258};259245test('Cannot use sync generators with stdin', testInvalidGenerator, 0, syncGenerator);246test('Cannot use sync generators with stdout', testInvalidGenerator, 1, syncGenerator);247test('Cannot use sync generators with stderr', testInvalidGenerator, 2, syncGenerator);248test('Cannot use sync generators with stdio[*]', testInvalidGenerator, 3, syncGenerator);249test('Cannot use sync generators with stdin, with options', testInvalidGenerator, 0, {transform: syncGenerator});250test('Cannot use sync generators with stdout, with options', testInvalidGenerator, 1, {transform: syncGenerator});251test('Cannot use sync generators with stderr, with options', testInvalidGenerator, 2, {transform: syncGenerator});252test('Cannot use sync generators with stdio[*], with options', testInvalidGenerator, 3, {transform: syncGenerator});260test('Cannot use invalid "transform" with stdin', testInvalidGenerator, 0, {transform: true});261test('Cannot use invalid "transform" with stdout', testInvalidGenerator, 1, {transform: true});262test('Cannot use invalid "transform" with stderr', testInvalidGenerator, 2, {transform: true});263test('Cannot use invalid "transform" with stdio[*]', testInvalidGenerator, 3, {transform: true});264test('Cannot use invalid "final" with stdin', testInvalidGenerator, 0, {final: true});265test('Cannot use invalid "final" with stdout', testInvalidGenerator, 1, {final: true});266test('Cannot use invalid "final" with stderr', testInvalidGenerator, 2, {final: true});267test('Cannot use invalid "final" with stdio[*]', testInvalidGenerator, 3, {final: true});268269const testInvalidBinary = (t, index, optionName) => {270 t.throws(() => {271 execa('empty.js', getStdio(index, {transform: uppercaseGenerator, [optionName]: 'true'}));
21 unmodified lines
293test('Cannot use generators with sync methods and stdio[*]', testSyncMethods, 3);294295const repeatHighWaterMark = 10;296286const writerGenerator = async function * (lines) {287 // eslint-disable-next-line no-unused-vars288 for await (const line of lines) {289 for (let index = 0; index < getDefaultHighWaterMark() * repeatHighWaterMark; index += 1) {290 yield '\n';297const writerGenerator = function * () {298 for (let index = 0; index < getDefaultHighWaterMark() * repeatHighWaterMark; index += 1) {299 yield '\n';291 }300 }301};302295const passThroughGenerator = async function * (chunks) {296 yield * chunks;303const getLengthGenerator = function * (chunk) {304 yield `${chunk.length}`;305};306299const getLengthGenerator = async function * (chunks) {300 for await (const chunk of chunks) {301 yield `${chunk.length}`;302 }303};304307const testHighWaterMark = async (t, passThrough, binary, objectMode) => {308 const {stdout} = await execa('noop.js', {309 stdout: [310 ...(objectMode ? [outputObjectGenerator] : []),311 writerGenerator,310 ...(passThrough ? [{transform: passThroughGenerator, binary}] : []),312 ...(passThrough ? [noopGenerator(false, binary)] : []),313 {transform: getLengthGenerator, binary: true},314 ],315 });316 t.is(stdout, `${getDefaultHighWaterMark()}`.repeat(repeatHighWaterMark));
4 unmodified lines
321test('Stream respects highWaterMark, binary passThrough', testHighWaterMark, true, true, false);322test('Stream respects highWaterMark, objectMode as input but not output', testHighWaterMark, false, false, true);323324const getTypeofGenerator = objectMode => ({323 async * transform(lines) {324 for await (const line of lines) {325 yield Object.prototype.toString.call(line);326 }325 * transform(line) {326 yield Object.prototype.toString.call(line);327 },328 objectMode,329});330
78 unmodified lines
409test('The first generator with result.stderr does not receive an object argument even in objectMode', testFirstOutputGeneratorArgument, 2);410test('The first generator with result.stdio[*] does not receive an object argument even in objectMode', testFirstOutputGeneratorArgument, 3);411412// eslint-disable-next-line max-params413const testGeneratorReturnType = async (t, input, encoding, reject, objectMode) => {413const testGeneratorReturnType = async (t, input, encoding, reject, objectMode, final) => {414 const fixtureName = reject ? 'noop-fd.js' : 'noop-fail.js';415 const {stdout} = await execa(fixtureName, ['1', 'other'], {416 stdout: getOutputGenerator(input, objectMode),416 stdout: convertTransformToFinal(getOutputGenerator(input, objectMode), final),417 encoding,418 reject,419 });420 const typeofChunk = Array.isArray(stdout) ? stdout[0] : stdout;421 const output = Buffer.from(typeofChunk, encoding === 'buffer' ? undefined : encoding).toString();422 t.is(output, foobarString);423};424425test('Generator can return string with default encoding', testGeneratorReturnType, foobarString, 'utf8', true, false);426test('Generator can return Uint8Array with default encoding', testGeneratorReturnType, foobarUint8Array, 'utf8', true, false);427test('Generator can return string with encoding "buffer"', testGeneratorReturnType, foobarString, 'buffer', true, false);428test('Generator can return Uint8Array with encoding "buffer"', testGeneratorReturnType, foobarUint8Array, 'buffer', true, false);429test('Generator can return string with encoding "hex"', testGeneratorReturnType, foobarString, 'hex', true, false);430test('Generator can return Uint8Array with encoding "hex"', testGeneratorReturnType, foobarUint8Array, 'hex', true, false);431test('Generator can return string with default encoding, failure', testGeneratorReturnType, foobarString, 'utf8', false, false);432test('Generator can return Uint8Array with default encoding, failure', testGeneratorReturnType, foobarUint8Array, 'utf8', false, false);433test('Generator can return string with encoding "buffer", failure', testGeneratorReturnType, foobarString, 'buffer', false, false);434test('Generator can return Uint8Array with encoding "buffer", failure', testGeneratorReturnType, foobarUint8Array, 'buffer', false, false);435test('Generator can return string with encoding "hex", failure', testGeneratorReturnType, foobarString, 'hex', false, false);436test('Generator can return Uint8Array with encoding "hex", failure', testGeneratorReturnType, foobarUint8Array, 'hex', false, false);437test('Generator can return string with default encoding, objectMode', testGeneratorReturnType, foobarString, 'utf8', true, true);438test('Generator can return Uint8Array with default encoding, objectMode', testGeneratorReturnType, foobarUint8Array, 'utf8', true, true);439test('Generator can return string with encoding "buffer", objectMode', testGeneratorReturnType, foobarString, 'buffer', true, true);440test('Generator can return Uint8Array with encoding "buffer", objectMode', testGeneratorReturnType, foobarUint8Array, 'buffer', true, true);441test('Generator can return string with encoding "hex", objectMode', testGeneratorReturnType, foobarString, 'hex', true, true);442test('Generator can return Uint8Array with encoding "hex", objectMode', testGeneratorReturnType, foobarUint8Array, 'hex', true, true);443test('Generator can return string with default encoding, objectMode, failure', testGeneratorReturnType, foobarString, 'utf8', false, true);444test('Generator can return Uint8Array with default encoding, objectMode, failure', testGeneratorReturnType, foobarUint8Array, 'utf8', false, true);445test('Generator can return string with encoding "buffer", objectMode, failure', testGeneratorReturnType, foobarString, 'buffer', false, true);446test('Generator can return Uint8Array with encoding "buffer", objectMode, failure', testGeneratorReturnType, foobarUint8Array, 'buffer', false, true);447test('Generator can return string with encoding "hex", objectMode, failure', testGeneratorReturnType, foobarString, 'hex', false, true);448test('Generator can return Uint8Array with encoding "hex", objectMode, failure', testGeneratorReturnType, foobarUint8Array, 'hex', false, true);425test('Generator can return string with default encoding', testGeneratorReturnType, foobarString, 'utf8', true, false, false);426test('Generator can return Uint8Array with default encoding', testGeneratorReturnType, foobarUint8Array, 'utf8', true, false, false);427test('Generator can return string with encoding "buffer"', testGeneratorReturnType, foobarString, 'buffer', true, false, false);428test('Generator can return Uint8Array with encoding "buffer"', testGeneratorReturnType, foobarUint8Array, 'buffer', true, false, false);429test('Generator can return string with encoding "hex"', testGeneratorReturnType, foobarString, 'hex', true, false, false);430test('Generator can return Uint8Array with encoding "hex"', testGeneratorReturnType, foobarUint8Array, 'hex', true, false, false);431test('Generator can return string with default encoding, failure', testGeneratorReturnType, foobarString, 'utf8', false, false, false);432test('Generator can return Uint8Array with default encoding, failure', testGeneratorReturnType, foobarUint8Array, 'utf8', false, false, false);433test('Generator can return string with encoding "buffer", failure', testGeneratorReturnType, foobarString, 'buffer', false, false, false);434test('Generator can return Uint8Array with encoding "buffer", failure', testGeneratorReturnType, foobarUint8Array, 'buffer', false, false, false);435test('Generator can return string with encoding "hex", failure', testGeneratorReturnType, foobarString, 'hex', false, false, false);436test('Generator can return Uint8Array with encoding "hex", failure', testGeneratorReturnType, foobarUint8Array, 'hex', false, false, false);437test('Generator can return string with default encoding, objectMode', testGeneratorReturnType, foobarString, 'utf8', true, true, false);438test('Generator can return Uint8Array with default encoding, objectMode', testGeneratorReturnType, foobarUint8Array, 'utf8', true, true, false);439test('Generator can return string with encoding "buffer", objectMode', testGeneratorReturnType, foobarString, 'buffer', true, true, false);440test('Generator can return Uint8Array with encoding "buffer", objectMode', testGeneratorReturnType, foobarUint8Array, 'buffer', true, true, false);441test('Generator can return string with encoding "hex", objectMode', testGeneratorReturnType, foobarString, 'hex', true, true, false);442test('Generator can return Uint8Array with encoding "hex", objectMode', testGeneratorReturnType, foobarUint8Array, 'hex', true, true, false);443test('Generator can return string with default encoding, objectMode, failure', testGeneratorReturnType, foobarString, 'utf8', false, true, false);444test('Generator can return Uint8Array with default encoding, objectMode, failure', testGeneratorReturnType, foobarUint8Array, 'utf8', false, true, false);445test('Generator can return string with encoding "buffer", objectMode, failure', testGeneratorReturnType, foobarString, 'buffer', false, true, false);446test('Generator can return Uint8Array with encoding "buffer", objectMode, failure', testGeneratorReturnType, foobarUint8Array, 'buffer', false, true, false);447test('Generator can return string with encoding "hex", objectMode, failure', testGeneratorReturnType, foobarString, 'hex', false, true, false);448test('Generator can return Uint8Array with encoding "hex", objectMode, failure', testGeneratorReturnType, foobarUint8Array, 'hex', false, true, false);449test('Generator can return final string with default encoding', testGeneratorReturnType, foobarString, 'utf8', true, false, true);450test('Generator can return final Uint8Array with default encoding', testGeneratorReturnType, foobarUint8Array, 'utf8', true, false, true);451test('Generator can return final string with encoding "buffer"', testGeneratorReturnType, foobarString, 'buffer', true, false, true);452test('Generator can return final Uint8Array with encoding "buffer"', testGeneratorReturnType, foobarUint8Array, 'buffer', true, false, true);453test('Generator can return final string with encoding "hex"', testGeneratorReturnType, foobarString, 'hex', true, false, true);454test('Generator can return final Uint8Array with encoding "hex"', testGeneratorReturnType, foobarUint8Array, 'hex', true, false, true);455test('Generator can return final string with default encoding, failure', testGeneratorReturnType, foobarString, 'utf8', false, false, true);456test('Generator can return final Uint8Array with default encoding, failure', testGeneratorReturnType, foobarUint8Array, 'utf8', false, false, true);457test('Generator can return final string with encoding "buffer", failure', testGeneratorReturnType, foobarString, 'buffer', false, false, true);458test('Generator can return final Uint8Array with encoding "buffer", failure', testGeneratorReturnType, foobarUint8Array, 'buffer', false, false, true);459test('Generator can return final string with encoding "hex", failure', testGeneratorReturnType, foobarString, 'hex', false, false, true);460test('Generator can return final Uint8Array with encoding "hex", failure', testGeneratorReturnType, foobarUint8Array, 'hex', false, false, true);461test('Generator can return final string with default encoding, objectMode', testGeneratorReturnType, foobarString, 'utf8', true, true, true);462test('Generator can return final Uint8Array with default encoding, objectMode', testGeneratorReturnType, foobarUint8Array, 'utf8', true, true, true);463test('Generator can return final string with encoding "buffer", objectMode', testGeneratorReturnType, foobarString, 'buffer', true, true, true);464test('Generator can return final Uint8Array with encoding "buffer", objectMode', testGeneratorReturnType, foobarUint8Array, 'buffer', true, true, true);465test('Generator can return final string with encoding "hex", objectMode', testGeneratorReturnType, foobarString, 'hex', true, true, true);466test('Generator can return final Uint8Array with encoding "hex", objectMode', testGeneratorReturnType, foobarUint8Array, 'hex', true, true, true);467test('Generator can return final string with default encoding, objectMode, failure', testGeneratorReturnType, foobarString, 'utf8', false, true, true);468test('Generator can return final Uint8Array with default encoding, objectMode, failure', testGeneratorReturnType, foobarUint8Array, 'utf8', false, true, true);469test('Generator can return final string with encoding "buffer", objectMode, failure', testGeneratorReturnType, foobarString, 'buffer', false, true, true);470test('Generator can return final Uint8Array with encoding "buffer", objectMode, failure', testGeneratorReturnType, foobarUint8Array, 'buffer', false, true, true);471test('Generator can return final string with encoding "hex", objectMode, failure', testGeneratorReturnType, foobarString, 'hex', false, true, true);472test('Generator can return final Uint8Array with encoding "hex", objectMode, failure', testGeneratorReturnType, foobarUint8Array, 'hex', false, true, true);473474const multibyteChar = '\u{1F984}';475const multibyteString = `${multibyteChar}${multibyteChar}`;476const multibyteUint8Array = textEncoder.encode(multibyteString);
19 unmodified lines
496497test('Generator handles partial multibyte characters with Uint8Array', testMultibytePartial, false);498test('Generator handles partial multibyte characters with Uint8Array, objectMode', testMultibytePartial, true);499476// eslint-disable-next-line require-yield477const noYieldGenerator = async function * (lines) {478 // eslint-disable-next-line no-empty, no-unused-vars479 for await (const line of lines) {}480};481482const testNoYield = async (t, objectMode, output) => {483 const {stdout} = await execa('noop.js', {stdout: {transform: noYieldGenerator, objectMode}});500const testNoYield = async (t, objectMode, final, output) => {501 const {stdout} = await execa('noop.js', {stdout: convertTransformToFinal(noYieldGenerator(objectMode), final)});502 t.deepEqual(stdout, output);503};504487test('Generator can filter by not calling yield', testNoYield, false, '');488test('Generator can filter by not calling yield, objectMode', testNoYield, true, []);505test('Generator can filter "transform" by not calling yield', testNoYield, false, false, '');506test('Generator can filter "transform" by not calling yield, objectMode', testNoYield, true, false, []);507test('Generator can filter "final" by not calling yield', testNoYield, false, false, '');508test('Generator can filter "final" by not calling yield, objectMode', testNoYield, true, false, []);509510const prefix = '> ';511const suffix = ' <';512493const multipleYieldGenerator = async function * (lines) {494 for await (const line of lines) {495 yield prefix;496 await setImmediate();497 yield line;498 await setImmediate();499 yield suffix;513const multipleYieldGenerator = async function * (line = foobarString) {514 yield prefix;515 await setImmediate();516 yield line;517 await setImmediate();518 yield suffix;500 }519};520503test('Generator can yield multiple times at different moments', async t => {504 const {stdout} = await execa('noop-fd.js', ['1', foobarString], {stdout: multipleYieldGenerator});521const testMultipleYields = async (t, final) => {522 const {stdout} = await execa('noop-fd.js', ['1', foobarString], {stdout: convertTransformToFinal(multipleYieldGenerator, final)});523 t.is(stdout, `${prefix}${foobarString}${suffix}`);506});524};525526test('Generator can yield "transform" multiple times at different moments', testMultipleYields, false);527test('Generator can yield "final" multiple times at different moments', testMultipleYields, true);528529const testInputFile = async (t, getOptions, reversed) => {530 const filePath = tempfile();531 await writeFile(filePath, foobarString);532 const {stdin, ...options} = getOptions(filePath);
44 unmodified lines
577});578579const casedSuffix = 'k';580560const appendGenerator = async function * (lines) {561 for await (const line of lines) {562 yield `${line}${casedSuffix}`;563 }581const appendGenerator = function * (line) {582 yield `${line}${casedSuffix}`;583};584585const testAppendInput = async (t, reversed) => {586 const stdin = [foobarUint8Array, uppercaseGenerator, appendGenerator];
32 unmodified lines
619 await t.throwsAsync(execa('noop.js', {maxBuffer, stdout: getOutputGenerator(`${bigString}.`, false)}));620});621622test('Generators take "maxBuffer" into account, objectMode', async t => {604 const bigArray = Array.from({length: maxBuffer});623 const bigArray = Array.from({length: maxBuffer}).fill('.');624 const {stdout} = await execa('noop.js', {maxBuffer, stdout: getOutputsGenerator(bigArray, true)});625 t.is(stdout.length, maxBuffer);626627 await t.throwsAsync(execa('noop.js', {maxBuffer, stdout: getOutputsGenerator([...bigArray, ''], true)}));628});629611const timeoutGenerator = async function * (timeout, lines) {612 for await (const line of lines) {613 await setTimeout(timeout);614 yield line;615 }630const timeoutGenerator = async function * (timeout) {631 await setTimeout(timeout);632 yield foobarString;633};634618test('Generators are awaited on success', async t => {619 const {stdout} = await execa('noop-fd.js', ['1', foobarString], {maxBuffer, stdout: timeoutGenerator.bind(undefined, 1e3)});635const testAsyncGenerators = async (t, final) => {636 const {stdout} = await execa('noop.js', {637 maxBuffer,638 stdout: convertTransformToFinal(timeoutGenerator.bind(undefined, 1e2), final),639 });640 t.is(stdout, foobarString);621});641};642643test('Generators "transform" is awaited on success', testAsyncGenerators, false);644test('Generators "final" is awaited on success', testAsyncGenerators, true);645646// eslint-disable-next-line require-yield624const throwingGenerator = async function * (lines) {625 // eslint-disable-next-line no-unreachable-loop626 for await (const line of lines) {627 throw new Error(`Generator error ${line}`);628 }647const throwingGenerator = function * () {648 throw new Error('Generator error');649};650631test('Generators errors make process fail', async t => {651const GENERATOR_ERROR_REGEXP = /Generator error/;652653const testThrowingGenerator = async (t, final) => {654 await t.throwsAsync(633 execa('noop-fd.js', ['1', foobarString], {stdout: throwingGenerator}),634 {message: /Generator error foobar/},655 execa('noop-fd.js', ['1', foobarString], {stdout: convertTransformToFinal(throwingGenerator, final)}),656 {message: GENERATOR_ERROR_REGEXP},657 );636});658};659660test('Generators "transform" errors make process fail', testThrowingGenerator, false);661test('Generators "final" errors make process fail', testThrowingGenerator, true);662663test('Generators errors make process fail even when other output generators do not throw', async t => {664 await t.throwsAsync(665 execa('noop-fd.js', ['1', foobarString], {stdout: [noopGenerator(false), throwingGenerator, noopGenerator(false)]}),641 {message: /Generator error foobar/},666 {message: GENERATOR_ERROR_REGEXP},667 );668});669670test('Generators errors make process fail even when other input generators do not throw', async t => {671 const childProcess = execa('stdin-fd.js', ['0'], {stdin: [noopGenerator(false), throwingGenerator, noopGenerator(false)]});672 childProcess.stdin.write('foobar\n');648 await t.throwsAsync(childProcess, {message: /Generator error foobar/});673 await t.throwsAsync(childProcess, {message: GENERATOR_ERROR_REGEXP});674});650651// eslint-disable-next-line require-yield652const errorHandlerGenerator = async function * (state, lines) {653 try {654 // eslint-disable-next-line no-unused-vars655 for await (const line of lines) {656 await setTimeout(1e8);657 }658 } catch (error) {659 state.error = error;660 }661};662663test('Process streams failures make generators throw', async t => {664 const state = {};665 const childProcess = execa('noop-fail.js', ['1'], {stdout: errorHandlerGenerator.bind(undefined, state)});666 const error = new Error('test');667 childProcess.stdout.emit('error', error);668 const thrownError = await t.throwsAsync(childProcess);669 t.is(error, thrownError);670 await setImmediate();671 t.is(state.error.code, 'ABORT_ERR');672});
modified:test/stdio/lines.js+8 added-13 removed
27 unmodified lines
2829const bigLine = '.'.repeat(1e5);30const manyChunks = Array.from({length: 1e3}).fill('.');3132const inputGenerator = async function * (input, chunks) {33 // eslint-disable-next-line no-unused-vars34 for await (const chunk of chunks) {35 for (const inputItem of input) {36 yield inputItem;37 // eslint-disable-next-line no-await-in-loop38 await scheduler.yield();32const inputGenerator = async function * (input) {33 for (const inputItem of input) {34 yield inputItem;35 // eslint-disable-next-line no-await-in-loop36 await scheduler.yield();39 }37 }38};3943const resultGenerator = async function * (lines, chunks) {44 for await (const chunk of chunks) {45 lines.push(chunk);46 yield chunk;40const resultGenerator = function * (lines, chunk) {41 lines.push(chunk);42 yield chunk;47 }43};4445const textEncoder = new TextEncoder();46const textDecoder = new TextDecoder();
183 unmodified lines
modified:index.d.ts+6 added-4 removed
18 unmodified lines
19 | 'inherit';2021// @todo Use `string`, `Uint8Array` or `unknown` for both the argument and the return type, based on whether `encoding: 'buffer'` and `objectMode: true` are used.22// See https://github.com/sindresorhus/execa/issues/69423type StdioTransform = ((chunks: Iterable<unknown>) => AsyncGenerator<unknown, void, void>);23type StdioTransform = (chunk: unknown) => AsyncGenerator<unknown, void, void> | Generator<unknown, void, void>;24type StdioFinal = () => AsyncGenerator<unknown, void, void> | Generator<unknown, void, void>;2526type StdioTransformFull = {27 transform: StdioTransform;28 final?: StdioFinal;29 binary?: boolean;30 objectMode?: boolean;31};32
287 unmodified lines
320 - an `Uint8Array`.321322 This can be an [array of values](https://github.com/sindresorhus/execa#redirect-stdinstdoutstderr-to-multiple-destinations) such as `['inherit', 'pipe']` or `[filePath, 'pipe']`.323322 This can also be an async generator function to transform the input. [Learn more.](https://github.com/sindresorhus/execa/tree/main/docs/transform.md)324 This can also be a generator function to transform the input. [Learn more.](https://github.com/sindresorhus/execa/tree/main/docs/transform.md)325326 @default `inherit` with `$`, `pipe` otherwise327 */328 readonly stdin?: StdinOption<IsSync>;
12 unmodified lines
341 - a web [`WritableStream`](https://developer.mozilla.org/en-US/docs/Web/API/WritableStream).342343 This can be an [array of values](https://github.com/sindresorhus/execa#redirect-stdinstdoutstderr-to-multiple-destinations) such as `['inherit', 'pipe']` or `[filePath, 'pipe']`.344343 This can also be an async generator function to transform the output. [Learn more.](https://github.com/sindresorhus/execa/tree/main/docs/transform.md)345 This can also be a generator function to transform the output. [Learn more.](https://github.com/sindresorhus/execa/tree/main/docs/transform.md)346347 @default 'pipe'348 */349 readonly stdout?: StdoutStderrOption<IsSync>;
12 unmodified lines
362 - a web [`WritableStream`](https://developer.mozilla.org/en-US/docs/Web/API/WritableStream).363364 This can be an [array of values](https://github.com/sindresorhus/execa#redirect-stdinstdoutstderr-to-multiple-destinations) such as `['inherit', 'pipe']` or `[filePath, 'pipe']`.365364 This can also be an async generator function to transform the output. [Learn more.](https://github.com/sindresorhus/execa/tree/main/docs/transform.md)366 This can also be a generator function to transform the output. [Learn more.](https://github.com/sindresorhus/execa/tree/main/docs/transform.md)367368 @default 'pipe'369 */370 readonly stderr?: StdoutStderrOption<IsSync>;
936 unmodified lines
modified:index.test-d.ts+164 added-109 removed
32 unmodified lines
33expectType<AnySyncChunk>({} as ExecaSyncReturnValue['stdout']);34expectType<AnySyncChunk>({} as ExecaSyncReturnValue['stderr']);35expectType<[undefined, AnySyncChunk, AnySyncChunk]>({} as ExecaSyncReturnValue['stdio']);3637const objectGenerator = async function * (lines: Iterable<unknown>) {38 for await (const line of lines) {39 yield JSON.parse(line as string) as object;40 }37const objectGenerator = function * (line: unknown) {38 yield JSON.parse(line as string) as object;39};4043const unknownArrayGenerator = async function * (lines: Iterable<unknown>) {44 for await (const line of lines) {45 yield line;46 }41const objectFinal = function * () {42 yield {};43};4449const booleanGenerator = async function * (lines: Iterable<boolean>) {50 for await (const line of lines) {51 yield line;52 }45const unknownGenerator = function * (line: unknown) {46 yield line;47};4855const arrayGenerator = async function * (lines: string[]) {56 for await (const line of lines) {57 yield line;58 }49const unknownFinal = function * () {50 yield {} as unknown;51};5261const invalidReturnGenerator = async function * (lines: Iterable<string>) {62 for await (const line of lines) {63 yield line;64 }53const booleanGenerator = function * (line: boolean) {54 yield line;55};5657const stringGenerator = function * (line: string) {58 yield line;59};6061const invalidReturnGenerator = function * (line: unknown) {62 yield line;63 return false;64};6569const syncGenerator = function * (lines: Iterable<string>) {70 for (const line of lines) {71 yield line;72 }7366const invalidReturnFinal = function * () {67 yield {} as unknown;68 return false;69};7071const asyncGenerator = async function * (line: unknown) {72 yield line;73};7475const asyncFinal = async function * () {76 yield {} as unknown;77};7879try {80 const execaPromise = execa('unicorns', {all: true});8182 const execaBufferPromise = execa('unicorns', {encoding: 'buffer', all: true});
265 unmodified lines
348349 const ignoreFd3Result = await execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', 'ignore']});350 expectType<undefined>(ignoreFd3Result.stdio[3]);351350 const objectTransformStdoutResult = await execa('unicorns', {stdout: {transform: objectGenerator, objectMode: true}});352 const objectTransformStdoutResult = await execa('unicorns', {stdout: {transform: objectGenerator, final: objectFinal, objectMode: true}});353 expectType<unknown[]>(objectTransformStdoutResult.stdout);354 expectType<[undefined, unknown[], string]>(objectTransformStdoutResult.stdio);355354 const objectTransformStderrResult = await execa('unicorns', {stderr: {transform: objectGenerator, objectMode: true}});356 const objectTransformStderrResult = await execa('unicorns', {stderr: {transform: objectGenerator, final: objectFinal, objectMode: true}});357 expectType<unknown[]>(objectTransformStderrResult.stderr);358 expectType<[undefined, string, unknown[]]>(objectTransformStderrResult.stdio);359358 const objectTransformStdioResult = await execa('unicorns', {stdio: ['pipe', 'pipe', {transform: objectGenerator, objectMode: true}]});360 const objectTransformStdioResult = await execa('unicorns', {stdio: ['pipe', 'pipe', {transform: objectGenerator, final: objectFinal, objectMode: true}]});361 expectType<unknown[]>(objectTransformStdioResult.stderr);362 expectType<[undefined, string, unknown[]]>(objectTransformStdioResult.stdio);363362 const singleObjectTransformStdoutResult = await execa('unicorns', {stdout: [{transform: objectGenerator, objectMode: true}]});364 const singleObjectTransformStdoutResult = await execa('unicorns', {stdout: [{transform: objectGenerator, final: objectFinal, objectMode: true}]});365 expectType<unknown[]>(singleObjectTransformStdoutResult.stdout);366 expectType<[undefined, unknown[], string]>(singleObjectTransformStdoutResult.stdio);367366 const manyObjectTransformStdoutResult = await execa('unicorns', {stdout: [{transform: objectGenerator, objectMode: true}, {transform: objectGenerator, objectMode: true}]});368 const manyObjectTransformStdoutResult = await execa('unicorns', {stdout: [{transform: objectGenerator, final: objectFinal, objectMode: true}, {transform: objectGenerator, final: objectFinal, objectMode: true}]});369 expectType<unknown[]>(manyObjectTransformStdoutResult.stdout);370 expectType<[undefined, unknown[], string]>(manyObjectTransformStdoutResult.stdio);371370 const falseObjectTransformStdoutResult = await execa('unicorns', {stdout: {transform: objectGenerator, objectMode: false}});372 const falseObjectTransformStdoutResult = await execa('unicorns', {stdout: {transform: objectGenerator, final: objectFinal, objectMode: false}});373 expectType<string>(falseObjectTransformStdoutResult.stdout);374 expectType<[undefined, string, string]>(falseObjectTransformStdoutResult.stdio);375374 const falseObjectTransformStderrResult = await execa('unicorns', {stderr: {transform: objectGenerator, objectMode: false}});376 const falseObjectTransformStderrResult = await execa('unicorns', {stderr: {transform: objectGenerator, final: objectFinal, objectMode: false}});377 expectType<string>(falseObjectTransformStderrResult.stderr);378 expectType<[undefined, string, string]>(falseObjectTransformStderrResult.stdio);379378 const falseObjectTransformStdioResult = await execa('unicorns', {stdio: ['pipe', 'pipe', {transform: objectGenerator, objectMode: false}]});380 const falseObjectTransformStdioResult = await execa('unicorns', {stdio: ['pipe', 'pipe', {transform: objectGenerator, final: objectFinal, objectMode: false}]});381 expectType<string>(falseObjectTransformStdioResult.stderr);382 expectType<[undefined, string, string]>(falseObjectTransformStdioResult.stdio);383382 const undefinedObjectTransformStdoutResult = await execa('unicorns', {stdout: {transform: objectGenerator}});384 const undefinedObjectTransformStdoutResult = await execa('unicorns', {stdout: {transform: objectGenerator, final: objectFinal}});385 expectType<string>(undefinedObjectTransformStdoutResult.stdout);386 expectType<[undefined, string, string]>(undefinedObjectTransformStdoutResult.stdio);387386 const noObjectTransformStdoutResult = await execa('unicorns', {stdout: objectGenerator});388 const noObjectTransformStdoutResult = await execa('unicorns', {stdout: objectGenerator, final: objectFinal});389 expectType<string>(noObjectTransformStdoutResult.stdout);390 expectType<[undefined, string, string]>(noObjectTransformStdoutResult.stdio);391390 const trueTrueObjectTransformResult = await execa('unicorns', {stdout: {transform: objectGenerator, objectMode: true}, stderr: {transform: objectGenerator, objectMode: true}, all: true});392 const trueTrueObjectTransformResult = await execa('unicorns', {stdout: {transform: objectGenerator, final: objectFinal, objectMode: true}, stderr: {transform: objectGenerator, final: objectFinal, objectMode: true}, all: true});393 expectType<unknown[]>(trueTrueObjectTransformResult.stdout);394 expectType<unknown[]>(trueTrueObjectTransformResult.stderr);395 expectType<unknown[]>(trueTrueObjectTransformResult.all);396 expectType<[undefined, unknown[], unknown[]]>(trueTrueObjectTransformResult.stdio);397396 const trueFalseObjectTransformResult = await execa('unicorns', {stdout: {transform: objectGenerator, objectMode: true}, stderr: {transform: objectGenerator, objectMode: false}, all: true});398 const trueFalseObjectTransformResult = await execa('unicorns', {stdout: {transform: objectGenerator, final: objectFinal, objectMode: true}, stderr: {transform: objectGenerator, final: objectFinal, objectMode: false}, all: true});399 expectType<unknown[]>(trueFalseObjectTransformResult.stdout);400 expectType<string>(trueFalseObjectTransformResult.stderr);401 expectType<unknown[]>(trueFalseObjectTransformResult.all);402 expectType<[undefined, unknown[], string]>(trueFalseObjectTransformResult.stdio);403402 const falseTrueObjectTransformResult = await execa('unicorns', {stdout: {transform: objectGenerator, objectMode: false}, stderr: {transform: objectGenerator, objectMode: true}, all: true});404 const falseTrueObjectTransformResult = await execa('unicorns', {stdout: {transform: objectGenerator, final: objectFinal, objectMode: false}, stderr: {transform: objectGenerator, final: objectFinal, objectMode: true}, all: true});405 expectType<string>(falseTrueObjectTransformResult.stdout);406 expectType<unknown[]>(falseTrueObjectTransformResult.stderr);407 expectType<unknown[]>(falseTrueObjectTransformResult.all);408 expectType<[undefined, string, unknown[]]>(falseTrueObjectTransformResult.stdio);409408 const falseFalseObjectTransformResult = await execa('unicorns', {stdout: {transform: objectGenerator, objectMode: false}, stderr: {transform: objectGenerator, objectMode: false}, all: true});410 const falseFalseObjectTransformResult = await execa('unicorns', {stdout: {transform: objectGenerator, final: objectFinal, objectMode: false}, stderr: {transform: objectGenerator, final: objectFinal, objectMode: false}, all: true});411 expectType<string>(falseFalseObjectTransformResult.stdout);412 expectType<string>(falseFalseObjectTransformResult.stderr);413 expectType<string>(falseFalseObjectTransformResult.all);414 expectType<[undefined, string, string]>(falseFalseObjectTransformResult.stdio);
103 unmodified lines
518 expectType<string>(streamStderrError.stdout);519 expectType<undefined>(streamStderrError.stderr);520 expectType<string>(streamStderrError.all);521520 const objectTransformStdoutError = error as ExecaError<{stdout: {transform: typeof objectGenerator; objectMode: true}}>;522 const objectTransformStdoutError = error as ExecaError<{stdout: {transform: typeof objectGenerator; final: typeof objectFinal; objectMode: true}}>;523 expectType<unknown[]>(objectTransformStdoutError.stdout);524 expectType<[undefined, unknown[], string]>(objectTransformStdoutError.stdio);525524 const objectTransformStderrError = error as ExecaError<{stderr: {transform: typeof objectGenerator; objectMode: true}}>;526 const objectTransformStderrError = error as ExecaError<{stderr: {transform: typeof objectGenerator; final: typeof objectFinal; objectMode: true}}>;527 expectType<unknown[]>(objectTransformStderrError.stderr);528 expectType<[undefined, string, unknown[]]>(objectTransformStderrError.stdio);529528 const objectTransformStdioError = error as ExecaError<{stdio: ['pipe', 'pipe', {transform: typeof objectGenerator; objectMode: true}]}>;530 const objectTransformStdioError = error as ExecaError<{stdio: ['pipe', 'pipe', {transform: typeof objectGenerator; final: typeof objectFinal; objectMode: true}]}>;531 expectType<unknown[]>(objectTransformStdioError.stderr);532 expectType<[undefined, string, unknown[]]>(objectTransformStdioError.stdio);533532 const falseObjectTransformStdoutError = error as ExecaError<{stdout: {transform: typeof objectGenerator; objectMode: false}}>;534 const falseObjectTransformStdoutError = error as ExecaError<{stdout: {transform: typeof objectGenerator; final: typeof objectFinal; objectMode: false}}>;535 expectType<string>(falseObjectTransformStdoutError.stdout);536 expectType<[undefined, string, string]>(falseObjectTransformStdoutError.stdio);537536 const falseObjectTransformStderrError = error as ExecaError<{stderr: {transform: typeof objectGenerator; objectMode: false}}>;538 const falseObjectTransformStderrError = error as ExecaError<{stderr: {transform: typeof objectGenerator; final: typeof objectFinal; objectMode: false}}>;539 expectType<string>(falseObjectTransformStderrError.stderr);540 expectType<[undefined, string, string]>(falseObjectTransformStderrError.stdio);541540 const falseObjectTransformStdioError = error as ExecaError<{stdio: ['pipe', 'pipe', {transform: typeof objectGenerator; objectMode: false}]}>;542 const falseObjectTransformStdioError = error as ExecaError<{stdio: ['pipe', 'pipe', {transform: typeof objectGenerator; final: typeof objectFinal; objectMode: false}]}>;543 expectType<string>(falseObjectTransformStdioError.stderr);544 expectType<[undefined, string, string]>(falseObjectTransformStdioError.stdio);545}546
285 unmodified lines
832execa('unicorns', {stdin: 1});833execaSync('unicorns', {stdin: 1});834execa('unicorns', {stdin: [1]});835execaSync('unicorns', {stdin: [1]});834execa('unicorns', {stdin: unknownArrayGenerator});835expectError(execaSync('unicorns', {stdin: unknownArrayGenerator}));836execa('unicorns', {stdin: [unknownArrayGenerator]});837expectError(execaSync('unicorns', {stdin: [unknownArrayGenerator]}));836execa('unicorns', {stdin: unknownGenerator});837expectError(execaSync('unicorns', {stdin: unknownGenerator}));838execa('unicorns', {stdin: [unknownGenerator]});839expectError(execaSync('unicorns', {stdin: [unknownGenerator]}));840expectError(execa('unicorns', {stdin: booleanGenerator}));839expectError(execa('unicorns', {stdin: arrayGenerator}));841expectError(execaSync('unicorns', {stdin: booleanGenerator}));842expectError(execa('unicorns', {stdin: stringGenerator}));843expectError(execaSync('unicorns', {stdin: stringGenerator}));844expectError(execa('unicorns', {stdin: invalidReturnGenerator}));841expectError(execa('unicorns', {stdin: syncGenerator}));842execa('unicorns', {stdin: {transform: unknownArrayGenerator}});843expectError(execaSync('unicorns', {stdin: {transform: unknownArrayGenerator}}));844execa('unicorns', {stdin: [{transform: unknownArrayGenerator}]});845expectError(execaSync('unicorns', {stdin: [{transform: unknownArrayGenerator}]}));845expectError(execaSync('unicorns', {stdin: invalidReturnGenerator}));846execa('unicorns', {stdin: asyncGenerator});847expectError(execaSync('unicorns', {stdin: asyncGenerator}));848execa('unicorns', {stdin: {transform: unknownGenerator}});849expectError(execaSync('unicorns', {stdin: {transform: unknownGenerator}}));850execa('unicorns', {stdin: [{transform: unknownGenerator}]});851expectError(execaSync('unicorns', {stdin: [{transform: unknownGenerator}]}));852expectError(execa('unicorns', {stdin: {transform: booleanGenerator}}));847expectError(execa('unicorns', {stdin: {transform: arrayGenerator}}));853expectError(execaSync('unicorns', {stdin: {transform: booleanGenerator}}));854expectError(execa('unicorns', {stdin: {transform: stringGenerator}}));855expectError(execaSync('unicorns', {stdin: {transform: stringGenerator}}));856expectError(execa('unicorns', {stdin: {transform: invalidReturnGenerator}}));849expectError(execa('unicorns', {stdin: {transform: syncGenerator}}));857expectError(execaSync('unicorns', {stdin: {transform: invalidReturnGenerator}}));858execa('unicorns', {stdin: {transform: asyncGenerator}});859expectError(execaSync('unicorns', {stdin: {transform: asyncGenerator}}));860execa('unicorns', {stdin: {transform: unknownGenerator, final: unknownFinal}});861expectError(execaSync('unicorns', {stdin: {transform: unknownGenerator, final: unknownFinal}}));862execa('unicorns', {stdin: [{transform: unknownGenerator, final: unknownFinal}]});863expectError(execaSync('unicorns', {stdin: [{transform: unknownGenerator, final: unknownFinal}]}));864expectError(execa('unicorns', {stdin: {transform: unknownGenerator, final: invalidReturnFinal}}));865expectError(execaSync('unicorns', {stdin: {transform: unknownGenerator, final: invalidReturnFinal}}));866execa('unicorns', {stdin: {transform: unknownGenerator, final: asyncFinal}});867expectError(execaSync('unicorns', {stdin: {transform: unknownGenerator, final: asyncFinal}}));868expectError(execa('unicorns', {stdin: {}}));869expectError(execa('unicorns', {stdin: {binary: true}}));870expectError(execa('unicorns', {stdin: {objectMode: true}}));871expectError(execa('unicorns', {stdin: {final: unknownFinal}}));853execa('unicorns', {stdin: {transform: unknownArrayGenerator, binary: true}});854expectError(execa('unicorns', {stdin: {transform: unknownArrayGenerator, binary: 'true'}}));855execa('unicorns', {stdin: {transform: unknownArrayGenerator, objectMode: true}});856expectError(execa('unicorns', {stdin: {transform: unknownArrayGenerator, objectMode: 'true'}}));872execa('unicorns', {stdin: {transform: unknownGenerator, binary: true}});873expectError(execa('unicorns', {stdin: {transform: unknownGenerator, binary: 'true'}}));874execa('unicorns', {stdin: {transform: unknownGenerator, objectMode: true}});875expectError(execa('unicorns', {stdin: {transform: unknownGenerator, objectMode: 'true'}}));876execa('unicorns', {stdin: undefined});877execaSync('unicorns', {stdin: undefined});878execa('unicorns', {stdin: [undefined]});879execaSync('unicorns', {stdin: [undefined]});
50 unmodified lines
930execa('unicorns', {stdout: 1});931execaSync('unicorns', {stdout: 1});932execa('unicorns', {stdout: [1]});933execaSync('unicorns', {stdout: [1]});915execa('unicorns', {stdout: unknownArrayGenerator});916expectError(execaSync('unicorns', {stdout: unknownArrayGenerator}));917execa('unicorns', {stdout: [unknownArrayGenerator]});918expectError(execaSync('unicorns', {stdout: [unknownArrayGenerator]}));934execa('unicorns', {stdout: unknownGenerator});935expectError(execaSync('unicorns', {stdout: unknownGenerator}));936execa('unicorns', {stdout: [unknownGenerator]});937expectError(execaSync('unicorns', {stdout: [unknownGenerator]}));938expectError(execa('unicorns', {stdout: booleanGenerator}));920expectError(execa('unicorns', {stdout: arrayGenerator}));939expectError(execaSync('unicorns', {stdout: booleanGenerator}));940expectError(execa('unicorns', {stdout: stringGenerator}));941expectError(execaSync('unicorns', {stdout: stringGenerator}));942expectError(execa('unicorns', {stdout: invalidReturnGenerator}));922expectError(execa('unicorns', {stdout: syncGenerator}));923execa('unicorns', {stdout: {transform: unknownArrayGenerator}});924expectError(execaSync('unicorns', {stdout: {transform: unknownArrayGenerator}}));925execa('unicorns', {stdout: [{transform: unknownArrayGenerator}]});926expectError(execaSync('unicorns', {stdout: [{transform: unknownArrayGenerator}]}));943expectError(execaSync('unicorns', {stdout: invalidReturnGenerator}));944execa('unicorns', {stdout: asyncGenerator});945expectError(execaSync('unicorns', {stdout: asyncGenerator}));946execa('unicorns', {stdout: {transform: unknownGenerator}});947expectError(execaSync('unicorns', {stdout: {transform: unknownGenerator}}));948execa('unicorns', {stdout: [{transform: unknownGenerator}]});949expectError(execaSync('unicorns', {stdout: [{transform: unknownGenerator}]}));950expectError(execa('unicorns', {stdout: {transform: booleanGenerator}}));928expectError(execa('unicorns', {stdout: {transform: arrayGenerator}}));951expectError(execaSync('unicorns', {stdout: {transform: booleanGenerator}}));952expectError(execa('unicorns', {stdout: {transform: stringGenerator}}));953expectError(execaSync('unicorns', {stdout: {transform: stringGenerator}}));954expectError(execa('unicorns', {stdout: {transform: invalidReturnGenerator}}));930expectError(execa('unicorns', {stdout: {transform: syncGenerator}}));955expectError(execaSync('unicorns', {stdout: {transform: invalidReturnGenerator}}));956execa('unicorns', {stdout: {transform: asyncGenerator}});957expectError(execaSync('unicorns', {stdout: {transform: asyncGenerator}}));958execa('unicorns', {stdout: {transform: unknownGenerator, final: unknownFinal}});959expectError(execaSync('unicorns', {stdout: {transform: unknownGenerator, final: unknownFinal}}));960execa('unicorns', {stdout: [{transform: unknownGenerator, final: unknownFinal}]});961expectError(execaSync('unicorns', {stdout: [{transform: unknownGenerator, final: unknownFinal}]}));962expectError(execa('unicorns', {stdout: {transform: unknownGenerator, final: invalidReturnFinal}}));963expectError(execaSync('unicorns', {stdout: {transform: unknownGenerator, final: invalidReturnFinal}}));964execa('unicorns', {stdout: {transform: unknownGenerator, final: asyncFinal}});965expectError(execaSync('unicorns', {stdout: {transform: unknownGenerator, final: asyncFinal}}));966expectError(execa('unicorns', {stdout: {}}));967expectError(execa('unicorns', {stdout: {binary: true}}));968expectError(execa('unicorns', {stdout: {objectMode: true}}));969expectError(execa('unicorns', {stdout: {final: unknownFinal}}));934execa('unicorns', {stdout: {transform: unknownArrayGenerator, binary: true}});935expectError(execa('unicorns', {stdout: {transform: unknownArrayGenerator, binary: 'true'}}));936execa('unicorns', {stdout: {transform: unknownArrayGenerator, objectMode: true}});937expectError(execa('unicorns', {stdout: {transform: unknownArrayGenerator, objectMode: 'true'}}));970execa('unicorns', {stdout: {transform: unknownGenerator, binary: true}});971expectError(execa('unicorns', {stdout: {transform: unknownGenerator, binary: 'true'}}));972execa('unicorns', {stdout: {transform: unknownGenerator, objectMode: true}});973expectError(execa('unicorns', {stdout: {transform: unknownGenerator, objectMode: 'true'}}));974execa('unicorns', {stdout: undefined});975execaSync('unicorns', {stdout: undefined});976execa('unicorns', {stdout: [undefined]});977execaSync('unicorns', {stdout: [undefined]});
50 unmodified lines
1028execa('unicorns', {stderr: 1});1029execaSync('unicorns', {stderr: 1});1030execa('unicorns', {stderr: [1]});1031execaSync('unicorns', {stderr: [1]});996execa('unicorns', {stderr: unknownArrayGenerator});997expectError(execaSync('unicorns', {stderr: unknownArrayGenerator}));998execa('unicorns', {stderr: [unknownArrayGenerator]});999expectError(execaSync('unicorns', {stderr: [unknownArrayGenerator]}));1032execa('unicorns', {stderr: unknownGenerator});1033expectError(execaSync('unicorns', {stderr: unknownGenerator}));1034execa('unicorns', {stderr: [unknownGenerator]});1035expectError(execaSync('unicorns', {stderr: [unknownGenerator]}));1036expectError(execa('unicorns', {stderr: booleanGenerator}));1001expectError(execa('unicorns', {stderr: arrayGenerator}));1037expectError(execaSync('unicorns', {stderr: booleanGenerator}));1038expectError(execa('unicorns', {stderr: stringGenerator}));1039expectError(execaSync('unicorns', {stderr: stringGenerator}));1040expectError(execa('unicorns', {stderr: invalidReturnGenerator}));1003expectError(execa('unicorns', {stderr: syncGenerator}));1004execa('unicorns', {stderr: {transform: unknownArrayGenerator}});1005expectError(execaSync('unicorns', {stderr: {transform: unknownArrayGenerator}}));1006execa('unicorns', {stderr: [{transform: unknownArrayGenerator}]});1007expectError(execaSync('unicorns', {stderr: [{transform: unknownArrayGenerator}]}));1041expectError(execaSync('unicorns', {stderr: invalidReturnGenerator}));1042execa('unicorns', {stderr: asyncGenerator});1043expectError(execaSync('unicorns', {stderr: asyncGenerator}));1044execa('unicorns', {stderr: {transform: unknownGenerator}});1045expectError(execaSync('unicorns', {stderr: {transform: unknownGenerator}}));1046execa('unicorns', {stderr: [{transform: unknownGenerator}]});1047expectError(execaSync('unicorns', {stderr: [{transform: unknownGenerator}]}));1048expectError(execa('unicorns', {stderr: {transform: booleanGenerator}}));1009expectError(execa('unicorns', {stderr: {transform: arrayGenerator}}));1049expectError(execaSync('unicorns', {stderr: {transform: booleanGenerator}}));1050expectError(execa('unicorns', {stderr: {transform: stringGenerator}}));1051expectError(execaSync('unicorns', {stderr: {transform: stringGenerator}}));1052expectError(execa('unicorns', {stderr: {transform: invalidReturnGenerator}}));1011expectError(execa('unicorns', {stderr: {transform: syncGenerator}}));1053expectError(execaSync('unicorns', {stderr: {transform: invalidReturnGenerator}}));1054execa('unicorns', {stderr: {transform: asyncGenerator}});1055expectError(execaSync('unicorns', {stderr: {transform: asyncGenerator}}));1056execa('unicorns', {stderr: {transform: unknownGenerator, final: unknownFinal}});1057expectError(execaSync('unicorns', {stderr: {transform: unknownGenerator, final: unknownFinal}}));1058execa('unicorns', {stderr: [{transform: unknownGenerator, final: unknownFinal}]});1059expectError(execaSync('unicorns', {stderr: [{transform: unknownGenerator, final: unknownFinal}]}));1060expectError(execa('unicorns', {stderr: {transform: unknownGenerator, final: invalidReturnFinal}}));1061expectError(execaSync('unicorns', {stderr: {transform: unknownGenerator, final: invalidReturnFinal}}));1062execa('unicorns', {stderr: {transform: unknownGenerator, final: asyncFinal}});1063expectError(execaSync('unicorns', {stderr: {transform: unknownGenerator, final: asyncFinal}}));1064expectError(execa('unicorns', {stderr: {}}));1065expectError(execa('unicorns', {stderr: {binary: true}}));1066expectError(execa('unicorns', {stderr: {objectMode: true}}));1067expectError(execa('unicorns', {stderr: {final: unknownFinal}}));1015execa('unicorns', {stderr: {transform: unknownArrayGenerator, binary: true}});1016expectError(execa('unicorns', {stderr: {transform: unknownArrayGenerator, binary: 'true'}}));1017execa('unicorns', {stderr: {transform: unknownArrayGenerator, objectMode: true}});1018expectError(execa('unicorns', {stderr: {transform: unknownArrayGenerator, objectMode: 'true'}}));1068execa('unicorns', {stderr: {transform: unknownGenerator, binary: true}});1069expectError(execa('unicorns', {stderr: {transform: unknownGenerator, binary: 'true'}}));1070execa('unicorns', {stderr: {transform: unknownGenerator, objectMode: true}});1071expectError(execa('unicorns', {stderr: {transform: unknownGenerator, objectMode: 'true'}}));1072execa('unicorns', {stderr: undefined});1073execaSync('unicorns', {stderr: undefined});1074execa('unicorns', {stderr: [undefined]});1075execaSync('unicorns', {stderr: [undefined]});
28 unmodified lines
1104expectError(execa('unicorns', {stdio: 'ipc'}));1105expectError(execaSync('unicorns', {stdio: 'ipc'}));1106expectError(execa('unicorns', {stdio: 1}));1107expectError(execaSync('unicorns', {stdio: 1}));1055expectError(execa('unicorns', {stdio: unknownArrayGenerator}));1056expectError(execaSync('unicorns', {stdio: unknownArrayGenerator}));1057expectError(execa('unicorns', {stdio: {transform: unknownArrayGenerator}}));1058expectError(execaSync('unicorns', {stdio: {transform: unknownArrayGenerator}}));1108expectError(execa('unicorns', {stdio: unknownGenerator}));1109expectError(execaSync('unicorns', {stdio: unknownGenerator}));1110expectError(execa('unicorns', {stdio: {transform: unknownGenerator}}));1111expectError(execaSync('unicorns', {stdio: {transform: unknownGenerator}}));1112expectError(execa('unicorns', {stdio: fileUrl}));1113expectError(execaSync('unicorns', {stdio: fileUrl}));1114expectError(execa('unicorns', {stdio: {file: './test'}}));1115expectError(execaSync('unicorns', {stdio: {file: './test'}}));
42 unmodified lines
1158 'ignore',1159 'inherit',1160 process.stdin,1161 1,1109 unknownArrayGenerator,1110 {transform: unknownArrayGenerator},1111 {transform: unknownArrayGenerator, binary: true},1112 {transform: unknownArrayGenerator, objectMode: true},1162 unknownGenerator,1163 {transform: unknownGenerator},1164 {transform: unknownGenerator, binary: true},1165 {transform: unknownGenerator, objectMode: true},1166 {transform: unknownGenerator, final: unknownFinal},1167 undefined,1168 fileUrl,1169 {file: './test'},1170 new Writable(),
21 unmodified lines
1192 new Readable(),1193 new Uint8Array(),1194 ],1195});1142expectError(execaSync('unicorns', {stdio: [unknownArrayGenerator]}));1143expectError(execaSync('unicorns', {stdio: [{transform: unknownArrayGenerator}]}));1196expectError(execaSync('unicorns', {stdio: [unknownGenerator]}));1197expectError(execaSync('unicorns', {stdio: [{transform: unknownGenerator}]}));1198expectError(execaSync('unicorns', {stdio: [new WritableStream()]}));1199expectError(execaSync('unicorns', {stdio: [new ReadableStream()]}));1200expectError(execaSync('unicorns', {stdio: [emptyStringGenerator()]}));1201expectError(execaSync('unicorns', {stdio: [asyncStringGenerator()]}));
6 unmodified lines
1208 ['ignore'],1209 ['inherit'],1210 [process.stdin],1211 [1],1158 [unknownArrayGenerator],1159 [{transform: unknownArrayGenerator}],1160 [{transform: unknownArrayGenerator, binary: true}],1161 [{transform: unknownArrayGenerator, objectMode: true}],1212 [unknownGenerator],1213 [{transform: unknownGenerator}],1214 [{transform: unknownGenerator, binary: true}],1215 [{transform: unknownGenerator, objectMode: true}],1216 [{transform: unknownGenerator, final: unknownFinal}],1217 [undefined],1218 [fileUrl],1219 [{file: './test'}],1220 [new Writable()],
25 unmodified lines
1246 [new Readable()],1247 [new Uint8Array()],1248 ],1249});1195expectError(execaSync('unicorns', {stdio: [[unknownArrayGenerator]]}));1196expectError(execaSync('unicorns', {stdio: [[{transform: unknownArrayGenerator}]]}));1250expectError(execaSync('unicorns', {stdio: [[unknownGenerator]]}));1251expectError(execaSync('unicorns', {stdio: [[{transform: unknownGenerator}]]}));1252expectError(execaSync('unicorns', {stdio: [[new WritableStream()]]}));1253expectError(execaSync('unicorns', {stdio: [[new ReadableStream()]]}));1254expectError(execaSync('unicorns', {stdio: [[['foo', 'bar']]]}));1255expectError(execaSync('unicorns', {stdio: [[[new Uint8Array(), new Uint8Array()]]]}));
149 unmodified lines
modified:readme.md+7 added-7 removed
556 unmodified lines
557See also the [`input`](#input) and [`stdin`](#stdin) options.558559#### stdin560561Type: `string | number | stream.Readable | ReadableStream | URL | Uint8Array | Iterable<string> | Iterable<Uint8Array> | Iterable<unknown> | AsyncIterable<string> | AsyncIterable<Uint8Array> | AsyncIterable<unknown> | AsyncGeneratorFunction<string> | AsyncGeneratorFunction<Uint8Array> | AsyncGeneratorFunction<unknown>` (or a tuple of those types)\561Type: `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)\562Default: `inherit` with [`$`](#command), `pipe` otherwise563564[How to setup](https://nodejs.org/api/child_process.html#child_process_options_stdio) the child process' standard input. This can be:565- `'pipe'`: Sets [`childProcess.stdin`](https://nodejs.org/api/child_process.html#subprocessstdin) stream.
10 unmodified lines
576- an `Uint8Array`.577578This can be an [array of values](#redirect-stdinstdoutstderr-to-multiple-destinations) such as `['inherit', 'pipe']` or `[filePath, 'pipe']`.579580This can also be an async generator function to transform the input. [Learn more.](docs/transform.md)580This can also be a generator function to transform the input. [Learn more.](docs/transform.md)581582#### stdout583584Type: `string | number | stream.Writable | WritableStream | URL | AsyncGeneratorFunction<string> | AsyncGeneratorFunction<Uint8Array> | AsyncGeneratorFunction<unknown>` (or a tuple of those types)\584Type: `string | number | stream.Writable | WritableStream | URL | GeneratorFunction<string> | GeneratorFunction<Uint8Array> | GeneratorFunction<unknown>| AsyncGeneratorFunction<string> | AsyncGeneratorFunction<Uint8Array> | AsyncGeneratorFunction<unknown>` (or a tuple of those types)\585Default: `pipe`586587[How to setup](https://nodejs.org/api/child_process.html#child_process_options_stdio) the child process' standard output. This can be:588- `'pipe'`: Sets [`childProcessResult.stdout`](#stdout) (as a string or `Uint8Array`) and [`childProcess.stdout`](https://nodejs.org/api/child_process.html#subprocessstdout) (as a stream).
8 unmodified lines
597- a web [`WritableStream`](https://developer.mozilla.org/en-US/docs/Web/API/WritableStream).598599This can be an [array of values](#redirect-stdinstdoutstderr-to-multiple-destinations) such as `['inherit', 'pipe']` or `[filePath, 'pipe']`.600601This can also be an async generator function to transform the output. [Learn more.](docs/transform.md)601This can also be a generator function to transform the output. [Learn more.](docs/transform.md)602603#### stderr604605Type: `string | number | stream.Writable | WritableStream | URL | AsyncGeneratorFunction<string> | AsyncGeneratorFunction<Uint8Array> | AsyncGeneratorFunction<unknown>` (or a tuple of those types)`\605Type: `string | number | stream.Writable | WritableStream | URL | GeneratorFunction<string> | GeneratorFunction<Uint8Array> | GeneratorFunction<unknown>| AsyncGeneratorFunction<string> | AsyncGeneratorFunction<Uint8Array> | AsyncGeneratorFunction<unknown>` (or a tuple of those types)\606Default: `pipe`607608[How to setup](https://nodejs.org/api/child_process.html#child_process_options_stdio) the child process' standard error. This can be:609- `'pipe'`: Sets [`childProcessResult.stderr`](#stderr) (as a string or `Uint8Array`) and [`childProcess.stderr`](https://nodejs.org/api/child_process.html#subprocessstderr) (as a stream).
8 unmodified lines
618- a web [`WritableStream`](https://developer.mozilla.org/en-US/docs/Web/API/WritableStream).619620This can be an [array of values](#redirect-stdinstdoutstderr-to-multiple-destinations) such as `['inherit', 'pipe']` or `[filePath, 'pipe']`.621622This can also be an async generator function to transform the output. [Learn more.](docs/transform.md)622This can also be a generator function to transform the output. [Learn more.](docs/transform.md)623624#### stdio625626Type: `string | Array<string | number | stream.Readable | stream.Writable | ReadableStream | WritableStream | URL | Uint8Array | Iterable<string> | Iterable<Uint8Array> | Iterable<unknown> | AsyncIterable<string> | AsyncIterable<Uint8Array> | AsyncIterable<unknown> | AsyncGeneratorFunction<string> | AsyncGeneratorFunction<Uint8Array> | AsyncGeneratorFunction<unknown>>` (or a tuple of those types)\626Type: `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)\627Default: `pipe`628629Like 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'}`.630
326 unmodified lines