Skip to content

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
Co-authored-by: Philipp Spiess <hello@philippspiess.com>
@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

3 participants