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