Add `.pipe(command, args, options)` shortcut (#864)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by ehmicky · committed by GitHub · parent 4bd0fe3 · Browse files · 6 files·+294 added−50 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
6 files+294 added−50 removed
- tests:+125 added−3 removed
- other:+169 added−47 removed
Provenance
- Commit
08f8e5d- Tree
1163aa4- Author
ehmicky <ehmicky@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent
4bd0fe3
6 files changed+294 added−50 removed
modified:lib/pipe/validate.js+17 added-5 removed
123456736 unmodified lines444546474647484950515253545556575850515960616263646554666768697079 unmodified linesimport {execa} from '../async.js';import {create$} from '../script.js';import {normalizeArguments} from '../arguments/options.js';import {STANDARD_STREAMS_ALIASES} from '../utils.js';
export const normalizePipeArguments = ({source, sourcePromise, stdioStreamsGroups, destinationOptions}, ...args) => { const sourceOptions = PROCESS_OPTIONS.get(source);36 unmodified lines const destination = create$({...destinationOptions, stdin: 'pipe'})(firstArgument, ...args); return {destination, pipeOptions: destinationOptions}; }
if (!PROCESS_OPTIONS.has(firstArgument)) { throw new TypeError(`The first argument must be a template string, an options object, or an Execa child process: ${firstArgument}`); if (typeof firstArgument === 'string' || firstArgument instanceof URL) { if (Object.keys(destinationOptions).length > 0) { throw new TypeError('Please use .pipe("file", ..., options) or .pipe(execa("file", ..., options)) instead of .pipe(options)(execa("file", ...)).'); }
const [rawFile, rawArgs, rawOptions] = normalizeArguments(firstArgument, ...args); const destination = execa(rawFile, rawArgs, {...rawOptions, stdin: 'pipe'}); return {destination, pipeOptions: rawOptions}; }
if (PROCESS_OPTIONS.has(firstArgument)) { if (Object.keys(destinationOptions).length > 0) { throw new TypeError('Please use .pipe(options)`command` or .pipe($(options)`command`) instead of .pipe(options)($`command`).'); if (Object.keys(destinationOptions).length > 0) { throw new TypeError('Please use .pipe(options)`command` or .pipe($(options)`command`) instead of .pipe(options)($`command`).'); }
return {destination: firstArgument, pipeOptions: args[0]}; }
return {destination: firstArgument, pipeOptions: args[0]}; throw new TypeError(`The first argument must be a template string, an options object, or an Execa child process: ${firstArgument}`);};
export const PROCESS_OPTIONS = new WeakMap();
79 unmodified linesmodified:test/pipe/template.js+123 added-1 removed
1 import {spawn} from 'node:child_process';2+import {pathToFileURL} from 'node:url';3 import test from 'ava';4 import {$, execa} from '../../index.js';4-import {setFixtureDir} from '../helpers/fixtures-dir.js';5+import {setFixtureDir, FIXTURES_DIR} from '../helpers/fixtures-dir.js';6 import {foobarString} from '../helpers/input.js';7 8 setFixtureDir();9 30 unmodified lines40 .pipe`stdin.js`;41 t.is(stdout, foobarString);42 });43 44+test('$.pipe("file")', async t => {45+ const {stdout} = await $`noop.js ${foobarString}`.pipe('stdin.js');46+ t.is(stdout, foobarString);47+});48+49+test('execa.$.pipe("file")`', async t => {50+ const {stdout} = await execa('noop.js', [foobarString]).pipe('stdin.js');51+ t.is(stdout, foobarString);52+});53+54+test('$.pipe.pipe("file")', async t => {55+ const {stdout} = await $`noop.js ${foobarString}`56+ .pipe`stdin.js`57+ .pipe('stdin.js');58+ t.is(stdout, foobarString);59+});60+61+test('execa.$.pipe(fileUrl)`', async t => {62+ const {stdout} = await execa('noop.js', [foobarString]).pipe(pathToFileURL(`${FIXTURES_DIR}/stdin.js`));63+ t.is(stdout, foobarString);64+});65+66+test('$.pipe("file", args, options)', async t => {67+ const {stdout} = await $`noop.js ${foobarString}`.pipe('node', ['stdin.js'], {cwd: FIXTURES_DIR});68+ t.is(stdout, foobarString);69+});70+71+test('execa.$.pipe("file", args, options)`', async t => {72+ const {stdout} = await execa('noop.js', [foobarString]).pipe('node', ['stdin.js'], {cwd: FIXTURES_DIR});73+ t.is(stdout, foobarString);74+});75+76+test('$.pipe.pipe("file", args, options)', async t => {77+ const {stdout} = await $`noop.js ${foobarString}`78+ .pipe`stdin.js`79+ .pipe('node', ['stdin.js'], {cwd: FIXTURES_DIR});80+ t.is(stdout, foobarString);81+});82+83 test('$.pipe(childProcess, pipeOptions)', async t => {84 const {stdout} = await $`noop-fd.js 2 ${foobarString}`.pipe($({stdin: 'pipe'})`stdin.js`, {from: 'stderr'});85 t.is(stdout, foobarString);86 });26 unmodified lines113 .pipe({from: 'stderr'})`stdin.js`;114 t.is(stdout, foobarString);115 });116 117+test('$.pipe("file", pipeOptions)', async t => {118+ const {stdout} = await $`noop-fd.js 2 ${foobarString}`.pipe('stdin.js', {from: 'stderr'});119+ t.is(stdout, foobarString);120+});121+122+test('execa.$.pipe("file", pipeOptions)', async t => {123+ const {stdout} = await execa('noop-fd.js', ['2', foobarString]).pipe('stdin.js', {from: 'stderr'});124+ t.is(stdout, foobarString);125+});126+127+test('$.pipe.pipe("file", pipeOptions)', async t => {128+ const {stdout} = await $`noop-fd.js 2 ${foobarString}`129+ .pipe({from: 'stderr'})`noop-stdin-fd.js 2`130+ .pipe('stdin.js', {from: 'stderr'});131+ t.is(stdout, foobarString);132+});133+134 test('$.pipe(options)`command`', async t => {135 const {stdout} = await $`noop.js ${foobarString}`.pipe({stripFinalNewline: false})`stdin.js`;136 t.is(stdout, `${foobarString}\n`);137 });9 unmodified lines147 .pipe({stripFinalNewline: false})`stdin.js`;148 t.is(stdout, `${foobarString}\n`);149 });150 151+test('$.pipe("file", options)', async t => {152+ const {stdout} = await $`noop.js ${foobarString}`.pipe('stdin.js', {stripFinalNewline: false});153+ t.is(stdout, `${foobarString}\n`);154+});155+156+test('execa.$.pipe("file", options)', async t => {157+ const {stdout} = await execa('noop.js', [foobarString]).pipe('stdin.js', {stripFinalNewline: false});158+ t.is(stdout, `${foobarString}\n`);159+});160+161+test('$.pipe.pipe("file", options)', async t => {162+ const {stdout} = await $`noop.js ${foobarString}`163+ .pipe({})`stdin.js`164+ .pipe('stdin.js', {stripFinalNewline: false});165+ t.is(stdout, `${foobarString}\n`);166+});167+168 test('$.pipe(pipeAndProcessOptions)`command`', async t => {169 const {stdout} = await $`noop-fd.js 2 ${foobarString}\n`.pipe({from: 'stderr', stripFinalNewline: false})`stdin.js`;170 t.is(stdout, `${foobarString}\n`);171 });9 unmodified lines181 .pipe({from: 'stderr', stripFinalNewline: false})`stdin.js`;182 t.is(stdout, `${foobarString}\n`);183 });184 185+test('$.pipe("file", pipeAndProcessOptions)', async t => {186+ const {stdout} = await $`noop-fd.js 2 ${foobarString}\n`.pipe('stdin.js', {from: 'stderr', stripFinalNewline: false});187+ t.is(stdout, `${foobarString}\n`);188+});189+190+test('execa.$.pipe("file", pipeAndProcessOptions)', async t => {191+ const {stdout} = await execa('noop-fd.js', ['2', `${foobarString}\n`]).pipe('stdin.js', {from: 'stderr', stripFinalNewline: false});192+ t.is(stdout, `${foobarString}\n`);193+});194+195+test('$.pipe.pipe("file", pipeAndProcessOptions)', async t => {196+ const {stdout} = await $`noop-fd.js 2 ${foobarString}\n`197+ .pipe({from: 'stderr'})`noop-stdin-fd.js 2`198+ .pipe('stdin.js', {from: 'stderr', stripFinalNewline: false});199+ t.is(stdout, `${foobarString}\n`);200+});201+202 test('$.pipe(options)(secondOptions)`command`', async t => {203 const {stdout} = await $`noop.js ${foobarString}`.pipe({stripFinalNewline: false})({stripFinalNewline: true})`stdin.js`;204 t.is(stdout, foobarString);205 });9 unmodified lines215 .pipe({stripFinalNewline: false})({stripFinalNewline: true})`stdin.js`;216 t.is(stdout, foobarString);217 });218 219+test('$.pipe`command` forces "stdin: pipe"', async t => {220+ const {stdout} = await $`noop.js ${foobarString}`.pipe({stdin: 'ignore'})`stdin.js`;221+ t.is(stdout, foobarString);222+});223+224+test('execa.pipe("file") forces "stdin: "pipe"', async t => {225+ const {stdout} = await execa('noop.js', [foobarString]).pipe('stdin.js', {stdin: 'ignore'});226+ t.is(stdout, foobarString);227+});228+229+test('execa.pipe(childProcess) does not force "stdin: pipe"', async t => {230+ await t.throwsAsync(231+ execa('noop.js', [foobarString]).pipe(execa('stdin.js', {stdin: 'ignore'})),232+ {message: /stdin must be available/},233+ );234+});235+236 test('$.pipe(options)(childProcess) fails', async t => {237 await t.throwsAsync(238 $`empty.js`.pipe({stdout: 'pipe'})($`empty.js`),239 {message: /Please use \.pipe/},6 unmodified lines246 {message: /Please use \.pipe/},247 );248 });249 250+test('$.pipe(options)("file") fails', async t => {251+ await t.throwsAsync(252+ $`empty.js`.pipe({stdout: 'pipe'})('empty.js'),253+ {message: /Please use \.pipe/},254+ );255+});256+257+test('execa.$.pipe(options)("file") fails', async t => {258+ await t.throwsAsync(259+ execa('empty.js').pipe({stdout: 'pipe'})('empty.js'),260+ {message: /Please use \.pipe/},261+ );262+});263+264 const testInvalidPipe = async (t, ...args) => {265 await t.throwsAsync(266 $`empty.js`.pipe(...args),267 {message: /must be a template string/},5 unmodified linesmodified:test/pipe/validate.js+2 added-2 removed
162 unmodified lines163 });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('');167+ const pipePromise = source.pipe(false);168 169 await assertPipeError(t, pipePromise, 'an Execa child process');170 t.like(await source, {stdout: ''});171 });172 173 test('Both arguments might be invalid', async t => {174 const source = execa('empty.js', {stdout: 'ignore'});175- const pipePromise = source.pipe('');175+ const pipePromise = source.pipe(false);176 177 await assertPipeError(t, pipePromise, 'an Execa child process');178 t.like(await source, {stdout: undefined});179 });30 unmodified linesmodified:index.d.ts+34 added-11 removed
834 unmodified lines835 };836 837 type PipableProcess = {838 /**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.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 follows the same syntax as `execa(file, arguments?, options?)` except both regular options and pipe-specific options can be specified.842+843+ This can be called multiple times to chain a series of processes.844+845+ Multiple child processes can be piped to the same process. Conversely, the same child process can be piped to multiple other processes.846+847+ This is usually the preferred method to pipe processes.848 */841- pipe(templates: TemplateStringsArray, ...expressions: TemplateExpression[]): Promise<ExecaReturnValue<{}>> & PipableProcess;849+ pipe<OptionsType extends Options & PipeOptions = {}>(850+ file: string | URL,851+ arguments?: readonly string[],852+ options?: OptionsType,853+ ): Promise<ExecaReturnValue<OptionsType>> & PipableProcess;854+ pipe<OptionsType extends Options & PipeOptions = {}>(855+ file: string | URL,856+ options?: OptionsType,857+ ): Promise<ExecaReturnValue<OptionsType>> & PipableProcess;858+859+ /**860+ Like `.pipe(file, arguments?, options?)` but using a `command` template string instead. This follows the same syntax as `$`.861+862+ This is the preferred method to pipe processes when using `$`.863+ */864+ pipe(templates: TemplateStringsArray, ...expressions: readonly TemplateExpression[]):865+ Promise<ExecaReturnValue<{}>> & PipableProcess;866 pipe<OptionsType extends Options & PipeOptions = {}>(options: OptionsType):843- (templates: TemplateStringsArray, ...expressions: TemplateExpression[])867+ (templates: TemplateStringsArray, ...expressions: readonly TemplateExpression[])868 => Promise<ExecaReturnValue<OptionsType>> & PipableProcess;869 870 /**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.871+ Like `.pipe(file, arguments?, options?)` but using the return value of another `execa()` call instead.872 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.873+ This is the most advanced method to pipe processes. It is useful in specific cases, such as piping multiple child processes to the same process.874 */853- pipe<Destination extends ExecaChildProcess>(destination: Destination, options?: PipeOptions): Promise<Awaited<Destination>> & PipableProcess;875+ pipe<Destination extends ExecaChildProcess>(destination: Destination, options?: PipeOptions):876+ Promise<Awaited<Destination>> & PipableProcess;877 };878 879 export type ExecaChildPromise<OptionsType extends Options = Options> = {880 stdin: StreamUnlessIgnored<'0', OptionsType>;297 unmodified lines1178 */1179 <NewOptionsType extends CommonOptions = {}>1180 (options: NewOptionsType): Execa$<OptionsType & NewOptionsType>;1181 1159- (templates: TemplateStringsArray, ...expressions: TemplateExpression[]):1182+ (templates: TemplateStringsArray, ...expressions: readonly TemplateExpression[]):1183 ExecaChildProcess<StricterOptions<OptionsType, Options>> & PipableProcess;1184 1185 /**1186 Same as $\`command\` but synchronous.45 unmodified lines1232 ```1233 */1234 sync(1235 templates: TemplateStringsArray,1213- ...expressions: TemplateExpression[]1236+ ...expressions: readonly TemplateExpression[]1237 ): ExecaSyncReturnValue<StricterOptions<OptionsType, SyncOptions>>;1238 1239 /**1240 Same as $\`command\` but synchronous.45 unmodified lines1286 ```1287 */1288 s(1289 templates: TemplateStringsArray,1267- ...expressions: TemplateExpression[]1290+ ...expressions: readonly TemplateExpression[]1291 ): ExecaSyncReturnValue<StricterOptions<OptionsType, SyncOptions>>;1292 };1293 1294 /**84 unmodified linesmodified:index.test-d.ts+92 added-22 removed
19 unmodified lines20 type ExecaSyncReturnValue,21 type ExecaSyncError,22 } from './index.js';23 24+const fileUrl = new URL('file:///test');25+26 type AnySyncChunk = string | Uint8Array | undefined;27 type AnyChunk = AnySyncChunk | string[] | Uint8Array[] | unknown[];28 expectType<Writable | null>({} as ExecaChildProcess['stdin']);29 expectType<Readable | null>({} as ExecaChildProcess['stdout']);57 unmodified lines87 const bufferResult = await execaBufferPromise;88 89 const scriptPromise = $`unicorns`;90 89- 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));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));91+ const pipeOptions = {from: 'stderr', all: true} as const;92+93+ type BufferExecaReturnValue = typeof bufferResult;94+ type EmptyExecaReturnValue = ExecaReturnValue<{}>;95+ type ShortcutExecaReturnValue = ExecaReturnValue<typeof pipeOptions>;96+97+ expectType<BufferExecaReturnValue>(await execaPromise.pipe(execaBufferPromise));98+ expectType<BufferExecaReturnValue>(await scriptPromise.pipe(execaBufferPromise));99+ expectNotType<BufferExecaReturnValue>(await execaPromise.pipe(execaPromise));100+ expectNotType<BufferExecaReturnValue>(await scriptPromise.pipe(execaPromise));101+ expectType<EmptyExecaReturnValue>(await execaPromise.pipe`stdin`);102+ expectType<EmptyExecaReturnValue>(await scriptPromise.pipe`stdin`);103+ expectType<ShortcutExecaReturnValue>(await execaPromise.pipe('stdin', pipeOptions));104+ expectType<ShortcutExecaReturnValue>(await scriptPromise.pipe('stdin', pipeOptions));105+ expectType<BufferExecaReturnValue>(await execaPromise.pipe(execaPromise).pipe(execaBufferPromise));106+ expectType<BufferExecaReturnValue>(await scriptPromise.pipe(execaPromise).pipe(execaBufferPromise));107+ expectType<EmptyExecaReturnValue>(await execaPromise.pipe(execaPromise).pipe`stdin`);108+ expectType<EmptyExecaReturnValue>(await scriptPromise.pipe(execaPromise).pipe`stdin`);109+ expectType<ShortcutExecaReturnValue>(await execaPromise.pipe(execaPromise).pipe('stdin', pipeOptions));110+ expectType<ShortcutExecaReturnValue>(await scriptPromise.pipe(execaPromise).pipe('stdin', pipeOptions));111+ expectType<BufferExecaReturnValue>(await execaPromise.pipe`stdin`.pipe(execaBufferPromise));112+ expectType<BufferExecaReturnValue>(await scriptPromise.pipe`stdin`.pipe(execaBufferPromise));113+ expectType<EmptyExecaReturnValue>(await execaPromise.pipe`stdin`.pipe`stdin`);114+ expectType<EmptyExecaReturnValue>(await scriptPromise.pipe`stdin`.pipe`stdin`);115+ expectType<ShortcutExecaReturnValue>(await execaPromise.pipe`stdin`.pipe('stdin', pipeOptions));116+ expectType<ShortcutExecaReturnValue>(await scriptPromise.pipe`stdin`.pipe('stdin', pipeOptions));117+ expectType<BufferExecaReturnValue>(await execaPromise.pipe('pipe').pipe(execaBufferPromise));118+ expectType<BufferExecaReturnValue>(await scriptPromise.pipe('pipe').pipe(execaBufferPromise));119+ expectType<EmptyExecaReturnValue>(await execaPromise.pipe('pipe').pipe`stdin`);120+ expectType<EmptyExecaReturnValue>(await scriptPromise.pipe('pipe').pipe`stdin`);121+ expectType<ShortcutExecaReturnValue>(await execaPromise.pipe('pipe').pipe('stdin', pipeOptions));122+ expectType<ShortcutExecaReturnValue>(await scriptPromise.pipe('pipe').pipe('stdin', pipeOptions));123 await execaPromise.pipe(execaPromise).pipe(execaBufferPromise, {from: 'stdout'});124 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'});125 await execaPromise.pipe(execaBufferPromise, {from: 'stdout'}).pipe`stdin`;126 await scriptPromise.pipe(execaBufferPromise, {from: 'stdout'}).pipe`stdin`;127+ await execaPromise.pipe(execaBufferPromise, {from: 'stdout'}).pipe('stdin');128+ await scriptPromise.pipe(execaBufferPromise, {from: 'stdout'}).pipe('stdin');129+ await execaPromise.pipe`stdin`.pipe(execaBufferPromise, {from: 'stdout'});130+ await scriptPromise.pipe`stdin`.pipe(execaBufferPromise, {from: 'stdout'});131+ await execaPromise.pipe`stdin`.pipe({from: 'stdout'})`stdin`;132+ await scriptPromise.pipe`stdin`.pipe({from: 'stdout'})`stdin`;133+ await execaPromise.pipe`stdin`.pipe('stdin', {from: 'stdout'});134+ await scriptPromise.pipe`stdin`.pipe('stdin', {from: 'stdout'});135 expectError(execaPromise.pipe(execaBufferPromise).stdout);136 expectError(scriptPromise.pipe(execaBufferPromise).stdout);137 expectError(execaPromise.pipe`stdin`.stdout);138 expectError(scriptPromise.pipe`stdin`.stdout);139+ expectError(execaPromise.pipe('stdin').stdout);140+ expectError(scriptPromise.pipe('stdin').stdout);141 expectError(execaPromise.pipe(createWriteStream('output.txt')));142 expectError(scriptPromise.pipe(createWriteStream('output.txt')));117- expectError(execaPromise.pipe('output.txt'));118- expectError(scriptPromise.pipe('output.txt'));143+ expectError(execaPromise.pipe(false));144+ expectError(scriptPromise.pipe(false));145 await execaPromise.pipe(execaBufferPromise, {});146 await scriptPromise.pipe(execaBufferPromise, {});147 await execaPromise.pipe({})`stdin`;148 await scriptPromise.pipe({})`stdin`;149+ await execaPromise.pipe('stdin', {});150+ await scriptPromise.pipe('stdin', {});151 expectError(execaPromise.pipe(execaBufferPromise, 'stdout'));152 expectError(scriptPromise.pipe(execaBufferPromise, 'stdout'));153 expectError(execaPromise.pipe('stdout')`stdin`);154 expectError(scriptPromise.pipe('stdout')`stdin`);155 await execaPromise.pipe(execaBufferPromise, {from: 'stdout'});156 await scriptPromise.pipe(execaBufferPromise, {from: 'stdout'});157 await execaPromise.pipe({from: 'stdout'})`stdin`;158 await scriptPromise.pipe({from: 'stdout'})`stdin`;159+ await execaPromise.pipe('stdin', {from: 'stdout'});160+ await scriptPromise.pipe('stdin', {from: 'stdout'});161 await execaPromise.pipe(execaBufferPromise, {from: 'stderr'});162 await scriptPromise.pipe(execaBufferPromise, {from: 'stderr'});163 await execaPromise.pipe({from: 'stderr'})`stdin`;164 await scriptPromise.pipe({from: 'stderr'})`stdin`;165+ await execaPromise.pipe('stdin', {from: 'stderr'});166+ await scriptPromise.pipe('stdin', {from: 'stderr'});167 await execaPromise.pipe(execaBufferPromise, {from: 'all'});168 await scriptPromise.pipe(execaBufferPromise, {from: 'all'});169 await execaPromise.pipe({from: 'all'})`stdin`;170 await scriptPromise.pipe({from: 'all'})`stdin`;171+ await execaPromise.pipe('stdin', {from: 'all'});172+ await scriptPromise.pipe('stdin', {from: 'all'});173 await execaPromise.pipe(execaBufferPromise, {from: 3});174 await scriptPromise.pipe(execaBufferPromise, {from: 3});175 await execaPromise.pipe({from: 3})`stdin`;176 await scriptPromise.pipe({from: 3})`stdin`;177+ await execaPromise.pipe('stdin', {from: 3});178+ await scriptPromise.pipe('stdin', {from: 3});179 expectError(execaPromise.pipe(execaBufferPromise, {from: 'other'}));180 expectError(scriptPromise.pipe(execaBufferPromise, {from: 'other'}));181 expectError(execaPromise.pipe({from: 'other'})`stdin`);182 expectError(scriptPromise.pipe({from: 'other'})`stdin`);183+ expectError(execaPromise.pipe('stdin', {from: 'other'}));184+ expectError(scriptPromise.pipe('stdin', {from: 'other'}));185 await execaPromise.pipe(execaBufferPromise, {unpipeSignal: new AbortController().signal});186 await scriptPromise.pipe(execaBufferPromise, {unpipeSignal: new AbortController().signal});187 await execaPromise.pipe({unpipeSignal: new AbortController().signal})`stdin`;188 await scriptPromise.pipe({unpipeSignal: new AbortController().signal})`stdin`;189+ await execaPromise.pipe('stdin', {unpipeSignal: new AbortController().signal});190+ await scriptPromise.pipe('stdin', {unpipeSignal: new AbortController().signal});191 expectError(await execaPromise.pipe(execaBufferPromise, {unpipeSignal: true}));192 expectError(await scriptPromise.pipe(execaBufferPromise, {unpipeSignal: true}));193 expectError(await execaPromise.pipe({unpipeSignal: true})`stdin`);194 expectError(await scriptPromise.pipe({unpipeSignal: true})`stdin`);195+ expectError(await execaPromise.pipe('stdin', {unpipeSignal: true}));196+ expectError(await scriptPromise.pipe('stdin', {unpipeSignal: true}));197 expectError(await execaPromise.pipe({})({}));198 expectError(await scriptPromise.pipe({})({}));199 expectError(await execaPromise.pipe({})(execaPromise));200 expectError(await scriptPromise.pipe({})(execaPromise));201+ expectError(await execaPromise.pipe({})('stdin'));202+ expectError(await scriptPromise.pipe({})('stdin'));203 204+ expectType<EmptyExecaReturnValue>(await execaPromise.pipe('stdin'));205+ await execaPromise.pipe('stdin');206+ await execaPromise.pipe(fileUrl);207+ await execaPromise.pipe('stdin', []);208+ await execaPromise.pipe('stdin', ['foo', 'bar']);209+ await execaPromise.pipe('stdin', ['foo', 'bar'], {});210+ await execaPromise.pipe('stdin', ['foo', 'bar'], {from: 'stderr', all: true});211+ await execaPromise.pipe('stdin', {from: 'stderr'});212+ await execaPromise.pipe('stdin', {all: true});213+ expectError(await execaPromise.pipe(['foo', 'bar']));214+ expectError(await execaPromise.pipe('stdin', 'foo'));215+ expectError(await execaPromise.pipe('stdin', [false]));216+ expectError(await execaPromise.pipe('stdin', [], false));217+ expectError(await execaPromise.pipe('stdin', {other: true}));218+ expectError(await execaPromise.pipe('stdin', [], {other: true}));219+ expectError(await execaPromise.pipe('stdin', {from: 'other'}));220+ expectError(await execaPromise.pipe('stdin', [], {from: 'other'}));221+222 const pipeResult = await execaPromise.pipe`stdin`;223 expectType<string>(pipeResult.stdout);224 const ignorePipeResult = await execaPromise.pipe({stdout: 'ignore'})`stdin`;225 expectType<undefined>(ignorePipeResult.stdout);2 unmodified lines228 expectType<string>(scriptPipeResult.stdout);229 const ignoreScriptPipeResult = await scriptPromise.pipe({stdout: 'ignore'})`stdin`;230 expectType<undefined>(ignoreScriptPipeResult.stdout);231 232+ const shortcutPipeResult = await execaPromise.pipe('stdin');233+ expectType<string>(shortcutPipeResult.stdout);234+ const ignoreShortcutPipeResult = await execaPromise.pipe('stdin', {stdout: 'ignore'});235+ expectType<undefined>(ignoreShortcutPipeResult.stdout);236+237+ const scriptShortcutPipeResult = await scriptPromise.pipe('stdin');238+ expectType<string>(scriptShortcutPipeResult.stdout);239+ const ignoreShortcutScriptPipeResult = await scriptPromise.pipe('stdin', {stdout: 'ignore'});240+ expectType<undefined>(ignoreShortcutScriptPipeResult.stdout);241+242 expectType<Readable>(execaPromise.all);243 const noAllPromise = execa('unicorns');244 expectType<undefined>(noAllPromise.all);245 const noAllResult = await noAllPromise;625 unmodified lines871 const asyncStringGenerator = async function * () {872 yield '';873 };874 803-const fileUrl = new URL('file:///test');804-875 expectAssignable<Options>({cleanup: false});876 expectNotAssignable<SyncOptions>({cleanup: false});877 expectAssignable<SyncOptions>({preferLocal: false});878 683 unmodified linesmodified:readme.md+26 added-9 removed
192 unmodified lines193 import {execa} from 'execa';194 195 // Similar to `npm run build | sort | head -n2` in Bash196 const {stdout, pipedFrom} = await execa('npm', ['run', 'build'])197- .pipe(execa('sort'))198- .pipe(execa('head', ['-n2']));197+ .pipe('sort')198+ .pipe('head', ['-n2']);199 console.log(stdout); // Result of `head -n2`200 console.log(pipedFrom[0]); // Result of `sort`201 console.log(pipedFrom[0].pipedFrom[0]); // Result of `npm run build`202 ```113 unmodified lines316 Same as [`execa()`](#execacommandcommand-options), [`execaCommand()`](#execacommand-command-options), [$\`command\`](#command) but synchronous.317 318 Cannot use the following options: [`all`](#all-2), [`cleanup`](#cleanup), [`buffer`](#buffer), [`detached`](#detached), [`ipc`](#ipc), [`serialization`](#serialization), [`signal`](#signal) and [`lines`](#lines). Also, the [`stdin`](#stdin), [`stdout`](#stdout-1), [`stderr`](#stderr-1), [`stdio`](#stdio-1) and [`input`](#input) options cannot be an array, an iterable or a web stream. Node.js streams [must have a file descriptor](#redirect-a-nodejs-stream-fromto-stdinstdoutstderr) unless the `input` option is used.319 320-Returns or throws a [`childProcessResult`](#childProcessResult). The [`childProcess`](#childprocess) is not returned: its methods and properties are not available. This includes [`.kill()`](https://nodejs.org/api/child_process.html#subprocesskillsignal), [`.pid`](https://nodejs.org/api/child_process.html#subprocesspid), [`.pipe()`](#pipesecondchildprocess-pipeoptions) and the [`.stdin`/`.stdout`/`.stderr`](https://nodejs.org/api/child_process.html#subprocessstdout) streams.320+Returns or throws a [`childProcessResult`](#childProcessResult). The [`childProcess`](#childprocess) is not returned: its methods and properties are not available. This includes [`.kill()`](https://nodejs.org/api/child_process.html#subprocesskillsignal), [`.pid`](https://nodejs.org/api/child_process.html#subprocesspid), [`.pipe()`](#pipefile-arguments-options) and the [`.stdin`/`.stdout`/`.stderr`](https://nodejs.org/api/child_process.html#subprocessstdout) streams.321 322 ### Shell syntax323 324 For all the [methods above](#methods), no shell interpreter (Bash, cmd.exe, etc.) is used unless the [`shell` option](#shell) is set. This means shell-specific characters and expressions (`$variable`, `&&`, `||`, `;`, `|`, etc.) have no special meaning and do not need to be escaped.13 unmodified lines338 This is `undefined` if either:339 - the [`all` option](#all-2) is `false` (the default value)340 - both [`stdout`](#stdout-1) and [`stderr`](#stderr-1) options are set to [`'inherit'`, `'ignore'`, `Stream` or `integer`](https://nodejs.org/api/child_process.html#child_process_options_stdio)341 342-#### pipe(secondChildProcess, pipeOptions?)342+#### pipe(file, arguments?, options?)343 344-`secondChildProcess`: [`execa()` return value](#pipe-multiple-processes)\345-`pipeOptions`: [`PipeOptions`](#pipeoptions)\344+`file`: `string | URL`\345+`arguments`: `string[]`\346+`options`: [`Options`](#options-1) and [`PipeOptions`](#pipeoptions)\347 _Returns_: [`Promise<ChildProcessResult>`](#childprocessresult)348 349 [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](#childprocessresult). If either process is rejected, this is rejected with that process' [error](#childprocessresult) instead.350 351+This follows the same syntax as [`execa(file, arguments?, options?)`](#execafile-arguments-options) except both [regular options](#options-1) and [pipe-specific options](#pipeoptions) can be specified.352+353 This can be called multiple times to chain a series of processes.354 355 Multiple child processes can be piped to the same process. Conversely, the same child process can be piped to multiple other processes.356 357+This is usually the preferred method to pipe processes.358+359 #### pipe`command`360 #### pipe(options)`command`361 362 `command`: `string`\363 `options`: [`Options`](#options-1) and [`PipeOptions`](#pipeoptions)\364 _Returns_: [`Promise<ChildProcessResult>`](#childprocessresult)365 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).366+Like [`.pipe(file, arguments?, options?)`](#pipefile-arguments-options) but using a [`command` template string](docs/scripts.md#piping-stdout-to-another-command) instead. This follows the same syntax as [`$`](#command).367 368+This is the preferred method to pipe processes when using [`$`](#command).369+370+#### pipe(secondChildProcess, pipeOptions?)371+372+`secondChildProcess`: [`execa()` return value](#childprocess)\373+`pipeOptions`: [`PipeOptions`](#pipeoptions)\374+_Returns_: [`Promise<ChildProcessResult>`](#childprocessresult)375+376+Like [`.pipe(file, arguments?, options?)`](#pipefile-arguments-options) but using the [return value](#childprocess) of another `execa()` call instead.377+378+This is the most advanced method to pipe processes. It is useful in specific cases, such as piping multiple child processes to the same process.379+380 ##### pipeOptions381 382 Type: `object`383 11 unmodified lines395 Type: [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal)396 397 Unpipe the child process when the signal aborts.398 382-The [`.pipe()`](#pipesecondchildprocess-pipeoptions) method will be rejected with a cancellation error.399+The [`.pipe()`](#pipefile-arguments-options) method will be rejected with a cancellation error.400 401 #### kill(signal, error?)402 #### kill(error?)403 160 unmodified lines564 Type: [`ChildProcessResult[]`](#childprocessresult)565 566 Results of the other processes that were [piped](#pipe-multiple-processes) into this child process. This is useful to inspect a series of child processes piped with each other.567 551-This array is initially empty and is populated each time the [`.pipe()`](#pipesecondchildprocess-pipeoptions) method resolves.568+This array is initially empty and is populated each time the [`.pipe()`](#pipefile-arguments-options) method resolves.569 570 ### options571 572 Type: `object`468 unmodified lines