@react-router/dev 0.0.0-experimental-e56aa53bc → 0.0.0-experimental-5bbc45fb6

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-e56aa53bc
2
+ * @react-router/dev v0.0.0-experimental-5bbc45fb6
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -47,7 +47,7 @@ module.exports = __toCommonJS(vite_exports);
47
47
  // vite/plugin.ts
48
48
  var import_node_crypto = require("crypto");
49
49
  var fs3 = __toESM(require("fs"));
50
- var path6 = __toESM(require("path"));
50
+ var path5 = __toESM(require("path"));
51
51
  var url = __toESM(require("url"));
52
52
  var fse = __toESM(require("fs-extra"));
53
53
  var babel = __toESM(require("@babel/core"));
@@ -59,10 +59,9 @@ var import_picocolors3 = __toESM(require("picocolors"));
59
59
  var import_kebabCase = __toESM(require("lodash/kebabCase"));
60
60
 
61
61
  // typegen/index.ts
62
- var import_node_fs2 = __toESM(require("fs"));
63
- var import_dedent2 = __toESM(require("dedent"));
62
+ var import_promises = __toESM(require("fs/promises"));
64
63
  var Path4 = __toESM(require("pathe"));
65
- var import_picocolors2 = __toESM(require("picocolors"));
64
+ var import_picocolors2 = require("picocolors");
66
65
 
67
66
  // config/config.ts
68
67
  var import_node_fs = __toESM(require("fs"));
@@ -136,13 +135,15 @@ var ssrExternals = isReactRouterRepo() ? [
136
135
  // vite/vite-node.ts
137
136
  async function createContext({
138
137
  root,
139
- mode
138
+ mode,
139
+ customLogger
140
140
  }) {
141
141
  await preloadVite();
142
142
  const vite2 = getVite();
143
143
  const devServer = await vite2.createServer({
144
144
  root,
145
145
  mode,
146
+ customLogger,
146
147
  server: {
147
148
  preTransformRequests: false,
148
149
  hmr: false,
@@ -154,6 +155,15 @@ async function createContext({
154
155
  optimizeDeps: {
155
156
  noDiscovery: true
156
157
  },
158
+ css: {
159
+ // This empty PostCSS config object prevents the PostCSS config file from
160
+ // being loaded. We don't need it in a React Router config context, and
161
+ // there's also an issue in Vite 5 when using a .ts PostCSS config file in
162
+ // an ESM project: https://github.com/vitejs/vite/issues/15869. Consumers
163
+ // can work around this in their own Vite config file, but they can't
164
+ // configure this internal usage of vite-node.
165
+ postcss: {}
166
+ },
157
167
  configFile: false,
158
168
  envFile: false,
159
169
  plugins: []
@@ -231,7 +241,7 @@ function validateRouteConfig({
231
241
  `Route config in "${routeConfigFile}" is invalid.`,
232
242
  root ? `${root}` : [],
233
243
  nested ? Object.entries(nested).map(
234
- ([path7, message]) => `Path: routes.${path7}
244
+ ([path6, message]) => `Path: routes.${path6}
235
245
  ${message}`
236
246
  ) : []
237
247
  ].flat().join("\n\n")
@@ -347,7 +357,8 @@ function err(error) {
347
357
  async function resolveConfig({
348
358
  root,
349
359
  viteNodeContext,
350
- reactRouterConfigFile
360
+ reactRouterConfigFile,
361
+ skipRoutes
351
362
  }) {
352
363
  let reactRouterUserConfig = {};
353
364
  if (reactRouterConfigFile) {
@@ -396,12 +407,17 @@ async function resolveConfig({
396
407
  serverModuleFormat: "esm",
397
408
  ssr: true
398
409
  };
410
+ let userAndPresetConfigs = mergeReactRouterConfig(
411
+ ...presets,
412
+ reactRouterUserConfig
413
+ );
399
414
  let {
400
415
  appDirectory: userAppDirectory,
401
- basename: basename2,
416
+ basename: basename3,
402
417
  buildDirectory: userBuildDirectory,
403
418
  buildEnd,
404
419
  prerender,
420
+ routeDiscovery: userRouteDiscovery,
405
421
  serverBuildFile,
406
422
  serverBundles,
407
423
  serverModuleFormat,
@@ -409,7 +425,7 @@ async function resolveConfig({
409
425
  } = {
410
426
  ...defaults,
411
427
  // Default values should be completely overridden by user/preset config, not merged
412
- ...mergeReactRouterConfig(...presets, reactRouterUserConfig)
428
+ ...userAndPresetConfigs
413
429
  };
414
430
  if (!ssr && serverBundles) {
415
431
  serverBundles = void 0;
@@ -420,6 +436,32 @@ async function resolveConfig({
420
436
  "The `prerender` config must be a boolean, an array of string paths, or a function returning a boolean or array of string paths"
421
437
  );
422
438
  }
439
+ let routeDiscovery;
440
+ if (userRouteDiscovery == null) {
441
+ if (ssr) {
442
+ routeDiscovery = {
443
+ mode: "lazy",
444
+ manifestPath: "/__manifest"
445
+ };
446
+ } else {
447
+ routeDiscovery = { mode: "initial" };
448
+ }
449
+ } else if (userRouteDiscovery.mode === "initial") {
450
+ routeDiscovery = userRouteDiscovery;
451
+ } else if (userRouteDiscovery.mode === "lazy") {
452
+ if (!ssr) {
453
+ return err(
454
+ 'The `routeDiscovery.mode` config cannot be set to "lazy" when setting `ssr:false`'
455
+ );
456
+ }
457
+ let { manifestPath } = userRouteDiscovery;
458
+ if (manifestPath != null && !manifestPath.startsWith("/")) {
459
+ return err(
460
+ 'The `routeDiscovery.manifestPath` config must be a root-relative pathname beginning with a slash (i.e., "/__manifest")'
461
+ );
462
+ }
463
+ routeDiscovery = userRouteDiscovery;
464
+ }
423
465
  let appDirectory = import_pathe3.default.resolve(root, userAppDirectory || "app");
424
466
  let buildDirectory = import_pathe3.default.resolve(root, userBuildDirectory);
425
467
  let rootRouteFile = findEntry(appDirectory, "root");
@@ -432,45 +474,50 @@ async function resolveConfig({
432
474
  `Could not find a root route module in the app directory as "${rootRouteDisplayPath}"`
433
475
  );
434
476
  }
435
- let routes = {
436
- root: { path: "", id: "root", file: rootRouteFile }
437
- };
438
- let routeConfigFile = findEntry(appDirectory, "routes");
439
- try {
440
- if (!routeConfigFile) {
441
- let routeConfigDisplayPath = import_pathe3.default.relative(
442
- root,
443
- import_pathe3.default.join(appDirectory, "routes.ts")
444
- );
445
- return err(`Route config file not found at "${routeConfigDisplayPath}".`);
446
- }
447
- setAppDirectory(appDirectory);
448
- let routeConfigExport = (await viteNodeContext.runner.executeFile(
449
- import_pathe3.default.join(appDirectory, routeConfigFile)
450
- )).default;
451
- let routeConfig = await routeConfigExport;
452
- let result = validateRouteConfig({
453
- routeConfigFile,
454
- routeConfig
455
- });
456
- if (!result.valid) {
457
- return err(result.message);
458
- }
477
+ let routes = {};
478
+ if (!skipRoutes) {
459
479
  routes = {
460
- ...routes,
461
- ...configRoutesToRouteManifest(appDirectory, routeConfig)
480
+ root: { path: "", id: "root", file: rootRouteFile }
462
481
  };
463
- } catch (error) {
464
- return err(
465
- [
466
- import_picocolors.default.red(`Route config in "${routeConfigFile}" is invalid.`),
467
- "",
468
- error.loc?.file && error.loc?.column && error.frame ? [
469
- import_pathe3.default.relative(appDirectory, error.loc.file) + ":" + error.loc.line + ":" + error.loc.column,
470
- error.frame.trim?.()
471
- ] : error.stack
472
- ].flat().join("\n")
473
- );
482
+ let routeConfigFile = findEntry(appDirectory, "routes");
483
+ try {
484
+ if (!routeConfigFile) {
485
+ let routeConfigDisplayPath = import_pathe3.default.relative(
486
+ root,
487
+ import_pathe3.default.join(appDirectory, "routes.ts")
488
+ );
489
+ return err(
490
+ `Route config file not found at "${routeConfigDisplayPath}".`
491
+ );
492
+ }
493
+ setAppDirectory(appDirectory);
494
+ let routeConfigExport = (await viteNodeContext.runner.executeFile(
495
+ import_pathe3.default.join(appDirectory, routeConfigFile)
496
+ )).default;
497
+ let routeConfig = await routeConfigExport;
498
+ let result = validateRouteConfig({
499
+ routeConfigFile,
500
+ routeConfig
501
+ });
502
+ if (!result.valid) {
503
+ return err(result.message);
504
+ }
505
+ routes = {
506
+ ...routes,
507
+ ...configRoutesToRouteManifest(appDirectory, routeConfig)
508
+ };
509
+ } catch (error) {
510
+ return err(
511
+ [
512
+ import_picocolors.default.red(`Route config in "${routeConfigFile}" is invalid.`),
513
+ "",
514
+ error.loc?.file && error.loc?.column && error.frame ? [
515
+ import_pathe3.default.relative(appDirectory, error.loc.file) + ":" + error.loc.line + ":" + error.loc.column,
516
+ error.frame.trim?.()
517
+ ] : error.stack
518
+ ].flat().join("\n")
519
+ );
520
+ }
474
521
  }
475
522
  let future = {
476
523
  unstable_middleware: reactRouterUserConfig.future?.unstable_middleware ?? false,
@@ -481,12 +528,13 @@ async function resolveConfig({
481
528
  };
482
529
  let reactRouterConfig = deepFreeze({
483
530
  appDirectory,
484
- basename: basename2,
531
+ basename: basename3,
485
532
  buildDirectory,
486
533
  buildEnd,
487
534
  future,
488
535
  prerender,
489
536
  routes,
537
+ routeDiscovery,
490
538
  serverBuildFile,
491
539
  serverBundles,
492
540
  serverModuleFormat,
@@ -499,24 +547,35 @@ async function resolveConfig({
499
547
  }
500
548
  async function createConfigLoader({
501
549
  rootDirectory: root,
502
- watch: watch2
550
+ watch: watch2,
551
+ mode,
552
+ skipRoutes
503
553
  }) {
504
- root = root ?? process.env.REACT_ROUTER_ROOT ?? process.cwd();
554
+ root = import_pathe3.default.normalize(root ?? process.env.REACT_ROUTER_ROOT ?? process.cwd());
555
+ let vite2 = await import("vite");
505
556
  let viteNodeContext = await createContext({
506
557
  root,
507
- mode: watch2 ? "development" : "production"
508
- });
509
- let reactRouterConfigFile = findEntry(root, "react-router.config", {
510
- absolute: true
558
+ mode,
559
+ // Filter out any info level logs from vite-node
560
+ customLogger: vite2.createLogger("warn", {
561
+ prefix: "[react-router]"
562
+ })
511
563
  });
512
- let getConfig = () => resolveConfig({ root, viteNodeContext, reactRouterConfigFile });
564
+ let reactRouterConfigFile;
565
+ let updateReactRouterConfigFile = () => {
566
+ reactRouterConfigFile = findEntry(root, "react-router.config", {
567
+ absolute: true
568
+ });
569
+ };
570
+ updateReactRouterConfigFile();
571
+ let getConfig = () => resolveConfig({ root, viteNodeContext, reactRouterConfigFile, skipRoutes });
513
572
  let appDirectory;
514
573
  let initialConfigResult = await getConfig();
515
574
  if (!initialConfigResult.ok) {
516
575
  throw new Error(initialConfigResult.error);
517
576
  }
518
- appDirectory = initialConfigResult.value.appDirectory;
519
- let lastConfig = initialConfigResult.value;
577
+ appDirectory = import_pathe3.default.normalize(initialConfigResult.value.appDirectory);
578
+ let currentConfig = initialConfigResult.value;
520
579
  let fsWatcher;
521
580
  let changeHandlers = [];
522
581
  return {
@@ -529,41 +588,71 @@ async function createConfigLoader({
529
588
  }
530
589
  changeHandlers.push(handler);
531
590
  if (!fsWatcher) {
532
- fsWatcher = import_chokidar.default.watch(
533
- [
534
- ...reactRouterConfigFile ? [reactRouterConfigFile] : [],
535
- appDirectory
536
- ],
537
- { ignoreInitial: true }
538
- );
591
+ fsWatcher = import_chokidar.default.watch([root, appDirectory], {
592
+ ignoreInitial: true,
593
+ ignored: (path6) => {
594
+ let dirname4 = import_pathe3.default.dirname(path6);
595
+ return !dirname4.startsWith(appDirectory) && // Ensure we're only watching files outside of the app directory
596
+ // that are at the root level, not nested in subdirectories
597
+ path6 !== root && // Watch the root directory itself
598
+ dirname4 !== root;
599
+ }
600
+ });
539
601
  fsWatcher.on("all", async (...args) => {
540
602
  let [event, rawFilepath] = args;
541
603
  let filepath = import_pathe3.default.normalize(rawFilepath);
542
- let appFileAddedOrRemoved = appDirectory && (event === "add" || event === "unlink") && filepath.startsWith(import_pathe3.default.normalize(appDirectory));
543
- let configCodeUpdated = Boolean(
604
+ let fileAddedOrRemoved = event === "add" || event === "unlink";
605
+ let appFileAddedOrRemoved = fileAddedOrRemoved && filepath.startsWith(import_pathe3.default.normalize(appDirectory));
606
+ let rootRelativeFilepath = import_pathe3.default.relative(root, filepath);
607
+ let configFileAddedOrRemoved = fileAddedOrRemoved && isEntryFile("react-router.config", rootRelativeFilepath);
608
+ if (configFileAddedOrRemoved) {
609
+ updateReactRouterConfigFile();
610
+ }
611
+ let moduleGraphChanged = configFileAddedOrRemoved || Boolean(
544
612
  viteNodeContext.devServer?.moduleGraph.getModuleById(filepath)
545
613
  );
546
- if (configCodeUpdated || appFileAddedOrRemoved) {
547
- viteNodeContext.devServer?.moduleGraph.invalidateAll();
548
- viteNodeContext.runner?.moduleCache.clear();
614
+ if (!moduleGraphChanged && !appFileAddedOrRemoved) {
615
+ return;
549
616
  }
550
- if (appFileAddedOrRemoved || configCodeUpdated) {
551
- let result = await getConfig();
552
- let configChanged = result.ok && !(0, import_isEqual.default)(lastConfig, result.value);
553
- let routeConfigChanged = result.ok && !(0, import_isEqual.default)(lastConfig?.routes, result.value.routes);
554
- for (let handler2 of changeHandlers) {
555
- handler2({
556
- result,
557
- configCodeUpdated,
558
- configChanged,
559
- routeConfigChanged,
560
- path: filepath,
561
- event
562
- });
563
- }
564
- if (result.ok) {
565
- lastConfig = result.value;
566
- }
617
+ viteNodeContext.devServer?.moduleGraph.invalidateAll();
618
+ viteNodeContext.runner?.moduleCache.clear();
619
+ let result = await getConfig();
620
+ let prevAppDirectory = appDirectory;
621
+ appDirectory = import_pathe3.default.normalize(
622
+ (result.value ?? currentConfig).appDirectory
623
+ );
624
+ if (appDirectory !== prevAppDirectory) {
625
+ fsWatcher.unwatch(prevAppDirectory);
626
+ fsWatcher.add(appDirectory);
627
+ }
628
+ let configCodeChanged = configFileAddedOrRemoved || reactRouterConfigFile !== void 0 && isEntryFileDependency(
629
+ viteNodeContext.devServer.moduleGraph,
630
+ reactRouterConfigFile,
631
+ filepath
632
+ );
633
+ let routeConfigFile = !skipRoutes ? findEntry(appDirectory, "routes", {
634
+ absolute: true
635
+ }) : void 0;
636
+ let routeConfigCodeChanged = routeConfigFile !== void 0 && isEntryFileDependency(
637
+ viteNodeContext.devServer.moduleGraph,
638
+ routeConfigFile,
639
+ filepath
640
+ );
641
+ let configChanged = result.ok && !(0, import_isEqual.default)(omitRoutes(currentConfig), omitRoutes(result.value));
642
+ let routeConfigChanged = result.ok && !(0, import_isEqual.default)(currentConfig?.routes, result.value.routes);
643
+ for (let handler2 of changeHandlers) {
644
+ handler2({
645
+ result,
646
+ configCodeChanged,
647
+ routeConfigCodeChanged,
648
+ configChanged,
649
+ routeConfigChanged,
650
+ path: filepath,
651
+ event
652
+ });
653
+ }
654
+ if (result.ok) {
655
+ currentConfig = result.value;
567
656
  }
568
657
  });
569
658
  }
@@ -595,7 +684,18 @@ async function resolveEntryFiles({
595
684
  let userEntryServerFile = findEntry(appDirectory, "entry.server");
596
685
  let entryServerFile;
597
686
  let entryClientFile = userEntryClientFile || "entry.client.tsx";
598
- let pkgJson = await import_package_json.default.load(rootDirectory);
687
+ let packageJsonPath = findEntry(rootDirectory, "package", {
688
+ extensions: [".json"],
689
+ absolute: true,
690
+ walkParents: true
691
+ });
692
+ if (!packageJsonPath) {
693
+ throw new Error(
694
+ `Could not find package.json in ${rootDirectory} or any of its parent directories`
695
+ );
696
+ }
697
+ let packageJsonDirectory = import_pathe3.default.dirname(packageJsonPath);
698
+ let pkgJson = await import_package_json.default.load(packageJsonDirectory);
599
699
  let deps = pkgJson.content.dependencies ?? {};
600
700
  if (userEntryServerFile) {
601
701
  entryServerFile = userEntryServerFile;
@@ -618,7 +718,7 @@ async function resolveEntryFiles({
618
718
  await pkgJson.save();
619
719
  let packageManager = detectPackageManager() ?? "npm";
620
720
  (0, import_node_child_process.execSync)(`${packageManager} install`, {
621
- cwd: rootDirectory,
721
+ cwd: packageJsonDirectory,
622
722
  stdio: "inherit"
623
723
  });
624
724
  }
@@ -628,17 +728,85 @@ async function resolveEntryFiles({
628
728
  let entryServerFilePath = userEntryServerFile ? import_pathe3.default.resolve(reactRouterConfig.appDirectory, userEntryServerFile) : import_pathe3.default.resolve(defaultsDirectory, entryServerFile);
629
729
  return { entryClientFilePath, entryServerFilePath };
630
730
  }
731
+ function omitRoutes(config) {
732
+ return {
733
+ ...config,
734
+ routes: {}
735
+ };
736
+ }
631
737
  var entryExts = [".js", ".jsx", ".ts", ".tsx"];
632
- function findEntry(dir, basename2, options) {
633
- for (let ext of entryExts) {
634
- let file = import_pathe3.default.resolve(dir, basename2 + ext);
635
- if (import_node_fs.default.existsSync(file)) {
636
- return options?.absolute ?? false ? file : import_pathe3.default.relative(dir, file);
738
+ function isEntryFile(entryBasename, filename2) {
739
+ return entryExts.some((ext) => filename2 === `${entryBasename}${ext}`);
740
+ }
741
+ function findEntry(dir, basename3, options) {
742
+ let currentDir = import_pathe3.default.resolve(dir);
743
+ let { root } = import_pathe3.default.parse(currentDir);
744
+ while (true) {
745
+ for (let ext of options?.extensions ?? entryExts) {
746
+ let file = import_pathe3.default.resolve(currentDir, basename3 + ext);
747
+ if (import_node_fs.default.existsSync(file)) {
748
+ return options?.absolute ?? false ? file : import_pathe3.default.relative(dir, file);
749
+ }
750
+ }
751
+ if (!options?.walkParents) {
752
+ return void 0;
753
+ }
754
+ let parentDir = import_pathe3.default.dirname(currentDir);
755
+ if (currentDir === root || parentDir === currentDir) {
756
+ return void 0;
757
+ }
758
+ currentDir = parentDir;
759
+ }
760
+ }
761
+ function isEntryFileDependency(moduleGraph, entryFilepath, filepath, visited = /* @__PURE__ */ new Set()) {
762
+ entryFilepath = import_pathe3.default.normalize(entryFilepath);
763
+ filepath = import_pathe3.default.normalize(filepath);
764
+ if (visited.has(filepath)) {
765
+ return false;
766
+ }
767
+ visited.add(filepath);
768
+ if (filepath === entryFilepath) {
769
+ return true;
770
+ }
771
+ let mod = moduleGraph.getModuleById(filepath);
772
+ if (!mod) {
773
+ return false;
774
+ }
775
+ for (let importer of mod.importers) {
776
+ if (!importer.id) {
777
+ continue;
778
+ }
779
+ if (importer.id === entryFilepath || isEntryFileDependency(moduleGraph, entryFilepath, importer.id, visited)) {
780
+ return true;
637
781
  }
638
782
  }
639
- return void 0;
783
+ return false;
640
784
  }
641
785
 
786
+ // typegen/context.ts
787
+ async function createContext2({
788
+ rootDirectory,
789
+ watch: watch2,
790
+ mode
791
+ }) {
792
+ const configLoader = await createConfigLoader({ rootDirectory, mode, watch: watch2 });
793
+ const configResult = await configLoader.getConfig();
794
+ if (!configResult.ok) {
795
+ throw new Error(configResult.error);
796
+ }
797
+ const config = configResult.value;
798
+ return {
799
+ configLoader,
800
+ rootDirectory,
801
+ config
802
+ };
803
+ }
804
+
805
+ // typegen/generate.ts
806
+ var import_dedent = __toESM(require("dedent"));
807
+ var Path3 = __toESM(require("pathe"));
808
+ var Pathe = __toESM(require("pathe/utils"));
809
+
642
810
  // vite/babel.ts
643
811
  var babel_exports = {};
644
812
  __export(babel_exports, {
@@ -652,26 +820,6 @@ var t = __toESM(require("@babel/types"));
652
820
  var traverse = require("@babel/traverse").default;
653
821
  var generate = require("@babel/generator").default;
654
822
 
655
- // typegen/generate.ts
656
- var import_dedent = __toESM(require("dedent"));
657
- var Path3 = __toESM(require("pathe"));
658
- var Pathe2 = __toESM(require("pathe/utils"));
659
-
660
- // typegen/paths.ts
661
- var Path2 = __toESM(require("pathe"));
662
- var Pathe = __toESM(require("pathe/utils"));
663
- function getTypesDir(ctx) {
664
- return Path2.join(ctx.rootDirectory, ".react-router/types");
665
- }
666
- function getTypesPath(ctx, route) {
667
- return Path2.join(
668
- getTypesDir(ctx),
669
- Path2.relative(ctx.rootDirectory, ctx.config.appDirectory),
670
- Path2.dirname(route.file),
671
- "+types/" + Pathe.filename(route.file) + ".ts"
672
- );
673
- }
674
-
675
823
  // typegen/params.ts
676
824
  function parse2(fullpath2) {
677
825
  const result = {};
@@ -702,194 +850,326 @@ function lineage(routes, route) {
702
850
  }
703
851
  function fullpath(lineage2) {
704
852
  if (lineage2.length === 1 && lineage2[0].id === "root") return "/";
705
- return "/" + lineage2.map((route) => route.path?.replace(/^\//, "")?.replace(/\/$/, "")).filter((path7) => path7 !== void 0 && path7 !== "").join("/");
853
+ return "/" + lineage2.map((route) => route.path?.replace(/^\//, "")?.replace(/\/$/, "")).filter((path6) => path6 !== void 0 && path6 !== "").join("/");
706
854
  }
707
855
 
708
856
  // typegen/generate.ts
709
- function generate2(ctx, route) {
710
- const lineage2 = lineage(ctx.config.routes, route);
711
- const fullpath2 = fullpath(lineage2);
712
- const typesPath = getTypesPath(ctx, route);
713
- const parents = lineage2.slice(0, -1);
714
- const parentTypeImports = parents.map((parent, i) => {
715
- const rel = Path3.relative(
716
- Path3.dirname(typesPath),
717
- getTypesPath(ctx, parent)
718
- );
719
- const indent = i === 0 ? "" : " ".repeat(2);
720
- let source = noExtension(rel);
721
- if (!source.startsWith("../")) source = "./" + source;
722
- return `${indent}import type { Info as Parent${i} } from "${source}.js"`;
723
- }).join("\n");
724
- return import_dedent.default`
725
- // React Router generated types for route:
726
- // ${route.file}
727
-
728
- import type * as T from "react-router/route-module"
729
-
730
- ${parentTypeImports}
731
-
732
- type Module = typeof import("../${Pathe2.filename(route.file)}.js")
733
-
734
- export type Info = {
735
- parents: [${parents.map((_, i) => `Parent${i}`).join(", ")}],
736
- id: "${route.id}"
737
- file: "${route.file}"
738
- path: "${route.path}"
739
- params: {${formatParamProperties(
740
- fullpath2
741
- )}} & { [key: string]: string | undefined }
742
- module: Module
743
- loaderData: T.CreateLoaderData<Module>
744
- actionData: T.CreateActionData<Module>
745
- }
746
-
747
- export namespace Route {
748
- export type LinkDescriptors = T.LinkDescriptors
749
- export type LinksFunction = () => LinkDescriptors
750
-
751
- export type MetaArgs = T.CreateMetaArgs<Info>
752
- export type MetaDescriptors = T.MetaDescriptors
753
- export type MetaFunction = (args: MetaArgs) => MetaDescriptors
754
-
755
- export type HeadersArgs = T.HeadersArgs
756
- export type HeadersFunction = (args: HeadersArgs) => Headers | HeadersInit
857
+ function typesDirectory(ctx) {
858
+ return Path3.join(ctx.rootDirectory, ".react-router/types");
859
+ }
860
+ function generateFuture(ctx) {
861
+ const filename2 = Path3.join(typesDirectory(ctx), "+future.ts");
862
+ const content = import_dedent.default`
863
+ // Generated by React Router
757
864
 
758
- export type unstable_MiddlewareFunction = T.CreateServerMiddlewareFunction<Info>
759
- export type unstable_ClientMiddlewareFunction = T.CreateClientMiddlewareFunction<Info>
760
- export type LoaderArgs = T.CreateServerLoaderArgs<Info>
761
- export type ClientLoaderArgs = T.CreateClientLoaderArgs<Info>
762
- export type ActionArgs = T.CreateServerActionArgs<Info>
763
- export type ClientActionArgs = T.CreateClientActionArgs<Info>
865
+ import "react-router";
764
866
 
765
- export type HydrateFallbackProps = T.CreateHydrateFallbackProps<Info>
766
- export type ComponentProps = T.CreateComponentProps<Info>
767
- export type ErrorBoundaryProps = T.CreateErrorBoundaryProps<Info>
867
+ declare module "react-router" {
868
+ interface Future {
869
+ unstable_middleware: ${ctx.config.future.unstable_middleware}
870
+ }
768
871
  }
769
872
  `;
873
+ return { filename: filename2, content };
770
874
  }
771
- var noExtension = (path7) => Path3.join(Path3.dirname(path7), Pathe2.filename(path7));
772
- function formatParamProperties(fullpath2) {
773
- const params = parse2(fullpath2);
774
- const properties = Object.entries(params).map(
775
- ([name, isRequired]) => isRequired ? `"${name}": string` : `"${name}"?: string`
776
- );
777
- return properties.join("; ");
778
- }
875
+ function generateServerBuild(ctx) {
876
+ const filename2 = Path3.join(typesDirectory(ctx), "+server-build.d.ts");
877
+ const content = import_dedent.default`
878
+ // Generated by React Router
779
879
 
780
- // typegen/index.ts
781
- async function watch(rootDirectory, { logger } = {}) {
782
- const ctx = await createContext2({ rootDirectory, watch: true });
783
- await writeAll(ctx);
784
- logger?.info(import_picocolors2.default.green("generated types"), { timestamp: true, clear: true });
785
- ctx.configLoader.onChange(async ({ result, routeConfigChanged }) => {
786
- if (!result.ok) {
787
- logger?.error(import_picocolors2.default.red(result.error), { timestamp: true, clear: true });
788
- return;
880
+ declare module "virtual:react-router/server-build" {
881
+ import { ServerBuild } from "react-router";
882
+ export const assets: ServerBuild["assets"];
883
+ export const assetsBuildDirectory: ServerBuild["assetsBuildDirectory"];
884
+ export const basename: ServerBuild["basename"];
885
+ export const entry: ServerBuild["entry"];
886
+ export const future: ServerBuild["future"];
887
+ export const isSpaMode: ServerBuild["isSpaMode"];
888
+ export const prerender: ServerBuild["prerender"];
889
+ export const publicPath: ServerBuild["publicPath"];
890
+ export const routeDiscovery: ServerBuild["routeDiscovery"];
891
+ export const routes: ServerBuild["routes"];
892
+ export const ssr: ServerBuild["ssr"];
893
+ export const unstable_getCriticalCss: ServerBuild["unstable_getCriticalCss"];
789
894
  }
790
- ctx.config = result.value;
791
- if (routeConfigChanged) {
792
- await writeAll(ctx);
793
- logger?.info(import_picocolors2.default.green("regenerated types"), {
794
- timestamp: true,
795
- clear: true
796
- });
797
- }
798
- });
799
- return {
800
- close: async () => await ctx.configLoader.close()
801
- };
802
- }
803
- async function createContext2({
804
- rootDirectory,
805
- watch: watch2
806
- }) {
807
- const configLoader = await createConfigLoader({ rootDirectory, watch: watch2 });
808
- const configResult = await configLoader.getConfig();
809
- if (!configResult.ok) {
810
- throw new Error(configResult.error);
811
- }
812
- const config = configResult.value;
813
- return {
814
- configLoader,
815
- rootDirectory,
816
- config
817
- };
895
+ `;
896
+ return { filename: filename2, content };
818
897
  }
819
- async function writeAll(ctx) {
820
- const typegenDir = getTypesDir(ctx);
821
- import_node_fs2.default.rmSync(typegenDir, { recursive: true, force: true });
898
+ var { t: t2 } = babel_exports;
899
+ function generatePages(ctx) {
900
+ const filename2 = Path3.join(typesDirectory(ctx), "+pages.ts");
901
+ const fullpaths = /* @__PURE__ */ new Set();
822
902
  Object.values(ctx.config.routes).forEach((route) => {
823
- const typesPath = getTypesPath(ctx, route);
824
- const content = generate2(ctx, route);
825
- import_node_fs2.default.mkdirSync(Path4.dirname(typesPath), { recursive: true });
826
- import_node_fs2.default.writeFileSync(typesPath, content);
903
+ if (route.id !== "root" && !route.path) return;
904
+ const lineage2 = lineage(ctx.config.routes, route);
905
+ const fullpath2 = fullpath(lineage2);
906
+ fullpaths.add(fullpath2);
827
907
  });
828
- const registerPath = Path4.join(typegenDir, "+register.ts");
829
- import_node_fs2.default.writeFileSync(registerPath, register(ctx));
830
- const virtualPath = Path4.join(typegenDir, "+virtual.d.ts");
831
- import_node_fs2.default.writeFileSync(virtualPath, virtual);
832
- }
833
- function register(ctx) {
834
- const register2 = import_dedent2.default`
835
- import "react-router";
908
+ const pagesType = t2.tsTypeAliasDeclaration(
909
+ t2.identifier("Pages"),
910
+ null,
911
+ t2.tsTypeLiteral(
912
+ Array.from(fullpaths).map((fullpath2) => {
913
+ return t2.tsPropertySignature(
914
+ t2.stringLiteral(fullpath2),
915
+ t2.tsTypeAnnotation(
916
+ t2.tsTypeLiteral([
917
+ t2.tsPropertySignature(
918
+ t2.identifier("params"),
919
+ t2.tsTypeAnnotation(paramsType(fullpath2))
920
+ )
921
+ ])
922
+ )
923
+ );
924
+ })
925
+ )
926
+ );
927
+ const content = import_dedent.default`
928
+ // Generated by React Router
836
929
 
837
- declare module "react-router" {
838
- interface Register {
839
- params: Params;
930
+ import "react-router"
931
+
932
+ declare module "react-router" {
933
+ interface Register {
934
+ pages: Pages
935
+ }
840
936
  }
841
- }
842
- `;
843
- const { t: t2 } = babel_exports;
844
- const indexPaths = new Set(
845
- Object.values(ctx.config.routes).filter((route) => route.index).map((route) => route.path)
846
- );
847
- const typeParams = t2.tsTypeAliasDeclaration(
848
- t2.identifier("Params"),
937
+ ` + "\n\n" + generate(pagesType).code;
938
+ return { filename: filename2, content };
939
+ }
940
+ function generateRoutes(ctx) {
941
+ const filename2 = Path3.join(typesDirectory(ctx), "+routes-pre.ts");
942
+ const routesType = t2.tsTypeAliasDeclaration(
943
+ t2.identifier("routesPre"),
849
944
  null,
850
945
  t2.tsTypeLiteral(
851
946
  Object.values(ctx.config.routes).map((route) => {
852
- if (route.id !== "root" && !route.path) return void 0;
853
- if (!route.index && indexPaths.has(route.path)) return void 0;
854
- const lineage2 = lineage(ctx.config.routes, route);
855
- const fullpath2 = fullpath(lineage2);
856
- const params = parse2(fullpath2);
857
947
  return t2.tsPropertySignature(
858
- t2.stringLiteral(fullpath2),
948
+ t2.stringLiteral(route.id),
859
949
  t2.tsTypeAnnotation(
860
- t2.tsTypeLiteral(
861
- Object.entries(params).map(([param, isRequired]) => {
862
- const property = t2.tsPropertySignature(
863
- t2.stringLiteral(param),
864
- t2.tsTypeAnnotation(t2.tsStringKeyword())
865
- );
866
- property.optional = !isRequired;
867
- return property;
868
- })
869
- )
950
+ t2.tsTypeLiteral([
951
+ t2.tsPropertySignature(
952
+ t2.identifier("parentId"),
953
+ t2.tsTypeAnnotation(
954
+ route.parentId ? t2.tsLiteralType(t2.stringLiteral(route.parentId)) : t2.tsUndefinedKeyword()
955
+ )
956
+ ),
957
+ t2.tsPropertySignature(
958
+ t2.identifier("path"),
959
+ t2.tsTypeAnnotation(
960
+ route.path ? t2.tsLiteralType(t2.stringLiteral(route.path)) : t2.tsUndefinedKeyword()
961
+ )
962
+ ),
963
+ t2.tsPropertySignature(
964
+ t2.identifier("params"),
965
+ t2.tsTypeAnnotation(paramsType(route.path ?? ""))
966
+ ),
967
+ t2.tsPropertySignature(
968
+ t2.identifier("index"),
969
+ t2.tsTypeAnnotation(
970
+ t2.tsLiteralType(t2.booleanLiteral(route.index ?? false))
971
+ )
972
+ ),
973
+ t2.tsPropertySignature(
974
+ t2.identifier("file"),
975
+ t2.tsTypeAnnotation(t2.tsLiteralType(t2.stringLiteral(route.file)))
976
+ )
977
+ ])
870
978
  )
871
979
  );
872
- }).filter((x) => x !== void 0)
980
+ })
873
981
  )
874
982
  );
875
- return [register2, generate(typeParams).code].join("\n\n");
983
+ const content = import_dedent.default`
984
+ // Generated by React Router
985
+
986
+ import "react-router"
987
+
988
+ declare module "react-router" {
989
+ interface Register {
990
+ routesPre: routesPre
991
+ }
992
+ }
993
+ ` + "\n\n" + generate(routesType).code;
994
+ return { filename: filename2, content };
995
+ }
996
+ function generateRouteModuleAnnotations(ctx) {
997
+ return Object.values(ctx.config.routes).map((route) => {
998
+ const filename2 = getRouteModuleAnnotationsFilepath(ctx, route);
999
+ const parents = getParents(ctx, route);
1000
+ const content = import_dedent.default`
1001
+ // Generated by React Router
1002
+
1003
+ import type {
1004
+ Params,
1005
+ RouteModuleAnnotations,
1006
+ CreateLoaderData,
1007
+ CreateActionData,
1008
+ } from "react-router/internal";
1009
+
1010
+ ${parents.map((parent) => parent.import).join("\n" + " ".repeat(3))}
1011
+ type Parents = [${parents.map((parent) => parent.name).join(", ")}]
1012
+
1013
+ type Id = "${route.id}"
1014
+ type Module = typeof import("../${Pathe.filename(route.file)}.js")
1015
+
1016
+ export type unstable_Props = {
1017
+ params: Params[Id]
1018
+ loaderData: CreateLoaderData<Module>
1019
+ actionData: CreateActionData<Module>
1020
+ }
1021
+
1022
+ type Annotations = RouteModuleAnnotations<unstable_Props & {
1023
+ parents: Parents,
1024
+ module: Module,
1025
+ }>;
1026
+
1027
+ export namespace Route {
1028
+ // links
1029
+ export type LinkDescriptors = Annotations["LinkDescriptors"];
1030
+ export type LinksFunction = Annotations["LinksFunction"];
1031
+
1032
+ // meta
1033
+ export type MetaArgs = Annotations["MetaArgs"];
1034
+ export type MetaDescriptors = Annotations["MetaDescriptors"];
1035
+ export type MetaFunction = Annotations["MetaFunction"];
1036
+
1037
+ // headers
1038
+ export type HeadersArgs = Annotations["HeadersArgs"];
1039
+ export type HeadersFunction = Annotations["HeadersFunction"];
1040
+
1041
+ // unstable_middleware
1042
+ export type unstable_MiddlewareFunction = Annotations["unstable_MiddlewareFunction"];
1043
+
1044
+ // unstable_clientMiddleware
1045
+ export type unstable_ClientMiddlewareFunction = Annotations["unstable_ClientMiddlewareFunction"];
1046
+
1047
+ // loader
1048
+ export type LoaderArgs = Annotations["LoaderArgs"];
1049
+
1050
+ // clientLoader
1051
+ export type ClientLoaderArgs = Annotations["ClientLoaderArgs"];
1052
+
1053
+ // action
1054
+ export type ActionArgs = Annotations["ActionArgs"];
1055
+
1056
+ // clientAction
1057
+ export type ClientActionArgs = Annotations["ClientActionArgs"];
1058
+
1059
+ // HydrateFallback
1060
+ export type HydrateFallbackProps = Annotations["HydrateFallbackProps"];
1061
+
1062
+ // Component
1063
+ export type ComponentProps = Annotations["ComponentProps"];
1064
+
1065
+ // ErrorBoundary
1066
+ export type ErrorBoundaryProps = Annotations["ErrorBoundaryProps"];
1067
+ }
1068
+ `;
1069
+ return { filename: filename2, content };
1070
+ });
1071
+ }
1072
+ function getRouteModuleAnnotationsFilepath(ctx, route) {
1073
+ return Path3.join(
1074
+ typesDirectory(ctx),
1075
+ Path3.relative(ctx.rootDirectory, ctx.config.appDirectory),
1076
+ Path3.dirname(route.file),
1077
+ "+types/" + Pathe.filename(route.file) + ".ts"
1078
+ );
1079
+ }
1080
+ function getParents(ctx, route) {
1081
+ const typesPath = getRouteModuleAnnotationsFilepath(ctx, route);
1082
+ const lineage2 = lineage(ctx.config.routes, route);
1083
+ const parents = lineage2.slice(0, -1);
1084
+ return parents.map((parent, i) => {
1085
+ const rel = Path3.relative(
1086
+ Path3.dirname(typesPath),
1087
+ getRouteModuleAnnotationsFilepath(ctx, parent)
1088
+ );
1089
+ let source = noExtension(rel);
1090
+ if (!source.startsWith("../")) source = "./" + source;
1091
+ const name = `Parent${i}`;
1092
+ return {
1093
+ name,
1094
+ import: `import type { unstable_Props as ${name} } from "${source}.js"`
1095
+ };
1096
+ });
1097
+ }
1098
+ function noExtension(path6) {
1099
+ return Path3.join(Path3.dirname(path6), Pathe.filename(path6));
1100
+ }
1101
+ function paramsType(path6) {
1102
+ const params = parse2(path6);
1103
+ return t2.tsTypeLiteral(
1104
+ Object.entries(params).map(([param, isRequired]) => {
1105
+ const property = t2.tsPropertySignature(
1106
+ t2.stringLiteral(param),
1107
+ t2.tsTypeAnnotation(t2.tsStringKeyword())
1108
+ );
1109
+ property.optional = !isRequired;
1110
+ return property;
1111
+ })
1112
+ );
1113
+ }
1114
+
1115
+ // typegen/index.ts
1116
+ async function clearRouteModuleAnnotations(ctx) {
1117
+ await import_promises.default.rm(
1118
+ Path4.join(typesDirectory(ctx), Path4.basename(ctx.config.appDirectory)),
1119
+ { recursive: true, force: true }
1120
+ );
1121
+ }
1122
+ async function write(...files) {
1123
+ return Promise.all(
1124
+ files.map(async ({ filename: filename2, content }) => {
1125
+ await import_promises.default.mkdir(Path4.dirname(filename2), { recursive: true });
1126
+ await import_promises.default.writeFile(filename2, content);
1127
+ })
1128
+ );
1129
+ }
1130
+ async function watch(rootDirectory, { mode, logger }) {
1131
+ const ctx = await createContext2({ rootDirectory, mode, watch: true });
1132
+ await clearRouteModuleAnnotations(ctx);
1133
+ await write(
1134
+ generateFuture(ctx),
1135
+ generatePages(ctx),
1136
+ generateRoutes(ctx),
1137
+ generateServerBuild(ctx),
1138
+ ...generateRouteModuleAnnotations(ctx)
1139
+ );
1140
+ logger?.info((0, import_picocolors2.green)("generated types"), { timestamp: true, clear: true });
1141
+ ctx.configLoader.onChange(
1142
+ async ({ result, configChanged, routeConfigChanged }) => {
1143
+ if (!result.ok) {
1144
+ logger?.error((0, import_picocolors2.red)(result.error), { timestamp: true, clear: true });
1145
+ return;
1146
+ }
1147
+ ctx.config = result.value;
1148
+ if (configChanged) {
1149
+ await write(generateFuture(ctx));
1150
+ logger?.info((0, import_picocolors2.green)("regenerated types"), {
1151
+ timestamp: true,
1152
+ clear: true
1153
+ });
1154
+ }
1155
+ if (routeConfigChanged) {
1156
+ await clearRouteModuleAnnotations(ctx);
1157
+ await write(
1158
+ generatePages(ctx),
1159
+ generateRoutes(ctx),
1160
+ ...generateRouteModuleAnnotations(ctx)
1161
+ );
1162
+ logger?.info((0, import_picocolors2.green)("regenerated types"), {
1163
+ timestamp: true,
1164
+ clear: true
1165
+ });
1166
+ }
1167
+ }
1168
+ );
1169
+ return {
1170
+ close: async () => await ctx.configLoader.close()
1171
+ };
876
1172
  }
877
- var virtual = import_dedent2.default`
878
- declare module "virtual:react-router/server-build" {
879
- import { ServerBuild } from "react-router";
880
- export const assets: ServerBuild["assets"];
881
- export const assetsBuildDirectory: ServerBuild["assetsBuildDirectory"];
882
- export const basename: ServerBuild["basename"];
883
- export const entry: ServerBuild["entry"];
884
- export const future: ServerBuild["future"];
885
- export const isSpaMode: ServerBuild["isSpaMode"];
886
- export const prerender: ServerBuild["prerender"];
887
- export const publicPath: ServerBuild["publicPath"];
888
- export const routes: ServerBuild["routes"];
889
- export const ssr: ServerBuild["ssr"];
890
- export const unstable_getCriticalCss: ServerBuild["unstable_getCriticalCss"];
891
- }
892
- `;
893
1173
 
894
1174
  // vite/node-adapter.ts
895
1175
  var import_node_events = require("events");
@@ -945,7 +1225,9 @@ function fromNodeRequest(nodeReq, nodeRes) {
945
1225
  }
946
1226
  async function toNodeRequest(res, nodeRes) {
947
1227
  nodeRes.statusCode = res.status;
948
- nodeRes.statusMessage = res.statusText;
1228
+ if (!nodeRes.req || nodeRes.req.httpVersionMajor < 2) {
1229
+ nodeRes.statusMessage = res.statusText;
1230
+ }
949
1231
  let cookiesStrings = [];
950
1232
  for (let [name, value] of res.headers) {
951
1233
  if (name === "set-cookie") {
@@ -966,17 +1248,17 @@ async function toNodeRequest(res, nodeRes) {
966
1248
  }
967
1249
 
968
1250
  // vite/styles.ts
969
- var path5 = __toESM(require("path"));
1251
+ var path4 = __toESM(require("path"));
970
1252
  var import_react_router = require("react-router");
971
1253
 
972
1254
  // vite/resolve-file-url.ts
973
- var path4 = __toESM(require("path"));
1255
+ var path3 = __toESM(require("path"));
974
1256
  var resolveFileUrl = ({ rootDirectory }, filePath) => {
975
1257
  let vite2 = getVite();
976
- let relativePath = path4.relative(rootDirectory, filePath);
977
- let isWithinRoot = !relativePath.startsWith("..") && !path4.isAbsolute(relativePath);
1258
+ let relativePath = path3.relative(rootDirectory, filePath);
1259
+ let isWithinRoot = !relativePath.startsWith("..") && !path3.isAbsolute(relativePath);
978
1260
  if (!isWithinRoot) {
979
- return path4.posix.join("/@fs", vite2.normalizePath(filePath));
1261
+ return path3.posix.join("/@fs", vite2.normalizePath(filePath));
980
1262
  }
981
1263
  return "/" + vite2.normalizePath(relativePath);
982
1264
  };
@@ -1013,7 +1295,7 @@ var getStylesForFiles = async ({
1013
1295
  let deps = /* @__PURE__ */ new Set();
1014
1296
  try {
1015
1297
  for (let file of files) {
1016
- let normalizedPath = path5.resolve(rootDirectory, file).replace(/\\/g, "/");
1298
+ let normalizedPath = path4.resolve(rootDirectory, file).replace(/\\/g, "/");
1017
1299
  let node = await viteDevServer.moduleGraph.getModuleById(normalizedPath);
1018
1300
  if (!node) {
1019
1301
  try {
@@ -1114,9 +1396,9 @@ var getStylesForPathname = async ({
1114
1396
  return void 0;
1115
1397
  }
1116
1398
  let routesWithChildren = createRoutesWithChildren(reactRouterConfig.routes);
1117
- let appPath = path5.relative(process.cwd(), reactRouterConfig.appDirectory);
1399
+ let appPath = path4.relative(process.cwd(), reactRouterConfig.appDirectory);
1118
1400
  let documentRouteFiles = (0, import_react_router.matchRoutes)(routesWithChildren, pathname, reactRouterConfig.basename)?.map(
1119
- (match) => path5.resolve(appPath, reactRouterConfig.routes[match.route.id].file)
1401
+ (match) => path4.resolve(appPath, reactRouterConfig.routes[match.route.id].file)
1120
1402
  ) ?? [];
1121
1403
  let styles = await getStylesForFiles({
1122
1404
  viteDevServer,
@@ -1124,13 +1406,27 @@ var getStylesForPathname = async ({
1124
1406
  loadCssContents,
1125
1407
  files: [
1126
1408
  // Always include the client entry file when crawling the module graph for CSS
1127
- path5.relative(rootDirectory, entryClientFilePath),
1409
+ path4.relative(rootDirectory, entryClientFilePath),
1128
1410
  // Then include any styles from the matched routes
1129
1411
  ...documentRouteFiles
1130
1412
  ]
1131
1413
  });
1132
1414
  return styles;
1133
1415
  };
1416
+ var getCssStringFromViteDevModuleCode = (code) => {
1417
+ let cssContent = void 0;
1418
+ const ast = import_parser.parse(code, { sourceType: "module" });
1419
+ traverse(ast, {
1420
+ VariableDeclaration(path6) {
1421
+ const declaration = path6.node.declarations[0];
1422
+ if (declaration?.id?.type === "Identifier" && declaration.id.name === "__vite__css" && declaration.init?.type === "StringLiteral") {
1423
+ cssContent = declaration.init.value;
1424
+ path6.stop();
1425
+ }
1426
+ }
1427
+ });
1428
+ return cssContent;
1429
+ };
1134
1430
 
1135
1431
  // vite/virtual-module.ts
1136
1432
  function create(name) {
@@ -1154,10 +1450,10 @@ var removeExports = (ast, exportsToRemove) => {
1154
1450
  let exportsFiltered = false;
1155
1451
  let markedForRemoval = /* @__PURE__ */ new Set();
1156
1452
  traverse(ast, {
1157
- ExportDeclaration(path7) {
1158
- if (path7.node.type === "ExportNamedDeclaration") {
1159
- if (path7.node.specifiers.length) {
1160
- path7.node.specifiers = path7.node.specifiers.filter((specifier) => {
1453
+ ExportDeclaration(path6) {
1454
+ if (path6.node.type === "ExportNamedDeclaration") {
1455
+ if (path6.node.specifiers.length) {
1456
+ path6.node.specifiers = path6.node.specifiers.filter((specifier) => {
1161
1457
  if (specifier.type === "ExportSpecifier" && specifier.exported.type === "Identifier") {
1162
1458
  if (exportsToRemove.includes(specifier.exported.name)) {
1163
1459
  exportsFiltered = true;
@@ -1166,12 +1462,12 @@ var removeExports = (ast, exportsToRemove) => {
1166
1462
  }
1167
1463
  return true;
1168
1464
  });
1169
- if (path7.node.specifiers.length === 0) {
1170
- markedForRemoval.add(path7);
1465
+ if (path6.node.specifiers.length === 0) {
1466
+ markedForRemoval.add(path6);
1171
1467
  }
1172
1468
  }
1173
- if (path7.node.declaration?.type === "VariableDeclaration") {
1174
- let declaration = path7.node.declaration;
1469
+ if (path6.node.declaration?.type === "VariableDeclaration") {
1470
+ let declaration = path6.node.declaration;
1175
1471
  declaration.declarations = declaration.declarations.filter(
1176
1472
  (declaration2) => {
1177
1473
  if (declaration2.id.type === "Identifier" && exportsToRemove.includes(declaration2.id.name)) {
@@ -1185,30 +1481,30 @@ var removeExports = (ast, exportsToRemove) => {
1185
1481
  }
1186
1482
  );
1187
1483
  if (declaration.declarations.length === 0) {
1188
- markedForRemoval.add(path7);
1484
+ markedForRemoval.add(path6);
1189
1485
  }
1190
1486
  }
1191
- if (path7.node.declaration?.type === "FunctionDeclaration") {
1192
- let id = path7.node.declaration.id;
1487
+ if (path6.node.declaration?.type === "FunctionDeclaration") {
1488
+ let id = path6.node.declaration.id;
1193
1489
  if (id && exportsToRemove.includes(id.name)) {
1194
- markedForRemoval.add(path7);
1490
+ markedForRemoval.add(path6);
1195
1491
  }
1196
1492
  }
1197
- if (path7.node.declaration?.type === "ClassDeclaration") {
1198
- let id = path7.node.declaration.id;
1493
+ if (path6.node.declaration?.type === "ClassDeclaration") {
1494
+ let id = path6.node.declaration.id;
1199
1495
  if (id && exportsToRemove.includes(id.name)) {
1200
- markedForRemoval.add(path7);
1496
+ markedForRemoval.add(path6);
1201
1497
  }
1202
1498
  }
1203
1499
  }
1204
- if (path7.node.type === "ExportDefaultDeclaration" && exportsToRemove.includes("default")) {
1205
- markedForRemoval.add(path7);
1500
+ if (path6.node.type === "ExportDefaultDeclaration" && exportsToRemove.includes("default")) {
1501
+ markedForRemoval.add(path6);
1206
1502
  }
1207
1503
  }
1208
1504
  });
1209
1505
  if (markedForRemoval.size > 0 || exportsFiltered) {
1210
- for (let path7 of markedForRemoval) {
1211
- path7.remove();
1506
+ for (let path6 of markedForRemoval) {
1507
+ path6.remove();
1212
1508
  }
1213
1509
  (0, import_babel_dead_code_elimination.deadCodeElimination)(ast, previouslyReferencedIdentifiers);
1214
1510
  }
@@ -1279,28 +1575,28 @@ function codeToAst(code, cache, cacheKey) {
1279
1575
  )
1280
1576
  );
1281
1577
  }
1282
- function assertNodePath(path7) {
1578
+ function assertNodePath(path6) {
1283
1579
  invariant(
1284
- path7 && !Array.isArray(path7),
1285
- `Expected a Path, but got ${Array.isArray(path7) ? "an array" : path7}`
1580
+ path6 && !Array.isArray(path6),
1581
+ `Expected a Path, but got ${Array.isArray(path6) ? "an array" : path6}`
1286
1582
  );
1287
1583
  }
1288
- function assertNodePathIsStatement(path7) {
1584
+ function assertNodePathIsStatement(path6) {
1289
1585
  invariant(
1290
- path7 && !Array.isArray(path7) && t.isStatement(path7.node),
1291
- `Expected a Statement path, but got ${Array.isArray(path7) ? "an array" : path7?.node?.type}`
1586
+ path6 && !Array.isArray(path6) && t.isStatement(path6.node),
1587
+ `Expected a Statement path, but got ${Array.isArray(path6) ? "an array" : path6?.node?.type}`
1292
1588
  );
1293
1589
  }
1294
- function assertNodePathIsVariableDeclarator(path7) {
1590
+ function assertNodePathIsVariableDeclarator(path6) {
1295
1591
  invariant(
1296
- path7 && !Array.isArray(path7) && t.isVariableDeclarator(path7.node),
1297
- `Expected an Identifier path, but got ${Array.isArray(path7) ? "an array" : path7?.node?.type}`
1592
+ path6 && !Array.isArray(path6) && t.isVariableDeclarator(path6.node),
1593
+ `Expected an Identifier path, but got ${Array.isArray(path6) ? "an array" : path6?.node?.type}`
1298
1594
  );
1299
1595
  }
1300
- function assertNodePathIsPattern(path7) {
1596
+ function assertNodePathIsPattern(path6) {
1301
1597
  invariant(
1302
- path7 && !Array.isArray(path7) && t.isPattern(path7.node),
1303
- `Expected a Pattern path, but got ${Array.isArray(path7) ? "an array" : path7?.node?.type}`
1598
+ path6 && !Array.isArray(path6) && t.isPattern(path6.node),
1599
+ `Expected a Pattern path, but got ${Array.isArray(path6) ? "an array" : path6?.node?.type}`
1304
1600
  );
1305
1601
  }
1306
1602
  function getExportDependencies(code, cache, cacheKey) {
@@ -1336,8 +1632,8 @@ function getExportDependencies(code, cache, cacheKey) {
1336
1632
  }
1337
1633
  let isWithinExportDestructuring = Boolean(
1338
1634
  identifier.findParent(
1339
- (path7) => Boolean(
1340
- path7.isPattern() && path7.parentPath?.isVariableDeclarator() && path7.parentPath.parentPath?.parentPath?.isExportNamedDeclaration()
1635
+ (path6) => Boolean(
1636
+ path6.isPattern() && path6.parentPath?.isVariableDeclarator() && path6.parentPath.parentPath?.parentPath?.isExportNamedDeclaration()
1341
1637
  )
1342
1638
  )
1343
1639
  );
@@ -1415,7 +1711,7 @@ function getExportDependencies(code, cache, cacheKey) {
1415
1711
  for (let specifier of node.specifiers) {
1416
1712
  if (t.isIdentifier(specifier.exported)) {
1417
1713
  let name = specifier.exported.name;
1418
- let specifierPath = exportPath.get("specifiers").find((path7) => path7.node === specifier);
1714
+ let specifierPath = exportPath.get("specifiers").find((path6) => path6.node === specifier);
1419
1715
  invariant(
1420
1716
  specifierPath,
1421
1717
  `Expected to find specifier path for ${name}`
@@ -1432,22 +1728,22 @@ function getExportDependencies(code, cache, cacheKey) {
1432
1728
  }
1433
1729
  );
1434
1730
  }
1435
- function getDependentIdentifiersForPath(path7, state) {
1731
+ function getDependentIdentifiersForPath(path6, state) {
1436
1732
  let { visited, identifiers } = state ?? {
1437
1733
  visited: /* @__PURE__ */ new Set(),
1438
1734
  identifiers: /* @__PURE__ */ new Set()
1439
1735
  };
1440
- if (visited.has(path7)) {
1736
+ if (visited.has(path6)) {
1441
1737
  return identifiers;
1442
1738
  }
1443
- visited.add(path7);
1444
- path7.traverse({
1445
- Identifier(path8) {
1446
- if (identifiers.has(path8)) {
1739
+ visited.add(path6);
1740
+ path6.traverse({
1741
+ Identifier(path7) {
1742
+ if (identifiers.has(path7)) {
1447
1743
  return;
1448
1744
  }
1449
- identifiers.add(path8);
1450
- let binding = path8.scope.getBinding(path8.node.name);
1745
+ identifiers.add(path7);
1746
+ let binding = path7.scope.getBinding(path7.node.name);
1451
1747
  if (!binding) {
1452
1748
  return;
1453
1749
  }
@@ -1469,7 +1765,7 @@ function getDependentIdentifiersForPath(path7, state) {
1469
1765
  }
1470
1766
  }
1471
1767
  });
1472
- let topLevelStatement = getTopLevelStatementPathForPath(path7);
1768
+ let topLevelStatement = getTopLevelStatementPathForPath(path6);
1473
1769
  let withinImportStatement = topLevelStatement.isImportDeclaration();
1474
1770
  let withinExportStatement = topLevelStatement.isExportDeclaration();
1475
1771
  if (!withinImportStatement && !withinExportStatement) {
@@ -1478,9 +1774,9 @@ function getDependentIdentifiersForPath(path7, state) {
1478
1774
  identifiers
1479
1775
  });
1480
1776
  }
1481
- if (withinExportStatement && path7.isIdentifier() && (t.isPattern(path7.parentPath.node) || // [foo]
1482
- t.isPattern(path7.parentPath.parentPath?.node))) {
1483
- let variableDeclarator = path7.findParent((p) => p.isVariableDeclarator());
1777
+ if (withinExportStatement && path6.isIdentifier() && (t.isPattern(path6.parentPath.node) || // [foo]
1778
+ t.isPattern(path6.parentPath.parentPath?.node))) {
1779
+ let variableDeclarator = path6.findParent((p) => p.isVariableDeclarator());
1484
1780
  assertNodePath(variableDeclarator);
1485
1781
  getDependentIdentifiersForPath(variableDeclarator, {
1486
1782
  visited,
@@ -1489,16 +1785,16 @@ function getDependentIdentifiersForPath(path7, state) {
1489
1785
  }
1490
1786
  return identifiers;
1491
1787
  }
1492
- function getTopLevelStatementPathForPath(path7) {
1493
- let ancestry = path7.getAncestry();
1788
+ function getTopLevelStatementPathForPath(path6) {
1789
+ let ancestry = path6.getAncestry();
1494
1790
  let topLevelStatement = ancestry[ancestry.length - 2];
1495
1791
  assertNodePathIsStatement(topLevelStatement);
1496
1792
  return topLevelStatement;
1497
1793
  }
1498
1794
  function getTopLevelStatementsForPaths(paths) {
1499
1795
  let topLevelStatements = /* @__PURE__ */ new Set();
1500
- for (let path7 of paths) {
1501
- let topLevelStatement = getTopLevelStatementPathForPath(path7);
1796
+ for (let path6 of paths) {
1797
+ let topLevelStatement = getTopLevelStatementPathForPath(path6);
1502
1798
  topLevelStatements.add(topLevelStatement.node);
1503
1799
  }
1504
1800
  return topLevelStatements;
@@ -1861,7 +2157,7 @@ function getRouteChunkNameFromModuleId(id) {
1861
2157
  }
1862
2158
 
1863
2159
  // vite/with-props.ts
1864
- var import_dedent3 = __toESM(require("dedent"));
2160
+ var import_dedent2 = __toESM(require("dedent"));
1865
2161
  var vmod = create("with-props");
1866
2162
  var NAMED_COMPONENT_EXPORTS = ["HydrateFallback", "ErrorBoundary"];
1867
2163
  var plugin = {
@@ -1872,7 +2168,7 @@ var plugin = {
1872
2168
  },
1873
2169
  async load(id) {
1874
2170
  if (id !== vmod.resolvedId) return;
1875
- return import_dedent3.default`
2171
+ return import_dedent2.default`
1876
2172
  import { createElement as h } from "react";
1877
2173
  import { useActionData, useLoaderData, useMatches, useParams, useRouteError } from "react-router";
1878
2174
 
@@ -1915,24 +2211,24 @@ var plugin = {
1915
2211
  };
1916
2212
  var transform = (ast) => {
1917
2213
  const hocs = [];
1918
- function getHocUid(path7, hocName) {
1919
- const uid = path7.scope.generateUidIdentifier(hocName);
2214
+ function getHocUid(path6, hocName) {
2215
+ const uid = path6.scope.generateUidIdentifier(hocName);
1920
2216
  hocs.push([hocName, uid]);
1921
2217
  return uid;
1922
2218
  }
1923
2219
  traverse(ast, {
1924
- ExportDeclaration(path7) {
1925
- if (path7.isExportDefaultDeclaration()) {
1926
- const declaration = path7.get("declaration");
2220
+ ExportDeclaration(path6) {
2221
+ if (path6.isExportDefaultDeclaration()) {
2222
+ const declaration = path6.get("declaration");
1927
2223
  const expr = declaration.isExpression() ? declaration.node : declaration.isFunctionDeclaration() ? toFunctionExpression(declaration.node) : void 0;
1928
2224
  if (expr) {
1929
- const uid = getHocUid(path7, "withComponentProps");
2225
+ const uid = getHocUid(path6, "withComponentProps");
1930
2226
  declaration.replaceWith(t.callExpression(uid, [expr]));
1931
2227
  }
1932
2228
  return;
1933
2229
  }
1934
- if (path7.isExportNamedDeclaration()) {
1935
- const decl = path7.get("declaration");
2230
+ if (path6.isExportNamedDeclaration()) {
2231
+ const decl = path6.get("declaration");
1936
2232
  if (decl.isVariableDeclaration()) {
1937
2233
  decl.get("declarations").forEach((varDeclarator) => {
1938
2234
  const id = varDeclarator.get("id");
@@ -1942,7 +2238,7 @@ var transform = (ast) => {
1942
2238
  if (!id.isIdentifier()) return;
1943
2239
  const { name } = id.node;
1944
2240
  if (!NAMED_COMPONENT_EXPORTS.includes(name)) return;
1945
- const uid = getHocUid(path7, `with${name}Props`);
2241
+ const uid = getHocUid(path6, `with${name}Props`);
1946
2242
  init.replaceWith(t.callExpression(uid, [expr]));
1947
2243
  });
1948
2244
  return;
@@ -1952,7 +2248,7 @@ var transform = (ast) => {
1952
2248
  if (!id) return;
1953
2249
  const { name } = id;
1954
2250
  if (!NAMED_COMPONENT_EXPORTS.includes(name)) return;
1955
- const uid = getHocUid(path7, `with${name}Props`);
2251
+ const uid = getHocUid(path6, `with${name}Props`);
1956
2252
  decl.replaceWith(
1957
2253
  t.variableDeclaration("const", [
1958
2254
  t.variableDeclarator(
@@ -2017,7 +2313,6 @@ var SSR_BUNDLE_PREFIX = "ssrBundle_";
2017
2313
  function isSsrBundleEnvironmentName(name) {
2018
2314
  return name.startsWith(SSR_BUNDLE_PREFIX);
2019
2315
  }
2020
- var CSS_DEV_HELPER_ENVIRONMENT_NAME = "__react_router_css_dev_helper__";
2021
2316
  function getServerEnvironmentEntries(ctx, record) {
2022
2317
  return Object.entries(record).filter(
2023
2318
  ([name]) => ctx.buildManifest?.serverBundles ? isSsrBundleEnvironmentName(name) : name === "ssr"
@@ -2033,7 +2328,7 @@ var isRouteVirtualModule = (id) => {
2033
2328
  return isRouteEntryModuleId(id) || isRouteChunkModuleId(id);
2034
2329
  };
2035
2330
  var isServerBuildVirtualModuleId = (id) => {
2036
- return id.split("?")[0] === virtual2.serverBuild.id;
2331
+ return id.split("?")[0] === virtual.serverBuild.id;
2037
2332
  };
2038
2333
  var getServerBuildFile = (viteManifest) => {
2039
2334
  let serverBuildIds = Object.keys(viteManifest).filter(
@@ -2053,23 +2348,23 @@ var virtualHmrRuntime = create("hmr-runtime");
2053
2348
  var virtualInjectHmrRuntime = create("inject-hmr-runtime");
2054
2349
  var normalizeRelativeFilePath = (file, reactRouterConfig) => {
2055
2350
  let vite2 = getVite();
2056
- let fullPath = path6.resolve(reactRouterConfig.appDirectory, file);
2057
- let relativePath = path6.relative(reactRouterConfig.appDirectory, fullPath);
2351
+ let fullPath = path5.resolve(reactRouterConfig.appDirectory, file);
2352
+ let relativePath = path5.relative(reactRouterConfig.appDirectory, fullPath);
2058
2353
  return vite2.normalizePath(relativePath).split("?")[0];
2059
2354
  };
2060
2355
  var resolveRelativeRouteFilePath = (route, reactRouterConfig) => {
2061
2356
  let vite2 = getVite();
2062
2357
  let file = route.file;
2063
- let fullPath = path6.resolve(reactRouterConfig.appDirectory, file);
2358
+ let fullPath = path5.resolve(reactRouterConfig.appDirectory, file);
2064
2359
  return vite2.normalizePath(fullPath);
2065
2360
  };
2066
- var virtual2 = {
2361
+ var virtual = {
2067
2362
  serverBuild: create("server-build"),
2068
2363
  serverManifest: create("server-manifest"),
2069
2364
  browserManifest: create("browser-manifest")
2070
2365
  };
2071
2366
  var invalidateVirtualModules = (viteDevServer) => {
2072
- Object.values(virtual2).forEach((vmod2) => {
2367
+ Object.values(virtual).forEach((vmod2) => {
2073
2368
  let mod = viteDevServer.moduleGraph.getModuleById(vmod2.resolvedId);
2074
2369
  if (mod) {
2075
2370
  viteDevServer.moduleGraph.invalidateModule(mod);
@@ -2083,7 +2378,7 @@ var getHash = (source, maxLength) => {
2083
2378
  var resolveChunk = (ctx, viteManifest, absoluteFilePath) => {
2084
2379
  let vite2 = getVite();
2085
2380
  let rootRelativeFilePath = vite2.normalizePath(
2086
- path6.relative(ctx.rootDirectory, absoluteFilePath)
2381
+ path5.relative(ctx.rootDirectory, absoluteFilePath)
2087
2382
  );
2088
2383
  let entryChunk = viteManifest[rootRelativeFilePath];
2089
2384
  if (!entryChunk) {
@@ -2147,7 +2442,7 @@ function dedupe(array2) {
2147
2442
  return [...new Set(array2)];
2148
2443
  }
2149
2444
  var writeFileSafe = async (file, contents) => {
2150
- await fse.ensureDir(path6.dirname(file));
2445
+ await fse.ensureDir(path5.dirname(file));
2151
2446
  await fse.writeFile(file, contents);
2152
2447
  };
2153
2448
  var getExportNames = (code) => {
@@ -2173,7 +2468,7 @@ var compileRouteFile = async (viteChildCompiler, ctx, routeFile, readRouteFile)
2173
2468
  }
2174
2469
  let ssr = true;
2175
2470
  let { pluginContainer, moduleGraph } = viteChildCompiler;
2176
- let routePath = path6.resolve(ctx.reactRouterConfig.appDirectory, routeFile);
2471
+ let routePath = path5.resolve(ctx.reactRouterConfig.appDirectory, routeFile);
2177
2472
  let url2 = resolveFileUrl(ctx, routePath);
2178
2473
  let resolveId = async () => {
2179
2474
  let result = await pluginContainer.resolveId(url2, void 0, { ssr });
@@ -2215,12 +2510,12 @@ var resolveEnvironmentBuildContext = ({
2215
2510
  };
2216
2511
  return resolvedBuildContext;
2217
2512
  };
2218
- var getServerBuildDirectory = (reactRouterConfig, { serverBundleId } = {}) => path6.join(
2513
+ var getServerBuildDirectory = (reactRouterConfig, { serverBundleId } = {}) => path5.join(
2219
2514
  reactRouterConfig.buildDirectory,
2220
2515
  "server",
2221
2516
  ...serverBundleId ? [serverBundleId] : []
2222
2517
  );
2223
- var getClientBuildDirectory = (reactRouterConfig) => path6.join(reactRouterConfig.buildDirectory, "client");
2518
+ var getClientBuildDirectory = (reactRouterConfig) => path5.join(reactRouterConfig.buildDirectory, "client");
2224
2519
  var getServerBundleRouteIds = (vitePluginContext, ctx) => {
2225
2520
  if (!ctx.buildManifest) {
2226
2521
  return void 0;
@@ -2238,14 +2533,13 @@ var getServerBundleRouteIds = (vitePluginContext, ctx) => {
2238
2533
  );
2239
2534
  return Object.keys(serverBundleRoutes);
2240
2535
  };
2241
- var injectQuery = (url2, query) => url2.includes("?") ? url2.replace("?", `?${query}&`) : `${url2}?${query}`;
2242
- var defaultEntriesDir = path6.resolve(
2243
- path6.dirname(require.resolve("@react-router/dev/package.json")),
2536
+ var defaultEntriesDir = path5.resolve(
2537
+ path5.dirname(require.resolve("@react-router/dev/package.json")),
2244
2538
  "dist",
2245
2539
  "config",
2246
2540
  "defaults"
2247
2541
  );
2248
- var defaultEntries = fse.readdirSync(defaultEntriesDir).map((filename3) => path6.join(defaultEntriesDir, filename3));
2542
+ var defaultEntries = fse.readdirSync(defaultEntriesDir).map((filename2) => path5.join(defaultEntriesDir, filename2));
2249
2543
  invariant(defaultEntries.length > 0, "No default entries found");
2250
2544
  var reactRouterDevLoadContext = () => void 0;
2251
2545
  var reactRouterVitePlugin = () => {
@@ -2341,10 +2635,10 @@ var reactRouterVitePlugin = () => {
2341
2635
  }
2342
2636
  }).join("\n")}
2343
2637
  export { default as assets } from ${JSON.stringify(
2344
- virtual2.serverManifest.id
2638
+ virtual.serverManifest.id
2345
2639
  )};
2346
2640
  export const assetsBuildDirectory = ${JSON.stringify(
2347
- path6.relative(
2641
+ path5.relative(
2348
2642
  ctx.rootDirectory,
2349
2643
  getClientBuildDirectory(ctx.reactRouterConfig)
2350
2644
  )
@@ -2354,6 +2648,9 @@ var reactRouterVitePlugin = () => {
2354
2648
  export const ssr = ${ctx.reactRouterConfig.ssr};
2355
2649
  export const isSpaMode = ${isSpaMode};
2356
2650
  export const prerender = ${JSON.stringify(prerenderPaths)};
2651
+ export const routeDiscovery = ${JSON.stringify(
2652
+ ctx.reactRouterConfig.routeDiscovery
2653
+ )};
2357
2654
  export const publicPath = ${JSON.stringify(ctx.publicPath)};
2358
2655
  export const entry = { module: entryServer };
2359
2656
  export const routes = {
@@ -2380,7 +2677,7 @@ var reactRouterVitePlugin = () => {
2380
2677
  };
2381
2678
  let loadViteManifest = async (directory) => {
2382
2679
  let manifestContents = await fse.readFile(
2383
- path6.resolve(directory, ".vite", "manifest.json"),
2680
+ path5.resolve(directory, ".vite", "manifest.json"),
2384
2681
  "utf-8"
2385
2682
  );
2386
2683
  return JSON.parse(manifestContents);
@@ -2411,7 +2708,7 @@ var reactRouterVitePlugin = () => {
2411
2708
  let contents;
2412
2709
  try {
2413
2710
  contents = await fse.readFile(
2414
- path6.join(entry.path, entry.name),
2711
+ path5.join(entry.path, entry.name),
2415
2712
  "utf-8"
2416
2713
  );
2417
2714
  } catch (e) {
@@ -2420,7 +2717,7 @@ var reactRouterVitePlugin = () => {
2420
2717
  }
2421
2718
  let hash = (0, import_node_crypto.createHash)("sha384").update(contents).digest().toString("base64");
2422
2719
  let filepath = getVite().normalizePath(
2423
- path6.relative(clientBuildDirectory, path6.join(entry.path, entry.name))
2720
+ path5.relative(clientBuildDirectory, path5.join(entry.path, entry.name))
2424
2721
  );
2425
2722
  sriManifest[`${ctx2.publicPath}${filepath}`] = `sha384-${hash}`;
2426
2723
  }
@@ -2447,7 +2744,7 @@ var reactRouterVitePlugin = () => {
2447
2744
  );
2448
2745
  let enforceSplitRouteModules = ctx.reactRouterConfig.future.unstable_splitRouteModules === "enforce";
2449
2746
  for (let route of Object.values(ctx.reactRouterConfig.routes)) {
2450
- let routeFile = path6.join(ctx.reactRouterConfig.appDirectory, route.file);
2747
+ let routeFile = path5.join(ctx.reactRouterConfig.appDirectory, route.file);
2451
2748
  let sourceExports = routeManifestExports[route.id];
2452
2749
  let isRootRoute = route.parentId === void 0;
2453
2750
  let hasClientAction = sourceExports.includes("clientAction");
@@ -2523,7 +2820,7 @@ var reactRouterVitePlugin = () => {
2523
2820
  }
2524
2821
  let fingerprintedValues = { entry, routes: browserRoutes };
2525
2822
  let version = getHash(JSON.stringify(fingerprintedValues), 8);
2526
- let manifestPath = path6.posix.join(
2823
+ let manifestPath = path5.posix.join(
2527
2824
  viteConfig.build.assetsDir,
2528
2825
  `manifest-${version}.js`
2529
2826
  );
@@ -2535,7 +2832,7 @@ var reactRouterVitePlugin = () => {
2535
2832
  sri: void 0
2536
2833
  };
2537
2834
  await writeFileSafe(
2538
- path6.join(getClientBuildDirectory(ctx.reactRouterConfig), manifestPath),
2835
+ path5.join(getClientBuildDirectory(ctx.reactRouterConfig), manifestPath),
2539
2836
  `window.__reactRouterManifest=${JSON.stringify(
2540
2837
  reactRouterBrowserManifest
2541
2838
  )};`
@@ -2620,7 +2917,7 @@ var reactRouterVitePlugin = () => {
2620
2917
  let sri = void 0;
2621
2918
  let reactRouterManifestForDev = {
2622
2919
  version: String(Math.random()),
2623
- url: combineURLs(ctx.publicPath, virtual2.browserManifest.url),
2920
+ url: combineURLs(ctx.publicPath, virtual.browserManifest.url),
2624
2921
  hmr: {
2625
2922
  runtime: combineURLs(ctx.publicPath, virtualInjectHmrRuntime.url)
2626
2923
  },
@@ -2645,31 +2942,17 @@ var reactRouterVitePlugin = () => {
2645
2942
  if (dep.file && isCssModulesFile(dep.file)) {
2646
2943
  return cssModulesManifest[dep.file];
2647
2944
  }
2648
- const vite2 = getVite();
2649
- const viteMajor = parseInt(vite2.version.split(".")[0], 10);
2650
- const url2 = viteMajor >= 6 ? (
2651
- // We need the ?inline query in Vite v6 when loading CSS in SSR
2652
- // since it does not expose the default export for CSS in a
2653
- // server environment. This is to align with non-SSR
2654
- // environments. For backwards compatibility with v5 we keep
2655
- // using the URL without ?inline query because the HMR code was
2656
- // relying on the implicit SSR-client module graph relationship.
2657
- injectQuery(dep.url, "inline")
2658
- ) : dep.url;
2659
- let cssMod;
2660
- if (ctx.reactRouterConfig.future.unstable_viteEnvironmentApi) {
2661
- const cssDevHelperEnvironment = viteDevServer.environments[CSS_DEV_HELPER_ENVIRONMENT_NAME];
2662
- invariant(cssDevHelperEnvironment, "Missing CSS dev helper environment");
2663
- invariant(vite2.isRunnableDevEnvironment(cssDevHelperEnvironment));
2664
- cssMod = await cssDevHelperEnvironment.runner.import(url2);
2665
- } else {
2666
- cssMod = await viteDevServer.ssrLoadModule(url2);
2667
- }
2945
+ let transformedCssCode = (await viteDevServer.transformRequest(dep.url))?.code;
2668
2946
  invariant(
2669
- typeof cssMod === "object" && cssMod !== null && "default" in cssMod && typeof cssMod.default === "string",
2947
+ transformedCssCode,
2670
2948
  `Failed to load CSS for ${dep.file ?? dep.url}`
2671
2949
  );
2672
- return cssMod.default;
2950
+ let cssString = getCssStringFromViteDevModuleCode(transformedCssCode);
2951
+ invariant(
2952
+ typeof cssString === "string",
2953
+ `Failed to extract CSS for ${dep.file ?? dep.url}`
2954
+ );
2955
+ return cssString;
2673
2956
  };
2674
2957
  return [
2675
2958
  {
@@ -2687,14 +2970,17 @@ var reactRouterVitePlugin = () => {
2687
2970
  prefix: "[react-router]"
2688
2971
  });
2689
2972
  rootDirectory = viteUserConfig.root ?? process.env.REACT_ROUTER_ROOT ?? process.cwd();
2973
+ let mode = viteConfigEnv.mode;
2690
2974
  if (viteCommand === "serve") {
2691
2975
  typegenWatcherPromise = watch(rootDirectory, {
2976
+ mode,
2692
2977
  // ignore `info` logs from typegen since they are redundant when Vite plugin logs are active
2693
2978
  logger: vite2.createLogger("warn", { prefix: "[react-router]" })
2694
2979
  });
2695
2980
  }
2696
2981
  reactRouterConfigLoader = await createConfigLoader({
2697
2982
  rootDirectory,
2983
+ mode,
2698
2984
  watch: viteCommand === "serve"
2699
2985
  });
2700
2986
  await updatePluginContext();
@@ -2952,7 +3238,8 @@ var reactRouterVitePlugin = () => {
2952
3238
  reactRouterConfigLoader.onChange(
2953
3239
  async ({
2954
3240
  result,
2955
- configCodeUpdated,
3241
+ configCodeChanged,
3242
+ routeConfigCodeChanged,
2956
3243
  configChanged,
2957
3244
  routeConfigChanged
2958
3245
  }) => {
@@ -2964,19 +3251,13 @@ var reactRouterVitePlugin = () => {
2964
3251
  });
2965
3252
  return;
2966
3253
  }
2967
- if (routeConfigChanged) {
2968
- logger.info(import_picocolors3.default.green("Route config changed."), {
2969
- clear: true,
2970
- timestamp: true
2971
- });
2972
- } else if (configCodeUpdated) {
2973
- logger.info(import_picocolors3.default.green("Config updated."), {
2974
- clear: true,
2975
- timestamp: true
2976
- });
2977
- }
3254
+ let message = configChanged ? "Config changed." : routeConfigChanged ? "Route config changed." : configCodeChanged ? "Config saved." : routeConfigCodeChanged ? " Route config saved." : "Config saved";
3255
+ logger.info(import_picocolors3.default.green(message), {
3256
+ clear: true,
3257
+ timestamp: true
3258
+ });
2978
3259
  await updatePluginContext();
2979
- if (configChanged) {
3260
+ if (configChanged || routeConfigChanged) {
2980
3261
  invalidateVirtualModules(viteDevServer);
2981
3262
  }
2982
3263
  }
@@ -3017,11 +3298,11 @@ var reactRouterVitePlugin = () => {
3017
3298
  return;
3018
3299
  }
3019
3300
  build = await ssrEnvironment.runner.import(
3020
- virtual2.serverBuild.id
3301
+ virtual.serverBuild.id
3021
3302
  );
3022
3303
  } else {
3023
3304
  build = await viteDevServer.ssrLoadModule(
3024
- virtual2.serverBuild.id
3305
+ virtual.serverBuild.id
3025
3306
  );
3026
3307
  }
3027
3308
  let handler = (0, import_react_router2.createRequestHandler)(build, "development");
@@ -3058,8 +3339,8 @@ var reactRouterVitePlugin = () => {
3058
3339
  let ssrAssetPaths = getViteManifestAssetPaths(ssrViteManifest);
3059
3340
  let movedAssetPaths = [];
3060
3341
  for (let ssrAssetPath of ssrAssetPaths) {
3061
- let src = path6.join(serverBuildDirectory, ssrAssetPath);
3062
- let dest = path6.join(clientBuildDirectory, ssrAssetPath);
3342
+ let src = path5.join(serverBuildDirectory, ssrAssetPath);
3343
+ let dest = path5.join(clientBuildDirectory, ssrAssetPath);
3063
3344
  if (!fse.existsSync(dest)) {
3064
3345
  await fse.move(src, dest);
3065
3346
  movedAssetPaths.push(dest);
@@ -3072,7 +3353,7 @@ var reactRouterVitePlugin = () => {
3072
3353
  );
3073
3354
  await Promise.all(
3074
3355
  ssrCssPaths.map(
3075
- (cssPath) => fse.remove(path6.join(serverBuildDirectory, cssPath))
3356
+ (cssPath) => fse.remove(path5.join(serverBuildDirectory, cssPath))
3076
3357
  )
3077
3358
  );
3078
3359
  if (movedAssetPaths.length) {
@@ -3081,12 +3362,13 @@ var reactRouterVitePlugin = () => {
3081
3362
  "",
3082
3363
  `${import_picocolors3.default.green("\u2713")} ${movedAssetPaths.length} asset${movedAssetPaths.length > 1 ? "s" : ""} moved from React Router server build to client assets.`,
3083
3364
  ...movedAssetPaths.map(
3084
- (movedAssetPath) => import_picocolors3.default.dim(path6.relative(ctx.rootDirectory, movedAssetPath))
3365
+ (movedAssetPath) => import_picocolors3.default.dim(path5.relative(ctx.rootDirectory, movedAssetPath))
3085
3366
  ),
3086
3367
  ""
3087
3368
  ].join("\n")
3088
3369
  );
3089
3370
  }
3371
+ process.env.IS_RR_BUILD_REQUEST = "yes";
3090
3372
  if (isPrerenderingEnabled(ctx.reactRouterConfig)) {
3091
3373
  await handlePrerender(
3092
3374
  viteConfig,
@@ -3159,7 +3441,7 @@ var reactRouterVitePlugin = () => {
3159
3441
  );
3160
3442
  let isMainChunkExport = (name) => !chunkedExports.includes(name);
3161
3443
  let mainChunkReexports = sourceExports.filter(isMainChunkExport).join(", ");
3162
- let chunkBasePath = `./${path6.basename(id)}`;
3444
+ let chunkBasePath = `./${path5.basename(id)}`;
3163
3445
  return [
3164
3446
  `export { ${mainChunkReexports} } from "${getRouteChunkModuleId(
3165
3447
  chunkBasePath,
@@ -3179,7 +3461,7 @@ var reactRouterVitePlugin = () => {
3179
3461
  async transform(code, id, options) {
3180
3462
  if (!id.endsWith(BUILD_CLIENT_ROUTE_QUERY_STRING)) return;
3181
3463
  let routeModuleId = id.replace(BUILD_CLIENT_ROUTE_QUERY_STRING, "");
3182
- let routeFileName = path6.basename(routeModuleId);
3464
+ let routeFileName = path5.basename(routeModuleId);
3183
3465
  let sourceExports = await getRouteModuleExports(
3184
3466
  viteChildCompiler,
3185
3467
  ctx,
@@ -3245,16 +3527,16 @@ var reactRouterVitePlugin = () => {
3245
3527
  name: "react-router:virtual-modules",
3246
3528
  enforce: "pre",
3247
3529
  resolveId(id) {
3248
- const vmod2 = Object.values(virtual2).find((vmod3) => vmod3.id === id);
3530
+ const vmod2 = Object.values(virtual).find((vmod3) => vmod3.id === id);
3249
3531
  if (vmod2) return vmod2.resolvedId;
3250
3532
  },
3251
3533
  async load(id) {
3252
3534
  switch (id) {
3253
- case virtual2.serverBuild.resolvedId: {
3535
+ case virtual.serverBuild.resolvedId: {
3254
3536
  let routeIds = getServerBundleRouteIds(this, ctx);
3255
3537
  return await getServerEntry({ routeIds });
3256
3538
  }
3257
- case virtual2.serverManifest.resolvedId: {
3539
+ case virtual.serverManifest.resolvedId: {
3258
3540
  let routeIds = getServerBundleRouteIds(this, ctx);
3259
3541
  let reactRouterManifest = viteCommand === "build" ? (await generateReactRouterManifestsForBuild({
3260
3542
  routeIds
@@ -3272,7 +3554,7 @@ var reactRouterVitePlugin = () => {
3272
3554
  es6: true
3273
3555
  })};`;
3274
3556
  }
3275
- case virtual2.browserManifest.resolvedId: {
3557
+ case virtual.browserManifest.resolvedId: {
3276
3558
  if (viteCommand === "build") {
3277
3559
  throw new Error("This module only exists in development");
3278
3560
  }
@@ -3306,7 +3588,7 @@ var reactRouterVitePlugin = () => {
3306
3588
  }
3307
3589
  let vite2 = getVite();
3308
3590
  let importerShort = vite2.normalizePath(
3309
- path6.relative(ctx.rootDirectory, importer)
3591
+ path5.relative(ctx.rootDirectory, importer)
3310
3592
  );
3311
3593
  if (isRoute(ctx.reactRouterConfig, importer)) {
3312
3594
  let serverOnlyExports = SERVER_ONLY_ROUTE_EXPORTS.map(
@@ -3429,10 +3711,10 @@ var reactRouterVitePlugin = () => {
3429
3711
  },
3430
3712
  async load(id) {
3431
3713
  if (id !== virtualHmrRuntime.resolvedId) return;
3432
- let reactRefreshDir = path6.dirname(
3714
+ let reactRefreshDir = path5.dirname(
3433
3715
  require.resolve("react-refresh/package.json")
3434
3716
  );
3435
- let reactRefreshRuntimePath = path6.join(
3717
+ let reactRefreshRuntimePath = path5.join(
3436
3718
  reactRefreshDir,
3437
3719
  "cjs/react-refresh-runtime.development.js"
3438
3720
  );
@@ -3613,7 +3895,7 @@ if (import.meta.hot && !inWebWorker) {
3613
3895
  function getRoute(pluginConfig, file) {
3614
3896
  let vite2 = getVite();
3615
3897
  let routePath = vite2.normalizePath(
3616
- path6.relative(pluginConfig.appDirectory, file)
3898
+ path5.relative(pluginConfig.appDirectory, file)
3617
3899
  );
3618
3900
  let route = Object.values(pluginConfig.routes).find(
3619
3901
  (r) => vite2.normalizePath(r.file) === routePath
@@ -3652,7 +3934,7 @@ async function getRouteMetadata(cache, ctx, viteChildCompiler, route, readRouteF
3652
3934
  caseSensitive: route.caseSensitive,
3653
3935
  url: combineURLs(
3654
3936
  ctx.publicPath,
3655
- "/" + path6.relative(
3937
+ "/" + path5.relative(
3656
3938
  ctx.rootDirectory,
3657
3939
  resolveRelativeRouteFilePath(route, ctx.reactRouterConfig)
3658
3940
  )
@@ -3680,7 +3962,7 @@ function isSpaModeEnabled(reactRouterConfig) {
3680
3962
  return reactRouterConfig.ssr === false && !isPrerenderingEnabled(reactRouterConfig);
3681
3963
  }
3682
3964
  async function getPrerenderBuildAndHandler(viteConfig, serverBuildDirectory, serverBuildFile) {
3683
- let serverBuildPath = path6.join(serverBuildDirectory, serverBuildFile);
3965
+ let serverBuildPath = path5.join(serverBuildDirectory, serverBuildFile);
3684
3966
  let build = await import(url.pathToFileURL(serverBuildPath).toString());
3685
3967
  let { createRequestHandler: createHandler } = await import("react-router");
3686
3968
  return {
@@ -3703,16 +3985,16 @@ async function handleSpaMode(viteConfig, reactRouterConfig, serverBuildDirectory
3703
3985
  let response = await handler(request);
3704
3986
  let html = await response.text();
3705
3987
  let isPrerenderSpaFallback = build.prerender.includes("/");
3706
- let filename3 = isPrerenderSpaFallback ? "__spa-fallback.html" : "index.html";
3988
+ let filename2 = isPrerenderSpaFallback ? "__spa-fallback.html" : "index.html";
3707
3989
  if (response.status !== 200) {
3708
3990
  if (isPrerenderSpaFallback) {
3709
3991
  throw new Error(
3710
- `Prerender: Received a ${response.status} status code from \`entry.server.tsx\` while prerendering your \`${filename3}\` file.
3992
+ `Prerender: Received a ${response.status} status code from \`entry.server.tsx\` while prerendering your \`${filename2}\` file.
3711
3993
  ` + html
3712
3994
  );
3713
3995
  } else {
3714
3996
  throw new Error(
3715
- `SPA Mode: Received a ${response.status} status code from \`entry.server.tsx\` while prerendering your \`${filename3}\` file.
3997
+ `SPA Mode: Received a ${response.status} status code from \`entry.server.tsx\` while prerendering your \`${filename2}\` file.
3716
3998
  ` + html
3717
3999
  );
3718
4000
  }
@@ -3722,9 +4004,9 @@ async function handleSpaMode(viteConfig, reactRouterConfig, serverBuildDirectory
3722
4004
  "SPA Mode: Did you forget to include `<Scripts/>` in your root route? Your pre-rendered HTML cannot hydrate without `<Scripts />`."
3723
4005
  );
3724
4006
  }
3725
- await fse.writeFile(path6.join(clientBuildDirectory, filename3), html);
3726
- let prettyDir = path6.relative(process.cwd(), clientBuildDirectory);
3727
- let prettyPath = path6.join(prettyDir, filename3);
4007
+ await fse.writeFile(path5.join(clientBuildDirectory, filename2), html);
4008
+ let prettyDir = path5.relative(process.cwd(), clientBuildDirectory);
4009
+ let prettyPath = path5.join(prettyDir, filename2);
3728
4010
  if (build.prerender.length > 0) {
3729
4011
  viteConfig.logger.info(
3730
4012
  `Prerender (html): SPA Fallback -> ${import_picocolors3.default.bold(prettyPath)}`
@@ -3740,22 +4022,17 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
3740
4022
  serverBuildPath
3741
4023
  );
3742
4024
  let routes = createPrerenderRoutes(reactRouterConfig.routes);
3743
- for (let path7 of build.prerender) {
3744
- let matches = (0, import_react_router2.matchRoutes)(routes, `/${path7}/`.replace(/^\/\/+/, "/"));
4025
+ for (let path6 of build.prerender) {
4026
+ let matches = (0, import_react_router2.matchRoutes)(routes, `/${path6}/`.replace(/^\/\/+/, "/"));
3745
4027
  if (!matches) {
3746
4028
  throw new Error(
3747
- `Unable to prerender path because it does not match any routes: ${path7}`
4029
+ `Unable to prerender path because it does not match any routes: ${path6}`
3748
4030
  );
3749
4031
  }
3750
4032
  }
3751
4033
  let buildRoutes = createPrerenderRoutes(build.routes);
3752
- let headers = {
3753
- // Header that can be used in the loader to know if you're running at
3754
- // build time or runtime
3755
- "X-React-Router-Prerender": "yes"
3756
- };
3757
- for (let path7 of build.prerender) {
3758
- let matches = (0, import_react_router2.matchRoutes)(buildRoutes, `/${path7}/`.replace(/^\/\/+/, "/"));
4034
+ for (let path6 of build.prerender) {
4035
+ let matches = (0, import_react_router2.matchRoutes)(buildRoutes, `/${path6}/`.replace(/^\/\/+/, "/"));
3759
4036
  if (!matches) {
3760
4037
  continue;
3761
4038
  }
@@ -3768,20 +4045,18 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
3768
4045
  if (manifestRoute.loader) {
3769
4046
  await prerenderData(
3770
4047
  handler,
3771
- path7,
4048
+ path6,
3772
4049
  [leafRoute.id],
3773
4050
  clientBuildDirectory,
3774
4051
  reactRouterConfig,
3775
- viteConfig,
3776
- { headers }
4052
+ viteConfig
3777
4053
  );
3778
4054
  await prerenderResourceRoute(
3779
4055
  handler,
3780
- path7,
4056
+ path6,
3781
4057
  clientBuildDirectory,
3782
4058
  reactRouterConfig,
3783
- viteConfig,
3784
- { headers }
4059
+ viteConfig
3785
4060
  );
3786
4061
  } else {
3787
4062
  viteConfig.logger.warn(
@@ -3796,26 +4071,24 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
3796
4071
  if (!isResourceRoute && hasLoaders) {
3797
4072
  data = await prerenderData(
3798
4073
  handler,
3799
- path7,
4074
+ path6,
3800
4075
  null,
3801
4076
  clientBuildDirectory,
3802
4077
  reactRouterConfig,
3803
- viteConfig,
3804
- { headers }
4078
+ viteConfig
3805
4079
  );
3806
4080
  }
3807
4081
  await prerenderRoute(
3808
4082
  handler,
3809
- path7,
4083
+ path6,
3810
4084
  clientBuildDirectory,
3811
4085
  reactRouterConfig,
3812
4086
  viteConfig,
3813
4087
  data ? {
3814
4088
  headers: {
3815
- ...headers,
3816
4089
  "X-React-Router-Prerender-Data": encodeURI(data)
3817
4090
  }
3818
- } : { headers }
4091
+ } : void 0
3819
4092
  );
3820
4093
  }
3821
4094
  }
@@ -3860,9 +4133,9 @@ async function prerenderData(handler, prerenderPath, onlyRoutes, clientBuildDire
3860
4133
  ${normalizedPath}`
3861
4134
  );
3862
4135
  }
3863
- let outdir = path6.relative(process.cwd(), clientBuildDirectory);
3864
- let outfile = path6.join(outdir, ...normalizedPath.split("/"));
3865
- await fse.ensureDir(path6.dirname(outfile));
4136
+ let outdir = path5.relative(process.cwd(), clientBuildDirectory);
4137
+ let outfile = path5.join(outdir, ...normalizedPath.split("/"));
4138
+ await fse.ensureDir(path5.dirname(outfile));
3866
4139
  await fse.outputFile(outfile, data);
3867
4140
  viteConfig.logger.info(
3868
4141
  `Prerender (data): ${prerenderPath} -> ${import_picocolors3.default.bold(outfile)}`
@@ -3899,9 +4172,9 @@ async function prerenderRoute(handler, prerenderPath, clientBuildDirectory, reac
3899
4172
  ${html}`
3900
4173
  );
3901
4174
  }
3902
- let outdir = path6.relative(process.cwd(), clientBuildDirectory);
3903
- let outfile = path6.join(outdir, ...normalizedPath.split("/"), "index.html");
3904
- await fse.ensureDir(path6.dirname(outfile));
4175
+ let outdir = path5.relative(process.cwd(), clientBuildDirectory);
4176
+ let outfile = path5.join(outdir, ...normalizedPath.split("/"), "index.html");
4177
+ await fse.ensureDir(path5.dirname(outfile));
3905
4178
  await fse.outputFile(outfile, html);
3906
4179
  viteConfig.logger.info(
3907
4180
  `Prerender (html): ${prerenderPath} -> ${import_picocolors3.default.bold(outfile)}`
@@ -3918,9 +4191,9 @@ async function prerenderResourceRoute(handler, prerenderPath, clientBuildDirecto
3918
4191
  ${content.toString("utf8")}`
3919
4192
  );
3920
4193
  }
3921
- let outdir = path6.relative(process.cwd(), clientBuildDirectory);
3922
- let outfile = path6.join(outdir, ...normalizedPath.split("/"));
3923
- await fse.ensureDir(path6.dirname(outfile));
4194
+ let outdir = path5.relative(process.cwd(), clientBuildDirectory);
4195
+ let outfile = path5.join(outdir, ...normalizedPath.split("/"));
4196
+ await fse.ensureDir(path5.dirname(outfile));
3924
4197
  await fse.outputFile(outfile, content);
3925
4198
  viteConfig.logger.info(
3926
4199
  `Prerender (resource): ${prerenderPath} -> ${import_picocolors3.default.bold(outfile)}`
@@ -3996,14 +4269,14 @@ async function validateSsrFalsePrerenderExports(viteConfig, ctx, manifest, viteC
3996
4269
  }
3997
4270
  let prerenderRoutes = createPrerenderRoutes(manifest.routes);
3998
4271
  let prerenderedRoutes = /* @__PURE__ */ new Set();
3999
- for (let path7 of prerenderPaths) {
4272
+ for (let path6 of prerenderPaths) {
4000
4273
  let matches = (0, import_react_router2.matchRoutes)(
4001
4274
  prerenderRoutes,
4002
- `/${path7}/`.replace(/^\/\/+/, "/")
4275
+ `/${path6}/`.replace(/^\/\/+/, "/")
4003
4276
  );
4004
4277
  invariant(
4005
4278
  matches,
4006
- `Unable to prerender path because it does not match any routes: ${path7}`
4279
+ `Unable to prerender path because it does not match any routes: ${path6}`
4007
4280
  );
4008
4281
  matches.forEach((m) => prerenderedRoutes.add(m.route.id));
4009
4282
  }
@@ -4170,8 +4443,8 @@ function validateRouteChunks({
4170
4443
  async function cleanBuildDirectory(viteConfig, ctx) {
4171
4444
  let buildDirectory = ctx.reactRouterConfig.buildDirectory;
4172
4445
  let isWithinRoot = () => {
4173
- let relativePath = path6.relative(ctx.rootDirectory, buildDirectory);
4174
- return !relativePath.startsWith("..") && !path6.isAbsolute(relativePath);
4446
+ let relativePath = path5.relative(ctx.rootDirectory, buildDirectory);
4447
+ return !relativePath.startsWith("..") && !path5.isAbsolute(relativePath);
4175
4448
  };
4176
4449
  if (viteConfig.build.emptyOutDir ?? isWithinRoot()) {
4177
4450
  await fse.remove(buildDirectory);
@@ -4182,7 +4455,7 @@ async function cleanViteManifests(environmentsOptions, ctx) {
4182
4455
  ([environmentName, options]) => {
4183
4456
  let outDir = options.build?.outDir;
4184
4457
  invariant(outDir, `Expected build.outDir for ${environmentName}`);
4185
- return path6.join(outDir, ".vite/manifest.json");
4458
+ return path5.join(outDir, ".vite/manifest.json");
4186
4459
  }
4187
4460
  );
4188
4461
  await Promise.all(
@@ -4192,7 +4465,7 @@ async function cleanViteManifests(environmentsOptions, ctx) {
4192
4465
  if (!ctx.viteManifestEnabled) {
4193
4466
  await fse.remove(viteManifestPath);
4194
4467
  }
4195
- let viteDir = path6.dirname(viteManifestPath);
4468
+ let viteDir = path5.dirname(viteManifestPath);
4196
4469
  let viteDirFiles = await fse.readdir(viteDir);
4197
4470
  if (viteDirFiles.length === 0) {
4198
4471
  await fse.remove(viteDir);
@@ -4210,12 +4483,12 @@ async function getBuildManifest({
4210
4483
  }
4211
4484
  let { normalizePath } = await import("vite");
4212
4485
  let serverBuildDirectory = getServerBuildDirectory(reactRouterConfig);
4213
- let resolvedAppDirectory = path6.resolve(rootDirectory, appDirectory);
4486
+ let resolvedAppDirectory = path5.resolve(rootDirectory, appDirectory);
4214
4487
  let rootRelativeRoutes = Object.fromEntries(
4215
4488
  Object.entries(routes).map(([id, route]) => {
4216
- let filePath = path6.join(resolvedAppDirectory, route.file);
4489
+ let filePath = path5.join(resolvedAppDirectory, route.file);
4217
4490
  let rootRelativeFilePath = normalizePath(
4218
- path6.relative(rootDirectory, filePath)
4491
+ path5.relative(rootDirectory, filePath)
4219
4492
  );
4220
4493
  return [id, { ...route, file: rootRelativeFilePath }];
4221
4494
  })
@@ -4233,7 +4506,7 @@ async function getBuildManifest({
4233
4506
  (route2) => configRouteToBranchRoute({
4234
4507
  ...route2,
4235
4508
  // Ensure absolute paths are passed to the serverBundles function
4236
- file: path6.join(resolvedAppDirectory, route2.file)
4509
+ file: path5.join(resolvedAppDirectory, route2.file)
4237
4510
  })
4238
4511
  )
4239
4512
  });
@@ -4257,10 +4530,10 @@ async function getBuildManifest({
4257
4530
  buildManifest.serverBundles[serverBundleId] ??= {
4258
4531
  id: serverBundleId,
4259
4532
  file: normalizePath(
4260
- path6.join(
4261
- path6.relative(
4533
+ path5.join(
4534
+ path5.relative(
4262
4535
  rootDirectory,
4263
- path6.join(serverBuildDirectory, serverBundleId)
4536
+ path5.join(serverBuildDirectory, serverBundleId)
4264
4537
  ),
4265
4538
  reactRouterConfig.serverBuildFile
4266
4539
  )
@@ -4279,10 +4552,10 @@ function mergeEnvironmentOptions(base, ...overrides) {
4279
4552
  }
4280
4553
  async function getEnvironmentOptionsResolvers(ctx, viteCommand) {
4281
4554
  let { serverBuildFile, serverModuleFormat } = ctx.reactRouterConfig;
4282
- let packageRoot = path6.dirname(
4555
+ let packageRoot = path5.dirname(
4283
4556
  require.resolve("@react-router/dev/package.json")
4284
4557
  );
4285
- let { moduleSyncEnabled } = await import(`file:///${path6.join(packageRoot, "module-sync-enabled/index.mjs")}`);
4558
+ let { moduleSyncEnabled } = await import(`file:///${path5.join(packageRoot, "module-sync-enabled/index.mjs")}`);
4286
4559
  let vite2 = getVite();
4287
4560
  let viteServerConditions = [
4288
4561
  ...vite2.defaultServerConditions ?? [],
@@ -4339,7 +4612,7 @@ async function getEnvironmentOptionsResolvers(ctx, viteCommand) {
4339
4612
  copyPublicDir: false,
4340
4613
  // Assets in the public directory are only used by the client
4341
4614
  rollupOptions: {
4342
- input: (ctx.reactRouterConfig.future.unstable_viteEnvironmentApi ? viteUserConfig.environments?.ssr?.build?.rollupOptions?.input : viteUserConfig.build?.rollupOptions?.input) ?? virtual2.serverBuild.id,
4615
+ input: (ctx.reactRouterConfig.future.unstable_viteEnvironmentApi ? viteUserConfig.environments?.ssr?.build?.rollupOptions?.input : viteUserConfig.build?.rollupOptions?.input) ?? virtual.serverBuild.id,
4343
4616
  output: {
4344
4617
  entryFileNames: serverBuildFile,
4345
4618
  format: serverModuleFormat
@@ -4356,7 +4629,7 @@ async function getEnvironmentOptionsResolvers(ctx, viteCommand) {
4356
4629
  ctx.entryClientFilePath,
4357
4630
  ...Object.values(ctx.reactRouterConfig.routes).flatMap(
4358
4631
  (route) => {
4359
- let routeFilePath = path6.resolve(
4632
+ let routeFilePath = path5.resolve(
4360
4633
  ctx.reactRouterConfig.appDirectory,
4361
4634
  route.file
4362
4635
  );
@@ -4379,8 +4652,9 @@ async function getEnvironmentOptionsResolvers(ctx, viteCommand) {
4379
4652
  ""
4380
4653
  ) : null;
4381
4654
  let routeChunkSuffix = routeChunkName ? `-${(0, import_kebabCase.default)(routeChunkName)}` : "";
4382
- return path6.posix.join(
4383
- (ctx.reactRouterConfig.future.unstable_viteEnvironmentApi ? viteUserConfig?.environments?.client?.build?.assetsDir : viteUserConfig?.build?.assetsDir) ?? "assets",
4655
+ let assetsDir = (ctx.reactRouterConfig.future.unstable_viteEnvironmentApi ? viteUserConfig?.environments?.client?.build?.assetsDir : null) ?? viteUserConfig?.build?.assetsDir ?? "assets";
4656
+ return path5.posix.join(
4657
+ assetsDir,
4384
4658
  `[name]${routeChunkSuffix}-[hash].js`
4385
4659
  );
4386
4660
  }
@@ -4415,9 +4689,6 @@ async function getEnvironmentOptionsResolvers(ctx, viteCommand) {
4415
4689
  }
4416
4690
  });
4417
4691
  }
4418
- if (ctx.reactRouterConfig.future.unstable_viteEnvironmentApi && viteCommand === "serve") {
4419
- environmentOptionsResolvers[CSS_DEV_HELPER_ENVIRONMENT_NAME] = () => ({});
4420
- }
4421
4692
  return environmentOptionsResolvers;
4422
4693
  }
4423
4694
  function resolveEnvironmentsOptions(environmentResolvers, resolverOptions) {