@react-router/dev 0.0.0-experimental-89dc2043e → 0.0.0-experimental-1ebb6d403

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-89dc2043e
3
+ * @react-router/dev v0.0.0-experimental-1ebb6d403
4
4
  *
5
5
  * Copyright (c) Remix Software Inc.
6
6
  *
@@ -55,26 +55,55 @@ var init_invariant = __esm({
55
55
  }
56
56
  });
57
57
 
58
- // vite/import-vite-esm-sync.ts
59
- async function preloadViteEsm() {
60
- vite = await import("vite");
58
+ // config/is-react-router-repo.ts
59
+ function isReactRouterRepo() {
60
+ let serverRuntimePath = import_pathe.default.dirname(
61
+ require.resolve("@react-router/node/package.json")
62
+ );
63
+ let serverRuntimeParentDir = import_pathe.default.basename(
64
+ import_pathe.default.resolve(serverRuntimePath, "..")
65
+ );
66
+ return serverRuntimeParentDir === "packages";
61
67
  }
62
- function importViteEsmSync() {
63
- invariant(vite, "importViteEsmSync() called before preloadViteEsm()");
68
+ var import_pathe;
69
+ var init_is_react_router_repo = __esm({
70
+ "config/is-react-router-repo.ts"() {
71
+ "use strict";
72
+ import_pathe = __toESM(require("pathe"));
73
+ }
74
+ });
75
+
76
+ // vite/vite.ts
77
+ async function preloadVite() {
78
+ vite = await import(viteImportSpecifier);
79
+ }
80
+ function getVite() {
81
+ invariant(vite, "getVite() called before preloadVite()");
64
82
  return vite;
65
83
  }
66
- var vite;
67
- var init_import_vite_esm_sync = __esm({
68
- "vite/import-vite-esm-sync.ts"() {
84
+ var import_pathe2, vite, viteImportSpecifier;
85
+ var init_vite = __esm({
86
+ "vite/vite.ts"() {
69
87
  "use strict";
88
+ import_pathe2 = __toESM(require("pathe"));
70
89
  init_invariant();
90
+ init_is_react_router_repo();
91
+ viteImportSpecifier = isReactRouterRepo() ? (
92
+ // Support testing against different versions of Vite by ensuring that Vite
93
+ // is resolved from the current working directory when running within this
94
+ // repo. If we don't do this, Vite will always be imported relative to this
95
+ // file, which means that it will always resolve to Vite 6.
96
+ `file:///${import_pathe2.default.normalize(
97
+ require.resolve("vite/package.json", { paths: [process.cwd()] })
98
+ ).replace("package.json", "dist/node/index.js")}`
99
+ ) : "vite";
71
100
  }
72
101
  });
73
102
 
74
103
  // vite/vite-node.ts
75
104
  async function createContext(viteConfig = {}) {
76
- await preloadViteEsm();
77
- const vite2 = importViteEsmSync();
105
+ await preloadVite();
106
+ const vite2 = getVite();
78
107
  const devServer = await vite2.createServer(
79
108
  vite2.mergeConfig(
80
109
  {
@@ -100,11 +129,11 @@ async function createContext(viteConfig = {}) {
100
129
  const runner = new import_client.ViteNodeRunner({
101
130
  root: devServer.config.root,
102
131
  base: devServer.config.base,
103
- fetchModule(id2) {
104
- return server.fetchModule(id2);
132
+ fetchModule(id) {
133
+ return server.fetchModule(id);
105
134
  },
106
- resolveId(id2, importer) {
107
- return server.resolveId(id2, importer);
135
+ resolveId(id, importer) {
136
+ return server.resolveId(id, importer);
108
137
  }
109
138
  });
110
139
  return { devServer, server, runner };
@@ -116,7 +145,7 @@ var init_vite_node = __esm({
116
145
  import_server = require("vite-node/server");
117
146
  import_client = require("vite-node/client");
118
147
  import_source_map = require("vite-node/source-map");
119
- init_import_vite_esm_sync();
148
+ init_vite();
120
149
  }
121
150
  });
122
151
 
@@ -149,7 +178,7 @@ function validateRouteConfig({
149
178
  `Route config in "${routeConfigFile}" is invalid.`,
150
179
  root ? `${root}` : [],
151
180
  nested ? Object.entries(nested).map(
152
- ([path8, message]) => `Path: routes.${path8}
181
+ ([path10, message]) => `Path: routes.${path10}
153
182
  ${message}`
154
183
  ) : []
155
184
  ].flat().join("\n\n")
@@ -160,24 +189,24 @@ ${message}`
160
189
  function configRoutesToRouteManifest(appDirectory, routes2, rootId = "root") {
161
190
  let routeManifest = {};
162
191
  function walk(route, parentId) {
163
- let id2 = route.id || createRouteId(route.file);
192
+ let id = route.id || createRouteId(route.file);
164
193
  let manifestItem = {
165
- id: id2,
194
+ id,
166
195
  parentId,
167
196
  file: Path.isAbsolute(route.file) ? Path.relative(appDirectory, route.file) : route.file,
168
197
  path: route.path,
169
198
  index: route.index,
170
199
  caseSensitive: route.caseSensitive
171
200
  };
172
- if (routeManifest.hasOwnProperty(id2)) {
201
+ if (routeManifest.hasOwnProperty(id)) {
173
202
  throw new Error(
174
- `Unable to define routes with duplicate route id: "${id2}"`
203
+ `Unable to define routes with duplicate route id: "${id}"`
175
204
  );
176
205
  }
177
- routeManifest[id2] = manifestItem;
206
+ routeManifest[id] = manifestItem;
178
207
  if (route.children) {
179
208
  for (let child of route.children) {
180
- walk(child, id2);
209
+ walk(child, id);
181
210
  }
182
211
  }
183
212
  }
@@ -307,13 +336,13 @@ async function resolveConfig({
307
336
  "The `prerender` config must be a boolean, an array of string paths, or a function returning a boolean or array of string paths"
308
337
  );
309
338
  }
310
- let appDirectory = import_pathe.default.resolve(root, userAppDirectory || "app");
311
- let buildDirectory = import_pathe.default.resolve(root, userBuildDirectory);
339
+ let appDirectory = import_pathe3.default.resolve(root, userAppDirectory || "app");
340
+ let buildDirectory = import_pathe3.default.resolve(root, userBuildDirectory);
312
341
  let rootRouteFile = findEntry(appDirectory, "root");
313
342
  if (!rootRouteFile) {
314
- let rootRouteDisplayPath = import_pathe.default.relative(
343
+ let rootRouteDisplayPath = import_pathe3.default.relative(
315
344
  root,
316
- import_pathe.default.join(appDirectory, "root.tsx")
345
+ import_pathe3.default.join(appDirectory, "root.tsx")
317
346
  );
318
347
  return err(
319
348
  `Could not find a root route module in the app directory as "${rootRouteDisplayPath}"`
@@ -325,15 +354,15 @@ async function resolveConfig({
325
354
  let routeConfigFile = findEntry(appDirectory, "routes");
326
355
  try {
327
356
  if (!routeConfigFile) {
328
- let routeConfigDisplayPath = import_pathe.default.relative(
357
+ let routeConfigDisplayPath = import_pathe3.default.relative(
329
358
  root,
330
- import_pathe.default.join(appDirectory, "routes.ts")
359
+ import_pathe3.default.join(appDirectory, "routes.ts")
331
360
  );
332
361
  return err(`Route config file not found at "${routeConfigDisplayPath}".`);
333
362
  }
334
363
  setAppDirectory(appDirectory);
335
364
  let routeConfigExport = (await viteNodeContext.runner.executeFile(
336
- import_pathe.default.join(appDirectory, routeConfigFile)
365
+ import_pathe3.default.join(appDirectory, routeConfigFile)
337
366
  )).default;
338
367
  let routeConfig = await routeConfigExport;
339
368
  let result = validateRouteConfig({
@@ -353,7 +382,7 @@ async function resolveConfig({
353
382
  import_picocolors.default.red(`Route config in "${routeConfigFile}" is invalid.`),
354
383
  "",
355
384
  error.loc?.file && error.loc?.column && error.frame ? [
356
- import_pathe.default.relative(appDirectory, error.loc.file) + ":" + error.loc.line + ":" + error.loc.column,
385
+ import_pathe3.default.relative(appDirectory, error.loc.file) + ":" + error.loc.line + ":" + error.loc.column,
357
386
  error.frame.trim?.()
358
387
  ] : error.stack
359
388
  ].flat().join("\n")
@@ -425,8 +454,8 @@ async function createConfigLoader({
425
454
  );
426
455
  fsWatcher.on("all", async (...args) => {
427
456
  let [event, rawFilepath] = args;
428
- let filepath = import_pathe.default.normalize(rawFilepath);
429
- let appFileAddedOrRemoved = appDirectory && (event === "add" || event === "unlink") && filepath.startsWith(import_pathe.default.normalize(appDirectory));
457
+ let filepath = import_pathe3.default.normalize(rawFilepath);
458
+ let appFileAddedOrRemoved = appDirectory && (event === "add" || event === "unlink") && filepath.startsWith(import_pathe3.default.normalize(appDirectory));
430
459
  let configCodeUpdated = Boolean(
431
460
  viteNodeContext.devServer?.moduleGraph.getModuleById(filepath)
432
461
  );
@@ -467,25 +496,16 @@ async function createConfigLoader({
467
496
  }
468
497
  };
469
498
  }
470
- function isInReactRouterMonorepo() {
471
- let serverRuntimePath = import_pathe.default.dirname(
472
- require.resolve("@react-router/node/package.json")
473
- );
474
- let serverRuntimeParentDir = import_pathe.default.basename(
475
- import_pathe.default.resolve(serverRuntimePath, "..")
476
- );
477
- return serverRuntimeParentDir === "packages";
478
- }
479
499
  function findEntry(dir, basename2, options) {
480
500
  for (let ext of entryExts) {
481
- let file = import_pathe.default.resolve(dir, basename2 + ext);
501
+ let file = import_pathe3.default.resolve(dir, basename2 + ext);
482
502
  if (import_node_fs.default.existsSync(file)) {
483
- return options?.absolute ?? false ? file : import_pathe.default.relative(dir, file);
503
+ return options?.absolute ?? false ? file : import_pathe3.default.relative(dir, file);
484
504
  }
485
505
  }
486
506
  return void 0;
487
507
  }
488
- var import_node_fs, import_node_child_process, import_package_json, import_pathe, import_chokidar, import_picocolors, import_pick2, import_omit, import_cloneDeep, import_isEqual, excludedConfigPresetKeys, branchRouteProperties, configRouteToBranchRoute, mergeReactRouterConfig, deepFreeze, ssrExternals, entryExts;
508
+ var import_node_fs, import_node_child_process, import_package_json, import_pathe3, import_chokidar, import_picocolors, import_pick2, import_omit, import_cloneDeep, import_isEqual, excludedConfigPresetKeys, branchRouteProperties, configRouteToBranchRoute, mergeReactRouterConfig, deepFreeze, ssrExternals, entryExts;
489
509
  var init_config = __esm({
490
510
  "config/config.ts"() {
491
511
  "use strict";
@@ -493,7 +513,7 @@ var init_config = __esm({
493
513
  import_node_child_process = require("child_process");
494
514
  import_package_json = __toESM(require("@npmcli/package-json"));
495
515
  init_vite_node();
496
- import_pathe = __toESM(require("pathe"));
516
+ import_pathe3 = __toESM(require("pathe"));
497
517
  import_chokidar = __toESM(require("chokidar"));
498
518
  import_picocolors = __toESM(require("picocolors"));
499
519
  import_pick2 = __toESM(require("lodash/pick"));
@@ -502,6 +522,7 @@ var init_config = __esm({
502
522
  import_isEqual = __toESM(require("lodash/isEqual"));
503
523
  init_routes();
504
524
  init_detectPackageManager();
525
+ init_is_react_router_repo();
505
526
  excludedConfigPresetKeys = ["presets"];
506
527
  branchRouteProperties = [
507
528
  "id",
@@ -548,7 +569,7 @@ var init_config = __esm({
548
569
  });
549
570
  return o;
550
571
  };
551
- ssrExternals = isInReactRouterMonorepo() ? [
572
+ ssrExternals = isReactRouterRepo() ? [
552
573
  // This is only needed within this repo because these packages
553
574
  // are linked to a directory outside of node_modules so Vite
554
575
  // treats them as internal code by default.
@@ -600,7 +621,7 @@ function generate(ctx, route) {
600
621
  const indent = i === 0 ? "" : " ".repeat(2);
601
622
  let source = noExtension(rel);
602
623
  if (!source.startsWith("../")) source = "./" + source;
603
- return `${indent}import type { Info as Parent${i} } from "${source}"`;
624
+ return `${indent}import type { Info as Parent${i} } from "${source}.js"`;
604
625
  }).join("\n");
605
626
  return import_dedent.default`
606
627
  // React Router generated types for route:
@@ -610,14 +631,16 @@ function generate(ctx, route) {
610
631
 
611
632
  ${parentTypeImports}
612
633
 
613
- type Module = typeof import("../${Pathe2.filename(route.file)}")
634
+ type Module = typeof import("../${Pathe2.filename(route.file)}.js")
614
635
 
615
636
  export type Info = {
616
637
  parents: [${parents.map((_, i) => `Parent${i}`).join(", ")}],
617
638
  id: "${route.id}"
618
639
  file: "${route.file}"
619
640
  path: "${route.path}"
620
- params: {${formatParamProperties(urlpath)}}
641
+ params: {${formatParamProperties(
642
+ urlpath
643
+ )}} & { [key: string]: string | undefined }
621
644
  module: Module
622
645
  loaderData: T.CreateLoaderData<Module>
623
646
  actionData: T.CreateActionData<Module>
@@ -693,7 +716,7 @@ var init_generate = __esm({
693
716
  Path3 = __toESM(require("pathe"));
694
717
  Pathe2 = __toESM(require("pathe/utils"));
695
718
  init_paths();
696
- noExtension = (path8) => Path3.join(Path3.dirname(path8), Pathe2.filename(path8));
719
+ noExtension = (path10) => Path3.join(Path3.dirname(path10), Pathe2.filename(path10));
697
720
  }
698
721
  });
699
722
 
@@ -789,34 +812,41 @@ var init_node_adapter = __esm({
789
812
  });
790
813
 
791
814
  // vite/resolve-file-url.ts
792
- var path2;
815
+ var path4;
793
816
  var init_resolve_file_url = __esm({
794
817
  "vite/resolve-file-url.ts"() {
795
818
  "use strict";
796
- path2 = __toESM(require("path"));
797
- init_import_vite_esm_sync();
819
+ path4 = __toESM(require("path"));
820
+ init_vite();
798
821
  }
799
822
  });
800
823
 
801
824
  // vite/styles.ts
802
- var path3, import_react_router, cssFileRegExp, cssModulesRegExp;
825
+ var path5, import_react_router, cssFileRegExp, cssModulesRegExp;
803
826
  var init_styles = __esm({
804
827
  "vite/styles.ts"() {
805
828
  "use strict";
806
- path3 = __toESM(require("path"));
829
+ path5 = __toESM(require("path"));
807
830
  import_react_router = require("react-router");
808
831
  init_resolve_file_url();
832
+ init_vite();
809
833
  cssFileRegExp = /\.(css|less|sass|scss|styl|stylus|pcss|postcss|sss)(?:$|\?)/;
810
834
  cssModulesRegExp = new RegExp(`\\.module${cssFileRegExp.source}`);
811
835
  }
812
836
  });
813
837
 
814
- // vite/vmod.ts
815
- var id;
816
- var init_vmod = __esm({
817
- "vite/vmod.ts"() {
838
+ // vite/virtual-module.ts
839
+ function create(name) {
840
+ let id = `virtual:react-router/${name}`;
841
+ return {
842
+ id,
843
+ resolvedId: `\0${id}`,
844
+ url: `/@id/__x00__${id}`
845
+ };
846
+ }
847
+ var init_virtual_module = __esm({
848
+ "vite/virtual-module.ts"() {
818
849
  "use strict";
819
- id = (name) => `virtual:react-router/${name}`;
820
850
  }
821
851
  });
822
852
 
@@ -838,14 +868,14 @@ var init_remove_exports = __esm({
838
868
  });
839
869
 
840
870
  // vite/with-props.ts
841
- var import_dedent2, vmodId;
871
+ var import_dedent2, vmod;
842
872
  var init_with_props = __esm({
843
873
  "vite/with-props.ts"() {
844
874
  "use strict";
845
875
  import_dedent2 = __toESM(require("dedent"));
846
876
  init_babel();
847
- init_vmod();
848
- vmodId = id("with-props");
877
+ init_virtual_module();
878
+ vmod = create("with-props");
849
879
  }
850
880
  });
851
881
 
@@ -855,7 +885,7 @@ async function resolveViteConfig({
855
885
  mode,
856
886
  root
857
887
  }) {
858
- let vite2 = await import("vite");
888
+ let vite2 = getVite();
859
889
  let viteConfig = await vite2.resolveConfig(
860
890
  { mode, configFile, root },
861
891
  "build",
@@ -905,17 +935,17 @@ async function loadPluginContext({
905
935
  function findConfig(dir, basename2, extensions) {
906
936
  for (let ext of extensions) {
907
937
  let name = basename2 + ext;
908
- let file = path4.join(dir, name);
938
+ let file = path6.join(dir, name);
909
939
  if (fse.existsSync(file)) return file;
910
940
  }
911
941
  return void 0;
912
942
  }
913
- var import_node_crypto, path4, url, fse, babel, import_react_router2, import_es_module_lexer, import_jsesc, import_picocolors3, serverBuildId, serverManifestId, browserManifestId, hmrRuntimeId, injectHmrRuntimeId, getServerBuildDirectory, defaultEntriesDir, defaultEntries, REACT_REFRESH_HEADER, REACT_REFRESH_FOOTER;
943
+ var import_node_crypto, path6, url, fse, babel, import_react_router2, import_es_module_lexer, import_jsesc, import_picocolors3, virtualHmrRuntime, virtualInjectHmrRuntime, virtual, getServerBuildDirectory, defaultEntriesDir, defaultEntries, REACT_REFRESH_HEADER;
914
944
  var init_plugin = __esm({
915
945
  "vite/plugin.ts"() {
916
946
  "use strict";
917
947
  import_node_crypto = require("crypto");
918
- path4 = __toESM(require("path"));
948
+ path6 = __toESM(require("path"));
919
949
  url = __toESM(require("url"));
920
950
  fse = __toESM(require("fs-extra"));
921
951
  babel = __toESM(require("@babel/core"));
@@ -928,33 +958,35 @@ var init_plugin = __esm({
928
958
  init_babel();
929
959
  init_node_adapter();
930
960
  init_styles();
931
- init_vmod();
961
+ init_virtual_module();
932
962
  init_resolve_file_url();
933
963
  init_combine_urls();
934
964
  init_remove_exports();
935
- init_import_vite_esm_sync();
965
+ init_vite();
936
966
  init_config();
937
967
  init_with_props();
938
- serverBuildId = id("server-build");
939
- serverManifestId = id("server-manifest");
940
- browserManifestId = id("browser-manifest");
941
- hmrRuntimeId = id("hmr-runtime");
942
- injectHmrRuntimeId = id("inject-hmr-runtime");
943
- getServerBuildDirectory = (ctx) => path4.join(
968
+ virtualHmrRuntime = create("hmr-runtime");
969
+ virtualInjectHmrRuntime = create("inject-hmr-runtime");
970
+ virtual = {
971
+ serverBuild: create("server-build"),
972
+ serverManifest: create("server-manifest"),
973
+ browserManifest: create("browser-manifest")
974
+ };
975
+ getServerBuildDirectory = (ctx) => path6.join(
944
976
  ctx.reactRouterConfig.buildDirectory,
945
977
  "server",
946
978
  ...ctx.serverBundleBuildConfig ? [ctx.serverBundleBuildConfig.serverBundleId] : []
947
979
  );
948
- defaultEntriesDir = path4.resolve(
949
- path4.dirname(require.resolve("@react-router/dev/package.json")),
980
+ defaultEntriesDir = path6.resolve(
981
+ path6.dirname(require.resolve("@react-router/dev/package.json")),
950
982
  "dist",
951
983
  "config",
952
984
  "defaults"
953
985
  );
954
- defaultEntries = fse.readdirSync(defaultEntriesDir).map((filename3) => path4.join(defaultEntriesDir, filename3));
986
+ defaultEntries = fse.readdirSync(defaultEntriesDir).map((filename3) => path6.join(defaultEntriesDir, filename3));
955
987
  invariant(defaultEntries.length > 0, "No default entries found");
956
988
  REACT_REFRESH_HEADER = `
957
- import RefreshRuntime from "${hmrRuntimeId}";
989
+ import RefreshRuntime from "${virtualHmrRuntime.id}";
958
990
 
959
991
  const inWebWorker = typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope;
960
992
  let prevRefreshReg;
@@ -973,21 +1005,46 @@ if (import.meta.hot && !inWebWorker) {
973
1005
  RefreshRuntime.register(type, __SOURCE__ + " " + id)
974
1006
  };
975
1007
  window.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;
976
- }`.trim();
977
- REACT_REFRESH_FOOTER = `
978
- if (import.meta.hot && !inWebWorker) {
979
- window.$RefreshReg$ = prevRefreshReg;
980
- window.$RefreshSig$ = prevRefreshSig;
981
- RefreshRuntime.__hmr_import(import.meta.url).then((currentExports) => {
982
- RefreshRuntime.registerExportsForReactRefresh(__SOURCE__, currentExports);
983
- import.meta.hot.accept((nextExports) => {
984
- if (!nextExports) return;
985
- __ROUTE_ID__ && window.__reactRouterRouteModuleUpdates.set(__ROUTE_ID__, nextExports);
986
- const invalidateMessage = RefreshRuntime.validateRefreshBoundaryAndEnqueueUpdate(currentExports, nextExports, __ACCEPT_EXPORTS__);
987
- if (invalidateMessage) import.meta.hot.invalidate(invalidateMessage);
988
- });
989
- });
990
- }`.trim();
1008
+ }`.replaceAll("\n", "");
1009
+ }
1010
+ });
1011
+
1012
+ // vite/profiler.ts
1013
+ var import_node_fs3, import_node_path, import_picocolors4, getSession, start, profileCount, stop;
1014
+ var init_profiler = __esm({
1015
+ "vite/profiler.ts"() {
1016
+ "use strict";
1017
+ import_node_fs3 = __toESM(require("fs"));
1018
+ import_node_path = __toESM(require("path"));
1019
+ import_picocolors4 = __toESM(require("picocolors"));
1020
+ getSession = () => global.__reactRouter_profile_session;
1021
+ start = async (callback) => {
1022
+ let inspector = await import("inspector").then((r) => r.default);
1023
+ let session = global.__reactRouter_profile_session = new inspector.Session();
1024
+ session.connect();
1025
+ session.post("Profiler.enable", () => {
1026
+ session.post("Profiler.start", callback);
1027
+ });
1028
+ };
1029
+ profileCount = 0;
1030
+ stop = (log) => {
1031
+ let session = getSession();
1032
+ if (!session) return;
1033
+ return new Promise((res, rej) => {
1034
+ session.post("Profiler.stop", (err2, { profile }) => {
1035
+ if (err2) return rej(err2);
1036
+ let outPath = import_node_path.default.resolve(`./react-router-${profileCount++}.cpuprofile`);
1037
+ import_node_fs3.default.writeFileSync(outPath, JSON.stringify(profile));
1038
+ log(
1039
+ import_picocolors4.default.yellow(
1040
+ `CPU profile written to ${import_picocolors4.default.white(import_picocolors4.default.dim(outPath))}`
1041
+ )
1042
+ );
1043
+ global.__reactRouter_profile_session = void 0;
1044
+ res();
1045
+ });
1046
+ });
1047
+ };
991
1048
  }
992
1049
  });
993
1050
 
@@ -998,8 +1055,8 @@ __export(build_exports, {
998
1055
  });
999
1056
  function getAddressableRoutes(routes2) {
1000
1057
  let nonAddressableIds = /* @__PURE__ */ new Set();
1001
- for (let id2 in routes2) {
1002
- let route = routes2[id2];
1058
+ for (let id in routes2) {
1059
+ let route = routes2[id];
1003
1060
  if (route.index) {
1004
1061
  invariant(
1005
1062
  route.parentId,
@@ -1008,7 +1065,7 @@ function getAddressableRoutes(routes2) {
1008
1065
  nonAddressableIds.add(route.parentId);
1009
1066
  }
1010
1067
  if (typeof route.path !== "string" && !route.index) {
1011
- nonAddressableIds.add(id2);
1068
+ nonAddressableIds.add(id);
1012
1069
  }
1013
1070
  }
1014
1071
  return Object.values(routes2).filter(
@@ -1039,12 +1096,12 @@ async function getServerBuilds(ctx) {
1039
1096
  let { normalizePath } = await import("vite");
1040
1097
  let resolvedAppDirectory = import_node_path2.default.resolve(rootDirectory, appDirectory);
1041
1098
  let rootRelativeRoutes = Object.fromEntries(
1042
- Object.entries(routes2).map(([id2, route]) => {
1099
+ Object.entries(routes2).map(([id, route]) => {
1043
1100
  let filePath = import_node_path2.default.join(resolvedAppDirectory, route.file);
1044
1101
  let rootRelativeFilePath = normalizePath(
1045
1102
  import_node_path2.default.relative(rootDirectory, filePath)
1046
1103
  );
1047
- return [id2, { ...route, file: rootRelativeFilePath }];
1104
+ return [id, { ...route, file: rootRelativeFilePath }];
1048
1105
  })
1049
1106
  );
1050
1107
  let buildManifest = {
@@ -1145,7 +1202,7 @@ async function build(root, {
1145
1202
  sourcemapClient,
1146
1203
  sourcemapServer
1147
1204
  }) {
1148
- await preloadViteEsm();
1205
+ await preloadVite();
1149
1206
  let viteConfig = await resolveViteConfig({ configFile, mode, root });
1150
1207
  const ctx = await extractPluginContext(viteConfig);
1151
1208
  if (!ctx) {
@@ -1155,7 +1212,7 @@ async function build(root, {
1155
1212
  process.exit(1);
1156
1213
  }
1157
1214
  let { reactRouterConfig } = ctx;
1158
- let vite2 = await import("vite");
1215
+ let vite2 = getVite();
1159
1216
  async function viteBuild({
1160
1217
  ssr,
1161
1218
  serverBundleBuildConfig
@@ -1212,22 +1269,84 @@ var init_build = __esm({
1212
1269
  init_plugin();
1213
1270
  init_config();
1214
1271
  init_invariant();
1215
- init_import_vite_esm_sync();
1272
+ init_vite();
1273
+ }
1274
+ });
1275
+
1276
+ // vite/dev.ts
1277
+ var dev_exports = {};
1278
+ __export(dev_exports, {
1279
+ dev: () => dev
1280
+ });
1281
+ async function dev(root, {
1282
+ clearScreen,
1283
+ config: configFile,
1284
+ cors,
1285
+ force,
1286
+ host,
1287
+ logLevel,
1288
+ mode,
1289
+ open,
1290
+ port,
1291
+ strictPort
1292
+ }) {
1293
+ await preloadVite();
1294
+ let vite2 = getVite();
1295
+ let server = await vite2.createServer({
1296
+ root,
1297
+ mode,
1298
+ configFile,
1299
+ server: { open, cors, host, port, strictPort },
1300
+ optimizeDeps: { force },
1301
+ clearScreen,
1302
+ logLevel
1303
+ });
1304
+ if (!server.config.plugins.find((plugin2) => plugin2.name === "react-router")) {
1305
+ console.error(
1306
+ import_picocolors6.default.red("React Router Vite plugin not found in Vite config")
1307
+ );
1308
+ process.exit(1);
1309
+ }
1310
+ await server.listen();
1311
+ server.printUrls();
1312
+ let customShortcuts = [
1313
+ {
1314
+ key: "p",
1315
+ description: "start/stop the profiler",
1316
+ async action(server2) {
1317
+ if (getSession()) {
1318
+ await stop(server2.config.logger.info);
1319
+ } else {
1320
+ await start(() => {
1321
+ server2.config.logger.info("Profiler started");
1322
+ });
1323
+ }
1324
+ }
1325
+ }
1326
+ ];
1327
+ server.bindCLIShortcuts({ print: true, customShortcuts });
1328
+ }
1329
+ var import_picocolors6;
1330
+ var init_dev = __esm({
1331
+ "vite/dev.ts"() {
1332
+ "use strict";
1333
+ import_picocolors6 = __toESM(require("picocolors"));
1334
+ init_vite();
1335
+ init_profiler();
1216
1336
  }
1217
1337
  });
1218
1338
 
1219
1339
  // cli/run.ts
1220
1340
  var import_arg = __toESM(require("arg"));
1221
1341
  var import_semver = __toESM(require("semver"));
1222
- var import_picocolors7 = __toESM(require("picocolors"));
1342
+ var import_picocolors8 = __toESM(require("picocolors"));
1223
1343
 
1224
1344
  // cli/commands.ts
1225
- var path7 = __toESM(require("path"));
1345
+ var path9 = __toESM(require("path"));
1226
1346
  var import_fs_extra2 = __toESM(require("fs-extra"));
1227
1347
  var import_package_json2 = __toESM(require("@npmcli/package-json"));
1228
- var import_picocolors6 = __toESM(require("picocolors"));
1229
- var import_execa = __toESM(require("execa"));
1230
- init_invariant();
1348
+ var import_exit_hook = __toESM(require("exit-hook"));
1349
+ var import_picocolors7 = __toESM(require("picocolors"));
1231
1350
 
1232
1351
  // config/format.ts
1233
1352
  function formatRoutes(routeManifest, format) {
@@ -1306,42 +1425,10 @@ function transpile(tsx, options = {}) {
1306
1425
  return import_prettier.default.format(mjs.code, { parser: "babel" });
1307
1426
  }
1308
1427
 
1309
- // vite/profiler.ts
1310
- var import_node_fs3 = __toESM(require("fs"));
1311
- var import_node_path = __toESM(require("path"));
1312
- var import_picocolors4 = __toESM(require("picocolors"));
1313
- var getSession = () => global.__reactRouter_profile_session;
1314
- var start = async (callback) => {
1315
- let inspector = await import("inspector").then((r) => r.default);
1316
- let session = global.__reactRouter_profile_session = new inspector.Session();
1317
- session.connect();
1318
- session.post("Profiler.enable", () => {
1319
- session.post("Profiler.start", callback);
1320
- });
1321
- };
1322
- var profileCount = 0;
1323
- var stop = (log) => {
1324
- let session = getSession();
1325
- if (!session) return;
1326
- return new Promise((res, rej) => {
1327
- session.post("Profiler.stop", (err2, { profile }) => {
1328
- if (err2) return rej(err2);
1329
- let outPath = import_node_path.default.resolve(`./react-router-${profileCount++}.cpuprofile`);
1330
- import_node_fs3.default.writeFileSync(outPath, JSON.stringify(profile));
1331
- log(
1332
- import_picocolors4.default.yellow(
1333
- `CPU profile written to ${import_picocolors4.default.white(import_picocolors4.default.dim(outPath))}`
1334
- )
1335
- );
1336
- global.__reactRouter_profile_session = void 0;
1337
- res();
1338
- });
1339
- });
1340
- };
1341
-
1342
1428
  // cli/commands.ts
1429
+ init_profiler();
1343
1430
  init_typegen();
1344
- init_import_vite_esm_sync();
1431
+ init_vite();
1345
1432
  async function routes(reactRouterRoot, flags = {}) {
1346
1433
  let ctx = await loadPluginContext({
1347
1434
  root: reactRouterRoot,
@@ -1349,7 +1436,7 @@ async function routes(reactRouterRoot, flags = {}) {
1349
1436
  });
1350
1437
  if (!ctx) {
1351
1438
  console.error(
1352
- import_picocolors6.default.red("React Router Vite plugin not found in Vite config")
1439
+ import_picocolors7.default.red("React Router Vite plugin not found in Vite config")
1353
1440
  );
1354
1441
  process.exit(1);
1355
1442
  }
@@ -1370,23 +1457,13 @@ async function build2(root, options = {}) {
1370
1457
  await stop(console.info);
1371
1458
  }
1372
1459
  }
1373
- async function dev(root, viteDevOptions = {}) {
1374
- let devScriptPath = path7.resolve(__dirname, "./dev.js");
1375
- invariant(
1376
- import_fs_extra2.default.existsSync(devScriptPath),
1377
- `dev script not found at ${devScriptPath}`
1378
- );
1379
- let args = { root, viteDevOptions };
1380
- let { NODE_OPTIONS } = process.env;
1381
- if (!NODE_OPTIONS?.includes("--conditions")) {
1382
- NODE_OPTIONS = `${NODE_OPTIONS ?? ""} --conditions=development`.trim();
1383
- }
1384
- (0, import_execa.default)(process.execPath, [devScriptPath, JSON.stringify(args)], {
1385
- env: { ...process.env, NODE_OPTIONS },
1386
- stdin: "inherit",
1387
- stdout: "inherit",
1388
- stderr: "inherit"
1389
- });
1460
+ async function dev2(root, options = {}) {
1461
+ let { dev: dev3 } = await Promise.resolve().then(() => (init_dev(), dev_exports));
1462
+ if (options.profile) {
1463
+ await start();
1464
+ }
1465
+ (0, import_exit_hook.default)(() => stop(console.info));
1466
+ await dev3(root, options);
1390
1467
  await new Promise(() => {
1391
1468
  });
1392
1469
  }
@@ -1413,24 +1490,24 @@ async function generateEntry(entry, reactRouterRoot, flags = {}) {
1413
1490
  let entriesArray = Array.from(entries);
1414
1491
  let list = conjunctionListFormat.format(entriesArray);
1415
1492
  console.error(
1416
- import_picocolors6.default.red(`Invalid entry file. Valid entry files are ${list}`)
1493
+ import_picocolors7.default.red(`Invalid entry file. Valid entry files are ${list}`)
1417
1494
  );
1418
1495
  return;
1419
1496
  }
1420
1497
  let pkgJson = await import_package_json2.default.load(rootDirectory);
1421
1498
  let deps = pkgJson.content.dependencies ?? {};
1422
1499
  if (!deps["@react-router/node"]) {
1423
- console.error(import_picocolors6.default.red(`No default server entry detected.`));
1500
+ console.error(import_picocolors7.default.red(`No default server entry detected.`));
1424
1501
  return;
1425
1502
  }
1426
- let defaultsDirectory = path7.resolve(
1427
- path7.dirname(require.resolve("@react-router/dev/package.json")),
1503
+ let defaultsDirectory = path9.resolve(
1504
+ path9.dirname(require.resolve("@react-router/dev/package.json")),
1428
1505
  "dist",
1429
1506
  "config",
1430
1507
  "defaults"
1431
1508
  );
1432
- let defaultEntryClient = path7.resolve(defaultsDirectory, "entry.client.tsx");
1433
- let defaultEntryServer = path7.resolve(
1509
+ let defaultEntryClient = path9.resolve(defaultsDirectory, "entry.client.tsx");
1510
+ let defaultEntryServer = path9.resolve(
1434
1511
  defaultsDirectory,
1435
1512
  `entry.server.node.tsx`
1436
1513
  );
@@ -1439,7 +1516,7 @@ async function generateEntry(entry, reactRouterRoot, flags = {}) {
1439
1516
  let useTypeScript = flags.typescript ?? true;
1440
1517
  let outputExtension = useTypeScript ? "tsx" : "jsx";
1441
1518
  let outputEntry = `${entry}.${outputExtension}`;
1442
- let outputFile2 = path7.resolve(appDirectory, outputEntry);
1519
+ let outputFile2 = path9.resolve(appDirectory, outputEntry);
1443
1520
  if (!useTypeScript) {
1444
1521
  let javascript = transpile(contents, {
1445
1522
  cwd: rootDirectory,
@@ -1450,8 +1527,8 @@ async function generateEntry(entry, reactRouterRoot, flags = {}) {
1450
1527
  await import_fs_extra2.default.writeFile(outputFile2, contents, "utf-8");
1451
1528
  }
1452
1529
  console.log(
1453
- import_picocolors6.default.blue(
1454
- `Entry file ${entry} created at ${path7.relative(
1530
+ import_picocolors7.default.blue(
1531
+ `Entry file ${entry} created at ${path9.relative(
1455
1532
  rootDirectory,
1456
1533
  outputFile2
1457
1534
  )}.`
@@ -1460,11 +1537,11 @@ async function generateEntry(entry, reactRouterRoot, flags = {}) {
1460
1537
  }
1461
1538
  async function checkForEntry(rootDirectory, appDirectory, entries2) {
1462
1539
  for (let entry of entries2) {
1463
- let entryPath = path7.resolve(appDirectory, entry);
1540
+ let entryPath = path9.resolve(appDirectory, entry);
1464
1541
  let exists = await import_fs_extra2.default.pathExists(entryPath);
1465
1542
  if (exists) {
1466
- let relative8 = path7.relative(rootDirectory, entryPath);
1467
- console.error(import_picocolors6.default.red(`Entry file ${relative8} already exists.`));
1543
+ let relative8 = path9.relative(rootDirectory, entryPath);
1544
+ console.error(import_picocolors7.default.red(`Entry file ${relative8} already exists.`));
1468
1545
  return process.exit(1);
1469
1546
  }
1470
1547
  }
@@ -1482,8 +1559,8 @@ async function createClientEntry(rootDirectory, appDirectory, inputFile) {
1482
1559
  async function typegen(root, flags) {
1483
1560
  root ??= process.cwd();
1484
1561
  if (flags.watch) {
1485
- await preloadViteEsm();
1486
- const vite2 = importViteEsmSync();
1562
+ await preloadVite();
1563
+ const vite2 = getVite();
1487
1564
  const logger = vite2.createLogger("info", { prefix: "[react-router]" });
1488
1565
  await watch(root, { logger });
1489
1566
  await new Promise(() => {
@@ -1495,14 +1572,14 @@ async function typegen(root, flags) {
1495
1572
 
1496
1573
  // cli/run.ts
1497
1574
  var helpText = `
1498
- ${import_picocolors7.default.blueBright("react-router")}
1575
+ ${import_picocolors8.default.blueBright("react-router")}
1499
1576
 
1500
- ${import_picocolors7.default.underline("Usage")}:
1501
- $ react-router build [${import_picocolors7.default.yellowBright("projectDir")}]
1502
- $ react-router dev [${import_picocolors7.default.yellowBright("projectDir")}]
1503
- $ react-router routes [${import_picocolors7.default.yellowBright("projectDir")}]
1577
+ ${import_picocolors8.default.underline("Usage")}:
1578
+ $ react-router build [${import_picocolors8.default.yellowBright("projectDir")}]
1579
+ $ react-router dev [${import_picocolors8.default.yellowBright("projectDir")}]
1580
+ $ react-router routes [${import_picocolors8.default.yellowBright("projectDir")}]
1504
1581
 
1505
- ${import_picocolors7.default.underline("Options")}:
1582
+ ${import_picocolors8.default.underline("Options")}:
1506
1583
  --help, -h Print this help message and exit
1507
1584
  --version, -v Print the CLI version and exit
1508
1585
  --no-color Disable ANSI colors in console output
@@ -1538,22 +1615,22 @@ ${import_picocolors7.default.blueBright("react-router")}
1538
1615
  \`typegen\` Options:
1539
1616
  --watch Automatically regenerate types whenever route config (\`routes.ts\`) or route modules change
1540
1617
 
1541
- ${import_picocolors7.default.underline("Build your project")}:
1618
+ ${import_picocolors8.default.underline("Build your project")}:
1542
1619
 
1543
1620
  $ react-router build
1544
1621
 
1545
- ${import_picocolors7.default.underline("Run your project locally in development")}:
1622
+ ${import_picocolors8.default.underline("Run your project locally in development")}:
1546
1623
 
1547
1624
  $ react-router dev
1548
1625
 
1549
- ${import_picocolors7.default.underline("Show all routes in your app")}:
1626
+ ${import_picocolors8.default.underline("Show all routes in your app")}:
1550
1627
 
1551
1628
  $ react-router routes
1552
1629
  $ react-router routes my-app
1553
1630
  $ react-router routes --json
1554
1631
  $ react-router routes --config vite.react-router.config.ts
1555
1632
 
1556
- ${import_picocolors7.default.underline("Reveal the used entry point")}:
1633
+ ${import_picocolors8.default.underline("Reveal the used entry point")}:
1557
1634
 
1558
1635
  $ react-router reveal entry.client
1559
1636
  $ react-router reveal entry.server
@@ -1561,7 +1638,7 @@ ${import_picocolors7.default.blueBright("react-router")}
1561
1638
  $ react-router reveal entry.server --no-typescript
1562
1639
  $ react-router reveal entry.server --config vite.react-router.config.ts
1563
1640
 
1564
- ${import_picocolors7.default.underline("Generate types for route modules")}:
1641
+ ${import_picocolors8.default.underline("Generate types for route modules")}:
1565
1642
 
1566
1643
  $ react-router typegen
1567
1644
  $ react-router typegen --watch
@@ -1647,13 +1724,13 @@ async function run2(argv = process.argv.slice(2)) {
1647
1724
  break;
1648
1725
  }
1649
1726
  case "dev":
1650
- await dev(input[1], flags);
1727
+ await dev2(input[1], flags);
1651
1728
  break;
1652
1729
  case "typegen":
1653
1730
  await typegen(input[1], flags);
1654
1731
  break;
1655
1732
  default:
1656
- await dev(input[0], flags);
1733
+ await dev2(input[0], flags);
1657
1734
  }
1658
1735
  }
1659
1736