@octanejs/rspack-plugin 0.2.9 → 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/package.json +3 -3
- package/src/data-manifest.js +21 -0
- package/src/plugin.js +57 -0
- package/src/shared.js +8 -0
- package/types/index.d.ts +14 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@octanejs/rspack-plugin",
|
|
3
|
-
"version": "0.2.
|
|
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.
|
|
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.
|
|
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/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;
|
|
@@ -549,6 +554,15 @@ export class OctaneRspackPlugin {
|
|
|
549
554
|
? realRoot(resolve(root, this.options.textTypes.tsconfig))
|
|
550
555
|
: undefined;
|
|
551
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
|
+
}
|
|
552
566
|
saltPersistentCacheVersion(compiler, {
|
|
553
567
|
root,
|
|
554
568
|
environment,
|
|
@@ -658,6 +672,19 @@ export class OctaneRspackPlugin {
|
|
|
658
672
|
use: [{ loader: 'builtin:swc-loader', options: { detectSyntax: 'auto' } }],
|
|
659
673
|
});
|
|
660
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
|
+
}
|
|
661
688
|
const layerRuntimeAliases = [];
|
|
662
689
|
for (const [layer, specialization] of Object.entries(this.options.layerSpecializations ?? {})) {
|
|
663
690
|
if (specialization.runtime === undefined) continue;
|
|
@@ -695,11 +722,41 @@ export class OctaneRspackPlugin {
|
|
|
695
722
|
compiler.hooks.watchRun?.tap(PLUGIN_NAME, () => {
|
|
696
723
|
for (const current of discoveryCompilers) current.invalidate();
|
|
697
724
|
discovery = undefined;
|
|
725
|
+
for (const file of [...(compiler.modifiedFiles ?? []), ...(compiler.removedFiles ?? [])])
|
|
726
|
+
dataProgram?.invalidate(file);
|
|
698
727
|
});
|
|
699
728
|
compiler.hooks.thisCompilation?.tap(PLUGIN_NAME, (compilation) => {
|
|
700
729
|
const current = discover();
|
|
701
730
|
addDependencies(compilation.fileDependencies, current.dependencies);
|
|
702
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
|
+
}
|
|
703
760
|
if (environment === 'client') {
|
|
704
761
|
const IndependentHydrationRuntimeModule = independentHydrationRuntimeModule(
|
|
705
762
|
compiler,
|
package/src/shared.js
CHANGED
|
@@ -57,6 +57,8 @@ const PLUGIN_OPTION_KEYS = new Set([
|
|
|
57
57
|
'transpile',
|
|
58
58
|
'cssModuleConstants',
|
|
59
59
|
'clientBuildMode',
|
|
60
|
+
'dataWorker',
|
|
61
|
+
'data',
|
|
60
62
|
]);
|
|
61
63
|
const LAYER_SPECIALIZATION_KEYS = new Set(['runtime', 'renderers', 'universalRuntime']);
|
|
62
64
|
|
|
@@ -201,6 +203,10 @@ function normalizeOptions(value, plugin) {
|
|
|
201
203
|
throw new TypeError('@octanejs/rspack-plugin: `root` must be a path string.');
|
|
202
204
|
}
|
|
203
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
|
+
}
|
|
204
210
|
if (
|
|
205
211
|
plugin &&
|
|
206
212
|
options.clientBuildMode !== undefined &&
|
|
@@ -290,6 +296,8 @@ function normalizeOptions(value, plugin) {
|
|
|
290
296
|
: null),
|
|
291
297
|
...(plugin && options.transpile !== undefined ? { transpile: options.transpile } : null),
|
|
292
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),
|
|
293
301
|
...(plugin && options.cssModuleConstants !== undefined
|
|
294
302
|
? { cssModuleConstants: options.cssModuleConstants }
|
|
295
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
|
/**
|