Skip to content

fix(plugins): fail production builds on theme errors instead of an empty theme - #924

Merged
owjs3901 merged 3 commits into
mainfrom
fix/theme-errors-fail-build
Nov 17, 2026
Merged

owjs3901 merged 3 commits into
mainfrom
fix/theme-errors-fail-build

Conversation

@owjs3901

Copy link
Copy Markdown
Contributor

Summary

#916 위에 쌓은 PR입니다. fix/devup-config-errors(#916)에서 브랜치를 땄으므로 #916이 먼저 머지된 뒤 머지해야 합니다. #916 머지 전까지는 이 PR의 diff에 #916 커밋(1a219e69b)도 함께 보입니다. 이 PR의 변경은 마지막 커밋 140017ab2 하나입니다.

감사 원칙(#682): 빌드 타임에 아무것도 조용히 넘어가면 안 되고, 프로덕션 빌드는 실패해야 합니다.

문제

Vite, webpack, Rsbuild, Bun 플러그인의 writeDataFiles는 loadDevupConfig + compiler.registerTheme(...)를 try/catch로 감싸 console.error만 하고 빈 테마(registerTheme({}))로 계속 진행했습니다. 그래서 다음 오류가 모두 삼켜지고, 빌드는 성공한 채 스타일이 빠진 결과물이 나갔습니다.

  • 잘못된 토큰 이름
  • #908에서 추가한 종류 간 CSS 변수 충돌 (theme: color token 'card' and shadow token 'card' both become the CSS variable --card)
  • 깨진 devup.json (#916에서 throw하도록 바뀐 load-config 오류)

Next.js는 webpack 경로가 webpack 플러그인을 거치므로 같은 문제가 있었고, Turbopack 경로는 원래 삼키지 않습니다.

변경

  • 프로덕션 / 일회성 빌드: 테마 오류를 그대로 rethrow해서 빌드가 그 오류로 실패합니다. 빈 테마 fallback은 없습니다.
    • Vite: vite build (command === 'build'이고 build.watch 없음)이면 configResolved가 reject됩니다.
    • webpack / Next.js(webpack): watch: false이면 apply()에서 throw합니다. 기존 apply 경로대로 endBuild()는 호출됩니다.
    • Rsbuild: api.context.action !== 'dev'이면 setup이 reject됩니다.
    • Bun: 한 번만 실행되므로 register() / Bun.build의 setup이 reject됩니다.
  • watch / dev: devup.json을 편집하는 중일 수 있으므로 서버는 살려 두고, 지금처럼 빈 테마로 계속하면서 오류를 보이게 알립니다.
    • Vite: serve 또는 vite build --watch. console.error로 출력하고, devup.json hot update가 실패하면 full-reload 대신 { type: 'error', err: { message, stack, plugin: 'devup-ui' } }를 보내 에러 오버레이를 띄웁니다 (Vite 6+ environment.hot.send, Vite 5 server.ws.send 둘 다).
    • webpack / Next.js dev: console.error로 출력하고, 테마가 다시 로드될 때까지 매 compilation의 compilation.errors에 [devup-ui] <message>를 WebpackError로 넣습니다.
    • Rsbuild dev: 같은 방식으로 compilation.errors에 넣습니다. Tailwind CSS 변경 때문에 일어나는 리로드는 rsbuild build에서도 watcher 안에서 돌기 때문에 watch 쪽으로 처리합니다.
    • Bun: Tailwind CSS 변경 리로드(이미 떠 있는 프로세스)에서만 console.error 후 빈 테마로 계속합니다.
  • Rsbuild는 테마 등록 전에 Tailwind CSS 파일 목록을 먼저 읽습니다. 등록이 실패해도 그 파일들을 계속 감시하므로, 고치면 다시 로드됩니다.

새 오류

  • 프로덕션 빌드는 이제 registerTheme / loadDevupConfig 오류 메시지 그대로 실패합니다 (예: theme: color token 'card' and shadow token 'card' both become the CSS variable --card, <file> is not valid JSON: ...).
  • dev에서는 compilation error [devup-ui] <message>가 나오고, Vite에서는 에러 오버레이가 뜹니다.

Test plan

  • bun --config=./bunfig.vite.toml test packages/vite-plugin/src/__tests__/plugin.test.ts: 626 pass. 추가한 테스트는 build에서 load / register 실패 시 reject, serve와 build --watch에서 빈 테마로 계속, hot update에서 Error / stack 없는 Error / 문자열을 던졌을 때 오버레이를 보내고 reload하지 않는지입니다.
  • bun test packages/webpack-plugin: 3568 pass, plugin.ts 100%. 추가한 테스트는 일회성 빌드의 apply throw, watch에서 매 compilation error 보고와 devup.json 복구 후 해제, config-errors.test.ts의 두 모드입니다.
  • bun test packages/rsbuild-plugin/src/__tests__/plugin.test.ts: 568 pass, plugin.ts 100%. 추가한 테스트는 build와 action 없음에서 reject, dev에서 compilation error 보고와 복구 후 해제, build 중 Tailwind 리로드 실패가 서버를 죽이지 않는지입니다.
  • bun test packages/bun-plugin: 61 pass, plugin.ts 100%. 추가한 테스트는 config read 실패와 register 실패 시 reject, Tailwind 리로드 실패 시 로그를 남기고 빈 테마로 가는지입니다.
  • bunx prettier --single-quote --no-semi --check 통과
  • CI

Refs #686

🤖 Generated with Claude Code

owjs3901 and others added 2 commits November 15, 2026 10:07
`loadDevupConfig` turned a file that is not valid JSON into `{}`, so a typo
silently dropped the whole theme, and it followed `extends` cycles until the
stack overflowed. Both are now errors that name the file and how to fix it,
as is a config that is not a JSON object. An `extends` target that does not
exist yet stays an empty config: the dev servers watch it and load it once it
appears.

Vite, webpack and Rsbuild already log a config error and clear the theme; Bun
swallowed it and now logs it too.

`theme.d.ts` is written even when the theme has no tokens, so tokens removed
from devup.json leave no stale declarations behind (Vite, webpack, Rsbuild and
Next.js; Bun already did). Rsbuild creates the CSS directory before writing
into it, like Vite, so a cold start cannot lose the race with ENOENT.

Refs #686 (PLG-19, PLG-09, PLG-10)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…pty theme

writeDataFiles in the Vite, webpack, Rsbuild and Bun plugins caught every
error from loading devup.json and registering the theme, logged it and went
on with an empty theme, so an invalid token or a CSS variable clash between
token kinds shipped unstyled output from a build that succeeded.

One-shot builds now rethrow the error. Watchers keep running on an empty
theme, since devup.json may be mid-edit, and report it through the bundler:
Vite sends the error overlay in place of the reload, webpack (and Next.js on
webpack) and Rsbuild push it into every compilation's errors until the theme
loads again, and a Bun reload logs it. Rsbuild now reads the Tailwind CSS
files before registering the theme, so a failed registration still watches
them.

Refs #686

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
packages/bun-plugin/src/plugin.ts 100.00% <100.00%> (ø)
packages/rsbuild-plugin/src/plugin.ts 100.00% <100.00%> (ø)
packages/vite-plugin/src/plugin.ts 100.00% <100.00%> (ø)
packages/webpack-plugin/src/plugin.ts 100.00% <100.00%> (ø)

... and 9 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Conflicts:
- bun-plugin/src/plugin.ts: main (#916) kept the empty-theme fallback
  with a console.error; kept this branch's writeDataFiles, which rethrows
  on the first load and only clears the theme on a Tailwind CSS reload.
- bun-plugin/src/__tests__/plugin.test.ts: replaced main's "registers an
  empty theme" expectation with this branch's rejection tests.
- rsbuild-plugin/src/plugin.ts: kept registering the theme after reading
  the Tailwind CSS files and returning { tailwindFiles, themeError }.
- webpack-plugin/src/plugin.ts: kept clearing themeError after a
  successful load; main's #945 warnings and #951 file removal merged
  cleanly around it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@owjs3901
owjs3901 merged commit f3bf0a0 into main Nov 17, 2026
27 checks passed
@owjs3901
owjs3901 deleted the fix/theme-errors-fail-build branch November 17, 2026 02:31
owjs3901 added a commit that referenced this pull request Nov 17, 2026
Resolve the conflicts with #924. Rsbuild's writeDataFiles takes the
`watching` flag again and returns one flat `{ tailwindFiles, configFiles,
themeError }`, so the watcher keeps both the extends chain and the theme
error. webpack keeps `configFiles` and `themeError` side by side: the catch
records the error (or rethrows in a one-shot build) and the `finally` still
records the config chain. Both sides' tests are kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
owjs3901 added a commit that referenced this pull request Nov 17, 2026
Resolve the conflict with #924 in the Bun plugin: keep this branch's
`createSourceFilter` for `include` and take main's `writeDataFiles`, which
rejects a theme error on the first load and reports it only on a reload.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
owjs3901 added a commit that referenced this pull request Nov 17, 2026
Resolve the conflict with #924 in the Bun plugin: writeDataFiles takes the
located project, so devup.json, df and the CSS directory still resolve
against the project root, and takes main's `reloading` flag after it. The
first load rejects a theme error; the Tailwind CSS watcher reloads the same
project with `reloading` set, so it reports the error and clears the theme.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
owjs3901 added a commit that referenced this pull request Nov 17, 2026
Resolve the conflicts with #924 and #960. The Bun plugin keeps
bunConditions, withDependencyImports and sourceLoader and takes main's
writeDataFiles, which rejects a theme error on the first load. In Vite,
webpack and Rsbuild main moved the source transform into one handler shared
with the MDX post transform; that handler now matches SOURCE_FILE_REGEX, so
.mts/.cts/.cjs modules are extracted, and Rsbuild's handler still sets the
environment's module resolver. Main's Rsbuild MDX test now looks the source
transform up by SOURCE_FILE_REGEX.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant