Skip to content

fix(plugins): forget the styles of source files deleted in watch mode - #951

Merged
owjs3901 merged 2 commits into
mainfrom
fix/remove-deleted-file-styles
Nov 15, 2026
Merged

owjs3901 merged 2 commits into
mainfrom
fix/remove-deleted-file-styles

Conversation

@owjs3901

Copy link
Copy Markdown
Contributor

Summary

PLG-07 / NXT-09: watch·dev 모드에서 소스 파일을 삭제하거나 이름을 바꾸면 그 파일의 스타일이 시트에 계속 남았습니다. 삭제된 파일은 다시 추출되지 않기 때문에 globalCss(전역 규칙은 페이지 전체에 적용됨), 파일 자신의 버킷, 클래스 맵 항목이 세션이 끝날 때까지 남았고, webpack watch 모드는 이 상태를 디스크에 저장해 다음 실행에도 이어졌습니다.

엔진 (libs/*, NAPI, WASM)

  • 새 API removeFile(filename): boolean을 NAPI와 WASM 양쪽에 추가했습니다. 시트가 바뀌었는지를 돌려줍니다.
    • 파일의 전역 CSS(css/@import/@font-face/layer 순서)와 전역 셀렉터 atom을 공유 버킷과 자기 버킷 양쪽에서 지웁니다.
    • 다른 파일이 collapse되어 들어오지 않은 자기 버킷이면 버킷 전체(속성·keyframes)와 그 버킷의 클래스 이름 스코프를 지웁니다.
    • canonical map에서 파일의 버킷 소속을 지웁니다.
    • 파일 번호는 남깁니다. 번호는 개수로 배정되므로 지우면 같은 번호가 두 번 배정됩니다.
    • 다른 파일과 공유하는 버킷(singleCss 시트, 다른 파일이 collapse된 버킷)의 atom은 남습니다. 어떤 파일이 넣었는지 기록이 없고, 더 이상 쓰는 모듈이 없는 클래스는 아무것도 스타일링하지 않습니다.
  • libs/sheet: rm_global_css에서 전역 atom 정리를 rm_global_atoms로 분리하고 rm_file을 추가했습니다.
  • ABI가 29개에서 30개 이름으로 늘어나서 관련 검사를 갱신했습니다(script.js, consumer.mjs, host.mjs, wasm-abi.test.ts, 인자 검증 descriptor와 케이스, README).
  • 네이티브 커버리지 corpus에 remove-file-drops-its-own-styles 시나리오를 추가했습니다. 로컬에서 네이티브와 WASM의 기록이 같은 것을 확인했습니다.

플러그인

  • Vite: watchChange의 delete 이벤트에서 removeFile을 호출합니다. 시트가 바뀌면 base 시트와 지금까지 쓴 버킷 시트를 다시 씁니다(내용이 바뀐 파일만 디스크에 씀).
  • webpack(Next.js webpack 모드 포함): watchRun에서 compiler.removedFiles를 cwd 기준 이름으로 removeFile합니다. watch 모드는 정리된 sheet/classMap/fileMap도 저장합니다. CSS 모듈은 매 컴파일마다 시트에서 다시 만들어집니다.
  • Rsbuild: watchRun에서 removedFiles를 transform이 쓰는 이름(atom 모드는 POSIX)으로 removeFile합니다. 오래된 스타일시트는 기존 finishModules 비교가 다시 빌드합니다.
  • Next.js Turbopack: 코디네이터에 삭제 알림이 없습니다. 그래서 이미 추출한 파일이 다시 추출될 때(수정, 첫 빌드에는 없음) 그 사이에 사라진 파일을 찾아 removeFile하고 base CSS와 상태 파일을 다시 씁니다. 파일을 지우면 그 파일을 import하던 파일이 수정되므로 이 시점에 정리됩니다.
  • Bun: 해당 없음. Bun.build는 매번 엔진을 리셋하고 시작하며(beginBuild), Bun 런타임에는 CSS를 쓰는 곳이 없고, 플러그인 API에 삭제 이벤트도 없습니다.

겹치는 PR

Refs #686

Test plan

  • cargo test -p sheet --lib rm_, cargo test -p devup-ui-binding-core --test remove_file, cargo test -p devup-ui-wasm --lib remove_file
  • cargo clippy -p css -p sheet -p devup-ui-binding-core -p devup-ui-binding -p devup-ui-wasm --all-targets -- -D warnings, cargo fmt --all -- --check
  • 디버그 네이티브 애드온과 WASM 양쪽으로 e2e/binding/host.mjs를 돌려 새 시나리오 기록이 같은지 확인, removeFile 인자 검증 케이스 통과
  • bun test --coverage packages/webpack-plugin packages/rsbuild-plugin packages/next-plugin: 4398개 통과, 수정한 파일 커버리지 100%
  • Vite 테스트(bunfig.vite.toml): plugin.ts 100%. 실패한 serve-coherence-prereq-native 2개는 origin/main에서도 같은 이유로 실패하고(로컬 환경 문제), serve-coherence-final-native는 따로 돌리면 통과합니다.
  • wasm-abi.test.ts, 수정한 패키지의 tsc --noEmit
  • CI tarpaulin / 네이티브 커버리지 100%

🤖 Generated with Claude Code

A deleted or renamed source file is never extracted again, so its
globalCss, its own bucket and its class names stayed in the shared sheet
for the rest of the session (and in webpack's persisted state).

The engine gains removeFile(filename), exposed on NAPI and WASM: it
drops the file's global CSS and global-selector atoms, its own bucket
with its keyframes and class scope when no other file collapses into it,
and its bucket membership. File numbers stay, since they are handed out
by count. Atoms in buckets other files share stay: nothing records which
file added them.

Vite calls it on a `delete` watch change and writes the changed sheets
again; webpack and Rsbuild call it for the removed files of a watch run
(webpack watch mode also saves the pruned state); the Next.js Turbopack
coordinator forgets the files gone since whenever an edited file is
extracted again. Bun builds start from a reset engine and need nothing.

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

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 Δ
bindings/devup-ui-binding/index.mjs 100.00% <100.00%> (ø)
bindings/devup-ui-binding/src/lib.rs 100.00% <ø> (ø)
bindings/devup-ui-wasm/src/lib.rs 100.00% <100.00%> (ø)
libs/binding/src/lib.rs 100.00% <100.00%> (ø)
libs/css/src/class_map.rs 100.00% <ø> (ø)
libs/css/src/file_map.rs 100.00% <100.00%> (ø)
libs/sheet/src/lib.rs 100.00% <100.00%> (ø)
packages/next-plugin/src/coordinator.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%> (ø)
... and 1 more
🚀 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.

@owjs3901
owjs3901 merged commit c750d33 into main Nov 15, 2026
27 checks passed
owjs3901 added a commit that referenced this pull request Nov 15, 2026
coordinator.ts: import both existsSync (main, deleted-source removal from
#951) and statSync (theme stamps). The /extract handler refreshes the theme
first, then records the source for deleted-file removal.

coordinator.test.ts: keep both new describe blocks (theme reload, deleted
sources) side by side.

plugin.ts: keep registerProjectTheme, and write theme.d.ts inside it even
when the interface is empty, as main now does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
owjs3901 added a commit that referenced this pull request Nov 15, 2026
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 added a commit that referenced this pull request Nov 15, 2026
Keep main's check_resolved_path/resolved_module re-exports beside the
session re-exports in libs/binding. removeFile (#951) only touches the
file map, canonical map, class map and global sheet, which CssState and
EngineState already swap per session; a new session test pins that
forgetting a file in one session leaves another session's styles alone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
owjs3901 added a commit that referenced this pull request Nov 15, 2026
coordinator.ts: import both existsSync (main, deleted-source removal from
#951) and statSync (dependency stamps). When main's removeDeletedSources
forgets a deleted file, it now drops that file's transform cache entry too:
the file's styles leave the sheet, so a restored file with the same source
must extract again instead of answering from the cache.

coordinator.test.ts: keep both new describe blocks (transform cache,
deleted sources), and add a test that a deleted file restored unchanged is
extracted again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
owjs3901 added a commit that referenced this pull request Nov 15, 2026
Brings in main through #963, including removeFile (#951). The ABI now
holds 33 names: main's 30 plus createSession, selectSession and
dropSession. Updated script.js, the native typings and README, the
e2e ABI list and consumer, and compiler-types (32 without Output).

Validation covers 48 positions in 21 functions (288 cases), and the
summary reports 21 functions. The corpus keeps both new scenarios and
adds remove-file-stays-in-its-session, which checks that removeFile
only forgets the file in the live session (28 scenarios).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
owjs3901 added a commit that referenced this pull request Nov 15, 2026
No conflicts. openCompilerSession wraps every compiler function in a
Proxy that selects the session first, so removeFile from main (#951)
runs on the scoped session like every other call.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
owjs3901 added a commit that referenced this pull request Nov 15, 2026
Conflicts:
- rsbuild-plugin/src/plugin.ts: kept this branch's shared extractModule
  handler for the source and MDX post transforms, using main's hoisted
  excludeRegex (#914) in it.
- vite-plugin/src/plugin.ts: kept both extractModule (this branch) and
  main's removeSource (#951); extractModule uses main's excludeRegex,
  and the pre transform stays a SOURCE_FILE_RE check plus extractModule.
- webpack-plugin/src/__tests__/plugin.test.ts (no textual conflict):
  the MDX post-rule test now expects #914's exact package exclude regex.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
owjs3901 added a commit that referenced this pull request Nov 15, 2026
main's coordinator (#951) tracked deleted sources in a module-level
extractedSources map, while this branch moved all extraction tracking
into each app's CoordinatorState. extractedSources now lives in that
state too, so each app forgets only its own deleted files. removeFile
is read from the session-scoped compiler the plugin hands over, so it
runs on the app's own engine session.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
owjs3901 added a commit that referenced this pull request Nov 15, 2026
No conflicts. main's sheet changes (rm_file and the stylesheet stack
from #951) merge beside the property_order sort in prop_cmp; the css,
sheet, binding-core, wasm and extractor tests pass unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
owjs3901 added a commit that referenced this pull request Nov 15, 2026
Conflicts:
- rsbuild-plugin/src/plugin.ts: imports keep both resolveDevupFile /
  resolveProjectPath (this branch) and setupWarning (#945).
- webpack-plugin/src/__tests__/plugin.test.ts: kept both the "project
  root" describe and main's deleted-source tests (#951).

Main's new paths now follow the project root, not the cwd:
- webpack: removeFiles (#951) names deleted files relative to this.root,
  and the import graph warning (#945) checks this.root/src for a missing
  directory. Added a test for removeFiles with a context other than cwd.
- Rsbuild: the import graph warning checks projectRoot/src.
- Bun: the file numbering warning checks <root>/src.
Vite's removeSource and Rsbuild's removeFiles use absolute ids already.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
owjs3901 added a commit that referenced this pull request Nov 17, 2026
#952 counted 45 validated argument positions; #951, merged alongside it,
added removeFile.filename, so main validates 46 and the ABI gate failed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
owjs3901 added a commit that referenced this pull request Nov 17, 2026
…rent merges (#990)

* test(rsbuild-plugin): expect the MDX post transform in the hook order

#957 recorded the hook order before #960 added an order: post transform
for .mdx modules. Both landed, so main registers two source transforms and
the test failed. Label the MDX transform and expect it last.

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

* test(wasm): count removeFile in the documented argument positions

#952 counted 45 validated argument positions; #951, merged alongside it,
added removeFile.filename, so main validates 46 and the ABI gate failed.

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

---------

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