CLI: Only listen for stdin close on TTYs #8523
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We have an incompatibility with turborepo because it doesn't pipe stdin to child processes. We currently always listen for stdin close (by closing the file descriptor, or in a TTY by pressing Ctrl + D) as a way to kill the process. If an app starts the Tailwind CLI with stdin closed it won't watch any files because as soon as we call resume we get an end event and exit.
To work around this we'll only wire up these listeners if the process is run in a terminal (a TTY) rather than as a general child process. I've verified this fix by running it in zsh but closed the file descriptor first:
0<&- ./lib/cli.js --watch input.css
. If an input file is not provided we still try to read from stdin which exits as expected because we can't read from stdin since there is no pipe.Fixes #8517