@react-router/dev 0.0.0-experimental-6b51a129b → 0.0.0-experimental-345f1da12

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  /**
3
- * @react-router/dev v0.0.0-experimental-6b51a129b
3
+ * @react-router/dev v0.0.0-experimental-345f1da12
4
4
  *
5
5
  * Copyright (c) Remix Software Inc.
6
6
  *
@@ -55,26 +55,55 @@ var init_invariant = __esm({
55
55
  }
56
56
  });
57
57
 
58
- // vite/import-vite-esm-sync.ts
59
- async function preloadViteEsm() {
60
- vite = await import("vite");
58
+ // config/is-react-router-repo.ts
59
+ function isReactRouterRepo() {
60
+ let serverRuntimePath = import_pathe.default.dirname(
61
+ require.resolve("@react-router/node/package.json")
62
+ );
63
+ let serverRuntimeParentDir = import_pathe.default.basename(
64
+ import_pathe.default.resolve(serverRuntimePath, "..")
65
+ );
66
+ return serverRuntimeParentDir === "packages";
67
+ }
68
+ var import_pathe;
69
+ var init_is_react_router_repo = __esm({
70
+ "config/is-react-router-repo.ts"() {
71
+ "use strict";
72
+ import_pathe = __toESM(require("pathe"));
73
+ }
74
+ });
75
+
76
+ // vite/vite.ts
77
+ async function preloadVite() {
78
+ vite = await import(viteImportSpecifier);
61
79
  }
62
- function importViteEsmSync() {
63
- invariant(vite, "importViteEsmSync() called before preloadViteEsm()");
80
+ function getVite() {
81
+ invariant(vite, "getVite() called before preloadVite()");
64
82
  return vite;
65
83
  }
66
- var vite;
67
- var init_import_vite_esm_sync = __esm({
68
- "vite/import-vite-esm-sync.ts"() {
84
+ var import_pathe2, vite, viteImportSpecifier;
85
+ var init_vite = __esm({
86
+ "vite/vite.ts"() {
69
87
  "use strict";
88
+ import_pathe2 = __toESM(require("pathe"));
70
89
  init_invariant();
90
+ init_is_react_router_repo();
91
+ viteImportSpecifier = isReactRouterRepo() ? (
92
+ // Support testing against different versions of Vite by ensuring that Vite
93
+ // is resolved from the current working directory when running within this
94
+ // repo. If we don't do this, Vite will always be imported relative to this
95
+ // file, which means that it will always resolve to Vite 6.
96
+ `file:///${import_pathe2.default.normalize(
97
+ require.resolve("vite/package.json", { paths: [process.cwd()] })
98
+ ).replace("package.json", "dist/node/index.js")}`
99
+ ) : "vite";
71
100
  }
72
101
  });
73
102
 
74
103
  // vite/vite-node.ts
75
104
  async function createContext(viteConfig = {}) {
76
- await preloadViteEsm();
77
- const vite2 = importViteEsmSync();
105
+ await preloadVite();
106
+ const vite2 = getVite();
78
107
  const devServer = await vite2.createServer(
79
108
  vite2.mergeConfig(
80
109
  {
@@ -100,11 +129,11 @@ async function createContext(viteConfig = {}) {
100
129
  const runner = new import_client.ViteNodeRunner({
101
130
  root: devServer.config.root,
102
131
  base: devServer.config.base,
103
- fetchModule(id2) {
104
- return server.fetchModule(id2);
132
+ fetchModule(id) {
133
+ return server.fetchModule(id);
105
134
  },
106
- resolveId(id2, importer) {
107
- return server.resolveId(id2, importer);
135
+ resolveId(id, importer) {
136
+ return server.resolveId(id, importer);
108
137
  }
109
138
  });
110
139
  return { devServer, server, runner };
@@ -116,7 +145,7 @@ var init_vite_node = __esm({
116
145
  import_server = require("vite-node/server");
117
146
  import_client = require("vite-node/client");
118
147
  import_source_map = require("vite-node/source-map");
119
- init_import_vite_esm_sync();
148
+ init_vite();
120
149
  }
121
150
  });
122
151
 
@@ -149,7 +178,7 @@ function validateRouteConfig({
149
178
  `Route config in "${routeConfigFile}" is invalid.`,
150
179
  root ? `${root}` : [],
151
180
  nested ? Object.entries(nested).map(
152
- ([path8, message]) => `Path: routes.${path8}
181
+ ([path10, message]) => `Path: routes.${path10}
153
182
  ${message}`
154
183
  ) : []
155
184
  ].flat().join("\n\n")
@@ -160,24 +189,24 @@ ${message}`
160
189
  function configRoutesToRouteManifest(appDirectory, routes2, rootId = "root") {
161
190
  let routeManifest = {};
162
191
  function walk(route, parentId) {
163
- let id2 = route.id || createRouteId(route.file);
192
+ let id = route.id || createRouteId(route.file);
164
193
  let manifestItem = {
165
- id: id2,
194
+ id,
166
195
  parentId,
167
196
  file: Path.isAbsolute(route.file) ? Path.relative(appDirectory, route.file) : route.file,
168
197
  path: route.path,
169
198
  index: route.index,
170
199
  caseSensitive: route.caseSensitive
171
200
  };
172
- if (routeManifest.hasOwnProperty(id2)) {
201
+ if (routeManifest.hasOwnProperty(id)) {
173
202
  throw new Error(
174
- `Unable to define routes with duplicate route id: "${id2}"`
203
+ `Unable to define routes with duplicate route id: "${id}"`
175
204
  );
176
205
  }
177
- routeManifest[id2] = manifestItem;
206
+ routeManifest[id] = manifestItem;
178
207
  if (route.children) {
179
208
  for (let child of route.children) {
180
- walk(child, id2);
209
+ walk(child, id);
181
210
  }
182
211
  }
183
212
  }
@@ -307,13 +336,13 @@ async function resolveConfig({
307
336
  "The `prerender` config must be a boolean, an array of string paths, or a function returning a boolean or array of string paths"
308
337
  );
309
338
  }
310
- let appDirectory = import_pathe.default.resolve(root, userAppDirectory || "app");
311
- let buildDirectory = import_pathe.default.resolve(root, userBuildDirectory);
339
+ let appDirectory = import_pathe3.default.resolve(root, userAppDirectory || "app");
340
+ let buildDirectory = import_pathe3.default.resolve(root, userBuildDirectory);
312
341
  let rootRouteFile = findEntry(appDirectory, "root");
313
342
  if (!rootRouteFile) {
314
- let rootRouteDisplayPath = import_pathe.default.relative(
343
+ let rootRouteDisplayPath = import_pathe3.default.relative(
315
344
  root,
316
- import_pathe.default.join(appDirectory, "root.tsx")
345
+ import_pathe3.default.join(appDirectory, "root.tsx")
317
346
  );
318
347
  return err(
319
348
  `Could not find a root route module in the app directory as "${rootRouteDisplayPath}"`
@@ -325,15 +354,15 @@ async function resolveConfig({
325
354
  let routeConfigFile = findEntry(appDirectory, "routes");
326
355
  try {
327
356
  if (!routeConfigFile) {
328
- let routeConfigDisplayPath = import_pathe.default.relative(
357
+ let routeConfigDisplayPath = import_pathe3.default.relative(
329
358
  root,
330
- import_pathe.default.join(appDirectory, "routes.ts")
359
+ import_pathe3.default.join(appDirectory, "routes.ts")
331
360
  );
332
361
  return err(`Route config file not found at "${routeConfigDisplayPath}".`);
333
362
  }
334
363
  setAppDirectory(appDirectory);
335
364
  let routeConfigExport = (await viteNodeContext.runner.executeFile(
336
- import_pathe.default.join(appDirectory, routeConfigFile)
365
+ import_pathe3.default.join(appDirectory, routeConfigFile)
337
366
  )).default;
338
367
  let routeConfig = await routeConfigExport;
339
368
  let result = validateRouteConfig({
@@ -353,7 +382,7 @@ async function resolveConfig({
353
382
  import_picocolors.default.red(`Route config in "${routeConfigFile}" is invalid.`),
354
383
  "",
355
384
  error.loc?.file && error.loc?.column && error.frame ? [
356
- import_pathe.default.relative(appDirectory, error.loc.file) + ":" + error.loc.line + ":" + error.loc.column,
385
+ import_pathe3.default.relative(appDirectory, error.loc.file) + ":" + error.loc.line + ":" + error.loc.column,
357
386
  error.frame.trim?.()
358
387
  ] : error.stack
359
388
  ].flat().join("\n")
@@ -425,8 +454,8 @@ async function createConfigLoader({
425
454
  );
426
455
  fsWatcher.on("all", async (...args) => {
427
456
  let [event, rawFilepath] = args;
428
- let filepath = import_pathe.default.normalize(rawFilepath);
429
- let appFileAddedOrRemoved = appDirectory && (event === "add" || event === "unlink") && filepath.startsWith(import_pathe.default.normalize(appDirectory));
457
+ let filepath = import_pathe3.default.normalize(rawFilepath);
458
+ let appFileAddedOrRemoved = appDirectory && (event === "add" || event === "unlink") && filepath.startsWith(import_pathe3.default.normalize(appDirectory));
430
459
  let configCodeUpdated = Boolean(
431
460
  viteNodeContext.devServer?.moduleGraph.getModuleById(filepath)
432
461
  );
@@ -467,25 +496,16 @@ async function createConfigLoader({
467
496
  }
468
497
  };
469
498
  }
470
- function isInReactRouterMonorepo() {
471
- let serverRuntimePath = import_pathe.default.dirname(
472
- require.resolve("@react-router/node/package.json")
473
- );
474
- let serverRuntimeParentDir = import_pathe.default.basename(
475
- import_pathe.default.resolve(serverRuntimePath, "..")
476
- );
477
- return serverRuntimeParentDir === "packages";
478
- }
479
499
  function findEntry(dir, basename2, options) {
480
500
  for (let ext of entryExts) {
481
- let file = import_pathe.default.resolve(dir, basename2 + ext);
501
+ let file = import_pathe3.default.resolve(dir, basename2 + ext);
482
502
  if (import_node_fs.default.existsSync(file)) {
483
- return options?.absolute ?? false ? file : import_pathe.default.relative(dir, file);
503
+ return options?.absolute ?? false ? file : import_pathe3.default.relative(dir, file);
484
504
  }
485
505
  }
486
506
  return void 0;
487
507
  }
488
- var import_node_fs, import_node_child_process, import_package_json, import_pathe, import_chokidar, import_picocolors, import_pick2, import_omit, import_cloneDeep, import_isEqual, excludedConfigPresetKeys, branchRouteProperties, configRouteToBranchRoute, mergeReactRouterConfig, deepFreeze, ssrExternals, entryExts;
508
+ var import_node_fs, import_node_child_process, import_package_json, import_pathe3, import_chokidar, import_picocolors, import_pick2, import_omit, import_cloneDeep, import_isEqual, excludedConfigPresetKeys, branchRouteProperties, configRouteToBranchRoute, mergeReactRouterConfig, deepFreeze, ssrExternals, entryExts;
489
509
  var init_config = __esm({
490
510
  "config/config.ts"() {
491
511
  "use strict";
@@ -493,7 +513,7 @@ var init_config = __esm({
493
513
  import_node_child_process = require("child_process");
494
514
  import_package_json = __toESM(require("@npmcli/package-json"));
495
515
  init_vite_node();
496
- import_pathe = __toESM(require("pathe"));
516
+ import_pathe3 = __toESM(require("pathe"));
497
517
  import_chokidar = __toESM(require("chokidar"));
498
518
  import_picocolors = __toESM(require("picocolors"));
499
519
  import_pick2 = __toESM(require("lodash/pick"));
@@ -502,6 +522,7 @@ var init_config = __esm({
502
522
  import_isEqual = __toESM(require("lodash/isEqual"));
503
523
  init_routes();
504
524
  init_detectPackageManager();
525
+ init_is_react_router_repo();
505
526
  excludedConfigPresetKeys = ["presets"];
506
527
  branchRouteProperties = [
507
528
  "id",
@@ -548,7 +569,7 @@ var init_config = __esm({
548
569
  });
549
570
  return o;
550
571
  };
551
- ssrExternals = isInReactRouterMonorepo() ? [
572
+ ssrExternals = isReactRouterRepo() ? [
552
573
  // This is only needed within this repo because these packages
553
574
  // are linked to a directory outside of node_modules so Vite
554
575
  // treats them as internal code by default.
@@ -565,141 +586,67 @@ var init_config = __esm({
565
586
  }
566
587
  });
567
588
 
568
- // typegen/paths.ts
569
- function getTypesDir(ctx) {
570
- return Path2.join(ctx.rootDirectory, ".react-router/types");
571
- }
572
- function getTypesPath(ctx, route) {
573
- return Path2.join(
574
- getTypesDir(ctx),
575
- Path2.relative(ctx.rootDirectory, ctx.config.appDirectory),
576
- Path2.dirname(route.file),
577
- "+types/" + Pathe.filename(route.file) + ".ts"
578
- );
579
- }
580
- var Path2, Pathe;
581
- var init_paths = __esm({
582
- "typegen/paths.ts"() {
583
- "use strict";
584
- Path2 = __toESM(require("pathe"));
585
- Pathe = __toESM(require("pathe/utils"));
586
- }
587
- });
588
-
589
589
  // typegen/generate.ts
590
- function generate(ctx, route) {
591
- const lineage = getRouteLineage(ctx.config.routes, route);
592
- const urlpath = lineage.map((route2) => route2.path).join("/");
593
- const typesPath = getTypesPath(ctx, route);
594
- const parents = lineage.slice(0, -1);
595
- const parentTypeImports = parents.map((parent, i) => {
596
- const rel = Path3.relative(
597
- Path3.dirname(typesPath),
598
- getTypesPath(ctx, parent)
599
- );
600
- const indent = i === 0 ? "" : " ".repeat(2);
601
- let source = noExtension(rel);
602
- if (!source.startsWith("../")) source = "./" + source;
603
- return `${indent}import type { Info as Parent${i} } from "${source}.js"`;
604
- }).join("\n");
590
+ function generate(route) {
605
591
  return import_dedent.default`
606
592
  // React Router generated types for route:
607
593
  // ${route.file}
608
594
 
609
- import type * as T from "react-router/route-module"
610
-
611
- ${parentTypeImports}
595
+ import type { RouteExports, Routes } from "react-router/types";
612
596
 
613
- type Module = typeof import("../${Pathe2.filename(route.file)}.js")
597
+ type RouteId = "${route.id}"
598
+ export type Info = Routes[RouteId];
614
599
 
615
- export type Info = {
616
- parents: [${parents.map((_, i) => `Parent${i}`).join(", ")}],
617
- id: "${route.id}"
618
- file: "${route.file}"
619
- path: "${route.path}"
620
- params: {${formatParamProperties(
621
- urlpath
622
- )}} & { [key: string]: string | undefined }
623
- module: Module
624
- loaderData: T.CreateLoaderData<Module>
625
- actionData: T.CreateActionData<Module>
626
- }
600
+ type Exports = RouteExports[RouteId];
627
601
 
628
602
  export namespace Route {
629
- export type LinkDescriptors = T.LinkDescriptors
630
- export type LinksFunction = () => LinkDescriptors
603
+ export type LinkDescriptors = Exports["links"]["return"];
604
+ export type LinksFunction = () => LinkDescriptors;
631
605
 
632
- export type MetaArgs = T.CreateMetaArgs<Info>
633
- export type MetaDescriptors = T.MetaDescriptors
634
- export type MetaFunction = (args: MetaArgs) => MetaDescriptors
606
+ export type MetaArgs = Exports["meta"]["args"];
607
+ export type MetaDescriptors = Exports["meta"]["return"];
608
+ export type MetaFunction = (args: MetaArgs) => MetaDescriptors;
635
609
 
636
- export type HeadersArgs = T.HeadersArgs
637
- export type HeadersFunction = (args: HeadersArgs) => Headers | HeadersInit
610
+ export type HeadersArgs = Exports["headers"]["args"];
611
+ export type HeadersFunction = (args: HeadersArgs) => Headers | HeadersInit;
638
612
 
639
- export type MiddlewareArgs = T.CreateServerMiddlewareArgs<Info>
640
- export type MiddlewareNextFunction = T.ServerMiddlewareNextFunction
641
- export type ClientMiddlewareArgs = T.CreateClientMiddlewareArgs<Info>
642
- export type ClientMiddlewareNextFunction = T.ClientMiddlewareNextFunction
643
- export type LoaderArgs = T.CreateServerLoaderArgs<Info>
644
- export type ClientLoaderArgs = T.CreateClientLoaderArgs<Info>
645
- export type ActionArgs = T.CreateServerActionArgs<Info>
646
- export type ClientActionArgs = T.CreateClientActionArgs<Info>
613
+ export type LoaderArgs = Exports["loader"]["args"];
614
+ export type ClientLoaderArgs = Exports["clientLoader"]["args"];
615
+ export type ActionArgs = Exports["action"]["args"];
616
+ export type ClientActionArgs = Exports["clientAction"]["args"];
647
617
 
648
- export type HydrateFallbackProps = T.CreateHydrateFallbackProps<Info>
649
- export type ComponentProps = T.CreateComponentProps<Info>
650
- export type ErrorBoundaryProps = T.CreateErrorBoundaryProps<Info>
618
+ export type HydrateFallbackProps = Exports["HydrateFallback"]["args"];
619
+ export type ComponentProps = Exports["default"]["args"];
620
+ export type ErrorBoundaryProps = Exports["ErrorBoundary"]["args"];
651
621
  }
652
622
  `;
653
623
  }
654
- function getRouteLineage(routes2, route) {
655
- const result = [];
656
- while (route) {
657
- result.push(route);
658
- if (!route.parentId) break;
659
- route = routes2[route.parentId];
660
- }
661
- result.reverse();
662
- return result;
663
- }
664
- function formatParamProperties(urlpath) {
665
- const params = parseParams(urlpath);
666
- const properties = Object.entries(params).map(([name, values]) => {
667
- if (values.length === 1) {
668
- const isOptional = values[0];
669
- return isOptional ? `"${name}"?: string` : `"${name}": string`;
670
- }
671
- const items = values.map(
672
- (isOptional) => isOptional ? "string | undefined" : "string"
673
- );
674
- return `"${name}": [${items.join(", ")}]`;
675
- });
676
- return properties.join("; ");
677
- }
678
- function parseParams(urlpath) {
679
- const result = {};
680
- let segments = urlpath.split("/");
681
- segments.forEach((segment) => {
682
- const match = segment.match(/^:([\w-]+)(\?)?/);
683
- if (!match) return;
684
- const param = match[1];
685
- const isOptional = match[2] !== void 0;
686
- result[param] ??= [];
687
- result[param].push(isOptional);
688
- return;
689
- });
690
- const hasSplat = segments.at(-1) === "*";
691
- if (hasSplat) result["*"] = [false];
692
- return result;
693
- }
694
- var import_dedent, Path3, Pathe2, noExtension;
624
+ var import_dedent;
695
625
  var init_generate = __esm({
696
626
  "typegen/generate.ts"() {
697
627
  "use strict";
698
628
  import_dedent = __toESM(require("dedent"));
699
- Path3 = __toESM(require("pathe"));
700
- Pathe2 = __toESM(require("pathe/utils"));
701
- init_paths();
702
- noExtension = (path8) => Path3.join(Path3.dirname(path8), Pathe2.filename(path8));
629
+ }
630
+ });
631
+
632
+ // typegen/paths.ts
633
+ function getTypesDir(ctx) {
634
+ return Path2.join(ctx.rootDirectory, ".react-router/types");
635
+ }
636
+ function getTypesPath(ctx, route) {
637
+ return Path2.join(
638
+ getTypesDir(ctx),
639
+ Path2.relative(ctx.rootDirectory, ctx.config.appDirectory),
640
+ Path2.dirname(route.file),
641
+ "+types/" + Pathe.filename(route.file) + ".ts"
642
+ );
643
+ }
644
+ var Path2, Pathe;
645
+ var init_paths = __esm({
646
+ "typegen/paths.ts"() {
647
+ "use strict";
648
+ Path2 = __toESM(require("pathe"));
649
+ Pathe = __toESM(require("pathe/utils"));
703
650
  }
704
651
  });
705
652
 
@@ -746,22 +693,100 @@ async function createContext2({
746
693
  config
747
694
  };
748
695
  }
696
+ function asJS(path10) {
697
+ return path10.replace(/\.(js|ts)x?$/, ".js");
698
+ }
699
+ function formatRoute({ id, path: path10, file, parentId }) {
700
+ return [
701
+ `"${id}": {`,
702
+ ` parentId: ${JSON.stringify(parentId)}`,
703
+ ` path: ${JSON.stringify(path10)}`,
704
+ ` module: typeof import("./app/${asJS(file)}")`,
705
+ `}`
706
+ ].map((line) => ` ${line}`).join("\n");
707
+ }
749
708
  async function writeAll(ctx) {
709
+ let routes2 = Object.values(ctx.config.routes);
710
+ let pathsToParams = /* @__PURE__ */ new Map();
711
+ for (let route of routes2) {
712
+ if (route.path === void 0) continue;
713
+ let lineage = getRouteLineage(ctx.config.routes, route);
714
+ let path10 = lineage.filter((route2) => route2.path !== void 0).map((route2) => route2.path).join("/");
715
+ if (path10 === "") path10 = "/";
716
+ pathsToParams.set(path10, parseParams(path10));
717
+ }
718
+ let formattedPaths = `type Paths = {`;
719
+ for (let [path10, params] of pathsToParams.entries()) {
720
+ let formattedParams = Object.entries(params).map(
721
+ ([param, required]) => `"${param}"${required ? "" : "?"}: string`
722
+ );
723
+ let formattedEntry = `"${path10}": {${formattedParams.join(",")}},
724
+ `;
725
+ formattedPaths += formattedEntry;
726
+ }
727
+ formattedPaths += `}`;
750
728
  const typegenDir = getTypesDir(ctx);
751
729
  import_node_fs2.default.rmSync(typegenDir, { recursive: true, force: true });
730
+ const newTypes = Path3.join(typegenDir, "routes.ts");
731
+ import_node_fs2.default.mkdirSync(Path3.dirname(newTypes), { recursive: true });
732
+ import_node_fs2.default.writeFileSync(
733
+ newTypes,
734
+ formattedPaths + `
735
+
736
+ type Routes = {
737
+ ${routes2.map(formatRoute).join("\n")}
738
+ }
739
+
740
+ ` + import_dedent2.default`
741
+ declare module "react-router/types" {
742
+ interface Register {
743
+ paths: Paths
744
+ routes: Routes
745
+ }
746
+ }
747
+
748
+ export {}
749
+ `
750
+ );
752
751
  Object.values(ctx.config.routes).forEach((route) => {
753
752
  const typesPath = getTypesPath(ctx, route);
754
- const content = generate(ctx, route);
755
- import_node_fs2.default.mkdirSync(Path4.dirname(typesPath), { recursive: true });
753
+ const content = generate(route);
754
+ import_node_fs2.default.mkdirSync(Path3.dirname(typesPath), { recursive: true });
756
755
  import_node_fs2.default.writeFileSync(typesPath, content);
757
756
  });
758
757
  }
759
- var import_node_fs2, Path4, import_picocolors2;
758
+ function getRouteLineage(routes2, route) {
759
+ const result = [];
760
+ while (route) {
761
+ result.push(route);
762
+ if (!route.parentId) break;
763
+ route = routes2[route.parentId];
764
+ }
765
+ result.reverse();
766
+ return result;
767
+ }
768
+ function parseParams(urlpath) {
769
+ const result = {};
770
+ let segments = urlpath.split("/");
771
+ segments.forEach((segment) => {
772
+ const match = segment.match(/^:([\w-]+)(\?)?/);
773
+ if (!match) return;
774
+ const param = match[1];
775
+ const isRequired = match[2] === void 0;
776
+ result[param] ||= isRequired;
777
+ return;
778
+ });
779
+ const hasSplat = segments.at(-1) === "*";
780
+ if (hasSplat) result["*"] = true;
781
+ return result;
782
+ }
783
+ var import_node_fs2, import_dedent2, Path3, import_picocolors2;
760
784
  var init_typegen = __esm({
761
785
  "typegen/index.ts"() {
762
786
  "use strict";
763
787
  import_node_fs2 = __toESM(require("fs"));
764
- Path4 = __toESM(require("pathe"));
788
+ import_dedent2 = __toESM(require("dedent"));
789
+ Path3 = __toESM(require("pathe"));
765
790
  import_picocolors2 = __toESM(require("picocolors"));
766
791
  init_config();
767
792
  init_generate();
@@ -795,34 +820,41 @@ var init_node_adapter = __esm({
795
820
  });
796
821
 
797
822
  // vite/resolve-file-url.ts
798
- var path2;
823
+ var path4;
799
824
  var init_resolve_file_url = __esm({
800
825
  "vite/resolve-file-url.ts"() {
801
826
  "use strict";
802
- path2 = __toESM(require("path"));
803
- init_import_vite_esm_sync();
827
+ path4 = __toESM(require("path"));
828
+ init_vite();
804
829
  }
805
830
  });
806
831
 
807
832
  // vite/styles.ts
808
- var path3, import_react_router, cssFileRegExp, cssModulesRegExp;
833
+ var path5, import_react_router, cssFileRegExp, cssModulesRegExp;
809
834
  var init_styles = __esm({
810
835
  "vite/styles.ts"() {
811
836
  "use strict";
812
- path3 = __toESM(require("path"));
837
+ path5 = __toESM(require("path"));
813
838
  import_react_router = require("react-router");
814
839
  init_resolve_file_url();
840
+ init_vite();
815
841
  cssFileRegExp = /\.(css|less|sass|scss|styl|stylus|pcss|postcss|sss)(?:$|\?)/;
816
842
  cssModulesRegExp = new RegExp(`\\.module${cssFileRegExp.source}`);
817
843
  }
818
844
  });
819
845
 
820
- // vite/vmod.ts
821
- var id;
822
- var init_vmod = __esm({
823
- "vite/vmod.ts"() {
846
+ // vite/virtual-module.ts
847
+ function create(name) {
848
+ let id = `virtual:react-router/${name}`;
849
+ return {
850
+ id,
851
+ resolvedId: `\0${id}`,
852
+ url: `/@id/__x00__${id}`
853
+ };
854
+ }
855
+ var init_virtual_module = __esm({
856
+ "vite/virtual-module.ts"() {
824
857
  "use strict";
825
- id = (name) => `virtual:react-router/${name}`;
826
858
  }
827
859
  });
828
860
 
@@ -844,14 +876,14 @@ var init_remove_exports = __esm({
844
876
  });
845
877
 
846
878
  // vite/with-props.ts
847
- var import_dedent2, vmodId;
879
+ var import_dedent3, vmod;
848
880
  var init_with_props = __esm({
849
881
  "vite/with-props.ts"() {
850
882
  "use strict";
851
- import_dedent2 = __toESM(require("dedent"));
883
+ import_dedent3 = __toESM(require("dedent"));
852
884
  init_babel();
853
- init_vmod();
854
- vmodId = id("with-props");
885
+ init_virtual_module();
886
+ vmod = create("with-props");
855
887
  }
856
888
  });
857
889
 
@@ -861,7 +893,7 @@ async function resolveViteConfig({
861
893
  mode,
862
894
  root
863
895
  }) {
864
- let vite2 = await import("vite");
896
+ let vite2 = getVite();
865
897
  let viteConfig = await vite2.resolveConfig(
866
898
  { mode, configFile, root },
867
899
  "build",
@@ -911,17 +943,17 @@ async function loadPluginContext({
911
943
  function findConfig(dir, basename2, extensions) {
912
944
  for (let ext of extensions) {
913
945
  let name = basename2 + ext;
914
- let file = path4.join(dir, name);
946
+ let file = path6.join(dir, name);
915
947
  if (fse.existsSync(file)) return file;
916
948
  }
917
949
  return void 0;
918
950
  }
919
- var import_node_crypto, path4, url, fse, babel, import_react_router2, import_es_module_lexer, import_jsesc, import_picocolors3, serverBuildId, serverManifestId, browserManifestId, hmrRuntimeId, injectHmrRuntimeId, getServerBuildDirectory, defaultEntriesDir, defaultEntries, REACT_REFRESH_HEADER, REACT_REFRESH_FOOTER;
951
+ var import_node_crypto, path6, url, fse, babel, import_react_router2, import_es_module_lexer, import_jsesc, import_picocolors3, virtualHmrRuntime, virtualInjectHmrRuntime, virtual, getServerBuildDirectory, defaultEntriesDir, defaultEntries, REACT_REFRESH_HEADER;
920
952
  var init_plugin = __esm({
921
953
  "vite/plugin.ts"() {
922
954
  "use strict";
923
955
  import_node_crypto = require("crypto");
924
- path4 = __toESM(require("path"));
956
+ path6 = __toESM(require("path"));
925
957
  url = __toESM(require("url"));
926
958
  fse = __toESM(require("fs-extra"));
927
959
  babel = __toESM(require("@babel/core"));
@@ -934,33 +966,35 @@ var init_plugin = __esm({
934
966
  init_babel();
935
967
  init_node_adapter();
936
968
  init_styles();
937
- init_vmod();
969
+ init_virtual_module();
938
970
  init_resolve_file_url();
939
971
  init_combine_urls();
940
972
  init_remove_exports();
941
- init_import_vite_esm_sync();
973
+ init_vite();
942
974
  init_config();
943
975
  init_with_props();
944
- serverBuildId = id("server-build");
945
- serverManifestId = id("server-manifest");
946
- browserManifestId = id("browser-manifest");
947
- hmrRuntimeId = id("hmr-runtime");
948
- injectHmrRuntimeId = id("inject-hmr-runtime");
949
- getServerBuildDirectory = (ctx) => path4.join(
976
+ virtualHmrRuntime = create("hmr-runtime");
977
+ virtualInjectHmrRuntime = create("inject-hmr-runtime");
978
+ virtual = {
979
+ serverBuild: create("server-build"),
980
+ serverManifest: create("server-manifest"),
981
+ browserManifest: create("browser-manifest")
982
+ };
983
+ getServerBuildDirectory = (ctx) => path6.join(
950
984
  ctx.reactRouterConfig.buildDirectory,
951
985
  "server",
952
986
  ...ctx.serverBundleBuildConfig ? [ctx.serverBundleBuildConfig.serverBundleId] : []
953
987
  );
954
- defaultEntriesDir = path4.resolve(
955
- path4.dirname(require.resolve("@react-router/dev/package.json")),
988
+ defaultEntriesDir = path6.resolve(
989
+ path6.dirname(require.resolve("@react-router/dev/package.json")),
956
990
  "dist",
957
991
  "config",
958
992
  "defaults"
959
993
  );
960
- defaultEntries = fse.readdirSync(defaultEntriesDir).map((filename3) => path4.join(defaultEntriesDir, filename3));
994
+ defaultEntries = fse.readdirSync(defaultEntriesDir).map((filename2) => path6.join(defaultEntriesDir, filename2));
961
995
  invariant(defaultEntries.length > 0, "No default entries found");
962
996
  REACT_REFRESH_HEADER = `
963
- import RefreshRuntime from "${hmrRuntimeId}";
997
+ import RefreshRuntime from "${virtualHmrRuntime.id}";
964
998
 
965
999
  const inWebWorker = typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope;
966
1000
  let prevRefreshReg;
@@ -979,21 +1013,7 @@ if (import.meta.hot && !inWebWorker) {
979
1013
  RefreshRuntime.register(type, __SOURCE__ + " " + id)
980
1014
  };
981
1015
  window.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;
982
- }`.trim();
983
- REACT_REFRESH_FOOTER = `
984
- if (import.meta.hot && !inWebWorker) {
985
- window.$RefreshReg$ = prevRefreshReg;
986
- window.$RefreshSig$ = prevRefreshSig;
987
- RefreshRuntime.__hmr_import(import.meta.url).then((currentExports) => {
988
- RefreshRuntime.registerExportsForReactRefresh(__SOURCE__, currentExports);
989
- import.meta.hot.accept((nextExports) => {
990
- if (!nextExports) return;
991
- __ROUTE_ID__ && window.__reactRouterRouteModuleUpdates.set(__ROUTE_ID__, nextExports);
992
- const invalidateMessage = RefreshRuntime.validateRefreshBoundaryAndEnqueueUpdate(currentExports, nextExports, __ACCEPT_EXPORTS__);
993
- if (invalidateMessage) import.meta.hot.invalidate(invalidateMessage);
994
- });
995
- });
996
- }`.trim();
1016
+ }`.replaceAll("\n", "");
997
1017
  }
998
1018
  });
999
1019
 
@@ -1043,8 +1063,8 @@ __export(build_exports, {
1043
1063
  });
1044
1064
  function getAddressableRoutes(routes2) {
1045
1065
  let nonAddressableIds = /* @__PURE__ */ new Set();
1046
- for (let id2 in routes2) {
1047
- let route = routes2[id2];
1066
+ for (let id in routes2) {
1067
+ let route = routes2[id];
1048
1068
  if (route.index) {
1049
1069
  invariant(
1050
1070
  route.parentId,
@@ -1053,7 +1073,7 @@ function getAddressableRoutes(routes2) {
1053
1073
  nonAddressableIds.add(route.parentId);
1054
1074
  }
1055
1075
  if (typeof route.path !== "string" && !route.index) {
1056
- nonAddressableIds.add(id2);
1076
+ nonAddressableIds.add(id);
1057
1077
  }
1058
1078
  }
1059
1079
  return Object.values(routes2).filter(
@@ -1084,12 +1104,12 @@ async function getServerBuilds(ctx) {
1084
1104
  let { normalizePath } = await import("vite");
1085
1105
  let resolvedAppDirectory = import_node_path2.default.resolve(rootDirectory, appDirectory);
1086
1106
  let rootRelativeRoutes = Object.fromEntries(
1087
- Object.entries(routes2).map(([id2, route]) => {
1107
+ Object.entries(routes2).map(([id, route]) => {
1088
1108
  let filePath = import_node_path2.default.join(resolvedAppDirectory, route.file);
1089
1109
  let rootRelativeFilePath = normalizePath(
1090
1110
  import_node_path2.default.relative(rootDirectory, filePath)
1091
1111
  );
1092
- return [id2, { ...route, file: rootRelativeFilePath }];
1112
+ return [id, { ...route, file: rootRelativeFilePath }];
1093
1113
  })
1094
1114
  );
1095
1115
  let buildManifest = {
@@ -1190,7 +1210,7 @@ async function build(root, {
1190
1210
  sourcemapClient,
1191
1211
  sourcemapServer
1192
1212
  }) {
1193
- await preloadViteEsm();
1213
+ await preloadVite();
1194
1214
  let viteConfig = await resolveViteConfig({ configFile, mode, root });
1195
1215
  const ctx = await extractPluginContext(viteConfig);
1196
1216
  if (!ctx) {
@@ -1200,7 +1220,7 @@ async function build(root, {
1200
1220
  process.exit(1);
1201
1221
  }
1202
1222
  let { reactRouterConfig } = ctx;
1203
- let vite2 = await import("vite");
1223
+ let vite2 = getVite();
1204
1224
  async function viteBuild({
1205
1225
  ssr,
1206
1226
  serverBundleBuildConfig
@@ -1257,7 +1277,7 @@ var init_build = __esm({
1257
1277
  init_plugin();
1258
1278
  init_config();
1259
1279
  init_invariant();
1260
- init_import_vite_esm_sync();
1280
+ init_vite();
1261
1281
  }
1262
1282
  });
1263
1283
 
@@ -1278,8 +1298,8 @@ async function dev(root, {
1278
1298
  port,
1279
1299
  strictPort
1280
1300
  }) {
1281
- await preloadViteEsm();
1282
- let vite2 = await import("vite");
1301
+ await preloadVite();
1302
+ let vite2 = getVite();
1283
1303
  let server = await vite2.createServer({
1284
1304
  root,
1285
1305
  mode,
@@ -1319,7 +1339,7 @@ var init_dev = __esm({
1319
1339
  "vite/dev.ts"() {
1320
1340
  "use strict";
1321
1341
  import_picocolors6 = __toESM(require("picocolors"));
1322
- init_import_vite_esm_sync();
1342
+ init_vite();
1323
1343
  init_profiler();
1324
1344
  }
1325
1345
  });
@@ -1330,7 +1350,7 @@ var import_semver = __toESM(require("semver"));
1330
1350
  var import_picocolors8 = __toESM(require("picocolors"));
1331
1351
 
1332
1352
  // cli/commands.ts
1333
- var path7 = __toESM(require("path"));
1353
+ var path9 = __toESM(require("path"));
1334
1354
  var import_fs_extra2 = __toESM(require("fs-extra"));
1335
1355
  var import_package_json2 = __toESM(require("@npmcli/package-json"));
1336
1356
  var import_exit_hook = __toESM(require("exit-hook"));
@@ -1416,7 +1436,7 @@ function transpile(tsx, options = {}) {
1416
1436
  // cli/commands.ts
1417
1437
  init_profiler();
1418
1438
  init_typegen();
1419
- init_import_vite_esm_sync();
1439
+ init_vite();
1420
1440
  async function routes(reactRouterRoot, flags = {}) {
1421
1441
  let ctx = await loadPluginContext({
1422
1442
  root: reactRouterRoot,
@@ -1488,14 +1508,14 @@ async function generateEntry(entry, reactRouterRoot, flags = {}) {
1488
1508
  console.error(import_picocolors7.default.red(`No default server entry detected.`));
1489
1509
  return;
1490
1510
  }
1491
- let defaultsDirectory = path7.resolve(
1492
- path7.dirname(require.resolve("@react-router/dev/package.json")),
1511
+ let defaultsDirectory = path9.resolve(
1512
+ path9.dirname(require.resolve("@react-router/dev/package.json")),
1493
1513
  "dist",
1494
1514
  "config",
1495
1515
  "defaults"
1496
1516
  );
1497
- let defaultEntryClient = path7.resolve(defaultsDirectory, "entry.client.tsx");
1498
- let defaultEntryServer = path7.resolve(
1517
+ let defaultEntryClient = path9.resolve(defaultsDirectory, "entry.client.tsx");
1518
+ let defaultEntryServer = path9.resolve(
1499
1519
  defaultsDirectory,
1500
1520
  `entry.server.node.tsx`
1501
1521
  );
@@ -1504,7 +1524,7 @@ async function generateEntry(entry, reactRouterRoot, flags = {}) {
1504
1524
  let useTypeScript = flags.typescript ?? true;
1505
1525
  let outputExtension = useTypeScript ? "tsx" : "jsx";
1506
1526
  let outputEntry = `${entry}.${outputExtension}`;
1507
- let outputFile2 = path7.resolve(appDirectory, outputEntry);
1527
+ let outputFile2 = path9.resolve(appDirectory, outputEntry);
1508
1528
  if (!useTypeScript) {
1509
1529
  let javascript = transpile(contents, {
1510
1530
  cwd: rootDirectory,
@@ -1516,7 +1536,7 @@ async function generateEntry(entry, reactRouterRoot, flags = {}) {
1516
1536
  }
1517
1537
  console.log(
1518
1538
  import_picocolors7.default.blue(
1519
- `Entry file ${entry} created at ${path7.relative(
1539
+ `Entry file ${entry} created at ${path9.relative(
1520
1540
  rootDirectory,
1521
1541
  outputFile2
1522
1542
  )}.`
@@ -1525,11 +1545,11 @@ async function generateEntry(entry, reactRouterRoot, flags = {}) {
1525
1545
  }
1526
1546
  async function checkForEntry(rootDirectory, appDirectory, entries2) {
1527
1547
  for (let entry of entries2) {
1528
- let entryPath = path7.resolve(appDirectory, entry);
1548
+ let entryPath = path9.resolve(appDirectory, entry);
1529
1549
  let exists = await import_fs_extra2.default.pathExists(entryPath);
1530
1550
  if (exists) {
1531
- let relative8 = path7.relative(rootDirectory, entryPath);
1532
- console.error(import_picocolors7.default.red(`Entry file ${relative8} already exists.`));
1551
+ let relative7 = path9.relative(rootDirectory, entryPath);
1552
+ console.error(import_picocolors7.default.red(`Entry file ${relative7} already exists.`));
1533
1553
  return process.exit(1);
1534
1554
  }
1535
1555
  }
@@ -1547,8 +1567,8 @@ async function createClientEntry(rootDirectory, appDirectory, inputFile) {
1547
1567
  async function typegen(root, flags) {
1548
1568
  root ??= process.cwd();
1549
1569
  if (flags.watch) {
1550
- await preloadViteEsm();
1551
- const vite2 = importViteEsmSync();
1570
+ await preloadVite();
1571
+ const vite2 = getVite();
1552
1572
  const logger = vite2.createLogger("info", { prefix: "[react-router]" });
1553
1573
  await watch(root, { logger });
1554
1574
  await new Promise(() => {