rsbuild-plugin-react-router 0.1.1 → 0.3.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 +185 -204
- package/dist/451.js +1087 -0
- package/dist/bounded-cache.d.ts +1 -0
- package/dist/build-manifest.d.ts +1 -1
- package/dist/build-output-transforms.d.ts +30 -0
- package/dist/concurrency.d.ts +2 -0
- package/dist/config-imports.d.ts +3 -0
- package/dist/constants.d.ts +3 -0
- package/dist/dev-generation.d.ts +25 -0
- package/dist/dev-runtime-artifacts.d.ts +39 -0
- package/dist/dev-runtime-compilation.d.ts +32 -0
- package/dist/dev-runtime-controller.d.ts +14 -0
- package/dist/dev-runtime-session.d.ts +34 -0
- package/dist/dev-server.d.ts +11 -2
- package/dist/export-utils.d.ts +15 -7
- package/dist/index.cjs +3085 -1272
- package/dist/index.d.ts +4 -1
- package/dist/index.js +2039 -1299
- package/dist/lazy-compilation.d.ts +5 -0
- package/dist/manifest.d.ts +32 -9
- package/dist/modify-browser-manifest.d.ts +30 -13
- package/dist/parallel-route-transform-protocol.d.ts +25 -0
- package/dist/parallel-route-transform-worker.d.ts +1 -0
- package/dist/parallel-route-transform-worker.js +38 -0
- package/dist/parallel-route-transforms.d.ts +14 -0
- package/dist/performance.d.ts +26 -0
- package/dist/plugin-utils.d.ts +2 -12
- package/dist/prerender-build.d.ts +32 -0
- package/dist/prerender.d.ts +28 -2
- package/dist/react-router-config.d.ts +8 -1
- package/dist/route-artifacts.d.ts +33 -0
- package/dist/route-ast.d.ts +21 -0
- package/dist/route-chunks.d.ts +9 -1
- package/dist/route-component-transform.d.ts +5 -0
- package/dist/route-export-pruning.d.ts +6 -0
- package/dist/route-export-resolution.d.ts +5 -0
- package/dist/route-transform-tasks.d.ts +47 -0
- package/dist/route-watch.d.ts +27 -0
- package/dist/server-build-plan.d.ts +22 -0
- package/dist/server-utils.d.ts +3 -2
- package/dist/templates/entry.client.js +3 -3
- package/dist/templates/entry.server.cjs +11 -8
- package/dist/templates/entry.server.js +5 -5
- package/dist/typegen.d.ts +2 -0
- package/dist/types.d.ts +30 -12
- package/dist/virtual-modules.d.ts +2 -0
- package/dist/warnings/warn-on-client-source-maps.d.ts +1 -0
- package/dist/yuku.d.ts +15 -0
- package/package.json +26 -22
- package/src/bounded-cache.ts +18 -0
- package/src/build-manifest.ts +168 -0
- package/src/build-output-transforms.ts +273 -0
- package/src/concurrency.ts +34 -0
- package/src/config-imports.ts +45 -0
- package/src/constants.ts +91 -0
- package/src/dev-generation.ts +700 -0
- package/src/dev-runtime-artifacts.ts +207 -0
- package/src/dev-runtime-compilation.ts +92 -0
- package/src/dev-runtime-controller.ts +462 -0
- package/src/dev-runtime-session.ts +184 -0
- package/src/dev-server.ts +58 -0
- package/src/export-utils.ts +219 -0
- package/src/index.ts +1025 -0
- package/src/lazy-compilation.ts +94 -0
- package/src/manifest.ts +480 -0
- package/src/modify-browser-manifest.ts +245 -0
- package/src/parallel-route-transform-protocol.ts +35 -0
- package/src/parallel-route-transform-worker.ts +82 -0
- package/src/parallel-route-transforms.ts +332 -0
- package/src/performance.ts +254 -0
- package/src/plugin-utils.ts +82 -0
- package/src/prerender-build.ts +623 -0
- package/src/prerender.ts +367 -0
- package/src/react-router-config.ts +220 -0
- package/src/route-artifacts.ts +155 -0
- package/src/route-ast.ts +163 -0
- package/src/route-chunks.ts +857 -0
- package/src/route-component-transform.ts +314 -0
- package/src/route-config.ts +106 -0
- package/src/route-export-pruning.ts +668 -0
- package/src/route-export-resolution.ts +329 -0
- package/src/route-transform-tasks.ts +249 -0
- package/src/route-watch.ts +322 -0
- package/src/server-build-plan.ts +91 -0
- package/src/server-utils.ts +210 -0
- package/src/ssr-externals.ts +59 -0
- package/src/templates/context.ts +12 -0
- package/src/templates/entry.client.tsx +12 -0
- package/src/templates/entry.server.tsx +76 -0
- package/src/typegen.ts +49 -0
- package/src/types.ts +82 -0
- package/src/validation/validate-plugin-order.ts +76 -0
- package/src/virtual-modules.ts +30 -0
- package/src/warnings/warn-on-client-source-maps.ts +96 -0
- package/src/yuku.ts +67 -0
- package/dist/906.js +0 -1
- package/dist/946.js +0 -1
- package/dist/babel.d.ts +0 -8
- package/dist/rslib-runtime.js +0 -23
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
type OperationTiming = {
|
|
2
|
+
count: number;
|
|
3
|
+
// Total sums every recorded duration, so parallel work can make it larger
|
|
4
|
+
// than elapsed wall-clock time. Use wallMs for non-overlapping elapsed time.
|
|
5
|
+
totalMs: number;
|
|
6
|
+
wallMs: number;
|
|
7
|
+
maxMs: number;
|
|
8
|
+
slowest: Array<{
|
|
9
|
+
durationMs: number;
|
|
10
|
+
resource: string;
|
|
11
|
+
}>;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
type OperationInterval = { startMs: number; endMs: number };
|
|
15
|
+
|
|
16
|
+
type MutableOperationTiming = Omit<OperationTiming, 'wallMs' | 'slowest'> & {
|
|
17
|
+
slowest: Array<{
|
|
18
|
+
durationMs: number;
|
|
19
|
+
resource: string;
|
|
20
|
+
}>;
|
|
21
|
+
intervals: OperationInterval[];
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
type EnvironmentTimings = Map<string, MutableOperationTiming>;
|
|
25
|
+
|
|
26
|
+
const MAX_SLOWEST_ENTRIES = 5;
|
|
27
|
+
|
|
28
|
+
const insertSlowestEntry = (
|
|
29
|
+
slowest: MutableOperationTiming['slowest'],
|
|
30
|
+
entry: MutableOperationTiming['slowest'][number]
|
|
31
|
+
) => {
|
|
32
|
+
if (
|
|
33
|
+
slowest.length === MAX_SLOWEST_ENTRIES &&
|
|
34
|
+
entry.durationMs <= slowest[slowest.length - 1].durationMs
|
|
35
|
+
) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
let insertIndex = slowest.length;
|
|
40
|
+
while (
|
|
41
|
+
insertIndex > 0 &&
|
|
42
|
+
entry.durationMs > slowest[insertIndex - 1].durationMs
|
|
43
|
+
) {
|
|
44
|
+
insertIndex -= 1;
|
|
45
|
+
}
|
|
46
|
+
slowest.splice(insertIndex, 0, entry);
|
|
47
|
+
if (slowest.length > MAX_SLOWEST_ENTRIES) {
|
|
48
|
+
slowest.pop();
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export const roundMs = (value: number): number => Math.round(value * 10) / 10;
|
|
53
|
+
|
|
54
|
+
export type ReactRouterPerformanceReport = {
|
|
55
|
+
environment: string;
|
|
56
|
+
compilerLifecycleMs?: number;
|
|
57
|
+
operations: Record<string, OperationTiming>;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export type ReactRouterPerformanceProfiler = {
|
|
61
|
+
record<T>(
|
|
62
|
+
environment: string | undefined,
|
|
63
|
+
operation: string,
|
|
64
|
+
resource: string,
|
|
65
|
+
callback: () => Promise<T>
|
|
66
|
+
): Promise<T>;
|
|
67
|
+
recordSync<T>(
|
|
68
|
+
environment: string | undefined,
|
|
69
|
+
operation: string,
|
|
70
|
+
resource: string,
|
|
71
|
+
callback: () => T
|
|
72
|
+
): T;
|
|
73
|
+
flush(
|
|
74
|
+
environment: string | undefined,
|
|
75
|
+
details?: Pick<ReactRouterPerformanceReport, 'compilerLifecycleMs'>
|
|
76
|
+
): void;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export const createReactRouterPerformanceProfiler = ({
|
|
80
|
+
enabled,
|
|
81
|
+
log,
|
|
82
|
+
}: {
|
|
83
|
+
enabled: boolean;
|
|
84
|
+
log: (message: string) => void;
|
|
85
|
+
}): ReactRouterPerformanceProfiler => {
|
|
86
|
+
const timingsByEnvironment = new Map<string, EnvironmentTimings>();
|
|
87
|
+
|
|
88
|
+
const getOperationTiming = (
|
|
89
|
+
environment: string,
|
|
90
|
+
operation: string
|
|
91
|
+
): MutableOperationTiming => {
|
|
92
|
+
let timings = timingsByEnvironment.get(environment);
|
|
93
|
+
if (!timings) {
|
|
94
|
+
timings = new Map();
|
|
95
|
+
timingsByEnvironment.set(environment, timings);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
let timing = timings.get(operation);
|
|
99
|
+
if (!timing) {
|
|
100
|
+
timing = {
|
|
101
|
+
count: 0,
|
|
102
|
+
totalMs: 0,
|
|
103
|
+
maxMs: 0,
|
|
104
|
+
slowest: [],
|
|
105
|
+
intervals: [],
|
|
106
|
+
};
|
|
107
|
+
timings.set(operation, timing);
|
|
108
|
+
}
|
|
109
|
+
return timing;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
const computeWallMs = (intervals: OperationInterval[]) => {
|
|
113
|
+
if (intervals.length === 0) {
|
|
114
|
+
return 0;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const sortedIntervals = [...intervals].sort(
|
|
118
|
+
(a, b) => a.startMs - b.startMs || a.endMs - b.endMs
|
|
119
|
+
);
|
|
120
|
+
let mergedStart = sortedIntervals[0].startMs;
|
|
121
|
+
let mergedEnd = sortedIntervals[0].endMs;
|
|
122
|
+
let wallMs = 0;
|
|
123
|
+
|
|
124
|
+
for (const interval of sortedIntervals.slice(1)) {
|
|
125
|
+
if (interval.startMs <= mergedEnd) {
|
|
126
|
+
mergedEnd = Math.max(mergedEnd, interval.endMs);
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
wallMs += mergedEnd - mergedStart;
|
|
131
|
+
mergedStart = interval.startMs;
|
|
132
|
+
mergedEnd = interval.endMs;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
wallMs += mergedEnd - mergedStart;
|
|
136
|
+
return roundMs(wallMs);
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
const toOperationTiming = (
|
|
140
|
+
timing: MutableOperationTiming
|
|
141
|
+
): OperationTiming => ({
|
|
142
|
+
count: timing.count,
|
|
143
|
+
totalMs: roundMs(timing.totalMs),
|
|
144
|
+
wallMs: computeWallMs(timing.intervals),
|
|
145
|
+
maxMs: roundMs(timing.maxMs),
|
|
146
|
+
slowest: timing.slowest.map(entry => ({
|
|
147
|
+
durationMs: roundMs(entry.durationMs),
|
|
148
|
+
resource: entry.resource,
|
|
149
|
+
})),
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
const recordDuration = (
|
|
153
|
+
environment: string,
|
|
154
|
+
operation: string,
|
|
155
|
+
resource: string,
|
|
156
|
+
startMs: number,
|
|
157
|
+
endMs: number
|
|
158
|
+
) => {
|
|
159
|
+
const duration = endMs - startMs;
|
|
160
|
+
const timing = getOperationTiming(environment, operation);
|
|
161
|
+
timing.count += 1;
|
|
162
|
+
timing.totalMs += duration;
|
|
163
|
+
timing.maxMs = Math.max(timing.maxMs, duration);
|
|
164
|
+
timing.intervals.push({ startMs, endMs });
|
|
165
|
+
insertSlowestEntry(timing.slowest, {
|
|
166
|
+
durationMs: duration,
|
|
167
|
+
resource,
|
|
168
|
+
});
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
return {
|
|
172
|
+
record(environment, operation, resource, callback) {
|
|
173
|
+
if (!enabled) {
|
|
174
|
+
try {
|
|
175
|
+
return Promise.resolve(callback());
|
|
176
|
+
} catch (error) {
|
|
177
|
+
return Promise.reject(error);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const resolvedEnvironment = environment ?? 'unknown';
|
|
182
|
+
const start = performance.now();
|
|
183
|
+
try {
|
|
184
|
+
return callback().then(
|
|
185
|
+
result => {
|
|
186
|
+
const end = performance.now();
|
|
187
|
+
recordDuration(
|
|
188
|
+
resolvedEnvironment,
|
|
189
|
+
operation,
|
|
190
|
+
resource,
|
|
191
|
+
start,
|
|
192
|
+
end
|
|
193
|
+
);
|
|
194
|
+
return result;
|
|
195
|
+
},
|
|
196
|
+
error => {
|
|
197
|
+
const end = performance.now();
|
|
198
|
+
recordDuration(
|
|
199
|
+
resolvedEnvironment,
|
|
200
|
+
operation,
|
|
201
|
+
resource,
|
|
202
|
+
start,
|
|
203
|
+
end
|
|
204
|
+
);
|
|
205
|
+
throw error;
|
|
206
|
+
}
|
|
207
|
+
);
|
|
208
|
+
} catch (error) {
|
|
209
|
+
const end = performance.now();
|
|
210
|
+
recordDuration(resolvedEnvironment, operation, resource, start, end);
|
|
211
|
+
return Promise.reject(error);
|
|
212
|
+
}
|
|
213
|
+
},
|
|
214
|
+
recordSync(environment, operation, resource, callback) {
|
|
215
|
+
if (!enabled) {
|
|
216
|
+
return callback();
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
const resolvedEnvironment = environment ?? 'unknown';
|
|
220
|
+
const start = performance.now();
|
|
221
|
+
try {
|
|
222
|
+
return callback();
|
|
223
|
+
} finally {
|
|
224
|
+
const end = performance.now();
|
|
225
|
+
recordDuration(resolvedEnvironment, operation, resource, start, end);
|
|
226
|
+
}
|
|
227
|
+
},
|
|
228
|
+
flush(environment, details = {}) {
|
|
229
|
+
if (!enabled) {
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
const resolvedEnvironment = environment ?? 'unknown';
|
|
234
|
+
const timings = timingsByEnvironment.get(resolvedEnvironment);
|
|
235
|
+
if (!timings || timings.size === 0) {
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
const operations = Object.fromEntries(
|
|
240
|
+
[...timings.entries()].map(([operation, timing]) => [
|
|
241
|
+
operation,
|
|
242
|
+
toOperationTiming(timing),
|
|
243
|
+
])
|
|
244
|
+
);
|
|
245
|
+
const report: ReactRouterPerformanceReport = {
|
|
246
|
+
environment: resolvedEnvironment,
|
|
247
|
+
...details,
|
|
248
|
+
operations,
|
|
249
|
+
};
|
|
250
|
+
log(`[react-router:performance] ${JSON.stringify(report)}`);
|
|
251
|
+
timingsByEnvironment.delete(resolvedEnvironment);
|
|
252
|
+
},
|
|
253
|
+
};
|
|
254
|
+
};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { normalize } from 'pathe';
|
|
2
|
+
import { existsSync } from 'node:fs';
|
|
3
|
+
import { JS_EXTENSIONS } from './constants.js';
|
|
4
|
+
|
|
5
|
+
export function combineURLs(baseURL: string, relativeURL: string): string {
|
|
6
|
+
return relativeURL
|
|
7
|
+
? `${baseURL.replace(/\/+$/, '')}/${relativeURL.replace(/^\/+/, '')}`
|
|
8
|
+
: baseURL;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function normalizeAssetPrefix(assetPrefix?: string): string {
|
|
12
|
+
if (!assetPrefix || assetPrefix === 'auto') {
|
|
13
|
+
return '/';
|
|
14
|
+
}
|
|
15
|
+
return assetPrefix.endsWith('/') ? assetPrefix : `${assetPrefix}/`;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function stripFileExtension(file: string): string {
|
|
19
|
+
return file.replace(/\.[^/.]+$/, '');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function createRouteId(file: string): string {
|
|
23
|
+
return normalize(stripFileExtension(file));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function findEntryFile(basePath: string): string {
|
|
27
|
+
for (const ext of JS_EXTENSIONS) {
|
|
28
|
+
const filePath = `${basePath}${ext}`;
|
|
29
|
+
if (existsSync(filePath)) {
|
|
30
|
+
return filePath;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return `${basePath}.tsx`;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function generateWithProps() {
|
|
37
|
+
return `
|
|
38
|
+
import { createElement as h } from "react";
|
|
39
|
+
import { useActionData, useLoaderData, useMatches, useParams, useRouteError } from "react-router";
|
|
40
|
+
|
|
41
|
+
export function withComponentProps(Component) {
|
|
42
|
+
return function Wrapped() {
|
|
43
|
+
const props = {
|
|
44
|
+
params: useParams(),
|
|
45
|
+
loaderData: useLoaderData(),
|
|
46
|
+
actionData: useActionData(),
|
|
47
|
+
matches: useMatches(),
|
|
48
|
+
};
|
|
49
|
+
return h(Component, props);
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function withHydrateFallbackProps(HydrateFallback) {
|
|
54
|
+
return function Wrapped() {
|
|
55
|
+
const props = {
|
|
56
|
+
params: useParams(),
|
|
57
|
+
};
|
|
58
|
+
return h(HydrateFallback, props);
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function withErrorBoundaryProps(ErrorBoundary) {
|
|
63
|
+
return function Wrapped() {
|
|
64
|
+
const props = {
|
|
65
|
+
params: useParams(),
|
|
66
|
+
loaderData: useLoaderData(),
|
|
67
|
+
actionData: useActionData(),
|
|
68
|
+
error: useRouteError(),
|
|
69
|
+
};
|
|
70
|
+
return h(ErrorBoundary, props);
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
`;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export {
|
|
77
|
+
invalidDestructureError,
|
|
78
|
+
removeExports,
|
|
79
|
+
removeUnusedImports,
|
|
80
|
+
validateDestructuredExports,
|
|
81
|
+
} from './route-export-pruning.js';
|
|
82
|
+
export { transformRoute } from './route-component-transform.js';
|