@octanejs/rspack-plugin 0.2.3 → 0.2.5

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
@@ -66,8 +66,11 @@ shape and `use*` spelling do not disable that optimization:
66
66
  new OctaneRspackPlugin({ strong: true });
67
67
  ```
68
68
 
69
- Dependencies keep their existing compatibility behavior. Any module can opt in
70
- on its own by putting `"use strong"` before its imports. Strong analysis is
69
+ Strong compiles `.tsrx`, `.ts`, and `.js` modules, so convert application
70
+ `.tsx` and `.jsx` modules to `.tsrx` first; the build reports
71
+ `OCTANE_STRONG_TSX_MODULE` for any it reaches. Dependencies keep their existing
72
+ compatibility behavior. Any `.tsrx`, `.ts`, or `.js` module can opt in on its
73
+ own by putting `"use strong"` before its imports. Strong analysis is
71
74
  bounded: unknown calls are assumed pure, so live accessors must remain in a
72
75
  compatibility-mode consumer or receive an actual snapshot.
73
76
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@octanejs/rspack-plugin",
3
- "version": "0.2.3",
3
+ "version": "0.2.5",
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.13.0"
48
+ "octane": "^0.14.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.13.0",
56
+ "octane": "0.14.0",
57
57
  "vitest": "^4.1.10"
58
58
  },
59
59
  "scripts": {
@@ -5,6 +5,7 @@ import {
5
5
  } from './css-module-data.js';
6
6
  import {
7
7
  clearVoidComponentBuildInfo,
8
+ lowersOnly,
8
9
  VOID_COMPONENT_BUILD_INFO_KEY,
9
10
  VOID_COMPONENT_CONTEXT_KEY,
10
11
  } from './void-component-data.js';
@@ -17,7 +18,9 @@ export function pitch() {
17
18
  this.data ??= {};
18
19
  this.data.octaneLayer = this._module?.layer ?? null;
19
20
  this.data[CSS_MODULE_CONTEXT_KEY] = this[CSS_MODULE_CONTEXT_KEY] ?? null;
20
- this.data[VOID_COMPONENT_CONTEXT_KEY] = this[VOID_COMPONENT_CONTEXT_KEY] ?? null;
21
+ const voidComponents = this[VOID_COMPONENT_CONTEXT_KEY];
22
+ this.data[VOID_COMPONENT_CONTEXT_KEY] =
23
+ voidComponents == null ? null : { ...voidComponents, lowersOnly: lowersOnly(this) };
21
24
  clearCssModuleBuildInfo(this._module);
22
25
  clearVoidComponentBuildInfo(this._module);
23
26
  if (this._module?.buildInfo && typeof this._module.buildInfo === 'object') {
@@ -13,10 +13,84 @@ const RELATIVE_IMPORT = /\bfrom\s*['"]\.\.?\//;
13
13
  const ROOT_FACTORY_IMPORT =
14
14
  /\bimport\s*\{[^}]*\b(?:createRoot|hydrateRoot)\b[^}]*\}\s*from\s*['"]octane['"]/;
15
15
 
16
+ // SWC options that only parse, lower syntax, or add helper and polyfill
17
+ // imports. Any other option, such as optimizer globals, const modules, import
18
+ // rewrites, React transforms, minification or wasm plugins, can rewrite a body.
19
+ const LOWERING_SWC_OPTIONS = {
20
+ detectSyntax: true,
21
+ isModule: true,
22
+ sourceMaps: true,
23
+ inputSourceMap: true,
24
+ collectTypeScriptInfo: true,
25
+ env: true,
26
+ jsc: {
27
+ parser: true,
28
+ target: true,
29
+ loose: true,
30
+ externalHelpers: true,
31
+ keepClassNames: true,
32
+ output: true,
33
+ experimental: {
34
+ cacheRoot: true,
35
+ keepImportAttributes: true,
36
+ emitAssertForImportAttributes: true,
37
+ disableAllLints: true,
38
+ },
39
+ transform: {
40
+ legacyDecorator: true,
41
+ decoratorMetadata: true,
42
+ decoratorVersion: true,
43
+ useDefineForClassFields: true,
44
+ verbatimModuleSyntax: true,
45
+ },
46
+ },
47
+ };
48
+
49
+ function lowersOnlyOptions(options, allowed = LOWERING_SWC_OPTIONS) {
50
+ return (
51
+ options !== null &&
52
+ typeof options === 'object' &&
53
+ Object.entries(options).every(([key, value]) => {
54
+ const rule = Object.hasOwn(allowed, key) ? allowed[key] : undefined;
55
+ return (
56
+ value === undefined ||
57
+ rule === true ||
58
+ (rule !== undefined && lowersOnlyOptions(value, rule))
59
+ );
60
+ })
61
+ );
62
+ }
63
+
16
64
  export function voidImportKey(request, imported) {
17
65
  return `${request}\0${imported}`;
18
66
  }
19
67
 
68
+ // A relative request never starts with these prefixes, so the keys cannot collide.
69
+ export function liteImportKey(request, imported) {
70
+ return `lite\0${voidImportKey(request, imported)}`;
71
+ }
72
+
73
+ export function anchorlessImportKey(request, imported) {
74
+ return `anchorless\0${voidImportKey(request, imported)}`;
75
+ }
76
+
77
+ /**
78
+ * Lite is a fact about the body Octane emitted: it calls no hook and reads no
79
+ * context or signal that an importer's lite edge would misplace. Only SWC's
80
+ * syntax lowering may stand between that body and the module's final code; any
81
+ * other later loader or SWC option could add such a read. Loader options are
82
+ * visible on the main thread only, so the parallel finalizer's pitch, which
83
+ * runs after every later loader is known, records this for its worker.
84
+ */
85
+ export function lowersOnly(context) {
86
+ return (
87
+ context.loaders
88
+ ?.slice(0, context.loaderIndex)
89
+ .every(({ path, options }) => path === 'builtin:swc-loader' && lowersOnlyOptions(options)) ===
90
+ true
91
+ );
92
+ }
93
+
20
94
  export function clearVoidComponentBuildInfo(module) {
21
95
  if (module?.buildInfo && typeof module.buildInfo === 'object') {
22
96
  delete module.buildInfo[VOID_COMPONENT_BUILD_INFO_KEY];
@@ -25,9 +99,10 @@ export function clearVoidComponentBuildInfo(module) {
25
99
 
26
100
  /**
27
101
  * Prepare this exact authored loader input's void-component facts. Every build
28
- * the controller enables records its own void exports and candidate imports,
29
- * so cached modules carry the same facts in a watch and a one-shot build. Only
30
- * a one-shot build's proof pass supplies proven imports.
102
+ * the controller enables records its own void, memo and lite exports and
103
+ * candidate imports, so cached modules carry the same facts in a watch and a
104
+ * one-shot build. Only a one-shot build's proof pass supplies proven imports,
105
+ * lite proofs and memo hints.
31
106
  */
32
107
  export function prepareVoidComponents(context, source, id, options) {
33
108
  const data = context[VOID_COMPONENT_CONTEXT_KEY];
@@ -47,9 +122,12 @@ export function prepareVoidComponents(context, source, id, options) {
47
122
  hash !== null && data.proof.sourceHash === hash
48
123
  ? new Set(data.proof.imports.map(({ request, imported }) => voidImportKey(request, imported)))
49
124
  : null;
50
- // A proof is a fact about other modules' final output, outside this module's
51
- // cache key. Output that may consume one is never cached.
52
- if (proven !== null) context.cacheable?.(false);
125
+ const lite = new Set(proven === null ? null : data.proof.lite);
126
+ const anchorless = new Set(proven === null ? null : data.proof.anchorless);
127
+ const memo = new Set(data.memo);
128
+ // A proof or hint is a fact about other modules' output, outside this
129
+ // module's cache key. Output that may consume one is never cached.
130
+ if (proven !== null || memo.size > 0) context.cacheable?.(false);
53
131
  const consumed = new Set();
54
132
  return {
55
133
  source,
@@ -58,6 +136,9 @@ export function prepareVoidComponents(context, source, id, options) {
58
136
  consumed,
59
137
  transformOptions: {
60
138
  collectVoidComponentExports: true,
139
+ // Always answered, so an export over an unhinted import publishes no
140
+ // memo proof of its own.
141
+ isCompilerMemoImport: (request, imported) => memo.has(voidImportKey(request, imported)),
61
142
  ...(proven === null
62
143
  ? null
63
144
  : {
@@ -67,6 +148,21 @@ export function prepareVoidComponents(context, source, id, options) {
67
148
  consumed.add(key);
68
149
  return true;
69
150
  },
151
+ // A lite proof rests on the import's void proof, so it consumes both.
152
+ isLiteComponentImport(request, imported) {
153
+ const key = voidImportKey(request, imported);
154
+ if (!lite.has(key)) return false;
155
+ consumed.add(key);
156
+ consumed.add(liteImportKey(request, imported));
157
+ return true;
158
+ },
159
+ isAnchorlessComponentImport(request, imported) {
160
+ const key = voidImportKey(request, imported);
161
+ if (!anchorless.has(key)) return false;
162
+ consumed.add(key);
163
+ consumed.add(anchorlessImportKey(request, imported));
164
+ return true;
165
+ },
70
166
  }),
71
167
  },
72
168
  };
@@ -83,11 +179,21 @@ export function finishVoidComponents(context, prepared, result) {
83
179
  const compiled = result?.kind === 'compile';
84
180
  const exports =
85
181
  compiled && Array.isArray(result.voidComponentExports) ? result.voidComponentExports : [];
182
+ const memoExports =
183
+ compiled && Array.isArray(result.compilerMemoExports) ? result.compilerMemoExports : [];
184
+ const lowered =
185
+ compiled && (context[VOID_COMPONENT_CONTEXT_KEY].lowersOnly ?? lowersOnly(context));
186
+ const lite =
187
+ lowered && Array.isArray(result.liteComponentExports) ? result.liteComponentExports : [];
188
+ const anchorless =
189
+ lowered && Array.isArray(result.anchorlessComponentExports)
190
+ ? result.anchorlessComponentExports
191
+ : [];
86
192
  const imports =
87
193
  RELATIVE_IMPORT.test(prepared.source) && (compiled || ROOT_FACTORY_IMPORT.test(prepared.source))
88
194
  ? findVoidComponentImports(prepared.source, prepared.id)
89
195
  : [];
90
- if (exports.length === 0 && imports.length === 0) return;
196
+ if (exports.length === 0 && memoExports.length === 0 && imports.length === 0) return;
91
197
  const consumed = [...prepared.consumed].sort();
92
198
  // null (unparseable output) can never match the final code's bindings.
93
199
  const bindings =
@@ -100,6 +206,9 @@ export function finishVoidComponents(context, prepared, result) {
100
206
  module.buildInfo[VOID_COMPONENT_BUILD_INFO_KEY] = {
101
207
  sourceHash: prepared.sourceHash ?? sourceHash(prepared.source),
102
208
  exports: [...exports],
209
+ memoExports: [...memoExports],
210
+ lite: [...lite],
211
+ anchorless: [...anchorless],
103
212
  imports: imports.map(({ request, imported }) => ({ request, imported })),
104
213
  consumed,
105
214
  bindings,
@@ -11,6 +11,8 @@ import {
11
11
  targetsFor,
12
12
  } from './module-graph.js';
13
13
  import {
14
+ anchorlessImportKey,
15
+ liteImportKey,
14
16
  VOID_COMPONENT_BUILD_INFO_KEY,
15
17
  VOID_COMPONENT_CONTEXT_KEY,
16
18
  voidImportKey,
@@ -46,6 +48,9 @@ function candidateInfo(module) {
46
48
  typeof info.sourceHash !== 'string' ||
47
49
  !HASH.test(info.sourceHash) ||
48
50
  !strings(info.exports) ||
51
+ !strings(info.memoExports) ||
52
+ !strings(info.lite) ||
53
+ !strings(info.anchorless) ||
49
54
  !strings(info.consumed) ||
50
55
  !importEntries(info.imports, false) ||
51
56
  (info.bindings !== null && !importEntries(info.bindings, true))
@@ -96,13 +101,16 @@ function finalFacts(module, id, analyses) {
96
101
  *
97
102
  * While proofs are collected, a provider that can consume proofs itself is
98
103
  * usually about to be rebuilt, so its current code is not what will run. Its
99
- * final code is proven after the rebuild instead (`deferred`).
104
+ * final code is proven after the rebuild instead (`deferred`). A `lite` or
105
+ * `anchorless` proof (`list`) also needs the build behind that final code to
106
+ * have listed the export there.
100
107
  */
101
- function provenProvider(target, imported, analyses, deferred = false) {
108
+ function provenProvider(target, imported, analyses, deferred = false, list = undefined) {
102
109
  const id = identifier(target);
103
110
  if (id === null || !JAVASCRIPT_TYPES.has(target.type)) return null;
104
111
  const info = candidateInfo(target);
105
- if (!info?.exports.includes(imported)) return null;
112
+ if (!info?.exports.includes(imported) || (list !== undefined && !info[list].includes(imported)))
113
+ return null;
106
114
  if (deferred && info.imports.length > 0) return { id };
107
115
  const facts = finalFacts(target, id, analyses);
108
116
  return facts?.exports.has(imported) ? { id, fingerprint: facts.fingerprint } : null;
@@ -115,7 +123,13 @@ function provenProvider(target, imported, analyses, deferred = false) {
115
123
  */
116
124
  function bindingsHold(info, facts) {
117
125
  if (info.bindings === null || facts.bindings === null) return false;
118
- const bound = new Set(info.bindings.map((entry) => voidImportKey(entry.request, entry.imported)));
126
+ const bound = new Set(
127
+ info.bindings.flatMap(({ request, imported }) => [
128
+ voidImportKey(request, imported),
129
+ liteImportKey(request, imported),
130
+ anchorlessImportKey(request, imported),
131
+ ]),
132
+ );
119
133
  if (!info.consumed.every((key) => bound.has(key))) return false;
120
134
  return info.bindings.every((entry) => {
121
135
  const binding = facts.bindings.get(entry.local);
@@ -137,17 +151,26 @@ function receiptRebuilt(compilation, state, analyses) {
137
151
  changed(id, undefined, 'the authored source changed while rebuilding');
138
152
  }
139
153
  if (info.consumed.length === 0) continue;
140
- const supplied = new Map(
141
- proof.imports.map((entry) => [voidImportKey(entry.request, entry.imported), entry]),
142
- );
154
+ const supplied = new Map();
155
+ for (const entry of proof.imports) {
156
+ const key = voidImportKey(entry.request, entry.imported);
157
+ supplied.set(key, entry);
158
+ if (proof.lite.includes(key))
159
+ supplied.set(liteImportKey(entry.request, entry.imported), { ...entry, list: 'lite' });
160
+ if (proof.anchorless.includes(key))
161
+ supplied.set(anchorlessImportKey(entry.request, entry.imported), {
162
+ ...entry,
163
+ list: 'anchorless',
164
+ });
165
+ }
143
166
  if (info.consumed.some((key) => !supplied.has(key))) {
144
167
  changed(id, undefined, 'the compiler consumed an unprovided import');
145
168
  }
146
169
  const consumed = info.consumed.map((key) => supplied.get(key));
147
170
  const targets = targetsFor(compilation, importer, requestsOf(consumed));
148
171
  const imports = [];
149
- for (const { request, imported } of consumed) {
150
- const provider = provenProvider(targets.get(request), imported, analyses);
172
+ for (const { request, imported, list } of consumed) {
173
+ const provider = provenProvider(targets.get(request), imported, analyses, false, list);
151
174
  if (provider === null) break;
152
175
  imports.push({ request, imported, ...provider });
153
176
  }
@@ -216,6 +239,49 @@ function verifyFinalSources(compilation, state) {
216
239
  }
217
240
  }
218
241
 
242
+ /**
243
+ * Hint each candidate import whose target's latest build listed it as a memo
244
+ * export, and supply a lite or anchorless proof for each proven import listed
245
+ * as one. A rebuild over either can publish more of both (an export over a lite
246
+ * import needs no context refresh), so callers repeat this until no importer
247
+ * gains one. Both only accumulate from what an earlier round published, which
248
+ * bounds the rounds by the import graph and never lets a cycle prove itself
249
+ * lite. Hints need no final-code proof: an importer's region still reads the
250
+ * runtime witness, so a stale hint costs only a miss. A consumed lite proof is
251
+ * receipted like a void one. Returns the importers that gained either.
252
+ */
253
+ function collectHints(compilation, state) {
254
+ const grown = [];
255
+ for (const [id, importer] of currentModules(compilation.modules)) {
256
+ const info = candidateInfo(importer);
257
+ if (!(info?.imports.length > 0)) continue;
258
+ const targets = targetsFor(compilation, importer, requestsOf(info.imports));
259
+ const proof = state.proofs.get(id);
260
+ const proven = new Set(
261
+ proof?.imports.map((entry) => voidImportKey(entry.request, entry.imported)),
262
+ );
263
+ const hints = new Set(state.memo.get(id));
264
+ const lite = new Set(proof?.lite);
265
+ const anchorless = new Set(proof?.anchorless);
266
+ const size = hints.size + lite.size + anchorless.size;
267
+ for (const { request, imported } of info.imports) {
268
+ 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);
273
+ }
274
+ if (hints.size + lite.size + anchorless.size === size) continue;
275
+ state.memo.set(id, [...hints]);
276
+ if (proof !== undefined) {
277
+ proof.lite = [...lite];
278
+ proof.anchorless = [...anchorless];
279
+ }
280
+ grown.push(id);
281
+ }
282
+ return grown;
283
+ }
284
+
219
285
  async function collectAndRebuild(compilation, state) {
220
286
  if (state.started) return;
221
287
  state.started = true;
@@ -237,17 +303,21 @@ async function collectAndRebuild(compilation, state) {
237
303
  targets.get(request) != null &&
238
304
  provenProvider(targets.get(request), imported, analyses, true) !== null,
239
305
  );
240
- if (imports.length > 0) state.proofs.set(id, { sourceHash: info.sourceHash, imports });
306
+ if (imports.length > 0)
307
+ state.proofs.set(id, { sourceHash: info.sourceHash, imports, lite: [], anchorless: [] });
241
308
  }
242
309
  }
243
- if (state.proofs.size === 0) return;
244
- await rebuildModules(compilation, [...state.proofs.keys()], changed);
310
+ let rebuild = [...new Set([...state.proofs.keys(), ...collectHints(compilation, state)])];
311
+ if (rebuild.length === 0) return;
312
+ do await rebuildModules(compilation, rebuild, changed);
313
+ while ((rebuild = collectHints(compilation, state)).length > 0);
245
314
  // Every consumed provider is proven on its final code here, including one
246
- // rebuilt as an importer in this batch. A later loader can also rewrite
315
+ // rebuilt as an importer in these rounds. A later loader can also rewrite
247
316
  // what Octane specialized; an importer whose proof does not hold is rebuilt
248
- // once more without one. Any change after that fails closed.
249
- const invalid = receiptRebuilt(compilation, state, analyses);
250
- if (invalid.length > 0) {
317
+ // without one. That can withdraw lite exports its own importers consumed,
318
+ // so repeat until every remaining receipt holds. Each importer is rebuilt
319
+ // generically at most once.
320
+ for (let invalid; (invalid = receiptRebuilt(compilation, state, analyses)).length > 0;) {
251
321
  for (const id of invalid) state.proofs.delete(id);
252
322
  await rebuildModules(compilation, invalid, changed);
253
323
  const modules = currentModules(compilation.modules);
@@ -257,8 +327,6 @@ async function collectAndRebuild(compilation, state) {
257
327
  }
258
328
  }
259
329
  state.receipts.clear();
260
- const unstable = receiptRebuilt(compilation, state, analyses);
261
- if (unstable.length > 0) changed(unstable[0], undefined, 'a consumed proof no longer holds');
262
330
  }
263
331
  verifyGraph(compilation, state);
264
332
  }
@@ -267,9 +335,11 @@ async function collectAndRebuild(compilation, state) {
267
335
  * Prove imported void components for production client builds. Rspack runs a
268
336
  * loader before it knows its module's outgoing edges or their final output, so
269
337
  * the proof is established after make from the effective graph, then supplied
270
- * to a rebuild of each importer that can use it. A one-shot build consumes
271
- * proofs and fails closed if any proven module changes later; a watch build
272
- * only records the facts its cached modules need for a later one-shot build.
338
+ * to a rebuild of each importer that can use it, with the lite proofs and
339
+ * compiler memo hints its imports' modules published. A one-shot build
340
+ * consumes proofs and hints and fails closed if any proven module changes
341
+ * later; a watch build only records the facts its cached modules need for a
342
+ * later one-shot build.
273
343
  */
274
344
  export function installVoidComponentProofs(compiler) {
275
345
  const NormalModule = compiler.webpack?.NormalModule;
@@ -286,6 +356,7 @@ export function installVoidComponentProofs(compiler) {
286
356
  discoverOnly: !oneShotProduction(compiler),
287
357
  started: false,
288
358
  proofs: new Map(),
359
+ memo: new Map(),
289
360
  receipts: new Map(),
290
361
  };
291
362
  states.set(compilation, state);
@@ -293,6 +364,7 @@ export function installVoidComponentProofs(compiler) {
293
364
  context[VOID_COMPONENT_CONTEXT_KEY] = {
294
365
  enabled: true,
295
366
  proof: state.proofs.get(identifier(module)) ?? null,
367
+ memo: state.memo.get(identifier(module)) ?? null,
296
368
  };
297
369
  });
298
370
  if (state.discoverOnly) return;