Skip to content

Commit a480043

Browse files
Add --silent option to suppress output in @tailwindcss/cli (#20100)
Edited by: @RobinMalfait This PR adds a new `--silent` option to the `@tailwindcss/cli` to suppress output (except for errors). ## Test plan - Existing tests pass - A new integration test for the `--silent` option was added --- Original: ## Summary Small change to add a `--quiet` option. @adamwathan previously said this type of thing [sounded like a good idea](#8050 (comment)): > [I] have made a note about the --silent option idea which I think definitely has value 👍🏻 This is helpful to keep logs high signal in some scenarios. For example, when I want AI to sift through my foreman logs, where "Done in X" becomes the dominant log message over time when running tailwind alongside other things. ## Test plan I've added an integration test. --------- Co-authored-by: Robin Malfait <[email protected]>
1 parent 9f9b7c5 commit a480043

3 files changed

Lines changed: 56 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- Add `--silent` option to suppress output in `@tailwindcss/cli` ([#20100](https://github.com/tailwindlabs/tailwindcss/pull/20100))
13+
1014
### Fixed
1115

1216
- Remove deprecation warnings by using `Module#registerHooks` instead of `Module#register` on Node 26+ ([#20028](https://github.com/tailwindlabs/tailwindcss/pull/20028))

integrations/cli/index.test.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2217,6 +2217,49 @@ test(
22172217
},
22182218
)
22192219

2220+
test(
2221+
'suppress output by using the --silent flag',
2222+
{
2223+
fs: {
2224+
'package.json': json`
2225+
{
2226+
"dependencies": {
2227+
"tailwindcss": "workspace:^",
2228+
"@tailwindcss/cli": "workspace:^"
2229+
}
2230+
}
2231+
`,
2232+
'index.css': css` @import 'tailwindcss/utilities';`,
2233+
'index.html': html`<div class="flex"></div>`,
2234+
},
2235+
},
2236+
async ({ fs, exec, expect }) => {
2237+
let output = await exec('pnpm tailwindcss --input index.css --output dist/loud.css')
2238+
expect(output).toContain('Done in')
2239+
2240+
let silentOutput = await exec(
2241+
'pnpm tailwindcss --input index.css --output dist/silent.css --silent',
2242+
)
2243+
expect(silentOutput).not.toContain('Done in')
2244+
expect(silentOutput).not.toContain('tailwindcss v')
2245+
2246+
expect(await fs.dumpFiles('./dist/*.css')).toMatchInlineSnapshot(`
2247+
"
2248+
--- ./dist/loud.css ---
2249+
.flex {
2250+
display: flex;
2251+
}
2252+
2253+
2254+
--- ./dist/silent.css ---
2255+
.flex {
2256+
display: flex;
2257+
}
2258+
"
2259+
`)
2260+
},
2261+
)
2262+
22202263
test(
22212264
'changes to CSS files should pick up new CSS variables (if any)',
22222265
{

packages/@tailwindcss-cli/src/commands/build/index.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ export function options() {
6666
description: 'Generate a source map',
6767
default: false,
6868
},
69+
'--silent': {
70+
type: 'boolean',
71+
description: 'Suppress non-error output',
72+
},
6973
} satisfies Arg
7074
}
7175

@@ -81,8 +85,8 @@ async function handleError<T>(fn: () => T): Promise<T> {
8185
}
8286

8387
export async function handle(args: Result<ReturnType<typeof options>>) {
84-
eprintln(header())
85-
eprintln()
88+
if (!args['--silent']) eprintln(header())
89+
if (!args['--silent']) eprintln()
8690

8791
using I = new Instrumentation()
8892
DEBUG && I.start('[@tailwindcss/cli] (initial build)')
@@ -348,7 +352,7 @@ export async function handle(args: Result<ReturnType<typeof options>>) {
348352
// disk, and can return early.
349353
if (newCandidates.length <= 0) {
350354
let end = process.hrtime.bigint()
351-
eprintln(`Done in ${formatDuration(end - start)}`)
355+
if (!args['--silent']) eprintln(`Done in ${formatDuration(end - start)}`)
352356
return
353357
}
354358

@@ -366,7 +370,7 @@ export async function handle(args: Result<ReturnType<typeof options>>) {
366370
await write(compiledCss, compiledMap, args, I)
367371

368372
let end = process.hrtime.bigint()
369-
eprintln(`Done in ${formatDuration(end - start)}`)
373+
if (!args['--silent']) eprintln(`Done in ${formatDuration(end - start)}`)
370374
} catch (err) {
371375
// Catch any errors and print them to stderr, but don't exit the process
372376
// and keep watching.
@@ -410,7 +414,7 @@ export async function handle(args: Result<ReturnType<typeof options>>) {
410414
await write(output, map, args, I)
411415

412416
let end = process.hrtime.bigint()
413-
eprintln(`Done in ${formatDuration(end - start)}`)
417+
if (!args['--silent']) eprintln(`Done in ${formatDuration(end - start)}`)
414418
}
415419

416420
async function createWatchers(dirs: string[], cb: (files: string[]) => void) {

0 commit comments

Comments
 (0)