@react-router/dev 0.0.0-experimental-9f7fdccd4 → 0.0.0-experimental-16086cbff

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.
@@ -1,2 +1 @@
1
-
2
- export { }
1
+ #!/usr/bin/env node
package/dist/cli/index.js CHANGED
@@ -1,5 +1,6 @@
1
+ #!/usr/bin/env node
1
2
  /**
2
- * @react-router/dev v0.0.0-experimental-9f7fdccd4
3
+ * @react-router/dev v0.0.0-experimental-16086cbff
3
4
  *
4
5
  * Copyright (c) Remix Software Inc.
5
6
  *
@@ -411,7 +412,7 @@ var init_plugin = __esm({
411
412
  "config",
412
413
  "defaults"
413
414
  );
414
- defaultEntries = fse2.readdirSync(defaultEntriesDir).map((filename2) => path4.join(defaultEntriesDir, filename2));
415
+ defaultEntries = fse2.readdirSync(defaultEntriesDir).map((filename3) => path4.join(defaultEntriesDir, filename3));
415
416
  invariant(defaultEntries.length > 0, "No default entries found");
416
417
  REACT_REFRESH_HEADER = `
417
418
  import RefreshRuntime from "${hmrRuntimeId}";
@@ -870,12 +871,11 @@ function transpile(tsx, options = {}) {
870
871
  // cli/commands.ts
871
872
  init_profiler();
872
873
 
873
- // typegen.ts
874
+ // typegen/index.ts
874
875
  var import_node_fs2 = __toESM(require("fs"));
875
876
  var import_chokidar = __toESM(require("chokidar"));
876
- var import_dedent2 = __toESM(require("dedent"));
877
877
  var Path = __toESM(require("pathe"));
878
- var Pathe = __toESM(require("pathe/utils"));
878
+ var Pathe2 = __toESM(require("pathe/utils"));
879
879
  var import_picocolors5 = __toESM(require("picocolors"));
880
880
 
881
881
  // logger.ts
@@ -916,121 +916,23 @@ var info = log("info");
916
916
  var warn = log("warn");
917
917
  var error = log("error");
918
918
 
919
- // typegen.ts
919
+ // typegen/index.ts
920
920
  init_routes();
921
921
  init_vite_node();
922
922
  init_config();
923
923
  init_plugin();
924
- function getDirectory(ctx) {
925
- return Path.join(ctx.rootDirectory, ".react-router/types");
926
- }
927
- async function watch(rootDirectory, options = {}) {
928
- const watchStart = performance.now();
929
- const vitePluginCtx = await loadPluginContext({
930
- root: rootDirectory,
931
- configFile: options.configFile
932
- });
933
- const routeConfigFile = findEntry(
934
- vitePluginCtx.reactRouterConfig.appDirectory,
935
- "routes"
936
- );
937
- if (!routeConfigFile) {
938
- warn(
939
- `Could not find route config within ${import_picocolors5.default.blue(
940
- Path.relative(
941
- vitePluginCtx.rootDirectory,
942
- vitePluginCtx.reactRouterConfig.appDirectory
943
- )
944
- )}`
945
- );
946
- process.exit(1);
947
- }
948
- const routeConfigPath = Path.join(
949
- vitePluginCtx.reactRouterConfig.appDirectory,
950
- routeConfigFile
951
- );
952
- const routesViteNodeContext = await createContext({
953
- root: rootDirectory
954
- });
955
- async function getRoutes() {
956
- const routes2 = {};
957
- const rootRouteFile = findEntry(
958
- vitePluginCtx.reactRouterConfig.appDirectory,
959
- "root"
960
- );
961
- if (rootRouteFile) {
962
- routes2.root = { path: "", id: "root", file: rootRouteFile };
963
- } else {
964
- warn(`Could not find \`root\` route`);
965
- }
966
- routesViteNodeContext.devServer.moduleGraph.invalidateAll();
967
- routesViteNodeContext.runner.moduleCache.clear();
968
- const routeConfig = (await routesViteNodeContext.runner.executeFile(routeConfigPath)).routes;
969
- return {
970
- ...routes2,
971
- ...configRoutesToRouteManifest(await routeConfig)
972
- };
973
- }
974
- const ctx = {
975
- rootDirectory,
976
- appDirectory: vitePluginCtx.reactRouterConfig.appDirectory,
977
- routes: await getRoutes()
978
- };
979
- await writeAll(ctx);
980
- info("generated initial types", {
981
- durationMs: performance.now() - watchStart
982
- });
983
- const watcher = import_chokidar.default.watch(ctx.appDirectory, { ignoreInitial: true });
984
- watcher.on("all", async (event, path8) => {
985
- const eventStart = performance.now();
986
- path8 = Path.normalize(path8);
987
- ctx.routes = await getRoutes();
988
- const routeConfigChanged = Boolean(
989
- routesViteNodeContext.devServer.moduleGraph.getModuleById(path8)
990
- );
991
- if (routeConfigChanged) {
992
- await writeAll(ctx);
993
- info("changed route config", {
994
- durationMs: performance.now() - eventStart
995
- });
996
- return;
997
- }
998
- const route = Object.values(ctx.routes).find(
999
- (route2) => path8 === Path.join(ctx.appDirectory, route2.file)
1000
- );
1001
- if (route && (event === "add" || event === "unlink")) {
1002
- await writeAll(ctx);
1003
- info(
1004
- `${event === "add" ? "added" : "removed"} route ${import_picocolors5.default.blue(route.file)}`,
1005
- { durationMs: performance.now() - eventStart }
1006
- );
1007
- return;
1008
- }
1009
- });
1010
- }
1011
- async function writeAll(ctx) {
1012
- import_node_fs2.default.rmSync(getDirectory(ctx), { recursive: true, force: true });
1013
- Object.values(ctx.routes).forEach((route) => {
1014
- if (!import_node_fs2.default.existsSync(Path.join(ctx.appDirectory, route.file))) return;
1015
- const typesPath = Path.join(
1016
- getDirectory(ctx),
1017
- Path.relative(ctx.rootDirectory, ctx.appDirectory),
1018
- Path.dirname(route.file),
1019
- "+types." + Pathe.filename(route.file) + ".d.ts"
1020
- );
1021
- const content = getModule(ctx.routes, route);
1022
- import_node_fs2.default.mkdirSync(Path.dirname(typesPath), { recursive: true });
1023
- import_node_fs2.default.writeFileSync(typesPath, content);
1024
- });
1025
- }
1026
- function getModule(routes2, route) {
924
+
925
+ // typegen/generate.ts
926
+ var import_dedent2 = __toESM(require("dedent"));
927
+ var Pathe = __toESM(require("pathe/utils"));
928
+ function generate2(routes2, route) {
1027
929
  return import_dedent2.default`
1028
930
  // React Router generated types for route:
1029
931
  // ${route.file}
1030
932
 
1031
933
  import * as T from "react-router/types"
1032
934
 
1033
- export type Params = {${formattedParamsProperties(routes2, route)}}
935
+ export type Params = {${formatParamProperties(routes2, route)}}
1034
936
 
1035
937
  type RouteModule = typeof import("./${Pathe.filename(route.file)}")
1036
938
 
@@ -1049,24 +951,24 @@ function getModule(routes2, route) {
1049
951
  }
1050
952
  `;
1051
953
  }
1052
- function formattedParamsProperties(routes2, route) {
1053
- const urlpath = routeLineage(routes2, route).map((route2) => route2.path).join("/");
954
+ function formatParamProperties(routes2, route) {
955
+ const urlpath = getRouteLineage(routes2, route).map((route2) => route2.path).join("/");
1054
956
  const params = parseParams(urlpath);
1055
957
  const indent = " ".repeat(3);
1056
958
  const properties = Object.entries(params).map(([name, values]) => {
1057
959
  if (values.length === 1) {
1058
960
  const isOptional = values[0];
1059
- return indent + (isOptional ? `${name}?: string` : `${name}: string`);
961
+ return indent + (isOptional ? `"${name}"?: string` : `"${name}": string`);
1060
962
  }
1061
963
  const items = values.map(
1062
964
  (isOptional) => isOptional ? "string | undefined" : "string"
1063
965
  );
1064
- return indent + `${name}: [${items.join(", ")}]`;
966
+ return indent + `"${name}": [${items.join(", ")}]`;
1065
967
  });
1066
968
  const body = properties.length === 0 ? "" : "\n" + properties.join("\n") + "\n";
1067
969
  return body;
1068
970
  }
1069
- function routeLineage(routes2, route) {
971
+ function getRouteLineage(routes2, route) {
1070
972
  const result = [];
1071
973
  while (route) {
1072
974
  result.push(route);
@@ -1079,19 +981,119 @@ function routeLineage(routes2, route) {
1079
981
  function parseParams(urlpath) {
1080
982
  const result = {};
1081
983
  let segments = urlpath.split("/");
1082
- segments.filter((s) => s.startsWith(":")).forEach((param) => {
1083
- param = param.slice(1);
1084
- let isOptional = param.endsWith("?");
1085
- if (isOptional) {
1086
- param = param.slice(0, -1);
1087
- }
984
+ segments.forEach((segment) => {
985
+ const match = segment.match(/^:([\w-]+)(\?)?/);
986
+ if (!match) return;
987
+ const param = match[1];
988
+ const isOptional = match[2] !== void 0;
1088
989
  result[param] ??= [];
1089
990
  result[param].push(isOptional);
1090
991
  return;
1091
992
  });
993
+ const hasSplat = segments.at(-1) === "*";
994
+ if (hasSplat) result["*"] = [false];
1092
995
  return result;
1093
996
  }
1094
997
 
998
+ // typegen/index.ts
999
+ async function run(rootDirectory, configFile) {
1000
+ const ctx = await createContext2(rootDirectory, configFile);
1001
+ await writeAll(ctx);
1002
+ }
1003
+ async function watch(rootDirectory, configFile) {
1004
+ const watchStart = performance.now();
1005
+ const ctx = await createContext2(rootDirectory, configFile);
1006
+ await writeAll(ctx);
1007
+ info("generated initial types", {
1008
+ durationMs: performance.now() - watchStart
1009
+ });
1010
+ const watcher = import_chokidar.default.watch(ctx.appDirectory, { ignoreInitial: true });
1011
+ watcher.on("all", async (event, path8) => {
1012
+ path8 = Path.normalize(path8);
1013
+ const eventStart = performance.now();
1014
+ const didRouteConfigChange = Boolean(
1015
+ ctx.routeConfigEnv.devServer.moduleGraph.getModuleById(path8)
1016
+ );
1017
+ if (didRouteConfigChange) {
1018
+ await writeAll(ctx);
1019
+ info("changed route config", {
1020
+ durationMs: performance.now() - eventStart
1021
+ });
1022
+ return;
1023
+ }
1024
+ ctx.routes = await getRoutes(ctx);
1025
+ const route = findRoute(ctx, path8);
1026
+ if (route && (event === "add" || event === "unlink")) {
1027
+ await writeAll(ctx);
1028
+ info(
1029
+ `${event === "add" ? "added" : "removed"} route ${import_picocolors5.default.blue(route.file)}`,
1030
+ { durationMs: performance.now() - eventStart }
1031
+ );
1032
+ return;
1033
+ }
1034
+ });
1035
+ }
1036
+ async function createContext2(rootDirectory, configFile) {
1037
+ const appDirectory = await getAppDirectory(rootDirectory, configFile);
1038
+ const routeConfigEnv = await createContext({
1039
+ root: rootDirectory
1040
+ });
1041
+ return {
1042
+ rootDirectory,
1043
+ appDirectory,
1044
+ routeConfigEnv,
1045
+ routes: await getRoutes({ rootDirectory, appDirectory, routeConfigEnv })
1046
+ };
1047
+ }
1048
+ async function getAppDirectory(rootDirectory, configFile) {
1049
+ const { reactRouterConfig } = await loadPluginContext({
1050
+ root: rootDirectory,
1051
+ configFile
1052
+ });
1053
+ return reactRouterConfig.appDirectory;
1054
+ }
1055
+ function findRoute(ctx, path8) {
1056
+ return Object.values(ctx.routes).find(
1057
+ (route) => path8 === Path.join(ctx.appDirectory, route.file)
1058
+ );
1059
+ }
1060
+ async function getRoutes(ctx) {
1061
+ ctx.routeConfigEnv.devServer.moduleGraph.invalidateAll();
1062
+ ctx.routeConfigEnv.runner.moduleCache.clear();
1063
+ const routeConfigFile = findEntry(ctx.appDirectory, "routes");
1064
+ if (!routeConfigFile) {
1065
+ warn(
1066
+ `Could not find route config within ${import_picocolors5.default.blue(
1067
+ Path.relative(ctx.rootDirectory, ctx.appDirectory)
1068
+ )}`
1069
+ );
1070
+ process.exit(1);
1071
+ }
1072
+ const routeConfigPath = Path.join(ctx.appDirectory, routeConfigFile);
1073
+ const routeConfig = (await ctx.routeConfigEnv.runner.executeFile(routeConfigPath)).routes;
1074
+ const routes2 = configRoutesToRouteManifest(await routeConfig);
1075
+ const rootRouteFile = findEntry(ctx.appDirectory, "root");
1076
+ if (!rootRouteFile) throw new Error("Could not find `root` route");
1077
+ routes2.root = { path: "", id: "root", file: rootRouteFile };
1078
+ return routes2;
1079
+ }
1080
+ async function writeAll(ctx) {
1081
+ const typegenDir = Path.join(ctx.rootDirectory, ".react-router/types");
1082
+ import_node_fs2.default.rmSync(typegenDir, { recursive: true, force: true });
1083
+ Object.values(ctx.routes).forEach((route) => {
1084
+ if (!import_node_fs2.default.existsSync(Path.join(ctx.appDirectory, route.file))) return;
1085
+ const typesPath = Path.join(
1086
+ typegenDir,
1087
+ Path.relative(ctx.rootDirectory, ctx.appDirectory),
1088
+ Path.dirname(route.file),
1089
+ "+types." + Pathe2.filename(route.file) + ".d.ts"
1090
+ );
1091
+ const content = generate2(ctx.routes, route);
1092
+ import_node_fs2.default.mkdirSync(Path.dirname(typesPath), { recursive: true });
1093
+ import_node_fs2.default.writeFileSync(typesPath, content);
1094
+ });
1095
+ }
1096
+
1095
1097
  // cli/commands.ts
1096
1098
  async function routes(reactRouterRoot, flags = {}) {
1097
1099
  let ctx = await loadPluginContext({
@@ -1223,17 +1225,12 @@ async function createClientEntry(rootDirectory, appDirectory, inputFile) {
1223
1225
  async function typegen(root, flags) {
1224
1226
  root ??= process.cwd();
1225
1227
  if (flags.watch) {
1226
- await watch(root, { configFile: flags.config });
1228
+ await watch(root, flags.config);
1227
1229
  await new Promise(() => {
1228
1230
  });
1229
1231
  return;
1230
1232
  }
1231
- let ctx = await loadPluginContext({ root, configFile: flags.config });
1232
- await writeAll({
1233
- rootDirectory: root,
1234
- appDirectory: ctx.reactRouterConfig.appDirectory,
1235
- routes: ctx.reactRouterConfig.routes
1236
- });
1233
+ await run(root, flags.config);
1237
1234
  }
1238
1235
 
1239
1236
  // cli/run.ts
@@ -1311,7 +1308,7 @@ ${import_picocolors9.default.blueBright("react-router")}
1311
1308
  $ react-router typegen --watch
1312
1309
  $ react-router typegen --config vite.react-router.config.ts
1313
1310
  `;
1314
- async function run(argv = process.argv.slice(2)) {
1311
+ async function run2(argv = process.argv.slice(2)) {
1315
1312
  let versions = process.versions;
1316
1313
  let MINIMUM_NODE_VERSION = 20;
1317
1314
  if (versions && versions.node && import_semver.default.major(versions.node) < MINIMUM_NODE_VERSION) {
@@ -1403,7 +1400,7 @@ async function run(argv = process.argv.slice(2)) {
1403
1400
  }
1404
1401
 
1405
1402
  // cli/index.ts
1406
- run().then(
1403
+ run2().then(
1407
1404
  () => {
1408
1405
  process.exit(0);
1409
1406
  },
package/dist/routes.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @react-router/dev v0.0.0-experimental-9f7fdccd4
2
+ * @react-router/dev v0.0.0-experimental-16086cbff
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @react-router/dev v0.0.0-experimental-9f7fdccd4
2
+ * @react-router/dev v0.0.0-experimental-16086cbff
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
package/dist/vite.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @react-router/dev v0.0.0-experimental-9f7fdccd4
2
+ * @react-router/dev v0.0.0-experimental-16086cbff
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1492,7 +1492,8 @@ var reactRouterVitePlugin = (_config) => {
1492
1492
  "react-router",
1493
1493
  "react-router/dom",
1494
1494
  "react-router-dom"
1495
- ]
1495
+ ],
1496
+ conditions: viteCommand === "build" ? [] : ["development"]
1496
1497
  },
1497
1498
  base: viteUserConfig.base,
1498
1499
  // When consumer provides an allow list for files that can be read by
@@ -2256,7 +2257,12 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
2256
2257
  clientBuildDirectory,
2257
2258
  reactRouterConfig,
2258
2259
  viteConfig,
2259
- data ? { headers: { ...headers, "X-React-Router-Prerender-Data": data } } : { headers }
2260
+ data ? {
2261
+ headers: {
2262
+ ...headers,
2263
+ "X-React-Router-Prerender-Data": encodeURI(data)
2264
+ }
2265
+ } : { headers }
2260
2266
  );
2261
2267
  }
2262
2268
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-router/dev",
3
- "version": "0.0.0-experimental-9f7fdccd4",
3
+ "version": "0.0.0-experimental-16086cbff",
4
4
  "description": "Dev tools and CLI for React Router",
5
5
  "homepage": "https://reactrouter.com",
6
6
  "bugs": {
@@ -36,7 +36,7 @@
36
36
  "files": [
37
37
  "cli/**",
38
38
  "config/**",
39
- "typescript/**",
39
+ "typegen/**",
40
40
  "vite/**",
41
41
  "*.ts",
42
42
  "bin.js",
@@ -77,7 +77,7 @@
77
77
  "set-cookie-parser": "^2.6.0",
78
78
  "valibot": "^0.41.0",
79
79
  "vite-node": "^1.6.0",
80
- "@react-router/node": "0.0.0-experimental-9f7fdccd4"
80
+ "@react-router/node": "0.0.0-experimental-16086cbff"
81
81
  },
82
82
  "devDependencies": {
83
83
  "@types/babel__core": "^7.20.5",
@@ -106,15 +106,15 @@
106
106
  "vite": "^5.1.0",
107
107
  "wireit": "0.14.9",
108
108
  "wrangler": "^3.28.2",
109
- "@react-router/serve": "0.0.0-experimental-9f7fdccd4",
110
- "react-router": "^0.0.0-experimental-9f7fdccd4"
109
+ "@react-router/serve": "0.0.0-experimental-16086cbff",
110
+ "react-router": "^0.0.0-experimental-16086cbff"
111
111
  },
112
112
  "peerDependencies": {
113
113
  "typescript": "^5.1.0",
114
114
  "vite": "^5.1.0",
115
115
  "wrangler": "^3.28.2",
116
- "react-router": "^0.0.0-experimental-9f7fdccd4",
117
- "@react-router/serve": "^0.0.0-experimental-9f7fdccd4"
116
+ "react-router": "^0.0.0-experimental-16086cbff",
117
+ "@react-router/serve": "^0.0.0-experimental-16086cbff"
118
118
  },
119
119
  "peerDependenciesMeta": {
120
120
  "@react-router/serve": {