Skip to content
Myr

Add `{value: 'pipe', input: true}` to use an additional file descriptor as input (#1246)

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

authored by Sindre Sorhus · committed by GitHub · parent dcf611c · Browse files · 23 files+332 added−23 removed
This commit

State

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

Diff stats

23 files+332 added−23 removed

  • tests:+86 added−2 removed
  • other:+246 added−21 removed

23 files+332 added−23 removed

modified:.github/workflows/main.yml+1 added-1 removed
modified:docs/api.md+2 added-2 removed
914 unmodified lines
915916### options.stdio917918_TypeScript:_ [`Options['stdio']`](typescript.md) or [`SyncOptions['stdio']`](typescript.md)\919_Type:_ `string | Array<string | number | stream.Readable | stream.Writable | ReadableStream | WritableStream | TransformStream | URL | {file: string} | Uint8Array | Iterable<string> | Iterable<Uint8Array> | Iterable<unknown> | AsyncIterable<string | Uint8Array | unknown> | GeneratorFunction<string | Uint8Array | unknown> | AsyncGeneratorFunction<string | Uint8Array | unknown> | {transform: GeneratorFunction | AsyncGeneratorFunction | Duplex | TransformStream}>` (or a tuple of those types)\919_Type:_ `string | Array<string | number | stream.Readable | stream.Writable | ReadableStream | WritableStream | TransformStream | URL | {file: string} | Uint8Array | Iterable<string> | Iterable<Uint8Array> | Iterable<unknown> | AsyncIterable<string | Uint8Array | unknown> | GeneratorFunction<string | Uint8Array | unknown> | AsyncGeneratorFunction<string | Uint8Array | unknown> | {transform: GeneratorFunction | AsyncGeneratorFunction | Duplex | TransformStream} | {value: 'pipe'; input?: boolean}>` (or a tuple of those types)\920_Default:_ `pipe`921922Like the [`stdin`](#optionsstdin), [`stdout`](#optionsstdout) and [`stderr`](#optionsstderr) options but for all [file descriptors](https://en.wikipedia.org/wiki/File_descriptor) at once. For example, `{stdio: ['ignore', 'pipe', 'pipe']}` is the same as `{stdin: 'ignore', stdout: 'pipe', stderr: 'pipe'}`.923924A single string can be used [as a shortcut](output.md#shortcut).925926The array can have more than 3 items, to create [additional file descriptors](output.md#additional-file-descriptors) beyond [`stdin`](#optionsstdin)/[`stdout`](#optionsstdout)/[`stderr`](#optionsstderr).926The array can have more than 3 items, to create [additional file descriptors](output.md#additional-file-descriptors) beyond [`stdin`](#optionsstdin)/[`stdout`](#optionsstdout)/[`stderr`](#optionsstderr). Passing `'pipe'` to an additional file descriptor defaults it to output. To use it for [input](input.md#additional-file-descriptors) instead, pass `{value: 'pipe', input: true}`.927928More info on [available values](output.md), [streaming](streams.md) and [transforms](transform.md).929930### options.all
377 unmodified lines
modified:docs/input.md+13 added
modified:docs/streams.md+8 added
102 unmodified lines
103104const duplex = execa`npm run scaffold`.duplex({from: 'stderr', to: 'fd3'});105```106107Writing to an additional file descriptor like `'fd3'` requires marking it as [input](input.md#additional-file-descriptors), since it otherwise defaults to output.108109```js110const subprocess = execa({stdio: ['pipe', 'pipe', 'pipe', {value: 'pipe', input: true}]})`npm run scaffold`;111112const writable = subprocess.writable({to: 'fd3'});113```114115### Error handling116117When using [`subprocess.readable()`](api.md#subprocessreadablereadableoptions), [`subprocess.writable()`](api.md#subprocesswritablewritableoptions) or [`subprocess.duplex()`](api.md#subprocessduplexduplexoptions), the stream waits for the subprocess to end, and emits an [`error`](https://nodejs.org/api/stream.html#event-error) event if the subprocess [fails](errors.md). This differs from [`subprocess.stdin`](api.md#subprocessstdin), [`subprocess.stdout`](api.md#subprocessstdout) and [`subprocess.stderr`](api.md#subprocessstderr)'s behavior.118
7 unmodified lines
modified:lib/arguments/fd-options.js+2 added-1 removed
61 unmodified lines
62 throw new TypeError(`"${getOptionName(isWritable)}" must not be ${fdName}. It must be a readable stream, not writable.`);63 }6465 if (fileDescriptor.direction !== 'input' && isWritable) {66 throw new TypeError(`"${getOptionName(isWritable)}" must not be ${fdName}. It must be a writable stream, not readable.`);66 throw new TypeError(`"${getOptionName(isWritable)}" must not be ${fdName}. It must be a writable stream, not readable.67If you meant to use it as input, please set its "stdio" option to \`{value: 'pipe', input: true}\`.`);68 }69};7071const getInvalidStdioOptionMessage = (fdNumber, fdName, options, isWritable) => {
38 unmodified lines
modified:lib/stdio/direction.js+3 added-1 removed
18 unmodified lines
1920 return directions.find(Boolean) ?? DEFAULT_DIRECTION;21};2223// `direction` is set when the user explicitly requests it, e.g. `{value: 'pipe', input: true}`.24// It takes precedence over guessing, but not over the fixed direction of `stdin`/`stdout`/`stderr`.23const getStdioItemDirection = ({type, value}, fdNumber) => KNOWN_DIRECTIONS[fdNumber] ?? guessStreamDirection[type](value);25const getStdioItemDirection = ({type, value, direction}, fdNumber) => KNOWN_DIRECTIONS[fdNumber] ?? direction ?? guessStreamDirection[type](value);2627// `stdin`/`stdout`/`stderr` have a known direction28const KNOWN_DIRECTIONS = ['input', 'output', 'output'];29
49 unmodified lines
modified:lib/stdio/duplicate.js+4 added-1 removed
6 unmodified lines
78// Duplicates in the same file descriptor is most likely an error.9// However, this can be useful with generators.10export const filterDuplicates = stdioItems => stdioItems.filter((stdioItemOne, indexOne) =>11 stdioItems.every((stdioItemTwo, indexTwo) => stdioItemOne.value !== stdioItemTwo.value11 stdioItems.every((stdioItemTwo, indexTwo) => !hasSameValueAndDirection(stdioItemOne, stdioItemTwo)12 || indexOne >= indexTwo13 || stdioItemOne.type === 'generator'14 || stdioItemOne.type === 'asyncGenerator'));1516const hasSameValueAndDirection = (stdioItemOne, stdioItemTwo) => stdioItemOne.value === stdioItemTwo.value17 && stdioItemOne.direction === stdioItemTwo.direction;1819// Check if two file descriptors are sharing the same target.20// For example `{stdout: {file: './output.txt'}, stderr: {file: './output.txt'}}`.21export const getDuplicateStream = ({stdioItem: {type, value, optionName}, direction, fileDescriptors, isSync}) => {22 const otherStdioItems = getOtherStdioItems(fileDescriptors, type);
97 unmodified lines
modified:lib/stdio/handle-sync.js+11 added
16 unmodified lines
1718 return {};19};2021// A native input pipe on an additional file descriptor cannot be fed in sync mode, since there is no way to write to it after spawning, so it would hang.22const forbiddenNativeInputIfSync = stdioItem => {23 const {optionName, value} = stdioItem;24 if (value === 'pipe' && optionName !== 'stdin') {25 throw new TypeError(`Only the \`stdin\` option, not \`${optionName}\`, can be an input pipe with synchronous methods.`);26 }2728 return forbiddenNativeIfSync(stdioItem);29};3031const throwInvalidSyncValue = (optionName, value) => {32 throw new TypeError(`The \`${optionName}\` option cannot be ${value} with synchronous methods.`);33};34
12 unmodified lines
4748const addPropertiesSync = {49 input: {50 ...addProperties,51 native: forbiddenNativeInputIfSync,52 fileUrl: ({value}) => ({contents: [bufferToUint8Array(readFileSync(value))]}),53 filePath: ({value: {file}}) => ({contents: [bufferToUint8Array(readFileSync(file))]}),54 fileNumber: forbiddenIfSync,55 iterable: ({value}) => ({contents: [...value]}),
13 unmodified lines
modified:lib/stdio/handle.js+25 added-5 removed
3 unmodified lines
4import {5 getStdioItemType,6 isRegularUrl,7 isUnknownStdioString,8 isPipeInputObject,9 checkBooleanOption,10 FILE_TYPES,11} from './type.js';12import {getStreamDirection} from './direction.js';13import {normalizeStdioOption} from './stdio-option.js';
69 unmodified lines
83const isInheritedStdinOnly = stdioItems => stdioItems.length === 184 && stdioItems[0].type === 'native'85 && stdioItems[0].value === 'inherit';8685const initializeStdioItem = (value, optionName) => ({86 type: getStdioItemType(value, optionName),87 value,88 optionName,89});87const initializeStdioItem = (value, optionName) => {88 if (isPipeInputObject(value)) {89 return initializePipeInputItem(value, optionName);90 }9192 return {93 type: getStdioItemType(value, optionName),94 value,95 optionName,96 };97};9899// The `{value: 'pipe', input: true}` object form is a native pipe, plus an explicit input direction.100const initializePipeInputItem = ({value, input}, optionName) => {101 checkBooleanOption(input, `${optionName}.input`);102103 return {104 type: 'native',105 value,106 direction: input ? 'input' : undefined,107 optionName,108 };109};110111const validateStdioArray = (stdioItems, isStdioArray, optionName) => {112 if (stdioItems.length === 0) {113 throw new TypeError(`The \`${optionName}\` option must not be an empty array.`);114 }
129 unmodified lines
modified:lib/stdio/stdio-option.js+14 added-3 removed
1import {STANDARD_STREAMS_ALIASES} from '../utils/standard-stream.js';2import {normalizeIpcStdioArray} from '../ipc/array.js';3import {isFullVerbose} from '../verbose/values.js';4import {isPipeInputObject} from './type.js';56// Add support for `stdin`/`stdout`/`stderr` as an alias for `stdio`.7// Also normalize the `stdio` option.8export const normalizeStdioOption = ({stdio, ipc, buffer, ...options}, verboseInfo, isSync) => {
51 unmodified lines
60const normalizeStdioSync = (stdioArray, buffer, verboseInfo) => stdioArray.map((stdioOption, fdNumber) =>61 !buffer[fdNumber]62 && fdNumber !== 063 && !isFullVerbose(verboseInfo, fdNumber)63 && isOutputPipeOnly(stdioOption)64 && isOutputPipeOnly(stdioOption, fdNumber)65 ? 'ignore'66 : stdioOption);6767const isOutputPipeOnly = stdioOption => stdioOption === 'pipe'68 || (Array.isArray(stdioOption) && stdioOption.every(item => item === 'pipe'));68const isOutputPipeOnly = (stdioOption, fdNumber) => isOutputPipe(stdioOption, fdNumber)69 || (Array.isArray(stdioOption) && stdioOption.every(item => isOutputPipe(item, fdNumber)));7071const isOutputPipe = (stdioOption, fdNumber) => stdioOption === 'pipe'72 || isOutputPipeObject(stdioOption, fdNumber);7374const isOutputPipeObject = (stdioOption, fdNumber) => isPipeInputObject(stdioOption)75 && stdioOption.value === 'pipe'76 && (stdioOption.input === undefined || stdioOption.input === false || isFixedOutputPipe(fdNumber, stdioOption.input));7778// On `stdout`/`stderr`, the direction is always output, so `input: true` is ignored and the pipe stays output.79const isFixedOutputPipe = (fdNumber, input) => input === true && (fdNumber === 1 || fdNumber === 2);
modified:lib/stdio/type.js+10 added-1 removed
106 unmodified lines
107108 return isAsyncGenerator(transform) || isAsyncGenerator(final) ? 'asyncGenerator' : 'generator';109};110111const checkBooleanOption = (value, optionName) => {111export const checkBooleanOption = (value, optionName) => {112 if (value !== undefined && typeof value !== 'boolean') {113 throw new TypeError(`The \`${optionName}\` option must use a boolean.`);114 }115};
13 unmodified lines
129 && isFilePathString(value.file);130const FILE_PATH_KEYS = new Set(['file', 'append']);131export const isFilePathString = file => typeof file === 'string';132133// The `{value: 'pipe', input: true}` object form marks an additional file descriptor as input instead of output.134// This is only needed for `'pipe'`/`'overlapped'` on fd3+, whose direction is otherwise ambiguous and defaults to output.135export const isPipeInputObject = value => isPlainObj(value)136 && Object.keys(value).length > 0137 && Object.keys(value).every(key => PIPE_INPUT_KEYS.has(key))138 && NATIVE_PIPE_VALUES.has(value.value);139const PIPE_INPUT_KEYS = new Set(['value', 'input']);140const NATIVE_PIPE_VALUES = new Set(['pipe', 'overlapped']);141142export const isUnknownStdioString = (type, value) => type === 'native'143 && typeof value === 'string'144 && !KNOWN_STDIO_STRINGS.has(value);145const KNOWN_STDIO_STRINGS = new Set(['ipc', 'ignore', 'inherit', 'overlapped', 'pipe']);
37 unmodified lines
modified:test/arguments/fd-options.js+5 added
267 unmodified lines
268 sourceOptions: fullStdio,269 to: 'fd3',270 message: 'must be a writable stream',271});272test('.duplex() "to" option on an output file descriptor suggests the input-pipe syntax', testNodeStream, {273 sourceOptions: fullStdio,274 to: 'fd3',275 message: '{value: \'pipe\', input: true}',276});277test('.pipe() "to" option cannot be "all"', testPipeError, {278 destinationOptions: fullStdio,279 to: 'all',280 message: 'must be a writable stream',
443 unmodified lines
modified:test/convert/duplex.js+7 added-1 removed
22 unmodified lines
23 getReadWriteSubprocess,24} from '../helpers/convert.js';25import {foobarString} from '../helpers/input.js';26import {majorNodeVersion} from '../helpers/node-version.js';27import {prematureClose, fullStdio, fullReadableStdio} from '../helpers/stdio.js';27import {28 getStdio,29 prematureClose,30 fullStdio,31 fullReadableStdio,32} from '../helpers/stdio.js';33import {defaultHighWaterMark} from '../helpers/stream.js';3435setFixtureDirectory();36
44 unmodified lines
81};8283test('.duplex() can use stdin', testWritableDuplexDefault, 0, 'stdin', {});84test('.duplex() can use input stdio[*]', testWritableDuplexDefault, 3, 'fd3', fullReadableStdio());85test('.duplex() can use input stdio[*] with { value: "pipe", input: true }', testWritableDuplexDefault, 3, 'fd3', getStdio(3, {value: 'pipe', input: true}));86test('.duplex() uses stdin by default', testWritableDuplexDefault, 0, undefined, {});8788test('.duplex() abort -> subprocess fail', async t => {89 const subprocess = getReadWriteSubprocess();
121 unmodified lines
modified:test/convert/writable.js+3 added-1 removed
24 unmodified lines
25 foobarBuffer,26 foobarObject,27 foobarObjectString,28} from '../helpers/input.js';29import {prematureClose, fullReadableStdio} from '../helpers/stdio.js';29import {getStdio, prematureClose, fullReadableStdio} from '../helpers/stdio.js';30import {31 throwingGenerator,32 serializeGenerator,33 noopAsyncGenerator,
28 unmodified lines
62};6364test('.writable() can use stdin', testWritableDefault, 0, 'stdin', {});65test('.writable() can use stdio[*]', testWritableDefault, 3, 'fd3', fullReadableStdio());66test('.writable() can use stdio[*] with { value: "pipe", input: true }', testWritableDefault, 3, 'fd3', getStdio(3, {value: 'pipe', input: true}));67test('.writable() can use stdio[*] with [{ value: "pipe", input: true }, "pipe"]', testWritableDefault, 3, 'fd3', getStdio(3, [{value: 'pipe', input: true}, 'pipe']));68test('.writable() uses stdin by default', testWritableDefault, 0, undefined, {});6970test('.writable() hangs until ended', async t => {71 const subprocess = getReadWriteSubprocess();
326 unmodified lines
modified:test/io/max-buffer.js+15 added
265 unmodified lines
266test('do not buffer stdout when `buffer` set to `false`, fd-specific, sync', testNoMaxBufferSync, 1, {stdout: false});267test('do not buffer stderr when `buffer` set to `false`, sync', testNoMaxBufferSync, 2, false);268test('do not buffer stderr when `buffer` set to `false`, fd-specific, sync', testNoMaxBufferSync, 2, {stderr: false});269270const testNoMaxBufferSyncObjectPipe = (t, fdNumber, fdName, stdioOption) => {271 const {isMaxBuffer, stdio} = execaSync('max-buffer.js', [`${fdNumber}`, `${maxBuffer + 1}`], {272 [fdName]: stdioOption,273 buffer: false,274 maxBuffer,275 });276 t.false(isMaxBuffer);277 t.is(stdio[fdNumber], undefined);278};279280test('do not buffer stdout object pipe when `buffer` set to `false`, sync', testNoMaxBufferSyncObjectPipe, 1, 'stdout', {value: 'pipe'});281test('do not buffer stdout object pipe with input false when `buffer` set to `false`, sync', testNoMaxBufferSyncObjectPipe, 1, 'stdout', {value: 'pipe', input: false});282test('do not buffer stdout object pipe with input true when `buffer` set to `false`, sync', testNoMaxBufferSyncObjectPipe, 1, 'stdout', {value: 'pipe', input: true});283test('do not buffer stderr object pipe with input true when `buffer` set to `false`, sync', testNoMaxBufferSyncObjectPipe, 2, 'stderr', {value: 'pipe', input: true});284285const testMaxBufferAbort = async (t, fdNumber) => {286 const subprocess = getMaxBufferSubprocess(execa, fdNumber);287 const [{isMaxBuffer, shortMessage}] = await Promise.all([288 t.throwsAsync(subprocess, maxBufferMessage),
35 unmodified lines
modified:test/stdio/direction.js+56 added
47 unmodified lines
48};4950test('stdin ambiguous direction is influenced by other values', testAmbiguousMultiple, 0);51test('stdio[*] ambiguous direction is influenced by other values', testAmbiguousMultiple, 3);5253const testDirectionInputPipe = async (t, stdioOption) => {54 const subprocess = execa('stdin-fd.js', ['3'], getStdio(3, stdioOption));55 subprocess.stdio[3].end(foobarString);56 const {stdout} = await subprocess;57 t.is(stdout, foobarString);58};5960test('stdio[*] { value: "pipe", input: true } sets the direction to input', testDirectionInputPipe, {value: 'pipe', input: true});61test('stdio[*] { value: "overlapped", input: true } sets the direction to input', testDirectionInputPipe, {value: 'overlapped', input: true});6263test('stdio[*] { value: "pipe", input: true } cannot be used in sync mode', t => {64 t.throws(() => {65 execaSync('empty.js', getStdio(3, {value: 'pipe', input: true}));66 }, {message: /can be an input pipe with synchronous methods/});67});6869test('stdio[*] { value: "pipe", input: true } cannot be used in sync mode with buffer false', t => {70 t.throws(() => {71 execaSync('empty.js', {...getStdio(3, {value: 'pipe', input: true}), buffer: false});72 }, {message: /can be an input pipe with synchronous methods/});73});7475const testDirectionOutputPipe = async (t, stdioOption, execaMethod) => {76 const {stdio} = await execaMethod('noop-fd.js', ['3', foobarString], getStdio(3, stdioOption));77 t.is(stdio[3], foobarString);78};7980test('stdio[*] { value: "pipe" } keeps the default output direction', testDirectionOutputPipe, {value: 'pipe'}, execa);81test('stdio[*] { value: "pipe" } keeps the default output direction - sync', testDirectionOutputPipe, {value: 'pipe'}, execaSync);82test('stdio[*] { value: "pipe", input: false } keeps the default output direction', testDirectionOutputPipe, {value: 'pipe', input: false}, execa);83test('stdio[*] { value: "pipe", input: false } keeps the default output direction - sync', testDirectionOutputPipe, {value: 'pipe', input: false}, execaSync);8485const testDirectionConflict = (t, execaMethod) => {86 t.throws(() => {87 execaMethod('empty.js', getStdio(3, [{value: 'pipe', input: true}, 1]));88 }, {message: /readable and writable/});89};9091test('Cannot pass { value: "pipe", input: true } with a writable value to stdio[*]', testDirectionConflict, execa);92test('Cannot pass { value: "pipe", input: true } with a writable value to stdio[*] - sync', testDirectionConflict, execaSync);9394const testInputBoolean = (t, execaMethod) => {95 t.throws(() => {96 execaMethod('empty.js', getStdio(3, {value: 'pipe', input: 'yes'}));97 }, {message: /`stdio\[3\]\.input` option must use a boolean/});98};99100test('stdio[*].input must be a boolean', testInputBoolean, execa);101test('stdio[*].input must be a boolean - sync', testInputBoolean, execaSync);102103test('stdout.input must be a boolean with buffer false - sync', t => {104 t.throws(() => {105 execaSync('empty.js', {stdout: {value: 'pipe', input: 'yes'}, buffer: false});106 }, {message: /`stdout\.input` option must use a boolean/});107});
modified:test-d/convert/writable.test-d.ts+3 added
18 unmodified lines
19expectError(subprocess.writable({preserveNewlines: false}));2021expectError(subprocess.writable('stdin'));22expectError(subprocess.writable({other: 'stdin'}));2324const inputPipeSubprocess = execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', {value: 'pipe', input: true}]});25inputPipeSubprocess.writable({to: 'fd3'});
modified:test-d/return/result-stdio.test-d.ts+26 added
109 unmodified lines
110111const inputFd3Result = await execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', ['pipe', new Readable()]]});112expectType<undefined>(inputFd3Result.stdio[3]);113114const inputPipeFd3Result = await execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', {value: 'pipe', input: true}]});115expectType<undefined>(inputPipeFd3Result.stdio[3]);116117const outputPipeFd3Result = await execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', {value: 'pipe'}]});118expectType<string>(outputPipeFd3Result.stdio[3]);119120const input = true as boolean;121const booleanInputPipeFd3Result = await execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', {value: 'pipe', input}]});122expectType<string | undefined>(booleanInputPipeFd3Result.stdio[3]);123124const optionalInputPipe: {readonly value: 'pipe'; readonly input?: boolean} = {value: 'pipe', input};125const optionalInputPipeFd3Result = await execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', optionalInputPipe]});126expectType<string | undefined>(optionalInputPipeFd3Result.stdio[3]);127128const optionalTrueInputPipe: {readonly value: 'pipe'; readonly input?: true} = {value: 'pipe', input: true};129const optionalTrueInputPipeFd3Result = await execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', optionalTrueInputPipe]});130expectType<string | undefined>(optionalTrueInputPipeFd3Result.stdio[3]);131132const stdoutInputPipeResult = await execa('unicorns', {stdout: {value: 'pipe', input: true}});133expectType<string>(stdoutInputPipeResult.stdout);134expectType<string>(stdoutInputPipeResult.stdio[1]);135136const stderrInputPipeResult = await execa('unicorns', {stderr: {value: 'pipe', input: true}});137expectType<string>(stderrInputPipeResult.stderr);138expectType<string>(stderrInputPipeResult.stdio[2]);139140const outputFd3Result = await execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', ['pipe', new Writable()]]});141expectType<string>(outputFd3Result.stdio[3]);142143const bufferFd3Result = await execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', 'pipe'], encoding: 'buffer'});
7 unmodified lines
added:test-d/stdio/option/input-pipe.test-d.ts+49 added
1import {expectError, expectAssignable} from 'tsd';2import {3 execa,4 execaSync,5 type StdinOption,6 type StdinSyncOption,7 type StdoutStderrOption,8 type StdoutStderrSyncOption,9} from '../../../index.js';1011const inputPipe = {value: 'pipe', input: true} as const;12const input = true as boolean;13const booleanInputPipe = {value: 'pipe', input} as const;1415await execa('unicorns', {stdin: inputPipe});16execaSync('unicorns', {stdin: inputPipe});17await execa('unicorns', {stdout: inputPipe});18execaSync('unicorns', {stdout: inputPipe});19await execa('unicorns', {stderr: inputPipe});20execaSync('unicorns', {stderr: inputPipe});2122await execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', inputPipe]});23expectError(execaSync('unicorns', {stdio: ['pipe', 'pipe', 'pipe', inputPipe]}));24await execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', booleanInputPipe]});25expectError(execaSync('unicorns', {stdio: ['pipe', 'pipe', 'pipe', booleanInputPipe]}));2627await execa('unicorns', {stdin: {value: 'pipe'}});28await execa('unicorns', {stdin: {value: 'overlapped', input: true}});29expectError(execaSync('unicorns', {stdin: {value: 'overlapped', input: true}}));3031expectError(await execa('unicorns', {stdin: {value: 'other', input: true}}));32expectError(await execa('unicorns', {stdin: {value: 'pipe', input: 'true'}}));3334expectAssignable<StdinOption>(inputPipe);35expectAssignable<StdinOption>(booleanInputPipe);36expectAssignable<StdinSyncOption>(inputPipe);37expectAssignable<StdinSyncOption>(booleanInputPipe);38expectAssignable<StdoutStderrOption>(inputPipe);39expectAssignable<StdoutStderrOption>(booleanInputPipe);40expectAssignable<StdoutStderrSyncOption>(inputPipe);41expectAssignable<StdoutStderrSyncOption>(booleanInputPipe);42expectAssignable<StdinOption>([inputPipe]);43expectAssignable<StdinOption>([booleanInputPipe]);44expectAssignable<StdinSyncOption>([inputPipe]);45expectAssignable<StdinSyncOption>([booleanInputPipe]);46expectAssignable<StdoutStderrOption>([inputPipe]);47expectAssignable<StdoutStderrOption>([booleanInputPipe]);48expectAssignable<StdoutStderrSyncOption>([inputPipe]);49expectAssignable<StdoutStderrSyncOption>([booleanInputPipe]);
modified:test-d/subprocess/stdio.test-d.ts+26 added
37 unmodified lines
38expectType<Readable>(multipleStdoutSubprocess.stderr);39expectType<Readable>(multipleStdoutSubprocess.stdio[2]);40expectType<Readable>(multipleStdoutSubprocess.all);41expectError(multipleStdoutSubprocess.stdio[3].destroy());4243const inputPipeSubprocess = execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', {value: 'pipe', input: true}]});44expectType<Writable>(inputPipeSubprocess.stdio[3]);4546const outputPipeSubprocess = execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', {value: 'pipe'}]});47expectType<Readable>(outputPipeSubprocess.stdio[3]);4849const input = true as boolean;50const booleanInputPipeSubprocess = execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', {value: 'pipe', input}]});51expectType<Readable | Writable>(booleanInputPipeSubprocess.stdio[3]);5253const optionalInputPipe: {readonly value: 'pipe'; readonly input?: boolean} = {value: 'pipe', input};54const optionalInputPipeSubprocess = execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', optionalInputPipe]});55expectType<Readable | Writable>(optionalInputPipeSubprocess.stdio[3]);5657const optionalTrueInputPipe: {readonly value: 'pipe'; readonly input?: true} = {value: 'pipe', input: true};58const optionalTrueInputPipeSubprocess = execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', optionalTrueInputPipe]});59expectType<Readable | Writable>(optionalTrueInputPipeSubprocess.stdio[3]);6061const stdoutInputPipeSubprocess = execa('unicorns', {stdout: {value: 'pipe', input: true}});62expectType<Readable>(stdoutInputPipeSubprocess.stdout);63expectType<Readable>(stdoutInputPipeSubprocess.stdio[1]);6465const stderrInputPipeSubprocess = execa('unicorns', {stderr: {value: 'pipe', input: true}});66expectType<Readable>(stderrInputPipeSubprocess.stderr);67expectType<Readable>(stderrInputPipeSubprocess.stdio[2]);
modified:types/return/ignore.d.ts+7 added-3 removed
8 unmodified lines
9 FdNumber extends string,10 OptionsType extends CommonOptions,11> = FdSpecificOption<OptionsType['buffer'], FdNumber> extends false12 ? true13 : IsInputFd<FdNumber, OptionsType> extends true14 ? true15 : IgnoresSubprocessOutput<FdNumber, OptionsType>;13 : IgnoresResultOutputDirection<IsInputFd<FdNumber, OptionsType>, FdNumber, OptionsType>;1415type IgnoresResultOutputDirection<16 IsInput extends boolean,17 FdNumber extends string,18 OptionsType extends CommonOptions,19> = IsInput extends true ? true : IgnoresSubprocessOutput<FdNumber, OptionsType>;2021// Whether `subprocess.stdout|stderr|all` is `undefined|null`22export type IgnoresSubprocessOutput<23 FdNumber extends string,24 OptionsType extends CommonOptions,
8 unmodified lines
modified:types/stdio/direction.d.ts+33 added-2 removed
1import type {CommonOptions} from '../arguments/options.js';2import type {Intersects} from '../utils.js';3import type {StdioSingleOptionItems, InputStdioOption} from './type.js';3import type {StdioSingleOptionItems, InputStdioOption, NativePipeStdioOption} from './type.js';4import type {FdStdioArrayOption} from './option.js';56type AnyNativePipeStdioOption = NativePipeStdioOption<boolean, false>;78type InputNativePipeStdioOption = AnyNativePipeStdioOption & {9 readonly input: true;10};1112type NativePipeInputValue<StdioOptionType> = StdioOptionType extends AnyNativePipeStdioOption13 ? NativePipeInputProperty<StdioOptionType>14 : never;1516type NativePipeInputProperty<StdioOptionType> = 'input' extends keyof StdioOptionType17 ? StdioOptionType extends {readonly input?: infer Input} ? Input : never18 : never;1920// Whether `result.stdio[FdNumber]` is an input stream21export type IsInputFd<22 FdNumber extends string,23 OptionsType extends CommonOptions,24> = FdNumber extends '0'25 ? true12 : Intersects<StdioSingleOptionItems<FdStdioArrayOption<FdNumber, OptionsType>>, InputStdioOption>;26 : IsInputFdOption<27 FdNumber,28 StdioSingleOptionItems<FdStdioArrayOption<FdNumber, OptionsType>>29 >;3031type IsInputFdOption<32 FdNumber extends string,33 StdioOptionType,34> = Intersects<35 StdioOptionType,36 FdNumber extends '1' | '2' ? InputStdioOption : InputStdioOption | InputNativePipeStdioOption37> extends true38 ? true39 : FdNumber extends '1' | '2'40 ? false41 : true extends NativePipeInputValue<StdioOptionType>42 ? boolean43 : false;4445export {};
modified:types/stdio/type.d.ts+9 added-1 removed
37 unmodified lines
38 | Unless<And<And<Not<IsSync>, IsArray>, IsExtra>, 'inherit'>39 | Unless<IsArray, 'ignore'>40 | Unless<IsSync, 'overlapped'>;4142export type NativePipeStdioOption<43 IsSync extends boolean,44 IsExtra extends boolean,45> = {46 readonly value: 'pipe' | Unless<IsSync, 'overlapped'>;47 readonly input?: Unless<And<IsSync, IsExtra>, boolean> | false;48};4950// Values available in both `options.stdin|stdio` and `options.stdout|stderr|stdio`51type CommonStdioOption<52 IsSync extends boolean,53 IsExtra extends boolean,54 IsArray extends boolean,55> =48 SimpleStdioOption<IsSync, IsExtra, IsArray> | URL | GeneratorTransform<IsSync> | GeneratorTransformFull<IsSync> | Unless<And<Not<IsSync>, IsArray>, 3 | 4 | 5 | 6 | 7 | 8 | 9> | Unless<IsSync, DuplexTransform | WebTransform | TransformStream> | {readonly file: string; readonly append?: boolean};56 SimpleStdioOption<IsSync, IsExtra, IsArray> | URL | GeneratorTransform<IsSync> | GeneratorTransformFull<IsSync> | Unless<And<Not<IsSync>, IsArray>, 3 | 4 | 5 | 6 | 7 | 8 | 9> | Unless<IsSync, DuplexTransform | WebTransform | TransformStream> | NativePipeStdioOption<IsSync, IsExtra> | {readonly file: string; readonly append?: boolean};5758// Synchronous iterables excluding strings, Uint8Arrays and Arrays59type IterableObject<IsArray extends boolean> = Iterable<unknown>60 & object
111 unmodified lines