Skip to content
Myr

Add support for `std*: ['pipe', 'inherit']` with `execaSync()` (#954)

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

authored by ehmicky · committed by GitHub · parent d0052ac · Browse files · 21 files+466 added−286 removed
This commit

State

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

Diff stats

21 files+466 added−286 removed

  • tests:+272 added−148 removed
  • other:+194 added−138 removed

21 files+466 added−286 removed

modified:lib/pipe/validate.js+1 added-8 removed
modified:lib/stdio/direction.js-5 removed
37 unmodified lines
38 asyncIterable: alwaysInput,39 uint8Array: alwaysInput,40 webStream: value => isWritableStream(value) ? 'output' : 'input',41 nodeStream(value) {42 const standardStreamDirection = getStandardStreamDirection(value);43 if (standardStreamDirection !== undefined) {44 return standardStreamDirection;45 }4642 if (!isNodeReadableStream(value, {checkOpen: false})) {43 return 'output';44 }45
31 unmodified lines
modified:lib/stdio/handle.js+7 added-6 removed
1import {handleStreamsVerbose} from '../verbose/output.js';2import {getStdioItemType, isRegularUrl, isUnknownStdioString} from './type.js';2import {getStdioItemType, isRegularUrl, isUnknownStdioString, FILE_TYPES} from './type.js';3import {getStreamDirection} from './direction.js';4import {normalizeStdio} from './option.js';5import {handleNativeStream} from './native.js';6import {handleInputOptions} from './input.js';
17 unmodified lines
24// For example, `stdout: ['ignore']` behaves the same as `stdout: 'ignore'`.25const getFileDescriptor = ({stdioOption, fdNumber, addProperties, options, isSync, stdioState, verboseInfo}) => {26 const outputLines = [];27 const optionName = getOptionName(fdNumber);28 const stdioItems = initializeStdioItems({stdioOption, fdNumber, options, isSync, optionName});29 const direction = getStreamDirection(stdioItems, fdNumber, optionName);28 const {stdioItems: initialStdioItems, isStdioArray} = initializeStdioItems({stdioOption, fdNumber, options, optionName});29 const direction = getStreamDirection(initialStdioItems, fdNumber, optionName);30 const stdioItems = initialStdioItems.map(stdioItem => handleNativeStream({stdioItem, isStdioArray, fdNumber, direction, isSync}));31 const objectMode = getObjectMode(stdioItems, optionName, direction, options);32 validateFileObjectMode(stdioItems, objectMode);33 const normalizedStdioItems = normalizeStdioItems({stdioItems, fdNumber, optionName, addProperties, options, isSync, direction, stdioState, verboseInfo, outputLines, objectMode});34 return {fdNumber, direction, outputLines, stdioItems: normalizedStdioItems};
1 unmodified line
3637const getOptionName = fdNumber => KNOWN_OPTION_NAMES[fdNumber] ?? `stdio[${fdNumber}]`;38const KNOWN_OPTION_NAMES = ['stdin', 'stdout', 'stderr'];3939const initializeStdioItems = ({stdioOption, fdNumber, options, isSync, optionName}) => {40const initializeStdioItems = ({stdioOption, fdNumber, options, optionName}) => {41 const values = Array.isArray(stdioOption) ? stdioOption : [stdioOption];42 const initialStdioItems = [43 ...values.map(value => initializeStdioItem(value, optionName)),44 ...handleInputOptions(options, fdNumber),
2 unmodified lines
47 const stdioItems = filterDuplicates(initialStdioItems);48 const isStdioArray = stdioItems.length > 1;49 validateStdioArray(stdioItems, isStdioArray, optionName);50 validateStreams(stdioItems);50 return stdioItems.map(stdioItem => handleNativeStream(stdioItem, isStdioArray, fdNumber, isSync));51 return {stdioItems, isStdioArray};52};5354const initializeStdioItem = (value, optionName) => ({55 type: getStdioItemType(value, optionName),
71 unmodified lines
127 if (!objectMode) {128 return;129 }130130 const fileStdioItem = stdioItems.find(({type}) => type === 'fileUrl' || type === 'filePath');131 const fileStdioItem = stdioItems.find(({type}) => FILE_TYPES.has(type));132 if (fileStdioItem !== undefined) {133 throw new TypeError(`The \`${fileStdioItem.optionName}\` option cannot use both files and transforms in objectMode.`);134 }135};
modified:lib/stdio/native.js+64 added-4 removed
1import {readFileSync} from 'node:fs';2import tty from 'node:tty';3import {isStream as isNodeStream} from 'is-stream';4import {STANDARD_STREAMS} from '../utils.js';5import {bufferToUint8Array} from './uint-array.js';67// When we use multiple `stdio` values for the same streams, we pass 'pipe' to `child_process.spawn()`.8// We then emulate the piping done by core Node.js.9// To do so, we transform the following values:10// - Node.js streams are marked as `type: nodeStream`11// - 'inherit' becomes `process.stdin|stdout|stderr`12// - any file descriptor integer becomes `process.stdio[fdNumber]`13// All of the above transformations tell Execa to perform manual piping.11export const handleNativeStream = (stdioItem, isStdioArray, fdNumber, isSync) => {12 const {type, value, optionName} = stdioItem;1314 if (!isStdioArray || type !== 'native' || isSync) {14export const handleNativeStream = ({stdioItem, stdioItem: {type}, isStdioArray, fdNumber, direction, isSync}) => {15 if (!isStdioArray || type !== 'native') {16 return stdioItem;17 }1819 return isSync20 ? handleNativeStreamSync({stdioItem, fdNumber, direction})21 : handleNativeStreamAsync({stdioItem, fdNumber});22};2324const handleNativeStreamSync = ({stdioItem, stdioItem: {value, optionName}, fdNumber, direction}) => {25 const targetFd = getTargetFd({value, optionName, fdNumber, direction});26 if (targetFd !== undefined) {27 return targetFd;28 }2930 if (isNodeStream(value, {checkOpen: false})) {31 throw new TypeError(`The \`${optionName}: Stream\` option cannot both be an array and include a stream with synchronous methods.`);32 }3334 return stdioItem;35};3637const getTargetFd = ({value, optionName, fdNumber, direction}) => {38 const targetFdNumber = getTargetFdNumber(value, fdNumber);39 if (targetFdNumber === undefined) {40 return;41 }4243 if (direction === 'output') {44 return {type: 'fileNumber', value: targetFdNumber, optionName};45 }4647 if (tty.isatty(targetFdNumber)) {48 throw new TypeError(`The \`${optionName}: ${serializeOptionValue(value)}\` option is invalid: it cannot be a TTY with synchronous methods.`);49 }5051 return {type: 'uint8Array', value: bufferToUint8Array(readFileSync(targetFdNumber)), optionName};52};5354const getTargetFdNumber = (value, fdNumber) => {55 if (value === 'inherit') {56 return fdNumber;57 }5859 if (typeof value === 'number') {60 return value;61 }6263 const standardStreamIndex = STANDARD_STREAMS.indexOf(value);64 if (standardStreamIndex !== -1) {65 return standardStreamIndex;66 }67};6869export const serializeOptionValue = value => {70 if (typeof value === 'string') {71 return `'${value}'`;72 }7374 return typeof value === 'number' ? `${value}` : 'Stream';75};7677const handleNativeStreamAsync = ({stdioItem, stdioItem: {value, optionName}, fdNumber}) => {78 if (value === 'inherit') {79 return {type: 'nodeStream', value: getStandardStream(fdNumber, value, optionName), optionName};80 }8182 if (typeof value === 'number') {
24 unmodified lines
modified:lib/stdio/output-sync.js+4 added-3 removed
1import {writeFileSync} from 'node:fs';2import {joinToString, joinToUint8Array, bufferToUint8Array} from './uint-array.js';3import {getGenerators, runGeneratorsSync} from './generator.js';4import {FILE_TYPES} from './type.js';56// Apply `stdout`/`stderr` options, after spawning, in sync mode7export const transformOutputSync = (fileDescriptors, {output}, options) => {8 if (output === null) {
50 unmodified lines
59 const finalResult = lines ? allOutputLines.flat() : serializedResult;60 return {serializedResult, finalResult};61};6262const writeToFiles = (transformedResult, allStdioItems) => {63const writeToFiles = (serializedResult, allStdioItems) => {64 for (const {type, path} of allStdioItems) {64 if (type === 'fileUrl' || type === 'filePath') {65 writeFileSync(path, transformedResult);65 if (FILE_TYPES.has(type)) {66 writeFileSync(path, serializedResult);67 }68 }69};
modified:lib/stdio/sync.js+2 added-50 removed
1import {readFileSync} from 'node:fs';2import {isStream as isNodeStream} from 'is-stream';2import {bufferToUint8Array} from './uint-array.js';3import {handleInput} from './handle.js';4import {TYPE_TO_MESSAGE} from './type.js';56// Normalize `input`, `inputFile`, `stdin`, `stdout` and `stderr` options, before spawning, in sync mode8export const handleInputSync = (options, verboseInfo) => {9 const {fileDescriptors} = handleInput(addPropertiesSync, options, verboseInfo, true);10 validateStdioArraysSync(fileDescriptors);11 return fileDescriptors;12};7export const handleInputSync = (options, verboseInfo) => handleInput(addPropertiesSync, options, verboseInfo, true);89const forbiddenIfSync = ({type, optionName}) => {10 throwInvalidSyncValue(optionName, TYPE_TO_MESSAGE[type]);11};
33 unmodified lines
45 output: {46 ...addProperties,47 fileUrl: ({value}) => ({path: value}),48 filePath: ({value: {file}}) => ({path: file}),49 fileNumber: ({value}) => ({path: value}),50 iterable: forbiddenIfSync,51 string: forbiddenIfSync,52 uint8Array: forbiddenIfSync,53 },54};5960const validateStdioArraysSync = fileDescriptors => {61 for (const {stdioItems} of fileDescriptors) {62 validateStdioArraySync(stdioItems);63 }64};6566const validateStdioArraySync = stdioItems => {67 if (stdioItems.length === 1) {68 return;69 }7071 const singleValueName = stdioItems.map(stdioItem => getSingleValueSync(stdioItem)).find(Boolean);72 if (singleValueName === undefined) {73 return;74 }7576 const inputOption = stdioItems.find(({optionName}) => OPTION_NAMES.has(optionName));77 if (inputOption !== undefined) {78 throw new TypeError(`The \`${singleValueName}\` and the \`${inputOption.optionName}\` options cannot be both set with synchronous methods.`);79 }8081 throw new TypeError(`The \`${singleValueName}\` option cannot be set as an array of values with synchronous methods.`);82};8384const getSingleValueSync = ({type, value, optionName}) => {85 if (type !== 'native') {86 return;87 }8889 if (value === 'inherit') {90 return `${optionName}: "inherit"`;91 }9293 if (typeof value === 'number') {94 return `${optionName}: ${value}`;95 }9697 if (isNodeStream(value, {checkOpen: false})) {98 return `${optionName}: Stream`;99 }100};101102const OPTION_NAMES = new Set(['input', 'inputFile']);
modified:lib/stdio/type.js+2 added
140 unmodified lines
141const isAsyncIterableObject = value => isObject(value) && typeof value[Symbol.asyncIterator] === 'function';142const isIterableObject = value => isObject(value) && typeof value[Symbol.iterator] === 'function';143const isObject = value => typeof value === 'object' && value !== null;144145export const FILE_TYPES = new Set(['fileUrl', 'filePath', 'fileNumber']);146147// Convert types to human-friendly strings for error messages148export const TYPE_TO_MESSAGE = {149 generator: 'a generator',150 asyncGenerator: 'an async generator',
12 unmodified lines
modified:lib/sync.js+1 added-1 removed
19 unmodified lines
20 try {21 const syncOptions = normalizeSyncOptions(rawOptions);22 const {file, args, options} = handleOptions(rawFile, rawArgs, syncOptions);23 validateSyncOptions(options);24 const fileDescriptors = handleInputSync(options, verboseInfo);24 const {fileDescriptors} = handleInputSync(options, verboseInfo);25 return {file, args, command, escapedCommand, startTime, verboseInfo, options, fileDescriptors};26 } catch (error) {27 logEarlyResult(error, startTime, verboseInfo);28 throw error;
62 unmodified lines
deleted:test/fixtures/nested-multiple-stderr.js-8 removed
1#!/usr/bin/env node2import process from 'node:process';3import {execa} from '../../index.js';4import {foobarString} from '../helpers/input.js';56const [options] = process.argv.slice(2);7const result = await execa('noop-fd.js', ['2', foobarString], {stderr: JSON.parse(options)});8process.stdout.write(`nested ${result.stderr}`);
modified:test/fixtures/nested-multiple-stdin.js+6 added-6 removed
1#!/usr/bin/env node2import process from 'node:process';3import {execa} from '../../index.js';3import {execa, execaSync} from '../../index.js';4import {foobarString} from '../helpers/input.js';5import {parseStdioOption} from '../helpers/stdio.js';66const [options] = process.argv.slice(2);7const subprocess = execa('stdin.js', {stdin: JSON.parse(options)});8subprocess.stdin.write(foobarString);9const {stdout} = await subprocess;10console.log(stdout);7const [stdioOption, isSyncString] = process.argv.slice(2);8const stdin = parseStdioOption(stdioOption);9const execaMethod = isSyncString === 'true' ? execaSync : execa;10await execaMethod('stdin.js', {input: foobarString, stdin, stdout: 'inherit'});
added:test/fixtures/nested-multiple-stdio-output.js+13 added
1#!/usr/bin/env node2import {Buffer} from 'node:buffer';3import process from 'node:process';4import {execa, execaSync} from '../../index.js';5import {foobarString} from '../helpers/input.js';6import {getStdio, parseStdioOption} from '../helpers/stdio.js';7import {getWriteStream} from '../helpers/fs.js';89const [stdioOption, fdNumber, outerFdNumber, isSyncString, encoding] = process.argv.slice(2);10const stdioValue = parseStdioOption(stdioOption);11const execaMethod = isSyncString === 'true' ? execaSync : execa;12const {stdio} = await execaMethod('noop-fd.js', [fdNumber, foobarString], {...getStdio(Number(fdNumber), stdioValue), encoding});13getWriteStream(Number(outerFdNumber)).write(`nested ${Buffer.from(stdio[fdNumber]).toString()}`);
deleted:test/fixtures/nested-multiple-stdout.js-8 removed
1#!/usr/bin/env node2import process from 'node:process';3import {execa} from '../../index.js';4import {foobarString} from '../helpers/input.js';56const [options] = process.argv.slice(2);7const result = await execa('noop.js', [foobarString], {stdout: JSON.parse(options)});8process.stderr.write(`nested ${result.stdout}`);
modified:test/fixtures/nested-stdio.js+12 added-10 removed
1#!/usr/bin/env node2import process from 'node:process';3import {execa} from '../../index.js';3import {execa, execaSync} from '../../index.js';4import {parseStdioOption} from '../helpers/stdio.js';55const [stdioOption, fdNumber, file, ...args] = process.argv.slice(2);6let optionValue = JSON.parse(stdioOption);7optionValue = typeof optionValue === 'string' ? process[optionValue] : optionValue;8optionValue = Array.isArray(optionValue) && typeof optionValue[0] === 'string'9 ? [process[optionValue[0]], ...optionValue.slice(1)]10 : optionValue;6const [stdioOption, fdNumber, isSyncString, file, ...args] = process.argv.slice(2);7const optionValue = parseStdioOption(stdioOption);8const isSync = isSyncString === 'true';9const stdio = ['ignore', 'inherit', 'inherit'];10stdio[fdNumber] = optionValue;11const execaMethod = isSync ? execaSync : execa;13const subprocess = execa(file, [`${fdNumber}`, ...args], {stdio});12const returnValue = execaMethod(file, [`${fdNumber}`, ...args], {stdio});1314const shouldPipe = Array.isArray(optionValue) && optionValue.includes('pipe');16const hasPipe = subprocess.stdio[fdNumber] !== null;15const fdReturnValue = returnValue.stdio[fdNumber];16const hasPipe = fdReturnValue !== undefined && fdReturnValue !== null;1718if (shouldPipe && !hasPipe) {19 throw new Error(`subprocess.stdio[${fdNumber}] is null.`);20}
1 unmodified line
22if (!shouldPipe && hasPipe) {23 throw new Error(`subprocess.stdio[${fdNumber}] should be null.`);24}2526await subprocess;26if (!isSync) {27 await returnValue;28}
added:test/fixtures/nested-sync-tty.js+26 added
1#!/usr/bin/env node2import process from 'node:process';3import tty from 'node:tty';4import {execa, execaSync} from '../../index.js';56const mockIsatty = fdNumber => {7 tty.isatty = fdNumberArg => fdNumber === fdNumberArg;8};910const originalIsatty = tty.isatty;11const unmockIsatty = () => {12 tty.isatty = originalIsatty;13};1415const [options, isSync, file, fdNumber, ...args] = process.argv.slice(2);16mockIsatty(Number(fdNumber));1718try {19 if (isSync === 'true') {20 execaSync(file, [fdNumber, ...args], JSON.parse(options));21 } else {22 await execa(file, [fdNumber, ...args], JSON.parse(options));23 }24} finally {25 unmockIsatty();26}
modified:test/helpers/stdio.js+13 added
25 unmodified lines
26 if (fdNumber === 1 && !isWindows) {27 t.true(stderr.includes('EPIPE'));28 }29};3031export const parseStdioOption = stdioOption => {32 const optionValue = JSON.parse(stdioOption);33 if (typeof optionValue === 'string' && optionValue in process) {34 return process[optionValue];35 }3637 if (Array.isArray(optionValue) && typeof optionValue[0] === 'string' && optionValue[0] in process) {38 return [process[optionValue[0]], ...optionValue.slice(1)];39 }4041 return optionValue;42};
modified:test/stdio/native.js+183 added-69 removed
1import {readFile, rm} from 'node:fs/promises';2import {platform} from 'node:process';3import test from 'ava';4import tempfile from 'tempfile';5import {execa} from '../../index.js';5import {execa, execaSync} from '../../index.js';6import {getStdio, fullStdio} from '../helpers/stdio.js';7import {setFixtureDir} from '../helpers/fixtures-dir.js';8import {foobarString} from '../helpers/input.js';910setFixtureDir();1112const isLinux = platform === 'linux';13const isWindows = platform === 'win32';1415const getFixtureName = isSync => isSync ? 'nested-sync.js' : 'nested.js';1617// eslint-disable-next-line max-params12const testRedirect = async (t, stdioOption, fdNumber, isInput) => {18const testRedirect = async (t, stdioOption, fdNumber, isInput, isSync) => {19 const {fixtureName, ...options} = isInput20 ? {fixtureName: 'stdin-fd.js', input: foobarString}21 : {fixtureName: 'noop-fd.js'};16 const {stdio} = await execa('nested-stdio.js', [JSON.stringify(stdioOption), `${fdNumber}`, fixtureName, foobarString], options);22 const {stdio} = await execa('nested-stdio.js', [JSON.stringify(stdioOption), `${fdNumber}`, `${isSync}`, fixtureName, foobarString], options);23 const resultFdNumber = isStderrDescriptor(stdioOption) ? 2 : 1;24 t.is(stdio[resultFdNumber], foobarString);25};2627const isStderrDescriptor = stdioOption => stdioOption === 228 || stdioOption === 'stderr'29 || (Array.isArray(stdioOption) && isStderrDescriptor(stdioOption[0]));3025test.serial('stdio[*] can be 0', testRedirect, 0, 3, true);26test.serial('stdio[*] can be [0]', testRedirect, [0], 3, true);27test.serial('stdio[*] can be [0, "pipe"]', testRedirect, [0, 'pipe'], 3, true);28test.serial('stdio[*] can be process.stdin', testRedirect, 'stdin', 3, true);29test.serial('stdio[*] can be [process.stdin]', testRedirect, ['stdin'], 3, true);30test.serial('stdio[*] can be [process.stdin, "pipe"]', testRedirect, ['stdin', 'pipe'], 3, true);31test('stdout can be 2', testRedirect, 2, 1, false);32test('stdout can be [2]', testRedirect, [2], 1, false);33test('stdout can be [2, "pipe"]', testRedirect, [2, 'pipe'], 1, false);34test('stdout can be process.stderr', testRedirect, 'stderr', 1, false);35test('stdout can be [process.stderr]', testRedirect, ['stderr'], 1, false);36test('stdout can be [process.stderr, "pipe"]', testRedirect, ['stderr', 'pipe'], 1, false);37test('stderr can be 1', testRedirect, 1, 2, false);38test('stderr can be [1]', testRedirect, [1], 2, false);39test('stderr can be [1, "pipe"]', testRedirect, [1, 'pipe'], 2, false);40test('stderr can be process.stdout', testRedirect, 'stdout', 2, false);41test('stderr can be [process.stdout]', testRedirect, ['stdout'], 2, false);42test('stderr can be [process.stdout, "pipe"]', testRedirect, ['stdout', 'pipe'], 2, false);43test('stdio[*] can be 1', testRedirect, 1, 3, false);44test('stdio[*] can be [1]', testRedirect, [1], 3, false);45test('stdio[*] can be [1, "pipe"]', testRedirect, [1, 'pipe'], 3, false);46test('stdio[*] can be 2', testRedirect, 2, 3, false);47test('stdio[*] can be [2]', testRedirect, [2], 3, false);48test('stdio[*] can be [2, "pipe"]', testRedirect, [2, 'pipe'], 3, false);49test('stdio[*] can be process.stdout', testRedirect, 'stdout', 3, false);50test('stdio[*] can be [process.stdout]', testRedirect, ['stdout'], 3, false);51test('stdio[*] can be [process.stdout, "pipe"]', testRedirect, ['stdout', 'pipe'], 3, false);52test('stdio[*] can be process.stderr', testRedirect, 'stderr', 3, false);53test('stdio[*] can be [process.stderr]', testRedirect, ['stderr'], 3, false);54test('stdio[*] can be [process.stderr, "pipe"]', testRedirect, ['stderr', 'pipe'], 3, false);31test.serial('stdio[*] can be 0', testRedirect, 0, 3, true, false);32test.serial('stdio[*] can be [0]', testRedirect, [0], 3, true, false);33test.serial('stdio[*] can be [0, "pipe"]', testRedirect, [0, 'pipe'], 3, true, false);34test.serial('stdio[*] can be process.stdin', testRedirect, 'stdin', 3, true, false);35test.serial('stdio[*] can be [process.stdin]', testRedirect, ['stdin'], 3, true, false);36test.serial('stdio[*] can be [process.stdin, "pipe"]', testRedirect, ['stdin', 'pipe'], 3, true, false);37test('stdout can be 2', testRedirect, 2, 1, false, false);38test('stdout can be [2]', testRedirect, [2], 1, false, false);39test('stdout can be [2, "pipe"]', testRedirect, [2, 'pipe'], 1, false, false);40test('stdout can be process.stderr', testRedirect, 'stderr', 1, false, false);41test('stdout can be [process.stderr]', testRedirect, ['stderr'], 1, false, false);42test('stdout can be [process.stderr, "pipe"]', testRedirect, ['stderr', 'pipe'], 1, false, false);43test('stderr can be 1', testRedirect, 1, 2, false, false);44test('stderr can be [1]', testRedirect, [1], 2, false, false);45test('stderr can be [1, "pipe"]', testRedirect, [1, 'pipe'], 2, false, false);46test('stderr can be process.stdout', testRedirect, 'stdout', 2, false, false);47test('stderr can be [process.stdout]', testRedirect, ['stdout'], 2, false, false);48test('stderr can be [process.stdout, "pipe"]', testRedirect, ['stdout', 'pipe'], 2, false, false);49test('stdio[*] can be 1', testRedirect, 1, 3, false, false);50test('stdio[*] can be [1]', testRedirect, [1], 3, false, false);51test('stdio[*] can be [1, "pipe"]', testRedirect, [1, 'pipe'], 3, false, false);52test('stdio[*] can be 2', testRedirect, 2, 3, false, false);53test('stdio[*] can be [2]', testRedirect, [2], 3, false, false);54test('stdio[*] can be [2, "pipe"]', testRedirect, [2, 'pipe'], 3, false, false);55test('stdio[*] can be process.stdout', testRedirect, 'stdout', 3, false, false);56test('stdio[*] can be [process.stdout]', testRedirect, ['stdout'], 3, false, false);57test('stdio[*] can be [process.stdout, "pipe"]', testRedirect, ['stdout', 'pipe'], 3, false, false);58test('stdio[*] can be process.stderr', testRedirect, 'stderr', 3, false, false);59test('stdio[*] can be [process.stderr]', testRedirect, ['stderr'], 3, false, false);60test('stdio[*] can be [process.stderr, "pipe"]', testRedirect, ['stderr', 'pipe'], 3, false, false);61test('stdout can be 2, sync', testRedirect, 2, 1, false, true);62test('stdout can be [2], sync', testRedirect, [2], 1, false, true);63test('stdout can be [2, "pipe"], sync', testRedirect, [2, 'pipe'], 1, false, true);64test('stdout can be process.stderr, sync', testRedirect, 'stderr', 1, false, true);65test('stdout can be [process.stderr], sync', testRedirect, ['stderr'], 1, false, true);66test('stdout can be [process.stderr, "pipe"], sync', testRedirect, ['stderr', 'pipe'], 1, false, true);67test('stderr can be 1, sync', testRedirect, 1, 2, false, true);68test('stderr can be [1], sync', testRedirect, [1], 2, false, true);69test('stderr can be [1, "pipe"], sync', testRedirect, [1, 'pipe'], 2, false, true);70test('stderr can be process.stdout, sync', testRedirect, 'stdout', 2, false, true);71test('stderr can be [process.stdout], sync', testRedirect, ['stdout'], 2, false, true);72test('stderr can be [process.stdout, "pipe"], sync', testRedirect, ['stdout', 'pipe'], 2, false, true);73test('stdio[*] can be 1, sync', testRedirect, 1, 3, false, true);74test('stdio[*] can be [1], sync', testRedirect, [1], 3, false, true);75test('stdio[*] can be [1, "pipe"], sync', testRedirect, [1, 'pipe'], 3, false, true);76test('stdio[*] can be 2, sync', testRedirect, 2, 3, false, true);77test('stdio[*] can be [2], sync', testRedirect, [2], 3, false, true);78test('stdio[*] can be [2, "pipe"], sync', testRedirect, [2, 'pipe'], 3, false, true);79test('stdio[*] can be process.stdout, sync', testRedirect, 'stdout', 3, false, true);80test('stdio[*] can be [process.stdout], sync', testRedirect, ['stdout'], 3, false, true);81test('stdio[*] can be [process.stdout, "pipe"], sync', testRedirect, ['stdout', 'pipe'], 3, false, true);82test('stdio[*] can be process.stderr, sync', testRedirect, 'stderr', 3, false, true);83test('stdio[*] can be [process.stderr], sync', testRedirect, ['stderr'], 3, false, true);84test('stdio[*] can be [process.stderr, "pipe"], sync', testRedirect, ['stderr', 'pipe'], 3, false, true);8556const testInheritStdin = async (t, stdin) => {57 const {stdout} = await execa('nested-multiple-stdin.js', [JSON.stringify(stdin)], {input: foobarString});86const testInheritStdin = async (t, stdioOption, isSync) => {87 const {stdout} = await execa('nested-multiple-stdin.js', [JSON.stringify(stdioOption), `${isSync}`], {input: foobarString});88 t.is(stdout, `${foobarString}${foobarString}`);89};9061test('stdin can be ["inherit", "pipe"]', testInheritStdin, ['inherit', 'pipe']);62test('stdin can be [0, "pipe"]', testInheritStdin, [0, 'pipe']);91test('stdin can be ["inherit", "pipe"]', testInheritStdin, ['inherit', 'pipe'], false);92test('stdin can be [0, "pipe"]', testInheritStdin, [0, 'pipe'], false);93test('stdin can be [process.stdin, "pipe"]', testInheritStdin, ['stdin', 'pipe'], false);94test.serial('stdin can be ["inherit", "pipe"], sync', testInheritStdin, ['inherit', 'pipe'], true);95test.serial('stdin can be [0, "pipe"], sync', testInheritStdin, [0, 'pipe'], true);96test.serial('stdin can be [process.stdin, "pipe"], sync', testInheritStdin, ['stdin', 'pipe'], true);9764const testInheritStdout = async (t, stdout) => {65 const result = await execa('nested-multiple-stdout.js', [JSON.stringify(stdout)]);66 t.is(result.stdout, foobarString);67 t.is(result.stderr, `nested ${foobarString}`);98// eslint-disable-next-line max-params99const testInheritStdioOutput = async (t, fdNumber, outerFdNumber, stdioOption, isSync, encoding) => {100 const {stdio} = await execa('nested-multiple-stdio-output.js', [JSON.stringify(stdioOption), `${fdNumber}`, `${outerFdNumber}`, `${isSync}`, encoding], fullStdio);101 t.is(stdio[fdNumber], foobarString);102 t.is(stdio[outerFdNumber], `nested ${foobarString}`);103};10470test('stdout can be ["inherit", "pipe"]', testInheritStdout, ['inherit', 'pipe']);71test('stdout can be [1, "pipe"]', testInheritStdout, [1, 'pipe']);105test('stdout can be ["inherit", "pipe"]', testInheritStdioOutput, 1, 2, ['inherit', 'pipe'], false, 'utf8');106test('stdout can be [1, "pipe"]', testInheritStdioOutput, 1, 2, [1, 'pipe'], false, 'utf8');107test('stdout can be [process.stdout, "pipe"]', testInheritStdioOutput, 1, 2, ['stdout', 'pipe'], false, 'utf8');108test('stderr can be ["inherit", "pipe"]', testInheritStdioOutput, 2, 1, ['inherit', 'pipe'], false, 'utf8');109test('stderr can be [2, "pipe"]', testInheritStdioOutput, 2, 1, [2, 'pipe'], false, 'utf8');110test('stderr can be [process.stderr, "pipe"]', testInheritStdioOutput, 2, 1, ['stderr', 'pipe'], false, 'utf8');111test('stdout can be ["inherit", "pipe"], encoding "buffer"', testInheritStdioOutput, 1, 2, ['inherit', 'pipe'], false, 'buffer');112test('stdout can be [1, "pipe"], encoding "buffer"', testInheritStdioOutput, 1, 2, [1, 'pipe'], false, 'buffer');113test('stdout can be [process.stdout, "pipe"], encoding "buffer"', testInheritStdioOutput, 1, 2, ['stdout', 'pipe'], false, 'buffer');114test('stderr can be ["inherit", "pipe"], encoding "buffer"', testInheritStdioOutput, 2, 1, ['inherit', 'pipe'], false, 'buffer');115test('stderr can be [2, "pipe"], encoding "buffer"', testInheritStdioOutput, 2, 1, [2, 'pipe'], false, 'buffer');116test('stderr can be [process.stderr, "pipe"], encoding "buffer"', testInheritStdioOutput, 2, 1, ['stderr', 'pipe'], false, 'buffer');117test('stdout can be ["inherit", "pipe"], sync', testInheritStdioOutput, 1, 2, ['inherit', 'pipe'], true, 'utf8');118test('stdout can be [1, "pipe"], sync', testInheritStdioOutput, 1, 2, [1, 'pipe'], true, 'utf8');119test('stdout can be [process.stdout, "pipe"], sync', testInheritStdioOutput, 1, 2, ['stdout', 'pipe'], true, 'utf8');120test('stderr can be ["inherit", "pipe"], sync', testInheritStdioOutput, 2, 1, ['inherit', 'pipe'], true, 'utf8');121test('stderr can be [2, "pipe"], sync', testInheritStdioOutput, 2, 1, [2, 'pipe'], true, 'utf8');122test('stderr can be [process.stderr, "pipe"], sync', testInheritStdioOutput, 2, 1, ['stderr', 'pipe'], true, 'utf8');123test('stdio[*] output can be ["inherit", "pipe"], sync', testInheritStdioOutput, 3, 1, ['inherit', 'pipe'], true, 'utf8');124test('stdio[*] output can be [3, "pipe"], sync', testInheritStdioOutput, 3, 1, [3, 'pipe'], true, 'utf8');125test('stdout can be ["inherit", "pipe"], encoding "buffer", sync', testInheritStdioOutput, 1, 2, ['inherit', 'pipe'], true, 'buffer');126test('stdout can be [1, "pipe"], encoding "buffer", sync', testInheritStdioOutput, 1, 2, [1, 'pipe'], true, 'buffer');127test('stdout can be [process.stdout, "pipe"], encoding "buffer", sync', testInheritStdioOutput, 1, 2, ['stdout', 'pipe'], true, 'buffer');128test('stderr can be ["inherit", "pipe"], encoding "buffer", sync', testInheritStdioOutput, 2, 1, ['inherit', 'pipe'], true, 'buffer');129test('stderr can be [2, "pipe"], encoding "buffer", sync', testInheritStdioOutput, 2, 1, [2, 'pipe'], true, 'buffer');130test('stderr can be [process.stderr, "pipe"], encoding "buffer", sync', testInheritStdioOutput, 2, 1, ['stderr', 'pipe'], true, 'buffer');131test('stdio[*] output can be ["inherit", "pipe"], encoding "buffer", sync', testInheritStdioOutput, 3, 1, ['inherit', 'pipe'], true, 'buffer');132test('stdio[*] output can be [3, "pipe"], encoding "buffer", sync', testInheritStdioOutput, 3, 1, [3, 'pipe'], true, 'buffer');13373const testInheritStderr = async (t, stderr) => {74 const result = await execa('nested-multiple-stderr.js', [JSON.stringify(stderr)]);75 t.is(result.stdout, `nested ${foobarString}`);76 t.is(result.stderr, foobarString);134const testFd3InheritOutput = async (t, stdioOption, isSync) => {135 const {stdio} = await execa(getFixtureName(isSync), [JSON.stringify(getStdio(3, stdioOption)), 'noop-fd.js', '3', foobarString], fullStdio);136 t.is(stdio[3], foobarString);137};13879test('stderr can be ["inherit", "pipe"]', testInheritStderr, ['inherit', 'pipe']);80test('stderr can be [2, "pipe"]', testInheritStderr, [2, 'pipe']);139test('stdio[*] output can use "inherit"', testFd3InheritOutput, 'inherit', false);140test('stdio[*] output can use ["inherit"]', testFd3InheritOutput, ['inherit'], false);141test('stdio[*] output can use "inherit", sync', testFd3InheritOutput, 'inherit', true);142test('stdio[*] output can use ["inherit"], sync', testFd3InheritOutput, ['inherit'], true);14382const testInheritNoBuffer = async (t, stdioOption) => {144const testInheritNoBuffer = async (t, stdioOption, isSync) => {145 const filePath = tempfile();84 await execa('nested.js', [JSON.stringify({stdin: stdioOption, buffer: false}), 'nested-write.js', filePath, foobarString], {input: foobarString});146 await execa(getFixtureName(isSync), [JSON.stringify({stdin: stdioOption, buffer: false}), 'nested-write.js', filePath, foobarString], {input: foobarString});147 t.is(await readFile(filePath, 'utf8'), `${foobarString} ${foobarString}`);148 await rm(filePath);149};15089test('stdin can be ["inherit", "pipe"], buffer: false', testInheritNoBuffer, ['inherit', 'pipe']);90test('stdin can be [0, "pipe"], buffer: false', testInheritNoBuffer, [0, 'pipe']);151test('stdin can be ["inherit", "pipe"], buffer: false', testInheritNoBuffer, ['inherit', 'pipe'], false);152test('stdin can be [0, "pipe"], buffer: false', testInheritNoBuffer, [0, 'pipe'], false);153test.serial('stdin can be ["inherit", "pipe"], buffer: false, sync', testInheritNoBuffer, ['inherit', 'pipe'], true);154test.serial('stdin can be [0, "pipe"], buffer: false, sync', testInheritNoBuffer, [0, 'pipe'], true);155156if (isLinux) {92const testOverflowStream = async (t, fdNumber, stdioOption) => {93 const {stdout} = await execa('nested.js', [JSON.stringify(getStdio(fdNumber, stdioOption)), 'empty.js'], fullStdio);94 t.is(stdout, '');95};157 const testOverflowStream = async (t, fdNumber, stdioOption, isSync) => {158 const {stdout} = await execa(getFixtureName(isSync), [JSON.stringify(getStdio(fdNumber, stdioOption)), 'empty.js'], fullStdio);159 t.is(stdout, '');160 };16197if (platform === 'linux') {98 test('stdin can use 4+', testOverflowStream, 0, 4);99 test('stdin can use [4+]', testOverflowStream, 0, [4]);100 test('stdout can use 4+', testOverflowStream, 1, 4);101 test('stdout can use [4+]', testOverflowStream, 1, [4]);102 test('stderr can use 4+', testOverflowStream, 2, 4);103 test('stderr can use [4+]', testOverflowStream, 2, [4]);104 test('stdio[*] can use 4+', testOverflowStream, 3, 4);105 test('stdio[*] can use [4+]', testOverflowStream, 3, [4]);162 test('stdin can use 4+', testOverflowStream, 0, 4, false);163 test('stdin can use [4+]', testOverflowStream, 0, [4], false);164 test('stdout can use 4+', testOverflowStream, 1, 4, false);165 test('stdout can use [4+]', testOverflowStream, 1, [4], false);166 test('stderr can use 4+', testOverflowStream, 2, 4, false);167 test('stderr can use [4+]', testOverflowStream, 2, [4], false);168 test('stdio[*] can use 4+', testOverflowStream, 3, 4, false);169 test('stdio[*] can use [4+]', testOverflowStream, 3, [4], false);170 test('stdin can use 4+, sync', testOverflowStream, 0, 4, true);171 test('stdin can use [4+], sync', testOverflowStream, 0, [4], true);172 test('stdout can use 4+, sync', testOverflowStream, 1, 4, true);173 test('stdout can use [4+], sync', testOverflowStream, 1, [4], true);174 test('stderr can use 4+, sync', testOverflowStream, 2, 4, true);175 test('stderr can use [4+], sync', testOverflowStream, 2, [4], true);176 test('stdio[*] can use 4+, sync', testOverflowStream, 3, 4, true);177 test('stdio[*] can use [4+], sync', testOverflowStream, 3, [4], true);178}179108test('stdio[*] can use "inherit"', testOverflowStream, 3, 'inherit');109test('stdio[*] can use ["inherit"]', testOverflowStream, 3, ['inherit']);110180const testOverflowStreamArray = (t, fdNumber, stdioOption) => {181 t.throws(() => {182 execa('empty.js', getStdio(fdNumber, stdioOption));183 }, {message: /no such standard stream/});
3 unmodified lines
187test('stdout cannot use 4+ and another value', testOverflowStreamArray, 1, [4, 'pipe']);188test('stderr cannot use 4+ and another value', testOverflowStreamArray, 2, [4, 'pipe']);189test('stdio[*] cannot use 4+ and another value', testOverflowStreamArray, 3, [4, 'pipe']);190test('stdio[*] cannot use "inherit" and another value', testOverflowStreamArray, 3, ['inherit', 'pipe']);191192const getInvalidFdCode = () => {193 if (isLinux) {194 return 'EINVAL';195 }196197 return isWindows ? 'EBADF' : 'ENXIO';198};199200const testOverflowStreamArraySync = (t, fdNumber) => {201 t.throws(() => {202 execaSync('noop-fd.js', [fdNumber, foobarString], getStdio(fdNumber, [4, 'pipe']));203 }, {code: getInvalidFdCode()});204};205206test('stdout cannot use 4+ and another value, sync', testOverflowStreamArraySync, 1);207test('stderr cannot use 4+ and another value, sync', testOverflowStreamArraySync, 2);208test('stdio[*] cannot use 4+ and another value, sync', testOverflowStreamArraySync, 3);209210test('stdin can use ["inherit", "pipe"] in a TTY', async t => {211 const stdioOption = [['inherit', 'pipe'], 'inherit', 'pipe'];212 const {stdout} = await execa('nested-sync-tty.js', [JSON.stringify({stdio: stdioOption}), 'false', 'stdin-fd.js', '0'], {input: foobarString});213 t.is(stdout, foobarString);214});215216const testNoTtyInput = async (t, fdNumber, optionName) => {217 const stdioOption = ['pipe', 'inherit', 'pipe'];218 stdioOption[fdNumber] = [[''], 'inherit', 'pipe'];219 const {message} = await t.throwsAsync(execa('nested-sync-tty.js', [JSON.stringify({stdio: stdioOption}), 'true', 'stdin-fd.js', `${fdNumber}`], fullStdio));220 t.true(message.includes(`The \`${optionName}: 'inherit'\` option is invalid: it cannot be a TTY`));221};222223test('stdin cannot use ["inherit", "pipe"] in a TTY, sync', testNoTtyInput, 0, 'stdin');224test('stdio[*] input cannot use ["inherit", "pipe"] in a TTY, sync', testNoTtyInput, 3, 'stdio[3]');225226const testTtyOutput = async (t, fdNumber, isSync) => {227 const {stdio} = await execa('nested-sync-tty.js', [JSON.stringify(getStdio(fdNumber, ['inherit', 'pipe'])), `${isSync}`, 'noop-fd.js', `${fdNumber}`, foobarString], fullStdio);228 t.is(stdio[fdNumber], foobarString);229};230231test('stdout can use ["inherit", "pipe"] in a TTY', testTtyOutput, 1, false);232test('stderr can use ["inherit", "pipe"] in a TTY', testTtyOutput, 2, false);233test('stdout can use ["inherit", "pipe"] in a TTY, sync', testTtyOutput, 1, true);234test('stderr can use ["inherit", "pipe"] in a TTY, sync', testTtyOutput, 2, true);235test('stdio[*] output can use ["inherit", "pipe"] in a TTY, sync', testTtyOutput, 3, true);
modified:test/stdio/node-stream.js+19 added
195 unmodified lines
196197test('stdin can be [Readable, "pipe"] without a file descriptor', testLazyFileReadable, 0);198test('stdio[*] can be [Readable, "pipe"] without a file descriptor', testLazyFileReadable, 3);199200const testLazyFileReadableSync = (t, fdNumber) => {201 t.throws(() => {202 execaSync('stdin-fd.js', [`${fdNumber}`], getStdio(fdNumber, [noopReadable(), 'pipe']));203 }, {message: /cannot both be an array and include a stream/});204};205206test('stdin cannot be [Readable, "pipe"] without a file descriptor, sync', testLazyFileReadableSync, 0);207test('stdio[*] cannot be [Readable, "pipe"] without a file descriptor, sync', testLazyFileReadableSync, 3);208209const testLazyFileWritable = async (t, fdNumber) => {210 const filePath = tempfile();211 const stream = createWriteStream(filePath);212
6 unmodified lines
219test('stdout can be [Writable, "pipe"] without a file descriptor', testLazyFileWritable, 1);220test('stderr can be [Writable, "pipe"] without a file descriptor', testLazyFileWritable, 2);221test('stdio[*] can be [Writable, "pipe"] without a file descriptor', testLazyFileWritable, 3);222223const testLazyFileWritableSync = (t, fdNumber) => {224 t.throws(() => {225 execaSync('noop-fd.js', [`${fdNumber}`], getStdio(fdNumber, [noopWritable(), 'pipe']));226 }, {message: /cannot both be an array and include a stream/});227};228229test('stdout cannot be [Writable, "pipe"] without a file descriptor, sync', testLazyFileWritableSync, 1);230test('stderr cannot be [Writable, "pipe"] without a file descriptor, sync', testLazyFileWritableSync, 2);231test('stdio[*] cannot be [Writable, "pipe"] without a file descriptor, sync', testLazyFileWritableSync, 3);232233test('Waits for custom streams destroy on subprocess errors', async t => {234 let waitedForDestroy = false;235 const stream = new Writable({236 destroy: callbackify(async error => {
91 unmodified lines
deleted:test/stdio/sync.js-47 removed
1import {fileURLToPath} from 'node:url';2import process from 'node:process';3import test from 'ava';4import {execaSync} from '../../index.js';5import {setFixtureDir} from '../helpers/fixtures-dir.js';6import {getStdio} from '../helpers/stdio.js';7import {noopReadable, noopWritable} from '../helpers/stream.js';89setFixtureDir();1011const getArrayMessage = singleValueName => `The \`${singleValueName}\` option cannot be set as an array`;12const getInputMessage = (singleValueName, inputName) => `The \`${singleValueName}\` and the \`${inputName}\` options cannot be both set`;1314const inputOptions = {input: ''};15const inputFileOptions = {inputFile: fileURLToPath(import.meta.url)};1617// eslint-disable-next-line max-params18const testInvalidStdioArraySync = (t, fdNumber, stdioOption, options, expectedMessage) => {19 const {message} = t.throws(() => {20 execaSync('empty.js', {...getStdio(fdNumber, stdioOption), ...options});21 });22 t.true(message.includes(expectedMessage));23};2425test('Cannot use ["inherit", "pipe"] with stdin, sync', testInvalidStdioArraySync, 0, ['inherit', 'pipe'], {}, getArrayMessage('stdin: "inherit"'));26test('Cannot use [0, "pipe"] with stdin, sync', testInvalidStdioArraySync, 0, [0, 'pipe'], {}, getArrayMessage('stdin: 0'));27test('Cannot use [process.stdin, "pipe"] with stdin, sync', testInvalidStdioArraySync, 0, [process.stdin, 'pipe'], {}, getArrayMessage('stdin: Stream'));28test('Cannot use [Readable, "pipe"] with stdin, sync', testInvalidStdioArraySync, 0, [noopReadable(), 'pipe'], {}, getArrayMessage('stdin: Stream'));29test('Cannot use "inherit" + "input" with stdin, sync', testInvalidStdioArraySync, 0, 'inherit', inputOptions, getInputMessage('stdin: "inherit"', 'input'));30test('Cannot use 0 + "input" with stdin, sync', testInvalidStdioArraySync, 0, 0, inputOptions, getInputMessage('stdin: 0', 'input'));31test('Cannot use process.stdin + "input" with stdin, sync', testInvalidStdioArraySync, 0, process.stdin, inputOptions, getInputMessage('stdin: Stream', 'input'));32test('Cannot use Readable + "input" with stdin, sync', testInvalidStdioArraySync, 0, noopReadable(), inputOptions, getInputMessage('stdin: Stream', 'input'));33test('Cannot use "inherit" + "inputFile" with stdin, sync', testInvalidStdioArraySync, 0, 'inherit', inputFileOptions, getInputMessage('stdin: "inherit"', 'inputFile'));34test('Cannot use 0 + "inputFile" with stdin, sync', testInvalidStdioArraySync, 0, 0, inputFileOptions, getInputMessage('stdin: 0', 'inputFile'));35test('Cannot use process.stdin + "inputFile" with stdin, sync', testInvalidStdioArraySync, 0, process.stdin, inputFileOptions, getInputMessage('stdin: Stream', 'inputFile'));36test('Cannot use Readable + "inputFile" with stdin, sync', testInvalidStdioArraySync, 0, noopReadable(), inputFileOptions, getInputMessage('stdin: Stream', 'inputFile'));37test('Cannot use ["inherit", "pipe"] with stdout, sync', testInvalidStdioArraySync, 1, ['inherit', 'pipe'], {}, getArrayMessage('stdout: "inherit"'));38test('Cannot use [1, "pipe"] with stdout, sync', testInvalidStdioArraySync, 1, [1, 'pipe'], {}, getArrayMessage('stdout: 1'));39test('Cannot use [process.stdout, "pipe"] with stdout, sync', testInvalidStdioArraySync, 1, [process.stdout, 'pipe'], {}, getArrayMessage('stdout: Stream'));40test('Cannot use [Writable, "pipe"] with stdout, sync', testInvalidStdioArraySync, 1, [noopWritable(), 'pipe'], {}, getArrayMessage('stdout: Stream'));41test('Cannot use ["inherit", "pipe"] with stderr, sync', testInvalidStdioArraySync, 2, ['inherit', 'pipe'], {}, getArrayMessage('stderr: "inherit"'));42test('Cannot use [2, "pipe"] with stderr, sync', testInvalidStdioArraySync, 2, [2, 'pipe'], {}, getArrayMessage('stderr: 2'));43test('Cannot use [process.stderr, "pipe"] with stderr, sync', testInvalidStdioArraySync, 2, [process.stderr, 'pipe'], {}, getArrayMessage('stderr: Stream'));44test('Cannot use [Writable, "pipe"] with stderr, sync', testInvalidStdioArraySync, 2, [noopWritable(), 'pipe'], {}, getArrayMessage('stderr: Stream'));45test('Cannot use ["inherit", "pipe"] with stdio[*], sync', testInvalidStdioArraySync, 3, ['inherit', 'pipe'], {}, getArrayMessage('stdio[3]: "inherit"'));46test('Cannot use [3, "pipe"] with stdio[*], sync', testInvalidStdioArraySync, 3, [3, 'pipe'], {}, getArrayMessage('stdio[3]: 3'));47test('Cannot use [Writable, "pipe"] with stdio[*], sync', testInvalidStdioArraySync, 3, [noopWritable(), 'pipe'], {}, getArrayMessage('stdio[3]: Stream'));
modified:index.d.ts+42 added-32 removed
1import {type ChildProcess} from 'node:child_process';2import {type Readable, type Writable, type Duplex} from 'node:stream';34type Not<Value extends boolean> = Value extends true ? false : true;56type And<First extends boolean, Second extends boolean> = First extends true ? Second : false;78type Or<First extends boolean, Second extends boolean> = First extends true ? true : Second;9
14 unmodified lines
24 | Unless<IsMainFd<FdNumber>, undefined>25 | readonly [NoStreamStdioOption<FdNumber>];2627type BaseStdioOption<26 IsSync extends boolean = boolean,27 IsArray extends boolean = boolean,28 IsSync extends boolean,29 IsExtra extends boolean,30 IsArray extends boolean,31> =32 | 'pipe'33 | undefined31 | Unless<And<IsSync, IsArray>, 'inherit'>34 | Unless<And<And<Not<IsSync>, IsArray>, IsExtra>, 'inherit'>35 | Unless<IsArray, 'ignore'>36 | Unless<IsSync, 'overlapped'>;3738// @todo Use `string`, `Uint8Array` or `unknown` for both the argument and the return type, based on whether `encoding: 'buffer'` and `objectMode: true` are used.
23 unmodified lines
62 objectMode?: boolean;63};6465type CommonStdioOption<63 IsSync extends boolean = boolean,64 IsArray extends boolean = boolean,66 IsSync extends boolean,67 IsExtra extends boolean,68 IsArray extends boolean,69> =66 | BaseStdioOption<IsSync, IsArray>70 | BaseStdioOption<IsSync, IsExtra, IsArray>71 | URL72 | {file: string}73 | GeneratorTransform<IsSync>74 | GeneratorTransformFull<IsSync>71 | Unless<And<IsSync, IsArray>, number>75 | Unless<And<Not<IsSync>, IsArray>, number>76 | Unless<Or<IsSync, IsArray>, 'ipc'>73 | Unless<IsSync,74 | DuplexTransform75 | WebTransform76 | TransformStream>;77 | Unless<IsSync, DuplexTransform | WebTransform | TransformStream>;7879// Synchronous iterables excluding strings, Uint8Arrays and Arrays79type IterableObject<IsArray extends boolean = boolean> = Iterable<unknown>80type IterableObject<IsArray extends boolean> = Iterable<unknown>81& object82& {readonly BYTES_PER_ELEMENT?: never}83& AndUnless<IsArray, {readonly lastIndexOf?: never}>;8485type InputStdioOption<85 IsSync extends boolean = boolean,86 IsExtra extends boolean = boolean,87 IsArray extends boolean = boolean,86 IsSync extends boolean,87 IsExtra extends boolean,88 IsArray extends boolean,89> =90 | 091 | Unless<And<IsSync, IsExtra>, Uint8Array | IterableObject<IsArray>>92 | Unless<And<IsSync, IsArray>, Readable>93 | Unless<IsSync, AsyncIterable<unknown> | ReadableStream>;9495type OutputStdioOption<94 IsSync extends boolean = boolean,95 IsArray extends boolean = boolean,96 IsSync extends boolean,97 IsArray extends boolean,98> =99 | 1100 | 2101 | Unless<And<IsSync, IsArray>, Writable>102 | Unless<IsSync, WritableStream>;103104type StdinSingleOption<105 IsSync extends boolean = boolean,106 IsExtra extends boolean = boolean,107 IsArray extends boolean = boolean,108> =105 | CommonStdioOption<IsSync, IsArray>109 | CommonStdioOption<IsSync, IsExtra, IsArray>110 | InputStdioOption<IsSync, IsExtra, IsArray>;111112type StdinOptionCommon<113 IsSync extends boolean = boolean,
6 unmodified lines
120export type StdinOptionSync = StdinOptionCommon<true, false>;121122type StdoutStderrSingleOption<123 IsSync extends boolean = boolean,124 IsExtra extends boolean = boolean,125 IsArray extends boolean = boolean,126> =122 | CommonStdioOption<IsSync, IsArray>127 | CommonStdioOption<IsSync, IsExtra, IsArray>128 | OutputStdioOption<IsSync, IsArray>;129125type StdoutStderrOptionCommon<IsSync extends boolean = boolean> =126 | StdoutStderrSingleOption<IsSync, false>127 | ReadonlyArray<StdoutStderrSingleOption<IsSync, true>>;130type StdoutStderrOptionCommon<131 IsSync extends boolean = boolean,132 IsExtra extends boolean = boolean,133> =134 | StdoutStderrSingleOption<IsSync, IsExtra, false>135 | ReadonlyArray<StdoutStderrSingleOption<IsSync, IsExtra, true>>;136129export type StdoutStderrOption = StdoutStderrOptionCommon<false>;130export type StdoutStderrOptionSync = StdoutStderrOptionCommon<true>;137export type StdoutStderrOption = StdoutStderrOptionCommon<false, false>;138export type StdoutStderrOptionSync = StdoutStderrOptionCommon<true, false>;139140type StdioExtraOptionCommon<IsSync extends boolean = boolean> =141 | StdinOptionCommon<IsSync, true>134 | StdoutStderrOptionCommon<IsSync>;142 | StdoutStderrOptionCommon<IsSync, true>;143144type StdioSingleOption<145 IsSync extends boolean = boolean,146 IsExtra extends boolean = boolean,147 IsArray extends boolean = boolean,148> =149 | StdinSingleOption<IsSync, IsExtra, IsArray>142 | StdoutStderrSingleOption<IsSync, IsArray>;150 | StdoutStderrSingleOption<IsSync, IsExtra, IsArray>;151152type StdioOptionCommon<IsSync extends boolean = boolean> =153 | StdinOptionCommon<IsSync>154 | StdoutStderrOptionCommon<IsSync>;
2 unmodified lines
157export type StdioOptionSync = StdioOptionCommon<true>;158159type StdioOptionsArray<IsSync extends boolean = boolean> = readonly [160 StdinOptionCommon<IsSync, false>,153 StdoutStderrOptionCommon<IsSync>,154 StdoutStderrOptionCommon<IsSync>,161 StdoutStderrOptionCommon<IsSync, false>,162 StdoutStderrOptionCommon<IsSync, false>,163 ...ReadonlyArray<StdioExtraOptionCommon<IsSync>>,164];165158type StdioOptions<IsSync extends boolean = boolean> = BaseStdioOption<IsSync> | StdioOptionsArray<IsSync>;166type StdioOptions<IsSync extends boolean = boolean> =167 | BaseStdioOption<IsSync, false, false>168 | StdioOptionsArray<IsSync>;169170type DefaultEncodingOption = 'utf8';171type TextEncodingOption =172 | DefaultEncodingOption
671 unmodified lines
844 - both `stdout` and `stderr` options are set to [`'inherit'`, `'ignore'`, `Stream` or `integer`](https://nodejs.org/api/child_process.html#child_process_options_stdio)845846 This is an array if the `lines` option is `true`, or if either the `stdout` or `stderr` option is a transform in object mode.847 */838 all: Unless<IsSync, AllOutput<OptionsType>>;848 all: Unless<IsSync, AllOutput<StricterOptions<OptionsType, Options>>>;849850 /**851 Results of the other subprocesses that were piped into this subprocess. This is useful to inspect a series of subprocesses piped with each other.852
565 unmodified lines
1418Same as `execa()` but synchronous.14191420Returns or throws a `subprocessResult`. The `subprocess` is not returned: its methods and properties are not available. This includes [`.kill()`](https://nodejs.org/api/child_process.html#subprocesskillsignal), [`.pid`](https://nodejs.org/api/child_process.html#subprocesspid), `.pipe()`, `.iterable()`, `.readable()`, `.writable()`, `.duplex()` and the [`.stdin`/`.stdout`/`.stderr`](https://nodejs.org/api/child_process.html#subprocessstdout) streams.14211412Cannot use the following options: `all`, `cleanup`, `detached`, `ipc`, `serialization`, `cancelSignal` and `forceKillAfterDelay`. Also, the `stdin`, `stdout`, `stderr` and `stdio` options cannot be a `['pipe', 'inherit']` array, [`'overlapped'`](https://nodejs.org/api/child_process.html#optionsstdio), an async iterable, an async transform, a `Duplex`, or a web stream. Node.js streams must have a file descriptor unless the `input` option is used.1422Cannot use the following options: `all`, `cleanup`, `detached`, `ipc`, `serialization`, `cancelSignal` and `forceKillAfterDelay`. Also, the `stdin`, `stdout`, `stderr` and `stdio` options cannot be [`'overlapped'`](https://nodejs.org/api/child_process.html#optionsstdio), an async iterable, an async transform, a `Duplex`, or a web stream. Node.js streams must have a file descriptor unless the `input` option is used.14231424@param file - The program/script to execute, as a string or file URL1425@param arguments - Arguments to pass to `file` on execution.1426@returns A `subprocessResult` object
105 unmodified lines
1532Same as `execaCommand()` but synchronous.15331534Returns or throws a `subprocessResult`. The `subprocess` is not returned: its methods and properties are not available. This includes [`.kill()`](https://nodejs.org/api/child_process.html#subprocesskillsignal), [`.pid`](https://nodejs.org/api/child_process.html#subprocesspid), `.pipe()`, `.iterable()`, `.readable()`, `.writable()`, `.duplex()` and the [`.stdin`/`.stdout`/`.stderr`](https://nodejs.org/api/child_process.html#subprocessstdout) streams.15351526Cannot use the following options: `all`, `cleanup`, `detached`, `ipc`, `serialization`, `cancelSignal` and `forceKillAfterDelay`. Also, the `stdin`, `stdout`, `stderr` and `stdio` options cannot be a `['pipe', 'inherit']` array, [`'overlapped'`](https://nodejs.org/api/child_process.html#optionsstdio), an async iterable, an async transform, a `Duplex`, or a web stream. Node.js streams must have a file descriptor unless the `input` option is used.1536Cannot use the following options: `all`, `cleanup`, `detached`, `ipc`, `serialization`, `cancelSignal` and `forceKillAfterDelay`. Also, the `stdin`, `stdout`, `stderr` and `stdio` options cannot be [`'overlapped'`](https://nodejs.org/api/child_process.html#optionsstdio), an async iterable, an async transform, a `Duplex`, or a web stream. Node.js streams must have a file descriptor unless the `input` option is used.15371538@param command - The program/script to execute and its arguments.1539@returns A `subprocessResult` object1540@throws A `subprocessResult` error
128 unmodified lines
modified:index.test-d.ts+70 added-28 removed
1525 unmodified lines
1526expectNotAssignable<StdioOptionSync>('unknown');1527expectNotAssignable<StdioOption>(['unknown']);1528expectNotAssignable<StdioOptionSync>(['unknown']);1529execa('unicorns', {stdin: pipeInherit});1530expectError(execaSync('unicorns', {stdin: pipeInherit}));1530execaSync('unicorns', {stdin: pipeInherit});1531execa('unicorns', {stdout: pipeInherit});1532expectError(execaSync('unicorns', {stdout: pipeInherit}));1532execaSync('unicorns', {stdout: pipeInherit});1533execa('unicorns', {stderr: pipeInherit});1534expectError(execaSync('unicorns', {stderr: pipeInherit}));1535execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', pipeInherit]});1536expectError(execaSync('unicorns', {stdio: ['pipe', 'pipe', 'pipe', pipeInherit]}));1534execaSync('unicorns', {stderr: pipeInherit});1535expectError(execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', pipeInherit]}));1536execaSync('unicorns', {stdio: ['pipe', 'pipe', 'pipe', pipeInherit]});1537expectAssignable<StdinOption>(pipeInherit);1538expectNotAssignable<StdinOptionSync>(pipeInherit);1538expectAssignable<StdinOptionSync>(pipeInherit);1539expectAssignable<StdoutStderrOption>(pipeInherit);1540expectNotAssignable<StdoutStderrOptionSync>(pipeInherit);1540expectAssignable<StdoutStderrOptionSync>(pipeInherit);1541expectAssignable<StdioOption>(pipeInherit);1542expectNotAssignable<StdioOptionSync>(pipeInherit);1542expectAssignable<StdioOptionSync>(pipeInherit);1543execa('unicorns', {stdin: pipeUndefined});1544execaSync('unicorns', {stdin: pipeUndefined});1545execa('unicorns', {stdout: pipeUndefined});1546execaSync('unicorns', {stdout: pipeUndefined});
99 unmodified lines
1646expectNotAssignable<StdioOptionSync>([null]);1647execa('unicorns', {stdin: 'inherit'});1648execaSync('unicorns', {stdin: 'inherit'});1649execa('unicorns', {stdin: ['inherit']});1650expectError(execaSync('unicorns', {stdin: ['inherit']}));1650execaSync('unicorns', {stdin: ['inherit']});1651execa('unicorns', {stdout: 'inherit'});1652execaSync('unicorns', {stdout: 'inherit'});1653execa('unicorns', {stdout: ['inherit']});1654expectError(execaSync('unicorns', {stdout: ['inherit']}));1654execaSync('unicorns', {stdout: ['inherit']});1655execa('unicorns', {stderr: 'inherit'});1656execaSync('unicorns', {stderr: 'inherit'});1657execa('unicorns', {stderr: ['inherit']});1658expectError(execaSync('unicorns', {stderr: ['inherit']}));1658execaSync('unicorns', {stderr: ['inherit']});1659execa('unicorns', {stdio: 'inherit'});1660execaSync('unicorns', {stdio: 'inherit'});1661execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', 'inherit']});1662execaSync('unicorns', {stdio: ['pipe', 'pipe', 'pipe', 'inherit']});1663execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', ['inherit']]});1664expectError(execaSync('unicorns', {stdio: ['pipe', 'pipe', 'pipe', ['inherit']]}));1663expectError(execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', ['inherit']]}));1664execaSync('unicorns', {stdio: ['pipe', 'pipe', 'pipe', ['inherit']]});1665expectAssignable<StdinOption>('inherit');1666expectAssignable<StdinOptionSync>('inherit');1667expectAssignable<StdinOption>(['inherit']);1668expectNotAssignable<StdinOptionSync>(['inherit']);1668expectAssignable<StdinOptionSync>(['inherit']);1669expectAssignable<StdoutStderrOption>('inherit');1670expectAssignable<StdoutStderrOptionSync>('inherit');1671expectAssignable<StdoutStderrOption>(['inherit']);1672expectNotAssignable<StdoutStderrOptionSync>(['inherit']);1672expectAssignable<StdoutStderrOptionSync>(['inherit']);1673expectAssignable<StdioOption>('inherit');1674expectAssignable<StdioOptionSync>('inherit');1675expectNotAssignable<StdioOption>(['inherit']);1676expectNotAssignable<StdioOptionSync>(['inherit']);1675expectAssignable<StdioOption>(['inherit']);1676expectAssignable<StdioOptionSync>(['inherit']);1677execa('unicorns', {stdin: 'ignore'});1678execaSync('unicorns', {stdin: 'ignore'});1679expectError(execa('unicorns', {stdin: ['ignore']}));1680expectError(execaSync('unicorns', {stdin: ['ignore']}));
85 unmodified lines
1766expectNotAssignable<StdioOptionSync>(['ipc']);1767execa('unicorns', {stdin: 0});1768execaSync('unicorns', {stdin: 0});1769execa('unicorns', {stdin: [0]});1770expectError(execaSync('unicorns', {stdin: [0]}));1770execaSync('unicorns', {stdin: [0]});1771expectError(execa('unicorns', {stdin: [1]}));1772expectError(execa('unicorns', {stdin: [2]}));1773execa('unicorns', {stdin: 3});1774execaSync('unicorns', {stdin: 3});1775expectError(execa('unicorns', {stdin: [3]}));1776execaSync('unicorns', {stdin: [3]});1777expectError(execa('unicorns', {stdout: [0]}));1778execa('unicorns', {stdout: 1});1779execaSync('unicorns', {stdout: 1});1780execa('unicorns', {stdout: [1]});1774expectError(execaSync('unicorns', {stdout: [1]}));1775execa('unicorns', {stderr: 2});1781execaSync('unicorns', {stdout: [1]});1782execa('unicorns', {stdout: 2});1783execaSync('unicorns', {stdout: 2});1784execa('unicorns', {stdout: [2]});1785execaSync('unicorns', {stdout: [2]});1786execa('unicorns', {stdout: 3});1787execaSync('unicorns', {stdout: 3});1788expectError(execa('unicorns', {stdout: [3]}));1789execaSync('unicorns', {stdout: [3]});1790expectError(execa('unicorns', {stderr: [0]}));1791execa('unicorns', {stderr: 1});1792execaSync('unicorns', {stderr: 1});1793execa('unicorns', {stderr: [1]});1794execaSync('unicorns', {stderr: [1]});1795execa('unicorns', {stderr: 1});1796execaSync('unicorns', {stderr: 2});1797execa('unicorns', {stderr: [2]});1798execaSync('unicorns', {stderr: [2]});1799execa('unicorns', {stderr: 3});1800execaSync('unicorns', {stderr: 3});1801expectError(execa('unicorns', {stderr: [3]}));1802execaSync('unicorns', {stderr: [3]});1803expectError(execa('unicorns', {stdio: 0}));1778expectError(execaSync('unicorns', {stderr: [2]}));1804expectError(execaSync('unicorns', {stdio: 0}));1805expectError(execa('unicorns', {stdio: 1}));1806expectError(execaSync('unicorns', {stdio: 1}));1807expectError(execa('unicorns', {stdio: 2}));1808expectError(execaSync('unicorns', {stdio: 2}));1809expectError(execa('unicorns', {stdio: 3}));1810expectError(execaSync('unicorns', {stdio: 3}));1811execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', 0]});1812execaSync('unicorns', {stdio: ['pipe', 'pipe', 'pipe', 0]});1813execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', [0]]});1814execaSync('unicorns', {stdio: ['pipe', 'pipe', 'pipe', [0]]});1815execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', 1]});1816execaSync('unicorns', {stdio: ['pipe', 'pipe', 'pipe', 1]});1817execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', [1]]});1818execaSync('unicorns', {stdio: ['pipe', 'pipe', 'pipe', [1]]});1819execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', 2]});1820execaSync('unicorns', {stdio: ['pipe', 'pipe', 'pipe', 2]});1821execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', [2]]});1822execaSync('unicorns', {stdio: ['pipe', 'pipe', 'pipe', [2]]});1823execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', 3]});1824execaSync('unicorns', {stdio: ['pipe', 'pipe', 'pipe', 3]});1783execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', [3]]});1784expectError(execaSync('unicorns', {stdio: ['pipe', 'pipe', 'pipe', [3]]}));1825expectError(execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', [3]]}));1826execaSync('unicorns', {stdio: ['pipe', 'pipe', 'pipe', [3]]});1827expectAssignable<StdinOption>(0);1828expectAssignable<StdinOptionSync>(0);1829expectAssignable<StdinOption>([0]);1788expectNotAssignable<StdinOptionSync>([0]);1830expectAssignable<StdinOptionSync>([0]);1831expectAssignable<StdoutStderrOption>(1);1832expectAssignable<StdoutStderrOptionSync>(1);1833expectAssignable<StdoutStderrOption>([1]);1792expectNotAssignable<StdoutStderrOptionSync>([1]);1834expectAssignable<StdoutStderrOptionSync>([1]);1835expectAssignable<StdoutStderrOption>(2);1836expectAssignable<StdoutStderrOptionSync>(2);1837expectAssignable<StdoutStderrOption>([2]);1796expectNotAssignable<StdoutStderrOptionSync>([2]);1838expectAssignable<StdoutStderrOptionSync>([2]);1839expectAssignable<StdioOption>(3);1840expectAssignable<StdioOptionSync>(3);1799expectAssignable<StdioOption>([3]);1800expectNotAssignable<StdioOptionSync>([3]);1841expectNotAssignable<StdioOption>([3]);1842expectAssignable<StdioOptionSync>([3]);1843execa('unicorns', {stdin: process.stdin});1844execaSync('unicorns', {stdin: process.stdin});1845execa('unicorns', {stdin: [process.stdin]});1846expectError(execaSync('unicorns', {stdin: [process.stdin]}));
1920 unmodified lines
modified:readme.md+1 added-1 removed
317 unmodified lines
318Same as [`execa()`](#execafile-arguments-options) but synchronous.319320Returns or throws a [`subprocessResult`](#subprocessResult). The [`subprocess`](#subprocess) is not returned: its methods and properties are not available. This includes [`.kill()`](https://nodejs.org/api/child_process.html#subprocesskillsignal), [`.pid`](https://nodejs.org/api/child_process.html#subprocesspid), [`.pipe()`](#pipefile-arguments-options), [`.iterable()`](#iterablereadableoptions), [`.readable()`](#readablereadableoptions), [`.writable()`](#writablewritableoptions), [`.duplex()`](#duplexduplexoptions) and the [`.stdin`/`.stdout`/`.stderr`](https://nodejs.org/api/child_process.html#subprocessstdout) streams.321322Cannot use the following options: [`all`](#all-2), [`cleanup`](#cleanup), [`detached`](#detached), [`ipc`](#ipc), [`serialization`](#serialization), [`cancelSignal`](#cancelsignal) and [`forceKillAfterDelay`](#forcekillafterdelay). Also, the [`stdin`](#stdin), [`stdout`](#stdout-1), [`stderr`](#stderr-1) and [`stdio`](#stdio-1) cannot be a [`['pipe', 'inherit']`](#redirect-stdinstdoutstderr-to-multiple-destinations) array, [`'overlapped'`](https://nodejs.org/api/child_process.html#optionsstdio), an async iterable, an async [transform](docs/transform.md), a [`Duplex`](docs/transform.md#duplextransform-streams), or a web stream. Node.js streams [must have a file descriptor](#redirect-a-nodejs-stream-fromto-stdinstdoutstderr) unless the `input` option is used.322Cannot use the following options: [`all`](#all-2), [`cleanup`](#cleanup), [`detached`](#detached), [`ipc`](#ipc), [`serialization`](#serialization), [`cancelSignal`](#cancelsignal) and [`forceKillAfterDelay`](#forcekillafterdelay). Also, the [`stdin`](#stdin), [`stdout`](#stdout-1), [`stderr`](#stderr-1) and [`stdio`](#stdio-1) cannot be [`'overlapped'`](https://nodejs.org/api/child_process.html#optionsstdio), an async iterable, an async [transform](docs/transform.md), a [`Duplex`](docs/transform.md#duplextransform-streams), or a web stream. Node.js streams [must have a file descriptor](#redirect-a-nodejs-stream-fromto-stdinstdoutstderr) unless the `input` option is used.323324#### $(file, arguments?, options?)325326`file`: `string | URL`\
899 unmodified lines