rsbuild-plugin-react-router 0.5.0 → 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 +58 -208
- package/dist/511.js +370 -331
- package/dist/build-output-transforms.d.ts +30 -6
- 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 -1
- 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/index.cjs +3957 -2208
- package/dist/index.d.ts +3 -1
- package/dist/index.js +3470 -1793
- 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/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-transform-tasks.d.ts +5 -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 +30 -1
- package/package.json +69 -14
- package/src/build-output-transforms.ts +155 -21
- 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 -85
- 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/index.ts +661 -496
- 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/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-transform-tasks.ts +39 -25
- 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 +39 -1
- package/src/warnings/warn-on-client-source-maps.ts +6 -10
package/dist/511.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { basename, dirname, normalize, relative, resolve } from "pathe";
|
|
2
2
|
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
3
|
+
import { createRequire } from "node:module";
|
|
3
4
|
import { langFromPath, parse, walk as external_yuku_parser_walk } from "yuku-parser";
|
|
4
5
|
import { Analyzer } from "yuku-analyzer";
|
|
5
6
|
import { print } from "yuku-codegen";
|
|
6
7
|
import { readFile, stat } from "node:fs/promises";
|
|
7
8
|
import { rspack } from "@rsbuild/core";
|
|
8
|
-
|
|
9
|
-
let PLUGIN_NAME = 'rsbuild:react-router', JS_EXTENSIONS = [
|
|
9
|
+
let PLUGIN_NAME = 'rsbuild:react-router', DEFAULT_JS_DIST_PATH = 'static/js', JS_EXTENSIONS = [
|
|
10
10
|
'.tsx',
|
|
11
11
|
'.ts',
|
|
12
12
|
'.jsx',
|
|
@@ -18,14 +18,16 @@ let PLUGIN_NAME = 'rsbuild:react-router', JS_EXTENSIONS = [
|
|
|
18
18
|
'action',
|
|
19
19
|
'middleware',
|
|
20
20
|
'headers'
|
|
21
|
-
], SERVER_ONLY_ROUTE_EXPORTS_SET = new Set(SERVER_ONLY_ROUTE_EXPORTS),
|
|
21
|
+
], SERVER_ONLY_ROUTE_EXPORTS_SET = new Set(SERVER_ONLY_ROUTE_EXPORTS), CLIENT_NON_COMPONENT_EXPORTS = [
|
|
22
22
|
'clientAction',
|
|
23
23
|
'clientLoader',
|
|
24
24
|
'clientMiddleware',
|
|
25
25
|
'handle',
|
|
26
26
|
'meta',
|
|
27
27
|
'links',
|
|
28
|
-
'shouldRevalidate'
|
|
28
|
+
'shouldRevalidate'
|
|
29
|
+
], CLIENT_ROUTE_EXPORTS_SET = new Set([
|
|
30
|
+
...CLIENT_NON_COMPONENT_EXPORTS,
|
|
29
31
|
'default',
|
|
30
32
|
'ErrorBoundary',
|
|
31
33
|
'HydrateFallback',
|
|
@@ -50,7 +52,7 @@ let PLUGIN_NAME = 'rsbuild:react-router', JS_EXTENSIONS = [
|
|
|
50
52
|
links: 'links',
|
|
51
53
|
meta: 'meta',
|
|
52
54
|
shouldRevalidate: 'shouldRevalidate'
|
|
53
|
-
}, getPatternIdentifierNames = (pattern, names = new Set())=>{
|
|
55
|
+
}, SPA_FALLBACK_HTML_FILE = '__spa-fallback.html', getProgram = (ast)=>ast.program ?? ast, getPatternIdentifierNames = (pattern, names = new Set())=>{
|
|
54
56
|
if (!pattern) return names;
|
|
55
57
|
if ('Identifier' === pattern.type) return names.add(pattern.name), names;
|
|
56
58
|
if ('RestElement' === pattern.type) return getPatternIdentifierNames(pattern.argument, names);
|
|
@@ -215,22 +217,115 @@ let PLUGIN_NAME = 'rsbuild:react-router', JS_EXTENSIONS = [
|
|
|
215
217
|
}
|
|
216
218
|
}
|
|
217
219
|
return cache.set(declaration, !1), !1;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
220
|
+
}, removeExports = (ast, exportsToRemove, exportsToRemoveSet = new Set(exportsToRemove), options = {})=>{
|
|
221
|
+
let currentlyLive, removedReferenceCache, isRemovableDeadDeclaration, program = getProgram(ast);
|
|
222
|
+
if (!((program, exportsToRemove)=>{
|
|
223
|
+
let removesNamedExports = [
|
|
224
|
+
...exportsToRemove
|
|
225
|
+
].some((name)=>'default' !== name);
|
|
226
|
+
for (let statement of program.body ?? []){
|
|
227
|
+
if ('ExportAllDeclaration' === statement.type) {
|
|
228
|
+
let exportedName = statement.exported ? getExportedName({
|
|
229
|
+
exported: statement.exported
|
|
230
|
+
}) : null;
|
|
231
|
+
if (exportedName && exportsToRemove.has(exportedName) || !exportedName && removesNamedExports) return !0;
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
if ('ExportDefaultDeclaration' === statement.type) {
|
|
235
|
+
if (exportsToRemove.has('default')) return !0;
|
|
236
|
+
continue;
|
|
237
|
+
}
|
|
238
|
+
if ('ExportNamedDeclaration' !== statement.type) continue;
|
|
239
|
+
for (let specifier of statement.specifiers ?? []){
|
|
240
|
+
if ('ExportSpecifier' !== specifier.type) continue;
|
|
241
|
+
let exportedName = getExportedName(specifier);
|
|
242
|
+
if (exportedName && exportsToRemove.has(exportedName)) return !0;
|
|
243
|
+
}
|
|
244
|
+
let declaration = statement.declaration;
|
|
245
|
+
if (declaration?.type === 'VariableDeclaration') {
|
|
246
|
+
for (let declarator of declaration.declarations ?? [])for (let name of getPatternIdentifierNames(declarator.id))if (exportsToRemove.has(name)) return !0;
|
|
247
|
+
continue;
|
|
248
|
+
}
|
|
249
|
+
if ((declaration?.type === 'FunctionDeclaration' || declaration?.type === 'ClassDeclaration') && declaration.id?.name && exportsToRemove.has(declaration.id.name)) return !0;
|
|
250
|
+
}
|
|
251
|
+
return !1;
|
|
252
|
+
})(program, exportsToRemoveSet)) return !1;
|
|
253
|
+
let declarationGraph = ((program)=>{
|
|
254
|
+
let declarationsByNode = new Map(), declarationsByName = new Map(), registerDeclaration = (node, declarationNode, declaredNames)=>{
|
|
255
|
+
let declaration = {
|
|
256
|
+
referencedNames: collectReferencedNames(declarationNode)
|
|
257
|
+
};
|
|
258
|
+
for (let name of (declarationsByNode.set(node, declaration), declaredNames)){
|
|
259
|
+
let namedDeclarations = declarationsByName.get(name) ?? new Set();
|
|
260
|
+
namedDeclarations.add(declaration), declarationsByName.set(name, namedDeclarations);
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
for (let statement of [
|
|
264
|
+
...program.body ?? []
|
|
265
|
+
]){
|
|
266
|
+
if ('VariableDeclaration' === statement.type) {
|
|
267
|
+
for (let declarator of statement.declarations ?? [])registerDeclaration(declarator, declarator, getPatternIdentifierNames(declarator.id));
|
|
268
|
+
continue;
|
|
269
|
+
}
|
|
270
|
+
('FunctionDeclaration' === statement.type || 'ClassDeclaration' === statement.type) && registerDeclaration(statement, statement, getDeclaredNames(statement));
|
|
271
|
+
}
|
|
272
|
+
return {
|
|
273
|
+
declarationsByNode,
|
|
274
|
+
declarationsByName
|
|
275
|
+
};
|
|
276
|
+
})(program), previouslyLive = collectLiveTopLevelDeclarations(program, declarationGraph), exportsChanged = !1, removedExportLocalNames = new Set(), removedExportReferencedNames = new Set(), removesNamedExports = exportsToRemove.some((name)=>'default' !== name), trackRemovedExportReferences = (node)=>{
|
|
277
|
+
if (!node) return;
|
|
278
|
+
let declaration = declarationGraph.declarationsByNode.get(node);
|
|
279
|
+
for (let name of declaration?.referencedNames ?? collectReferencedNames(node))removedExportReferencedNames.add(name);
|
|
224
280
|
};
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
281
|
+
for (let statement of [
|
|
282
|
+
...program.body
|
|
283
|
+
]){
|
|
284
|
+
if ('ExportAllDeclaration' === statement.type) {
|
|
285
|
+
let exportedName = statement.exported ? getExportedName({
|
|
286
|
+
exported: statement.exported
|
|
287
|
+
}) : null;
|
|
288
|
+
if (exportedName && exportsToRemoveSet.has(exportedName) && (exportsChanged = !0, removeFromArray(program.body, statement)), !exportedName && removesNamedExports) throw Error('Cannot remove named exports from `export *`; use explicit named re-exports.');
|
|
289
|
+
continue;
|
|
290
|
+
}
|
|
291
|
+
if ('ExportNamedDeclaration' === statement.type) {
|
|
292
|
+
statement.specifiers?.length && (statement.specifiers = statement.specifiers.filter((specifier)=>{
|
|
293
|
+
if ('ExportSpecifier' !== specifier.type) return !0;
|
|
294
|
+
let exportedName = getExportedName(specifier);
|
|
295
|
+
return !(exportedName && exportsToRemoveSet.has(exportedName)) || (exportsChanged = !0, specifier.local?.name && (removedExportLocalNames.add(specifier.local.name), removedExportReferencedNames.add(specifier.local.name)), !1);
|
|
296
|
+
}), 0 !== statement.specifiers.length || statement.declaration || removeFromArray(program.body, statement));
|
|
297
|
+
let declaration = statement.declaration;
|
|
298
|
+
declaration?.type === 'VariableDeclaration' && (declaration.declarations = (declaration.declarations ?? []).filter((declarator)=>{
|
|
299
|
+
let id = declarator.id;
|
|
300
|
+
return id?.type === 'Identifier' ? !(id.name && exportsToRemoveSet.has(id.name)) || (exportsChanged = !0, removedExportLocalNames.add(id.name), removedExportReferencedNames.add(id.name), trackRemovedExportReferences(declarator), !1) : (id && validateBindingTarget(id, new Set(exportsToRemove)), !0);
|
|
301
|
+
}), 0 === declaration.declarations.length && removeFromArray(program.body, statement)), (declaration?.type === 'FunctionDeclaration' || declaration?.type === 'ClassDeclaration') && declaration.id?.name && exportsToRemoveSet.has(declaration.id.name) && (exportsChanged = !0, removedExportLocalNames.add(declaration.id.name), removedExportReferencedNames.add(declaration.id.name), trackRemovedExportReferences(statement), removeFromArray(program.body, statement));
|
|
302
|
+
}
|
|
303
|
+
if ('ExportDefaultDeclaration' === statement.type && exportsToRemoveSet.has('default')) {
|
|
304
|
+
exportsChanged = !0;
|
|
305
|
+
let declaration = statement.declaration;
|
|
306
|
+
declaration?.type === 'Identifier' && declaration.name ? (removedExportLocalNames.add(declaration.name), removedExportReferencedNames.add(declaration.name)) : declaration?.id?.name && (removedExportLocalNames.add(declaration.id.name), removedExportReferencedNames.add(declaration.id.name)), trackRemovedExportReferences(statement), removeFromArray(program.body, statement);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
for (let statement of [
|
|
310
|
+
...program.body
|
|
311
|
+
]){
|
|
312
|
+
let expression = 'ExpressionStatement' === statement.type ? statement.expression : null, left = expression?.type === 'AssignmentExpression' ? expression.left : null;
|
|
313
|
+
left?.type === 'MemberExpression' && left.object?.type === 'Identifier' && left.object.name && removedExportLocalNames.has(left.object.name) && removeFromArray(program.body, statement);
|
|
314
|
+
}
|
|
315
|
+
return exportsChanged && !1 !== options.pruneDeadDeclarations && (currentlyLive = collectLiveTopLevelDeclarations(program, declarationGraph), removedReferenceCache = new Map(), isRemovableDeadDeclaration = (node)=>{
|
|
316
|
+
let declaration = declarationGraph.declarationsByNode.get(node);
|
|
317
|
+
return !(!declaration || currentlyLive.has(declaration)) && (previouslyLive.has(declaration) || declarationReferencesName(declaration, removedExportReferencedNames, declarationGraph, removedReferenceCache));
|
|
318
|
+
}, program.body = program.body.filter((statement)=>'VariableDeclaration' === statement.type ? (statement.declarations = (statement.declarations ?? []).filter((declarator)=>!isRemovableDeadDeclaration(declarator)), statement.declarations.length > 0) : !isRemovableDeadDeclaration(statement))), exportsChanged;
|
|
319
|
+
}, removeUnusedImports = (ast)=>{
|
|
320
|
+
let program = getProgram(ast), referenced = collectReferencedNames(program);
|
|
321
|
+
for (let statement of [
|
|
322
|
+
...program.body
|
|
323
|
+
])'ImportDeclaration' === statement.type && 0 !== (statement.specifiers ?? []).length && (statement.specifiers = (statement.specifiers ?? []).filter((specifier)=>'type' !== specifier.importKind && (!specifier.local?.name || referenced.has(specifier.local.name))), 0 === statement.specifiers.length && removeFromArray(program.body, statement));
|
|
324
|
+
}, toExpression = (decl, type)=>({
|
|
228
325
|
...decl,
|
|
229
|
-
type
|
|
326
|
+
type,
|
|
230
327
|
declare: void 0
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
let getComponentExportName = (exportedName)=>{
|
|
328
|
+
}), getComponentExportName = (exportedName)=>{
|
|
234
329
|
var name;
|
|
235
330
|
return 'default' === exportedName ? 'Component' : (name = exportedName, NAMED_COMPONENT_EXPORTS_SET.has(name)) ? exportedName : null;
|
|
236
331
|
}, declarationIncludesName = (declaration, name)=>'VariableDeclaration' === declaration.type ? (declaration.declarations ?? []).some((declarator)=>{
|
|
@@ -250,13 +345,40 @@ let getComponentExportName = (exportedName)=>{
|
|
|
250
345
|
if (declaration && declarationIncludesName(declaration, name)) return !0;
|
|
251
346
|
}
|
|
252
347
|
return !1;
|
|
253
|
-
}
|
|
348
|
+
}, requireFromApp = createRequire(resolve(process.cwd(), 'package.json')), resolveAppPackagePath = (specifier)=>{
|
|
349
|
+
try {
|
|
350
|
+
return requireFromApp.resolve(specifier);
|
|
351
|
+
} catch {
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
}, parseVersionMajorMinor = (version)=>{
|
|
355
|
+
let match = version?.match(/^(\d+)\.(\d+)\./);
|
|
356
|
+
if (match) return {
|
|
357
|
+
major: Number(match[1]),
|
|
358
|
+
minor: Number(match[2])
|
|
359
|
+
};
|
|
360
|
+
}, packageVersionCache = new Map(), getPackageVersion = (packageName, resolvePackagePath = resolveAppPackagePath)=>{
|
|
361
|
+
let cacheable = resolvePackagePath === resolveAppPackagePath;
|
|
362
|
+
if (cacheable && packageVersionCache.has(packageName)) return packageVersionCache.get(packageName);
|
|
363
|
+
let packageJsonPath = resolvePackagePath(`${packageName}/package.json`);
|
|
364
|
+
if (packageJsonPath) try {
|
|
365
|
+
let packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8')), version = 'string' == typeof packageJson.version ? packageJson.version : void 0;
|
|
366
|
+
return cacheable && packageVersionCache.set(packageName, version), version;
|
|
367
|
+
} catch {
|
|
368
|
+
cacheable && packageVersionCache.set(packageName, void 0);
|
|
369
|
+
return;
|
|
370
|
+
}
|
|
371
|
+
}, escapeHtml = (value)=>value.replaceAll('&', '&').replaceAll('<', '<').replaceAll('>', '>');
|
|
254
372
|
function combineURLs(baseURL, relativeURL) {
|
|
255
373
|
return relativeURL ? `${baseURL.replace(/\/+$/, '')}/${relativeURL.replace(/^\/+/, '')}` : baseURL;
|
|
256
374
|
}
|
|
257
375
|
function normalizeAssetPrefix(assetPrefix) {
|
|
258
376
|
return assetPrefix && 'auto' !== assetPrefix ? assetPrefix.endsWith('/') ? assetPrefix : `${assetPrefix}/` : '/';
|
|
259
377
|
}
|
|
378
|
+
function resolveEffectiveAssetPrefix(config) {
|
|
379
|
+
let outputPrefix = 'string' == typeof config.output?.assetPrefix ? config.output.assetPrefix : void 0;
|
|
380
|
+
return config.isBuild ? normalizeAssetPrefix(outputPrefix) : normalizeAssetPrefix(('string' == typeof config.dev?.assetPrefix ? config.dev.assetPrefix : void 0) ?? outputPrefix);
|
|
381
|
+
}
|
|
260
382
|
function createRouteId(file) {
|
|
261
383
|
return normalize(file.replace(/\.[^/.]+$/, ''));
|
|
262
384
|
}
|
|
@@ -269,41 +391,15 @@ function findEntryFile(basePath) {
|
|
|
269
391
|
}
|
|
270
392
|
function generateWithProps() {
|
|
271
393
|
return `
|
|
272
|
-
import {
|
|
273
|
-
|
|
394
|
+
import {
|
|
395
|
+
UNSAFE_withComponentProps,
|
|
396
|
+
UNSAFE_withErrorBoundaryProps,
|
|
397
|
+
UNSAFE_withHydrateFallbackProps,
|
|
398
|
+
} from "react-router";
|
|
274
399
|
|
|
275
|
-
export
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
params: useParams(),
|
|
279
|
-
loaderData: useLoaderData(),
|
|
280
|
-
actionData: useActionData(),
|
|
281
|
-
matches: useMatches(),
|
|
282
|
-
};
|
|
283
|
-
return h(Component, props);
|
|
284
|
-
};
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
export function withHydrateFallbackProps(HydrateFallback) {
|
|
288
|
-
return function Wrapped() {
|
|
289
|
-
const props = {
|
|
290
|
-
params: useParams(),
|
|
291
|
-
};
|
|
292
|
-
return h(HydrateFallback, props);
|
|
293
|
-
};
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
export function withErrorBoundaryProps(ErrorBoundary) {
|
|
297
|
-
return function Wrapped() {
|
|
298
|
-
const props = {
|
|
299
|
-
params: useParams(),
|
|
300
|
-
loaderData: useLoaderData(),
|
|
301
|
-
actionData: useActionData(),
|
|
302
|
-
error: useRouteError(),
|
|
303
|
-
};
|
|
304
|
-
return h(ErrorBoundary, props);
|
|
305
|
-
};
|
|
306
|
-
}
|
|
400
|
+
export const withComponentProps = UNSAFE_withComponentProps;
|
|
401
|
+
export const withHydrateFallbackProps = UNSAFE_withHydrateFallbackProps;
|
|
402
|
+
export const withErrorBoundaryProps = UNSAFE_withErrorBoundaryProps;
|
|
307
403
|
`;
|
|
308
404
|
}
|
|
309
405
|
let routeChunkExportNames = [
|
|
@@ -339,7 +435,7 @@ let mightContainRouteChunkExportName = (source)=>routeChunkExportNames.some((exp
|
|
|
339
435
|
value,
|
|
340
436
|
version
|
|
341
437
|
}), value;
|
|
342
|
-
}, analyzeCode = (code, cache, cacheKey)=>getOrSetFromCache(cache, `${cacheKey}::analyzeCode`, code, ()=>{
|
|
438
|
+
}, hasCachedValue = (cache, key, version)=>cache.get(key)?.version === version, analyzeCode = (code, cache, cacheKey)=>getOrSetFromCache(cache, `${cacheKey}::analyzeCode`, code, ()=>{
|
|
343
439
|
let module = new Analyzer().addFile(cacheKey, code, {
|
|
344
440
|
lang: 'tsx',
|
|
345
441
|
sourceType: 'module',
|
|
@@ -350,10 +446,19 @@ let mightContainRouteChunkExportName = (source)=>routeChunkExportNames.some((exp
|
|
|
350
446
|
module,
|
|
351
447
|
program: module.ast
|
|
352
448
|
};
|
|
353
|
-
}),
|
|
449
|
+
}), isTopLevelExportedVariableDeclarator = (module, node)=>{
|
|
450
|
+
let declaration = module.parentOf(node);
|
|
451
|
+
if (declaration?.type !== 'VariableDeclaration') return !1;
|
|
452
|
+
let statement = module.parentOf(declaration);
|
|
453
|
+
return statement?.type === 'ExportNamedDeclaration';
|
|
454
|
+
}, route_chunks_getExportedName = (exported)=>'Identifier' === exported.type ? exported.name : String(exported.value), setsIntersect = (set1, set2)=>{
|
|
354
455
|
let smallerSet = set1, largerSet = set2;
|
|
355
456
|
for (let element of (set1.size > set2.size && (smallerSet = set2, largerSet = set1), smallerSet))if (largerSet.has(element)) return !0;
|
|
356
457
|
return !1;
|
|
458
|
+
}, isEntryClientImport = (source, importer)=>{
|
|
459
|
+
if (!source.startsWith('.') && !source.startsWith('/')) return !1;
|
|
460
|
+
let resolved = normalize(resolve('/', dirname(importer), source));
|
|
461
|
+
return /(?:^|\/)entry\.client(?:\.[cm]?[jt]sx?)?$/.test(resolved);
|
|
357
462
|
}, getExportDependencies = (code, cache, cacheKey)=>getOrSetFromCache(cache, `${cacheKey}::getExportDependencies`, code, ()=>{
|
|
358
463
|
let { module } = analyzeCode(code, cache, cacheKey), exportDependencies = new Map(), topLevelStatementCache = new Map(), variableDeclaratorCache = new Map(), getCachedTopLevelStatementForNode = (node)=>{
|
|
359
464
|
let cached = topLevelStatementCache.get(node);
|
|
@@ -383,6 +488,7 @@ let mightContainRouteChunkExportName = (source)=>routeChunkExportNames.some((exp
|
|
|
383
488
|
topLevelStatements: new Set(),
|
|
384
489
|
topLevelNonModuleStatements: new Set(),
|
|
385
490
|
importedIdentifierNames: new Set(),
|
|
491
|
+
importSources: new Set(),
|
|
386
492
|
exportedVariableDeclarators: new Set()
|
|
387
493
|
}, visitedSymbols = new Set(), scannedNodes = new Set(), scanNode = (node)=>{
|
|
388
494
|
scannedNodes.has(node) || (scannedNodes.add(node), external_yuku_parser_walk(node, {
|
|
@@ -392,12 +498,15 @@ let mightContainRouteChunkExportName = (source)=>routeChunkExportNames.some((exp
|
|
|
392
498
|
}
|
|
393
499
|
}));
|
|
394
500
|
}, visitSymbol = (symbol)=>{
|
|
395
|
-
if (!visitedSymbols.has(symbol)) {
|
|
396
|
-
for (let declaration of
|
|
501
|
+
if (!visitedSymbols.has(symbol) && (visitedSymbols.add(symbol), 0 !== symbol.declarations.length)) {
|
|
502
|
+
for (let declaration of symbol.declarations){
|
|
397
503
|
let statement = addCachedTopLevelStatement(dependencies, declaration);
|
|
398
|
-
'ImportDeclaration' === statement.type
|
|
504
|
+
if ('ImportDeclaration' === statement.type) {
|
|
505
|
+
dependencies.importedIdentifierNames.add(symbol.name), 'string' == typeof statement.source?.value && dependencies.importSources.add(statement.source.value);
|
|
506
|
+
return;
|
|
507
|
+
}
|
|
399
508
|
let declarator = getCachedVariableDeclaratorForNode(declaration);
|
|
400
|
-
declarator &&
|
|
509
|
+
declarator && isTopLevelExportedVariableDeclarator(module, declarator) && dependencies.exportedVariableDeclarators.add(declarator), scanNode(declarator ?? statement);
|
|
401
510
|
}
|
|
402
511
|
for (let reference of symbol.references){
|
|
403
512
|
let statement = addCachedTopLevelStatement(dependencies, reference.node);
|
|
@@ -409,19 +518,25 @@ let mightContainRouteChunkExportName = (source)=>routeChunkExportNames.some((exp
|
|
|
409
518
|
};
|
|
410
519
|
for (let exp of module.exports)exp.typeOnly || exp.isStar || exp.isExportEquals || handleExport(exp.name, exp.node, exp.local ?? null);
|
|
411
520
|
return exportDependencies;
|
|
521
|
+
}), isExportChunkable = (exportName, exportDependencies, importer)=>{
|
|
522
|
+
let dependencies = exportDependencies.get(exportName);
|
|
523
|
+
if (!dependencies || 'clientLoader' === exportName && hasHydrateAssignment(dependencies) || 'clientLoader' === exportName && ((dependencies, importer)=>{
|
|
524
|
+
for (let source of dependencies.importSources)if (isEntryClientImport(source, importer)) return !0;
|
|
525
|
+
return !1;
|
|
526
|
+
})(dependencies, importer)) return !1;
|
|
527
|
+
for (let [currentExportName, currentDependencies] of exportDependencies)if (currentExportName !== exportName && setsIntersect(currentDependencies.topLevelNonModuleStatements, dependencies.topLevelNonModuleStatements)) return !1;
|
|
528
|
+
if (dependencies.exportedVariableDeclarators.size > 1) return !1;
|
|
529
|
+
if (dependencies.exportedVariableDeclarators.size > 0) {
|
|
530
|
+
for (let [currentExportName, currentDependencies] of exportDependencies)if (currentExportName !== exportName && setsIntersect(currentDependencies.exportedVariableDeclarators, dependencies.exportedVariableDeclarators)) return !1;
|
|
531
|
+
}
|
|
532
|
+
return !0;
|
|
533
|
+
}, hasHydrateAssignment = (dependencies)=>Array.from(dependencies.topLevelNonModuleStatements).some((statement)=>{
|
|
534
|
+
let expression = statement.expression, left = expression?.left;
|
|
535
|
+
return 'ExpressionStatement' === statement.type && expression?.type === 'AssignmentExpression' && left?.type === 'MemberExpression' && left.object?.type === 'Identifier' && 'clientLoader' === left.object.name && left.property?.type === 'Identifier' && 'hydrate' === left.property.name;
|
|
412
536
|
}), getChunkableExportMap = (code, cache, cacheKey)=>getOrSetFromCache(cache, `${cacheKey}::getChunkableExportMap`, code, ()=>{
|
|
413
537
|
let exportDependencies = getExportDependencies(code, cache, cacheKey);
|
|
414
|
-
return createRouteChunkExportMap((exportName)=>(
|
|
415
|
-
|
|
416
|
-
if (!dependencies) return !1;
|
|
417
|
-
for (let [currentExportName, currentDependencies] of exportDependencies)if (currentExportName !== exportName && setsIntersect(currentDependencies.topLevelNonModuleStatements, dependencies.topLevelNonModuleStatements)) return !1;
|
|
418
|
-
if (dependencies.exportedVariableDeclarators.size > 1) return !1;
|
|
419
|
-
if (dependencies.exportedVariableDeclarators.size > 0) {
|
|
420
|
-
for (let [currentExportName, currentDependencies] of exportDependencies)if (currentExportName !== exportName && setsIntersect(currentDependencies.exportedVariableDeclarators, dependencies.exportedVariableDeclarators)) return !1;
|
|
421
|
-
}
|
|
422
|
-
return !0;
|
|
423
|
-
})(exportName, exportDependencies));
|
|
424
|
-
}), generateCode = (program)=>{
|
|
538
|
+
return createRouteChunkExportMap((exportName)=>isExportChunkable(exportName, exportDependencies, cacheKey));
|
|
539
|
+
}), hasChunkableExport = (code, exportName, cache, cacheKey)=>routeChunkExportNames.includes(exportName) ? getChunkableExportMap(code, cache, cacheKey)[exportName] : isExportChunkable(exportName, getExportDependencies(code, cache, cacheKey), cacheKey), generateCode = (program)=>{
|
|
425
540
|
if (0 === program.body.length) return;
|
|
426
541
|
let result = print(program, {
|
|
427
542
|
comments: !0
|
|
@@ -436,7 +551,7 @@ let mightContainRouteChunkExportName = (source)=>routeChunkExportNames.some((exp
|
|
|
436
551
|
specifiers
|
|
437
552
|
} : null;
|
|
438
553
|
}, getChunkedExport = (code, exportName, cache, cacheKey)=>getOrSetFromCache(cache, `${cacheKey}::getChunkedExport::${exportName}`, code, ()=>{
|
|
439
|
-
if (!
|
|
554
|
+
if (!hasChunkableExport(code, exportName, cache, cacheKey)) return;
|
|
440
555
|
let dependencies = getExportDependencies(code, cache, cacheKey).get(exportName);
|
|
441
556
|
invariant(dependencies, 'Expected export to have dependencies');
|
|
442
557
|
let program = analyzeCode(code, cache, cacheKey).program, body = program.body.filter((node)=>dependencies.topLevelStatements.has(node)).map((node)=>'ImportDeclaration' !== node.type ? node : 0 === dependencies.importedIdentifierNames.size ? null : filterImportSpecifiers(node, (importedName)=>dependencies.importedIdentifierNames.has(importedName))).map((node)=>{
|
|
@@ -468,77 +583,90 @@ let mightContainRouteChunkExportName = (source)=>routeChunkExportNames.some((exp
|
|
|
468
583
|
...program,
|
|
469
584
|
body
|
|
470
585
|
});
|
|
471
|
-
}), hasCachedChunkedExport = (code, exportName, cache, cacheKey)=>{
|
|
472
|
-
let
|
|
473
|
-
return
|
|
474
|
-
|
|
586
|
+
}), getChunkedExportCacheKey = (cacheKey, exportName)=>`${cacheKey}::getChunkedExport::${exportName}`, hasCachedChunkedExport = (code, exportName, cache, cacheKey)=>hasCachedValue(cache, getChunkedExportCacheKey(cacheKey, exportName), code), getSharedChunkedExports = (exportDependencies, cacheKey)=>Array.from(exportDependencies.keys()).filter((exportName)=>'default' !== exportName && !routeChunkExportNames.includes(exportName) && !SERVER_ONLY_ROUTE_EXPORTS_SET.has(exportName) && isExportChunkable(exportName, exportDependencies, cacheKey)).sort(), getChunkedExportNames = (code, cache, cacheKey)=>{
|
|
587
|
+
let exportDependencies = getExportDependencies(code, cache, cacheKey), routeChunkedExports = routeChunkExportNames.filter((exportName)=>isExportChunkable(exportName, exportDependencies, cacheKey));
|
|
588
|
+
return 0 === routeChunkedExports.length ? [] : [
|
|
589
|
+
...routeChunkedExports,
|
|
590
|
+
...getSharedChunkedExports(exportDependencies, cacheKey)
|
|
591
|
+
];
|
|
592
|
+
}, detectRouteChunks = (code, cache, cacheKey)=>{
|
|
593
|
+
let analysisCache = cache ?? new Map(), exportDependencies = getExportDependencies(code, analysisCache, cacheKey), hasRouteChunkByExportName = getChunkableExportMap(code, analysisCache, cacheKey), chunkedExports = Object.entries(hasRouteChunkByExportName).filter(([, isChunked])=>isChunked).map(([exportName])=>exportName), sharedChunkedExports = chunkedExports.length > 0 ? getSharedChunkedExports(exportDependencies, cacheKey) : [], hasRouteChunks = chunkedExports.length > 0 || sharedChunkedExports.length > 0;
|
|
594
|
+
return {
|
|
595
|
+
exportNames: Array.from(exportDependencies.keys()),
|
|
596
|
+
hasRouteChunks,
|
|
597
|
+
hasRouteChunkByExportName,
|
|
598
|
+
chunkedExports,
|
|
599
|
+
sharedChunkedExports
|
|
600
|
+
};
|
|
601
|
+
}, getRouteChunkModuleId = (filePath, chunkName)=>`${filePath}${routeChunkQueryStrings[chunkName] ?? `${routeChunkQueryStringPrefix}${encodeURIComponent(chunkName)}`}`, getRouteChunkNameFromModuleId = (id)=>{
|
|
602
|
+
let queryIndex = id.indexOf(routeChunkQueryStringPrefix);
|
|
603
|
+
if (-1 === queryIndex) return null;
|
|
604
|
+
let chunkNameStart = queryIndex + routeChunkQueryStringPrefix.length, chunkNameEnd = id.indexOf('&', chunkNameStart), chunkName = id.slice(chunkNameStart, -1 === chunkNameEnd ? void 0 : chunkNameEnd);
|
|
605
|
+
return 'main' === chunkName || /^[A-Za-z_$][\w$]*$/.test(chunkName) ? chunkName : null;
|
|
606
|
+
}, normalizeRelativeFilePath = (file, appDirectory)=>{
|
|
475
607
|
let fullPath = resolve(appDirectory, file);
|
|
476
608
|
return normalize(relative(appDirectory, fullPath)).split('?')[0];
|
|
477
|
-
}, isRootRouteModuleId = (config, id)=>normalizeRelativeFilePath(id, config.appDirectory) === config.rootRouteFile, shouldAnalyzeRouteChunks = (config, id, code)=>!!config.splitRouteModules && mightContainRouteChunkExportName(code) && !isRootRouteModuleId(config, id), createEmptyRouteChunkByExportName = ()=>createRouteChunkExportMap(()=>!1), buildManifestChunkValidity = (exportNames, hasRouteChunkByExportName)=>createRouteChunkExportMap((exportName)=>!exportNames.has(exportName) || hasRouteChunkByExportName[exportName]), detectRouteChunksIfEnabled = async (cache, config, id, code)=>{
|
|
478
|
-
let analysisCache, exportDependencies, hasRouteChunkByExportName, chunkedExports, hasRouteChunks;
|
|
479
|
-
if (!shouldAnalyzeRouteChunks(config, id, code)) return {
|
|
609
|
+
}, isRootRouteModuleId = (config, id)=>normalizeRelativeFilePath(id, config.appDirectory) === config.rootRouteFile, shouldAnalyzeRouteChunks = (config, id, code)=>!!config.splitRouteModules && mightContainRouteChunkExportName(code) && !isRootRouteModuleId(config, id), createEmptyRouteChunkByExportName = ()=>createRouteChunkExportMap(()=>!1), buildManifestChunkValidity = (exportNames, hasRouteChunkByExportName)=>createRouteChunkExportMap((exportName)=>!exportNames.has(exportName) || hasRouteChunkByExportName[exportName]), detectRouteChunksIfEnabled = async (cache, config, id, code)=>shouldAnalyzeRouteChunks(config, id, code) ? detectRouteChunks(code, cache, normalizeRelativeFilePath(id, config.appDirectory)) : {
|
|
480
610
|
exportNames: [],
|
|
481
611
|
chunkedExports: [],
|
|
612
|
+
sharedChunkedExports: [],
|
|
482
613
|
hasRouteChunks: !1,
|
|
483
614
|
hasRouteChunkByExportName: createEmptyRouteChunkByExportName()
|
|
484
|
-
}
|
|
485
|
-
let cacheKey = normalizeRelativeFilePath(id, config.appDirectory);
|
|
486
|
-
return exportDependencies = getExportDependencies(code, analysisCache = cache ?? new Map(), cacheKey), hasRouteChunks = (chunkedExports = Object.entries(hasRouteChunkByExportName = getChunkableExportMap(code, analysisCache, cacheKey)).filter(([, isChunked])=>isChunked).map(([exportName])=>exportName)).length > 0, {
|
|
487
|
-
exportNames: Array.from(exportDependencies.keys()),
|
|
488
|
-
hasRouteChunks,
|
|
489
|
-
hasRouteChunkByExportName,
|
|
490
|
-
chunkedExports
|
|
491
|
-
};
|
|
492
|
-
}, getRouteChunkIfEnabled = async (cache, config, id, chunkName, code)=>{
|
|
615
|
+
}, getRouteChunkIfEnabled = async (cache, config, id, chunkName, code)=>{
|
|
493
616
|
if (!config.splitRouteModules) return null;
|
|
494
617
|
if ('main' === chunkName) {
|
|
495
618
|
if (!mightContainRouteChunkExportName(code)) return code;
|
|
496
619
|
} else if (!code.includes(chunkName)) return null;
|
|
497
620
|
return ((code, chunkName, cache, cacheKey)=>{
|
|
498
621
|
let analysisCache = cache ?? new Map();
|
|
499
|
-
if ('main' === chunkName)
|
|
500
|
-
let
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
let program = analyzeCode(code, analysisCache, cacheKey).program, body = program.body.filter((node)=>!omittedStatements.has(node)).map((node)=>'ImportDeclaration' !== node.type ? node : filterImportSpecifiers(node, (importedName)=>!!retainedImportedIdentifierNames.has(importedName) || !omittedImportedIdentifierNames.has(importedName))).map((node)=>{
|
|
512
|
-
if (!node || !node.type.startsWith('Export') || 'ExportAllDeclaration' === node.type) return node;
|
|
513
|
-
if ('ExportDefaultDeclaration' === node.type) return isOmitted('default') ? null : node;
|
|
514
|
-
if (node.declaration?.type === 'VariableDeclaration') {
|
|
515
|
-
let declarations = node.declaration.declarations.filter((declarationNode)=>!omittedExportedVariableDeclarators.has(declarationNode));
|
|
516
|
-
return declarations.length > 0 ? {
|
|
517
|
-
...node,
|
|
518
|
-
declaration: {
|
|
519
|
-
...node.declaration,
|
|
520
|
-
declarations
|
|
521
|
-
}
|
|
522
|
-
} : null;
|
|
622
|
+
if ('main' === chunkName) {
|
|
623
|
+
let exportNames, serverOnlyExports = Array.from(getExportDependencies(code, analysisCache, cacheKey).keys()).filter((exportName)=>SERVER_ONLY_ROUTE_EXPORTS_SET.has(exportName));
|
|
624
|
+
return exportNames = [
|
|
625
|
+
...getChunkedExportNames(code, analysisCache, cacheKey),
|
|
626
|
+
...serverOnlyExports
|
|
627
|
+
], getOrSetFromCache(analysisCache, `${cacheKey}::omitChunkedExports::${exportNames.join(',')}`, code, ()=>{
|
|
628
|
+
let exportNameSet = new Set(exportNames), isOmitted = (exportName)=>exportNameSet.has(exportName) && hasChunkableExport(code, exportName, analysisCache, cacheKey), exportDependencies = getExportDependencies(code, analysisCache, cacheKey), allExportNames = Array.from(exportDependencies.keys()), omittedExportNames = allExportNames.filter(isOmitted), retainedExportNames = allExportNames.filter((exportName)=>!isOmitted(exportName)), omittedStatements = new Set(), omittedExportedVariableDeclarators = new Set(), retainedImportedIdentifierNames = new Set(), omittedImportedIdentifierNames = new Set();
|
|
629
|
+
for (let omittedExportName of omittedExportNames){
|
|
630
|
+
let dependencies = exportDependencies.get(omittedExportName);
|
|
631
|
+
for (let statement of (invariant(dependencies, `Expected dependencies for ${omittedExportName}`), dependencies.topLevelNonModuleStatements))omittedStatements.add(statement);
|
|
632
|
+
for (let declarator of dependencies.exportedVariableDeclarators)omittedExportedVariableDeclarators.add(declarator);
|
|
633
|
+
for (let importedName of dependencies.importedIdentifierNames)omittedImportedIdentifierNames.add(importedName);
|
|
523
634
|
}
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
let
|
|
527
|
-
return specifiers.length > 0 || node.declaration ? {
|
|
528
|
-
...node,
|
|
529
|
-
specifiers
|
|
530
|
-
} : null;
|
|
635
|
+
for (let retainedExportName of retainedExportNames){
|
|
636
|
+
let dependencies = exportDependencies.get(retainedExportName);
|
|
637
|
+
if (dependencies) for (let importedName of dependencies.importedIdentifierNames)retainedImportedIdentifierNames.add(importedName);
|
|
531
638
|
}
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
639
|
+
let program = analyzeCode(code, analysisCache, cacheKey).program, body = program.body.filter((node)=>!omittedStatements.has(node)).map((node)=>'ImportDeclaration' !== node.type ? node : filterImportSpecifiers(node, (importedName)=>!!retainedImportedIdentifierNames.has(importedName) || !omittedImportedIdentifierNames.has(importedName))).map((node)=>{
|
|
640
|
+
if (!node || !node.type.startsWith('Export') || 'ExportAllDeclaration' === node.type) return node;
|
|
641
|
+
if ('ExportDefaultDeclaration' === node.type) return isOmitted('default') ? null : node;
|
|
642
|
+
if (node.declaration?.type === 'VariableDeclaration') {
|
|
643
|
+
let declarations = node.declaration.declarations.filter((declarationNode)=>!omittedExportedVariableDeclarators.has(declarationNode));
|
|
644
|
+
return declarations.length > 0 ? {
|
|
645
|
+
...node,
|
|
646
|
+
declaration: {
|
|
647
|
+
...node.declaration,
|
|
648
|
+
declarations
|
|
649
|
+
}
|
|
650
|
+
} : null;
|
|
651
|
+
}
|
|
652
|
+
if (node.declaration?.type === 'FunctionDeclaration' || node.declaration?.type === 'ClassDeclaration') return isOmitted(node.declaration.id.name) ? null : node;
|
|
653
|
+
if ('ExportNamedDeclaration' === node.type) {
|
|
654
|
+
let specifiers = node.specifiers.filter((specifier)=>!isOmitted(route_chunks_getExportedName(specifier.exported)));
|
|
655
|
+
return specifiers.length > 0 || node.declaration ? {
|
|
656
|
+
...node,
|
|
657
|
+
specifiers
|
|
658
|
+
} : null;
|
|
659
|
+
}
|
|
660
|
+
throw Error('Unknown node type');
|
|
661
|
+
}).filter(Boolean);
|
|
662
|
+
return generateCode({
|
|
663
|
+
...program,
|
|
664
|
+
body
|
|
665
|
+
});
|
|
537
666
|
});
|
|
538
|
-
}
|
|
667
|
+
}
|
|
539
668
|
return hasCachedChunkedExport(code, chunkName, analysisCache, cacheKey) || ((code, cache, cacheKey)=>{
|
|
540
|
-
let
|
|
541
|
-
for (let exportName of routeChunkExportNames)chunkableExportMap[exportName] && (hasCachedChunkedExport(code, exportName, cache, cacheKey) || getChunkedExport(code, exportName, cache, cacheKey));
|
|
669
|
+
for (let exportName of getChunkedExportNames(code, cache, cacheKey))hasChunkableExport(code, exportName, cache, cacheKey) && !hasCachedChunkedExport(code, exportName, cache, cacheKey) && (hasCachedValue(cache, getChunkedExportCacheKey(cacheKey, exportName), code) || getChunkedExport(code, exportName, cache, cacheKey));
|
|
542
670
|
})(code, analysisCache, cacheKey), getChunkedExport(code, chunkName, analysisCache, cacheKey);
|
|
543
671
|
})(code, chunkName, cache, normalizeRelativeFilePath(id, config.appDirectory)) ?? null;
|
|
544
672
|
}, validateRouteChunks = ({ config, id, valid })=>{
|
|
@@ -563,7 +691,7 @@ let mightContainRouteChunkExportName = (source)=>routeChunkExportNames.some((exp
|
|
|
563
691
|
sourceType: 'module',
|
|
564
692
|
lang
|
|
565
693
|
}), errors = getParseErrors(result);
|
|
566
|
-
if (0 === errors.length) return result
|
|
694
|
+
if (0 === errors.length) return getProgram(result);
|
|
567
695
|
if (!sourcePath || 'ts' !== lang && 'tsx' !== lang) throw Error(getParseErrorMessage(errors));
|
|
568
696
|
let normalizedResult = parse(rspack.experiments.swc.transformSync(code, {
|
|
569
697
|
filename: sourcePath,
|
|
@@ -578,7 +706,7 @@ let mightContainRouteChunkExportName = (source)=>routeChunkExportNames.some((exp
|
|
|
578
706
|
lang: 'js'
|
|
579
707
|
}), normalizedErrors = getParseErrors(normalizedResult);
|
|
580
708
|
if (normalizedErrors.length > 0) throw Error(getParseErrorMessage(normalizedErrors));
|
|
581
|
-
return normalizedResult
|
|
709
|
+
return getProgram(normalizedResult);
|
|
582
710
|
}, cachePromiseOnReject = (promise, invalidate)=>promise.catch((error)=>{
|
|
583
711
|
throw invalidate(), error;
|
|
584
712
|
}), isTypeOnlyExport = (node)=>'type' === node.exportKind || 'TSExportAssignment' === node.type || node.declaration?.declare === !0 || 'ExportDefaultDeclaration' === node.type && node.declaration?.type === 'TSInterfaceDeclaration', collectProgramExportNames = (program)=>{
|
|
@@ -628,22 +756,54 @@ let mightContainRouteChunkExportName = (source)=>routeChunkExportNames.some((exp
|
|
|
628
756
|
})(), ()=>{
|
|
629
757
|
exportInfoCache.get(cacheKey) === trackedExportInfo && exportInfoCache.delete(cacheKey);
|
|
630
758
|
}), setBoundedCacheEntry(exportInfoCache, cacheKey, trackedExportInfo, 2048), trackedExportInfo);
|
|
759
|
+
}, analyzeRouteModuleCode = (code, resourcePath)=>{
|
|
760
|
+
let program = parseProgram(code, resourcePath);
|
|
761
|
+
return {
|
|
762
|
+
code,
|
|
763
|
+
exports: collectProgramExportNames(program),
|
|
764
|
+
exportAllModules: collectExportAllModules(program)
|
|
765
|
+
};
|
|
631
766
|
}, getRouteModuleAnalysis = async (resourcePath)=>{
|
|
632
767
|
let trackedAnalysis, stats = await stat(resourcePath), cached = routeModuleAnalysisCache.get(resourcePath);
|
|
633
|
-
return cached?.mtimeMs === stats.mtimeMs && cached.size === stats.size ? cached.analysis : (trackedAnalysis = cachePromiseOnReject((async ()=>{
|
|
634
|
-
let source = await readFile(resourcePath, 'utf8'), program = parseProgram(source, resourcePath);
|
|
635
|
-
return {
|
|
636
|
-
code: source,
|
|
637
|
-
exports: collectProgramExportNames(program),
|
|
638
|
-
exportAllModules: collectExportAllModules(program)
|
|
639
|
-
};
|
|
640
|
-
})(), ()=>{
|
|
768
|
+
return cached?.mtimeMs === stats.mtimeMs && cached.size === stats.size ? cached.analysis : (trackedAnalysis = cachePromiseOnReject((async ()=>analyzeRouteModuleCode(await readFile(resourcePath, 'utf8'), resourcePath))(), ()=>{
|
|
641
769
|
routeModuleAnalysisCache.get(resourcePath)?.analysis === trackedAnalysis && routeModuleAnalysisCache.delete(resourcePath);
|
|
642
770
|
}), setBoundedCacheEntry(routeModuleAnalysisCache, resourcePath, {
|
|
643
771
|
mtimeMs: stats.mtimeMs,
|
|
644
772
|
size: stats.size,
|
|
645
773
|
analysis: trackedAnalysis
|
|
646
774
|
}, 2048), trackedAnalysis);
|
|
775
|
+
}, yuku_parse = (code, options = {})=>{
|
|
776
|
+
let result = parse(code, {
|
|
777
|
+
...options,
|
|
778
|
+
sourceType: options.sourceType ?? 'module',
|
|
779
|
+
lang: options.lang ?? 'tsx',
|
|
780
|
+
attachComments: options.attachComments ?? !0
|
|
781
|
+
}), errors = result.diagnostics.filter((diagnostic)=>'error' === diagnostic.severity);
|
|
782
|
+
if (errors.length > 0) throw Error(errors.map((error)=>error.message).join('\n'));
|
|
783
|
+
return result;
|
|
784
|
+
}, generate = (ast, options = {})=>{
|
|
785
|
+
let result = 'program' in ast ? ast : {
|
|
786
|
+
program: ast,
|
|
787
|
+
lineStarts: []
|
|
788
|
+
}, generated = print(result.program, {
|
|
789
|
+
comments: !0,
|
|
790
|
+
sourceMaps: options.sourceMaps ? {
|
|
791
|
+
lineStarts: result.lineStarts,
|
|
792
|
+
file: options.filename,
|
|
793
|
+
sourceFileName: options.sourceFileName
|
|
794
|
+
} : void 0
|
|
795
|
+
});
|
|
796
|
+
if (generated.errors.length > 0) throw Error(generated.errors.map((error)=>error.message).join('\n'));
|
|
797
|
+
let map = generated.map ? {
|
|
798
|
+
...generated.map,
|
|
799
|
+
file: generated.map.file ?? options.filename ?? '',
|
|
800
|
+
sourceRoot: generated.map.sourceRoot ?? void 0,
|
|
801
|
+
sourcesContent: generated.map.sourcesContent?.map((source)=>source ?? '') ?? void 0
|
|
802
|
+
} : null;
|
|
803
|
+
return {
|
|
804
|
+
code: generated.code,
|
|
805
|
+
map
|
|
806
|
+
};
|
|
647
807
|
}, tryStat = (path)=>statSync(path, {
|
|
648
808
|
throwIfNoEntry: !1
|
|
649
809
|
}) ?? null, PACKAGE_IMPORT_CONDITIONS = new Set([
|
|
@@ -764,56 +924,72 @@ let mightContainRouteChunkExportName = (source)=>routeChunkExportNames.some((exp
|
|
|
764
924
|
'hasClientMiddleware',
|
|
765
925
|
'hasErrorBoundary',
|
|
766
926
|
'hasLoader'
|
|
767
|
-
],
|
|
768
|
-
|
|
769
|
-
hasClientAction: CLIENT_EXPORTS.clientAction,
|
|
770
|
-
hasClientLoader: CLIENT_EXPORTS.clientLoader,
|
|
771
|
-
hasClientMiddleware: CLIENT_EXPORTS.clientMiddleware,
|
|
772
|
-
hasErrorBoundary: CLIENT_EXPORTS.ErrorBoundary,
|
|
773
|
-
hasLoader: SERVER_EXPORTS.loader
|
|
774
|
-
}, createRouteClientEntryArtifact = async ({ code, resourcePath, environmentName, isBuild, routeChunkCache, routeChunkConfig, routeId, devHmr })=>{
|
|
775
|
-
let isServer = 'node' === environmentName, routeChunkInfo = !isServer && isBuild && shouldAnalyzeRouteChunks(routeChunkConfig, resourcePath, code) ? await detectRouteChunksIfEnabled(routeChunkCache, routeChunkConfig, resourcePath, code) : null;
|
|
927
|
+
], createRouteClientEntryArtifact = async ({ code, resourcePath, environmentName, isBuild, routeChunkCache, routeChunkConfig, routeId, devHmr })=>{
|
|
928
|
+
let isServer = 'node' === environmentName, routeChunkInfo = !isServer && isBuild && shouldAnalyzeRouteChunks(routeChunkConfig, resourcePath, code) ? await detectRouteChunksIfEnabled(routeChunkCache, routeChunkConfig, resourcePath, code) : null, exportNames = routeChunkInfo?.exportNames ?? await getExportNames(code, resourcePath);
|
|
776
929
|
return {
|
|
777
|
-
code: (({ exportNames, chunkedExports, isServer, resourcePath, routeId, devHmr })=>{
|
|
778
|
-
let exports,
|
|
779
|
-
|
|
780
|
-
|
|
930
|
+
code: (({ exportNames, chunkedExports, sharedChunkedExports = [], isServer, resourcePath, routeId, devHmr })=>{
|
|
931
|
+
let exports, chunkedExportSet = chunkedExports.length > 0 || sharedChunkedExports.length > 0 ? new Set([
|
|
932
|
+
...chunkedExports,
|
|
933
|
+
...sharedChunkedExports
|
|
934
|
+
]) : void 0, routeRequestPath = `./${basename(resourcePath)}`, target = isServer ? routeRequestPath : chunkedExports.length > 0 ? getRouteChunkModuleId(routeRequestPath, 'main') : `${routeRequestPath}?react-router-route`, reexports = exportNames.filter((exportName)=>(({ chunkedExportSet, exportName, isServer })=>!chunkedExportSet?.has(exportName) && (isServer ? CLIENT_ROUTE_EXPORTS_SET.has(exportName) || SERVER_ONLY_ROUTE_EXPORTS_SET.has(exportName) : CLIENT_ROUTE_EXPORTS_SET.has(exportName)))({
|
|
935
|
+
chunkedExportSet,
|
|
936
|
+
exportName,
|
|
937
|
+
isServer
|
|
938
|
+
})).sort(), reexportCode = [
|
|
939
|
+
reexports.length > 0 ? `export { ${reexports.join(', ')} } from ${JSON.stringify(target)};` : null,
|
|
940
|
+
...sharedChunkedExports.map((exportName)=>`export { ${exportName} } from ${JSON.stringify(getRouteChunkModuleId(routeRequestPath, exportName))};`)
|
|
941
|
+
].filter(Boolean).join('\n');
|
|
942
|
+
return !devHmr || isServer || void 0 === routeId ? reexportCode : reexportCode + (({ routeId, target, metadata })=>{
|
|
943
|
+
let targetJson = JSON.stringify(target);
|
|
781
944
|
return `
|
|
782
|
-
import * as
|
|
945
|
+
import * as __reactRouterRouteModule from ${targetJson};
|
|
783
946
|
import {
|
|
784
|
-
registerReactRouterRouteExports as
|
|
785
|
-
scheduleReactRouterRouteUpdate as
|
|
947
|
+
registerReactRouterRouteExports as __reactRouterRegisterRouteExports,
|
|
948
|
+
scheduleReactRouterRouteUpdate as __reactRouterScheduleRouteUpdate,
|
|
786
949
|
} from "virtual/react-router/hmr-runtime";
|
|
787
950
|
|
|
788
|
-
const
|
|
789
|
-
const
|
|
790
|
-
const
|
|
791
|
-
const __rru0 = () => {
|
|
792
|
-
__rrr(__rrid, __rrm);
|
|
793
|
-
__rru(__rrid, __rrf, __rrg);
|
|
794
|
-
};
|
|
951
|
+
const __reactRouterRouteId = ${JSON.stringify(routeId)};
|
|
952
|
+
const __reactRouterRouteMetadata = ${JSON.stringify(metadata)};
|
|
953
|
+
const __reactRouterGetRouteModule = () => __reactRouterRouteModule;
|
|
795
954
|
|
|
796
|
-
|
|
955
|
+
__reactRouterRegisterRouteExports(
|
|
956
|
+
__reactRouterRouteId,
|
|
957
|
+
__reactRouterRouteModule
|
|
958
|
+
);
|
|
797
959
|
|
|
798
960
|
if (import.meta.webpackHot) {
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
if (
|
|
961
|
+
import.meta.webpackHot.accept();
|
|
962
|
+
import.meta.webpackHot.dispose(data => {
|
|
963
|
+
data.__reactRouterRouteShim = true;
|
|
964
|
+
});
|
|
965
|
+
if (
|
|
966
|
+
import.meta.webpackHot.data &&
|
|
967
|
+
import.meta.webpackHot.data.__reactRouterRouteShim
|
|
968
|
+
) {
|
|
969
|
+
__reactRouterScheduleRouteUpdate(
|
|
970
|
+
__reactRouterRouteId,
|
|
971
|
+
__reactRouterRouteMetadata,
|
|
972
|
+
__reactRouterGetRouteModule
|
|
973
|
+
);
|
|
974
|
+
}
|
|
804
975
|
}
|
|
805
976
|
`;
|
|
806
977
|
})({
|
|
807
978
|
routeId,
|
|
808
979
|
target,
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
exports.has(
|
|
812
|
-
|
|
980
|
+
metadata: {
|
|
981
|
+
hasAction: (exports = new Set(exportNames)).has(SERVER_EXPORTS.action),
|
|
982
|
+
hasClientAction: exports.has(CLIENT_EXPORTS.clientAction),
|
|
983
|
+
hasClientLoader: exports.has(CLIENT_EXPORTS.clientLoader),
|
|
984
|
+
hasClientMiddleware: exports.has(CLIENT_EXPORTS.clientMiddleware),
|
|
985
|
+
hasErrorBoundary: exports.has(CLIENT_EXPORTS.ErrorBoundary),
|
|
986
|
+
hasLoader: exports.has(SERVER_EXPORTS.loader)
|
|
987
|
+
}
|
|
813
988
|
});
|
|
814
989
|
})({
|
|
815
|
-
exportNames
|
|
990
|
+
exportNames,
|
|
816
991
|
chunkedExports: routeChunkInfo?.chunkedExports ?? [],
|
|
992
|
+
sharedChunkedExports: routeChunkInfo?.sharedChunkedExports ?? [],
|
|
817
993
|
isServer,
|
|
818
994
|
resourcePath,
|
|
819
995
|
routeId,
|
|
@@ -826,12 +1002,7 @@ if (import.meta.webpackHot) {
|
|
|
826
1002
|
code: 'export {};',
|
|
827
1003
|
map: null
|
|
828
1004
|
};
|
|
829
|
-
let chunkName = (
|
|
830
|
-
let queryIndex = id.indexOf(routeChunkQueryStringPrefix);
|
|
831
|
-
if (-1 === queryIndex) return null;
|
|
832
|
-
let chunkNameStart = queryIndex + routeChunkQueryStringPrefix.length, chunkNameEnd = id.indexOf('&', chunkNameStart), chunkName = id.slice(chunkNameStart, -1 === chunkNameEnd ? void 0 : chunkNameEnd);
|
|
833
|
-
return 'main' === chunkName || routeChunkExportNames.includes(chunkName) ? chunkName : null;
|
|
834
|
-
})(resource);
|
|
1005
|
+
let chunkName = getRouteChunkNameFromModuleId(resource);
|
|
835
1006
|
if (!chunkName) throw Error(`Invalid route chunk name in "${resource}"`);
|
|
836
1007
|
if ('main' !== chunkName && !code.includes(chunkName)) return {
|
|
837
1008
|
code: 'export {};',
|
|
@@ -910,131 +1081,27 @@ if (import.meta.webpackHot) {
|
|
|
910
1081
|
return !1;
|
|
911
1082
|
}
|
|
912
1083
|
})(declarator.init) && names.add(declarator.id.name);
|
|
1084
|
+
}, validateSpaModeRouteExports = ({ exportNames, resourcePath, rootRoutePath })=>{
|
|
1085
|
+
let isRootRoute = resourcePath === rootRoutePath, relativePath = relative(process.cwd(), resourcePath), invalidServerOnly = exportNames.filter((exp)=>(!isRootRoute || 'loader' !== exp) && SERVER_ONLY_ROUTE_EXPORTS_SET.has(exp));
|
|
1086
|
+
if (invalidServerOnly.length > 0) {
|
|
1087
|
+
let list = invalidServerOnly.map((exp)=>`\`${exp}\``).join(', ');
|
|
1088
|
+
throw Error(`SPA Mode: ${invalidServerOnly.length} invalid route export(s) in \`${relativePath}\`: ${list}. See https://reactrouter.com/how-to/spa for more information.`);
|
|
1089
|
+
}
|
|
1090
|
+
if (!isRootRoute && exportNames.includes('HydrateFallback')) throw Error(`SPA Mode: Invalid \`HydrateFallback\` export found in \`${relativePath}\`. \`HydrateFallback\` is only permitted on the root route in SPA Mode. See https://reactrouter.com/how-to/spa for more information.`);
|
|
913
1091
|
}, transformRouteModule = async (task)=>{
|
|
914
1092
|
let code = task.code, defaultExportMatch = code.match(/\n\s{0,}([\w\d_]+)\sas default,?/);
|
|
915
1093
|
defaultExportMatch && 'number' == typeof defaultExportMatch.index && (code = code.slice(0, defaultExportMatch.index) + code.slice(defaultExportMatch.index + defaultExportMatch[0].length) + `\nexport default ${defaultExportMatch[1]};`);
|
|
916
|
-
let ast = (
|
|
917
|
-
let result = parse(code, {
|
|
918
|
-
...options,
|
|
919
|
-
sourceType: options.sourceType ?? 'module',
|
|
920
|
-
lang: options.lang ?? 'tsx',
|
|
921
|
-
attachComments: options.attachComments ?? !0
|
|
922
|
-
}), errors = result.diagnostics.filter((diagnostic)=>'error' === diagnostic.severity);
|
|
923
|
-
if (errors.length > 0) throw Error(errors.map((error)=>error.message).join('\n'));
|
|
924
|
-
return result;
|
|
925
|
-
})(code, {
|
|
1094
|
+
let ast = yuku_parse(code, {
|
|
926
1095
|
sourceType: 'module'
|
|
927
1096
|
});
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
if (!isRootRoute && resolvedExportNames.includes('HydrateFallback')) throw Error(`SPA Mode: Invalid \`HydrateFallback\` export found in \`${relativePath}\`. \`HydrateFallback\` is only permitted on the root route in SPA Mode. See https://reactrouter.com/how-to/spa for more information.`);
|
|
935
|
-
}
|
|
936
|
-
let removedServerOnlyExports = 'web' === task.environmentName && ((ast, exportsToRemove, exportsToRemoveSet = new Set(exportsToRemove))=>{
|
|
937
|
-
let currentlyLive, removedReferenceCache, isRemovableDeadDeclaration, program = ast.program ?? ast;
|
|
938
|
-
if (!((program, exportsToRemove)=>{
|
|
939
|
-
let removesNamedExports = [
|
|
940
|
-
...exportsToRemove
|
|
941
|
-
].some((name)=>'default' !== name);
|
|
942
|
-
for (let statement of program.body ?? []){
|
|
943
|
-
if ('ExportAllDeclaration' === statement.type) {
|
|
944
|
-
let exportedName = statement.exported ? getExportedName({
|
|
945
|
-
exported: statement.exported
|
|
946
|
-
}) : null;
|
|
947
|
-
if (exportedName && exportsToRemove.has(exportedName) || !exportedName && removesNamedExports) return !0;
|
|
948
|
-
continue;
|
|
949
|
-
}
|
|
950
|
-
if ('ExportDefaultDeclaration' === statement.type) {
|
|
951
|
-
if (exportsToRemove.has('default')) return !0;
|
|
952
|
-
continue;
|
|
953
|
-
}
|
|
954
|
-
if ('ExportNamedDeclaration' !== statement.type) continue;
|
|
955
|
-
for (let specifier of statement.specifiers ?? []){
|
|
956
|
-
if ('ExportSpecifier' !== specifier.type) continue;
|
|
957
|
-
let exportedName = getExportedName(specifier);
|
|
958
|
-
if (exportedName && exportsToRemove.has(exportedName)) return !0;
|
|
959
|
-
}
|
|
960
|
-
let declaration = statement.declaration;
|
|
961
|
-
if (declaration?.type === 'VariableDeclaration') {
|
|
962
|
-
for (let declarator of declaration.declarations ?? [])for (let name of getPatternIdentifierNames(declarator.id))if (exportsToRemove.has(name)) return !0;
|
|
963
|
-
continue;
|
|
964
|
-
}
|
|
965
|
-
if ((declaration?.type === 'FunctionDeclaration' || declaration?.type === 'ClassDeclaration') && declaration.id?.name && exportsToRemove.has(declaration.id.name)) return !0;
|
|
966
|
-
}
|
|
967
|
-
return !1;
|
|
968
|
-
})(program, exportsToRemoveSet)) return !1;
|
|
969
|
-
let declarationGraph = ((program)=>{
|
|
970
|
-
let declarationsByNode = new Map(), declarationsByName = new Map(), registerDeclaration = (node, declarationNode, declaredNames)=>{
|
|
971
|
-
let declaration = {
|
|
972
|
-
referencedNames: collectReferencedNames(declarationNode)
|
|
973
|
-
};
|
|
974
|
-
for (let name of (declarationsByNode.set(node, declaration), declaredNames)){
|
|
975
|
-
let namedDeclarations = declarationsByName.get(name) ?? new Set();
|
|
976
|
-
namedDeclarations.add(declaration), declarationsByName.set(name, namedDeclarations);
|
|
977
|
-
}
|
|
978
|
-
};
|
|
979
|
-
for (let statement of [
|
|
980
|
-
...program.body ?? []
|
|
981
|
-
]){
|
|
982
|
-
if ('VariableDeclaration' === statement.type) {
|
|
983
|
-
for (let declarator of statement.declarations ?? [])registerDeclaration(declarator, declarator, getPatternIdentifierNames(declarator.id));
|
|
984
|
-
continue;
|
|
985
|
-
}
|
|
986
|
-
('FunctionDeclaration' === statement.type || 'ClassDeclaration' === statement.type) && registerDeclaration(statement, statement, getDeclaredNames(statement));
|
|
987
|
-
}
|
|
988
|
-
return {
|
|
989
|
-
declarationsByNode,
|
|
990
|
-
declarationsByName
|
|
991
|
-
};
|
|
992
|
-
})(program), previouslyLive = collectLiveTopLevelDeclarations(program, declarationGraph), exportsChanged = !1, removedExportLocalNames = new Set(), removedExportReferencedNames = new Set(), removesNamedExports = exportsToRemove.some((name)=>'default' !== name), trackRemovedExportReferences = (node)=>{
|
|
993
|
-
if (!node) return;
|
|
994
|
-
let declaration = declarationGraph.declarationsByNode.get(node);
|
|
995
|
-
for (let name of declaration?.referencedNames ?? collectReferencedNames(node))removedExportReferencedNames.add(name);
|
|
996
|
-
};
|
|
997
|
-
for (let statement of [
|
|
998
|
-
...program.body
|
|
999
|
-
]){
|
|
1000
|
-
if ('ExportAllDeclaration' === statement.type) {
|
|
1001
|
-
let exportedName = statement.exported ? getExportedName({
|
|
1002
|
-
exported: statement.exported
|
|
1003
|
-
}) : null;
|
|
1004
|
-
if (exportedName && exportsToRemoveSet.has(exportedName) && (exportsChanged = !0, removeFromArray(program.body, statement)), !exportedName && removesNamedExports) throw Error('Cannot remove named exports from `export *`; use explicit named re-exports.');
|
|
1005
|
-
continue;
|
|
1006
|
-
}
|
|
1007
|
-
if ('ExportNamedDeclaration' === statement.type) {
|
|
1008
|
-
statement.specifiers?.length && (statement.specifiers = statement.specifiers.filter((specifier)=>{
|
|
1009
|
-
if ('ExportSpecifier' !== specifier.type) return !0;
|
|
1010
|
-
let exportedName = getExportedName(specifier);
|
|
1011
|
-
return !(exportedName && exportsToRemoveSet.has(exportedName)) || (exportsChanged = !0, specifier.local?.name && (removedExportLocalNames.add(specifier.local.name), removedExportReferencedNames.add(specifier.local.name)), !1);
|
|
1012
|
-
}), 0 !== statement.specifiers.length || statement.declaration || removeFromArray(program.body, statement));
|
|
1013
|
-
let declaration = statement.declaration;
|
|
1014
|
-
declaration?.type === 'VariableDeclaration' && (declaration.declarations = (declaration.declarations ?? []).filter((declarator)=>{
|
|
1015
|
-
let id = declarator.id;
|
|
1016
|
-
return id?.type === 'Identifier' ? !(id.name && exportsToRemoveSet.has(id.name)) || (exportsChanged = !0, removedExportLocalNames.add(id.name), removedExportReferencedNames.add(id.name), trackRemovedExportReferences(declarator), !1) : (id && validateBindingTarget(id, new Set(exportsToRemove)), !0);
|
|
1017
|
-
}), 0 === declaration.declarations.length && removeFromArray(program.body, statement)), (declaration?.type === 'FunctionDeclaration' || declaration?.type === 'ClassDeclaration') && declaration.id?.name && exportsToRemoveSet.has(declaration.id.name) && (exportsChanged = !0, removedExportLocalNames.add(declaration.id.name), removedExportReferencedNames.add(declaration.id.name), trackRemovedExportReferences(statement), removeFromArray(program.body, statement));
|
|
1018
|
-
}
|
|
1019
|
-
if ('ExportDefaultDeclaration' === statement.type && exportsToRemoveSet.has('default')) {
|
|
1020
|
-
exportsChanged = !0;
|
|
1021
|
-
let declaration = statement.declaration;
|
|
1022
|
-
declaration?.type === 'Identifier' && declaration.name ? (removedExportLocalNames.add(declaration.name), removedExportReferencedNames.add(declaration.name)) : declaration?.id?.name && (removedExportLocalNames.add(declaration.id.name), removedExportReferencedNames.add(declaration.id.name)), trackRemovedExportReferences(statement), removeFromArray(program.body, statement);
|
|
1023
|
-
}
|
|
1024
|
-
}
|
|
1025
|
-
for (let statement of [
|
|
1026
|
-
...program.body
|
|
1027
|
-
]){
|
|
1028
|
-
let expression = 'ExpressionStatement' === statement.type ? statement.expression : null, left = expression?.type === 'AssignmentExpression' ? expression.left : null;
|
|
1029
|
-
left?.type === 'MemberExpression' && left.object?.type === 'Identifier' && left.object.name && removedExportLocalNames.has(left.object.name) && removeFromArray(program.body, statement);
|
|
1030
|
-
}
|
|
1031
|
-
return exportsChanged && (currentlyLive = collectLiveTopLevelDeclarations(program, declarationGraph), removedReferenceCache = new Map(), isRemovableDeadDeclaration = (node)=>{
|
|
1032
|
-
let declaration = declarationGraph.declarationsByNode.get(node);
|
|
1033
|
-
return !(!declaration || currentlyLive.has(declaration)) && (previouslyLive.has(declaration) || declarationReferencesName(declaration, removedExportReferencedNames, declarationGraph, removedReferenceCache));
|
|
1034
|
-
}, program.body = program.body.filter((statement)=>'VariableDeclaration' === statement.type ? (statement.declarations = (statement.declarations ?? []).filter((declarator)=>!isRemovableDeadDeclaration(declarator)), statement.declarations.length > 0) : !isRemovableDeadDeclaration(statement))), exportsChanged;
|
|
1035
|
-
})(ast, SERVER_ONLY_ROUTE_EXPORTS, SERVER_ONLY_ROUTE_EXPORTS_SET);
|
|
1097
|
+
'web' === task.environmentName && !task.ssr && task.isSpaMode && validateSpaModeRouteExports({
|
|
1098
|
+
exportNames: collectProgramExportNames(getProgram(ast)),
|
|
1099
|
+
resourcePath: task.resourcePath,
|
|
1100
|
+
rootRoutePath: task.rootRoutePath
|
|
1101
|
+
});
|
|
1102
|
+
let removedServerOnlyExports = 'web' === task.environmentName && removeExports(ast, SERVER_ONLY_ROUTE_EXPORTS, SERVER_ONLY_ROUTE_EXPORTS_SET);
|
|
1036
1103
|
((ast)=>{
|
|
1037
|
-
let program = ast
|
|
1104
|
+
let program = getProgram(ast), usedNames = new Set(), hocs = [], componentWrapperDeclarations = [];
|
|
1038
1105
|
function getUid(name) {
|
|
1039
1106
|
let uid = `_${name}`, index = 2;
|
|
1040
1107
|
for(; usedNames.has(uid) || hasTopLevelBindingName(program, uid);)uid = `_${name}${index++}`;
|
|
@@ -1043,7 +1110,7 @@ if (import.meta.webpackHot) {
|
|
|
1043
1110
|
function getHocUid(hocName) {
|
|
1044
1111
|
let uid = getUid(hocName);
|
|
1045
1112
|
return hocs.push([
|
|
1046
|
-
hocName
|
|
1113
|
+
`UNSAFE_${hocName}`,
|
|
1047
1114
|
uid
|
|
1048
1115
|
]), identifier(uid);
|
|
1049
1116
|
}
|
|
@@ -1063,7 +1130,7 @@ if (import.meta.webpackHot) {
|
|
|
1063
1130
|
continue;
|
|
1064
1131
|
}
|
|
1065
1132
|
statement.declaration = callExpression(uid, [
|
|
1066
|
-
'FunctionDeclaration' === declaration.type ?
|
|
1133
|
+
'FunctionDeclaration' === declaration.type ? toExpression(declaration, 'FunctionExpression') : 'ClassDeclaration' === declaration.type ? toExpression(declaration, 'ClassExpression') : declaration
|
|
1067
1134
|
]);
|
|
1068
1135
|
continue;
|
|
1069
1136
|
}
|
|
@@ -1083,7 +1150,7 @@ if (import.meta.webpackHot) {
|
|
|
1083
1150
|
statement.declaration = function(name, declaration) {
|
|
1084
1151
|
let uid = getHocUid(`with${name}Props`);
|
|
1085
1152
|
return variableDeclaration(name, callExpression(uid, [
|
|
1086
|
-
'FunctionDeclaration' === declaration.type ?
|
|
1153
|
+
'FunctionDeclaration' === declaration.type ? toExpression(declaration, 'FunctionExpression') : 'ClassDeclaration' === declaration.type ? toExpression(declaration, 'ClassExpression') : declaration
|
|
1087
1154
|
]));
|
|
1088
1155
|
}(declaration.id.name, declaration);
|
|
1089
1156
|
continue;
|
|
@@ -1131,37 +1198,9 @@ if (import.meta.webpackHot) {
|
|
|
1131
1198
|
})(program), 0, importDeclaration(hocs.map(([name, local])=>({
|
|
1132
1199
|
imported: name,
|
|
1133
1200
|
local
|
|
1134
|
-
})), '
|
|
1135
|
-
})(ast), removedServerOnlyExports && (
|
|
1136
|
-
|
|
1137
|
-
for (let statement of [
|
|
1138
|
-
...program.body
|
|
1139
|
-
])'ImportDeclaration' === statement.type && 0 !== (statement.specifiers ?? []).length && (statement.specifiers = (statement.specifiers ?? []).filter((specifier)=>'type' !== specifier.importKind && (!specifier.local?.name || referenced.has(specifier.local.name))), 0 === statement.specifiers.length && removeFromArray(program.body, statement));
|
|
1140
|
-
})(ast);
|
|
1141
|
-
let result = ((ast, options = {})=>{
|
|
1142
|
-
let result = 'program' in ast ? ast : {
|
|
1143
|
-
program: ast,
|
|
1144
|
-
lineStarts: []
|
|
1145
|
-
}, generated = print(result.program, {
|
|
1146
|
-
comments: !0,
|
|
1147
|
-
sourceMaps: options.sourceMaps ? {
|
|
1148
|
-
lineStarts: result.lineStarts,
|
|
1149
|
-
file: options.filename,
|
|
1150
|
-
sourceFileName: options.sourceFileName
|
|
1151
|
-
} : void 0
|
|
1152
|
-
});
|
|
1153
|
-
if (generated.errors.length > 0) throw Error(generated.errors.map((error)=>error.message).join('\n'));
|
|
1154
|
-
let map = generated.map ? {
|
|
1155
|
-
...generated.map,
|
|
1156
|
-
file: generated.map.file ?? options.filename ?? '',
|
|
1157
|
-
sourceRoot: generated.map.sourceRoot ?? void 0,
|
|
1158
|
-
sourcesContent: generated.map.sourcesContent?.map((source)=>source ?? '') ?? void 0
|
|
1159
|
-
} : null;
|
|
1160
|
-
return {
|
|
1161
|
-
code: generated.code,
|
|
1162
|
-
map
|
|
1163
|
-
};
|
|
1164
|
-
})(ast, {
|
|
1201
|
+
})), 'react-router'));
|
|
1202
|
+
})(ast), removedServerOnlyExports && removeUnusedImports(ast);
|
|
1203
|
+
let result = generate(ast, {
|
|
1165
1204
|
sourceMaps: task.sourceMaps,
|
|
1166
1205
|
filename: task.resource,
|
|
1167
1206
|
sourceFileName: task.resourcePath
|
|
@@ -1184,7 +1223,7 @@ if (import.meta.webpackHot) {
|
|
|
1184
1223
|
return [
|
|
1185
1224
|
...declared
|
|
1186
1225
|
].filter((name)=>!registered.has(name));
|
|
1187
|
-
})(ast
|
|
1226
|
+
})(getProgram(ast));
|
|
1188
1227
|
unregisteredComponents.length > 0 && (result.code += (registrations = unregisteredComponents.map((name)=>` if (typeof ${name} === 'function' || (typeof ${name} === 'object' && ${name} !== null)) $RefreshReg$(${name}, ${JSON.stringify(name)});`).join('\n'), `\nif (typeof $RefreshReg$ === 'function') {\n${registrations}\n}\n`));
|
|
1189
1228
|
}
|
|
1190
1229
|
return result;
|
|
@@ -1309,4 +1348,4 @@ if (import.meta.webpackHot) {
|
|
|
1309
1348
|
}
|
|
1310
1349
|
};
|
|
1311
1350
|
};
|
|
1312
|
-
export { BUILD_CLIENT_ROUTE_QUERY_STRING, CLIENT_EXPORTS, HMR_PATCHABLE_ROUTE_FLAGS, JS_EXTENSIONS, PLUGIN_NAME, SERVER_EXPORTS, buildManifestChunkValidity, combineURLs, createBundlerRouteExportResolver, createEmptyRouteChunkByExportName, createReactRouterPerformanceProfiler, createRouteId, detectRouteChunksIfEnabled, executeRouteTransformTask, findEntryFile, generateWithProps, getRouteChunkEntryName, getRouteChunkModuleId, getRouteModuleAnalysis, normalizeAssetPrefix, roundMs, routeChunkExportNames, validateRouteChunks };
|
|
1351
|
+
export { BUILD_CLIENT_ROUTE_QUERY_STRING, CLIENT_EXPORTS, CLIENT_NON_COMPONENT_EXPORTS, DEFAULT_JS_DIST_PATH, HMR_PATCHABLE_ROUTE_FLAGS, JS_EXTENSIONS, PLUGIN_NAME, SERVER_EXPORTS, SERVER_ONLY_ROUTE_EXPORTS, SPA_FALLBACK_HTML_FILE, analyzeRouteModuleCode, buildManifestChunkValidity, collectReferencedNames, combineURLs, createBundlerRouteExportResolver, createEmptyRouteChunkByExportName, createReactRouterPerformanceProfiler, createRouteId, detectRouteChunks, detectRouteChunksIfEnabled, escapeHtml, executeRouteTransformTask, findEntryFile, generate, generateWithProps, getExportNames, getExportedName, getPackageVersion, getPatternIdentifierNames, getProgram, getRouteChunkEntryName, getRouteChunkModuleId, getRouteChunkNameFromModuleId, getRouteModuleAnalysis, normalizeAssetPrefix, parseVersionMajorMinor, removeExports, removeUnusedImports, resolveAppPackagePath, resolveEffectiveAssetPrefix, roundMs, routeChunkExportNames, validateRouteChunks, validateSpaModeRouteExports, yuku_parse };
|