handle.js
This file
Path
lib/stdio/handle.js
132 lines · 5.9 KiB · JavaScript
Last changed by
Fix `lines` option (#957)ehmickybefore adoption15ab4e6
History of this fileTake it
The walk stopped after 200 commits: lines older than 249e7c4 point at it.
Print output with `verbose` option (#884)ehmickybefore adoption6fda30f
line 1why, one step back1import {handleStreamsVerbose} from '../verbose/output.js';Add support for `std*: ['pipe', 'inherit']` with `execaSync()` (#954)ehmickybefore adoptionc15edbc
line 2why, one step back2import {getStdioItemType, isRegularUrl, isUnknownStdioString, FILE_TYPES} from './type.js';Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d
line 3why, one step back3import {getStreamDirection} from './direction.js';Split files (#837)ehmickybefore adoption672c2d7
line 4why, one step back4import {normalizeStdio} from './option.js';Improve performance of `childProcess.all` when `stdout` or `stderr` is `ignore` (#646)ehmickybefore adoption249e7c4
line 5why, one step back5import {handleNativeStream} from './native.js';Allow using the `input`, `inputFile` and `stdin` options together (#666)ehmickybefore adoptionbeabd25
line 6why, one step back6import {handleInputOptions} from './input.js';Rename 2 files with wrong file names (#865)ehmickybefore adoption4bd0fe3
line 7why, one step back7import {handleStreamsEncoding} from './encoding-final.js';Refactor tests (#934)ehmickybefore adoption52c4bde
line 8why, one step back8import {normalizeTransforms, getObjectMode} from './generator.js';Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d
line 9why, one step back9import {forwardStdio, willPipeFileDescriptor} from './forward.js';Improve performance of `childProcess.all` when `stdout` or `stderr` is `ignore` (#646)ehmickybefore adoption249e7c4
lines 10–11why, one step back1011// Handle `input`, `inputFile`, `stdin`, `stdout` and `stderr` options, before spawning, in async/sync modePrint output with `verbose` option (#884)ehmickybefore adoption6fda30f
lines 12–13why, one step back12export const handleInput = (addProperties, options, verboseInfo, isSync) => {13 const stdioState = {};Add support for `buffer: false` to `execaSync()` (#953)ehmickybefore adoptiond0052ac
line 14why, one step back14 const stdio = normalizeStdio(options, isSync);Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d
lines 15–18why, one step back15 const fileDescriptors = stdio.map((stdioOption, fdNumber) =>16 getFileDescriptor({stdioOption, fdNumber, addProperties, options, isSync, stdioState, verboseInfo}));17 options.stdio = fileDescriptors.map(({stdioItems}) => forwardStdio(stdioItems));18 return {fileDescriptors, stdioState};Improve performance of `childProcess.all` when `stdout` or `stderr` is `ignore` (#646)ehmickybefore adoption249e7c4
lines 19–23why, one step back19};2021// We make sure passing an array with a single item behaves the same as passing that item without an array.22// This is what users would expect.23// For example, `stdout: ['ignore']` behaves the same as `stdout: 'ignore'`.Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d
line 24why, one step back24const getFileDescriptor = ({stdioOption, fdNumber, addProperties, options, isSync, stdioState, verboseInfo}) => {Rename `index` to `fdNumber` (#862)ehmickybefore adoption295ef40
line 25why, one step back25 const optionName = getOptionName(fdNumber);Add support for `std*: ['pipe', 'inherit']` with `execaSync()` (#954)ehmickybefore adoptionc15edbc
lines 26–28why, one step back26 const {stdioItems: initialStdioItems, isStdioArray} = initializeStdioItems({stdioOption, fdNumber, options, optionName});27 const direction = getStreamDirection(initialStdioItems, fdNumber, optionName);28 const stdioItems = initialStdioItems.map(stdioItem => handleNativeStream({stdioItem, isStdioArray, fdNumber, direction, isSync}));Add support for transforms with `execaSync()` (#945)ehmickybefore adoptionc5f9f09
lines 29–30why, one step back29 const objectMode = getObjectMode(stdioItems, optionName, direction, options);30 validateFileObjectMode(stdioItems, objectMode);Fix `lines` option (#957)ehmickybefore adoption15ab4e6
lines 31–32why, one step back31 const normalizedStdioItems = normalizeStdioItems({stdioItems, fdNumber, optionName, addProperties, options, direction, stdioState, verboseInfo, objectMode});32 return {direction, objectMode, stdioItems: normalizedStdioItems};Simplify `stdio` logic (#663)ehmickybefore adoption66d0efb
line 33why, one step back33};Improve performance of `childProcess.all` when `stdout` or `stderr` is `ignore` (#646)ehmickybefore adoption249e7c4
line 34why, one step back34Rename `index` to `fdNumber` (#862)ehmickybefore adoption295ef40
line 35why, one step back35const getOptionName = fdNumber => KNOWN_OPTION_NAMES[fdNumber] ?? `stdio[${fdNumber}]`;Simplify `stdio` logic (#663)ehmickybefore adoption66d0efb
line 36why, one step back36const KNOWN_OPTION_NAMES = ['stdin', 'stdout', 'stderr'];Improve performance of `childProcess.all` when `stdout` or `stderr` is `ignore` (#646)ehmickybefore adoption249e7c4
line 37why, one step back37Add support for `std*: ['pipe', 'inherit']` with `execaSync()` (#954)ehmickybefore adoptionc15edbc
line 38why, one step back38const initializeStdioItems = ({stdioOption, fdNumber, options, optionName}) => {Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d
lines 39–48why, one step back39 const values = Array.isArray(stdioOption) ? stdioOption : [stdioOption];40 const initialStdioItems = [41 ...values.map(value => initializeStdioItem(value, optionName)),42 ...handleInputOptions(options, fdNumber),43 ];4445 const stdioItems = filterDuplicates(initialStdioItems);46 const isStdioArray = stdioItems.length > 1;47 validateStdioArray(stdioItems, isStdioArray, optionName);48 validateStreams(stdioItems);Add support for `std*: ['pipe', 'inherit']` with `execaSync()` (#954)ehmickybefore adoptionc15edbc
line 49why, one step back49 return {stdioItems, isStdioArray};Add passing the same transform multiple times (#697)ehmickybefore adoption35ec8de
lines 50–51why, one step back50};51Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d
lines 52–56why, one step back52const initializeStdioItem = (value, optionName) => ({53 type: getStdioItemType(value, optionName),54 value,55 optionName,56});Add passing the same transform multiple times (#697)ehmickybefore adoption35ec8de
line 57why, one step back57Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d
line 58why, one step back58const filterDuplicates = stdioItems => stdioItems.filter((stdioItemOne, indexOne) =>Add support for transforms with `execaSync()` (#945)ehmickybefore adoptionc5f9f09
lines 59–62why, one step back59 stdioItems.every((stdioItemTwo, indexTwo) => stdioItemOne.value !== stdioItemTwo.value60 || indexOne >= indexTwo61 || stdioItemOne.type === 'generator'62 || stdioItemOne.type === 'asyncGenerator'));Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d
lines 63–65why, one step back6364const validateStdioArray = (stdioItems, isStdioArray, optionName) => {65 if (stdioItems.length === 0) {Improve performance of `childProcess.all` when `stdout` or `stderr` is `ignore` (#646)ehmickybefore adoption249e7c4
lines 66–68why, one step back66 throw new TypeError(`The \`${optionName}\` option must not be an empty array.`);67 }68Simplify `stdio` logic (#663)ehmickybefore adoption66d0efb
lines 69–70why, one step back69 if (!isStdioArray) {70 return;Improve performance of `childProcess.all` when `stdout` or `stderr` is `ignore` (#646)ehmickybefore adoption249e7c4
lines 71–72why, one step back71 }72Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d
line 73why, one step back73 for (const {value, optionName} of stdioItems) {Add passing the same transform multiple times (#697)ehmickybefore adoption35ec8de
lines 74–75why, one step back74 if (INVALID_STDIO_ARRAY_OPTIONS.has(value)) {75 throw new Error(`The \`${optionName}\` option must not include \`${value}\`.`);Improve performance of `childProcess.all` when `stdout` or `stderr` is `ignore` (#646)ehmickybefore adoption249e7c4
lines 76–81why, one step back76 }77 }78};7980// Using those `stdio` values together with others for the same stream does not make sense, so we make it fail.81// However, we do allow it if the array has a single item.Add passing the same transform multiple times (#697)ehmickybefore adoption35ec8de
line 82why, one step back82const INVALID_STDIO_ARRAY_OPTIONS = new Set(['ignore', 'ipc']);Improve performance of `childProcess.all` when `stdout` or `stderr` is `ignore` (#646)ehmickybefore adoption249e7c4
line 83why, one step back83Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d
lines 84–86why, one step back84const validateStreams = stdioItems => {85 for (const stdioItem of stdioItems) {86 validateFileStdio(stdioItem);Allow using the `input`, `inputFile` and `stdin` options together (#666)ehmickybefore adoptionbeabd25
line 87why, one step back87 }Improve performance of `childProcess.all` when `stdout` or `stderr` is `ignore` (#646)ehmickybefore adoption249e7c4
lines 88–96why, one step back88};8990const validateFileStdio = ({type, value, optionName}) => {91 if (isRegularUrl(value)) {92 throw new TypeError(`The \`${optionName}: URL\` option must use the \`file:\` scheme.93For example, you can use the \`pathToFileURL()\` method of the \`url\` core module.`);94 }9596 if (isUnknownStdioString(type, value)) {Improve syntax of `std*: filePath` option (#671)ehmickybefore adoption90e0e13
line 97why, one step back97 throw new TypeError(`The \`${optionName}: { file: '...' }\` option must be used instead of \`${optionName}: '...'\`.`);Improve performance of `childProcess.all` when `stdout` or `stderr` is `ignore` (#646)ehmickybefore adoption249e7c4
lines 98–100why, one step back98 }99};100Fix `lines` option (#957)ehmickybefore adoption15ab4e6
lines 101–102why, one step back101const normalizeStdioItems = ({stdioItems, fdNumber, optionName, addProperties, options, direction, stdioState, verboseInfo, objectMode}) => {102 const allStdioItems = addInternalStdioItems({stdioItems, fdNumber, optionName, options, direction, stdioState, verboseInfo, objectMode});Add support for `std*: duplex` option (#937)ehmickybefore adoption6ca44fb
line 103why, one step back103 const normalizedStdioItems = normalizeTransforms(allStdioItems, optionName, direction, options);Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d
lines 104–106why, one step back104 return normalizedStdioItems.map(stdioItem => addStreamProperties(stdioItem, addProperties, direction));105};106Fix `lines` option (#957)ehmickybefore adoption15ab4e6
line 107why, one step back107const addInternalStdioItems = ({stdioItems, fdNumber, optionName, options, direction, stdioState, verboseInfo, objectMode}) => willPipeFileDescriptor(stdioItems)Add support for transforms with `execaSync()` (#945)ehmickybefore adoptionc5f9f09
line 108why, one step back108 ? [Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d
line 109why, one step back109 ...stdioItems,Add support for transforms with `execaSync()` (#945)ehmickybefore adoptionc5f9f09
line 110why, one step back110 ...handleStreamsEncoding({options, direction, optionName, objectMode}),Add support for `verbose` option to `execaSync()` (#950)ehmickybefore adoptioned052d4
line 111why, one step back111 ...handleStreamsVerbose({stdioItems, options, stdioState, verboseInfo, fdNumber, optionName}),Add support for transforms with `execaSync()` (#945)ehmickybefore adoptionc5f9f09
lines 112–113why, one step back112 ]113 : stdioItems;Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d
line 114why, one step back114Improve performance of `childProcess.all` when `stdout` or `stderr` is `ignore` (#646)ehmickybefore adoption249e7c4
lines 115–117why, one step back115// Some `stdio` values require Execa to create streams.116// For example, file paths create file read/write streams.117// Those transformations are specified in `addProperties`, which is both direction-specific and type-specific.Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d
lines 118–121why, one step back118const addStreamProperties = (stdioItem, addProperties, direction) => ({119 ...stdioItem,120 ...addProperties[direction][stdioItem.type](stdioItem),121});Add support for transforms with `execaSync()` (#945)ehmickybefore adoptionc5f9f09
lines 122–127why, one step back122123const validateFileObjectMode = (stdioItems, objectMode) => {124 if (!objectMode) {125 return;126 }127Add support for `std*: ['pipe', 'inherit']` with `execaSync()` (#954)ehmickybefore adoptionc15edbc
line 128why, one step back128 const fileStdioItem = stdioItems.find(({type}) => FILE_TYPES.has(type));Add support for transforms with `execaSync()` (#945)ehmickybefore adoptionc5f9f09
lines 129–132why, one step back129 if (fileStdioItem !== undefined) {130 throw new TypeError(`The \`${fileStdioItem.optionName}\` option cannot use both files and transforms in objectMode.`);131 }132};