From a480043a8aafa95a489d430cfc973b1f65925dec Mon Sep 17 00:00:00 2001 From: Jordan Brough Date: Fri, 22 May 2026 07:03:32 -0600 Subject: [PATCH] Add `--silent` option to suppress output in `@tailwindcss/cli` (#20100) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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](https://github.com/tailwindlabs/tailwindcss/issues/8050#issuecomment-1100164351): > [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 --- CHANGELOG.md | 4 ++ integrations/cli/index.test.ts | 43 +++++++++++++++++++ .../src/commands/build/index.ts | 14 +++--- 3 files changed, 56 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d886c914..366e11780 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- Add `--silent` option to suppress output in `@tailwindcss/cli` ([#20100](https://github.com/tailwindlabs/tailwindcss/pull/20100)) + ### Fixed - Remove deprecation warnings by using `Module#registerHooks` instead of `Module#register` on Node 26+ ([#20028](https://github.com/tailwindlabs/tailwindcss/pull/20028)) diff --git a/integrations/cli/index.test.ts b/integrations/cli/index.test.ts index 409a9de7c..f56cd765e 100644 --- a/integrations/cli/index.test.ts +++ b/integrations/cli/index.test.ts @@ -2217,6 +2217,49 @@ test( }, ) +test( + 'suppress output by using the --silent flag', + { + fs: { + 'package.json': json` + { + "dependencies": { + "tailwindcss": "workspace:^", + "@tailwindcss/cli": "workspace:^" + } + } + `, + 'index.css': css` @import 'tailwindcss/utilities';`, + 'index.html': html`
`, + }, + }, + async ({ fs, exec, expect }) => { + let output = await exec('pnpm tailwindcss --input index.css --output dist/loud.css') + expect(output).toContain('Done in') + + let silentOutput = await exec( + 'pnpm tailwindcss --input index.css --output dist/silent.css --silent', + ) + expect(silentOutput).not.toContain('Done in') + expect(silentOutput).not.toContain('tailwindcss v') + + expect(await fs.dumpFiles('./dist/*.css')).toMatchInlineSnapshot(` + " + --- ./dist/loud.css --- + .flex { + display: flex; + } + + + --- ./dist/silent.css --- + .flex { + display: flex; + } + " + `) + }, +) + test( 'changes to CSS files should pick up new CSS variables (if any)', { diff --git a/packages/@tailwindcss-cli/src/commands/build/index.ts b/packages/@tailwindcss-cli/src/commands/build/index.ts index eabd2a1de..01d646a6a 100644 --- a/packages/@tailwindcss-cli/src/commands/build/index.ts +++ b/packages/@tailwindcss-cli/src/commands/build/index.ts @@ -66,6 +66,10 @@ export function options() { description: 'Generate a source map', default: false, }, + '--silent': { + type: 'boolean', + description: 'Suppress non-error output', + }, } satisfies Arg } @@ -81,8 +85,8 @@ async function handleError(fn: () => T): Promise { } export async function handle(args: Result>) { - eprintln(header()) - eprintln() + if (!args['--silent']) eprintln(header()) + if (!args['--silent']) eprintln() using I = new Instrumentation() DEBUG && I.start('[@tailwindcss/cli] (initial build)') @@ -348,7 +352,7 @@ export async function handle(args: Result>) { // disk, and can return early. if (newCandidates.length <= 0) { let end = process.hrtime.bigint() - eprintln(`Done in ${formatDuration(end - start)}`) + if (!args['--silent']) eprintln(`Done in ${formatDuration(end - start)}`) return } @@ -366,7 +370,7 @@ export async function handle(args: Result>) { await write(compiledCss, compiledMap, args, I) let end = process.hrtime.bigint() - eprintln(`Done in ${formatDuration(end - start)}`) + if (!args['--silent']) eprintln(`Done in ${formatDuration(end - start)}`) } catch (err) { // Catch any errors and print them to stderr, but don't exit the process // and keep watching. @@ -410,7 +414,7 @@ export async function handle(args: Result>) { await write(output, map, args, I) let end = process.hrtime.bigint() - eprintln(`Done in ${formatDuration(end - start)}`) + if (!args['--silent']) eprintln(`Done in ${formatDuration(end - start)}`) } async function createWatchers(dirs: string[], cb: (files: string[]) => void) {