Skip to content

refactor(rspack,webpack): use DI model to split builders - #35751

Merged
danielroe merged 4 commits into
mainfrom
refactor/rspack
Jul 21, 2026
Merged

danielroe merged 4 commits into
mainfrom
refactor/rspack

Conversation

@danielroe

Copy link
Copy Markdown
Member

🔗 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

@socket-security

socket-security Bot commented Jul 20, 2026 •

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Added@​types/​hash-sum@​1.0.21001005479100

View full report

@coderabbitai

This comment has been minimized.

@github-actions github-actions Bot added 5.x ♻️ refactor Code restructuring without behavior change labels Jul 20, 2026
@pkg-pr-new

pkg-pr-new Bot commented Jul 20, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@nuxt/kit

npm i https://pkg.pr.new/@nuxt/kit@35751

@nuxt/nitro-server

npm i https://pkg.pr.new/@nuxt/nitro-server@35751

nuxt

npm i https://pkg.pr.new/nuxt@35751

@nuxt/rspack-builder

npm i https://pkg.pr.new/@nuxt/rspack-builder@35751

@nuxt/schema

npm i https://pkg.pr.new/@nuxt/schema@35751

@nuxt/vite-builder

npm i https://pkg.pr.new/@nuxt/vite-builder@35751

@nuxt/webpack-builder

npm i https://pkg.pr.new/@nuxt/webpack-builder@35751

commit: d4d267c

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/webpack/src/builder-registry.ts (1)

28-30: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Prevent multiple initialisations of the builder registry.

Because builder.ts destructures the registry values immediately upon module evaluation, calling setBuilderImpl a second time will not update those exported bindings, leading to a silent divergence in state. Throwing an error if _impl is 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

📥 Commits

Reviewing files that changed from the base of the PR and between e3f4498 and 827ee43.

📒 Files selected for processing (6)
  • packages/rspack/src/impl.ts
  • packages/webpack/src/builder-registry.ts
  • packages/webpack/src/builder.ts
  • packages/webpack/src/impl.ts
  • packages/webpack/src/plugins/chunk.ts
  • packages/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

Comment thread packages/webpack/src/builder.ts Resolved
@codspeed

codspeed Bot commented Jul 20, 2026 •

Copy link
Copy Markdown

Merging this PR will degrade performance by 14.12%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

❌ 1 regressed benchmark
✅ 20 untouched benchmarks
⏩ 3 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

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)

Open in CodSpeed

Footnotes

  1. 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. ↩

@danielroe
danielroe force-pushed the main branch 2 times, most recently from 791b61d to f2a96d5 Compare July 20, 2026 21:09
@danielroe
danielroe enabled auto-merge July 20, 2026 21:32
Copilot AI review requested due to automatic review settings July 21, 2026 09:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-builder impl.ts side-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-sum catalog 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.

Comment on lines +1 to +17
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
}
Comment on lines +1 to +14
import { getBuilderImpl } from './builder-registry.ts'

export const {
builder,
webpack,
createRsbuild,
WebpackBarPlugin,
MiniCssExtractPlugin,
TsCheckerPlugin,
VueLoaderPlugin,
getVueLoaderHash,
vueLoader,
vueModuleIdentifierLoader,
} = getBuilderImpl()
@danielroe
danielroe added this pull request to the merge queue Jul 21, 2026
Merged via the queue into main with commit cf8e798 Jul 21, 2026
33 checks passed
@danielroe
danielroe deleted the refactor/rspack branch July 21, 2026 16:34
@github-actions github-actions Bot mentioned this pull request Jul 21, 2026
2 of 5 tasks
@coderabbitai coderabbitai Bot mentioned this pull request Jul 21, 2026
3 tasks
@github-actions github-actions Bot mentioned this pull request Jul 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

5.x ♻️ refactor Code restructuring without behavior change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants