pipe-arguments.js
This file
Path
lib/pipe/pipe-arguments.js
90 lines · 3.2 KiB · JavaScript
Last changed by
Add more code comments (#984)ehmickybefore adoptionfdd8a9f
History of this fileTake it
Rename files (#977)ehmickybefore adoption4b2e316
lines 1–2why, one step back1import {normalizeParameters} from '../methods/parameters.js';2import {getStartTime} from '../return/duration.js';Refactor logic and rename some variables (#983)ehmickybefore adoptionbd3b478
line 3why, one step back3import {SUBPROCESS_OPTIONS, getToStream, getFromStream} from '../arguments/fd-options.js';Rename files (#977)ehmickybefore adoption4b2e316
line 4why, one step back4Add more code comments (#984)ehmickybefore adoptionfdd8a9f
line 5why, one step back5// Normalize and validate arguments passed to `source.pipe(destination)`Upgrade xo (#980)ehmickybefore adoptionccfa412
line 6why, one step back6export const normalizePipeArguments = ({source, sourcePromise, boundOptions, createNested}, ...pipeArguments) => {Rename files (#977)ehmickybefore adoption4b2e316
lines 7–13why, one step back7 const startTime = getStartTime();8 const {9 destination,10 destinationStream,11 destinationError,12 from,13 unpipeSignal,Upgrade xo (#980)ehmickybefore adoptionccfa412
line 14why, one step back14 } = getDestinationStream(boundOptions, createNested, pipeArguments);Rename files (#977)ehmickybefore adoption4b2e316
lines 15–30why, one step back15 const {sourceStream, sourceError} = getSourceStream(source, from);16 const {options: sourceOptions, fileDescriptors} = SUBPROCESS_OPTIONS.get(source);17 return {18 sourcePromise,19 sourceStream,20 sourceOptions,21 sourceError,22 destination,23 destinationStream,24 destinationError,25 unpipeSignal,26 fileDescriptors,27 startTime,28 };29};30Upgrade xo (#980)ehmickybefore adoptionccfa412
line 31why, one step back31const getDestinationStream = (boundOptions, createNested, pipeArguments) => {Rename files (#977)ehmickybefore adoption4b2e316
lines 32–35why, one step back32 try {33 const {34 destination,35 pipeOptions: {from, to, unpipeSignal} = {},Upgrade xo (#980)ehmickybefore adoptionccfa412
line 36why, one step back36 } = getDestination(boundOptions, createNested, ...pipeArguments);Refactor logic and rename some variables (#983)ehmickybefore adoptionbd3b478
line 37why, one step back37 const destinationStream = getToStream(destination, to);Upgrade xo (#980)ehmickybefore adoptionccfa412
lines 38–43why, one step back38 return {39 destination,40 destinationStream,41 from,42 unpipeSignal,43 };Rename files (#977)ehmickybefore adoption4b2e316
lines 44–48why, one step back44 } catch (error) {45 return {destinationError: error};46 }47};48Add more code comments (#984)ehmickybefore adoptionfdd8a9f
lines 49–52why, one step back49// Piping subprocesses can use three syntaxes:50// - source.pipe('command', commandArguments, pipeOptionsOrDestinationOptions)51// - source.pipe`command commandArgument` or source.pipe(pipeOptionsOrDestinationOptions)`command commandArgument`52// - source.pipe(execa(...), pipeOptions)Upgrade xo (#980)ehmickybefore adoptionccfa412
line 53why, one step back53const getDestination = (boundOptions, createNested, firstArgument, ...pipeArguments) => {Rename files (#977)ehmickybefore adoption4b2e316
line 54why, one step back54 if (Array.isArray(firstArgument)) {Upgrade xo (#980)ehmickybefore adoptionccfa412
line 55why, one step back55 const destination = createNested(mapDestinationArguments, boundOptions)(firstArgument, ...pipeArguments);Rename files (#977)ehmickybefore adoption4b2e316
lines 56–63why, one step back56 return {destination, pipeOptions: boundOptions};57 }5859 if (typeof firstArgument === 'string' || firstArgument instanceof URL) {60 if (Object.keys(boundOptions).length > 0) {61 throw new TypeError('Please use .pipe("file", ..., options) or .pipe(execa("file", ..., options)) instead of .pipe(options)("file", ...).');62 }63Upgrade xo (#980)ehmickybefore adoptionccfa412
lines 64–65why, one step back64 const [rawFile, rawArguments, rawOptions] = normalizeParameters(firstArgument, ...pipeArguments);65 const destination = createNested(mapDestinationArguments)(rawFile, rawArguments, rawOptions);Rename files (#977)ehmickybefore adoption4b2e316
lines 66–73why, one step back66 return {destination, pipeOptions: rawOptions};67 }6869 if (SUBPROCESS_OPTIONS.has(firstArgument)) {70 if (Object.keys(boundOptions).length > 0) {71 throw new TypeError('Please use .pipe(options)`command` or .pipe($(options)`command`) instead of .pipe(options)($`command`).');72 }73Upgrade xo (#980)ehmickybefore adoptionccfa412
line 74why, one step back74 return {destination: firstArgument, pipeOptions: pipeArguments[0]};Rename files (#977)ehmickybefore adoption4b2e316
lines 75–79why, one step back75 }7677 throw new TypeError(`The first argument must be a template string, an options object, or an Execa subprocess: ${firstArgument}`);78};79Add more code comments (#984)ehmickybefore adoptionfdd8a9f
line 80why, one step back80// Force `stdin: 'pipe'` with the destination subprocessRename files (#977)ehmickybefore adoption4b2e316
lines 81–84why, one step back81const mapDestinationArguments = ({options}) => ({options: {...options, stdin: 'pipe', piped: true}});8283const getSourceStream = (source, from) => {84 try {Refactor logic and rename some variables (#983)ehmickybefore adoptionbd3b478
line 85why, one step back85 const sourceStream = getFromStream(source, from);Rename files (#977)ehmickybefore adoption4b2e316
lines 86–90why, one step back86 return {sourceStream};87 } catch (error) {88 return {sourceError: error};89 }90};