@react-router/dev 0.0.0-experimental-df6bc686c → 0.0.0-experimental-759a11a62
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/dist/cli/index.js +244 -234
- package/dist/config/defaults/entry.server.node.tsx +1 -1
- package/dist/config.d.ts +1 -5
- package/dist/config.js +1 -1
- package/dist/routes.js +1 -1
- package/dist/static/refresh-utils.cjs +0 -1
- package/dist/vite/cloudflare.js +1 -1
- package/dist/vite.js +177 -1074
- package/package.json +6 -14
- package/module-sync-enabled/false.cjs +0 -1
- package/module-sync-enabled/index.d.mts +0 -2
- package/module-sync-enabled/index.mjs +0 -4
- package/module-sync-enabled/true.mjs +0 -2
package/dist/vite.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @react-router/dev v0.0.0-experimental-
|
|
2
|
+
* @react-router/dev v0.0.0-experimental-759a11a62
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -57,7 +57,8 @@ var import_picocolors3 = __toESM(require("picocolors"));
|
|
|
57
57
|
|
|
58
58
|
// typegen/index.ts
|
|
59
59
|
var import_node_fs2 = __toESM(require("fs"));
|
|
60
|
-
var
|
|
60
|
+
var import_dedent2 = __toESM(require("dedent"));
|
|
61
|
+
var Path3 = __toESM(require("pathe"));
|
|
61
62
|
var import_picocolors2 = __toESM(require("picocolors"));
|
|
62
63
|
|
|
63
64
|
// config/config.ts
|
|
@@ -371,7 +372,6 @@ async function resolveConfig({
|
|
|
371
372
|
basename: basename2,
|
|
372
373
|
buildDirectory: userBuildDirectory,
|
|
373
374
|
buildEnd,
|
|
374
|
-
future: userFuture,
|
|
375
375
|
prerender,
|
|
376
376
|
serverBuildFile,
|
|
377
377
|
serverBundles,
|
|
@@ -444,8 +444,7 @@ async function resolveConfig({
|
|
|
444
444
|
);
|
|
445
445
|
}
|
|
446
446
|
let future = {
|
|
447
|
-
unstable_optimizeDeps: reactRouterUserConfig.future?.unstable_optimizeDeps ?? false
|
|
448
|
-
unstable_splitRouteModules: userFuture?.unstable_splitRouteModules ?? false
|
|
447
|
+
unstable_optimizeDeps: reactRouterUserConfig.future?.unstable_optimizeDeps ?? false
|
|
449
448
|
};
|
|
450
449
|
let reactRouterConfig = deepFreeze({
|
|
451
450
|
appDirectory,
|
|
@@ -626,125 +625,54 @@ function findEntry(dir, basename2, options) {
|
|
|
626
625
|
|
|
627
626
|
// typegen/generate.ts
|
|
628
627
|
var import_dedent = __toESM(require("dedent"));
|
|
629
|
-
|
|
630
|
-
var Pathe2 = __toESM(require("pathe/utils"));
|
|
631
|
-
|
|
632
|
-
// typegen/paths.ts
|
|
633
|
-
var Path2 = __toESM(require("pathe"));
|
|
634
|
-
var Pathe = __toESM(require("pathe/utils"));
|
|
635
|
-
function getTypesDir(ctx) {
|
|
636
|
-
return Path2.join(ctx.rootDirectory, ".react-router/types");
|
|
637
|
-
}
|
|
638
|
-
function getTypesPath(ctx, route) {
|
|
639
|
-
return Path2.join(
|
|
640
|
-
getTypesDir(ctx),
|
|
641
|
-
Path2.relative(ctx.rootDirectory, ctx.config.appDirectory),
|
|
642
|
-
Path2.dirname(route.file),
|
|
643
|
-
"+types/" + Pathe.filename(route.file) + ".ts"
|
|
644
|
-
);
|
|
645
|
-
}
|
|
646
|
-
|
|
647
|
-
// typegen/generate.ts
|
|
648
|
-
function generate(ctx, route) {
|
|
649
|
-
const lineage = getRouteLineage(ctx.config.routes, route);
|
|
650
|
-
const urlpath = lineage.map((route2) => route2.path).join("/");
|
|
651
|
-
const typesPath = getTypesPath(ctx, route);
|
|
652
|
-
const parents = lineage.slice(0, -1);
|
|
653
|
-
const parentTypeImports = parents.map((parent, i) => {
|
|
654
|
-
const rel = Path3.relative(
|
|
655
|
-
Path3.dirname(typesPath),
|
|
656
|
-
getTypesPath(ctx, parent)
|
|
657
|
-
);
|
|
658
|
-
const indent = i === 0 ? "" : " ".repeat(2);
|
|
659
|
-
let source = noExtension(rel);
|
|
660
|
-
if (!source.startsWith("../")) source = "./" + source;
|
|
661
|
-
return `${indent}import type { Info as Parent${i} } from "${source}.js"`;
|
|
662
|
-
}).join("\n");
|
|
628
|
+
function generate(route) {
|
|
663
629
|
return import_dedent.default`
|
|
664
630
|
// React Router generated types for route:
|
|
665
631
|
// ${route.file}
|
|
666
632
|
|
|
667
|
-
import type
|
|
668
|
-
|
|
669
|
-
${parentTypeImports}
|
|
633
|
+
import type { RouteExports, Routes } from "react-router/types";
|
|
670
634
|
|
|
671
|
-
type
|
|
635
|
+
type RouteId = "${route.id}"
|
|
636
|
+
export type Info = Routes[RouteId];
|
|
672
637
|
|
|
673
|
-
|
|
674
|
-
parents: [${parents.map((_, i) => `Parent${i}`).join(", ")}],
|
|
675
|
-
id: "${route.id}"
|
|
676
|
-
file: "${route.file}"
|
|
677
|
-
path: "${route.path}"
|
|
678
|
-
params: {${formatParamProperties(
|
|
679
|
-
urlpath
|
|
680
|
-
)}} & { [key: string]: string | undefined }
|
|
681
|
-
module: Module
|
|
682
|
-
loaderData: T.CreateLoaderData<Module>
|
|
683
|
-
actionData: T.CreateActionData<Module>
|
|
684
|
-
}
|
|
638
|
+
type Exports = RouteExports[RouteId];
|
|
685
639
|
|
|
686
640
|
export namespace Route {
|
|
687
|
-
export type LinkDescriptors =
|
|
688
|
-
export type LinksFunction = () => LinkDescriptors
|
|
641
|
+
export type LinkDescriptors = Exports["links"]["return"];
|
|
642
|
+
export type LinksFunction = () => LinkDescriptors;
|
|
689
643
|
|
|
690
|
-
export type MetaArgs =
|
|
691
|
-
export type MetaDescriptors =
|
|
692
|
-
export type MetaFunction = (args: MetaArgs) => MetaDescriptors
|
|
644
|
+
export type MetaArgs = Exports["meta"]["args"];
|
|
645
|
+
export type MetaDescriptors = Exports["meta"]["return"];
|
|
646
|
+
export type MetaFunction = (args: MetaArgs) => MetaDescriptors;
|
|
693
647
|
|
|
694
|
-
export type HeadersArgs =
|
|
695
|
-
export type HeadersFunction = (args: HeadersArgs) => Headers | HeadersInit
|
|
648
|
+
export type HeadersArgs = Exports["headers"]["args"];
|
|
649
|
+
export type HeadersFunction = (args: HeadersArgs) => Headers | HeadersInit;
|
|
696
650
|
|
|
697
|
-
export type LoaderArgs =
|
|
698
|
-
export type ClientLoaderArgs =
|
|
699
|
-
export type ActionArgs =
|
|
700
|
-
export type ClientActionArgs =
|
|
651
|
+
export type LoaderArgs = Exports["loader"]["args"];
|
|
652
|
+
export type ClientLoaderArgs = Exports["clientLoader"]["args"];
|
|
653
|
+
export type ActionArgs = Exports["action"]["args"];
|
|
654
|
+
export type ClientActionArgs = Exports["clientAction"]["args"];
|
|
701
655
|
|
|
702
|
-
export type HydrateFallbackProps =
|
|
703
|
-
export type ComponentProps =
|
|
704
|
-
export type ErrorBoundaryProps =
|
|
656
|
+
export type HydrateFallbackProps = Exports["HydrateFallback"]["args"];
|
|
657
|
+
export type ComponentProps = Exports["default"]["args"];
|
|
658
|
+
export type ErrorBoundaryProps = Exports["ErrorBoundary"]["args"];
|
|
705
659
|
}
|
|
706
660
|
`;
|
|
707
661
|
}
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
route = routes[route.parentId];
|
|
715
|
-
}
|
|
716
|
-
result.reverse();
|
|
717
|
-
return result;
|
|
718
|
-
}
|
|
719
|
-
function formatParamProperties(urlpath) {
|
|
720
|
-
const params = parseParams(urlpath);
|
|
721
|
-
const properties = Object.entries(params).map(([name, values]) => {
|
|
722
|
-
if (values.length === 1) {
|
|
723
|
-
const isOptional = values[0];
|
|
724
|
-
return isOptional ? `"${name}"?: string` : `"${name}": string`;
|
|
725
|
-
}
|
|
726
|
-
const items = values.map(
|
|
727
|
-
(isOptional) => isOptional ? "string | undefined" : "string"
|
|
728
|
-
);
|
|
729
|
-
return `"${name}": [${items.join(", ")}]`;
|
|
730
|
-
});
|
|
731
|
-
return properties.join("; ");
|
|
662
|
+
|
|
663
|
+
// typegen/paths.ts
|
|
664
|
+
var Path2 = __toESM(require("pathe"));
|
|
665
|
+
var Pathe = __toESM(require("pathe/utils"));
|
|
666
|
+
function getTypesDir(ctx) {
|
|
667
|
+
return Path2.join(ctx.rootDirectory, ".react-router/types");
|
|
732
668
|
}
|
|
733
|
-
function
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
const isOptional = match[2] !== void 0;
|
|
741
|
-
result[param] ??= [];
|
|
742
|
-
result[param].push(isOptional);
|
|
743
|
-
return;
|
|
744
|
-
});
|
|
745
|
-
const hasSplat = segments.at(-1) === "*";
|
|
746
|
-
if (hasSplat) result["*"] = [false];
|
|
747
|
-
return result;
|
|
669
|
+
function getTypesPath(ctx, route) {
|
|
670
|
+
return Path2.join(
|
|
671
|
+
getTypesDir(ctx),
|
|
672
|
+
Path2.relative(ctx.rootDirectory, ctx.config.appDirectory),
|
|
673
|
+
Path2.dirname(route.file),
|
|
674
|
+
"+types/" + Pathe.filename(route.file) + ".ts"
|
|
675
|
+
);
|
|
748
676
|
}
|
|
749
677
|
|
|
750
678
|
// typegen/index.ts
|
|
@@ -786,16 +714,97 @@ async function createContext2({
|
|
|
786
714
|
config
|
|
787
715
|
};
|
|
788
716
|
}
|
|
717
|
+
function asJS(path7) {
|
|
718
|
+
return path7.replace(/\.(js|ts)x?$/, ".js");
|
|
719
|
+
}
|
|
720
|
+
function formatRoute(ctx, { id, path: path7, file, parentId }) {
|
|
721
|
+
const modulePath = Path3.relative(
|
|
722
|
+
ctx.rootDirectory,
|
|
723
|
+
Path3.join(ctx.config.appDirectory, file)
|
|
724
|
+
);
|
|
725
|
+
return [
|
|
726
|
+
`"${id}": {`,
|
|
727
|
+
` parentId: ${JSON.stringify(parentId)}`,
|
|
728
|
+
` path: ${JSON.stringify(path7)}`,
|
|
729
|
+
` module: typeof import("${asJS(modulePath)}")`,
|
|
730
|
+
`}`
|
|
731
|
+
].map((line) => ` ${line}`).join("\n");
|
|
732
|
+
}
|
|
789
733
|
async function writeAll(ctx) {
|
|
734
|
+
let routes = Object.values(ctx.config.routes);
|
|
735
|
+
let pathsToParams = /* @__PURE__ */ new Map();
|
|
736
|
+
for (let route of routes) {
|
|
737
|
+
if (route.path === void 0) continue;
|
|
738
|
+
let lineage = getRouteLineage(ctx.config.routes, route);
|
|
739
|
+
let path7 = lineage.filter((route2) => route2.path !== void 0).map((route2) => route2.path).join("/");
|
|
740
|
+
if (path7 === "") path7 = "/";
|
|
741
|
+
pathsToParams.set(path7, parseParams(path7));
|
|
742
|
+
}
|
|
743
|
+
let formattedPaths = `type Paths = {`;
|
|
744
|
+
for (let [path7, params] of pathsToParams.entries()) {
|
|
745
|
+
let formattedParams = Object.entries(params).map(
|
|
746
|
+
([param, required]) => `"${param}"${required ? "" : "?"}: string`
|
|
747
|
+
);
|
|
748
|
+
let formattedEntry = `"${path7}": {${formattedParams.join(",")}},
|
|
749
|
+
`;
|
|
750
|
+
formattedPaths += formattedEntry;
|
|
751
|
+
}
|
|
752
|
+
formattedPaths += `}`;
|
|
790
753
|
const typegenDir = getTypesDir(ctx);
|
|
791
754
|
import_node_fs2.default.rmSync(typegenDir, { recursive: true, force: true });
|
|
755
|
+
const newTypes = Path3.join(typegenDir, "routes.ts");
|
|
756
|
+
import_node_fs2.default.mkdirSync(Path3.dirname(newTypes), { recursive: true });
|
|
757
|
+
import_node_fs2.default.writeFileSync(
|
|
758
|
+
newTypes,
|
|
759
|
+
formattedPaths + `
|
|
760
|
+
|
|
761
|
+
type Routes = {
|
|
762
|
+
${routes.map((route) => formatRoute(ctx, route)).join("\n")}
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
` + import_dedent2.default`
|
|
766
|
+
declare module "react-router/types" {
|
|
767
|
+
interface Register {
|
|
768
|
+
paths: Paths
|
|
769
|
+
routes: Routes
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
export {}
|
|
774
|
+
`
|
|
775
|
+
);
|
|
792
776
|
Object.values(ctx.config.routes).forEach((route) => {
|
|
793
777
|
const typesPath = getTypesPath(ctx, route);
|
|
794
|
-
const content = generate(
|
|
795
|
-
import_node_fs2.default.mkdirSync(
|
|
778
|
+
const content = generate(route);
|
|
779
|
+
import_node_fs2.default.mkdirSync(Path3.dirname(typesPath), { recursive: true });
|
|
796
780
|
import_node_fs2.default.writeFileSync(typesPath, content);
|
|
797
781
|
});
|
|
798
782
|
}
|
|
783
|
+
function getRouteLineage(routes, route) {
|
|
784
|
+
const result = [];
|
|
785
|
+
while (route) {
|
|
786
|
+
result.push(route);
|
|
787
|
+
if (!route.parentId) break;
|
|
788
|
+
route = routes[route.parentId];
|
|
789
|
+
}
|
|
790
|
+
result.reverse();
|
|
791
|
+
return result;
|
|
792
|
+
}
|
|
793
|
+
function parseParams(urlpath) {
|
|
794
|
+
const result = {};
|
|
795
|
+
let segments = urlpath.split("/");
|
|
796
|
+
segments.forEach((segment) => {
|
|
797
|
+
const match = segment.match(/^:([\w-]+)(\?)?/);
|
|
798
|
+
if (!match) return;
|
|
799
|
+
const param = match[1];
|
|
800
|
+
const isRequired = match[2] === void 0;
|
|
801
|
+
result[param] ||= isRequired;
|
|
802
|
+
return;
|
|
803
|
+
});
|
|
804
|
+
const hasSplat = segments.at(-1) === "*";
|
|
805
|
+
if (hasSplat) result["*"] = true;
|
|
806
|
+
return result;
|
|
807
|
+
}
|
|
799
808
|
|
|
800
809
|
// vite/babel.ts
|
|
801
810
|
var import_parser = require("@babel/parser");
|
|
@@ -1161,609 +1170,8 @@ function invalidDestructureError(name) {
|
|
|
1161
1170
|
return new Error(`Cannot remove destructured export "${name}"`);
|
|
1162
1171
|
}
|
|
1163
1172
|
|
|
1164
|
-
// vite/cache.ts
|
|
1165
|
-
function getOrSetFromCache(cache, key, version, getValue) {
|
|
1166
|
-
if (!cache) {
|
|
1167
|
-
return getValue();
|
|
1168
|
-
}
|
|
1169
|
-
let entry = cache.get(key);
|
|
1170
|
-
if (entry?.version === version) {
|
|
1171
|
-
return entry.value;
|
|
1172
|
-
}
|
|
1173
|
-
let value = getValue();
|
|
1174
|
-
let newEntry = { value, version };
|
|
1175
|
-
cache.set(key, newEntry);
|
|
1176
|
-
return value;
|
|
1177
|
-
}
|
|
1178
|
-
|
|
1179
|
-
// vite/route-chunks.ts
|
|
1180
|
-
function codeToAst(code, cache, cacheKey) {
|
|
1181
|
-
return structuredClone(
|
|
1182
|
-
getOrSetFromCache(
|
|
1183
|
-
cache,
|
|
1184
|
-
`${cacheKey}::codeToAst`,
|
|
1185
|
-
code,
|
|
1186
|
-
() => (0, import_parser.parse)(code, { sourceType: "module" })
|
|
1187
|
-
)
|
|
1188
|
-
);
|
|
1189
|
-
}
|
|
1190
|
-
function assertNodePath(path7) {
|
|
1191
|
-
invariant(
|
|
1192
|
-
path7 && !Array.isArray(path7),
|
|
1193
|
-
`Expected a Path, but got ${Array.isArray(path7) ? "an array" : path7}`
|
|
1194
|
-
);
|
|
1195
|
-
}
|
|
1196
|
-
function assertNodePathIsStatement(path7) {
|
|
1197
|
-
invariant(
|
|
1198
|
-
path7 && !Array.isArray(path7) && t.isStatement(path7.node),
|
|
1199
|
-
`Expected a Statement path, but got ${Array.isArray(path7) ? "an array" : path7?.node?.type}`
|
|
1200
|
-
);
|
|
1201
|
-
}
|
|
1202
|
-
function assertNodePathIsVariableDeclarator(path7) {
|
|
1203
|
-
invariant(
|
|
1204
|
-
path7 && !Array.isArray(path7) && t.isVariableDeclarator(path7.node),
|
|
1205
|
-
`Expected an Identifier path, but got ${Array.isArray(path7) ? "an array" : path7?.node?.type}`
|
|
1206
|
-
);
|
|
1207
|
-
}
|
|
1208
|
-
function assertNodePathIsPattern(path7) {
|
|
1209
|
-
invariant(
|
|
1210
|
-
path7 && !Array.isArray(path7) && t.isPattern(path7.node),
|
|
1211
|
-
`Expected a Pattern path, but got ${Array.isArray(path7) ? "an array" : path7?.node?.type}`
|
|
1212
|
-
);
|
|
1213
|
-
}
|
|
1214
|
-
function getExportDependencies(code, cache, cacheKey) {
|
|
1215
|
-
return getOrSetFromCache(
|
|
1216
|
-
cache,
|
|
1217
|
-
`${cacheKey}::getExportDependencies`,
|
|
1218
|
-
code,
|
|
1219
|
-
() => {
|
|
1220
|
-
let exportDependencies = /* @__PURE__ */ new Map();
|
|
1221
|
-
let ast = codeToAst(code, cache, cacheKey);
|
|
1222
|
-
function handleExport(exportName, exportPath, identifiersPath = exportPath) {
|
|
1223
|
-
let identifiers = getDependentIdentifiersForPath(identifiersPath);
|
|
1224
|
-
let topLevelStatements = /* @__PURE__ */ new Set([
|
|
1225
|
-
exportPath.node,
|
|
1226
|
-
...getTopLevelStatementsForPaths(identifiers)
|
|
1227
|
-
]);
|
|
1228
|
-
let topLevelNonModuleStatements = new Set(
|
|
1229
|
-
Array.from(topLevelStatements).filter(
|
|
1230
|
-
(statement) => !t.isImportDeclaration(statement) && !t.isExportDeclaration(statement)
|
|
1231
|
-
)
|
|
1232
|
-
);
|
|
1233
|
-
let importedIdentifierNames = /* @__PURE__ */ new Set();
|
|
1234
|
-
for (let identifier of identifiers) {
|
|
1235
|
-
if (identifier.parentPath.parentPath?.isImportDeclaration()) {
|
|
1236
|
-
importedIdentifierNames.add(identifier.node.name);
|
|
1237
|
-
}
|
|
1238
|
-
}
|
|
1239
|
-
let exportedVariableDeclarators = /* @__PURE__ */ new Set();
|
|
1240
|
-
for (let identifier of identifiers) {
|
|
1241
|
-
if (identifier.parentPath.isVariableDeclarator() && identifier.parentPath.parentPath.parentPath?.isExportNamedDeclaration()) {
|
|
1242
|
-
exportedVariableDeclarators.add(identifier.parentPath.node);
|
|
1243
|
-
continue;
|
|
1244
|
-
}
|
|
1245
|
-
let isWithinExportNamedDeclaration = Boolean(
|
|
1246
|
-
identifier.findParent((path7) => path7.isExportNamedDeclaration())
|
|
1247
|
-
);
|
|
1248
|
-
if (isWithinExportNamedDeclaration) {
|
|
1249
|
-
let currentPath = identifier;
|
|
1250
|
-
while (currentPath) {
|
|
1251
|
-
if (
|
|
1252
|
-
// Check the identifier is within a variable declaration, and if
|
|
1253
|
-
// so, ensure we're on the left-hand side of the expression
|
|
1254
|
-
// since these identifiers are what make up the export names,
|
|
1255
|
-
// e.g. export const { foo } = { foo: bar }; should pick up
|
|
1256
|
-
// `foo` but not `bar`.
|
|
1257
|
-
currentPath.parentPath?.isVariableDeclarator() && currentPath.parentKey === "id"
|
|
1258
|
-
) {
|
|
1259
|
-
exportedVariableDeclarators.add(currentPath.parentPath.node);
|
|
1260
|
-
break;
|
|
1261
|
-
}
|
|
1262
|
-
currentPath = currentPath.parentPath;
|
|
1263
|
-
}
|
|
1264
|
-
}
|
|
1265
|
-
}
|
|
1266
|
-
let dependencies = {
|
|
1267
|
-
topLevelStatements,
|
|
1268
|
-
topLevelNonModuleStatements,
|
|
1269
|
-
importedIdentifierNames,
|
|
1270
|
-
exportedVariableDeclarators
|
|
1271
|
-
};
|
|
1272
|
-
exportDependencies.set(exportName, dependencies);
|
|
1273
|
-
}
|
|
1274
|
-
traverse(ast, {
|
|
1275
|
-
ExportDeclaration(exportPath) {
|
|
1276
|
-
let { node } = exportPath;
|
|
1277
|
-
if (t.isExportAllDeclaration(node)) {
|
|
1278
|
-
return;
|
|
1279
|
-
}
|
|
1280
|
-
if (t.isExportDefaultDeclaration(node)) {
|
|
1281
|
-
handleExport("default", exportPath);
|
|
1282
|
-
return;
|
|
1283
|
-
}
|
|
1284
|
-
let { declaration } = node;
|
|
1285
|
-
if (t.isVariableDeclaration(declaration)) {
|
|
1286
|
-
let { declarations } = declaration;
|
|
1287
|
-
for (let i = 0; i < declarations.length; i++) {
|
|
1288
|
-
let declarator = declarations[i];
|
|
1289
|
-
if (t.isIdentifier(declarator.id)) {
|
|
1290
|
-
let declaratorPath = exportPath.get(
|
|
1291
|
-
`declaration.declarations.${i}`
|
|
1292
|
-
);
|
|
1293
|
-
assertNodePathIsVariableDeclarator(declaratorPath);
|
|
1294
|
-
handleExport(declarator.id.name, exportPath, declaratorPath);
|
|
1295
|
-
continue;
|
|
1296
|
-
}
|
|
1297
|
-
if (t.isPattern(declarator.id)) {
|
|
1298
|
-
let exportedPatternPath = exportPath.get(
|
|
1299
|
-
`declaration.declarations.${i}.id`
|
|
1300
|
-
);
|
|
1301
|
-
assertNodePathIsPattern(exportedPatternPath);
|
|
1302
|
-
let identifiers = getIdentifiersForPatternPath(exportedPatternPath);
|
|
1303
|
-
for (let identifier of identifiers) {
|
|
1304
|
-
handleExport(identifier.node.name, exportPath, identifier);
|
|
1305
|
-
}
|
|
1306
|
-
}
|
|
1307
|
-
}
|
|
1308
|
-
return;
|
|
1309
|
-
}
|
|
1310
|
-
if (t.isFunctionDeclaration(declaration) || t.isClassDeclaration(declaration)) {
|
|
1311
|
-
invariant(
|
|
1312
|
-
declaration.id,
|
|
1313
|
-
"Expected exported function or class declaration to have a name when not the default export"
|
|
1314
|
-
);
|
|
1315
|
-
handleExport(declaration.id.name, exportPath);
|
|
1316
|
-
return;
|
|
1317
|
-
}
|
|
1318
|
-
if (t.isExportNamedDeclaration(node)) {
|
|
1319
|
-
for (let specifier of node.specifiers) {
|
|
1320
|
-
if (t.isIdentifier(specifier.exported)) {
|
|
1321
|
-
let name = specifier.exported.name;
|
|
1322
|
-
let specifierPath = exportPath.get("specifiers").find((path7) => path7.node === specifier);
|
|
1323
|
-
invariant(
|
|
1324
|
-
specifierPath,
|
|
1325
|
-
`Expected to find specifier path for ${name}`
|
|
1326
|
-
);
|
|
1327
|
-
handleExport(name, exportPath, specifierPath);
|
|
1328
|
-
}
|
|
1329
|
-
}
|
|
1330
|
-
return;
|
|
1331
|
-
}
|
|
1332
|
-
throw new Error(`Unknown export node type: ${node.type}`);
|
|
1333
|
-
}
|
|
1334
|
-
});
|
|
1335
|
-
return exportDependencies;
|
|
1336
|
-
}
|
|
1337
|
-
);
|
|
1338
|
-
}
|
|
1339
|
-
function getDependentIdentifiersForPath(path7, state) {
|
|
1340
|
-
let { visited, identifiers } = state ?? {
|
|
1341
|
-
visited: /* @__PURE__ */ new Set(),
|
|
1342
|
-
identifiers: /* @__PURE__ */ new Set()
|
|
1343
|
-
};
|
|
1344
|
-
if (visited.has(path7)) {
|
|
1345
|
-
return identifiers;
|
|
1346
|
-
}
|
|
1347
|
-
visited.add(path7);
|
|
1348
|
-
path7.traverse({
|
|
1349
|
-
Identifier(path8) {
|
|
1350
|
-
if (identifiers.has(path8)) {
|
|
1351
|
-
return;
|
|
1352
|
-
}
|
|
1353
|
-
identifiers.add(path8);
|
|
1354
|
-
let binding = path8.scope.getBinding(path8.node.name);
|
|
1355
|
-
if (!binding) {
|
|
1356
|
-
return;
|
|
1357
|
-
}
|
|
1358
|
-
getDependentIdentifiersForPath(binding.path, { visited, identifiers });
|
|
1359
|
-
for (let reference of binding.referencePaths) {
|
|
1360
|
-
if (reference.isExportNamedDeclaration()) {
|
|
1361
|
-
continue;
|
|
1362
|
-
}
|
|
1363
|
-
getDependentIdentifiersForPath(reference, {
|
|
1364
|
-
visited,
|
|
1365
|
-
identifiers
|
|
1366
|
-
});
|
|
1367
|
-
}
|
|
1368
|
-
for (let constantViolation of binding.constantViolations) {
|
|
1369
|
-
getDependentIdentifiersForPath(constantViolation, {
|
|
1370
|
-
visited,
|
|
1371
|
-
identifiers
|
|
1372
|
-
});
|
|
1373
|
-
}
|
|
1374
|
-
}
|
|
1375
|
-
});
|
|
1376
|
-
let topLevelStatement = getTopLevelStatementPathForPath(path7);
|
|
1377
|
-
let withinImportStatement = topLevelStatement.isImportDeclaration();
|
|
1378
|
-
let withinExportStatement = topLevelStatement.isExportDeclaration();
|
|
1379
|
-
if (!withinImportStatement && !withinExportStatement) {
|
|
1380
|
-
getDependentIdentifiersForPath(topLevelStatement, {
|
|
1381
|
-
visited,
|
|
1382
|
-
identifiers
|
|
1383
|
-
});
|
|
1384
|
-
}
|
|
1385
|
-
if (withinExportStatement && path7.isIdentifier() && (t.isPattern(path7.parentPath.node) || // [foo]
|
|
1386
|
-
t.isPattern(path7.parentPath.parentPath?.node))) {
|
|
1387
|
-
let variableDeclarator = path7.findParent((p) => p.isVariableDeclarator());
|
|
1388
|
-
assertNodePath(variableDeclarator);
|
|
1389
|
-
getDependentIdentifiersForPath(variableDeclarator, {
|
|
1390
|
-
visited,
|
|
1391
|
-
identifiers
|
|
1392
|
-
});
|
|
1393
|
-
}
|
|
1394
|
-
return identifiers;
|
|
1395
|
-
}
|
|
1396
|
-
function getTopLevelStatementPathForPath(path7) {
|
|
1397
|
-
let ancestry = path7.getAncestry();
|
|
1398
|
-
let topLevelStatement = ancestry[ancestry.length - 2];
|
|
1399
|
-
assertNodePathIsStatement(topLevelStatement);
|
|
1400
|
-
return topLevelStatement;
|
|
1401
|
-
}
|
|
1402
|
-
function getTopLevelStatementsForPaths(paths) {
|
|
1403
|
-
let topLevelStatements = /* @__PURE__ */ new Set();
|
|
1404
|
-
for (let path7 of paths) {
|
|
1405
|
-
let topLevelStatement = getTopLevelStatementPathForPath(path7);
|
|
1406
|
-
topLevelStatements.add(topLevelStatement.node);
|
|
1407
|
-
}
|
|
1408
|
-
return topLevelStatements;
|
|
1409
|
-
}
|
|
1410
|
-
function getIdentifiersForPatternPath(patternPath, identifiers = /* @__PURE__ */ new Set()) {
|
|
1411
|
-
function walk(currentPath) {
|
|
1412
|
-
if (currentPath.isIdentifier()) {
|
|
1413
|
-
identifiers.add(currentPath);
|
|
1414
|
-
return;
|
|
1415
|
-
}
|
|
1416
|
-
if (currentPath.isObjectPattern()) {
|
|
1417
|
-
let { properties } = currentPath.node;
|
|
1418
|
-
for (let i = 0; i < properties.length; i++) {
|
|
1419
|
-
const property = properties[i];
|
|
1420
|
-
if (t.isObjectProperty(property)) {
|
|
1421
|
-
let valuePath = currentPath.get(`properties.${i}.value`);
|
|
1422
|
-
assertNodePath(valuePath);
|
|
1423
|
-
walk(valuePath);
|
|
1424
|
-
} else if (t.isRestElement(property)) {
|
|
1425
|
-
let argumentPath = currentPath.get(`properties.${i}.argument`);
|
|
1426
|
-
assertNodePath(argumentPath);
|
|
1427
|
-
walk(argumentPath);
|
|
1428
|
-
}
|
|
1429
|
-
}
|
|
1430
|
-
} else if (currentPath.isArrayPattern()) {
|
|
1431
|
-
let { elements } = currentPath.node;
|
|
1432
|
-
for (let i = 0; i < elements.length; i++) {
|
|
1433
|
-
const element = elements[i];
|
|
1434
|
-
if (element) {
|
|
1435
|
-
let elementPath = currentPath.get(`elements.${i}`);
|
|
1436
|
-
assertNodePath(elementPath);
|
|
1437
|
-
walk(elementPath);
|
|
1438
|
-
}
|
|
1439
|
-
}
|
|
1440
|
-
} else if (currentPath.isRestElement()) {
|
|
1441
|
-
let argumentPath = currentPath.get("argument");
|
|
1442
|
-
assertNodePath(argumentPath);
|
|
1443
|
-
walk(argumentPath);
|
|
1444
|
-
}
|
|
1445
|
-
}
|
|
1446
|
-
walk(patternPath);
|
|
1447
|
-
return identifiers;
|
|
1448
|
-
}
|
|
1449
|
-
var getExportedName = (exported) => {
|
|
1450
|
-
return t.isIdentifier(exported) ? exported.name : exported.value;
|
|
1451
|
-
};
|
|
1452
|
-
function setsIntersect(set1, set2) {
|
|
1453
|
-
let smallerSet = set1;
|
|
1454
|
-
let largerSet = set2;
|
|
1455
|
-
if (set1.size > set2.size) {
|
|
1456
|
-
smallerSet = set2;
|
|
1457
|
-
largerSet = set1;
|
|
1458
|
-
}
|
|
1459
|
-
for (let element of smallerSet) {
|
|
1460
|
-
if (largerSet.has(element)) {
|
|
1461
|
-
return true;
|
|
1462
|
-
}
|
|
1463
|
-
}
|
|
1464
|
-
return false;
|
|
1465
|
-
}
|
|
1466
|
-
function hasChunkableExport(code, exportName, cache, cacheKey) {
|
|
1467
|
-
return getOrSetFromCache(
|
|
1468
|
-
cache,
|
|
1469
|
-
`${cacheKey}::hasChunkableExport::${exportName}`,
|
|
1470
|
-
code,
|
|
1471
|
-
() => {
|
|
1472
|
-
let exportDependencies = getExportDependencies(code, cache, cacheKey);
|
|
1473
|
-
let dependencies = exportDependencies.get(exportName);
|
|
1474
|
-
if (!dependencies) {
|
|
1475
|
-
return false;
|
|
1476
|
-
}
|
|
1477
|
-
for (let [currentExportName, currentDependencies] of exportDependencies) {
|
|
1478
|
-
if (currentExportName === exportName) {
|
|
1479
|
-
continue;
|
|
1480
|
-
}
|
|
1481
|
-
if (setsIntersect(
|
|
1482
|
-
currentDependencies.topLevelNonModuleStatements,
|
|
1483
|
-
dependencies.topLevelNonModuleStatements
|
|
1484
|
-
)) {
|
|
1485
|
-
return false;
|
|
1486
|
-
}
|
|
1487
|
-
}
|
|
1488
|
-
if (dependencies.exportedVariableDeclarators.size > 1) {
|
|
1489
|
-
return false;
|
|
1490
|
-
}
|
|
1491
|
-
if (dependencies.exportedVariableDeclarators.size > 0) {
|
|
1492
|
-
for (let [
|
|
1493
|
-
currentExportName,
|
|
1494
|
-
currentDependencies
|
|
1495
|
-
] of exportDependencies) {
|
|
1496
|
-
if (currentExportName === exportName) {
|
|
1497
|
-
continue;
|
|
1498
|
-
}
|
|
1499
|
-
if (setsIntersect(
|
|
1500
|
-
currentDependencies.exportedVariableDeclarators,
|
|
1501
|
-
dependencies.exportedVariableDeclarators
|
|
1502
|
-
)) {
|
|
1503
|
-
return false;
|
|
1504
|
-
}
|
|
1505
|
-
}
|
|
1506
|
-
}
|
|
1507
|
-
return true;
|
|
1508
|
-
}
|
|
1509
|
-
);
|
|
1510
|
-
}
|
|
1511
|
-
function getChunkedExport(code, exportName, generateOptions = {}, cache, cacheKey) {
|
|
1512
|
-
return getOrSetFromCache(
|
|
1513
|
-
cache,
|
|
1514
|
-
`${cacheKey}::getChunkedExport::${exportName}::${JSON.stringify(
|
|
1515
|
-
generateOptions
|
|
1516
|
-
)}`,
|
|
1517
|
-
code,
|
|
1518
|
-
() => {
|
|
1519
|
-
if (!hasChunkableExport(code, exportName, cache, cacheKey)) {
|
|
1520
|
-
return void 0;
|
|
1521
|
-
}
|
|
1522
|
-
let exportDependencies = getExportDependencies(code, cache, cacheKey);
|
|
1523
|
-
let dependencies = exportDependencies.get(exportName);
|
|
1524
|
-
invariant(dependencies, "Expected export to have dependencies");
|
|
1525
|
-
let topLevelStatementsArray = Array.from(dependencies.topLevelStatements);
|
|
1526
|
-
let exportedVariableDeclaratorsArray = Array.from(
|
|
1527
|
-
dependencies.exportedVariableDeclarators
|
|
1528
|
-
);
|
|
1529
|
-
let ast = codeToAst(code, cache, cacheKey);
|
|
1530
|
-
ast.program.body = ast.program.body.filter(
|
|
1531
|
-
(node) => topLevelStatementsArray.some(
|
|
1532
|
-
(statement) => t.isNodesEquivalent(node, statement)
|
|
1533
|
-
)
|
|
1534
|
-
).map((node) => {
|
|
1535
|
-
if (!t.isImportDeclaration(node)) {
|
|
1536
|
-
return node;
|
|
1537
|
-
}
|
|
1538
|
-
if (dependencies.importedIdentifierNames.size === 0) {
|
|
1539
|
-
return null;
|
|
1540
|
-
}
|
|
1541
|
-
node.specifiers = node.specifiers.filter(
|
|
1542
|
-
(specifier) => dependencies.importedIdentifierNames.has(specifier.local.name)
|
|
1543
|
-
);
|
|
1544
|
-
invariant(
|
|
1545
|
-
node.specifiers.length > 0,
|
|
1546
|
-
"Expected import statement to have used specifiers"
|
|
1547
|
-
);
|
|
1548
|
-
return node;
|
|
1549
|
-
}).map((node) => {
|
|
1550
|
-
if (!t.isExportDeclaration(node)) {
|
|
1551
|
-
return node;
|
|
1552
|
-
}
|
|
1553
|
-
if (t.isExportAllDeclaration(node)) {
|
|
1554
|
-
return null;
|
|
1555
|
-
}
|
|
1556
|
-
if (t.isExportDefaultDeclaration(node)) {
|
|
1557
|
-
return exportName === "default" ? node : null;
|
|
1558
|
-
}
|
|
1559
|
-
let { declaration } = node;
|
|
1560
|
-
if (t.isVariableDeclaration(declaration)) {
|
|
1561
|
-
declaration.declarations = declaration.declarations.filter(
|
|
1562
|
-
(node2) => exportedVariableDeclaratorsArray.some(
|
|
1563
|
-
(declarator) => t.isNodesEquivalent(node2, declarator)
|
|
1564
|
-
)
|
|
1565
|
-
);
|
|
1566
|
-
if (declaration.declarations.length === 0) {
|
|
1567
|
-
return null;
|
|
1568
|
-
}
|
|
1569
|
-
return node;
|
|
1570
|
-
}
|
|
1571
|
-
if (t.isFunctionDeclaration(node.declaration) || t.isClassDeclaration(node.declaration)) {
|
|
1572
|
-
return node.declaration.id?.name === exportName ? node : null;
|
|
1573
|
-
}
|
|
1574
|
-
if (t.isExportNamedDeclaration(node)) {
|
|
1575
|
-
if (node.specifiers.length === 0) {
|
|
1576
|
-
return null;
|
|
1577
|
-
}
|
|
1578
|
-
node.specifiers = node.specifiers.filter(
|
|
1579
|
-
(specifier) => getExportedName(specifier.exported) === exportName
|
|
1580
|
-
);
|
|
1581
|
-
if (node.specifiers.length === 0) {
|
|
1582
|
-
return null;
|
|
1583
|
-
}
|
|
1584
|
-
return node;
|
|
1585
|
-
}
|
|
1586
|
-
throw new Error(`Unknown export node type: ${node.type}`);
|
|
1587
|
-
}).filter((node) => node !== null);
|
|
1588
|
-
return generate2(ast, generateOptions);
|
|
1589
|
-
}
|
|
1590
|
-
);
|
|
1591
|
-
}
|
|
1592
|
-
function omitChunkedExports(code, exportNames, generateOptions = {}, cache, cacheKey) {
|
|
1593
|
-
return getOrSetFromCache(
|
|
1594
|
-
cache,
|
|
1595
|
-
`${cacheKey}::omitChunkedExports::${exportNames.join(
|
|
1596
|
-
","
|
|
1597
|
-
)}::${JSON.stringify(generateOptions)}`,
|
|
1598
|
-
code,
|
|
1599
|
-
() => {
|
|
1600
|
-
const isChunkable = (exportName) => hasChunkableExport(code, exportName, cache, cacheKey);
|
|
1601
|
-
const isOmitted = (exportName) => exportNames.includes(exportName) && isChunkable(exportName);
|
|
1602
|
-
const isRetained = (exportName) => !isOmitted(exportName);
|
|
1603
|
-
let exportDependencies = getExportDependencies(code, cache, cacheKey);
|
|
1604
|
-
let allExportNames = Array.from(exportDependencies.keys());
|
|
1605
|
-
let omittedExportNames = allExportNames.filter(isOmitted);
|
|
1606
|
-
let retainedExportNames = allExportNames.filter(isRetained);
|
|
1607
|
-
let omittedStatements = /* @__PURE__ */ new Set();
|
|
1608
|
-
let omittedExportedVariableDeclarators = /* @__PURE__ */ new Set();
|
|
1609
|
-
for (let omittedExportName of omittedExportNames) {
|
|
1610
|
-
let dependencies = exportDependencies.get(omittedExportName);
|
|
1611
|
-
invariant(
|
|
1612
|
-
dependencies,
|
|
1613
|
-
`Expected dependencies for ${omittedExportName}`
|
|
1614
|
-
);
|
|
1615
|
-
for (let statement of dependencies.topLevelNonModuleStatements) {
|
|
1616
|
-
omittedStatements.add(statement);
|
|
1617
|
-
}
|
|
1618
|
-
for (let declarator of dependencies.exportedVariableDeclarators) {
|
|
1619
|
-
omittedExportedVariableDeclarators.add(declarator);
|
|
1620
|
-
}
|
|
1621
|
-
}
|
|
1622
|
-
let ast = codeToAst(code, cache, cacheKey);
|
|
1623
|
-
let omittedStatementsArray = Array.from(omittedStatements);
|
|
1624
|
-
let omittedExportedVariableDeclaratorsArray = Array.from(
|
|
1625
|
-
omittedExportedVariableDeclarators
|
|
1626
|
-
);
|
|
1627
|
-
ast.program.body = ast.program.body.filter(
|
|
1628
|
-
(node) => omittedStatementsArray.every(
|
|
1629
|
-
(statement) => !t.isNodesEquivalent(node, statement)
|
|
1630
|
-
)
|
|
1631
|
-
).map((node) => {
|
|
1632
|
-
if (!t.isImportDeclaration(node)) {
|
|
1633
|
-
return node;
|
|
1634
|
-
}
|
|
1635
|
-
if (node.specifiers.length === 0) {
|
|
1636
|
-
return node;
|
|
1637
|
-
}
|
|
1638
|
-
node.specifiers = node.specifiers.filter((specifier) => {
|
|
1639
|
-
let importedName = specifier.local.name;
|
|
1640
|
-
for (let retainedExportName of retainedExportNames) {
|
|
1641
|
-
let dependencies = exportDependencies.get(retainedExportName);
|
|
1642
|
-
if (dependencies?.importedIdentifierNames?.has(importedName)) {
|
|
1643
|
-
return true;
|
|
1644
|
-
}
|
|
1645
|
-
}
|
|
1646
|
-
for (let omittedExportName of omittedExportNames) {
|
|
1647
|
-
let dependencies = exportDependencies.get(omittedExportName);
|
|
1648
|
-
if (dependencies?.importedIdentifierNames?.has(importedName)) {
|
|
1649
|
-
return false;
|
|
1650
|
-
}
|
|
1651
|
-
}
|
|
1652
|
-
return true;
|
|
1653
|
-
});
|
|
1654
|
-
if (node.specifiers.length === 0) {
|
|
1655
|
-
return null;
|
|
1656
|
-
}
|
|
1657
|
-
return node;
|
|
1658
|
-
}).map((node) => {
|
|
1659
|
-
if (!t.isExportDeclaration(node)) {
|
|
1660
|
-
return node;
|
|
1661
|
-
}
|
|
1662
|
-
if (t.isExportAllDeclaration(node)) {
|
|
1663
|
-
return node;
|
|
1664
|
-
}
|
|
1665
|
-
if (t.isExportDefaultDeclaration(node)) {
|
|
1666
|
-
return isOmitted("default") ? null : node;
|
|
1667
|
-
}
|
|
1668
|
-
if (t.isVariableDeclaration(node.declaration)) {
|
|
1669
|
-
node.declaration.declarations = node.declaration.declarations.filter(
|
|
1670
|
-
(node2) => omittedExportedVariableDeclaratorsArray.every(
|
|
1671
|
-
(declarator) => !t.isNodesEquivalent(node2, declarator)
|
|
1672
|
-
)
|
|
1673
|
-
);
|
|
1674
|
-
if (node.declaration.declarations.length === 0) {
|
|
1675
|
-
return null;
|
|
1676
|
-
}
|
|
1677
|
-
return node;
|
|
1678
|
-
}
|
|
1679
|
-
if (t.isFunctionDeclaration(node.declaration) || t.isClassDeclaration(node.declaration)) {
|
|
1680
|
-
invariant(
|
|
1681
|
-
node.declaration.id,
|
|
1682
|
-
"Expected exported function or class declaration to have a name when not the default export"
|
|
1683
|
-
);
|
|
1684
|
-
return isOmitted(node.declaration.id.name) ? null : node;
|
|
1685
|
-
}
|
|
1686
|
-
if (t.isExportNamedDeclaration(node)) {
|
|
1687
|
-
if (node.specifiers.length === 0) {
|
|
1688
|
-
return node;
|
|
1689
|
-
}
|
|
1690
|
-
node.specifiers = node.specifiers.filter((specifier) => {
|
|
1691
|
-
const exportedName = getExportedName(specifier.exported);
|
|
1692
|
-
return !isOmitted(exportedName);
|
|
1693
|
-
});
|
|
1694
|
-
if (node.specifiers.length === 0) {
|
|
1695
|
-
return null;
|
|
1696
|
-
}
|
|
1697
|
-
return node;
|
|
1698
|
-
}
|
|
1699
|
-
throw new Error(`Unknown node type: ${node.type}`);
|
|
1700
|
-
}).filter((node) => node !== null);
|
|
1701
|
-
if (ast.program.body.length === 0) {
|
|
1702
|
-
return void 0;
|
|
1703
|
-
}
|
|
1704
|
-
return generate2(ast, generateOptions);
|
|
1705
|
-
}
|
|
1706
|
-
);
|
|
1707
|
-
}
|
|
1708
|
-
function detectRouteChunks(code, cache, cacheKey) {
|
|
1709
|
-
const hasRouteChunkByExportName = Object.fromEntries(
|
|
1710
|
-
routeChunkExportNames.map((exportName) => [
|
|
1711
|
-
exportName,
|
|
1712
|
-
hasChunkableExport(code, exportName, cache, cacheKey)
|
|
1713
|
-
])
|
|
1714
|
-
);
|
|
1715
|
-
const chunkedExports = Object.entries(hasRouteChunkByExportName).filter(([, isChunked]) => isChunked).map(([exportName]) => exportName);
|
|
1716
|
-
const hasRouteChunks = chunkedExports.length > 0;
|
|
1717
|
-
return {
|
|
1718
|
-
hasRouteChunks,
|
|
1719
|
-
hasRouteChunkByExportName,
|
|
1720
|
-
chunkedExports
|
|
1721
|
-
};
|
|
1722
|
-
}
|
|
1723
|
-
var routeChunkExportNames = [
|
|
1724
|
-
"clientAction",
|
|
1725
|
-
"clientLoader",
|
|
1726
|
-
"HydrateFallback"
|
|
1727
|
-
];
|
|
1728
|
-
var mainChunkName = "main";
|
|
1729
|
-
var routeChunkNames = ["main", ...routeChunkExportNames];
|
|
1730
|
-
function getRouteChunkCode(code, chunkName, cache, cacheKey) {
|
|
1731
|
-
if (chunkName === mainChunkName) {
|
|
1732
|
-
return omitChunkedExports(code, routeChunkExportNames, {}, cache, cacheKey);
|
|
1733
|
-
}
|
|
1734
|
-
return getChunkedExport(code, chunkName, {}, cache, cacheKey);
|
|
1735
|
-
}
|
|
1736
|
-
var routeChunkQueryStringPrefix = "?route-chunk=";
|
|
1737
|
-
var routeChunkQueryStrings = {
|
|
1738
|
-
main: `${routeChunkQueryStringPrefix}main`,
|
|
1739
|
-
clientAction: `${routeChunkQueryStringPrefix}clientAction`,
|
|
1740
|
-
clientLoader: `${routeChunkQueryStringPrefix}clientLoader`,
|
|
1741
|
-
HydrateFallback: `${routeChunkQueryStringPrefix}HydrateFallback`
|
|
1742
|
-
};
|
|
1743
|
-
function getRouteChunkModuleId(filePath, chunkName) {
|
|
1744
|
-
return `${filePath}${routeChunkQueryStrings[chunkName]}`;
|
|
1745
|
-
}
|
|
1746
|
-
function isRouteChunkModuleId(id) {
|
|
1747
|
-
return Object.values(routeChunkQueryStrings).some(
|
|
1748
|
-
(queryString) => id.endsWith(queryString)
|
|
1749
|
-
);
|
|
1750
|
-
}
|
|
1751
|
-
function isRouteChunkName(name) {
|
|
1752
|
-
return name === mainChunkName || routeChunkExportNames.includes(name);
|
|
1753
|
-
}
|
|
1754
|
-
function getRouteChunkNameFromModuleId(id) {
|
|
1755
|
-
if (!isRouteChunkModuleId(id)) {
|
|
1756
|
-
return null;
|
|
1757
|
-
}
|
|
1758
|
-
let chunkName = id.split(routeChunkQueryStringPrefix)[1].split("&")[0];
|
|
1759
|
-
if (!isRouteChunkName(chunkName)) {
|
|
1760
|
-
return null;
|
|
1761
|
-
}
|
|
1762
|
-
return chunkName;
|
|
1763
|
-
}
|
|
1764
|
-
|
|
1765
1173
|
// vite/with-props.ts
|
|
1766
|
-
var
|
|
1174
|
+
var import_dedent3 = __toESM(require("dedent"));
|
|
1767
1175
|
var vmod = create("with-props");
|
|
1768
1176
|
var NAMED_COMPONENT_EXPORTS = ["HydrateFallback", "ErrorBoundary"];
|
|
1769
1177
|
var plugin = {
|
|
@@ -1774,7 +1182,7 @@ var plugin = {
|
|
|
1774
1182
|
},
|
|
1775
1183
|
async load(id) {
|
|
1776
1184
|
if (id !== vmod.resolvedId) return;
|
|
1777
|
-
return
|
|
1185
|
+
return import_dedent3.default`
|
|
1778
1186
|
import { createElement as h } from "react";
|
|
1779
1187
|
import { useActionData, useLoaderData, useMatches, useParams, useRouteError } from "react-router";
|
|
1780
1188
|
|
|
@@ -1901,20 +1309,8 @@ var CLIENT_ROUTE_EXPORTS = [
|
|
|
1901
1309
|
"shouldRevalidate"
|
|
1902
1310
|
];
|
|
1903
1311
|
var BUILD_CLIENT_ROUTE_QUERY_STRING = "?__react-router-build-client-route";
|
|
1904
|
-
var isRouteEntryModuleId = (id) => {
|
|
1905
|
-
return id.endsWith(BUILD_CLIENT_ROUTE_QUERY_STRING);
|
|
1906
|
-
};
|
|
1907
|
-
var isRouteVirtualModule = (id) => {
|
|
1908
|
-
return isRouteEntryModuleId(id) || isRouteChunkModuleId(id);
|
|
1909
|
-
};
|
|
1910
1312
|
var virtualHmrRuntime = create("hmr-runtime");
|
|
1911
1313
|
var virtualInjectHmrRuntime = create("inject-hmr-runtime");
|
|
1912
|
-
var normalizeRelativeFilePath = (file, reactRouterConfig) => {
|
|
1913
|
-
let vite2 = getVite();
|
|
1914
|
-
let fullPath = path6.resolve(reactRouterConfig.appDirectory, file);
|
|
1915
|
-
let relativePath = path6.relative(reactRouterConfig.appDirectory, fullPath);
|
|
1916
|
-
return vite2.normalizePath(relativePath).split("?")[0];
|
|
1917
|
-
};
|
|
1918
1314
|
var resolveRelativeRouteFilePath = (route, reactRouterConfig) => {
|
|
1919
1315
|
let vite2 = getVite();
|
|
1920
1316
|
let file = route.file;
|
|
@@ -1943,35 +1339,23 @@ var resolveChunk = (ctx, viteManifest, absoluteFilePath) => {
|
|
|
1943
1339
|
let rootRelativeFilePath = vite2.normalizePath(
|
|
1944
1340
|
path6.relative(ctx.rootDirectory, absoluteFilePath)
|
|
1945
1341
|
);
|
|
1946
|
-
let entryChunk = viteManifest[rootRelativeFilePath];
|
|
1342
|
+
let entryChunk = viteManifest[rootRelativeFilePath + BUILD_CLIENT_ROUTE_QUERY_STRING] ?? viteManifest[rootRelativeFilePath];
|
|
1947
1343
|
if (!entryChunk) {
|
|
1948
|
-
|
|
1344
|
+
let knownManifestKeys = Object.keys(viteManifest).map((key) => '"' + key + '"').join(", ");
|
|
1345
|
+
throw new Error(
|
|
1346
|
+
`No manifest entry found for "${rootRelativeFilePath}". Known manifest keys: ${knownManifestKeys}`
|
|
1347
|
+
);
|
|
1949
1348
|
}
|
|
1950
1349
|
return entryChunk;
|
|
1951
1350
|
};
|
|
1952
|
-
var getPublicModulePathForEntry = (ctx, viteManifest, entryFilePath) => {
|
|
1953
|
-
let entryChunk = resolveChunk(ctx, viteManifest, entryFilePath);
|
|
1954
|
-
return entryChunk ? `${ctx.publicPath}${entryChunk.file}` : void 0;
|
|
1955
|
-
};
|
|
1956
1351
|
var getReactRouterManifestBuildAssets = (ctx, viteManifest, entryFilePath, prependedAssetFilePaths = []) => {
|
|
1957
1352
|
let entryChunk = resolveChunk(ctx, viteManifest, entryFilePath);
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
invariant(chunk, "Chunk not found");
|
|
1962
|
-
return chunk;
|
|
1963
|
-
});
|
|
1964
|
-
let routeModuleChunks = routeChunkNames.map(
|
|
1965
|
-
(routeChunkName) => resolveChunk(
|
|
1966
|
-
ctx,
|
|
1967
|
-
viteManifest,
|
|
1968
|
-
getRouteChunkModuleId(entryFilePath.split("?")[0], routeChunkName)
|
|
1969
|
-
)
|
|
1970
|
-
).filter(isNonNullable);
|
|
1353
|
+
let prependedAssetChunks = prependedAssetFilePaths.map(
|
|
1354
|
+
(filePath) => resolveChunk(ctx, viteManifest, filePath)
|
|
1355
|
+
);
|
|
1971
1356
|
let chunks = resolveDependantChunks(viteManifest, [
|
|
1972
1357
|
...prependedAssetChunks,
|
|
1973
|
-
entryChunk
|
|
1974
|
-
...routeModuleChunks
|
|
1358
|
+
entryChunk
|
|
1975
1359
|
]);
|
|
1976
1360
|
return {
|
|
1977
1361
|
module: `${ctx.publicPath}${entryChunk.file}`,
|
|
@@ -2008,10 +1392,6 @@ var writeFileSafe = async (file, contents) => {
|
|
|
2008
1392
|
await fse.ensureDir(path6.dirname(file));
|
|
2009
1393
|
await fse.writeFile(file, contents);
|
|
2010
1394
|
};
|
|
2011
|
-
var getExportNames = (code) => {
|
|
2012
|
-
let [, exportSpecifiers] = (0, import_es_module_lexer.parse)(code);
|
|
2013
|
-
return exportSpecifiers.map(({ n: name }) => name);
|
|
2014
|
-
};
|
|
2015
1395
|
var getRouteManifestModuleExports = async (viteChildCompiler, ctx) => {
|
|
2016
1396
|
let entries = await Promise.all(
|
|
2017
1397
|
Object.entries(ctx.reactRouterConfig.routes).map(async ([key, route]) => {
|
|
@@ -2025,7 +1405,7 @@ var getRouteManifestModuleExports = async (viteChildCompiler, ctx) => {
|
|
|
2025
1405
|
);
|
|
2026
1406
|
return Object.fromEntries(entries);
|
|
2027
1407
|
};
|
|
2028
|
-
var
|
|
1408
|
+
var getRouteModuleExports = async (viteChildCompiler, ctx, routeFile, readRouteFile) => {
|
|
2029
1409
|
if (!viteChildCompiler) {
|
|
2030
1410
|
throw new Error("Vite child compiler not found");
|
|
2031
1411
|
}
|
|
@@ -2045,19 +1425,9 @@ var compileRouteFile = async (viteChildCompiler, ctx, routeFile, readRouteFile)
|
|
|
2045
1425
|
moduleGraph.ensureEntryFromUrl(url2, ssr)
|
|
2046
1426
|
]);
|
|
2047
1427
|
let transformed = await pluginContainer.transform(code, id, { ssr });
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
if (!viteChildCompiler) {
|
|
2052
|
-
throw new Error("Vite child compiler not found");
|
|
2053
|
-
}
|
|
2054
|
-
let code = await compileRouteFile(
|
|
2055
|
-
viteChildCompiler,
|
|
2056
|
-
ctx,
|
|
2057
|
-
routeFile,
|
|
2058
|
-
readRouteFile
|
|
2059
|
-
);
|
|
2060
|
-
return getExportNames(code);
|
|
1428
|
+
let [, exports2] = (0, import_es_module_lexer.parse)(transformed.code);
|
|
1429
|
+
let exportNames = exports2.map((e) => e.n);
|
|
1430
|
+
return exportNames;
|
|
2061
1431
|
};
|
|
2062
1432
|
var getServerBundleBuildConfig = (viteUserConfig) => {
|
|
2063
1433
|
if (!("__reactRouterServerBundleBuildConfig" in viteUserConfig) || !viteUserConfig.__reactRouterServerBundleBuildConfig) {
|
|
@@ -2077,7 +1447,7 @@ var defaultEntriesDir = path6.resolve(
|
|
|
2077
1447
|
"config",
|
|
2078
1448
|
"defaults"
|
|
2079
1449
|
);
|
|
2080
|
-
var defaultEntries = fse.readdirSync(defaultEntriesDir).map((
|
|
1450
|
+
var defaultEntries = fse.readdirSync(defaultEntriesDir).map((filename2) => path6.join(defaultEntriesDir, filename2));
|
|
2081
1451
|
invariant(defaultEntries.length > 0, "No default entries found");
|
|
2082
1452
|
var reactRouterDevLoadContext = () => ({});
|
|
2083
1453
|
var reactRouterVitePlugin = () => {
|
|
@@ -2088,7 +1458,6 @@ var reactRouterVitePlugin = () => {
|
|
|
2088
1458
|
let viteConfig;
|
|
2089
1459
|
let cssModulesManifest = {};
|
|
2090
1460
|
let viteChildCompiler = null;
|
|
2091
|
-
let cache = /* @__PURE__ */ new Map();
|
|
2092
1461
|
let reactRouterConfigLoader;
|
|
2093
1462
|
let typegenWatcherPromise;
|
|
2094
1463
|
let logger;
|
|
@@ -2228,31 +1597,13 @@ var reactRouterVitePlugin = () => {
|
|
|
2228
1597
|
viteChildCompiler,
|
|
2229
1598
|
ctx
|
|
2230
1599
|
);
|
|
2231
|
-
let enforceSplitRouteModules = ctx.reactRouterConfig.future.unstable_splitRouteModules === "enforce";
|
|
2232
1600
|
for (let [key, route] of Object.entries(ctx.reactRouterConfig.routes)) {
|
|
2233
|
-
let
|
|
1601
|
+
let routeFilePath = path6.join(
|
|
1602
|
+
ctx.reactRouterConfig.appDirectory,
|
|
1603
|
+
route.file
|
|
1604
|
+
);
|
|
2234
1605
|
let sourceExports = routeManifestExports[key];
|
|
2235
1606
|
let isRootRoute = route.parentId === void 0;
|
|
2236
|
-
let hasClientAction = sourceExports.includes("clientAction");
|
|
2237
|
-
let hasClientLoader = sourceExports.includes("clientLoader");
|
|
2238
|
-
let hasHydrateFallback = sourceExports.includes("HydrateFallback");
|
|
2239
|
-
let { hasRouteChunkByExportName } = await detectRouteChunksIfEnabled(
|
|
2240
|
-
cache,
|
|
2241
|
-
ctx,
|
|
2242
|
-
routeFile,
|
|
2243
|
-
{ routeFile, viteChildCompiler }
|
|
2244
|
-
);
|
|
2245
|
-
if (enforceSplitRouteModules) {
|
|
2246
|
-
validateRouteChunks({
|
|
2247
|
-
ctx,
|
|
2248
|
-
id: route.file,
|
|
2249
|
-
valid: {
|
|
2250
|
-
clientAction: !hasClientAction || hasRouteChunkByExportName.clientAction,
|
|
2251
|
-
clientLoader: !hasClientLoader || hasRouteChunkByExportName.clientLoader,
|
|
2252
|
-
HydrateFallback: !hasHydrateFallback || hasRouteChunkByExportName.HydrateFallback
|
|
2253
|
-
}
|
|
2254
|
-
});
|
|
2255
|
-
}
|
|
2256
1607
|
let routeManifestEntry = {
|
|
2257
1608
|
id: route.id,
|
|
2258
1609
|
parentId: route.parentId,
|
|
@@ -2261,33 +1612,18 @@ var reactRouterVitePlugin = () => {
|
|
|
2261
1612
|
caseSensitive: route.caseSensitive,
|
|
2262
1613
|
hasAction: sourceExports.includes("action"),
|
|
2263
1614
|
hasLoader: sourceExports.includes("loader"),
|
|
2264
|
-
hasClientAction,
|
|
2265
|
-
hasClientLoader,
|
|
1615
|
+
hasClientAction: sourceExports.includes("clientAction"),
|
|
1616
|
+
hasClientLoader: sourceExports.includes("clientLoader"),
|
|
2266
1617
|
hasErrorBoundary: sourceExports.includes("ErrorBoundary"),
|
|
2267
1618
|
...getReactRouterManifestBuildAssets(
|
|
2268
1619
|
ctx,
|
|
2269
1620
|
viteManifest,
|
|
2270
|
-
|
|
1621
|
+
routeFilePath,
|
|
2271
1622
|
// If this is the root route, we also need to include assets from the
|
|
2272
1623
|
// client entry file as this is a common way for consumers to import
|
|
2273
1624
|
// global reset styles, etc.
|
|
2274
1625
|
isRootRoute ? [ctx.entryClientFilePath] : []
|
|
2275
|
-
)
|
|
2276
|
-
clientActionModule: hasRouteChunkByExportName.clientAction ? getPublicModulePathForEntry(
|
|
2277
|
-
ctx,
|
|
2278
|
-
viteManifest,
|
|
2279
|
-
getRouteChunkModuleId(routeFile, "clientAction")
|
|
2280
|
-
) : void 0,
|
|
2281
|
-
clientLoaderModule: hasRouteChunkByExportName.clientLoader ? getPublicModulePathForEntry(
|
|
2282
|
-
ctx,
|
|
2283
|
-
viteManifest,
|
|
2284
|
-
getRouteChunkModuleId(routeFile, "clientLoader")
|
|
2285
|
-
) : void 0,
|
|
2286
|
-
hydrateFallbackModule: hasRouteChunkByExportName.HydrateFallback ? getPublicModulePathForEntry(
|
|
2287
|
-
ctx,
|
|
2288
|
-
viteManifest,
|
|
2289
|
-
getRouteChunkModuleId(routeFile, "HydrateFallback")
|
|
2290
|
-
) : void 0
|
|
1626
|
+
)
|
|
2291
1627
|
};
|
|
2292
1628
|
browserRoutes[key] = routeManifestEntry;
|
|
2293
1629
|
let serverBundleRoutes = ctx.serverBundleBuildConfig?.routes;
|
|
@@ -2328,52 +1664,25 @@ var reactRouterVitePlugin = () => {
|
|
|
2328
1664
|
viteChildCompiler,
|
|
2329
1665
|
ctx
|
|
2330
1666
|
);
|
|
2331
|
-
let enforceSplitRouteModules = ctx.reactRouterConfig.future.unstable_splitRouteModules === "enforce";
|
|
2332
1667
|
for (let [key, route] of Object.entries(ctx.reactRouterConfig.routes)) {
|
|
2333
|
-
let routeFile = route.file;
|
|
2334
1668
|
let sourceExports = routeManifestExports[key];
|
|
2335
|
-
let hasClientAction = sourceExports.includes("clientAction");
|
|
2336
|
-
let hasClientLoader = sourceExports.includes("clientLoader");
|
|
2337
|
-
let hasHydrateFallback = sourceExports.includes("HydrateFallback");
|
|
2338
|
-
let routeModulePath = combineURLs(
|
|
2339
|
-
ctx.publicPath,
|
|
2340
|
-
`${resolveFileUrl(
|
|
2341
|
-
ctx,
|
|
2342
|
-
resolveRelativeRouteFilePath(route, ctx.reactRouterConfig)
|
|
2343
|
-
)}`
|
|
2344
|
-
);
|
|
2345
|
-
if (enforceSplitRouteModules) {
|
|
2346
|
-
let { hasRouteChunkByExportName } = await detectRouteChunksIfEnabled(
|
|
2347
|
-
cache,
|
|
2348
|
-
ctx,
|
|
2349
|
-
routeFile,
|
|
2350
|
-
{ routeFile, viteChildCompiler }
|
|
2351
|
-
);
|
|
2352
|
-
validateRouteChunks({
|
|
2353
|
-
ctx,
|
|
2354
|
-
id: route.file,
|
|
2355
|
-
valid: {
|
|
2356
|
-
clientAction: !hasClientAction || hasRouteChunkByExportName.clientAction,
|
|
2357
|
-
clientLoader: !hasClientLoader || hasRouteChunkByExportName.clientLoader,
|
|
2358
|
-
HydrateFallback: !hasHydrateFallback || hasRouteChunkByExportName.HydrateFallback
|
|
2359
|
-
}
|
|
2360
|
-
});
|
|
2361
|
-
}
|
|
2362
1669
|
routes[key] = {
|
|
2363
1670
|
id: route.id,
|
|
2364
1671
|
parentId: route.parentId,
|
|
2365
1672
|
path: route.path,
|
|
2366
1673
|
index: route.index,
|
|
2367
1674
|
caseSensitive: route.caseSensitive,
|
|
2368
|
-
module:
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
1675
|
+
module: combineURLs(
|
|
1676
|
+
ctx.publicPath,
|
|
1677
|
+
resolveFileUrl(
|
|
1678
|
+
ctx,
|
|
1679
|
+
resolveRelativeRouteFilePath(route, ctx.reactRouterConfig)
|
|
1680
|
+
)
|
|
1681
|
+
),
|
|
2373
1682
|
hasAction: sourceExports.includes("action"),
|
|
2374
1683
|
hasLoader: sourceExports.includes("loader"),
|
|
2375
|
-
hasClientAction,
|
|
2376
|
-
hasClientLoader,
|
|
1684
|
+
hasClientAction: sourceExports.includes("clientAction"),
|
|
1685
|
+
hasClientLoader: sourceExports.includes("clientLoader"),
|
|
2377
1686
|
hasErrorBoundary: sourceExports.includes("ErrorBoundary"),
|
|
2378
1687
|
imports: []
|
|
2379
1688
|
};
|
|
@@ -2406,13 +1715,8 @@ var reactRouterVitePlugin = () => {
|
|
|
2406
1715
|
let viteClientConditions = [
|
|
2407
1716
|
...vite2.defaultClientConditions ?? []
|
|
2408
1717
|
];
|
|
2409
|
-
let packageRoot = path6.dirname(
|
|
2410
|
-
require.resolve("@react-router/dev/package.json")
|
|
2411
|
-
);
|
|
2412
|
-
let { moduleSyncEnabled } = await import(`file:///${path6.join(packageRoot, "module-sync-enabled/index.mjs")}`);
|
|
2413
1718
|
let viteServerConditions = [
|
|
2414
|
-
...vite2.defaultServerConditions ?? []
|
|
2415
|
-
...moduleSyncEnabled ? ["module-sync"] : []
|
|
1719
|
+
...vite2.defaultServerConditions ?? []
|
|
2416
1720
|
];
|
|
2417
1721
|
logger = vite2.createLogger(viteUserConfig.logLevel, {
|
|
2418
1722
|
prefix: "[react-router]"
|
|
@@ -2526,28 +1830,12 @@ var reactRouterVitePlugin = () => {
|
|
|
2526
1830
|
preserveEntrySignatures: "exports-only",
|
|
2527
1831
|
input: [
|
|
2528
1832
|
ctx.entryClientFilePath,
|
|
2529
|
-
...Object.values(
|
|
2530
|
-
|
|
2531
|
-
).flatMap((route) => {
|
|
2532
|
-
let routeFilePath = path6.resolve(
|
|
1833
|
+
...Object.values(ctx.reactRouterConfig.routes).map(
|
|
1834
|
+
(route) => `${path6.resolve(
|
|
2533
1835
|
ctx.reactRouterConfig.appDirectory,
|
|
2534
1836
|
route.file
|
|
2535
|
-
)
|
|
2536
|
-
|
|
2537
|
-
let code = fse.readFileSync(
|
|
2538
|
-
routeFilePath,
|
|
2539
|
-
"utf-8"
|
|
2540
|
-
);
|
|
2541
|
-
return [
|
|
2542
|
-
`${routeFilePath}${BUILD_CLIENT_ROUTE_QUERY_STRING}`,
|
|
2543
|
-
...ctx.reactRouterConfig.future.unstable_splitRouteModules && !isRootRoute ? routeChunkExportNames.map(
|
|
2544
|
-
(exportName) => code.includes(exportName) ? getRouteChunkModuleId(
|
|
2545
|
-
routeFilePath,
|
|
2546
|
-
exportName
|
|
2547
|
-
) : null
|
|
2548
|
-
) : []
|
|
2549
|
-
].filter(isNonNullable);
|
|
2550
|
-
})
|
|
1837
|
+
)}${BUILD_CLIENT_ROUTE_QUERY_STRING}`
|
|
1838
|
+
)
|
|
2551
1839
|
]
|
|
2552
1840
|
}
|
|
2553
1841
|
} : {
|
|
@@ -2815,59 +2103,10 @@ var reactRouterVitePlugin = () => {
|
|
|
2815
2103
|
await typegenWatcher?.close();
|
|
2816
2104
|
}
|
|
2817
2105
|
},
|
|
2818
|
-
{
|
|
2819
|
-
name: "react-router:route-chunks-index",
|
|
2820
|
-
// This plugin provides the route module "index" since route modules can
|
|
2821
|
-
// be chunked and may be made up of multiple smaller modules. This plugin
|
|
2822
|
-
// primarily ensures code is never duplicated across a route module and
|
|
2823
|
-
// its chunks. If we didn't have this plugin, any app that explicitly
|
|
2824
|
-
// imports a route module would result in duplicate code since the app
|
|
2825
|
-
// would contain code for both the unprocessed route module as well as its
|
|
2826
|
-
// individual chunks. This is because, since they have different module
|
|
2827
|
-
// IDs, they are treated as completely separate modules even though they
|
|
2828
|
-
// all reference the same underlying file. This plugin addresses this by
|
|
2829
|
-
// ensuring that any explicit imports of a route module resolve to a
|
|
2830
|
-
// module that simply re-exports from its underlying chunks, if present.
|
|
2831
|
-
async transform(code, id, options) {
|
|
2832
|
-
if (viteCommand !== "build") return;
|
|
2833
|
-
if (options?.ssr) {
|
|
2834
|
-
return;
|
|
2835
|
-
}
|
|
2836
|
-
if (!isRoute(ctx.reactRouterConfig, id)) {
|
|
2837
|
-
return;
|
|
2838
|
-
}
|
|
2839
|
-
if (isRouteVirtualModule(id)) {
|
|
2840
|
-
return;
|
|
2841
|
-
}
|
|
2842
|
-
let { hasRouteChunks, chunkedExports } = await detectRouteChunksIfEnabled(cache, ctx, id, code);
|
|
2843
|
-
if (!hasRouteChunks) {
|
|
2844
|
-
return;
|
|
2845
|
-
}
|
|
2846
|
-
let sourceExports = await getRouteModuleExports(
|
|
2847
|
-
viteChildCompiler,
|
|
2848
|
-
ctx,
|
|
2849
|
-
id
|
|
2850
|
-
);
|
|
2851
|
-
let isMainChunkExport = (name) => !chunkedExports.includes(name);
|
|
2852
|
-
let mainChunkReexports = sourceExports.filter(isMainChunkExport).join(", ");
|
|
2853
|
-
let chunkBasePath = `./${path6.basename(id)}`;
|
|
2854
|
-
return [
|
|
2855
|
-
`export { ${mainChunkReexports} } from "${getRouteChunkModuleId(
|
|
2856
|
-
chunkBasePath,
|
|
2857
|
-
"main"
|
|
2858
|
-
)}";`,
|
|
2859
|
-
...chunkedExports.map(
|
|
2860
|
-
(exportName) => `export { ${exportName} } from "${getRouteChunkModuleId(
|
|
2861
|
-
chunkBasePath,
|
|
2862
|
-
exportName
|
|
2863
|
-
)}";`
|
|
2864
|
-
)
|
|
2865
|
-
].filter(Boolean).join("\n");
|
|
2866
|
-
}
|
|
2867
|
-
},
|
|
2868
2106
|
{
|
|
2869
2107
|
name: "react-router:build-client-route",
|
|
2870
|
-
|
|
2108
|
+
enforce: "pre",
|
|
2109
|
+
async transform(_code, id, options) {
|
|
2871
2110
|
if (!id.endsWith(BUILD_CLIENT_ROUTE_QUERY_STRING)) return;
|
|
2872
2111
|
let routeModuleId = id.replace(BUILD_CLIENT_ROUTE_QUERY_STRING, "");
|
|
2873
2112
|
let routeFileName = path6.basename(routeModuleId);
|
|
@@ -2876,53 +2115,12 @@ var reactRouterVitePlugin = () => {
|
|
|
2876
2115
|
ctx,
|
|
2877
2116
|
routeModuleId
|
|
2878
2117
|
);
|
|
2879
|
-
let
|
|
2880
|
-
|
|
2881
|
-
|
|
2882
|
-
let isChunkedExport = chunkedExports.includes(
|
|
2883
|
-
exportName
|
|
2884
|
-
);
|
|
2885
|
-
return isRouteEntryExport && !isChunkedExport;
|
|
2886
|
-
}).join(", ");
|
|
2118
|
+
let reexports = sourceExports.filter(
|
|
2119
|
+
(exportName) => options?.ssr && SERVER_ONLY_ROUTE_EXPORTS.includes(exportName) || CLIENT_ROUTE_EXPORTS.includes(exportName)
|
|
2120
|
+
).join(", ");
|
|
2887
2121
|
return `export { ${reexports} } from "./${routeFileName}";`;
|
|
2888
2122
|
}
|
|
2889
2123
|
},
|
|
2890
|
-
{
|
|
2891
|
-
name: "react-router:route-chunks",
|
|
2892
|
-
async transform(code, id, options) {
|
|
2893
|
-
if (options?.ssr) return;
|
|
2894
|
-
if (!isRouteChunkModuleId(id)) return;
|
|
2895
|
-
let chunkName = getRouteChunkNameFromModuleId(id);
|
|
2896
|
-
if (!chunkName) {
|
|
2897
|
-
throw new Error(`Invalid route chunk name "${chunkName}" in "${id}"`);
|
|
2898
|
-
}
|
|
2899
|
-
let chunk = await getRouteChunkIfEnabled(
|
|
2900
|
-
cache,
|
|
2901
|
-
ctx,
|
|
2902
|
-
id,
|
|
2903
|
-
chunkName,
|
|
2904
|
-
code
|
|
2905
|
-
);
|
|
2906
|
-
let preventEmptyChunkSnippet = ({ reason }) => `Math.random()<0&&console.log(${JSON.stringify(reason)});`;
|
|
2907
|
-
if (chunk === null) {
|
|
2908
|
-
return preventEmptyChunkSnippet({ reason: "Route chunks disabled" });
|
|
2909
|
-
}
|
|
2910
|
-
let enforceSplitRouteModules = ctx.reactRouterConfig.future.unstable_splitRouteModules === "enforce";
|
|
2911
|
-
if (enforceSplitRouteModules && chunkName === "main" && chunk) {
|
|
2912
|
-
let exportNames = getExportNames(chunk.code);
|
|
2913
|
-
validateRouteChunks({
|
|
2914
|
-
ctx,
|
|
2915
|
-
id,
|
|
2916
|
-
valid: {
|
|
2917
|
-
clientAction: !exportNames.includes("clientAction"),
|
|
2918
|
-
clientLoader: !exportNames.includes("clientLoader"),
|
|
2919
|
-
HydrateFallback: !exportNames.includes("HydrateFallback")
|
|
2920
|
-
}
|
|
2921
|
-
});
|
|
2922
|
-
}
|
|
2923
|
-
return chunk ?? preventEmptyChunkSnippet({ reason: `No ${chunkName} chunk` });
|
|
2924
|
-
}
|
|
2925
|
-
},
|
|
2926
2124
|
{
|
|
2927
2125
|
name: "react-router:virtual-modules",
|
|
2928
2126
|
enforce: "pre",
|
|
@@ -2977,7 +2175,8 @@ var reactRouterVitePlugin = () => {
|
|
|
2977
2175
|
let importerShort = vite2.normalizePath(
|
|
2978
2176
|
path6.relative(ctx.rootDirectory, importer)
|
|
2979
2177
|
);
|
|
2980
|
-
|
|
2178
|
+
let isRoute = getRoute(ctx.reactRouterConfig, importer);
|
|
2179
|
+
if (isRoute) {
|
|
2981
2180
|
let serverOnlyExports = SERVER_ONLY_ROUTE_EXPORTS.map(
|
|
2982
2181
|
(xport) => `\`${xport}\``
|
|
2983
2182
|
).join(", ");
|
|
@@ -3016,10 +2215,10 @@ var reactRouterVitePlugin = () => {
|
|
|
3016
2215
|
let clientFileRE = /\.client(\.[cm]?[jt]sx?)?$/;
|
|
3017
2216
|
let clientDirRE = /\/\.client\//;
|
|
3018
2217
|
if (clientFileRE.test(id) || clientDirRE.test(id)) {
|
|
3019
|
-
let exports2 =
|
|
2218
|
+
let exports2 = (0, import_es_module_lexer.parse)(code)[1];
|
|
3020
2219
|
return {
|
|
3021
2220
|
code: exports2.map(
|
|
3022
|
-
(name) => name === "default" ? "export default undefined;" : `export const ${name} = undefined;`
|
|
2221
|
+
({ n: name }) => name === "default" ? "export default undefined;" : `export const ${name} = undefined;`
|
|
3023
2222
|
).join("\n"),
|
|
3024
2223
|
map: null
|
|
3025
2224
|
};
|
|
@@ -3030,25 +2229,17 @@ var reactRouterVitePlugin = () => {
|
|
|
3030
2229
|
{
|
|
3031
2230
|
name: "react-router:route-exports",
|
|
3032
2231
|
async transform(code, id, options) {
|
|
3033
|
-
if (isRouteChunkModuleId(id)) {
|
|
3034
|
-
id = id.split("?")[0];
|
|
3035
|
-
}
|
|
3036
2232
|
let route = getRoute(ctx.reactRouterConfig, id);
|
|
3037
2233
|
if (!route) return;
|
|
3038
2234
|
if (!options?.ssr && !ctx.reactRouterConfig.ssr) {
|
|
3039
|
-
let
|
|
3040
|
-
let serverOnlyExports = exportNames.filter(
|
|
3041
|
-
(exp) => SERVER_ONLY_ROUTE_EXPORTS.includes(exp)
|
|
3042
|
-
);
|
|
2235
|
+
let serverOnlyExports = (0, import_es_module_lexer.parse)(code)[1].map((exp) => exp.n).filter((exp) => SERVER_ONLY_ROUTE_EXPORTS.includes(exp));
|
|
3043
2236
|
if (serverOnlyExports.length > 0) {
|
|
3044
2237
|
let str = serverOnlyExports.map((e) => `\`${e}\``).join(", ");
|
|
3045
2238
|
let message = `SPA Mode: ${serverOnlyExports.length} invalid route export(s) in \`${route.file}\`: ${str}. See https://remix.run/guides/spa-mode for more information.`;
|
|
3046
2239
|
throw Error(message);
|
|
3047
2240
|
}
|
|
3048
2241
|
if (route.id !== "root") {
|
|
3049
|
-
let hasHydrateFallback =
|
|
3050
|
-
(exp) => exp === "HydrateFallback"
|
|
3051
|
-
);
|
|
2242
|
+
let hasHydrateFallback = (0, import_es_module_lexer.parse)(code)[1].map((exp) => exp.n).some((exp) => exp === "HydrateFallback");
|
|
3052
2243
|
if (hasHydrateFallback) {
|
|
3053
2244
|
let message = `SPA Mode: Invalid \`HydrateFallback\` export found in \`${route.file}\`. \`HydrateFallback\` is only permitted on the root route in SPA Mode. See https://remix.run/guides/spa-mode for more information.`;
|
|
3054
2245
|
throw Error(message);
|
|
@@ -3126,9 +2317,6 @@ var reactRouterVitePlugin = () => {
|
|
|
3126
2317
|
let isJSX = filepath.endsWith("x");
|
|
3127
2318
|
let useFastRefresh = !ssr && (isJSX || code.includes(devRuntime));
|
|
3128
2319
|
if (!useFastRefresh) return;
|
|
3129
|
-
if (isRouteVirtualModule(id)) {
|
|
3130
|
-
return { code: addRefreshWrapper(ctx.reactRouterConfig, code, id) };
|
|
3131
|
-
}
|
|
3132
2320
|
let result = await babel.transformAsync(code, {
|
|
3133
2321
|
babelrc: false,
|
|
3134
2322
|
configFile: false,
|
|
@@ -3159,7 +2347,6 @@ var reactRouterVitePlugin = () => {
|
|
|
3159
2347
|
let serverManifest = (await server.ssrLoadModule(virtual.serverManifest.id)).default;
|
|
3160
2348
|
let oldRouteMetadata = serverManifest.routes[route.id];
|
|
3161
2349
|
let newRouteMetadata = await getRouteMetadata(
|
|
3162
|
-
cache,
|
|
3163
2350
|
ctx,
|
|
3164
2351
|
viteChildCompiler,
|
|
3165
2352
|
route,
|
|
@@ -3169,12 +2356,9 @@ var reactRouterVitePlugin = () => {
|
|
|
3169
2356
|
if (!oldRouteMetadata || [
|
|
3170
2357
|
"hasLoader",
|
|
3171
2358
|
"hasClientLoader",
|
|
3172
|
-
"clientLoaderModule",
|
|
3173
2359
|
"hasAction",
|
|
3174
2360
|
"hasClientAction",
|
|
3175
|
-
"
|
|
3176
|
-
"hasErrorBoundary",
|
|
3177
|
-
"hydrateFallbackModule"
|
|
2361
|
+
"hasErrorBoundary"
|
|
3178
2362
|
].some((key) => oldRouteMetadata[key] !== newRouteMetadata[key])) {
|
|
3179
2363
|
invalidateVirtualModules(server);
|
|
3180
2364
|
}
|
|
@@ -3292,30 +2476,13 @@ function getRoute(pluginConfig, file) {
|
|
|
3292
2476
|
);
|
|
3293
2477
|
return route;
|
|
3294
2478
|
}
|
|
3295
|
-
function
|
|
3296
|
-
return Boolean(getRoute(pluginConfig, file));
|
|
3297
|
-
}
|
|
3298
|
-
async function getRouteMetadata(cache, ctx, viteChildCompiler, route, readRouteFile) {
|
|
3299
|
-
let routeFile = route.file;
|
|
2479
|
+
async function getRouteMetadata(ctx, viteChildCompiler, route, readRouteFile) {
|
|
3300
2480
|
let sourceExports = await getRouteModuleExports(
|
|
3301
2481
|
viteChildCompiler,
|
|
3302
2482
|
ctx,
|
|
3303
2483
|
route.file,
|
|
3304
2484
|
readRouteFile
|
|
3305
2485
|
);
|
|
3306
|
-
let { hasRouteChunkByExportName } = await detectRouteChunksIfEnabled(
|
|
3307
|
-
cache,
|
|
3308
|
-
ctx,
|
|
3309
|
-
routeFile,
|
|
3310
|
-
{ routeFile, readRouteFile, viteChildCompiler }
|
|
3311
|
-
);
|
|
3312
|
-
let moduleUrl = combineURLs(
|
|
3313
|
-
ctx.publicPath,
|
|
3314
|
-
`${resolveFileUrl(
|
|
3315
|
-
ctx,
|
|
3316
|
-
resolveRelativeRouteFilePath(route, ctx.reactRouterConfig)
|
|
3317
|
-
)}`
|
|
3318
|
-
);
|
|
3319
2486
|
let info = {
|
|
3320
2487
|
id: route.id,
|
|
3321
2488
|
parentId: route.parentId,
|
|
@@ -3329,11 +2496,14 @@ async function getRouteMetadata(cache, ctx, viteChildCompiler, route, readRouteF
|
|
|
3329
2496
|
resolveRelativeRouteFilePath(route, ctx.reactRouterConfig)
|
|
3330
2497
|
)
|
|
3331
2498
|
),
|
|
3332
|
-
module:
|
|
2499
|
+
module: combineURLs(
|
|
2500
|
+
ctx.publicPath,
|
|
2501
|
+
`${resolveFileUrl(
|
|
2502
|
+
ctx,
|
|
2503
|
+
resolveRelativeRouteFilePath(route, ctx.reactRouterConfig)
|
|
2504
|
+
)}?import`
|
|
2505
|
+
),
|
|
3333
2506
|
// Ensure the Vite dev server responds with a JS module
|
|
3334
|
-
clientActionModule: hasRouteChunkByExportName.clientAction ? `${getRouteChunkModuleId(moduleUrl, "clientAction")}` : void 0,
|
|
3335
|
-
clientLoaderModule: hasRouteChunkByExportName.clientLoader ? `${getRouteChunkModuleId(moduleUrl, "clientLoader")}` : void 0,
|
|
3336
|
-
hydrateFallbackModule: hasRouteChunkByExportName.HydrateFallback ? `${getRouteChunkModuleId(moduleUrl, "HydrateFallback")}` : void 0,
|
|
3337
2507
|
hasAction: sourceExports.includes("action"),
|
|
3338
2508
|
hasClientAction: sourceExports.includes("clientAction"),
|
|
3339
2509
|
hasLoader: sourceExports.includes("loader"),
|
|
@@ -3582,73 +2752,6 @@ function createPrerenderRoutes(manifest, parentId = "", routesByParentId = group
|
|
|
3582
2752
|
};
|
|
3583
2753
|
});
|
|
3584
2754
|
}
|
|
3585
|
-
var resolveRouteFileCode = async (ctx, input) => {
|
|
3586
|
-
if (typeof input === "string") return input;
|
|
3587
|
-
invariant(input.viteChildCompiler);
|
|
3588
|
-
return await compileRouteFile(
|
|
3589
|
-
input.viteChildCompiler,
|
|
3590
|
-
ctx,
|
|
3591
|
-
input.routeFile,
|
|
3592
|
-
input.readRouteFile
|
|
3593
|
-
);
|
|
3594
|
-
};
|
|
3595
|
-
async function detectRouteChunksIfEnabled(cache, ctx, id, input) {
|
|
3596
|
-
function noRouteChunks() {
|
|
3597
|
-
return {
|
|
3598
|
-
chunkedExports: [],
|
|
3599
|
-
hasRouteChunks: false,
|
|
3600
|
-
hasRouteChunkByExportName: {
|
|
3601
|
-
clientAction: false,
|
|
3602
|
-
clientLoader: false,
|
|
3603
|
-
HydrateFallback: false
|
|
3604
|
-
}
|
|
3605
|
-
};
|
|
3606
|
-
}
|
|
3607
|
-
if (!ctx.reactRouterConfig.future.unstable_splitRouteModules) {
|
|
3608
|
-
return noRouteChunks();
|
|
3609
|
-
}
|
|
3610
|
-
if (normalizeRelativeFilePath(id, ctx.reactRouterConfig) === ctx.reactRouterConfig.routes.root.file) {
|
|
3611
|
-
return noRouteChunks();
|
|
3612
|
-
}
|
|
3613
|
-
let code = await resolveRouteFileCode(ctx, input);
|
|
3614
|
-
if (!routeChunkExportNames.some((exportName) => code.includes(exportName))) {
|
|
3615
|
-
return noRouteChunks();
|
|
3616
|
-
}
|
|
3617
|
-
let cacheKey = normalizeRelativeFilePath(id, ctx.reactRouterConfig) + (typeof input === "string" ? "" : "?read");
|
|
3618
|
-
return detectRouteChunks(code, cache, cacheKey);
|
|
3619
|
-
}
|
|
3620
|
-
async function getRouteChunkIfEnabled(cache, ctx, id, chunkName, input) {
|
|
3621
|
-
if (!ctx.reactRouterConfig.future.unstable_splitRouteModules) {
|
|
3622
|
-
return null;
|
|
3623
|
-
}
|
|
3624
|
-
let code = await resolveRouteFileCode(ctx, input);
|
|
3625
|
-
let cacheKey = normalizeRelativeFilePath(id, ctx.reactRouterConfig) + (typeof input === "string" ? "" : "?read");
|
|
3626
|
-
return getRouteChunkCode(code, chunkName, cache, cacheKey);
|
|
3627
|
-
}
|
|
3628
|
-
function validateRouteChunks({
|
|
3629
|
-
ctx,
|
|
3630
|
-
id,
|
|
3631
|
-
valid
|
|
3632
|
-
}) {
|
|
3633
|
-
let invalidChunks = Object.entries(valid).filter(([_, isValid]) => !isValid).map(([chunkName]) => chunkName);
|
|
3634
|
-
if (invalidChunks.length === 0) {
|
|
3635
|
-
return;
|
|
3636
|
-
}
|
|
3637
|
-
let plural = invalidChunks.length > 1;
|
|
3638
|
-
throw new Error(
|
|
3639
|
-
[
|
|
3640
|
-
`Error splitting route module: ${normalizeRelativeFilePath(
|
|
3641
|
-
id,
|
|
3642
|
-
ctx.reactRouterConfig
|
|
3643
|
-
)}`,
|
|
3644
|
-
invalidChunks.map((name) => `- ${name}`).join("\n"),
|
|
3645
|
-
`${plural ? "These exports" : "This export"} could not be split into ${plural ? "their own chunks" : "its own chunk"} because ${plural ? "they share" : "it shares"} code with other exports. You should extract any shared code into its own module and then import it within the route module.`
|
|
3646
|
-
].join("\n\n")
|
|
3647
|
-
);
|
|
3648
|
-
}
|
|
3649
|
-
function isNonNullable(x) {
|
|
3650
|
-
return x != null;
|
|
3651
|
-
}
|
|
3652
2755
|
// Annotate the CommonJS export names for ESM import in node:
|
|
3653
2756
|
0 && (module.exports = {
|
|
3654
2757
|
reactRouter
|