execa icon indicating copy to clipboard operation
execa copied to clipboard

Stdio `tap` option

Open jamestalmage opened this issue 8 years ago • 6 comments

For stderr and stdout the choice between inherit and pipe, has tradeoffs.

Specifically, if you choose inherit, you loose the ability to observe the stream, it's piped straight to the parents stdout/stderr.

I propose we add a tap option. It will be converted internally to the pipe option, but we will grab the pipe, split it into two streams, one stream we pipe directly to stdout/stderr, the other we make available for observation.

jamestalmage avatar Apr 24 '16 01:04 jamestalmage

Yes! I've always wanted this 😀

That also means you can do use execa() with inherit and get it written directly console, while still getting the stdout/stderr in the promise.

sindresorhus avatar Apr 24 '16 09:04 sindresorhus

One downside with piping vs inherit: You lose the tty support.

We fake tty for forked processes in AVA. We could reimplement that for execa, but it involves some magic and would only work for Node sources. Maybe opt-in via an option?

jamestalmage avatar Apr 24 '16 09:04 jamestalmage

Maybe opt-in via an option?

👍 You should make the fake TTY thing in AVA a reusable module we can use here too.

sindresorhus avatar Apr 24 '16 09:04 sindresorhus

If only Node.js had PTY support...

(tl;dr It would let us pretend to be a terminal when spawning a child process).

sindresorhus avatar Apr 24 '16 18:04 sindresorhus

There is pty.js - I've used it before and it works. It's got a native component though.

Maybe we could try incorporating that as an optional/peer dependency. If they try to fork a non-node module, it tries to require it (and if it fails it fails - give them a decent error message explaining pty.js is required to make non-node executables work).

Or maybe that is too much effort for what may be a niche case.

jamestalmage avatar Apr 24 '16 18:04 jamestalmage

There is pty.js - I've used it before and it works.

I'm aware. I've used it too.

It's got a native component though.

That's why it's not a solution for me. Native dependencies are too much hassle.

Or maybe that is too much effort for what may be a niche case.

Yeah. Not worth it, and would be weird with varying behavior. I'd rather see it builtin in Node.js, and I'm planning to open a ticket convincing them when I have time.

sindresorhus avatar Apr 24 '16 19:04 sindresorhus

Done in #643: one can now use stdout: ['inherit', 'pipe'] to get that behavior. This works also with stderr and stdin.

ehmicky avatar Dec 25 '23 01:12 ehmicky