@tanstack/router-generator 1.141.7 → 1.141.9

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/esm/utils.js CHANGED
@@ -6,23 +6,16 @@ class RoutePrefixMap {
6
6
  constructor(routes) {
7
7
  this.prefixToRoute = /* @__PURE__ */ new Map();
8
8
  this.layoutRoutes = [];
9
- this.nonNestedRoutes = [];
10
9
  for (const route of routes) {
11
10
  if (!route.routePath || route.routePath === `/${rootPathId}`) continue;
12
11
  this.prefixToRoute.set(route.routePath, route);
13
12
  if (route._fsRouteType === "pathless_layout" || route._fsRouteType === "layout" || route._fsRouteType === "__root") {
14
13
  this.layoutRoutes.push(route);
15
14
  }
16
- if (route._isExperimentalNonNestedRoute) {
17
- this.nonNestedRoutes.push(route);
18
- }
19
15
  }
20
16
  this.layoutRoutes.sort(
21
17
  (a, b) => (b.routePath?.length ?? 0) - (a.routePath?.length ?? 0)
22
18
  );
23
- this.nonNestedRoutes.sort(
24
- (a, b) => (b.routePath?.length ?? 0) - (a.routePath?.length ?? 0)
25
- );
26
19
  }
27
20
  /**
28
21
  * Find the longest matching parent route for a given path.
@@ -42,26 +35,6 @@ class RoutePrefixMap {
42
35
  }
43
36
  return null;
44
37
  }
45
- /**
46
- * Find parent for non-nested routes (needs layout route matching).
47
- */
48
- findParentForNonNested(routePath, originalRoutePath, nonNestedSegments) {
49
- for (const route of this.nonNestedRoutes) {
50
- if (route.routePath !== routePath && originalRoutePath?.startsWith(`${route.originalRoutePath}/`)) {
51
- return route;
52
- }
53
- }
54
- for (const route of this.layoutRoutes) {
55
- if (route.routePath === "/") continue;
56
- if (nonNestedSegments.some((seg) => seg === `${route.originalRoutePath}_`)) {
57
- continue;
58
- }
59
- if (routePath.startsWith(`${route.routePath}/`) && route.routePath !== routePath) {
60
- return route;
61
- }
62
- }
63
- return null;
64
- }
65
38
  /**
66
39
  * Check if a route exists at the given path.
67
40
  */
@@ -123,7 +96,7 @@ function removeTrailingSlash(s) {
123
96
  }
124
97
  const BRACKET_CONTENT_RE = /\[(.*?)\]/g;
125
98
  const SPLIT_REGEX = new RegExp("(?<!\\[)\\.(?!\\])", "g");
126
- function determineInitialRoutePath(routePath, config) {
99
+ function determineInitialRoutePath(routePath) {
127
100
  const DISALLOWED_ESCAPE_CHARS = /* @__PURE__ */ new Set([
128
101
  "/",
129
102
  "\\",
@@ -136,25 +109,13 @@ function determineInitialRoutePath(routePath, config) {
136
109
  "|",
137
110
  "!",
138
111
  "$",
139
- "%"
112
+ "%",
113
+ "_"
140
114
  ]);
141
115
  const originalRoutePath = cleanPath(
142
116
  `/${(cleanPath(routePath) || "").split(SPLIT_REGEX).join("/")}`
143
117
  ) || "";
144
- const isExperimentalNonNestedRoute = isValidNonNestedRoute(
145
- originalRoutePath,
146
- config
147
- );
148
- let cleanedRoutePath = routePath;
149
- if (config?.experimental?.nonNestedRoutes) {
150
- if (originalRoutePath !== `/${rootPathId}`) {
151
- cleanedRoutePath = removeTrailingUnderscores(
152
- originalRoutePath,
153
- config.routeToken
154
- );
155
- }
156
- }
157
- const parts = cleanedRoutePath.split(SPLIT_REGEX);
118
+ const parts = routePath.split(SPLIT_REGEX);
158
119
  const escapedParts = parts.map((part) => {
159
120
  let match;
160
121
  while ((match = BRACKET_CONTENT_RE.exec(part)) !== null) {
@@ -176,7 +137,6 @@ Please remove and/or replace them.`
176
137
  const final = cleanPath(`/${escapedParts.join("/")}`) || "";
177
138
  return {
178
139
  routePath: final,
179
- isExperimentalNonNestedRoute,
180
140
  originalRoutePath
181
141
  };
182
142
  }
@@ -234,25 +194,6 @@ const underscoreSlashRegex = /(\/_|_\/)/gi;
234
194
  function removeUnderscores(s) {
235
195
  return s?.replace(underscoreStartEndRegex, "").replace(underscoreSlashRegex, "/");
236
196
  }
237
- function escapeRegExp(s) {
238
- return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
239
- }
240
- function removeLeadingUnderscores(s, routeToken) {
241
- if (!s) return s;
242
- const hasLeadingUnderscore = routeToken[0] === "_";
243
- const routeTokenToExclude = hasLeadingUnderscore ? routeToken.slice(1) : routeToken;
244
- const escapedRouteToken = escapeRegExp(routeTokenToExclude);
245
- const leadingUnderscoreRegex = hasLeadingUnderscore ? new RegExp(`(?<=^|\\/)_(?!${escapedRouteToken})`, "g") : new RegExp(`(?<=^|\\/)_`, "g");
246
- return s.replaceAll(leadingUnderscoreRegex, "");
247
- }
248
- function removeTrailingUnderscores(s, routeToken) {
249
- if (!s) return s;
250
- const hasTrailingUnderscore = routeToken.slice(-1) === "_";
251
- const routeTokenToExclude = hasTrailingUnderscore ? routeToken.slice(0, -1) : routeToken;
252
- const escapedRouteToken = escapeRegExp(routeTokenToExclude);
253
- const trailingUnderscoreRegex = hasTrailingUnderscore ? new RegExp(`(?<!${escapedRouteToken})_(?=\\/|$)`, "g") : new RegExp(`_(?=\\/)|_$`, "g");
254
- return s.replaceAll(trailingUnderscoreRegex, "");
255
- }
256
197
  function capitalize(s) {
257
198
  if (typeof s !== "string") return "";
258
199
  return s.charAt(0).toUpperCase() + s.slice(1);
@@ -306,36 +247,10 @@ function removeLastSegmentFromPath(routePath = "/") {
306
247
  segments.pop();
307
248
  return segments.join("/");
308
249
  }
309
- const nonNestedSegmentRegex = /_(?=\/|$)/g;
310
- const openBracketRegex = /\[/g;
311
- const closeBracketRegex = /\]/g;
312
- function getNonNestedSegments(routePath) {
313
- nonNestedSegmentRegex.lastIndex = 0;
314
- const result = [];
315
- for (const match of routePath.matchAll(nonNestedSegmentRegex)) {
316
- const beforeStr = routePath.substring(0, match.index);
317
- openBracketRegex.lastIndex = 0;
318
- closeBracketRegex.lastIndex = 0;
319
- const openBrackets = beforeStr.match(openBracketRegex)?.length ?? 0;
320
- const closeBrackets = beforeStr.match(closeBracketRegex)?.length ?? 0;
321
- if (openBrackets === closeBrackets) {
322
- result.push(routePath.substring(0, match.index + 1));
323
- }
324
- }
325
- return result.reverse();
326
- }
327
- function hasParentRoute(prefixMap, node, routePathToCheck, originalRoutePathToCheck) {
250
+ function hasParentRoute(prefixMap, node, routePathToCheck) {
328
251
  if (!routePathToCheck || routePathToCheck === "/") {
329
252
  return null;
330
253
  }
331
- if (node._isExperimentalNonNestedRoute && originalRoutePathToCheck) {
332
- const nonNestedSegments = getNonNestedSegments(originalRoutePathToCheck);
333
- return prefixMap.findParentForNonNested(
334
- routePathToCheck,
335
- originalRoutePathToCheck,
336
- nonNestedSegments
337
- );
338
- }
339
254
  return prefixMap.findParent(routePathToCheck);
340
255
  }
341
256
  const getResolvedRouteNodeVariableName = (routeNode) => {
@@ -350,24 +265,21 @@ function isRouteNodeValidForAugmentation(routeNode) {
350
265
  const inferPath = (routeNode) => {
351
266
  return routeNode.cleanedPath === "/" ? routeNode.cleanedPath : routeNode.cleanedPath?.replace(/\/$/, "") ?? "";
352
267
  };
353
- const inferFullPath = (routeNode, config) => {
268
+ const inferFullPath = (routeNode) => {
354
269
  const fullPath = removeGroups(
355
- (config?.experimental?.nonNestedRoutes ? removeLayoutSegments(routeNode.routePath) : removeUnderscores(removeLayoutSegments(routeNode.routePath))) ?? ""
270
+ removeUnderscores(removeLayoutSegments(routeNode.routePath)) ?? ""
356
271
  );
357
272
  return routeNode.cleanedPath === "/" ? fullPath : fullPath.replace(/\/$/, "");
358
273
  };
359
- const createRouteNodesByFullPath = (routeNodes, config) => {
274
+ const createRouteNodesByFullPath = (routeNodes) => {
360
275
  return new Map(
361
- routeNodes.map((routeNode) => [
362
- inferFullPath(routeNode, config),
363
- routeNode
364
- ])
276
+ routeNodes.map((routeNode) => [inferFullPath(routeNode), routeNode])
365
277
  );
366
278
  };
367
- const createRouteNodesByTo = (routeNodes, config) => {
279
+ const createRouteNodesByTo = (routeNodes) => {
368
280
  return new Map(
369
281
  dedupeBranchesAndIndexRoutes(routeNodes).map((routeNode) => [
370
- inferTo(routeNode, config),
282
+ inferTo(routeNode),
371
283
  routeNode
372
284
  ])
373
285
  );
@@ -380,8 +292,8 @@ const createRouteNodesById = (routeNodes) => {
380
292
  })
381
293
  );
382
294
  };
383
- const inferTo = (routeNode, config) => {
384
- const fullPath = inferFullPath(routeNode, config);
295
+ const inferTo = (routeNode) => {
296
+ const fullPath = inferFullPath(routeNode);
385
297
  if (fullPath === "/") return fullPath;
386
298
  return fullPath.replace(/\/$/, "");
387
299
  };
@@ -405,7 +317,7 @@ function checkUnique(routes, key) {
405
317
  }
406
318
  function checkRouteFullPathUniqueness(_routes, config) {
407
319
  const routes = _routes.map((d) => {
408
- const inferredFullPath = inferFullPath(d, config);
320
+ const inferredFullPath = inferFullPath(d);
409
321
  return { ...d, inferredFullPath };
410
322
  });
411
323
  const conflictingFiles = checkUnique(routes, "inferredFullPath");
@@ -504,7 +416,7 @@ function buildFileRoutesByPathInterface(opts) {
504
416
  return `'${filePathId}': {
505
417
  id: '${filePathId}'
506
418
  path: '${inferPath(routeNode)}'
507
- fullPath: '${inferFullPath(routeNode, opts.config)}'
419
+ fullPath: '${inferFullPath(routeNode)}'
508
420
  preLoaderRoute: ${preloaderRoute}
509
421
  parentRoute: typeof ${parent}
510
422
  }`;
@@ -545,31 +457,6 @@ function getImportForRouteNode(node, config, generatedRouteTreePath, root) {
545
457
  ]
546
458
  };
547
459
  }
548
- function isValidNonNestedRoute(normalizedRoutePath, config) {
549
- if (!config?.experimental?.nonNestedRoutes) {
550
- return false;
551
- }
552
- const segments = normalizedRoutePath.split("/").filter(Boolean);
553
- if (segments.length === 0) {
554
- return false;
555
- }
556
- const lastRouteSegment = segments[segments.length - 1];
557
- if (lastRouteSegment === rootPathId) {
558
- return false;
559
- }
560
- if (lastRouteSegment !== config.indexToken && lastRouteSegment !== config.routeToken && lastRouteSegment.endsWith("_")) {
561
- return true;
562
- }
563
- for (const segment of segments.slice(0, -1).reverse()) {
564
- if (segment === config.routeToken) {
565
- return false;
566
- }
567
- if (segment.endsWith("_")) {
568
- return true;
569
- }
570
- }
571
- return false;
572
- }
573
460
  export {
574
461
  RoutePrefixMap,
575
462
  buildFileRoutesByPathInterface,
@@ -589,14 +476,12 @@ export {
589
476
  format,
590
477
  getImportForRouteNode,
591
478
  getImportPath,
592
- getNonNestedSegments,
593
479
  getResolvedRouteNodeVariableName,
594
480
  hasParentRoute,
595
481
  inferFullPath,
596
482
  inferPath,
597
483
  inferTo,
598
484
  isRouteNodeValidForAugmentation,
599
- isValidNonNestedRoute,
600
485
  mergeImportDeclarations,
601
486
  multiSortBy,
602
487
  removeExt,
@@ -604,9 +489,7 @@ export {
604
489
  removeLastSegmentFromPath,
605
490
  removeLayoutSegments,
606
491
  removeLeadingSlash,
607
- removeLeadingUnderscores,
608
492
  removeTrailingSlash,
609
- removeTrailingUnderscores,
610
493
  removeUnderscores,
611
494
  replaceBackslash,
612
495
  resetRegex,
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sources":["../../src/utils.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/prefer-for-of */\nimport * as fsp from 'node:fs/promises'\nimport path from 'node:path'\nimport * as prettier from 'prettier'\nimport { rootPathId } from './filesystem/physical/rootPathId'\nimport type { Config } from './config'\nimport type { ImportDeclaration, RouteNode } from './types'\n\n/**\n * Prefix map for O(1) parent route lookups.\n * Maps each route path prefix to the route node that owns that prefix.\n * Enables finding longest matching parent without linear search.\n */\nexport class RoutePrefixMap {\n private prefixToRoute: Map<string, RouteNode> = new Map()\n private layoutRoutes: Array<RouteNode> = []\n private nonNestedRoutes: Array<RouteNode> = []\n\n constructor(routes: Array<RouteNode>) {\n for (const route of routes) {\n if (!route.routePath || route.routePath === `/${rootPathId}`) continue\n\n // Index by exact path for direct lookups\n this.prefixToRoute.set(route.routePath, route)\n\n // Track layout routes separately for non-nested route handling\n if (\n route._fsRouteType === 'pathless_layout' ||\n route._fsRouteType === 'layout' ||\n route._fsRouteType === '__root'\n ) {\n this.layoutRoutes.push(route)\n }\n\n // Track non-nested routes separately\n if (route._isExperimentalNonNestedRoute) {\n this.nonNestedRoutes.push(route)\n }\n }\n\n // Sort by path length descending for longest-match-first\n this.layoutRoutes.sort(\n (a, b) => (b.routePath?.length ?? 0) - (a.routePath?.length ?? 0),\n )\n this.nonNestedRoutes.sort(\n (a, b) => (b.routePath?.length ?? 0) - (a.routePath?.length ?? 0),\n )\n }\n\n /**\n * Find the longest matching parent route for a given path.\n * O(k) where k is the number of path segments, not O(n) routes.\n */\n findParent(routePath: string): RouteNode | null {\n if (!routePath || routePath === '/') return null\n\n // Walk up the path segments\n let searchPath = routePath\n while (searchPath.length > 0) {\n const lastSlash = searchPath.lastIndexOf('/')\n if (lastSlash <= 0) break\n\n searchPath = searchPath.substring(0, lastSlash)\n const parent = this.prefixToRoute.get(searchPath)\n if (parent && parent.routePath !== routePath) {\n return parent\n }\n }\n return null\n }\n\n /**\n * Find parent for non-nested routes (needs layout route matching).\n */\n findParentForNonNested(\n routePath: string,\n originalRoutePath: string | undefined,\n nonNestedSegments: Array<string>,\n ): RouteNode | null {\n // First check for other non-nested routes that are prefixes\n // Use pre-sorted array for longest-match-first\n for (const route of this.nonNestedRoutes) {\n if (\n route.routePath !== routePath &&\n originalRoutePath?.startsWith(`${route.originalRoutePath}/`)\n ) {\n return route\n }\n }\n\n // Then check layout routes\n for (const route of this.layoutRoutes) {\n if (route.routePath === '/') continue\n\n // Skip if this route's original path + underscore matches a non-nested segment\n if (\n nonNestedSegments.some((seg) => seg === `${route.originalRoutePath}_`)\n ) {\n continue\n }\n\n // Check if this layout route is a prefix of the path we're looking for\n if (\n routePath.startsWith(`${route.routePath}/`) &&\n route.routePath !== routePath\n ) {\n return route\n }\n }\n\n return null\n }\n\n /**\n * Check if a route exists at the given path.\n */\n has(routePath: string): boolean {\n return this.prefixToRoute.has(routePath)\n }\n\n /**\n * Get a route by exact path.\n */\n get(routePath: string): RouteNode | undefined {\n return this.prefixToRoute.get(routePath)\n }\n}\n\nexport function multiSortBy<T>(\n arr: Array<T>,\n accessors: Array<(item: T) => any> = [(d) => d],\n): Array<T> {\n const len = arr.length\n // Pre-compute all accessor values to avoid repeated function calls during sort\n const indexed: Array<{ item: T; index: number; keys: Array<any> }> =\n new Array(len)\n for (let i = 0; i < len; i++) {\n const item = arr[i]!\n const keys = new Array(accessors.length)\n for (let j = 0; j < accessors.length; j++) {\n keys[j] = accessors[j]!(item)\n }\n indexed[i] = { item, index: i, keys }\n }\n\n indexed.sort((a, b) => {\n for (let j = 0; j < accessors.length; j++) {\n const ao = a.keys[j]\n const bo = b.keys[j]\n\n if (typeof ao === 'undefined') {\n if (typeof bo === 'undefined') {\n continue\n }\n return 1\n }\n\n if (ao === bo) {\n continue\n }\n\n return ao > bo ? 1 : -1\n }\n\n return a.index - b.index\n })\n\n const result: Array<T> = new Array(len)\n for (let i = 0; i < len; i++) {\n result[i] = indexed[i]!.item\n }\n return result\n}\n\nexport function cleanPath(path: string) {\n // remove double slashes\n return path.replace(/\\/{2,}/g, '/')\n}\n\nexport function trimPathLeft(path: string) {\n return path === '/' ? path : path.replace(/^\\/{1,}/, '')\n}\n\nexport function removeLeadingSlash(path: string): string {\n return path.replace(/^\\//, '')\n}\n\nexport function removeTrailingSlash(s: string) {\n return s.replace(/\\/$/, '')\n}\n\nconst BRACKET_CONTENT_RE = /\\[(.*?)\\]/g\nconst SPLIT_REGEX = /(?<!\\[)\\.(?!\\])/g\n\nexport function determineInitialRoutePath(\n routePath: string,\n config?: Pick<Config, 'experimental' | 'routeToken' | 'indexToken'>,\n) {\n const DISALLOWED_ESCAPE_CHARS = new Set([\n '/',\n '\\\\',\n '?',\n '#',\n ':',\n '*',\n '<',\n '>',\n '|',\n '!',\n '$',\n '%',\n ])\n\n const originalRoutePath =\n cleanPath(\n `/${(cleanPath(routePath) || '').split(SPLIT_REGEX).join('/')}`,\n ) || ''\n\n // check if the route path is a valid non-nested path,\n // TODO with new major rename to reflect not experimental anymore\n const isExperimentalNonNestedRoute = isValidNonNestedRoute(\n originalRoutePath,\n config,\n )\n\n let cleanedRoutePath = routePath\n\n // we already identified the path as non-nested and can now remove the trailing underscores\n // we need to do this now before we encounter any escaped trailing underscores\n // this way we can be sure any remaining trailing underscores should remain\n // TODO with new major we can remove check and always remove leading underscores\n if (config?.experimental?.nonNestedRoutes) {\n // we should leave trailing underscores if the route path is the root path\n if (originalRoutePath !== `/${rootPathId}`) {\n // remove trailing underscores on various path segments\n cleanedRoutePath = removeTrailingUnderscores(\n originalRoutePath,\n config.routeToken,\n )\n }\n }\n\n const parts = cleanedRoutePath.split(SPLIT_REGEX)\n\n // Escape any characters that in square brackets\n // we keep the original path untouched\n const escapedParts = parts.map((part) => {\n // Check if any disallowed characters are used in brackets\n\n let match\n while ((match = BRACKET_CONTENT_RE.exec(part)) !== null) {\n const character = match[1]\n if (character === undefined) continue\n if (DISALLOWED_ESCAPE_CHARS.has(character)) {\n console.error(\n `Error: Disallowed character \"${character}\" found in square brackets in route path \"${routePath}\".\\nYou cannot use any of the following characters in square brackets: ${Array.from(\n DISALLOWED_ESCAPE_CHARS,\n ).join(', ')}\\nPlease remove and/or replace them.`,\n )\n process.exit(1)\n }\n }\n\n // Since this split segment is safe at this point, we can\n // remove the brackets and replace them with the content inside\n return part.replace(BRACKET_CONTENT_RE, '$1')\n })\n\n // If the syntax for prefix/suffix is different, from the path\n // matching internals of router-core, we'd perform those changes here\n // on the `escapedParts` array before it is joined back together in\n // `final`\n\n const final = cleanPath(`/${escapedParts.join('/')}`) || ''\n\n return {\n routePath: final,\n isExperimentalNonNestedRoute,\n originalRoutePath,\n }\n}\n\nconst backslashRegex = /\\\\/g\n\nexport function replaceBackslash(s: string) {\n return s.replace(backslashRegex, '/')\n}\n\nconst alphanumericRegex = /[a-zA-Z0-9_]/\nconst splatSlashRegex = /\\/\\$\\//g\nconst trailingSplatRegex = /\\$$/g\nconst bracketSplatRegex = /\\$\\{\\$\\}/g\nconst dollarSignRegex = /\\$/g\nconst splitPathRegex = /[/-]/g\nconst leadingDigitRegex = /^(\\d)/g\n\nconst toVariableSafeChar = (char: string): string => {\n if (alphanumericRegex.test(char)) {\n return char // Keep alphanumeric characters and underscores as is\n }\n\n // Replace special characters with meaningful text equivalents\n switch (char) {\n case '.':\n return 'Dot'\n case '-':\n return 'Dash'\n case '@':\n return 'At'\n case '(':\n return '' // Removed since route groups use parentheses\n case ')':\n return '' // Removed since route groups use parentheses\n case ' ':\n return '' // Remove spaces\n default:\n return `Char${char.charCodeAt(0)}` // For any other characters\n }\n}\n\nexport function routePathToVariable(routePath: string): string {\n const cleaned = removeUnderscores(routePath)\n if (!cleaned) return ''\n\n const parts = cleaned\n .replace(splatSlashRegex, '/splat/')\n .replace(trailingSplatRegex, 'splat')\n .replace(bracketSplatRegex, 'splat')\n .replace(dollarSignRegex, '')\n .split(splitPathRegex)\n\n let result = ''\n for (let i = 0; i < parts.length; i++) {\n const part = parts[i]!\n const segment = i > 0 ? capitalize(part) : part\n for (let j = 0; j < segment.length; j++) {\n result += toVariableSafeChar(segment[j]!)\n }\n }\n\n return result.replace(leadingDigitRegex, 'R$1')\n}\n\nconst underscoreStartEndRegex = /(^_|_$)/gi\nconst underscoreSlashRegex = /(\\/_|_\\/)/gi\n\nexport function removeUnderscores(s?: string) {\n return s\n ?.replace(underscoreStartEndRegex, '')\n .replace(underscoreSlashRegex, '/')\n}\n\nfunction escapeRegExp(s: string): string {\n return s.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')\n}\n\nexport function removeLeadingUnderscores(s: string, routeToken: string) {\n if (!s) return s\n\n const hasLeadingUnderscore = routeToken[0] === '_'\n\n const routeTokenToExclude = hasLeadingUnderscore\n ? routeToken.slice(1)\n : routeToken\n\n const escapedRouteToken = escapeRegExp(routeTokenToExclude)\n\n const leadingUnderscoreRegex = hasLeadingUnderscore\n ? new RegExp(`(?<=^|\\\\/)_(?!${escapedRouteToken})`, 'g')\n : new RegExp(`(?<=^|\\\\/)_`, 'g')\n\n return s.replaceAll(leadingUnderscoreRegex, '')\n}\n\nexport function removeTrailingUnderscores(s: string, routeToken: string) {\n if (!s) return s\n\n const hasTrailingUnderscore = routeToken.slice(-1) === '_'\n\n const routeTokenToExclude = hasTrailingUnderscore\n ? routeToken.slice(0, -1)\n : routeToken\n\n const escapedRouteToken = escapeRegExp(routeTokenToExclude)\n\n const trailingUnderscoreRegex = hasTrailingUnderscore\n ? new RegExp(`(?<!${escapedRouteToken})_(?=\\\\/|$)`, 'g')\n : new RegExp(`_(?=\\\\/)|_$`, 'g')\n\n return s.replaceAll(trailingUnderscoreRegex, '')\n}\n\nexport function capitalize(s: string) {\n if (typeof s !== 'string') return ''\n return s.charAt(0).toUpperCase() + s.slice(1)\n}\n\nexport function removeExt(d: string, keepExtension: boolean = false) {\n return keepExtension ? d : d.substring(0, d.lastIndexOf('.')) || d\n}\n\n/**\n * This function writes to a file if the content is different.\n *\n * @param filepath The path to the file\n * @param content Original content\n * @param incomingContent New content\n * @param callbacks Callbacks to run before and after writing\n * @returns Whether the file was written\n */\nexport async function writeIfDifferent(\n filepath: string,\n content: string,\n incomingContent: string,\n callbacks?: { beforeWrite?: () => void; afterWrite?: () => void },\n): Promise<boolean> {\n if (content !== incomingContent) {\n callbacks?.beforeWrite?.()\n await fsp.writeFile(filepath, incomingContent)\n callbacks?.afterWrite?.()\n return true\n }\n return false\n}\n\n/**\n * This function formats the source code using the default formatter (Prettier).\n *\n * @param source The content to format\n * @param config The configuration object\n * @returns The formatted content\n */\nexport async function format(\n source: string,\n config: {\n quoteStyle: 'single' | 'double'\n semicolons: boolean\n },\n): Promise<string> {\n const prettierOptions: prettier.Config = {\n semi: config.semicolons,\n singleQuote: config.quoteStyle === 'single',\n parser: 'typescript',\n }\n return prettier.format(source, prettierOptions)\n}\n\n/**\n * This function resets the regex index to 0 so that it can be reused\n * without having to create a new regex object or worry about the last\n * state when using the global flag.\n *\n * @param regex The regex object to reset\n * @returns\n */\nexport function resetRegex(regex: RegExp) {\n regex.lastIndex = 0\n return\n}\n\n/**\n * This function checks if a file exists.\n *\n * @param file The path to the file\n * @returns Whether the file exists\n */\nexport async function checkFileExists(file: string) {\n try {\n await fsp.access(file, fsp.constants.F_OK)\n return true\n } catch {\n return false\n }\n}\n\nconst possiblyNestedRouteGroupPatternRegex = /\\([^/]+\\)\\/?/g\nexport function removeGroups(s: string) {\n return s.replace(possiblyNestedRouteGroupPatternRegex, '')\n}\n\n/**\n * Removes all segments from a given path that start with an underscore ('_').\n *\n * @param {string} routePath - The path from which to remove segments. Defaults to '/'.\n * @returns {string} The path with all underscore-prefixed segments removed.\n * @example\n * removeLayoutSegments('/workspace/_auth/foo') // '/workspace/foo'\n */\nexport function removeLayoutSegments(routePath: string = '/'): string {\n const segments = routePath.split('/')\n const newSegments = segments.filter((segment) => !segment.startsWith('_'))\n return newSegments.join('/')\n}\n\n/**\n * The `node.path` is used as the `id` in the route definition.\n * This function checks if the given node has a parent and if so, it determines the correct path for the given node.\n * @param node - The node to determine the path for.\n * @returns The correct path for the given node.\n */\nexport function determineNodePath(node: RouteNode) {\n return (node.path = node.parent\n ? node.routePath?.replace(node.parent.routePath ?? '', '') || '/'\n : node.routePath)\n}\n\n/**\n * Removes the last segment from a given path. Segments are considered to be separated by a '/'.\n *\n * @param {string} routePath - The path from which to remove the last segment. Defaults to '/'.\n * @returns {string} The path with the last segment removed.\n * @example\n * removeLastSegmentFromPath('/workspace/_auth/foo') // '/workspace/_auth'\n */\nexport function removeLastSegmentFromPath(routePath: string = '/'): string {\n const segments = routePath.split('/')\n segments.pop() // Remove the last segment\n return segments.join('/')\n}\n\nconst nonNestedSegmentRegex = /_(?=\\/|$)/g\nconst openBracketRegex = /\\[/g\nconst closeBracketRegex = /\\]/g\n\n/**\n * Extracts non-nested segments from a route path.\n * Used for determining parent routes in non-nested route scenarios.\n */\nexport function getNonNestedSegments(routePath: string): Array<string> {\n nonNestedSegmentRegex.lastIndex = 0\n const result: Array<string> = []\n for (const match of routePath.matchAll(nonNestedSegmentRegex)) {\n const beforeStr = routePath.substring(0, match.index)\n openBracketRegex.lastIndex = 0\n closeBracketRegex.lastIndex = 0\n const openBrackets = beforeStr.match(openBracketRegex)?.length ?? 0\n const closeBrackets = beforeStr.match(closeBracketRegex)?.length ?? 0\n if (openBrackets === closeBrackets) {\n result.push(routePath.substring(0, match.index + 1))\n }\n }\n return result.reverse()\n}\n\n/**\n * Find parent route using RoutePrefixMap for O(k) lookups instead of O(n).\n */\nexport function hasParentRoute(\n prefixMap: RoutePrefixMap,\n node: RouteNode,\n routePathToCheck: string | undefined,\n originalRoutePathToCheck: string | undefined,\n): RouteNode | null {\n if (!routePathToCheck || routePathToCheck === '/') {\n return null\n }\n\n if (node._isExperimentalNonNestedRoute && originalRoutePathToCheck) {\n const nonNestedSegments = getNonNestedSegments(originalRoutePathToCheck)\n return prefixMap.findParentForNonNested(\n routePathToCheck,\n originalRoutePathToCheck,\n nonNestedSegments,\n )\n }\n\n return prefixMap.findParent(routePathToCheck)\n}\n\n/**\n * Gets the final variable name for a route\n */\nexport const getResolvedRouteNodeVariableName = (\n routeNode: RouteNode,\n): string => {\n return routeNode.children?.length\n ? `${routeNode.variableName}RouteWithChildren`\n : `${routeNode.variableName}Route`\n}\n\n/**\n * Checks if a given RouteNode is valid for augmenting it with typing based on conditions.\n * Also asserts that the RouteNode is defined.\n *\n * @param routeNode - The RouteNode to check.\n * @returns A boolean indicating whether the RouteNode is defined.\n */\nexport function isRouteNodeValidForAugmentation(\n routeNode?: RouteNode,\n): routeNode is RouteNode {\n if (!routeNode || routeNode.isVirtual) {\n return false\n }\n return true\n}\n\n/**\n * Infers the path for use by TS\n */\nexport const inferPath = (routeNode: RouteNode): string => {\n return routeNode.cleanedPath === '/'\n ? routeNode.cleanedPath\n : (routeNode.cleanedPath?.replace(/\\/$/, '') ?? '')\n}\n\n/**\n * Infers the full path for use by TS\n */\nexport const inferFullPath = (\n routeNode: RouteNode,\n config?: Pick<Config, 'experimental' | 'routeToken'>,\n): string => {\n // with new nonNestedPaths feature we can be sure any remaining trailing underscores are escaped and should remain\n // TODO with new major we can remove check and only remove leading underscores\n const fullPath = removeGroups(\n (config?.experimental?.nonNestedRoutes\n ? removeLayoutSegments(routeNode.routePath)\n : removeUnderscores(removeLayoutSegments(routeNode.routePath))) ?? '',\n )\n\n return routeNode.cleanedPath === '/' ? fullPath : fullPath.replace(/\\/$/, '')\n}\n\n/**\n * Creates a map from fullPath to routeNode\n */\nexport const createRouteNodesByFullPath = (\n routeNodes: Array<RouteNode>,\n config?: Pick<Config, 'experimental' | 'routeToken'>,\n): Map<string, RouteNode> => {\n return new Map(\n routeNodes.map((routeNode) => [\n inferFullPath(routeNode, config),\n routeNode,\n ]),\n )\n}\n\n/**\n * Create a map from 'to' to a routeNode\n */\nexport const createRouteNodesByTo = (\n routeNodes: Array<RouteNode>,\n config?: Pick<Config, 'experimental' | 'routeToken'>,\n): Map<string, RouteNode> => {\n return new Map(\n dedupeBranchesAndIndexRoutes(routeNodes).map((routeNode) => [\n inferTo(routeNode, config),\n routeNode,\n ]),\n )\n}\n\n/**\n * Create a map from 'id' to a routeNode\n */\nexport const createRouteNodesById = (\n routeNodes: Array<RouteNode>,\n): Map<string, RouteNode> => {\n return new Map(\n routeNodes.map((routeNode) => {\n const id = routeNode.routePath ?? ''\n return [id, routeNode]\n }),\n )\n}\n\n/**\n * Infers to path\n */\nexport const inferTo = (\n routeNode: RouteNode,\n config?: Pick<Config, 'experimental' | 'routeToken'>,\n): string => {\n const fullPath = inferFullPath(routeNode, config)\n\n if (fullPath === '/') return fullPath\n\n return fullPath.replace(/\\/$/, '')\n}\n\n/**\n * Dedupes branches and index routes\n */\nexport const dedupeBranchesAndIndexRoutes = (\n routes: Array<RouteNode>,\n): Array<RouteNode> => {\n return routes.filter((route) => {\n if (route.children?.find((child) => child.cleanedPath === '/')) return false\n return true\n })\n}\n\nfunction checkUnique<TElement>(routes: Array<TElement>, key: keyof TElement) {\n // Check no two routes have the same `key`\n // if they do, throw an error with the conflicting filePaths\n const keys = routes.map((d) => d[key])\n const uniqueKeys = new Set(keys)\n if (keys.length !== uniqueKeys.size) {\n const duplicateKeys = keys.filter((d, i) => keys.indexOf(d) !== i)\n const conflictingFiles = routes.filter((d) =>\n duplicateKeys.includes(d[key]),\n )\n return conflictingFiles\n }\n return undefined\n}\n\nexport function checkRouteFullPathUniqueness(\n _routes: Array<RouteNode>,\n config: Config,\n) {\n const routes = _routes.map((d) => {\n const inferredFullPath = inferFullPath(d, config)\n return { ...d, inferredFullPath }\n })\n\n const conflictingFiles = checkUnique(routes, 'inferredFullPath')\n\n if (conflictingFiles !== undefined) {\n const errorMessage = `Conflicting configuration paths were found for the following route${conflictingFiles.length > 1 ? 's' : ''}: ${conflictingFiles\n .map((p) => `\"${p.inferredFullPath}\"`)\n .join(', ')}.\nPlease ensure each Route has a unique full path.\nConflicting files: \\n ${conflictingFiles.map((d) => path.resolve(config.routesDirectory, d.filePath)).join('\\n ')}\\n`\n throw new Error(errorMessage)\n }\n}\n\nexport function buildRouteTreeConfig(\n nodes: Array<RouteNode>,\n disableTypes: boolean,\n depth = 1,\n): Array<string> {\n const children = nodes.map((node) => {\n if (node._fsRouteType === '__root') {\n return\n }\n\n if (node._fsRouteType === 'pathless_layout' && !node.children?.length) {\n return\n }\n\n const route = `${node.variableName}`\n\n if (node.children?.length) {\n const childConfigs = buildRouteTreeConfig(\n node.children,\n disableTypes,\n depth + 1,\n )\n\n const childrenDeclaration = disableTypes\n ? ''\n : `interface ${route}RouteChildren {\n ${node.children\n .map(\n (child) =>\n `${child.variableName}Route: typeof ${getResolvedRouteNodeVariableName(child)}`,\n )\n .join(',')}\n}`\n\n const children = `const ${route}RouteChildren${disableTypes ? '' : `: ${route}RouteChildren`} = {\n ${node.children\n .map(\n (child) =>\n `${child.variableName}Route: ${getResolvedRouteNodeVariableName(child)}`,\n )\n .join(',')}\n}`\n\n const routeWithChildren = `const ${route}RouteWithChildren = ${route}Route._addFileChildren(${route}RouteChildren)`\n\n return [\n childConfigs.join('\\n'),\n childrenDeclaration,\n children,\n routeWithChildren,\n ].join('\\n\\n')\n }\n\n return undefined\n })\n\n return children.filter((x) => x !== undefined)\n}\n\nexport function buildImportString(\n importDeclaration: ImportDeclaration,\n): string {\n const { source, specifiers, importKind } = importDeclaration\n return specifiers.length\n ? `import ${importKind === 'type' ? 'type ' : ''}{ ${specifiers.map((s) => (s.local ? `${s.imported} as ${s.local}` : s.imported)).join(', ')} } from '${source}'`\n : ''\n}\n\nexport function lowerCaseFirstChar(value: string) {\n if (!value[0]) {\n return value\n }\n\n return value[0].toLowerCase() + value.slice(1)\n}\n\nexport function mergeImportDeclarations(\n imports: Array<ImportDeclaration>,\n): Array<ImportDeclaration> {\n const merged = new Map<string, ImportDeclaration>()\n\n for (const imp of imports) {\n const key = `${imp.source}-${imp.importKind ?? ''}`\n let existing = merged.get(key)\n if (!existing) {\n existing = { ...imp, specifiers: [] }\n merged.set(key, existing)\n }\n\n const existingSpecs = existing.specifiers\n for (const specifier of imp.specifiers) {\n let found = false\n for (let i = 0; i < existingSpecs.length; i++) {\n const e = existingSpecs[i]!\n if (e.imported === specifier.imported && e.local === specifier.local) {\n found = true\n break\n }\n }\n if (!found) {\n existingSpecs.push(specifier)\n }\n }\n }\n\n return [...merged.values()]\n}\n\nexport const findParent = (node: RouteNode | undefined): string => {\n if (!node) {\n return `rootRouteImport`\n }\n if (node.parent) {\n return `${node.parent.variableName}Route`\n }\n return findParent(node.parent)\n}\n\nexport function buildFileRoutesByPathInterface(opts: {\n routeNodes: Array<RouteNode>\n module: string\n interfaceName: string\n config?: Pick<Config, 'experimental' | 'routeToken'>\n}): string {\n return `declare module '${opts.module}' {\n interface ${opts.interfaceName} {\n ${opts.routeNodes\n .map((routeNode) => {\n const filePathId = routeNode.routePath\n const preloaderRoute = `typeof ${routeNode.variableName}RouteImport`\n\n const parent = findParent(routeNode)\n\n return `'${filePathId}': {\n id: '${filePathId}'\n path: '${inferPath(routeNode)}'\n fullPath: '${inferFullPath(routeNode, opts.config)}'\n preLoaderRoute: ${preloaderRoute}\n parentRoute: typeof ${parent}\n }`\n })\n .join('\\n')}\n }\n}`\n}\n\nexport function getImportPath(\n node: RouteNode,\n config: Config,\n generatedRouteTreePath: string,\n): string {\n return replaceBackslash(\n removeExt(\n path.relative(\n path.dirname(generatedRouteTreePath),\n path.resolve(config.routesDirectory, node.filePath),\n ),\n config.addExtensions,\n ),\n )\n}\n\nexport function getImportForRouteNode(\n node: RouteNode,\n config: Config,\n generatedRouteTreePath: string,\n root: string,\n): ImportDeclaration {\n let source = ''\n if (config.importRoutesUsingAbsolutePaths) {\n source = replaceBackslash(\n removeExt(\n path.resolve(root, config.routesDirectory, node.filePath),\n config.addExtensions,\n ),\n )\n } else {\n source = `./${getImportPath(node, config, generatedRouteTreePath)}`\n }\n return {\n source,\n specifiers: [\n {\n imported: 'Route',\n local: `${node.variableName}RouteImport`,\n },\n ],\n } satisfies ImportDeclaration\n}\n\n/**\n * Used to validate if a route is a pathless layout route\n * @param normalizedRoutePath Normalized route path, i.e `/foo/_layout/route.tsx` and `/foo._layout.route.tsx` to `/foo/_layout/route`\n * @param config The `router-generator` configuration object\n * @returns Boolean indicating if the route is a pathless layout route\n */\nexport function isValidNonNestedRoute(\n normalizedRoutePath: string,\n config?: Pick<Config, 'experimental' | 'routeToken' | 'indexToken'>,\n): boolean {\n if (!config?.experimental?.nonNestedRoutes) {\n return false\n }\n\n const segments = normalizedRoutePath.split('/').filter(Boolean)\n\n if (segments.length === 0) {\n return false\n }\n\n const lastRouteSegment = segments[segments.length - 1]!\n\n // If segment === __root, then exit as false\n if (lastRouteSegment === rootPathId) {\n return false\n }\n\n if (\n lastRouteSegment !== config.indexToken &&\n lastRouteSegment !== config.routeToken &&\n lastRouteSegment.endsWith('_')\n ) {\n return true\n }\n\n for (const segment of segments.slice(0, -1).reverse()) {\n if (segment === config.routeToken) {\n return false\n }\n\n if (segment.endsWith('_')) {\n return true\n }\n }\n\n return false\n}\n"],"names":["path","children"],"mappings":";;;;AAaO,MAAM,eAAe;AAAA,EAK1B,YAAY,QAA0B;AAJtC,SAAQ,oCAA4C,IAAA;AACpD,SAAQ,eAAiC,CA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b,MAAI,OAAO,gCAAgC;AACzC,aAAS;AAAA,MACP;AAAA,QACE,KAAK,QAAQ,MAAM,OAAO,iBAAiB,KAAK,QAAQ;AAAA,QACxD,OAAO;AAAA,MAAA;AAAA,IACT;AAAA,EAEJ,OAAO;AACL,aAAS,KAAK,cAAc,MAAM,QAAQ,sBAAsB,CAAC;AAAA,EACnE;AACA,SAAO;AAAA,IACL;AAAA,IACA,YAAY;AAAA,MACV;AAAA,QACE,UAAU;AAAA,QACV,OAAO,GAAG,KAAK,YAAY;AAAA,MAAA;AAAA,IAC7B;AAAA,EACF;AAEJ;AAQO,SAAS,sBACd,qBACA,QACS;AACT,MAAI,CAAC,QAAQ,cAAc,iBAAiB;AAC1C,WAAO;AAAA,EACT;AAEA,QAAM,WAAW,oBAAoB,MAAM,GAAG,EAAE,OAAO,OAAO;AAE9D,MAAI,SAAS,WAAW,GAAG;AACzB,WAAO;AAAA,EACT;AAEA,QAAM,mBAAmB,SAAS,SAAS,SAAS,CAAC;AAGrD,MAAI,qBAAqB,YAAY;AACnC,WAAO;AAAA,EACT;AAEA,MACE,qBAAqB,OAAO,cAC5B,qBAAqB,OAAO,cAC5B,iBAAiB,SAAS,GAAG,GAC7B;AACA,WAAO;AAAA,EACT;AAEA,aAAW,WAAW,SAAS,MAAM,GAAG,EAAE,EAAE,WAAW;AACrD,QAAI,YAAY,OAAO,YAAY;AACjC,aAAO;AAAA,IACT;AAEA,QAAI,QAAQ,SAAS,GAAG,GAAG;AACzB,aAAO;AAAA,IACT;AAAA,EACF;AAEA,SAAO;AACT;"}
1
+ {"version":3,"file":"utils.js","sources":["../../src/utils.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/prefer-for-of */\nimport * as fsp from 'node:fs/promises'\nimport path from 'node:path'\nimport * as prettier from 'prettier'\nimport { rootPathId } from './filesystem/physical/rootPathId'\nimport type { Config } from './config'\nimport type { ImportDeclaration, RouteNode } from './types'\n\n/**\n * Prefix map for O(1) parent route lookups.\n * Maps each route path prefix to the route node that owns that prefix.\n * Enables finding longest matching parent without linear search.\n */\nexport class RoutePrefixMap {\n private prefixToRoute: Map<string, RouteNode> = new Map()\n private layoutRoutes: Array<RouteNode> = []\n\n constructor(routes: Array<RouteNode>) {\n for (const route of routes) {\n if (!route.routePath || route.routePath === `/${rootPathId}`) continue\n\n // Index by exact path for direct lookups\n this.prefixToRoute.set(route.routePath, route)\n\n if (\n route._fsRouteType === 'pathless_layout' ||\n route._fsRouteType === 'layout' ||\n route._fsRouteType === '__root'\n ) {\n this.layoutRoutes.push(route)\n }\n }\n\n // Sort by path length descending for longest-match-first\n this.layoutRoutes.sort(\n (a, b) => (b.routePath?.length ?? 0) - (a.routePath?.length ?? 0),\n )\n }\n\n /**\n * Find the longest matching parent route for a given path.\n * O(k) where k is the number of path segments, not O(n) routes.\n */\n findParent(routePath: string): RouteNode | null {\n if (!routePath || routePath === '/') return null\n\n // Walk up the path segments\n let searchPath = routePath\n while (searchPath.length > 0) {\n const lastSlash = searchPath.lastIndexOf('/')\n if (lastSlash <= 0) break\n\n searchPath = searchPath.substring(0, lastSlash)\n const parent = this.prefixToRoute.get(searchPath)\n if (parent && parent.routePath !== routePath) {\n return parent\n }\n }\n return null\n }\n\n /**\n * Check if a route exists at the given path.\n */\n has(routePath: string): boolean {\n return this.prefixToRoute.has(routePath)\n }\n\n /**\n * Get a route by exact path.\n */\n get(routePath: string): RouteNode | undefined {\n return this.prefixToRoute.get(routePath)\n }\n}\n\nexport function multiSortBy<T>(\n arr: Array<T>,\n accessors: Array<(item: T) => any> = [(d) => d],\n): Array<T> {\n const len = arr.length\n // Pre-compute all accessor values to avoid repeated function calls during sort\n const indexed: Array<{ item: T; index: number; keys: Array<any> }> =\n new Array(len)\n for (let i = 0; i < len; i++) {\n const item = arr[i]!\n const keys = new Array(accessors.length)\n for (let j = 0; j < accessors.length; j++) {\n keys[j] = accessors[j]!(item)\n }\n indexed[i] = { item, index: i, keys }\n }\n\n indexed.sort((a, b) => {\n for (let j = 0; j < accessors.length; j++) {\n const ao = a.keys[j]\n const bo = b.keys[j]\n\n if (typeof ao === 'undefined') {\n if (typeof bo === 'undefined') {\n continue\n }\n return 1\n }\n\n if (ao === bo) {\n continue\n }\n\n return ao > bo ? 1 : -1\n }\n\n return a.index - b.index\n })\n\n const result: Array<T> = new Array(len)\n for (let i = 0; i < len; i++) {\n result[i] = indexed[i]!.item\n }\n return result\n}\n\nexport function cleanPath(path: string) {\n // remove double slashes\n return path.replace(/\\/{2,}/g, '/')\n}\n\nexport function trimPathLeft(path: string) {\n return path === '/' ? path : path.replace(/^\\/{1,}/, '')\n}\n\nexport function removeLeadingSlash(path: string): string {\n return path.replace(/^\\//, '')\n}\n\nexport function removeTrailingSlash(s: string) {\n return s.replace(/\\/$/, '')\n}\n\nconst BRACKET_CONTENT_RE = /\\[(.*?)\\]/g\nconst SPLIT_REGEX = /(?<!\\[)\\.(?!\\])/g\n\nexport function determineInitialRoutePath(routePath: string) {\n const DISALLOWED_ESCAPE_CHARS = new Set([\n '/',\n '\\\\',\n '?',\n '#',\n ':',\n '*',\n '<',\n '>',\n '|',\n '!',\n '$',\n '%',\n '_',\n ])\n\n const originalRoutePath =\n cleanPath(\n `/${(cleanPath(routePath) || '').split(SPLIT_REGEX).join('/')}`,\n ) || ''\n\n const parts = routePath.split(SPLIT_REGEX)\n\n // Escape any characters that in square brackets\n // we keep the original path untouched\n const escapedParts = parts.map((part) => {\n // Check if any disallowed characters are used in brackets\n\n let match\n while ((match = BRACKET_CONTENT_RE.exec(part)) !== null) {\n const character = match[1]\n if (character === undefined) continue\n if (DISALLOWED_ESCAPE_CHARS.has(character)) {\n console.error(\n `Error: Disallowed character \"${character}\" found in square brackets in route path \"${routePath}\".\\nYou cannot use any of the following characters in square brackets: ${Array.from(\n DISALLOWED_ESCAPE_CHARS,\n ).join(', ')}\\nPlease remove and/or replace them.`,\n )\n process.exit(1)\n }\n }\n\n // Since this split segment is safe at this point, we can\n // remove the brackets and replace them with the content inside\n return part.replace(BRACKET_CONTENT_RE, '$1')\n })\n\n // If the syntax for prefix/suffix is different, from the path\n // matching internals of router-core, we'd perform those changes here\n // on the `escapedParts` array before it is joined back together in\n // `final`\n\n const final = cleanPath(`/${escapedParts.join('/')}`) || ''\n\n return {\n routePath: final,\n originalRoutePath,\n }\n}\n\nconst backslashRegex = /\\\\/g\n\nexport function replaceBackslash(s: string) {\n return s.replace(backslashRegex, '/')\n}\n\nconst alphanumericRegex = /[a-zA-Z0-9_]/\nconst splatSlashRegex = /\\/\\$\\//g\nconst trailingSplatRegex = /\\$$/g\nconst bracketSplatRegex = /\\$\\{\\$\\}/g\nconst dollarSignRegex = /\\$/g\nconst splitPathRegex = /[/-]/g\nconst leadingDigitRegex = /^(\\d)/g\n\nconst toVariableSafeChar = (char: string): string => {\n if (alphanumericRegex.test(char)) {\n return char // Keep alphanumeric characters and underscores as is\n }\n\n // Replace special characters with meaningful text equivalents\n switch (char) {\n case '.':\n return 'Dot'\n case '-':\n return 'Dash'\n case '@':\n return 'At'\n case '(':\n return '' // Removed since route groups use parentheses\n case ')':\n return '' // Removed since route groups use parentheses\n case ' ':\n return '' // Remove spaces\n default:\n return `Char${char.charCodeAt(0)}` // For any other characters\n }\n}\n\nexport function routePathToVariable(routePath: string): string {\n const cleaned = removeUnderscores(routePath)\n if (!cleaned) return ''\n\n const parts = cleaned\n .replace(splatSlashRegex, '/splat/')\n .replace(trailingSplatRegex, 'splat')\n .replace(bracketSplatRegex, 'splat')\n .replace(dollarSignRegex, '')\n .split(splitPathRegex)\n\n let result = ''\n for (let i = 0; i < parts.length; i++) {\n const part = parts[i]!\n const segment = i > 0 ? capitalize(part) : part\n for (let j = 0; j < segment.length; j++) {\n result += toVariableSafeChar(segment[j]!)\n }\n }\n\n return result.replace(leadingDigitRegex, 'R$1')\n}\n\nconst underscoreStartEndRegex = /(^_|_$)/gi\nconst underscoreSlashRegex = /(\\/_|_\\/)/gi\n\nexport function removeUnderscores(s?: string) {\n return s\n ?.replace(underscoreStartEndRegex, '')\n .replace(underscoreSlashRegex, '/')\n}\n\nfunction escapeRegExp(s: string): string {\n return s.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')\n}\n\nexport function removeLeadingUnderscores(s: string, routeToken: string) {\n if (!s) return s\n\n const hasLeadingUnderscore = routeToken[0] === '_'\n\n const routeTokenToExclude = hasLeadingUnderscore\n ? routeToken.slice(1)\n : routeToken\n\n const escapedRouteToken = escapeRegExp(routeTokenToExclude)\n\n const leadingUnderscoreRegex = hasLeadingUnderscore\n ? new RegExp(`(?<=^|\\\\/)_(?!${escapedRouteToken})`, 'g')\n : new RegExp(`(?<=^|\\\\/)_`, 'g')\n\n return s.replaceAll(leadingUnderscoreRegex, '')\n}\n\nexport function removeTrailingUnderscores(s: string, routeToken: string) {\n if (!s) return s\n\n const hasTrailingUnderscore = routeToken.slice(-1) === '_'\n\n const routeTokenToExclude = hasTrailingUnderscore\n ? routeToken.slice(0, -1)\n : routeToken\n\n const escapedRouteToken = escapeRegExp(routeTokenToExclude)\n\n const trailingUnderscoreRegex = hasTrailingUnderscore\n ? new RegExp(`(?<!${escapedRouteToken})_(?=\\\\/|$)`, 'g')\n : new RegExp(`_(?=\\\\/)|_$`, 'g')\n\n return s.replaceAll(trailingUnderscoreRegex, '')\n}\n\nexport function capitalize(s: string) {\n if (typeof s !== 'string') return ''\n return s.charAt(0).toUpperCase() + s.slice(1)\n}\n\nexport function removeExt(d: string, keepExtension: boolean = false) {\n return keepExtension ? d : d.substring(0, d.lastIndexOf('.')) || d\n}\n\n/**\n * This function writes to a file if the content is different.\n *\n * @param filepath The path to the file\n * @param content Original content\n * @param incomingContent New content\n * @param callbacks Callbacks to run before and after writing\n * @returns Whether the file was written\n */\nexport async function writeIfDifferent(\n filepath: string,\n content: string,\n incomingContent: string,\n callbacks?: { beforeWrite?: () => void; afterWrite?: () => void },\n): Promise<boolean> {\n if (content !== incomingContent) {\n callbacks?.beforeWrite?.()\n await fsp.writeFile(filepath, incomingContent)\n callbacks?.afterWrite?.()\n return true\n }\n return false\n}\n\n/**\n * This function formats the source code using the default formatter (Prettier).\n *\n * @param source The content to format\n * @param config The configuration object\n * @returns The formatted content\n */\nexport async function format(\n source: string,\n config: {\n quoteStyle: 'single' | 'double'\n semicolons: boolean\n },\n): Promise<string> {\n const prettierOptions: prettier.Config = {\n semi: config.semicolons,\n singleQuote: config.quoteStyle === 'single',\n parser: 'typescript',\n }\n return prettier.format(source, prettierOptions)\n}\n\n/**\n * This function resets the regex index to 0 so that it can be reused\n * without having to create a new regex object or worry about the last\n * state when using the global flag.\n *\n * @param regex The regex object to reset\n * @returns\n */\nexport function resetRegex(regex: RegExp) {\n regex.lastIndex = 0\n return\n}\n\n/**\n * This function checks if a file exists.\n *\n * @param file The path to the file\n * @returns Whether the file exists\n */\nexport async function checkFileExists(file: string) {\n try {\n await fsp.access(file, fsp.constants.F_OK)\n return true\n } catch {\n return false\n }\n}\n\nconst possiblyNestedRouteGroupPatternRegex = /\\([^/]+\\)\\/?/g\nexport function removeGroups(s: string) {\n return s.replace(possiblyNestedRouteGroupPatternRegex, '')\n}\n\n/**\n * Removes all segments from a given path that start with an underscore ('_').\n *\n * @param {string} routePath - The path from which to remove segments. Defaults to '/'.\n * @returns {string} The path with all underscore-prefixed segments removed.\n * @example\n * removeLayoutSegments('/workspace/_auth/foo') // '/workspace/foo'\n */\nexport function removeLayoutSegments(routePath: string = '/'): string {\n const segments = routePath.split('/')\n const newSegments = segments.filter((segment) => !segment.startsWith('_'))\n return newSegments.join('/')\n}\n\n/**\n * The `node.path` is used as the `id` in the route definition.\n * This function checks if the given node has a parent and if so, it determines the correct path for the given node.\n * @param node - The node to determine the path for.\n * @returns The correct path for the given node.\n */\nexport function determineNodePath(node: RouteNode) {\n return (node.path = node.parent\n ? node.routePath?.replace(node.parent.routePath ?? '', '') || '/'\n : node.routePath)\n}\n\n/**\n * Removes the last segment from a given path. Segments are considered to be separated by a '/'.\n *\n * @param {string} routePath - The path from which to remove the last segment. Defaults to '/'.\n * @returns {string} The path with the last segment removed.\n * @example\n * removeLastSegmentFromPath('/workspace/_auth/foo') // '/workspace/_auth'\n */\nexport function removeLastSegmentFromPath(routePath: string = '/'): string {\n const segments = routePath.split('/')\n segments.pop() // Remove the last segment\n return segments.join('/')\n}\n\n/**\n * Find parent route using RoutePrefixMap for O(k) lookups instead of O(n).\n */\nexport function hasParentRoute(\n prefixMap: RoutePrefixMap,\n node: RouteNode,\n routePathToCheck: string | undefined,\n): RouteNode | null {\n if (!routePathToCheck || routePathToCheck === '/') {\n return null\n }\n\n return prefixMap.findParent(routePathToCheck)\n}\n\n/**\n * Gets the final variable name for a route\n */\nexport const getResolvedRouteNodeVariableName = (\n routeNode: RouteNode,\n): string => {\n return routeNode.children?.length\n ? `${routeNode.variableName}RouteWithChildren`\n : `${routeNode.variableName}Route`\n}\n\n/**\n * Checks if a given RouteNode is valid for augmenting it with typing based on conditions.\n * Also asserts that the RouteNode is defined.\n *\n * @param routeNode - The RouteNode to check.\n * @returns A boolean indicating whether the RouteNode is defined.\n */\nexport function isRouteNodeValidForAugmentation(\n routeNode?: RouteNode,\n): routeNode is RouteNode {\n if (!routeNode || routeNode.isVirtual) {\n return false\n }\n return true\n}\n\n/**\n * Infers the path for use by TS\n */\nexport const inferPath = (routeNode: RouteNode): string => {\n return routeNode.cleanedPath === '/'\n ? routeNode.cleanedPath\n : (routeNode.cleanedPath?.replace(/\\/$/, '') ?? '')\n}\n\n/**\n * Infers the full path for use by TS\n */\nexport const inferFullPath = (routeNode: RouteNode): string => {\n const fullPath = removeGroups(\n removeUnderscores(removeLayoutSegments(routeNode.routePath)) ?? '',\n )\n\n return routeNode.cleanedPath === '/' ? fullPath : fullPath.replace(/\\/$/, '')\n}\n\n/**\n * Creates a map from fullPath to routeNode\n */\nexport const createRouteNodesByFullPath = (\n routeNodes: Array<RouteNode>,\n): Map<string, RouteNode> => {\n return new Map(\n routeNodes.map((routeNode) => [inferFullPath(routeNode), routeNode]),\n )\n}\n\n/**\n * Create a map from 'to' to a routeNode\n */\nexport const createRouteNodesByTo = (\n routeNodes: Array<RouteNode>,\n): Map<string, RouteNode> => {\n return new Map(\n dedupeBranchesAndIndexRoutes(routeNodes).map((routeNode) => [\n inferTo(routeNode),\n routeNode,\n ]),\n )\n}\n\n/**\n * Create a map from 'id' to a routeNode\n */\nexport const createRouteNodesById = (\n routeNodes: Array<RouteNode>,\n): Map<string, RouteNode> => {\n return new Map(\n routeNodes.map((routeNode) => {\n const id = routeNode.routePath ?? ''\n return [id, routeNode]\n }),\n )\n}\n\n/**\n * Infers to path\n */\nexport const inferTo = (routeNode: RouteNode): string => {\n const fullPath = inferFullPath(routeNode)\n\n if (fullPath === '/') return fullPath\n\n return fullPath.replace(/\\/$/, '')\n}\n\n/**\n * Dedupes branches and index routes\n */\nexport const dedupeBranchesAndIndexRoutes = (\n routes: Array<RouteNode>,\n): Array<RouteNode> => {\n return routes.filter((route) => {\n if (route.children?.find((child) => child.cleanedPath === '/')) return false\n return true\n })\n}\n\nfunction checkUnique<TElement>(routes: Array<TElement>, key: keyof TElement) {\n // Check no two routes have the same `key`\n // if they do, throw an error with the conflicting filePaths\n const keys = routes.map((d) => d[key])\n const uniqueKeys = new Set(keys)\n if (keys.length !== uniqueKeys.size) {\n const duplicateKeys = keys.filter((d, i) => keys.indexOf(d) !== i)\n const conflictingFiles = routes.filter((d) =>\n duplicateKeys.includes(d[key]),\n )\n return conflictingFiles\n }\n return undefined\n}\n\nexport function checkRouteFullPathUniqueness(\n _routes: Array<RouteNode>,\n config: Config,\n) {\n const routes = _routes.map((d) => {\n const inferredFullPath = inferFullPath(d)\n return { ...d, inferredFullPath }\n })\n\n const conflictingFiles = checkUnique(routes, 'inferredFullPath')\n\n if (conflictingFiles !== undefined) {\n const errorMessage = `Conflicting configuration paths were found for the following route${conflictingFiles.length > 1 ? 's' : ''}: ${conflictingFiles\n .map((p) => `\"${p.inferredFullPath}\"`)\n .join(', ')}.\nPlease ensure each Route has a unique full path.\nConflicting files: \\n ${conflictingFiles.map((d) => path.resolve(config.routesDirectory, d.filePath)).join('\\n ')}\\n`\n throw new Error(errorMessage)\n }\n}\n\nexport function buildRouteTreeConfig(\n nodes: Array<RouteNode>,\n disableTypes: boolean,\n depth = 1,\n): Array<string> {\n const children = nodes.map((node) => {\n if (node._fsRouteType === '__root') {\n return\n }\n\n if (node._fsRouteType === 'pathless_layout' && !node.children?.length) {\n return\n }\n\n const route = `${node.variableName}`\n\n if (node.children?.length) {\n const childConfigs = buildRouteTreeConfig(\n node.children,\n disableTypes,\n depth + 1,\n )\n\n const childrenDeclaration = disableTypes\n ? ''\n : `interface ${route}RouteChildren {\n ${node.children\n .map(\n (child) =>\n `${child.variableName}Route: typeof ${getResolvedRouteNodeVariableName(child)}`,\n )\n .join(',')}\n}`\n\n const children = `const ${route}RouteChildren${disableTypes ? '' : `: ${route}RouteChildren`} = {\n ${node.children\n .map(\n (child) =>\n `${child.variableName}Route: ${getResolvedRouteNodeVariableName(child)}`,\n )\n .join(',')}\n}`\n\n const routeWithChildren = `const ${route}RouteWithChildren = ${route}Route._addFileChildren(${route}RouteChildren)`\n\n return [\n childConfigs.join('\\n'),\n childrenDeclaration,\n children,\n routeWithChildren,\n ].join('\\n\\n')\n }\n\n return undefined\n })\n\n return children.filter((x) => x !== undefined)\n}\n\nexport function buildImportString(\n importDeclaration: ImportDeclaration,\n): string {\n const { source, specifiers, importKind } = importDeclaration\n return specifiers.length\n ? `import ${importKind === 'type' ? 'type ' : ''}{ ${specifiers.map((s) => (s.local ? `${s.imported} as ${s.local}` : s.imported)).join(', ')} } from '${source}'`\n : ''\n}\n\nexport function lowerCaseFirstChar(value: string) {\n if (!value[0]) {\n return value\n }\n\n return value[0].toLowerCase() + value.slice(1)\n}\n\nexport function mergeImportDeclarations(\n imports: Array<ImportDeclaration>,\n): Array<ImportDeclaration> {\n const merged = new Map<string, ImportDeclaration>()\n\n for (const imp of imports) {\n const key = `${imp.source}-${imp.importKind ?? ''}`\n let existing = merged.get(key)\n if (!existing) {\n existing = { ...imp, specifiers: [] }\n merged.set(key, existing)\n }\n\n const existingSpecs = existing.specifiers\n for (const specifier of imp.specifiers) {\n let found = false\n for (let i = 0; i < existingSpecs.length; i++) {\n const e = existingSpecs[i]!\n if (e.imported === specifier.imported && e.local === specifier.local) {\n found = true\n break\n }\n }\n if (!found) {\n existingSpecs.push(specifier)\n }\n }\n }\n\n return [...merged.values()]\n}\n\nexport const findParent = (node: RouteNode | undefined): string => {\n if (!node) {\n return `rootRouteImport`\n }\n if (node.parent) {\n return `${node.parent.variableName}Route`\n }\n return findParent(node.parent)\n}\n\nexport function buildFileRoutesByPathInterface(opts: {\n routeNodes: Array<RouteNode>\n module: string\n interfaceName: string\n config?: Pick<Config, 'routeToken'>\n}): string {\n return `declare module '${opts.module}' {\n interface ${opts.interfaceName} {\n ${opts.routeNodes\n .map((routeNode) => {\n const filePathId = routeNode.routePath\n const preloaderRoute = `typeof ${routeNode.variableName}RouteImport`\n\n const parent = findParent(routeNode)\n\n return `'${filePathId}': {\n id: '${filePathId}'\n path: '${inferPath(routeNode)}'\n fullPath: '${inferFullPath(routeNode)}'\n preLoaderRoute: ${preloaderRoute}\n parentRoute: typeof ${parent}\n }`\n })\n .join('\\n')}\n }\n}`\n}\n\nexport function getImportPath(\n node: RouteNode,\n config: Config,\n generatedRouteTreePath: string,\n): string {\n return replaceBackslash(\n removeExt(\n path.relative(\n path.dirname(generatedRouteTreePath),\n path.resolve(config.routesDirectory, node.filePath),\n ),\n config.addExtensions,\n ),\n )\n}\n\nexport function getImportForRouteNode(\n node: RouteNode,\n config: Config,\n generatedRouteTreePath: string,\n root: string,\n): ImportDeclaration {\n let source = ''\n if (config.importRoutesUsingAbsolutePaths) {\n source = replaceBackslash(\n removeExt(\n path.resolve(root, config.routesDirectory, node.filePath),\n config.addExtensions,\n ),\n )\n } else {\n source = `./${getImportPath(node, config, generatedRouteTreePath)}`\n }\n return {\n source,\n specifiers: [\n {\n imported: 'Route',\n local: `${node.vari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A,QACnC,KAAK,QAAQ,OAAO,iBAAiB,KAAK,QAAQ;AAAA,MAAA;AAAA,MAEpD,OAAO;AAAA,IAAA;AAAA,EACT;AAEJ;AAEO,SAAS,sBACd,MACA,QACA,wBACA,MACmB;AACnB,MAAI,SAAS;AACb,MAAI,OAAO,gCAAgC;AACzC,aAAS;AAAA,MACP;AAAA,QACE,KAAK,QAAQ,MAAM,OAAO,iBAAiB,KAAK,QAAQ;AAAA,QACxD,OAAO;AAAA,MAAA;AAAA,IACT;AAAA,EAEJ,OAAO;AACL,aAAS,KAAK,cAAc,MAAM,QAAQ,sBAAsB,CAAC;AAAA,EACnE;AACA,SAAO;AAAA,IACL;AAAA,IACA,YAAY;AAAA,MACV;AAAA,QACE,UAAU;AAAA,QACV,OAAO,GAAG,KAAK,YAAY;AAAA,MAAA;AAAA,IAC7B;AAAA,EACF;AAEJ;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/router-generator",
3
- "version": "1.141.7",
3
+ "version": "1.141.9",
4
4
  "description": "Modern and scalable routing for React applications",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -54,12 +54,12 @@
54
54
  "source-map": "^0.7.4",
55
55
  "tsx": "^4.19.2",
56
56
  "zod": "^3.24.2",
57
- "@tanstack/router-core": "1.141.6",
58
- "@tanstack/virtual-file-routes": "1.141.0",
59
- "@tanstack/router-utils": "1.141.0"
57
+ "@tanstack/router-core": "1.141.8",
58
+ "@tanstack/router-utils": "1.141.0",
59
+ "@tanstack/virtual-file-routes": "1.141.0"
60
60
  },
61
61
  "devDependencies": {
62
- "@tanstack/react-router": "1.141.6"
62
+ "@tanstack/react-router": "1.141.8"
63
63
  },
64
64
  "scripts": {
65
65
  "clean": "rimraf ./dist && rimraf ./coverage",
package/src/config.ts CHANGED
@@ -54,8 +54,6 @@ export const configSchema = baseConfigSchema.extend({
54
54
  .object({
55
55
  // TODO: This has been made stable and is now "autoCodeSplitting". Remove in next major version.
56
56
  enableCodeSplitting: z.boolean().optional(),
57
- // TODO: This resolves issues with non-nested paths in file-based routing. To be made default in next major version.
58
- nonNestedRoutes: z.boolean().optional(),
59
57
  })
60
58
  .optional(),
61
59
  plugins: z.array(z.custom<GeneratorPlugin>()).optional(),
@@ -34,7 +34,6 @@ export async function getRouteNodes(
34
34
  | 'disableLogging'
35
35
  | 'routeToken'
36
36
  | 'indexToken'
37
- | 'experimental'
38
37
  >,
39
38
  root: string,
40
39
  ): Promise<GetRouteNodesResult> {
@@ -135,8 +134,7 @@ export async function getRouteNodes(
135
134
  const {
136
135
  routePath: initialRoutePath,
137
136
  originalRoutePath: initialOriginalRoutePath,
138
- isExperimentalNonNestedRoute,
139
- } = determineInitialRoutePath(filePathNoExt, config)
137
+ } = determineInitialRoutePath(filePathNoExt)
140
138
 
141
139
  let routePath = initialRoutePath
142
140
  let originalRoutePath = initialOriginalRoutePath
@@ -228,7 +226,6 @@ export async function getRouteNodes(
228
226
  routePath,
229
227
  variableName,
230
228
  _fsRouteType: routeType,
231
- _isExperimentalNonNestedRoute: isExperimentalNonNestedRoute,
232
229
  originalRoutePath,
233
230
  })
234
231
  }
package/src/generator.ts CHANGED
@@ -34,7 +34,6 @@ import {
34
34
  removeGroups,
35
35
  removeLastSegmentFromPath,
36
36
  removeLayoutSegments,
37
- removeLeadingUnderscores,
38
37
  removeTrailingSlash,
39
38
  removeUnderscores,
40
39
  replaceBackslash,
@@ -822,11 +821,8 @@ export class Generator {
822
821
  let fileRoutesByFullPath = ''
823
822
 
824
823
  if (!config.disableTypes) {
825
- const routeNodesByFullPath = createRouteNodesByFullPath(
826
- acc.routeNodes,
827
- config,
828
- )
829
- const routeNodesByTo = createRouteNodesByTo(acc.routeNodes, config)
824
+ const routeNodesByFullPath = createRouteNodesByFullPath(acc.routeNodes)
825
+ const routeNodesByTo = createRouteNodesByTo(acc.routeNodes)
830
826
  const routeNodesById = createRouteNodesById(acc.routeNodes)
831
827
 
832
828
  fileRoutesByFullPath = [
@@ -1360,15 +1356,7 @@ ${acc.routeTree.map((child) => `${child.variableName}Route: typeof ${getResolved
1360
1356
  prefixMap: RoutePrefixMap,
1361
1357
  config?: Config,
1362
1358
  ) {
1363
- const useExperimentalNonNestedRoutes =
1364
- config?.experimental?.nonNestedRoutes ?? false
1365
-
1366
- const parentRoute = hasParentRoute(
1367
- prefixMap,
1368
- node,
1369
- node.routePath,
1370
- node.originalRoutePath,
1371
- )
1359
+ const parentRoute = hasParentRoute(prefixMap, node, node.routePath)
1372
1360
 
1373
1361
  if (parentRoute) node.parent = parentRoute
1374
1362
 
@@ -1383,15 +1371,8 @@ ${acc.routeTree.map((child) => `${child.variableName}Route: typeof ${getResolved
1383
1371
  lastRouteSegment.startsWith('_') ||
1384
1372
  split.every((part) => this.routeGroupPatternRegex.test(part))
1385
1373
 
1386
- // with new nonNestedPaths feature we can be sure any remaining trailing underscores are escaped and should remain
1387
- // TODO with new major we can remove check and only remove leading underscores
1388
1374
  node.cleanedPath = removeGroups(
1389
- (useExperimentalNonNestedRoutes
1390
- ? removeLeadingUnderscores(
1391
- removeLayoutSegments(node.path ?? ''),
1392
- config?.routeToken ?? '',
1393
- )
1394
- : removeUnderscores(removeLayoutSegments(node.path))) ?? '',
1375
+ removeUnderscores(removeLayoutSegments(node.path)) ?? '',
1395
1376
  )
1396
1377
 
1397
1378
  if (
package/src/types.ts CHANGED
@@ -13,7 +13,6 @@ export type RouteNode = {
13
13
  children?: Array<RouteNode>
14
14
  parent?: RouteNode
15
15
  createFileRouteProps?: Set<string>
16
- _isExperimentalNonNestedRoute?: boolean
17
16
  }
18
17
 
19
18
  export interface GetRouteNodesResult {