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

Write to stdout when --output is omitted #15656

Merged
merged 7 commits into from
Jan 17, 2025
Merged

Write to stdout when --output is omitted #15656

merged 7 commits into from
Jan 17, 2025

Conversation

RobinMalfait
Copy link
Member

@RobinMalfait RobinMalfait commented Jan 16, 2025

This PR fixes an issue with the @tailwindcss/cli, where omitting the --output flag should output to stdout but it didn't. This PR fixes that by writing to stdout if no --output is passed.

That said, if nothing is passed, then the --help will show.

In summary:

  • If you want to read from stdin, use: --input - or -i -
  • If you want to write to stdout, use: --output - or -o - or omit entirely

Fixes: #15648

Test plan

Added integration tests to ensure that reading / writing to stdin / stdout works as expected.

Ran the updated CLI in my terminal to show that the --help shows by default, but if you use any arguments (like an --input) that the result is printed to stdout as expected.

image

Note the tw command is just a shorthand for running bun --bun ~/github.com/tailwindlabs/tailwindcss/packages/@tailwindcss-cli/src/index.ts.

This is similar to `--input -`, where it reads the input from stdin. We
will default to `-` so that it always prints to stdout when you omit
the `-o` option.
When parsing `-o -`, it parses as `o: true` because mri thinks that `-`
is the start of a new argument, _I think_. So to solve it, we pre
process the options to convert `-` to a fallback value, then parse and
then convert it back.

I wish we could use a symbol, but mri will crash.
If you just run `npx @tailwindcss/cli`, then apart from `npx` and
`@tailwindcss/cli`, no other arguments are passed. In this case, the
help should show.
This is the equivalent of:

```
echo '...' | node ./my-command.js
```
- One test reads from stdin (added for completeness)
- One test writes to stdout
@RobinMalfait RobinMalfait marked this pull request as ready for review January 17, 2025 10:39
@RobinMalfait RobinMalfait requested a review from a team as a code owner January 17, 2025 10:39
CHANGELOG.md Outdated Show resolved Hide resolved
Co-authored-by: Philipp Spiess <[email protected]>
@RobinMalfait RobinMalfait enabled auto-merge (squash) January 17, 2025 15:21
@RobinMalfait RobinMalfait merged commit f93c42f into next Jan 17, 2025
5 checks passed
@RobinMalfait RobinMalfait deleted the fix/issue-15648 branch January 17, 2025 15:23
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.

[v4] Attempting to capture STDOUT writes styles to ./true
2 participants