@octanejs/rspack-plugin 0.2.13 → 0.2.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -7,7 +7,7 @@ integration lives in `@octanejs/rsbuild-plugin`.
7
7
  ## Install
8
8
 
9
9
  ```sh
10
- pnpm add octane @tsrx/oxc@0.23.0
10
+ pnpm add octane @tsrx/oxc@0.24.0
11
11
  pnpm add -D @rspack/core @octanejs/rspack-plugin
12
12
  ```
13
13
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@octanejs/rspack-plugin",
3
- "version": "0.2.13",
3
+ "version": "0.2.15",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "engines": {
@@ -45,7 +45,7 @@
45
45
  },
46
46
  "peerDependencies": {
47
47
  "@rspack/core": "^2.0.0",
48
- "octane": "^0.21.0"
48
+ "octane": "^0.23.0"
49
49
  },
50
50
  "devDependencies": {
51
51
  "@rspack/core": "^2.1.4",
@@ -53,7 +53,7 @@
53
53
  "@types/node": "^24.13.3",
54
54
  "css-loader": "6.11.0",
55
55
  "jsdom": "^30.0.1",
56
- "octane": "0.21.0",
56
+ "octane": "0.23.0",
57
57
  "vitest": "^4.1.10"
58
58
  },
59
59
  "scripts": {
package/src/plugin.js CHANGED
@@ -114,6 +114,21 @@ function addRuntimeAliases(compiler, request, root, explicitRuntime, environment
114
114
  const packageRoot = octanePackageRoot(override) ?? octanePackageRoot(selected) ?? root;
115
115
  const aliases = esm.alias === false ? {} : (esm.alias ?? {});
116
116
  const additions = {};
117
+ // An explicit runtime that selects the package's CommonJS build keeps the
118
+ // private entries compiled helpers import in that same module graph.
119
+ let subpathResolver = packageResolver;
120
+ if (
121
+ override !== undefined &&
122
+ override !== resolveRuntimeModule(packageResolver, 'octane', packageRoot)
123
+ ) {
124
+ const commonjs = compiler.resolverFactory.get('normal', {
125
+ ...compiler.webpack.util.cleverMerge(base, byDependency?.commonjs ?? {}),
126
+ alias: false,
127
+ dependencyType: 'commonjs',
128
+ });
129
+ if (resolveRuntimeModule(commonjs, 'octane', packageRoot) === override)
130
+ subpathResolver = commonjs;
131
+ }
117
132
  for (const subpath of RUNTIME_SUBPATHS) {
118
133
  // Resolve package self-references without a broad `octane` alias. Linked
119
134
  // packages must share the selected runtime's refs, context, and profiler.
@@ -121,7 +136,7 @@ function addRuntimeAliases(compiler, request, root, explicitRuntime, environment
121
136
  additions[`${subpath}$`] =
122
137
  aliases[`${subpath}$`] ??
123
138
  aliases[subpath] ??
124
- resolveRuntimeModule(packageResolver, subpath, packageRoot);
139
+ resolveRuntimeModule(subpathResolver, subpath, packageRoot);
125
140
  }
126
141
  if (environment === 'server') {
127
142
  const serverRequest = 'octane/react/server';
@@ -8,6 +8,7 @@ import {
8
8
  rebuildModules,
9
9
  sameStrings,
10
10
  sourceHash,
11
+ targetForRequest,
11
12
  targetsFor,
12
13
  } from './module-graph.js';
13
14
  import {
@@ -87,6 +88,7 @@ function finalFacts(module, id, analyses) {
87
88
  analysis === null
88
89
  ? null
89
90
  : new Map(analysis.importBindings.map((binding) => [binding.local, binding])),
91
+ reexports: analysis?.reexports ?? [],
90
92
  };
91
93
  analyses.set(id, facts);
92
94
  }
@@ -105,15 +107,52 @@ function finalFacts(module, id, analyses) {
105
107
  * `anchorless` proof (`list`) also needs the build behind that final code to
106
108
  * have listed the export there.
107
109
  */
108
- function provenProvider(target, imported, analyses, deferred = false, list = undefined) {
110
+ function provenProvider(
111
+ compilation,
112
+ target,
113
+ imported,
114
+ analyses,
115
+ deferred = false,
116
+ list = undefined,
117
+ ) {
118
+ const resolved = resolveReexport(compilation, target, imported, analyses);
119
+ if (resolved === null) return null;
120
+ ({ target, imported } = resolved);
109
121
  const id = identifier(target);
110
- if (id === null || !JAVASCRIPT_TYPES.has(target.type)) return null;
111
122
  const info = candidateInfo(target);
112
- if (!info?.exports.includes(imported) || (list !== undefined && !info[list].includes(imported)))
113
- return null;
114
- if (deferred && info.imports.length > 0) return { id };
123
+ if (list !== undefined && !info[list].includes(imported)) return null;
124
+ const { chain } = resolved;
125
+ if (deferred && info.imports.length > 0) return { id, chain };
115
126
  const facts = finalFacts(target, id, analyses);
116
- return facts?.exports.has(imported) ? { id, fingerprint: facts.fingerprint } : null;
127
+ return facts?.exports.has(imported) ? { id, fingerprint: facts.fingerprint, chain } : null;
128
+ }
129
+
130
+ /**
131
+ * The module whose Octane build listed `imported` as a void export, reached
132
+ * from `target` through exact `export { a as b } from '...'` re-exports in each
133
+ * intermediate module's final code, such as a plain `.ts` index over `.tsrx`
134
+ * components. An ESM re-export is a live binding its module cannot reassign.
135
+ * `chain` records each intermediate hop's request, identity and final source
136
+ * so the receipt fails closed if any hop changes later.
137
+ */
138
+ function resolveReexport(compilation, target, imported, analyses) {
139
+ const chain = [];
140
+ const visited = new Set();
141
+ for (;;) {
142
+ const id = identifier(target);
143
+ if (id === null || !JAVASCRIPT_TYPES.has(target.type) || visited.has(id)) return null;
144
+ visited.add(id);
145
+ if (candidateInfo(target)?.exports.includes(imported)) return { target, imported, chain };
146
+ const facts = finalFacts(target, id, analyses);
147
+ // A module exports each name once, so at most one re-export matches.
148
+ const reexport = facts?.reexports.find((entry) => entry.exported === imported);
149
+ if (reexport === undefined) return null;
150
+ const next = targetForRequest(compilation, target, reexport.request);
151
+ if (next == null) return null;
152
+ chain.push({ request: reexport.request, from: id, fingerprint: facts.fingerprint });
153
+ target = next;
154
+ imported = reexport.imported;
155
+ }
117
156
  }
118
157
 
119
158
  /**
@@ -170,7 +209,14 @@ function receiptRebuilt(compilation, state, analyses) {
170
209
  const targets = targetsFor(compilation, importer, requestsOf(consumed));
171
210
  const imports = [];
172
211
  for (const { request, imported, list } of consumed) {
173
- const provider = provenProvider(targets.get(request), imported, analyses, false, list);
212
+ const provider = provenProvider(
213
+ compilation,
214
+ targets.get(request),
215
+ imported,
216
+ analyses,
217
+ false,
218
+ list,
219
+ );
174
220
  if (provider === null) break;
175
221
  imports.push({ request, imported, ...provider });
176
222
  }
@@ -209,7 +255,15 @@ function verifyGraph(compilation, state) {
209
255
  }
210
256
  const targets = targetsFor(compilation, importer, requestsOf(receipt.imports));
211
257
  for (const entry of receipt.imports) {
212
- const target = targets.get(entry.request);
258
+ let target = targets.get(entry.request);
259
+ for (const hop of entry.chain) {
260
+ if (identifier(target) !== hop.from)
261
+ changed(id, entry.request, 'the effective module identity differs');
262
+ const reexported = moduleSource(target);
263
+ if (reexported === null || sourceHash(reexported) !== hop.fingerprint)
264
+ changed(id, entry.request, 'the final re-exporting source differs');
265
+ target = targetForRequest(compilation, target, hop.request);
266
+ }
213
267
  if (identifier(target) !== entry.id)
214
268
  changed(id, entry.request, 'the effective module identity differs');
215
269
  const provided = moduleSource(target);
@@ -225,7 +279,10 @@ function verifyFinalSources(compilation, state) {
225
279
  const expected = new Map();
226
280
  for (const [id, receipt] of state.receipts) {
227
281
  expected.set(id, receipt.fingerprint);
228
- for (const entry of receipt.imports) expected.set(entry.id, entry.fingerprint);
282
+ for (const entry of receipt.imports) {
283
+ expected.set(entry.id, entry.fingerprint);
284
+ for (const hop of entry.chain) expected.set(hop.from, hop.fingerprint);
285
+ }
229
286
  }
230
287
  for (const [id, fingerprint] of expected) {
231
288
  const module = modules.get(id);
@@ -250,7 +307,7 @@ function verifyFinalSources(compilation, state) {
250
307
  * runtime witness, so a stale hint costs only a miss. A consumed lite proof is
251
308
  * receipted like a void one. Returns the importers that gained either.
252
309
  */
253
- function collectHints(compilation, state) {
310
+ function collectHints(compilation, state, analyses) {
254
311
  const grown = [];
255
312
  for (const [id, importer] of currentModules(compilation.modules)) {
256
313
  const info = candidateInfo(importer);
@@ -266,10 +323,15 @@ function collectHints(compilation, state) {
266
323
  const size = hints.size + lite.size + anchorless.size;
267
324
  for (const { request, imported } of info.imports) {
268
325
  const key = voidImportKey(request, imported);
269
- const target = candidateInfo(targets.get(request));
270
- if (target?.memoExports.includes(imported)) hints.add(key);
271
- if (proven.has(key) && target?.lite.includes(imported)) lite.add(key);
272
- if (proven.has(key) && target?.anchorless.includes(imported)) anchorless.add(key);
326
+ const target = targets.get(request);
327
+ if (candidateInfo(target)?.memoExports.includes(imported)) hints.add(key);
328
+ if (!proven.has(key)) continue;
329
+ // Lite lists belong to the module that compiled the export, which a
330
+ // proven import may reach through re-exports.
331
+ const provider = resolveReexport(compilation, target, imported, analyses);
332
+ const listed = provider === null ? null : candidateInfo(provider.target);
333
+ if (listed?.lite.includes(provider.imported)) lite.add(key);
334
+ if (listed?.anchorless.includes(provider.imported)) anchorless.add(key);
273
335
  }
274
336
  if (hints.size + lite.size + anchorless.size === size) continue;
275
337
  state.memo.set(id, [...hints]);
@@ -301,16 +363,18 @@ async function collectAndRebuild(compilation, state) {
301
363
  const imports = info.imports.filter(
302
364
  ({ request, imported }) =>
303
365
  targets.get(request) != null &&
304
- provenProvider(targets.get(request), imported, analyses, true) !== null,
366
+ provenProvider(compilation, targets.get(request), imported, analyses, true) !== null,
305
367
  );
306
368
  if (imports.length > 0)
307
369
  state.proofs.set(id, { sourceHash: info.sourceHash, imports, lite: [], anchorless: [] });
308
370
  }
309
371
  }
310
- let rebuild = [...new Set([...state.proofs.keys(), ...collectHints(compilation, state)])];
372
+ let rebuild = [
373
+ ...new Set([...state.proofs.keys(), ...collectHints(compilation, state, analyses)]),
374
+ ];
311
375
  if (rebuild.length === 0) return;
312
376
  do await rebuildModules(compilation, rebuild, changed);
313
- while ((rebuild = collectHints(compilation, state)).length > 0);
377
+ while ((rebuild = collectHints(compilation, state, analyses)).length > 0);
314
378
  // Every consumed provider is proven on its final code here, including one
315
379
  // rebuilt as an importer in these rounds. A later loader can also rewrite
316
380
  // what Octane specialized; an importer whose proof does not hold is rebuilt