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) {