option.js
This file
Path
lib/stdio/option.js
53 lines · 2.0 KiB · JavaScript
Last changed by
Add support for `buffer: false` to `execaSync()` (#953)ehmickybefore adoptiond0052ac
History of this fileTake it
Split files (#837)ehmickybefore adoption672c2d7
lines 1–3why, one step back1import {STANDARD_STREAMS_ALIASES} from '../utils.js';23// Add support for `stdin`/`stdout`/`stderr` as an alias for `stdio`Add support for `buffer: false` to `execaSync()` (#953)ehmickybefore adoptiond0052ac
line 4why, one step back4export const normalizeStdio = ({stdio, ipc, buffer, verbose, ...options}, isSync) => {Fix `stdio: [..., undefined]` option (#948)ehmickybefore adoption96d2ef7
line 5why, one step back5 const stdioArray = getStdioArray(stdio, options).map((stdioOption, fdNumber) => addDefaultValue(stdioOption, fdNumber));Add support for `buffer: false` to `execaSync()` (#953)ehmickybefore adoptiond0052ac
line 6why, one step back6 return isSync ? normalizeStdioSync(stdioArray, buffer, verbose) : normalizeStdioAsync(stdioArray, ipc);Split files (#837)ehmickybefore adoption672c2d7
lines 7–26why, one step back7};89const getStdioArray = (stdio, options) => {10 if (stdio === undefined) {11 return STANDARD_STREAMS_ALIASES.map(alias => options[alias]);12 }1314 if (hasAlias(options)) {15 throw new Error(`It's not possible to provide \`stdio\` in combination with one of ${STANDARD_STREAMS_ALIASES.map(alias => `\`${alias}\``).join(', ')}`);16 }1718 if (typeof stdio === 'string') {19 return [stdio, stdio, stdio];20 }2122 if (!Array.isArray(stdio)) {23 throw new TypeError(`Expected \`stdio\` to be of type \`string\` or \`Array\`, got \`${typeof stdio}\``);24 }2526 const length = Math.max(stdio.length, STANDARD_STREAMS_ALIASES.length);Fix `stdio: [..., undefined]` option (#948)ehmickybefore adoption96d2ef7
line 27why, one step back27 return Array.from({length}, (_, fdNumber) => stdio[fdNumber]);Split files (#837)ehmickybefore adoption672c2d7
lines 28–30why, one step back28};2930const hasAlias = options => STANDARD_STREAMS_ALIASES.some(alias => options[alias] !== undefined);Fix `stdio: [..., undefined]` option (#948)ehmickybefore adoption96d2ef7
lines 31–32why, one step back3132const addDefaultValue = (stdioOption, fdNumber) => {Fix types for `stdio: [..., undefined]` (#952)ehmickybefore adoption6233874
lines 33–36why, one step back33 if (Array.isArray(stdioOption)) {34 return stdioOption.map(item => addDefaultValue(item, fdNumber));35 }36Fix `stdio: [..., undefined]` option (#948)ehmickybefore adoption96d2ef7
lines 37–42why, one step back37 if (stdioOption === null || stdioOption === undefined) {38 return fdNumber >= STANDARD_STREAMS_ALIASES.length ? 'ignore' : 'pipe';39 }4041 return stdioOption;42};Add support for `buffer: false` to `execaSync()` (#953)ehmickybefore adoptiond0052ac
lines 43–53why, one step back4344const normalizeStdioSync = (stdioArray, buffer, verbose) => buffer || verbose === 'full'45 ? stdioArray46 : stdioArray.map((stdioOption, fdNumber) => fdNumber !== 0 && isOutputPipeOnly(stdioOption) ? 'ignore' : stdioOption);4748const isOutputPipeOnly = stdioOption => stdioOption === 'pipe'49 || (Array.isArray(stdioOption) && stdioOption.every(item => item === 'pipe'));5051const normalizeStdioAsync = (stdioArray, ipc) => ipc && !stdioArray.includes('ipc')52 ? [...stdioArray, 'ipc']53 : stdioArray;