Skip to content

Commit de096f7

Browse files
Don't print minified code when the build fails (#15106)
Fix #15085 We were relying on Node's printing of errors during build but this prints the line of code the error occurs on. Since the code is minified you'd get a really long string of code that wrapped a ton in the console before the actual error. Now we print errors during build like we do in watch mode.
1 parent dd2058d commit de096f7

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

CHANGELOG.md

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

1212
- Use configured `--letter-spacing` values for custom font size utilities ([#15099](https://github.com/tailwindlabs/tailwindcss/pull/15099))
1313
- 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))
14+
- Don't print minified code when the build fails in the CLI ([#15106](https://github.com/tailwindlabs/tailwindcss/pull/15106))
1415
- _Upgrade (experimental)_: Always add `layer(…)` as the first param to `@import` ([#15102](https://github.com/tailwindlabs/tailwindcss/pull/15102))
1516

1617
### Changed

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,17 @@ export function options() {
5454
} satisfies Arg
5555
}
5656

57+
async function handleError<T>(fn: () => T): Promise<T> {
58+
try {
59+
return await fn()
60+
} catch (err) {
61+
if (err instanceof Error) {
62+
eprintln(err.toString())
63+
}
64+
process.exit(1)
65+
}
66+
}
67+
5768
export async function handle(args: Result<ReturnType<typeof options>>) {
5869
let base = path.resolve(args['--cwd'])
5970

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

162-
let [compiler, scanner] = await createCompiler(input)
173+
let [compiler, scanner] = await handleError(() => createCompiler(input))
163174

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

0 commit comments

Comments
 (0)