handle.js
This file
Path
lib/stdio/handle.js
134 lines · 6.0 KiB · JavaScript
Last changed by
Add support for `verbose` option to `execaSync()` (#950)ehmickybefore adoptioned052d4
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';Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d
lines 2–3why, one step back2import {getStdioItemType, isRegularUrl, isUnknownStdioString} from './type.js';3import {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';Strip newlines in transforms (#919)ehmickybefore adoption26e9150
line 7why, one step back7import {handleStreamsLines} from './lines.js';Rename 2 files with wrong file names (#865)ehmickybefore adoption4bd0fe3
line 8why, one step back8import {handleStreamsEncoding} from './encoding-final.js';Refactor tests (#934)ehmickybefore adoption52c4bde
line 9why, one step back9import {normalizeTransforms, getObjectMode} from './generator.js';Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d
line 10why, one step back10import {forwardStdio, willPipeFileDescriptor} from './forward.js';Improve performance of `childProcess.all` when `stdout` or `stderr` is `ignore` (#646)ehmickybefore adoption249e7c4
lines 11–12why, one step back1112// Handle `input`, `inputFile`, `stdin`, `stdout` and `stderr` options, before spawning, in async/sync modePrint output with `verbose` option (#884)ehmickybefore adoption6fda30f
lines 13–14why, one step back13export const handleInput = (addProperties, options, verboseInfo, isSync) => {14 const stdioState = {};Improve performance of `childProcess.all` when `stdout` or `stderr` is `ignore` (#646)ehmickybefore adoption249e7c4
line 15why, one step back15 const stdio = normalizeStdio(options);Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d
lines 16–19why, one step back16 const fileDescriptors = stdio.map((stdioOption, fdNumber) =>17 getFileDescriptor({stdioOption, fdNumber, addProperties, options, isSync, stdioState, verboseInfo}));18 options.stdio = fileDescriptors.map(({stdioItems}) => forwardStdio(stdioItems));19 return {fileDescriptors, stdioState};Improve performance of `childProcess.all` when `stdout` or `stderr` is `ignore` (#646)ehmickybefore adoption249e7c4
lines 20–24why, one step back20};2122// We make sure passing an array with a single item behaves the same as passing that item without an array.23// This is what users would expect.24// For example, `stdout: ['ignore']` behaves the same as `stdout: 'ignore'`.Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d
line 25why, one step back25const getFileDescriptor = ({stdioOption, fdNumber, addProperties, options, isSync, stdioState, verboseInfo}) => {Simplify `lines` option (#929)ehmickybefore adoptiond30fcbc
line 26why, one step back26 const outputLines = [];Rename `index` to `fdNumber` (#862)ehmickybefore adoption295ef40
line 27why, one step back27 const optionName = getOptionName(fdNumber);Improve validation of `execaSync()` `stdio` option (#941)ehmickybefore adoptioncc565f9
line 28why, one step back28 const stdioItems = initializeStdioItems({stdioOption, fdNumber, options, isSync, optionName});Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d
line 29why, one step back29 const direction = getStreamDirection(stdioItems, fdNumber, optionName);Add support for transforms with `execaSync()` (#945)ehmickybefore adoptionc5f9f09
lines 30–32why, one step back30 const objectMode = getObjectMode(stdioItems, optionName, direction, options);31 validateFileObjectMode(stdioItems, objectMode);32 const normalizedStdioItems = normalizeStdioItems({stdioItems, fdNumber, optionName, addProperties, options, isSync, direction, stdioState, verboseInfo, outputLines, objectMode});Simplify `lines` option (#929)ehmickybefore adoptiond30fcbc
line 33why, one step back33 return {fdNumber, direction, outputLines, stdioItems: normalizedStdioItems};Simplify `stdio` logic (#663)ehmickybefore adoption66d0efb
line 34why, one step back34};Improve performance of `childProcess.all` when `stdout` or `stderr` is `ignore` (#646)ehmickybefore adoption249e7c4
line 35why, one step back35Rename `index` to `fdNumber` (#862)ehmickybefore adoption295ef40
line 36why, one step back36const getOptionName = fdNumber => KNOWN_OPTION_NAMES[fdNumber] ?? `stdio[${fdNumber}]`;Simplify `stdio` logic (#663)ehmickybefore adoption66d0efb
line 37why, one step back37const KNOWN_OPTION_NAMES = ['stdin', 'stdout', 'stderr'];Improve performance of `childProcess.all` when `stdout` or `stderr` is `ignore` (#646)ehmickybefore adoption249e7c4
line 38why, one step back38Improve validation of `execaSync()` `stdio` option (#941)ehmickybefore adoptioncc565f9
line 39why, one step back39const initializeStdioItems = ({stdioOption, fdNumber, options, isSync, optionName}) => {Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d
lines 40–49why, one step back40 const values = Array.isArray(stdioOption) ? stdioOption : [stdioOption];41 const initialStdioItems = [42 ...values.map(value => initializeStdioItem(value, optionName)),43 ...handleInputOptions(options, fdNumber),44 ];4546 const stdioItems = filterDuplicates(initialStdioItems);47 const isStdioArray = stdioItems.length > 1;48 validateStdioArray(stdioItems, isStdioArray, optionName);49 validateStreams(stdioItems);Improve validation of `execaSync()` `stdio` option (#941)ehmickybefore adoptioncc565f9
line 50why, one step back50 return stdioItems.map(stdioItem => handleNativeStream(stdioItem, isStdioArray, fdNumber, isSync));Add passing the same transform multiple times (#697)ehmickybefore adoption35ec8de
lines 51–52why, one step back51};52Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d
lines 53–57why, one step back53const initializeStdioItem = (value, optionName) => ({54 type: getStdioItemType(value, optionName),55 value,56 optionName,57});Add passing the same transform multiple times (#697)ehmickybefore adoption35ec8de
line 58why, one step back58Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d
line 59why, one step back59const filterDuplicates = stdioItems => stdioItems.filter((stdioItemOne, indexOne) =>Add support for transforms with `execaSync()` (#945)ehmickybefore adoptionc5f9f09
lines 60–63why, one step back60 stdioItems.every((stdioItemTwo, indexTwo) => stdioItemOne.value !== stdioItemTwo.value61 || indexOne >= indexTwo62 || stdioItemOne.type === 'generator'63 || stdioItemOne.type === 'asyncGenerator'));Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d
lines 64–66why, one step back6465const validateStdioArray = (stdioItems, isStdioArray, optionName) => {66 if (stdioItems.length === 0) {Improve performance of `childProcess.all` when `stdout` or `stderr` is `ignore` (#646)ehmickybefore adoption249e7c4
lines 67–69why, one step back67 throw new TypeError(`The \`${optionName}\` option must not be an empty array.`);68 }69Simplify `stdio` logic (#663)ehmickybefore adoption66d0efb
lines 70–71why, one step back70 if (!isStdioArray) {71 return;Improve performance of `childProcess.all` when `stdout` or `stderr` is `ignore` (#646)ehmickybefore adoption249e7c4
lines 72–73why, one step back72 }73Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d
line 74why, one step back74 for (const {value, optionName} of stdioItems) {Add passing the same transform multiple times (#697)ehmickybefore adoption35ec8de
lines 75–76why, one step back75 if (INVALID_STDIO_ARRAY_OPTIONS.has(value)) {76 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 77–82why, one step back77 }78 }79};8081// Using those `stdio` values together with others for the same stream does not make sense, so we make it fail.82// However, we do allow it if the array has a single item.Add passing the same transform multiple times (#697)ehmickybefore adoption35ec8de
line 83why, one step back83const INVALID_STDIO_ARRAY_OPTIONS = new Set(['ignore', 'ipc']);Improve performance of `childProcess.all` when `stdout` or `stderr` is `ignore` (#646)ehmickybefore adoption249e7c4
line 84why, one step back84Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d
lines 85–87why, one step back85const validateStreams = stdioItems => {86 for (const stdioItem of stdioItems) {87 validateFileStdio(stdioItem);Allow using the `input`, `inputFile` and `stdin` options together (#666)ehmickybefore adoptionbeabd25
line 88why, one step back88 }Improve performance of `childProcess.all` when `stdout` or `stderr` is `ignore` (#646)ehmickybefore adoption249e7c4
lines 89–97why, one step back89};9091const validateFileStdio = ({type, value, optionName}) => {92 if (isRegularUrl(value)) {93 throw new TypeError(`The \`${optionName}: URL\` option must use the \`file:\` scheme.94For example, you can use the \`pathToFileURL()\` method of the \`url\` core module.`);95 }9697 if (isUnknownStdioString(type, value)) {Improve syntax of `std*: filePath` option (#671)ehmickybefore adoption90e0e13
line 98why, one step back98 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 99–101why, one step back99 }100};101Add support for transforms with `execaSync()` (#945)ehmickybefore adoptionc5f9f09
lines 102–103why, one step back102const normalizeStdioItems = ({stdioItems, fdNumber, optionName, addProperties, options, isSync, direction, stdioState, verboseInfo, outputLines, objectMode}) => {103 const allStdioItems = addInternalStdioItems({stdioItems, fdNumber, optionName, options, isSync, direction, stdioState, verboseInfo, outputLines, objectMode});Add support for `std*: duplex` option (#937)ehmickybefore adoption6ca44fb
line 104why, one step back104 const normalizedStdioItems = normalizeTransforms(allStdioItems, optionName, direction, options);Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d
lines 105–107why, one step back105 return normalizedStdioItems.map(stdioItem => addStreamProperties(stdioItem, addProperties, direction));106};107Add support for transforms with `execaSync()` (#945)ehmickybefore adoptionc5f9f09
lines 108–109why, one step back108const addInternalStdioItems = ({stdioItems, fdNumber, optionName, options, isSync, direction, stdioState, verboseInfo, outputLines, objectMode}) => willPipeFileDescriptor(stdioItems)109 ? [Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d
line 110why, one step back110 ...stdioItems,Add support for transforms with `execaSync()` (#945)ehmickybefore adoptionc5f9f09
line 111why, one step back111 ...handleStreamsEncoding({options, direction, optionName, objectMode}),Add support for `verbose` option to `execaSync()` (#950)ehmickybefore adoptioned052d4
line 112why, one step back112 ...handleStreamsVerbose({stdioItems, options, stdioState, verboseInfo, fdNumber, optionName}),Simplify `lines` option (#929)ehmickybefore adoptiond30fcbc
line 113why, one step back113 ...handleStreamsLines({options, isSync, direction, optionName, objectMode, outputLines}),Add support for transforms with `execaSync()` (#945)ehmickybefore adoptionc5f9f09
lines 114–115why, one step back114 ]115 : stdioItems;Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d
line 116why, one step back116Improve performance of `childProcess.all` when `stdout` or `stderr` is `ignore` (#646)ehmickybefore adoption249e7c4
lines 117–119why, one step back117// Some `stdio` values require Execa to create streams.118// For example, file paths create file read/write streams.119// Those transformations are specified in `addProperties`, which is both direction-specific and type-specific.Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d
lines 120–123why, one step back120const addStreamProperties = (stdioItem, addProperties, direction) => ({121 ...stdioItem,122 ...addProperties[direction][stdioItem.type](stdioItem),123});Add support for transforms with `execaSync()` (#945)ehmickybefore adoptionc5f9f09
lines 124–134why, one step back124125const validateFileObjectMode = (stdioItems, objectMode) => {126 if (!objectMode) {127 return;128 }129130 const fileStdioItem = stdioItems.find(({type}) => type === 'fileUrl' || type === 'filePath');131 if (fileStdioItem !== undefined) {132 throw new TypeError(`The \`${fileStdioItem.optionName}\` option cannot use both files and transforms in objectMode.`);133 }134};