Repository navigation
refactor(rspack,webpack): use DI model to split builders - #35751
Conversation
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
This comment has been minimized.
This comment has been minimized.
@nuxt/kit
@nuxt/nitro-server
nuxt
@nuxt/rspack-builder
@nuxt/schema
@nuxt/vite-builder
@nuxt/webpack-builder
commit: |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
packages/webpack/src/builder-registry.ts (1)
28-30: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick winPrevent multiple initialisations of the builder registry.
Because
builder.tsdestructures the registry values immediately upon module evaluation, callingsetBuilderImpla second time will not update those exported bindings, leading to a silent divergence in state. Throwing an error if_implis already set ensures early detection of accidental re-initialisation.♻️ Proposed fix
export function setBuilderImpl (impl: BuilderImpl): void { + if (_impl) { + throw new Error('Builder implementation is already set.') + } _impl = impl }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/webpack/src/builder-registry.ts` around lines 28 - 30, Update setBuilderImpl to reject re-initialization: before assigning the supplied BuilderImpl to _impl, detect whether _impl is already set and throw an error instead of overwriting it. Preserve the existing assignment behavior for the first initialization.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/webpack/src/builder.ts`:
- Line 4: Remove the setBuilderImpl re-export from builder.ts, leaving registry
initialization available only through the direct ./builder-registry.ts module
import.
---
Nitpick comments:
In `@packages/webpack/src/builder-registry.ts`:
- Around line 28-30: Update setBuilderImpl to reject re-initialization: before
assigning the supplied BuilderImpl to _impl, detect whether _impl is already set
and throw an error instead of overwriting it. Preserve the existing assignment
behavior for the first initialization.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: e994d80e-2c8c-4a8f-a74a-b982e7a463d6
📒 Files selected for processing (6)
packages/rspack/src/impl.tspackages/webpack/src/builder-registry.tspackages/webpack/src/builder.tspackages/webpack/src/impl.tspackages/webpack/src/plugins/chunk.tspackages/webpack/test/base.test.ts
🚧 Files skipped from review as they are similar to previous changes (2)
- packages/rspack/src/impl.ts
- packages/webpack/src/impl.ts
Merging this PR will degrade performance by 14.12%
|
| Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|
| ❌ | loadNuxt in the basic test fixture |
382.2 ms | 445 ms | -14.12% |
Tip
Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.
Comparing refactor/rspack (d4d267c) with main (ebdcb69)
Footnotes
-
3 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩
791b61d to
f2a96d5
Compare
c4737a9 to
8dfb503
Compare
There was a problem hiding this comment.
Pull request overview
Refactors the webpack/rspack builder packages to use a dependency-injection “builder impl” model instead of the #builder import alias, with the goal of ensuring CI actually runs tests against the rspack builder (instead of effectively exercising the webpack path twice).
Changes:
- Introduce a shared builder implementation registry (
builder-registry.ts) plus per-builderimpl.tsside-effect initializers, and update webpack/rspack entrypoints and internal imports accordingly. - Update tests and presets/plugins/configs to consume the injected builder bindings, and adjust a few rspack dev-server middleware behaviors.
- Add a patched Nitro version (pnpm patch) and a new
@types/hash-sumcatalog entry.
Reviewed changes
Copilot reviewed 29 out of 31 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| test/server-components.test.ts | Switches webpack/rspack gating to use the matrix builder value. |
| test/basic.test.ts | Switches specific “fails in dev” gating to use builder === 'webpack'. |
| pnpm-workspace.yaml | Adds Nitro patch + adds @types/hash-sum to catalogs. |
| pnpm-lock.yaml | Records patched Nitro + @types/hash-sum lock entries. |
| patches/[email protected] | Patches Nitro dev stack-trace sourcemap consumer handling/caching. |
| packages/webpack/tsdown.config.ts | Removes #builder from neverBundle list. |
| packages/webpack/test/vue-loader.test.ts | Updates test to use injected impl instead of builder.mjs. |
| packages/webpack/test/base.test.ts | Ensures webpack impl is injected before importing modules that use builder bindings. |
| packages/webpack/src/webpack.ts | Switches builder import to local DI binding + adjusts rsbuild dev handler behavior for asset prefixes. |
| packages/webpack/src/presets/vue.ts | Uses injected vueModuleIdentifierLoader rather than resolving it directly. |
| packages/webpack/src/presets/style.ts | Switches MiniCssExtractPlugin import to injected binding. |
| packages/webpack/src/presets/node.ts | Switches builder import to injected binding. |
| packages/webpack/src/presets/base.ts | Switches WebpackBarPlugin/webpack imports to injected binding. |
| packages/webpack/src/plugins/vue/server.ts | Switches webpack import to injected binding. |
| packages/webpack/src/plugins/ssr-styles.ts | Switches getVueLoaderHash import to injected binding and updates comment. |
| packages/webpack/src/plugins/chunk.ts | Switches webpack import to injected binding. |
| packages/webpack/src/index.ts | Imports ./impl.ts first to inject the webpack impl before exporting bundle. |
| packages/webpack/src/impl.ts | New: webpack-specific injected implementation (sets registry). |
| packages/webpack/src/configs/server.ts | Switches TsCheckerPlugin/webpack import to injected binding. |
| packages/webpack/src/configs/client.ts | Switches TsCheckerPlugin/builder/webpack import to injected binding. |
| packages/webpack/src/builder.ts | New: exposes builder bindings by reading from the registry. |
| packages/webpack/src/builder-registry.ts | New: shared DI registry for webpack/rspack builder implementations. |
| packages/webpack/package.json | Removes #builder import map and stops publishing builder.mjs; adds @types/hash-sum. |
| packages/webpack/builder.mjs | Deleted: old #builder implementation module. |
| packages/webpack/builder.d.ts | Deleted: old #builder type declarations. |
| packages/rspack/tsdown.config.ts | Removes #builder from neverBundle list. |
| packages/rspack/test/vue-loader.test.ts | Updates test to use injected impl instead of builder.mjs. |
| packages/rspack/src/index.ts | Imports ./impl.ts first to inject the rspack impl before exporting bundle. |
| packages/rspack/src/impl.ts | New: rspack-specific injected implementation (sets registry). |
| packages/rspack/package.json | Removes #builder import map and stops publishing builder.mjs. |
| packages/rspack/builder.mjs | Deleted: old #builder implementation module. |
Files not reviewed (1)
- pnpm-lock.yaml: Generated file
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| import type Webpack from 'webpack' | ||
| import type MiniCssExtractPluginType from 'mini-css-extract-plugin' | ||
| import type TsCheckerPluginType from 'fork-ts-checker-webpack-plugin' | ||
| import type VueLoaderPluginConstructor from 'vue-loader/dist/pluginWebpack5.js' | ||
|
|
||
| export interface BuilderImpl { | ||
| builder: 'webpack' | 'rspack' | ||
| webpack: typeof Webpack | ||
| createRsbuild: undefined | ((options?: any) => Promise<any>) | ||
| WebpackBarPlugin: typeof import('webpackbar').default | ||
| MiniCssExtractPlugin: typeof MiniCssExtractPluginType | ||
| TsCheckerPlugin: typeof TsCheckerPluginType | ||
| VueLoaderPlugin: typeof VueLoaderPluginConstructor | ||
| getVueLoaderHash: (value: string) => string | ||
| vueLoader: string | ||
| vueModuleIdentifierLoader: string | ||
| } |
| import { getBuilderImpl } from './builder-registry.ts' | ||
|
|
||
| export const { | ||
| builder, | ||
| webpack, | ||
| createRsbuild, | ||
| WebpackBarPlugin, | ||
| MiniCssExtractPlugin, | ||
| TsCheckerPlugin, | ||
| VueLoaderPlugin, | ||
| getVueLoaderHash, | ||
| vueLoader, | ||
| vueModuleIdentifierLoader, | ||
| } = getBuilderImpl() |
🔗 Linked issue
📚 Description
the key consequence of this PR is that tests in CI actually run against the rspack builder rather than the webpack one twice