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

Line-wise standard streams #706

Closed
ehmicky opened this issue Jan 20, 2024 · 1 comment · Fixed by #741
Closed

Line-wise standard streams #706

ehmicky opened this issue Jan 20, 2024 · 1 comment · Fixed by #741

Comments

@ehmicky
Copy link
Collaborator

ehmicky commented Jan 20, 2024

With #695, we just added line-wise transforms. However, this does not cover childProcess.std*.

const childProcess = execa('...')
for await (const chunk of childProcess.stdout) {
  console.log(chunk) // Buffer, and not line-wise
}

What are your thoughts on adding the following?

const childProcess = execa('...', {lines: true})
for await (const line of childProcess.stdout) {
  console.log(line) // String, and line-wise
}

This would work also for childProcess.stdout.read(), childProcess.stdout.on('data') and when redirecting from/to Node.js/web streams.

const writableStream = new Writable({
  write(line, encoding, done) {
    console.log(line) // String, and line-wise
    done()
  }
})
await execa('...', {lines: true, stdout: writableStream})

This would be pretty fairly simple to implement since it can re-use most of the logic of 2 separate features:

Under the hood, when the lines: true option is used, we would just add an internal transform that is a noop, but is both line-wise and in objectMode.

@sindresorhus
Copy link
Owner

Yes, this would be nice 👍

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.

2 participants