Rename `index` to `fdNumber` (#862)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by ehmicky · committed by GitHub · parent 3bb0d61 · Browse files · 45 files·+394 added−394 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
45 files+394 added−394 removed
- tests:+285 added−285 removed
- other:+109 added−109 removed
Provenance
- Commit
295ef40- Tree
7a93ad3- Author
ehmicky <ehmicky@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent
3bb0d61
45 files changed+394 added−394 removed
modified:lib/pipe/validate.js+22 added-22 removed
46 unmodified lines4748495051525152535455555657585960616263646564656667686970697071727373747576777877787980818283838485858687888990909192939394959697969798991001011011021031041051061071081071081091101101111121131141141151161171181181191201211225 unmodified lines46 unmodified linesexport const PROCESS_OPTIONS = new WeakMap();
const getSourceStream = (source, stdioStreamsGroups, from, sourceOptions) => { try { const streamIndex = getStreamIndex(stdioStreamsGroups, from); const sourceStream = streamIndex === 'all' ? source.all : source.stdio[streamIndex]; const fdNumber = getFdNumber(stdioStreamsGroups, from); const sourceStream = fdNumber === 'all' ? source.all : source.stdio[fdNumber];
if (sourceStream === null || sourceStream === undefined) { throw new TypeError(getInvalidStdioOptionMessage(streamIndex, from, sourceOptions)); throw new TypeError(getInvalidStdioOptionMessage(fdNumber, from, sourceOptions)); }
return {sourceStream}; } catch (error) { return {sourceError: error}; }};
const getStreamIndex = (stdioStreamsGroups, from = 'stdout') => { const streamIndex = STANDARD_STREAMS_ALIASES.includes(from)const getFdNumber = (stdioStreamsGroups, from = 'stdout') => { const fdNumber = STANDARD_STREAMS_ALIASES.includes(from) ? STANDARD_STREAMS_ALIASES.indexOf(from) : from;
if (streamIndex === 'all') { return streamIndex; if (fdNumber === 'all') { return fdNumber; }
if (streamIndex === 0) { if (fdNumber === 0) { throw new TypeError('The "from" option must not be "stdin".'); }
if (!Number.isInteger(streamIndex) || streamIndex < 0) { throw new TypeError(`The "from" option must not be "${streamIndex}". if (!Number.isInteger(fdNumber) || fdNumber < 0) { throw new TypeError(`The "from" option must not be "${fdNumber}".It must be "stdout", "stderr", "all" or a file descriptor integer.It is optional and defaults to "stdout".`); }
const stdioStreams = stdioStreamsGroups[streamIndex]; const stdioStreams = stdioStreamsGroups[fdNumber]; if (stdioStreams === undefined) { throw new TypeError(`The "from" option must not be ${streamIndex}. That file descriptor does not exist. throw new TypeError(`The "from" option must not be ${fdNumber}. That file descriptor does not exist.Please set the "stdio" option to ensure that file descriptor exists.`); }
if (stdioStreams[0].direction === 'input') { throw new TypeError(`The "from" option must not be ${streamIndex}. It must be a readable stream, not writable.`); throw new TypeError(`The "from" option must not be ${fdNumber}. It must be a readable stream, not writable.`); }
return streamIndex; return fdNumber;};
const getInvalidStdioOptionMessage = (streamIndex, from, sourceOptions) => { if (streamIndex === 'all' && !sourceOptions.all) {const getInvalidStdioOptionMessage = (fdNumber, from, sourceOptions) => { if (fdNumber === 'all' && !sourceOptions.all) { return 'The "all" option must be true to use `childProcess.pipe(destinationProcess, {from: "all"})`.'; }
const {optionName, optionValue} = getInvalidStdioOption(streamIndex, sourceOptions); const {optionName, optionValue} = getInvalidStdioOption(fdNumber, sourceOptions); const pipeOptions = from === undefined ? '' : `, {from: ${serializeOptionValue(from)}}`; return `The \`${optionName}: ${serializeOptionValue(optionValue)}\` option is incompatible with using \`childProcess.pipe(destinationProcess${pipeOptions})\`.Please set this option with "pipe" instead.`;};
const getInvalidStdioOption = (streamIndex, {stdout, stderr, stdio}) => { const usedIndex = streamIndex === 'all' ? 1 : streamIndex;const getInvalidStdioOption = (fdNumber, {stdout, stderr, stdio}) => { const usedDescriptor = fdNumber === 'all' ? 1 : fdNumber;
if (usedIndex === 1 && stdout !== undefined) { if (usedDescriptor === 1 && stdout !== undefined) { return {optionName: 'stdout', optionValue: stdout}; }
if (usedIndex === 2 && stderr !== undefined) { if (usedDescriptor === 2 && stderr !== undefined) { return {optionName: 'stderr', optionValue: stderr}; }
return {optionName: `stdio[${usedIndex}]`, optionValue: stdio[usedIndex]}; return {optionName: `stdio[${usedDescriptor}]`, optionValue: stdio[usedDescriptor]};};
const serializeOptionValue = optionValue => { if (typeof optionValue === 'string') {5 unmodified linesmodified:lib/stdio/async.js+5 added-5 removed
47 unmodified lines48 pipeStdioOption(spawned, nonGeneratorStream, inputStreamsGroups, controller);49 }50 }51 52- for (const [index, inputStreams] of Object.entries(inputStreamsGroups)) {53- pipeStreams(inputStreams, spawned.stdio[index]);52+ for (const [fdNumber, inputStreams] of Object.entries(inputStreamsGroups)) {53+ pipeStreams(inputStreams, spawned.stdio[fdNumber]);54 }55 };56 57-const pipeStdioOption = (spawned, {type, value, direction, index}, inputStreamsGroups, controller) => {57+const pipeStdioOption = (spawned, {type, value, direction, fdNumber}, inputStreamsGroups, controller) => {58 if (type === 'native') {59 return;60 }61 62 setStandardStreamMaxListeners(value, controller);63 64 if (direction === 'output') {65- pipeStreams([spawned.stdio[index]], value);65+ pipeStreams([spawned.stdio[fdNumber]], value);66 } else {67- inputStreamsGroups[index] = [...(inputStreamsGroups[index] ?? []), value];67+ inputStreamsGroups[fdNumber] = [...(inputStreamsGroups[fdNumber] ?? []), value];68 }69 };70 71 // Multiple processes might be piping from/to `process.std*` at the same time.23 unmodified linesmodified:lib/stdio/direction.js+3 added-3 removed
4 unmodified lines5 isWritableStream as isNodeWritableStream,6 } from 'is-stream';7 import {isWritableStream} from './type.js';8 9-// For `stdio[index]` beyond stdin/stdout/stderr, we need to guess whether the value passed is intended for inputs or outputs.9+// For `stdio[fdNumber]` beyond stdin/stdout/stderr, we need to guess whether the value passed is intended for inputs or outputs.10 // This allows us to know whether to pipe _into_ or _from_ the stream.11-// When `stdio[index]` is a single value, this guess is fairly straightforward.11+// When `stdio[fdNumber]` is a single value, this guess is fairly straightforward.12 // However, when it is an array instead, we also need to make sure the different values are not incompatible with each other.13 export const addStreamDirection = stdioStreams => {14 const directions = stdioStreams.map(stdioStream => getStreamDirection(stdioStream));15 4 unmodified lines20 const direction = directions.find(Boolean);21 return stdioStreams.map(stdioStream => addDirection(stdioStream, direction));22 };23 24-const getStreamDirection = stdioStream => KNOWN_DIRECTIONS[stdioStream.index] ?? guessStreamDirection[stdioStream.type](stdioStream.value);24+const getStreamDirection = stdioStream => KNOWN_DIRECTIONS[stdioStream.fdNumber] ?? guessStreamDirection[stdioStream.type](stdioStream.value);25 26 // `stdin`/`stdout`/`stderr` have a known direction27 const KNOWN_DIRECTIONS = ['input', 'output', 'output'];28 52 unmodified linesmodified:lib/stdio/generator.js+5 added-5 removed
83 unmodified lines84 return {value: duplexStream};85 };86 87 // `childProcess.stdin|stdout|stderr|stdio` is directly mutated.88-export const pipeGenerator = (spawned, {value, direction, index}) => {88+export const pipeGenerator = (spawned, {value, direction, fdNumber}) => {89 if (direction === 'output') {90- pipeStreams([spawned.stdio[index]], value);90+ pipeStreams([spawned.stdio[fdNumber]], value);91 } else {92- pipeStreams([value], spawned.stdio[index]);92+ pipeStreams([value], spawned.stdio[fdNumber]);93 }94 95- const streamProperty = PROCESS_STREAM_PROPERTIES[index];95+ const streamProperty = PROCESS_STREAM_PROPERTIES[fdNumber];96 if (streamProperty !== undefined) {97 spawned[streamProperty] = value;98 }99 100- spawned.stdio[index] = value;100+ spawned.stdio[fdNumber] = value;101 };102 103 const PROCESS_STREAM_PROPERTIES = ['stdin', 'stdout', 'stderr'];modified:lib/stdio/handle.js+7 added-7 removed
9 unmodified lines10 11 // Handle `input`, `inputFile`, `stdin`, `stdout` and `stderr` options, before spawning, in async/sync mode12 export const handleInput = (addProperties, options, isSync) => {13 const stdio = normalizeStdio(options);14- const [stdinStreams, ...otherStreamsGroups] = stdio.map((stdioOption, index) => getStdioStreams(stdioOption, index));14+ const [stdinStreams, ...otherStreamsGroups] = stdio.map((stdioOption, fdNumber) => getStdioStreams(stdioOption, fdNumber));15 const stdioStreamsGroups = [[...stdinStreams, ...handleInputOptions(options)], ...otherStreamsGroups]16 .map(stdioStreams => validateStreams(stdioStreams))17 .map(stdioStreams => addStreamDirection(stdioStreams))18 .map(stdioStreams => handleStreamsLines(stdioStreams, options, isSync))6 unmodified lines25 26 // We make sure passing an array with a single item behaves the same as passing that item without an array.27 // This is what users would expect.28 // For example, `stdout: ['ignore']` behaves the same as `stdout: 'ignore'`.29-const getStdioStreams = (stdioOption, index) => {30- const optionName = getOptionName(index);29+const getStdioStreams = (stdioOption, fdNumber) => {30+ const optionName = getOptionName(fdNumber);31 const stdioOptions = Array.isArray(stdioOption) ? stdioOption : [stdioOption];32- const rawStdioStreams = stdioOptions.map(stdioOption => getStdioStream(stdioOption, optionName, index));32+ const rawStdioStreams = stdioOptions.map(stdioOption => getStdioStream(stdioOption, optionName, fdNumber));33 const stdioStreams = filterDuplicates(rawStdioStreams);34 const isStdioArray = stdioStreams.length > 1;35 validateStdioArray(stdioStreams, isStdioArray, optionName);36 return stdioStreams.map(stdioStream => handleNativeStream(stdioStream, isStdioArray));37 };38 39-const getOptionName = index => KNOWN_OPTION_NAMES[index] ?? `stdio[${index}]`;39+const getOptionName = fdNumber => KNOWN_OPTION_NAMES[fdNumber] ?? `stdio[${fdNumber}]`;40 const KNOWN_OPTION_NAMES = ['stdin', 'stdout', 'stderr'];41 42-const getStdioStream = (stdioOption, optionName, index) => {42+const getStdioStream = (stdioOption, optionName, fdNumber) => {43 const type = getStdioOptionType(stdioOption, optionName);44- return {type, value: stdioOption, optionName, index};44+ return {type, value: stdioOption, optionName, fdNumber};45 };46 47 const filterDuplicates = stdioStreams => stdioStreams.filter((stdioStreamOne, indexOne) =>48 stdioStreams.every((stdioStreamTwo, indexTwo) =>48 unmodified linesmodified:lib/stdio/input.js+2 added-2 removed
10 unmodified lines1112131415151617181913 unmodified lines333435363737383940419 unmodified lines10 unmodified linesconst handleInputOption = input => input === undefined ? undefined : { type: getInputType(input), value: input, optionName: 'input', index: 0, fdNumber: 0,};
const getInputType = input => { if (isReadableStream(input, {checkOpen: false})) {13 unmodified lines
const handleInputFileOption = inputFile => inputFile === undefined ? undefined : { ...getInputFileType(inputFile), optionName: 'inputFile', index: 0, fdNumber: 0,};
const getInputFileType = inputFile => { if (isUrl(inputFile)) {9 unmodified linesmodified:lib/stdio/native.js+5 added-5 removed
4 unmodified lines5 // We then emulate the piping done by core Node.js.6 // To do so, we transform the following values:7 // - Node.js streams are marked as `type: nodeStream`8 // - 'inherit' becomes `process.stdin|stdout|stderr`9-// - any file descriptor integer becomes `process.stdio[index]`9+// - any file descriptor integer becomes `process.stdio[fdNumber]`10 // All of the above transformations tell Execa to perform manual piping.11 export const handleNativeStream = (stdioStream, isStdioArray) => {12- const {type, value, index, optionName} = stdioStream;12+ const {type, value, fdNumber, optionName} = stdioStream;13 14 if (!isStdioArray || type !== 'native') {15 return stdioStream;16 }17 18 if (value === 'inherit') {19- return {...stdioStream, type: 'nodeStream', value: getStandardStream(index, value, optionName)};19+ return {...stdioStream, type: 'nodeStream', value: getStandardStream(fdNumber, value, optionName)};20 }21 22 if (typeof value === 'number') {23 return {...stdioStream, type: 'nodeStream', value: getStandardStream(value, value, optionName)};10 unmodified lines34 // - `fs.createReadStream()`/`fs.createWriteStream()` with the `fd` option do not work with character devices that use blocking reads/writes (such as interactive TTYs).35 // - Using a TCP `Socket` would work but be rather complex to implement.36 // Since this is an edge case, we simply throw an error message.37 // See https://github.com/sindresorhus/execa/pull/643#discussion_r143590570738-const getStandardStream = (index, value, optionName) => {39- const standardStream = STANDARD_STREAMS[index];38+const getStandardStream = (fdNumber, value, optionName) => {39+ const standardStream = STANDARD_STREAMS[fdNumber];40 41 if (standardStream === undefined) {42 throw new TypeError(`The \`${optionName}: ${value}\` option is invalid: no such standard stream.`);43 }3 unmodified linesmodified:lib/stdio/option.js+1 added-1 removed
24 unmodified lines25 throw new TypeError(`Expected \`stdio\` to be of type \`string\` or \`Array\`, got \`${typeof stdio}\``);26 }27 28 const length = Math.max(stdio.length, STANDARD_STREAMS_ALIASES.length);29- return Array.from({length}, (value, index) => stdio[index]);29+ return Array.from({length}, (value, fdNumber) => stdio[fdNumber]);30 };31 32 const hasAlias = options => STANDARD_STREAMS_ALIASES.some(alias => options[alias] !== undefined);modified:lib/stdio/sync.js+1 added-1 removed
52 unmodified lines53 }54 55 for (const stdioStreams of stdioStreamsGroups) {56 for (const stdioStream of stdioStreams) {57- pipeStdioOptionSync(result.output[stdioStream.index], stdioStream);57+ pipeStdioOptionSync(result.output[stdioStream.fdNumber], stdioStream);58 }59 }60 };61 9 unmodified linesmodified:lib/stream/all.js+1 added-1 removed
9 unmodified lines10 // Read the contents of `childProcess.all` and|or wait for its completion11 export const waitForAllStream = ({spawned, encoding, buffer, maxBuffer, streamInfo}) => waitForChildStream({12 stream: getAllStream(spawned, encoding),13 spawned,14- index: 1,14+ fdNumber: 1,15 encoding,16 buffer,17 maxBuffer: maxBuffer * 2,18 streamInfo,18 unmodified linesmodified:lib/stream/child.js+5 added-5 removed
1 import {setImmediate} from 'node:timers/promises';2 import getStream, {getStreamAsArrayBuffer, getStreamAsArray, MaxBufferError} from 'get-stream';3 import {waitForStream, handleStreamError, isInputFileDescriptor} from './wait.js';4 5-export const waitForChildStream = async ({stream, spawned, index, encoding, buffer, maxBuffer, streamInfo}) => {5+export const waitForChildStream = async ({stream, spawned, fdNumber, encoding, buffer, maxBuffer, streamInfo}) => {6 if (!stream) {7 return;8 }9 10- if (isInputFileDescriptor(index, streamInfo.stdioStreamsGroups)) {11- await waitForStream(stream, index, streamInfo);10+ if (isInputFileDescriptor(fdNumber, streamInfo.stdioStreamsGroups)) {11+ await waitForStream(stream, fdNumber, streamInfo);12 return;13 }14 15 if (!buffer) {16 await Promise.all([17- waitForStream(stream, index, streamInfo),17+ waitForStream(stream, fdNumber, streamInfo),18 resumeStream(stream),19 ]);20 return;21 }4 unmodified lines26 if (error instanceof MaxBufferError) {27 spawned.kill();28 }29 30- handleStreamError(error, index, streamInfo);30+ handleStreamError(error, fdNumber, streamInfo);31 return handleBufferedData(error, encoding);32 }33 };34 36 unmodified linesmodified:lib/stream/resolve.js+5 added-5 removed
52 unmodified lines53 };54 55 // Read the contents of `childProcess.std*` and|or wait for its completion56 const waitForChildStreams = ({spawned, encoding, buffer, maxBuffer, streamInfo}) =>57- spawned.stdio.map((stream, index) => waitForChildStream({stream, spawned, index, encoding, buffer, maxBuffer, streamInfo}));57+ spawned.stdio.map((stream, fdNumber) => waitForChildStream({stream, spawned, fdNumber, encoding, buffer, maxBuffer, streamInfo}));58 59 // Transforms replace `childProcess.std*`, which means they are not exposed to users.60 // However, we still want to wait for their completion.61 const waitForOriginalStreams = (originalStreams, spawned, streamInfo) =>62- originalStreams.map((stream, index) => stream === spawned.stdio[index]62+ originalStreams.map((stream, fdNumber) => stream === spawned.stdio[fdNumber]63 ? undefined64- : waitForStream(stream, index, streamInfo));64+ : waitForStream(stream, fdNumber, streamInfo));65 66 // Some `stdin`/`stdout`/`stderr` options create a stream, e.g. when passing a file path.67 // The `.pipe()` method automatically ends that stream when `childProcess` ends.68 // This makes sure we wait for the completion of those streams, in order to catch any error.69-const waitForCustomStreamsEnd = (stdioStreamsGroups, streamInfo) => stdioStreamsGroups.flatMap((stdioStreams, index) => stdioStreams69+const waitForCustomStreamsEnd = (stdioStreamsGroups, streamInfo) => stdioStreamsGroups.flatMap((stdioStreams, fdNumber) => stdioStreams70 .filter(({value}) => isStream(value, {checkOpen: false}) && !isStandardStream(value))71- .map(({type, value}) => waitForStream(value, index, streamInfo, {71+ .map(({type, value}) => waitForStream(value, fdNumber, streamInfo, {72 isSameDirection: type === 'generator',73 stopOnExit: type === 'native',74 })));75 9 unmodified linesmodified:lib/stream/wait.js+9 added-9 removed
1 unmodified line2 3 // Wraps `finished(stream)` to handle the following case:4 // - When the child process exits, Node.js automatically calls `childProcess.stdin.destroy()`, which we need to ignore.5 // - However, we still need to throw if `childProcess.stdin.destroy()` is called before child process exit.6-export const waitForStream = async (stream, index, streamInfo, {isSameDirection, stopOnExit = false} = {}) => {6+export const waitForStream = async (stream, fdNumber, streamInfo, {isSameDirection, stopOnExit = false} = {}) => {7 const {originalStreams: [originalStdin], exitPromise} = streamInfo;8 9 const abortController = new AbortController();10 try {1 unmodified line12 ...(stopOnExit || stream === originalStdin ? [exitPromise] : []),13 finished(stream, {cleanup: true, signal: abortController.signal}),14 ]);15 } catch (error) {16- handleStreamError(error, index, streamInfo, isSameDirection);16+ handleStreamError(error, fdNumber, streamInfo, isSameDirection);17 } finally {18 abortController.abort();19 }20 };2 unmodified lines23 // When one stream errors, the error is propagated to the other streams on the same file descriptor.24 // Those other streams might have a different direction due to the above.25 // When this happens, the direction of both the initial stream and the others should then be taken into account.26 // Therefore, we keep track of which file descriptor is currently propagating stream errors.27-export const handleStreamError = (error, index, streamInfo, isSameDirection) => {28- if (!shouldIgnoreStreamError(error, index, streamInfo, isSameDirection)) {27+export const handleStreamError = (error, fdNumber, streamInfo, isSameDirection) => {28+ if (!shouldIgnoreStreamError(error, fdNumber, streamInfo, isSameDirection)) {29 throw error;30 }31 };32 33-const shouldIgnoreStreamError = (error, index, {stdioStreamsGroups, propagating}, isSameDirection = true) => {34- if (propagating.has(index)) {33+const shouldIgnoreStreamError = (error, fdNumber, {stdioStreamsGroups, propagating}, isSameDirection = true) => {34+ if (propagating.has(fdNumber)) {35 return isStreamEpipe(error) || isStreamAbort(error);36 }37 38- propagating.add(index);39- return isInputFileDescriptor(index, stdioStreamsGroups) === isSameDirection38+ propagating.add(fdNumber);39+ return isInputFileDescriptor(fdNumber, stdioStreamsGroups) === isSameDirection40 ? isStreamEpipe(error)41 : isStreamAbort(error);42 };43 1 unmodified line45 // For example, `childProcess.stdin` is technically a Duplex, but can only be used as a writable.46 // Therefore, we need to use the file descriptor's direction (`stdin` is input, `stdout` is output, etc.).47 // However, while `childProcess.std*` and transforms follow that direction, any stream passed the `std*` option has the opposite direction.48 // For example, `childProcess.stdin` is a writable, but the `stdin` option is a readable.49-export const isInputFileDescriptor = (index, stdioStreamsGroups) => stdioStreamsGroups[index][0].direction === 'input';49+export const isInputFileDescriptor = (fdNumber, stdioStreamsGroups) => stdioStreamsGroups[fdNumber][0].direction === 'input';50 51 // When `stream.destroy()` is called without an `error` argument, stream is aborted.52 // This is the only way to abort a readable stream, which can be useful in some instances.53 // Therefore, we ignore this error on readable streams.8 unmodified linesmodified:test/fixtures/max-buffer.js+4 added-4 removed
1 #!/usr/bin/env node2 import process from 'node:process';3 import {writeSync} from 'node:fs';4 5-const index = Number(process.argv[2]);5+const fdNumber = Number(process.argv[2]);6 const bytes = '.'.repeat(Number(process.argv[3] || 1e7));7-if (index === 1) {7+if (fdNumber === 1) {8 process.stdout.write(bytes);9-} else if (index === 2) {9+} else if (fdNumber === 2) {10 process.stderr.write(bytes);11 } else {12- writeSync(index, bytes);12+ writeSync(fdNumber, bytes);13 }modified:test/fixtures/nested-stdio.js+6 added-6 removed
1 #!/usr/bin/env node2 import process from 'node:process';3 import {execa} from '../../index.js';4 5-const [stdioOption, index, file, ...args] = process.argv.slice(2);5+const [stdioOption, fdNumber, file, ...args] = process.argv.slice(2);6 let optionValue = JSON.parse(stdioOption);7 optionValue = typeof optionValue === 'string' ? process[optionValue] : optionValue;8 optionValue = Array.isArray(optionValue) && typeof optionValue[0] === 'string'9 ? [process[optionValue[0]], ...optionValue.slice(1)]10 : optionValue;11 const stdio = ['ignore', 'inherit', 'inherit'];12-stdio[index] = optionValue;13-const childProcess = execa(file, [`${index}`, ...args], {stdio});12+stdio[fdNumber] = optionValue;13+const childProcess = execa(file, [`${fdNumber}`, ...args], {stdio});14 15 const shouldPipe = Array.isArray(optionValue) && optionValue.includes('pipe');16-const hasPipe = childProcess.stdio[index] !== null;16+const hasPipe = childProcess.stdio[fdNumber] !== null;17 18 if (shouldPipe && !hasPipe) {19- throw new Error(`childProcess.stdio[${index}] is null.`);19+ throw new Error(`childProcess.stdio[${fdNumber}] is null.`);20 }21 22 if (!shouldPipe && hasPipe) {23- throw new Error(`childProcess.stdio[${index}] should be null.`);23+ throw new Error(`childProcess.stdio[${fdNumber}] should be null.`);24 }25 26 await childProcess;modified:test/fixtures/stdin-fd.js+3 added-3 removed
1 #!/usr/bin/env node2 import process from 'node:process';3 import {readFileSync} from 'node:fs';4 5-const fileDescriptorIndex = Number(process.argv[2]);6-if (fileDescriptorIndex === 0) {5+const fdNumber = Number(process.argv[2]);6+if (fdNumber === 0) {7 process.stdin.pipe(process.stdout);8 } else {9- process.stdout.write(readFileSync(fileDescriptorIndex));9+ process.stdout.write(readFileSync(fdNumber));10 }modified:test/helpers/stdio.js+4 added-4 removed
1 import process from 'node:process';2 3 export const identity = value => value;4 5-export const getStdio = (indexOrName, stdioOption, length = 3) => {6- if (typeof indexOrName === 'string') {7- return {[indexOrName]: stdioOption};5+export const getStdio = (fdNumberOrName, stdioOption, length = 3) => {6+ if (typeof fdNumberOrName === 'string') {7+ return {[fdNumberOrName]: stdioOption};8 }9 10 const stdio = Array.from({length}).fill('pipe');11- stdio[indexOrName] = stdioOption;11+ stdio[fdNumberOrName] = stdioOption;12 return {stdio};13 };14 15 export const fullStdio = getStdio(3, 'pipe');4 unmodified linesmodified:test/pipe/setup.js+2 added-2 removed
3 unmodified lines4 import {fullStdio} from '../helpers/stdio.js';5 6 setFixtureDir();7 8-const pipeToProcess = async (t, index, from, options) => {9- const {stdout} = await execa('noop-fd.js', [`${index}`, 'test'], options)8+const pipeToProcess = 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');12 };13 10 unmodified linesmodified:test/return/error.js+2 added-2 removed
70 unmodified lines71 test('error.message contains stdout/stderr/stdio even with encoding "buffer", objectMode', testStdioMessage, 'buffer', false, true);72 test('error.message contains all if available, objectMode', testStdioMessage, 'utf8', true, true);73 test('error.message contains all even with encoding "buffer", objectMode', testStdioMessage, 'buffer', true, true);74 75-const testPartialIgnoreMessage = async (t, index, stdioOption, output) => {76- const {message} = await t.throwsAsync(execa('echo-fail.js', getStdio(index, stdioOption, 4)));75+const testPartialIgnoreMessage = async (t, fdNumber, stdioOption, output) => {76+ const {message} = await t.throwsAsync(execa('echo-fail.js', getStdio(fdNumber, stdioOption, 4)));77 t.true(message.endsWith(`echo-fail.js\n\n${output}\n\nfd3`));78 };79 80 test('error.message does not contain stdout if not available', testPartialIgnoreMessage, 1, 'ignore', 'stderr');106 unmodified linesmodified:test/return/output.js+10 added-10 removed
4 unmodified lines5 import {noopGenerator} from '../helpers/generator.js';6 7 setFixtureDir();8 9-const testOutput = async (t, index, execaMethod) => {10- const {stdout, stderr, stdio} = await execaMethod('noop-fd.js', [`${index}`, 'foobar'], fullStdio);11- t.is(stdio[index], 'foobar');9+const testOutput = async (t, fdNumber, execaMethod) => {10+ const {stdout, stderr, stdio} = await execaMethod('noop-fd.js', [`${fdNumber}`, 'foobar'], fullStdio);11+ t.is(stdio[fdNumber], 'foobar');12 13- if (index === 1) {14- t.is(stdio[index], stdout);15- } else if (index === 2) {16- t.is(stdio[index], stderr);13+ if (fdNumber === 1) {14+ t.is(stdio[fdNumber], stdout);15+ } else if (fdNumber === 2) {16+ t.is(stdio[fdNumber], stderr);17 }18 };19 20 test('can return stdout', testOutput, 1, execa);90 unmodified lines111 112 test('error.stdout/stderr/stdio is defined', testErrorOutput, execa);113 test('error.stdout/stderr/stdio is defined - sync', testErrorOutput, execaSync);114 115-const testStripFinalNewline = async (t, index, stripFinalNewline, execaMethod) => {116- const {stdio} = await execaMethod('noop-fd.js', [`${index}`, 'foobar\n'], {...fullStdio, stripFinalNewline});117- t.is(stdio[index], `foobar${stripFinalNewline === false ? '\n' : ''}`);115+const testStripFinalNewline = async (t, fdNumber, stripFinalNewline, execaMethod) => {116+ const {stdio} = await execaMethod('noop-fd.js', [`${fdNumber}`, 'foobar\n'], {...fullStdio, stripFinalNewline});117+ t.is(stdio[fdNumber], `foobar${stripFinalNewline === false ? '\n' : ''}`);118 };119 120 test('stripFinalNewline: undefined with stdout', testStripFinalNewline, 1, undefined, execa);121 test('stripFinalNewline: true with stdout', testStripFinalNewline, 1, true, execa);21 unmodified linesmodified:test/stdio/async.js+2 added-2 removed
29 unmodified lines30 if (isMultiple) {31 await onStdinRemoveListener();32 }33 34- for (const [index, streamNewListeners] of Object.entries(getStandardStreamsListeners())) {34+ for (const [fdNumber, streamNewListeners] of Object.entries(getStandardStreamsListeners())) {35 const defaultListeners = Object.fromEntries(Reflect.ownKeys(streamNewListeners).map(eventName => [eventName, []]));36- t.deepEqual(streamNewListeners, {...defaultListeners, ...streamsPreviousListeners[index]});36+ t.deepEqual(streamNewListeners, {...defaultListeners, ...streamsPreviousListeners[fdNumber]});37 }38 };39 40 test.serial('process.std* listeners are cleaned up on success with a single input', testListenersCleanup, false);45 unmodified linesmodified:test/stdio/direction.js+2 added-2 removed
36 unmodified lines37 38 test('stdio[*] default direction is output', testAmbiguousDirection, execa);39 test('stdio[*] default direction is output - sync', testAmbiguousDirection, execaSync);40 41-const testAmbiguousMultiple = async (t, index) => {41+const testAmbiguousMultiple = async (t, fdNumber) => {42 const filePath = tempfile();43 await writeFile(filePath, 'foobar');44- const {stdout} = await execa('stdin-fd.js', [`${index}`], getStdio(index, [{file: filePath}, ['foo', 'bar']]));44+ const {stdout} = await execa('stdin-fd.js', [`${fdNumber}`], getStdio(fdNumber, [{file: filePath}, ['foo', 'bar']]));45 t.is(stdout, 'foobarfoobar');46 await rm(filePath);47 };48 2 unmodified linesmodified:test/stdio/encoding-end.js+8 added-8 removed
12 unmodified lines13 const pExec = promisify(exec);14 15 setFixtureDir();16 17-const checkEncoding = async (t, encoding, index, execaMethod) => {18- const {stdio} = await execaMethod('noop-fd.js', [`${index}`, STRING_TO_ENCODE], {...fullStdio, encoding});19- compareValues(t, stdio[index], encoding);17+const checkEncoding = async (t, encoding, fdNumber, execaMethod) => {18+ const {stdio} = await execaMethod('noop-fd.js', [`${fdNumber}`, STRING_TO_ENCODE], {...fullStdio, encoding});19+ compareValues(t, stdio[fdNumber], encoding);20 21 if (execaMethod !== execaSync) {22- const childProcess = execaMethod('noop-fd.js', [`${index}`, STRING_TO_ENCODE], {...fullStdio, encoding, buffer: false});22+ const childProcess = execaMethod('noop-fd.js', [`${fdNumber}`, STRING_TO_ENCODE], {...fullStdio, encoding, buffer: false});23 const getStreamMethod = encoding === 'buffer' ? getStreamAsBuffer : getStream;24- const result = await getStreamMethod(childProcess.stdio[index]);24+ const result = await getStreamMethod(childProcess.stdio[fdNumber]);25 compareValues(t, result, encoding);26 await childProcess;27 }28 29- if (index === 3) {29+ if (fdNumber === 3) {30 return;31 }32 33- const {stdout, stderr} = await pExec(`node noop-fd.js ${index} ${STRING_TO_ENCODE}`, {encoding, cwd: FIXTURES_DIR});34- compareValues(t, index === 1 ? stdout : stderr, encoding);33+ const {stdout, stderr} = await pExec(`node noop-fd.js ${fdNumber} ${STRING_TO_ENCODE}`, {encoding, cwd: FIXTURES_DIR});34+ compareValues(t, fdNumber === 1 ? stdout : stderr, encoding);35 };36 37 const compareValues = (t, value, encoding) => {38 if (encoding === 'buffer') {158 unmodified linesmodified:test/stdio/encoding-start.js+3 added-3 removed
88 unmodified lines89 test('Next generator argument is Uint8Array with encoding "hex", with Uint8Array writes', testGeneratorNextEncoding, foobarUint8Array, 'hex', false, false, 'String');90 test('Next generator argument is object with default encoding, with object writes, objectMode first', testGeneratorNextEncoding, foobarObject, 'utf8', true, false, 'Object');91 test('Next generator argument is object with default encoding, with object writes, objectMode both', testGeneratorNextEncoding, foobarObject, 'utf8', true, true, 'Object');92 93-const testFirstOutputGeneratorArgument = async (t, index) => {94- const {stdio} = await execa('noop-fd.js', [`${index}`], getStdio(index, getTypeofGenerator(true)));95- t.deepEqual(stdio[index], ['[object String]']);93+const testFirstOutputGeneratorArgument = async (t, fdNumber) => {94+ const {stdio} = await execa('noop-fd.js', [`${fdNumber}`], getStdio(fdNumber, getTypeofGenerator(true)));95+ t.deepEqual(stdio[fdNumber], ['[object String]']);96 };97 98 test('The first generator with result.stdout does not receive an object argument even in objectMode', testFirstOutputGeneratorArgument, 1);99 test('The first generator with result.stderr does not receive an object argument even in objectMode', testFirstOutputGeneratorArgument, 2);89 unmodified linesmodified:test/stdio/file-descriptor.js+5 added-5 removed
5 unmodified lines6 import {getStdio} from '../helpers/stdio.js';7 8 setFixtureDir();9 10-const testFileDescriptorOption = async (t, index, execaMethod) => {10+const testFileDescriptorOption = async (t, fdNumber, execaMethod) => {11 const filePath = tempfile();12 const fileDescriptor = await open(filePath, 'w');13- await execaMethod('noop-fd.js', [`${index}`, 'foobar'], getStdio(index, fileDescriptor));13+ await execaMethod('noop-fd.js', [`${fdNumber}`, 'foobar'], getStdio(fdNumber, fileDescriptor));14 t.is(await readFile(filePath, 'utf8'), 'foobar');15 await rm(filePath);16 await fileDescriptor.close();17 };4 unmodified lines22 test('pass `stdout` to a file descriptor - sync', testFileDescriptorOption, 1, execaSync);23 test('pass `stderr` to a file descriptor - sync', testFileDescriptorOption, 2, execaSync);24 test('pass `stdio[*]` to a file descriptor - sync', testFileDescriptorOption, 3, execaSync);25 26-const testStdinWrite = async (t, index) => {27- const subprocess = execa('stdin-fd.js', [`${index}`], getStdio(index, 'pipe'));28- subprocess.stdio[index].end('unicorns');26+const testStdinWrite = async (t, fdNumber) => {27+ const subprocess = execa('stdin-fd.js', [`${fdNumber}`], getStdio(fdNumber, 'pipe'));28+ subprocess.stdio[fdNumber].end('unicorns');29 const {stdout} = await subprocess;30 t.is(stdout, 'unicorns');31 };32 2 unmodified linesmodified:test/stdio/file-path.js+20 added-20 removed
15 unmodified lines16 17 const getAbsolutePath = file => ({file});18 const getRelativePath = filePath => ({file: relative('.', filePath)});19 20-const getStdioFile = (index, file) => getStdio(index, index === 0 ? {file} : file);20+const getStdioFile = (fdNumber, file) => getStdio(fdNumber, fdNumber === 0 ? {file} : file);21 22-const getStdioInput = (index, file) => {23- if (index === 'string') {22+const getStdioInput = (fdNumberOrName, file) => {23+ if (fdNumberOrName === 'string') {24 return {input: 'foobar'};25 }26 27- if (index === 'binary') {27+ if (fdNumberOrName === 'binary') {28 return {input: foobarUint8Array};29 }30 31- return getStdioFile(index, file);31+ return getStdioFile(fdNumberOrName, file);32 };33 34-const testStdinFile = async (t, mapFilePath, index, execaMethod) => {34+const testStdinFile = async (t, mapFilePath, fdNumber, execaMethod) => {35 const filePath = tempfile();36 await writeFile(filePath, 'foobar');37- const {stdout} = await execaMethod('stdin.js', getStdio(index, mapFilePath(filePath)));37+ const {stdout} = await execaMethod('stdin.js', getStdio(fdNumber, mapFilePath(filePath)));38 t.is(stdout, 'foobar');39 await rm(filePath);40 };41 9 unmodified lines51 test('stdin can be an absolute file path - sync', testStdinFile, getAbsolutePath, 0, execaSync);52 test('inputFile can be a relative file path - sync', testStdinFile, identity, 'inputFile', execaSync);53 test('stdin can be a relative file path - sync', testStdinFile, getRelativePath, 0, execaSync);54 55-const testOutputFile = async (t, mapFile, index, execaMethod) => {55+const testOutputFile = async (t, mapFile, fdNumber, execaMethod) => {56 const filePath = tempfile();57- await execaMethod('noop-fd.js', [`${index}`, 'foobar'], getStdio(index, mapFile(filePath)));57+ await execaMethod('noop-fd.js', [`${fdNumber}`, 'foobar'], getStdio(fdNumber, mapFile(filePath)));58 t.is(await readFile(filePath, 'utf8'), 'foobar');59 await rm(filePath);60 };61 15 unmodified lines77 test('stdout can be a relative file path - sync', testOutputFile, getRelativePath, 1, execaSync);78 test('stderr can be a relative file path - sync', testOutputFile, getRelativePath, 2, execaSync);79 test('stdio[*] can be a relative file path - sync', testOutputFile, getRelativePath, 3, execaSync);80 81-const testStdioNonFileUrl = (t, index, execaMethod) => {81+const testStdioNonFileUrl = (t, fdNumber, execaMethod) => {82 t.throws(() => {83- execaMethod('empty.js', getStdio(index, nonFileUrl));83+ execaMethod('empty.js', getStdio(fdNumber, nonFileUrl));84 }, {message: /pathToFileURL/});85 };86 87 test('inputFile cannot be a non-file URL', testStdioNonFileUrl, 'inputFile', execa);15 unmodified lines103 104 test('inputFile must be a file URL or string', testInvalidInputFile, execa);105 test('inputFile must be a file URL or string - sync', testInvalidInputFile, execaSync);106 107-const testInputFileValidUrl = async (t, index, execaMethod) => {107+const testInputFileValidUrl = async (t, fdNumber, execaMethod) => {108 const filePath = tempfile();109 await writeFile(filePath, 'foobar');110 const currentCwd = process.cwd();111 process.chdir(dirname(filePath));112 113 try {114- const {stdout} = await execaMethod('stdin.js', getStdioFile(index, basename(filePath)));114+ const {stdout} = await execaMethod('stdin.js', getStdioFile(fdNumber, basename(filePath)));115 t.is(stdout, 'foobar');116 } finally {117 process.chdir(currentCwd);118 await rm(filePath);4 unmodified lines123 test.serial('stdin does not need to start with . when being a relative file path', testInputFileValidUrl, 0, execa);124 test.serial('inputFile does not need to start with . when being a relative file path - sync', testInputFileValidUrl, 'inputFile', execaSync);125 test.serial('stdin does not need to start with . when being a relative file path - sync', testInputFileValidUrl, 0, execaSync);126 127-const testFilePathObject = (t, index, execaMethod) => {127+const testFilePathObject = (t, fdNumber, execaMethod) => {128 t.throws(() => {129- execaMethod('empty.js', getStdio(index, 'foobar'));129+ execaMethod('empty.js', getStdio(fdNumber, 'foobar'));130 }, {message: /must be used/});131 };132 133 test('stdin must be an object when it is a file path string', testFilePathObject, 0, execa);4 unmodified lines138 test('stdout be an object when it is a file path string - sync', testFilePathObject, 1, execaSync);139 test('stderr be an object when it is a file path string - sync', testFilePathObject, 2, execaSync);140 test('stdio[*] must be an object when it is a file path string - sync', testFilePathObject, 3, execaSync);141 142-const testFileError = async (t, fixtureName, mapFile, index) => {142+const testFileError = async (t, fixtureName, mapFile, fdNumber) => {143 await t.throwsAsync(144- execa(fixtureName, [`${index}`], getStdio(index, mapFile('./unknown/file'))),144+ execa(fixtureName, [`${fdNumber}`], getStdio(fdNumber, mapFile('./unknown/file'))),145 {code: 'ENOENT'},146 );147 };148 7 unmodified lines156 test.serial('stdout file path errors should be handled', testFileError, 'noop-fd.js', getAbsolutePath, 1);157 test.serial('stderr file path errors should be handled', testFileError, 'noop-fd.js', getAbsolutePath, 2);158 test.serial('stdio[*] file path errors should be handled', testFileError, 'noop-fd.js', getAbsolutePath, 3);159 160-const testFileErrorSync = (t, mapFile, index) => {160+const testFileErrorSync = (t, mapFile, fdNumber) => {161 t.throws(() => {162- execaSync('empty.js', getStdio(index, mapFile('./unknown/file')));162+ execaSync('empty.js', getStdio(fdNumber, mapFile('./unknown/file')));163 }, {code: 'ENOENT'});164 };165 166 test('inputFile file URL errors should be handled - sync', testFileErrorSync, pathToFileURL, 'inputFile');9 unmodified lines176 177 const testMultipleInputs = async (t, indices, execaMethod) => {178 const filePath = tempfile();179 await writeFile(filePath, 'foobar');180- const options = Object.assign({}, ...indices.map(index => getStdioInput(index, filePath)));180+ const options = Object.assign({}, ...indices.map(fdNumber => getStdioInput(fdNumber, filePath)));181 const {stdout} = await execaMethod('stdin.js', options);182 t.is(stdout, 'foobar'.repeat(indices.length));183 await rm(filePath);184 };29 unmodified linesmodified:test/stdio/forward.js+2 added-2 removed
3 unmodified lines4 import {setFixtureDir} from '../helpers/fixtures-dir.js';5 6 setFixtureDir();7 8-const testOverlapped = async (t, index) => {9- const {stdout} = await execa('noop.js', ['foobar'], getStdio(index, ['overlapped', 'pipe']));8+const testOverlapped = async (t, fdNumber) => {9+ const {stdout} = await execa('noop.js', ['foobar'], getStdio(fdNumber, ['overlapped', 'pipe']));10 t.is(stdout, 'foobar');11 };12 13 test('stdin can be ["overlapped", "pipe"]', testOverlapped, 0);3 unmodified linesmodified:test/stdio/generator.js+8 added-8 removed
31 unmodified lines32 const getOutputObjectMode = objectMode => objectMode33 ? {generator: outputObjectGenerator, output: [foobarObject], getStreamMethod: getStreamAsArray}34 : {generator: uppercaseGenerator, output: foobarUppercase, getStreamMethod: getStream};35 36-const testGeneratorInput = async (t, index, objectMode) => {36+const testGeneratorInput = async (t, fdNumber, objectMode) => {37 const {input, generator, output} = getInputObjectMode(objectMode);38- const {stdout} = await execa('stdin-fd.js', [`${index}`], getStdio(index, [input, generator]));38+ const {stdout} = await execa('stdin-fd.js', [`${fdNumber}`], getStdio(fdNumber, [input, generator]));39 t.is(stdout, output);40 };41 42 test('Can use generators with result.stdin', testGeneratorInput, 0, false);30 unmodified lines73 test('Can use generators with childProcess.stdio[*] as input', testGeneratorStdioInputPipe, false);74 test('Can use generators with childProcess.stdio[*] as input, objectMode', testGeneratorStdioInputPipe, true);75 76 // eslint-disable-next-line max-params77-const testGeneratorOutput = async (t, index, reject, useShortcutProperty, objectMode) => {77+const testGeneratorOutput = async (t, fdNumber, reject, useShortcutProperty, objectMode) => {78 const {generator, output} = getOutputObjectMode(objectMode);79 const fixtureName = reject ? 'noop-fd.js' : 'noop-fail.js';80- const {stdout, stderr, stdio} = await execa(fixtureName, [`${index}`, foobarString], {...getStdio(index, generator), reject});81- const result = useShortcutProperty ? [stdout, stderr][index - 1] : stdio[index];80+ const {stdout, stderr, stdio} = await execa(fixtureName, [`${fdNumber}`, foobarString], {...getStdio(fdNumber, generator), reject});81+ const result = useShortcutProperty ? [stdout, stderr][fdNumber - 1] : stdio[fdNumber];82 t.deepEqual(result, output);83 };84 85 test('Can use generators with result.stdio[1]', testGeneratorOutput, 1, true, false, false);16 unmodified lines102 test('Can use generators with error.stdio[2], objectMode', testGeneratorOutput, 2, false, false, true);103 test('Can use generators with error.stderr, objectMode', testGeneratorOutput, 2, false, true, true);104 test('Can use generators with error.stdio[*] as output, objectMode', testGeneratorOutput, 3, false, false, true);105 106-const testGeneratorOutputPipe = async (t, index, useShortcutProperty, objectMode) => {106+const testGeneratorOutputPipe = async (t, fdNumber, useShortcutProperty, objectMode) => {107 const {generator, output, getStreamMethod} = getOutputObjectMode(objectMode);108- const childProcess = execa('noop-fd.js', [`${index}`, foobarString], {...getStdio(index, generator), buffer: false});109- const stream = useShortcutProperty ? [childProcess.stdout, childProcess.stderr][index - 1] : childProcess.stdio[index];108+ const childProcess = execa('noop-fd.js', [`${fdNumber}`, foobarString], {...getStdio(fdNumber, generator), buffer: false});109+ const stream = useShortcutProperty ? [childProcess.stdout, childProcess.stderr][fdNumber - 1] : childProcess.stdio[fdNumber];110 const [result] = await Promise.all([getStreamMethod(stream), childProcess]);111 t.deepEqual(result, output);112 };113 174 unmodified linesmodified:test/stdio/handle.js+7 added-7 removed
3 unmodified lines4 import {setFixtureDir} from '../helpers/fixtures-dir.js';5 6 setFixtureDir();7 8-const testEmptyArray = (t, index, optionName, execaMethod) => {8+const testEmptyArray = (t, fdNumber, optionName, execaMethod) => {9 t.throws(() => {10- execaMethod('empty.js', getStdio(index, []));10+ execaMethod('empty.js', getStdio(fdNumber, []));11 }, {message: `The \`${optionName}\` option must not be an empty array.`});12 };13 14 test('Cannot pass an empty array to stdin', testEmptyArray, 0, 'stdin', execa);4 unmodified lines19 test('Cannot pass an empty array to stdout - sync', testEmptyArray, 1, 'stdout', execaSync);20 test('Cannot pass an empty array to stderr - sync', testEmptyArray, 2, 'stderr', execaSync);21 test('Cannot pass an empty array to stdio[*] - sync', testEmptyArray, 3, 'stdio[3]', execaSync);22 23-const testNoPipeOption = async (t, stdioOption, index) => {24- const childProcess = execa('empty.js', getStdio(index, stdioOption));25- t.is(childProcess.stdio[index], null);23+const testNoPipeOption = async (t, stdioOption, fdNumber) => {24+ const childProcess = execa('empty.js', getStdio(fdNumber, stdioOption));25+ t.is(childProcess.stdio[fdNumber], null);26 await childProcess;27 };28 29 test('stdin can be "ignore"', testNoPipeOption, 'ignore', 0);32 unmodified lines62 test('stdio[*] can be ["inherit"]', testNoPipeOption, ['inherit'], 3);63 test('stdio[*] can be 3', testNoPipeOption, 3, 3);64 test('stdio[*] can be [3]', testNoPipeOption, [3], 3);65 66-const testInvalidArrayValue = (t, invalidStdio, index, execaMethod) => {66+const testInvalidArrayValue = (t, invalidStdio, fdNumber, execaMethod) => {67 t.throws(() => {68- execaMethod('empty.js', getStdio(index, ['pipe', invalidStdio]));68+ execaMethod('empty.js', getStdio(fdNumber, ['pipe', invalidStdio]));69 }, {message: /must not include/});70 };71 72 test('Cannot pass "ignore" and another value to stdin', testInvalidArrayValue, 'ignore', 0, execa);15 unmodified linesmodified:test/stdio/iterable.js+12 added-12 removed
27 unmodified lines28 };29 30 setFixtureDir();31 32-const testIterable = async (t, stdioOption, index) => {33- const {stdout} = await execa('stdin-fd.js', [`${index}`], getStdio(index, stdioOption));32+const testIterable = async (t, stdioOption, fdNumber) => {33+ const {stdout} = await execa('stdin-fd.js', [`${fdNumber}`], getStdio(fdNumber, stdioOption));34 t.is(stdout, 'foobar');35 };36 37 test.serial('stdin option can be an array of strings', testIterable, [stringArray], 0);14 unmodified lines52 const foobarAsyncObjectGenerator = function * () {53 yield foobarObject;54 };55 56-const testObjectIterable = async (t, stdioOption, index) => {57- const {stdout} = await execa('stdin-fd.js', [`${index}`], getStdio(index, [stdioOption, serializeGenerator]));56+const testObjectIterable = async (t, stdioOption, fdNumber) => {57+ const {stdout} = await execa('stdin-fd.js', [`${fdNumber}`], getStdio(fdNumber, [stdioOption, serializeGenerator]));58 t.is(stdout, foobarObjectString);59 };60 61 test('stdin option can be an array of objects', testObjectIterable, [foobarObject], 0);2 unmodified lines64 test('stdio[*] option can be an iterable of objects', testObjectIterable, foobarObjectGenerator(), 3);65 test('stdin option can be an async iterable of objects', testObjectIterable, foobarAsyncObjectGenerator(), 0);66 test('stdio[*] option can be an async iterable of objects', testObjectIterable, foobarAsyncObjectGenerator(), 3);67 68-const testIterableSync = (t, stdioOption, index) => {68+const testIterableSync = (t, stdioOption, fdNumber) => {69 t.throws(() => {70- execaSync('empty.js', getStdio(index, stdioOption));70+ execaSync('empty.js', getStdio(fdNumber, stdioOption));71 }, {message: /an iterable in sync mode/});72 };73 74 test('stdin option cannot be an array of strings - sync', testIterableSync, [stringArray], 0);7 unmodified lines82 const throwingGenerator = function * () {83 throw new Error('generator error');84 };85 86-const testIterableError = async (t, index) => {87- const {originalMessage} = await t.throwsAsync(execa('stdin-fd.js', [`${index}`], getStdio(index, throwingGenerator())));86+const testIterableError = async (t, fdNumber) => {87+ const {originalMessage} = await t.throwsAsync(execa('stdin-fd.js', [`${fdNumber}`], getStdio(fdNumber, throwingGenerator())));88 t.is(originalMessage, 'generator error');89 };90 91 test('stdin option handles errors in iterables', testIterableError, 0);92 test('stdio[*] option handles errors in iterables', testIterableError, 3);93 94-const testNoIterableOutput = (t, stdioOption, index, execaMethod) => {94+const testNoIterableOutput = (t, stdioOption, fdNumber, execaMethod) => {95 t.throws(() => {96- execaMethod('empty.js', getStdio(index, stdioOption));96+ execaMethod('empty.js', getStdio(fdNumber, stdioOption));97 }, {message: /cannot be an iterable/});98 };99 100 test('stdout option cannot be an array of strings', testNoIterableOutput, [stringArray], 1, execa);14 unmodified lines115 t.true(stdout.startsWith('foo'));116 t.deepEqual(await iterable.next(), {value: undefined, done: true});117 });118 119-const testMultipleIterable = async (t, index) => {120- const {stdout} = await execa('stdin-fd.js', [`${index}`], getStdio(index, [stringGenerator(), asyncGenerator()]));119+const testMultipleIterable = async (t, fdNumber) => {120+ const {stdout} = await execa('stdin-fd.js', [`${fdNumber}`], getStdio(fdNumber, [stringGenerator(), asyncGenerator()]));121 t.is(stdout, 'foobarfoobar');122 };123 124 test('stdin option can be multiple iterables', testMultipleIterable, 0);8 unmodified linesmodified:test/stdio/lines.js+7 added-7 removed
56 unmodified lines57 ? textDecoder.decode(resultItem)58 : resultItem;59 60 // eslint-disable-next-line max-params61-const testLines = async (t, index, input, expectedLines, isUint8Array, objectMode) => {61+const testLines = async (t, fdNumber, input, expectedLines, isUint8Array, objectMode) => {62 const lines = [];63- const {stdio} = await execa('noop-fd.js', [`${index}`], {64- ...getStdio(index, [63+ const {stdio} = await execa('noop-fd.js', [`${fdNumber}`], {64+ ...getStdio(fdNumber, [65 {transform: inputGenerator.bind(undefined, stringsToUint8Arrays(input, isUint8Array)), objectMode},66 {transform: resultGenerator.bind(undefined, lines), objectMode},67 ]),68 encoding: isUint8Array ? 'buffer' : 'utf8',69 stripFinalNewline: false,70 });71- t.is(input.join(''), serializeResult(stdio[index], isUint8Array, objectMode));71+ t.is(input.join(''), serializeResult(stdio[fdNumber], isUint8Array, objectMode));72 t.deepEqual(lines, stringsToUint8Arrays(expectedLines, isUint8Array));73 };74 75 test('Split string stdout - n newlines, 1 chunk', testLines, 1, simpleChunk, simpleLines, false, false);69 unmodified lines145 test('Splits lines when "binary" is false, objectMode', testBinaryOption, false, simpleChunk, simpleLines, true);146 test('Splits lines when "binary" is undefined, objectMode', testBinaryOption, undefined, simpleChunk, simpleLines, true);147 148 // eslint-disable-next-line max-params149-const testStreamLines = async (t, index, input, expectedLines, isUint8Array) => {150- const {stdio} = await execa('noop-fd.js', [`${index}`, input], {149+const testStreamLines = async (t, fdNumber, input, expectedLines, isUint8Array) => {150+ const {stdio} = await execa('noop-fd.js', [`${fdNumber}`, input], {151 ...fullStdio,152 lines: true,153 encoding: isUint8Array ? 'buffer' : 'utf8',154 });155- t.deepEqual(stdio[index], stringsToUint8Arrays(expectedLines, isUint8Array));155+ t.deepEqual(stdio[fdNumber], stringsToUint8Arrays(expectedLines, isUint8Array));156 };157 158 test('"lines: true" splits lines, stdout, string', testStreamLines, 1, simpleChunk[0], simpleLines, false);159 test('"lines: true" splits lines, stdout, Uint8Array', testStreamLines, 1, simpleChunk[0], simpleLines, true);70 unmodified linesmodified:test/stdio/native.js+8 added-8 removed
4 unmodified lines5 import {setFixtureDir} from '../helpers/fixtures-dir.js';6 7 setFixtureDir();8 9-const testRedirect = async (t, stdioOption, index, isInput) => {9+const testRedirect = async (t, stdioOption, fdNumber, isInput) => {10 const {fixtureName, ...options} = isInput11 ? {fixtureName: 'stdin-fd.js', input: 'foobar'}12 : {fixtureName: 'noop-fd.js'};13- const {stdio} = await execa('nested-stdio.js', [JSON.stringify(stdioOption), `${index}`, fixtureName, 'foobar'], options);14- const resultIndex = isStderrDescriptor(stdioOption) ? 2 : 1;15- t.is(stdio[resultIndex], 'foobar');13+ const {stdio} = await execa('nested-stdio.js', [JSON.stringify(stdioOption), `${fdNumber}`, fixtureName, 'foobar'], options);14+ const resultFdNumber = isStderrDescriptor(stdioOption) ? 2 : 1;15+ t.is(stdio[resultFdNumber], 'foobar');16 };17 18 const isStderrDescriptor = stdioOption => stdioOption === 219 || stdioOption === 'stderr'55 unmodified lines75 76 test('stderr can be ["inherit", "pipe"]', testInheritStderr, ['inherit', 'pipe']);77 test('stderr can be [2, "pipe"]', testInheritStderr, [2, 'pipe']);78 79-const testOverflowStream = async (t, index, stdioOption) => {80- const {stdout} = await execa('nested.js', [JSON.stringify(getStdio(index, stdioOption)), 'empty.js'], fullStdio);79+const testOverflowStream = async (t, fdNumber, stdioOption) => {80+ const {stdout} = await execa('nested.js', [JSON.stringify(getStdio(fdNumber, stdioOption)), 'empty.js'], fullStdio);81 t.is(stdout, '');82 };83 84 if (platform === 'linux') {9 unmodified lines94 95 test('stdio[*] can use "inherit"', testOverflowStream, 3, 'inherit');96 test('stdio[*] can use ["inherit"]', testOverflowStream, 3, ['inherit']);97 98-const testOverflowStreamArray = (t, index, stdioOption) => {98+const testOverflowStreamArray = (t, fdNumber, stdioOption) => {99 t.throws(() => {100- execa('empty.js', getStdio(index, stdioOption));100+ execa('empty.js', getStdio(fdNumber, stdioOption));101 }, {message: /no such standard stream/});102 };103 104 test('stdin cannot use 4+ and another value', testOverflowStreamArray, 0, [4, 'pipe']);4 unmodified linesmodified:test/stdio/node-stream.js+27 added-27 removed
13 unmodified lines14 import {noopReadable, noopWritable, noopDuplex, simpleReadable} from '../helpers/stream.js';15 16 setFixtureDir();17 18-const testNoFileStreamSync = async (t, index, stream) => {18+const testNoFileStreamSync = async (t, fdNumber, stream) => {19 t.throws(() => {20- execaSync('empty.js', getStdio(index, stream));20+ execaSync('empty.js', getStdio(fdNumber, stream));21 }, {code: 'ERR_INVALID_ARG_VALUE'});22 };23 24 test('stdin cannot be a Node.js Readable without a file descriptor - sync', testNoFileStreamSync, 0, noopReadable());16 unmodified lines41 execaSync('empty.js', {input: simpleReadable()});42 }, {message: 'The `input` option cannot be a Node.js stream in sync mode.'});43 });44 45-const testNoFileStream = async (t, index, stream) => {46- await t.throwsAsync(execa('empty.js', getStdio(index, stream)), {code: 'ERR_INVALID_ARG_VALUE'});45+const testNoFileStream = async (t, fdNumber, stream) => {46+ await t.throwsAsync(execa('empty.js', getStdio(fdNumber, stream)), {code: 'ERR_INVALID_ARG_VALUE'});47 };48 49 test('stdin cannot be a Node.js Readable without a file descriptor', testNoFileStream, 0, noopReadable());50 test('stdin cannot be a Node.js Duplex without a file descriptor', testNoFileStream, 0, noopDuplex());30 unmodified lines81 82 await rm(filePath);83 };84 85-const testFileReadable = async (t, index, execaMethod) => {85+const testFileReadable = async (t, fdNumber, execaMethod) => {86 const {stream, filePath} = await createFileReadStream();87 88- const indexString = index === 'input' ? '0' : `${index}`;89- const {stdout} = await execaMethod('stdin-fd.js', [indexString], getStdio(index, stream));88+ const fdNumberString = fdNumber === 'input' ? '0' : `${fdNumber}`;89+ const {stdout} = await execaMethod('stdin-fd.js', [fdNumberString], getStdio(fdNumber, stream));90 t.is(stdout, 'foobar');91 92 await rm(filePath);93 };3 unmodified lines97 test('stdio[*] can be a Node.js Readable with a file descriptor', testFileReadable, 3, execa);98 test('stdin can be a Node.js Readable with a file descriptor - sync', testFileReadable, 0, execaSync);99 test('stdio[*] can be a Node.js Readable with a file descriptor - sync', testFileReadable, 3, execaSync);100 101-const testFileReadableError = async (t, index) => {101+const testFileReadableError = async (t, fdNumber) => {102 const {stream, filePath} = await createFileReadStream();103 104- const indexString = index === 'input' ? '0' : `${index}`;105- const childProcess = execa('stdin-fd.js', [indexString], getStdio(index, stream));104+ const fdNumberString = fdNumber === 'input' ? '0' : `${fdNumber}`;105+ const childProcess = execa('stdin-fd.js', [fdNumberString], getStdio(fdNumber, stream));106 107 await assertFileStreamError(t, childProcess, stream, filePath);108 };109 110 test.serial('input handles errors from a Node.js Readable with a file descriptor', testFileReadableError, 'input');111 test.serial('stdin handles errors from a Node.js Readable with a file descriptor', testFileReadableError, 0);112 test.serial('stdio[*] handles errors from a Node.js Readable with a file descriptor', testFileReadableError, 3);113 114-const testFileReadableOpen = async (t, index, useSingle, execaMethod) => {114+const testFileReadableOpen = async (t, fdNumber, useSingle, execaMethod) => {115 const {stream, filePath} = await createFileReadStream();116 t.deepEqual(stream.eventNames(), []);117 118 const stdioOption = useSingle ? stream : [stream, 'pipe'];119- await execaMethod('empty.js', getStdio(index, stdioOption));119+ await execaMethod('empty.js', getStdio(fdNumber, stdioOption));120 121- t.is(stream.readable, useSingle && index !== 'input');121+ t.is(stream.readable, useSingle && fdNumber !== 'input');122 t.deepEqual(stream.eventNames(), []);123 124 await rm(filePath);125 };4 unmodified lines130 test('stdio[*] leaves open a single Node.js Readable with a file descriptor', testFileReadableOpen, 3, true, execa);131 test('stdin leaves open a single Node.js Readable with a file descriptor - sync', testFileReadableOpen, 0, true, execaSync);132 test('stdio[*] leaves open a single Node.js Readable with a file descriptor - sync', testFileReadableOpen, 3, true, execaSync);133 134-const testFileWritable = async (t, index, execaMethod) => {134+const testFileWritable = async (t, fdNumber, execaMethod) => {135 const {stream, filePath} = await createFileWriteStream();136 137- await execaMethod('noop-fd.js', [`${index}`, 'foobar'], getStdio(index, stream));137+ await execaMethod('noop-fd.js', [`${fdNumber}`, 'foobar'], getStdio(fdNumber, stream));138 t.is(await readFile(filePath, 'utf8'), 'foobar');139 140 await rm(filePath);141 };4 unmodified lines146 test('stdout can be a Node.js Writable with a file descriptor - sync', testFileWritable, 1, execaSync);147 test('stderr can be a Node.js Writable with a file descriptor - sync', testFileWritable, 2, execaSync);148 test('stdio[*] can be a Node.js Writable with a file descriptor - sync', testFileWritable, 3, execaSync);149 150-const testFileWritableError = async (t, index) => {150+const testFileWritableError = async (t, fdNumber) => {151 const {stream, filePath} = await createFileWriteStream();152 153- const childProcess = execa('noop-stdin-fd.js', [`${index}`], getStdio(index, stream));153+ const childProcess = execa('noop-stdin-fd.js', [`${fdNumber}`], getStdio(fdNumber, stream));154 childProcess.stdin.end(foobarString);155 156 await assertFileStreamError(t, childProcess, stream, filePath);157 };1 unmodified line159 test.serial('stdout handles errors from a Node.js Writable with a file descriptor', testFileWritableError, 1);160 test.serial('stderr handles errors from a Node.js Writable with a file descriptor', testFileWritableError, 2);161 test.serial('stdio[*] handles errors from a Node.js Writable with a file descriptor', testFileWritableError, 3);162 163-const testFileWritableOpen = async (t, index, useSingle, execaMethod) => {163+const testFileWritableOpen = async (t, fdNumber, useSingle, execaMethod) => {164 const {stream, filePath} = await createFileWriteStream();165 t.deepEqual(stream.eventNames(), []);166 167 const stdioOption = useSingle ? stream : [stream, 'pipe'];168- await execaMethod('empty.js', getStdio(index, stdioOption));168+ await execaMethod('empty.js', getStdio(fdNumber, stdioOption));169 170 t.is(stream.writable, useSingle);171 t.deepEqual(stream.eventNames(), []);172 9 unmodified lines182 test('stdout leaves open a single Node.js Writable with a file descriptor - sync', testFileWritableOpen, 1, true, execaSync);183 test('stderr leaves open a single Node.js Writable with a file descriptor - sync', testFileWritableOpen, 2, true, execaSync);184 test('stdio[*] leaves open a single Node.js Writable with a file descriptor - sync', testFileWritableOpen, 3, true, execaSync);185 186-const testLazyFileReadable = async (t, index) => {186+const testLazyFileReadable = async (t, fdNumber) => {187 const filePath = tempfile();188 await writeFile(filePath, 'foobar');189 const stream = createReadStream(filePath);190 191- const {stdout} = await execa('stdin-fd.js', [`${index}`], getStdio(index, [stream, 'pipe']));191+ const {stdout} = await execa('stdin-fd.js', [`${fdNumber}`], getStdio(fdNumber, [stream, 'pipe']));192 t.is(stdout, 'foobar');193 194 await rm(filePath);195 };196 197 test('stdin can be [Readable, "pipe"] without a file descriptor', testLazyFileReadable, 0);198 test('stdio[*] can be [Readable, "pipe"] without a file descriptor', testLazyFileReadable, 3);199 200-const testLazyFileWritable = async (t, index) => {200+const testLazyFileWritable = async (t, fdNumber) => {201 const filePath = tempfile();202 const stream = createWriteStream(filePath);203 204- await execa('noop-fd.js', [`${index}`, 'foobar'], getStdio(index, [stream, 'pipe']));204+ await execa('noop-fd.js', [`${fdNumber}`, 'foobar'], getStdio(fdNumber, [stream, 'pipe']));205 t.is(await readFile(filePath, 'utf8'), 'foobar');206 207 await rm(filePath);208 };34 unmodified lines243 244 test('Input streams are canceled on early process exit', testStreamEarlyExit, noopReadable(), 'stdin');245 test('Output streams are canceled on early process exit', testStreamEarlyExit, noopWritable(), 'stdout');246 247-const testInputDuplexStream = async (t, index) => {247+const testInputDuplexStream = async (t, fdNumber) => {248 const stream = new PassThrough();249 stream.end(foobarString);250- const {stdout} = await execa('stdin-fd.js', [`${index}`], getStdio(index, [stream, new Uint8Array()]));250+ const {stdout} = await execa('stdin-fd.js', [`${fdNumber}`], getStdio(fdNumber, [stream, new Uint8Array()]));251 t.is(stdout, foobarString);252 };253 254 test('Can pass Duplex streams to stdin', testInputDuplexStream, 0);255 test('Can pass Duplex streams to input stdio[*]', testInputDuplexStream, 3);256 257-const testOutputDuplexStream = async (t, index) => {257+const testOutputDuplexStream = async (t, fdNumber) => {258 const stream = new PassThrough();259 const [output] = await Promise.all([260 text(stream),261- execa('noop-fd.js', [`${index}`], getStdio(index, [stream, 'pipe'])),261+ execa('noop-fd.js', [`${fdNumber}`], getStdio(fdNumber, [stream, 'pipe'])),262 ]);263 t.is(output, foobarString);264 };265 3 unmodified linesmodified:test/stdio/pipeline.js+10 added-10 removed
3 unmodified lines4 import {setFixtureDir} from '../helpers/fixtures-dir.js';5 6 setFixtureDir();7 8-const testDestroyStandard = async (t, index) => {9- const childProcess = execa('forever.js', {...getStdio(index, [STANDARD_STREAMS[index], 'pipe']), timeout: 1});8+const testDestroyStandard = async (t, fdNumber) => {9+ const childProcess = execa('forever.js', {...getStdio(fdNumber, [STANDARD_STREAMS[fdNumber], 'pipe']), timeout: 1});10 await t.throwsAsync(childProcess, {message: /timed out/});11- t.false(STANDARD_STREAMS[index].destroyed);11+ t.false(STANDARD_STREAMS[fdNumber].destroyed);12 };13 14 test('Does not destroy process.stdin on child process errors', testDestroyStandard, 0);15 test('Does not destroy process.stdout on child process errors', testDestroyStandard, 1);16 test('Does not destroy process.stderr on child process errors', testDestroyStandard, 2);17 18-const testDestroyStandardSpawn = async (t, index) => {19- await t.throwsAsync(execa('forever.js', {...getStdio(index, [STANDARD_STREAMS[index], 'pipe']), uid: -1}));20- t.false(STANDARD_STREAMS[index].destroyed);18+const testDestroyStandardSpawn = async (t, fdNumber) => {19+ await t.throwsAsync(execa('forever.js', {...getStdio(fdNumber, [STANDARD_STREAMS[fdNumber], 'pipe']), uid: -1}));20+ t.false(STANDARD_STREAMS[fdNumber].destroyed);21 };22 23 test('Does not destroy process.stdin on spawn process errors', testDestroyStandardSpawn, 0);24 test('Does not destroy process.stdout on spawn process errors', testDestroyStandardSpawn, 1);25 test('Does not destroy process.stderr on spawn process errors', testDestroyStandardSpawn, 2);26 27-const testDestroyStandardStream = async (t, index) => {28- const childProcess = execa('forever.js', getStdio(index, [STANDARD_STREAMS[index], 'pipe']));27+const testDestroyStandardStream = async (t, fdNumber) => {28+ const childProcess = execa('forever.js', getStdio(fdNumber, [STANDARD_STREAMS[fdNumber], 'pipe']));29 const error = new Error('test');30- childProcess.stdio[index].destroy(error);30+ childProcess.stdio[fdNumber].destroy(error);31 childProcess.kill();32 const thrownError = await t.throwsAsync(childProcess);33 t.is(thrownError, error);34- t.false(STANDARD_STREAMS[index].destroyed);34+ t.false(STANDARD_STREAMS[fdNumber].destroyed);35 };36 37 test('Does not destroy process.stdin on stream process errors', testDestroyStandardStream, 0);38 test('Does not destroy process.stdout on stream process errors', testDestroyStandardStream, 1);1 unmodified linemodified:test/stdio/type.js+6 added-6 removed
8 unmodified lines9 const uppercaseGenerator = function * (line) {10 yield line.toUpperCase();11 };12 13-const testInvalidGenerator = (t, index, stdioOption) => {13+const testInvalidGenerator = (t, fdNumber, stdioOption) => {14 t.throws(() => {15- execa('empty.js', getStdio(index, {...noopGenerator(), ...stdioOption}));15+ execa('empty.js', getStdio(fdNumber, {...noopGenerator(), ...stdioOption}));16 }, {message: /must be a generator/});17 };18 19 test('Cannot use invalid "transform" with stdin', testInvalidGenerator, 0, {transform: true});4 unmodified lines24 test('Cannot use invalid "final" with stdout', testInvalidGenerator, 1, {final: true});25 test('Cannot use invalid "final" with stderr', testInvalidGenerator, 2, {final: true});26 test('Cannot use invalid "final" with stdio[*]', testInvalidGenerator, 3, {final: true});27 28-const testInvalidBinary = (t, index, optionName) => {28+const testInvalidBinary = (t, fdNumber, optionName) => {29 t.throws(() => {30- execa('empty.js', getStdio(index, {transform: uppercaseGenerator, [optionName]: 'true'}));30+ execa('empty.js', getStdio(fdNumber, {transform: uppercaseGenerator, [optionName]: 'true'}));31 }, {message: /a boolean/});32 };33 34 test('Cannot use invalid "binary" with stdin', testInvalidBinary, 0, 'binary');4 unmodified lines39 test('Cannot use invalid "objectMode" with stdout', testInvalidBinary, 1, 'objectMode');40 test('Cannot use invalid "objectMode" with stderr', testInvalidBinary, 2, 'objectMode');41 test('Cannot use invalid "objectMode" with stdio[*]', testInvalidBinary, 3, 'objectMode');42 43-const testSyncMethods = (t, index) => {43+const testSyncMethods = (t, fdNumber) => {44 t.throws(() => {45- execaSync('empty.js', getStdio(index, uppercaseGenerator));45+ execaSync('empty.js', getStdio(fdNumber, uppercaseGenerator));46 }, {message: /cannot be a generator/});47 };48 49 test('Cannot use generators with sync methods and stdin', testSyncMethods, 0);3 unmodified linesmodified:test/stdio/typed-array.js+4 added-4 removed
4 unmodified lines5 import {foobarUint8Array} from '../helpers/input.js';6 7 setFixtureDir();8 9-const testUint8Array = async (t, index) => {10- const {stdout} = await execa('stdin-fd.js', [`${index}`], getStdio(index, foobarUint8Array));9+const testUint8Array = async (t, fdNumber) => {10+ const {stdout} = await execa('stdin-fd.js', [`${fdNumber}`], getStdio(fdNumber, foobarUint8Array));11 t.is(stdout, 'foobar');12 };13 14 test('stdin option can be a Uint8Array', testUint8Array, 0);15 test('stdio[*] option can be a Uint8Array', testUint8Array, 3);16 test('stdin option can be a Uint8Array - sync', testUint8Array, 0);17 test('stdio[*] option can be a Uint8Array - sync', testUint8Array, 3);18 19-const testNoUint8ArrayOutput = (t, index, execaMethod) => {19+const testNoUint8ArrayOutput = (t, fdNumber, execaMethod) => {20 t.throws(() => {21- execaMethod('empty.js', getStdio(index, foobarUint8Array));21+ execaMethod('empty.js', getStdio(fdNumber, foobarUint8Array));22 }, {message: /cannot be a Uint8Array/});23 };24 25 test('stdout option cannot be a Uint8Array', testNoUint8ArrayOutput, 1, execa);3 unmodified linesmodified:test/stdio/validate.js+2 added-2 removed
6 unmodified lines7 8 setFixtureDir();9 10 // eslint-disable-next-line max-params11-const testGeneratorReturn = async (t, index, generators, fixtureName, isNull) => {12- const childProcess = execa(fixtureName, [`${index}`], getStdio(index, generators));11+const testGeneratorReturn = async (t, fdNumber, generators, fixtureName, isNull) => {12+ const childProcess = execa(fixtureName, [`${fdNumber}`], getStdio(fdNumber, generators));13 const message = isNull ? /not be called at all/ : /a string or an Uint8Array/;14 await t.throwsAsync(childProcess, {message});15 };16 23 unmodified linesmodified:test/stdio/web-stream.js+12 added-12 removed
5 unmodified lines6 import {getStdio} from '../helpers/stdio.js';7 8 setFixtureDir();9 10-const testReadableStream = async (t, index) => {10+const testReadableStream = async (t, fdNumber) => {11 const readableStream = Readable.toWeb(Readable.from('foobar'));12- const {stdout} = await execa('stdin-fd.js', [`${index}`], getStdio(index, readableStream));12+ const {stdout} = await execa('stdin-fd.js', [`${fdNumber}`], getStdio(fdNumber, readableStream));13 t.is(stdout, 'foobar');14 };15 16 test('stdin can be a ReadableStream', testReadableStream, 0);17 test('stdio[*] can be a ReadableStream', testReadableStream, 3);18 19-const testWritableStream = async (t, index) => {19+const testWritableStream = async (t, fdNumber) => {20 const result = [];21 const writableStream = new WritableStream({22 write(chunk) {23 result.push(chunk);24 },25 });26- await execa('noop-fd.js', [`${index}`, 'foobar'], getStdio(index, writableStream));26+ await execa('noop-fd.js', [`${fdNumber}`, 'foobar'], getStdio(fdNumber, writableStream));27 t.is(result.join(''), 'foobar');28 };29 30 test('stdout can be a WritableStream', testWritableStream, 1);31 test('stderr can be a WritableStream', testWritableStream, 2);32 test('stdio[*] can be a WritableStream', testWritableStream, 3);33 34-const testWebStreamSync = (t, StreamClass, index, optionName) => {34+const testWebStreamSync = (t, StreamClass, fdNumber, optionName) => {35 t.throws(() => {36- execaSync('empty.js', getStdio(index, new StreamClass()));36+ execaSync('empty.js', getStdio(fdNumber, new StreamClass()));37 }, {message: `The \`${optionName}\` option cannot be a web stream in sync mode.`});38 };39 40 test('stdin cannot be a ReadableStream - sync', testWebStreamSync, ReadableStream, 0, 'stdin');1 unmodified line42 test('stdout cannot be a WritableStream - sync', testWebStreamSync, WritableStream, 1, 'stdout');43 test('stderr cannot be a WritableStream - sync', testWebStreamSync, WritableStream, 2, 'stderr');44 test('stdio[*] cannot be a WritableStream - sync', testWebStreamSync, WritableStream, 3, 'stdio[3]');45 46-const testLongWritableStream = async (t, index) => {46+const testLongWritableStream = async (t, fdNumber) => {47 let result = false;48 const writableStream = new WritableStream({49 async close() {50 await setImmediate();51 result = true;52 },53 });54- await execa('empty.js', getStdio(index, writableStream));54+ await execa('empty.js', getStdio(fdNumber, writableStream));55 t.true(result);56 };57 58 test('stdout waits for WritableStream completion', testLongWritableStream, 1);59 test('stderr waits for WritableStream completion', testLongWritableStream, 2);60 test('stdio[*] waits for WritableStream completion', testLongWritableStream, 3);61 62-const testWritableStreamError = async (t, index) => {62+const testWritableStreamError = async (t, fdNumber) => {63 const error = new Error('foobar');64 const writableStream = new WritableStream({65 start(controller) {66 controller.error(error);67 },68 });69- const thrownError = await t.throwsAsync(execa('noop.js', getStdio(index, writableStream)));69+ const thrownError = await t.throwsAsync(execa('noop.js', getStdio(fdNumber, writableStream)));70 t.is(thrownError, error);71 };72 73 test('stdout option handles errors in WritableStream', testWritableStreamError, 1);74 test('stderr option handles errors in WritableStream', testWritableStreamError, 2);75 test('stdio[*] option handles errors in WritableStream', testWritableStreamError, 3);76 77-const testReadableStreamError = async (t, index) => {77+const testReadableStreamError = async (t, fdNumber) => {78 const error = new Error('foobar');79 const readableStream = new ReadableStream({80 start(controller) {81 controller.error(error);82 },83 });84- const thrownError = await t.throwsAsync(execa('stdin-fd.js', [`${index}`], getStdio(index, readableStream)));84+ const thrownError = await t.throwsAsync(execa('stdin-fd.js', [`${fdNumber}`], getStdio(fdNumber, readableStream)));85 t.is(thrownError, error);86 };87 88 test('stdin option handles errors in ReadableStream', testReadableStreamError, 0);10 unmodified linesmodified:test/stream/child.js+29 added-29 removed
8 unmodified lines9 setFixtureDir();10 11 const isWindows = platform === 'win32';12 13-const getStreamInputProcess = index => execa('stdin-fd.js', [`${index}`], index === 313+const getStreamInputProcess = fdNumber => execa('stdin-fd.js', [`${fdNumber}`], fdNumber === 314 ? getStdio(3, [new Uint8Array(), infiniteGenerator])15 : {});16-const getStreamOutputProcess = index => execa('noop-repeat.js', [`${index}`], index === 3 ? fullStdio : {});16+const getStreamOutputProcess = fdNumber => execa('noop-repeat.js', [`${fdNumber}`], fdNumber === 3 ? fullStdio : {});17 18 const assertStreamInputError = (t, {exitCode, signal, isTerminated, failed}) => {19 t.is(exitCode, 0);20 t.is(signal, undefined);21 t.false(isTerminated);22 t.true(failed);23 };24 25-const assertStreamOutputError = (t, index, {exitCode, signal, isTerminated, failed, stderr}) => {26- if (index !== 3) {25+const assertStreamOutputError = (t, fdNumber, {exitCode, signal, isTerminated, failed, stderr}) => {26+ if (fdNumber !== 3) {27 t.is(exitCode, 1);28 }29 30 t.is(signal, undefined);31 t.false(isTerminated);32 t.true(failed);33 34- if (index === 1 && !isWindows) {34+ if (fdNumber === 1 && !isWindows) {35 t.true(stderr.includes('EPIPE'));36 }37 };38 39-const testStreamInputAbort = async (t, index) => {40- const childProcess = getStreamInputProcess(index);41- childProcess.stdio[index].destroy();39+const testStreamInputAbort = async (t, fdNumber) => {40+ const childProcess = getStreamInputProcess(fdNumber);41+ childProcess.stdio[fdNumber].destroy();42 const error = await t.throwsAsync(childProcess, prematureClose);43 assertStreamInputError(t, error);44 };45 46 test('Aborting stdin should not make the process exit', testStreamInputAbort, 0);47 test('Aborting input stdio[*] should not make the process exit', testStreamInputAbort, 3);48 49-const testStreamOutputAbort = async (t, index) => {50- const childProcess = getStreamOutputProcess(index);51- childProcess.stdio[index].destroy();49+const testStreamOutputAbort = async (t, fdNumber) => {50+ const childProcess = getStreamOutputProcess(fdNumber);51+ childProcess.stdio[fdNumber].destroy();52 const error = await t.throwsAsync(childProcess);53- assertStreamOutputError(t, index, error);53+ assertStreamOutputError(t, fdNumber, error);54 };55 56 test('Aborting stdout should not make the process exit', testStreamOutputAbort, 1);57 test('Aborting stderr should not make the process exit', testStreamOutputAbort, 2);58 test('Aborting output stdio[*] should not make the process exit', testStreamOutputAbort, 3);59 60-const testStreamInputDestroy = async (t, index) => {61- const childProcess = getStreamInputProcess(index);60+const testStreamInputDestroy = async (t, fdNumber) => {61+ const childProcess = getStreamInputProcess(fdNumber);62 const error = new Error('test');63- childProcess.stdio[index].destroy(error);63+ childProcess.stdio[fdNumber].destroy(error);64 t.is(await t.throwsAsync(childProcess), error);65 assertStreamInputError(t, error);66 };67 68 test('Destroying stdin should not make the process exit', testStreamInputDestroy, 0);69 test('Destroying input stdio[*] should not make the process exit', testStreamInputDestroy, 3);70 71-const testStreamOutputDestroy = async (t, index) => {72- const childProcess = getStreamOutputProcess(index);71+const testStreamOutputDestroy = async (t, fdNumber) => {72+ const childProcess = getStreamOutputProcess(fdNumber);73 const error = new Error('test');74- childProcess.stdio[index].destroy(error);74+ childProcess.stdio[fdNumber].destroy(error);75 t.is(await t.throwsAsync(childProcess), error);76- assertStreamOutputError(t, index, error);76+ assertStreamOutputError(t, fdNumber, error);77 };78 79 test('Destroying stdout should not make the process exit', testStreamOutputDestroy, 1);80 test('Destroying stderr should not make the process exit', testStreamOutputDestroy, 2);81 test('Destroying output stdio[*] should not make the process exit', testStreamOutputDestroy, 3);82 83-const testStreamInputError = async (t, index) => {84- const childProcess = getStreamInputProcess(index);83+const testStreamInputError = async (t, fdNumber) => {84+ const childProcess = getStreamInputProcess(fdNumber);85 const error = new Error('test');86- const stream = childProcess.stdio[index];86+ const stream = childProcess.stdio[fdNumber];87 stream.emit('error', error);88 stream.end();89 t.is(await t.throwsAsync(childProcess), error);90 assertStreamInputError(t, error);1 unmodified line92 93 test('Errors on stdin should not make the process exit', testStreamInputError, 0);94 test('Errors on input stdio[*] should not make the process exit', testStreamInputError, 3);95 96-const testStreamOutputError = async (t, index) => {97- const childProcess = getStreamOutputProcess(index);96+const testStreamOutputError = async (t, fdNumber) => {97+ const childProcess = getStreamOutputProcess(fdNumber);98 const error = new Error('test');99- const stream = childProcess.stdio[index];99+ const stream = childProcess.stdio[fdNumber];100 stream.emit('error', error);101 t.is(await t.throwsAsync(childProcess), error);102- assertStreamOutputError(t, index, error);102+ assertStreamOutputError(t, fdNumber, error);103 };104 105 test('Errors on stdout should not make the process exit', testStreamOutputError, 1);106 test('Errors on stderr should not make the process exit', testStreamOutputError, 2);107 test('Errors on output stdio[*] should not make the process exit', testStreamOutputError, 3);108 109-const testWaitOnStreamEnd = async (t, index) => {110- const childProcess = execa('stdin-fd.js', [`${index}`], fullStdio);109+const testWaitOnStreamEnd = async (t, fdNumber) => {110+ const childProcess = execa('stdin-fd.js', [`${fdNumber}`], fullStdio);111 await setTimeout(100);112- childProcess.stdio[index].end('foobar');112+ childProcess.stdio[fdNumber].end('foobar');113 const {stdout} = await childProcess;114 t.is(stdout, 'foobar');115 };116 2 unmodified linesmodified:test/stream/exit.js+18 added-18 removed
5 unmodified lines6 import {fullStdio, getStdio} from '../helpers/stdio.js';7 8 setFixtureDir();9 10-const testBufferIgnore = async (t, index, all) => {11- await t.notThrowsAsync(execa('max-buffer.js', [`${index}`], {...getStdio(index, 'ignore'), buffer: false, all}));10+const testBufferIgnore = async (t, fdNumber, all) => {11+ await t.notThrowsAsync(execa('max-buffer.js', [`${fdNumber}`], {...getStdio(fdNumber, 'ignore'), buffer: false, all}));12 };13 14 test('Process buffers stdout, which does not prevent exit if ignored', testBufferIgnore, 1, false);15 test('Process buffers stderr, which does not prevent exit if ignored', testBufferIgnore, 2, false);16 test('Process buffers all, which does not prevent exit if ignored', testBufferIgnore, 1, true);17 18-const testBufferNotRead = async (t, index, all) => {19- const subprocess = execa('max-buffer.js', [`${index}`], {...fullStdio, buffer: false, all});18+const testBufferNotRead = async (t, fdNumber, all) => {19+ const subprocess = execa('max-buffer.js', [`${fdNumber}`], {...fullStdio, buffer: false, all});20 await t.notThrowsAsync(subprocess);21 };22 23 test('Process buffers stdout, which does not prevent exit if not read and buffer is false', testBufferNotRead, 1, false);24 test('Process buffers stderr, which does not prevent exit if not read and buffer is false', testBufferNotRead, 2, false);25 test('Process buffers stdio[*], which does not prevent exit if not read and buffer is false', testBufferNotRead, 3, false);26 test('Process buffers all, which does not prevent exit if not read and buffer is false', testBufferNotRead, 1, true);27 28-const testBufferRead = async (t, index, all) => {29- const subprocess = execa('max-buffer.js', [`${index}`], {...fullStdio, buffer: false, all});30- const stream = all ? subprocess.all : subprocess.stdio[index];28+const testBufferRead = async (t, fdNumber, all) => {29+ const subprocess = execa('max-buffer.js', [`${fdNumber}`], {...fullStdio, buffer: false, all});30+ const stream = all ? subprocess.all : subprocess.stdio[fdNumber];31 stream.resume();32 await t.notThrowsAsync(subprocess);33 };34 1 unmodified line36 test('Process buffers stderr, which does not prevent exit if read and buffer is false', testBufferRead, 2, false);37 test('Process buffers stdio[*], which does not prevent exit if read and buffer is false', testBufferRead, 3, false);38 test('Process buffers all, which does not prevent exit if read and buffer is false', testBufferRead, 1, true);39 40-const testBufferExit = async (t, index, fixtureName, reject) => {41- const childProcess = execa(fixtureName, [`${index}`], {...fullStdio, reject});40+const testBufferExit = async (t, fdNumber, fixtureName, reject) => {41+ const childProcess = execa(fixtureName, [`${fdNumber}`], {...fullStdio, reject});42 await setTimeout(100);43 const {stdio} = await childProcess;44- t.is(stdio[index], 'foobar');44+ t.is(stdio[fdNumber], 'foobar');45 };46 47 test('Process buffers stdout before it is read', testBufferExit, 1, 'noop-delay.js', true);48 test('Process buffers stderr before it is read', testBufferExit, 2, 'noop-delay.js', true);4 unmodified lines53 test('Process buffers stdout right away, on failure', testBufferExit, 1, 'noop-fail.js', false);54 test('Process buffers stderr right away, on failure', testBufferExit, 2, 'noop-fail.js', false);55 test('Process buffers stdio[*] right away, on failure', testBufferExit, 3, 'noop-fail.js', false);56 57-const testBufferDirect = async (t, index) => {58- const childProcess = execa('noop-fd.js', [`${index}`], fullStdio);59- const data = await once(childProcess.stdio[index], 'data');57+const testBufferDirect = async (t, fdNumber) => {58+ const childProcess = execa('noop-fd.js', [`${fdNumber}`], fullStdio);59+ const data = await once(childProcess.stdio[fdNumber], 'data');60 t.is(data.toString().trim(), 'foobar');61 const result = await childProcess;62- t.is(result.stdio[index], 'foobar');62+ t.is(result.stdio[fdNumber], 'foobar');63 };64 65 test('Process buffers stdout right away, even if directly read', testBufferDirect, 1);66 test('Process buffers stderr right away, even if directly read', testBufferDirect, 2);67 test('Process buffers stdio[*] right away, even if directly read', testBufferDirect, 3);68 69-const testBufferDestroyOnEnd = async (t, index) => {70- const childProcess = execa('noop-fd.js', [`${index}`], fullStdio);69+const testBufferDestroyOnEnd = async (t, fdNumber) => {70+ const childProcess = execa('noop-fd.js', [`${fdNumber}`], fullStdio);71 const result = await childProcess;72- t.is(result.stdio[index], 'foobar');73- t.true(childProcess.stdio[index].destroyed);72+ t.is(result.stdio[fdNumber], 'foobar');73+ t.true(childProcess.stdio[fdNumber].destroyed);74 };75 76 test('childProcess.stdout must be read right away', testBufferDestroyOnEnd, 1);77 test('childProcess.stderr must be read right away', testBufferDestroyOnEnd, 2);1 unmodified linemodified:test/stream/max-buffer.js+22 added-22 removed
7 unmodified lines8 setFixtureDir();9 10 const maxBuffer = 10;11 12-const testMaxBufferSuccess = async (t, index, all) => {13- await t.notThrowsAsync(execa('max-buffer.js', [`${index}`, `${maxBuffer}`], {...fullStdio, maxBuffer, all}));12+const testMaxBufferSuccess = async (t, fdNumber, all) => {13+ await t.notThrowsAsync(execa('max-buffer.js', [`${fdNumber}`, `${maxBuffer}`], {...fullStdio, maxBuffer, all}));14 };15 16 test('maxBuffer does not affect stdout if too high', testMaxBufferSuccess, 1, false);17 test('maxBuffer does not affect stderr if too high', testMaxBufferSuccess, 2, false);8 unmodified lines26 t.true(isTerminated);27 t.is(signal, 'SIGINT');28 });29 30-const testMaxBufferLimit = async (t, index, all) => {30+const testMaxBufferLimit = async (t, fdNumber, all) => {31 const length = all ? maxBuffer * 2 : maxBuffer;32 const result = await t.throwsAsync(33- execa('max-buffer.js', [`${index}`, `${length + 1}`], {...fullStdio, maxBuffer, all}),33+ execa('max-buffer.js', [`${fdNumber}`, `${length + 1}`], {...fullStdio, maxBuffer, all}),34 {message: /maxBuffer exceeded/},35 );36- t.is(all ? result.all : result.stdio[index], '.'.repeat(length));36+ t.is(all ? result.all : result.stdio[fdNumber], '.'.repeat(length));37 };38 39 test('maxBuffer affects stdout', testMaxBufferLimit, 1, false);40 test('maxBuffer affects stderr', testMaxBufferLimit, 2, false);41 test('maxBuffer affects stdio[*]', testMaxBufferLimit, 3, false);42 test('maxBuffer affects all', testMaxBufferLimit, 1, true);43 44-const testMaxBufferEncoding = async (t, index) => {44+const testMaxBufferEncoding = async (t, fdNumber) => {45 const result = await t.throwsAsync(46- execa('max-buffer.js', [`${index}`, `${maxBuffer + 1}`], {...fullStdio, maxBuffer, encoding: 'buffer'}),46+ execa('max-buffer.js', [`${fdNumber}`, `${maxBuffer + 1}`], {...fullStdio, maxBuffer, encoding: 'buffer'}),47 );48- const stream = result.stdio[index];48+ const stream = result.stdio[fdNumber];49 t.true(stream instanceof Uint8Array);50 t.is(Buffer.from(stream).toString(), '.'.repeat(maxBuffer));51 };52 53 test('maxBuffer works with encoding buffer and stdout', testMaxBufferEncoding, 1);54 test('maxBuffer works with encoding buffer and stderr', testMaxBufferEncoding, 2);55 test('maxBuffer works with encoding buffer and stdio[*]', testMaxBufferEncoding, 3);56 57-const testMaxBufferHex = async (t, index) => {57+const testMaxBufferHex = async (t, fdNumber) => {58 const halfMaxBuffer = maxBuffer / 2;59 const {stdio} = await t.throwsAsync(60- execa('max-buffer.js', [`${index}`, `${halfMaxBuffer + 1}`], {...fullStdio, maxBuffer, encoding: 'hex'}),60+ execa('max-buffer.js', [`${fdNumber}`, `${halfMaxBuffer + 1}`], {...fullStdio, maxBuffer, encoding: 'hex'}),61 );62- t.is(stdio[index], Buffer.from('.'.repeat(halfMaxBuffer)).toString('hex'));62+ t.is(stdio[fdNumber], Buffer.from('.'.repeat(halfMaxBuffer)).toString('hex'));63 };64 65 test('maxBuffer works with other encodings and stdout', testMaxBufferHex, 1);66 test('maxBuffer works with other encodings and stderr', testMaxBufferHex, 2);67 test('maxBuffer works with other encodings and stdio[*]', testMaxBufferHex, 3);68 69-const testNoMaxBuffer = async (t, index) => {70- const subprocess = execa('max-buffer.js', [`${index}`, `${maxBuffer}`], {...fullStdio, buffer: false});69+const testNoMaxBuffer = async (t, fdNumber) => {70+ const subprocess = execa('max-buffer.js', [`${fdNumber}`, `${maxBuffer}`], {...fullStdio, buffer: false});71 const [result, output] = await Promise.all([72 subprocess,73- getStream(subprocess.stdio[index]),73+ getStream(subprocess.stdio[fdNumber]),74 ]);75- t.is(result.stdio[index], undefined);75+ t.is(result.stdio[fdNumber], undefined);76 t.is(output, '.'.repeat(maxBuffer));77 };78 79 test('do not buffer stdout when `buffer` set to `false`', testNoMaxBuffer, 1);80 test('do not buffer stderr when `buffer` set to `false`', testNoMaxBuffer, 2);81 test('do not buffer stdio[*] when `buffer` set to `false`', testNoMaxBuffer, 3);82 83-const testNoMaxBufferOption = async (t, index) => {83+const testNoMaxBufferOption = async (t, fdNumber) => {84 const length = maxBuffer + 1;85- const subprocess = execa('max-buffer.js', [`${index}`, `${length}`], {...fullStdio, maxBuffer, buffer: false});85+ const subprocess = execa('max-buffer.js', [`${fdNumber}`, `${length}`], {...fullStdio, maxBuffer, buffer: false});86 const [result, output] = await Promise.all([87 subprocess,88- getStream(subprocess.stdio[index]),88+ getStream(subprocess.stdio[fdNumber]),89 ]);90- t.is(result.stdio[index], undefined);90+ t.is(result.stdio[fdNumber], undefined);91 t.is(output, '.'.repeat(length));92 };93 94 test('do not hit maxBuffer when `buffer` is `false` with stdout', testNoMaxBufferOption, 1);95 test('do not hit maxBuffer when `buffer` is `false` with stderr', testNoMaxBufferOption, 2);96 test('do not hit maxBuffer when `buffer` is `false` with stdio[*]', testNoMaxBufferOption, 3);97 98-const testMaxBufferAbort = async (t, index) => {99- const childProcess = execa('max-buffer.js', [`${index}`, `${maxBuffer + 1}`], {...fullStdio, maxBuffer});98+const testMaxBufferAbort = async (t, fdNumber) => {99+ const childProcess = execa('max-buffer.js', [`${fdNumber}`, `${maxBuffer + 1}`], {...fullStdio, maxBuffer});100 await Promise.all([101 t.throwsAsync(childProcess, {message: /maxBuffer exceeded/}),102- t.throwsAsync(getStream(childProcess.stdio[index]), {code: 'ABORT_ERR'}),102+ t.throwsAsync(getStream(childProcess.stdio[fdNumber]), {code: 'ABORT_ERR'}),103 ]);104 };105 106 test('abort stream when hitting maxBuffer with stdout', testMaxBufferAbort, 1);2 unmodified linesmodified:test/stream/no-buffer.js+12 added-12 removed
6 unmodified lines7 import {foobarString} from '../helpers/input.js';8 9 setFixtureDir();10 11-const testLateStream = async (t, index, all) => {12- const subprocess = execa('noop-fd-ipc.js', [`${index}`, foobarString], {...getStdio(4, 'ipc', 4), buffer: false, all});11+const testLateStream = async (t, fdNumber, all) => {12+ const subprocess = execa('noop-fd-ipc.js', [`${fdNumber}`, foobarString], {...getStdio(4, 'ipc', 4), buffer: false, all});13 await once(subprocess, 'message');14 const [output, allOutput] = await Promise.all([15- getStream(subprocess.stdio[index]),15+ getStream(subprocess.stdio[fdNumber]),16 all ? getStream(subprocess.all) : undefined,17 subprocess,18 ]);19 14 unmodified lines34 return output.toString();35 };36 37 // eslint-disable-next-line max-params38-const testIterationBuffer = async (t, index, buffer, useDataEvents, all) => {39- const subprocess = execa('noop-fd.js', [`${index}`, foobarString], {...fullStdio, buffer, all});38+const testIterationBuffer = async (t, fdNumber, buffer, useDataEvents, all) => {39+ const subprocess = execa('noop-fd.js', [`${fdNumber}`, foobarString], {...fullStdio, buffer, all});40 const getOutput = useDataEvents ? getFirstDataEvent : getStream;41 const [result, output, allOutput] = await Promise.all([42 subprocess,43- getOutput(subprocess.stdio[index]),43+ getOutput(subprocess.stdio[fdNumber]),44 all ? getOutput(subprocess.all) : undefined,45 ]);46 47 const expectedProcessResult = buffer ? foobarString : undefined;48 const expectedOutput = !buffer || useDataEvents ? foobarString : '';49 50- t.is(result.stdio[index], expectedProcessResult);50+ t.is(result.stdio[fdNumber], expectedProcessResult);51 t.is(output, expectedOutput);52 53 if (all) {54 t.is(result.all, expectedProcessResult);17 unmodified lines72 test('Can listen to `data` events on stderr when `buffer` set to `true`', testIterationBuffer, 2, true, true, false);73 test('Can listen to `data` events on stdio[*] when `buffer` set to `true`', testIterationBuffer, 3, true, true, false);74 test('Can listen to `data` events on all when `buffer` set to `true`', testIterationBuffer, 1, true, true, true);75 76-const testNoBufferStreamError = async (t, index, all) => {77- const subprocess = execa('noop-fd.js', [`${index}`], {...fullStdio, buffer: false, all});78- const stream = all ? subprocess.all : subprocess.stdio[index];76+const testNoBufferStreamError = async (t, fdNumber, all) => {77+ const subprocess = execa('noop-fd.js', [`${fdNumber}`], {...fullStdio, buffer: false, all});78+ const stream = all ? subprocess.all : subprocess.stdio[fdNumber];79 const error = new Error('test');80 stream.destroy(error);81 t.is(await t.throwsAsync(subprocess), error);82 };11 unmodified lines94 const {exitCode} = await t.throwsAsync(execa('fail.js', {buffer: false}));95 t.is(exitCode, 2);96 });97 98-const testStreamEnd = async (t, index, buffer) => {98+const testStreamEnd = async (t, fdNumber, buffer) => {99 const subprocess = execa('wrong command', {...fullStdio, buffer});100 await Promise.all([101 t.throwsAsync(subprocess, {message: /wrong command/}),102- once(subprocess.stdio[index], 'end'),102+ once(subprocess.stdio[fdNumber], 'end'),103 ]);104 };105 106 test('buffer: false > emits end event on stdout when promise is rejected', testStreamEnd, 1, false);5 unmodified linesmodified:test/stream/resolve.js+3 added-3 removed
3 unmodified lines4 import {getStdio} from '../helpers/stdio.js';5 6 setFixtureDir();7 8-const testIgnore = async (t, index, execaMethod) => {9- const result = await execaMethod('noop.js', getStdio(index, 'ignore'));10- t.is(result.stdio[index], undefined);8+const testIgnore = async (t, fdNumber, execaMethod) => {9+ const result = await execaMethod('noop.js', getStdio(fdNumber, 'ignore'));10+ t.is(result.stdio[fdNumber], undefined);11 };12 13 test('stdout is undefined if ignored', testIgnore, 1, execa);14 test('stderr is undefined if ignored', testIgnore, 2, execa);35 unmodified linesmodified:test/stream/wait.js+25 added-25 removed
20 unmodified lines21 const destroyOptionStream = ({stream, error}) => {22 stream.destroy(error);23 };24 25-const destroyChildStream = ({childProcess, index, error}) => {26- childProcess.stdio[index].destroy(error);25+const destroyChildStream = ({childProcess, fdNumber, error}) => {26+ childProcess.stdio[fdNumber].destroy(error);27 };28 29-const getStreamStdio = (index, stream, useTransform) => getStdio(index, [stream, useTransform ? noopGenerator(false) : 'pipe']);29+const getStreamStdio = (fdNumber, stream, useTransform) => getStdio(fdNumber, [stream, useTransform ? noopGenerator(false) : 'pipe']);30 31 // eslint-disable-next-line max-params32-const testStreamAbortWait = async (t, streamMethod, stream, index, useTransform) => {33- const childProcess = execa('noop-stdin-fd.js', [`${index}`], getStreamStdio(index, stream, useTransform));34- streamMethod({stream, childProcess, index});32+const testStreamAbortWait = async (t, streamMethod, stream, fdNumber, useTransform) => {33+ const childProcess = execa('noop-stdin-fd.js', [`${fdNumber}`], getStreamStdio(fdNumber, stream, useTransform));34+ streamMethod({stream, childProcess, fdNumber});35 childProcess.stdin.end();36 await setImmediate();37 stream.destroy();38 9 unmodified lines48 test('Keeps running when stdin option is used and childProcess.stdin Duplex ends, with a transform', testStreamAbortWait, noop, noopDuplex(), 0, true);49 test('Keeps running when input stdio[*] option is used and input childProcess.stdio[*] ends, with a transform', testStreamAbortWait, noop, noopReadable(), 3, true);50 51 // eslint-disable-next-line max-params52-const testStreamAbortSuccess = async (t, streamMethod, stream, index, useTransform) => {53- const childProcess = execa('noop-stdin-fd.js', [`${index}`], getStreamStdio(index, stream, useTransform));54- streamMethod({stream, childProcess, index});52+const testStreamAbortSuccess = async (t, streamMethod, stream, fdNumber, useTransform) => {53+ const childProcess = execa('noop-stdin-fd.js', [`${fdNumber}`], getStreamStdio(fdNumber, stream, useTransform));54+ streamMethod({stream, childProcess, fdNumber});55 childProcess.stdin.end();56 57 const {stdout} = await childProcess;58 t.is(stdout, '');25 unmodified lines84 test('Passes when output childProcess.stdio[*] aborts with no more writes, with a transform', testStreamAbortSuccess, destroyChildStream, noopWritable(), 3, true);85 test('Passes when output childProcess.stdio[*] Duplex aborts with no more writes, with a transform', testStreamAbortSuccess, destroyChildStream, noopDuplex(), 3, true);86 87 // eslint-disable-next-line max-params88-const testStreamAbortFail = async (t, streamMethod, stream, index, useTransform) => {89- const childProcess = execa('noop-stdin-fd.js', [`${index}`], getStreamStdio(index, stream, useTransform));90- streamMethod({stream, childProcess, index});91- if (index !== 0) {88+const testStreamAbortFail = async (t, streamMethod, stream, fdNumber, useTransform) => {89+ const childProcess = execa('noop-stdin-fd.js', [`${fdNumber}`], getStreamStdio(fdNumber, stream, useTransform));90+ streamMethod({stream, childProcess, fdNumber});91+ if (fdNumber !== 0) {92 childProcess.stdin.end();93 }94 95 const error = await t.throwsAsync(childProcess);20 unmodified lines116 test('Throws abort error when output stdio[*] option aborts with no more writes, with a transform', testStreamAbortFail, destroyOptionStream, noopWritable(), 3, true);117 test('Throws abort error when output stdio[*] Duplex option aborts with no more writes, with a transform', testStreamAbortFail, destroyOptionStream, noopDuplex(), 3, true);118 119 // eslint-disable-next-line max-params120-const testStreamEpipeSuccess = async (t, streamMethod, stream, index, useTransform) => {121- const childProcess = execa('noop-stdin-fd.js', [`${index}`], getStreamStdio(index, stream, useTransform));122- streamMethod({stream, childProcess, index});120+const testStreamEpipeSuccess = async (t, streamMethod, stream, fdNumber, useTransform) => {121+ const childProcess = execa('noop-stdin-fd.js', [`${fdNumber}`], getStreamStdio(fdNumber, stream, useTransform));122+ streamMethod({stream, childProcess, fdNumber});123 childProcess.stdin.end(foobarString);124 125 const {stdio} = await childProcess;126- t.is(stdio[index], foobarString);126+ t.is(stdio[fdNumber], foobarString);127 t.true(stream.destroyed);128 };129 130 test('Passes when stdout option ends with more writes', testStreamEpipeSuccess, endOptionStream, noopWritable(), 1, false);3 unmodified lines134 test('Passes when stderr option ends with more writes, with a transform', testStreamEpipeSuccess, endOptionStream, noopWritable(), 2, true);135 test('Passes when output stdio[*] option ends with more writes, with a transform', testStreamEpipeSuccess, endOptionStream, noopWritable(), 3, true);136 137 // eslint-disable-next-line max-params138-const testStreamEpipeFail = async (t, streamMethod, stream, index, useTransform) => {139- const childProcess = execa('noop-stdin-fd.js', [`${index}`], getStreamStdio(index, stream, useTransform));140- streamMethod({stream, childProcess, index});138+const testStreamEpipeFail = async (t, streamMethod, stream, fdNumber, useTransform) => {139+ const childProcess = execa('noop-stdin-fd.js', [`${fdNumber}`], getStreamStdio(fdNumber, stream, useTransform));140+ streamMethod({stream, childProcess, fdNumber});141 await setImmediate();142 childProcess.stdin.end(foobarString);143 144 const {exitCode, stdio, stderr} = await t.throwsAsync(childProcess);145 t.is(exitCode, 1);146- t.is(stdio[index], '');146+ t.is(stdio[fdNumber], '');147 t.true(stream.destroyed);148- if (index !== 2 && !isWindows) {148+ if (fdNumber !== 2 && !isWindows) {149 t.true(stderr.includes('EPIPE'));150 }151 };152 22 unmodified lines175 test('Throws EPIPE when output childProcess.stdio[*] aborts with more writes, with a transform', testStreamEpipeFail, destroyChildStream, noopWritable(), 3, true);176 test('Throws EPIPE when output childProcess.stdio[*] Duplex aborts with more writes, with a transform', testStreamEpipeFail, destroyChildStream, noopDuplex(), 3, true);177 178 // eslint-disable-next-line max-params179-const testStreamError = async (t, streamMethod, stream, index, useTransform) => {180- const childProcess = execa('empty.js', getStreamStdio(index, stream, useTransform));179+const testStreamError = async (t, streamMethod, stream, fdNumber, useTransform) => {180+ const childProcess = execa('empty.js', getStreamStdio(fdNumber, stream, useTransform));181 const error = new Error('test');182- streamMethod({stream, childProcess, index, error});182+ streamMethod({stream, childProcess, fdNumber, error});183 184 t.is(await t.throwsAsync(childProcess), error);185 const {exitCode, signal, isTerminated, failed} = error;186 t.is(exitCode, 0);42 unmodified linesmodified:index.d.ts+38 added-38 removed
102 unmodified lines103 type BufferEncodingOption = 'buffer';104 105 // Whether `result.stdout|stderr|all` is an array of values due to `objectMode: true`106 type IsObjectStream<107- StreamIndex extends string,107+ FdNumber extends string,108 OptionsType extends CommonOptions = CommonOptions,109-> = IsObjectModeStream<StreamIndex, IsObjectOutputOptions<StreamOption<StreamIndex, OptionsType>>, OptionsType>;109+> = IsObjectModeStream<FdNumber, IsObjectOutputOptions<StreamOption<FdNumber, OptionsType>>, OptionsType>;110 111 type IsObjectModeStream<112- StreamIndex extends string,112+ FdNumber extends string,113 IsObjectModeStreamOption extends boolean,114 OptionsType extends CommonOptions = CommonOptions,115 > = IsObjectModeStreamOption extends true116 ? true117- : IsObjectOutputOptions<StdioProperty<StreamIndex, OptionsType>>;117+ : IsObjectOutputOptions<StdioProperty<FdNumber, OptionsType>>;118 119 type IsObjectOutputOptions<OutputOptions extends StdioOption> = IsObjectOutputOption<OutputOptions extends StdioSingleOption[]120 ? OutputOptions[number]121 : OutputOptions6 unmodified lines128 type BooleanObjectMode<ObjectModeOption extends StdioTransformFull['objectMode']> = ObjectModeOption extends true ? true : false;129 130 // Whether `result.stdout|stderr|all` is `undefined`, excluding the `buffer` option131 type IgnoresStreamResult<132- StreamIndex extends string,132+ FdNumber extends string,133 OptionsType extends CommonOptions = CommonOptions,134-> = IgnoresStreamReturn<StreamIndex, IgnoresStdioResult<StreamOption<StreamIndex, OptionsType>>, OptionsType>;134+> = IgnoresStreamReturn<FdNumber, IgnoresStdioResult<StreamOption<FdNumber, OptionsType>>, OptionsType>;135 136 type IgnoresStreamReturn<137- StreamIndex extends string,137+ FdNumber extends string,138 IsIgnoredStreamOption extends boolean,139 OptionsType extends CommonOptions = CommonOptions,140 > = IsIgnoredStreamOption extends true141 ? true142- : IgnoresStdioResult<StdioProperty<StreamIndex, OptionsType>>;142+ : IgnoresStdioResult<StdioProperty<FdNumber, OptionsType>>;143 144 // Whether `result.stdio[*]` is `undefined`145 type IgnoresStdioResult<StdioOptionType extends StdioOption> = StdioOptionType extends NoStreamStdioOption ? true : false;146 147 // Whether `result.stdout|stderr|all` is `undefined`148 type IgnoresStreamOutput<149- StreamIndex extends string,149+ FdNumber extends string,150 OptionsType extends CommonOptions = CommonOptions,151 > = LacksBuffer<OptionsType['buffer']> extends true152 ? true153- : IsInputStdioIndex<StreamIndex, OptionsType> extends true153+ : IsInputStdioDescriptor<FdNumber, OptionsType> extends true154 ? true155- : IgnoresStreamResult<StreamIndex, OptionsType>;155+ : IgnoresStreamResult<FdNumber, OptionsType>;156 157 type LacksBuffer<BufferOption extends Options['buffer']> = BufferOption extends false ? true : false;158 159-// Whether `result.stdio[StreamIndex]` is an input stream160-type IsInputStdioIndex<161- StreamIndex extends string,159+// Whether `result.stdio[FdNumber]` is an input stream160+type IsInputStdioDescriptor<161+ FdNumber extends string,162 OptionsType extends CommonOptions = CommonOptions,163-> = StreamIndex extends '0'163+> = FdNumber extends '0'164 ? true165- : IsInputStdio<StdioProperty<StreamIndex, OptionsType>>;165+ : IsInputStdio<StdioProperty<FdNumber, OptionsType>>;166 167 // Whether `result.stdio[3+]` is an input stream168 type IsInputStdio<StdioOptionType extends StdioOption> = StdioOptionType extends StdinOption169 ? StdioOptionType extends StdoutStderrOption2 unmodified lines172 : false;173 174 // `options.stdin|stdout|stderr`175 type StreamOption<176- StreamIndex extends string,176+ FdNumber extends string,177 OptionsType extends CommonOptions = CommonOptions,178-> = string extends StreamIndex ? StdioOption179- : StreamIndex extends '0' ? OptionsType['stdin']180- : StreamIndex extends '1' ? OptionsType['stdout']181- : StreamIndex extends '2' ? OptionsType['stderr']178+> = string extends FdNumber ? StdioOption179+ : FdNumber extends '0' ? OptionsType['stdin']180+ : FdNumber extends '1' ? OptionsType['stdout']181+ : FdNumber extends '2' ? OptionsType['stderr']182 : undefined;183 184-// `options.stdio[StreamIndex]`184+// `options.stdio[FdNumber]`185 type StdioProperty<186- StreamIndex extends string,186+ FdNumber extends string,187 OptionsType extends CommonOptions = CommonOptions,188-> = StdioOptionProperty<StreamIndex, StdioArrayOption<OptionsType>>;188+> = StdioOptionProperty<FdNumber, StdioArrayOption<OptionsType>>;189 190 type StdioOptionProperty<191- StreamIndex extends string,191+ FdNumber extends string,192 StdioOptionsType extends StdioOptions,193-> = string extends StreamIndex193+> = string extends FdNumber194 ? StdioOption | undefined195 : StdioOptionsType extends StdioOptionsArray196- ? StreamIndex extends keyof StdioOptionsType197- ? StdioOptionsType[StreamIndex]196+ ? FdNumber extends keyof StdioOptionsType197+ ? StdioOptionsType[FdNumber]198 : undefined199 : undefined;200 201 // Type of `result.stdout|stderr`202 type StdioOutput<203- StreamIndex extends string,203+ FdNumber extends string,204 OptionsType extends CommonOptions = CommonOptions,205-> = StdioOutputResult<StreamIndex, IgnoresStreamOutput<StreamIndex, OptionsType>, OptionsType>;205+> = StdioOutputResult<FdNumber, IgnoresStreamOutput<FdNumber, OptionsType>, OptionsType>;206 207 type StdioOutputResult<208- StreamIndex extends string,208+ FdNumber extends string,209 StreamOutputIgnored extends boolean,210 OptionsType extends CommonOptions = CommonOptions,211 > = StreamOutputIgnored extends true212 ? undefined213- : StreamEncoding<IsObjectStream<StreamIndex, OptionsType>, OptionsType['lines'], OptionsType['encoding']>;213+ : StreamEncoding<IsObjectStream<FdNumber, OptionsType>, OptionsType['lines'], OptionsType['encoding']>;214 215 type StreamEncoding<216 IsObjectResult extends boolean,217 LinesOption extends CommonOptions['lines'],27 unmodified lines245 type MapStdioOptions<246 StdioOptionsArrayType extends StdioOptionsArray,247 OptionsType extends CommonOptions = CommonOptions,248 > = {249- [StreamIndex in keyof StdioOptionsArrayType]: StdioOutput<250- StreamIndex extends string ? StreamIndex : string,249+ [FdNumber in keyof StdioOptionsArrayType]: StdioOutput<250+ FdNumber extends string ? FdNumber : string,251 OptionsType252 >253 };254 526 unmodified lines781 export type ExecaError<OptionsType extends Options = Options> = ExecaCommonReturnValue<false, OptionsType> & ExecaCommonError;782 export type ExecaSyncError<OptionsType extends SyncOptions = SyncOptions> = ExecaCommonReturnValue<true, OptionsType> & ExecaCommonError;783 784 type StreamUnlessIgnored<785- StreamIndex extends string,785+ FdNumber extends string,786 OptionsType extends Options = Options,787-> = ChildProcessStream<StreamIndex, IgnoresStreamResult<StreamIndex, OptionsType>, OptionsType>;787+> = ChildProcessStream<FdNumber, IgnoresStreamResult<FdNumber, OptionsType>, OptionsType>;788 789 type ChildProcessStream<790- StreamIndex extends string,790+ FdNumber extends string,791 StreamResultIgnored extends boolean,792 OptionsType extends Options = Options,793 > = StreamResultIgnored extends true794 ? null795- : InputOutputStream<IsInputStdioIndex<StreamIndex, OptionsType>>;795+ : InputOutputStream<IsInputStdioDescriptor<FdNumber, OptionsType>>;796 797 type InputOutputStream<IsInput extends boolean> = IsInput extends true798 ? Writable799 : Readable;582 unmodified lines