Remove the old `stdio: [..., 'ipc']` syntax (#1245)
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 3ced394 · Browse files · 14 files·+43 added−88 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
14 files+43 added−88 removed
- tests:+22 added−52 removed
- other:+21 added−36 removed
Provenance
- Commit
dcf611c- Tree
727abb2- Author
Sindre Sorhus <sindresorhus@gmail.com>- Committer
GitHub <noreply@github.com>- Parent
3ced394
14 files changed+43 added−88 removed
modified:lib/ipc/array.js+1 added-1 removed
12234// The `ipc` option adds an `ipc` item to the `stdio` optionexport const normalizeIpcStdioArray = (stdioArray, ipc) => ipc && !stdioArray.includes('ipc')export const normalizeIpcStdioArray = (stdioArray, ipc) => ipc ? [...stdioArray, 'ipc'] : stdioArray;modified:lib/stdio/handle-sync.js+1 added-1 removed
9 unmodified lines1011121314141516171839 unmodified lines9 unmodified lines throwInvalidSyncValue(optionName, TYPE_TO_MESSAGE[type]);};
const forbiddenNativeIfSync = ({optionName, value}) => { if (value === 'ipc' || value === 'overlapped') { if (value === 'overlapped') { throwInvalidSyncValue(optionName, `"${value}"`); }
return {};39 unmodified linesmodified:lib/stdio/handle.js+2 added-2 removed
102 unmodified lines103 }104 }105 };106 107-// Using those `stdio` values together with others for the same stream does not make sense, so we make it fail.107+// Using the `ignore` value together with others for the same stream does not make sense, so we make it fail.108 // However, we do allow it if the array has a single item.109-const INVALID_STDIO_ARRAY_OPTIONS = new Set(['ignore', 'ipc']);109+const INVALID_STDIO_ARRAY_OPTIONS = new Set(['ignore']);110 111 const validateStreams = stdioItems => {112 for (const stdioItem of stdioItems) {113 validateFileStdio(stdioItem);110 unmodified linesmodified:lib/stdio/stdio-option.js+8 added
4 unmodified lines567891011121314151617181920212223242543 unmodified lines4 unmodified lines// Add support for `stdin`/`stdout`/`stderr` as an alias for `stdio`.// Also normalize the `stdio` option.export const normalizeStdioOption = ({stdio, ipc, buffer, ...options}, verboseInfo, isSync) => { const stdioArray = getStdioArray(stdio, options).map((stdioOption, fdNumber) => addDefaultValue(stdioOption, fdNumber)); validateIpcStdioOption(stdioArray); return isSync ? normalizeStdioSync(stdioArray, buffer, verboseInfo) : normalizeIpcStdioArray(stdioArray, ipc);};
// The `stdio: 'ipc'` value (raw `child_process` syntax) was replaced by the `ipc: true` optionconst validateIpcStdioOption = stdioArray => { if (stdioArray.some(stdioOption => Array.isArray(stdioOption) ? stdioOption.includes('ipc') : stdioOption === 'ipc')) { throw new Error('The `ipc: true` option must be used instead of `stdio: \'ipc\'`.'); }};
const getStdioArray = (stdio, options) => { if (stdio === undefined) { return STANDARD_STREAMS_ALIASES.map(alias => options[alias]); }43 unmodified linesmodified:test/arguments/fd-options.js-21 removed
617 unmodified lines618 sourceOptions: {stdin: 'inherit'},619 message: ['stdin', '\'inherit\''],620 writable: true,621 });622-test('Cannot set "stdout" option to "ipc" to use .pipe()', testPipeError, {623- sourceOptions: {stdout: 'ipc'},624- message: ['stdout', '\'ipc\''],625-});626-test('Cannot set "stdout" option to "ipc" to use .duplex()', testNodeStream, {627- sourceOptions: {stdout: 'ipc'},628- message: ['stdout', '\'ipc\''],629-});630-test('Cannot set "stdout" option to "ipc" to use .iterable()', testIterable, {631- sourceOptions: {stdout: 'ipc'},632- message: ['stdout', '\'ipc\''],633-});634-test('Cannot set "stdin" option to "ipc" to use .pipe()', testPipeError, {635- destinationOptions: {stdin: 'ipc'},636- message: ['stdin', '\'ipc\''],637-});638-test('Cannot set "stdin" option to "ipc" to use .duplex()', testNodeStream, {639- sourceOptions: {stdin: 'ipc'},640- message: ['stdin', '\'ipc\''],641- writable: true,642-});622 test('Cannot set "stdout" option to file descriptors to use .pipe()', testPipeError, {623 sourceOptions: {stdout: 1},624 message: ['stdout', '1'],625 });93 unmodified linesmodified:test/ipc/validation.js-6 removed
1 import test from 'ava';2 import {execa} from '../../index.js';3 import {setFixtureDirectory} from '../helpers/fixtures-directory.js';4 import {foobarString} from '../helpers/input.js';5-import {getStdio} from '../helpers/stdio.js';5 6 setFixtureDirectory();7 9-const stdioIpc = getStdio(3, 'ipc');10-8 const testRequiredIpcSubprocess = async (t, methodName, options) => {9 const subprocess = execa('empty.js', options);10 const {message} = await t.throws(() => subprocess[methodName]());11 t.true(message.includes(`subprocess.${methodName}() can only be used`));1 unmodified line13 };14 15 test('Cannot use subprocess.sendMessage() without ipc option', testRequiredIpcSubprocess, 'sendMessage', {});16 test('Cannot use subprocess.sendMessage() with ipc: false', testRequiredIpcSubprocess, 'sendMessage', {ipc: false});20-test('Cannot use subprocess.sendMessage() with stdio: [..., "ipc"]', testRequiredIpcSubprocess, 'sendMessage', stdioIpc);17 test('Cannot use subprocess.getOneMessage() without ipc option', testRequiredIpcSubprocess, 'getOneMessage', {});18 test('Cannot use subprocess.getOneMessage() with ipc: false', testRequiredIpcSubprocess, 'getOneMessage', {ipc: false});23-test('Cannot use subprocess.getOneMessage() with stdio: [..., "ipc"]', testRequiredIpcSubprocess, 'getOneMessage', stdioIpc);19 test('Cannot use subprocess.getEachMessage() without ipc option', testRequiredIpcSubprocess, 'getEachMessage', {});20 test('Cannot use subprocess.getEachMessage() with ipc: false', testRequiredIpcSubprocess, 'getEachMessage', {ipc: false});26-test('Cannot use subprocess.getEachMessage() with stdio: [..., "ipc"]', testRequiredIpcSubprocess, 'getEachMessage', stdioIpc);21 22 const testRequiredIpcExports = async (t, methodName, options) => {23 const {message} = await t.throwsAsync(execa('ipc-any.js', [methodName], options));24 t.true(message.includes(`${methodName}() can only be used`));70 unmodified linesmodified:test/methods/node.js-1 removed
250 unmodified lines251 test('The "node" option adds an ipc channel', testIpc, runWithNodeOption, {});252 test('The "ipc" option adds an ipc channel', testIpc, runWithIpc, {});253 test('The "ipc" option works with "stdio: \'pipe\'"', testIpc, runWithIpc, {stdio: 'pipe'});254 test('The "ipc" option works with "stdio: [\'pipe\', \'pipe\', \'pipe\']"', testIpc, runWithIpc, {stdio: ['pipe', 'pipe', 'pipe']});255-test('The "ipc" option works with "stdio: [\'pipe\', \'pipe\', \'pipe\', \'ipc\']"', testIpc, runWithIpc, {stdio: ['pipe', 'pipe', 'pipe', 'ipc']});255 test('The "ipc" option works with "stdout: \'pipe\'"', testIpc, runWithIpc, {stdout: 'pipe'});256 257 const NO_SEND_MESSAGE = 'sendMessage() can only be used';258 43 unmodified linesmodified:test/stdio/handle-invalid.js+22 added-12 removed
25 unmodified lines26272829303132333031323311 unmodified lines4546474853545556575859604950515253545556575859606162636465666768697025 unmodified lines }); t.true(message.includes(`cannot be "${stdioOption}" with synchronous methods`));};
test('stdin cannot be "ipc", sync', testInvalidValueSync, 0, 'ipc');test('stdout cannot be "ipc", sync', testInvalidValueSync, 1, 'ipc');test('stderr cannot be "ipc", sync', testInvalidValueSync, 2, 'ipc');test('stdio[*] cannot be "ipc", sync', testInvalidValueSync, 3, 'ipc');test('stdin cannot be "overlapped", sync', testInvalidValueSync, 0, 'overlapped');test('stdout cannot be "overlapped", sync', testInvalidValueSync, 1, 'overlapped');test('stderr cannot be "overlapped", sync', testInvalidValueSync, 2, 'overlapped');test('stdio[*] cannot be "overlapped", sync', testInvalidValueSync, 3, 'overlapped');11 unmodified linestest('Cannot pass "ignore" and another value to stdin - sync', testInvalidArrayValue, 'ignore', 0, execaSync);test('Cannot pass "ignore" and another value to stdout - sync', testInvalidArrayValue, 'ignore', 1, execaSync);test('Cannot pass "ignore" and another value to stderr - sync', testInvalidArrayValue, 'ignore', 2, execaSync);test('Cannot pass "ignore" and another value to stdio[*] - sync', testInvalidArrayValue, 'ignore', 3, execaSync);test('Cannot pass "ipc" and another value to stdin', testInvalidArrayValue, 'ipc', 0, execa);test('Cannot pass "ipc" and another value to stdout', testInvalidArrayValue, 'ipc', 1, execa);test('Cannot pass "ipc" and another value to stderr', testInvalidArrayValue, 'ipc', 2, execa);test('Cannot pass "ipc" and another value to stdio[*]', testInvalidArrayValue, 'ipc', 3, execa);test('Cannot pass "ipc" and another value to stdin - sync', testInvalidArrayValue, 'ipc', 0, execaSync);test('Cannot pass "ipc" and another value to stdout - sync', testInvalidArrayValue, 'ipc', 1, execaSync);test('Cannot pass "ipc" and another value to stderr - sync', testInvalidArrayValue, 'ipc', 2, execaSync);test('Cannot pass "ipc" and another value to stdio[*] - sync', testInvalidArrayValue, 'ipc', 3, execaSync);
// The `stdio: 'ipc'` value (raw `child_process` syntax) was replaced by the `ipc: true` optionconst testIpcStdioOption = (t, fdNumber, stdioOption, execaMethod) => { t.throws(() => { execaMethod('empty.js', getStdio(fdNumber, stdioOption)); }, {message: /The `ipc: true` option must be used instead/});};
test('stdin cannot be "ipc"', testIpcStdioOption, 0, 'ipc', execa);test('stdout cannot be "ipc"', testIpcStdioOption, 1, 'ipc', execa);test('stderr cannot be "ipc"', testIpcStdioOption, 2, 'ipc', execa);test('stdio[*] cannot be "ipc"', testIpcStdioOption, 3, 'ipc', execa);test('stdin cannot be "ipc" - sync', testIpcStdioOption, 0, 'ipc', execaSync);test('stdout cannot be "ipc" - sync', testIpcStdioOption, 1, 'ipc', execaSync);test('stderr cannot be "ipc" - sync', testIpcStdioOption, 2, 'ipc', execaSync);test('stdio[*] cannot be "ipc" - sync', testIpcStdioOption, 3, 'ipc', execaSync);test('stdio cannot be "ipc"', testIpcStdioOption, 'stdio', 'ipc', execa);test('stdio cannot be "ipc" - sync', testIpcStdioOption, 'stdio', 'ipc', execaSync);test('stdio[*] cannot be ["ipc"]', testIpcStdioOption, 3, ['ipc'], execa);test('stdio[*] cannot be ["ipc"] - sync', testIpcStdioOption, 3, ['ipc'], execaSync);test('Cannot pass "ipc" and another value to stdio[*]', testIpcStdioOption, 3, ['pipe', 'ipc'], execa);test('Cannot pass "ipc" and another value to stdio[*] - sync', testIpcStdioOption, 3, ['pipe', 'ipc'], execaSync);modified:test/stdio/handle-options.js-8 removed
12 unmodified lines13 14 test('stdin can be "ignore"', testNoPipeOption, 'ignore', 0);15 test('stdin can be ["ignore"]', testNoPipeOption, ['ignore'], 0);16 test('stdin can be ["ignore", "ignore"]', testNoPipeOption, ['ignore', 'ignore'], 0);17-test('stdin can be "ipc"', testNoPipeOption, 'ipc', 0);18-test('stdin can be ["ipc"]', testNoPipeOption, ['ipc'], 0);17 test('stdin can be "inherit"', testNoPipeOption, 'inherit', 0);18 test('stdin can be ["inherit"]', testNoPipeOption, ['inherit'], 0);19 test('stdin can be 0', testNoPipeOption, 0, 0);20 test('stdin can be [0]', testNoPipeOption, [0], 0);21 test('stdout can be "ignore"', testNoPipeOption, 'ignore', 1);22 test('stdout can be ["ignore"]', testNoPipeOption, ['ignore'], 1);23 test('stdout can be ["ignore", "ignore"]', testNoPipeOption, ['ignore', 'ignore'], 1);26-test('stdout can be "ipc"', testNoPipeOption, 'ipc', 1);27-test('stdout can be ["ipc"]', testNoPipeOption, ['ipc'], 1);24 test('stdout can be "inherit"', testNoPipeOption, 'inherit', 1);25 test('stdout can be ["inherit"]', testNoPipeOption, ['inherit'], 1);26 test('stdout can be 1', testNoPipeOption, 1, 1);27 test('stdout can be [1]', testNoPipeOption, [1], 1);28 test('stderr can be "ignore"', testNoPipeOption, 'ignore', 2);29 test('stderr can be ["ignore"]', testNoPipeOption, ['ignore'], 2);30 test('stderr can be ["ignore", "ignore"]', testNoPipeOption, ['ignore', 'ignore'], 2);35-test('stderr can be "ipc"', testNoPipeOption, 'ipc', 2);36-test('stderr can be ["ipc"]', testNoPipeOption, ['ipc'], 2);31 test('stderr can be "inherit"', testNoPipeOption, 'inherit', 2);32 test('stderr can be ["inherit"]', testNoPipeOption, ['inherit'], 2);33 test('stderr can be 2', testNoPipeOption, 2, 2);34 test('stderr can be [2]', testNoPipeOption, [2], 2);35 test('stdio[*] can be "ignore"', testNoPipeOption, 'ignore', 3);36 test('stdio[*] can be ["ignore"]', testNoPipeOption, ['ignore'], 3);37 test('stdio[*] can be ["ignore", "ignore"]', testNoPipeOption, ['ignore', 'ignore'], 3);44-test('stdio[*] can be "ipc"', testNoPipeOption, 'ipc', 3);45-test('stdio[*] can be ["ipc"]', testNoPipeOption, ['ipc'], 3);38 test('stdio[*] can be "inherit"', testNoPipeOption, 'inherit', 3);39 test('stdio[*] can be ["inherit"]', testNoPipeOption, ['inherit'], 3);40 test('stdio[*] can be 3', testNoPipeOption, 3, 3);41 test('stdio[*] can be [3]', testNoPipeOption, [3], 3);modified:test/transform/encoding-ignored.js-4 removed
28 unmodified lines29 const base64Options = {encoding: 'base64'};30 const linesOptions = {lines: true};31 test('Is ignored with other encodings and "ignore"', testIgnoredEncoding, 'ignore', true, base64Options, execa);32 test('Is ignored with other encodings and ["ignore"]', testIgnoredEncoding, ['ignore'], true, base64Options, execa);33-test('Is ignored with other encodings and "ipc"', testIgnoredEncoding, 'ipc', true, base64Options, execa);34-test('Is ignored with other encodings and ["ipc"]', testIgnoredEncoding, ['ipc'], true, base64Options, execa);33 test('Is ignored with other encodings and "inherit"', testIgnoredEncoding, 'inherit', true, base64Options, execa);34 test('Is ignored with other encodings and ["inherit"]', testIgnoredEncoding, ['inherit'], true, base64Options, execa);35 test('Is ignored with other encodings and 1', testIgnoredEncoding, 1, true, base64Options, execa);36 test('Is ignored with other encodings and [1]', testIgnoredEncoding, [1], true, base64Options, execa);7 unmodified lines44 test('Is not ignored with other encodings and undefined', testIgnoredEncoding, undefined, false, base64Options, execa);45 test('Is not ignored with other encodings and null', testIgnoredEncoding, null, false, base64Options, execa);46 test('Is ignored with "lines: true" and "ignore"', testIgnoredEncoding, 'ignore', true, linesOptions, execa);47 test('Is ignored with "lines: true" and ["ignore"]', testIgnoredEncoding, ['ignore'], true, linesOptions, execa);50-test('Is ignored with "lines: true" and "ipc"', testIgnoredEncoding, 'ipc', true, linesOptions, execa);51-test('Is ignored with "lines: true" and ["ipc"]', testIgnoredEncoding, ['ipc'], true, linesOptions, execa);48 test('Is ignored with "lines: true" and "inherit"', testIgnoredEncoding, 'inherit', true, linesOptions, execa);49 test('Is ignored with "lines: true" and ["inherit"]', testIgnoredEncoding, ['inherit'], true, linesOptions, execa);50 test('Is ignored with "lines: true" and 1', testIgnoredEncoding, 1, true, linesOptions, execa);51 test('Is ignored with "lines: true" and [1]', testIgnoredEncoding, [1], true, linesOptions, execa);37 unmodified linesmodified:test-d/return/ignore-other.test-d.ts-20 removed
55 unmodified lines56 expectType<string>(inheritStderrErrorSync.stdout);57 expectType<undefined>(inheritStderrErrorSync.stderr);58 expectType<string>(inheritStderrErrorSync.all);59 60-const ipcStdoutResult = await execa('unicorns', {stdout: 'ipc', all: true});61-expectType<undefined>(ipcStdoutResult.stdout);62-expectType<string>(ipcStdoutResult.stderr);63-expectType<string>(ipcStdoutResult.all);64-65-const ipcStderrResult = await execa('unicorns', {stderr: 'ipc', all: true});66-expectType<string>(ipcStderrResult.stdout);67-expectType<undefined>(ipcStderrResult.stderr);68-expectType<string>(ipcStderrResult.all);69-70-const ipcStdoutError = new Error('.') as ExecaError<{stdout: 'ipc'; all: true}>;71-expectType<undefined>(ipcStdoutError.stdout);72-expectType<string>(ipcStdoutError.stderr);73-expectType<string>(ipcStdoutError.all);74-75-const ipcStderrError = new Error('.') as ExecaError<{stderr: 'ipc'; all: true}>;76-expectType<string>(ipcStderrError.stdout);77-expectType<undefined>(ipcStderrError.stderr);78-expectType<string>(ipcStderrError.all);79-60 const streamStdoutResult = await execa('unicorns', {stdout: process.stdout, all: true});61 expectType<undefined>(streamStdoutResult.stdout);62 expectType<string>(streamStdoutResult.stderr);63 expectType<string>(streamStdoutResult.all);75 unmodified linesmodified:test-d/stdio/option/ipc.test-d.ts+8 added-7 removed
1-import {expectError, expectAssignable, expectNotAssignable} from 'tsd';1+import {expectError, expectNotAssignable} from 'tsd';2 import {3 execa,4 execaSync,5 type StdinOption,1 unmodified line7 type StdoutStderrOption,8 type StdoutStderrSyncOption,9 } from '../../../index.js';10 11-await execa('unicorns', {stdin: 'ipc'});11+// The `stdio: 'ipc'` value (raw `child_process` syntax) was replaced by the `ipc: true` option12+expectError(await execa('unicorns', {stdin: 'ipc'}));13 expectError(execaSync('unicorns', {stdin: 'ipc'}));14 expectError(await execa('unicorns', {stdin: ['ipc']}));15 expectError(execaSync('unicorns', {stdin: ['ipc']}));16 16-await execa('unicorns', {stdout: 'ipc'});17+expectError(await execa('unicorns', {stdout: 'ipc'}));18 expectError(execaSync('unicorns', {stdout: 'ipc'}));19 expectError(await execa('unicorns', {stdout: ['ipc']}));20 expectError(execaSync('unicorns', {stdout: ['ipc']}));21 21-await execa('unicorns', {stderr: 'ipc'});22+expectError(await execa('unicorns', {stderr: 'ipc'}));23 expectError(execaSync('unicorns', {stderr: 'ipc'}));24 expectError(await execa('unicorns', {stderr: ['ipc']}));25 expectError(execaSync('unicorns', {stderr: ['ipc']}));26 27 expectError(await execa('unicorns', {stdio: 'ipc'}));28 expectError(execaSync('unicorns', {stdio: 'ipc'}));29 29-await execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', 'ipc']});30+expectError(await execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', 'ipc']}));31 expectError(execaSync('unicorns', {stdio: ['pipe', 'pipe', 'pipe', 'ipc']}));32 expectError(await execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', ['ipc']]}));33 expectError(execaSync('unicorns', {stdio: ['pipe', 'pipe', 'pipe', ['ipc']]}));34 34-expectAssignable<StdinOption>('ipc');35+expectNotAssignable<StdinOption>('ipc');36 expectNotAssignable<StdinSyncOption>('ipc');37 expectNotAssignable<StdinOption>(['ipc']);38 expectNotAssignable<StdinSyncOption>(['ipc']);39 39-expectAssignable<StdoutStderrOption>('ipc');40+expectNotAssignable<StdoutStderrOption>('ipc');41 expectNotAssignable<StdoutStderrSyncOption>('ipc');42 expectNotAssignable<StdoutStderrOption>(['ipc']);43 expectNotAssignable<StdoutStderrSyncOption>(['ipc']);modified:types/stdio/type.d.ts+1 added-3 removed
1 unmodified line2 import type {ReadableStream, WritableStream, TransformStream} from 'node:stream/web';3 import type {4 Not,5 And,6- Or,6 Unless,7 AndUnless,8 } from '../utils.js';9 import type {10 unmodified lines20 // When `options.stdin|stdout|stderr|stdio` is set to one of those values, no stream is created21 export type NoStreamStdioOption<FdNumber extends string> =22 | 'ignore'23 | 'inherit'25- | 'ipc'24 | number25 | Readable26 | Writable27 | Unless<IsStandardStream<FdNumber>, undefined>16 unmodified lines44 IsSync extends boolean,45 IsExtra extends boolean,46 IsArray extends boolean,47 > =50- SimpleStdioOption<IsSync, IsExtra, IsArray> | URL | GeneratorTransform<IsSync> | GeneratorTransformFull<IsSync> | Unless<And<Not<IsSync>, IsArray>, 3 | 4 | 5 | 6 | 7 | 8 | 9> | Unless<Or<IsSync, IsArray>, 'ipc'> | Unless<IsSync, DuplexTransform | WebTransform | TransformStream> | {readonly file: string; readonly append?: boolean};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};49 50 // Synchronous iterables excluding strings, Uint8Arrays and Arrays51 type IterableObject<IsArray extends boolean> = Iterable<unknown>52 & object111 unmodified linesmodified:types/utils.d.ts-2 removed
1 export type Not<Value extends boolean> = Value extends true ? false : true;2 3 export type And<First extends boolean, Second extends boolean> = First extends true ? Second : false;4 5-export type Or<First extends boolean, Second extends boolean> = First extends true ? true : Second;6-5 export type Unless<Condition extends boolean, ThenValue, ElseValue = never> = Condition extends true ? ElseValue : ThenValue;6 7 export type AndUnless<Condition extends boolean, ThenValue, ElseValue = unknown> = Condition extends true ? ElseValue : ThenValue;8 5 unmodified lines