Skip to content

Commit

Permalink
Don't print minified code when the build fails (#15106)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
thecrypticace authored Nov 22, 2024
1 parent dd2058d commit de096f7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
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

0 comments on commit de096f7

Please sign in to comment.