@react-router/dev 0.0.0-experimental-a25eed86d → 0.0.0-experimental-ab0e85b04

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-a25eed86d
3
+ * @react-router/dev v0.0.0-experimental-ab0e85b04
4
4
  *
5
5
  * Copyright (c) Remix Software Inc.
6
6
  *
@@ -125,13 +125,15 @@ var init_ssr_externals = __esm({
125
125
  // vite/vite-node.ts
126
126
  async function createContext({
127
127
  root,
128
- mode
128
+ mode,
129
+ customLogger
129
130
  }) {
130
131
  await preloadVite();
131
132
  const vite2 = getVite();
132
133
  const devServer = await vite2.createServer({
133
134
  root,
134
135
  mode,
136
+ customLogger,
135
137
  server: {
136
138
  preTransformRequests: false,
137
139
  hmr: false,
@@ -214,7 +216,7 @@ function validateRouteConfig({
214
216
  `Route config in "${routeConfigFile}" is invalid.`,
215
217
  root ? `${root}` : [],
216
218
  nested ? Object.entries(nested).map(
217
- ([path9, message]) => `Path: routes.${path9}
219
+ ([path8, message]) => `Path: routes.${path8}
218
220
  ${message}`
219
221
  ) : []
220
222
  ].flat().join("\n\n")
@@ -299,7 +301,8 @@ function err(error) {
299
301
  async function resolveConfig({
300
302
  root,
301
303
  viteNodeContext,
302
- reactRouterConfigFile
304
+ reactRouterConfigFile,
305
+ skipRoutes
303
306
  }) {
304
307
  let reactRouterUserConfig = {};
305
308
  if (reactRouterConfigFile) {
@@ -415,45 +418,50 @@ async function resolveConfig({
415
418
  `Could not find a root route module in the app directory as "${rootRouteDisplayPath}"`
416
419
  );
417
420
  }
418
- let routes2 = {
419
- root: { path: "", id: "root", file: rootRouteFile }
420
- };
421
- let routeConfigFile = findEntry(appDirectory, "routes");
422
- try {
423
- if (!routeConfigFile) {
424
- let routeConfigDisplayPath = import_pathe3.default.relative(
425
- root,
426
- import_pathe3.default.join(appDirectory, "routes.ts")
427
- );
428
- return err(`Route config file not found at "${routeConfigDisplayPath}".`);
429
- }
430
- setAppDirectory(appDirectory);
431
- let routeConfigExport = (await viteNodeContext.runner.executeFile(
432
- import_pathe3.default.join(appDirectory, routeConfigFile)
433
- )).default;
434
- let routeConfig = await routeConfigExport;
435
- let result = validateRouteConfig({
436
- routeConfigFile,
437
- routeConfig
438
- });
439
- if (!result.valid) {
440
- return err(result.message);
441
- }
421
+ let routes2 = {};
422
+ if (!skipRoutes) {
442
423
  routes2 = {
443
- ...routes2,
444
- ...configRoutesToRouteManifest(appDirectory, routeConfig)
424
+ root: { path: "", id: "root", file: rootRouteFile }
445
425
  };
446
- } catch (error) {
447
- return err(
448
- [
449
- import_picocolors.default.red(`Route config in "${routeConfigFile}" is invalid.`),
450
- "",
451
- error.loc?.file && error.loc?.column && error.frame ? [
452
- import_pathe3.default.relative(appDirectory, error.loc.file) + ":" + error.loc.line + ":" + error.loc.column,
453
- error.frame.trim?.()
454
- ] : error.stack
455
- ].flat().join("\n")
456
- );
426
+ let routeConfigFile = findEntry(appDirectory, "routes");
427
+ try {
428
+ if (!routeConfigFile) {
429
+ let routeConfigDisplayPath = import_pathe3.default.relative(
430
+ root,
431
+ import_pathe3.default.join(appDirectory, "routes.ts")
432
+ );
433
+ return err(
434
+ `Route config file not found at "${routeConfigDisplayPath}".`
435
+ );
436
+ }
437
+ setAppDirectory(appDirectory);
438
+ let routeConfigExport = (await viteNodeContext.runner.executeFile(
439
+ import_pathe3.default.join(appDirectory, routeConfigFile)
440
+ )).default;
441
+ let routeConfig = await routeConfigExport;
442
+ let result = validateRouteConfig({
443
+ routeConfigFile,
444
+ routeConfig
445
+ });
446
+ if (!result.valid) {
447
+ return err(result.message);
448
+ }
449
+ routes2 = {
450
+ ...routes2,
451
+ ...configRoutesToRouteManifest(appDirectory, routeConfig)
452
+ };
453
+ } catch (error) {
454
+ return err(
455
+ [
456
+ import_picocolors.default.red(`Route config in "${routeConfigFile}" is invalid.`),
457
+ "",
458
+ error.loc?.file && error.loc?.column && error.frame ? [
459
+ import_pathe3.default.relative(appDirectory, error.loc.file) + ":" + error.loc.line + ":" + error.loc.column,
460
+ error.frame.trim?.()
461
+ ] : error.stack
462
+ ].flat().join("\n")
463
+ );
464
+ }
457
465
  }
458
466
  let future = {
459
467
  unstable_middleware: reactRouterUserConfig.future?.unstable_middleware ?? false,
@@ -484,24 +492,34 @@ async function resolveConfig({
484
492
  async function createConfigLoader({
485
493
  rootDirectory: root,
486
494
  watch: watch2,
487
- mode
495
+ mode,
496
+ skipRoutes
488
497
  }) {
489
- root = root ?? process.env.REACT_ROUTER_ROOT ?? process.cwd();
498
+ root = import_pathe3.default.normalize(root ?? process.env.REACT_ROUTER_ROOT ?? process.cwd());
499
+ let vite2 = await import("vite");
490
500
  let viteNodeContext = await createContext({
491
501
  root,
492
- mode
493
- });
494
- let reactRouterConfigFile = findEntry(root, "react-router.config", {
495
- absolute: true
502
+ mode,
503
+ // Filter out any info level logs from vite-node
504
+ customLogger: vite2.createLogger("warn", {
505
+ prefix: "[react-router]"
506
+ })
496
507
  });
497
- let getConfig = () => resolveConfig({ root, viteNodeContext, reactRouterConfigFile });
508
+ let reactRouterConfigFile;
509
+ let updateReactRouterConfigFile = () => {
510
+ reactRouterConfigFile = findEntry(root, "react-router.config", {
511
+ absolute: true
512
+ });
513
+ };
514
+ updateReactRouterConfigFile();
515
+ let getConfig = () => resolveConfig({ root, viteNodeContext, reactRouterConfigFile, skipRoutes });
498
516
  let appDirectory;
499
517
  let initialConfigResult = await getConfig();
500
518
  if (!initialConfigResult.ok) {
501
519
  throw new Error(initialConfigResult.error);
502
520
  }
503
- appDirectory = initialConfigResult.value.appDirectory;
504
- let lastConfig = initialConfigResult.value;
521
+ appDirectory = import_pathe3.default.normalize(initialConfigResult.value.appDirectory);
522
+ let currentConfig = initialConfigResult.value;
505
523
  let fsWatcher;
506
524
  let changeHandlers = [];
507
525
  return {
@@ -514,41 +532,71 @@ async function createConfigLoader({
514
532
  }
515
533
  changeHandlers.push(handler);
516
534
  if (!fsWatcher) {
517
- fsWatcher = import_chokidar.default.watch(
518
- [
519
- ...reactRouterConfigFile ? [reactRouterConfigFile] : [],
520
- appDirectory
521
- ],
522
- { ignoreInitial: true }
523
- );
535
+ fsWatcher = import_chokidar.default.watch([root, appDirectory], {
536
+ ignoreInitial: true,
537
+ ignored: (path8) => {
538
+ let dirname6 = import_pathe3.default.dirname(path8);
539
+ return !dirname6.startsWith(appDirectory) && // Ensure we're only watching files outside of the app directory
540
+ // that are at the root level, not nested in subdirectories
541
+ path8 !== root && // Watch the root directory itself
542
+ dirname6 !== root;
543
+ }
544
+ });
524
545
  fsWatcher.on("all", async (...args) => {
525
546
  let [event, rawFilepath] = args;
526
547
  let filepath = import_pathe3.default.normalize(rawFilepath);
527
- let appFileAddedOrRemoved = appDirectory && (event === "add" || event === "unlink") && filepath.startsWith(import_pathe3.default.normalize(appDirectory));
528
- let configCodeUpdated = Boolean(
548
+ let fileAddedOrRemoved = event === "add" || event === "unlink";
549
+ let appFileAddedOrRemoved = fileAddedOrRemoved && filepath.startsWith(import_pathe3.default.normalize(appDirectory));
550
+ let rootRelativeFilepath = import_pathe3.default.relative(root, filepath);
551
+ let configFileAddedOrRemoved = fileAddedOrRemoved && isEntryFile("react-router.config", rootRelativeFilepath);
552
+ if (configFileAddedOrRemoved) {
553
+ updateReactRouterConfigFile();
554
+ }
555
+ let moduleGraphChanged = configFileAddedOrRemoved || Boolean(
529
556
  viteNodeContext.devServer?.moduleGraph.getModuleById(filepath)
530
557
  );
531
- if (configCodeUpdated || appFileAddedOrRemoved) {
532
- viteNodeContext.devServer?.moduleGraph.invalidateAll();
533
- viteNodeContext.runner?.moduleCache.clear();
558
+ if (!moduleGraphChanged && !appFileAddedOrRemoved) {
559
+ return;
534
560
  }
535
- if (appFileAddedOrRemoved || configCodeUpdated) {
536
- let result = await getConfig();
537
- let configChanged = result.ok && !(0, import_isEqual.default)(lastConfig, result.value);
538
- let routeConfigChanged = result.ok && !(0, import_isEqual.default)(lastConfig?.routes, result.value.routes);
539
- for (let handler2 of changeHandlers) {
540
- handler2({
541
- result,
542
- configCodeUpdated,
543
- configChanged,
544
- routeConfigChanged,
545
- path: filepath,
546
- event
547
- });
548
- }
549
- if (result.ok) {
550
- lastConfig = result.value;
551
- }
561
+ viteNodeContext.devServer?.moduleGraph.invalidateAll();
562
+ viteNodeContext.runner?.moduleCache.clear();
563
+ let result = await getConfig();
564
+ let prevAppDirectory = appDirectory;
565
+ appDirectory = import_pathe3.default.normalize(
566
+ (result.value ?? currentConfig).appDirectory
567
+ );
568
+ if (appDirectory !== prevAppDirectory) {
569
+ fsWatcher.unwatch(prevAppDirectory);
570
+ fsWatcher.add(appDirectory);
571
+ }
572
+ let configCodeChanged = configFileAddedOrRemoved || reactRouterConfigFile !== void 0 && isEntryFileDependency(
573
+ viteNodeContext.devServer.moduleGraph,
574
+ reactRouterConfigFile,
575
+ filepath
576
+ );
577
+ let routeConfigFile = !skipRoutes ? findEntry(appDirectory, "routes", {
578
+ absolute: true
579
+ }) : void 0;
580
+ let routeConfigCodeChanged = routeConfigFile !== void 0 && isEntryFileDependency(
581
+ viteNodeContext.devServer.moduleGraph,
582
+ routeConfigFile,
583
+ filepath
584
+ );
585
+ let configChanged = result.ok && !(0, import_isEqual.default)(omitRoutes(currentConfig), omitRoutes(result.value));
586
+ let routeConfigChanged = result.ok && !(0, import_isEqual.default)(currentConfig?.routes, result.value.routes);
587
+ for (let handler2 of changeHandlers) {
588
+ handler2({
589
+ result,
590
+ configCodeChanged,
591
+ routeConfigCodeChanged,
592
+ configChanged,
593
+ routeConfigChanged,
594
+ path: filepath,
595
+ event
596
+ });
597
+ }
598
+ if (result.ok) {
599
+ currentConfig = result.value;
552
600
  }
553
601
  });
554
602
  }
@@ -567,17 +615,28 @@ async function createConfigLoader({
567
615
  }
568
616
  async function loadConfig({
569
617
  rootDirectory,
570
- mode
618
+ mode,
619
+ skipRoutes
571
620
  }) {
572
621
  let configLoader = await createConfigLoader({
573
622
  rootDirectory,
574
623
  mode,
624
+ skipRoutes,
575
625
  watch: false
576
626
  });
577
627
  let config = await configLoader.getConfig();
578
628
  await configLoader.close();
579
629
  return config;
580
630
  }
631
+ function omitRoutes(config) {
632
+ return {
633
+ ...config,
634
+ routes: {}
635
+ };
636
+ }
637
+ function isEntryFile(entryBasename, filename3) {
638
+ return entryExts.some((ext) => filename3 === `${entryBasename}${ext}`);
639
+ }
581
640
  function findEntry(dir, basename2, options) {
582
641
  let currentDir = import_pathe3.default.resolve(dir);
583
642
  let { root } = import_pathe3.default.parse(currentDir);
@@ -598,6 +657,30 @@ function findEntry(dir, basename2, options) {
598
657
  currentDir = parentDir;
599
658
  }
600
659
  }
660
+ function isEntryFileDependency(moduleGraph, entryFilepath, filepath, visited = /* @__PURE__ */ new Set()) {
661
+ entryFilepath = import_pathe3.default.normalize(entryFilepath);
662
+ filepath = import_pathe3.default.normalize(filepath);
663
+ if (visited.has(filepath)) {
664
+ return false;
665
+ }
666
+ visited.add(filepath);
667
+ if (filepath === entryFilepath) {
668
+ return true;
669
+ }
670
+ let mod = moduleGraph.getModuleById(filepath);
671
+ if (!mod) {
672
+ return false;
673
+ }
674
+ for (let importer of mod.importers) {
675
+ if (!importer.id) {
676
+ continue;
677
+ }
678
+ if (importer.id === entryFilepath || isEntryFileDependency(moduleGraph, entryFilepath, importer.id, visited)) {
679
+ return true;
680
+ }
681
+ }
682
+ return false;
683
+ }
601
684
  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, mergeReactRouterConfig, deepFreeze, entryExts;
602
685
  var init_config = __esm({
603
686
  "config/config.ts"() {
@@ -718,21 +801,21 @@ var init_babel = __esm({
718
801
 
719
802
  // typegen/paths.ts
720
803
  function getTypesDir(ctx) {
721
- return Path2.join(ctx.rootDirectory, ".react-router/types");
804
+ return Path3.join(ctx.rootDirectory, ".react-router/types");
722
805
  }
723
806
  function getTypesPath(ctx, route) {
724
- return Path2.join(
807
+ return Path3.join(
725
808
  getTypesDir(ctx),
726
- Path2.relative(ctx.rootDirectory, ctx.config.appDirectory),
727
- Path2.dirname(route.file),
809
+ Path3.relative(ctx.rootDirectory, ctx.config.appDirectory),
810
+ Path3.dirname(route.file),
728
811
  "+types/" + Pathe.filename(route.file) + ".ts"
729
812
  );
730
813
  }
731
- var Path2, Pathe;
814
+ var Path3, Pathe;
732
815
  var init_paths = __esm({
733
816
  "typegen/paths.ts"() {
734
817
  "use strict";
735
- Path2 = __toESM(require("pathe"));
818
+ Path3 = __toESM(require("pathe"));
736
819
  Pathe = __toESM(require("pathe/utils"));
737
820
  }
738
821
  });
@@ -772,7 +855,7 @@ function lineage(routes2, route) {
772
855
  }
773
856
  function fullpath(lineage2) {
774
857
  if (lineage2.length === 1 && lineage2[0].id === "root") return "/";
775
- return "/" + lineage2.map((route) => route.path?.replace(/^\//, "")?.replace(/\/$/, "")).filter((path9) => path9 !== void 0 && path9 !== "").join("/");
858
+ return "/" + lineage2.map((route) => route.path?.replace(/^\//, "")?.replace(/\/$/, "")).filter((path8) => path8 !== void 0 && path8 !== "").join("/");
776
859
  }
777
860
  var init_route = __esm({
778
861
  "typegen/route.ts"() {
@@ -787,8 +870,8 @@ function generate2(ctx, route) {
787
870
  const typesPath = getTypesPath(ctx, route);
788
871
  const parents = lineage2.slice(0, -1);
789
872
  const parentTypeImports = parents.map((parent, i) => {
790
- const rel = Path3.relative(
791
- Path3.dirname(typesPath),
873
+ const rel = Path4.relative(
874
+ Path4.dirname(typesPath),
792
875
  getTypesPath(ctx, parent)
793
876
  );
794
877
  const indent = i === 0 ? "" : " ".repeat(2);
@@ -850,17 +933,17 @@ function formatParamProperties(fullpath2) {
850
933
  );
851
934
  return properties.join("; ");
852
935
  }
853
- var import_dedent, Path3, Pathe2, noExtension;
936
+ var import_dedent, Path4, Pathe2, noExtension;
854
937
  var init_generate = __esm({
855
938
  "typegen/generate.ts"() {
856
939
  "use strict";
857
940
  import_dedent = __toESM(require("dedent"));
858
- Path3 = __toESM(require("pathe"));
941
+ Path4 = __toESM(require("pathe"));
859
942
  Pathe2 = __toESM(require("pathe/utils"));
860
943
  init_paths();
861
944
  init_params();
862
945
  init_route();
863
- noExtension = (path9) => Path3.join(Path3.dirname(path9), Pathe2.filename(path9));
946
+ noExtension = (path8) => Path4.join(Path4.dirname(path8), Pathe2.filename(path8));
864
947
  }
865
948
  });
866
949
 
@@ -873,20 +956,22 @@ async function watch(rootDirectory, { mode, logger }) {
873
956
  const ctx = await createContext2({ rootDirectory, mode, watch: true });
874
957
  await writeAll(ctx);
875
958
  logger?.info(import_picocolors3.default.green("generated types"), { timestamp: true, clear: true });
876
- ctx.configLoader.onChange(async ({ result, routeConfigChanged }) => {
877
- if (!result.ok) {
878
- logger?.error(import_picocolors3.default.red(result.error), { timestamp: true, clear: true });
879
- return;
880
- }
881
- ctx.config = result.value;
882
- if (routeConfigChanged) {
883
- await writeAll(ctx);
884
- logger?.info(import_picocolors3.default.green("regenerated types"), {
885
- timestamp: true,
886
- clear: true
887
- });
959
+ ctx.configLoader.onChange(
960
+ async ({ result, configChanged, routeConfigChanged }) => {
961
+ if (!result.ok) {
962
+ logger?.error(import_picocolors3.default.red(result.error), { timestamp: true, clear: true });
963
+ return;
964
+ }
965
+ ctx.config = result.value;
966
+ if (configChanged || routeConfigChanged) {
967
+ await writeAll(ctx);
968
+ logger?.info(import_picocolors3.default.green("regenerated types"), {
969
+ timestamp: true,
970
+ clear: true
971
+ });
972
+ }
888
973
  }
889
- });
974
+ );
890
975
  return {
891
976
  close: async () => await ctx.configLoader.close()
892
977
  };
@@ -914,12 +999,12 @@ async function writeAll(ctx) {
914
999
  Object.values(ctx.config.routes).forEach((route) => {
915
1000
  const typesPath = getTypesPath(ctx, route);
916
1001
  const content = generate2(ctx, route);
917
- import_node_fs3.default.mkdirSync(Path4.dirname(typesPath), { recursive: true });
1002
+ import_node_fs3.default.mkdirSync(Path5.dirname(typesPath), { recursive: true });
918
1003
  import_node_fs3.default.writeFileSync(typesPath, content);
919
1004
  });
920
- const registerPath = Path4.join(typegenDir, "+register.ts");
1005
+ const registerPath = Path5.join(typegenDir, "+register.ts");
921
1006
  import_node_fs3.default.writeFileSync(registerPath, register(ctx));
922
- const virtualPath = Path4.join(typegenDir, "+virtual.d.ts");
1007
+ const virtualPath = Path5.join(typegenDir, "+virtual.d.ts");
923
1008
  import_node_fs3.default.writeFileSync(virtualPath, virtual);
924
1009
  }
925
1010
  function register(ctx) {
@@ -930,24 +1015,25 @@ function register(ctx) {
930
1015
  interface Register {
931
1016
  params: Params;
932
1017
  }
1018
+
1019
+ interface Future {
1020
+ unstable_middleware: ${ctx.config.future.unstable_middleware}
1021
+ }
933
1022
  }
934
1023
  `;
935
1024
  const { t: t2 } = babel_exports;
936
- const fullpaths = {};
937
- for (const route of Object.values(ctx.config.routes)) {
938
- if (route.id !== "root" && !route.path) continue;
1025
+ const fullpaths = /* @__PURE__ */ new Set();
1026
+ Object.values(ctx.config.routes).forEach((route) => {
1027
+ if (route.id !== "root" && !route.path) return;
939
1028
  const lineage2 = lineage(ctx.config.routes, route);
940
1029
  const fullpath2 = fullpath(lineage2);
941
- const existing = fullpaths[fullpath2];
942
- if (!existing || existing.length < lineage2.length) {
943
- fullpaths[fullpath2] = lineage2;
944
- }
945
- }
1030
+ fullpaths.add(fullpath2);
1031
+ });
946
1032
  const typeParams = t2.tsTypeAliasDeclaration(
947
1033
  t2.identifier("Params"),
948
1034
  null,
949
1035
  t2.tsTypeLiteral(
950
- Object.keys(fullpaths).map((fullpath2) => {
1036
+ Array.from(fullpaths).map((fullpath2) => {
951
1037
  const params = parse2(fullpath2);
952
1038
  return t2.tsPropertySignature(
953
1039
  t2.stringLiteral(fullpath2),
@@ -969,13 +1055,13 @@ function register(ctx) {
969
1055
  );
970
1056
  return [register2, generate(typeParams).code].join("\n\n");
971
1057
  }
972
- var import_node_fs3, import_dedent2, Path4, import_picocolors3, virtual;
1058
+ var import_node_fs3, import_dedent2, Path5, import_picocolors3, virtual;
973
1059
  var init_typegen = __esm({
974
1060
  "typegen/index.ts"() {
975
1061
  "use strict";
976
1062
  import_node_fs3 = __toESM(require("fs"));
977
1063
  import_dedent2 = __toESM(require("dedent"));
978
- Path4 = __toESM(require("pathe"));
1064
+ Path5 = __toESM(require("pathe"));
979
1065
  import_picocolors3 = __toESM(require("picocolors"));
980
1066
  init_config();
981
1067
  init_babel();
@@ -1017,21 +1103,21 @@ var init_node_adapter = __esm({
1017
1103
  });
1018
1104
 
1019
1105
  // vite/resolve-file-url.ts
1020
- var path5;
1106
+ var path4;
1021
1107
  var init_resolve_file_url = __esm({
1022
1108
  "vite/resolve-file-url.ts"() {
1023
1109
  "use strict";
1024
- path5 = __toESM(require("path"));
1110
+ path4 = __toESM(require("path"));
1025
1111
  init_vite();
1026
1112
  }
1027
1113
  });
1028
1114
 
1029
1115
  // vite/styles.ts
1030
- var path6, import_react_router, cssFileRegExp, cssModulesRegExp;
1116
+ var path5, import_react_router, cssFileRegExp, cssModulesRegExp;
1031
1117
  var init_styles = __esm({
1032
1118
  "vite/styles.ts"() {
1033
1119
  "use strict";
1034
- path6 = __toESM(require("path"));
1120
+ path5 = __toESM(require("path"));
1035
1121
  import_react_router = require("react-router");
1036
1122
  init_resolve_file_url();
1037
1123
  init_babel();
@@ -1181,8 +1267,8 @@ function getServerBundleIds(ctx) {
1181
1267
  async function cleanBuildDirectory(viteConfig, ctx) {
1182
1268
  let buildDirectory = ctx.reactRouterConfig.buildDirectory;
1183
1269
  let isWithinRoot = () => {
1184
- let relativePath = path7.relative(ctx.rootDirectory, buildDirectory);
1185
- return !relativePath.startsWith("..") && !path7.isAbsolute(relativePath);
1270
+ let relativePath = path6.relative(ctx.rootDirectory, buildDirectory);
1271
+ return !relativePath.startsWith("..") && !path6.isAbsolute(relativePath);
1186
1272
  };
1187
1273
  if (viteConfig.build.emptyOutDir ?? isWithinRoot()) {
1188
1274
  await fse.remove(buildDirectory);
@@ -1193,7 +1279,7 @@ async function cleanViteManifests(environmentsOptions, ctx) {
1193
1279
  ([environmentName, options]) => {
1194
1280
  let outDir = options.build?.outDir;
1195
1281
  invariant(outDir, `Expected build.outDir for ${environmentName}`);
1196
- return path7.join(outDir, ".vite/manifest.json");
1282
+ return path6.join(outDir, ".vite/manifest.json");
1197
1283
  }
1198
1284
  );
1199
1285
  await Promise.all(
@@ -1203,7 +1289,7 @@ async function cleanViteManifests(environmentsOptions, ctx) {
1203
1289
  if (!ctx.viteManifestEnabled) {
1204
1290
  await fse.remove(viteManifestPath);
1205
1291
  }
1206
- let viteDir = path7.dirname(viteManifestPath);
1292
+ let viteDir = path6.dirname(viteManifestPath);
1207
1293
  let viteDirFiles = await fse.readdir(viteDir);
1208
1294
  if (viteDirFiles.length === 0) {
1209
1295
  await fse.remove(viteDir);
@@ -1220,10 +1306,10 @@ function mergeEnvironmentOptions(base, ...overrides) {
1220
1306
  }
1221
1307
  async function getEnvironmentOptionsResolvers(ctx, viteCommand) {
1222
1308
  let { serverBuildFile, serverModuleFormat } = ctx.reactRouterConfig;
1223
- let packageRoot = path7.dirname(
1309
+ let packageRoot = path6.dirname(
1224
1310
  require.resolve("@react-router/dev/package.json")
1225
1311
  );
1226
- let { moduleSyncEnabled } = await import(`file:///${path7.join(packageRoot, "module-sync-enabled/index.mjs")}`);
1312
+ let { moduleSyncEnabled } = await import(`file:///${path6.join(packageRoot, "module-sync-enabled/index.mjs")}`);
1227
1313
  let vite2 = getVite();
1228
1314
  let viteServerConditions = [
1229
1315
  ...vite2.defaultServerConditions ?? [],
@@ -1297,7 +1383,7 @@ async function getEnvironmentOptionsResolvers(ctx, viteCommand) {
1297
1383
  ctx.entryClientFilePath,
1298
1384
  ...Object.values(ctx.reactRouterConfig.routes).flatMap(
1299
1385
  (route) => {
1300
- let routeFilePath = path7.resolve(
1386
+ let routeFilePath = path6.resolve(
1301
1387
  ctx.reactRouterConfig.appDirectory,
1302
1388
  route.file
1303
1389
  );
@@ -1321,7 +1407,7 @@ async function getEnvironmentOptionsResolvers(ctx, viteCommand) {
1321
1407
  ) : null;
1322
1408
  let routeChunkSuffix = routeChunkName ? `-${(0, import_kebabCase.default)(routeChunkName)}` : "";
1323
1409
  let assetsDir = (ctx.reactRouterConfig.future.unstable_viteEnvironmentApi ? viteUserConfig?.environments?.client?.build?.assetsDir : null) ?? viteUserConfig?.build?.assetsDir ?? "assets";
1324
- return path7.posix.join(
1410
+ return path6.posix.join(
1325
1411
  assetsDir,
1326
1412
  `[name]${routeChunkSuffix}-[hash].js`
1327
1413
  );
@@ -1371,13 +1457,13 @@ function resolveEnvironmentsOptions(environmentResolvers, resolverOptions) {
1371
1457
  function isNonNullable(x) {
1372
1458
  return x != null;
1373
1459
  }
1374
- var import_node_crypto, fs4, path7, url, fse, babel2, import_react_router2, import_es_module_lexer, import_pick3, import_jsesc, import_picocolors4, import_kebabCase, CLIENT_NON_COMPONENT_EXPORTS, CLIENT_ROUTE_EXPORTS, BUILD_CLIENT_ROUTE_QUERY_STRING, SSR_BUNDLE_PREFIX, virtualHmrRuntime, virtualInjectHmrRuntime, virtual2, getServerBuildDirectory, getClientBuildDirectory, defaultEntriesDir, defaultEntries, REACT_REFRESH_HEADER;
1460
+ var import_node_crypto, fs4, path6, url, fse, babel2, import_react_router2, import_es_module_lexer, import_pick3, import_jsesc, import_picocolors4, import_kebabCase, CLIENT_NON_COMPONENT_EXPORTS, CLIENT_ROUTE_EXPORTS, BUILD_CLIENT_ROUTE_QUERY_STRING, SSR_BUNDLE_PREFIX, virtualHmrRuntime, virtualInjectHmrRuntime, virtual2, getServerBuildDirectory, getClientBuildDirectory, defaultEntriesDir, defaultEntries, REACT_REFRESH_HEADER;
1375
1461
  var init_plugin = __esm({
1376
1462
  "vite/plugin.ts"() {
1377
1463
  "use strict";
1378
1464
  import_node_crypto = require("crypto");
1379
1465
  fs4 = __toESM(require("fs"));
1380
- path7 = __toESM(require("path"));
1466
+ path6 = __toESM(require("path"));
1381
1467
  url = __toESM(require("url"));
1382
1468
  fse = __toESM(require("fs-extra"));
1383
1469
  babel2 = __toESM(require("@babel/core"));
@@ -1426,19 +1512,19 @@ var init_plugin = __esm({
1426
1512
  serverManifest: create("server-manifest"),
1427
1513
  browserManifest: create("browser-manifest")
1428
1514
  };
1429
- getServerBuildDirectory = (reactRouterConfig, { serverBundleId } = {}) => path7.join(
1515
+ getServerBuildDirectory = (reactRouterConfig, { serverBundleId } = {}) => path6.join(
1430
1516
  reactRouterConfig.buildDirectory,
1431
1517
  "server",
1432
1518
  ...serverBundleId ? [serverBundleId] : []
1433
1519
  );
1434
- getClientBuildDirectory = (reactRouterConfig) => path7.join(reactRouterConfig.buildDirectory, "client");
1435
- defaultEntriesDir = path7.resolve(
1436
- path7.dirname(require.resolve("@react-router/dev/package.json")),
1520
+ getClientBuildDirectory = (reactRouterConfig) => path6.join(reactRouterConfig.buildDirectory, "client");
1521
+ defaultEntriesDir = path6.resolve(
1522
+ path6.dirname(require.resolve("@react-router/dev/package.json")),
1437
1523
  "dist",
1438
1524
  "config",
1439
1525
  "defaults"
1440
1526
  );
1441
- defaultEntries = fse.readdirSync(defaultEntriesDir).map((filename3) => path7.join(defaultEntriesDir, filename3));
1527
+ defaultEntries = fse.readdirSync(defaultEntriesDir).map((filename3) => path6.join(defaultEntriesDir, filename3));
1442
1528
  invariant(defaultEntries.length > 0, "No default entries found");
1443
1529
  REACT_REFRESH_HEADER = `
1444
1530
  import RefreshRuntime from "${virtualHmrRuntime.id}";
@@ -1474,7 +1560,10 @@ async function build(root, viteBuildOptions) {
1474
1560
  let vite2 = getVite();
1475
1561
  let configResult = await loadConfig({
1476
1562
  rootDirectory: root,
1477
- mode: viteBuildOptions.mode ?? "production"
1563
+ mode: viteBuildOptions.mode ?? "production",
1564
+ // In this scope we only need future flags, so we can skip evaluating
1565
+ // routes.ts until we're within the Vite build context
1566
+ skipRoutes: true
1478
1567
  });
1479
1568
  if (!configResult.ok) {
1480
1569
  throw new Error(configResult.error);
@@ -1715,7 +1804,7 @@ var import_semver = __toESM(require("semver"));
1715
1804
  var import_picocolors8 = __toESM(require("picocolors"));
1716
1805
 
1717
1806
  // cli/commands.ts
1718
- var path8 = __toESM(require("path"));
1807
+ var path7 = __toESM(require("path"));
1719
1808
  var import_fs_extra = __toESM(require("fs-extra"));
1720
1809
  var import_package_json2 = __toESM(require("@npmcli/package-json"));
1721
1810
  var import_exit_hook = __toESM(require("exit-hook"));
@@ -1874,14 +1963,14 @@ async function generateEntry(entry, rootDirectory, flags = {}) {
1874
1963
  console.error(import_picocolors7.default.red(`No default server entry detected.`));
1875
1964
  return;
1876
1965
  }
1877
- let defaultsDirectory = path8.resolve(
1878
- path8.dirname(require.resolve("@react-router/dev/package.json")),
1966
+ let defaultsDirectory = path7.resolve(
1967
+ path7.dirname(require.resolve("@react-router/dev/package.json")),
1879
1968
  "dist",
1880
1969
  "config",
1881
1970
  "defaults"
1882
1971
  );
1883
- let defaultEntryClient = path8.resolve(defaultsDirectory, "entry.client.tsx");
1884
- let defaultEntryServer = path8.resolve(
1972
+ let defaultEntryClient = path7.resolve(defaultsDirectory, "entry.client.tsx");
1973
+ let defaultEntryServer = path7.resolve(
1885
1974
  defaultsDirectory,
1886
1975
  `entry.server.node.tsx`
1887
1976
  );
@@ -1890,7 +1979,7 @@ async function generateEntry(entry, rootDirectory, flags = {}) {
1890
1979
  let useTypeScript = flags.typescript ?? true;
1891
1980
  let outputExtension = useTypeScript ? "tsx" : "jsx";
1892
1981
  let outputEntry = `${entry}.${outputExtension}`;
1893
- let outputFile2 = path8.resolve(appDirectory, outputEntry);
1982
+ let outputFile2 = path7.resolve(appDirectory, outputEntry);
1894
1983
  if (!useTypeScript) {
1895
1984
  let javascript = transpile(contents, {
1896
1985
  cwd: rootDirectory,
@@ -1902,7 +1991,7 @@ async function generateEntry(entry, rootDirectory, flags = {}) {
1902
1991
  }
1903
1992
  console.log(
1904
1993
  import_picocolors7.default.blue(
1905
- `Entry file ${entry} created at ${path8.relative(
1994
+ `Entry file ${entry} created at ${path7.relative(
1906
1995
  rootDirectory,
1907
1996
  outputFile2
1908
1997
  )}.`
@@ -1911,16 +2000,16 @@ async function generateEntry(entry, rootDirectory, flags = {}) {
1911
2000
  }
1912
2001
  function resolveRootDirectory(root, flags) {
1913
2002
  if (root) {
1914
- return path8.resolve(root);
2003
+ return path7.resolve(root);
1915
2004
  }
1916
- return process.env.REACT_ROUTER_ROOT || (flags?.config ? path8.dirname(path8.resolve(flags.config)) : process.cwd());
2005
+ return process.env.REACT_ROUTER_ROOT || (flags?.config ? path7.dirname(path7.resolve(flags.config)) : process.cwd());
1917
2006
  }
1918
2007
  async function checkForEntry(rootDirectory, appDirectory, entries2) {
1919
2008
  for (let entry of entries2) {
1920
- let entryPath = path8.resolve(appDirectory, entry);
2009
+ let entryPath = path7.resolve(appDirectory, entry);
1921
2010
  let exists = await import_fs_extra.default.pathExists(entryPath);
1922
2011
  if (exists) {
1923
- let relative8 = path8.relative(rootDirectory, entryPath);
2012
+ let relative8 = path7.relative(rootDirectory, entryPath);
1924
2013
  console.error(import_picocolors7.default.red(`Entry file ${relative8} already exists.`));
1925
2014
  return process.exit(1);
1926
2015
  }