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

Don't print minified code when the build fails #15106

Merged
merged 2 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Use configured `--letter-spacing` values for custom font size utilities ([#15099](https://github.com/tailwindlabs/tailwindcss/pull/15099))
- Ensure `space-x/y-*` and `divide-x/y-*` with variants can undo `space-x/y-reverse` and `divide-x/y-reverse` ([#15094](https://github.com/tailwindlabs/tailwindcss/pull/15094))
- Don't print minified code when the build fails in the CLI ([#15106](https://github.com/tailwindlabs/tailwindcss/pull/15106))
- _Upgrade (experimental)_: Always add `layer(…)` as the first param to `@import` ([#15102](https://github.com/tailwindlabs/tailwindcss/pull/15102))

### Changed
Expand Down
15 changes: 13 additions & 2 deletions packages/@tailwindcss-cli/src/commands/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,17 @@ export function options() {
} satisfies Arg
}

async function handleError<T>(fn: () => T): Promise<T> {
try {
return await fn()
} catch (err) {
if (err instanceof Error) {
eprintln(err.toString())
}
process.exit(1)
}
}

export async function handle(args: Result<ReturnType<typeof options>>) {
let base = path.resolve(args['--cwd'])

Expand Down Expand Up @@ -159,7 +170,7 @@ export async function handle(args: Result<ReturnType<typeof options>>) {
return [compiler, scanner] as const
}

let [compiler, scanner] = await createCompiler(input)
let [compiler, scanner] = await handleError(() => createCompiler(input))

// Watch for changes
if (args['--watch']) {
Expand Down Expand Up @@ -288,7 +299,7 @@ export async function handle(args: Result<ReturnType<typeof options>>) {
let candidates = scanner.scan()
env.DEBUG && console.timeEnd('[@tailwindcss/cli] Scan for candidates')
env.DEBUG && console.time('[@tailwindcss/cli] Build CSS')
let output = compiler.build(candidates)
let output = await handleError(() => compiler.build(candidates))
env.DEBUG && console.timeEnd('[@tailwindcss/cli] Build CSS')
await write(output, args)

Expand Down