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.
This commit is contained in:
Jordan Pittman 2024-11-22 10:39:51 -05:00 • committed by GitHub
parent dd2058df6a
commit de096f7cae
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 14 additions and 2 deletions

View file

@ -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

View file

@ -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'])
@ -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']) {
@ -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)