@octanejs/rspack-plugin 0.2.9 → 0.2.11
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 +4 -0
- package/package.json +3 -3
- package/src/data-manifest.js +21 -0
- package/src/plugin.js +73 -1
- package/src/shared.js +8 -0
- package/types/index.d.ts +14 -0
package/README.md
CHANGED
|
@@ -173,6 +173,10 @@ export default {
|
|
|
173
173
|
};
|
|
174
174
|
```
|
|
175
175
|
|
|
176
|
+
For an SSR build, the class plugin resolves `octane/react` to the selected
|
|
177
|
+
Octane package's server implementation. Use `octane/react/server` explicitly
|
|
178
|
+
when a server externalizes the compatibility entry or uses the loader alone.
|
|
179
|
+
|
|
176
180
|
With the loader-only form, configure `.tsrx` resolution, TypeScript stripping,
|
|
177
181
|
and exact `octane$` / `octane/profiling$` aliases to the app's Octane package
|
|
178
182
|
yourself. The profiling alias keeps compiler metadata and runtime recording on
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@octanejs/rspack-plugin",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.11",
|
|
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.19.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.19.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;
|
|
@@ -91,7 +96,7 @@ function mergeRuntimeAliases(aliases, additions) {
|
|
|
91
96
|
};
|
|
92
97
|
}
|
|
93
98
|
|
|
94
|
-
function addRuntimeAliases(compiler, request, root, explicitRuntime) {
|
|
99
|
+
function addRuntimeAliases(compiler, request, root, explicitRuntime, environment) {
|
|
95
100
|
const resolveOptions = compiler.options.resolve;
|
|
96
101
|
// The factory is created before Rspack applies mode/target defaults. Merge
|
|
97
102
|
// the finalized ESM options (including `...`) before resolving; require
|
|
@@ -118,6 +123,20 @@ function addRuntimeAliases(compiler, request, root, explicitRuntime) {
|
|
|
118
123
|
aliases[subpath] ??
|
|
119
124
|
resolveRuntimeModule(packageResolver, subpath, packageRoot);
|
|
120
125
|
}
|
|
126
|
+
if (environment === 'server') {
|
|
127
|
+
const serverRequest = 'octane/react/server';
|
|
128
|
+
const aliasedServer =
|
|
129
|
+
Object.hasOwn(aliases, 'octane/react/server$') || Object.hasOwn(aliases, serverRequest);
|
|
130
|
+
const serverReact = aliasedServer
|
|
131
|
+
? serverRequest
|
|
132
|
+
: resolveRuntimeModule(packageResolver, serverRequest, packageRoot);
|
|
133
|
+
if (aliasedServer || serverReact !== serverRequest) {
|
|
134
|
+
if (!aliasedServer) additions['octane/react/server$'] = serverReact;
|
|
135
|
+
// Keep the second request visible to Rspack's issuer-layer aliases.
|
|
136
|
+
if (!Object.hasOwn(aliases, 'octane/react$') && !Object.hasOwn(aliases, 'octane/react'))
|
|
137
|
+
additions['octane/react$'] = serverRequest;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
121
140
|
const runtime = explicitRuntime
|
|
122
141
|
? override
|
|
123
142
|
: request === 'octane' || selected === false
|
|
@@ -549,6 +568,15 @@ export class OctaneRspackPlugin {
|
|
|
549
568
|
? realRoot(resolve(root, this.options.textTypes.tsconfig))
|
|
550
569
|
: undefined;
|
|
551
570
|
assertProfilingDefineAvailable(compiler, profile);
|
|
571
|
+
if (this.options.dataWorker && environment === 'client') {
|
|
572
|
+
// The data worker keeps one path across deploys, so every tab shares one SharedWorker.
|
|
573
|
+
new compiler.webpack.EntryPlugin(compilerRoot, this.options.dataWorker, {
|
|
574
|
+
name: 'octane-data-worker',
|
|
575
|
+
filename: DATA_WORKER_PATH.slice(1),
|
|
576
|
+
// A worker has no document to load chunks into, so its dynamic imports stay in the file.
|
|
577
|
+
asyncChunks: false,
|
|
578
|
+
}).apply(compiler);
|
|
579
|
+
}
|
|
552
580
|
saltPersistentCacheVersion(compiler, {
|
|
553
581
|
root,
|
|
554
582
|
environment,
|
|
@@ -658,6 +686,19 @@ export class OctaneRspackPlugin {
|
|
|
658
686
|
use: [{ loader: 'builtin:swc-loader', options: { detectSyntax: 'auto' } }],
|
|
659
687
|
});
|
|
660
688
|
}
|
|
689
|
+
// The octane/data contract check. `data: false` turns it off; otherwise
|
|
690
|
+
// importing the generated manifest turns it on.
|
|
691
|
+
const dataProgram = this.options.data === false ? null : createDataProgram(root);
|
|
692
|
+
if (dataProgram !== null) {
|
|
693
|
+
compiler.options.module.rules.push(
|
|
694
|
+
{ resolve: { alias: { [`${DATA_MANIFEST_MODULE}$`]: dataManifestPath } } },
|
|
695
|
+
{
|
|
696
|
+
resource: dataManifestPath,
|
|
697
|
+
enforce: 'post',
|
|
698
|
+
use: [{ loader: dataManifestPath, options: { root } }],
|
|
699
|
+
},
|
|
700
|
+
);
|
|
701
|
+
}
|
|
661
702
|
const layerRuntimeAliases = [];
|
|
662
703
|
for (const [layer, specialization] of Object.entries(this.options.layerSpecializations ?? {})) {
|
|
663
704
|
if (specialization.runtime === undefined) continue;
|
|
@@ -674,6 +715,7 @@ export class OctaneRspackPlugin {
|
|
|
674
715
|
runtimeRequest,
|
|
675
716
|
root,
|
|
676
717
|
this.options.runtime !== undefined,
|
|
718
|
+
environment,
|
|
677
719
|
);
|
|
678
720
|
for (const [alias, request] of layerRuntimeAliases) {
|
|
679
721
|
alias.octane$ = resolveRuntimeModule(resolver, request, root);
|
|
@@ -695,11 +737,41 @@ export class OctaneRspackPlugin {
|
|
|
695
737
|
compiler.hooks.watchRun?.tap(PLUGIN_NAME, () => {
|
|
696
738
|
for (const current of discoveryCompilers) current.invalidate();
|
|
697
739
|
discovery = undefined;
|
|
740
|
+
for (const file of [...(compiler.modifiedFiles ?? []), ...(compiler.removedFiles ?? [])])
|
|
741
|
+
dataProgram?.invalidate(file);
|
|
698
742
|
});
|
|
699
743
|
compiler.hooks.thisCompilation?.tap(PLUGIN_NAME, (compilation) => {
|
|
700
744
|
const current = discover();
|
|
701
745
|
addDependencies(compilation.fileDependencies, current.dependencies);
|
|
702
746
|
addDependencies(compilation.missingDependencies, current.missingDependencies);
|
|
747
|
+
if (dataProgram !== null) {
|
|
748
|
+
compilation.hooks.finishModules.tap(PLUGIN_NAME, (modules) => {
|
|
749
|
+
// Opted in by `data: true` or by importing the manifest, which is in
|
|
750
|
+
// the graph by now.
|
|
751
|
+
if (
|
|
752
|
+
this.options.data !== true &&
|
|
753
|
+
![...modules].some((module) => module.resource === dataManifestPath)
|
|
754
|
+
)
|
|
755
|
+
return;
|
|
756
|
+
const report = (list, diagnostic) =>
|
|
757
|
+
list.push(new compiler.webpack.WebpackError(formatDataDiagnostic(diagnostic, root)));
|
|
758
|
+
for (const module of modules) {
|
|
759
|
+
if (typeof module.resource !== 'string') continue;
|
|
760
|
+
const file = module.resource.split('?')[0];
|
|
761
|
+
for (const diagnostic of dataProgram.check(file))
|
|
762
|
+
report(compilation.errors, diagnostic);
|
|
763
|
+
}
|
|
764
|
+
// The whole program is read from disk, so the client build reports it
|
|
765
|
+
// once. Dev reports it as warnings, which the overlay shows.
|
|
766
|
+
if (environment !== 'client') return;
|
|
767
|
+
for (const diagnostic of dataProgram.report()) {
|
|
768
|
+
report(
|
|
769
|
+
diagnostic.severity === 'hint' || dev ? compilation.warnings : compilation.errors,
|
|
770
|
+
diagnostic,
|
|
771
|
+
);
|
|
772
|
+
}
|
|
773
|
+
});
|
|
774
|
+
}
|
|
703
775
|
if (environment === 'client') {
|
|
704
776
|
const IndependentHydrationRuntimeModule = independentHydrationRuntimeModule(
|
|
705
777
|
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
|
/**
|