Improve `.pipe()` method (#859)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by ehmicky · committed by GitHub · parent aeb8194 · Browse files · 11 files·+159 added−113 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
11 files+159 added−113 removed
- tests:+78 added−10 removed
- other:+81 added−103 removed
Provenance
- Commit
2ef9e86- Tree
e75656d- Author
ehmicky <ehmicky@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent
aeb8194
11 files changed+159 added−113 removed
modified:lib/pipe/sequence.js+2 added-2 removed
123455678991011121311 unmodified lines// Like Bash, we await both processes. This is unlike some other shells which only await the destination process.// Like Bash with the `pipefail` option, if either process fails, the whole pipe fails.// Like Bash, if both processes fail, we return the failure of the destination.// This ensures both processes' errors are present, using `error.pipedFrom`.export const waitForBothProcesses = async (sourcePromise, destination) => {export const waitForBothProcesses = async processPromises => { const [ {status: sourceStatus, reason: sourceReason, value: sourceResult = sourceReason}, {status: destinationStatus, reason: destinationReason, value: destinationResult = destinationReason}, ] = await Promise.allSettled([sourcePromise, destination]); ] = await processPromises;
if (!destinationResult.pipedFrom.includes(sourceResult)) { destinationResult.pipedFrom.push(sourceResult); }11 unmodified linesmodified:lib/pipe/setup.js+16 added-4 removed
1234567891011121314151617181119202122236 unmodified lines3031323334352736373038394041424344454640474849505152535455565758import isPlainObject from 'is-plain-obj';import {normalizePipeArguments} from './validate.js';import {handlePipeArgumentsError} from './throw.js';import {waitForBothProcesses} from './sequence.js';import {pipeProcessStream} from './streaming.js';import {unpipeOnAbort} from './abort.js';
// Pipe a process' `stdout`/`stderr`/`stdio` into another process' `stdin`export const pipeToProcess = (sourceInfo, ...args) => { if (isPlainObject(args[0])) { return pipeToProcess.bind(undefined, { ...sourceInfo, destinationOptions: {...sourceInfo.destinationOptions, ...args[0]}, }); }
const {destination, ...normalizedInfo} = normalizePipeArguments(sourceInfo, ...args); const promise = handlePipePromise({...normalizedInfo, destination}); promise.pipe = pipeToProcess.bind(undefined, {...sourceInfo, source: destination, sourcePromise: promise}); promise.pipe = pipeToProcess.bind(undefined, {...sourceInfo, source: destination, sourcePromise: promise, destinationOptions: {}}); return promise;};
const handlePipePromise = async ({6 unmodified lines destinationError, unpipeSignal, stdioStreamsGroups,}) => { const processPromises = getProcessPromises(sourcePromise, destination); handlePipeArgumentsError({ sourcePromise, sourceStream, sourceError, destination, destinationStream, destinationError, stdioStreamsGroups, sourceOptions, }); const maxListenersController = new AbortController(); try { const mergedStream = pipeProcessStream(sourceStream, destinationStream, maxListenersController); return await Promise.race([ waitForBothProcesses(sourcePromise, destination), waitForBothProcesses(processPromises), ...unpipeOnAbort(unpipeSignal, {sourceStream, mergedStream, sourceOptions, stdioStreamsGroups}), ]); } finally { maxListenersController.abort(); }};
// `.pipe()` awaits the child process promises.// When invalid arguments are passed to `.pipe()`, we throw an error, which prevents awaiting them.// We need to ensure this does not create unhandled rejections.const getProcessPromises = (sourcePromise, destination) => Promise.allSettled([sourcePromise, destination]);modified:lib/pipe/throw.js+2 added-14 removed
1234556878910111215161314151819201617181910 unmodified lines3031323339404142434445343536375 unmodified linesimport {makeEarlyError} from '../return/error.js';import {abortSourceStream, endDestinationStream} from './streaming.js';
export const handlePipeArgumentsError = ({ sourcePromise, sourceStream, sourceError, destination, destinationStream, destinationError, stdioStreamsGroups, sourceOptions,}) => { const error = getPipeArgumentsError({sourceStream, sourceError, destinationStream, destinationError}); if (error === undefined) { return; if (error !== undefined) { throw createNonCommandError({error, stdioStreamsGroups, sourceOptions}); }
preventUnhandledRejection(sourcePromise, destination); throw createNonCommandError({error, stdioStreamsGroups, sourceOptions});};
const getPipeArgumentsError = ({sourceStream, sourceError, destinationStream, destinationError}) => { if (sourceError !== undefined && destinationError !== undefined) {10 unmodified lines return sourceError; }};
// `.pipe()` awaits the child process promises.// When invalid arguments are passed to `.pipe()`, we throw an error, which prevents awaiting them.// We need to ensure this does not create unhandled rejections.const preventUnhandledRejection = (sourcePromise, destination) => { Promise.allSettled([sourcePromise, destination]);};
export const createNonCommandError = ({error, stdioStreamsGroups, sourceOptions}) => makeEarlyError({ error, command: PIPE_COMMAND_MESSAGE, escapedCommand: PIPE_COMMAND_MESSAGE,5 unmodified linesmodified:lib/pipe/validate.js+16 added-6 removed
1+import {create$} from '../script.js';2 import {STANDARD_STREAMS_ALIASES} from '../utils.js';3 3-export const normalizePipeArguments = ({source, sourcePromise, stdioStreamsGroups}, ...args) => {4+export const normalizePipeArguments = ({source, sourcePromise, stdioStreamsGroups, destinationOptions}, ...args) => {5 const sourceOptions = PROCESS_OPTIONS.get(source);6 const {7 destination,8 destinationStream,9 destinationError,10 pipeOptions: {from, unpipeSignal} = {},10- } = getDestinationStream(...args);11+ } = getDestinationStream(destinationOptions, ...args);12 const {sourceStream, sourceError} = getSourceStream(source, stdioStreamsGroups, from, sourceOptions);13 return {14 sourcePromise,15 sourceStream,6 unmodified lines22 stdioStreamsGroups,23 };24 };25 25-const getDestinationStream = (...args) => {26+const getDestinationStream = (destinationOptions, ...args) => {27 try {27- const {destination, pipeOptions} = getDestination(...args);28+ const {destination, pipeOptions} = getDestination(destinationOptions, ...args);29 const destinationStream = destination.stdin;30 if (destinationStream === null) {31 throw new TypeError('The destination child process\'s stdin must be available. Please set its "stdin" option to "pipe".');32 }3 unmodified lines36 return {destinationError: error};37 }38 };39 39-const getDestination = (firstArgument, ...args) => {40+const getDestination = (destinationOptions, firstArgument, ...args) => {41+ if (Array.isArray(firstArgument)) {42+ const destination = create$({...destinationOptions, stdin: 'pipe'})(firstArgument, ...args);43+ return {destination, pipeOptions: destinationOptions};44+ }45+46 if (!PROCESS_OPTIONS.has(firstArgument)) {41- throw new TypeError(`The first argument must be an Execa child process: ${firstArgument}`);47+ throw new TypeError(`The first argument must be a template string, an options object, or an Execa child process: ${firstArgument}`);48 }49 50+ if (Object.keys(destinationOptions).length > 0) {51+ throw new TypeError('Please use .pipe(options)`command` or .pipe($(options)`command`) instead of .pipe(options)($`command`).');52+ }53+54 return {destination: firstArgument, pipeOptions: args[0]};55 };56 57 export const PROCESS_OPTIONS = new WeakMap();80 unmodified linesmodified:lib/async.js+1 added-1 removed
13 unmodified lines14 import {mergePromise} from './promise.js';15 16 export const execa = (rawFile, rawArgs, rawOptions) => {17 const {spawned, promise, options, stdioStreamsGroups} = runExeca(rawFile, rawArgs, rawOptions);18- spawned.pipe = pipeToProcess.bind(undefined, {source: spawned, sourcePromise: promise, stdioStreamsGroups});18+ spawned.pipe = pipeToProcess.bind(undefined, {source: spawned, sourcePromise: promise, stdioStreamsGroups, destinationOptions: {}});19 mergePromise(spawned, promise);20 PROCESS_OPTIONS.set(spawned, options);21 return spawned;22 };74 unmodified linesmodified:lib/script.js+2 added-32 removed
1 import isPlainObject from 'is-plain-obj';2 import {isBinary, binaryToString, isChildProcess} from './utils.js';3 import {execa} from './async.js';4 import {execaSync} from './sync.js';5-import {PROCESS_OPTIONS} from './pipe/validate.js';5 7-const create$ = options => {6+export const create$ = options => {7 function $(templatesOrOptions, ...expressions) {8 if (isPlainObject(templatesOrOptions)) {9 return create$({...options, ...templatesOrOptions});10 }2 unmodified lines13 throw new TypeError('Please use either $(option) or $`command`.');14 }15 16 const [file, ...args] = parseTemplates(templatesOrOptions, expressions);18- const childProcess = execa(file, args, normalizeScriptOptions(options));19- return scriptWithPipe(childProcess);17+ return execa(file, args, normalizeScriptOptions(options));18 }19 20 $.sync = (templates, ...expressions) => {21 if (isPlainObject(templates)) {14 unmodified lines36 };37 38 export const $ = create$();39 42-const scriptWithPipe = returnValue => {43- const originalPipe = returnValue.pipe.bind(returnValue);44- const pipeMethod = (...args) => scriptWithPipe(originalPipe(...args));45- returnValue.pipe = scriptPipe.bind(undefined, pipeMethod, {});46- return returnValue;47-};48-49-const scriptPipe = (pipeMethod, options, firstArgument, ...args) => {50- if (PROCESS_OPTIONS.has(firstArgument)) {51- if (Object.keys(options).length > 0) {52- throw new TypeError('Please use .pipe(options)`command` or .pipe($(options)`command`) instead of .pipe(options)($`command`).');53- }54-55- return pipeMethod(firstArgument, ...args);56- }57-58- if (isPlainObject(firstArgument)) {59- return scriptPipe.bind(undefined, pipeMethod, {...options, ...firstArgument});60- }61-62- if (!Array.isArray(firstArgument)) {63- throw new TypeError('The first argument must be a template string, an options object, or an Execa child process.');64- }65-66- const childProcess = create$({...options, stdin: 'pipe'})(firstArgument, ...args);67- return pipeMethod(childProcess, options);68-};69-40 const parseTemplates = (templates, expressions) => {41 let tokens = [];42 43 for (const [index, template] of templates.entries()) {133 unmodified linesmodified:test/pipe/template.js+53 added-9 removed
1 import {spawn} from 'node:child_process';2 import test from 'ava';3-import {$} from '../../index.js';3+import {$, execa} from '../../index.js';4 import {setFixtureDir} from '../helpers/fixtures-dir.js';5 import {foobarString} from '../helpers/input.js';6 7 setFixtureDir();2 unmodified lines10 const {stdout} = await $`noop.js ${foobarString}`.pipe($({stdin: 'pipe'})`stdin.js`);11 t.is(stdout, foobarString);12 });13 14+test('execa.$.pipe(childProcess)', async t => {15+ const {stdout} = await execa('noop.js', [foobarString]).pipe($({stdin: 'pipe'})`stdin.js`);16+ t.is(stdout, foobarString);17+});18+19 test('$.pipe.pipe(childProcess)', async t => {20 const {stdout} = await $`noop.js ${foobarString}`21 .pipe($({stdin: 'pipe'})`stdin.js`)22 .pipe($({stdin: 'pipe'})`stdin.js`);4 unmodified lines27 const {stdout} = await $`noop.js ${foobarString}`.pipe`stdin.js`;28 t.is(stdout, foobarString);29 });30 31+test('execa.$.pipe`command`', async t => {32+ const {stdout} = await execa('noop.js', [foobarString]).pipe`stdin.js`;33+ t.is(stdout, foobarString);34+});35+36 test('$.pipe.pipe`command`', async t => {37 const {stdout} = await $`noop.js ${foobarString}`38 .pipe`stdin.js`39 .pipe`stdin.js`;4 unmodified lines44 const {stdout} = await $`noop-fd.js 2 ${foobarString}`.pipe($({stdin: 'pipe'})`stdin.js`, {from: 'stderr'});45 t.is(stdout, foobarString);46 });47 48+test('execa.$.pipe(childProcess, pipeOptions)', async t => {49+ const {stdout} = await execa('noop-fd.js', ['2', foobarString]).pipe($({stdin: 'pipe'})`stdin.js`, {from: 'stderr'});50+ t.is(stdout, foobarString);51+});52+53 test('$.pipe.pipe(childProcess, pipeOptions)', async t => {54 const {stdout} = await $`noop-fd.js 2 ${foobarString}`55 .pipe($({stdin: 'pipe'})`noop-stdin-fd.js 2`, {from: 'stderr'})56 .pipe($({stdin: 'pipe'})`stdin.js`, {from: 'stderr'});4 unmodified lines61 const {stdout} = await $`noop-fd.js 2 ${foobarString}`.pipe({from: 'stderr'})`stdin.js`;62 t.is(stdout, foobarString);63 });64 65+test('execa.$.pipe(pipeOptions)`command`', async t => {66+ const {stdout} = await execa('noop-fd.js', ['2', foobarString]).pipe({from: 'stderr'})`stdin.js`;67+ t.is(stdout, foobarString);68+});69+70 test('$.pipe.pipe(pipeOptions)`command`', async t => {71 const {stdout} = await $`noop-fd.js 2 ${foobarString}`72 .pipe({from: 'stderr'})`noop-stdin-fd.js 2`73 .pipe({from: 'stderr'})`stdin.js`;4 unmodified lines78 const {stdout} = await $`noop.js ${foobarString}`.pipe({stripFinalNewline: false})`stdin.js`;79 t.is(stdout, `${foobarString}\n`);80 });81 82+test('execa.$.pipe(options)`command`', async t => {83+ const {stdout} = await execa('noop.js', [foobarString]).pipe({stripFinalNewline: false})`stdin.js`;84+ t.is(stdout, `${foobarString}\n`);85+});86+87 test('$.pipe.pipe(options)`command`', async t => {88 const {stdout} = await $`noop.js ${foobarString}`89 .pipe({})`stdin.js`90 .pipe({stripFinalNewline: false})`stdin.js`;4 unmodified lines95 const {stdout} = await $`noop-fd.js 2 ${foobarString}\n`.pipe({from: 'stderr', stripFinalNewline: false})`stdin.js`;96 t.is(stdout, `${foobarString}\n`);97 });98 99+test('execa.$.pipe(pipeAndProcessOptions)`command`', async t => {100+ const {stdout} = await execa('noop-fd.js', ['2', `${foobarString}\n`]).pipe({from: 'stderr', stripFinalNewline: false})`stdin.js`;101+ t.is(stdout, `${foobarString}\n`);102+});103+104 test('$.pipe.pipe(pipeAndProcessOptions)`command`', async t => {105 const {stdout} = await $`noop-fd.js 2 ${foobarString}\n`106 .pipe({from: 'stderr'})`noop-stdin-fd.js 2`107 .pipe({from: 'stderr', stripFinalNewline: false})`stdin.js`;4 unmodified lines112 const {stdout} = await $`noop.js ${foobarString}`.pipe({stripFinalNewline: false})({stripFinalNewline: true})`stdin.js`;113 t.is(stdout, foobarString);114 });115 116+test('execa.$.pipe(options)(secondOptions)`command`', async t => {117+ const {stdout} = await execa('noop.js', [foobarString]).pipe({stripFinalNewline: false})({stripFinalNewline: true})`stdin.js`;118+ t.is(stdout, foobarString);119+});120+121 test('$.pipe.pipe(options)(secondOptions)`command`', async t => {122 const {stdout} = await $`noop.js ${foobarString}`123 .pipe({})({})`stdin.js`124 .pipe({stripFinalNewline: false})({stripFinalNewline: true})`stdin.js`;125 t.is(stdout, foobarString);126 });127 93-test('$.pipe(options)(childProcess) fails', t => {94- t.throws(() => {95- $`empty.js`.pipe({stdout: 'pipe'})($`empty.js`);96- }, {message: /Please use \.pipe/});128+test('$.pipe(options)(childProcess) fails', async t => {129+ await t.throwsAsync(130+ $`empty.js`.pipe({stdout: 'pipe'})($`empty.js`),131+ {message: /Please use \.pipe/},132+ );133 });134 99-const testInvalidPipe = (t, ...args) => {100- t.throws(() => {101- $`empty.js`.pipe(...args);102- }, {message: /must be a template string/});135+test('execa.$.pipe(options)(childProcess) fails', async t => {136+ await t.throwsAsync(137+ execa('empty.js').pipe({stdout: 'pipe'})($`empty.js`),138+ {message: /Please use \.pipe/},139+ );140+});141+142+const testInvalidPipe = async (t, ...args) => {143+ await t.throwsAsync(144+ $`empty.js`.pipe(...args),145+ {message: /must be a template string/},146+ );147 };148 149 test('$.pipe(nonExecaChildProcess) fails', testInvalidPipe, spawn('node', ['--version']));150 test('$.pipe(false) fails', testInvalidPipe, false);modified:test/pipe/validate.js+25 added-1 removed
51 unmodified lines52 'an Execa child process',53 );54 };55 56-test('pipe() cannot pipe to non-processes', invalidDestination, () => ({stdin: new PassThrough()}));56+test('pipe() cannot pipe to non-processes', invalidDestination, () => new PassThrough());57 test('pipe() cannot pipe to non-Execa processes', invalidDestination, () => spawn('node', ['--version']));58 59 test('pipe() "from" option cannot be "stdin"', async t => {60 await assertPipeError(3 unmodified lines64 'not be "stdin"',65 );66 });67 68+test('$.pipe() "from" option cannot be "stdin"', async t => {69+ await assertPipeError(70+ t,71+ execa('empty.js')72+ .pipe({from: 'stdin'})`empty.js`,73+ 'not be "stdin"',74+ );75+});76+77 const invalidFromOption = async (t, from) => {78 await assertPipeError(79 t,80 execa('empty.js')75 unmodified lines156 await source;157 t.like(await destination, {stdout: ''});158 });159 160+test('Destination stream is ended when first argument is invalid - $', async t => {161+ const pipePromise = execa('empty.js', {stdout: 'ignore'}).pipe`stdin.js`;162+ await assertPipeError(t, pipePromise, 'option is incompatible');163+});164+165 test('Source stream is aborted when second argument is invalid', async t => {166 const source = execa('noop.js', [foobarString]);167 const pipePromise = source.pipe('');168 8 unmodified lines177 await assertPipeError(t, pipePromise, 'an Execa child process');178 t.like(await source, {stdout: undefined});179 });180 181+test('Sets the right error message when the "all" option is incompatible - execa.$', async t => {182+ await assertPipeError(183+ t,184+ execa('empty.js')185+ .pipe({all: false})`stdin.js`186+ .pipe(execa('empty.js'), {from: 'all'}),187+ '"all" option must be true',188+ );189+});190+191 test('Sets the right error message when the "all" option is incompatible - execa.execa', async t => {192 await assertPipeError(193 t,194 execa('empty.js')15 unmodified linesmodified:index.d.ts+7 added-33 removed
834 unmodified lines835 };836 837 type PipableProcess = {838 /**839- [Pipe](https://nodejs.org/api/stream.html#readablepipedestination-options) the child process' `stdout` to a second Execa child process' `stdin`. This resolves with that second process' result. If either process is rejected, this is rejected with that process' error instead.840-841- This can be called multiple times to chain a series of processes.842-843- Multiple child processes can be piped to the same process. Conversely, the same child process can be piped to multiple other processes.844-845- When using `$`, the following simpler syntax can be used instead.846-847- ```js848- import {$} from 'execa';849-850- await $`command`.pipe`secondCommand`;851-852- // To pass either child process options or pipe options853- await $`command`.pipe(options)`secondCommand`;854- ```839+ Like `.pipe(secondChildProcess)` but using a `command` template string instead. This follows the same syntax as `$`. `options` can be used to specify both pipe options and regular options.840 */856- pipe<Destination extends ExecaChildProcess>(destination: Destination, options?: PipeOptions): Promise<Awaited<Destination>> & PipableProcess;857-};841+ pipe(templates: TemplateStringsArray, ...expressions: TemplateExpression[]): Promise<ExecaReturnValue<{}>> & PipableProcess;842+ pipe<OptionsType extends Options & PipeOptions = {}>(options: OptionsType):843+ (templates: TemplateStringsArray, ...expressions: TemplateExpression[])844+ => Promise<ExecaReturnValue<OptionsType>> & PipableProcess;845 859-type ScriptPipableProcess = {846 /**847 [Pipe](https://nodejs.org/api/stream.html#readablepipedestination-options) the child process' `stdout` to a second Execa child process' `stdin`. This resolves with that second process' result. If either process is rejected, this is rejected with that process' error instead.848 849 This can be called multiple times to chain a series of processes.850 851 Multiple child processes can be piped to the same process. Conversely, the same child process can be piped to multiple other processes.866-867- When using `$`, the following simpler syntax can be used instead.868-869- ```js870- await $`command`.pipe`secondCommand`;871- // To pass either child process options or pipe options872- await $`command`.pipe(options)`secondCommand`;873- ```852 */875- pipe<Destination extends ExecaChildProcess>(destination: Destination, options?: PipeOptions): Promise<Awaited<Destination>> & ScriptPipableProcess;876- pipe(templates: TemplateStringsArray, ...expressions: TemplateExpression[]): Promise<ExecaReturnValue<{}>> & ScriptPipableProcess;877- pipe<OptionsType extends Options & PipeOptions = {}>(options: OptionsType):878- (templates: TemplateStringsArray, ...expressions: TemplateExpression[])879- => Promise<ExecaReturnValue<OptionsType>> & ScriptPipableProcess;853+ pipe<Destination extends ExecaChildProcess>(destination: Destination, options?: PipeOptions): Promise<Awaited<Destination>> & PipableProcess;854 };855 856 export type ExecaChildPromise<OptionsType extends Options = Options> = {857 stdin: StreamUnlessIgnored<'0', OptionsType>;298 unmodified lines1156 <NewOptionsType extends CommonOptions = {}>1157 (options: NewOptionsType): Execa$<OptionsType & NewOptionsType>;1158 1159 (templates: TemplateStringsArray, ...expressions: TemplateExpression[]):1186- Omit<ExecaChildProcess<StricterOptions<OptionsType, Options>>, 'pipe'> & ScriptPipableProcess;1160+ ExecaChildProcess<StricterOptions<OptionsType, Options>> & PipableProcess;1161 1162 /**1163 Same as $\`command\` but synchronous.1164 191 unmodified linesmodified:index.test-d.ts+29 added-3 removed
88 unmodified lines89 expectType<typeof bufferResult>(await execaPromise.pipe(execaBufferPromise));90 expectType<typeof bufferResult>(await scriptPromise.pipe(execaBufferPromise));91 expectNotType<typeof bufferResult>(await execaPromise.pipe(execaPromise));92 expectNotType<typeof bufferResult>(await scriptPromise.pipe(execaPromise));93+ expectType<ExecaReturnValue<{}>>(await execaPromise.pipe`stdin`);94 expectType<ExecaReturnValue<{}>>(await scriptPromise.pipe`stdin`);95 expectType<typeof bufferResult>(await execaPromise.pipe(execaPromise).pipe(execaBufferPromise));96 expectType<typeof bufferResult>(await scriptPromise.pipe(execaPromise).pipe(execaBufferPromise));96- expectType <ExecaReturnValue<{}>>(await scriptPromise.pipe`stdin`.pipe`stdin`);97+ expectType<ExecaReturnValue<{}>>(await execaPromise.pipe`stdin`.pipe`stdin`);98+ expectType<ExecaReturnValue<{}>>(await scriptPromise.pipe`stdin`.pipe`stdin`);99+ expectType<ExecaReturnValue<{}>>(await execaPromise.pipe(execaPromise).pipe`stdin`);100+ expectType<ExecaReturnValue<{}>>(await scriptPromise.pipe(execaPromise).pipe`stdin`);101+ expectType<typeof bufferResult>(await execaPromise.pipe`stdin`.pipe(execaBufferPromise));102+ expectType<typeof bufferResult>(await scriptPromise.pipe`stdin`.pipe(execaBufferPromise));103 await execaPromise.pipe(execaPromise).pipe(execaBufferPromise, {from: 'stdout'});104 await scriptPromise.pipe(execaPromise).pipe(execaBufferPromise, {from: 'stdout'});105+ await execaPromise.pipe`stdin`.pipe({from: 'stdout'})`stdin`;106 await scriptPromise.pipe`stdin`.pipe({from: 'stdout'})`stdin`;107+ await execaPromise.pipe`stdin`.pipe(execaBufferPromise, {from: 'stdout'});108 await scriptPromise.pipe`stdin`.pipe(execaBufferPromise, {from: 'stdout'});109+ await execaPromise.pipe(execaBufferPromise, {from: 'stdout'}).pipe`stdin`;110 await scriptPromise.pipe(execaBufferPromise, {from: 'stdout'}).pipe`stdin`;111 expectError(execaPromise.pipe(execaBufferPromise).stdout);112 expectError(scriptPromise.pipe(execaBufferPromise).stdout);113+ expectError(execaPromise.pipe`stdin`.stdout);114 expectError(scriptPromise.pipe`stdin`.stdout);115 expectError(execaPromise.pipe(createWriteStream('output.txt')));116 expectError(scriptPromise.pipe(createWriteStream('output.txt')));117 expectError(execaPromise.pipe('output.txt'));118 expectError(scriptPromise.pipe('output.txt'));119 await execaPromise.pipe(execaBufferPromise, {});120 await scriptPromise.pipe(execaBufferPromise, {});121+ await execaPromise.pipe({})`stdin`;122 await scriptPromise.pipe({})`stdin`;123 expectError(execaPromise.pipe(execaBufferPromise, 'stdout'));124 expectError(scriptPromise.pipe(execaBufferPromise, 'stdout'));125+ expectError(execaPromise.pipe('stdout')`stdin`);126 expectError(scriptPromise.pipe('stdout')`stdin`);127 await execaPromise.pipe(execaBufferPromise, {from: 'stdout'});128 await scriptPromise.pipe(execaBufferPromise, {from: 'stdout'});129+ await execaPromise.pipe({from: 'stdout'})`stdin`;130 await scriptPromise.pipe({from: 'stdout'})`stdin`;131 await execaPromise.pipe(execaBufferPromise, {from: 'stderr'});132 await scriptPromise.pipe(execaBufferPromise, {from: 'stderr'});133+ await execaPromise.pipe({from: 'stderr'})`stdin`;134 await scriptPromise.pipe({from: 'stderr'})`stdin`;135 await execaPromise.pipe(execaBufferPromise, {from: 'all'});136 await scriptPromise.pipe(execaBufferPromise, {from: 'all'});137+ await execaPromise.pipe({from: 'all'})`stdin`;138 await scriptPromise.pipe({from: 'all'})`stdin`;139 await execaPromise.pipe(execaBufferPromise, {from: 3});140 await scriptPromise.pipe(execaBufferPromise, {from: 3});141+ await execaPromise.pipe({from: 3})`stdin`;142 await scriptPromise.pipe({from: 3})`stdin`;143 expectError(execaPromise.pipe(execaBufferPromise, {from: 'other'}));144 expectError(scriptPromise.pipe(execaBufferPromise, {from: 'other'}));145+ expectError(execaPromise.pipe({from: 'other'})`stdin`);146 expectError(scriptPromise.pipe({from: 'other'})`stdin`);147 await execaPromise.pipe(execaBufferPromise, {unpipeSignal: new AbortController().signal});148 await scriptPromise.pipe(execaBufferPromise, {unpipeSignal: new AbortController().signal});149+ await execaPromise.pipe({unpipeSignal: new AbortController().signal})`stdin`;150 await scriptPromise.pipe({unpipeSignal: new AbortController().signal})`stdin`;151 expectError(await execaPromise.pipe(execaBufferPromise, {unpipeSignal: true}));152 expectError(await scriptPromise.pipe(execaBufferPromise, {unpipeSignal: true}));153+ expectError(await execaPromise.pipe({unpipeSignal: true})`stdin`);154 expectError(await scriptPromise.pipe({unpipeSignal: true})`stdin`);155+ expectError(await execaPromise.pipe({})({}));156 expectError(await scriptPromise.pipe({})({}));157+ expectError(await execaPromise.pipe({})(execaPromise));158 expectError(await scriptPromise.pipe({})(execaPromise));159 139- const pipeResult = await scriptPromise.pipe`stdin`;160+ const pipeResult = await execaPromise.pipe`stdin`;161 expectType<string>(pipeResult.stdout);141- const ignorePipeResult = await scriptPromise.pipe({stdout: 'ignore'})`stdin`;162+ const ignorePipeResult = await execaPromise.pipe({stdout: 'ignore'})`stdin`;163 expectType<undefined>(ignorePipeResult.stdout);164 165+ const scriptPipeResult = await scriptPromise.pipe`stdin`;166+ expectType<string>(scriptPipeResult.stdout);167+ const ignoreScriptPipeResult = await scriptPromise.pipe({stdout: 'ignore'})`stdin`;168+ expectType<undefined>(ignoreScriptPipeResult.stdout);169+170 expectType<Readable>(execaPromise.all);171 const noAllPromise = execa('unicorns');172 expectType<undefined>(noAllPromise.all);173 const noAllResult = await noAllPromise;1318 unmodified linesmodified:readme.md+6 added-8 removed
349 unmodified lines350 This can be called multiple times to chain a series of processes.351 352 Multiple child processes can be piped to the same process. Conversely, the same child process can be piped to multiple other processes.353 354-When using [`$`](#command), the following [simpler syntax](docs/scripts.md#piping-stdout-to-another-command) can be used instead.354+#### pipe`command`355+#### pipe(options)`command`356 356-```js357-import {$} from 'execa';357+`command`: `string`\358+`options`: [`Options`](#options-1) and [`PipeOptions`](#pipeoptions)\359+_Returns_: [`Promise<ChildProcessResult>`](#childprocessresult)360 359-await $`command`.pipe`secondCommand`;361+Like [`.pipe(secondChildProcess)`](#pipesecondchildprocess-pipeoptions) but using a [`command` template string](docs/scripts.md#piping-stdout-to-another-command) instead. This follows the same syntax as [`$`](#command). `options` can be used to specify both [pipe options](#pipeoptions) and [regular options](#options-1).362 361-// To pass either child process options or pipe options362-await $`command`.pipe(options)`secondCommand`;363-```364-363 ##### pipeOptions364 365 Type: `object`366 657 unmodified lines