Repository navigation
fix(plugins): compile modern modules, resolve bundler conditions and hoist over every source root - #934
Open
owjs3901 wants to merge 8 commits into
Open
fix(plugins): compile modern modules, resolve bundler conditions and hoist over every source root#934owjs3901 wants to merge 8 commits into
owjs3901 wants to merge 8 commits into
Conversation
…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>
This was referenced Nov 15, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests.
... and 5 files with indirect coverage changes 🚀 New features to boost your workflow:
|
This was referenced Nov 15, 2026
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>
Contributor
Author
|
main(#916, #926, #943, #945, #951, #914, #920, #942, #949 등)을 머지하면서 충돌을 해결했습니다 (c525af1). 충돌 파일: main 쪽을 남기고 이 PR에서 뺀 것
main과 겹치는 코드 확인
문서
검증
|
This was referenced Nov 17, 2026
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>
Contributor
Author
Bun docs check (3bee184)I checked the "Compiled Files" section of What the code does:
If #925 (
|
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>
14 tasks done
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 inbackup/plugin-core-wip,eb55f4e3c). As instructed, I first tried mergingorigin/maininto that branch.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.cjsmodulesSOURCE_EXTENSIONS/SOURCE_FILE_REGEX. All of the following follow this list:*.{tsx,ts,mts,cts,jsx,js,mjs,cjs}) and Next prewarm./a.js/./a.mjs/./a.cjsimports also resolve to a neighboringa.ts(a.tsx) /a.mts/a.cts. This is the TS ESM convention, and matches Rsbuild's and Next'sextensionAlias..mts/.ctswith thetsloader. Previously it read them asjs.Bun.buildalso compiles the project's own.js/.cjs. Those insidenode_modulesare read by Bun directly because the hook returns no value.onLoad() expects an object returned), and Bun filters do not support lookahead. So at runtime, local.jsis not taken, as before.PLG-12: package
exportsconditionscreateModuleResolver({ conditions }).resolve.conditions(includingdevelopment|productionsubstitution)byDependency.esm.conditionNames(with...expansion). The loader caches one resolver per condition set.browser/node/bun) andconditionsimport,module,node).require. So a package that exports only viarequireis tried once more with therequirecondition. The previous behavior is kept.PLG-13: webpack/Rsbuild atom-hoist graph roots
srcandappunder both the cwd and the bundler root (webpackcontext, RsbuildrootPath). Previously it looked only at<cwd>/src.buildStaticImportGraph(srcDir, tsconfig, roots)andconventionalSourceRoots().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().dependenciesis no longer dropped. A bare import such asimport "./tokens.ts";is appended to the end of the extracted code.watchFiles, so this takes the same approach as fix(plugin-core): align bundler resolution, roots and WASM diagnostics #755.Handling of each #755 item
.mdxfile 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.SourceMapMode::Skip, error on malformed resolver result)context. Moving when options are normalized is done separately.Bun.build, documented)bindings/devup-ui-wasm/src/resident_owner,libs/css/src/resident_owner), resolver state, production manifest, nonphysical module, compiled guard, Vite native filter, etc.libs/bindingand 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 inbackup/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.jsonwas written for this PR's contents.New errors
None.
Behavior changes
{ node, import },nodeis now picked by declaration order. Previouslyimportwas picked.browserbranch 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 failimport-graph.ts,bundler-conditions.ts,source-extensions.ts,reservation-discovery.tsplugin.ts,loader.ts,reservation.ts,prewarm.tsbun --config=./bunfig.vite.toml test --coveragereservation-native-boundary,serve-coherence-prereq-nativetheme/alias) fail the same way on main without this PR in this Windows environment..mts/.cts/.cjsgraph edgesexportsdeclaration order and conditions (nested, empty branch,require-only)appandcontextroots into the graph.jsand delegating package.jswith a realBun.buildSOURCE_EXTENSIONSbun run build(including tsc) passes for 6 packagesbunx prettier --single-quote --no-semi --checkpasses요약
#755(
fix/plugin-core)를 대신하는 PR입니다. #755는 그대로 두었고, 닫는 것은 메인테이너가 합니다.#755는 예전 main(
24a595763) 위의 커밋 99개에, 커밋하지 않은 WIP 130개 파일이 더 얹힌 상태였습니다(WIP는backup/plugin-core-wip,eb55f4e3c에 보존). 처음에는 지시대로 이 브랜치에origin/main을 merge해 보았습니다.그래서 merge 결과를 고쳐 쓰지 않았습니다. main에서 새로 브랜치를 만들고, main에 아직 없는 #755의 수정만 다시 구현했습니다. 리뷰할 수 있는 크기(소스 약 +400줄, 테스트 포함 +1.1k줄)이고, 영역이 서로 얽혀 있어 PR 하나로 냈습니다.
모듈 해석과 graph는 JavaScript(plugin-utils) 쪽에 있습니다. 그래서 이 변경은 NAPI와 WASM 엔진 모두에 똑같이 적용됩니다. Rust는 바꾸지 않았습니다.
이 PR이 고치는 것
PLG-06 (확장자 부분) / NXT-20:
.mts.cts.cjs모듈 컴파일SOURCE_EXTENSIONS/SOURCE_FILE_REGEX를 하나 두었습니다. 다음이 모두 이 목록을 따릅니다.*.{tsx,ts,mts,cts,jsx,js,mjs,cjs}), Next prewarm./a.js/./a.mjs/./a.cjsimport가 옆의a.ts(a.tsx) /a.mts/a.cts로도 해석됩니다. TS ESM 관례이며, Rsbuild와 Next의extensionAlias와 같습니다..mts/.cts를tsloader로 읽습니다. 예전에는js로 읽었습니다.Bun.build에서 프로젝트 자신의.js/.cjs도 컴파일합니다.node_modules안의 것은 hook이 값을 돌려주지 않아 Bun이 직접 읽습니다.onLoad() expects an object returned). Bun filter는 lookahead도 지원하지 않습니다. 그래서 런타임에서는 로컬.js를 이전처럼 받지 않습니다.PLG-12: 패키지
exports조건createModuleResolver({ conditions })로 bundler의 조건을 받습니다.resolve.conditions(development|production치환 포함)byDependency.esm.conditionNames(...확장). loader는 조건 세트마다 resolver를 하나씩 캐시합니다.browser/node/bun)과conditionsimport,module,node)을 씁니다.require를 구분할 수 없습니다. 그래서require로만 export하는 패키지는require조건으로 한 번 더 시도합니다. 이전 동작이 유지됩니다.PLG-13: webpack·Rsbuild atom-hoist graph root
context, RsbuildrootPath) 각각의src와app을 봅니다. 예전에는<cwd>/src하나만 봤습니다.buildStaticImportGraph(srcDir, tsconfig, roots)와conventionalSourceRoots()를 추가했습니다.src/app+ include)를 쓰고 있어 바꾸지 않았습니다. #928이 webpack/Rsbuild PLG-13을 일부러 남겨 둔 것을 여기서 처리합니다.PLG-20: Bun build-time dependency
codeExtract().dependencies를 버리지 않습니다. 추출 코드 끝에import "./tokens.ts";같은 bare import를 붙입니다.watchFiles가 없어 #755와 같은 방식을 택했습니다.#755 항목별 처리
.mdx파일명을 받아야 합니다(지금은 unknown extension 오류). ② 각 bundler에 post 단계 hook이 있어야 합니다. ③ reservation/numbering이 MDX도 알아야 합니다. #755의 구현(prepared source, compiled-mdx source type, MDX companion)은 옛 WASM 내부 구조 위에 있어 옮기지 않았습니다. 후속 PR로 남깁니다.SourceMapMode::Skip, malformed resolver 결과 오류)context를 보게 된 것 말고는 그대로입니다. option 정규화 시점을 옮기는 일은 별도로 합니다.Bun.build는 false, 문서화됨)을 유지합니다bindings/devup-ui-wasm/src/resident_owner,libs/css/src/resident_owner), resolver state, production manifest, nonphysical module, compiled guard, Vite native filter 등libs/binding, WASM은 얇은 wrapper입니다. WASM 안에 상주 owner를 두는 설계는 이 구조와 충돌하고, 반쯤 동작하는 상태로 남길 수 없습니다. 코드는backup/plugin-core-wip에 그대로 있습니다.changepack: #755와 WIP의 changepack은 모두 제외된 작업을 설명하므로 가져오지 않았습니다. 이 PR 내용으로
changepack_log_plugin_core.json을 새로 썼습니다.새로 생기는 오류
없습니다.
동작 변화
{ node, import }순서로 선언하면, 이제 선언 순서대로node를 고릅니다. 이전에는import를 골랐습니다.browserbranch를 고릅니다.테스트 계획
bun test packages/plugin-utils packages/bun-plugin packages/webpack-plugin packages/rsbuild-plugin packages/next-plugin: 4999 pass / 0 failimport-graph.ts,bundler-conditions.ts,source-extensions.ts,reservation-discovery.tsplugin.ts,loader.ts,reservation.ts,prewarm.tsbun --config=./bunfig.vite.toml test --coveragereservation-native-boundary,serve-coherence-prereq-nativetheme/alias)은 이 PR이 없는 main에서도 이 Windows 환경에서 똑같이 실패합니다..mts/.cts/.cjsgraph edgeexports선언 순서와 조건(중첩, 빈 branch,require전용)app과contextroot까지 graph에 넣는지Bun.build로 로컬.js컴파일과 package.js위임SOURCE_EXTENSIONS를 모두 덮는지bun run build(tsc 포함) 통과bunx prettier --single-quote --no-semi --check통과Refs #686
🤖 Generated with Claude Code