Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add .pipe(file, arguments, options) shortcut #863

Closed
ehmicky opened this issue Feb 27, 2024 · 0 comments · Fixed by #864
Closed

Add .pipe(file, arguments, options) shortcut #863

ehmicky opened this issue Feb 27, 2024 · 0 comments · Fixed by #864

Comments

@ehmicky
Copy link
Collaborator

ehmicky commented Feb 27, 2024

Instead of passing a child process to .pipe():

await execa('npm', ['run', 'path'])
  .pipe(execa('sort'))
  .pipe(execa('head', ['-n', '2']))

A template string can be passed to pipe as a shortcut when using $:

await $`npm run path`
  .pipe`sort`
  .pipe`head -n 2`

It would be nice to have that kind of shortcut when not using $ as well, like:

await execa('npm', ['run', 'path'])
  .pipe('sort')
  .pipe('head', ['-n', '2'])

This is a simpler syntax that works for most use cases. The only time this does not work is when the child process is used outside of the pipe, e.g. when childProcess.kill() is used or when piping multiple processes to the same process. But those are not the normal use case.

For everyone else, avoiding the double ((...)) parenthesis and repetition of execa() is more straightforward. It is also easy to remember since the arguments are identical to the execa() call.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant