@@ -7,7 +7,7 @@ import-protection core in `src/import-protection/INTERNALS.md`.
77
88Rsbuild owns:
99
10- - post-transform enforcement through ` api.transform({ order: ' post' }) `
10+ - post-transform enforcement through a Rspack post-loader
1111- virtual-module transport through ` VirtualModulesPlugin `
1212- compilation-truth reporting in ` processAssets `
1313- final graph reconstruction from Rspack compilation data
@@ -34,8 +34,10 @@ object:
34341 . ` onBeforeBuild `
35352 . ` onBeforeDevCompile `
36363 . ` modifyRspackConfig `
37- 4 . ` transform(..., { order: 'post' }) `
38- 5 . ` processAssets(..., { stage: 'report' }) `
37+ 4 . ` processAssets(..., { stage: 'report' }) `
38+
39+ ` modifyRspackConfig ` installs both the virtual-modules plugin and the
40+ environment-scoped import-protection post-loader.
3941
4042## State Model
4143
@@ -50,11 +52,6 @@ Shared adapter state contains:
5052- ` vmPlugins `
5153- ` readyVmPlugins `
5254- ` pendingWrites `
53- - ` moduleByResource `
54-
55- ` moduleByResource ` associates each loader resource with its Rspack module. The
56- loader hook populates it, the matching post-transform hook consumes it, and
57- durable marker metadata lives on ` module.buildInfo ` .
5855
5956Notably absent compared to Vite:
6057
@@ -65,7 +62,10 @@ Notably absent compared to Vite:
6562
6663## Transform Phase
6764
68- Rsbuild enforcement runs after the Start compiler in a ` post ` transform.
65+ Rsbuild enforcement runs after the Start compiler in a Rspack loader with
66+ ` enforce: 'post' ` . The complete transform pipeline lives in
67+ ` import-protection-loader.ts ` ; mutable configuration and per-environment state
68+ are passed through loader options.
6969
7070That matters because many compiler-safe imports are already stripped by the time
7171import protection runs. This naturally suppresses a large class of false
@@ -154,9 +154,16 @@ The Rsbuild adapter intentionally prefers native Rspack APIs where possible.
154154
155155Transform-time:
156156
157- - ` ctx.resource `
158- - ` ctx.context `
159- - ` ctx.resolve(...) `
157+ - ` loaderContext.resource `
158+ - ` loaderContext.resourcePath `
159+ - ` loaderContext.context `
160+ - ` loaderContext.resolve(...) `
161+ - ` loaderContext._module.buildInfo `
162+
163+ ` _module ` is a deprecated Rspack loader-context API. It is used deliberately
164+ because a loader invocation is bound to one exact module instance, including
165+ its layer. Keying modules by resource would collapse distinct modules that use
166+ the same resource in different layers. Do not add a resource-map fallback.
160167
161168Compilation-time:
162169
@@ -175,11 +182,11 @@ Compilation-time:
175182Unlike Vite, Rsbuild does not introduce plugin-owned virtual marker modules for
176183normal operation.
177184
178- The real package marker files are source-level markers. Rspack's loader hook
179- records the module under the exact loader resource. The matching post-transform
180- hook writes ` { kind, source } ` to ` module.buildInfo ` before replacing a
181- wrong-environment module. The metadata survives self-denial mocking and
182- persistent-cache restores.
185+ The real package marker files are source-level markers. The post- loader writes
186+ ` { kind, source } ` directly to its current ` _module.buildInfo ` before replacing
187+ a wrong-environment module. The metadata therefore stays attached to the exact
188+ resource-and-layer module and survives self-denial mocking and persistent-cache
189+ restores.
183190
184191` processAssets ` treats non-excluded, non-file-denied imports as possible marker
185192modules, then checks their ` buildInfo ` . It does not infer marker kind from final
0 commit comments