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

Allow piping data into the CLI #6876

Merged
merged 4 commits into from
Jan 4, 2022
Merged

Allow piping data into the CLI #6876

merged 4 commits into from
Jan 4, 2022

Conversation

RobinMalfait
Copy link
Member

@RobinMalfait RobinMalfait commented Jan 4, 2022

This PR will allow you to pipe data to the cli (and the standalone binaries)

We use - as a placeholder for the input to indicate that we want to read from stdin. There is no way to tell if you getting data via stdin or not (unless you actually get the data). We could use !process.stdin.isTTY, the issue is that this is also false in CI-like environments.

If we actually receive data, then everything works fine as expected, however if we don't receive data then we wait forever. This makes sense if you think about this example:

super-long-running-process-that-gives-you-data-after-10-minutes | npx tailwindcss -o output.css

When do we know that we have to stop watching? We could wait for 100ms, 1s, ... but we don't know when to stop. Halting problem!

As an alternative, a lot of tools use the - instead of the input file to indicate that we want to wait for stdin. You can try it yourself: cat - it will just hang forever.

Long story short, this now works:

cat input.css | npx tailwindcss -i - -o output.css

Fixes #6865

@RobinMalfait RobinMalfait changed the title fix/6865 Allow piping data into the CLI Jan 4, 2022
@RobinMalfait RobinMalfait force-pushed the fix/6865 branch 7 times, most recently from 4651a54 to 0a60c48 Compare January 4, 2022 17:21
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 this pull request may close these issues.

For same input Stdin produces different output from "-i <file.css>"
1 participant