@tanstack/router-generator 1.146.2 → 1.149.0

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.
Files changed (36) hide show
  1. package/dist/cjs/config.cjs +29 -6
  2. package/dist/cjs/config.cjs.map +1 -1
  3. package/dist/cjs/config.d.cts +94 -12
  4. package/dist/cjs/filesystem/physical/getRouteNodes.cjs +50 -27
  5. package/dist/cjs/filesystem/physical/getRouteNodes.cjs.map +1 -1
  6. package/dist/cjs/filesystem/physical/getRouteNodes.d.cts +12 -3
  7. package/dist/cjs/filesystem/virtual/getRouteNodes.cjs +12 -5
  8. package/dist/cjs/filesystem/virtual/getRouteNodes.cjs.map +1 -1
  9. package/dist/cjs/filesystem/virtual/getRouteNodes.d.cts +3 -2
  10. package/dist/cjs/generator.cjs +32 -7
  11. package/dist/cjs/generator.cjs.map +1 -1
  12. package/dist/cjs/generator.d.cts +20 -2
  13. package/dist/cjs/utils.cjs +47 -0
  14. package/dist/cjs/utils.cjs.map +1 -1
  15. package/dist/cjs/utils.d.cts +6 -1
  16. package/dist/esm/config.d.ts +94 -12
  17. package/dist/esm/config.js +29 -6
  18. package/dist/esm/config.js.map +1 -1
  19. package/dist/esm/filesystem/physical/getRouteNodes.d.ts +12 -3
  20. package/dist/esm/filesystem/physical/getRouteNodes.js +51 -28
  21. package/dist/esm/filesystem/physical/getRouteNodes.js.map +1 -1
  22. package/dist/esm/filesystem/virtual/getRouteNodes.d.ts +3 -2
  23. package/dist/esm/filesystem/virtual/getRouteNodes.js +12 -5
  24. package/dist/esm/filesystem/virtual/getRouteNodes.js.map +1 -1
  25. package/dist/esm/generator.d.ts +20 -2
  26. package/dist/esm/generator.js +33 -8
  27. package/dist/esm/generator.js.map +1 -1
  28. package/dist/esm/utils.d.ts +6 -1
  29. package/dist/esm/utils.js +47 -0
  30. package/dist/esm/utils.js.map +1 -1
  31. package/package.json +4 -4
  32. package/src/config.ts +58 -6
  33. package/src/filesystem/physical/getRouteNodes.ts +105 -43
  34. package/src/filesystem/virtual/getRouteNodes.ts +12 -2
  35. package/src/generator.ts +59 -9
  36. package/src/utils.ts +73 -1
@@ -1,6 +1,6 @@
1
1
  import path from "node:path";
2
2
  import * as fsp from "node:fs/promises";
3
- import { replaceBackslash, routePathToVariable, removeExt, determineInitialRoutePath, hasEscapedLeadingUnderscore } from "../../utils.js";
3
+ import { replaceBackslash, routePathToVariable, removeExt, determineInitialRoutePath, unwrapBracketWrappedSegment, hasEscapedLeadingUnderscore } from "../../utils.js";
4
4
  import { getRouteNodes as getRouteNodes$1 } from "../virtual/getRouteNodes.js";
5
5
  import { loadConfigFile } from "../virtual/loadConfigFile.js";
6
6
  import { logging } from "../../logger.js";
@@ -10,7 +10,7 @@ const virtualConfigFileRegExp = /__virtual\.[mc]?[jt]s$/;
10
10
  function isVirtualConfigFile(fileName) {
11
11
  return virtualConfigFileRegExp.test(fileName);
12
12
  }
13
- async function getRouteNodes(config, root) {
13
+ async function getRouteNodes(config, root, tokenRegexes) {
14
14
  const { routeFilePrefix, routeFileIgnorePrefix, routeFileIgnorePattern } = config;
15
15
  const logger = logging({ disabled: config.disableLogging });
16
16
  const routeFileIgnoreRegExp = new RegExp(routeFileIgnorePattern ?? "", "g");
@@ -58,7 +58,8 @@ async function getRouteNodes(config, root) {
58
58
  routesDirectory: fullDir,
59
59
  virtualRouteConfig: dummyRoot
60
60
  },
61
- root
61
+ root,
62
+ tokenRegexes
62
63
  );
63
64
  allPhysicalDirectories.push(...physicalDirectories);
64
65
  virtualRouteNodes.forEach((node) => {
@@ -103,7 +104,7 @@ async function getRouteNodes(config, root) {
103
104
  logger.error(`ERROR: ${errorMessage}`);
104
105
  throw new Error(errorMessage);
105
106
  }
106
- const meta = getRouteMeta(routePath, originalRoutePath, config);
107
+ const meta = getRouteMeta(routePath, originalRoutePath, tokenRegexes);
107
108
  const variableName = meta.variableName;
108
109
  let routeType = meta.fsRouteType;
109
110
  if (routeType === "lazy") {
@@ -114,7 +115,7 @@ async function getRouteNodes(config, root) {
114
115
  routePath,
115
116
  originalRoutePath,
116
117
  routeType,
117
- config
118
+ tokenRegexes
118
119
  )) {
119
120
  routeType = "pathless_layout";
120
121
  }
@@ -136,42 +137,58 @@ async function getRouteNodes(config, root) {
136
137
  }
137
138
  const originalSegments = originalRoutePath.split("/").filter(Boolean);
138
139
  const lastOriginalSegmentForSuffix = originalSegments[originalSegments.length - 1] || "";
140
+ const { routeTokenSegmentRegex, indexTokenSegmentRegex } = tokenRegexes;
139
141
  const specialSuffixes = [
140
142
  "component",
141
143
  "errorComponent",
142
144
  "notFoundComponent",
143
145
  "pendingComponent",
144
146
  "loader",
145
- config.routeToken,
146
147
  "lazy"
147
148
  ];
149
+ const routePathSegments = routePath.split("/").filter(Boolean);
150
+ const lastRouteSegment = routePathSegments[routePathSegments.length - 1] || "";
148
151
  const suffixToStrip = specialSuffixes.find((suffix) => {
149
152
  const endsWithSuffix = routePath.endsWith(`/${suffix}`);
150
- const isEscaped = lastOriginalSegmentForSuffix === `[${suffix}]`;
153
+ const isEscaped = lastOriginalSegmentForSuffix.startsWith("[") && lastOriginalSegmentForSuffix.endsWith("]") && unwrapBracketWrappedSegment(lastOriginalSegmentForSuffix) === suffix;
151
154
  return endsWithSuffix && !isEscaped;
152
155
  });
153
- if (suffixToStrip) {
154
- routePath = routePath.replace(new RegExp(`/${suffixToStrip}$`), "");
156
+ const routeTokenCandidate = unwrapBracketWrappedSegment(
157
+ lastOriginalSegmentForSuffix
158
+ );
159
+ const isRouteTokenEscaped = lastOriginalSegmentForSuffix !== routeTokenCandidate && routeTokenSegmentRegex.test(routeTokenCandidate);
160
+ const shouldStripRouteToken = routeTokenSegmentRegex.test(lastRouteSegment) && !isRouteTokenEscaped;
161
+ if (suffixToStrip || shouldStripRouteToken) {
162
+ const stripSegment = suffixToStrip ?? lastRouteSegment;
163
+ routePath = routePath.replace(new RegExp(`/${stripSegment}$`), "");
155
164
  originalRoutePath = originalRoutePath.replace(
156
- new RegExp(`/${suffixToStrip}$`),
165
+ new RegExp(`/${stripSegment}$`),
157
166
  ""
158
167
  );
159
168
  }
160
169
  const lastOriginalSegment = originalRoutePath.split("/").filter(Boolean).pop() || "";
161
- const isIndexEscaped = lastOriginalSegment === `[${config.indexToken}]`;
170
+ const indexTokenCandidate = unwrapBracketWrappedSegment(lastOriginalSegment);
171
+ const isIndexEscaped = lastOriginalSegment !== indexTokenCandidate && indexTokenSegmentRegex.test(indexTokenCandidate);
162
172
  if (!isIndexEscaped) {
163
- if (routePath === config.indexToken) {
164
- routePath = "/";
165
- }
166
- if (originalRoutePath === config.indexToken) {
167
- originalRoutePath = "/";
173
+ const updatedRouteSegments = routePath.split("/").filter(Boolean);
174
+ const updatedLastRouteSegment = updatedRouteSegments[updatedRouteSegments.length - 1] || "";
175
+ if (indexTokenSegmentRegex.test(updatedLastRouteSegment)) {
176
+ if (routePathSegments.length === 1) {
177
+ routePath = "/";
178
+ }
179
+ if (lastOriginalSegment === updatedLastRouteSegment) {
180
+ originalRoutePath = "/";
181
+ }
182
+ const isLayoutRoute = routeType === "layout";
183
+ routePath = routePath.replace(
184
+ new RegExp(`/${updatedLastRouteSegment}$`),
185
+ "/"
186
+ ) || (isLayoutRoute ? "" : "/");
187
+ originalRoutePath = originalRoutePath.replace(
188
+ new RegExp(`/${indexTokenCandidate}$`),
189
+ "/"
190
+ ) || (isLayoutRoute ? "" : "/");
168
191
  }
169
- const isLayoutRoute = routeType === "layout";
170
- routePath = routePath.replace(new RegExp(`/${config.indexToken}$`), "/") || (isLayoutRoute ? "" : "/");
171
- originalRoutePath = originalRoutePath.replace(
172
- new RegExp(`/${config.indexToken}$`),
173
- "/"
174
- ) || (isLayoutRoute ? "" : "/");
175
192
  }
176
193
  routeNodes.push({
177
194
  filePath,
@@ -207,14 +224,19 @@ async function getRouteNodes(config, root) {
207
224
  physicalDirectories: allPhysicalDirectories
208
225
  };
209
226
  }
210
- function getRouteMeta(routePath, originalRoutePath, config) {
227
+ function getRouteMeta(routePath, originalRoutePath, tokenRegexes) {
211
228
  let fsRouteType = "static";
212
229
  const originalSegments = originalRoutePath.split("/").filter(Boolean);
213
230
  const lastOriginalSegment = originalSegments[originalSegments.length - 1] || "";
231
+ const { routeTokenSegmentRegex } = tokenRegexes;
214
232
  const isSuffixEscaped = (suffix) => {
215
- return lastOriginalSegment === `[${suffix}]`;
233
+ return lastOriginalSegment.startsWith("[") && lastOriginalSegment.endsWith("]") && unwrapBracketWrappedSegment(lastOriginalSegment) === suffix;
216
234
  };
217
- if (routePath.endsWith(`/${config.routeToken}`) && !isSuffixEscaped(config.routeToken)) {
235
+ const routeSegments = routePath.split("/").filter(Boolean);
236
+ const lastRouteSegment = routeSegments[routeSegments.length - 1] || "";
237
+ const routeTokenCandidate = unwrapBracketWrappedSegment(lastOriginalSegment);
238
+ const isRouteTokenEscaped = lastOriginalSegment !== routeTokenCandidate && routeTokenSegmentRegex.test(routeTokenCandidate);
239
+ if (routeTokenSegmentRegex.test(lastRouteSegment) && !isRouteTokenEscaped) {
218
240
  fsRouteType = "layout";
219
241
  } else if (routePath.endsWith("/lazy") && !isSuffixEscaped("lazy")) {
220
242
  fsRouteType = "lazy";
@@ -232,7 +254,7 @@ function getRouteMeta(routePath, originalRoutePath, config) {
232
254
  const variableName = routePathToVariable(routePath);
233
255
  return { fsRouteType, variableName };
234
256
  }
235
- function isValidPathlessLayoutRoute(normalizedRoutePath, originalRoutePath, routeType, config) {
257
+ function isValidPathlessLayoutRoute(normalizedRoutePath, originalRoutePath, routeType, tokenRegexes) {
236
258
  if (routeType === "lazy") {
237
259
  return false;
238
260
  }
@@ -248,7 +270,8 @@ function isValidPathlessLayoutRoute(normalizedRoutePath, originalRoutePath, rout
248
270
  if (lastRouteSegment === rootPathId) {
249
271
  return false;
250
272
  }
251
- if (lastRouteSegment === config.routeToken && typeof secondToLastRouteSegment === "string" && typeof secondToLastOriginalSegment === "string") {
273
+ const { routeTokenSegmentRegex, indexTokenSegmentRegex } = tokenRegexes;
274
+ if (routeTokenSegmentRegex.test(lastRouteSegment) && typeof secondToLastRouteSegment === "string" && typeof secondToLastOriginalSegment === "string") {
252
275
  if (hasEscapedLeadingUnderscore(secondToLastOriginalSegment)) {
253
276
  return false;
254
277
  }
@@ -257,7 +280,7 @@ function isValidPathlessLayoutRoute(normalizedRoutePath, originalRoutePath, rout
257
280
  if (hasEscapedLeadingUnderscore(lastOriginalSegment)) {
258
281
  return false;
259
282
  }
260
- return lastRouteSegment !== config.indexToken && lastRouteSegment !== config.routeToken && lastRouteSegment.startsWith("_");
283
+ return !indexTokenSegmentRegex.test(lastRouteSegment) && !routeTokenSegmentRegex.test(lastRouteSegment) && lastRouteSegment.startsWith("_");
261
284
  }
262
285
  export {
263
286
  getRouteMeta,
@@ -1 +1 @@
1
- {"version":3,"file":"getRouteNodes.js","sources":["../../../../src/filesystem/physical/getRouteNodes.ts"],"sourcesContent":["import path from 'node:path'\nimport * as fsp from 'node:fs/promises'\nimport {\n determineInitialRoutePath,\n hasEscapedLeadingUnderscore,\n removeExt,\n replaceBackslash,\n routePathToVariable,\n} from '../../utils'\nimport { getRouteNodes as getRouteNodesVirtual } from '../virtual/getRouteNodes'\nimport { loadConfigFile } from '../virtual/loadConfigFile'\nimport { logging } from '../../logger'\nimport { rootPathId } from './rootPathId'\nimport type {\n VirtualRootRoute,\n VirtualRouteSubtreeConfig,\n} from '@tanstack/virtual-file-routes'\nimport type { FsRouteType, GetRouteNodesResult, RouteNode } from '../../types'\nimport type { Config } from '../../config'\n\nconst disallowedRouteGroupConfiguration = /\\(([^)]+)\\).(ts|js|tsx|jsx|vue)/\n\nconst virtualConfigFileRegExp = /__virtual\\.[mc]?[jt]s$/\nexport function isVirtualConfigFile(fileName: string): boolean {\n return virtualConfigFileRegExp.test(fileName)\n}\n\nexport async function getRouteNodes(\n config: Pick<\n Config,\n | 'routesDirectory'\n | 'routeFilePrefix'\n | 'routeFileIgnorePrefix'\n | 'routeFileIgnorePattern'\n | 'disableLogging'\n | 'routeToken'\n | 'indexToken'\n >,\n root: string,\n): Promise<GetRouteNodesResult> {\n const { routeFilePrefix, routeFileIgnorePrefix, routeFileIgnorePattern } =\n config\n\n const logger = logging({ disabled: config.disableLogging })\n const routeFileIgnoreRegExp = new RegExp(routeFileIgnorePattern ?? '', 'g')\n\n const routeNodes: Array<RouteNode> = []\n const allPhysicalDirectories: Array<string> = []\n\n async function recurse(dir: string) {\n const fullDir = path.resolve(config.routesDirectory, dir)\n let dirList = await fsp.readdir(fullDir, { withFileTypes: true })\n\n dirList = dirList.filter((d) => {\n if (\n d.name.startsWith('.') ||\n (routeFileIgnorePrefix && d.name.startsWith(routeFileIgnorePrefix))\n ) {\n return false\n }\n\n if (routeFilePrefix) {\n if (routeFileIgnorePattern) {\n return (\n d.name.startsWith(routeFilePrefix) &&\n !d.name.match(routeFileIgnoreRegExp)\n )\n }\n\n return d.name.startsWith(routeFilePrefix)\n }\n\n if (routeFileIgnorePattern) {\n return !d.name.match(routeFileIgnoreRegExp)\n }\n\n return true\n })\n\n const virtualConfigFile = dirList.find((dirent) => {\n return dirent.isFile() && isVirtualConfigFile(dirent.name)\n })\n\n if (virtualConfigFile !== undefined) {\n const virtualRouteConfigExport = await loadConfigFile(\n path.resolve(fullDir, virtualConfigFile.name),\n )\n let virtualRouteSubtreeConfig: VirtualRouteSubtreeConfig\n if (typeof virtualRouteConfigExport.default === 'function') {\n virtualRouteSubtreeConfig = await virtualRouteConfigExport.default()\n } else {\n virtualRouteSubtreeConfig = virtualRouteConfigExport.default\n }\n const dummyRoot: VirtualRootRoute = {\n type: 'root',\n file: '',\n children: virtualRouteSubtreeConfig,\n }\n const { routeNodes: virtualRouteNodes, physicalDirectories } =\n await getRouteNodesVirtual(\n {\n ...config,\n routesDirectory: fullDir,\n virtualRouteConfig: dummyRoot,\n },\n root,\n )\n allPhysicalDirectories.push(...physicalDirectories)\n virtualRouteNodes.forEach((node) => {\n const filePath = replaceBackslash(path.join(dir, node.filePath))\n const routePath = `/${dir}${node.routePath}`\n\n node.variableName = routePathToVariable(\n `${dir}/${removeExt(node.filePath)}`,\n )\n node.routePath = routePath\n // Keep originalRoutePath aligned with routePath for escape detection\n if (node.originalRoutePath) {\n node.originalRoutePath = `/${dir}${node.originalRoutePath}`\n }\n node.filePath = filePath\n })\n\n routeNodes.push(...virtualRouteNodes)\n\n return\n }\n\n await Promise.all(\n dirList.map(async (dirent) => {\n const fullPath = replaceBackslash(path.join(fullDir, dirent.name))\n const relativePath = path.posix.join(dir, dirent.name)\n\n if (dirent.isDirectory()) {\n await recurse(relativePath)\n } else if (fullPath.match(/\\.(tsx|ts|jsx|js|vue)$/)) {\n const filePath = replaceBackslash(path.join(dir, dirent.name))\n const filePathNoExt = removeExt(filePath)\n const {\n routePath: initialRoutePath,\n originalRoutePath: initialOriginalRoutePath,\n } = determineInitialRoutePath(filePathNoExt)\n\n let routePath = initialRoutePath\n let originalRoutePath = initialOriginalRoutePath\n\n if (routeFilePrefix) {\n routePath = routePath.replaceAll(routeFilePrefix, '')\n originalRoutePath = originalRoutePath.replaceAll(\n routeFilePrefix,\n '',\n )\n }\n\n if (disallowedRouteGroupConfiguration.test(dirent.name)) {\n const errorMessage = `A route configuration for a route group was found at \\`${filePath}\\`. This is not supported. Did you mean to use a layout/pathless route instead?`\n logger.error(`ERROR: ${errorMessage}`)\n throw new Error(errorMessage)\n }\n\n const meta = getRouteMeta(routePath, originalRoutePath, config)\n const variableName = meta.variableName\n let routeType: FsRouteType = meta.fsRouteType\n\n if (routeType === 'lazy') {\n routePath = routePath.replace(/\\/lazy$/, '')\n originalRoutePath = originalRoutePath.replace(/\\/lazy$/, '')\n }\n\n // this check needs to happen after the lazy route has been cleaned up\n // since the routePath is used to determine if a route is pathless\n if (\n isValidPathlessLayoutRoute(\n routePath,\n originalRoutePath,\n routeType,\n config,\n )\n ) {\n routeType = 'pathless_layout'\n }\n\n // Only show deprecation warning for .tsx/.ts files, not .vue files\n // Vue files using .component.vue is the Vue-native way\n const isVueFile = filePath.endsWith('.vue')\n if (!isVueFile) {\n ;(\n [\n ['component', 'component'],\n ['errorComponent', 'errorComponent'],\n ['notFoundComponent', 'notFoundComponent'],\n ['pendingComponent', 'pendingComponent'],\n ['loader', 'loader'],\n ] satisfies Array<[FsRouteType, string]>\n ).forEach(([matcher, type]) => {\n if (routeType === matcher) {\n logger.warn(\n `WARNING: The \\`.${type}.tsx\\` suffix used for the ${filePath} file is deprecated. Use the new \\`.lazy.tsx\\` suffix instead.`,\n )\n }\n })\n }\n\n // Get the last segment of originalRoutePath to check for escaping\n const originalSegments = originalRoutePath.split('/').filter(Boolean)\n const lastOriginalSegmentForSuffix =\n originalSegments[originalSegments.length - 1] || ''\n\n // List of special suffixes that can be escaped\n const specialSuffixes = [\n 'component',\n 'errorComponent',\n 'notFoundComponent',\n 'pendingComponent',\n 'loader',\n config.routeToken,\n 'lazy',\n ]\n\n // Only strip the suffix if it wasn't escaped (not wrapped in brackets)\n const suffixToStrip = specialSuffixes.find((suffix) => {\n const endsWithSuffix = routePath.endsWith(`/${suffix}`)\n const isEscaped = lastOriginalSegmentForSuffix === `[${suffix}]`\n return endsWithSuffix && !isEscaped\n })\n\n if (suffixToStrip) {\n routePath = routePath.replace(new RegExp(`/${suffixToStrip}$`), '')\n originalRoutePath = originalRoutePath.replace(\n new RegExp(`/${suffixToStrip}$`),\n '',\n )\n }\n\n // Check if the index token should be treated specially or as a literal path\n // If it's escaped (wrapped in brackets in originalRoutePath), it should be literal\n const lastOriginalSegment =\n originalRoutePath.split('/').filter(Boolean).pop() || ''\n const isIndexEscaped =\n lastOriginalSegment === `[${config.indexToken}]`\n\n if (!isIndexEscaped) {\n if (routePath === config.indexToken) {\n routePath = '/'\n }\n\n if (originalRoutePath === config.indexToken) {\n originalRoutePath = '/'\n }\n\n // For layout routes, don't use '/' fallback - an empty path means\n // \"layout for the parent path\" which is important for physical() mounts\n // where route.tsx at root should have empty path, not '/'\n const isLayoutRoute = routeType === 'layout'\n\n routePath =\n routePath.replace(new RegExp(`/${config.indexToken}$`), '/') ||\n (isLayoutRoute ? '' : '/')\n\n originalRoutePath =\n originalRoutePath.replace(\n new RegExp(`/${config.indexToken}$`),\n '/',\n ) || (isLayoutRoute ? '' : '/')\n }\n\n routeNodes.push({\n filePath,\n fullPath,\n routePath,\n variableName,\n _fsRouteType: routeType,\n originalRoutePath,\n })\n }\n }),\n )\n\n return routeNodes\n }\n\n await recurse('./')\n\n // Find the root route node - prefer the actual route file over component/loader files\n const rootRouteNode =\n routeNodes.find(\n (d) =>\n d.routePath === `/${rootPathId}` &&\n ![\n 'component',\n 'errorComponent',\n 'notFoundComponent',\n 'pendingComponent',\n 'loader',\n 'lazy',\n ].includes(d._fsRouteType),\n ) ?? routeNodes.find((d) => d.routePath === `/${rootPathId}`)\n if (rootRouteNode) {\n rootRouteNode._fsRouteType = '__root'\n rootRouteNode.variableName = 'root'\n }\n\n return {\n rootRouteNode,\n routeNodes,\n physicalDirectories: allPhysicalDirectories,\n }\n}\n\n/**\n * Determines the metadata for a given route path based on the provided configuration.\n *\n * @param routePath - The determined initial routePath (with brackets removed).\n * @param originalRoutePath - The original route path (may contain brackets for escaped content).\n * @param config - The user configuration object.\n * @returns An object containing the type of the route and the variable name derived from the route path.\n */\nexport function getRouteMeta(\n routePath: string,\n originalRoutePath: string,\n config: Pick<Config, 'routeToken' | 'indexToken'>,\n): {\n // `__root` is can be more easily determined by filtering down to routePath === /${rootPathId}\n // `pathless` is needs to determined after `lazy` has been cleaned up from the routePath\n fsRouteType: Extract<\n FsRouteType,\n | 'static'\n | 'layout'\n | 'api'\n | 'lazy'\n | 'loader'\n | 'component'\n | 'pendingComponent'\n | 'errorComponent'\n | 'notFoundComponent'\n >\n variableName: string\n} {\n let fsRouteType: FsRouteType = 'static'\n\n // Get the last segment from the original path to check for escaping\n const originalSegments = originalRoutePath.split('/').filter(Boolean)\n const lastOriginalSegment =\n originalSegments[originalSegments.length - 1] || ''\n\n // Helper to check if a specific suffix is escaped\n const isSuffixEscaped = (suffix: string): boolean => {\n return lastOriginalSegment === `[${suffix}]`\n }\n\n if (\n routePath.endsWith(`/${config.routeToken}`) &&\n !isSuffixEscaped(config.routeToken)\n ) {\n // layout routes, i.e `/foo/route.tsx` or `/foo/_layout/route.tsx`\n fsRouteType = 'layout'\n } else if (routePath.endsWith('/lazy') && !isSuffixEscaped('lazy')) {\n // lazy routes, i.e. `/foo.lazy.tsx`\n fsRouteType = 'lazy'\n } else if (routePath.endsWith('/loader') && !isSuffixEscaped('loader')) {\n // loader routes, i.e. `/foo.loader.tsx`\n fsRouteType = 'loader'\n } else if (\n routePath.endsWith('/component') &&\n !isSuffixEscaped('component')\n ) {\n // component routes, i.e. `/foo.component.tsx`\n fsRouteType = 'component'\n } else if (\n routePath.endsWith('/pendingComponent') &&\n !isSuffixEscaped('pendingComponent')\n ) {\n // pending component routes, i.e. `/foo.pendingComponent.tsx`\n fsRouteType = 'pendingComponent'\n } else if (\n routePath.endsWith('/errorComponent') &&\n !isSuffixEscaped('errorComponent')\n ) {\n // error component routes, i.e. `/foo.errorComponent.tsx`\n fsRouteType = 'errorComponent'\n } else if (\n routePath.endsWith('/notFoundComponent') &&\n !isSuffixEscaped('notFoundComponent')\n ) {\n // not found component routes, i.e. `/foo.notFoundComponent.tsx`\n fsRouteType = 'notFoundComponent'\n }\n\n const variableName = routePathToVariable(routePath)\n\n return { fsRouteType, variableName }\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 originalRoutePath Original route path with brackets for escaped content\n * @param routeType The route type determined from file extension\n * @param config The `router-generator` configuration object\n * @returns Boolean indicating if the route is a pathless layout route\n */\nfunction isValidPathlessLayoutRoute(\n normalizedRoutePath: string,\n originalRoutePath: string,\n routeType: FsRouteType,\n config: Pick<Config, 'routeToken' | 'indexToken'>,\n): boolean {\n if (routeType === 'lazy') {\n return false\n }\n\n const segments = normalizedRoutePath.split('/').filter(Boolean)\n const originalSegments = originalRoutePath.split('/').filter(Boolean)\n\n if (segments.length === 0) {\n return false\n }\n\n const lastRouteSegment = segments[segments.length - 1]!\n const lastOriginalSegment =\n originalSegments[originalSegments.length - 1] || ''\n const secondToLastRouteSegment = segments[segments.length - 2]\n const secondToLastOriginalSegment =\n originalSegments[originalSegments.length - 2]\n\n // If segment === __root, then exit as false\n if (lastRouteSegment === rootPathId) {\n return false\n }\n\n // If segment === config.routeToken and secondToLastSegment is a string that starts with _, then exit as true\n // Since the route is actually a configuration route for a layout/pathless route\n // i.e. /foo/_layout/route.tsx === /foo/_layout.tsx\n // But if the underscore is escaped, it's not a pathless layout\n if (\n lastRouteSegment === config.routeToken &&\n typeof secondToLastRouteSegment === 'string' &&\n typeof secondToLastOriginalSegment === 'string'\n ) {\n // Check if the underscore is escaped\n if (hasEscapedLeadingUnderscore(secondToLastOriginalSegment)) {\n return false\n }\n return secondToLastRouteSegment.startsWith('_')\n }\n\n // Segment starts with _ but check if it's escaped\n // If the original segment has [_] at the start, the underscore is escaped and it's not a pathless layout\n if (hasEscapedLeadingUnderscore(lastOriginalSegment)) {\n return false\n }\n\n return (\n lastRouteSegment !== config.indexToken &&\n lastRouteSegment !== config.routeToken &&\n lastRouteSegment.startsWith('_')\n )\n}\n"],"names":["getRouteNodesVirtual"],"mappings":";;;;;;;AAoBA,MAAM,oCAAoC;AAE1C,MAAM,0BAA0B;AACzB,SAAS,oBAAoB,UAA2B;AAC7D,SAAO,wBAAwB,KAAK,QAAQ;AAC9C;AAEA,eAAsB,cACpB,QAUA,MAC8B;AAC9B,QAAM,EAAE,iBAAiB,uBAAuB,uBAAA,IAC9C;AAEF,QAAM,SAAS,QAAQ,EAAE,UAAU,OAAO,gBAAgB;AAC1D,QAAM,wBAAwB,IAAI,OAAO,0BAA0B,IAAI,GAAG;AAE1E,QAAM,aAA+B,CAAA;AACrC,QAAM,yBAAwC,CAAA;AAE9C,iBAAe,QAAQ,KAAa;AAClC,UA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AM,2BAA2B,SAAS,SAAS,SAAS,CAAC;AAC7D,QAAM,8BACJ,iBAAiB,iBAAiB,SAAS,CAAC;AAG9C,MAAI,qBAAqB,YAAY;AACnC,WAAO;AAAA,EACT;AAMA,MACE,qBAAqB,OAAO,cAC5B,OAAO,6BAA6B,YACpC,OAAO,gCAAgC,UACvC;AAEA,QAAI,4BAA4B,2BAA2B,GAAG;AAC5D,aAAO;AAAA,IACT;AACA,WAAO,yBAAyB,WAAW,GAAG;AAAA,EAChD;AAIA,MAAI,4BAA4B,mBAAmB,GAAG;AACpD,WAAO;AAAA,EACT;AAEA,SACE,qBAAqB,OAAO,cAC5B,qBAAqB,OAAO,cAC5B,iBAAiB,WAAW,GAAG;AAEnC;"}
1
+ {"version":3,"file":"getRouteNodes.js","sources":["../../../../src/filesystem/physical/getRouteNodes.ts"],"sourcesContent":["import path from 'node:path'\nimport * as fsp from 'node:fs/promises'\nimport {\n determineInitialRoutePath,\n hasEscapedLeadingUnderscore,\n removeExt,\n replaceBackslash,\n routePathToVariable,\n unwrapBracketWrappedSegment,\n} from '../../utils'\nimport { getRouteNodes as getRouteNodesVirtual } from '../virtual/getRouteNodes'\nimport { loadConfigFile } from '../virtual/loadConfigFile'\nimport { logging } from '../../logger'\nimport { rootPathId } from './rootPathId'\nimport type {\n VirtualRootRoute,\n VirtualRouteSubtreeConfig,\n} from '@tanstack/virtual-file-routes'\nimport type { FsRouteType, GetRouteNodesResult, RouteNode } from '../../types'\nimport type { Config } from '../../config'\n\n/**\n * Pre-compiled segment regexes for matching token patterns against route segments.\n * These are created once (in Generator constructor) and passed through to avoid\n * repeated regex compilation during route crawling.\n */\nexport interface TokenRegexBundle {\n indexTokenSegmentRegex: RegExp\n routeTokenSegmentRegex: RegExp\n}\n\nconst disallowedRouteGroupConfiguration = /\\(([^)]+)\\).(ts|js|tsx|jsx|vue)/\n\nconst virtualConfigFileRegExp = /__virtual\\.[mc]?[jt]s$/\nexport function isVirtualConfigFile(fileName: string): boolean {\n return virtualConfigFileRegExp.test(fileName)\n}\n\nexport async function getRouteNodes(\n config: Pick<\n Config,\n | 'routesDirectory'\n | 'routeFilePrefix'\n | 'routeFileIgnorePrefix'\n | 'routeFileIgnorePattern'\n | 'disableLogging'\n | 'routeToken'\n | 'indexToken'\n >,\n root: string,\n tokenRegexes: TokenRegexBundle,\n): Promise<GetRouteNodesResult> {\n const { routeFilePrefix, routeFileIgnorePrefix, routeFileIgnorePattern } =\n config\n\n const logger = logging({ disabled: config.disableLogging })\n const routeFileIgnoreRegExp = new RegExp(routeFileIgnorePattern ?? '', 'g')\n\n const routeNodes: Array<RouteNode> = []\n const allPhysicalDirectories: Array<string> = []\n\n async function recurse(dir: string) {\n const fullDir = path.resolve(config.routesDirectory, dir)\n let dirList = await fsp.readdir(fullDir, { withFileTypes: true })\n\n dirList = dirList.filter((d) => {\n if (\n d.name.startsWith('.') ||\n (routeFileIgnorePrefix && d.name.startsWith(routeFileIgnorePrefix))\n ) {\n return false\n }\n\n if (routeFilePrefix) {\n if (routeFileIgnorePattern) {\n return (\n d.name.startsWith(routeFilePrefix) &&\n !d.name.match(routeFileIgnoreRegExp)\n )\n }\n\n return d.name.startsWith(routeFilePrefix)\n }\n\n if (routeFileIgnorePattern) {\n return !d.name.match(routeFileIgnoreRegExp)\n }\n\n return true\n })\n\n const virtualConfigFile = dirList.find((dirent) => {\n return dirent.isFile() && isVirtualConfigFile(dirent.name)\n })\n\n if (virtualConfigFile !== undefined) {\n const virtualRouteConfigExport = await loadConfigFile(\n path.resolve(fullDir, virtualConfigFile.name),\n )\n let virtualRouteSubtreeConfig: VirtualRouteSubtreeConfig\n if (typeof virtualRouteConfigExport.default === 'function') {\n virtualRouteSubtreeConfig = await virtualRouteConfigExport.default()\n } else {\n virtualRouteSubtreeConfig = virtualRouteConfigExport.default\n }\n const dummyRoot: VirtualRootRoute = {\n type: 'root',\n file: '',\n children: virtualRouteSubtreeConfig,\n }\n const { routeNodes: virtualRouteNodes, physicalDirectories } =\n await getRouteNodesVirtual(\n {\n ...config,\n routesDirectory: fullDir,\n virtualRouteConfig: dummyRoot,\n },\n root,\n tokenRegexes,\n )\n allPhysicalDirectories.push(...physicalDirectories)\n virtualRouteNodes.forEach((node) => {\n const filePath = replaceBackslash(path.join(dir, node.filePath))\n const routePath = `/${dir}${node.routePath}`\n\n node.variableName = routePathToVariable(\n `${dir}/${removeExt(node.filePath)}`,\n )\n node.routePath = routePath\n // Keep originalRoutePath aligned with routePath for escape detection\n if (node.originalRoutePath) {\n node.originalRoutePath = `/${dir}${node.originalRoutePath}`\n }\n node.filePath = filePath\n })\n\n routeNodes.push(...virtualRouteNodes)\n\n return\n }\n\n await Promise.all(\n dirList.map(async (dirent) => {\n const fullPath = replaceBackslash(path.join(fullDir, dirent.name))\n const relativePath = path.posix.join(dir, dirent.name)\n\n if (dirent.isDirectory()) {\n await recurse(relativePath)\n } else if (fullPath.match(/\\.(tsx|ts|jsx|js|vue)$/)) {\n const filePath = replaceBackslash(path.join(dir, dirent.name))\n const filePathNoExt = removeExt(filePath)\n const {\n routePath: initialRoutePath,\n originalRoutePath: initialOriginalRoutePath,\n } = determineInitialRoutePath(filePathNoExt)\n\n let routePath = initialRoutePath\n let originalRoutePath = initialOriginalRoutePath\n\n if (routeFilePrefix) {\n routePath = routePath.replaceAll(routeFilePrefix, '')\n originalRoutePath = originalRoutePath.replaceAll(\n routeFilePrefix,\n '',\n )\n }\n\n if (disallowedRouteGroupConfiguration.test(dirent.name)) {\n const errorMessage = `A route configuration for a route group was found at \\`${filePath}\\`. This is not supported. Did you mean to use a layout/pathless route instead?`\n logger.error(`ERROR: ${errorMessage}`)\n throw new Error(errorMessage)\n }\n\n const meta = getRouteMeta(routePath, originalRoutePath, tokenRegexes)\n const variableName = meta.variableName\n let routeType: FsRouteType = meta.fsRouteType\n\n if (routeType === 'lazy') {\n routePath = routePath.replace(/\\/lazy$/, '')\n originalRoutePath = originalRoutePath.replace(/\\/lazy$/, '')\n }\n\n // this check needs to happen after the lazy route has been cleaned up\n // since the routePath is used to determine if a route is pathless\n if (\n isValidPathlessLayoutRoute(\n routePath,\n originalRoutePath,\n routeType,\n tokenRegexes,\n )\n ) {\n routeType = 'pathless_layout'\n }\n\n // Only show deprecation warning for .tsx/.ts files, not .vue files\n // Vue files using .component.vue is the Vue-native way\n const isVueFile = filePath.endsWith('.vue')\n if (!isVueFile) {\n ;(\n [\n ['component', 'component'],\n ['errorComponent', 'errorComponent'],\n ['notFoundComponent', 'notFoundComponent'],\n ['pendingComponent', 'pendingComponent'],\n ['loader', 'loader'],\n ] satisfies Array<[FsRouteType, string]>\n ).forEach(([matcher, type]) => {\n if (routeType === matcher) {\n logger.warn(\n `WARNING: The \\`.${type}.tsx\\` suffix used for the ${filePath} file is deprecated. Use the new \\`.lazy.tsx\\` suffix instead.`,\n )\n }\n })\n }\n\n // Get the last segment of originalRoutePath to check for escaping\n const originalSegments = originalRoutePath.split('/').filter(Boolean)\n const lastOriginalSegmentForSuffix =\n originalSegments[originalSegments.length - 1] || ''\n\n const { routeTokenSegmentRegex, indexTokenSegmentRegex } =\n tokenRegexes\n\n // List of special suffixes that can be escaped\n const specialSuffixes = [\n 'component',\n 'errorComponent',\n 'notFoundComponent',\n 'pendingComponent',\n 'loader',\n 'lazy',\n ]\n\n const routePathSegments = routePath.split('/').filter(Boolean)\n const lastRouteSegment =\n routePathSegments[routePathSegments.length - 1] || ''\n\n const suffixToStrip = specialSuffixes.find((suffix) => {\n const endsWithSuffix = routePath.endsWith(`/${suffix}`)\n // A suffix is escaped if wrapped in brackets in the original: [lazy] means literal \"lazy\"\n const isEscaped =\n lastOriginalSegmentForSuffix.startsWith('[') &&\n lastOriginalSegmentForSuffix.endsWith(']') &&\n unwrapBracketWrappedSegment(lastOriginalSegmentForSuffix) ===\n suffix\n return endsWithSuffix && !isEscaped\n })\n\n const routeTokenCandidate = unwrapBracketWrappedSegment(\n lastOriginalSegmentForSuffix,\n )\n const isRouteTokenEscaped =\n lastOriginalSegmentForSuffix !== routeTokenCandidate &&\n routeTokenSegmentRegex.test(routeTokenCandidate)\n\n const shouldStripRouteToken =\n routeTokenSegmentRegex.test(lastRouteSegment) &&\n !isRouteTokenEscaped\n\n if (suffixToStrip || shouldStripRouteToken) {\n const stripSegment = suffixToStrip ?? lastRouteSegment\n routePath = routePath.replace(new RegExp(`/${stripSegment}$`), '')\n originalRoutePath = originalRoutePath.replace(\n new RegExp(`/${stripSegment}$`),\n '',\n )\n }\n\n // Check if the index token should be treated specially or as a literal path\n // Escaping stays literal-only: if the last original segment is bracket-wrapped,\n // treat it as literal even if it matches the token regex.\n const lastOriginalSegment =\n originalRoutePath.split('/').filter(Boolean).pop() || ''\n\n const indexTokenCandidate =\n unwrapBracketWrappedSegment(lastOriginalSegment)\n const isIndexEscaped =\n lastOriginalSegment !== indexTokenCandidate &&\n indexTokenSegmentRegex.test(indexTokenCandidate)\n\n if (!isIndexEscaped) {\n const updatedRouteSegments = routePath.split('/').filter(Boolean)\n const updatedLastRouteSegment =\n updatedRouteSegments[updatedRouteSegments.length - 1] || ''\n\n if (indexTokenSegmentRegex.test(updatedLastRouteSegment)) {\n if (routePathSegments.length === 1) {\n routePath = '/'\n }\n\n if (lastOriginalSegment === updatedLastRouteSegment) {\n originalRoutePath = '/'\n }\n\n // For layout routes, don't use '/' fallback - an empty path means\n // \"layout for the parent path\" which is important for physical() mounts\n // where route.tsx at root should have empty path, not '/'\n const isLayoutRoute = routeType === 'layout'\n\n routePath =\n routePath.replace(\n new RegExp(`/${updatedLastRouteSegment}$`),\n '/',\n ) || (isLayoutRoute ? '' : '/')\n\n originalRoutePath =\n originalRoutePath.replace(\n new RegExp(`/${indexTokenCandidate}$`),\n '/',\n ) || (isLayoutRoute ? '' : '/')\n }\n }\n\n routeNodes.push({\n filePath,\n fullPath,\n routePath,\n variableName,\n _fsRouteType: routeType,\n originalRoutePath,\n })\n }\n }),\n )\n\n return routeNodes\n }\n\n await recurse('./')\n\n // Find the root route node - prefer the actual route file over component/loader files\n const rootRouteNode =\n routeNodes.find(\n (d) =>\n d.routePath === `/${rootPathId}` &&\n ![\n 'component',\n 'errorComponent',\n 'notFoundComponent',\n 'pendingComponent',\n 'loader',\n 'lazy',\n ].includes(d._fsRouteType),\n ) ?? routeNodes.find((d) => d.routePath === `/${rootPathId}`)\n if (rootRouteNode) {\n rootRouteNode._fsRouteType = '__root'\n rootRouteNode.variableName = 'root'\n }\n\n return {\n rootRouteNode,\n routeNodes,\n physicalDirectories: allPhysicalDirectories,\n }\n}\n\n/**\n * Determines the metadata for a given route path based on the provided configuration.\n *\n * @param routePath - The determined initial routePath (with brackets removed).\n * @param originalRoutePath - The original route path (may contain brackets for escaped content).\n * @param tokenRegexes - Pre-compiled token regexes for matching.\n * @returns An object containing the type of the route and the variable name derived from the route path.\n */\nexport function getRouteMeta(\n routePath: string,\n originalRoutePath: string,\n tokenRegexes: TokenRegexBundle,\n): {\n // `__root` is can be more easily determined by filtering down to routePath === /${rootPathId}\n // `pathless` is needs to determined after `lazy` has been cleaned up from the routePath\n fsRouteType: Extract<\n FsRouteType,\n | 'static'\n | 'layout'\n | 'api'\n | 'lazy'\n | 'loader'\n | 'component'\n | 'pendingComponent'\n | 'errorComponent'\n | 'notFoundComponent'\n >\n variableName: string\n} {\n let fsRouteType: FsRouteType = 'static'\n\n // Get the last segment from the original path to check for escaping\n const originalSegments = originalRoutePath.split('/').filter(Boolean)\n const lastOriginalSegment =\n originalSegments[originalSegments.length - 1] || ''\n\n const { routeTokenSegmentRegex } = tokenRegexes\n\n // Helper to check if a specific suffix is escaped (literal-only)\n // A suffix is escaped if the original segment is wrapped in brackets: [lazy] means literal \"lazy\"\n const isSuffixEscaped = (suffix: string): boolean => {\n return (\n lastOriginalSegment.startsWith('[') &&\n lastOriginalSegment.endsWith(']') &&\n unwrapBracketWrappedSegment(lastOriginalSegment) === suffix\n )\n }\n\n const routeSegments = routePath.split('/').filter(Boolean)\n const lastRouteSegment = routeSegments[routeSegments.length - 1] || ''\n\n const routeTokenCandidate = unwrapBracketWrappedSegment(lastOriginalSegment)\n const isRouteTokenEscaped =\n lastOriginalSegment !== routeTokenCandidate &&\n routeTokenSegmentRegex.test(routeTokenCandidate)\n\n if (routeTokenSegmentRegex.test(lastRouteSegment) && !isRouteTokenEscaped) {\n // layout routes, i.e `/foo/route.tsx` or `/foo/_layout/route.tsx`\n fsRouteType = 'layout'\n } else if (routePath.endsWith('/lazy') && !isSuffixEscaped('lazy')) {\n // lazy routes, i.e. `/foo.lazy.tsx`\n fsRouteType = 'lazy'\n } else if (routePath.endsWith('/loader') && !isSuffixEscaped('loader')) {\n // loader routes, i.e. `/foo.loader.tsx`\n fsRouteType = 'loader'\n } else if (\n routePath.endsWith('/component') &&\n !isSuffixEscaped('component')\n ) {\n // component routes, i.e. `/foo.component.tsx`\n fsRouteType = 'component'\n } else if (\n routePath.endsWith('/pendingComponent') &&\n !isSuffixEscaped('pendingComponent')\n ) {\n // pending component routes, i.e. `/foo.pendingComponent.tsx`\n fsRouteType = 'pendingComponent'\n } else if (\n routePath.endsWith('/errorComponent') &&\n !isSuffixEscaped('errorComponent')\n ) {\n // error component routes, i.e. `/foo.errorComponent.tsx`\n fsRouteType = 'errorComponent'\n } else if (\n routePath.endsWith('/notFoundComponent') &&\n !isSuffixEscaped('notFoundComponent')\n ) {\n // not found component routes, i.e. `/foo.notFoundComponent.tsx`\n fsRouteType = 'notFoundComponent'\n }\n\n const variableName = routePathToVariable(routePath)\n\n return { fsRouteType, variableName }\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 originalRoutePath Original route path with brackets for escaped content\n * @param routeType The route type determined from file extension\n * @param tokenRegexes Pre-compiled token regexes for matching\n * @returns Boolean indicating if the route is a pathless layout route\n */\nfunction isValidPathlessLayoutRoute(\n normalizedRoutePath: string,\n originalRoutePath: string,\n routeType: FsRouteType,\n tokenRegexes: TokenRegexBundle,\n): boolean {\n if (routeType === 'lazy') {\n return false\n }\n\n const segments = normalizedRoutePath.split('/').filter(Boolean)\n const originalSegments = originalRoutePath.split('/').filter(Boolean)\n\n if (segments.length === 0) {\n return false\n }\n\n const lastRouteSegment = segments[segments.length - 1]!\n const lastOriginalSegment =\n originalSegments[originalSegments.length - 1] || ''\n const secondToLastRouteSegment = segments[segments.length - 2]\n const secondToLastOriginalSegment =\n originalSegments[originalSegments.length - 2]\n\n // If segment === __root, then exit as false\n if (lastRouteSegment === rootPathId) {\n return false\n }\n\n const { routeTokenSegmentRegex, indexTokenSegmentRegex } = tokenRegexes\n\n // If segment matches routeToken and secondToLastSegment is a string that starts with _, then exit as true\n // Since the route is actually a configuration route for a layout/pathless route\n // i.e. /foo/_layout/route.tsx === /foo/_layout.tsx\n // But if the underscore is escaped, it's not a pathless layout\n if (\n routeTokenSegmentRegex.test(lastRouteSegment) &&\n typeof secondToLastRouteSegment === 'string' &&\n typeof secondToLastOriginalSegment === 'string'\n ) {\n // Check if the underscore is escaped\n if (hasEscapedLeadingUnderscore(secondToLastOriginalSegment)) {\n return false\n }\n return secondToLastRouteSegment.startsWith('_')\n }\n\n // Segment starts with _ but check if it's escaped\n // If the original segment has [_] at the start, the underscore is escaped and it's not a pathless layout\n if (hasEscapedLeadingUnderscore(lastOriginalSegment)) {\n return false\n }\n\n return (\n !indexTokenSegmentRegex.test(lastRouteSegment) &&\n !routeTokenSegmentRegex.test(lastRouteSegment) &&\n lastRouteSegment.startsWith('_')\n )\n}\n"],"names":["getRouteNodesVirtual"],"mappings":";;;;;;;AA+BA,MAAM,oCAAoC;AAE1C,MAAM,0BAA0B;AACzB,SAAS,oBAAoB,UAA2B;AAC7D,SAAO,wBAAwB,KAAK,QAAQ;AAC9C;AAEA,eAAsB,cACpB,QAUA,MACA,cAC8B;AAC9B,QAAM,EAAE,iBAAiB,uBAAuB,uBAAA,IAC9C;AAEF,QAAM,SAAS,QAAQ,EAAE,UAAU,OAAO,gBAAgB;AA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AK,gBAAgB,KAC5C,OAAO,6BAA6B,YACpC,OAAO,gCAAgC,UACvC;AAEA,QAAI,4BAA4B,2BAA2B,GAAG;AAC5D,aAAO;AAAA,IACT;AACA,WAAO,yBAAyB,WAAW,GAAG;AAAA,EAChD;AAIA,MAAI,4BAA4B,mBAAmB,GAAG;AACpD,WAAO;AAAA,EACT;AAEA,SACE,CAAC,uBAAuB,KAAK,gBAAgB,KAC7C,CAAC,uBAAuB,KAAK,gBAAgB,KAC7C,iBAAiB,WAAW,GAAG;AAEnC;"}
@@ -1,8 +1,9 @@
1
1
  import { VirtualRouteNode } from '@tanstack/virtual-file-routes';
2
2
  import { GetRouteNodesResult, RouteNode } from '../../types.js';
3
3
  import { Config } from '../../config.js';
4
- export declare function getRouteNodes(tsrConfig: Pick<Config, 'routesDirectory' | 'virtualRouteConfig' | 'routeFileIgnorePrefix' | 'disableLogging' | 'indexToken' | 'routeToken'>, root: string): Promise<GetRouteNodesResult>;
5
- export declare function getRouteNodesRecursive(tsrConfig: Pick<Config, 'routesDirectory' | 'routeFileIgnorePrefix' | 'disableLogging' | 'indexToken' | 'routeToken'>, root: string, fullDir: string, nodes?: Array<VirtualRouteNode>, parent?: RouteNode): Promise<{
4
+ import { TokenRegexBundle } from '../physical/getRouteNodes.js';
5
+ export declare function getRouteNodes(tsrConfig: Pick<Config, 'routesDirectory' | 'virtualRouteConfig' | 'routeFileIgnorePrefix' | 'disableLogging' | 'indexToken' | 'routeToken'>, root: string, tokenRegexes: TokenRegexBundle): Promise<GetRouteNodesResult>;
6
+ export declare function getRouteNodesRecursive(tsrConfig: Pick<Config, 'routesDirectory' | 'routeFileIgnorePrefix' | 'disableLogging' | 'indexToken' | 'routeToken'>, root: string, fullDir: string, nodes: Array<VirtualRouteNode> | undefined, tokenRegexes: TokenRegexBundle, parent?: RouteNode): Promise<{
6
7
  children: Array<RouteNode>;
7
8
  physicalDirectories: Array<string>;
8
9
  }>;
@@ -20,7 +20,7 @@ function flattenTree(node) {
20
20
  delete node.children;
21
21
  return result;
22
22
  }
23
- async function getRouteNodes(tsrConfig, root) {
23
+ async function getRouteNodes(tsrConfig, root, tokenRegexes) {
24
24
  const fullDir = resolve(tsrConfig.routesDirectory);
25
25
  if (tsrConfig.virtualRouteConfig === void 0) {
26
26
  throw new Error(`virtualRouteConfig is undefined`);
@@ -38,7 +38,8 @@ async function getRouteNodes(tsrConfig, root) {
38
38
  tsrConfig,
39
39
  root,
40
40
  fullDir,
41
- virtualRouteConfig.children
41
+ virtualRouteConfig.children,
42
+ tokenRegexes
42
43
  );
43
44
  const allNodes = flattenTree({
44
45
  children,
@@ -65,7 +66,7 @@ async function getVirtualRouteConfigFromFileExport(tsrConfig, root) {
65
66
  const virtualRouteConfig = "routes" in exports ? exports.routes : exports.default;
66
67
  return virtualRootRouteSchema.parse(virtualRouteConfig);
67
68
  }
68
- async function getRouteNodesRecursive(tsrConfig, root, fullDir, nodes, parent) {
69
+ async function getRouteNodesRecursive(tsrConfig, root, fullDir, nodes, tokenRegexes, parent) {
69
70
  if (nodes === void 0) {
70
71
  return { children: [], physicalDirectories: [] };
71
72
  }
@@ -78,9 +79,13 @@ async function getRouteNodesRecursive(tsrConfig, root, fullDir, nodes, parent) {
78
79
  ...tsrConfig,
79
80
  routesDirectory: resolve(fullDir, node.directory)
80
81
  },
81
- root
82
+ root,
83
+ tokenRegexes
84
+ );
85
+ allPhysicalDirectories.push(
86
+ resolve(fullDir, node.directory),
87
+ ...physicalDirectories
82
88
  );
83
- allPhysicalDirectories.push(node.directory);
84
89
  routeNodes.forEach((subtreeNode) => {
85
90
  subtreeNode.variableName = routePathToVariable(
86
91
  `${node.pathPrefix}/${removeExt(subtreeNode.filePath)}`
@@ -148,6 +153,7 @@ async function getRouteNodesRecursive(tsrConfig, root, fullDir, nodes, parent) {
148
153
  root,
149
154
  fullDir,
150
155
  node.children,
156
+ tokenRegexes,
151
157
  routeNode
152
158
  );
153
159
  routeNode.children = children2;
@@ -186,6 +192,7 @@ async function getRouteNodesRecursive(tsrConfig, root, fullDir, nodes, parent) {
186
192
  root,
187
193
  fullDir,
188
194
  node.children,
195
+ tokenRegexes,
189
196
  routeNode
190
197
  );
191
198
  routeNode.children = children2;
@@ -1 +1 @@
1
- {"version":3,"file":"getRouteNodes.js","sources":["../../../../src/filesystem/virtual/getRouteNodes.ts"],"sourcesContent":["import path, { join, resolve } from 'node:path'\nimport {\n determineInitialRoutePath,\n removeExt,\n removeLeadingSlash,\n removeTrailingSlash,\n replaceBackslash,\n routePathToVariable,\n} from '../../utils'\nimport { getRouteNodes as getRouteNodesPhysical } from '../physical/getRouteNodes'\nimport { rootPathId } from '../physical/rootPathId'\nimport { virtualRootRouteSchema } from './config'\nimport { loadConfigFile } from './loadConfigFile'\nimport type {\n VirtualRootRoute,\n VirtualRouteNode,\n} from '@tanstack/virtual-file-routes'\nimport type { GetRouteNodesResult, RouteNode } from '../../types'\nimport type { Config } from '../../config'\n\nfunction ensureLeadingUnderScore(id: string) {\n if (id.startsWith('_')) {\n return id\n }\n return `_${id}`\n}\n\nfunction flattenTree(node: RouteNode): Array<RouteNode> {\n const result = [node]\n\n if (node.children) {\n for (const child of node.children) {\n result.push(...flattenTree(child))\n }\n }\n delete node.children\n\n return result\n}\n\nexport async function getRouteNodes(\n tsrConfig: Pick<\n Config,\n | 'routesDirectory'\n | 'virtualRouteConfig'\n | 'routeFileIgnorePrefix'\n | 'disableLogging'\n | 'indexToken'\n | 'routeToken'\n >,\n root: string,\n): Promise<GetRouteNodesResult> {\n const fullDir = resolve(tsrConfig.routesDirectory)\n if (tsrConfig.virtualRouteConfig === undefined) {\n throw new Error(`virtualRouteConfig is undefined`)\n }\n let virtualRouteConfig: VirtualRootRoute\n if (typeof tsrConfig.virtualRouteConfig === 'string') {\n virtualRouteConfig = await getVirtualRouteConfigFromFileExport(\n tsrConfig,\n root,\n )\n } else {\n virtualRouteConfig = tsrConfig.virtualRouteConfig\n }\n const { children, physicalDirectories } = await getRouteNodesRecursive(\n tsrConfig,\n root,\n fullDir,\n virtualRouteConfig.children,\n )\n const allNodes = flattenTree({\n children,\n filePath: virtualRouteConfig.file,\n fullPath: replaceBackslash(join(fullDir, virtualRouteConfig.file)),\n variableName: 'root',\n routePath: `/${rootPathId}`,\n _fsRouteType: '__root',\n })\n\n const rootRouteNode = allNodes[0]\n const routeNodes = allNodes.slice(1)\n\n return { rootRouteNode, routeNodes, physicalDirectories }\n}\n\n/**\n * Get the virtual route config from a file export\n *\n * @example\n * ```ts\n * // routes.ts\n * import { rootRoute } from '@tanstack/virtual-file-routes'\n *\n * export const routes = rootRoute({ ... })\n * // or\n * export default rootRoute({ ... })\n * ```\n *\n */\nasync function getVirtualRouteConfigFromFileExport(\n tsrConfig: Pick<Config, 'virtualRouteConfig'>,\n root: string,\n): Promise<VirtualRootRoute> {\n if (\n tsrConfig.virtualRouteConfig === undefined ||\n typeof tsrConfig.virtualRouteConfig !== 'string' ||\n tsrConfig.virtualRouteConfig === ''\n ) {\n throw new Error(`virtualRouteConfig is undefined or empty`)\n }\n const exports = await loadConfigFile(join(root, tsrConfig.virtualRouteConfig))\n\n if (!('routes' in exports) && !('default' in exports)) {\n throw new Error(\n `routes not found in ${tsrConfig.virtualRouteConfig}. The routes export must be named like 'export const routes = ...' or done using 'export default ...'`,\n )\n }\n\n const virtualRouteConfig =\n 'routes' in exports ? exports.routes : exports.default\n\n return virtualRootRouteSchema.parse(virtualRouteConfig)\n}\n\nexport async function getRouteNodesRecursive(\n tsrConfig: Pick<\n Config,\n | 'routesDirectory'\n | 'routeFileIgnorePrefix'\n | 'disableLogging'\n | 'indexToken'\n | 'routeToken'\n >,\n root: string,\n fullDir: string,\n nodes?: Array<VirtualRouteNode>,\n parent?: RouteNode,\n): Promise<{ children: Array<RouteNode>; physicalDirectories: Array<string> }> {\n if (nodes === undefined) {\n return { children: [], physicalDirectories: [] }\n }\n const allPhysicalDirectories: Array<string> = []\n const children = await Promise.all(\n nodes.map(async (node) => {\n if (node.type === 'physical') {\n const { routeNodes, physicalDirectories } = await getRouteNodesPhysical(\n {\n ...tsrConfig,\n routesDirectory: resolve(fullDir, node.directory),\n },\n root,\n )\n allPhysicalDirectories.push(node.directory)\n routeNodes.forEach((subtreeNode) => {\n subtreeNode.variableName = routePathToVariable(\n `${node.pathPrefix}/${removeExt(subtreeNode.filePath)}`,\n )\n subtreeNode.routePath = `${parent?.routePath ?? ''}${node.pathPrefix}${subtreeNode.routePath}`\n // Keep originalRoutePath aligned with routePath for escape detection\n if (subtreeNode.originalRoutePath) {\n subtreeNode.originalRoutePath = `${parent?.routePath ?? ''}${node.pathPrefix}${subtreeNode.originalRoutePath}`\n }\n subtreeNode.filePath = `${node.directory}/${subtreeNode.filePath}`\n })\n return routeNodes\n }\n\n function getFile(file: string) {\n const filePath = file\n const variableName = routePathToVariable(removeExt(filePath))\n const fullPath = replaceBackslash(join(fullDir, filePath))\n return { filePath, variableName, fullPath }\n }\n const parentRoutePath = removeTrailingSlash(parent?.routePath ?? '/')\n\n switch (node.type) {\n case 'index': {\n const { filePath, variableName, fullPath } = getFile(node.file)\n const routePath = `${parentRoutePath}/`\n return {\n filePath,\n fullPath,\n variableName,\n routePath,\n _fsRouteType: 'static',\n } satisfies RouteNode\n }\n\n case 'route': {\n const lastSegment = node.path\n let routeNode: RouteNode\n\n // Process the segment to handle escape sequences like [_]\n const {\n routePath: escapedSegment,\n originalRoutePath: originalSegment,\n } = determineInitialRoutePath(removeLeadingSlash(lastSegment))\n const routePath = `${parentRoutePath}${escapedSegment}`\n // Store the original path with brackets for escape detection\n const originalRoutePath = `${parentRoutePath}${originalSegment}`\n\n if (node.file) {\n const { filePath, variableName, fullPath } = getFile(node.file)\n routeNode = {\n filePath,\n fullPath,\n variableName,\n routePath,\n originalRoutePath,\n _fsRouteType: 'static',\n }\n } else {\n routeNode = {\n filePath: '',\n fullPath: '',\n variableName: routePathToVariable(routePath),\n routePath,\n originalRoutePath,\n isVirtual: true,\n _fsRouteType: 'static',\n }\n }\n\n if (node.children !== undefined) {\n const { children, physicalDirectories } =\n await getRouteNodesRecursive(\n tsrConfig,\n root,\n fullDir,\n node.children,\n routeNode,\n )\n routeNode.children = children\n allPhysicalDirectories.push(...physicalDirectories)\n\n // If the route has children, it should be a layout\n routeNode._fsRouteType = 'layout'\n }\n return routeNode\n }\n case 'layout': {\n const { filePath, variableName, fullPath } = getFile(node.file)\n\n if (node.id !== undefined) {\n node.id = ensureLeadingUnderScore(node.id)\n } else {\n const baseName = path.basename(filePath)\n const fileNameWithoutExt = path.parse(baseName).name\n node.id = ensureLeadingUnderScore(fileNameWithoutExt)\n }\n const lastSegment = node.id\n // Process the segment to handle escape sequences like [_]\n const {\n routePath: escapedSegment,\n originalRoutePath: originalSegment,\n } = determineInitialRoutePath(removeLeadingSlash(lastSegment))\n const routePath = `${parentRoutePath}${escapedSegment}`\n // Store the original path with brackets for escape detection\n const originalRoutePath = `${parentRoutePath}${originalSegment}`\n\n const routeNode: RouteNode = {\n fullPath,\n filePath,\n variableName,\n routePath,\n originalRoutePath,\n _fsRouteType: 'pathless_layout',\n }\n\n if (node.children !== undefined) {\n const { children, physicalDirectories } =\n await getRouteNodesRecursive(\n tsrConfig,\n root,\n fullDir,\n node.children,\n routeNode,\n )\n routeNode.children = children\n allPhysicalDirectories.push(...physicalDirectories)\n }\n return routeNode\n }\n }\n }),\n )\n return {\n children: children.flat(),\n physicalDirectories: allPhysicalDirectories,\n }\n}\n"],"names":["getRouteNodesPhysical","children"],"mappings":";;;;;;AAoBA,SAAS,wBAAwB,IAAY;AAC3C,MAAI,GAAG,WAAW,GAAG,GAAG;AACtB,WAAO;AAAA,EACT;AACA,SAAO,IAAI,EAAE;AACf;AAEA,SAAS,YAAY,MAAmC;AACtD,QAAM,SAAS,CAAC,IAAI;AAEpB,MAAI,KAAK,UAAU;AACjB,eAAW,SAAS,KAAK,UAAU;AACjC,aAAO,KAAK,GAAG,YAAY,KAAK,CAAC;AAAA,IACnC;AAAA,EACF;AACA,SAAO,KAAK;AAEZ,SAA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AAA,UACtD;AACA,gBAAM,cAAc,KAAK;AAEzB,gBAAM;AAAA,YACJ,WAAW;AAAA,YACX,mBAAmB;AAAA,UAAA,IACjB,0BAA0B,mBAAmB,WAAW,CAAC;AAC7D,gBAAM,YAAY,GAAG,eAAe,GAAG,cAAc;AAErD,gBAAM,oBAAoB,GAAG,eAAe,GAAG,eAAe;AAE9D,gBAAM,YAAuB;AAAA,YAC3B;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA,cAAc;AAAA,UAAA;AAGhB,cAAI,KAAK,aAAa,QAAW;AAC/B,kBAAM,EAAE,UAAAA,WAAU,oBAAA,IAChB,MAAM;AAAA,cACJ;AAAA,cACA;AAAA,cACA;AAAA,cACA,KAAK;AAAA,cACL;AAAA,YAAA;AAEJ,sBAAU,WAAWA;AACrB,mCAAuB,KAAK,GAAG,mBAAmB;AAAA,UACpD;AACA,iBAAO;AAAA,QACT;AAAA,MAAA;AAAA,IAEJ,CAAC;AAAA,EAAA;AAEH,SAAO;AAAA,IACL,UAAU,SAAS,KAAA;AAAA,IACnB,qBAAqB;AAAA,EAAA;AAEzB;"}
1
+ {"version":3,"file":"getRouteNodes.js","sources":["../../../../src/filesystem/virtual/getRouteNodes.ts"],"sourcesContent":["import path, { join, resolve } from 'node:path'\nimport {\n determineInitialRoutePath,\n removeExt,\n removeLeadingSlash,\n removeTrailingSlash,\n replaceBackslash,\n routePathToVariable,\n} from '../../utils'\nimport { getRouteNodes as getRouteNodesPhysical } from '../physical/getRouteNodes'\nimport { rootPathId } from '../physical/rootPathId'\nimport { virtualRootRouteSchema } from './config'\nimport { loadConfigFile } from './loadConfigFile'\nimport type {\n VirtualRootRoute,\n VirtualRouteNode,\n} from '@tanstack/virtual-file-routes'\nimport type { GetRouteNodesResult, RouteNode } from '../../types'\nimport type { Config } from '../../config'\nimport type { TokenRegexBundle } from '../physical/getRouteNodes'\n\nfunction ensureLeadingUnderScore(id: string) {\n if (id.startsWith('_')) {\n return id\n }\n return `_${id}`\n}\n\nfunction flattenTree(node: RouteNode): Array<RouteNode> {\n const result = [node]\n\n if (node.children) {\n for (const child of node.children) {\n result.push(...flattenTree(child))\n }\n }\n delete node.children\n\n return result\n}\n\nexport async function getRouteNodes(\n tsrConfig: Pick<\n Config,\n | 'routesDirectory'\n | 'virtualRouteConfig'\n | 'routeFileIgnorePrefix'\n | 'disableLogging'\n | 'indexToken'\n | 'routeToken'\n >,\n root: string,\n tokenRegexes: TokenRegexBundle,\n): Promise<GetRouteNodesResult> {\n const fullDir = resolve(tsrConfig.routesDirectory)\n if (tsrConfig.virtualRouteConfig === undefined) {\n throw new Error(`virtualRouteConfig is undefined`)\n }\n let virtualRouteConfig: VirtualRootRoute\n if (typeof tsrConfig.virtualRouteConfig === 'string') {\n virtualRouteConfig = await getVirtualRouteConfigFromFileExport(\n tsrConfig,\n root,\n )\n } else {\n virtualRouteConfig = tsrConfig.virtualRouteConfig\n }\n const { children, physicalDirectories } = await getRouteNodesRecursive(\n tsrConfig,\n root,\n fullDir,\n virtualRouteConfig.children,\n tokenRegexes,\n )\n const allNodes = flattenTree({\n children,\n filePath: virtualRouteConfig.file,\n fullPath: replaceBackslash(join(fullDir, virtualRouteConfig.file)),\n variableName: 'root',\n routePath: `/${rootPathId}`,\n _fsRouteType: '__root',\n })\n\n const rootRouteNode = allNodes[0]\n const routeNodes = allNodes.slice(1)\n\n return { rootRouteNode, routeNodes, physicalDirectories }\n}\n\n/**\n * Get the virtual route config from a file export\n *\n * @example\n * ```ts\n * // routes.ts\n * import { rootRoute } from '@tanstack/virtual-file-routes'\n *\n * export const routes = rootRoute({ ... })\n * // or\n * export default rootRoute({ ... })\n * ```\n *\n */\nasync function getVirtualRouteConfigFromFileExport(\n tsrConfig: Pick<Config, 'virtualRouteConfig'>,\n root: string,\n): Promise<VirtualRootRoute> {\n if (\n tsrConfig.virtualRouteConfig === undefined ||\n typeof tsrConfig.virtualRouteConfig !== 'string' ||\n tsrConfig.virtualRouteConfig === ''\n ) {\n throw new Error(`virtualRouteConfig is undefined or empty`)\n }\n const exports = await loadConfigFile(join(root, tsrConfig.virtualRouteConfig))\n\n if (!('routes' in exports) && !('default' in exports)) {\n throw new Error(\n `routes not found in ${tsrConfig.virtualRouteConfig}. The routes export must be named like 'export const routes = ...' or done using 'export default ...'`,\n )\n }\n\n const virtualRouteConfig =\n 'routes' in exports ? exports.routes : exports.default\n\n return virtualRootRouteSchema.parse(virtualRouteConfig)\n}\n\nexport async function getRouteNodesRecursive(\n tsrConfig: Pick<\n Config,\n | 'routesDirectory'\n | 'routeFileIgnorePrefix'\n | 'disableLogging'\n | 'indexToken'\n | 'routeToken'\n >,\n root: string,\n fullDir: string,\n nodes: Array<VirtualRouteNode> | undefined,\n tokenRegexes: TokenRegexBundle,\n parent?: RouteNode,\n): Promise<{ children: Array<RouteNode>; physicalDirectories: Array<string> }> {\n if (nodes === undefined) {\n return { children: [], physicalDirectories: [] }\n }\n const allPhysicalDirectories: Array<string> = []\n const children = await Promise.all(\n nodes.map(async (node) => {\n if (node.type === 'physical') {\n const { routeNodes, physicalDirectories } = await getRouteNodesPhysical(\n {\n ...tsrConfig,\n routesDirectory: resolve(fullDir, node.directory),\n },\n root,\n tokenRegexes,\n )\n allPhysicalDirectories.push(\n resolve(fullDir, node.directory),\n ...physicalDirectories,\n )\n routeNodes.forEach((subtreeNode) => {\n subtreeNode.variableName = routePathToVariable(\n `${node.pathPrefix}/${removeExt(subtreeNode.filePath)}`,\n )\n subtreeNode.routePath = `${parent?.routePath ?? ''}${node.pathPrefix}${subtreeNode.routePath}`\n // Keep originalRoutePath aligned with routePath for escape detection\n if (subtreeNode.originalRoutePath) {\n subtreeNode.originalRoutePath = `${parent?.routePath ?? ''}${node.pathPrefix}${subtreeNode.originalRoutePath}`\n }\n subtreeNode.filePath = `${node.directory}/${subtreeNode.filePath}`\n })\n return routeNodes\n }\n\n function getFile(file: string) {\n const filePath = file\n const variableName = routePathToVariable(removeExt(filePath))\n const fullPath = replaceBackslash(join(fullDir, filePath))\n return { filePath, variableName, fullPath }\n }\n const parentRoutePath = removeTrailingSlash(parent?.routePath ?? '/')\n\n switch (node.type) {\n case 'index': {\n const { filePath, variableName, fullPath } = getFile(node.file)\n const routePath = `${parentRoutePath}/`\n return {\n filePath,\n fullPath,\n variableName,\n routePath,\n _fsRouteType: 'static',\n } satisfies RouteNode\n }\n\n case 'route': {\n const lastSegment = node.path\n let routeNode: RouteNode\n\n // Process the segment to handle escape sequences like [_]\n const {\n routePath: escapedSegment,\n originalRoutePath: originalSegment,\n } = determineInitialRoutePath(removeLeadingSlash(lastSegment))\n const routePath = `${parentRoutePath}${escapedSegment}`\n // Store the original path with brackets for escape detection\n const originalRoutePath = `${parentRoutePath}${originalSegment}`\n\n if (node.file) {\n const { filePath, variableName, fullPath } = getFile(node.file)\n routeNode = {\n filePath,\n fullPath,\n variableName,\n routePath,\n originalRoutePath,\n _fsRouteType: 'static',\n }\n } else {\n routeNode = {\n filePath: '',\n fullPath: '',\n variableName: routePathToVariable(routePath),\n routePath,\n originalRoutePath,\n isVirtual: true,\n _fsRouteType: 'static',\n }\n }\n\n if (node.children !== undefined) {\n const { children, physicalDirectories } =\n await getRouteNodesRecursive(\n tsrConfig,\n root,\n fullDir,\n node.children,\n tokenRegexes,\n routeNode,\n )\n routeNode.children = children\n allPhysicalDirectories.push(...physicalDirectories)\n\n // If the route has children, it should be a layout\n routeNode._fsRouteType = 'layout'\n }\n return routeNode\n }\n case 'layout': {\n const { filePath, variableName, fullPath } = getFile(node.file)\n\n if (node.id !== undefined) {\n node.id = ensureLeadingUnderScore(node.id)\n } else {\n const baseName = path.basename(filePath)\n const fileNameWithoutExt = path.parse(baseName).name\n node.id = ensureLeadingUnderScore(fileNameWithoutExt)\n }\n const lastSegment = node.id\n // Process the segment to handle escape sequences like [_]\n const {\n routePath: escapedSegment,\n originalRoutePath: originalSegment,\n } = determineInitialRoutePath(removeLeadingSlash(lastSegment))\n const routePath = `${parentRoutePath}${escapedSegment}`\n // Store the original path with brackets for escape detection\n const originalRoutePath = `${parentRoutePath}${originalSegment}`\n\n const routeNode: RouteNode = {\n fullPath,\n filePath,\n variableName,\n routePath,\n originalRoutePath,\n _fsRouteType: 'pathless_layout',\n }\n\n if (node.children !== undefined) {\n const { children, physicalDirectories } =\n await getRouteNodesRecursive(\n tsrConfig,\n root,\n fullDir,\n node.children,\n tokenRegexes,\n routeNode,\n )\n routeNode.children = children\n allPhysicalDirectories.push(...physicalDirectories)\n }\n return routeNode\n }\n }\n }),\n )\n return {\n children: children.flat(),\n physicalDirectories: allPhysicalDirectories,\n }\n}\n"],"names":["getRouteNodesPhysical","children"],"mappings":";;;;;;AAqBA,SAAS,wBAAwB,IAAY;AAC3C,MAAI,GAAG,WAAW,GAAG,GAAG;AACtB,WAAO;AAAA,EACT;AACA,SAAO,IAAI,EAAE;AACf;AAEA,SAAS,YAAY,MAAmC;AACtD,QAAM,SAAS,CAAC,IAAI;AAEpB,MAAI,KAAK,UAAU;AACjB,eAAW,SAAS,KAAK,UAAU;AACjC,aAAO,KAAK,GAAG,YAAY,KAAK,CAAC;AAAA,IACnC;AAAA,EACF;AACA,SAAO,KAAK;AAEZ,SAAO;AACT;AAEA,eAAsB,cACpB,WASA,MACA,cAC8B;AAC9B,QAAM,UAAU,QAAQ,UAAU,eAAe;AACjD,MAAI,UAAU,uBAAuB,QAAW;AAC9C,UAAM,IAAI,MAAM,iCAAiC;AAAA,EACnD;AACA,MAAI;AACJ,MAAI,OAAO,UAAU,uBAAuB,UAAU;AACpD,yBAAqB,MAAM;AAAA,MACzB;AAAA,MACA;AAAA,IAAA;AAAA,EAEJ,OAAO;AACL,yBAAqB,UAAU;AAAA,EACjC;AACA,QAAM,EAAE,UAAU,oBAAA,IAAwB,MAAM;AAAA,IAC9C;AAAA,IACA;AAAA,IACA;AAAA,IACA,mBAAmB;AAAA,IACnB;AAAA,EAAA;AAEF,QAAM,WAAW,YAAY;AAAA,IAC3B;AAAA,IACA,UAAU,mBAAmB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ChB,MAAM;AAAA,cACJ;AAAA,cACA;AAAA,cACA;AAAA,cACA,KAAK;AAAA,cACL;AAAA,cACA;AAAA,YAAA;AAEJ,sBAAU,WAAWA;AACrB,mCAAuB,KAAK,GAAG,mBAAmB;AAAA,UACpD;AACA,iBAAO;AAAA,QACT;AAAA,MAAA;AAAA,IAEJ,CAAC;AAAA,EAAA;AAEH,SAAO;AAAA,IACL,UAAU,SAAS,KAAA;AAAA,IACnB,qBAAqB;AAAA,EAAA;AAEzB;"}
@@ -60,8 +60,26 @@ export declare class Generator {
60
60
  private plugins;
61
61
  private static routeGroupPatternRegex;
62
62
  private physicalDirectories;
63
- private indexTokenRegex;
64
- private routeTokenRegex;
63
+ /**
64
+ * Token regexes are pre-compiled once here and reused throughout route processing.
65
+ * We need TWO types of regex for each token because they match against different inputs:
66
+ *
67
+ * 1. FILENAME regexes: Match token patterns within full file path strings.
68
+ * Example: For file "routes/dashboard.index.tsx", we want to detect ".index."
69
+ * Pattern: `[./](?:token)[.]` - matches token bounded by path separators/dots
70
+ * Used in: sorting route nodes by file path
71
+ *
72
+ * 2. SEGMENT regexes: Match token against a single logical route segment.
73
+ * Example: For segment "index" (extracted from path), match the whole segment
74
+ * Pattern: `^(?:token)$` - matches entire segment exactly
75
+ * Used in: route parsing, determining route types, escape detection
76
+ *
77
+ * We cannot reuse one for the other without false positives or missing matches.
78
+ */
79
+ private indexTokenFilenameRegex;
80
+ private routeTokenFilenameRegex;
81
+ private indexTokenSegmentRegex;
82
+ private routeTokenSegmentRegex;
65
83
  private static componentPieceRegex;
66
84
  constructor(opts: {
67
85
  config: Config;
@@ -7,7 +7,7 @@ import { logging } from "./logger.js";
7
7
  import { getRouteNodes as getRouteNodes$1, isVirtualConfigFile } from "./filesystem/physical/getRouteNodes.js";
8
8
  import { getRouteNodes } from "./filesystem/virtual/getRouteNodes.js";
9
9
  import { rootPathId } from "./filesystem/physical/rootPathId.js";
10
- import { multiSortBy, RoutePrefixMap, format, getImportForRouteNode, isRouteNodeValidForAugmentation, buildRouteTreeConfig, findParent, replaceBackslash, removeExt, createRouteNodesByFullPath, createRouteNodesByTo, createRouteNodesById, getResolvedRouteNodeVariableName, buildFileRoutesByPathInterface, checkRouteFullPathUniqueness, mergeImportDeclarations, buildImportString, checkFileExists, hasParentRoute, determineNodePath, trimPathLeft, isSegmentPathless, removeGroups, removeUnderscoresWithEscape, removeLayoutSegmentsWithEscape, removeTrailingSlash, removeLastSegmentFromPath, getImportPath } from "./utils.js";
10
+ import { createTokenRegex, multiSortBy, RoutePrefixMap, format, getImportForRouteNode, isRouteNodeValidForAugmentation, buildRouteTreeConfig, findParent, replaceBackslash, removeExt, createRouteNodesByFullPath, createRouteNodesByTo, createRouteNodesById, getResolvedRouteNodeVariableName, buildFileRoutesByPathInterface, checkRouteFullPathUniqueness, mergeImportDeclarations, buildImportString, checkFileExists, hasParentRoute, determineNodePath, trimPathLeft, isSegmentPathless, removeGroups, removeUnderscoresWithEscape, removeLayoutSegmentsWithEscape, removeTrailingSlash, removeLastSegmentFromPath, getImportPath } from "./utils.js";
11
11
  import { getTargetTemplate, fillTemplate } from "./template.js";
12
12
  import { transform } from "./transform/transform.js";
13
13
  const DefaultFileSystem = {
@@ -63,8 +63,18 @@ const _Generator = class _Generator {
63
63
  this.targetTemplate = getTargetTemplate(this.config);
64
64
  this.routesDirectoryPath = this.getRoutesDirectoryPath();
65
65
  this.plugins.push(...opts.config.plugins || []);
66
- this.indexTokenRegex = new RegExp(`[./]${this.config.indexToken}[.]`);
67
- this.routeTokenRegex = new RegExp(`[./]${this.config.routeToken}[.]`);
66
+ this.indexTokenFilenameRegex = createTokenRegex(this.config.indexToken, {
67
+ type: "filename"
68
+ });
69
+ this.routeTokenFilenameRegex = createTokenRegex(this.config.routeToken, {
70
+ type: "filename"
71
+ });
72
+ this.indexTokenSegmentRegex = createTokenRegex(this.config.indexToken, {
73
+ type: "segment"
74
+ });
75
+ this.routeTokenSegmentRegex = createTokenRegex(this.config.routeToken, {
76
+ type: "segment"
77
+ });
68
78
  for (const plugin of this.plugins) {
69
79
  plugin.init?.({ generator: this });
70
80
  }
@@ -154,9 +164,19 @@ const _Generator = class _Generator {
154
164
  let writeRouteTreeFile = false;
155
165
  let getRouteNodesResult;
156
166
  if (this.config.virtualRouteConfig) {
157
- getRouteNodesResult = await getRouteNodes(this.config, this.root);
167
+ getRouteNodesResult = await getRouteNodes(this.config, this.root, {
168
+ indexTokenSegmentRegex: this.indexTokenSegmentRegex,
169
+ routeTokenSegmentRegex: this.routeTokenSegmentRegex
170
+ });
158
171
  } else {
159
- getRouteNodesResult = await getRouteNodes$1(this.config, this.root);
172
+ getRouteNodesResult = await getRouteNodes$1(
173
+ this.config,
174
+ this.root,
175
+ {
176
+ indexTokenSegmentRegex: this.indexTokenSegmentRegex,
177
+ routeTokenSegmentRegex: this.routeTokenSegmentRegex
178
+ }
179
+ );
160
180
  }
161
181
  const {
162
182
  rootRouteNode,
@@ -177,9 +197,9 @@ Add the file in: "${this.config.routesDirectory}/${rootPathId}.${this.config.dis
177
197
  const preRouteNodes = multiSortBy(beforeRouteNodes, [
178
198
  (d) => d.routePath === "/" ? -1 : 1,
179
199
  (d) => d.routePath?.split("/").length,
180
- (d) => d.filePath.match(this.indexTokenRegex) ? 1 : -1,
200
+ (d) => d.filePath.match(this.indexTokenFilenameRegex) ? 1 : -1,
181
201
  (d) => d.filePath.match(_Generator.componentPieceRegex) ? 1 : -1,
182
- (d) => d.filePath.match(this.routeTokenRegex) ? -1 : 1,
202
+ (d) => d.filePath.match(this.routeTokenFilenameRegex) ? -1 : 1,
183
203
  (d) => d.routePath?.endsWith("/") ? -1 : 1,
184
204
  (d) => d.routePath
185
205
  ]).filter((d) => {
@@ -324,10 +344,15 @@ Add the file in: "${this.config.routesDirectory}/${rootPathId}.${this.config.dis
324
344
  buildRouteTree(opts) {
325
345
  const config = { ...this.config, ...opts.config || {} };
326
346
  const { rootRouteNode, acc } = opts;
347
+ const indexTokenSegmentRegex = config.indexToken === this.config.indexToken ? this.indexTokenSegmentRegex : createTokenRegex(config.indexToken, { type: "segment" });
327
348
  const sortedRouteNodes = multiSortBy(acc.routeNodes, [
328
349
  (d) => d.routePath?.includes(`/${rootPathId}`) ? -1 : 1,
329
350
  (d) => d.routePath?.split("/").length,
330
- (d) => d.routePath?.endsWith(config.indexToken) ? -1 : 1,
351
+ (d) => {
352
+ const segments = d.routePath?.split("/").filter(Boolean) ?? [];
353
+ const last = segments[segments.length - 1] ?? "";
354
+ return indexTokenSegmentRegex.test(last) ? -1 : 1;
355
+ },
331
356
  (d) => d
332
357
  ]);
333
358
  const routeImports = [];