Skip to content
Myr

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 file

Take it

Rename files (#977)ehmickybefore adoption4b2e316

lines 1–2why, one step back
1import {normalizeParameters} from '../methods/parameters.js';
2import {getStartTime} from '../return/duration.js';

Refactor logic and rename some variables (#983)ehmickybefore adoptionbd3b478

line 3why, one step back
3import {SUBPROCESS_OPTIONS, getToStream, getFromStream} from '../arguments/fd-options.js';

Rename files (#977)ehmickybefore adoption4b2e316

line 4why, one step back
4

Add more code comments (#984)ehmickybefore adoptionfdd8a9f

line 5why, one step back
5// Normalize and validate arguments passed to `source.pipe(destination)`

Upgrade xo (#980)ehmickybefore adoptionccfa412

line 6why, one step back
6export const normalizePipeArguments = ({source, sourcePromise, boundOptions, createNested}, ...pipeArguments) => {

Rename files (#977)ehmickybefore adoption4b2e316

lines 7–13why, one step back
7 const startTime = getStartTime();
8 const {9 destination,10 destinationStream,11 destinationError,12 from,13 unpipeSignal,

Upgrade xo (#980)ehmickybefore adoptionccfa412

line 14why, one step back
14 } = getDestinationStream(boundOptions, createNested, pipeArguments);

Rename files (#977)ehmickybefore adoption4b2e316

lines 15–30why, one step back
15 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};30

Upgrade xo (#980)ehmickybefore adoptionccfa412

line 31why, one step back
31const getDestinationStream = (boundOptions, createNested, pipeArguments) => {

Rename files (#977)ehmickybefore adoption4b2e316

lines 32–35why, one step back
32 try {
33 const {34 destination,35 pipeOptions: {from, to, unpipeSignal} = {},

Upgrade xo (#980)ehmickybefore adoptionccfa412

line 36why, one step back
36 } = getDestination(boundOptions, createNested, ...pipeArguments);

Refactor logic and rename some variables (#983)ehmickybefore adoptionbd3b478

line 37why, one step back
37 const destinationStream = getToStream(destination, to);

Upgrade xo (#980)ehmickybefore adoptionccfa412

lines 38–43why, one step back
38 return {
39 destination,40 destinationStream,41 from,42 unpipeSignal,43 };

Rename files (#977)ehmickybefore adoption4b2e316

lines 44–48why, one step back
44 } catch (error) {
45 return {destinationError: error};46 }47};48

Add more code comments (#984)ehmickybefore adoptionfdd8a9f

lines 49–52why, one step back
49// 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 back
53const getDestination = (boundOptions, createNested, firstArgument, ...pipeArguments) => {

Rename files (#977)ehmickybefore adoption4b2e316

line 54why, one step back
54 if (Array.isArray(firstArgument)) {

Upgrade xo (#980)ehmickybefore adoptionccfa412

line 55why, one step back
55 const destination = createNested(mapDestinationArguments, boundOptions)(firstArgument, ...pipeArguments);

Rename files (#977)ehmickybefore adoption4b2e316

lines 56–63why, one step back
56 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 }63

Upgrade xo (#980)ehmickybefore adoptionccfa412

lines 64–65why, one step back
64 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 back
66 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 }73

Upgrade xo (#980)ehmickybefore adoptionccfa412

line 74why, one step back
74 return {destination: firstArgument, pipeOptions: pipeArguments[0]};

Rename files (#977)ehmickybefore adoption4b2e316

lines 75–79why, one step back
75 }
7677 throw new TypeError(`The first argument must be a template string, an options object, or an Execa subprocess: ${firstArgument}`);78};79

Add more code comments (#984)ehmickybefore adoptionfdd8a9f

line 80why, one step back
80// Force `stdin: 'pipe'` with the destination subprocess

Rename files (#977)ehmickybefore adoption4b2e316

lines 81–84why, one step back
81const 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 back
85 const sourceStream = getFromStream(source, from);

Rename files (#977)ehmickybefore adoption4b2e316

lines 86–90why, one step back
86 return {sourceStream};
87 } catch (error) {88 return {sourceError: error};89 }90};