Rename `from|to: 3` to `from|to: 'fd3'` (#920)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by ehmicky · committed by GitHub · parent 26e9150 · Browse files · 11 files·+203 added−128 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
11 files+203 added−128 removed
- tests:+120 added−78 removed
- other:+83 added−50 removed
Provenance
- Commit
8dfdd91- Tree
0e80fb5- Author
ehmicky <ehmicky@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent
26e9150
11 files changed+203 added−128 removed
modified:lib/pipe/validate.js+33 added-19 removed
107 unmodified linesExpand all1081091101111121131141121131141151161171161171181191201211201211221231241251261221231241251261271281291301311321331341351361371381391401411421291431441311451461471481491361501511521531401541551421431561571581595 unmodified lines1651661671681571691701711721738 unmodified lines1821831841851861871881891901915 unmodified lines107 unmodified linesExpand all return sourceStream;};
const getFdNumber = (stdioStreamsGroups, fdName, isWritable) => { const fdNumber = STANDARD_STREAMS_ALIASES.includes(fdName) ? STANDARD_STREAMS_ALIASES.indexOf(fdName) : fdName; const fdNumber = parseFdNumber(fdName, isWritable); validateFdNumber(fdNumber, fdName, isWritable, stdioStreamsGroups); return fdNumber;};
const parseFdNumber = (fdName, isWritable) => { if (fdNumber === 'all') { return fdNumber; if (fdName === 'all') { return fdName; }
if (!Number.isInteger(fdNumber) || fdNumber < 0) { const {validOptions, defaultValue} = isWritable ? {validOptions: '"stdin"', defaultValue: 'stdin'} : {validOptions: '"stdout", "stderr", "all"', defaultValue: 'stdout'}; throw new TypeError(`"${getOptionName(isWritable)}" must not be "${fdNumber}".It must be ${validOptions} or a file descriptor integer.It is optional and defaults to "${defaultValue}".`); if (STANDARD_STREAMS_ALIASES.includes(fdName)) { return STANDARD_STREAMS_ALIASES.indexOf(fdName); }
const regexpResult = FD_REGEXP.exec(fdName); if (regexpResult !== null) { return Number(regexpResult[1]); }
const {validOptions, defaultValue} = isWritable ? {validOptions: '"stdin"', defaultValue: 'stdin'} : {validOptions: '"stdout", "stderr", "all"', defaultValue: 'stdout'}; throw new TypeError(`"${getOptionName(isWritable)}" must not be "${fdName}".It must be ${validOptions} or "fd3", "fd4" (and so on).It is optional and defaults to "${defaultValue}".`);};
const FD_REGEXP = /^fd(\d+)$/;
const validateFdNumber = (fdNumber, fdName, isWritable, stdioStreamsGroups) => { const usedDescriptor = getUsedDescriptor(fdNumber); const stdioStreams = stdioStreamsGroups[fdNumber]; const stdioStreams = stdioStreamsGroups[usedDescriptor]; if (stdioStreams === undefined) { throw new TypeError(`"${getOptionName(isWritable)}" must not be ${fdNumber}. That file descriptor does not exist. throw new TypeError(`"${getOptionName(isWritable)}" must not be ${fdName}. That file descriptor does not exist.Please set the "stdio" option to ensure that file descriptor exists.`); }
if (stdioStreams[0].direction === 'input' && !isWritable) { throw new TypeError(`"${getOptionName(isWritable)}" must not be ${fdNumber}. It must be a readable stream, not writable.`); throw new TypeError(`"${getOptionName(isWritable)}" must not be ${fdName}. It must be a readable stream, not writable.`); }
if (stdioStreams[0].direction !== 'input' && isWritable) { throw new TypeError(`"${getOptionName(isWritable)}" must not be ${fdNumber}. It must be a writable stream, not readable.`); throw new TypeError(`"${getOptionName(isWritable)}" must not be ${fdName}. It must be a writable stream, not readable.`); }
return fdNumber;};
const getInvalidStdioOptionMessage = (fdNumber, fdName, options, isWritable) => { if (fdNumber === 'all' && !options.all) {5 unmodified linesPlease set this option with "pipe" instead.`;};
const getInvalidStdioOption = (fdNumber, {stdin, stdout, stderr, stdio}) => { const usedDescriptor = fdNumber === 'all' ? 1 : fdNumber; const usedDescriptor = getUsedDescriptor(fdNumber);
if (usedDescriptor === 0 && stdin !== undefined) { return {optionName: 'stdin', optionValue: stdin}; }8 unmodified lines
return {optionName: `stdio[${usedDescriptor}]`, optionValue: stdio[usedDescriptor]};};
const getUsedDescriptor = fdNumber => fdNumber === 'all' ? 1 : fdNumber;
const serializeOptionValue = optionValue => { if (typeof optionValue === 'string') { return `'${optionValue}'`; }5 unmodified linesmodified:test/convert/concurrent.js+20 added-20 removed
50 unmodified lines51 ]);52 await assertSubprocessOutput(t, subprocess, foobarString, fdNumber);53 };54 55-test('Can call .readable() twice on same file descriptor', testReadableTwice, 1, undefined);55+test('Can call .readable() twice on same file descriptor', testReadableTwice, 1);56 test('Can call .readable({from: "stderr"}) twice on same file descriptor', testReadableTwice, 2, 'stderr');57 58-const testWritableTwice = async (t, fdNumber, options) => {58+const testWritableTwice = async (t, fdNumber, to, options) => {59 const subprocess = execa('stdin-fd.js', [`${fdNumber}`], options);60- const stream = subprocess.writable({to: fdNumber});61- const secondStream = subprocess.writable({to: fdNumber});60+ const stream = subprocess.writable({to});61+ const secondStream = subprocess.writable({to});62 63 await Promise.all([64 finishedStream(stream),65 finishedStream(secondStream),1 unmodified line67 ]);68 await assertSubprocessOutput(t, subprocess, `${foobarString}${foobarString}`);69 };70 71-test('Can call .writable() twice on same file descriptor', testWritableTwice, 0, {});72-test('Can call .writable({to: 3}) twice on same file descriptor', testWritableTwice, 3, fullReadableStdio());71+test('Can call .writable() twice on same file descriptor', testWritableTwice, 0, undefined, {});72+test('Can call .writable({to: "fd3"}) twice on same file descriptor', testWritableTwice, 3, 'fd3', fullReadableStdio());73 74-const testDuplexTwice = async (t, fdNumber, options) => {74+const testDuplexTwice = async (t, fdNumber, to, options) => {75 const subprocess = execa('stdin-fd.js', [`${fdNumber}`], options);76- const stream = subprocess.duplex({to: fdNumber});77- const secondStream = subprocess.duplex({to: fdNumber});76+ const stream = subprocess.duplex({to});77+ const secondStream = subprocess.duplex({to});78 79 const expectedOutput = `${foobarString}${foobarString}`;80 await Promise.all([81 assertStreamOutput(t, stream, expectedOutput),2 unmodified lines84 ]);85 await assertSubprocessOutput(t, subprocess, expectedOutput);86 };87 88-test('Can call .duplex() twice on same file descriptor', testDuplexTwice, 0, {});89-test('Can call .duplex({to: 3}) twice on same file descriptor', testDuplexTwice, 3, fullReadableStdio());88+test('Can call .duplex() twice on same file descriptor', testDuplexTwice, 0, undefined, {});89+test('Can call .duplex({to: "fd3"}) twice on same file descriptor', testDuplexTwice, 3, 'fd3', fullReadableStdio());90 91 test('Can call .duplex() twice on same readable file descriptor but different writable one', async t => {92 const subprocess = execa('stdin-fd-both.js', ['3'], fullReadableStdio());93- const stream = subprocess.duplex({to: 0});94- const secondStream = subprocess.duplex({to: 3});93+ const stream = subprocess.duplex();94+ const secondStream = subprocess.duplex({to: 'fd3'});95 96 const expectedOutput = `${foobarString}${foobarString}`;97 await Promise.all([98 assertStreamOutput(t, stream, expectedOutput),19 unmodified lines118 119 test('Can call .writable() twice on different file descriptors', async t => {120 const subprocess = execa('stdin-fd-both.js', ['3'], fullReadableStdio());121 const stream = subprocess.writable();122- const secondStream = subprocess.writable({to: 3});122+ const secondStream = subprocess.writable({to: 'fd3'});123 124 await Promise.all([125 finishedStream(stream),126 finishedStream(secondStream),4 unmodified lines131 132 test('Can call .duplex() twice on different file descriptors', async t => {133 const subprocess = execa('stdin-twice-both.js', ['3'], fullReadableStdio());134 const stream = subprocess.duplex();135- const secondStream = subprocess.duplex({from: 'stderr', to: 3});135+ const secondStream = subprocess.duplex({from: 'stderr', to: 'fd3'});136 137 await Promise.all([138 assertStreamOutput(t, stream),139 assertStreamOutput(t, secondStream),18 unmodified lines158 159 test('Can call .writable() and .duplex()', async t => {160 const subprocess = execa('stdin-fd-both.js', ['3'], fullReadableStdio());161 const stream = subprocess.duplex();162- const secondStream = subprocess.writable({to: 3});162+ const secondStream = subprocess.writable({to: 'fd3'});163 164 const expectedOutput = `${foobarString}${foobarString}`;165 await Promise.all([166 assertStreamOutput(t, stream, expectedOutput),112 unmodified lines279 280 test('Can error one of two .writable() on different file descriptors', async t => {281 const subprocess = execa('stdin-fd-both.js', ['3'], fullReadableStdio());282 const stream = subprocess.writable();283- const secondStream = subprocess.writable({to: 3});283+ const secondStream = subprocess.writable({to: 'fd3'});284 const cause = new Error(foobarString);285 stream.destroy(cause);286 secondStream.end(foobarString);287 8 unmodified lines296 297 test('Can error both .writable() on different file descriptors', async t => {298 const subprocess = execa('stdin-fd-both.js', ['3'], fullReadableStdio());299 const stream = subprocess.writable();300- const secondStream = subprocess.writable({to: 3});300+ const secondStream = subprocess.writable({to: 'fd3'});301 const cause = new Error(foobarString);302 stream.destroy(cause);303 secondStream.destroy(cause);304 37 unmodified lines342 343 test('Can error one of two .duplex() on different file descriptors', async t => {344 const subprocess = execa('stdin-twice-both.js', ['3'], fullReadableStdio());345 const stream = subprocess.duplex();346- const secondStream = subprocess.duplex({from: 'stderr', to: 3});346+ const secondStream = subprocess.duplex({from: 'stderr', to: 'fd3'});347 const cause = new Error(foobarString);348 stream.destroy(cause);349 secondStream.end(foobarString);350 7 unmodified lines358 359 test('Can error both .duplex() on different file descriptors', async t => {360 const subprocess = execa('stdin-twice-both.js', ['3'], fullReadableStdio());361 const stream = subprocess.duplex();362- const secondStream = subprocess.duplex({from: 'stderr', to: 3});362+ const secondStream = subprocess.duplex({from: 'stderr', to: 'fd3'});363 const cause = new Error(foobarString);364 stream.destroy(cause);365 secondStream.destroy(cause);366 6 unmodified linesmodified:test/convert/duplex.js+7 added-7 removed
46 unmodified lines47 await assertStreamOutput(t, stream, hasResult ? foobarString : '');48 await assertSubprocessOutput(t, subprocess, foobarString, fdNumber);49 };50 51-test('.duplex() can use stdout', testReadableDuplexDefault, 1, 1, {}, true);52-test('.duplex() can use stderr', testReadableDuplexDefault, 2, 2, {}, true);53-test('.duplex() can use output stdio[*]', testReadableDuplexDefault, 3, 3, fullStdio, true);51+test('.duplex() can use stdout', testReadableDuplexDefault, 1, 'stdout', {}, true);52+test('.duplex() can use stderr', testReadableDuplexDefault, 2, 'stderr', {}, true);53+test('.duplex() can use output stdio[*]', testReadableDuplexDefault, 3, 'fd3', fullStdio, true);54 test('.duplex() uses stdout by default', testReadableDuplexDefault, 1, undefined, {}, true);55 test('.duplex() does not use stderr by default', testReadableDuplexDefault, 2, undefined, {}, false);56 test('.duplex() does not use stdio[*] by default', testReadableDuplexDefault, 3, undefined, fullStdio, false);57-test('.duplex() uses stdout even if stderr is "ignore"', testReadableDuplexDefault, 1, 1, {stderr: 'ignore'}, true);58-test('.duplex() uses stderr even if stdout is "ignore"', testReadableDuplexDefault, 2, 2, {stdout: 'ignore'}, true);57+test('.duplex() uses stdout even if stderr is "ignore"', testReadableDuplexDefault, 1, 'stdout', {stderr: 'ignore'}, true);58+test('.duplex() uses stderr even if stdout is "ignore"', testReadableDuplexDefault, 2, 'stderr', {stdout: 'ignore'}, true);59 test('.duplex() uses stdout if "all" is used', testReadableDuplexDefault, 1, 'all', {all: true}, true);60 test('.duplex() uses stderr if "all" is used', testReadableDuplexDefault, 2, 'all', {all: true}, true);61 62 const testWritableDuplexDefault = async (t, fdNumber, to, options) => {5 unmodified lines68 await assertStreamOutput(t, stream, foobarString);69 await assertSubprocessOutput(t, subprocess);70 };71 72-test('.duplex() can use stdin', testWritableDuplexDefault, 0, 0, {});73-test('.duplex() can use input stdio[*]', testWritableDuplexDefault, 3, 3, fullReadableStdio());72+test('.duplex() can use stdin', testWritableDuplexDefault, 0, 'stdin', {});73+test('.duplex() can use input stdio[*]', testWritableDuplexDefault, 3, 'fd3', fullReadableStdio());74 test('.duplex() uses stdin by default', testWritableDuplexDefault, 0, undefined, {});75 76 test('.duplex() abort -> subprocess fail', async t => {77 const subprocess = getReadWriteSubprocess();111 unmodified linesmodified:test/convert/readable.js+5 added-5 removed
49 unmodified lines50 await assertStreamOutput(t, stream, hasResult ? foobarString : '');51 await assertSubprocessOutput(t, subprocess, foobarString, fdNumber);52 };53 54-test('.readable() can use stdout', testReadableDefault, 1, 1, {}, true);55-test('.readable() can use stderr', testReadableDefault, 2, 2, {}, true);56-test('.readable() can use stdio[*]', testReadableDefault, 3, 3, fullStdio, true);54+test('.readable() can use stdout', testReadableDefault, 1, 'stdout', {}, true);55+test('.readable() can use stderr', testReadableDefault, 2, 'stderr', {}, true);56+test('.readable() can use stdio[*]', testReadableDefault, 3, 'fd3', fullStdio, true);57 test('.readable() uses stdout by default', testReadableDefault, 1, undefined, {}, true);58 test('.readable() does not use stderr by default', testReadableDefault, 2, undefined, {}, false);59 test('.readable() does not use stdio[*] by default', testReadableDefault, 3, undefined, fullStdio, false);60-test('.readable() uses stdout even if stderr is "ignore"', testReadableDefault, 1, 1, {stderr: 'ignore'}, true);61-test('.readable() uses stderr even if stdout is "ignore"', testReadableDefault, 2, 2, {stdout: 'ignore'}, true);60+test('.readable() uses stdout even if stderr is "ignore"', testReadableDefault, 1, 'stdout', {stderr: 'ignore'}, true);61+test('.readable() uses stderr even if stdout is "ignore"', testReadableDefault, 2, 'stderr', {stdout: 'ignore'}, true);62 test('.readable() uses stdout if "all" is used', testReadableDefault, 1, 'all', {all: true}, true);63 test('.readable() uses stderr if "all" is used', testReadableDefault, 2, 'all', {all: true}, true);64 65 const testBuffering = async (t, methodName) => {389 unmodified linesmodified:test/convert/writable.js+2 added-2 removed
55 unmodified lines56 await finishedStream(stream);57 await assertSubprocessOutput(t, subprocess);58 };59 60-test('.writable() can use stdin', testWritableDefault, 0, 0, {});61-test('.writable() can use stdio[*]', testWritableDefault, 3, 3, fullReadableStdio());60+test('.writable() can use stdin', testWritableDefault, 0, 'stdin', {});61+test('.writable() can use stdio[*]', testWritableDefault, 3, 'fd3', fullReadableStdio());62 test('.writable() uses stdin by default', testWritableDefault, 0, undefined, {});63 64 test('.writable() hangs until ended', async t => {65 const subprocess = getReadWriteSubprocess();324 unmodified linesmodified:test/pipe/setup.js+5 added-5 removed
13 unmodified lines14 };15 16 test('pipe(...) can pipe', pipeToSubprocess, 1, 0);17 test('pipe(..., {from: "stdout"}) can pipe', pipeToSubprocess, 1, 0, 'stdout');18-test('pipe(..., {from: 1}) can pipe', pipeToSubprocess, 1, 0, 1);18+test('pipe(..., {from: "fd1"}) can pipe', pipeToSubprocess, 1, 0, 'fd1');19 test('pipe(..., {from: "stderr"}) can pipe stderr', pipeToSubprocess, 2, 0, 'stderr');20-test('pipe(..., {from: 2}) can pipe', pipeToSubprocess, 2, 0, 2);21-test('pipe(..., {from: 3}) can pipe', pipeToSubprocess, 3, 0, 3, undefined, fullStdio);20+test('pipe(..., {from: "fd2"}) can pipe', pipeToSubprocess, 2, 0, 'fd2');21+test('pipe(..., {from: "fd3"}) can pipe', pipeToSubprocess, 3, 0, 'fd3', undefined, fullStdio);22 test('pipe(..., {from: "all"}) can pipe stdout', pipeToSubprocess, 1, 0, 'all', undefined, {all: true});23 test('pipe(..., {from: "all"}) can pipe stderr', pipeToSubprocess, 2, 0, 'all', undefined, {all: true});24 test('pipe(..., {from: "all"}) can pipe stdout even with "stderr: ignore"', pipeToSubprocess, 1, 0, 'all', undefined, {all: true, stderr: 'ignore'});25 test('pipe(..., {from: "all"}) can pipe stderr even with "stdout: ignore"', pipeToSubprocess, 2, 0, 'all', undefined, {all: true, stdout: 'ignore'});26 test('pipe(..., {to: "stdin"}) can pipe', pipeToSubprocess, 1, 0, undefined, 'stdin');27-test('pipe(..., {to: 0}) can pipe', pipeToSubprocess, 1, 0, undefined, 0);28-test('pipe(..., {to: 3}) can pipe', pipeToSubprocess, 1, 3, undefined, 3, {}, fullReadableStdio());27+test('pipe(..., {to: "fd0"}) can pipe', pipeToSubprocess, 1, 0, undefined, 'fd0');28+test('pipe(..., {to: "fd3"}) can pipe', pipeToSubprocess, 1, 3, undefined, 'fd3', {}, fullReadableStdio());modified:test/pipe/streaming.js+1 added-1 removed
90 unmodified lines91 test('Can pipe same source to two streams from same subprocess', async t => {92 const source = execa('noop-fd.js', ['1', foobarString]);93 const destination = execa('stdin-fd-both.js', ['3'], fullReadableStdio());94 const pipePromise = source.pipe(destination);95- const secondPipePromise = source.pipe(destination, {to: 3});95+ const secondPipePromise = source.pipe(destination, {to: 'fd3'});96 97 t.like(await source, {stdout: foobarString});98 t.like(await destination, {stdout: `${foobarString}${foobarString}`});99 t.is(await pipePromise, await destination);342 unmodified linesmodified:test/pipe/validate.js+80 added-38 removed
131 unmodified lines132 test('.duplex() "to" option cannot be any string', testNodeStream, {133 to: 'other',134 message: 'must be "stdin"',135 });136+test('.pipe() "from" option cannot be a number without "fd"', testPipeError, {137+ from: '1',138+ message: 'must be "stdout", "stderr", "all"',139+});140+test('.duplex() "from" option cannot be a number without "fd"', testNodeStream, {141+ from: '1',142+ message: 'must be "stdout", "stderr", "all"',143+});144+test('.pipe() "to" option cannot be a number without "fd"', testPipeError, {145+ to: '0',146+ message: 'must be "stdin"',147+});148+test('.duplex() "to" option cannot be a number without "fd"', testNodeStream, {149+ to: '0',150+ message: 'must be "stdin"',151+});152+test('.pipe() "from" option cannot be just "fd"', testPipeError, {153+ from: 'fd',154+ message: 'must be "stdout", "stderr", "all"',155+});156+test('.duplex() "from" option cannot be just "fd"', testNodeStream, {157+ from: 'fd',158+ message: 'must be "stdout", "stderr", "all"',159+});160+test('.pipe() "to" option cannot be just "fd"', testPipeError, {161+ to: 'fd',162+ message: 'must be "stdin"',163+});164+test('.duplex() "to" option cannot be just "fd"', testNodeStream, {165+ to: 'fd',166+ message: 'must be "stdin"',167+});168 test('.pipe() "from" option cannot be a float', testPipeError, {137- from: 1.5,169+ from: 'fd1.5',170 message: 'must be "stdout", "stderr", "all"',171 });172 test('.duplex() "from" option cannot be a float', testNodeStream, {141- from: 1.5,173+ from: 'fd1.5',174 message: 'must be "stdout", "stderr", "all"',175 });176 test('.pipe() "to" option cannot be a float', testPipeError, {145- to: 1.5,177+ to: 'fd1.5',178 message: 'must be "stdin"',179 });180 test('.duplex() "to" option cannot be a float', testNodeStream, {149- to: 1.5,181+ to: 'fd1.5',182 message: 'must be "stdin"',183 });184 test('.pipe() "from" option cannot be a negative number', testPipeError, {153- from: -1,185+ from: 'fd-1',186 message: 'must be "stdout", "stderr", "all"',187 });188 test('.duplex() "from" option cannot be a negative number', testNodeStream, {157- from: -1,189+ from: 'fd-1',190 message: 'must be "stdout", "stderr", "all"',191 });192 test('.pipe() "to" option cannot be a negative number', testPipeError, {161- to: -1,193+ to: 'fd-1',194 message: 'must be "stdin"',195 });196 test('.duplex() "to" option cannot be a negative number', testNodeStream, {165- to: -1,197+ to: 'fd-1',198 message: 'must be "stdin"',199 });200 test('.pipe() "from" option cannot be a non-existing file descriptor', testPipeError, {169- from: 3,201+ from: 'fd3',202 message: 'file descriptor does not exist',203 });204 test('.duplex() "from" cannot be a non-existing file descriptor', testNodeStream, {173- from: 3,205+ from: 'fd3',206 message: 'file descriptor does not exist',207 });208 test('.pipe() "to" option cannot be a non-existing file descriptor', testPipeError, {177- to: 3,209+ to: 'fd3',210 message: 'file descriptor does not exist',211 });212 test('.duplex() "to" cannot be a non-existing file descriptor', testNodeStream, {181- to: 3,213+ to: 'fd3',214 message: 'file descriptor does not exist',215 });216 test('.pipe() "from" option cannot be an input file descriptor', testPipeError, {217 sourceOptions: getStdio(3, new Uint8Array()),186- from: 3,218+ from: 'fd3',219 message: 'must be a readable stream',220 });221 test('.duplex() "from" option cannot be an input file descriptor', testNodeStream, {222 sourceOptions: getStdio(3, new Uint8Array()),191- from: 3,223+ from: 'fd3',224 message: 'must be a readable stream',225 });226 test('.pipe() "to" option cannot be an output file descriptor', testPipeError, {227 destinationOptions: fullStdio,196- to: 3,228+ to: 'fd3',229 message: 'must be a writable stream',230 });231 test('.duplex() "to" option cannot be an output file descriptor', testNodeStream, {232 sourceOptions: fullStdio,201- to: 3,233+ to: 'fd3',234 message: 'must be a writable stream',235 });236+test('.pipe() "to" option cannot be "all"', testPipeError, {237+ destinationOptions: fullStdio,238+ to: 'all',239+ message: 'must be a writable stream',240+});241+test('.duplex() "to" option cannot be "all"', testNodeStream, {242+ sourceOptions: fullStdio,243+ to: 'all',244+ message: 'must be a writable stream',245+});246 test('Cannot set "stdout" option to "ignore" to use .pipe()', testPipeError, {247 sourceOptions: {stdout: 'ignore'},248 message: ['stdout', '\'ignore\''],249 });11 unmodified lines261 writable: true,262 });263 test('Cannot set "stdout" option to "ignore" to use .pipe(1)', testPipeError, {264 sourceOptions: {stdout: 'ignore'},223- from: 1,265+ from: 'fd1',266 message: ['stdout', '\'ignore\''],267 });268 test('Cannot set "stdout" option to "ignore" to use .duplex(1)', testNodeStream, {269 sourceOptions: {stdout: 'ignore'},228- from: 1,270+ from: 'fd1',271 message: ['stdout', '\'ignore\''],272 });273 test('Cannot set "stdin" option to "ignore" to use .pipe(0)', testPipeError, {274 destinationOptions: {stdin: 'ignore'},275 message: ['stdin', '\'ignore\''],234- to: 0,276+ to: 'fd0',277 });278 test('Cannot set "stdin" option to "ignore" to use .duplex(0)', testNodeStream, {279 sourceOptions: {stdin: 'ignore'},280 message: ['stdin', '\'ignore\''],239- to: 0,281+ to: 'fd0',282 });283 test('Cannot set "stdout" option to "ignore" to use .pipe("stdout")', testPipeError, {284 sourceOptions: {stdout: 'ignore'},285 from: 'stdout',23 unmodified lines309 message: ['stdout', '\'ignore\''],310 });311 test('Cannot set "stdout" + "stderr" option to "ignore" to use .pipe(1)', testPipeError, {312 sourceOptions: {stdout: 'ignore', stderr: 'ignore'},271- from: 1,313+ from: 'fd1',314 message: ['stdout', '\'ignore\''],315 });316 test('Cannot set "stdout" + "stderr" option to "ignore" to use .duplex(1)', testNodeStream, {317 sourceOptions: {stdout: 'ignore', stderr: 'ignore'},276- from: 1,318+ from: 'fd1',319 message: ['stdout', '\'ignore\''],320 });321 test('Cannot set "stdout" + "stderr" option to "ignore" to use .pipe("stdout")', testPipeError, {322 sourceOptions: {stdout: 'ignore', stderr: 'ignore'},23 unmodified lines346 writable: true,347 });348 test('Cannot set "stdio[1]" option to "ignore" to use .pipe(1)', testPipeError, {349 sourceOptions: {stdio: ['pipe', 'ignore', 'pipe']},308- from: 1,350+ from: 'fd1',351 message: ['stdio[1]', '\'ignore\''],352 });353 test('Cannot set "stdio[1]" option to "ignore" to use .duplex(1)', testNodeStream, {354 sourceOptions: {stdio: ['pipe', 'ignore', 'pipe']},313- from: 1,355+ from: 'fd1',356 message: ['stdio[1]', '\'ignore\''],357 });358 test('Cannot set "stdio[0]" option to "ignore" to use .pipe(0)', testPipeError, {359 destinationOptions: {stdio: ['ignore', 'pipe', 'pipe']},360 message: ['stdio[0]', '\'ignore\''],319- to: 0,361+ to: 'fd0',362 });363 test('Cannot set "stdio[0]" option to "ignore" to use .duplex(0)', testNodeStream, {364 sourceOptions: {stdio: ['ignore', 'pipe', 'pipe']},365 message: ['stdio[0]', '\'ignore\''],324- to: 0,366+ to: 'fd0',367 });368 test('Cannot set "stdio[1]" option to "ignore" to use .pipe("stdout")', testPipeError, {369 sourceOptions: {stdio: ['pipe', 'ignore', 'pipe']},370 from: 'stdout',15 unmodified lines386 to: 'stdin',387 });388 test('Cannot set "stderr" option to "ignore" to use .pipe(2)', testPipeError, {389 sourceOptions: {stderr: 'ignore'},348- from: 2,390+ from: 'fd2',391 message: ['stderr', '\'ignore\''],392 });393 test('Cannot set "stderr" option to "ignore" to use .duplex(2)', testNodeStream, {394 sourceOptions: {stderr: 'ignore'},353- from: 2,395+ from: 'fd2',396 message: ['stderr', '\'ignore\''],397 });398 test('Cannot set "stderr" option to "ignore" to use .pipe("stderr")', testPipeError, {399 sourceOptions: {stderr: 'ignore'},6 unmodified lines406 message: ['stderr', '\'ignore\''],407 });408 test('Cannot set "stdout" + "stderr" option to "ignore" to use .pipe(2)', testPipeError, {409 sourceOptions: {stdout: 'ignore', stderr: 'ignore'},368- from: 2,410+ from: 'fd2',411 message: ['stderr', '\'ignore\''],412 });413 test('Cannot set "stdout" + "stderr" option to "ignore" to use .duplex(2)', testNodeStream, {414 sourceOptions: {stdout: 'ignore', stderr: 'ignore'},373- from: 2,415+ from: 'fd2',416 message: ['stderr', '\'ignore\''],417 });418 test('Cannot set "stdout" + "stderr" option to "ignore" to use .pipe("stderr")', testPipeError, {419 sourceOptions: {stdout: 'ignore', stderr: 'ignore'},6 unmodified lines426 message: ['stderr', '\'ignore\''],427 });428 test('Cannot set "stdio[2]" option to "ignore" to use .pipe(2)', testPipeError, {429 sourceOptions: {stdio: ['pipe', 'pipe', 'ignore']},388- from: 2,430+ from: 'fd2',431 message: ['stdio[2]', '\'ignore\''],432 });433 test('Cannot set "stdio[2]" option to "ignore" to use .duplex(2)', testNodeStream, {434 sourceOptions: {stdio: ['pipe', 'pipe', 'ignore']},393- from: 2,435+ from: 'fd2',436 message: ['stdio[2]', '\'ignore\''],437 });438 test('Cannot set "stdio[2]" option to "ignore" to use .pipe("stderr")', testPipeError, {439 sourceOptions: {stdio: ['pipe', 'pipe', 'ignore']},6 unmodified lines446 message: ['stdio[2]', '\'ignore\''],447 });448 test('Cannot set "stdio[3]" option to "ignore" to use .pipe(3)', testPipeError, {449 sourceOptions: getStdio(3, 'ignore'),408- from: 3,450+ from: 'fd3',451 message: ['stdio[3]', '\'ignore\''],452 });453 test('Cannot set "stdio[3]" option to "ignore" to use .duplex(3)', testNodeStream, {454 sourceOptions: getStdio(3, 'ignore'),413- from: 3,455+ from: 'fd3',456 message: ['stdio[3]', '\'ignore\''],457 });458 test('Cannot set "stdout" + "stderr" option to "ignore" to use .pipe("all")', testPipeError, {459 sourceOptions: {stdout: 'ignore', stderr: 'ignore', all: true},85 unmodified lines545 });546 test('Cannot set "stdio[3]" option to Node.js Writable streams to use .pipe()', testPipeError, {547 sourceOptions: getStdio(3, process.stdout),548 message: ['stdio[3]', 'Stream'],507- from: 3,549+ from: 'fd3',550 });551 test('Cannot set "stdio[3]" option to Node.js Writable streams to use .duplex()', testNodeStream, {552 sourceOptions: getStdio(3, process.stdout),553 message: ['stdio[3]', 'Stream'],512- from: 3,554+ from: 'fd3',555 });556 test('Cannot set "stdio[3]" option to Node.js Readable streams to use .pipe()', testPipeError, {557 destinationOptions: getStdio(3, process.stdin),558 message: ['stdio[3]', 'Stream'],517- to: 3,559+ to: 'fd3',560 });561 test('Cannot set "stdio[3]" option to Node.js Readable streams to use .duplex()', testNodeStream, {562 sourceOptions: getStdio(3, process.stdin),563 message: ['stdio[3]', 'Stream'],522- to: 3,564+ to: 'fd3',565 });566 567 test('Destination stream is ended when first argument is invalid', async t => {568 const source = execa('empty.js', {stdout: 'ignore'});58 unmodified linesmodified:index.d.ts+7 added-6 removed
903 unmodified lines904 type AllIfStderr<StderrResultIgnored extends boolean> = StderrResultIgnored extends true905 ? undefined906 : Readable;907 908-type FromOption = 'stdout' | 'stderr' | 'all' | number;909-type ToOption = 'stdin' | number;908+type FileDescriptorOption = `fd${number}`;909+type FromOption = 'stdout' | 'stderr' | 'all' | FileDescriptorOption;910+type ToOption = 'stdin' | FileDescriptorOption;911 912 type PipeOptions = {913 /**913- Which stream to pipe from the source subprocess. A file descriptor number can also be passed.914+ Which stream to pipe from the source subprocess. A file descriptor like `"fd3"` can also be passed.915 916 `"all"` pipes both `stdout` and `stderr`. This requires the `all` option to be `true`.917 */918 readonly from?: FromOption;919 920 /**920- Which stream to pipe to the destination subprocess. A file descriptor number can also be passed.921+ Which stream to pipe to the destination subprocess. A file descriptor like `"fd3"` can also be passed.922 */923 readonly to?: ToOption;924 925 /**47 unmodified lines973 };974 975 type ReadableStreamOptions = {976 /**976- Which stream to read from the subprocess. A file descriptor number can also be passed.977+ Which stream to read from the subprocess. A file descriptor like `"fd3"` can also be passed.978 979 `"all"` reads both `stdout` and `stderr`. This requires the `all` option to be `true`.980 */981 readonly from?: FromOption;982 };983 984 type WritableStreamOptions = {985 /**985- Which stream to write to the subprocess. A file descriptor number can also be passed.986+ Which stream to write to the subprocess. A file descriptor like `"fd3"` can also be passed.987 */988 readonly to?: ToOption;989 };990 539 unmodified linesmodified:index.test-d.ts+35 added-17 removed
86 unmodified lines87 const bufferResult = await execaBufferPromise;88 89 const scriptPromise = $`unicorns`;90 91- const pipeOptions = {from: 'stderr', to: 3, all: true} as const;91+ const pipeOptions = {from: 'stderr', to: 'fd3', all: true} as const;92 93 type BufferExecaReturnValue = typeof bufferResult;94 type EmptyExecaReturnValue = ExecaResult<{}>;95 type ShortcutExecaReturnValue = ExecaResult<typeof pipeOptions>;73 unmodified lines169 await execaPromise.pipe({from: 'all'})`stdin`;170 await scriptPromise.pipe({from: 'all'})`stdin`;171 await execaPromise.pipe('stdin', {from: 'all'});172 await scriptPromise.pipe('stdin', {from: 'all'});173- await execaPromise.pipe(execaBufferPromise, {from: 3});174- await scriptPromise.pipe(execaBufferPromise, {from: 3});175- await execaPromise.pipe({from: 3})`stdin`;176- await scriptPromise.pipe({from: 3})`stdin`;177- await execaPromise.pipe('stdin', {from: 3});178- await scriptPromise.pipe('stdin', {from: 3});173+ await execaPromise.pipe(execaBufferPromise, {from: 'fd3'});174+ await scriptPromise.pipe(execaBufferPromise, {from: 'fd3'});175+ await execaPromise.pipe({from: 'fd3'})`stdin`;176+ await scriptPromise.pipe({from: 'fd3'})`stdin`;177+ await execaPromise.pipe('stdin', {from: 'fd3'});178+ await scriptPromise.pipe('stdin', {from: 'fd3'});179 expectError(execaPromise.pipe(execaBufferPromise, {from: 'stdin'}));180 expectError(scriptPromise.pipe(execaBufferPromise, {from: 'stdin'}));181 expectError(execaPromise.pipe({from: 'stdin'})`stdin`);182 expectError(scriptPromise.pipe({from: 'stdin'})`stdin`);4 unmodified lines187 await execaPromise.pipe({to: 'stdin'})`stdin`;188 await scriptPromise.pipe({to: 'stdin'})`stdin`;189 await execaPromise.pipe('stdin', {to: 'stdin'});190 await scriptPromise.pipe('stdin', {to: 'stdin'});191- await execaPromise.pipe(execaBufferPromise, {to: 3});192- await scriptPromise.pipe(execaBufferPromise, {to: 3});193- await execaPromise.pipe({to: 3})`stdin`;194- await scriptPromise.pipe({to: 3})`stdin`;195- await execaPromise.pipe('stdin', {to: 3});196- await scriptPromise.pipe('stdin', {to: 3});191+ await execaPromise.pipe(execaBufferPromise, {to: 'fd3'});192+ await scriptPromise.pipe(execaBufferPromise, {to: 'fd3'});193+ await execaPromise.pipe({to: 'fd3'})`stdin`;194+ await scriptPromise.pipe({to: 'fd3'})`stdin`;195+ await execaPromise.pipe('stdin', {to: 'fd3'});196+ await scriptPromise.pipe('stdin', {to: 'fd3'});197 expectError(execaPromise.pipe(execaBufferPromise, {to: 'stdout'}));198 expectError(scriptPromise.pipe(execaBufferPromise, {to: 'stdout'}));199 expectError(execaPromise.pipe({to: 'stdout'})`stdin`);200 expectError(scriptPromise.pipe({to: 'stdout'})`stdin`);33 unmodified lines234 expectError(await execaPromise.pipe('stdin', [false]));235 expectError(await execaPromise.pipe('stdin', [], false));236 expectError(await execaPromise.pipe('stdin', {other: true}));237 expectError(await execaPromise.pipe('stdin', [], {other: true}));238+ expectError(await execaPromise.pipe('stdin', {from: 'fd'}));239+ expectError(await execaPromise.pipe('stdin', [], {from: 'fd'}));240+ expectError(await execaPromise.pipe('stdin', {from: 'fdNotANumber'}));241+ expectError(await execaPromise.pipe('stdin', [], {from: 'fdNotANumber'}));242 expectError(await execaPromise.pipe('stdin', {from: 'other'}));243 expectError(await execaPromise.pipe('stdin', [], {from: 'other'}));244+ expectError(await execaPromise.pipe('stdin', {to: 'fd'}));245+ expectError(await execaPromise.pipe('stdin', [], {to: 'fd'}));246+ expectError(await execaPromise.pipe('stdin', {to: 'fdNotANumber'}));247+ expectError(await execaPromise.pipe('stdin', [], {to: 'fdNotANumber'}));248+ expectError(await execaPromise.pipe('stdin', {to: 'other'}));249+ expectError(await execaPromise.pipe('stdin', [], {to: 'other'}));250 251 const pipeResult = await execaPromise.pipe`stdin`;252 expectType<string>(pipeResult.stdout);253 const ignorePipeResult = await execaPromise.pipe({stdout: 'ignore'})`stdin`;21 unmodified lines275 scriptPromise.readable({});276 scriptPromise.readable({from: 'stdout'});277 scriptPromise.readable({from: 'stderr'});278 scriptPromise.readable({from: 'all'});269- scriptPromise.readable({from: 3});279+ scriptPromise.readable({from: 'fd3'});280 expectError(scriptPromise.readable('stdout'));281 expectError(scriptPromise.readable({from: 'stdin'}));282+ expectError(scriptPromise.readable({from: 'fd'}));283+ expectError(scriptPromise.readable({from: 'fdNotANumber'}));284 expectError(scriptPromise.readable({other: 'stdout'}));285 scriptPromise.writable({});286 scriptPromise.writable({to: 'stdin'});275- scriptPromise.writable({to: 3});287+ scriptPromise.writable({to: 'fd3'});288 expectError(scriptPromise.writable('stdin'));289 expectError(scriptPromise.writable({to: 'stdout'}));290+ expectError(scriptPromise.writable({to: 'fd'}));291+ expectError(scriptPromise.writable({to: 'fdNotANumber'}));292 expectError(scriptPromise.writable({other: 'stdin'}));293 scriptPromise.duplex({});294 scriptPromise.duplex({from: 'stdout'});295 scriptPromise.duplex({from: 'stderr'});296 scriptPromise.duplex({from: 'all'});283- scriptPromise.duplex({from: 3});297+ scriptPromise.duplex({from: 'fd3'});298 scriptPromise.duplex({from: 'stdout', to: 'stdin'});285- scriptPromise.duplex({from: 'stdout', to: 3});299+ scriptPromise.duplex({from: 'stdout', to: 'fd3'});300 expectError(scriptPromise.duplex('stdout'));301 expectError(scriptPromise.duplex({from: 'stdin'}));302 expectError(scriptPromise.duplex({from: 'stderr', to: 'stdout'}));303+ expectError(scriptPromise.duplex({from: 'fd'}));304+ expectError(scriptPromise.duplex({from: 'fdNotANumber'}));305+ expectError(scriptPromise.duplex({to: 'fd'}));306+ expectError(scriptPromise.duplex({to: 'fdNotANumber'}));307 expectError(scriptPromise.duplex({other: 'stdout'}));308 309 expectType<Readable>(execaPromise.all);310 const noAllPromise = execa('unicorns');1350 unmodified linesmodified:readme.md+8 added-8 removed
399 unmodified lines400 Type: `object`401 402 ##### pipeOptions.from403 404-Type: `"stdout" | "stderr" | "all" | number`\404+Type: `"stdout" | "stderr" | "all" | "fd3" | "fd4" | ...`\405 Default: `"stdout"`406 407-Which stream to pipe from the source subprocess. A file descriptor number can also be passed.407+Which stream to pipe from the source subprocess. A file descriptor like `"fd3"` can also be passed.408 409 `"all"` pipes both `stdout` and `stderr`. This requires the [`all` option](#all-2) to be `true`.410 411 ##### pipeOptions.to412 413-Type: `"stdin" | number`\413+Type: `"stdin" | "fd3" | "fd4" | ...`\414 Default: `"stdin"`415 416-Which stream to pipe to the destination subprocess. A file descriptor number can also be passed.416+Which stream to pipe to the destination subprocess. A file descriptor like `"fd3"` can also be passed.417 418 ##### pipeOptions.unpipeSignal419 420 Type: [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal)55 unmodified lines476 Type: `object`477 478 ##### streamOptions.from479 480-Type: `"stdout" | "stderr" | "all" | number`\480+Type: `"stdout" | "stderr" | "all" | "fd3" | "fd4" | ...`\481 Default: `"stdout"`482 483-Which stream to read from the subprocess. A file descriptor number can also be passed.483+Which stream to read from the subprocess. A file descriptor like `"fd3"` can also be passed.484 485 `"all"` reads both `stdout` and `stderr`. This requires the [`all` option](#all-2) to be `true`.486 487 Only available with [`.readable()`](#readablestreamoptions) and [`.duplex()`](#duplexstreamoptions), not [`.writable()`](#writablestreamoptions).488 489 ##### streamOptions.to490 491-Type: `"stdin" | number`\491+Type: `"stdin" | "fd3" | "fd4" | ...`\492 Default: `"stdin"`493 494-Which stream to write to the subprocess. A file descriptor number can also be passed.494+Which stream to write to the subprocess. A file descriptor like `"fd3"` can also be passed.495 496 Only available with [`.writable()`](#writablestreamoptions) and [`.duplex()`](#duplexstreamoptions), not [`.readable()`](#readablestreamoptions).497 498 ### SubprocessResult662 unmodified lines