Allow piping process to any file descriptor (#903)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by ehmicky · committed by GitHub · parent 588bf16 · Browse files · 20 files·+441 added−213 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
20 files+441 added−213 removed
- tests:+302 added−133 removed
- other:+139 added−80 removed
Provenance
- Commit
6642cd2- Tree
c45ba6d- Author
ehmicky <ehmicky@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent
588bf16
20 files changed+441 added−213 removed
modified:lib/pipe/setup.js+2 added-2 removed
8 unmodified lines91011121313141516171819192021222337 unmodified lines8 unmodified linesexport const pipeToSubprocess = (sourceInfo, ...args) => { if (isPlainObject(args[0])) { return pipeToSubprocess.bind(undefined, { ...sourceInfo, destinationOptions: {...sourceInfo.destinationOptions, ...args[0]}, boundOptions: {...sourceInfo.boundOptions, ...args[0]}, }); }
const {destination, ...normalizedInfo} = normalizePipeArguments(sourceInfo, ...args); const promise = handlePipePromise({...normalizedInfo, destination}); promise.pipe = pipeToSubprocess.bind(undefined, {...sourceInfo, source: destination, sourcePromise: promise, destinationOptions: {}}); promise.pipe = pipeToSubprocess.bind(undefined, {...sourceInfo, source: destination, sourcePromise: promise, boundOptions: {}}); return promise;};
const handlePipePromise = async ({37 unmodified linesmodified:lib/pipe/validate.js+76 added-48 removed
2 unmodified lines3 import {normalizeArguments} from '../arguments/options.js';4 import {STANDARD_STREAMS_ALIASES} from '../utils.js';5 import {getStartTime} from '../return/duration.js';6 7-export const normalizePipeArguments = ({source, sourcePromise, stdioStreamsGroups, destinationOptions}, ...args) => {7+export const normalizePipeArguments = ({source, sourcePromise, boundOptions}, ...args) => {8 const startTime = getStartTime();9- const sourceOptions = SUBPROCESS_OPTIONS.get(source);9 const {10 destination,11 destinationStream,12 destinationError,14- pipeOptions: {from, unpipeSignal} = {},15- } = getDestinationStream(destinationOptions, ...args);16- const {sourceStream, sourceError} = getSourceStream(source, stdioStreamsGroups, from, sourceOptions);13+ from,14+ unpipeSignal,15+ } = getDestinationStream(boundOptions, args);16+ const {sourceStream, sourceError} = getSourceStream(source, from);17+ const {options: sourceOptions, stdioStreamsGroups} = SUBPROCESS_OPTIONS.get(source);18 return {19 sourcePromise,20 sourceStream,21 sourceOptions,6 unmodified lines28 startTime,29 };30 };31 31-const getDestinationStream = (destinationOptions, ...args) => {32+const getDestinationStream = (boundOptions, args) => {33 try {33- const {destination, pipeOptions} = getDestination(destinationOptions, ...args);34- const destinationStream = destination.stdin;35- if (destinationStream === null) {36- throw new TypeError('The destination subprocess\'s stdin must be available. Please set its "stdin" option to "pipe".');37- }38-39- return {destination, destinationStream, pipeOptions};34+ const {35+ destination,36+ pipeOptions: {from, to, unpipeSignal} = {},37+ } = getDestination(boundOptions, ...args);38+ const destinationStream = getWritable(destination, to);39+ return {destination, destinationStream, from, unpipeSignal};40 } catch (error) {41 return {destinationError: error};42 }43 };44 45-const getDestination = (destinationOptions, firstArgument, ...args) => {45+const getDestination = (boundOptions, firstArgument, ...args) => {46 if (Array.isArray(firstArgument)) {47- const destination = create$({...destinationOptions, ...PIPED_SUBPROCESS_OPTIONS})(firstArgument, ...args);48- return {destination, pipeOptions: destinationOptions};47+ const destination = create$({...boundOptions, ...PIPED_SUBPROCESS_OPTIONS})(firstArgument, ...args);48+ return {destination, pipeOptions: boundOptions};49 }50 51 if (typeof firstArgument === 'string' || firstArgument instanceof URL) {52- if (Object.keys(destinationOptions).length > 0) {53- throw new TypeError('Please use .pipe("file", ..., options) or .pipe(execa("file", ..., options)) instead of .pipe(options)(execa("file", ...)).');52+ if (Object.keys(boundOptions).length > 0) {53+ throw new TypeError('Please use .pipe("file", ..., options) or .pipe(execa("file", ..., options)) instead of .pipe(options)("file", ...).');54 }55 56 const [rawFile, rawArgs, rawOptions] = normalizeArguments(firstArgument, ...args);57 const destination = execa(rawFile, rawArgs, {...rawOptions, ...PIPED_SUBPROCESS_OPTIONS});58 return {destination, pipeOptions: rawOptions};59 }60 61 if (SUBPROCESS_OPTIONS.has(firstArgument)) {62- if (Object.keys(destinationOptions).length > 0) {62+ if (Object.keys(boundOptions).length > 0) {63 throw new TypeError('Please use .pipe(options)`command` or .pipe($(options)`command`) instead of .pipe(options)($`command`).');64 }65 66 return {destination: firstArgument, pipeOptions: args[0]};5 unmodified lines72 const PIPED_SUBPROCESS_OPTIONS = {stdin: 'pipe', piped: true};73 74 export const SUBPROCESS_OPTIONS = new WeakMap();75 76-const getSourceStream = (source, stdioStreamsGroups, from, sourceOptions) => {77- try {78- const fdNumber = getFdNumber(stdioStreamsGroups, from);79- const sourceStream = fdNumber === 'all' ? source.all : source.stdio[fdNumber];76+const getWritable = (destination, to = 'stdin') => {77+ const isWritable = true;78+ const {options, stdioStreamsGroups} = SUBPROCESS_OPTIONS.get(destination);79+ const fdNumber = getFdNumber(stdioStreamsGroups, to, isWritable);80+ const destinationStream = destination.stdio[fdNumber];81 81- if (sourceStream === null || sourceStream === undefined) {82- throw new TypeError(getInvalidStdioOptionMessage(fdNumber, from, sourceOptions));83- }82+ if (destinationStream === null) {83+ throw new TypeError(getInvalidStdioOptionMessage(fdNumber, to, options, isWritable));84+ }85 86+ return destinationStream;87+};88+89+const getSourceStream = (source, from) => {90+ try {91+ const sourceStream = getReadable(source, from);92 return {sourceStream};93 } catch (error) {94 return {sourceError: error};95 }96 };97 91-const getFdNumber = (stdioStreamsGroups, from = 'stdout') => {92- const fdNumber = STANDARD_STREAMS_ALIASES.includes(from)93- ? STANDARD_STREAMS_ALIASES.indexOf(from)94- : from;98+const getReadable = (source, from = 'stdout') => {99+ const isWritable = false;100+ const {options, stdioStreamsGroups} = SUBPROCESS_OPTIONS.get(source);101+ const fdNumber = getFdNumber(stdioStreamsGroups, from, isWritable);102+ const sourceStream = fdNumber === 'all' ? source.all : source.stdio[fdNumber];103 104+ if (sourceStream === null || sourceStream === undefined) {105+ throw new TypeError(getInvalidStdioOptionMessage(fdNumber, from, options, isWritable));106+ }107+108+ return sourceStream;109+};110+111+const getFdNumber = (stdioStreamsGroups, fdName, isWritable) => {112+ const fdNumber = STANDARD_STREAMS_ALIASES.includes(fdName)113+ ? STANDARD_STREAMS_ALIASES.indexOf(fdName)114+ : fdName;115+116 if (fdNumber === 'all') {117 return fdNumber;118 }119 100- if (fdNumber === 0) {101- throw new TypeError('The "from" option must not be "stdin".');102- }103-120 if (!Number.isInteger(fdNumber) || fdNumber < 0) {121+ const {validOptions, defaultValue} = isWritable122+ ? {validOptions: '"stdin"', defaultValue: 'stdin'}123+ : {validOptions: '"stdout", "stderr", "all"', defaultValue: 'stdout'};105- throw new TypeError(`The "from" option must not be "${fdNumber}".106-It must be "stdout", "stderr", "all" or a file descriptor integer.107-It is optional and defaults to "stdout".`);124+ throw new TypeError(`"${getOptionName(isWritable)}" must not be "${fdNumber}".125+It must be ${validOptions} or a file descriptor integer.126+It is optional and defaults to "${defaultValue}".`);127 }128 129 const stdioStreams = stdioStreamsGroups[fdNumber];130 if (stdioStreams === undefined) {112- throw new TypeError(`The "from" option must not be ${fdNumber}. That file descriptor does not exist.131+ throw new TypeError(`"${getOptionName(isWritable)}" must not be ${fdNumber}. That file descriptor does not exist.132 Please set the "stdio" option to ensure that file descriptor exists.`);133 }134 116- if (stdioStreams[0].direction === 'input') {117- throw new TypeError(`The "from" option must not be ${fdNumber}. It must be a readable stream, not writable.`);135+ if (stdioStreams[0].direction === 'input' && !isWritable) {136+ throw new TypeError(`"${getOptionName(isWritable)}" must not be ${fdNumber}. It must be a readable stream, not writable.`);137 }138 139+ if (stdioStreams[0].direction !== 'input' && isWritable) {140+ throw new TypeError(`"${getOptionName(isWritable)}" must not be ${fdNumber}. It must be a writable stream, not readable.`);141+ }142+143 return fdNumber;144 };145 123-const getInvalidStdioOptionMessage = (fdNumber, from, sourceOptions) => {124- if (fdNumber === 'all' && !sourceOptions.all) {125- return 'The "all" option must be true to use `subprocess.pipe(destinationSubprocess, {from: "all"})`.';146+const getInvalidStdioOptionMessage = (fdNumber, fdName, options, isWritable) => {147+ if (fdNumber === 'all' && !options.all) {148+ return 'The "all" option must be true to use "from: \'all\'".';149 }150 128- const {optionName, optionValue} = getInvalidStdioOption(fdNumber, sourceOptions);129- const pipeOptions = from === undefined ? '' : `, {from: ${serializeOptionValue(from)}}`;130- return `The \`${optionName}: ${serializeOptionValue(optionValue)}\` option is incompatible with using \`subprocess.pipe(destinationSubprocess${pipeOptions})\`.151+ const {optionName, optionValue} = getInvalidStdioOption(fdNumber, options);152+ return `The "${optionName}: ${serializeOptionValue(optionValue)}" option is incompatible with using "${getOptionName(isWritable)}: ${serializeOptionValue(fdName)}".153 Please set this option with "pipe" instead.`;154 };155 134-const getInvalidStdioOption = (fdNumber, {stdout, stderr, stdio}) => {156+const getInvalidStdioOption = (fdNumber, {stdin, stdout, stderr, stdio}) => {157 const usedDescriptor = fdNumber === 'all' ? 1 : fdNumber;158 159+ if (usedDescriptor === 0 && stdin !== undefined) {160+ return {optionName: 'stdin', optionValue: stdin};161+ }162+163 if (usedDescriptor === 1 && stdout !== undefined) {164 return {optionName: 'stdout', optionValue: stdout};165 }166 5 unmodified lines172 };173 174 const serializeOptionValue = optionValue => {175 if (typeof optionValue === 'string') {150- return `"${optionValue}"`;176+ return `'${optionValue}'`;177 }178 179 return typeof optionValue === 'number' ? `${optionValue}` : 'Stream';180 };181+182+const getOptionName = isWritable => isWritable ? 'to' : 'from';modified:lib/stream/resolve.js+1 added-1 removed
17 unmodified lines1819202122222324252658 unmodified lines17 unmodified lines originalStreams, controller,}) => { const exitPromise = waitForExit(subprocess); const streamInfo = {originalStreams, stdioStreamsGroups, subprocess, exitPromise, propagating: new Set([])}; const streamInfo = {originalStreams, stdioStreamsGroups, subprocess, exitPromise, propagating: false};
const stdioPromises = waitForSubprocessStreams({subprocess, encoding, buffer, maxBuffer, streamInfo}); const allPromise = waitForAllStream({subprocess, encoding, buffer, maxBuffer, streamInfo}); const originalPromises = waitForOriginalStreams(originalStreams, subprocess, streamInfo);58 unmodified linesmodified:lib/stream/wait.js+5 added-5 removed
56 unmodified lines57 // We ignore EPIPEs on writable streams and aborts on readable streams since those can happen normally.58 // When one stream errors, the error is propagated to the other streams on the same file descriptor.59 // Those other streams might have a different direction due to the above.60 // When this happens, the direction of both the initial stream and the others should then be taken into account.61-// Therefore, we keep track of which file descriptor is currently propagating stream errors.61+// Therefore, we keep track of whether a stream error is currently propagating.62 export const handleStreamError = (error, fdNumber, streamInfo, isSameDirection) => {63 if (!shouldIgnoreStreamError(error, fdNumber, streamInfo, isSameDirection)) {64 throw error;65 }66 };67 68-const shouldIgnoreStreamError = (error, fdNumber, {stdioStreamsGroups, propagating}, isSameDirection = true) => {69- if (propagating.has(fdNumber)) {68+const shouldIgnoreStreamError = (error, fdNumber, streamInfo, isSameDirection = true) => {69+ if (streamInfo.propagating) {70 return isStreamEpipe(error) || isStreamAbort(error);71 }72 73- propagating.add(fdNumber);74- return isInputFileDescriptor(fdNumber, stdioStreamsGroups) === isSameDirection73+ streamInfo.propagating = true;74+ return isInputFileDescriptor(fdNumber, streamInfo.stdioStreamsGroups) === isSameDirection75 ? isStreamEpipe(error)76 : isStreamAbort(error);77 };78 21 unmodified linesmodified:lib/async.js+2 added-2 removed
15 unmodified lines16 17 export const execa = (rawFile, rawArgs, rawOptions) => {18 const {file, args, command, escapedCommand, startTime, verboseInfo, options, stdioStreamsGroups, stdioState} = handleAsyncArguments(rawFile, rawArgs, rawOptions);19 const {subprocess, promise} = spawnSubprocessAsync({file, args, options, startTime, verboseInfo, command, escapedCommand, stdioStreamsGroups, stdioState});20- subprocess.pipe = pipeToSubprocess.bind(undefined, {source: subprocess, sourcePromise: promise, stdioStreamsGroups, destinationOptions: {}});20+ subprocess.pipe = pipeToSubprocess.bind(undefined, {source: subprocess, sourcePromise: promise, boundOptions: {}});21 mergePromise(subprocess, promise);22- SUBPROCESS_OPTIONS.set(subprocess, options);22+ SUBPROCESS_OPTIONS.set(subprocess, {options, stdioStreamsGroups});23 return subprocess;24 };25 26 const handleAsyncArguments = (rawFile, rawArgs, rawOptions) => {77 unmodified linesmodified:test/exit/kill.js+1 added-1 removed
177 unmodified lines178 test('Cannot call .kill(null)', testInvalidKillArgument, null);179 test('Cannot call .kill(0n)', testInvalidKillArgument, 0n);180 test('Cannot call .kill(true)', testInvalidKillArgument, true);181 test('Cannot call .kill(errorObject)', testInvalidKillArgument, {name: '', message: '', stack: ''});182-test('Cannot call .kill([error])', testInvalidKillArgument, [new Error('test')]);182+test('Cannot call .kill(errorArray)', testInvalidKillArgument, [new Error('test')]);183 test('Cannot call .kill(undefined, true)', testInvalidKillArgument, undefined, true);184 test('Cannot call .kill("SIGTERM", true)', testInvalidKillArgument, 'SIGTERM', true);185 test('Cannot call .kill(true, error)', testInvalidKillArgument, true, new Error('test'));186 120 unmodified linesmodified:test/fixtures/noop-stdin-fd.js+3 added-5 removed
12334658910678#!/usr/bin/env nodeimport process from 'node:process';import {text} from 'node:stream/consumers';import {writeSync} from 'node:fs';
const stdinString = await text(process.stdin);const writableFileDescriptor = Number(process.argv[2]);if (stdinString !== '') { writeSync(writableFileDescriptor, stdinString);}process.stdin.on('data', chunk => { writeSync(writableFileDescriptor, chunk);});added:test/fixtures/stdin-fd-both.js+8 added
12345678#!/usr/bin/env nodeimport process from 'node:process';import {readFileSync} from 'node:fs';
const fdNumber = Number(process.argv[2]);
process.stdin.pipe(process.stdout);process.stdout.write(readFileSync(fdNumber));modified:test/helpers/stdio.js+2 added
1 import process from 'node:process';2+import {noopReadable} from './stream.js';3 4 export const identity = value => value;5 6 export const getStdio = (fdNumberOrName, stdioOption, length = 3) => {6 unmodified lines13 return {stdio};14 };15 16 export const fullStdio = getStdio(3, 'pipe');17+export const fullReadableStdio = () => getStdio(3, ['pipe', noopReadable()]);18 19 export const STANDARD_STREAMS = [process.stdin, process.stdout, process.stderr];20 21 export const prematureClose = {code: 'ERR_STREAM_PREMATURE_CLOSE'};modified:test/helpers/stream.js+3 added-1 removed
1-import {Readable, Writable, PassThrough} from 'node:stream';1+import {Readable, Writable, PassThrough, getDefaultHighWaterMark} from 'node:stream';2 import {foobarString} from './input.js';3 4 export const noopReadable = () => new Readable({read() {}});5 export const noopWritable = () => new Writable({write() {}});6 export const noopDuplex = () => new PassThrough().resume();7 export const simpleReadable = () => Readable.from([foobarString]);8+9+export const defaultHighWaterMark = getDefaultHighWaterMark(false);modified:test/pipe/setup.js+20 added-15 removed
1 import test from 'ava';2 import {execa} from '../../index.js';3 import {setFixtureDir} from '../helpers/fixtures-dir.js';4-import {fullStdio} from '../helpers/stdio.js';4+import {fullStdio, fullReadableStdio} from '../helpers/stdio.js';5+import {foobarString} from '../helpers/input.js';6 7 setFixtureDir();8 8-const pipeToSubprocess = async (t, fdNumber, from, options) => {9- const {stdout} = await execa('noop-fd.js', [`${fdNumber}`, 'test'], options)10- .pipe(execa('stdin.js'), {from});11- t.is(stdout, 'test');9+// eslint-disable-next-line max-params10+const pipeToSubprocess = async (t, readableFdNumber, writableFdNumber, from, to, readableOptions = {}, writableOptions = {}) => {11+ const {stdout} = await execa('noop-fd.js', [`${readableFdNumber}`, foobarString], readableOptions)12+ .pipe(execa('stdin-fd.js', [`${writableFdNumber}`], writableOptions), {from, to});13+ t.is(stdout, foobarString);14 };15 14-test('pipe(...) can pipe', pipeToSubprocess, 1, undefined, {});15-test('pipe(..., {from: "stdout"}) can pipe', pipeToSubprocess, 1, 'stdout', {});16-test('pipe(..., {from: 1}) can pipe', pipeToSubprocess, 1, 1, {});17-test('pipe(..., {from: "stderr"}) stderr can pipe', pipeToSubprocess, 2, 'stderr', {});18-test('pipe(..., {from: 2}) can pipe', pipeToSubprocess, 2, 2, {});19-test('pipe(..., {from: 3}) can pipe', pipeToSubprocess, 3, 3, fullStdio);20-test('pipe(..., {from: "all"}) can pipe stdout', pipeToSubprocess, 1, 'all', {all: true});21-test('pipe(..., {from: "all"}) can pipe stderr', pipeToSubprocess, 2, 'all', {all: true});22-test('pipe(..., {from: "all"}) can pipe stdout even with "stderr: ignore"', pipeToSubprocess, 1, 'all', {all: true, stderr: 'ignore'});23-test('pipe(..., {from: "all"}) can pipe stderr even with "stdout: ignore"', pipeToSubprocess, 2, 'all', {all: true, stdout: 'ignore'});16+test('pipe(...) can pipe', pipeToSubprocess, 1, 0);17+test('pipe(..., {from: "stdout"}) can pipe', pipeToSubprocess, 1, 0, 'stdout');18+test('pipe(..., {from: 1}) can pipe', pipeToSubprocess, 1, 0, 1);19+test('pipe(..., {from: "stderr"}) can pipe stderr', pipeToSubprocess, 2, 0, 'stderr');20+test('pipe(..., {from: 2}) can pipe', pipeToSubprocess, 2, 0, 2);21+test('pipe(..., {from: 3}) can pipe', pipeToSubprocess, 3, 0, 3, undefined, fullStdio);22+test('pipe(..., {from: "all"}) can pipe stdout', pipeToSubprocess, 1, 0, 'all', undefined, {all: true});23+test('pipe(..., {from: "all"}) can pipe stderr', pipeToSubprocess, 2, 0, 'all', undefined, {all: true});24+test('pipe(..., {from: "all"}) can pipe stdout even with "stderr: ignore"', pipeToSubprocess, 1, 0, 'all', undefined, {all: true, stderr: 'ignore'});25+test('pipe(..., {from: "all"}) can pipe stderr even with "stdout: ignore"', pipeToSubprocess, 2, 0, 'all', undefined, {all: true, stdout: 'ignore'});26+test('pipe(..., {to: "stdin"}) can pipe', pipeToSubprocess, 1, 0, undefined, 'stdin');27+test('pipe(..., {to: 0}) can pipe', pipeToSubprocess, 1, 0, undefined, 0);28+test('pipe(..., {to: 3}) can pipe', pipeToSubprocess, 1, 3, undefined, 3, {}, fullReadableStdio());modified:test/pipe/streaming.js+13 added
3 unmodified lines4 import {execa} from '../../index.js';5 import {setFixtureDir} from '../helpers/fixtures-dir.js';6 import {foobarString} from '../helpers/input.js';7 import {assertMaxListeners} from '../helpers/listeners.js';8+import {fullReadableStdio} from '../helpers/stdio.js';9 10 setFixtureDir();11 12 test('Can pipe two sources to same destination', async t => {74 unmodified lines87 t.is(await pipePromise, await destination);88 t.is(await secondPipePromise, await destination);89 });90 91+test('Can pipe same source to two streams from same subprocess', async t => {92+ const source = execa('noop-fd.js', ['1', foobarString]);93+ const destination = execa('stdin-fd-both.js', ['3'], fullReadableStdio());94+ const pipePromise = source.pipe(destination);95+ const secondPipePromise = source.pipe(destination, {to: 3});96+97+ t.like(await source, {stdout: foobarString});98+ t.like(await destination, {stdout: `${foobarString}${foobarString}`});99+ t.is(await pipePromise, await destination);100+ t.is(await secondPipePromise, await destination);101+});102+103 test('Can pipe a new source to same destination after some source has already written', async t => {104 const passThroughStream = new PassThrough();105 const source = execa('stdin.js', {stdin: ['pipe', passThroughStream]});106 const destination = execa('stdin.js');335 unmodified linesmodified:test/pipe/template.js+1 added-1 removed
227 unmodified lines228 229 test('execa.pipe(subprocess) does not force "stdin: pipe"', async t => {230 await t.throwsAsync(231 execa('noop.js', [foobarString]).pipe(execa('stdin.js', {stdin: 'ignore'})),232- {message: /stdin must be available/},232+ {message: /"stdin: 'ignore'" option is incompatible/},233 );234 });235 236 test('$.pipe(options)(subprocess) fails', async t => {36 unmodified linesmodified:test/pipe/validate.js+241 added-103 removed
3 unmodified lines4 import test from 'ava';5 import {execa} from '../../index.js';6 import {setFixtureDir} from '../helpers/fixtures-dir.js';7 import {foobarString} from '../helpers/input.js';8+import {fullStdio, getStdio} from '../helpers/stdio.js';9 import {getEarlyErrorSubprocess} from '../helpers/early-error.js';10 11 setFixtureDir();12 23 unmodified lines36 37 t.true(error.originalMessage.includes(message));38 };39 39-test('Must set "all" option to "true" to use pipe(..., {from: "all"})', async t => {40- await assertPipeError(41- t,42- execa('empty.js')43- .pipe(execa('empty.js'), {from: 'all'}),44- '"all" option must be true',45- );46-});40+const getMessage = message => Array.isArray(message)41+ ? `"${message[0]}: ${message[1]}" option is incompatible`42+ : message;43 48-const invalidDestination = async (t, getDestination) => {49- await assertPipeError(50- t,51- execa('empty.js')52- .pipe(getDestination()),53- 'an Execa subprocess',54- );44+const testPipeError = async (t, {45+ message,46+ sourceOptions = {},47+ destinationOptions = {},48+ getSource = () => execa('empty.js', sourceOptions),49+ getDestination = () => execa('empty.js', destinationOptions),50+ isScript = false,51+ from,52+ to,53+}) => {54+ const source = getSource();55+ const pipePromise = isScript ? source.pipe({from, to})`empty.js` : source.pipe(getDestination(), {from, to});56+ await assertPipeError(t, pipePromise, getMessage(message));57 };58 57-test('pipe() cannot pipe to non-subprocesses', invalidDestination, () => new PassThrough());58-test('pipe() cannot pipe to non-Execa subprocesses', invalidDestination, () => spawn('node', ['--version']));59-60-test('pipe() "from" option cannot be "stdin"', async t => {61- await assertPipeError(62- t,63- execa('empty.js')64- .pipe(execa('empty.js'), {from: 'stdin'}),65- 'not be "stdin"',66- );59+test('Must set "all" option to "true" to use .pipe("all")', testPipeError, {60+ from: 'all',61+ message: '"all" option must be true',62 });68-69-test('$.pipe() "from" option cannot be "stdin"', async t => {70- await assertPipeError(71- t,72- execa('empty.js')73- .pipe({from: 'stdin'})`empty.js`,74- 'not be "stdin"',75- );63+test('.pipe() cannot pipe to non-subprocesses', testPipeError, {64+ getDestination: () => new PassThrough(),65+ message: 'an Execa subprocess',66 });77-78-const invalidFromOption = async (t, from) => {79- await assertPipeError(80- t,81- execa('empty.js')82- .pipe(execa('empty.js'), {from}),83- '"from" option must not be',84- );85-};86-87-test('pipe() "from" option cannot be any string', invalidFromOption, 'other');88-test('pipe() "from" option cannot be a float', invalidFromOption, 1.5);89-test('pipe() "from" option cannot be a negative number', invalidFromOption, -1);90-91-test('pipe() "from" option cannot be a non-existing file descriptor', async t => {92- await assertPipeError(93- t,94- execa('empty.js')95- .pipe(execa('empty.js'), {from: 3}),96- 'file descriptor does not exist',97- );67+test('.pipe() cannot pipe to non-Execa subprocesses', testPipeError, {68+ getDestination: () => spawn('node', ['--version']),69+ message: 'an Execa subprocess',70 });99-100-test('pipe() "from" option cannot be an input file descriptor', async t => {101- await assertPipeError(102- t,103- execa('stdin-fd.js', ['3'], {stdio: ['pipe', 'pipe', 'pipe', new Uint8Array()]})104- .pipe(execa('empty.js'), {from: 3}),105- 'must be a readable stream',106- );71+test('.pipe() "from" option cannot be "stdin"', testPipeError, {72+ from: 'stdin',73+ message: '"from" must not be',74 });108-109-test('Must set destination "stdin" option to "pipe" to use pipe()', async t => {110- await assertPipeError(111- t,112- execa('empty.js')113- .pipe(execa('stdin.js', {stdin: 'ignore'})),114- 'stdin must be available',115- );75+test('$.pipe() "from" option cannot be "stdin"', testPipeError, {76+ from: 'stdin',77+ isScript: true,78+ message: '"from" must not be',79 });80+test('.pipe() "to" option cannot be "stdout"', testPipeError, {81+ to: 'stdout',82+ message: '"to" must not be',83+});84+test('$.pipe() "to" option cannot be "stdout"', testPipeError, {85+ to: 'stdout',86+ isScript: true,87+ message: '"to" must not be',88+});89+test('.pipe() "from" option cannot be any string', testPipeError, {90+ from: 'other',91+ message: 'must be "stdout", "stderr", "all"',92+});93+test('.pipe() "to" option cannot be any string', testPipeError, {94+ to: 'other',95+ message: 'must be "stdin"',96+});97+test('.pipe() "from" option cannot be a float', testPipeError, {98+ from: 1.5,99+ message: 'must be "stdout", "stderr", "all"',100+});101+test('.pipe() "to" option cannot be a float', testPipeError, {102+ to: 1.5,103+ message: 'must be "stdin"',104+});105+test('.pipe() "from" option cannot be a negative number', testPipeError, {106+ from: -1,107+ message: 'must be "stdout", "stderr", "all"',108+});109+test('.pipe() "to" option cannot be a negative number', testPipeError, {110+ to: -1,111+ message: 'must be "stdin"',112+});113+test('.pipe() "from" option cannot be a non-existing file descriptor', testPipeError, {114+ from: 3,115+ message: 'file descriptor does not exist',116+});117+test('.pipe() "to" option cannot be a non-existing file descriptor', testPipeError, {118+ to: 3,119+ message: 'file descriptor does not exist',120+});121+test('.pipe() "from" option cannot be an input file descriptor', testPipeError, {122+ sourceOptions: getStdio(3, new Uint8Array()),123+ from: 3,124+ message: 'must be a readable stream',125+});126+test('.pipe() "to" option cannot be an output file descriptor', testPipeError, {127+ destinationOptions: fullStdio,128+ to: 3,129+ message: 'must be a writable stream',130+});131+test('Cannot set "stdout" option to "ignore" to use .pipe()', testPipeError, {132+ sourceOptions: {stdout: 'ignore'},133+ message: ['stdout', '\'ignore\''],134+});135+test('Cannot set "stdin" option to "ignore" to use .pipe()', testPipeError, {136+ destinationOptions: {stdin: 'ignore'},137+ message: ['stdin', '\'ignore\''],138+});139+test('Cannot set "stdout" option to "ignore" to use .pipe(1)', testPipeError, {140+ sourceOptions: {stdout: 'ignore'},141+ from: 1,142+ message: ['stdout', '\'ignore\''],143+});144+test('Cannot set "stdin" option to "ignore" to use .pipe(0)', testPipeError, {145+ destinationOptions: {stdin: 'ignore'},146+ message: ['stdin', '\'ignore\''],147+ to: 0,148+});149+test('Cannot set "stdout" option to "ignore" to use .pipe("stdout")', testPipeError, {150+ sourceOptions: {stdout: 'ignore'},151+ from: 'stdout',152+ message: ['stdout', '\'ignore\''],153+});154+test('Cannot set "stdin" option to "ignore" to use .pipe("stdin")', testPipeError, {155+ destinationOptions: {stdin: 'ignore'},156+ message: ['stdin', '\'ignore\''],157+ to: 'stdin',158+});159+test('Cannot set "stdout" + "stderr" option to "ignore" to use .pipe()', testPipeError, {160+ sourceOptions: {stdout: 'ignore', stderr: 'ignore'},161+ message: ['stdout', '\'ignore\''],162+});163+test('Cannot set "stdout" + "stderr" option to "ignore" to use .pipe(1)', testPipeError, {164+ sourceOptions: {stdout: 'ignore', stderr: 'ignore'},165+ from: 1,166+ message: ['stdout', '\'ignore\''],167+});168+test('Cannot set "stdout" + "stderr" option to "ignore" to use .pipe("stdout")', testPipeError, {169+ sourceOptions: {stdout: 'ignore', stderr: 'ignore'},170+ from: 'stdout',171+ message: ['stdout', '\'ignore\''],172+});173+test('Cannot set "stdio[1]" option to "ignore" to use .pipe()', testPipeError, {174+ sourceOptions: {stdio: ['pipe', 'ignore', 'pipe']},175+ message: ['stdio[1]', '\'ignore\''],176+});177+test('Cannot set "stdio[0]" option to "ignore" to use .pipe()', testPipeError, {178+ destinationOptions: {stdio: ['ignore', 'pipe', 'pipe']},179+ message: ['stdio[0]', '\'ignore\''],180+});181+test('Cannot set "stdio[1]" option to "ignore" to use .pipe(1)', testPipeError, {182+ sourceOptions: {stdio: ['pipe', 'ignore', 'pipe']},183+ from: 1,184+ message: ['stdio[1]', '\'ignore\''],185+});186+test('Cannot set "stdio[0]" option to "ignore" to use .pipe(0)', testPipeError, {187+ destinationOptions: {stdio: ['ignore', 'pipe', 'pipe']},188+ message: ['stdio[0]', '\'ignore\''],189+ to: 0,190+});191+test('Cannot set "stdio[1]" option to "ignore" to use .pipe("stdout")', testPipeError, {192+ sourceOptions: {stdio: ['pipe', 'ignore', 'pipe']},193+ from: 'stdout',194+ message: ['stdio[1]', '\'ignore\''],195+});196+test('Cannot set "stdio[0]" option to "ignore" to use .pipe("stdin")', testPipeError, {197+ destinationOptions: {stdio: ['ignore', 'pipe', 'pipe']},198+ message: ['stdio[0]', '\'ignore\''],199+ to: 'stdin',200+});201+test('Cannot set "stderr" option to "ignore" to use .pipe(2)', testPipeError, {202+ sourceOptions: {stderr: 'ignore'},203+ from: 2,204+ message: ['stderr', '\'ignore\''],205+});206+test('Cannot set "stderr" option to "ignore" to use .pipe("stderr")', testPipeError, {207+ sourceOptions: {stderr: 'ignore'},208+ from: 'stderr',209+ message: ['stderr', '\'ignore\''],210+});211+test('Cannot set "stdout" + "stderr" option to "ignore" to use .pipe(2)', testPipeError, {212+ sourceOptions: {stdout: 'ignore', stderr: 'ignore'},213+ from: 2,214+ message: ['stderr', '\'ignore\''],215+});216+test('Cannot set "stdout" + "stderr" option to "ignore" to use .pipe("stderr")', testPipeError, {217+ sourceOptions: {stdout: 'ignore', stderr: 'ignore'},218+ from: 'stderr',219+ message: ['stderr', '\'ignore\''],220+});221+test('Cannot set "stdio[2]" option to "ignore" to use .pipe(2)', testPipeError, {222+ sourceOptions: {stdio: ['pipe', 'pipe', 'ignore']},223+ from: 2,224+ message: ['stdio[2]', '\'ignore\''],225+});226+test('Cannot set "stdio[2]" option to "ignore" to use .pipe("stderr")', testPipeError, {227+ sourceOptions: {stdio: ['pipe', 'pipe', 'ignore']},228+ from: 'stderr',229+ message: ['stdio[2]', '\'ignore\''],230+});231+test('Cannot set "stdio[3]" option to "ignore" to use .pipe(3)', testPipeError, {232+ sourceOptions: getStdio(3, 'ignore'),233+ from: 3,234+ message: ['stdio[3]', '\'ignore\''],235+});236+test('Cannot set "stdout" + "stderr" option to "ignore" to use .pipe("all")', testPipeError, {237+ sourceOptions: {stdout: 'ignore', stderr: 'ignore', all: true},238+ from: 'all',239+ message: ['stdout', '\'ignore\''],240+});241+test('Cannot set "stdio[1]" + "stdio[2]" option to "ignore" to use .pipe("all")', testPipeError, {242+ sourceOptions: {stdio: ['pipe', 'ignore', 'ignore'], all: true},243+ from: 'all',244+ message: ['stdio[1]', '\'ignore\''],245+});246+test('Cannot set "stdout" option to "inherit" to use .pipe()', testPipeError, {247+ sourceOptions: {stdout: 'inherit'},248+ message: ['stdout', '\'inherit\''],249+});250+test('Cannot set "stdin" option to "inherit" to use .pipe()', testPipeError, {251+ destinationOptions: {stdin: 'inherit'},252+ message: ['stdin', '\'inherit\''],253+});254+test('Cannot set "stdout" option to "ipc" to use .pipe()', testPipeError, {255+ sourceOptions: {stdout: 'ipc'},256+ message: ['stdout', '\'ipc\''],257+});258+test('Cannot set "stdin" option to "ipc" to use .pipe()', testPipeError, {259+ destinationOptions: {stdin: 'ipc'},260+ message: ['stdin', '\'ipc\''],261+});262+test('Cannot set "stdout" option to file descriptors to use .pipe()', testPipeError, {263+ sourceOptions: {stdout: 1},264+ message: ['stdout', '1'],265+});266+test('Cannot set "stdin" option to file descriptors to use .pipe()', testPipeError, {267+ destinationOptions: {stdin: 0},268+ message: ['stdin', '0'],269+});270+test('Cannot set "stdout" option to Node.js streams to use .pipe()', testPipeError, {271+ sourceOptions: {stdout: process.stdout},272+ message: ['stdout', 'Stream'],273+});274+test('Cannot set "stdin" option to Node.js streams to use .pipe()', testPipeError, {275+ destinationOptions: {stdin: process.stdin},276+ message: ['stdin', 'Stream'],277+});278+test('Cannot set "stdio[3]" option to Node.js Writable streams to use .pipe()', testPipeError, {279+ sourceOptions: getStdio(3, process.stdout),280+ message: ['stdio[3]', 'Stream'],281+ from: 3,282+});283+test('Cannot set "stdio[3]" option to Node.js Readable streams to use .pipe()', testPipeError, {284+ destinationOptions: getStdio(3, process.stdin),285+ message: ['stdio[3]', 'Stream'],286+ to: 3,287+});288 118-// eslint-disable-next-line max-params119-const invalidSource = async (t, optionName, optionValue, from, options) => {120- await assertPipeError(121- t,122- execa('empty.js', options)123- .pipe(execa('empty.js'), {from}),124- `\`${optionName}: ${optionValue}\` option is incompatible`,125- );126-};127-128-test('Cannot set "stdout" option to "ignore" to use pipe(...)', invalidSource, 'stdout', '"ignore"', undefined, {stdout: 'ignore'});129-test('Cannot set "stdout" option to "ignore" to use pipe(..., 1)', invalidSource, 'stdout', '"ignore"', 1, {stdout: 'ignore'});130-test('Cannot set "stdout" option to "ignore" to use pipe(..., "stdout")', invalidSource, 'stdout', '"ignore"', 'stdout', {stdout: 'ignore'});131-test('Cannot set "stdout" + "stderr" option to "ignore" to use pipe(...)', invalidSource, 'stdout', '"ignore"', undefined, {stdout: 'ignore', stderr: 'ignore'});132-test('Cannot set "stdout" + "stderr" option to "ignore" to use pipe(..., 1)', invalidSource, 'stdout', '"ignore"', 1, {stdout: 'ignore', stderr: 'ignore'});133-test('Cannot set "stdout" + "stderr" option to "ignore" to use pipe(..., "stdout")', invalidSource, 'stdout', '"ignore"', 'stdout', {stdout: 'ignore', stderr: 'ignore'});134-test('Cannot set "stdio[1]" option to "ignore" to use pipe(...)', invalidSource, 'stdio[1]', '"ignore"', undefined, {stdio: ['pipe', 'ignore', 'pipe']});135-test('Cannot set "stdio[1]" option to "ignore" to use pipe(..., 1)', invalidSource, 'stdio[1]', '"ignore"', 1, {stdio: ['pipe', 'ignore', 'pipe']});136-test('Cannot set "stdio[1]" option to "ignore" to use pipe(..., "stdout")', invalidSource, 'stdio[1]', '"ignore"', 'stdout', {stdio: ['pipe', 'ignore', 'pipe']});137-test('Cannot set "stderr" option to "ignore" to use pipe(..., 2)', invalidSource, 'stderr', '"ignore"', 2, {stderr: 'ignore'});138-test('Cannot set "stderr" option to "ignore" to use pipe(..., "stderr")', invalidSource, 'stderr', '"ignore"', 'stderr', {stderr: 'ignore'});139-test('Cannot set "stdout" + "stderr" option to "ignore" to use pipe(..., 2)', invalidSource, 'stderr', '"ignore"', 2, {stdout: 'ignore', stderr: 'ignore'});140-test('Cannot set "stdout" + "stderr" option to "ignore" to use pipe(..., "stderr")', invalidSource, 'stderr', '"ignore"', 'stderr', {stdout: 'ignore', stderr: 'ignore'});141-test('Cannot set "stdio[2]" option to "ignore" to use pipe(..., 2)', invalidSource, 'stdio[2]', '"ignore"', 2, {stdio: ['pipe', 'pipe', 'ignore']});142-test('Cannot set "stdio[2]" option to "ignore" to use pipe(..., "stderr")', invalidSource, 'stdio[2]', '"ignore"', 'stderr', {stdio: ['pipe', 'pipe', 'ignore']});143-test('Cannot set "stdio[3]" option to "ignore" to use pipe(..., 3)', invalidSource, 'stdio[3]', '"ignore"', 3, {stdio: ['pipe', 'pipe', 'pipe', 'ignore']});144-test('Cannot set "stdout" + "stderr" option to "ignore" to use pipe(..., "all")', invalidSource, 'stdout', '"ignore"', 'all', {stdout: 'ignore', stderr: 'ignore', all: true});145-test('Cannot set "stdio[1]" + "stdio[2]" option to "ignore" to use pipe(..., "all")', invalidSource, 'stdio[1]', '"ignore"', 'all', {stdio: ['pipe', 'ignore', 'ignore'], all: true});146-test('Cannot set "stdout" option to "inherit" to use pipe()', invalidSource, 'stdout', '"inherit"', 1, {stdout: 'inherit'});147-test('Cannot set "stdout" option to "ipc" to use pipe()', invalidSource, 'stdout', '"ipc"', 1, {stdout: 'ipc'});148-test('Cannot set "stdout" option to file descriptors to use pipe()', invalidSource, 'stdout', '1', 1, {stdout: 1});149-test('Cannot set "stdout" option to Node.js streams to use pipe()', invalidSource, 'stdout', 'Stream', 1, {stdout: process.stdout});150-289 test('Destination stream is ended when first argument is invalid', async t => {290 const source = execa('empty.js', {stdout: 'ignore'});291 const destination = execa('stdin.js');292 const pipePromise = source.pipe(destination);56 unmodified linesmodified:test/return/early-error.js+4 added-1 removed
77 unmodified lines78 test('child_process.spawn() early errors can use .pipe`` multiple times', testEarlyErrorPipe, () => $(earlyErrorOptions)`empty.js`.pipe(earlyErrorOptions)`empty.js`.pipe`empty.js`);79 80 const testEarlyErrorStream = async (t, getStreamProperty, all) => {81 const subprocess = getEarlyErrorSubprocess({all});82- getStreamProperty(subprocess).on('end', () => {});82+ const stream = getStreamProperty(subprocess);83+ stream.on('close', () => {});84+ stream.read?.();85+ stream.end?.();86 await t.throwsAsync(subprocess);87 };88 89 test('child_process.spawn() early errors can use .stdin', testEarlyErrorStream, ({stdin}) => stdin, false);4 unmodified linesmodified:test/stdio/transform.js+4 added-4 removed
1 import {Buffer} from 'node:buffer';2 import {once} from 'node:events';3 import {setTimeout, scheduler} from 'node:timers/promises';4-import {getDefaultHighWaterMark} from 'node:stream';4 import test from 'ava';5 import {getStreamAsArray} from 'get-stream';6 import {execa} from '../../index.js';7 import {foobarString} from '../helpers/input.js';5 unmodified lines13 outputObjectGenerator,14 convertTransformToFinal,15 noYieldGenerator,16 } from '../helpers/generator.js';17+import {defaultHighWaterMark} from '../helpers/stream.js';18 import {setFixtureDir} from '../helpers/fixtures-dir.js';19 20 setFixtureDir();21 4 unmodified lines26 27 test('Generators "final" can be used', testGeneratorFinal, 'noop.js');28 test('Generators "final" is used even on empty streams', testGeneratorFinal, 'empty.js');29 30-const repeatCount = getDefaultHighWaterMark() * 3;30+const repeatCount = defaultHighWaterMark * 3;31 32 const writerGenerator = function * () {33 for (let index = 0; index < repeatCount; index += 1) {34 yield '\n';54 unmodified lines89 90 const partsPerChunk = 4;91 const chunksPerCall = 10;92 const callCount = 5;93-const fullString = '\n'.repeat(getDefaultHighWaterMark(false) / partsPerChunk);93+const fullString = '\n'.repeat(defaultHighWaterMark / partsPerChunk);94 95 const yieldFullStrings = function * () {96 yield * Array.from({length: partsPerChunk * chunksPerCall}).fill(fullString);97 };8 unmodified lines106 107 const testManyYields = async (t, final) => {108 const subprocess = execa('noop.js', {stdout: convertTransformToFinal(manyYieldGenerator, final), buffer: false});109 const [chunks] = await Promise.all([getStreamAsArray(subprocess.stdout), subprocess]);110- const expectedChunk = Buffer.alloc(getDefaultHighWaterMark(false) * chunksPerCall).fill('\n');110+ const expectedChunk = Buffer.alloc(defaultHighWaterMark * chunksPerCall).fill('\n');111 t.deepEqual(chunks, Array.from({length: callCount}).fill(expectedChunk));112 };113 114 test('Generator "transform" yields are sent right away', testManyYields, false);90 unmodified linesmodified:test/stream/all.js+2 added-2 removed
1-import {getDefaultHighWaterMark} from 'node:stream';1 import test from 'ava';2 import {execa} from '../../index.js';3 import {setFixtureDir} from '../helpers/fixtures-dir.js';4+import {defaultHighWaterMark} from '../helpers/stream.js';5 6 setFixtureDir();7 8 test.serial('result.all shows both `stdout` and `stderr` intermixed', async t => {13 unmodified lines22 23 const testAllProperties = async (t, options) => {24 const subprocess = execa('empty.js', {...options, all: true});25 t.is(subprocess.all.readableObjectMode, false);26- t.is(subprocess.all.readableHighWaterMark, getDefaultHighWaterMark(false));26+ t.is(subprocess.all.readableHighWaterMark, defaultHighWaterMark);27 await subprocess;28 };29 30 test('subprocess.all has the right objectMode and highWaterMark - stdout + stderr', testAllProperties, {});31 unmodified linesmodified:index.d.ts+6 added-1 removed
830 unmodified lines831 : Readable;832 833 type PipeOptions = {834 /**835- Which stream to pipe. A file descriptor number can also be passed.835+ Which stream to pipe from the source subprocess. A file descriptor number can also be passed.836 837 `"all"` pipes both `stdout` and `stderr`. This requires the `all` option to be `true`.838 */839 readonly from?: 'stdout' | 'stderr' | 'all' | number;840 841 /**842+ Which stream to pipe to the destination subprocess. A file descriptor number can also be passed.843+ */844+ readonly to?: 'stdin' | number;845+846+ /**847 Unpipe the subprocess when the signal aborts.848 849 The `.pipe()` method will be rejected with a cancellation error.850 */548 unmodified linesmodified:index.test-d.ts+39 added-20 removed
86 unmodified lines87 const bufferResult = await execaBufferPromise;88 89 const scriptPromise = $`unicorns`;90 91- const pipeOptions = {from: 'stderr', all: true} as const;91+ const pipeOptions = {from: 'stderr', to: 3, all: true} as const;92 93 type BufferExecaReturnValue = typeof bufferResult;94 type EmptyExecaReturnValue = ExecaResult<{}>;95 type ShortcutExecaReturnValue = ExecaResult<typeof pipeOptions>;23 unmodified lines119 expectType<EmptyExecaReturnValue>(await execaPromise.pipe('pipe').pipe`stdin`);120 expectType<EmptyExecaReturnValue>(await scriptPromise.pipe('pipe').pipe`stdin`);121 expectType<ShortcutExecaReturnValue>(await execaPromise.pipe('pipe').pipe('stdin', pipeOptions));122 expectType<ShortcutExecaReturnValue>(await scriptPromise.pipe('pipe').pipe('stdin', pipeOptions));123- await execaPromise.pipe(execaPromise).pipe(execaBufferPromise, {from: 'stdout'});124- await scriptPromise.pipe(execaPromise).pipe(execaBufferPromise, {from: 'stdout'});125- await execaPromise.pipe(execaBufferPromise, {from: 'stdout'}).pipe`stdin`;126- await scriptPromise.pipe(execaBufferPromise, {from: 'stdout'}).pipe`stdin`;127- await execaPromise.pipe(execaBufferPromise, {from: 'stdout'}).pipe('stdin');128- await scriptPromise.pipe(execaBufferPromise, {from: 'stdout'}).pipe('stdin');129- await execaPromise.pipe`stdin`.pipe(execaBufferPromise, {from: 'stdout'});130- await scriptPromise.pipe`stdin`.pipe(execaBufferPromise, {from: 'stdout'});131- await execaPromise.pipe`stdin`.pipe({from: 'stdout'})`stdin`;132- await scriptPromise.pipe`stdin`.pipe({from: 'stdout'})`stdin`;133- await execaPromise.pipe`stdin`.pipe('stdin', {from: 'stdout'});134- await scriptPromise.pipe`stdin`.pipe('stdin', {from: 'stdout'});123+ await execaPromise.pipe(execaPromise).pipe(execaBufferPromise, pipeOptions);124+ await scriptPromise.pipe(execaPromise).pipe(execaBufferPromise, pipeOptions);125+ await execaPromise.pipe(execaBufferPromise, pipeOptions).pipe`stdin`;126+ await scriptPromise.pipe(execaBufferPromise, pipeOptions).pipe`stdin`;127+ await execaPromise.pipe(execaBufferPromise, pipeOptions).pipe('stdin');128+ await scriptPromise.pipe(execaBufferPromise, pipeOptions).pipe('stdin');129+ await execaPromise.pipe`stdin`.pipe(execaBufferPromise, pipeOptions);130+ await scriptPromise.pipe`stdin`.pipe(execaBufferPromise, pipeOptions);131+ await execaPromise.pipe`stdin`.pipe(pipeOptions)`stdin`;132+ await scriptPromise.pipe`stdin`.pipe(pipeOptions)`stdin`;133+ await execaPromise.pipe`stdin`.pipe('stdin', pipeOptions);134+ await scriptPromise.pipe`stdin`.pipe('stdin', pipeOptions);135 expectError(execaPromise.pipe(execaBufferPromise).stdout);136 expectError(scriptPromise.pipe(execaBufferPromise).stdout);137 expectError(execaPromise.pipe`stdin`.stdout);138 expectError(scriptPromise.pipe`stdin`.stdout);36 unmodified lines175 await execaPromise.pipe({from: 3})`stdin`;176 await scriptPromise.pipe({from: 3})`stdin`;177 await execaPromise.pipe('stdin', {from: 3});178 await scriptPromise.pipe('stdin', {from: 3});179- expectError(execaPromise.pipe(execaBufferPromise, {from: 'other'}));180- expectError(scriptPromise.pipe(execaBufferPromise, {from: 'other'}));181- expectError(execaPromise.pipe({from: 'other'})`stdin`);182- expectError(scriptPromise.pipe({from: 'other'})`stdin`);183- expectError(execaPromise.pipe('stdin', {from: 'other'}));184- expectError(scriptPromise.pipe('stdin', {from: 'other'}));179+ expectError(execaPromise.pipe(execaBufferPromise, {from: 'stdin'}));180+ expectError(scriptPromise.pipe(execaBufferPromise, {from: 'stdin'}));181+ expectError(execaPromise.pipe({from: 'stdin'})`stdin`);182+ expectError(scriptPromise.pipe({from: 'stdin'})`stdin`);183+ expectError(execaPromise.pipe('stdin', {from: 'stdin'}));184+ expectError(scriptPromise.pipe('stdin', {from: 'stdin'}));185+ await execaPromise.pipe(execaBufferPromise, {to: 'stdin'});186+ await scriptPromise.pipe(execaBufferPromise, {to: 'stdin'});187+ await execaPromise.pipe({to: 'stdin'})`stdin`;188+ await scriptPromise.pipe({to: 'stdin'})`stdin`;189+ await execaPromise.pipe('stdin', {to: 'stdin'});190+ await scriptPromise.pipe('stdin', {to: 'stdin'});191+ await execaPromise.pipe(execaBufferPromise, {to: 3});192+ await scriptPromise.pipe(execaBufferPromise, {to: 3});193+ await execaPromise.pipe({to: 3})`stdin`;194+ await scriptPromise.pipe({to: 3})`stdin`;195+ await execaPromise.pipe('stdin', {to: 3});196+ await scriptPromise.pipe('stdin', {to: 3});197+ expectError(execaPromise.pipe(execaBufferPromise, {to: 'stdout'}));198+ expectError(scriptPromise.pipe(execaBufferPromise, {to: 'stdout'}));199+ expectError(execaPromise.pipe({to: 'stdout'})`stdin`);200+ expectError(scriptPromise.pipe({to: 'stdout'})`stdin`);201+ expectError(execaPromise.pipe('stdin', {to: 'stdout'}));202+ expectError(scriptPromise.pipe('stdin', {to: 'stdout'}));203 await execaPromise.pipe(execaBufferPromise, {unpipeSignal: new AbortController().signal});204 await scriptPromise.pipe(execaBufferPromise, {unpipeSignal: new AbortController().signal});205 await execaPromise.pipe({unpipeSignal: new AbortController().signal})`stdin`;206 await scriptPromise.pipe({unpipeSignal: new AbortController().signal})`stdin`;17 unmodified lines224 await execaPromise.pipe(fileUrl);225 await execaPromise.pipe('stdin', []);226 await execaPromise.pipe('stdin', ['foo', 'bar']);227 await execaPromise.pipe('stdin', ['foo', 'bar'], {});210- await execaPromise.pipe('stdin', ['foo', 'bar'], {from: 'stderr', all: true});228+ await execaPromise.pipe('stdin', ['foo', 'bar'], {from: 'stderr', to: 'stdin', all: true});229 await execaPromise.pipe('stdin', {from: 'stderr'});230+ await execaPromise.pipe('stdin', {to: 'stdin'});231 await execaPromise.pipe('stdin', {all: true});232 expectError(await execaPromise.pipe(['foo', 'bar']));233 expectError(await execaPromise.pipe('stdin', 'foo'));234 expectError(await execaPromise.pipe('stdin', [false]));1356 unmodified linesmodified:readme.md+8 added-1 removed
395 unmodified lines396 397 Type: `"stdout" | "stderr" | "all" | number`\398 Default: `"stdout"`399 400-Which stream to pipe. A file descriptor number can also be passed.400+Which stream to pipe from the source subprocess. A file descriptor number can also be passed.401 402 `"all"` pipes both `stdout` and `stderr`. This requires the [`all` option](#all-2) to be `true`.403 404+##### pipeOptions.to405+406+Type: `"stdin" | number`\407+Default: `"stdin"`408+409+Which stream to pipe to the destination subprocess. A file descriptor number can also be passed.410+411 ##### pipeOptions.unpipeSignal412 413 Type: [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal)414 657 unmodified lines