@octanejs/rspack-plugin 0.2.8 → 0.2.10

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.20.0
10
+ pnpm add octane @tsrx/oxc@0.23.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.8",
3
+ "version": "0.2.10",
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.16.0"
48
+ "octane": "^0.18.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.16.0",
56
+ "octane": "0.18.0",
57
57
  "vitest": "^4.1.10"
58
58
  },
59
59
  "scripts": {
@@ -0,0 +1,21 @@
1
+ // `octane/data/manifest` resolves to this file, and this loader replaces it
2
+ // with the manifest generated from the project's `*.data.ts` modules.
3
+ import { createDataProgram } from 'octane/compiler/bundler';
4
+
5
+ /** One program per root, so unchanged contract modules are not reparsed. */
6
+ const programs = new Map();
7
+
8
+ export default function dataManifestLoader() {
9
+ const { root } = this.getOptions();
10
+ let program = programs.get(root);
11
+ if (program === undefined) {
12
+ program = createDataProgram(root);
13
+ programs.set(root, program);
14
+ }
15
+ // Adding or removing a contract module anywhere under the root rebuilds it.
16
+ program.invalidate();
17
+ this.addContextDependency(root);
18
+ const { code, files } = program.manifest();
19
+ for (const file of files) this.addDependency(file);
20
+ return code;
21
+ }
package/src/loader.js CHANGED
@@ -127,6 +127,9 @@ export default function octaneLoader(source, inputSourceMap) {
127
127
  root,
128
128
  profile,
129
129
  ...(options.strong === undefined ? null : { strong: options.strong }),
130
+ ...(options.strongDependencies === undefined
131
+ ? null
132
+ : { strongDependencies: options.strongDependencies }),
130
133
  ...(options.knownAttributeSpreads === undefined
131
134
  ? null
132
135
  : { knownAttributeSpreads: options.knownAttributeSpreads }),
package/src/plugin.js CHANGED
@@ -5,9 +5,13 @@ import { dirname, isAbsolute, join, resolve } from 'node:path';
5
5
  import { fileURLToPath } from 'node:url';
6
6
  import {
7
7
  CLIENT_REFERENCE_MANIFEST_FILENAME,
8
+ DATA_WORKER_PATH,
9
+ DATA_MANIFEST_MODULE,
8
10
  INDEPENDENT_HYDRATION_MANIFEST_FILENAME,
9
11
  createClientReferenceManifest,
12
+ createDataProgram,
10
13
  createOctaneCompiler,
14
+ formatDataDiagnostic,
11
15
  } from 'octane/compiler/bundler';
12
16
  import { installCssModuleConstants } from './css-module-constants.js';
13
17
  import { createStreamedSignalHmrRuntimeModule } from './streamed-signals-hmr.js';
@@ -29,6 +33,7 @@ const PLUGIN_VERSION = createRequire(import.meta.url)('../package.json').version
29
33
  const loaderPath = fileURLToPath(new URL('./loader.js', import.meta.url));
30
34
  const finalizeLoaderPath = fileURLToPath(new URL('./finalize-loader.js', import.meta.url));
31
35
  const parallelLoaderPath = fileURLToPath(new URL('./parallel-loader.js', import.meta.url));
36
+ const dataManifestPath = fileURLToPath(new URL('./data-manifest.js', import.meta.url));
32
37
  const DEFAULT_MAX_WORKERS = 4;
33
38
  const OCTANE_RULE = /\.(?:tsrx|tsx|ts|js)$/i;
34
39
  const TYPESCRIPT_RULE = /\.(?:tsrx|tsx|ts)$/i;
@@ -185,6 +190,9 @@ function createDiscoveryCompiler(options, root, profile, specialization) {
185
190
  root,
186
191
  profile,
187
192
  ...(options.strong === undefined ? null : { strong: options.strong }),
193
+ ...(options.strongDependencies === undefined
194
+ ? null
195
+ : { strongDependencies: options.strongDependencies }),
188
196
  ...(options.knownAttributeSpreads === undefined
189
197
  ? null
190
198
  : { knownAttributeSpreads: options.knownAttributeSpreads }),
@@ -546,6 +554,15 @@ export class OctaneRspackPlugin {
546
554
  ? realRoot(resolve(root, this.options.textTypes.tsconfig))
547
555
  : undefined;
548
556
  assertProfilingDefineAvailable(compiler, profile);
557
+ if (this.options.dataWorker && environment === 'client') {
558
+ // The data worker keeps one path across deploys, so every tab shares one SharedWorker.
559
+ new compiler.webpack.EntryPlugin(compilerRoot, this.options.dataWorker, {
560
+ name: 'octane-data-worker',
561
+ filename: DATA_WORKER_PATH.slice(1),
562
+ // A worker has no document to load chunks into, so its dynamic imports stay in the file.
563
+ asyncChunks: false,
564
+ }).apply(compiler);
565
+ }
549
566
  saltPersistentCacheVersion(compiler, {
550
567
  root,
551
568
  environment,
@@ -553,6 +570,7 @@ export class OctaneRspackPlugin {
553
570
  dev,
554
571
  profile,
555
572
  strong: this.options.strong === true,
573
+ strongDependencies: this.options.strongDependencies,
556
574
  knownAttributeSpreads: this.options.knownAttributeSpreads,
557
575
  exclude: this.options.exclude ?? [],
558
576
  renderers: this.options.renderers?.signature,
@@ -603,6 +621,9 @@ export class OctaneRspackPlugin {
603
621
  environment,
604
622
  profile,
605
623
  ...(this.options.strong === undefined ? null : { strong: this.options.strong }),
624
+ ...(this.options.strongDependencies === undefined
625
+ ? null
626
+ : { strongDependencies: this.options.strongDependencies }),
606
627
  ...(this.options.knownAttributeSpreads === undefined
607
628
  ? null
608
629
  : { knownAttributeSpreads: this.options.knownAttributeSpreads }),
@@ -651,6 +672,19 @@ export class OctaneRspackPlugin {
651
672
  use: [{ loader: 'builtin:swc-loader', options: { detectSyntax: 'auto' } }],
652
673
  });
653
674
  }
675
+ // The octane/data contract check. `data: false` turns it off; otherwise
676
+ // importing the generated manifest turns it on.
677
+ const dataProgram = this.options.data === false ? null : createDataProgram(root);
678
+ if (dataProgram !== null) {
679
+ compiler.options.module.rules.push(
680
+ { resolve: { alias: { [`${DATA_MANIFEST_MODULE}$`]: dataManifestPath } } },
681
+ {
682
+ resource: dataManifestPath,
683
+ enforce: 'post',
684
+ use: [{ loader: dataManifestPath, options: { root } }],
685
+ },
686
+ );
687
+ }
654
688
  const layerRuntimeAliases = [];
655
689
  for (const [layer, specialization] of Object.entries(this.options.layerSpecializations ?? {})) {
656
690
  if (specialization.runtime === undefined) continue;
@@ -688,11 +722,41 @@ export class OctaneRspackPlugin {
688
722
  compiler.hooks.watchRun?.tap(PLUGIN_NAME, () => {
689
723
  for (const current of discoveryCompilers) current.invalidate();
690
724
  discovery = undefined;
725
+ for (const file of [...(compiler.modifiedFiles ?? []), ...(compiler.removedFiles ?? [])])
726
+ dataProgram?.invalidate(file);
691
727
  });
692
728
  compiler.hooks.thisCompilation?.tap(PLUGIN_NAME, (compilation) => {
693
729
  const current = discover();
694
730
  addDependencies(compilation.fileDependencies, current.dependencies);
695
731
  addDependencies(compilation.missingDependencies, current.missingDependencies);
732
+ if (dataProgram !== null) {
733
+ compilation.hooks.finishModules.tap(PLUGIN_NAME, (modules) => {
734
+ // Opted in by `data: true` or by importing the manifest, which is in
735
+ // the graph by now.
736
+ if (
737
+ this.options.data !== true &&
738
+ ![...modules].some((module) => module.resource === dataManifestPath)
739
+ )
740
+ return;
741
+ const report = (list, diagnostic) =>
742
+ list.push(new compiler.webpack.WebpackError(formatDataDiagnostic(diagnostic, root)));
743
+ for (const module of modules) {
744
+ if (typeof module.resource !== 'string') continue;
745
+ const file = module.resource.split('?')[0];
746
+ for (const diagnostic of dataProgram.check(file))
747
+ report(compilation.errors, diagnostic);
748
+ }
749
+ // The whole program is read from disk, so the client build reports it
750
+ // once. Dev reports it as warnings, which the overlay shows.
751
+ if (environment !== 'client') return;
752
+ for (const diagnostic of dataProgram.report()) {
753
+ report(
754
+ diagnostic.severity === 'hint' || dev ? compilation.warnings : compilation.errors,
755
+ diagnostic,
756
+ );
757
+ }
758
+ });
759
+ }
696
760
  if (environment === 'client') {
697
761
  const IndependentHydrationRuntimeModule = independentHydrationRuntimeModule(
698
762
  compiler,
package/src/shared.js CHANGED
@@ -41,6 +41,7 @@ const LOADER_OPTION_KEYS = new Set([
41
41
  'dev',
42
42
  'profile',
43
43
  'strong',
44
+ 'strongDependencies',
44
45
  'knownAttributeSpreads',
45
46
  'exclude',
46
47
  'renderers',
@@ -56,6 +57,8 @@ const PLUGIN_OPTION_KEYS = new Set([
56
57
  'transpile',
57
58
  'cssModuleConstants',
58
59
  'clientBuildMode',
60
+ 'dataWorker',
61
+ 'data',
59
62
  ]);
60
63
  const LAYER_SPECIALIZATION_KEYS = new Set(['runtime', 'renderers', 'universalRuntime']);
61
64
 
@@ -200,6 +203,10 @@ function normalizeOptions(value, plugin) {
200
203
  throw new TypeError('@octanejs/rspack-plugin: `root` must be a path string.');
201
204
  }
202
205
  if (plugin) normalizeRuntimeRequest(options.runtime);
206
+ if (plugin) normalizeRuntimeRequest(options.dataWorker, 'dataWorker');
207
+ if (plugin && options.data !== undefined && typeof options.data !== 'boolean') {
208
+ throw new TypeError('@octanejs/rspack-plugin: `data` must be a boolean when provided.');
209
+ }
203
210
  if (
204
211
  plugin &&
205
212
  options.clientBuildMode !== undefined &&
@@ -267,6 +274,9 @@ function normalizeOptions(value, plugin) {
267
274
  ...(options.dev === undefined ? null : { dev: options.dev }),
268
275
  ...(options.profile === undefined ? null : { profile: options.profile }),
269
276
  ...(options.strong === undefined ? null : { strong: options.strong }),
277
+ ...(options.strongDependencies === undefined
278
+ ? null
279
+ : { strongDependencies: options.strongDependencies }),
270
280
  ...(options.knownAttributeSpreads === undefined
271
281
  ? null
272
282
  : { knownAttributeSpreads: options.knownAttributeSpreads }),
@@ -286,6 +296,8 @@ function normalizeOptions(value, plugin) {
286
296
  : null),
287
297
  ...(plugin && options.transpile !== undefined ? { transpile: options.transpile } : null),
288
298
  ...(plugin && options.runtime !== undefined ? { runtime: options.runtime } : null),
299
+ ...(plugin && options.dataWorker !== undefined ? { dataWorker: options.dataWorker } : null),
300
+ ...(plugin && options.data !== undefined ? { data: options.data } : null),
289
301
  ...(plugin && options.cssModuleConstants !== undefined
290
302
  ? { cssModuleConstants: options.cssModuleConstants }
291
303
  : null),
package/types/index.d.ts CHANGED
@@ -177,6 +177,20 @@ export interface OctaneRspackLoaderOptions {
177
177
  }
178
178
 
179
179
  export interface OctaneRspackPluginOptions extends OctaneRspackLoaderOptions {
180
+ /**
181
+ * The app's data worker module, which calls `serveDataOwner` from
182
+ * `octane/data`. Client builds emit it as the `octane-data-worker` entry at
183
+ * `/_octane/data-worker.js`, so every deploy's tabs share one owner through
184
+ * `sharedOwner`. Leave that entry out of the pages' HTML. A request resolved
185
+ * from the compiler's context.
186
+ */
187
+ dataWorker?: string;
188
+ /**
189
+ * The `octane/data` contract check and the generated `octane/data/manifest`.
190
+ * On once the app imports `octane/data/manifest`; `true` turns the check on
191
+ * without it, and `false` turns both off.
192
+ */
193
+ data?: boolean;
180
194
  /** Build intent for SSR metadata; independent of optimization/HMR settings. */
181
195
  clientBuildMode?: 'production' | 'development';
182
196
  /**