Refactor `stdio` options (#623)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by ehmicky · committed by GitHub · parent 14485c7 · Browse files · 10 files·+315 added−301 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
10 files+315 added−301 removed
- tests:+4 added−4 removed
- other:+311 added−297 removed
Provenance
- Commit
2d76897- Tree
9af75e3- Author
ehmicky <ehmicky@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent
14485c7
10 files changed+315 added−301 removed
added:lib/stdio/async.js+46 added
12345678910111213141516171819202122232425262728293031323334353637383940414243444546import {createReadStream, createWriteStream} from 'node:fs';import {Readable, Writable} from 'node:stream';import {handleInput} from './input.js';
// Handle `input`, `inputFile`, `stdin`, `stdout` and `stderr` options, before spawning, in async modeexport const handleInputAsync = options => handleInput(addPropertiesAsync, options);
const addPropertiesAsync = { input: { filePath: ({value}) => ({value: createReadStream(value)}), webStream: ({value}) => ({value: Readable.fromWeb(value)}), iterable: ({value}) => ({value: Readable.from(value)}), }, output: { filePath: ({value}) => ({value: createWriteStream(value)}), webStream: ({value}) => ({value: Writable.fromWeb(value)}), iterable({optionName}) { throw new TypeError(`The \`${optionName}\` option cannot be an iterable.`); }, },};
// Handle `input`, `inputFile`, `stdin`, `stdout` and `stderr` options, after spawning, in async modeexport const pipeOutputAsync = (spawned, stdioStreams) => { for (const [index, stdioStream] of stdioStreams.entries()) { pipeStdioOption(spawned.stdio[index], stdioStream); }};
const pipeStdioOption = (childStream, {type, value, direction}) => { if (type === 'native') { return; }
if (direction === 'output') { childStream.pipe(value); return; }
if (type === 'stringOrBuffer') { childStream.end(value); return; }
value.pipe(childStream);};added:lib/stdio/input.js+98 added
1+import {isStream as isNodeStream} from 'is-stream';2+import {getStdioOptionType, isRegularUrl, isUnknownStdioString} from './type.js';3+import {normalizeStdio} from './normalize.js';4+5+// Handle `input`, `inputFile`, `stdin`, `stdout` and `stderr` options, before spawning, in async/sync mode6+export const handleInput = (addProperties, options) => {7+ const stdio = normalizeStdio(options);8+ const stdioArray = arrifyStdio(stdio);9+ const stdioStreams = stdioArray.map((stdioOption, index) => getStdioStream(stdioOption, index, addProperties, options));10+ options.stdio = transformStdio(stdio, stdioStreams);11+ return stdioStreams;12+};13+14+const arrifyStdio = (stdio = []) => Array.isArray(stdio) ? stdio : [stdio, stdio, stdio];15+16+const getStdioStream = (stdioOption, index, addProperties, {input, inputFile}) => {17+ let stdioStream = {18+ type: getStdioOptionType(stdioOption),19+ value: stdioOption,20+ optionName: OPTION_NAMES[index],21+ direction: index === 0 ? 'input' : 'output',22+ };23+ validateFileStdio(stdioStream);24+25+ stdioStream = handleInputOption(stdioStream, index, input);26+ stdioStream = handleInputFileOption(stdioStream, index, inputFile, input);27+28+ return {29+ ...stdioStream,30+ ...addProperties[stdioStream.direction][stdioStream.type]?.(stdioStream),31+ };32+};33+34+const OPTION_NAMES = ['stdin', 'stdout', 'stderr'];35+36+const validateFileStdio = ({type, value, optionName}) => {37+ if (type !== 'native') {38+ return;39+ }40+41+ validateRegularUrl(value, optionName);42+43+ if (isUnknownStdioString(value)) {44+ throw new TypeError(`The \`${optionName}: filePath\` option must either be an absolute file path or start with \`.\`.`);45+ }46+};47+48+// Override the `stdin` option with the `input` option49+const handleInputOption = (stdioStream, index, input) => {50+ if (input === undefined || index !== 0) {51+ return stdioStream;52+ }53+54+ const optionName = 'input';55+ validateInputOption(stdioStream.value, optionName);56+ const type = isNodeStream(input) ? 'nodeStream' : 'stringOrBuffer';57+ return {...stdioStream, value: input, type, optionName};58+};59+60+// Override the `stdin` option with the `inputFile` option61+const handleInputFileOption = (stdioStream, index, inputFile, input) => {62+ if (inputFile === undefined || index !== 0) {63+ return stdioStream;64+ }65+66+ if (input !== undefined) {67+ throw new TypeError('The `input` and `inputFile` options cannot be both set.');68+ }69+70+ const optionName = 'inputFile';71+ validateInputOption(stdioStream.value, optionName);72+ validateRegularUrl(inputFile, optionName);73+ return {...stdioStream, value: inputFile, type: 'filePath', optionName};74+};75+76+const validateInputOption = (value, optionName) => {77+ if (!CAN_USE_INPUT.has(value)) {78+ throw new TypeError(`The \`${optionName}\` and \`stdin\` options cannot be both set.`);79+ }80+};81+82+const CAN_USE_INPUT = new Set([undefined, null, 'overlapped', 'pipe']);83+84+const validateRegularUrl = (value, optionName) => {85+ if (isRegularUrl(value)) {86+ throw new TypeError(`The \`${optionName}: URL\` option must use the \`file:\` scheme.87+For example, you can use the \`pathToFileURL()\` method of the \`url\` core module.`);88+ }89+};90+91+// When the `std*: Iterable | WebStream | URL | filePath`, `input` or `inputFile` option is used, we pipe to `spawned.std*`.92+// Therefore the `std*` options must be either `pipe` or `overlapped`. Other values do not set `spawned.std*`.93+const transformStdio = (stdio, stdioStreams) => Array.isArray(stdio)94+ ? stdio.map((stdioItem, index) => transformStdioItem(stdioItem, index, stdioStreams))95+ : stdio;96+97+const transformStdioItem = (stdioItem, index, stdioStreams) =>98+ stdioStreams[index].type !== 'native' && stdioItem !== 'overlapped' ? 'pipe' : stdioItem;added:lib/stdio/normalize.js+50 added
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950// Add support for `stdin`/`stdout`/`stderr` as an alias for `stdio`export const normalizeStdio = options => { if (!options) { return; }
const {stdio} = options;
if (stdio === undefined) { return aliases.map(alias => options[alias]); }
if (hasAlias(options)) { throw new Error(`It's not possible to provide \`stdio\` in combination with one of ${aliases.map(alias => `\`${alias}\``).join(', ')}`); }
if (typeof stdio === 'string') { return stdio; }
if (!Array.isArray(stdio)) { throw new TypeError(`Expected \`stdio\` to be of type \`string\` or \`Array\`, got \`${typeof stdio}\``); }
const length = Math.max(stdio.length, aliases.length); return Array.from({length}, (value, index) => stdio[index]);};
const hasAlias = options => aliases.some(alias => options[alias] !== undefined);
const aliases = ['stdin', 'stdout', 'stderr'];
// Same but for `execaNode()`, i.e. push `ipc` unless already presentexport const normalizeStdioNode = options => { const stdio = normalizeStdio(options);
if (stdio === 'ipc') { return 'ipc'; }
if (stdio === undefined || typeof stdio === 'string') { return [stdio, stdio, stdio, 'ipc']; }
if (stdio.includes('ipc')) { return stdio; }
return [...stdio, 'ipc'];};added:lib/stdio/sync.js+56 added
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556import {readFileSync, writeFileSync} from 'node:fs';import {handleInput} from './input.js';import {TYPE_TO_MESSAGE} from './type.js';
// Handle `input`, `inputFile`, `stdin`, `stdout` and `stderr` options, before spawning, in sync modeexport const handleInputSync = options => { const stdioStreams = handleInput(addPropertiesSync, options); addInputOptionSync(stdioStreams, options); return stdioStreams;};
const forbiddenIfSync = ({type, optionName}) => { throw new TypeError(`The \`${optionName}\` option cannot be ${TYPE_TO_MESSAGE[type]} in sync mode.`);};
const addPropertiesSync = { input: { filePath: ({value}) => ({value: readFileSync(value), type: 'stringOrBuffer'}), webStream: forbiddenIfSync, nodeStream: forbiddenIfSync, iterable: forbiddenIfSync, }, output: { webStream: forbiddenIfSync, nodeStream: forbiddenIfSync, iterable: forbiddenIfSync, },};
const addInputOptionSync = (stdioStreams, options) => { const inputValue = stdioStreams.find(({type}) => type === 'stringOrBuffer')?.value; if (inputValue !== undefined) { options.input = inputValue; }};
// Handle `input`, `inputFile`, `stdin`, `stdout` and `stderr` options, after spawning, in sync modeexport const pipeOutputSync = (stdioStreams, result) => { if (result.output === null) { return; }
for (const [index, stdioStream] of stdioStreams.entries()) { pipeStdioOptionSync(result.output[index], stdioStream); }};
const pipeStdioOptionSync = (result, {type, value, direction}) => { if (result === null || direction === 'input') { return; }
if (type === 'filePath') { writeFileSync(value, result); }};added:lib/stdio/type.js+51 added
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051import {isAbsolute} from 'node:path';import {isStream as isNodeStream} from 'is-stream';
// The `stdin`/`stdout`/`stderr` option can be of many types. This detects it.export const getStdioOptionType = stdioOption => { if (isFileUrl(stdioOption) || isFilePath(stdioOption)) { return 'filePath'; }
if (isWebStream(stdioOption)) { return 'webStream'; }
if (isNodeStream(stdioOption)) { return 'native'; }
if (isIterableObject(stdioOption)) { return 'iterable'; }
return 'native';};
const isUrlInstance = stdioOption => Object.prototype.toString.call(stdioOption) === '[object URL]';const hasFileProtocol = url => url.protocol === 'file:';const isFileUrl = stdioOption => isUrlInstance(stdioOption) && hasFileProtocol(stdioOption);export const isRegularUrl = stdioOption => isUrlInstance(stdioOption) && !hasFileProtocol(stdioOption);
const stringIsFilePath = stdioOption => stdioOption.startsWith('.') || isAbsolute(stdioOption);const isFilePath = stdioOption => typeof stdioOption === 'string' && stringIsFilePath(stdioOption);export const isUnknownStdioString = stdioOption => typeof stdioOption === 'string' && !stringIsFilePath(stdioOption) && !KNOWN_STDIO_STRINGS.has(stdioOption);const KNOWN_STDIO_STRINGS = new Set(['ipc', 'ignore', 'inherit', 'overlapped', 'pipe']);
const isReadableStream = stdioOption => Object.prototype.toString.call(stdioOption) === '[object ReadableStream]';const isWritableStream = stdioOption => Object.prototype.toString.call(stdioOption) === '[object WritableStream]';const isWebStream = stdioOption => isReadableStream(stdioOption) || isWritableStream(stdioOption);
const isIterableObject = stdinOption => typeof stdinOption === 'object' && stdinOption !== null && (typeof stdinOption[Symbol.asyncIterator] === 'function' || typeof stdinOption[Symbol.iterator] === 'function');
// Convert types to human-friendly strings for error messagesexport const TYPE_TO_MESSAGE = { filePath: 'a file path', webStream: 'a web stream', nodeStream: 'a Node.js stream', native: 'any value', iterable: 'an iterable', stringOrBuffer: 'a string or Uint8Array',};deleted:lib/stdio.js-289 removed
1-import {createReadStream, createWriteStream, readFileSync, writeFileSync} from 'node:fs';2-import {isAbsolute} from 'node:path';3-import {Readable, Writable} from 'node:stream';4-import {isStream as isNodeStream} from 'is-stream';5-6-const arrifyStdio = (stdio = []) => Array.isArray(stdio) ? stdio : [stdio, stdio, stdio];7-8-const isIterableStdin = stdinOption => typeof stdinOption === 'object'9- && stdinOption !== null10- && !isNodeStream(stdinOption)11- && !isReadableStream(stdinOption)12- && (typeof stdinOption[Symbol.asyncIterator] === 'function' || typeof stdinOption[Symbol.iterator] === 'function');13-14-const getIterableStdin = stdioOption => isIterableStdin(stdioOption)15- ? stdioOption16- : undefined;17-18-const isUrlInstance = stdioOption => Object.prototype.toString.call(stdioOption) === '[object URL]';19-const hasFileProtocol = url => url.protocol === 'file:';20-const isFileUrl = stdioOption => isUrlInstance(stdioOption) && hasFileProtocol(stdioOption);21-const isRegularUrl = stdioOption => isUrlInstance(stdioOption) && !hasFileProtocol(stdioOption);22-23-const stringIsFilePath = stdioOption => stdioOption.startsWith('.') || isAbsolute(stdioOption);24-const isFilePath = stdioOption => typeof stdioOption === 'string' && stringIsFilePath(stdioOption);25-const isUnknownStdioString = stdioOption => typeof stdioOption === 'string' && !stringIsFilePath(stdioOption) && !KNOWN_STDIO.has(stdioOption);26-27-const isReadableStream = stdioOption => Object.prototype.toString.call(stdioOption) === '[object ReadableStream]';28-const isWritableStream = stdioOption => Object.prototype.toString.call(stdioOption) === '[object WritableStream]';29-30-// Check whether the `stdin` option results in `spawned.stdin` being `undefined`.31-// We use a deny list instead of an allow list to be forward compatible with new options.32-const cannotPipeStdin = stdinOption => NO_PIPE_STDIO.has(stdinOption)33- || isNodeStream(stdinOption)34- || isReadableStream(stdinOption)35- || typeof stdinOption === 'number'36- || isIterableStdin(stdinOption)37- || isFileUrl(stdinOption)38- || isFilePath(stdinOption);39-40-const NO_PIPE_STDIO = new Set(['ipc', 'ignore', 'inherit']);41-const KNOWN_STDIO = new Set([...NO_PIPE_STDIO, 'overlapped', 'pipe']);42-43-const validateFileSdio = (stdioOption, optionName) => {44- if (isRegularUrl(stdioOption)) {45- throw new TypeError(`The \`${optionName}: URL\` option must use the \`file:\` scheme.46-For example, you can use the \`pathToFileURL()\` method of the \`url\` core module.`);47- }48-49- if (isUnknownStdioString(stdioOption)) {50- throw new TypeError(`The \`${optionName}: filePath\` option must either be an absolute file path or start with \`.\`.`);51- }52-};53-54-const validateInputOptions = (stdioArray, input, inputFile) => {55- if (input !== undefined && inputFile !== undefined) {56- throw new TypeError('The `input` and `inputFile` options cannot be both set.');57- }58-59- const noPipeStdin = cannotPipeStdin(stdioArray[0]);60- if (noPipeStdin && input !== undefined) {61- throw new TypeError('The `input` and `stdin` options cannot be both set.');62- }63-64- if (noPipeStdin && inputFile !== undefined) {65- throw new TypeError('The `inputFile` and `stdin` options cannot be both set.');66- }67-68- validateFileSdio(stdioArray[0], 'stdin');69- validateFileSdio(stdioArray[1], 'stdout');70- validateFileSdio(stdioArray[2], 'stderr');71-};72-73-const getStdioStreams = (stdioArray, {input, inputFile}) => [74- {...getStdinStream(stdioArray[0], input, inputFile), isInput: true},75- getOutputStream(stdioArray[1]),76- getOutputStream(stdioArray[2]),77-];78-79-const getStdinStream = (stdinOption, input, inputFile) => {80- const iterableStdin = getIterableStdin(stdinOption);81-82- if (iterableStdin !== undefined) {83- return {value: Readable.from(iterableStdin)};84- }85-86- if (isReadableStream(stdinOption)) {87- return {value: Readable.fromWeb(stdinOption)};88- }89-90- if (isFileUrl(stdinOption) || isFilePath(stdinOption)) {91- return {value: createReadStream(stdinOption), finite: true};92- }93-94- if (inputFile !== undefined) {95- return {value: createReadStream(inputFile), finite: true};96- }97-98- if (input === undefined) {99- return {};100- }101-102- if (isNodeStream(input)) {103- return {value: input};104- }105-106- return {value: input, single: true};107-};108-109-const getOutputStream = stdioOption => {110- if (isWritableStream(stdioOption)) {111- return {value: Writable.fromWeb(stdioOption)};112- }113-114- if (isFileUrl(stdioOption) || isFilePath(stdioOption)) {115- return {value: createWriteStream(stdioOption), finite: true};116- }117-118- return {};119-};120-121-// When the `stdin: Iterable | ReadableStream | URL | filePath`, `input` or `inputFile` option is used, we pipe to `spawned.std*`.122-// Therefore the `std*` options must be either `pipe` or `overlapped`. Other values do not set `spawned.std*`.123-const transformStdioItem = (stdioItem, index, stdioStreams) =>124- stdioStreams[index]?.value !== undefined && stdioItem !== 'overlapped' ? 'pipe' : stdioItem;125-126-const transformStdio = (stdio, stdioStreams) => Array.isArray(stdio)127- ? stdio.map((stdioItem, index) => transformStdioItem(stdioItem, index, stdioStreams))128- : stdio;129-130-// Handle `input`, `inputFile`, `stdin`, `stdout` and `stderr` options, before spawning, in async mode131-export const handleStdioOption = options => {132- const stdio = normalizeStdio(options);133- const stdioArray = arrifyStdio(stdio);134- validateInputOptions(stdioArray, options.input, options.inputFile);135- const stdioStreams = getStdioStreams(stdioArray, options);136- options.stdio = transformStdio(stdio, stdioStreams);137- return stdioStreams;138-};139-140-// Handle `input`, `inputFile`, `stdin`, `stdout` and `stderr` options, after spawning, in async mode141-export const pipeStdioOptions = (spawned, stdioStreams) => {142- for (const [index, stdioStream] of stdioStreams.entries()) {143- pipeStdioOption(spawned.stdio[index], stdioStream);144- }145-};146-147-const pipeStdioOption = (childStream, {single, value, isInput}) => {148- if (value === undefined) {149- return;150- }151-152- if (!isInput) {153- childStream.pipe(value);154- return;155- }156-157- if (single) {158- childStream.end(value);159- return;160- }161-162- value.pipe(childStream);163-};164-165-const transformStdioItemSync = stdioItem => isFileUrl(stdioItem) || isFilePath(stdioItem) ? 'pipe' : stdioItem;166-167-const transformStdioSync = stdio => Array.isArray(stdio)168- ? stdio.map(stdioItem => transformStdioItemSync(stdioItem))169- : stdio;170-171-const validateInputOptionsSync = (stdinOption, input) => {172- if (getIterableStdin(stdinOption) !== undefined) {173- throw new TypeError('The `stdin` option cannot be an iterable in sync mode');174- }175-176- if (isReadableStream(stdinOption)) {177- throw new TypeError('The `stdin` option cannot be a stream in sync mode');178- }179-180- if (isNodeStream(input)) {181- throw new TypeError('The `input` option cannot be a stream in sync mode');182- }183-};184-185-const validateOutputOptionsSync = (stdioOption, optionName) => {186- if (isWritableStream(stdioOption)) {187- throw new TypeError(`The \`${optionName}\` option cannot be a stream in sync mode`);188- }189-};190-191-const validateOptionsSync = (stdioArray, {input, inputFile}) => {192- validateInputOptions(stdioArray, input, inputFile);193- validateInputOptionsSync(stdioArray[0], input);194- validateOutputOptionsSync(stdioArray[1], 'stdout');195- validateOutputOptionsSync(stdioArray[2], 'stderr');196-};197-198-const getInputOption = (stdinOption, {input, inputFile}) => {199- if (isFileUrl(stdinOption) || isFilePath(stdinOption)) {200- return readFileSync(stdinOption);201- }202-203- if (inputFile !== undefined) {204- return readFileSync(inputFile);205- }206-207- return input;208-};209-210-// Handle `input`, `inputFile` and `stdin` options, before spawning, in sync mode211-export const handleInputSync = options => {212- const stdio = normalizeStdio(options);213- const stdioArray = arrifyStdio(stdio);214- validateOptionsSync(stdioArray, options);215-216- const input = getInputOption(stdioArray[0], options);217- if (input !== undefined) {218- options.input = input;219- }220-221- options.stdio = transformStdioSync(stdio);222- return stdioArray;223-};224-225-// Handle `stdout` and `stderr` options, before spawning, in sync mode226-const handleOutputOption = (stdioOption, result) => {227- if (result === null) {228- return;229- }230-231- if (isFileUrl(stdioOption) || isFilePath(stdioOption)) {232- writeFileSync(stdioOption, result);233- }234-};235-236-export const handleOutputSync = (stdioArray, {stdout, stderr}) => {237- handleOutputOption(stdioArray[1], stdout);238- handleOutputOption(stdioArray[2], stderr);239-};240-241-const aliases = ['stdin', 'stdout', 'stderr'];242-243-const hasAlias = options => aliases.some(alias => options[alias] !== undefined);244-245-export const normalizeStdio = options => {246- if (!options) {247- return;248- }249-250- const {stdio} = options;251-252- if (stdio === undefined) {253- return aliases.map(alias => options[alias]);254- }255-256- if (hasAlias(options)) {257- throw new Error(`It's not possible to provide \`stdio\` in combination with one of ${aliases.map(alias => `\`${alias}\``).join(', ')}`);258- }259-260- if (typeof stdio === 'string') {261- return stdio;262- }263-264- if (!Array.isArray(stdio)) {265- throw new TypeError(`Expected \`stdio\` to be of type \`string\` or \`Array\`, got \`${typeof stdio}\``);266- }267-268- const length = Math.max(stdio.length, aliases.length);269- return Array.from({length}, (value, index) => stdio[index]);270-};271-272-// `ipc` is pushed unless it is already present273-export const normalizeStdioNode = options => {274- const stdio = normalizeStdio(options);275-276- if (stdio === 'ipc') {277- return 'ipc';278- }279-280- if (stdio === undefined || typeof stdio === 'string') {281- return [stdio, stdio, stdio, 'ipc'];282- }283-284- if (stdio.includes('ipc')) {285- return stdio;286- }287-288- return [...stdio, 'ipc'];289-};modified:lib/stream.js+3 added-3 removed
56 unmodified lines57 // We need to handle any `error` coming from the `stdin|stdout|stderr` options.58 // However, those might be infinite streams, e.g. a TTY passed as input or output.59 // We wait for completion or not depending on whether `finite` is `true`.60 // In either case, we handle `error` events while the process is running.61-const waitForStreamEnd = ({value, finite, single}, processDone) => {62- if (value === undefined || single) {61+const waitForStreamEnd = ({value, type}, processDone) => {62+ if (type === 'native' || type === 'stringOrBuffer') {63 return;64 }65 66- return finite66+ return type === 'filePath'67 ? finished(value)68 : Promise.race([processDone, throwOnStreamError(value)]);69 };70 34 unmodified linesmodified:test/stdio.js+1 added-1 removed
1233456759 unmodified linesimport {inspect} from 'node:util';import test from 'ava';import {normalizeStdio, normalizeStdioNode} from '../lib/stdio.js';import {normalizeStdio, normalizeStdioNode} from '../lib/stdio/normalize.js';
const macro = (t, input, expected, func) => { if (expected instanceof Error) { t.throws(() => {59 unmodified linesmodified:test/stream.js+3 added-3 removed
533 unmodified lines534 535 test('input cannot be a Node.js Readable in sync mode', t => {536 t.throws(() => {537 execaSync('stdin.js', {input: new Stream.PassThrough()});538- }, {message: /The `input` option cannot be a stream in sync mode/});538+ }, {message: /The `input` option cannot be a Node\.js stream in sync mode/});539 });540 541 test('stdin cannot be a ReadableStream in sync mode', t => {542 const stdin = Stream.Readable.toWeb(Stream.Readable.from('howdy'));543 t.throws(() => {544 execaSync('stdin.js', {stdin});545- }, {message: /The `stdin` option cannot be a stream in sync mode/});545+ }, {message: /The `stdin` option cannot be a web stream in sync mode/});546 });547 548 const testWritableStreamSync = (t, streamName) => {549 t.throws(() => {550 execaSync('noop.js', {[streamName]: new WritableStream()});551- }, {message: new RegExp(`The \`${streamName}\` option cannot be a stream in sync mode`)});551+ }, {message: new RegExp(`The \`${streamName}\` option cannot be a web stream in sync mode`)});552 };553 554 test('stdout cannot be a WritableStream in sync mode', testWritableStreamSync, 'stdout');555 test('stderr cannot be a WritableStream in sync mode', testWritableStreamSync, 'stderr');207 unmodified linesmodified:index.js+7 added-5 removed
5 unmodified lines6 import stripFinalNewline from 'strip-final-newline';7 import {npmRunPathEnv} from 'npm-run-path';8 import onetime from 'onetime';9 import {makeError} from './lib/error.js';10-import {handleStdioOption, handleInputSync, handleOutputSync, pipeStdioOptions, normalizeStdioNode} from './lib/stdio.js';10+import {handleInputAsync, pipeOutputAsync} from './lib/stdio/async.js';11+import {handleInputSync, pipeOutputSync} from './lib/stdio/sync.js';12+import {normalizeStdioNode} from './lib/stdio/normalize.js';13 import {spawnedKill, spawnedCancel, setupTimeout, validateTimeout, setExitHandler} from './lib/kill.js';14 import {addPipeMethods} from './lib/pipe.js';15 import {getSpawnedResult, makeAllStream} from './lib/stream.js';16 import {mergePromise, getSpawnedPromise} from './lib/promise.js';59 unmodified lines76 };77 78 export function execa(file, args, options) {79 const parsed = handleArguments(file, args, options);78- const stdioStreams = handleStdioOption(parsed.options);80+ const stdioStreams = handleInputAsync(parsed.options);81 validateTimeout(parsed.options);82 83 const command = joinCommand(file, args);84 const escapedCommand = getEscapedCommand(file, args);74 unmodified lines159 };160 161 const handlePromiseOnce = onetime(handlePromise);162 161- pipeStdioOptions(spawned, stdioStreams);163+ pipeOutputAsync(spawned, stdioStreams);164 165 spawned.all = makeAllStream(spawned, parsed.options);166 167 addPipeMethods(spawned);2 unmodified lines170 }171 172 export function execaSync(file, args, options) {173 const parsed = handleArguments(file, args, options);172- const stdioArray = handleInputSync(parsed.options);174+ const stdioStreams = handleInputSync(parsed.options);175 176 const command = joinCommand(file, args);177 const escapedCommand = getEscapedCommand(file, args);178 logCommand(escapedCommand, parsed.options);15 unmodified lines194 killed: false,195 });196 }197 196- handleOutputSync(stdioArray, result);198+ pipeOutputSync(stdioStreams, result);199 const stdout = handleOutput(parsed.options, result.stdout, result.error);200 const stderr = handleOutput(parsed.options, result.stderr, result.error);201 202 if (result.error || result.status !== 0 || result.signal !== null) {111 unmodified lines