@octanejs/rspack-plugin 0.2.14 → 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/package.json +3 -3
- package/src/void-component-proofs.js +81 -17
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@octanejs/rspack-plugin",
|
|
3
|
-
"version": "0.2.
|
|
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.
|
|
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.
|
|
56
|
+
"octane": "0.23.0",
|
|
57
57
|
"vitest": "^4.1.10"
|
|
58
58
|
},
|
|
59
59
|
"scripts": {
|
|
@@ -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(
|
|
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 (
|
|
113
|
-
|
|
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(
|
|
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
|
-
|
|
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)
|
|
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 =
|
|
270
|
-
if (target?.memoExports.includes(imported)) hints.add(key);
|
|
271
|
-
if (proven.has(key)
|
|
272
|
-
|
|
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 = [
|
|
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
|