rsbuild-plugin-react-router 0.4.1 → 0.6.0
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 +72 -240
- package/dist/{451.js → 511.js} +461 -331
- package/dist/build-output-transforms.d.ts +32 -7
- package/dist/classic-mode.d.ts +56 -0
- package/dist/config-imports.d.ts +8 -2
- package/dist/constants.d.ts +3 -0
- package/dist/dev-background-resources.d.ts +3 -3
- package/dist/dev-generation.d.ts +2 -3
- package/dist/dev-hmr.d.ts +8 -2
- package/dist/dev-runtime-controller.d.ts +6 -1
- package/dist/dev-source-maps.d.ts +4 -0
- package/dist/effect-runtime.d.ts +17 -5
- package/dist/entry-paths.d.ts +16 -0
- package/dist/environment-output.d.ts +6 -0
- package/dist/export-utils.d.ts +2 -1
- package/dist/federation.d.ts +2 -0
- package/dist/index.cjs +3675 -2107
- package/dist/index.d.ts +3 -1
- package/dist/index.js +3614 -2214
- package/dist/lazy-compilation-prewarm.d.ts +8 -5
- package/dist/manifest.d.ts +16 -4
- package/dist/mode-plan.d.ts +82 -0
- package/dist/modify-browser-manifest.d.ts +8 -4
- package/dist/performance.d.ts +4 -1
- package/dist/plugin-utils.d.ts +27 -1
- package/dist/prerender-build.d.ts +5 -5
- package/dist/prerender.d.ts +1 -5
- package/dist/react-router-config.d.ts +11 -3
- package/dist/route-artifacts.d.ts +4 -2
- package/dist/route-chunks.d.ts +2 -1
- package/dist/route-component-transform.d.ts +0 -2
- package/dist/route-export-pruning.d.ts +4 -1
- package/dist/route-imports.d.ts +18 -0
- package/dist/route-module-transform-loader.d.ts +14 -0
- package/dist/route-module-transform-loader.js +44 -0
- package/dist/route-module-transform-rules.d.ts +14 -0
- package/dist/route-transform-tasks.d.ts +6 -0
- package/dist/route-watch.d.ts +11 -6
- package/dist/rsc-dev-server.d.ts +26 -0
- package/dist/rsc-prerender.d.ts +54 -0
- package/dist/rsc-route-config.d.ts +6 -0
- package/dist/rsc-route-exports.d.ts +15 -0
- package/dist/rsc-route-transform-loader.cjs +43 -0
- package/dist/rsc-route-transform-loader.d.ts +30 -0
- package/dist/rsc-route-transform-loader.js +16 -0
- package/dist/rsc-route-transform-registration.d.ts +12 -0
- package/dist/rsc-route-transforms.d.ts +21 -0
- package/dist/rsc-support.d.ts +23 -0
- package/dist/rsc-virtual-modules.d.ts +19 -0
- package/dist/server-build-plan.d.ts +2 -1
- package/dist/server-build-resolution.d.ts +1 -2
- package/dist/server-utils.d.ts +4 -5
- package/dist/ssr-asset-relocation.d.ts +98 -0
- package/dist/templates/entry.rsc.client.d.ts +1 -0
- package/dist/templates/entry.rsc.client.js +61 -0
- package/dist/templates/entry.rsc.d.ts +9 -0
- package/dist/templates/entry.rsc.js +38 -0
- package/dist/templates/entry.rsc.ssr.d.ts +4 -0
- package/dist/templates/entry.rsc.ssr.js +24 -0
- package/dist/typegen.d.ts +4 -2
- package/dist/types.d.ts +34 -6
- package/package.json +76 -22
- package/src/build-output-transforms.ts +181 -43
- package/src/classic-mode.ts +253 -0
- package/src/config-imports.ts +153 -6
- package/src/constants.ts +6 -2
- package/src/dev-background-resources.ts +46 -100
- package/src/dev-generation.ts +52 -33
- package/src/dev-hmr.ts +112 -80
- package/src/dev-runtime-artifacts.ts +11 -12
- package/src/dev-runtime-controller.ts +75 -85
- package/src/dev-runtime-session.ts +14 -18
- package/src/dev-server.ts +2 -0
- package/src/dev-source-maps.ts +257 -0
- package/src/effect-runtime.ts +105 -57
- package/src/entry-paths.ts +80 -0
- package/src/environment-output.ts +55 -0
- package/src/export-utils.ts +15 -11
- package/src/federation.ts +38 -0
- package/src/index.ts +666 -519
- package/src/lazy-compilation-prewarm.ts +20 -4
- package/src/manifest.ts +157 -82
- package/src/mode-plan.ts +367 -0
- package/src/modify-browser-manifest.ts +130 -124
- package/src/performance.ts +11 -2
- package/src/plugin-utils.ts +103 -39
- package/src/prerender-build.ts +82 -104
- package/src/prerender.ts +23 -24
- package/src/react-router-config.ts +72 -26
- package/src/route-artifacts.ts +96 -66
- package/src/route-chunks.ts +167 -51
- package/src/route-component-transform.ts +14 -21
- package/src/route-export-pruning.ts +4 -3
- package/src/route-imports.ts +100 -0
- package/src/route-module-transform-loader.ts +149 -0
- package/src/route-module-transform-rules.ts +115 -0
- package/src/route-transform-tasks.ts +44 -29
- package/src/route-watch.ts +166 -188
- package/src/rsc-dev-server.ts +112 -0
- package/src/rsc-prerender.ts +362 -0
- package/src/rsc-route-config.ts +175 -0
- package/src/rsc-route-exports.ts +67 -0
- package/src/rsc-route-transform-loader.ts +65 -0
- package/src/rsc-route-transform-registration.ts +145 -0
- package/src/rsc-route-transforms.ts +995 -0
- package/src/rsc-runtime.d.ts +143 -0
- package/src/rsc-support.ts +116 -0
- package/src/rsc-virtual-modules.ts +113 -0
- package/src/server-build-plan.ts +14 -3
- package/src/server-build-resolution.ts +37 -47
- package/src/server-utils.ts +21 -35
- package/src/ssr-asset-relocation.ts +183 -0
- package/src/ssr-externals.ts +8 -26
- package/src/templates/entry.rsc.client.tsx +168 -0
- package/src/templates/entry.rsc.ssr.tsx +45 -0
- package/src/templates/entry.rsc.tsx +80 -0
- package/src/typegen.ts +40 -23
- package/src/types.ts +43 -6
- package/src/warnings/warn-on-client-source-maps.ts +6 -10
- package/dist/parallel-route-transform-protocol.d.ts +0 -25
- package/dist/parallel-route-transform-worker.d.ts +0 -1
- package/dist/parallel-route-transform-worker.js +0 -38
- package/dist/parallel-route-transforms.d.ts +0 -29
- package/src/parallel-route-transform-protocol.ts +0 -35
- package/src/parallel-route-transform-worker.ts +0 -82
- package/src/parallel-route-transforms.ts +0 -458
package/src/types.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { RsbuildConfig } from '@rsbuild/core';
|
|
1
|
+
import type { RsbuildConfig, Rspack } from '@rsbuild/core';
|
|
2
2
|
|
|
3
3
|
export type Route = {
|
|
4
4
|
id: string;
|
|
@@ -30,6 +30,23 @@ export type PluginOptions = {
|
|
|
30
30
|
*/
|
|
31
31
|
federation?: boolean;
|
|
32
32
|
|
|
33
|
+
/**
|
|
34
|
+
* Enable experimental React Router RSC framework mode.
|
|
35
|
+
* This composes `rsbuild-plugin-rsc` with React Router's Rsbuild
|
|
36
|
+
* environments. Environment names are managed by this plugin.
|
|
37
|
+
* Requires `react-router >=7.18.0 || >=8.0.0`, `rsbuild-plugin-rsc`,
|
|
38
|
+
* and `react-server-dom-rspack`.
|
|
39
|
+
* @default false
|
|
40
|
+
*/
|
|
41
|
+
rsc?:
|
|
42
|
+
| boolean
|
|
43
|
+
| {
|
|
44
|
+
layers?: {
|
|
45
|
+
rsc?: Rspack.RuleSetCondition;
|
|
46
|
+
ssr?: Rspack.RuleSetCondition;
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
|
|
33
50
|
/**
|
|
34
51
|
* Rsbuild dev-only lazy compilation behavior.
|
|
35
52
|
*
|
|
@@ -57,11 +74,10 @@ export type PluginOptions = {
|
|
|
57
74
|
logPerformance?: boolean;
|
|
58
75
|
|
|
59
76
|
/**
|
|
60
|
-
* Run route transforms
|
|
61
|
-
* Pass `true` to
|
|
62
|
-
* the worker count, or `false` to disable.
|
|
63
|
-
* @default
|
|
64
|
-
* pool uses available CPU cores minus 2.
|
|
77
|
+
* Run route module transforms with Rspack's parallel loader workers.
|
|
78
|
+
* Pass `true` to use Rspack's default worker count, a positive integer to set
|
|
79
|
+
* the maximum worker count, or `false` to disable.
|
|
80
|
+
* @default false
|
|
65
81
|
*/
|
|
66
82
|
parallelRouteTransform?: boolean | number;
|
|
67
83
|
|
|
@@ -74,6 +90,27 @@ export type PluginOptions = {
|
|
|
74
90
|
onRouteTopologyChange?: () => void | Promise<void>;
|
|
75
91
|
};
|
|
76
92
|
|
|
93
|
+
export type ReactRouterRSCPluginOptions = Omit<PluginOptions, 'rsc'> & {
|
|
94
|
+
/**
|
|
95
|
+
* Optional overrides forwarded to `rsbuild-plugin-rsc`.
|
|
96
|
+
* Environment names are managed by this plugin.
|
|
97
|
+
*/
|
|
98
|
+
rsc?: Exclude<NonNullable<PluginOptions['rsc']>, boolean>;
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
export type PrerenderPathsConfig =
|
|
102
|
+
| boolean
|
|
103
|
+
| string[]
|
|
104
|
+
| ((args: {
|
|
105
|
+
getStaticPaths: () => string[];
|
|
106
|
+
}) => boolean | string[] | Promise<boolean | string[]>);
|
|
107
|
+
|
|
108
|
+
export type PrerenderConfigObject = {
|
|
109
|
+
paths: PrerenderPathsConfig;
|
|
110
|
+
concurrency?: number;
|
|
111
|
+
unstable_concurrency?: number;
|
|
112
|
+
};
|
|
113
|
+
|
|
77
114
|
export type RouteManifestItem = Omit<Route, 'file' | 'children'> & {
|
|
78
115
|
module: string;
|
|
79
116
|
clientActionModule?: string;
|
|
@@ -13,10 +13,8 @@ export function isSourceMapEnabled(value: unknown): boolean {
|
|
|
13
13
|
// Rsbuild normalizes `output.sourceMap` into either:
|
|
14
14
|
// - boolean
|
|
15
15
|
// - { js?: devtool; css: boolean }
|
|
16
|
-
if (value === true) return true;
|
|
17
|
-
if (value
|
|
18
|
-
if (typeof value === 'string') return true;
|
|
19
|
-
if (typeof value === 'object') {
|
|
16
|
+
if (value === true || typeof value === 'string') return true;
|
|
17
|
+
if (value !== null && typeof value === 'object') {
|
|
20
18
|
const js = (value as SourceMapConfigObject).js;
|
|
21
19
|
// Any truthy devtool string/object means source maps are on for JS.
|
|
22
20
|
return Boolean(js);
|
|
@@ -26,12 +24,11 @@ export function isSourceMapEnabled(value: unknown): boolean {
|
|
|
26
24
|
|
|
27
25
|
function isDevtoolSourceMap(value: unknown): boolean {
|
|
28
26
|
if (value === true) return true;
|
|
29
|
-
if (value == null || value === false) return false;
|
|
30
27
|
if (typeof value === 'string') {
|
|
31
28
|
return value.includes('source-map');
|
|
32
29
|
}
|
|
33
30
|
// Unknown object shape - treat as enabled to be safe.
|
|
34
|
-
return typeof value === 'object';
|
|
31
|
+
return value !== null && typeof value === 'object';
|
|
35
32
|
}
|
|
36
33
|
|
|
37
34
|
export function getClientSourceMapSetting(
|
|
@@ -58,10 +55,9 @@ export function getClientDevtoolSetting(
|
|
|
58
55
|
}
|
|
59
56
|
|
|
60
57
|
function getDevtoolFromRspackConfig(config?: ToolsRspackConfig): unknown {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
return (config as { devtool?: unknown }).devtool;
|
|
58
|
+
return config !== null && typeof config === 'object'
|
|
59
|
+
? (config as { devtool?: unknown }).devtool
|
|
60
|
+
: undefined;
|
|
65
61
|
}
|
|
66
62
|
|
|
67
63
|
export function warnOnClientSourceMaps(
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import type { RouteTransformResult, RouteTransformTask } from './route-transform-tasks.js';
|
|
2
|
-
type WithoutRequiredSource<Task> = Task extends RouteTransformTask ? Omit<Task, 'code'> & {
|
|
3
|
-
code?: string;
|
|
4
|
-
} : never;
|
|
5
|
-
export type CachedRouteTransformTask = WithoutRequiredSource<RouteTransformTask>;
|
|
6
|
-
export type WorkerRequest = {
|
|
7
|
-
id: number;
|
|
8
|
-
task: RouteTransformTask | CachedRouteTransformTask;
|
|
9
|
-
sourceCacheKey?: string;
|
|
10
|
-
};
|
|
11
|
-
export type WorkerErrorPayload = {
|
|
12
|
-
name?: string;
|
|
13
|
-
message: string;
|
|
14
|
-
stack?: string;
|
|
15
|
-
};
|
|
16
|
-
export type WorkerResponse = {
|
|
17
|
-
id: number;
|
|
18
|
-
ok: true;
|
|
19
|
-
result: RouteTransformResult;
|
|
20
|
-
} | {
|
|
21
|
-
id: number;
|
|
22
|
-
ok: false;
|
|
23
|
-
error: WorkerErrorPayload;
|
|
24
|
-
};
|
|
25
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { parentPort } from "node:worker_threads";
|
|
2
|
-
import { setBoundedCacheEntry, executeRouteTransformTask } from "./451.js";
|
|
3
|
-
if (!parentPort) throw Error('parallel route transform worker requires parentPort');
|
|
4
|
-
let sourceCache = new Map();
|
|
5
|
-
parentPort.on('message', async ({ id, task, sourceCacheKey })=>{
|
|
6
|
-
try {
|
|
7
|
-
let hydratedTask = (({ task, sourceCacheKey })=>{
|
|
8
|
-
if (!sourceCacheKey) return task;
|
|
9
|
-
if ('string' == typeof task.code) return setBoundedCacheEntry(sourceCache, sourceCacheKey, task.code, 2048), task;
|
|
10
|
-
let code = sourceCache.get(sourceCacheKey);
|
|
11
|
-
if (void 0 === code) throw Error(`Missing cached route transform source for ${sourceCacheKey}.`);
|
|
12
|
-
return {
|
|
13
|
-
...task,
|
|
14
|
-
code
|
|
15
|
-
};
|
|
16
|
-
})({
|
|
17
|
-
task,
|
|
18
|
-
sourceCacheKey
|
|
19
|
-
}), result = await executeRouteTransformTask(hydratedTask);
|
|
20
|
-
parentPort?.postMessage({
|
|
21
|
-
id,
|
|
22
|
-
ok: !0,
|
|
23
|
-
result
|
|
24
|
-
});
|
|
25
|
-
} catch (error) {
|
|
26
|
-
parentPort?.postMessage({
|
|
27
|
-
id,
|
|
28
|
-
ok: !1,
|
|
29
|
-
error: error instanceof Error ? {
|
|
30
|
-
name: error.name,
|
|
31
|
-
message: error.message,
|
|
32
|
-
stack: error.stack
|
|
33
|
-
} : {
|
|
34
|
-
message: String(error)
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
});
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { type RouteTransformResult, type RouteTransformTask, type RouteTransformTaskOptions } from './route-transform-tasks.js';
|
|
2
|
-
import type { PluginOptions } from './types.js';
|
|
3
|
-
import type { WorkerRequest, WorkerResponse } from './parallel-route-transform-protocol.js';
|
|
4
|
-
export type ParallelRouteTransformConfig = NonNullable<PluginOptions['parallelRouteTransform']> extends infer Config ? Exclude<Config, false> : never;
|
|
5
|
-
export type RouteTransformExecutorOptions = RouteTransformTaskOptions & {
|
|
6
|
-
parallelRouteTransform?: PluginOptions['parallelRouteTransform'];
|
|
7
|
-
splitRouteModules?: boolean;
|
|
8
|
-
isBuild?: boolean;
|
|
9
|
-
};
|
|
10
|
-
export type RouteTransformExecutor = {
|
|
11
|
-
run: (task: RouteTransformTask) => Promise<RouteTransformResult>;
|
|
12
|
-
prewarm: () => void;
|
|
13
|
-
close: () => Promise<void>;
|
|
14
|
-
};
|
|
15
|
-
type RouteTransformWorker = {
|
|
16
|
-
on(event: 'message', handler: (response: WorkerResponse) => void): unknown;
|
|
17
|
-
on(event: 'error', handler: (error: Error) => void): unknown;
|
|
18
|
-
on(event: 'exit', handler: (code: number) => void): unknown;
|
|
19
|
-
postMessage(message: WorkerRequest): void;
|
|
20
|
-
terminate(): Promise<number> | number;
|
|
21
|
-
};
|
|
22
|
-
type RouteTransformWorkerFactory = () => RouteTransformWorker;
|
|
23
|
-
export declare const getDefaultWorkerCount: (cpuCount?: number, { isBuild }?: {
|
|
24
|
-
isBuild?: boolean;
|
|
25
|
-
}) => number;
|
|
26
|
-
export declare const shouldParallelizeRouteTransforms: (routeCount: number) => boolean;
|
|
27
|
-
export declare const createRouteTransformExecutor: ({ parallelRouteTransform, routeChunkCache, splitRouteModules, isBuild, }?: RouteTransformExecutorOptions) => RouteTransformExecutor;
|
|
28
|
-
export declare const createRouteTransformExecutorForTesting: (options: RouteTransformExecutorOptions, createWorker: RouteTransformWorkerFactory) => RouteTransformExecutor;
|
|
29
|
-
export {};
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
RouteTransformResult,
|
|
3
|
-
RouteTransformTask,
|
|
4
|
-
} from './route-transform-tasks.js';
|
|
5
|
-
|
|
6
|
-
type WithoutRequiredSource<Task> = Task extends RouteTransformTask
|
|
7
|
-
? Omit<Task, 'code'> & { code?: string }
|
|
8
|
-
: never;
|
|
9
|
-
|
|
10
|
-
export type CachedRouteTransformTask =
|
|
11
|
-
WithoutRequiredSource<RouteTransformTask>;
|
|
12
|
-
|
|
13
|
-
export type WorkerRequest = {
|
|
14
|
-
id: number;
|
|
15
|
-
task: RouteTransformTask | CachedRouteTransformTask;
|
|
16
|
-
sourceCacheKey?: string;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export type WorkerErrorPayload = {
|
|
20
|
-
name?: string;
|
|
21
|
-
message: string;
|
|
22
|
-
stack?: string;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export type WorkerResponse =
|
|
26
|
-
| {
|
|
27
|
-
id: number;
|
|
28
|
-
ok: true;
|
|
29
|
-
result: RouteTransformResult;
|
|
30
|
-
}
|
|
31
|
-
| {
|
|
32
|
-
id: number;
|
|
33
|
-
ok: false;
|
|
34
|
-
error: WorkerErrorPayload;
|
|
35
|
-
};
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { parentPort } from 'node:worker_threads';
|
|
2
|
-
import { setBoundedCacheEntry } from './bounded-cache.js';
|
|
3
|
-
import {
|
|
4
|
-
executeRouteTransformTask,
|
|
5
|
-
type RouteTransformTask,
|
|
6
|
-
} from './route-transform-tasks.js';
|
|
7
|
-
import type {
|
|
8
|
-
WorkerErrorPayload,
|
|
9
|
-
WorkerRequest,
|
|
10
|
-
WorkerResponse,
|
|
11
|
-
} from './parallel-route-transform-protocol.js';
|
|
12
|
-
|
|
13
|
-
const serializeError = (error: unknown): WorkerErrorPayload => {
|
|
14
|
-
if (error instanceof Error) {
|
|
15
|
-
return {
|
|
16
|
-
name: error.name,
|
|
17
|
-
message: error.message,
|
|
18
|
-
stack: error.stack,
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
return {
|
|
22
|
-
message: String(error),
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
if (!parentPort) {
|
|
27
|
-
throw new Error('parallel route transform worker requires parentPort');
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const MAX_SOURCE_CACHE_ENTRIES = 2048;
|
|
31
|
-
const sourceCache = new Map<string, string>();
|
|
32
|
-
|
|
33
|
-
const hydrateTaskSource = ({
|
|
34
|
-
task,
|
|
35
|
-
sourceCacheKey,
|
|
36
|
-
}: Pick<WorkerRequest, 'task' | 'sourceCacheKey'>): RouteTransformTask => {
|
|
37
|
-
if (!sourceCacheKey) {
|
|
38
|
-
return task as RouteTransformTask;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
if (typeof task.code === 'string') {
|
|
42
|
-
setBoundedCacheEntry(
|
|
43
|
-
sourceCache,
|
|
44
|
-
sourceCacheKey,
|
|
45
|
-
task.code,
|
|
46
|
-
MAX_SOURCE_CACHE_ENTRIES
|
|
47
|
-
);
|
|
48
|
-
return task as RouteTransformTask;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const code = sourceCache.get(sourceCacheKey);
|
|
52
|
-
if (code === undefined) {
|
|
53
|
-
throw new Error(
|
|
54
|
-
`Missing cached route transform source for ${sourceCacheKey}.`
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
return {
|
|
58
|
-
...task,
|
|
59
|
-
code,
|
|
60
|
-
} as RouteTransformTask;
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
parentPort.on(
|
|
64
|
-
'message',
|
|
65
|
-
async ({ id, task, sourceCacheKey }: WorkerRequest) => {
|
|
66
|
-
try {
|
|
67
|
-
const hydratedTask = hydrateTaskSource({ task, sourceCacheKey });
|
|
68
|
-
const result = await executeRouteTransformTask(hydratedTask);
|
|
69
|
-
parentPort?.postMessage({
|
|
70
|
-
id,
|
|
71
|
-
ok: true,
|
|
72
|
-
result,
|
|
73
|
-
} satisfies WorkerResponse);
|
|
74
|
-
} catch (error) {
|
|
75
|
-
parentPort?.postMessage({
|
|
76
|
-
id,
|
|
77
|
-
ok: false,
|
|
78
|
-
error: serializeError(error),
|
|
79
|
-
} satisfies WorkerResponse);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
);
|