Skip to content

fix(plugins): compile modern modules, resolve bundler conditions and hoist over every source root - #934

Open
owjs3901 wants to merge 8 commits into
mainfrom
fix/plugin-core-update
Open

owjs3901 wants to merge 8 commits into
mainfrom
fix/plugin-core-update

Conversation

@owjs3901

@owjs3901 owjs3901 commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This PR replaces #755 (fix/plugin-core). #755 is left as is; closing it is up to the maintainer.

#755 was 99 commits on an old main (24a595763) with another 130 files of uncommitted WIP on top (the WIP is preserved in backup/plugin-core-wip, eb55f4e3c). As instructed, I first tried merging origin/main into that branch.

  • 55 files conflicted. Of those, 13 were Rust in extractor and 6 in binding/wasm.
  • The diff against main was about 700 files, +75k lines.
  • Most of it does not fit main's current NAPI design: a resident owner inside WASM, resolver state, a production manifest, nonphysical modules, and the like.

So I did not rework the merge result. I branched fresh from main and reimplemented only the #755 fixes main does not have yet. It is a reviewable size (about +400 lines of source, +1.1k lines including tests), and the areas are intertwined, so it is one PR.

Module resolution and the graph live on the JavaScript (plugin-utils) side, so this change applies equally to the NAPI and WASM engines. Rust is unchanged.

What this PR fixes

PLG-06 (extension part) / NXT-20: compile .mts .cts .cjs modules

  • plugin-utils has a single SOURCE_EXTENSIONS / SOURCE_FILE_REGEX. All of the following follow this list:
    • the import graph and module resolver
    • the Vite / webpack / Rsbuild / Bun transform filters
    • the Turbopack rule (*.{tsx,ts,mts,cts,jsx,js,mjs,cjs}) and Next prewarm
  • ./a.js / ./a.mjs / ./a.cjs imports also resolve to a neighboring a.ts (a.tsx) / a.mts / a.cts. This is the TS ESM convention, and matches Rsbuild's and Next's extensionAlias.
  • Bun
    • Reads .mts/.cts with the ts loader. Previously it read them as js.
    • Bun.build also compiles the project's own .js/.cjs. Those inside node_modules are read by Bun directly because the hook returns no value.
    • The runtime plugin does not allow a hook that returns no value (onLoad() expects an object returned), and Bun filters do not support lookahead. So at runtime, local .js is not taken, as before.

PLG-12: package exports conditions

  • Picks the first applicable branch in the order the package declares, not in the order of the condition name list (same as Node and bundlers).
  • Takes the bundler's conditions via createModuleResolver({ conditions }).
    • Vite: resolve.conditions (including development|production substitution)
    • webpack: each compiler's byDependency.esm.conditionNames (with ... expansion). The loader caches one resolver per condition set.
    • Rsbuild: uses the conditions from the Rspack config per environment, and each transform uses that environment's resolver.
    • Bun: target (browser/node/bun) and conditions
    • Turbopack uses the defaults (import, module, node).
  • The resolver cannot tell an import from a require. So a package that exports only via require is tried once more with the require condition. The previous behavior is kept.
  • The resolver in the reservation stage takes the same conditions.

PLG-13: webpack/Rsbuild atom-hoist graph roots

  • The collapse and atom hoisting plans are built on a single graph. This graph looks at src and app under both the cwd and the bundler root (webpack context, Rsbuild rootPath). Previously it looked only at <cwd>/src.
  • Added buildStaticImportGraph(srcDir, tsconfig, roots) and conventionalSourceRoots().
  • The canonical map and reach share one graph (part of PLG-23).
  • Vite already uses the reservation inventory graph (entry closure + src/app + include) on main, so it is unchanged. This handles the webpack/Rsbuild PLG-13 that fix(plugins): watch the configs devup.json extends in webpack and Rsbuild #928 intentionally left out.

PLG-20: Bun build-time dependencies

  • codeExtract().dependencies is no longer dropped. A bare import such as import "./tokens.ts"; is appended to the end of the extracted code.
    • So Bun's module graph and watcher keep tracking modules whose values were inlined.
    • Since it is appended at the end, existing lines and columns do not move.
  • The Bun plugin API has no watchFiles, so this takes the same approach as fix(plugin-core): align bundler resolution, roots and WASM diagnostics #755.

Handling of each #755 item

Item Handling
PLG-06 extensions This PR (above)
PLG-06 MDX Deferred. Handling compiled MDX needs three things. ① The extractor must accept .mdx file names (currently an unknown extension error). ② Each bundler needs a post-stage hook. ③ Reservation/numbering must also know about MDX. #755's implementation (prepared source, compiled-mdx source type, MDX companion) sits on the old WASM internals, so it was not ported. Left for a follow-up PR.
NXT-20, PLG-12, PLG-13, PLG-20 This PR
PLG-23 Only the canonical+reach graph sharing for webpack/Rsbuild was done. Prewarm builds its graph separately.
PLG-05, PLG-28 Follows main: #914
PLG-09, PLG-10, PLG-19 Follows main: #916 / #924
PLG-11 Follows main: #926
PLG-08 Follows main: #928
PLG-21 Follows main: #920
PLG-22 Follows main: #921 (docs). #755's Vite library aggregate CSS completeness implementation was not ported.
INF-06, INF-07 Already on main (SourceMapMode::Skip, error on malformed resolver result)
INF-08 Follows main: #919
NXT-10, NXT-18 Follows main: #918
Resolver cache Already on main: #900 / #901
PLG-18 Deferred. Unchanged apart from the webpack graph now seeing context. Moving when options are normalized is done separately.
PLG-24, PLG-27 (webpack/Rsbuild) Deferred
PLG-29 Keeps main's intended defaults (debug true for the Bun runtime, false for Bun.build, documented)
WIP: resident owner (bindings/devup-ui-wasm/src/resident_owner, libs/css/src/resident_owner), resolver state, production manifest, nonphysical module, compiled guard, Vite native filter, etc. Excluded. After NAPI, the shared core is libs/binding and WASM is a thin wrapper. A design with a resident owner inside WASM conflicts with this structure and cannot be left half-working. The code remains intact in backup/plugin-core-wip.

changepack: the changepacks from #755 and the WIP all describe excluded work, so they were not brought over. A new changepack_log_plugin_core.json was written for this PR's contents.

New errors

None.

Behavior changes

  • If a package declares conditions in the order { node, import }, node is now picked by declaration order. Previously import was picked.
  • In client builds, the browser branch is picked, as bundlers do.

Test plan

  • bun test packages/plugin-utils packages/bun-plugin packages/webpack-plugin packages/rsbuild-plugin packages/next-plugin: 4999 pass / 0 fail
  • 100% line/function coverage on every changed source file
    • plugin-utils import-graph.ts, bundler-conditions.ts, source-extensions.ts, reservation-discovery.ts
    • each plugin's plugin.ts, loader.ts, reservation.ts, prewarm.ts
  • bun --config=./bunfig.vite.toml test --coverage
    • The changed Vite files are at 100%.
    • The 3 remaining failures (reservation-native-boundary, serve-coherence-prereq-native theme/alias) fail the same way on main without this PR in this Windows environment.
  • New tests
    • The extension list and TS source resolution, .mts/.cts/.cjs graph edges
    • exports declaration order and conditions (nested, empty branch, require-only)
    • webpack/Rspack/Vite/Bun condition computation, the webpack loader and Rsbuild per-environment resolvers
    • Whether webpack/Rsbuild put the app and context roots into the graph
    • Compiling local .js and delegating package .js with a real Bun.build
    • The Bun dependency import, and whether the Turbopack rule covers all of SOURCE_EXTENSIONS
  • bun run build (including tsc) passes for 6 packages
  • bunx prettier --single-quote --no-semi --check passes
  • CI

요약

#755(fix/plugin-core)를 대신하는 PR입니다. #755는 그대로 두었고, 닫는 것은 메인테이너가 합니다.

#755는 예전 main(24a595763) 위의 커밋 99개에, 커밋하지 않은 WIP 130개 파일이 더 얹힌 상태였습니다(WIP는 backup/plugin-core-wip, eb55f4e3c에 보존). 처음에는 지시대로 이 브랜치에 origin/main을 merge해 보았습니다.

  • 충돌 파일이 55개였습니다. 그중 Rust가 extractor 13개, binding/wasm 6개였습니다.
  • main 대비 diff는 약 700파일, +75k줄이었습니다.
  • 대부분은 지금 main의 NAPI 설계와 맞지 않습니다. WASM 안의 resident owner, resolver state, production manifest, nonphysical module 같은 것들입니다.

그래서 merge 결과를 고쳐 쓰지 않았습니다. main에서 새로 브랜치를 만들고, main에 아직 없는 #755의 수정만 다시 구현했습니다. 리뷰할 수 있는 크기(소스 약 +400줄, 테스트 포함 +1.1k줄)이고, 영역이 서로 얽혀 있어 PR 하나로 냈습니다.

모듈 해석과 graph는 JavaScript(plugin-utils) 쪽에 있습니다. 그래서 이 변경은 NAPI와 WASM 엔진 모두에 똑같이 적용됩니다. Rust는 바꾸지 않았습니다.

이 PR이 고치는 것

PLG-06 (확장자 부분) / NXT-20: .mts .cts .cjs 모듈 컴파일

  • plugin-utils에 SOURCE_EXTENSIONS / SOURCE_FILE_REGEX를 하나 두었습니다. 다음이 모두 이 목록을 따릅니다.
    • import graph, module resolver
    • Vite / webpack / Rsbuild / Bun의 transform filter
    • Turbopack rule(*.{tsx,ts,mts,cts,jsx,js,mjs,cjs}), Next prewarm
  • ./a.js / ./a.mjs / ./a.cjs import가 옆의 a.ts(a.tsx) / a.mts / a.cts로도 해석됩니다. TS ESM 관례이며, Rsbuild와 Next의 extensionAlias와 같습니다.
  • Bun
    • .mts/.cts를 ts loader로 읽습니다. 예전에는 js로 읽었습니다.
    • Bun.build에서 프로젝트 자신의 .js/.cjs도 컴파일합니다. node_modules 안의 것은 hook이 값을 돌려주지 않아 Bun이 직접 읽습니다.
    • 런타임 플러그인은 값을 돌려주지 않는 hook을 허용하지 않습니다(onLoad() expects an object returned). Bun filter는 lookahead도 지원하지 않습니다. 그래서 런타임에서는 로컬 .js를 이전처럼 받지 않습니다.

PLG-12: 패키지 exports 조건

  • 조건 이름 목록의 순서가 아니라 패키지가 선언한 순서대로, 적용되는 첫 branch를 고릅니다(Node, bundler와 같음).
  • createModuleResolver({ conditions })로 bundler의 조건을 받습니다.
    • Vite: resolve.conditions(development|production 치환 포함)
    • webpack: 각 compiler의 byDependency.esm.conditionNames(... 확장). loader는 조건 세트마다 resolver를 하나씩 캐시합니다.
    • Rsbuild: environment마다 Rspack config의 조건을 쓰고, transform마다 그 environment의 resolver를 씁니다.
    • Bun: target(browser/node/bun)과 conditions
    • Turbopack은 기본값(import, module, node)을 씁니다.
  • resolver는 import와 require를 구분할 수 없습니다. 그래서 require로만 export하는 패키지는 require 조건으로 한 번 더 시도합니다. 이전 동작이 유지됩니다.
  • reservation 단계의 resolver도 같은 조건을 받습니다.

PLG-13: webpack·Rsbuild atom-hoist graph root

  • collapse와 atom hoisting 계획을 graph 하나 위에서 세웁니다. 이 graph는 cwd와 bundler root(webpack context, Rsbuild rootPath) 각각의 src와 app을 봅니다. 예전에는 <cwd>/src 하나만 봤습니다.
  • buildStaticImportGraph(srcDir, tsconfig, roots)와 conventionalSourceRoots()를 추가했습니다.
  • canonical map과 reach가 graph 하나를 같이 씁니다(PLG-23의 일부).
  • Vite는 main에서 이미 reservation inventory graph(entry closure + src/app + include)를 쓰고 있어 바꾸지 않았습니다. #928이 webpack/Rsbuild PLG-13을 일부러 남겨 둔 것을 여기서 처리합니다.

PLG-20: Bun build-time dependency

  • codeExtract().dependencies를 버리지 않습니다. 추출 코드 끝에 import "./tokens.ts"; 같은 bare import를 붙입니다.
    • 그래서 Bun의 module graph와 watcher가 값을 inline한 모듈을 계속 추적합니다.
    • 끝에 붙이므로 기존 줄과 열은 움직이지 않습니다.
  • Bun plugin API에는 watchFiles가 없어 #755와 같은 방식을 택했습니다.

#755 항목별 처리

항목 처리
PLG-06 확장자 이 PR (위)
PLG-06 MDX 보류. 컴파일된 MDX를 다루려면 세 가지가 필요합니다. ① extractor가 .mdx 파일명을 받아야 합니다(지금은 unknown extension 오류). ② 각 bundler에 post 단계 hook이 있어야 합니다. ③ reservation/numbering이 MDX도 알아야 합니다. #755의 구현(prepared source, compiled-mdx source type, MDX companion)은 옛 WASM 내부 구조 위에 있어 옮기지 않았습니다. 후속 PR로 남깁니다.
NXT-20, PLG-12, PLG-13, PLG-20 이 PR
PLG-23 webpack/Rsbuild의 canonical+reach graph 공유까지만 했습니다. prewarm은 graph를 따로 만듭니다.
PLG-05, PLG-28 main 쪽을 따릅니다: #914
PLG-09, PLG-10, PLG-19 main 쪽을 따릅니다: #916 / #924
PLG-11 main 쪽을 따릅니다: #926
PLG-08 main 쪽을 따릅니다: #928
PLG-21 main 쪽을 따릅니다: #920
PLG-22 main 쪽을 따릅니다: #921(문서). #755의 Vite library aggregate CSS 완결성 구현은 옮기지 않았습니다.
INF-06, INF-07 main에 이미 있습니다(SourceMapMode::Skip, malformed resolver 결과 오류)
INF-08 main 쪽을 따릅니다: #919
NXT-10, NXT-18 main 쪽을 따릅니다: #918
resolver 캐시 main에 이미 있습니다: #900 / #901
PLG-18 보류. webpack graph가 context를 보게 된 것 말고는 그대로입니다. option 정규화 시점을 옮기는 일은 별도로 합니다.
PLG-24, PLG-27 (webpack/Rsbuild) 보류
PLG-29 main의 의도된 기본값(Bun 런타임은 debug true, Bun.build는 false, 문서화됨)을 유지합니다
WIP: resident owner(bindings/devup-ui-wasm/src/resident_owner, libs/css/src/resident_owner), resolver state, production manifest, nonphysical module, compiled guard, Vite native filter 등 제외. NAPI 이후 공용 코어는 libs/binding, WASM은 얇은 wrapper입니다. WASM 안에 상주 owner를 두는 설계는 이 구조와 충돌하고, 반쯤 동작하는 상태로 남길 수 없습니다. 코드는 backup/plugin-core-wip에 그대로 있습니다.

changepack: #755와 WIP의 changepack은 모두 제외된 작업을 설명하므로 가져오지 않았습니다. 이 PR 내용으로 changepack_log_plugin_core.json을 새로 썼습니다.

새로 생기는 오류

없습니다.

동작 변화

  • 패키지가 조건을 { node, import } 순서로 선언하면, 이제 선언 순서대로 node를 고릅니다. 이전에는 import를 골랐습니다.
  • 클라이언트 빌드에서는 bundler처럼 browser branch를 고릅니다.

테스트 계획

  • bun test packages/plugin-utils packages/bun-plugin packages/webpack-plugin packages/rsbuild-plugin packages/next-plugin: 4999 pass / 0 fail
  • 변경한 소스 파일 모두 line/function coverage 100%
    • plugin-utils import-graph.ts, bundler-conditions.ts, source-extensions.ts, reservation-discovery.ts
    • 각 plugin의 plugin.ts, loader.ts, reservation.ts, prewarm.ts
  • bun --config=./bunfig.vite.toml test --coverage
    • 변경한 Vite 파일은 100%입니다.
    • 남은 실패 3건(reservation-native-boundary, serve-coherence-prereq-native theme/alias)은 이 PR이 없는 main에서도 이 Windows 환경에서 똑같이 실패합니다.
  • 새 테스트
    • 확장자 목록과 TS 소스 해석, .mts/.cts/.cjs graph edge
    • exports 선언 순서와 조건(중첩, 빈 branch, require 전용)
    • webpack/Rspack/Vite/Bun 조건 계산, webpack loader와 Rsbuild environment별 resolver
    • webpack/Rsbuild가 app과 context root까지 graph에 넣는지
    • 실제 Bun.build로 로컬 .js 컴파일과 package .js 위임
    • Bun dependency import, Turbopack rule이 SOURCE_EXTENSIONS를 모두 덮는지
  • 6개 package bun run build(tsc 포함) 통과
  • bunx prettier --single-quote --no-semi --check 통과
  • CI

Refs #686

🤖 Generated with Claude Code

…hoist over every source root

Carries the plugin core fixes of #755 that main still lacked onto the
native-engine main. Module resolution is JavaScript shared by both
engines, so the NAPI and WASM builds get them alike.

- PLG-06 / NXT-20: one SOURCE_EXTENSIONS list (.ts .tsx .mts .cts .js
  .jsx .mjs .cjs) drives the import graph, the module resolver and the
  Vite, webpack, Rsbuild, Bun and Turbopack filters, and the Next
  prewarm. An import of ./a.js, ./a.mjs or ./a.cjs also resolves to the
  a.ts, a.mts or a.cts beside it. Bun bundles the project's own .js and
  .cjs modules and leaves those of packages to Bun.
- PLG-12: package exports take the first branch in the package's own
  order whose condition applies, with the conditions of the bundler:
  Vite's resolve.conditions, the ESM conditions of webpack and Rspack
  (per environment in Rsbuild) and Bun's target and conditions. A
  package exported only to require still resolves.
- PLG-13: webpack and Rsbuild plan collapse and atom hoisting over one
  graph of the src and app directories of the working directory and of
  the bundler root, instead of src alone.
- PLG-20: Bun appends a bare import of each module whose values a file
  inlines, so its module graph and watcher keep them.

Refs #686

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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/next-plugin/src/plugin.ts 100.00% <100.00%> (ø)
packages/next-plugin/src/prewarm.ts 100.00% <100.00%> (ø)
packages/plugin-utils/src/bundler-conditions.ts 100.00% <100.00%> (ø)
packages/plugin-utils/src/import-graph.ts 100.00% <100.00%> (ø)
packages/plugin-utils/src/index.ts 100.00% <100.00%> (ø)
packages/plugin-utils/src/reservation-discovery.ts 100.00% <100.00%> (ø)
packages/plugin-utils/src/source-extensions.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 5 more

... and 5 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:
- webpack, Rsbuild and Vite plugin.ts imports: kept main's setupWarning
  (#945) next to this branch's SOURCE_FILE_REGEX.
- Rsbuild transform: kept this branch's `environment` parameter, with
  main's hoisted excludeRegex (#914) in place of the per-call
  createNodeModulesExcludeRegex(include).
- Vite transform: kept this branch's SOURCE_FILE_REGEX check, with
  main's hoisted excludeRegex.
- Bun loadSourceFile: kept main's runtime sheet write, which writes only
  the sheet a module changed (#942), and this branch's
  withDependencyImports return.

Dropped from this branch in favor of main: the per-call exclude regex in
the Rsbuild and Vite transforms (#914) and the unconditional runtime
sheet write in Bun (#942).

Also updated the "Compiled Files" section that #949 added to the Bun
README: `.mts`/`.cts` are compiled, and `Bun.build` compiles the
project's own `.js`/`.cjs` outside node_modules.

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

Copy link
Copy Markdown
Contributor Author

main(#916, #926, #943, #945, #951, #914, #920, #942, #949 등)을 머지하면서 충돌을 해결했습니다 (c525af1).

충돌 파일: packages/{webpack,rsbuild,vite,bun}-plugin/src/plugin.ts

main 쪽을 남기고 이 PR에서 뺀 것

  • Rsbuild·Vite transform에서 호출할 때마다 만들던 createNodeModulesExcludeRegex(include): main이 #914에서 한 번 만들어 두는 excludeRegex로 바꿨습니다. 이 PR의 SOURCE_FILE_REGEX 검사와 Rsbuild의 environment 인자는 그대로 둡니다.
  • Bun 런타임에서 매번 getCss로 sheet 전체를 쓰던 부분: 모듈이 sheet를 바꿨을 때만 쓰는 main의 perf(bun-plugin): write the runtime sheet only when a module changes it #942 방식을 남겼습니다. 이 PR의 withDependencyImports 반환은 그대로 둡니다.

main과 겹치는 코드 확인

문서

  • #949가 Bun README에 추가한 "Compiled Files" 절을 이 PR 동작에 맞게 고쳤습니다. .mts/.cts도 컴파일되고, Bun.build는 node_modules 밖에 있는 프로젝트 자신의 .js/.cjs도 컴파일한다는 내용입니다.

검증

  • bun test --coverage packages/plugin-utils packages/bun-plugin packages/webpack-plugin packages/rsbuild-plugin packages/next-plugin: 5042 pass, 0 fail, 이 패키지들의 소스 파일은 모두 100%
  • bun --config=./bunfig.vite.toml test --coverage packages/vite-plugin: 884 pass, 0 fail, 100%
  • 6개 패키지 모두 tsc --noEmit 통과
  • 바뀐 파일은 prettier 통과. packages/bun-plugin/README.md만 경고가 나오는데, main에서도 이미 줄 끝이 섞여 있어서 생기는 경고입니다.

The runtime filter matches `.ts`, `.mts`, `.cts`, `.tsx`, `.jsx` and
`.mjs` files anywhere, `node_modules` included, and `.js` files of
`@devup-ui` packages. `Bun.build` adds every `.js` and `.cjs` file whose
path is outside `node_modules`, which includes linked workspace packages
resolved to their real path.

Bun reads the source a runtime plugin returns as an ES module, so a
`.cts` file now matched under the runtime loses the exports of
`module.exports` or `export =`; `Bun.build` reads it as CommonJS. Say so
in the README and the limitations page, which still listed the old
extensions.

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

Copy link
Copy Markdown
Contributor Author

Bun docs check (3bee184)

I checked the "Compiled Files" section of packages/bun-plugin/README.md against this PR's plugin.ts and corrected it. I also updated the Bun line in docs/limitations, which still listed only .ts, .tsx, .jsx and .mjs.

What the code does:

  • Runtime and Bun.build: /\.(?:[mc]?ts|tsx|jsx|mjs)$|[\\/]@devup-ui[\\/].*\.js$/. This matches those extensions anywhere, node_modules included, and .js files of @devup-ui packages. .mts/.cts use the ts loader.
  • Bun.build only: /\.c?js$/ for paths with no node_modules segment. That covers the project's own files and linked workspace packages Bun resolves to their real path. Other .js/.cjs files inside node_modules are left to Bun.
  • Checked on Bun 1.4.4: under the runtime, Bun reads returned source as an ES module. A .cts file is now matched there, so if it uses module.exports or export =, it loses its exports (require() gives {}). Bun.build reads the same returned source as CommonJS correctly. The README and the limitations page now say this. If that regression is not acceptable, the runtime filter should leave .cts out.
  • Also on Bun 1.4.4, an onLoad filter with a lookahead ((?!...)) does match. The PR body says Bun filters do not support lookahead. Please re-check that, although the runtime still cannot skip .js files for the CommonJS reason above.

If #925 (fix/bun-include-js) also merges

  • createSourceFilter in fix(bun-plugin): compile the .js files of included packages #925 still builds \.(?:tsx?|jsx|mjs)$. It needs \.(?:[mc]?ts|tsx|jsx|mjs)$ from this PR, or .mts/.cts stop being compiled.
  • README "Compiled Files": fix(bun-plugin): compile the .js files of included packages #925 rewrites the same sentence. The merged wording should be ".js files inside @devup-ui packages and the packages you list in include". The Bun.build sentence should also exclude them: "A .js or .cjs file inside node_modules is left to Bun, except the .js files of @devup-ui packages and of the packages in include". The .cjs files of an included package are compiled by neither path.
  • fix(bun-plugin): compile the .js files of included packages #925's "Libraries" section says included packages are read as ES modules. That applies only under the runtime. Bun.build reads them as CommonJS when they are CommonJS. The current "Under the runtime" wording is already correct.
  • docs/limitations: the Bun line from this PR should add the include packages next to @devup-ui.

Bun 문서 확인 (3bee184)

이 PR의 plugin.ts와 대조해 packages/bun-plugin/README.md의 "Compiled Files" 절을 고쳤습니다. 아직 .ts, .tsx, .jsx, .mjs만 적혀 있던 docs/limitations의 Bun 항목도 갱신했습니다.

코드가 실제로 하는 일:

  • 런타임과 Bun.build 공통: /\.(?:[mc]?ts|tsx|jsx|mjs)$|[\\/]@devup-ui[\\/].*\.js$/. 이 확장자들은 node_modules를 포함해 어디서든 매칭되고, @devup-ui 패키지의 .js도 매칭됩니다. .mts/.cts는 ts loader로 읽습니다.
  • Bun.build 전용: 경로에 node_modules가 없는 파일에 /\.c?js$/. 프로젝트 자신의 파일과, Bun이 실제 경로로 해석한 링크된 workspace 패키지가 여기에 해당합니다. node_modules 안의 다른 .js/.cjs는 Bun이 직접 읽습니다.
  • Bun 1.4.4에서 확인했습니다. 런타임에서 Bun은 돌려받은 소스를 ES module로 읽습니다. 이제 .cts도 런타임에서 매칭되므로, module.exports나 export =를 쓰는 .cts는 export를 잃습니다(require()가 {}를 돌려줌). Bun.build는 같은 소스를 CommonJS로 올바르게 읽습니다. README와 limitations 페이지에 이 내용을 적었습니다. 이 회귀를 받아들일 수 없다면 런타임 filter에서 .cts를 빼야 합니다.
  • 역시 Bun 1.4.4에서, lookahead((?!...))가 있는 onLoad filter도 매칭됩니다. PR 본문에는 Bun filter가 lookahead를 지원하지 않는다고 되어 있으니 다시 확인해 주세요. 다만 위의 CommonJS 문제 때문에 런타임에서 .js를 건너뛸 수 없는 것은 그대로입니다.

#925(fix/bun-include-js)도 병합된다면

  • #925의 createSourceFilter는 아직 \.(?:tsx?|jsx|mjs)$를 만듭니다. 이 PR의 \.(?:[mc]?ts|tsx|jsx|mjs)$를 반영해야 합니다. 그러지 않으면 .mts/.cts가 다시 컴파일되지 않습니다.
  • README "Compiled Files": #925가 같은 문장을 고칩니다. 병합된 문구는 "@devup-ui 패키지와 include에 적은 패키지의 .js 파일"이어야 합니다. Bun.build 문장에서도 이들을 예외로 둬야 합니다: "node_modules 안의 .js/.cjs는 Bun이 읽고, @devup-ui 패키지와 include 패키지의 .js만 예외". include 패키지의 .cjs는 두 경로 모두에서 컴파일되지 않습니다.
  • #925의 "Libraries" 절은 include 패키지를 ES module로 읽는다고 설명합니다. 이것은 런타임에만 해당합니다. Bun.build는 CommonJS 패키지를 CommonJS로 읽습니다. 지금의 "Under the runtime" 문구는 이미 맞습니다.
  • docs/limitations: 이 PR의 Bun 항목에서 @devup-ui 옆에 include 패키지를 추가해야 합니다.

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>
owjs3901 and others added 3 commits November 17, 2026 14:02
Build the Bun source filter with #925's createSourceFilter, whose base now
takes .mts and .cts as this branch does, so included packages keep their .js
files. Merge the README sections, and move #944's Turbopack Tailwind test to
this branch's wider rule glob.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Keep #947's ThemeProvider limitation next to this branch's Bun line, which
now also names the packages in include. Rsbuild transforms take both #928's
addMissingDependency and this branch's environment, so the merged tests pass
both, including #957's hook tests that predate addMissingDependency.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
#962 resolves the project from the bundler root: the Rsbuild and webpack
source graphs, canonical maps and resolver ids now use that root instead of
the cwd (the graph tests follow), while this branch keeps its source filters
and per-environment bundler conditions. The webpack loader caches one
resolver per root and condition set; Bun passes its project and conditions
to initialize. Also pass #928's inputs Set in #962's webpack project-root
assertion.

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