@tanstack/router-generator 1.167.41 → 1.167.42

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.
@@ -545,7 +545,8 @@ ${acc.routeTree.map((child) => `${child.variableName}Route: typeof ${require_uti
545
545
  newContent: updatedCacheEntry.fileContent,
546
546
  strategy: {
547
547
  type: "mtime",
548
- expectedMtimeMs: updatedCacheEntry.mtimeMs
548
+ expectedMtimeMs: updatedCacheEntry.mtimeMs,
549
+ expectedContent: existingRouteFile.fileContent
549
550
  }
550
551
  })).mtimeMs;
551
552
  this.routeNodeShadowCache.set(node.fullPath, updatedCacheEntry);
@@ -577,14 +578,8 @@ ${acc.routeTree.map((child) => `${child.variableName}Route: typeof ${require_uti
577
578
  const tmpPath = this.getTempFileName(opts.filePath);
578
579
  await this.fs.writeFile(tmpPath, opts.newContent);
579
580
  if (opts.strategy.type === "mtime") {
581
+ const { expectedMtimeMs, expectedContent } = opts.strategy;
580
582
  const beforeStat = await this.fs.stat(opts.filePath);
581
- if (beforeStat.mtimeMs !== opts.strategy.expectedMtimeMs) throw rerun({
582
- msg: `File ${opts.filePath} was modified by another process during processing.`,
583
- event: {
584
- type: "update",
585
- path: opts.filePath
586
- }
587
- });
588
583
  const newFileState = await this.fs.stat(tmpPath);
589
584
  if (newFileState.mode !== beforeStat.mode) await this.fs.chmod(tmpPath, beforeStat.mode);
590
585
  if (newFileState.uid !== beforeStat.uid || newFileState.gid !== beforeStat.gid) try {
@@ -593,6 +588,19 @@ ${acc.routeTree.map((child) => `${child.variableName}Route: typeof ${require_uti
593
588
  if (typeof err === "object" && err !== null && "code" in err && err.code === "EPERM") console.warn(`[safeFileWrite] chown failed: ${err.message}`);
594
589
  else throw err;
595
590
  }
591
+ let changed;
592
+ if (expectedContent === void 0) changed = (await this.fs.stat(opts.filePath)).mtimeMs !== expectedMtimeMs;
593
+ else {
594
+ const current = await this.fs.readFile(opts.filePath);
595
+ changed = current === "file-not-existing" || current.stat.mtimeMs !== expectedMtimeMs || current.fileContent !== expectedContent;
596
+ }
597
+ if (changed) throw rerun({
598
+ msg: `File ${opts.filePath} was modified by another process during processing.`,
599
+ event: {
600
+ type: "update",
601
+ path: opts.filePath
602
+ }
603
+ });
596
604
  } else if (await require_utils.checkFileExists(opts.filePath)) throw rerun({
597
605
  msg: `File ${opts.filePath} already exists. Cannot overwrite.`,
598
606
  event: {
@@ -665,7 +673,8 @@ ${acc.routeTree.map((child) => `${child.variableName}Route: typeof ${require_uti
665
673
  newContent: rootRouteContent,
666
674
  strategy: {
667
675
  type: "mtime",
668
- expectedMtimeMs: rootNodeFile.stat.mtimeMs
676
+ expectedMtimeMs: rootNodeFile.stat.mtimeMs,
677
+ expectedContent: rootNodeFile.fileContent
669
678
  }
670
679
  });
671
680
  updatedCacheEntry.fileContent = rootRouteContent;
@@ -1 +1 @@
1
- {"version":3,"file":"generator.cjs","names":["countRoutePathSegments","fsp","logging","getTargetTemplate","createTokenRegex","path","existsSync","virtualGetRouteNodes","physicalGetRouteNodes","rootPathId","multiSortBy","countSlashSeparatedParts","RoutePrefixMap","format","sortRouteNodes","getImportForRouteNode","buildRouteTreeConfig","findParent","replaceBackslash","removeExt","createRouteNodesByFullPath","createRouteNodesByTo","createRouteNodesById","getResolvedRouteNodeVariableName","rootRouteId","buildFileRoutesByPathInterface","mergeImportDeclarations","buildImportString","fillTemplate","transform","checkFileExists","crypto","hasParentRoute","determineNodePath","trimPathLeft","isSegmentPathless","removeGroups","removeLayoutSegmentsAndUnderscoresWithEscape","removeTrailingSlash","removeLastSegmentFromPath","isVirtualConfigFile"],"sources":["../../src/generator.ts"],"sourcesContent":["import path from 'node:path'\nimport * as fsp from 'node:fs/promises'\nimport { existsSync, mkdirSync } from 'node:fs'\nimport crypto from 'node:crypto'\nimport { rootRouteId } from '@tanstack/router-core'\nimport { logging } from './logger'\nimport {\n isVirtualConfigFile,\n getRouteNodes as physicalGetRouteNodes,\n} from './filesystem/physical/getRouteNodes'\nimport { getRouteNodes as virtualGetRouteNodes } from './filesystem/virtual/getRouteNodes'\nimport { rootPathId } from './filesystem/physical/rootPathId'\nimport {\n RoutePrefixMap,\n buildFileRoutesByPathInterface,\n buildImportString,\n buildRouteTreeConfig,\n checkFileExists,\n checkRouteFullPathUniqueness,\n countRoutePathSegments,\n countSlashSeparatedParts,\n createRouteNodesByFullPath,\n createRouteNodesById,\n createRouteNodesByTo,\n createTokenRegex,\n determineNodePath,\n findParent,\n format,\n getImportForRouteNode,\n getResolvedRouteNodeVariableName,\n hasParentRoute,\n isSegmentPathless,\n mergeImportDeclarations,\n multiSortBy,\n removeExt,\n removeGroups,\n removeLastSegmentFromPath,\n removeLayoutSegmentsAndUnderscoresWithEscape,\n removeTrailingSlash,\n replaceBackslash,\n sortRouteNodes,\n trimPathLeft,\n} from './utils'\nimport { fillTemplate, getTargetTemplate } from './template'\nimport { transform } from './transform/transform'\nimport { validateRouteParams } from './validate-route-params'\nimport type { GeneratorPlugin } from './plugin/types'\nimport type { TargetTemplate } from './template'\nimport type {\n FsRouteType,\n GetRouteNodesResult,\n GetRoutesByFileMapResult,\n HandleNodeAccumulator,\n ImportDeclaration,\n RouteNode,\n RoutePathSegmentMetadata,\n} from './types'\nimport type { Config } from './config'\nimport type { Logger } from './logger'\n\ninterface fs {\n stat: (\n filePath: string,\n ) => Promise<{ mtimeMs: bigint; mode: number; uid: number; gid: number }>\n rename: (oldPath: string, newPath: string) => Promise<void>\n writeFile: (filePath: string, content: string) => Promise<void>\n readFile: (\n filePath: string,\n ) => Promise<\n { stat: { mtimeMs: bigint }; fileContent: string } | 'file-not-existing'\n >\n chmod: (filePath: string, mode: number) => Promise<void>\n chown: (filePath: string, uid: number, gid: number) => Promise<void>\n}\n\nfunction getRoutePathSegmentMetadataForPath(\n node: RouteNode,\n routePath: string,\n parentRoutePath?: string,\n): Array<RoutePathSegmentMetadata | undefined> | undefined {\n if (!node._routePathSegmentMetadata) return undefined\n\n const segments = routePath.split('/')\n const result = new Array<RoutePathSegmentMetadata | undefined>(\n segments.length,\n )\n const parentSegmentCount = countRoutePathSegments(parentRoutePath)\n let hasMetadata = false\n let segmentCount = 0\n\n for (let i = 0; i < segments.length; i++) {\n if (!segments[i]) continue\n const sourceIndex = parentSegmentCount + segmentCount + 1\n result[i] = node._routePathSegmentMetadata[sourceIndex]\n hasMetadata ||= !!result[i]\n segmentCount++\n }\n\n return hasMetadata ? result : undefined\n}\n\nconst DefaultFileSystem: fs = {\n stat: async (filePath) => {\n const res = await fsp.stat(filePath, { bigint: true })\n return {\n mtimeMs: res.mtimeMs,\n mode: Number(res.mode),\n uid: Number(res.uid),\n gid: Number(res.gid),\n }\n },\n rename: (oldPath, newPath) => fsp.rename(oldPath, newPath),\n writeFile: (filePath, content) => fsp.writeFile(filePath, content),\n readFile: async (filePath: string) => {\n try {\n const fileHandle = await fsp.open(filePath, 'r')\n const stat = await fileHandle.stat({ bigint: true })\n const fileContent = (await fileHandle.readFile()).toString()\n await fileHandle.close()\n return { stat, fileContent }\n } catch (e: any) {\n if ('code' in e) {\n if (e.code === 'ENOENT') {\n return 'file-not-existing'\n }\n }\n throw e\n }\n },\n chmod: (filePath, mode) => fsp.chmod(filePath, mode),\n chown: (filePath, uid, gid) => fsp.chown(filePath, uid, gid),\n}\n\ninterface Rerun {\n rerun: true\n msg?: string\n event: GeneratorEvent\n}\nfunction rerun(opts: { msg?: string; event?: GeneratorEvent }): Rerun {\n const { event, ...rest } = opts\n return { rerun: true, event: event ?? { type: 'rerun' }, ...rest }\n}\n\nfunction isRerun(result: unknown): result is Rerun {\n return (\n typeof result === 'object' &&\n result !== null &&\n 'rerun' in result &&\n result.rerun === true\n )\n}\n\nexport type FileEventType = 'create' | 'update' | 'delete'\nexport type FileEvent = {\n type: FileEventType\n path: string\n}\nexport type GeneratorEvent = FileEvent | { type: 'rerun' }\n\ntype FileCacheChange<TCacheEntry extends GeneratorCacheEntry> =\n | {\n result: false\n cacheEntry: TCacheEntry\n }\n | { result: true; mtimeMs: bigint; cacheEntry: TCacheEntry }\n | {\n result: 'file-not-in-cache'\n }\n | {\n result: 'cannot-stat-file'\n }\n\ninterface GeneratorCacheEntry {\n mtimeMs: bigint\n fileContent: string\n}\n\ninterface RouteNodeCacheEntry extends GeneratorCacheEntry {\n routeId: string\n node: RouteNode\n}\n\ntype GeneratorRouteNodeCache = Map</** filePath **/ string, RouteNodeCacheEntry>\n\ninterface CrawlingResult {\n rootRouteNode: RouteNode\n routeFileResult: Array<RouteNode>\n acc: HandleNodeAccumulator\n}\n\nexport class Generator {\n /**\n * why do we have two caches for the route files?\n * During processing, we READ from the cache and WRITE to the shadow cache.\n *\n * After a route file is processed, we write to the shadow cache.\n * If during processing we bail out and re-run, we don't lose this modification\n * but still can track whether the file contributed changes and thus the route tree file needs to be regenerated.\n * After all files are processed, we swap the shadow cache with the main cache and initialize a new shadow cache.\n * That way we also ensure deleted/renamed files don't stay in the cache forever.\n */\n private routeNodeCache: GeneratorRouteNodeCache = new Map()\n private routeNodeShadowCache: GeneratorRouteNodeCache = new Map()\n\n private routeTreeFileCache: GeneratorCacheEntry | undefined\n\n private crawlingResult: CrawlingResult | undefined\n public config: Config\n public targetTemplate: TargetTemplate\n\n private root: string\n private routesDirectoryPath: string\n private sessionId?: string\n private fs: fs\n private logger: Logger\n private generatedRouteTreePath: string\n private runPromise: Promise<void> | undefined\n private fileEventQueue: Array<GeneratorEvent> = []\n private plugins: Array<GeneratorPlugin> = []\n private static routeGroupPatternRegex = /\\(.+\\)/\n private physicalDirectories: Array<string> = []\n\n /**\n * Token regexes are pre-compiled once here and reused throughout route processing.\n * We need TWO types of regex for each token because they match against different inputs:\n *\n * 1. FILENAME regexes: Match token patterns within full file path strings.\n * Example: For file \"routes/dashboard.index.tsx\", we want to detect \".index.\"\n * Pattern: `[./](?:token)[.]` - matches token bounded by path separators/dots\n * Used in: sorting route nodes by file path\n *\n * 2. SEGMENT regexes: Match token against a single logical route segment.\n * Example: For segment \"index\" (extracted from path), match the whole segment\n * Pattern: `^(?:token)$` - matches entire segment exactly\n * Used in: route parsing, determining route types, escape detection\n *\n * We cannot reuse one for the other without false positives or missing matches.\n */\n private indexTokenFilenameRegex: RegExp\n private routeTokenFilenameRegex: RegExp\n private indexTokenSegmentRegex: RegExp\n private routeTokenSegmentRegex: RegExp\n private static componentPieceRegex =\n /[./](component|errorComponent|notFoundComponent|pendingComponent|loader|lazy)[.]/\n\n constructor(opts: { config: Config; root: string; fs?: fs }) {\n this.config = opts.config\n this.logger = logging({ disabled: this.config.disableLogging })\n this.root = opts.root\n this.fs = opts.fs || DefaultFileSystem\n this.generatedRouteTreePath = this.getGeneratedRouteTreePath()\n this.targetTemplate = getTargetTemplate(this.config)\n\n this.routesDirectoryPath = this.getRoutesDirectoryPath()\n this.plugins.push(...(opts.config.plugins || []))\n\n // Create all token regexes once in constructor\n this.indexTokenFilenameRegex = createTokenRegex(this.config.indexToken, {\n type: 'filename',\n })\n this.routeTokenFilenameRegex = createTokenRegex(this.config.routeToken, {\n type: 'filename',\n })\n this.indexTokenSegmentRegex = createTokenRegex(this.config.indexToken, {\n type: 'segment',\n })\n this.routeTokenSegmentRegex = createTokenRegex(this.config.routeToken, {\n type: 'segment',\n })\n\n for (const plugin of this.plugins) {\n plugin.init?.({ generator: this })\n }\n }\n\n private getGeneratedRouteTreePath() {\n const generatedRouteTreePath = path.isAbsolute(\n this.config.generatedRouteTree,\n )\n ? this.config.generatedRouteTree\n : path.resolve(this.root, this.config.generatedRouteTree)\n\n const generatedRouteTreeDir = path.dirname(generatedRouteTreePath)\n\n if (!existsSync(generatedRouteTreeDir)) {\n mkdirSync(generatedRouteTreeDir, { recursive: true })\n }\n\n return generatedRouteTreePath\n }\n\n private getRoutesDirectoryPath() {\n return path.isAbsolute(this.config.routesDirectory)\n ? this.config.routesDirectory\n : path.resolve(this.root, this.config.routesDirectory)\n }\n\n public getRoutesByFileMap(): GetRoutesByFileMapResult {\n return new Map(\n [...this.routeNodeCache.entries()].map(([filePath, cacheEntry]) => [\n filePath,\n { routeId: cacheEntry.routeId },\n ]),\n )\n }\n\n public async run(event?: GeneratorEvent): Promise<void> {\n if (\n event &&\n event.type !== 'rerun' &&\n !this.isFileRelevantForRouteTreeGeneration(event.path)\n ) {\n return\n }\n this.fileEventQueue.push(event ?? { type: 'rerun' })\n // only allow a single run at a time\n if (this.runPromise) {\n return this.runPromise\n }\n\n this.runPromise = (async () => {\n do {\n // synchronously copy and clear the queue since we are going to iterate asynchronously over it\n // and while we do so, a new event could be put into the queue\n const tempQueue = this.fileEventQueue\n this.fileEventQueue = []\n // if we only have 'update' events in the queue\n // and we already have the affected files' latest state in our cache, we can exit early\n const remainingEvents = (\n await Promise.all(\n tempQueue.map(async (e) => {\n if (e.type === 'update') {\n let cacheEntry: GeneratorCacheEntry | undefined\n if (e.path === this.generatedRouteTreePath) {\n cacheEntry = this.routeTreeFileCache\n } else {\n // we only check the routeNodeCache here\n // if the file's state is only up-to-date in the shadow cache we need to re-run\n cacheEntry = this.routeNodeCache.get(e.path)\n }\n const change = await this.didFileChangeComparedToCache(\n { path: e.path },\n cacheEntry,\n )\n if (change.result === false) {\n return null\n }\n }\n return e\n }),\n )\n ).filter((e) => e !== null)\n\n if (remainingEvents.length === 0) {\n break\n }\n\n try {\n await this.generatorInternal()\n } catch (err) {\n const errArray = !Array.isArray(err) ? [err] : err\n\n const recoverableErrors = errArray.filter((e) => isRerun(e))\n if (recoverableErrors.length === errArray.length) {\n this.fileEventQueue.push(...recoverableErrors.map((e) => e.event))\n recoverableErrors.forEach((e) => {\n if (e.msg) {\n this.logger.info(e.msg)\n }\n })\n } else {\n const unrecoverableErrors = errArray.filter((e) => !isRerun(e))\n this.runPromise = undefined\n throw new Error(\n unrecoverableErrors.map((e) => (e as Error).message).join(),\n )\n }\n }\n } while (this.fileEventQueue.length)\n this.runPromise = undefined\n })()\n return this.runPromise\n }\n\n private async generatorInternal() {\n let writeRouteTreeFile: boolean | 'force' = false\n\n let getRouteNodesResult: GetRouteNodesResult\n\n if (this.config.virtualRouteConfig) {\n getRouteNodesResult = await virtualGetRouteNodes(this.config, this.root, {\n indexTokenSegmentRegex: this.indexTokenSegmentRegex,\n routeTokenSegmentRegex: this.routeTokenSegmentRegex,\n })\n } else {\n getRouteNodesResult = await physicalGetRouteNodes(\n this.config,\n this.root,\n {\n indexTokenSegmentRegex: this.indexTokenSegmentRegex,\n routeTokenSegmentRegex: this.routeTokenSegmentRegex,\n },\n )\n }\n\n const {\n rootRouteNode,\n routeNodes: beforeRouteNodes,\n physicalDirectories,\n } = getRouteNodesResult\n if (rootRouteNode === undefined) {\n let errorMessage = `rootRouteNode must not be undefined. Make sure you've added your root route into the route-tree.`\n if (!this.config.virtualRouteConfig) {\n errorMessage += `\\nMake sure that you add a \"${rootPathId}.${this.config.disableTypes ? 'js' : 'tsx'}\" file to your routes directory.\\nAdd the file in: \"${this.config.routesDirectory}/${rootPathId}.${this.config.disableTypes ? 'js' : 'tsx'}\"`\n }\n throw new Error(errorMessage)\n }\n this.physicalDirectories = physicalDirectories\n\n await this.handleRootNode(rootRouteNode)\n\n const preRouteNodes = multiSortBy(beforeRouteNodes, [\n (d) => (d.routePath === '/' ? -1 : 1),\n (d) =>\n d.routePath === undefined\n ? undefined\n : countSlashSeparatedParts(d.routePath),\n (d) => (d.filePath.match(this.indexTokenFilenameRegex) ? 1 : -1),\n (d) => (d.filePath.match(Generator.componentPieceRegex) ? 1 : -1),\n (d) => (d.filePath.match(this.routeTokenFilenameRegex) ? -1 : 1),\n (d) => (d.routePath?.endsWith('/') ? -1 : 1),\n (d) => d.routePath,\n ]).filter((d) => {\n // Exclude the root route itself, but keep component/loader pieces for the root\n if (d.routePath === `/${rootPathId}`) {\n return [\n 'component',\n 'errorComponent',\n 'notFoundComponent',\n 'pendingComponent',\n 'loader',\n 'lazy',\n ].includes(d._fsRouteType)\n }\n return true\n })\n\n const routeFileAllResult = await Promise.allSettled(\n preRouteNodes\n // only process routes that are backed by an actual file\n .filter((n) => !n.isVirtualParentRoute && !n.isVirtual)\n .map((n) => this.processRouteNodeFile(n)),\n )\n\n const rejections = routeFileAllResult.filter(\n (result) => result.status === 'rejected',\n )\n if (rejections.length > 0) {\n throw rejections.map((e) => e.reason)\n }\n\n const routeFileResult = routeFileAllResult.flatMap((result) => {\n if (result.status === 'fulfilled' && result.value !== null) {\n if (result.value.shouldWriteTree) {\n writeRouteTreeFile = true\n }\n return result.value.node\n }\n return []\n })\n\n // reset children in case we re-use a node from the cache\n routeFileResult.forEach((r) => (r.children = undefined))\n\n const acc: HandleNodeAccumulator = {\n routeTree: [],\n routeNodes: [],\n routePiecesByPath: {},\n routeNodesByPath: new Map(),\n }\n\n const prefixMap = new RoutePrefixMap(routeFileResult)\n\n for (const node of routeFileResult) {\n Generator.handleNode(node, acc, prefixMap, this.config)\n }\n\n this.crawlingResult = { rootRouteNode, routeFileResult, acc }\n\n // this is the first time the generator runs, so read in the route tree file if it exists yet\n if (!this.routeTreeFileCache) {\n const routeTreeFile = await this.fs.readFile(this.generatedRouteTreePath)\n if (routeTreeFile !== 'file-not-existing') {\n this.routeTreeFileCache = {\n fileContent: routeTreeFile.fileContent,\n mtimeMs: routeTreeFile.stat.mtimeMs,\n }\n }\n writeRouteTreeFile = true\n } else {\n const routeTreeFileChange = await this.didFileChangeComparedToCache(\n { path: this.generatedRouteTreePath },\n this.routeTreeFileCache,\n )\n if (routeTreeFileChange.result !== false) {\n writeRouteTreeFile = 'force'\n if (routeTreeFileChange.result === true) {\n const routeTreeFile = await this.fs.readFile(\n this.generatedRouteTreePath,\n )\n if (routeTreeFile !== 'file-not-existing') {\n this.routeTreeFileCache = {\n fileContent: routeTreeFile.fileContent,\n mtimeMs: routeTreeFile.stat.mtimeMs,\n }\n }\n }\n }\n }\n\n if (!writeRouteTreeFile) {\n // only needs to be done if no other changes have been detected yet\n // compare shadowCache and cache to identify deleted routes\n if (this.routeNodeCache.size !== this.routeNodeShadowCache.size) {\n writeRouteTreeFile = true\n } else {\n for (const fullPath of this.routeNodeCache.keys()) {\n if (!this.routeNodeShadowCache.has(fullPath)) {\n writeRouteTreeFile = true\n break\n }\n }\n }\n }\n\n if (!writeRouteTreeFile) {\n this.swapCaches()\n return\n }\n\n const buildResult = this.buildRouteTree({\n rootRouteNode,\n acc,\n routeFileResult,\n })\n let routeTreeContent = buildResult.routeTreeContent\n\n routeTreeContent = this.config.enableRouteTreeFormatting\n ? await format(routeTreeContent, this.config)\n : routeTreeContent\n\n let newMtimeMs: bigint | undefined\n if (this.routeTreeFileCache) {\n if (this.routeTreeFileCache.fileContent === routeTreeContent) {\n // existing route tree file is already up-to-date, don't write it.\n // When 'force' was set because an external change was detected,\n // we still re-read and re-check here, but if the generated content\n // matches we skip the write to avoid triggering another watcher cycle.\n } else {\n const newRouteTreeFileStat = await this.safeFileWrite({\n filePath: this.generatedRouteTreePath,\n newContent: routeTreeContent,\n strategy: {\n type: 'mtime',\n expectedMtimeMs: this.routeTreeFileCache.mtimeMs,\n },\n })\n newMtimeMs = newRouteTreeFileStat.mtimeMs\n }\n } else {\n const newRouteTreeFileStat = await this.safeFileWrite({\n filePath: this.generatedRouteTreePath,\n newContent: routeTreeContent,\n strategy: {\n type: 'new-file',\n },\n })\n newMtimeMs = newRouteTreeFileStat.mtimeMs\n }\n\n if (newMtimeMs !== undefined) {\n this.routeTreeFileCache = {\n fileContent: routeTreeContent,\n mtimeMs: newMtimeMs,\n }\n }\n\n this.plugins.map((plugin) => {\n return plugin.onRouteTreeChanged?.({\n routeTree: buildResult.routeTree,\n routeNodes: buildResult.routeNodes,\n acc,\n rootRouteNode,\n })\n })\n this.swapCaches()\n }\n\n private swapCaches() {\n this.routeNodeCache = this.routeNodeShadowCache\n this.routeNodeShadowCache = new Map()\n }\n\n public buildRouteTree(opts: {\n rootRouteNode: RouteNode\n acc: HandleNodeAccumulator\n routeFileResult: Array<RouteNode>\n config?: Partial<Config>\n }) {\n const config = { ...this.config, ...(opts.config || {}) }\n\n const { rootRouteNode, acc } = opts\n\n // Use pre-compiled regex if config hasn't been overridden, otherwise create new one\n const indexTokenSegmentRegex =\n config.indexToken === this.config.indexToken\n ? this.indexTokenSegmentRegex\n : createTokenRegex(config.indexToken, { type: 'segment' })\n\n const sortedRouteNodes = sortRouteNodes(\n acc.routeNodes,\n indexTokenSegmentRegex,\n )\n\n const routeImports: Array<ImportDeclaration> = []\n const virtualRouteNodes: Array<string> = []\n\n for (const node of sortedRouteNodes) {\n if (node.isVirtual) {\n virtualRouteNodes.push(\n `const ${node.variableName}RouteImport = createFileRoute('${node.routePath}')()`,\n )\n } else {\n routeImports.push(\n getImportForRouteNode(\n node,\n config,\n this.generatedRouteTreePath,\n this.root,\n ),\n )\n }\n }\n\n const imports: Array<ImportDeclaration> = []\n if (virtualRouteNodes.length > 0) {\n imports.push({\n specifiers: [{ imported: 'createFileRoute' }],\n source: this.targetTemplate.fullPkg,\n })\n }\n // Add lazyRouteComponent import if there are component pieces\n let hasComponentPieces = false\n let hasLoaderPieces = false\n for (const node of sortedRouteNodes) {\n const pieces = acc.routePiecesByPath[node.routePath!]\n if (pieces) {\n if (\n pieces.component ||\n pieces.errorComponent ||\n pieces.notFoundComponent ||\n pieces.pendingComponent\n ) {\n hasComponentPieces = true\n }\n if (pieces.loader) {\n hasLoaderPieces = true\n }\n if (hasComponentPieces && hasLoaderPieces) break\n }\n }\n if (hasComponentPieces || hasLoaderPieces) {\n const runtimeImport: ImportDeclaration = {\n specifiers: [],\n source: this.targetTemplate.fullPkg,\n }\n if (hasComponentPieces) {\n runtimeImport.specifiers.push({ imported: 'lazyRouteComponent' })\n }\n if (hasLoaderPieces) {\n runtimeImport.specifiers.push({ imported: 'lazyFn' })\n }\n imports.push(runtimeImport)\n }\n const routeTreeConfig = buildRouteTreeConfig(\n acc.routeTree,\n config.disableTypes,\n )\n\n const createUpdateRoutes = sortedRouteNodes.map((node) => {\n const pieces = acc.routePiecesByPath[node.routePath!]\n const loaderNode = pieces?.loader\n const componentNode = pieces?.component\n const errorComponentNode = pieces?.errorComponent\n const notFoundComponentNode = pieces?.notFoundComponent\n const pendingComponentNode = pieces?.pendingComponent\n const lazyComponentNode = pieces?.lazy\n\n return [\n [\n `const ${node.variableName}Route = ${node.variableName}RouteImport.update({\n ${[\n `id: '${node.path}'`,\n !node.isNonPath ||\n (node._fsRouteType === 'pathless_layout' && node.cleanedPath)\n ? `path: '${node.cleanedPath}'`\n : undefined,\n `getParentRoute: () => ${findParent(node)}`,\n ]\n .filter(Boolean)\n .join(',')}\n }${config.disableTypes ? '' : 'as any'})`,\n loaderNode\n ? `.updateLoader({ loader: lazyFn(() => import('./${replaceBackslash(\n removeExt(\n path.relative(\n path.dirname(config.generatedRouteTree),\n path.resolve(config.routesDirectory, loaderNode.filePath),\n ),\n config.addExtensions,\n ),\n )}'), 'loader') })`\n : '',\n componentNode ||\n errorComponentNode ||\n notFoundComponentNode ||\n pendingComponentNode\n ? `.update({\n ${(\n [\n ['component', componentNode],\n ['errorComponent', errorComponentNode],\n ['notFoundComponent', notFoundComponentNode],\n ['pendingComponent', pendingComponentNode],\n ] as const\n )\n .filter((d) => d[1])\n .map((d) => {\n // For .vue files, use 'default' as the export name since Vue SFCs export default\n const isVueFile = d[1]!.filePath.endsWith('.vue')\n const exportName = isVueFile ? 'default' : d[0]\n // Keep .vue extension for Vue files since Vite requires it\n const importPath = replaceBackslash(\n isVueFile\n ? path.relative(\n path.dirname(config.generatedRouteTree),\n path.resolve(\n config.routesDirectory,\n d[1]!.filePath,\n ),\n )\n : removeExt(\n path.relative(\n path.dirname(config.generatedRouteTree),\n path.resolve(\n config.routesDirectory,\n d[1]!.filePath,\n ),\n ),\n config.addExtensions,\n ),\n )\n return `${\n d[0]\n }: lazyRouteComponent(() => import('./${importPath}'), '${exportName}')`\n })\n .join('\\n,')}\n })`\n : '',\n lazyComponentNode\n ? (() => {\n // For .vue files, use 'default' export since Vue SFCs export default\n const isVueFile = lazyComponentNode.filePath.endsWith('.vue')\n const exportAccessor = isVueFile ? 'd.default' : 'd.Route'\n // Keep .vue extension for Vue files since Vite requires it\n const importPath = replaceBackslash(\n isVueFile\n ? path.relative(\n path.dirname(config.generatedRouteTree),\n path.resolve(\n config.routesDirectory,\n lazyComponentNode.filePath,\n ),\n )\n : removeExt(\n path.relative(\n path.dirname(config.generatedRouteTree),\n path.resolve(\n config.routesDirectory,\n lazyComponentNode.filePath,\n ),\n ),\n config.addExtensions,\n ),\n )\n return `.lazy(() => import('./${importPath}').then((d) => ${exportAccessor}))`\n })()\n : '',\n ].join(''),\n ].join('\\n\\n')\n })\n\n // Generate update for root route if it has component pieces\n const rootRoutePath = `/${rootPathId}`\n const rootPieces = acc.routePiecesByPath[rootRoutePath]\n const rootComponentNode = rootPieces?.component\n const rootErrorComponentNode = rootPieces?.errorComponent\n const rootNotFoundComponentNode = rootPieces?.notFoundComponent\n const rootPendingComponentNode = rootPieces?.pendingComponent\n\n let rootRouteUpdate = ''\n if (\n rootComponentNode ||\n rootErrorComponentNode ||\n rootNotFoundComponentNode ||\n rootPendingComponentNode\n ) {\n rootRouteUpdate = `const rootRouteWithChildren = rootRouteImport${\n rootComponentNode ||\n rootErrorComponentNode ||\n rootNotFoundComponentNode ||\n rootPendingComponentNode\n ? `.update({\n ${(\n [\n ['component', rootComponentNode],\n ['errorComponent', rootErrorComponentNode],\n ['notFoundComponent', rootNotFoundComponentNode],\n ['pendingComponent', rootPendingComponentNode],\n ] as const\n )\n .filter((d) => d[1])\n .map((d) => {\n // For .vue files, use 'default' as the export name since Vue SFCs export default\n const isVueFile = d[1]!.filePath.endsWith('.vue')\n const exportName = isVueFile ? 'default' : d[0]\n // Keep .vue extension for Vue files since Vite requires it\n const importPath = replaceBackslash(\n isVueFile\n ? path.relative(\n path.dirname(config.generatedRouteTree),\n path.resolve(config.routesDirectory, d[1]!.filePath),\n )\n : removeExt(\n path.relative(\n path.dirname(config.generatedRouteTree),\n path.resolve(\n config.routesDirectory,\n d[1]!.filePath,\n ),\n ),\n config.addExtensions,\n ),\n )\n return `${d[0]}: lazyRouteComponent(() => import('./${importPath}'), '${exportName}')`\n })\n .join('\\n,')}\n })`\n : ''\n }._addFileChildren(rootRouteChildren)${config.disableTypes ? '' : `._addFileTypes<FileRouteTypes>()`}`\n }\n\n let fileRoutesByPathInterface = ''\n let fileRoutesByFullPath = ''\n\n if (!config.disableTypes) {\n const routeNodesByFullPath = createRouteNodesByFullPath(acc.routeNodes)\n const routeNodesByTo = createRouteNodesByTo(acc.routeNodes)\n const routeNodesById = createRouteNodesById(acc.routeNodes)\n\n fileRoutesByFullPath = [\n `export interface FileRoutesByFullPath {\n${[...routeNodesByFullPath.entries()]\n .filter(([fullPath]) => fullPath)\n .map(([fullPath, routeNode]) => {\n return `'${fullPath}': typeof ${getResolvedRouteNodeVariableName(routeNode)}`\n })}\n}`,\n `export interface FileRoutesByTo {\n${[...routeNodesByTo.entries()]\n .filter(([to]) => to)\n .map(([to, routeNode]) => {\n return `'${to}': typeof ${getResolvedRouteNodeVariableName(routeNode)}`\n })}\n}`,\n `export interface FileRoutesById {\n'${rootRouteId}': typeof rootRouteImport,\n${[...routeNodesById.entries()].map(([id, routeNode]) => {\n return `'${id}': typeof ${getResolvedRouteNodeVariableName(routeNode)}`\n})}\n}`,\n `export interface FileRouteTypes {\nfileRoutesByFullPath: FileRoutesByFullPath\nfullPaths: ${\n acc.routeNodes.length > 0\n ? [...routeNodesByFullPath.keys()]\n .filter((fullPath) => fullPath)\n .map((fullPath) => `'${fullPath}'`)\n .join('|')\n : 'never'\n }\nfileRoutesByTo: FileRoutesByTo\nto: ${\n acc.routeNodes.length > 0\n ? [...routeNodesByTo.keys()]\n .filter((to) => to)\n .map((to) => `'${to}'`)\n .join('|')\n : 'never'\n }\nid: ${[`'${rootRouteId}'`, ...[...routeNodesById.keys()].map((id) => `'${id}'`)].join('|')}\nfileRoutesById: FileRoutesById\n}`,\n `export interface RootRouteChildren {\n${acc.routeTree.map((child) => `${child.variableName}Route: typeof ${getResolvedRouteNodeVariableName(child)}`).join(',')}\n}`,\n ].join('\\n')\n\n fileRoutesByPathInterface = buildFileRoutesByPathInterface({\n module: this.targetTemplate.fullPkg,\n interfaceName: 'FileRoutesByPath',\n routeNodes: sortedRouteNodes,\n config,\n })\n }\n\n const routeTree = [\n `const rootRouteChildren${config.disableTypes ? '' : `: RootRouteChildren`} = {\n ${acc.routeTree\n .map(\n (child) =>\n `${child.variableName}Route: ${getResolvedRouteNodeVariableName(child)}`,\n )\n .join(',')}\n}`,\n rootRouteUpdate\n ? rootRouteUpdate.replace(\n 'const rootRouteWithChildren = ',\n 'export const routeTree = ',\n )\n : `export const routeTree = rootRouteImport._addFileChildren(rootRouteChildren)${config.disableTypes ? '' : `._addFileTypes<FileRouteTypes>()`}`,\n ].join('\\n')\n\n checkRouteFullPathUniqueness(\n sortedRouteNodes.filter(\n (d) => d.children === undefined && 'lazy' !== d._fsRouteType,\n ),\n config,\n )\n\n let mergedImports = mergeImportDeclarations(imports)\n if (config.disableTypes) {\n mergedImports = mergedImports.filter((d) => d.importKind !== 'type')\n }\n\n const importStatements = mergedImports.map(buildImportString)\n\n const rootRouteImport = getImportForRouteNode(\n rootRouteNode,\n config,\n this.generatedRouteTreePath,\n this.root,\n )\n routeImports.unshift(rootRouteImport)\n\n let footer: Array<string> = []\n if (config.routeTreeFileFooter) {\n if (Array.isArray(config.routeTreeFileFooter)) {\n footer = config.routeTreeFileFooter\n } else {\n footer = config.routeTreeFileFooter()\n }\n }\n const routeTreeContent = [\n ...config.routeTreeFileHeader,\n `// This file was automatically generated by TanStack Router.\n// You should NOT make any changes in this file as it will be overwritten.\n// Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified.`,\n [...importStatements].join('\\n'),\n mergeImportDeclarations(routeImports).map(buildImportString).join('\\n'),\n virtualRouteNodes.join('\\n'),\n createUpdateRoutes.join('\\n'),\n fileRoutesByFullPath,\n fileRoutesByPathInterface,\n routeTreeConfig.join('\\n'),\n routeTree,\n ...footer,\n ]\n .filter(Boolean)\n .join('\\n\\n')\n return {\n routeTreeContent,\n routeTree: acc.routeTree,\n routeNodes: acc.routeNodes,\n }\n }\n\n private async processRouteNodeFile(node: RouteNode): Promise<{\n shouldWriteTree: boolean\n cacheEntry: RouteNodeCacheEntry\n node: RouteNode\n } | null> {\n const result = await this.isRouteFileCacheFresh(node)\n\n if (result.status === 'fresh') {\n return {\n node: result.cacheEntry.node,\n shouldWriteTree: false,\n cacheEntry: result.cacheEntry,\n }\n }\n\n const previousCacheEntry = result.cacheEntry\n\n const existingRouteFile = await this.fs.readFile(node.fullPath)\n if (existingRouteFile === 'file-not-existing') {\n throw new Error(`⚠️ File ${node.fullPath} does not exist`)\n }\n\n if (node.routePath) {\n validateRouteParams(node.routePath, node.filePath, this.logger)\n }\n\n const updatedCacheEntry: RouteNodeCacheEntry = {\n fileContent: existingRouteFile.fileContent,\n mtimeMs: existingRouteFile.stat.mtimeMs,\n routeId: node.routePath ?? '$$TSR_NO_ROUTE_PATH_ASSIGNED$$',\n node,\n }\n\n const escapedRoutePath = node.routePath?.replaceAll('$', '$$') ?? ''\n\n let shouldWriteRouteFile = false\n let shouldWriteTree = false\n // now we need to either scaffold the file or transform it\n if (!existingRouteFile.fileContent) {\n shouldWriteRouteFile = true\n shouldWriteTree = true\n // Creating a new lazy route file\n if (node._fsRouteType === 'lazy') {\n const tLazyRouteTemplate = this.targetTemplate.lazyRoute\n // Check by default check if the user has a specific lazy route template\n // If not, check if the user has a route template and use that instead\n updatedCacheEntry.fileContent = await fillTemplate(\n this.config,\n (this.config.customScaffolding?.lazyRouteTemplate ||\n this.config.customScaffolding?.routeTemplate) ??\n tLazyRouteTemplate.template(),\n {\n tsrImports: tLazyRouteTemplate.imports.tsrImports(),\n tsrPath: escapedRoutePath.replaceAll(/\\{(.+?)\\}/gm, '$1'),\n tsrExportStart:\n tLazyRouteTemplate.imports.tsrExportStart(escapedRoutePath),\n tsrExportEnd: tLazyRouteTemplate.imports.tsrExportEnd(),\n },\n )\n } else if (\n // Creating a new normal route file\n (['layout', 'static'] satisfies Array<FsRouteType>).some(\n (d) => d === node._fsRouteType,\n ) ||\n (\n [\n 'component',\n 'pendingComponent',\n 'errorComponent',\n 'notFoundComponent',\n 'loader',\n ] satisfies Array<FsRouteType>\n ).every((d) => d !== node._fsRouteType)\n ) {\n const tRouteTemplate = this.targetTemplate.route\n updatedCacheEntry.fileContent = await fillTemplate(\n this.config,\n this.config.customScaffolding?.routeTemplate ??\n tRouteTemplate.template(),\n {\n tsrImports: tRouteTemplate.imports.tsrImports(),\n tsrPath: escapedRoutePath.replaceAll(/\\{(.+?)\\}/gm, '$1'),\n tsrExportStart:\n tRouteTemplate.imports.tsrExportStart(escapedRoutePath),\n tsrExportEnd: tRouteTemplate.imports.tsrExportEnd(),\n },\n )\n } else {\n return null\n }\n }\n\n // Check if this is a Vue component file\n // Vue SFC files (.vue) don't need transformation as they can't have a Route export\n const isVueFile = node.filePath.endsWith('.vue')\n\n if (!isVueFile) {\n // transform the file\n const transformResult = await transform({\n source: updatedCacheEntry.fileContent,\n filename: node.fullPath,\n ctx: {\n target: this.config.target,\n routeId: escapedRoutePath,\n lazy: node._fsRouteType === 'lazy',\n },\n node,\n })\n\n if (transformResult.result === 'no-route-export') {\n const fileName = path.basename(node.fullPath)\n const dirName = path.dirname(node.fullPath)\n const ignorePrefix = this.config.routeFileIgnorePrefix\n const ignorePattern = this.config.routeFileIgnorePattern\n const suggestedFileName = `${ignorePrefix}${fileName}`\n const suggestedFullPath = path.join(dirName, suggestedFileName)\n\n let message = `Warning: Route file \"${node.fullPath}\" does not export a Route. This file will not be included in the route tree.`\n message += `\\n\\nIf this file is not intended to be a route, you can exclude it using one of these options:`\n message += `\\n 1. Rename the file to \"${suggestedFullPath}\" (prefix with \"${ignorePrefix}\")`\n message += `\\n 2. Use 'routeFileIgnorePattern' in your config to match this file`\n message += `\\n\\nCurrent configuration:`\n message += `\\n routeFileIgnorePrefix: \"${ignorePrefix}\"`\n message += `\\n routeFileIgnorePattern: ${ignorePattern ? `\"${ignorePattern}\"` : 'undefined'}`\n\n this.logger.warn(message)\n return null\n }\n if (transformResult.result === 'error') {\n throw new Error(\n `Error transforming route file ${node.fullPath}: ${transformResult.error}`,\n )\n }\n if (transformResult.result === 'modified') {\n updatedCacheEntry.fileContent = transformResult.output\n shouldWriteRouteFile = true\n }\n }\n\n for (const plugin of this.plugins) {\n plugin.afterTransform?.({ node, prevNode: previousCacheEntry?.node })\n }\n\n // file was changed\n if (shouldWriteRouteFile) {\n const stats = await this.safeFileWrite({\n filePath: node.fullPath,\n newContent: updatedCacheEntry.fileContent,\n strategy: {\n type: 'mtime',\n expectedMtimeMs: updatedCacheEntry.mtimeMs,\n },\n })\n updatedCacheEntry.mtimeMs = stats.mtimeMs\n }\n\n this.routeNodeShadowCache.set(node.fullPath, updatedCacheEntry)\n return {\n node,\n shouldWriteTree,\n cacheEntry: updatedCacheEntry,\n }\n }\n\n private async didRouteFileChangeComparedToCache(\n file: {\n path: string\n mtimeMs?: bigint\n },\n cache: 'routeNodeCache' | 'routeNodeShadowCache',\n ): Promise<FileCacheChange<RouteNodeCacheEntry>> {\n const cacheEntry = this[cache].get(file.path)\n return this.didFileChangeComparedToCache(file, cacheEntry)\n }\n\n private async didFileChangeComparedToCache<\n TCacheEntry extends GeneratorCacheEntry,\n >(\n file: {\n path: string\n mtimeMs?: bigint\n },\n cacheEntry: TCacheEntry | undefined,\n ): Promise<FileCacheChange<TCacheEntry>> {\n // for now we rely on the modification time of the file\n // to determine if the file has changed\n // we could also compare the file content but this would be slower as we would have to read the file\n\n if (!cacheEntry) {\n return { result: 'file-not-in-cache' }\n }\n let mtimeMs = file.mtimeMs\n\n if (mtimeMs === undefined) {\n try {\n const currentStat = await this.fs.stat(file.path)\n mtimeMs = currentStat.mtimeMs\n } catch {\n return { result: 'cannot-stat-file' }\n }\n }\n return { result: mtimeMs !== cacheEntry.mtimeMs, mtimeMs, cacheEntry }\n }\n\n private async safeFileWrite(opts: {\n filePath: string\n newContent: string\n strategy:\n | {\n type: 'mtime'\n expectedMtimeMs: bigint\n }\n | {\n type: 'new-file'\n }\n }) {\n const tmpPath = this.getTempFileName(opts.filePath)\n await this.fs.writeFile(tmpPath, opts.newContent)\n\n if (opts.strategy.type === 'mtime') {\n const beforeStat = await this.fs.stat(opts.filePath)\n if (beforeStat.mtimeMs !== opts.strategy.expectedMtimeMs) {\n throw rerun({\n msg: `File ${opts.filePath} was modified by another process during processing.`,\n event: { type: 'update', path: opts.filePath },\n })\n }\n const newFileState = await this.fs.stat(tmpPath)\n if (newFileState.mode !== beforeStat.mode) {\n await this.fs.chmod(tmpPath, beforeStat.mode)\n }\n if (\n newFileState.uid !== beforeStat.uid ||\n newFileState.gid !== beforeStat.gid\n ) {\n try {\n await this.fs.chown(tmpPath, beforeStat.uid, beforeStat.gid)\n } catch (err) {\n if (\n typeof err === 'object' &&\n err !== null &&\n 'code' in err &&\n (err as any).code === 'EPERM'\n ) {\n console.warn(\n `[safeFileWrite] chown failed: ${(err as any).message}`,\n )\n } else {\n throw err\n }\n }\n }\n } else {\n if (await checkFileExists(opts.filePath)) {\n throw rerun({\n msg: `File ${opts.filePath} already exists. Cannot overwrite.`,\n event: { type: 'update', path: opts.filePath },\n })\n }\n }\n\n await this.fs.rename(tmpPath, opts.filePath)\n\n // stat the target file AFTER rename so the cached mtime matches\n // what the filesystem reports for the actual file path.\n // Previously we stat'd the temp file before rename, but rename()\n // can assign a different mtime to the target on some filesystems,\n // causing the cache to be permanently stale.\n const stat = await this.fs.stat(opts.filePath)\n\n return stat\n }\n\n private getTempFileName(filePath: string) {\n const absPath = path.resolve(filePath)\n const hash = crypto.createHash('md5').update(absPath).digest('hex')\n // lazy initialize sessionId to only create tmpDir when it is first needed\n if (!this.sessionId) {\n // ensure the directory exists\n mkdirSync(this.config.tmpDir, { recursive: true })\n this.sessionId = crypto.randomBytes(4).toString('hex')\n }\n return path.join(this.config.tmpDir, `${this.sessionId}-${hash}`)\n }\n\n private async isRouteFileCacheFresh(node: RouteNode): Promise<\n | {\n status: 'fresh'\n cacheEntry: RouteNodeCacheEntry\n }\n | { status: 'stale'; cacheEntry?: RouteNodeCacheEntry }\n > {\n const fileChangedCache = await this.didRouteFileChangeComparedToCache(\n { path: node.fullPath },\n 'routeNodeCache',\n )\n if (fileChangedCache.result === false) {\n this.routeNodeShadowCache.set(node.fullPath, fileChangedCache.cacheEntry)\n return {\n status: 'fresh',\n cacheEntry: fileChangedCache.cacheEntry,\n }\n }\n if (fileChangedCache.result === 'cannot-stat-file') {\n throw new Error(`⚠️ expected route file to exist at ${node.fullPath}`)\n }\n const mtimeMs =\n fileChangedCache.result === true ? fileChangedCache.mtimeMs : undefined\n\n const shadowCacheFileChange = await this.didRouteFileChangeComparedToCache(\n { path: node.fullPath, mtimeMs },\n 'routeNodeShadowCache',\n )\n\n if (shadowCacheFileChange.result === 'cannot-stat-file') {\n throw new Error(`⚠️ expected route file to exist at ${node.fullPath}`)\n }\n\n if (shadowCacheFileChange.result === false) {\n // shadow cache has latest file state already\n if (fileChangedCache.result === true) {\n return {\n status: 'fresh',\n cacheEntry: shadowCacheFileChange.cacheEntry,\n }\n }\n }\n\n if (fileChangedCache.result === 'file-not-in-cache') {\n return {\n status: 'stale',\n }\n }\n return { status: 'stale', cacheEntry: fileChangedCache.cacheEntry }\n }\n\n private async handleRootNode(node: RouteNode) {\n const result = await this.isRouteFileCacheFresh(node)\n\n if (result.status === 'fresh') {\n this.routeNodeShadowCache.set(node.fullPath, result.cacheEntry)\n }\n const rootNodeFile = await this.fs.readFile(node.fullPath)\n if (rootNodeFile === 'file-not-existing') {\n throw new Error(`⚠️ expected root route to exist at ${node.fullPath}`)\n }\n\n const updatedCacheEntry: RouteNodeCacheEntry = {\n fileContent: rootNodeFile.fileContent,\n mtimeMs: rootNodeFile.stat.mtimeMs,\n routeId: node.routePath ?? '$$TSR_NO_ROOT_ROUTE_PATH_ASSIGNED$$',\n node,\n }\n\n // scaffold the root route\n if (!rootNodeFile.fileContent) {\n const rootTemplate = this.targetTemplate.rootRoute\n const rootRouteContent = await fillTemplate(\n this.config,\n rootTemplate.template(),\n {\n tsrImports: rootTemplate.imports.tsrImports(),\n tsrPath: rootPathId,\n tsrExportStart: rootTemplate.imports.tsrExportStart(),\n tsrExportEnd: rootTemplate.imports.tsrExportEnd(),\n },\n )\n\n this.logger.log(`🟡 Creating ${node.fullPath}`)\n const stats = await this.safeFileWrite({\n filePath: node.fullPath,\n newContent: rootRouteContent,\n strategy: {\n type: 'mtime',\n expectedMtimeMs: rootNodeFile.stat.mtimeMs,\n },\n })\n updatedCacheEntry.fileContent = rootRouteContent\n updatedCacheEntry.mtimeMs = stats.mtimeMs\n }\n\n this.routeNodeShadowCache.set(node.fullPath, updatedCacheEntry)\n }\n\n public async getCrawlingResult(): Promise<CrawlingResult | undefined> {\n await this.runPromise\n return this.crawlingResult\n }\n\n private static handleNode(\n node: RouteNode,\n acc: HandleNodeAccumulator,\n prefixMap: RoutePrefixMap,\n config?: Config,\n ) {\n let parentRoute = hasParentRoute(prefixMap, node, node.routePath)\n\n // Check routeNodesByPath for a closer parent that may not be in prefixMap.\n //\n // Why: The prefixMap excludes lazy routes by design. When lazy-only routes are\n // nested inside a pathless layout, the virtual route created from the lazy file\n // won't be in the prefixMap, but it will be in routeNodesByPath.\n //\n // Example: Given files _layout/path.lazy.tsx and _layout/path.index.lazy.tsx:\n // - prefixMap contains: /_layout (from route.tsx)\n // - routeNodesByPath contains: /_layout AND /_layout/path (virtual from lazy)\n // - For /_layout/path/, hasParentRoute returns /_layout (wrong)\n // - But the correct parent is /_layout/path (the virtual route from path.lazy.tsx)\n //\n // We walk up the path segments to find the closest registered parent. This handles\n // cases where multiple path segments (e.g., $a/$b) don't have intermediate routes.\n if (node.routePath) {\n let searchPath = node.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 candidate = acc.routeNodesByPath.get(searchPath)\n if (candidate && candidate.routePath !== node.routePath) {\n // Found a parent in routeNodesByPath\n // If it's different from what prefixMap found AND is a closer match, use it\n if (candidate !== parentRoute) {\n // Check if this candidate is a closer parent than what prefixMap found\n // (longer path prefix means closer parent)\n if (\n !parentRoute ||\n (candidate.routePath?.length ?? 0) >\n (parentRoute.routePath?.length ?? 0)\n ) {\n parentRoute = candidate\n }\n }\n break\n }\n }\n }\n\n // Virtual routes may have an explicit parent from virtual config.\n // If we can find that exact parent, use it to prevent auto-nesting siblings\n // based on path prefix matching (#5822, #5431).\n if (node._virtualParentRoutePath !== undefined) {\n const explicitParent = acc.routeNodesByPath.get(\n node._virtualParentRoutePath,\n )\n if (explicitParent) {\n parentRoute = explicitParent\n } else if (node._virtualParentRoutePath === `/${rootPathId}`) {\n // The explicit parent is the root route (handled separately).\n // Override path-based inference so this node stays at root level.\n parentRoute = null\n }\n // Otherwise the explicit parent was a virtual file-less route that got\n // filtered out. Fall back to the path-based parentRoute already computed.\n }\n\n if (parentRoute) node.parent = parentRoute\n\n node.path = determineNodePath(node)\n\n const trimmedPath = trimPathLeft(node.path ?? '')\n const originalPath =\n node.originalRoutePath && node.parent?.originalRoutePath\n ? node.originalRoutePath.replace(node.parent.originalRoutePath, '') ||\n '/'\n : node.originalRoutePath\n const routePathSegmentMetadata = getRoutePathSegmentMetadataForPath(\n node,\n node.path ?? '/',\n node.parent?.routePath,\n )\n const trimmedOriginalPath = trimPathLeft(originalPath ?? '')\n\n const split = trimmedPath.split('/')\n const pathSplit = (node.path ?? '').split('/')\n const originalSplit = trimmedOriginalPath.split('/')\n const lastRouteSegment = split[split.length - 1] ?? trimmedPath\n const lastOriginalSegment =\n originalSplit[originalSplit.length - 1] ?? trimmedOriginalPath\n const lastRouteSegmentMetadata =\n routePathSegmentMetadata?.[pathSplit.length - 1]\n\n // A segment is non-path if it starts with underscore AND the underscore is not escaped\n node.isNonPath =\n (!lastRouteSegmentMetadata?.literalLeadingUnderscore &&\n isSegmentPathless(lastRouteSegment, lastOriginalSegment)) ||\n split.every((part) => this.routeGroupPatternRegex.test(part))\n\n // Use a single pass so layout removal does not desync escaped underscore checks.\n node.cleanedPath = removeGroups(\n removeLayoutSegmentsAndUnderscoresWithEscape(\n node.path,\n originalPath,\n routePathSegmentMetadata,\n ),\n )\n\n if (\n node._fsRouteType === 'layout' ||\n node._fsRouteType === 'pathless_layout'\n ) {\n node.cleanedPath = removeTrailingSlash(node.cleanedPath)\n }\n\n if (\n !node.isVirtual &&\n (\n [\n 'lazy',\n 'loader',\n 'component',\n 'pendingComponent',\n 'errorComponent',\n 'notFoundComponent',\n ] satisfies Array<FsRouteType>\n ).some((d) => d === node._fsRouteType)\n ) {\n acc.routePiecesByPath[node.routePath!] =\n acc.routePiecesByPath[node.routePath!] || {}\n\n const pieceKey =\n node._fsRouteType === 'lazy'\n ? 'lazy'\n : (node._fsRouteType as keyof (typeof acc.routePiecesByPath)[string])\n acc.routePiecesByPath[node.routePath!]![pieceKey] = node\n\n const anchorRoute = acc.routeNodesByPath.get(node.routePath!)\n\n // Don't create virtual routes for root route component pieces - the root route is handled separately\n if (!anchorRoute && node.routePath !== `/${rootPathId}`) {\n this.handleNode(\n {\n ...node,\n isVirtual: true,\n _fsRouteType: 'static',\n },\n acc,\n prefixMap,\n config,\n )\n }\n return\n }\n\n const isPathlessLayoutWithPath =\n node._fsRouteType === 'pathless_layout' &&\n node.cleanedPath &&\n node.cleanedPath.length > 0\n\n // Special handling: pathless layouts with path need to find real ancestor\n if (!node.isVirtual && isPathlessLayoutWithPath) {\n const immediateParentPath =\n removeLastSegmentFromPath(node.routePath) || '/'\n const immediateParentOriginalPath =\n removeLastSegmentFromPath(node.originalRoutePath) || '/'\n let searchPath = immediateParentPath\n\n // Find nearest real (non-virtual, non-index) parent\n while (searchPath) {\n const candidate = acc.routeNodesByPath.get(searchPath)\n if (candidate && !candidate.isVirtual && candidate.path !== '/') {\n node.parent = candidate\n node.path =\n node.routePath?.replace(candidate.routePath ?? '', '') || '/'\n const pathRelativeToParent =\n immediateParentPath.replace(candidate.routePath ?? '', '') || '/'\n const originalPathRelativeToParent =\n immediateParentOriginalPath.replace(\n candidate.originalRoutePath ?? '',\n '',\n ) || '/'\n const routePathSegmentMetadataRelativeToParent =\n getRoutePathSegmentMetadataForPath(\n node,\n pathRelativeToParent,\n candidate.routePath,\n )\n node.cleanedPath = removeGroups(\n removeLayoutSegmentsAndUnderscoresWithEscape(\n pathRelativeToParent,\n originalPathRelativeToParent,\n routePathSegmentMetadataRelativeToParent,\n ),\n )\n break\n }\n if (searchPath === '/') break\n searchPath = removeLastSegmentFromPath(searchPath) || '/'\n }\n }\n\n // Add to parent's children or to root\n if (node.parent) {\n node.parent.children = node.parent.children ?? []\n node.parent.children.push(node)\n } else {\n acc.routeTree.push(node)\n }\n\n acc.routeNodes.push(node)\n if (node.routePath) {\n // Always register routes by path so child routes can find parents.\n // Virtual routes (created from lazy-only files) also need to be registered\n // so that index routes like path.index.lazy.tsx can find their parent path.lazy.tsx.\n // If a non-virtual route is later processed for the same path, it will overwrite.\n acc.routeNodesByPath.set(node.routePath, node)\n }\n }\n\n // only process files that are relevant for the route tree generation\n private isFileRelevantForRouteTreeGeneration(filePath: string): boolean {\n // the generated route tree file\n if (filePath === this.generatedRouteTreePath) {\n return true\n }\n\n // files inside the routes folder\n if (filePath.startsWith(this.routesDirectoryPath)) {\n return true\n }\n\n // the virtual route config file passed into `virtualRouteConfig`\n if (\n typeof this.config.virtualRouteConfig === 'string' &&\n filePath === this.config.virtualRouteConfig\n ) {\n return true\n }\n\n // this covers all files that are mounted via `virtualRouteConfig` or any `__virtual.ts` files\n if (this.routeNodeCache.has(filePath)) {\n return true\n }\n\n // virtual config files such as`__virtual.ts`\n if (isVirtualConfigFile(path.basename(filePath))) {\n return true\n }\n\n // route files inside directories mounted via `physical()` inside a virtual route config\n if (this.physicalDirectories.some((dir) => filePath.startsWith(dir))) {\n return true\n }\n\n return false\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AA2EA,SAAS,mCACP,MACA,W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AIT,IACE,OAAO,KAAK,OAAO,uBAAuB,YAC1C,aAAa,KAAK,OAAO,oBAEzB,OAAO;EAIT,IAAI,KAAK,eAAe,IAAI,QAAQ,GAClC,OAAO;EAIT,IAAIC,wBAAAA,oBAAoBnC,UAAAA,QAAK,SAAS,QAAQ,CAAC,GAC7C,OAAO;EAIT,IAAI,KAAK,oBAAoB,MAAM,QAAQ,SAAS,WAAW,GAAG,CAAC,GACjE,OAAO;EAGT,OAAO;CACT;AACF"}
1
+ {"version":3,"file":"generator.cjs","names":["countRoutePathSegments","fsp","logging","getTargetTemplate","createTokenRegex","path","existsSync","virtualGetRouteNodes","physicalGetRouteNodes","rootPathId","multiSortBy","countSlashSeparatedParts","RoutePrefixMap","format","sortRouteNodes","getImportForRouteNode","buildRouteTreeConfig","findParent","replaceBackslash","removeExt","createRouteNodesByFullPath","createRouteNodesByTo","createRouteNodesById","getResolvedRouteNodeVariableName","rootRouteId","buildFileRoutesByPathInterface","mergeImportDeclarations","buildImportString","fillTemplate","transform","checkFileExists","crypto","hasParentRoute","determineNodePath","trimPathLeft","isSegmentPathless","removeGroups","removeLayoutSegmentsAndUnderscoresWithEscape","removeTrailingSlash","removeLastSegmentFromPath","isVirtualConfigFile"],"sources":["../../src/generator.ts"],"sourcesContent":["import path from 'node:path'\nimport * as fsp from 'node:fs/promises'\nimport { existsSync, mkdirSync } from 'node:fs'\nimport crypto from 'node:crypto'\nimport { rootRouteId } from '@tanstack/router-core'\nimport { logging } from './logger'\nimport {\n isVirtualConfigFile,\n getRouteNodes as physicalGetRouteNodes,\n} from './filesystem/physical/getRouteNodes'\nimport { getRouteNodes as virtualGetRouteNodes } from './filesystem/virtual/getRouteNodes'\nimport { rootPathId } from './filesystem/physical/rootPathId'\nimport {\n RoutePrefixMap,\n buildFileRoutesByPathInterface,\n buildImportString,\n buildRouteTreeConfig,\n checkFileExists,\n checkRouteFullPathUniqueness,\n countRoutePathSegments,\n countSlashSeparatedParts,\n createRouteNodesByFullPath,\n createRouteNodesById,\n createRouteNodesByTo,\n createTokenRegex,\n determineNodePath,\n findParent,\n format,\n getImportForRouteNode,\n getResolvedRouteNodeVariableName,\n hasParentRoute,\n isSegmentPathless,\n mergeImportDeclarations,\n multiSortBy,\n removeExt,\n removeGroups,\n removeLastSegmentFromPath,\n removeLayoutSegmentsAndUnderscoresWithEscape,\n removeTrailingSlash,\n replaceBackslash,\n sortRouteNodes,\n trimPathLeft,\n} from './utils'\nimport { fillTemplate, getTargetTemplate } from './template'\nimport { transform } from './transform/transform'\nimport { validateRouteParams } from './validate-route-params'\nimport type { GeneratorPlugin } from './plugin/types'\nimport type { TargetTemplate } from './template'\nimport type {\n FsRouteType,\n GetRouteNodesResult,\n GetRoutesByFileMapResult,\n HandleNodeAccumulator,\n ImportDeclaration,\n RouteNode,\n RoutePathSegmentMetadata,\n} from './types'\nimport type { Config } from './config'\nimport type { Logger } from './logger'\n\ninterface fs {\n stat: (\n filePath: string,\n ) => Promise<{ mtimeMs: bigint; mode: number; uid: number; gid: number }>\n rename: (oldPath: string, newPath: string) => Promise<void>\n writeFile: (filePath: string, content: string) => Promise<void>\n readFile: (\n filePath: string,\n ) => Promise<\n { stat: { mtimeMs: bigint }; fileContent: string } | 'file-not-existing'\n >\n chmod: (filePath: string, mode: number) => Promise<void>\n chown: (filePath: string, uid: number, gid: number) => Promise<void>\n}\n\nfunction getRoutePathSegmentMetadataForPath(\n node: RouteNode,\n routePath: string,\n parentRoutePath?: string,\n): Array<RoutePathSegmentMetadata | undefined> | undefined {\n if (!node._routePathSegmentMetadata) return undefined\n\n const segments = routePath.split('/')\n const result = new Array<RoutePathSegmentMetadata | undefined>(\n segments.length,\n )\n const parentSegmentCount = countRoutePathSegments(parentRoutePath)\n let hasMetadata = false\n let segmentCount = 0\n\n for (let i = 0; i < segments.length; i++) {\n if (!segments[i]) continue\n const sourceIndex = parentSegmentCount + segmentCount + 1\n result[i] = node._routePathSegmentMetadata[sourceIndex]\n hasMetadata ||= !!result[i]\n segmentCount++\n }\n\n return hasMetadata ? result : undefined\n}\n\nconst DefaultFileSystem: fs = {\n stat: async (filePath) => {\n const res = await fsp.stat(filePath, { bigint: true })\n return {\n mtimeMs: res.mtimeMs,\n mode: Number(res.mode),\n uid: Number(res.uid),\n gid: Number(res.gid),\n }\n },\n rename: (oldPath, newPath) => fsp.rename(oldPath, newPath),\n writeFile: (filePath, content) => fsp.writeFile(filePath, content),\n readFile: async (filePath: string) => {\n try {\n const fileHandle = await fsp.open(filePath, 'r')\n const stat = await fileHandle.stat({ bigint: true })\n const fileContent = (await fileHandle.readFile()).toString()\n await fileHandle.close()\n return { stat, fileContent }\n } catch (e: any) {\n if ('code' in e) {\n if (e.code === 'ENOENT') {\n return 'file-not-existing'\n }\n }\n throw e\n }\n },\n chmod: (filePath, mode) => fsp.chmod(filePath, mode),\n chown: (filePath, uid, gid) => fsp.chown(filePath, uid, gid),\n}\n\ninterface Rerun {\n rerun: true\n msg?: string\n event: GeneratorEvent\n}\nfunction rerun(opts: { msg?: string; event?: GeneratorEvent }): Rerun {\n const { event, ...rest } = opts\n return { rerun: true, event: event ?? { type: 'rerun' }, ...rest }\n}\n\nfunction isRerun(result: unknown): result is Rerun {\n return (\n typeof result === 'object' &&\n result !== null &&\n 'rerun' in result &&\n result.rerun === true\n )\n}\n\nexport type FileEventType = 'create' | 'update' | 'delete'\nexport type FileEvent = {\n type: FileEventType\n path: string\n}\nexport type GeneratorEvent = FileEvent | { type: 'rerun' }\n\ntype FileCacheChange<TCacheEntry extends GeneratorCacheEntry> =\n | {\n result: false\n cacheEntry: TCacheEntry\n }\n | { result: true; mtimeMs: bigint; cacheEntry: TCacheEntry }\n | {\n result: 'file-not-in-cache'\n }\n | {\n result: 'cannot-stat-file'\n }\n\ninterface GeneratorCacheEntry {\n mtimeMs: bigint\n fileContent: string\n}\n\ninterface RouteNodeCacheEntry extends GeneratorCacheEntry {\n routeId: string\n node: RouteNode\n}\n\ntype GeneratorRouteNodeCache = Map</** filePath **/ string, RouteNodeCacheEntry>\n\ninterface CrawlingResult {\n rootRouteNode: RouteNode\n routeFileResult: Array<RouteNode>\n acc: HandleNodeAccumulator\n}\n\nexport class Generator {\n /**\n * why do we have two caches for the route files?\n * During processing, we READ from the cache and WRITE to the shadow cache.\n *\n * After a route file is processed, we write to the shadow cache.\n * If during processing we bail out and re-run, we don't lose this modification\n * but still can track whether the file contributed changes and thus the route tree file needs to be regenerated.\n * After all files are processed, we swap the shadow cache with the main cache and initialize a new shadow cache.\n * That way we also ensure deleted/renamed files don't stay in the cache forever.\n */\n private routeNodeCache: GeneratorRouteNodeCache = new Map()\n private routeNodeShadowCache: GeneratorRouteNodeCache = new Map()\n\n private routeTreeFileCache: GeneratorCacheEntry | undefined\n\n private crawlingResult: CrawlingResult | undefined\n public config: Config\n public targetTemplate: TargetTemplate\n\n private root: string\n private routesDirectoryPath: string\n private sessionId?: string\n private fs: fs\n private logger: Logger\n private generatedRouteTreePath: string\n private runPromise: Promise<void> | undefined\n private fileEventQueue: Array<GeneratorEvent> = []\n private plugins: Array<GeneratorPlugin> = []\n private static routeGroupPatternRegex = /\\(.+\\)/\n private physicalDirectories: Array<string> = []\n\n /**\n * Token regexes are pre-compiled once here and reused throughout route processing.\n * We need TWO types of regex for each token because they match against different inputs:\n *\n * 1. FILENAME regexes: Match token patterns within full file path strings.\n * Example: For file \"routes/dashboard.index.tsx\", we want to detect \".index.\"\n * Pattern: `[./](?:token)[.]` - matches token bounded by path separators/dots\n * Used in: sorting route nodes by file path\n *\n * 2. SEGMENT regexes: Match token against a single logical route segment.\n * Example: For segment \"index\" (extracted from path), match the whole segment\n * Pattern: `^(?:token)$` - matches entire segment exactly\n * Used in: route parsing, determining route types, escape detection\n *\n * We cannot reuse one for the other without false positives or missing matches.\n */\n private indexTokenFilenameRegex: RegExp\n private routeTokenFilenameRegex: RegExp\n private indexTokenSegmentRegex: RegExp\n private routeTokenSegmentRegex: RegExp\n private static componentPieceRegex =\n /[./](component|errorComponent|notFoundComponent|pendingComponent|loader|lazy)[.]/\n\n constructor(opts: { config: Config; root: string; fs?: fs }) {\n this.config = opts.config\n this.logger = logging({ disabled: this.config.disableLogging })\n this.root = opts.root\n this.fs = opts.fs || DefaultFileSystem\n this.generatedRouteTreePath = this.getGeneratedRouteTreePath()\n this.targetTemplate = getTargetTemplate(this.config)\n\n this.routesDirectoryPath = this.getRoutesDirectoryPath()\n this.plugins.push(...(opts.config.plugins || []))\n\n // Create all token regexes once in constructor\n this.indexTokenFilenameRegex = createTokenRegex(this.config.indexToken, {\n type: 'filename',\n })\n this.routeTokenFilenameRegex = createTokenRegex(this.config.routeToken, {\n type: 'filename',\n })\n this.indexTokenSegmentRegex = createTokenRegex(this.config.indexToken, {\n type: 'segment',\n })\n this.routeTokenSegmentRegex = createTokenRegex(this.config.routeToken, {\n type: 'segment',\n })\n\n for (const plugin of this.plugins) {\n plugin.init?.({ generator: this })\n }\n }\n\n private getGeneratedRouteTreePath() {\n const generatedRouteTreePath = path.isAbsolute(\n this.config.generatedRouteTree,\n )\n ? this.config.generatedRouteTree\n : path.resolve(this.root, this.config.generatedRouteTree)\n\n const generatedRouteTreeDir = path.dirname(generatedRouteTreePath)\n\n if (!existsSync(generatedRouteTreeDir)) {\n mkdirSync(generatedRouteTreeDir, { recursive: true })\n }\n\n return generatedRouteTreePath\n }\n\n private getRoutesDirectoryPath() {\n return path.isAbsolute(this.config.routesDirectory)\n ? this.config.routesDirectory\n : path.resolve(this.root, this.config.routesDirectory)\n }\n\n public getRoutesByFileMap(): GetRoutesByFileMapResult {\n return new Map(\n [...this.routeNodeCache.entries()].map(([filePath, cacheEntry]) => [\n filePath,\n { routeId: cacheEntry.routeId },\n ]),\n )\n }\n\n public async run(event?: GeneratorEvent): Promise<void> {\n if (\n event &&\n event.type !== 'rerun' &&\n !this.isFileRelevantForRouteTreeGeneration(event.path)\n ) {\n return\n }\n this.fileEventQueue.push(event ?? { type: 'rerun' })\n // only allow a single run at a time\n if (this.runPromise) {\n return this.runPromise\n }\n\n this.runPromise = (async () => {\n do {\n // synchronously copy and clear the queue since we are going to iterate asynchronously over it\n // and while we do so, a new event could be put into the queue\n const tempQueue = this.fileEventQueue\n this.fileEventQueue = []\n // if we only have 'update' events in the queue\n // and we already have the affected files' latest state in our cache, we can exit early\n const remainingEvents = (\n await Promise.all(\n tempQueue.map(async (e) => {\n if (e.type === 'update') {\n let cacheEntry: GeneratorCacheEntry | undefined\n if (e.path === this.generatedRouteTreePath) {\n cacheEntry = this.routeTreeFileCache\n } else {\n // we only check the routeNodeCache here\n // if the file's state is only up-to-date in the shadow cache we need to re-run\n cacheEntry = this.routeNodeCache.get(e.path)\n }\n const change = await this.didFileChangeComparedToCache(\n { path: e.path },\n cacheEntry,\n )\n if (change.result === false) {\n return null\n }\n }\n return e\n }),\n )\n ).filter((e) => e !== null)\n\n if (remainingEvents.length === 0) {\n break\n }\n\n try {\n await this.generatorInternal()\n } catch (err) {\n const errArray = !Array.isArray(err) ? [err] : err\n\n const recoverableErrors = errArray.filter((e) => isRerun(e))\n if (recoverableErrors.length === errArray.length) {\n this.fileEventQueue.push(...recoverableErrors.map((e) => e.event))\n recoverableErrors.forEach((e) => {\n if (e.msg) {\n this.logger.info(e.msg)\n }\n })\n } else {\n const unrecoverableErrors = errArray.filter((e) => !isRerun(e))\n this.runPromise = undefined\n throw new Error(\n unrecoverableErrors.map((e) => (e as Error).message).join(),\n )\n }\n }\n } while (this.fileEventQueue.length)\n this.runPromise = undefined\n })()\n return this.runPromise\n }\n\n private async generatorInternal() {\n let writeRouteTreeFile: boolean | 'force' = false\n\n let getRouteNodesResult: GetRouteNodesResult\n\n if (this.config.virtualRouteConfig) {\n getRouteNodesResult = await virtualGetRouteNodes(this.config, this.root, {\n indexTokenSegmentRegex: this.indexTokenSegmentRegex,\n routeTokenSegmentRegex: this.routeTokenSegmentRegex,\n })\n } else {\n getRouteNodesResult = await physicalGetRouteNodes(\n this.config,\n this.root,\n {\n indexTokenSegmentRegex: this.indexTokenSegmentRegex,\n routeTokenSegmentRegex: this.routeTokenSegmentRegex,\n },\n )\n }\n\n const {\n rootRouteNode,\n routeNodes: beforeRouteNodes,\n physicalDirectories,\n } = getRouteNodesResult\n if (rootRouteNode === undefined) {\n let errorMessage = `rootRouteNode must not be undefined. Make sure you've added your root route into the route-tree.`\n if (!this.config.virtualRouteConfig) {\n errorMessage += `\\nMake sure that you add a \"${rootPathId}.${this.config.disableTypes ? 'js' : 'tsx'}\" file to your routes directory.\\nAdd the file in: \"${this.config.routesDirectory}/${rootPathId}.${this.config.disableTypes ? 'js' : 'tsx'}\"`\n }\n throw new Error(errorMessage)\n }\n this.physicalDirectories = physicalDirectories\n\n await this.handleRootNode(rootRouteNode)\n\n const preRouteNodes = multiSortBy(beforeRouteNodes, [\n (d) => (d.routePath === '/' ? -1 : 1),\n (d) =>\n d.routePath === undefined\n ? undefined\n : countSlashSeparatedParts(d.routePath),\n (d) => (d.filePath.match(this.indexTokenFilenameRegex) ? 1 : -1),\n (d) => (d.filePath.match(Generator.componentPieceRegex) ? 1 : -1),\n (d) => (d.filePath.match(this.routeTokenFilenameRegex) ? -1 : 1),\n (d) => (d.routePath?.endsWith('/') ? -1 : 1),\n (d) => d.routePath,\n ]).filter((d) => {\n // Exclude the root route itself, but keep component/loader pieces for the root\n if (d.routePath === `/${rootPathId}`) {\n return [\n 'component',\n 'errorComponent',\n 'notFoundComponent',\n 'pendingComponent',\n 'loader',\n 'lazy',\n ].includes(d._fsRouteType)\n }\n return true\n })\n\n const routeFileAllResult = await Promise.allSettled(\n preRouteNodes\n // only process routes that are backed by an actual file\n .filter((n) => !n.isVirtualParentRoute && !n.isVirtual)\n .map((n) => this.processRouteNodeFile(n)),\n )\n\n const rejections = routeFileAllResult.filter(\n (result) => result.status === 'rejected',\n )\n if (rejections.length > 0) {\n throw rejections.map((e) => e.reason)\n }\n\n const routeFileResult = routeFileAllResult.flatMap((result) => {\n if (result.status === 'fulfilled' && result.value !== null) {\n if (result.value.shouldWriteTree) {\n writeRouteTreeFile = true\n }\n return result.value.node\n }\n return []\n })\n\n // reset children in case we re-use a node from the cache\n routeFileResult.forEach((r) => (r.children = undefined))\n\n const acc: HandleNodeAccumulator = {\n routeTree: [],\n routeNodes: [],\n routePiecesByPath: {},\n routeNodesByPath: new Map(),\n }\n\n const prefixMap = new RoutePrefixMap(routeFileResult)\n\n for (const node of routeFileResult) {\n Generator.handleNode(node, acc, prefixMap, this.config)\n }\n\n this.crawlingResult = { rootRouteNode, routeFileResult, acc }\n\n // this is the first time the generator runs, so read in the route tree file if it exists yet\n if (!this.routeTreeFileCache) {\n const routeTreeFile = await this.fs.readFile(this.generatedRouteTreePath)\n if (routeTreeFile !== 'file-not-existing') {\n this.routeTreeFileCache = {\n fileContent: routeTreeFile.fileContent,\n mtimeMs: routeTreeFile.stat.mtimeMs,\n }\n }\n writeRouteTreeFile = true\n } else {\n const routeTreeFileChange = await this.didFileChangeComparedToCache(\n { path: this.generatedRouteTreePath },\n this.routeTreeFileCache,\n )\n if (routeTreeFileChange.result !== false) {\n writeRouteTreeFile = 'force'\n if (routeTreeFileChange.result === true) {\n const routeTreeFile = await this.fs.readFile(\n this.generatedRouteTreePath,\n )\n if (routeTreeFile !== 'file-not-existing') {\n this.routeTreeFileCache = {\n fileContent: routeTreeFile.fileContent,\n mtimeMs: routeTreeFile.stat.mtimeMs,\n }\n }\n }\n }\n }\n\n if (!writeRouteTreeFile) {\n // only needs to be done if no other changes have been detected yet\n // compare shadowCache and cache to identify deleted routes\n if (this.routeNodeCache.size !== this.routeNodeShadowCache.size) {\n writeRouteTreeFile = true\n } else {\n for (const fullPath of this.routeNodeCache.keys()) {\n if (!this.routeNodeShadowCache.has(fullPath)) {\n writeRouteTreeFile = true\n break\n }\n }\n }\n }\n\n if (!writeRouteTreeFile) {\n this.swapCaches()\n return\n }\n\n const buildResult = this.buildRouteTree({\n rootRouteNode,\n acc,\n routeFileResult,\n })\n let routeTreeContent = buildResult.routeTreeContent\n\n routeTreeContent = this.config.enableRouteTreeFormatting\n ? await format(routeTreeContent, this.config)\n : routeTreeContent\n\n let newMtimeMs: bigint | undefined\n if (this.routeTreeFileCache) {\n if (this.routeTreeFileCache.fileContent === routeTreeContent) {\n // existing route tree file is already up-to-date, don't write it.\n // When 'force' was set because an external change was detected,\n // we still re-read and re-check here, but if the generated content\n // matches we skip the write to avoid triggering another watcher cycle.\n } else {\n const newRouteTreeFileStat = await this.safeFileWrite({\n filePath: this.generatedRouteTreePath,\n newContent: routeTreeContent,\n strategy: {\n type: 'mtime',\n expectedMtimeMs: this.routeTreeFileCache.mtimeMs,\n },\n })\n newMtimeMs = newRouteTreeFileStat.mtimeMs\n }\n } else {\n const newRouteTreeFileStat = await this.safeFileWrite({\n filePath: this.generatedRouteTreePath,\n newContent: routeTreeContent,\n strategy: {\n type: 'new-file',\n },\n })\n newMtimeMs = newRouteTreeFileStat.mtimeMs\n }\n\n if (newMtimeMs !== undefined) {\n this.routeTreeFileCache = {\n fileContent: routeTreeContent,\n mtimeMs: newMtimeMs,\n }\n }\n\n this.plugins.map((plugin) => {\n return plugin.onRouteTreeChanged?.({\n routeTree: buildResult.routeTree,\n routeNodes: buildResult.routeNodes,\n acc,\n rootRouteNode,\n })\n })\n this.swapCaches()\n }\n\n private swapCaches() {\n this.routeNodeCache = this.routeNodeShadowCache\n this.routeNodeShadowCache = new Map()\n }\n\n public buildRouteTree(opts: {\n rootRouteNode: RouteNode\n acc: HandleNodeAccumulator\n routeFileResult: Array<RouteNode>\n config?: Partial<Config>\n }) {\n const config = { ...this.config, ...(opts.config || {}) }\n\n const { rootRouteNode, acc } = opts\n\n // Use pre-compiled regex if config hasn't been overridden, otherwise create new one\n const indexTokenSegmentRegex =\n config.indexToken === this.config.indexToken\n ? this.indexTokenSegmentRegex\n : createTokenRegex(config.indexToken, { type: 'segment' })\n\n const sortedRouteNodes = sortRouteNodes(\n acc.routeNodes,\n indexTokenSegmentRegex,\n )\n\n const routeImports: Array<ImportDeclaration> = []\n const virtualRouteNodes: Array<string> = []\n\n for (const node of sortedRouteNodes) {\n if (node.isVirtual) {\n virtualRouteNodes.push(\n `const ${node.variableName}RouteImport = createFileRoute('${node.routePath}')()`,\n )\n } else {\n routeImports.push(\n getImportForRouteNode(\n node,\n config,\n this.generatedRouteTreePath,\n this.root,\n ),\n )\n }\n }\n\n const imports: Array<ImportDeclaration> = []\n if (virtualRouteNodes.length > 0) {\n imports.push({\n specifiers: [{ imported: 'createFileRoute' }],\n source: this.targetTemplate.fullPkg,\n })\n }\n // Add lazyRouteComponent import if there are component pieces\n let hasComponentPieces = false\n let hasLoaderPieces = false\n for (const node of sortedRouteNodes) {\n const pieces = acc.routePiecesByPath[node.routePath!]\n if (pieces) {\n if (\n pieces.component ||\n pieces.errorComponent ||\n pieces.notFoundComponent ||\n pieces.pendingComponent\n ) {\n hasComponentPieces = true\n }\n if (pieces.loader) {\n hasLoaderPieces = true\n }\n if (hasComponentPieces && hasLoaderPieces) break\n }\n }\n if (hasComponentPieces || hasLoaderPieces) {\n const runtimeImport: ImportDeclaration = {\n specifiers: [],\n source: this.targetTemplate.fullPkg,\n }\n if (hasComponentPieces) {\n runtimeImport.specifiers.push({ imported: 'lazyRouteComponent' })\n }\n if (hasLoaderPieces) {\n runtimeImport.specifiers.push({ imported: 'lazyFn' })\n }\n imports.push(runtimeImport)\n }\n const routeTreeConfig = buildRouteTreeConfig(\n acc.routeTree,\n config.disableTypes,\n )\n\n const createUpdateRoutes = sortedRouteNodes.map((node) => {\n const pieces = acc.routePiecesByPath[node.routePath!]\n const loaderNode = pieces?.loader\n const componentNode = pieces?.component\n const errorComponentNode = pieces?.errorComponent\n const notFoundComponentNode = pieces?.notFoundComponent\n const pendingComponentNode = pieces?.pendingComponent\n const lazyComponentNode = pieces?.lazy\n\n return [\n [\n `const ${node.variableName}Route = ${node.variableName}RouteImport.update({\n ${[\n `id: '${node.path}'`,\n !node.isNonPath ||\n (node._fsRouteType === 'pathless_layout' && node.cleanedPath)\n ? `path: '${node.cleanedPath}'`\n : undefined,\n `getParentRoute: () => ${findParent(node)}`,\n ]\n .filter(Boolean)\n .join(',')}\n }${config.disableTypes ? '' : 'as any'})`,\n loaderNode\n ? `.updateLoader({ loader: lazyFn(() => import('./${replaceBackslash(\n removeExt(\n path.relative(\n path.dirname(config.generatedRouteTree),\n path.resolve(config.routesDirectory, loaderNode.filePath),\n ),\n config.addExtensions,\n ),\n )}'), 'loader') })`\n : '',\n componentNode ||\n errorComponentNode ||\n notFoundComponentNode ||\n pendingComponentNode\n ? `.update({\n ${(\n [\n ['component', componentNode],\n ['errorComponent', errorComponentNode],\n ['notFoundComponent', notFoundComponentNode],\n ['pendingComponent', pendingComponentNode],\n ] as const\n )\n .filter((d) => d[1])\n .map((d) => {\n // For .vue files, use 'default' as the export name since Vue SFCs export default\n const isVueFile = d[1]!.filePath.endsWith('.vue')\n const exportName = isVueFile ? 'default' : d[0]\n // Keep .vue extension for Vue files since Vite requires it\n const importPath = replaceBackslash(\n isVueFile\n ? path.relative(\n path.dirname(config.generatedRouteTree),\n path.resolve(\n config.routesDirectory,\n d[1]!.filePath,\n ),\n )\n : removeExt(\n path.relative(\n path.dirname(config.generatedRouteTree),\n path.resolve(\n config.routesDirectory,\n d[1]!.filePath,\n ),\n ),\n config.addExtensions,\n ),\n )\n return `${\n d[0]\n }: lazyRouteComponent(() => import('./${importPath}'), '${exportName}')`\n })\n .join('\\n,')}\n })`\n : '',\n lazyComponentNode\n ? (() => {\n // For .vue files, use 'default' export since Vue SFCs export default\n const isVueFile = lazyComponentNode.filePath.endsWith('.vue')\n const exportAccessor = isVueFile ? 'd.default' : 'd.Route'\n // Keep .vue extension for Vue files since Vite requires it\n const importPath = replaceBackslash(\n isVueFile\n ? path.relative(\n path.dirname(config.generatedRouteTree),\n path.resolve(\n config.routesDirectory,\n lazyComponentNode.filePath,\n ),\n )\n : removeExt(\n path.relative(\n path.dirname(config.generatedRouteTree),\n path.resolve(\n config.routesDirectory,\n lazyComponentNode.filePath,\n ),\n ),\n config.addExtensions,\n ),\n )\n return `.lazy(() => import('./${importPath}').then((d) => ${exportAccessor}))`\n })()\n : '',\n ].join(''),\n ].join('\\n\\n')\n })\n\n // Generate update for root route if it has component pieces\n const rootRoutePath = `/${rootPathId}`\n const rootPieces = acc.routePiecesByPath[rootRoutePath]\n const rootComponentNode = rootPieces?.component\n const rootErrorComponentNode = rootPieces?.errorComponent\n const rootNotFoundComponentNode = rootPieces?.notFoundComponent\n const rootPendingComponentNode = rootPieces?.pendingComponent\n\n let rootRouteUpdate = ''\n if (\n rootComponentNode ||\n rootErrorComponentNode ||\n rootNotFoundComponentNode ||\n rootPendingComponentNode\n ) {\n rootRouteUpdate = `const rootRouteWithChildren = rootRouteImport${\n rootComponentNode ||\n rootErrorComponentNode ||\n rootNotFoundComponentNode ||\n rootPendingComponentNode\n ? `.update({\n ${(\n [\n ['component', rootComponentNode],\n ['errorComponent', rootErrorComponentNode],\n ['notFoundComponent', rootNotFoundComponentNode],\n ['pendingComponent', rootPendingComponentNode],\n ] as const\n )\n .filter((d) => d[1])\n .map((d) => {\n // For .vue files, use 'default' as the export name since Vue SFCs export default\n const isVueFile = d[1]!.filePath.endsWith('.vue')\n const exportName = isVueFile ? 'default' : d[0]\n // Keep .vue extension for Vue files since Vite requires it\n const importPath = replaceBackslash(\n isVueFile\n ? path.relative(\n path.dirname(config.generatedRouteTree),\n path.resolve(config.routesDirectory, d[1]!.filePath),\n )\n : removeExt(\n path.relative(\n path.dirname(config.generatedRouteTree),\n path.resolve(\n config.routesDirectory,\n d[1]!.filePath,\n ),\n ),\n config.addExtensions,\n ),\n )\n return `${d[0]}: lazyRouteComponent(() => import('./${importPath}'), '${exportName}')`\n })\n .join('\\n,')}\n })`\n : ''\n }._addFileChildren(rootRouteChildren)${config.disableTypes ? '' : `._addFileTypes<FileRouteTypes>()`}`\n }\n\n let fileRoutesByPathInterface = ''\n let fileRoutesByFullPath = ''\n\n if (!config.disableTypes) {\n const routeNodesByFullPath = createRouteNodesByFullPath(acc.routeNodes)\n const routeNodesByTo = createRouteNodesByTo(acc.routeNodes)\n const routeNodesById = createRouteNodesById(acc.routeNodes)\n\n fileRoutesByFullPath = [\n `export interface FileRoutesByFullPath {\n${[...routeNodesByFullPath.entries()]\n .filter(([fullPath]) => fullPath)\n .map(([fullPath, routeNode]) => {\n return `'${fullPath}': typeof ${getResolvedRouteNodeVariableName(routeNode)}`\n })}\n}`,\n `export interface FileRoutesByTo {\n${[...routeNodesByTo.entries()]\n .filter(([to]) => to)\n .map(([to, routeNode]) => {\n return `'${to}': typeof ${getResolvedRouteNodeVariableName(routeNode)}`\n })}\n}`,\n `export interface FileRoutesById {\n'${rootRouteId}': typeof rootRouteImport,\n${[...routeNodesById.entries()].map(([id, routeNode]) => {\n return `'${id}': typeof ${getResolvedRouteNodeVariableName(routeNode)}`\n})}\n}`,\n `export interface FileRouteTypes {\nfileRoutesByFullPath: FileRoutesByFullPath\nfullPaths: ${\n acc.routeNodes.length > 0\n ? [...routeNodesByFullPath.keys()]\n .filter((fullPath) => fullPath)\n .map((fullPath) => `'${fullPath}'`)\n .join('|')\n : 'never'\n }\nfileRoutesByTo: FileRoutesByTo\nto: ${\n acc.routeNodes.length > 0\n ? [...routeNodesByTo.keys()]\n .filter((to) => to)\n .map((to) => `'${to}'`)\n .join('|')\n : 'never'\n }\nid: ${[`'${rootRouteId}'`, ...[...routeNodesById.keys()].map((id) => `'${id}'`)].join('|')}\nfileRoutesById: FileRoutesById\n}`,\n `export interface RootRouteChildren {\n${acc.routeTree.map((child) => `${child.variableName}Route: typeof ${getResolvedRouteNodeVariableName(child)}`).join(',')}\n}`,\n ].join('\\n')\n\n fileRoutesByPathInterface = buildFileRoutesByPathInterface({\n module: this.targetTemplate.fullPkg,\n interfaceName: 'FileRoutesByPath',\n routeNodes: sortedRouteNodes,\n config,\n })\n }\n\n const routeTree = [\n `const rootRouteChildren${config.disableTypes ? '' : `: RootRouteChildren`} = {\n ${acc.routeTree\n .map(\n (child) =>\n `${child.variableName}Route: ${getResolvedRouteNodeVariableName(child)}`,\n )\n .join(',')}\n}`,\n rootRouteUpdate\n ? rootRouteUpdate.replace(\n 'const rootRouteWithChildren = ',\n 'export const routeTree = ',\n )\n : `export const routeTree = rootRouteImport._addFileChildren(rootRouteChildren)${config.disableTypes ? '' : `._addFileTypes<FileRouteTypes>()`}`,\n ].join('\\n')\n\n checkRouteFullPathUniqueness(\n sortedRouteNodes.filter(\n (d) => d.children === undefined && 'lazy' !== d._fsRouteType,\n ),\n config,\n )\n\n let mergedImports = mergeImportDeclarations(imports)\n if (config.disableTypes) {\n mergedImports = mergedImports.filter((d) => d.importKind !== 'type')\n }\n\n const importStatements = mergedImports.map(buildImportString)\n\n const rootRouteImport = getImportForRouteNode(\n rootRouteNode,\n config,\n this.generatedRouteTreePath,\n this.root,\n )\n routeImports.unshift(rootRouteImport)\n\n let footer: Array<string> = []\n if (config.routeTreeFileFooter) {\n if (Array.isArray(config.routeTreeFileFooter)) {\n footer = config.routeTreeFileFooter\n } else {\n footer = config.routeTreeFileFooter()\n }\n }\n const routeTreeContent = [\n ...config.routeTreeFileHeader,\n `// This file was automatically generated by TanStack Router.\n// You should NOT make any changes in this file as it will be overwritten.\n// Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified.`,\n [...importStatements].join('\\n'),\n mergeImportDeclarations(routeImports).map(buildImportString).join('\\n'),\n virtualRouteNodes.join('\\n'),\n createUpdateRoutes.join('\\n'),\n fileRoutesByFullPath,\n fileRoutesByPathInterface,\n routeTreeConfig.join('\\n'),\n routeTree,\n ...footer,\n ]\n .filter(Boolean)\n .join('\\n\\n')\n return {\n routeTreeContent,\n routeTree: acc.routeTree,\n routeNodes: acc.routeNodes,\n }\n }\n\n private async processRouteNodeFile(node: RouteNode): Promise<{\n shouldWriteTree: boolean\n cacheEntry: RouteNodeCacheEntry\n node: RouteNode\n } | null> {\n const result = await this.isRouteFileCacheFresh(node)\n\n if (result.status === 'fresh') {\n return {\n node: result.cacheEntry.node,\n shouldWriteTree: false,\n cacheEntry: result.cacheEntry,\n }\n }\n\n const previousCacheEntry = result.cacheEntry\n\n const existingRouteFile = await this.fs.readFile(node.fullPath)\n if (existingRouteFile === 'file-not-existing') {\n throw new Error(`⚠️ File ${node.fullPath} does not exist`)\n }\n\n if (node.routePath) {\n validateRouteParams(node.routePath, node.filePath, this.logger)\n }\n\n const updatedCacheEntry: RouteNodeCacheEntry = {\n fileContent: existingRouteFile.fileContent,\n mtimeMs: existingRouteFile.stat.mtimeMs,\n routeId: node.routePath ?? '$$TSR_NO_ROUTE_PATH_ASSIGNED$$',\n node,\n }\n\n const escapedRoutePath = node.routePath?.replaceAll('$', '$$') ?? ''\n\n let shouldWriteRouteFile = false\n let shouldWriteTree = false\n // now we need to either scaffold the file or transform it\n if (!existingRouteFile.fileContent) {\n shouldWriteRouteFile = true\n shouldWriteTree = true\n // Creating a new lazy route file\n if (node._fsRouteType === 'lazy') {\n const tLazyRouteTemplate = this.targetTemplate.lazyRoute\n // Check by default check if the user has a specific lazy route template\n // If not, check if the user has a route template and use that instead\n updatedCacheEntry.fileContent = await fillTemplate(\n this.config,\n (this.config.customScaffolding?.lazyRouteTemplate ||\n this.config.customScaffolding?.routeTemplate) ??\n tLazyRouteTemplate.template(),\n {\n tsrImports: tLazyRouteTemplate.imports.tsrImports(),\n tsrPath: escapedRoutePath.replaceAll(/\\{(.+?)\\}/gm, '$1'),\n tsrExportStart:\n tLazyRouteTemplate.imports.tsrExportStart(escapedRoutePath),\n tsrExportEnd: tLazyRouteTemplate.imports.tsrExportEnd(),\n },\n )\n } else if (\n // Creating a new normal route file\n (['layout', 'static'] satisfies Array<FsRouteType>).some(\n (d) => d === node._fsRouteType,\n ) ||\n (\n [\n 'component',\n 'pendingComponent',\n 'errorComponent',\n 'notFoundComponent',\n 'loader',\n ] satisfies Array<FsRouteType>\n ).every((d) => d !== node._fsRouteType)\n ) {\n const tRouteTemplate = this.targetTemplate.route\n updatedCacheEntry.fileContent = await fillTemplate(\n this.config,\n this.config.customScaffolding?.routeTemplate ??\n tRouteTemplate.template(),\n {\n tsrImports: tRouteTemplate.imports.tsrImports(),\n tsrPath: escapedRoutePath.replaceAll(/\\{(.+?)\\}/gm, '$1'),\n tsrExportStart:\n tRouteTemplate.imports.tsrExportStart(escapedRoutePath),\n tsrExportEnd: tRouteTemplate.imports.tsrExportEnd(),\n },\n )\n } else {\n return null\n }\n }\n\n // Check if this is a Vue component file\n // Vue SFC files (.vue) don't need transformation as they can't have a Route export\n const isVueFile = node.filePath.endsWith('.vue')\n\n if (!isVueFile) {\n // transform the file\n const transformResult = await transform({\n source: updatedCacheEntry.fileContent,\n filename: node.fullPath,\n ctx: {\n target: this.config.target,\n routeId: escapedRoutePath,\n lazy: node._fsRouteType === 'lazy',\n },\n node,\n })\n\n if (transformResult.result === 'no-route-export') {\n const fileName = path.basename(node.fullPath)\n const dirName = path.dirname(node.fullPath)\n const ignorePrefix = this.config.routeFileIgnorePrefix\n const ignorePattern = this.config.routeFileIgnorePattern\n const suggestedFileName = `${ignorePrefix}${fileName}`\n const suggestedFullPath = path.join(dirName, suggestedFileName)\n\n let message = `Warning: Route file \"${node.fullPath}\" does not export a Route. This file will not be included in the route tree.`\n message += `\\n\\nIf this file is not intended to be a route, you can exclude it using one of these options:`\n message += `\\n 1. Rename the file to \"${suggestedFullPath}\" (prefix with \"${ignorePrefix}\")`\n message += `\\n 2. Use 'routeFileIgnorePattern' in your config to match this file`\n message += `\\n\\nCurrent configuration:`\n message += `\\n routeFileIgnorePrefix: \"${ignorePrefix}\"`\n message += `\\n routeFileIgnorePattern: ${ignorePattern ? `\"${ignorePattern}\"` : 'undefined'}`\n\n this.logger.warn(message)\n return null\n }\n if (transformResult.result === 'error') {\n throw new Error(\n `Error transforming route file ${node.fullPath}: ${transformResult.error}`,\n )\n }\n if (transformResult.result === 'modified') {\n updatedCacheEntry.fileContent = transformResult.output\n shouldWriteRouteFile = true\n }\n }\n\n for (const plugin of this.plugins) {\n plugin.afterTransform?.({ node, prevNode: previousCacheEntry?.node })\n }\n\n // file was changed\n if (shouldWriteRouteFile) {\n const stats = await this.safeFileWrite({\n filePath: node.fullPath,\n newContent: updatedCacheEntry.fileContent,\n strategy: {\n type: 'mtime',\n expectedMtimeMs: updatedCacheEntry.mtimeMs,\n expectedContent: existingRouteFile.fileContent,\n },\n })\n updatedCacheEntry.mtimeMs = stats.mtimeMs\n }\n\n this.routeNodeShadowCache.set(node.fullPath, updatedCacheEntry)\n return {\n node,\n shouldWriteTree,\n cacheEntry: updatedCacheEntry,\n }\n }\n\n private async didRouteFileChangeComparedToCache(\n file: {\n path: string\n mtimeMs?: bigint\n },\n cache: 'routeNodeCache' | 'routeNodeShadowCache',\n ): Promise<FileCacheChange<RouteNodeCacheEntry>> {\n const cacheEntry = this[cache].get(file.path)\n return this.didFileChangeComparedToCache(file, cacheEntry)\n }\n\n private async didFileChangeComparedToCache<\n TCacheEntry extends GeneratorCacheEntry,\n >(\n file: {\n path: string\n mtimeMs?: bigint\n },\n cacheEntry: TCacheEntry | undefined,\n ): Promise<FileCacheChange<TCacheEntry>> {\n // for now we rely on the modification time of the file\n // to determine if the file has changed\n // we could also compare the file content but this would be slower as we would have to read the file\n\n if (!cacheEntry) {\n return { result: 'file-not-in-cache' }\n }\n let mtimeMs = file.mtimeMs\n\n if (mtimeMs === undefined) {\n try {\n const currentStat = await this.fs.stat(file.path)\n mtimeMs = currentStat.mtimeMs\n } catch {\n return { result: 'cannot-stat-file' }\n }\n }\n return { result: mtimeMs !== cacheEntry.mtimeMs, mtimeMs, cacheEntry }\n }\n\n private async safeFileWrite(opts: {\n filePath: string\n newContent: string\n strategy:\n | {\n type: 'mtime'\n expectedMtimeMs: bigint\n // An in-place save can truncate and rewrite a file within one mtime\n // tick, so user-authored files also compare the content.\n expectedContent?: string\n }\n | {\n type: 'new-file'\n }\n }) {\n const tmpPath = this.getTempFileName(opts.filePath)\n await this.fs.writeFile(tmpPath, opts.newContent)\n\n if (opts.strategy.type === 'mtime') {\n const { expectedMtimeMs, expectedContent } = opts.strategy\n const beforeStat = await this.fs.stat(opts.filePath)\n const newFileState = await this.fs.stat(tmpPath)\n if (newFileState.mode !== beforeStat.mode) {\n await this.fs.chmod(tmpPath, beforeStat.mode)\n }\n if (\n newFileState.uid !== beforeStat.uid ||\n newFileState.gid !== beforeStat.gid\n ) {\n try {\n await this.fs.chown(tmpPath, beforeStat.uid, beforeStat.gid)\n } catch (err) {\n if (\n typeof err === 'object' &&\n err !== null &&\n 'code' in err &&\n (err as any).code === 'EPERM'\n ) {\n console.warn(\n `[safeFileWrite] chown failed: ${(err as any).message}`,\n )\n } else {\n throw err\n }\n }\n }\n // Check right before the rename so that changes made while the\n // temporary file was prepared are not overwritten.\n let changed: boolean\n if (expectedContent === undefined) {\n const current = await this.fs.stat(opts.filePath)\n changed = current.mtimeMs !== expectedMtimeMs\n } else {\n const current = await this.fs.readFile(opts.filePath)\n changed =\n current === 'file-not-existing' ||\n current.stat.mtimeMs !== expectedMtimeMs ||\n current.fileContent !== expectedContent\n }\n if (changed) {\n throw rerun({\n msg: `File ${opts.filePath} was modified by another process during processing.`,\n event: { type: 'update', path: opts.filePath },\n })\n }\n } else {\n if (await checkFileExists(opts.filePath)) {\n throw rerun({\n msg: `File ${opts.filePath} already exists. Cannot overwrite.`,\n event: { type: 'update', path: opts.filePath },\n })\n }\n }\n\n await this.fs.rename(tmpPath, opts.filePath)\n\n // stat the target file AFTER rename so the cached mtime matches\n // what the filesystem reports for the actual file path.\n // Previously we stat'd the temp file before rename, but rename()\n // can assign a different mtime to the target on some filesystems,\n // causing the cache to be permanently stale.\n const stat = await this.fs.stat(opts.filePath)\n\n return stat\n }\n\n private getTempFileName(filePath: string) {\n const absPath = path.resolve(filePath)\n const hash = crypto.createHash('md5').update(absPath).digest('hex')\n // lazy initialize sessionId to only create tmpDir when it is first needed\n if (!this.sessionId) {\n // ensure the directory exists\n mkdirSync(this.config.tmpDir, { recursive: true })\n this.sessionId = crypto.randomBytes(4).toString('hex')\n }\n return path.join(this.config.tmpDir, `${this.sessionId}-${hash}`)\n }\n\n private async isRouteFileCacheFresh(node: RouteNode): Promise<\n | {\n status: 'fresh'\n cacheEntry: RouteNodeCacheEntry\n }\n | { status: 'stale'; cacheEntry?: RouteNodeCacheEntry }\n > {\n const fileChangedCache = await this.didRouteFileChangeComparedToCache(\n { path: node.fullPath },\n 'routeNodeCache',\n )\n if (fileChangedCache.result === false) {\n this.routeNodeShadowCache.set(node.fullPath, fileChangedCache.cacheEntry)\n return {\n status: 'fresh',\n cacheEntry: fileChangedCache.cacheEntry,\n }\n }\n if (fileChangedCache.result === 'cannot-stat-file') {\n throw new Error(`⚠️ expected route file to exist at ${node.fullPath}`)\n }\n const mtimeMs =\n fileChangedCache.result === true ? fileChangedCache.mtimeMs : undefined\n\n const shadowCacheFileChange = await this.didRouteFileChangeComparedToCache(\n { path: node.fullPath, mtimeMs },\n 'routeNodeShadowCache',\n )\n\n if (shadowCacheFileChange.result === 'cannot-stat-file') {\n throw new Error(`⚠️ expected route file to exist at ${node.fullPath}`)\n }\n\n if (shadowCacheFileChange.result === false) {\n // shadow cache has latest file state already\n if (fileChangedCache.result === true) {\n return {\n status: 'fresh',\n cacheEntry: shadowCacheFileChange.cacheEntry,\n }\n }\n }\n\n if (fileChangedCache.result === 'file-not-in-cache') {\n return {\n status: 'stale',\n }\n }\n return { status: 'stale', cacheEntry: fileChangedCache.cacheEntry }\n }\n\n private async handleRootNode(node: RouteNode) {\n const result = await this.isRouteFileCacheFresh(node)\n\n if (result.status === 'fresh') {\n this.routeNodeShadowCache.set(node.fullPath, result.cacheEntry)\n }\n const rootNodeFile = await this.fs.readFile(node.fullPath)\n if (rootNodeFile === 'file-not-existing') {\n throw new Error(`⚠️ expected root route to exist at ${node.fullPath}`)\n }\n\n const updatedCacheEntry: RouteNodeCacheEntry = {\n fileContent: rootNodeFile.fileContent,\n mtimeMs: rootNodeFile.stat.mtimeMs,\n routeId: node.routePath ?? '$$TSR_NO_ROOT_ROUTE_PATH_ASSIGNED$$',\n node,\n }\n\n // scaffold the root route\n if (!rootNodeFile.fileContent) {\n const rootTemplate = this.targetTemplate.rootRoute\n const rootRouteContent = await fillTemplate(\n this.config,\n rootTemplate.template(),\n {\n tsrImports: rootTemplate.imports.tsrImports(),\n tsrPath: rootPathId,\n tsrExportStart: rootTemplate.imports.tsrExportStart(),\n tsrExportEnd: rootTemplate.imports.tsrExportEnd(),\n },\n )\n\n this.logger.log(`🟡 Creating ${node.fullPath}`)\n const stats = await this.safeFileWrite({\n filePath: node.fullPath,\n newContent: rootRouteContent,\n strategy: {\n type: 'mtime',\n expectedMtimeMs: rootNodeFile.stat.mtimeMs,\n expectedContent: rootNodeFile.fileContent,\n },\n })\n updatedCacheEntry.fileContent = rootRouteContent\n updatedCacheEntry.mtimeMs = stats.mtimeMs\n }\n\n this.routeNodeShadowCache.set(node.fullPath, updatedCacheEntry)\n }\n\n public async getCrawlingResult(): Promise<CrawlingResult | undefined> {\n await this.runPromise\n return this.crawlingResult\n }\n\n private static handleNode(\n node: RouteNode,\n acc: HandleNodeAccumulator,\n prefixMap: RoutePrefixMap,\n config?: Config,\n ) {\n let parentRoute = hasParentRoute(prefixMap, node, node.routePath)\n\n // Check routeNodesByPath for a closer parent that may not be in prefixMap.\n //\n // Why: The prefixMap excludes lazy routes by design. When lazy-only routes are\n // nested inside a pathless layout, the virtual route created from the lazy file\n // won't be in the prefixMap, but it will be in routeNodesByPath.\n //\n // Example: Given files _layout/path.lazy.tsx and _layout/path.index.lazy.tsx:\n // - prefixMap contains: /_layout (from route.tsx)\n // - routeNodesByPath contains: /_layout AND /_layout/path (virtual from lazy)\n // - For /_layout/path/, hasParentRoute returns /_layout (wrong)\n // - But the correct parent is /_layout/path (the virtual route from path.lazy.tsx)\n //\n // We walk up the path segments to find the closest registered parent. This handles\n // cases where multiple path segments (e.g., $a/$b) don't have intermediate routes.\n if (node.routePath) {\n let searchPath = node.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 candidate = acc.routeNodesByPath.get(searchPath)\n if (candidate && candidate.routePath !== node.routePath) {\n // Found a parent in routeNodesByPath\n // If it's different from what prefixMap found AND is a closer match, use it\n if (candidate !== parentRoute) {\n // Check if this candidate is a closer parent than what prefixMap found\n // (longer path prefix means closer parent)\n if (\n !parentRoute ||\n (candidate.routePath?.length ?? 0) >\n (parentRoute.routePath?.length ?? 0)\n ) {\n parentRoute = candidate\n }\n }\n break\n }\n }\n }\n\n // Virtual routes may have an explicit parent from virtual config.\n // If we can find that exact parent, use it to prevent auto-nesting siblings\n // based on path prefix matching (#5822, #5431).\n if (node._virtualParentRoutePath !== undefined) {\n const explicitParent = acc.routeNodesByPath.get(\n node._virtualParentRoutePath,\n )\n if (explicitParent) {\n parentRoute = explicitParent\n } else if (node._virtualParentRoutePath === `/${rootPathId}`) {\n // The explicit parent is the root route (handled separately).\n // Override path-based inference so this node stays at root level.\n parentRoute = null\n }\n // Otherwise the explicit parent was a virtual file-less route that got\n // filtered out. Fall back to the path-based parentRoute already computed.\n }\n\n if (parentRoute) node.parent = parentRoute\n\n node.path = determineNodePath(node)\n\n const trimmedPath = trimPathLeft(node.path ?? '')\n const originalPath =\n node.originalRoutePath && node.parent?.originalRoutePath\n ? node.originalRoutePath.replace(node.parent.originalRoutePath, '') ||\n '/'\n : node.originalRoutePath\n const routePathSegmentMetadata = getRoutePathSegmentMetadataForPath(\n node,\n node.path ?? '/',\n node.parent?.routePath,\n )\n const trimmedOriginalPath = trimPathLeft(originalPath ?? '')\n\n const split = trimmedPath.split('/')\n const pathSplit = (node.path ?? '').split('/')\n const originalSplit = trimmedOriginalPath.split('/')\n const lastRouteSegment = split[split.length - 1] ?? trimmedPath\n const lastOriginalSegment =\n originalSplit[originalSplit.length - 1] ?? trimmedOriginalPath\n const lastRouteSegmentMetadata =\n routePathSegmentMetadata?.[pathSplit.length - 1]\n\n // A segment is non-path if it starts with underscore AND the underscore is not escaped\n node.isNonPath =\n (!lastRouteSegmentMetadata?.literalLeadingUnderscore &&\n isSegmentPathless(lastRouteSegment, lastOriginalSegment)) ||\n split.every((part) => this.routeGroupPatternRegex.test(part))\n\n // Use a single pass so layout removal does not desync escaped underscore checks.\n node.cleanedPath = removeGroups(\n removeLayoutSegmentsAndUnderscoresWithEscape(\n node.path,\n originalPath,\n routePathSegmentMetadata,\n ),\n )\n\n if (\n node._fsRouteType === 'layout' ||\n node._fsRouteType === 'pathless_layout'\n ) {\n node.cleanedPath = removeTrailingSlash(node.cleanedPath)\n }\n\n if (\n !node.isVirtual &&\n (\n [\n 'lazy',\n 'loader',\n 'component',\n 'pendingComponent',\n 'errorComponent',\n 'notFoundComponent',\n ] satisfies Array<FsRouteType>\n ).some((d) => d === node._fsRouteType)\n ) {\n acc.routePiecesByPath[node.routePath!] =\n acc.routePiecesByPath[node.routePath!] || {}\n\n const pieceKey =\n node._fsRouteType === 'lazy'\n ? 'lazy'\n : (node._fsRouteType as keyof (typeof acc.routePiecesByPath)[string])\n acc.routePiecesByPath[node.routePath!]![pieceKey] = node\n\n const anchorRoute = acc.routeNodesByPath.get(node.routePath!)\n\n // Don't create virtual routes for root route component pieces - the root route is handled separately\n if (!anchorRoute && node.routePath !== `/${rootPathId}`) {\n this.handleNode(\n {\n ...node,\n isVirtual: true,\n _fsRouteType: 'static',\n },\n acc,\n prefixMap,\n config,\n )\n }\n return\n }\n\n const isPathlessLayoutWithPath =\n node._fsRouteType === 'pathless_layout' &&\n node.cleanedPath &&\n node.cleanedPath.length > 0\n\n // Special handling: pathless layouts with path need to find real ancestor\n if (!node.isVirtual && isPathlessLayoutWithPath) {\n const immediateParentPath =\n removeLastSegmentFromPath(node.routePath) || '/'\n const immediateParentOriginalPath =\n removeLastSegmentFromPath(node.originalRoutePath) || '/'\n let searchPath = immediateParentPath\n\n // Find nearest real (non-virtual, non-index) parent\n while (searchPath) {\n const candidate = acc.routeNodesByPath.get(searchPath)\n if (candidate && !candidate.isVirtual && candidate.path !== '/') {\n node.parent = candidate\n node.path =\n node.routePath?.replace(candidate.routePath ?? '', '') || '/'\n const pathRelativeToParent =\n immediateParentPath.replace(candidate.routePath ?? '', '') || '/'\n const originalPathRelativeToParent =\n immediateParentOriginalPath.replace(\n candidate.originalRoutePath ?? '',\n '',\n ) || '/'\n const routePathSegmentMetadataRelativeToParent =\n getRoutePathSegmentMetadataForPath(\n node,\n pathRelativeToParent,\n candidate.routePath,\n )\n node.cleanedPath = removeGroups(\n removeLayoutSegmentsAndUnderscoresWithEscape(\n pathRelativeToParent,\n originalPathRelativeToParent,\n routePathSegmentMetadataRelativeToParent,\n ),\n )\n break\n }\n if (searchPath === '/') break\n searchPath = removeLastSegmentFromPath(searchPath) || '/'\n }\n }\n\n // Add to parent's children or to root\n if (node.parent) {\n node.parent.children = node.parent.children ?? []\n node.parent.children.push(node)\n } else {\n acc.routeTree.push(node)\n }\n\n acc.routeNodes.push(node)\n if (node.routePath) {\n // Always register routes by path so child routes can find parents.\n // Virtual routes (created from lazy-only files) also need to be registered\n // so that index routes like path.index.lazy.tsx can find their parent path.lazy.tsx.\n // If a non-virtual route is later processed for the same path, it will overwrite.\n acc.routeNodesByPath.set(node.routePath, node)\n }\n }\n\n // only process files that are relevant for the route tree generation\n private isFileRelevantForRouteTreeGeneration(filePath: string): boolean {\n // the generated route tree file\n if (filePath === this.generatedRouteTreePath) {\n return true\n }\n\n // files inside the routes folder\n if (filePath.startsWith(this.routesDirectoryPath)) {\n return true\n }\n\n // the virtual route config file passed into `virtualRouteConfig`\n if (\n typeof this.config.virtualRouteConfig === 'string' &&\n filePath === this.config.virtualRouteConfig\n ) {\n return true\n }\n\n // this covers all files that are mounted via `virtualRouteConfig` or any `__virtual.ts` files\n if (this.routeNodeCache.has(filePath)) {\n return true\n }\n\n // virtual config files such as`__virtual.ts`\n if (isVirtualConfigFile(path.basename(filePath))) {\n return true\n }\n\n // route files inside directories mounted via `physical()` inside a virtual route config\n if (this.phys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IACxB,aAAaE,cAAAA,0BAA0B,UAAU,KAAK;GACxD;EACF;EAGA,IAAI,KAAK,QAAQ;GACf,KAAK,OAAO,WAAW,KAAK,OAAO,YAAY,CAAC;GAChD,KAAK,OAAO,SAAS,KAAK,IAAI;EAChC,OACE,IAAI,UAAU,KAAK,IAAI;EAGzB,IAAI,WAAW,KAAK,IAAI;EACxB,IAAI,KAAK,WAKP,IAAI,iBAAiB,IAAI,KAAK,WAAW,IAAI;CAEjD;CAGA,qCAA6C,UAA2B;EAEtE,IAAI,aAAa,KAAK,wBACpB,OAAO;EAIT,IAAI,SAAS,WAAW,KAAK,mBAAmB,GAC9C,OAAO;EAIT,IACE,OAAO,KAAK,OAAO,uBAAuB,YAC1C,aAAa,KAAK,OAAO,oBAEzB,OAAO;EAIT,IAAI,KAAK,eAAe,IAAI,QAAQ,GAClC,OAAO;EAIT,IAAIC,wBAAAA,oBAAoBnC,UAAAA,QAAK,SAAS,QAAQ,CAAC,GAC7C,OAAO;EAIT,IAAI,KAAK,oBAAoB,MAAM,QAAQ,SAAS,WAAW,GAAG,CAAC,GACjE,OAAO;EAGT,OAAO;CACT;AACF"}
@@ -541,7 +541,8 @@ ${acc.routeTree.map((child) => `${child.variableName}Route: typeof ${getResolved
541
541
  newContent: updatedCacheEntry.fileContent,
542
542
  strategy: {
543
543
  type: "mtime",
544
- expectedMtimeMs: updatedCacheEntry.mtimeMs
544
+ expectedMtimeMs: updatedCacheEntry.mtimeMs,
545
+ expectedContent: existingRouteFile.fileContent
545
546
  }
546
547
  })).mtimeMs;
547
548
  this.routeNodeShadowCache.set(node.fullPath, updatedCacheEntry);
@@ -573,14 +574,8 @@ ${acc.routeTree.map((child) => `${child.variableName}Route: typeof ${getResolved
573
574
  const tmpPath = this.getTempFileName(opts.filePath);
574
575
  await this.fs.writeFile(tmpPath, opts.newContent);
575
576
  if (opts.strategy.type === "mtime") {
577
+ const { expectedMtimeMs, expectedContent } = opts.strategy;
576
578
  const beforeStat = await this.fs.stat(opts.filePath);
577
- if (beforeStat.mtimeMs !== opts.strategy.expectedMtimeMs) throw rerun({
578
- msg: `File ${opts.filePath} was modified by another process during processing.`,
579
- event: {
580
- type: "update",
581
- path: opts.filePath
582
- }
583
- });
584
579
  const newFileState = await this.fs.stat(tmpPath);
585
580
  if (newFileState.mode !== beforeStat.mode) await this.fs.chmod(tmpPath, beforeStat.mode);
586
581
  if (newFileState.uid !== beforeStat.uid || newFileState.gid !== beforeStat.gid) try {
@@ -589,6 +584,19 @@ ${acc.routeTree.map((child) => `${child.variableName}Route: typeof ${getResolved
589
584
  if (typeof err === "object" && err !== null && "code" in err && err.code === "EPERM") console.warn(`[safeFileWrite] chown failed: ${err.message}`);
590
585
  else throw err;
591
586
  }
587
+ let changed;
588
+ if (expectedContent === void 0) changed = (await this.fs.stat(opts.filePath)).mtimeMs !== expectedMtimeMs;
589
+ else {
590
+ const current = await this.fs.readFile(opts.filePath);
591
+ changed = current === "file-not-existing" || current.stat.mtimeMs !== expectedMtimeMs || current.fileContent !== expectedContent;
592
+ }
593
+ if (changed) throw rerun({
594
+ msg: `File ${opts.filePath} was modified by another process during processing.`,
595
+ event: {
596
+ type: "update",
597
+ path: opts.filePath
598
+ }
599
+ });
592
600
  } else if (await checkFileExists(opts.filePath)) throw rerun({
593
601
  msg: `File ${opts.filePath} already exists. Cannot overwrite.`,
594
602
  event: {
@@ -661,7 +669,8 @@ ${acc.routeTree.map((child) => `${child.variableName}Route: typeof ${getResolved
661
669
  newContent: rootRouteContent,
662
670
  strategy: {
663
671
  type: "mtime",
664
- expectedMtimeMs: rootNodeFile.stat.mtimeMs
672
+ expectedMtimeMs: rootNodeFile.stat.mtimeMs,
673
+ expectedContent: rootNodeFile.fileContent
665
674
  }
666
675
  });
667
676
  updatedCacheEntry.fileContent = rootRouteContent;
@@ -1 +1 @@
1
- {"version":3,"file":"generator.js","names":["virtualGetRouteNodes","physicalGetRouteNodes"],"sources":["../../src/generator.ts"],"sourcesContent":["import path from 'node:path'\nimport * as fsp from 'node:fs/promises'\nimport { existsSync, mkdirSync } from 'node:fs'\nimport crypto from 'node:crypto'\nimport { rootRouteId } from '@tanstack/router-core'\nimport { logging } from './logger'\nimport {\n isVirtualConfigFile,\n getRouteNodes as physicalGetRouteNodes,\n} from './filesystem/physical/getRouteNodes'\nimport { getRouteNodes as virtualGetRouteNodes } from './filesystem/virtual/getRouteNodes'\nimport { rootPathId } from './filesystem/physical/rootPathId'\nimport {\n RoutePrefixMap,\n buildFileRoutesByPathInterface,\n buildImportString,\n buildRouteTreeConfig,\n checkFileExists,\n checkRouteFullPathUniqueness,\n countRoutePathSegments,\n countSlashSeparatedParts,\n createRouteNodesByFullPath,\n createRouteNodesById,\n createRouteNodesByTo,\n createTokenRegex,\n determineNodePath,\n findParent,\n format,\n getImportForRouteNode,\n getResolvedRouteNodeVariableName,\n hasParentRoute,\n isSegmentPathless,\n mergeImportDeclarations,\n multiSortBy,\n removeExt,\n removeGroups,\n removeLastSegmentFromPath,\n removeLayoutSegmentsAndUnderscoresWithEscape,\n removeTrailingSlash,\n replaceBackslash,\n sortRouteNodes,\n trimPathLeft,\n} from './utils'\nimport { fillTemplate, getTargetTemplate } from './template'\nimport { transform } from './transform/transform'\nimport { validateRouteParams } from './validate-route-params'\nimport type { GeneratorPlugin } from './plugin/types'\nimport type { TargetTemplate } from './template'\nimport type {\n FsRouteType,\n GetRouteNodesResult,\n GetRoutesByFileMapResult,\n HandleNodeAccumulator,\n ImportDeclaration,\n RouteNode,\n RoutePathSegmentMetadata,\n} from './types'\nimport type { Config } from './config'\nimport type { Logger } from './logger'\n\ninterface fs {\n stat: (\n filePath: string,\n ) => Promise<{ mtimeMs: bigint; mode: number; uid: number; gid: number }>\n rename: (oldPath: string, newPath: string) => Promise<void>\n writeFile: (filePath: string, content: string) => Promise<void>\n readFile: (\n filePath: string,\n ) => Promise<\n { stat: { mtimeMs: bigint }; fileContent: string } | 'file-not-existing'\n >\n chmod: (filePath: string, mode: number) => Promise<void>\n chown: (filePath: string, uid: number, gid: number) => Promise<void>\n}\n\nfunction getRoutePathSegmentMetadataForPath(\n node: RouteNode,\n routePath: string,\n parentRoutePath?: string,\n): Array<RoutePathSegmentMetadata | undefined> | undefined {\n if (!node._routePathSegmentMetadata) return undefined\n\n const segments = routePath.split('/')\n const result = new Array<RoutePathSegmentMetadata | undefined>(\n segments.length,\n )\n const parentSegmentCount = countRoutePathSegments(parentRoutePath)\n let hasMetadata = false\n let segmentCount = 0\n\n for (let i = 0; i < segments.length; i++) {\n if (!segments[i]) continue\n const sourceIndex = parentSegmentCount + segmentCount + 1\n result[i] = node._routePathSegmentMetadata[sourceIndex]\n hasMetadata ||= !!result[i]\n segmentCount++\n }\n\n return hasMetadata ? result : undefined\n}\n\nconst DefaultFileSystem: fs = {\n stat: async (filePath) => {\n const res = await fsp.stat(filePath, { bigint: true })\n return {\n mtimeMs: res.mtimeMs,\n mode: Number(res.mode),\n uid: Number(res.uid),\n gid: Number(res.gid),\n }\n },\n rename: (oldPath, newPath) => fsp.rename(oldPath, newPath),\n writeFile: (filePath, content) => fsp.writeFile(filePath, content),\n readFile: async (filePath: string) => {\n try {\n const fileHandle = await fsp.open(filePath, 'r')\n const stat = await fileHandle.stat({ bigint: true })\n const fileContent = (await fileHandle.readFile()).toString()\n await fileHandle.close()\n return { stat, fileContent }\n } catch (e: any) {\n if ('code' in e) {\n if (e.code === 'ENOENT') {\n return 'file-not-existing'\n }\n }\n throw e\n }\n },\n chmod: (filePath, mode) => fsp.chmod(filePath, mode),\n chown: (filePath, uid, gid) => fsp.chown(filePath, uid, gid),\n}\n\ninterface Rerun {\n rerun: true\n msg?: string\n event: GeneratorEvent\n}\nfunction rerun(opts: { msg?: string; event?: GeneratorEvent }): Rerun {\n const { event, ...rest } = opts\n return { rerun: true, event: event ?? { type: 'rerun' }, ...rest }\n}\n\nfunction isRerun(result: unknown): result is Rerun {\n return (\n typeof result === 'object' &&\n result !== null &&\n 'rerun' in result &&\n result.rerun === true\n )\n}\n\nexport type FileEventType = 'create' | 'update' | 'delete'\nexport type FileEvent = {\n type: FileEventType\n path: string\n}\nexport type GeneratorEvent = FileEvent | { type: 'rerun' }\n\ntype FileCacheChange<TCacheEntry extends GeneratorCacheEntry> =\n | {\n result: false\n cacheEntry: TCacheEntry\n }\n | { result: true; mtimeMs: bigint; cacheEntry: TCacheEntry }\n | {\n result: 'file-not-in-cache'\n }\n | {\n result: 'cannot-stat-file'\n }\n\ninterface GeneratorCacheEntry {\n mtimeMs: bigint\n fileContent: string\n}\n\ninterface RouteNodeCacheEntry extends GeneratorCacheEntry {\n routeId: string\n node: RouteNode\n}\n\ntype GeneratorRouteNodeCache = Map</** filePath **/ string, RouteNodeCacheEntry>\n\ninterface CrawlingResult {\n rootRouteNode: RouteNode\n routeFileResult: Array<RouteNode>\n acc: HandleNodeAccumulator\n}\n\nexport class Generator {\n /**\n * why do we have two caches for the route files?\n * During processing, we READ from the cache and WRITE to the shadow cache.\n *\n * After a route file is processed, we write to the shadow cache.\n * If during processing we bail out and re-run, we don't lose this modification\n * but still can track whether the file contributed changes and thus the route tree file needs to be regenerated.\n * After all files are processed, we swap the shadow cache with the main cache and initialize a new shadow cache.\n * That way we also ensure deleted/renamed files don't stay in the cache forever.\n */\n private routeNodeCache: GeneratorRouteNodeCache = new Map()\n private routeNodeShadowCache: GeneratorRouteNodeCache = new Map()\n\n private routeTreeFileCache: GeneratorCacheEntry | undefined\n\n private crawlingResult: CrawlingResult | undefined\n public config: Config\n public targetTemplate: TargetTemplate\n\n private root: string\n private routesDirectoryPath: string\n private sessionId?: string\n private fs: fs\n private logger: Logger\n private generatedRouteTreePath: string\n private runPromise: Promise<void> | undefined\n private fileEventQueue: Array<GeneratorEvent> = []\n private plugins: Array<GeneratorPlugin> = []\n private static routeGroupPatternRegex = /\\(.+\\)/\n private physicalDirectories: Array<string> = []\n\n /**\n * Token regexes are pre-compiled once here and reused throughout route processing.\n * We need TWO types of regex for each token because they match against different inputs:\n *\n * 1. FILENAME regexes: Match token patterns within full file path strings.\n * Example: For file \"routes/dashboard.index.tsx\", we want to detect \".index.\"\n * Pattern: `[./](?:token)[.]` - matches token bounded by path separators/dots\n * Used in: sorting route nodes by file path\n *\n * 2. SEGMENT regexes: Match token against a single logical route segment.\n * Example: For segment \"index\" (extracted from path), match the whole segment\n * Pattern: `^(?:token)$` - matches entire segment exactly\n * Used in: route parsing, determining route types, escape detection\n *\n * We cannot reuse one for the other without false positives or missing matches.\n */\n private indexTokenFilenameRegex: RegExp\n private routeTokenFilenameRegex: RegExp\n private indexTokenSegmentRegex: RegExp\n private routeTokenSegmentRegex: RegExp\n private static componentPieceRegex =\n /[./](component|errorComponent|notFoundComponent|pendingComponent|loader|lazy)[.]/\n\n constructor(opts: { config: Config; root: string; fs?: fs }) {\n this.config = opts.config\n this.logger = logging({ disabled: this.config.disableLogging })\n this.root = opts.root\n this.fs = opts.fs || DefaultFileSystem\n this.generatedRouteTreePath = this.getGeneratedRouteTreePath()\n this.targetTemplate = getTargetTemplate(this.config)\n\n this.routesDirectoryPath = this.getRoutesDirectoryPath()\n this.plugins.push(...(opts.config.plugins || []))\n\n // Create all token regexes once in constructor\n this.indexTokenFilenameRegex = createTokenRegex(this.config.indexToken, {\n type: 'filename',\n })\n this.routeTokenFilenameRegex = createTokenRegex(this.config.routeToken, {\n type: 'filename',\n })\n this.indexTokenSegmentRegex = createTokenRegex(this.config.indexToken, {\n type: 'segment',\n })\n this.routeTokenSegmentRegex = createTokenRegex(this.config.routeToken, {\n type: 'segment',\n })\n\n for (const plugin of this.plugins) {\n plugin.init?.({ generator: this })\n }\n }\n\n private getGeneratedRouteTreePath() {\n const generatedRouteTreePath = path.isAbsolute(\n this.config.generatedRouteTree,\n )\n ? this.config.generatedRouteTree\n : path.resolve(this.root, this.config.generatedRouteTree)\n\n const generatedRouteTreeDir = path.dirname(generatedRouteTreePath)\n\n if (!existsSync(generatedRouteTreeDir)) {\n mkdirSync(generatedRouteTreeDir, { recursive: true })\n }\n\n return generatedRouteTreePath\n }\n\n private getRoutesDirectoryPath() {\n return path.isAbsolute(this.config.routesDirectory)\n ? this.config.routesDirectory\n : path.resolve(this.root, this.config.routesDirectory)\n }\n\n public getRoutesByFileMap(): GetRoutesByFileMapResult {\n return new Map(\n [...this.routeNodeCache.entries()].map(([filePath, cacheEntry]) => [\n filePath,\n { routeId: cacheEntry.routeId },\n ]),\n )\n }\n\n public async run(event?: GeneratorEvent): Promise<void> {\n if (\n event &&\n event.type !== 'rerun' &&\n !this.isFileRelevantForRouteTreeGeneration(event.path)\n ) {\n return\n }\n this.fileEventQueue.push(event ?? { type: 'rerun' })\n // only allow a single run at a time\n if (this.runPromise) {\n return this.runPromise\n }\n\n this.runPromise = (async () => {\n do {\n // synchronously copy and clear the queue since we are going to iterate asynchronously over it\n // and while we do so, a new event could be put into the queue\n const tempQueue = this.fileEventQueue\n this.fileEventQueue = []\n // if we only have 'update' events in the queue\n // and we already have the affected files' latest state in our cache, we can exit early\n const remainingEvents = (\n await Promise.all(\n tempQueue.map(async (e) => {\n if (e.type === 'update') {\n let cacheEntry: GeneratorCacheEntry | undefined\n if (e.path === this.generatedRouteTreePath) {\n cacheEntry = this.routeTreeFileCache\n } else {\n // we only check the routeNodeCache here\n // if the file's state is only up-to-date in the shadow cache we need to re-run\n cacheEntry = this.routeNodeCache.get(e.path)\n }\n const change = await this.didFileChangeComparedToCache(\n { path: e.path },\n cacheEntry,\n )\n if (change.result === false) {\n return null\n }\n }\n return e\n }),\n )\n ).filter((e) => e !== null)\n\n if (remainingEvents.length === 0) {\n break\n }\n\n try {\n await this.generatorInternal()\n } catch (err) {\n const errArray = !Array.isArray(err) ? [err] : err\n\n const recoverableErrors = errArray.filter((e) => isRerun(e))\n if (recoverableErrors.length === errArray.length) {\n this.fileEventQueue.push(...recoverableErrors.map((e) => e.event))\n recoverableErrors.forEach((e) => {\n if (e.msg) {\n this.logger.info(e.msg)\n }\n })\n } else {\n const unrecoverableErrors = errArray.filter((e) => !isRerun(e))\n this.runPromise = undefined\n throw new Error(\n unrecoverableErrors.map((e) => (e as Error).message).join(),\n )\n }\n }\n } while (this.fileEventQueue.length)\n this.runPromise = undefined\n })()\n return this.runPromise\n }\n\n private async generatorInternal() {\n let writeRouteTreeFile: boolean | 'force' = false\n\n let getRouteNodesResult: GetRouteNodesResult\n\n if (this.config.virtualRouteConfig) {\n getRouteNodesResult = await virtualGetRouteNodes(this.config, this.root, {\n indexTokenSegmentRegex: this.indexTokenSegmentRegex,\n routeTokenSegmentRegex: this.routeTokenSegmentRegex,\n })\n } else {\n getRouteNodesResult = await physicalGetRouteNodes(\n this.config,\n this.root,\n {\n indexTokenSegmentRegex: this.indexTokenSegmentRegex,\n routeTokenSegmentRegex: this.routeTokenSegmentRegex,\n },\n )\n }\n\n const {\n rootRouteNode,\n routeNodes: beforeRouteNodes,\n physicalDirectories,\n } = getRouteNodesResult\n if (rootRouteNode === undefined) {\n let errorMessage = `rootRouteNode must not be undefined. Make sure you've added your root route into the route-tree.`\n if (!this.config.virtualRouteConfig) {\n errorMessage += `\\nMake sure that you add a \"${rootPathId}.${this.config.disableTypes ? 'js' : 'tsx'}\" file to your routes directory.\\nAdd the file in: \"${this.config.routesDirectory}/${rootPathId}.${this.config.disableTypes ? 'js' : 'tsx'}\"`\n }\n throw new Error(errorMessage)\n }\n this.physicalDirectories = physicalDirectories\n\n await this.handleRootNode(rootRouteNode)\n\n const preRouteNodes = multiSortBy(beforeRouteNodes, [\n (d) => (d.routePath === '/' ? -1 : 1),\n (d) =>\n d.routePath === undefined\n ? undefined\n : countSlashSeparatedParts(d.routePath),\n (d) => (d.filePath.match(this.indexTokenFilenameRegex) ? 1 : -1),\n (d) => (d.filePath.match(Generator.componentPieceRegex) ? 1 : -1),\n (d) => (d.filePath.match(this.routeTokenFilenameRegex) ? -1 : 1),\n (d) => (d.routePath?.endsWith('/') ? -1 : 1),\n (d) => d.routePath,\n ]).filter((d) => {\n // Exclude the root route itself, but keep component/loader pieces for the root\n if (d.routePath === `/${rootPathId}`) {\n return [\n 'component',\n 'errorComponent',\n 'notFoundComponent',\n 'pendingComponent',\n 'loader',\n 'lazy',\n ].includes(d._fsRouteType)\n }\n return true\n })\n\n const routeFileAllResult = await Promise.allSettled(\n preRouteNodes\n // only process routes that are backed by an actual file\n .filter((n) => !n.isVirtualParentRoute && !n.isVirtual)\n .map((n) => this.processRouteNodeFile(n)),\n )\n\n const rejections = routeFileAllResult.filter(\n (result) => result.status === 'rejected',\n )\n if (rejections.length > 0) {\n throw rejections.map((e) => e.reason)\n }\n\n const routeFileResult = routeFileAllResult.flatMap((result) => {\n if (result.status === 'fulfilled' && result.value !== null) {\n if (result.value.shouldWriteTree) {\n writeRouteTreeFile = true\n }\n return result.value.node\n }\n return []\n })\n\n // reset children in case we re-use a node from the cache\n routeFileResult.forEach((r) => (r.children = undefined))\n\n const acc: HandleNodeAccumulator = {\n routeTree: [],\n routeNodes: [],\n routePiecesByPath: {},\n routeNodesByPath: new Map(),\n }\n\n const prefixMap = new RoutePrefixMap(routeFileResult)\n\n for (const node of routeFileResult) {\n Generator.handleNode(node, acc, prefixMap, this.config)\n }\n\n this.crawlingResult = { rootRouteNode, routeFileResult, acc }\n\n // this is the first time the generator runs, so read in the route tree file if it exists yet\n if (!this.routeTreeFileCache) {\n const routeTreeFile = await this.fs.readFile(this.generatedRouteTreePath)\n if (routeTreeFile !== 'file-not-existing') {\n this.routeTreeFileCache = {\n fileContent: routeTreeFile.fileContent,\n mtimeMs: routeTreeFile.stat.mtimeMs,\n }\n }\n writeRouteTreeFile = true\n } else {\n const routeTreeFileChange = await this.didFileChangeComparedToCache(\n { path: this.generatedRouteTreePath },\n this.routeTreeFileCache,\n )\n if (routeTreeFileChange.result !== false) {\n writeRouteTreeFile = 'force'\n if (routeTreeFileChange.result === true) {\n const routeTreeFile = await this.fs.readFile(\n this.generatedRouteTreePath,\n )\n if (routeTreeFile !== 'file-not-existing') {\n this.routeTreeFileCache = {\n fileContent: routeTreeFile.fileContent,\n mtimeMs: routeTreeFile.stat.mtimeMs,\n }\n }\n }\n }\n }\n\n if (!writeRouteTreeFile) {\n // only needs to be done if no other changes have been detected yet\n // compare shadowCache and cache to identify deleted routes\n if (this.routeNodeCache.size !== this.routeNodeShadowCache.size) {\n writeRouteTreeFile = true\n } else {\n for (const fullPath of this.routeNodeCache.keys()) {\n if (!this.routeNodeShadowCache.has(fullPath)) {\n writeRouteTreeFile = true\n break\n }\n }\n }\n }\n\n if (!writeRouteTreeFile) {\n this.swapCaches()\n return\n }\n\n const buildResult = this.buildRouteTree({\n rootRouteNode,\n acc,\n routeFileResult,\n })\n let routeTreeContent = buildResult.routeTreeContent\n\n routeTreeContent = this.config.enableRouteTreeFormatting\n ? await format(routeTreeContent, this.config)\n : routeTreeContent\n\n let newMtimeMs: bigint | undefined\n if (this.routeTreeFileCache) {\n if (this.routeTreeFileCache.fileContent === routeTreeContent) {\n // existing route tree file is already up-to-date, don't write it.\n // When 'force' was set because an external change was detected,\n // we still re-read and re-check here, but if the generated content\n // matches we skip the write to avoid triggering another watcher cycle.\n } else {\n const newRouteTreeFileStat = await this.safeFileWrite({\n filePath: this.generatedRouteTreePath,\n newContent: routeTreeContent,\n strategy: {\n type: 'mtime',\n expectedMtimeMs: this.routeTreeFileCache.mtimeMs,\n },\n })\n newMtimeMs = newRouteTreeFileStat.mtimeMs\n }\n } else {\n const newRouteTreeFileStat = await this.safeFileWrite({\n filePath: this.generatedRouteTreePath,\n newContent: routeTreeContent,\n strategy: {\n type: 'new-file',\n },\n })\n newMtimeMs = newRouteTreeFileStat.mtimeMs\n }\n\n if (newMtimeMs !== undefined) {\n this.routeTreeFileCache = {\n fileContent: routeTreeContent,\n mtimeMs: newMtimeMs,\n }\n }\n\n this.plugins.map((plugin) => {\n return plugin.onRouteTreeChanged?.({\n routeTree: buildResult.routeTree,\n routeNodes: buildResult.routeNodes,\n acc,\n rootRouteNode,\n })\n })\n this.swapCaches()\n }\n\n private swapCaches() {\n this.routeNodeCache = this.routeNodeShadowCache\n this.routeNodeShadowCache = new Map()\n }\n\n public buildRouteTree(opts: {\n rootRouteNode: RouteNode\n acc: HandleNodeAccumulator\n routeFileResult: Array<RouteNode>\n config?: Partial<Config>\n }) {\n const config = { ...this.config, ...(opts.config || {}) }\n\n const { rootRouteNode, acc } = opts\n\n // Use pre-compiled regex if config hasn't been overridden, otherwise create new one\n const indexTokenSegmentRegex =\n config.indexToken === this.config.indexToken\n ? this.indexTokenSegmentRegex\n : createTokenRegex(config.indexToken, { type: 'segment' })\n\n const sortedRouteNodes = sortRouteNodes(\n acc.routeNodes,\n indexTokenSegmentRegex,\n )\n\n const routeImports: Array<ImportDeclaration> = []\n const virtualRouteNodes: Array<string> = []\n\n for (const node of sortedRouteNodes) {\n if (node.isVirtual) {\n virtualRouteNodes.push(\n `const ${node.variableName}RouteImport = createFileRoute('${node.routePath}')()`,\n )\n } else {\n routeImports.push(\n getImportForRouteNode(\n node,\n config,\n this.generatedRouteTreePath,\n this.root,\n ),\n )\n }\n }\n\n const imports: Array<ImportDeclaration> = []\n if (virtualRouteNodes.length > 0) {\n imports.push({\n specifiers: [{ imported: 'createFileRoute' }],\n source: this.targetTemplate.fullPkg,\n })\n }\n // Add lazyRouteComponent import if there are component pieces\n let hasComponentPieces = false\n let hasLoaderPieces = false\n for (const node of sortedRouteNodes) {\n const pieces = acc.routePiecesByPath[node.routePath!]\n if (pieces) {\n if (\n pieces.component ||\n pieces.errorComponent ||\n pieces.notFoundComponent ||\n pieces.pendingComponent\n ) {\n hasComponentPieces = true\n }\n if (pieces.loader) {\n hasLoaderPieces = true\n }\n if (hasComponentPieces && hasLoaderPieces) break\n }\n }\n if (hasComponentPieces || hasLoaderPieces) {\n const runtimeImport: ImportDeclaration = {\n specifiers: [],\n source: this.targetTemplate.fullPkg,\n }\n if (hasComponentPieces) {\n runtimeImport.specifiers.push({ imported: 'lazyRouteComponent' })\n }\n if (hasLoaderPieces) {\n runtimeImport.specifiers.push({ imported: 'lazyFn' })\n }\n imports.push(runtimeImport)\n }\n const routeTreeConfig = buildRouteTreeConfig(\n acc.routeTree,\n config.disableTypes,\n )\n\n const createUpdateRoutes = sortedRouteNodes.map((node) => {\n const pieces = acc.routePiecesByPath[node.routePath!]\n const loaderNode = pieces?.loader\n const componentNode = pieces?.component\n const errorComponentNode = pieces?.errorComponent\n const notFoundComponentNode = pieces?.notFoundComponent\n const pendingComponentNode = pieces?.pendingComponent\n const lazyComponentNode = pieces?.lazy\n\n return [\n [\n `const ${node.variableName}Route = ${node.variableName}RouteImport.update({\n ${[\n `id: '${node.path}'`,\n !node.isNonPath ||\n (node._fsRouteType === 'pathless_layout' && node.cleanedPath)\n ? `path: '${node.cleanedPath}'`\n : undefined,\n `getParentRoute: () => ${findParent(node)}`,\n ]\n .filter(Boolean)\n .join(',')}\n }${config.disableTypes ? '' : 'as any'})`,\n loaderNode\n ? `.updateLoader({ loader: lazyFn(() => import('./${replaceBackslash(\n removeExt(\n path.relative(\n path.dirname(config.generatedRouteTree),\n path.resolve(config.routesDirectory, loaderNode.filePath),\n ),\n config.addExtensions,\n ),\n )}'), 'loader') })`\n : '',\n componentNode ||\n errorComponentNode ||\n notFoundComponentNode ||\n pendingComponentNode\n ? `.update({\n ${(\n [\n ['component', componentNode],\n ['errorComponent', errorComponentNode],\n ['notFoundComponent', notFoundComponentNode],\n ['pendingComponent', pendingComponentNode],\n ] as const\n )\n .filter((d) => d[1])\n .map((d) => {\n // For .vue files, use 'default' as the export name since Vue SFCs export default\n const isVueFile = d[1]!.filePath.endsWith('.vue')\n const exportName = isVueFile ? 'default' : d[0]\n // Keep .vue extension for Vue files since Vite requires it\n const importPath = replaceBackslash(\n isVueFile\n ? path.relative(\n path.dirname(config.generatedRouteTree),\n path.resolve(\n config.routesDirectory,\n d[1]!.filePath,\n ),\n )\n : removeExt(\n path.relative(\n path.dirname(config.generatedRouteTree),\n path.resolve(\n config.routesDirectory,\n d[1]!.filePath,\n ),\n ),\n config.addExtensions,\n ),\n )\n return `${\n d[0]\n }: lazyRouteComponent(() => import('./${importPath}'), '${exportName}')`\n })\n .join('\\n,')}\n })`\n : '',\n lazyComponentNode\n ? (() => {\n // For .vue files, use 'default' export since Vue SFCs export default\n const isVueFile = lazyComponentNode.filePath.endsWith('.vue')\n const exportAccessor = isVueFile ? 'd.default' : 'd.Route'\n // Keep .vue extension for Vue files since Vite requires it\n const importPath = replaceBackslash(\n isVueFile\n ? path.relative(\n path.dirname(config.generatedRouteTree),\n path.resolve(\n config.routesDirectory,\n lazyComponentNode.filePath,\n ),\n )\n : removeExt(\n path.relative(\n path.dirname(config.generatedRouteTree),\n path.resolve(\n config.routesDirectory,\n lazyComponentNode.filePath,\n ),\n ),\n config.addExtensions,\n ),\n )\n return `.lazy(() => import('./${importPath}').then((d) => ${exportAccessor}))`\n })()\n : '',\n ].join(''),\n ].join('\\n\\n')\n })\n\n // Generate update for root route if it has component pieces\n const rootRoutePath = `/${rootPathId}`\n const rootPieces = acc.routePiecesByPath[rootRoutePath]\n const rootComponentNode = rootPieces?.component\n const rootErrorComponentNode = rootPieces?.errorComponent\n const rootNotFoundComponentNode = rootPieces?.notFoundComponent\n const rootPendingComponentNode = rootPieces?.pendingComponent\n\n let rootRouteUpdate = ''\n if (\n rootComponentNode ||\n rootErrorComponentNode ||\n rootNotFoundComponentNode ||\n rootPendingComponentNode\n ) {\n rootRouteUpdate = `const rootRouteWithChildren = rootRouteImport${\n rootComponentNode ||\n rootErrorComponentNode ||\n rootNotFoundComponentNode ||\n rootPendingComponentNode\n ? `.update({\n ${(\n [\n ['component', rootComponentNode],\n ['errorComponent', rootErrorComponentNode],\n ['notFoundComponent', rootNotFoundComponentNode],\n ['pendingComponent', rootPendingComponentNode],\n ] as const\n )\n .filter((d) => d[1])\n .map((d) => {\n // For .vue files, use 'default' as the export name since Vue SFCs export default\n const isVueFile = d[1]!.filePath.endsWith('.vue')\n const exportName = isVueFile ? 'default' : d[0]\n // Keep .vue extension for Vue files since Vite requires it\n const importPath = replaceBackslash(\n isVueFile\n ? path.relative(\n path.dirname(config.generatedRouteTree),\n path.resolve(config.routesDirectory, d[1]!.filePath),\n )\n : removeExt(\n path.relative(\n path.dirname(config.generatedRouteTree),\n path.resolve(\n config.routesDirectory,\n d[1]!.filePath,\n ),\n ),\n config.addExtensions,\n ),\n )\n return `${d[0]}: lazyRouteComponent(() => import('./${importPath}'), '${exportName}')`\n })\n .join('\\n,')}\n })`\n : ''\n }._addFileChildren(rootRouteChildren)${config.disableTypes ? '' : `._addFileTypes<FileRouteTypes>()`}`\n }\n\n let fileRoutesByPathInterface = ''\n let fileRoutesByFullPath = ''\n\n if (!config.disableTypes) {\n const routeNodesByFullPath = createRouteNodesByFullPath(acc.routeNodes)\n const routeNodesByTo = createRouteNodesByTo(acc.routeNodes)\n const routeNodesById = createRouteNodesById(acc.routeNodes)\n\n fileRoutesByFullPath = [\n `export interface FileRoutesByFullPath {\n${[...routeNodesByFullPath.entries()]\n .filter(([fullPath]) => fullPath)\n .map(([fullPath, routeNode]) => {\n return `'${fullPath}': typeof ${getResolvedRouteNodeVariableName(routeNode)}`\n })}\n}`,\n `export interface FileRoutesByTo {\n${[...routeNodesByTo.entries()]\n .filter(([to]) => to)\n .map(([to, routeNode]) => {\n return `'${to}': typeof ${getResolvedRouteNodeVariableName(routeNode)}`\n })}\n}`,\n `export interface FileRoutesById {\n'${rootRouteId}': typeof rootRouteImport,\n${[...routeNodesById.entries()].map(([id, routeNode]) => {\n return `'${id}': typeof ${getResolvedRouteNodeVariableName(routeNode)}`\n})}\n}`,\n `export interface FileRouteTypes {\nfileRoutesByFullPath: FileRoutesByFullPath\nfullPaths: ${\n acc.routeNodes.length > 0\n ? [...routeNodesByFullPath.keys()]\n .filter((fullPath) => fullPath)\n .map((fullPath) => `'${fullPath}'`)\n .join('|')\n : 'never'\n }\nfileRoutesByTo: FileRoutesByTo\nto: ${\n acc.routeNodes.length > 0\n ? [...routeNodesByTo.keys()]\n .filter((to) => to)\n .map((to) => `'${to}'`)\n .join('|')\n : 'never'\n }\nid: ${[`'${rootRouteId}'`, ...[...routeNodesById.keys()].map((id) => `'${id}'`)].join('|')}\nfileRoutesById: FileRoutesById\n}`,\n `export interface RootRouteChildren {\n${acc.routeTree.map((child) => `${child.variableName}Route: typeof ${getResolvedRouteNodeVariableName(child)}`).join(',')}\n}`,\n ].join('\\n')\n\n fileRoutesByPathInterface = buildFileRoutesByPathInterface({\n module: this.targetTemplate.fullPkg,\n interfaceName: 'FileRoutesByPath',\n routeNodes: sortedRouteNodes,\n config,\n })\n }\n\n const routeTree = [\n `const rootRouteChildren${config.disableTypes ? '' : `: RootRouteChildren`} = {\n ${acc.routeTree\n .map(\n (child) =>\n `${child.variableName}Route: ${getResolvedRouteNodeVariableName(child)}`,\n )\n .join(',')}\n}`,\n rootRouteUpdate\n ? rootRouteUpdate.replace(\n 'const rootRouteWithChildren = ',\n 'export const routeTree = ',\n )\n : `export const routeTree = rootRouteImport._addFileChildren(rootRouteChildren)${config.disableTypes ? '' : `._addFileTypes<FileRouteTypes>()`}`,\n ].join('\\n')\n\n checkRouteFullPathUniqueness(\n sortedRouteNodes.filter(\n (d) => d.children === undefined && 'lazy' !== d._fsRouteType,\n ),\n config,\n )\n\n let mergedImports = mergeImportDeclarations(imports)\n if (config.disableTypes) {\n mergedImports = mergedImports.filter((d) => d.importKind !== 'type')\n }\n\n const importStatements = mergedImports.map(buildImportString)\n\n const rootRouteImport = getImportForRouteNode(\n rootRouteNode,\n config,\n this.generatedRouteTreePath,\n this.root,\n )\n routeImports.unshift(rootRouteImport)\n\n let footer: Array<string> = []\n if (config.routeTreeFileFooter) {\n if (Array.isArray(config.routeTreeFileFooter)) {\n footer = config.routeTreeFileFooter\n } else {\n footer = config.routeTreeFileFooter()\n }\n }\n const routeTreeContent = [\n ...config.routeTreeFileHeader,\n `// This file was automatically generated by TanStack Router.\n// You should NOT make any changes in this file as it will be overwritten.\n// Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified.`,\n [...importStatements].join('\\n'),\n mergeImportDeclarations(routeImports).map(buildImportString).join('\\n'),\n virtualRouteNodes.join('\\n'),\n createUpdateRoutes.join('\\n'),\n fileRoutesByFullPath,\n fileRoutesByPathInterface,\n routeTreeConfig.join('\\n'),\n routeTree,\n ...footer,\n ]\n .filter(Boolean)\n .join('\\n\\n')\n return {\n routeTreeContent,\n routeTree: acc.routeTree,\n routeNodes: acc.routeNodes,\n }\n }\n\n private async processRouteNodeFile(node: RouteNode): Promise<{\n shouldWriteTree: boolean\n cacheEntry: RouteNodeCacheEntry\n node: RouteNode\n } | null> {\n const result = await this.isRouteFileCacheFresh(node)\n\n if (result.status === 'fresh') {\n return {\n node: result.cacheEntry.node,\n shouldWriteTree: false,\n cacheEntry: result.cacheEntry,\n }\n }\n\n const previousCacheEntry = result.cacheEntry\n\n const existingRouteFile = await this.fs.readFile(node.fullPath)\n if (existingRouteFile === 'file-not-existing') {\n throw new Error(`⚠️ File ${node.fullPath} does not exist`)\n }\n\n if (node.routePath) {\n validateRouteParams(node.routePath, node.filePath, this.logger)\n }\n\n const updatedCacheEntry: RouteNodeCacheEntry = {\n fileContent: existingRouteFile.fileContent,\n mtimeMs: existingRouteFile.stat.mtimeMs,\n routeId: node.routePath ?? '$$TSR_NO_ROUTE_PATH_ASSIGNED$$',\n node,\n }\n\n const escapedRoutePath = node.routePath?.replaceAll('$', '$$') ?? ''\n\n let shouldWriteRouteFile = false\n let shouldWriteTree = false\n // now we need to either scaffold the file or transform it\n if (!existingRouteFile.fileContent) {\n shouldWriteRouteFile = true\n shouldWriteTree = true\n // Creating a new lazy route file\n if (node._fsRouteType === 'lazy') {\n const tLazyRouteTemplate = this.targetTemplate.lazyRoute\n // Check by default check if the user has a specific lazy route template\n // If not, check if the user has a route template and use that instead\n updatedCacheEntry.fileContent = await fillTemplate(\n this.config,\n (this.config.customScaffolding?.lazyRouteTemplate ||\n this.config.customScaffolding?.routeTemplate) ??\n tLazyRouteTemplate.template(),\n {\n tsrImports: tLazyRouteTemplate.imports.tsrImports(),\n tsrPath: escapedRoutePath.replaceAll(/\\{(.+?)\\}/gm, '$1'),\n tsrExportStart:\n tLazyRouteTemplate.imports.tsrExportStart(escapedRoutePath),\n tsrExportEnd: tLazyRouteTemplate.imports.tsrExportEnd(),\n },\n )\n } else if (\n // Creating a new normal route file\n (['layout', 'static'] satisfies Array<FsRouteType>).some(\n (d) => d === node._fsRouteType,\n ) ||\n (\n [\n 'component',\n 'pendingComponent',\n 'errorComponent',\n 'notFoundComponent',\n 'loader',\n ] satisfies Array<FsRouteType>\n ).every((d) => d !== node._fsRouteType)\n ) {\n const tRouteTemplate = this.targetTemplate.route\n updatedCacheEntry.fileContent = await fillTemplate(\n this.config,\n this.config.customScaffolding?.routeTemplate ??\n tRouteTemplate.template(),\n {\n tsrImports: tRouteTemplate.imports.tsrImports(),\n tsrPath: escapedRoutePath.replaceAll(/\\{(.+?)\\}/gm, '$1'),\n tsrExportStart:\n tRouteTemplate.imports.tsrExportStart(escapedRoutePath),\n tsrExportEnd: tRouteTemplate.imports.tsrExportEnd(),\n },\n )\n } else {\n return null\n }\n }\n\n // Check if this is a Vue component file\n // Vue SFC files (.vue) don't need transformation as they can't have a Route export\n const isVueFile = node.filePath.endsWith('.vue')\n\n if (!isVueFile) {\n // transform the file\n const transformResult = await transform({\n source: updatedCacheEntry.fileContent,\n filename: node.fullPath,\n ctx: {\n target: this.config.target,\n routeId: escapedRoutePath,\n lazy: node._fsRouteType === 'lazy',\n },\n node,\n })\n\n if (transformResult.result === 'no-route-export') {\n const fileName = path.basename(node.fullPath)\n const dirName = path.dirname(node.fullPath)\n const ignorePrefix = this.config.routeFileIgnorePrefix\n const ignorePattern = this.config.routeFileIgnorePattern\n const suggestedFileName = `${ignorePrefix}${fileName}`\n const suggestedFullPath = path.join(dirName, suggestedFileName)\n\n let message = `Warning: Route file \"${node.fullPath}\" does not export a Route. This file will not be included in the route tree.`\n message += `\\n\\nIf this file is not intended to be a route, you can exclude it using one of these options:`\n message += `\\n 1. Rename the file to \"${suggestedFullPath}\" (prefix with \"${ignorePrefix}\")`\n message += `\\n 2. Use 'routeFileIgnorePattern' in your config to match this file`\n message += `\\n\\nCurrent configuration:`\n message += `\\n routeFileIgnorePrefix: \"${ignorePrefix}\"`\n message += `\\n routeFileIgnorePattern: ${ignorePattern ? `\"${ignorePattern}\"` : 'undefined'}`\n\n this.logger.warn(message)\n return null\n }\n if (transformResult.result === 'error') {\n throw new Error(\n `Error transforming route file ${node.fullPath}: ${transformResult.error}`,\n )\n }\n if (transformResult.result === 'modified') {\n updatedCacheEntry.fileContent = transformResult.output\n shouldWriteRouteFile = true\n }\n }\n\n for (const plugin of this.plugins) {\n plugin.afterTransform?.({ node, prevNode: previousCacheEntry?.node })\n }\n\n // file was changed\n if (shouldWriteRouteFile) {\n const stats = await this.safeFileWrite({\n filePath: node.fullPath,\n newContent: updatedCacheEntry.fileContent,\n strategy: {\n type: 'mtime',\n expectedMtimeMs: updatedCacheEntry.mtimeMs,\n },\n })\n updatedCacheEntry.mtimeMs = stats.mtimeMs\n }\n\n this.routeNodeShadowCache.set(node.fullPath, updatedCacheEntry)\n return {\n node,\n shouldWriteTree,\n cacheEntry: updatedCacheEntry,\n }\n }\n\n private async didRouteFileChangeComparedToCache(\n file: {\n path: string\n mtimeMs?: bigint\n },\n cache: 'routeNodeCache' | 'routeNodeShadowCache',\n ): Promise<FileCacheChange<RouteNodeCacheEntry>> {\n const cacheEntry = this[cache].get(file.path)\n return this.didFileChangeComparedToCache(file, cacheEntry)\n }\n\n private async didFileChangeComparedToCache<\n TCacheEntry extends GeneratorCacheEntry,\n >(\n file: {\n path: string\n mtimeMs?: bigint\n },\n cacheEntry: TCacheEntry | undefined,\n ): Promise<FileCacheChange<TCacheEntry>> {\n // for now we rely on the modification time of the file\n // to determine if the file has changed\n // we could also compare the file content but this would be slower as we would have to read the file\n\n if (!cacheEntry) {\n return { result: 'file-not-in-cache' }\n }\n let mtimeMs = file.mtimeMs\n\n if (mtimeMs === undefined) {\n try {\n const currentStat = await this.fs.stat(file.path)\n mtimeMs = currentStat.mtimeMs\n } catch {\n return { result: 'cannot-stat-file' }\n }\n }\n return { result: mtimeMs !== cacheEntry.mtimeMs, mtimeMs, cacheEntry }\n }\n\n private async safeFileWrite(opts: {\n filePath: string\n newContent: string\n strategy:\n | {\n type: 'mtime'\n expectedMtimeMs: bigint\n }\n | {\n type: 'new-file'\n }\n }) {\n const tmpPath = this.getTempFileName(opts.filePath)\n await this.fs.writeFile(tmpPath, opts.newContent)\n\n if (opts.strategy.type === 'mtime') {\n const beforeStat = await this.fs.stat(opts.filePath)\n if (beforeStat.mtimeMs !== opts.strategy.expectedMtimeMs) {\n throw rerun({\n msg: `File ${opts.filePath} was modified by another process during processing.`,\n event: { type: 'update', path: opts.filePath },\n })\n }\n const newFileState = await this.fs.stat(tmpPath)\n if (newFileState.mode !== beforeStat.mode) {\n await this.fs.chmod(tmpPath, beforeStat.mode)\n }\n if (\n newFileState.uid !== beforeStat.uid ||\n newFileState.gid !== beforeStat.gid\n ) {\n try {\n await this.fs.chown(tmpPath, beforeStat.uid, beforeStat.gid)\n } catch (err) {\n if (\n typeof err === 'object' &&\n err !== null &&\n 'code' in err &&\n (err as any).code === 'EPERM'\n ) {\n console.warn(\n `[safeFileWrite] chown failed: ${(err as any).message}`,\n )\n } else {\n throw err\n }\n }\n }\n } else {\n if (await checkFileExists(opts.filePath)) {\n throw rerun({\n msg: `File ${opts.filePath} already exists. Cannot overwrite.`,\n event: { type: 'update', path: opts.filePath },\n })\n }\n }\n\n await this.fs.rename(tmpPath, opts.filePath)\n\n // stat the target file AFTER rename so the cached mtime matches\n // what the filesystem reports for the actual file path.\n // Previously we stat'd the temp file before rename, but rename()\n // can assign a different mtime to the target on some filesystems,\n // causing the cache to be permanently stale.\n const stat = await this.fs.stat(opts.filePath)\n\n return stat\n }\n\n private getTempFileName(filePath: string) {\n const absPath = path.resolve(filePath)\n const hash = crypto.createHash('md5').update(absPath).digest('hex')\n // lazy initialize sessionId to only create tmpDir when it is first needed\n if (!this.sessionId) {\n // ensure the directory exists\n mkdirSync(this.config.tmpDir, { recursive: true })\n this.sessionId = crypto.randomBytes(4).toString('hex')\n }\n return path.join(this.config.tmpDir, `${this.sessionId}-${hash}`)\n }\n\n private async isRouteFileCacheFresh(node: RouteNode): Promise<\n | {\n status: 'fresh'\n cacheEntry: RouteNodeCacheEntry\n }\n | { status: 'stale'; cacheEntry?: RouteNodeCacheEntry }\n > {\n const fileChangedCache = await this.didRouteFileChangeComparedToCache(\n { path: node.fullPath },\n 'routeNodeCache',\n )\n if (fileChangedCache.result === false) {\n this.routeNodeShadowCache.set(node.fullPath, fileChangedCache.cacheEntry)\n return {\n status: 'fresh',\n cacheEntry: fileChangedCache.cacheEntry,\n }\n }\n if (fileChangedCache.result === 'cannot-stat-file') {\n throw new Error(`⚠️ expected route file to exist at ${node.fullPath}`)\n }\n const mtimeMs =\n fileChangedCache.result === true ? fileChangedCache.mtimeMs : undefined\n\n const shadowCacheFileChange = await this.didRouteFileChangeComparedToCache(\n { path: node.fullPath, mtimeMs },\n 'routeNodeShadowCache',\n )\n\n if (shadowCacheFileChange.result === 'cannot-stat-file') {\n throw new Error(`⚠️ expected route file to exist at ${node.fullPath}`)\n }\n\n if (shadowCacheFileChange.result === false) {\n // shadow cache has latest file state already\n if (fileChangedCache.result === true) {\n return {\n status: 'fresh',\n cacheEntry: shadowCacheFileChange.cacheEntry,\n }\n }\n }\n\n if (fileChangedCache.result === 'file-not-in-cache') {\n return {\n status: 'stale',\n }\n }\n return { status: 'stale', cacheEntry: fileChangedCache.cacheEntry }\n }\n\n private async handleRootNode(node: RouteNode) {\n const result = await this.isRouteFileCacheFresh(node)\n\n if (result.status === 'fresh') {\n this.routeNodeShadowCache.set(node.fullPath, result.cacheEntry)\n }\n const rootNodeFile = await this.fs.readFile(node.fullPath)\n if (rootNodeFile === 'file-not-existing') {\n throw new Error(`⚠️ expected root route to exist at ${node.fullPath}`)\n }\n\n const updatedCacheEntry: RouteNodeCacheEntry = {\n fileContent: rootNodeFile.fileContent,\n mtimeMs: rootNodeFile.stat.mtimeMs,\n routeId: node.routePath ?? '$$TSR_NO_ROOT_ROUTE_PATH_ASSIGNED$$',\n node,\n }\n\n // scaffold the root route\n if (!rootNodeFile.fileContent) {\n const rootTemplate = this.targetTemplate.rootRoute\n const rootRouteContent = await fillTemplate(\n this.config,\n rootTemplate.template(),\n {\n tsrImports: rootTemplate.imports.tsrImports(),\n tsrPath: rootPathId,\n tsrExportStart: rootTemplate.imports.tsrExportStart(),\n tsrExportEnd: rootTemplate.imports.tsrExportEnd(),\n },\n )\n\n this.logger.log(`🟡 Creating ${node.fullPath}`)\n const stats = await this.safeFileWrite({\n filePath: node.fullPath,\n newContent: rootRouteContent,\n strategy: {\n type: 'mtime',\n expectedMtimeMs: rootNodeFile.stat.mtimeMs,\n },\n })\n updatedCacheEntry.fileContent = rootRouteContent\n updatedCacheEntry.mtimeMs = stats.mtimeMs\n }\n\n this.routeNodeShadowCache.set(node.fullPath, updatedCacheEntry)\n }\n\n public async getCrawlingResult(): Promise<CrawlingResult | undefined> {\n await this.runPromise\n return this.crawlingResult\n }\n\n private static handleNode(\n node: RouteNode,\n acc: HandleNodeAccumulator,\n prefixMap: RoutePrefixMap,\n config?: Config,\n ) {\n let parentRoute = hasParentRoute(prefixMap, node, node.routePath)\n\n // Check routeNodesByPath for a closer parent that may not be in prefixMap.\n //\n // Why: The prefixMap excludes lazy routes by design. When lazy-only routes are\n // nested inside a pathless layout, the virtual route created from the lazy file\n // won't be in the prefixMap, but it will be in routeNodesByPath.\n //\n // Example: Given files _layout/path.lazy.tsx and _layout/path.index.lazy.tsx:\n // - prefixMap contains: /_layout (from route.tsx)\n // - routeNodesByPath contains: /_layout AND /_layout/path (virtual from lazy)\n // - For /_layout/path/, hasParentRoute returns /_layout (wrong)\n // - But the correct parent is /_layout/path (the virtual route from path.lazy.tsx)\n //\n // We walk up the path segments to find the closest registered parent. This handles\n // cases where multiple path segments (e.g., $a/$b) don't have intermediate routes.\n if (node.routePath) {\n let searchPath = node.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 candidate = acc.routeNodesByPath.get(searchPath)\n if (candidate && candidate.routePath !== node.routePath) {\n // Found a parent in routeNodesByPath\n // If it's different from what prefixMap found AND is a closer match, use it\n if (candidate !== parentRoute) {\n // Check if this candidate is a closer parent than what prefixMap found\n // (longer path prefix means closer parent)\n if (\n !parentRoute ||\n (candidate.routePath?.length ?? 0) >\n (parentRoute.routePath?.length ?? 0)\n ) {\n parentRoute = candidate\n }\n }\n break\n }\n }\n }\n\n // Virtual routes may have an explicit parent from virtual config.\n // If we can find that exact parent, use it to prevent auto-nesting siblings\n // based on path prefix matching (#5822, #5431).\n if (node._virtualParentRoutePath !== undefined) {\n const explicitParent = acc.routeNodesByPath.get(\n node._virtualParentRoutePath,\n )\n if (explicitParent) {\n parentRoute = explicitParent\n } else if (node._virtualParentRoutePath === `/${rootPathId}`) {\n // The explicit parent is the root route (handled separately).\n // Override path-based inference so this node stays at root level.\n parentRoute = null\n }\n // Otherwise the explicit parent was a virtual file-less route that got\n // filtered out. Fall back to the path-based parentRoute already computed.\n }\n\n if (parentRoute) node.parent = parentRoute\n\n node.path = determineNodePath(node)\n\n const trimmedPath = trimPathLeft(node.path ?? '')\n const originalPath =\n node.originalRoutePath && node.parent?.originalRoutePath\n ? node.originalRoutePath.replace(node.parent.originalRoutePath, '') ||\n '/'\n : node.originalRoutePath\n const routePathSegmentMetadata = getRoutePathSegmentMetadataForPath(\n node,\n node.path ?? '/',\n node.parent?.routePath,\n )\n const trimmedOriginalPath = trimPathLeft(originalPath ?? '')\n\n const split = trimmedPath.split('/')\n const pathSplit = (node.path ?? '').split('/')\n const originalSplit = trimmedOriginalPath.split('/')\n const lastRouteSegment = split[split.length - 1] ?? trimmedPath\n const lastOriginalSegment =\n originalSplit[originalSplit.length - 1] ?? trimmedOriginalPath\n const lastRouteSegmentMetadata =\n routePathSegmentMetadata?.[pathSplit.length - 1]\n\n // A segment is non-path if it starts with underscore AND the underscore is not escaped\n node.isNonPath =\n (!lastRouteSegmentMetadata?.literalLeadingUnderscore &&\n isSegmentPathless(lastRouteSegment, lastOriginalSegment)) ||\n split.every((part) => this.routeGroupPatternRegex.test(part))\n\n // Use a single pass so layout removal does not desync escaped underscore checks.\n node.cleanedPath = removeGroups(\n removeLayoutSegmentsAndUnderscoresWithEscape(\n node.path,\n originalPath,\n routePathSegmentMetadata,\n ),\n )\n\n if (\n node._fsRouteType === 'layout' ||\n node._fsRouteType === 'pathless_layout'\n ) {\n node.cleanedPath = removeTrailingSlash(node.cleanedPath)\n }\n\n if (\n !node.isVirtual &&\n (\n [\n 'lazy',\n 'loader',\n 'component',\n 'pendingComponent',\n 'errorComponent',\n 'notFoundComponent',\n ] satisfies Array<FsRouteType>\n ).some((d) => d === node._fsRouteType)\n ) {\n acc.routePiecesByPath[node.routePath!] =\n acc.routePiecesByPath[node.routePath!] || {}\n\n const pieceKey =\n node._fsRouteType === 'lazy'\n ? 'lazy'\n : (node._fsRouteType as keyof (typeof acc.routePiecesByPath)[string])\n acc.routePiecesByPath[node.routePath!]![pieceKey] = node\n\n const anchorRoute = acc.routeNodesByPath.get(node.routePath!)\n\n // Don't create virtual routes for root route component pieces - the root route is handled separately\n if (!anchorRoute && node.routePath !== `/${rootPathId}`) {\n this.handleNode(\n {\n ...node,\n isVirtual: true,\n _fsRouteType: 'static',\n },\n acc,\n prefixMap,\n config,\n )\n }\n return\n }\n\n const isPathlessLayoutWithPath =\n node._fsRouteType === 'pathless_layout' &&\n node.cleanedPath &&\n node.cleanedPath.length > 0\n\n // Special handling: pathless layouts with path need to find real ancestor\n if (!node.isVirtual && isPathlessLayoutWithPath) {\n const immediateParentPath =\n removeLastSegmentFromPath(node.routePath) || '/'\n const immediateParentOriginalPath =\n removeLastSegmentFromPath(node.originalRoutePath) || '/'\n let searchPath = immediateParentPath\n\n // Find nearest real (non-virtual, non-index) parent\n while (searchPath) {\n const candidate = acc.routeNodesByPath.get(searchPath)\n if (candidate && !candidate.isVirtual && candidate.path !== '/') {\n node.parent = candidate\n node.path =\n node.routePath?.replace(candidate.routePath ?? '', '') || '/'\n const pathRelativeToParent =\n immediateParentPath.replace(candidate.routePath ?? '', '') || '/'\n const originalPathRelativeToParent =\n immediateParentOriginalPath.replace(\n candidate.originalRoutePath ?? '',\n '',\n ) || '/'\n const routePathSegmentMetadataRelativeToParent =\n getRoutePathSegmentMetadataForPath(\n node,\n pathRelativeToParent,\n candidate.routePath,\n )\n node.cleanedPath = removeGroups(\n removeLayoutSegmentsAndUnderscoresWithEscape(\n pathRelativeToParent,\n originalPathRelativeToParent,\n routePathSegmentMetadataRelativeToParent,\n ),\n )\n break\n }\n if (searchPath === '/') break\n searchPath = removeLastSegmentFromPath(searchPath) || '/'\n }\n }\n\n // Add to parent's children or to root\n if (node.parent) {\n node.parent.children = node.parent.children ?? []\n node.parent.children.push(node)\n } else {\n acc.routeTree.push(node)\n }\n\n acc.routeNodes.push(node)\n if (node.routePath) {\n // Always register routes by path so child routes can find parents.\n // Virtual routes (created from lazy-only files) also need to be registered\n // so that index routes like path.index.lazy.tsx can find their parent path.lazy.tsx.\n // If a non-virtual route is later processed for the same path, it will overwrite.\n acc.routeNodesByPath.set(node.routePath, node)\n }\n }\n\n // only process files that are relevant for the route tree generation\n private isFileRelevantForRouteTreeGeneration(filePath: string): boolean {\n // the generated route tree file\n if (filePath === this.generatedRouteTreePath) {\n return true\n }\n\n // files inside the routes folder\n if (filePath.startsWith(this.routesDirectoryPath)) {\n return true\n }\n\n // the virtual route config file passed into `virtualRouteConfig`\n if (\n typeof this.config.virtualRouteConfig === 'string' &&\n filePath === this.config.virtualRouteConfig\n ) {\n return true\n }\n\n // this covers all files that are mounted via `virtualRouteConfig` or any `__virtual.ts` files\n if (this.routeNodeCache.has(filePath)) {\n return true\n }\n\n // virtual config files such as`__virtual.ts`\n if (isVirtualConfigFile(path.basename(filePath))) {\n return true\n }\n\n // route files inside directories mounted via `physical()` inside a virtual route config\n if (this.physicalDirectories.some((dir) => filePath.startsWith(dir))) {\n return true\n }\n\n return false\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AA2EA,SAAS,mCACP,MACA,WACA,iBACyD;CACzD,IAAI,CAAC,KAAK,2BAA2B,OAAO,KAAA;CAE5C,MAAM,WAAW,UAAU,MAAM,GAAG;CACpC,MAAM,SAAS,IAAI,MACjB,SAAS,MACX;CACA,MAAM,qBAAqB,uBAAuB,eAAe;CACjE,IAAI,cAAc;CAClB,IAAI,eAAe;CAEnB,KAAK,IAAI,IAAI,GAAG,IAAI,SAAS,QAAQ,KAAK;EACxC,IAAI,CAAC,SAAS,IAAI;EAClB,MAAM,cAAc,qBAAqB,eAAe;EACxD,OAAO,KAAK,KAAK,0BAA0B;EAC3C,gBAAgB,CAAC,CAAC,OAAO;EACzB;CACF;CAEA,OAAO,cAAc,SAAS,KAAA;AAChC;AAEA,IAAM,oBAAwB;CAC5B,MAAM,OAAO,aAAa;EACxB,MAAM,MAAM,MAAM,IAAI,KAAK,UAAU,EAAE,QAAQ,KAAK,CAAC;EACrD,OAAO;GACL,SAAS,IAAI;GACb,MAAM,OAAO,IAAI,IAAI;GACrB,KAAK,OAAO,IAAI,GAAG;GACnB,KAAK,OAAO,IAAI,GAAG;EACrB;CACF;CACA,SAAS,SAAS,YAAY,IAAI,OAAO,SAAS,OAAO;CACzD,YAAY,UAAU,YAAY,IAAI,UAAU,UAAU,OAAO;CACjE,UAAU,OAAO,aAAqB;EACpC,IAAI;GACF,MAAM,aAAa,MAAM,IAAI,KAAK,UAAU,GAAG;GAC/C,MAAM,OAAO,MAAM,WAAW,KAAK,EAAE,QAAQ,KAAK,CAAC;GACnD,MAAM,eAAe,MAAM,WAAW,SAAS,EAAA,CAAG,SAAS;GAC3D,MAAM,WAAW,MAAM;GACvB,OAAO;IAAE;IAAM;GAAY;EAC7B,SAAS,GAA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AAU,SACZ;KACF,KAAK,cAAc,aACjB,6CACE,sBACA,8BACA,wCACF,CACF;KACA;IACF;IACA,IAAI,eAAe,KAAK;IACxB,aAAa,0BAA0B,UAAU,KAAK;GACxD;EACF;EAGA,IAAI,KAAK,QAAQ;GACf,KAAK,OAAO,WAAW,KAAK,OAAO,YAAY,CAAC;GAChD,KAAK,OAAO,SAAS,KAAK,IAAI;EAChC,OACE,IAAI,UAAU,KAAK,IAAI;EAGzB,IAAI,WAAW,KAAK,IAAI;EACxB,IAAI,KAAK,WAKP,IAAI,iBAAiB,IAAI,KAAK,WAAW,IAAI;CAEjD;CAGA,qCAA6C,UAA2B;EAEtE,IAAI,aAAa,KAAK,wBACpB,OAAO;EAIT,IAAI,SAAS,WAAW,KAAK,mBAAmB,GAC9C,OAAO;EAIT,IACE,OAAO,KAAK,OAAO,uBAAuB,YAC1C,aAAa,KAAK,OAAO,oBAEzB,OAAO;EAIT,IAAI,KAAK,eAAe,IAAI,QAAQ,GAClC,OAAO;EAIT,IAAI,oBAAoB,KAAK,SAAS,QAAQ,CAAC,GAC7C,OAAO;EAIT,IAAI,KAAK,oBAAoB,MAAM,QAAQ,SAAS,WAAW,GAAG,CAAC,GACjE,OAAO;EAGT,OAAO;CACT;AACF"}
1
+ {"version":3,"file":"generator.js","names":["virtualGetRouteNodes","physicalGetRouteNodes"],"sources":["../../src/generator.ts"],"sourcesContent":["import path from 'node:path'\nimport * as fsp from 'node:fs/promises'\nimport { existsSync, mkdirSync } from 'node:fs'\nimport crypto from 'node:crypto'\nimport { rootRouteId } from '@tanstack/router-core'\nimport { logging } from './logger'\nimport {\n isVirtualConfigFile,\n getRouteNodes as physicalGetRouteNodes,\n} from './filesystem/physical/getRouteNodes'\nimport { getRouteNodes as virtualGetRouteNodes } from './filesystem/virtual/getRouteNodes'\nimport { rootPathId } from './filesystem/physical/rootPathId'\nimport {\n RoutePrefixMap,\n buildFileRoutesByPathInterface,\n buildImportString,\n buildRouteTreeConfig,\n checkFileExists,\n checkRouteFullPathUniqueness,\n countRoutePathSegments,\n countSlashSeparatedParts,\n createRouteNodesByFullPath,\n createRouteNodesById,\n createRouteNodesByTo,\n createTokenRegex,\n determineNodePath,\n findParent,\n format,\n getImportForRouteNode,\n getResolvedRouteNodeVariableName,\n hasParentRoute,\n isSegmentPathless,\n mergeImportDeclarations,\n multiSortBy,\n removeExt,\n removeGroups,\n removeLastSegmentFromPath,\n removeLayoutSegmentsAndUnderscoresWithEscape,\n removeTrailingSlash,\n replaceBackslash,\n sortRouteNodes,\n trimPathLeft,\n} from './utils'\nimport { fillTemplate, getTargetTemplate } from './template'\nimport { transform } from './transform/transform'\nimport { validateRouteParams } from './validate-route-params'\nimport type { GeneratorPlugin } from './plugin/types'\nimport type { TargetTemplate } from './template'\nimport type {\n FsRouteType,\n GetRouteNodesResult,\n GetRoutesByFileMapResult,\n HandleNodeAccumulator,\n ImportDeclaration,\n RouteNode,\n RoutePathSegmentMetadata,\n} from './types'\nimport type { Config } from './config'\nimport type { Logger } from './logger'\n\ninterface fs {\n stat: (\n filePath: string,\n ) => Promise<{ mtimeMs: bigint; mode: number; uid: number; gid: number }>\n rename: (oldPath: string, newPath: string) => Promise<void>\n writeFile: (filePath: string, content: string) => Promise<void>\n readFile: (\n filePath: string,\n ) => Promise<\n { stat: { mtimeMs: bigint }; fileContent: string } | 'file-not-existing'\n >\n chmod: (filePath: string, mode: number) => Promise<void>\n chown: (filePath: string, uid: number, gid: number) => Promise<void>\n}\n\nfunction getRoutePathSegmentMetadataForPath(\n node: RouteNode,\n routePath: string,\n parentRoutePath?: string,\n): Array<RoutePathSegmentMetadata | undefined> | undefined {\n if (!node._routePathSegmentMetadata) return undefined\n\n const segments = routePath.split('/')\n const result = new Array<RoutePathSegmentMetadata | undefined>(\n segments.length,\n )\n const parentSegmentCount = countRoutePathSegments(parentRoutePath)\n let hasMetadata = false\n let segmentCount = 0\n\n for (let i = 0; i < segments.length; i++) {\n if (!segments[i]) continue\n const sourceIndex = parentSegmentCount + segmentCount + 1\n result[i] = node._routePathSegmentMetadata[sourceIndex]\n hasMetadata ||= !!result[i]\n segmentCount++\n }\n\n return hasMetadata ? result : undefined\n}\n\nconst DefaultFileSystem: fs = {\n stat: async (filePath) => {\n const res = await fsp.stat(filePath, { bigint: true })\n return {\n mtimeMs: res.mtimeMs,\n mode: Number(res.mode),\n uid: Number(res.uid),\n gid: Number(res.gid),\n }\n },\n rename: (oldPath, newPath) => fsp.rename(oldPath, newPath),\n writeFile: (filePath, content) => fsp.writeFile(filePath, content),\n readFile: async (filePath: string) => {\n try {\n const fileHandle = await fsp.open(filePath, 'r')\n const stat = await fileHandle.stat({ bigint: true })\n const fileContent = (await fileHandle.readFile()).toString()\n await fileHandle.close()\n return { stat, fileContent }\n } catch (e: any) {\n if ('code' in e) {\n if (e.code === 'ENOENT') {\n return 'file-not-existing'\n }\n }\n throw e\n }\n },\n chmod: (filePath, mode) => fsp.chmod(filePath, mode),\n chown: (filePath, uid, gid) => fsp.chown(filePath, uid, gid),\n}\n\ninterface Rerun {\n rerun: true\n msg?: string\n event: GeneratorEvent\n}\nfunction rerun(opts: { msg?: string; event?: GeneratorEvent }): Rerun {\n const { event, ...rest } = opts\n return { rerun: true, event: event ?? { type: 'rerun' }, ...rest }\n}\n\nfunction isRerun(result: unknown): result is Rerun {\n return (\n typeof result === 'object' &&\n result !== null &&\n 'rerun' in result &&\n result.rerun === true\n )\n}\n\nexport type FileEventType = 'create' | 'update' | 'delete'\nexport type FileEvent = {\n type: FileEventType\n path: string\n}\nexport type GeneratorEvent = FileEvent | { type: 'rerun' }\n\ntype FileCacheChange<TCacheEntry extends GeneratorCacheEntry> =\n | {\n result: false\n cacheEntry: TCacheEntry\n }\n | { result: true; mtimeMs: bigint; cacheEntry: TCacheEntry }\n | {\n result: 'file-not-in-cache'\n }\n | {\n result: 'cannot-stat-file'\n }\n\ninterface GeneratorCacheEntry {\n mtimeMs: bigint\n fileContent: string\n}\n\ninterface RouteNodeCacheEntry extends GeneratorCacheEntry {\n routeId: string\n node: RouteNode\n}\n\ntype GeneratorRouteNodeCache = Map</** filePath **/ string, RouteNodeCacheEntry>\n\ninterface CrawlingResult {\n rootRouteNode: RouteNode\n routeFileResult: Array<RouteNode>\n acc: HandleNodeAccumulator\n}\n\nexport class Generator {\n /**\n * why do we have two caches for the route files?\n * During processing, we READ from the cache and WRITE to the shadow cache.\n *\n * After a route file is processed, we write to the shadow cache.\n * If during processing we bail out and re-run, we don't lose this modification\n * but still can track whether the file contributed changes and thus the route tree file needs to be regenerated.\n * After all files are processed, we swap the shadow cache with the main cache and initialize a new shadow cache.\n * That way we also ensure deleted/renamed files don't stay in the cache forever.\n */\n private routeNodeCache: GeneratorRouteNodeCache = new Map()\n private routeNodeShadowCache: GeneratorRouteNodeCache = new Map()\n\n private routeTreeFileCache: GeneratorCacheEntry | undefined\n\n private crawlingResult: CrawlingResult | undefined\n public config: Config\n public targetTemplate: TargetTemplate\n\n private root: string\n private routesDirectoryPath: string\n private sessionId?: string\n private fs: fs\n private logger: Logger\n private generatedRouteTreePath: string\n private runPromise: Promise<void> | undefined\n private fileEventQueue: Array<GeneratorEvent> = []\n private plugins: Array<GeneratorPlugin> = []\n private static routeGroupPatternRegex = /\\(.+\\)/\n private physicalDirectories: Array<string> = []\n\n /**\n * Token regexes are pre-compiled once here and reused throughout route processing.\n * We need TWO types of regex for each token because they match against different inputs:\n *\n * 1. FILENAME regexes: Match token patterns within full file path strings.\n * Example: For file \"routes/dashboard.index.tsx\", we want to detect \".index.\"\n * Pattern: `[./](?:token)[.]` - matches token bounded by path separators/dots\n * Used in: sorting route nodes by file path\n *\n * 2. SEGMENT regexes: Match token against a single logical route segment.\n * Example: For segment \"index\" (extracted from path), match the whole segment\n * Pattern: `^(?:token)$` - matches entire segment exactly\n * Used in: route parsing, determining route types, escape detection\n *\n * We cannot reuse one for the other without false positives or missing matches.\n */\n private indexTokenFilenameRegex: RegExp\n private routeTokenFilenameRegex: RegExp\n private indexTokenSegmentRegex: RegExp\n private routeTokenSegmentRegex: RegExp\n private static componentPieceRegex =\n /[./](component|errorComponent|notFoundComponent|pendingComponent|loader|lazy)[.]/\n\n constructor(opts: { config: Config; root: string; fs?: fs }) {\n this.config = opts.config\n this.logger = logging({ disabled: this.config.disableLogging })\n this.root = opts.root\n this.fs = opts.fs || DefaultFileSystem\n this.generatedRouteTreePath = this.getGeneratedRouteTreePath()\n this.targetTemplate = getTargetTemplate(this.config)\n\n this.routesDirectoryPath = this.getRoutesDirectoryPath()\n this.plugins.push(...(opts.config.plugins || []))\n\n // Create all token regexes once in constructor\n this.indexTokenFilenameRegex = createTokenRegex(this.config.indexToken, {\n type: 'filename',\n })\n this.routeTokenFilenameRegex = createTokenRegex(this.config.routeToken, {\n type: 'filename',\n })\n this.indexTokenSegmentRegex = createTokenRegex(this.config.indexToken, {\n type: 'segment',\n })\n this.routeTokenSegmentRegex = createTokenRegex(this.config.routeToken, {\n type: 'segment',\n })\n\n for (const plugin of this.plugins) {\n plugin.init?.({ generator: this })\n }\n }\n\n private getGeneratedRouteTreePath() {\n const generatedRouteTreePath = path.isAbsolute(\n this.config.generatedRouteTree,\n )\n ? this.config.generatedRouteTree\n : path.resolve(this.root, this.config.generatedRouteTree)\n\n const generatedRouteTreeDir = path.dirname(generatedRouteTreePath)\n\n if (!existsSync(generatedRouteTreeDir)) {\n mkdirSync(generatedRouteTreeDir, { recursive: true })\n }\n\n return generatedRouteTreePath\n }\n\n private getRoutesDirectoryPath() {\n return path.isAbsolute(this.config.routesDirectory)\n ? this.config.routesDirectory\n : path.resolve(this.root, this.config.routesDirectory)\n }\n\n public getRoutesByFileMap(): GetRoutesByFileMapResult {\n return new Map(\n [...this.routeNodeCache.entries()].map(([filePath, cacheEntry]) => [\n filePath,\n { routeId: cacheEntry.routeId },\n ]),\n )\n }\n\n public async run(event?: GeneratorEvent): Promise<void> {\n if (\n event &&\n event.type !== 'rerun' &&\n !this.isFileRelevantForRouteTreeGeneration(event.path)\n ) {\n return\n }\n this.fileEventQueue.push(event ?? { type: 'rerun' })\n // only allow a single run at a time\n if (this.runPromise) {\n return this.runPromise\n }\n\n this.runPromise = (async () => {\n do {\n // synchronously copy and clear the queue since we are going to iterate asynchronously over it\n // and while we do so, a new event could be put into the queue\n const tempQueue = this.fileEventQueue\n this.fileEventQueue = []\n // if we only have 'update' events in the queue\n // and we already have the affected files' latest state in our cache, we can exit early\n const remainingEvents = (\n await Promise.all(\n tempQueue.map(async (e) => {\n if (e.type === 'update') {\n let cacheEntry: GeneratorCacheEntry | undefined\n if (e.path === this.generatedRouteTreePath) {\n cacheEntry = this.routeTreeFileCache\n } else {\n // we only check the routeNodeCache here\n // if the file's state is only up-to-date in the shadow cache we need to re-run\n cacheEntry = this.routeNodeCache.get(e.path)\n }\n const change = await this.didFileChangeComparedToCache(\n { path: e.path },\n cacheEntry,\n )\n if (change.result === false) {\n return null\n }\n }\n return e\n }),\n )\n ).filter((e) => e !== null)\n\n if (remainingEvents.length === 0) {\n break\n }\n\n try {\n await this.generatorInternal()\n } catch (err) {\n const errArray = !Array.isArray(err) ? [err] : err\n\n const recoverableErrors = errArray.filter((e) => isRerun(e))\n if (recoverableErrors.length === errArray.length) {\n this.fileEventQueue.push(...recoverableErrors.map((e) => e.event))\n recoverableErrors.forEach((e) => {\n if (e.msg) {\n this.logger.info(e.msg)\n }\n })\n } else {\n const unrecoverableErrors = errArray.filter((e) => !isRerun(e))\n this.runPromise = undefined\n throw new Error(\n unrecoverableErrors.map((e) => (e as Error).message).join(),\n )\n }\n }\n } while (this.fileEventQueue.length)\n this.runPromise = undefined\n })()\n return this.runPromise\n }\n\n private async generatorInternal() {\n let writeRouteTreeFile: boolean | 'force' = false\n\n let getRouteNodesResult: GetRouteNodesResult\n\n if (this.config.virtualRouteConfig) {\n getRouteNodesResult = await virtualGetRouteNodes(this.config, this.root, {\n indexTokenSegmentRegex: this.indexTokenSegmentRegex,\n routeTokenSegmentRegex: this.routeTokenSegmentRegex,\n })\n } else {\n getRouteNodesResult = await physicalGetRouteNodes(\n this.config,\n this.root,\n {\n indexTokenSegmentRegex: this.indexTokenSegmentRegex,\n routeTokenSegmentRegex: this.routeTokenSegmentRegex,\n },\n )\n }\n\n const {\n rootRouteNode,\n routeNodes: beforeRouteNodes,\n physicalDirectories,\n } = getRouteNodesResult\n if (rootRouteNode === undefined) {\n let errorMessage = `rootRouteNode must not be undefined. Make sure you've added your root route into the route-tree.`\n if (!this.config.virtualRouteConfig) {\n errorMessage += `\\nMake sure that you add a \"${rootPathId}.${this.config.disableTypes ? 'js' : 'tsx'}\" file to your routes directory.\\nAdd the file in: \"${this.config.routesDirectory}/${rootPathId}.${this.config.disableTypes ? 'js' : 'tsx'}\"`\n }\n throw new Error(errorMessage)\n }\n this.physicalDirectories = physicalDirectories\n\n await this.handleRootNode(rootRouteNode)\n\n const preRouteNodes = multiSortBy(beforeRouteNodes, [\n (d) => (d.routePath === '/' ? -1 : 1),\n (d) =>\n d.routePath === undefined\n ? undefined\n : countSlashSeparatedParts(d.routePath),\n (d) => (d.filePath.match(this.indexTokenFilenameRegex) ? 1 : -1),\n (d) => (d.filePath.match(Generator.componentPieceRegex) ? 1 : -1),\n (d) => (d.filePath.match(this.routeTokenFilenameRegex) ? -1 : 1),\n (d) => (d.routePath?.endsWith('/') ? -1 : 1),\n (d) => d.routePath,\n ]).filter((d) => {\n // Exclude the root route itself, but keep component/loader pieces for the root\n if (d.routePath === `/${rootPathId}`) {\n return [\n 'component',\n 'errorComponent',\n 'notFoundComponent',\n 'pendingComponent',\n 'loader',\n 'lazy',\n ].includes(d._fsRouteType)\n }\n return true\n })\n\n const routeFileAllResult = await Promise.allSettled(\n preRouteNodes\n // only process routes that are backed by an actual file\n .filter((n) => !n.isVirtualParentRoute && !n.isVirtual)\n .map((n) => this.processRouteNodeFile(n)),\n )\n\n const rejections = routeFileAllResult.filter(\n (result) => result.status === 'rejected',\n )\n if (rejections.length > 0) {\n throw rejections.map((e) => e.reason)\n }\n\n const routeFileResult = routeFileAllResult.flatMap((result) => {\n if (result.status === 'fulfilled' && result.value !== null) {\n if (result.value.shouldWriteTree) {\n writeRouteTreeFile = true\n }\n return result.value.node\n }\n return []\n })\n\n // reset children in case we re-use a node from the cache\n routeFileResult.forEach((r) => (r.children = undefined))\n\n const acc: HandleNodeAccumulator = {\n routeTree: [],\n routeNodes: [],\n routePiecesByPath: {},\n routeNodesByPath: new Map(),\n }\n\n const prefixMap = new RoutePrefixMap(routeFileResult)\n\n for (const node of routeFileResult) {\n Generator.handleNode(node, acc, prefixMap, this.config)\n }\n\n this.crawlingResult = { rootRouteNode, routeFileResult, acc }\n\n // this is the first time the generator runs, so read in the route tree file if it exists yet\n if (!this.routeTreeFileCache) {\n const routeTreeFile = await this.fs.readFile(this.generatedRouteTreePath)\n if (routeTreeFile !== 'file-not-existing') {\n this.routeTreeFileCache = {\n fileContent: routeTreeFile.fileContent,\n mtimeMs: routeTreeFile.stat.mtimeMs,\n }\n }\n writeRouteTreeFile = true\n } else {\n const routeTreeFileChange = await this.didFileChangeComparedToCache(\n { path: this.generatedRouteTreePath },\n this.routeTreeFileCache,\n )\n if (routeTreeFileChange.result !== false) {\n writeRouteTreeFile = 'force'\n if (routeTreeFileChange.result === true) {\n const routeTreeFile = await this.fs.readFile(\n this.generatedRouteTreePath,\n )\n if (routeTreeFile !== 'file-not-existing') {\n this.routeTreeFileCache = {\n fileContent: routeTreeFile.fileContent,\n mtimeMs: routeTreeFile.stat.mtimeMs,\n }\n }\n }\n }\n }\n\n if (!writeRouteTreeFile) {\n // only needs to be done if no other changes have been detected yet\n // compare shadowCache and cache to identify deleted routes\n if (this.routeNodeCache.size !== this.routeNodeShadowCache.size) {\n writeRouteTreeFile = true\n } else {\n for (const fullPath of this.routeNodeCache.keys()) {\n if (!this.routeNodeShadowCache.has(fullPath)) {\n writeRouteTreeFile = true\n break\n }\n }\n }\n }\n\n if (!writeRouteTreeFile) {\n this.swapCaches()\n return\n }\n\n const buildResult = this.buildRouteTree({\n rootRouteNode,\n acc,\n routeFileResult,\n })\n let routeTreeContent = buildResult.routeTreeContent\n\n routeTreeContent = this.config.enableRouteTreeFormatting\n ? await format(routeTreeContent, this.config)\n : routeTreeContent\n\n let newMtimeMs: bigint | undefined\n if (this.routeTreeFileCache) {\n if (this.routeTreeFileCache.fileContent === routeTreeContent) {\n // existing route tree file is already up-to-date, don't write it.\n // When 'force' was set because an external change was detected,\n // we still re-read and re-check here, but if the generated content\n // matches we skip the write to avoid triggering another watcher cycle.\n } else {\n const newRouteTreeFileStat = await this.safeFileWrite({\n filePath: this.generatedRouteTreePath,\n newContent: routeTreeContent,\n strategy: {\n type: 'mtime',\n expectedMtimeMs: this.routeTreeFileCache.mtimeMs,\n },\n })\n newMtimeMs = newRouteTreeFileStat.mtimeMs\n }\n } else {\n const newRouteTreeFileStat = await this.safeFileWrite({\n filePath: this.generatedRouteTreePath,\n newContent: routeTreeContent,\n strategy: {\n type: 'new-file',\n },\n })\n newMtimeMs = newRouteTreeFileStat.mtimeMs\n }\n\n if (newMtimeMs !== undefined) {\n this.routeTreeFileCache = {\n fileContent: routeTreeContent,\n mtimeMs: newMtimeMs,\n }\n }\n\n this.plugins.map((plugin) => {\n return plugin.onRouteTreeChanged?.({\n routeTree: buildResult.routeTree,\n routeNodes: buildResult.routeNodes,\n acc,\n rootRouteNode,\n })\n })\n this.swapCaches()\n }\n\n private swapCaches() {\n this.routeNodeCache = this.routeNodeShadowCache\n this.routeNodeShadowCache = new Map()\n }\n\n public buildRouteTree(opts: {\n rootRouteNode: RouteNode\n acc: HandleNodeAccumulator\n routeFileResult: Array<RouteNode>\n config?: Partial<Config>\n }) {\n const config = { ...this.config, ...(opts.config || {}) }\n\n const { rootRouteNode, acc } = opts\n\n // Use pre-compiled regex if config hasn't been overridden, otherwise create new one\n const indexTokenSegmentRegex =\n config.indexToken === this.config.indexToken\n ? this.indexTokenSegmentRegex\n : createTokenRegex(config.indexToken, { type: 'segment' })\n\n const sortedRouteNodes = sortRouteNodes(\n acc.routeNodes,\n indexTokenSegmentRegex,\n )\n\n const routeImports: Array<ImportDeclaration> = []\n const virtualRouteNodes: Array<string> = []\n\n for (const node of sortedRouteNodes) {\n if (node.isVirtual) {\n virtualRouteNodes.push(\n `const ${node.variableName}RouteImport = createFileRoute('${node.routePath}')()`,\n )\n } else {\n routeImports.push(\n getImportForRouteNode(\n node,\n config,\n this.generatedRouteTreePath,\n this.root,\n ),\n )\n }\n }\n\n const imports: Array<ImportDeclaration> = []\n if (virtualRouteNodes.length > 0) {\n imports.push({\n specifiers: [{ imported: 'createFileRoute' }],\n source: this.targetTemplate.fullPkg,\n })\n }\n // Add lazyRouteComponent import if there are component pieces\n let hasComponentPieces = false\n let hasLoaderPieces = false\n for (const node of sortedRouteNodes) {\n const pieces = acc.routePiecesByPath[node.routePath!]\n if (pieces) {\n if (\n pieces.component ||\n pieces.errorComponent ||\n pieces.notFoundComponent ||\n pieces.pendingComponent\n ) {\n hasComponentPieces = true\n }\n if (pieces.loader) {\n hasLoaderPieces = true\n }\n if (hasComponentPieces && hasLoaderPieces) break\n }\n }\n if (hasComponentPieces || hasLoaderPieces) {\n const runtimeImport: ImportDeclaration = {\n specifiers: [],\n source: this.targetTemplate.fullPkg,\n }\n if (hasComponentPieces) {\n runtimeImport.specifiers.push({ imported: 'lazyRouteComponent' })\n }\n if (hasLoaderPieces) {\n runtimeImport.specifiers.push({ imported: 'lazyFn' })\n }\n imports.push(runtimeImport)\n }\n const routeTreeConfig = buildRouteTreeConfig(\n acc.routeTree,\n config.disableTypes,\n )\n\n const createUpdateRoutes = sortedRouteNodes.map((node) => {\n const pieces = acc.routePiecesByPath[node.routePath!]\n const loaderNode = pieces?.loader\n const componentNode = pieces?.component\n const errorComponentNode = pieces?.errorComponent\n const notFoundComponentNode = pieces?.notFoundComponent\n const pendingComponentNode = pieces?.pendingComponent\n const lazyComponentNode = pieces?.lazy\n\n return [\n [\n `const ${node.variableName}Route = ${node.variableName}RouteImport.update({\n ${[\n `id: '${node.path}'`,\n !node.isNonPath ||\n (node._fsRouteType === 'pathless_layout' && node.cleanedPath)\n ? `path: '${node.cleanedPath}'`\n : undefined,\n `getParentRoute: () => ${findParent(node)}`,\n ]\n .filter(Boolean)\n .join(',')}\n }${config.disableTypes ? '' : 'as any'})`,\n loaderNode\n ? `.updateLoader({ loader: lazyFn(() => import('./${replaceBackslash(\n removeExt(\n path.relative(\n path.dirname(config.generatedRouteTree),\n path.resolve(config.routesDirectory, loaderNode.filePath),\n ),\n config.addExtensions,\n ),\n )}'), 'loader') })`\n : '',\n componentNode ||\n errorComponentNode ||\n notFoundComponentNode ||\n pendingComponentNode\n ? `.update({\n ${(\n [\n ['component', componentNode],\n ['errorComponent', errorComponentNode],\n ['notFoundComponent', notFoundComponentNode],\n ['pendingComponent', pendingComponentNode],\n ] as const\n )\n .filter((d) => d[1])\n .map((d) => {\n // For .vue files, use 'default' as the export name since Vue SFCs export default\n const isVueFile = d[1]!.filePath.endsWith('.vue')\n const exportName = isVueFile ? 'default' : d[0]\n // Keep .vue extension for Vue files since Vite requires it\n const importPath = replaceBackslash(\n isVueFile\n ? path.relative(\n path.dirname(config.generatedRouteTree),\n path.resolve(\n config.routesDirectory,\n d[1]!.filePath,\n ),\n )\n : removeExt(\n path.relative(\n path.dirname(config.generatedRouteTree),\n path.resolve(\n config.routesDirectory,\n d[1]!.filePath,\n ),\n ),\n config.addExtensions,\n ),\n )\n return `${\n d[0]\n }: lazyRouteComponent(() => import('./${importPath}'), '${exportName}')`\n })\n .join('\\n,')}\n })`\n : '',\n lazyComponentNode\n ? (() => {\n // For .vue files, use 'default' export since Vue SFCs export default\n const isVueFile = lazyComponentNode.filePath.endsWith('.vue')\n const exportAccessor = isVueFile ? 'd.default' : 'd.Route'\n // Keep .vue extension for Vue files since Vite requires it\n const importPath = replaceBackslash(\n isVueFile\n ? path.relative(\n path.dirname(config.generatedRouteTree),\n path.resolve(\n config.routesDirectory,\n lazyComponentNode.filePath,\n ),\n )\n : removeExt(\n path.relative(\n path.dirname(config.generatedRouteTree),\n path.resolve(\n config.routesDirectory,\n lazyComponentNode.filePath,\n ),\n ),\n config.addExtensions,\n ),\n )\n return `.lazy(() => import('./${importPath}').then((d) => ${exportAccessor}))`\n })()\n : '',\n ].join(''),\n ].join('\\n\\n')\n })\n\n // Generate update for root route if it has component pieces\n const rootRoutePath = `/${rootPathId}`\n const rootPieces = acc.routePiecesByPath[rootRoutePath]\n const rootComponentNode = rootPieces?.component\n const rootErrorComponentNode = rootPieces?.errorComponent\n const rootNotFoundComponentNode = rootPieces?.notFoundComponent\n const rootPendingComponentNode = rootPieces?.pendingComponent\n\n let rootRouteUpdate = ''\n if (\n rootComponentNode ||\n rootErrorComponentNode ||\n rootNotFoundComponentNode ||\n rootPendingComponentNode\n ) {\n rootRouteUpdate = `const rootRouteWithChildren = rootRouteImport${\n rootComponentNode ||\n rootErrorComponentNode ||\n rootNotFoundComponentNode ||\n rootPendingComponentNode\n ? `.update({\n ${(\n [\n ['component', rootComponentNode],\n ['errorComponent', rootErrorComponentNode],\n ['notFoundComponent', rootNotFoundComponentNode],\n ['pendingComponent', rootPendingComponentNode],\n ] as const\n )\n .filter((d) => d[1])\n .map((d) => {\n // For .vue files, use 'default' as the export name since Vue SFCs export default\n const isVueFile = d[1]!.filePath.endsWith('.vue')\n const exportName = isVueFile ? 'default' : d[0]\n // Keep .vue extension for Vue files since Vite requires it\n const importPath = replaceBackslash(\n isVueFile\n ? path.relative(\n path.dirname(config.generatedRouteTree),\n path.resolve(config.routesDirectory, d[1]!.filePath),\n )\n : removeExt(\n path.relative(\n path.dirname(config.generatedRouteTree),\n path.resolve(\n config.routesDirectory,\n d[1]!.filePath,\n ),\n ),\n config.addExtensions,\n ),\n )\n return `${d[0]}: lazyRouteComponent(() => import('./${importPath}'), '${exportName}')`\n })\n .join('\\n,')}\n })`\n : ''\n }._addFileChildren(rootRouteChildren)${config.disableTypes ? '' : `._addFileTypes<FileRouteTypes>()`}`\n }\n\n let fileRoutesByPathInterface = ''\n let fileRoutesByFullPath = ''\n\n if (!config.disableTypes) {\n const routeNodesByFullPath = createRouteNodesByFullPath(acc.routeNodes)\n const routeNodesByTo = createRouteNodesByTo(acc.routeNodes)\n const routeNodesById = createRouteNodesById(acc.routeNodes)\n\n fileRoutesByFullPath = [\n `export interface FileRoutesByFullPath {\n${[...routeNodesByFullPath.entries()]\n .filter(([fullPath]) => fullPath)\n .map(([fullPath, routeNode]) => {\n return `'${fullPath}': typeof ${getResolvedRouteNodeVariableName(routeNode)}`\n })}\n}`,\n `export interface FileRoutesByTo {\n${[...routeNodesByTo.entries()]\n .filter(([to]) => to)\n .map(([to, routeNode]) => {\n return `'${to}': typeof ${getResolvedRouteNodeVariableName(routeNode)}`\n })}\n}`,\n `export interface FileRoutesById {\n'${rootRouteId}': typeof rootRouteImport,\n${[...routeNodesById.entries()].map(([id, routeNode]) => {\n return `'${id}': typeof ${getResolvedRouteNodeVariableName(routeNode)}`\n})}\n}`,\n `export interface FileRouteTypes {\nfileRoutesByFullPath: FileRoutesByFullPath\nfullPaths: ${\n acc.routeNodes.length > 0\n ? [...routeNodesByFullPath.keys()]\n .filter((fullPath) => fullPath)\n .map((fullPath) => `'${fullPath}'`)\n .join('|')\n : 'never'\n }\nfileRoutesByTo: FileRoutesByTo\nto: ${\n acc.routeNodes.length > 0\n ? [...routeNodesByTo.keys()]\n .filter((to) => to)\n .map((to) => `'${to}'`)\n .join('|')\n : 'never'\n }\nid: ${[`'${rootRouteId}'`, ...[...routeNodesById.keys()].map((id) => `'${id}'`)].join('|')}\nfileRoutesById: FileRoutesById\n}`,\n `export interface RootRouteChildren {\n${acc.routeTree.map((child) => `${child.variableName}Route: typeof ${getResolvedRouteNodeVariableName(child)}`).join(',')}\n}`,\n ].join('\\n')\n\n fileRoutesByPathInterface = buildFileRoutesByPathInterface({\n module: this.targetTemplate.fullPkg,\n interfaceName: 'FileRoutesByPath',\n routeNodes: sortedRouteNodes,\n config,\n })\n }\n\n const routeTree = [\n `const rootRouteChildren${config.disableTypes ? '' : `: RootRouteChildren`} = {\n ${acc.routeTree\n .map(\n (child) =>\n `${child.variableName}Route: ${getResolvedRouteNodeVariableName(child)}`,\n )\n .join(',')}\n}`,\n rootRouteUpdate\n ? rootRouteUpdate.replace(\n 'const rootRouteWithChildren = ',\n 'export const routeTree = ',\n )\n : `export const routeTree = rootRouteImport._addFileChildren(rootRouteChildren)${config.disableTypes ? '' : `._addFileTypes<FileRouteTypes>()`}`,\n ].join('\\n')\n\n checkRouteFullPathUniqueness(\n sortedRouteNodes.filter(\n (d) => d.children === undefined && 'lazy' !== d._fsRouteType,\n ),\n config,\n )\n\n let mergedImports = mergeImportDeclarations(imports)\n if (config.disableTypes) {\n mergedImports = mergedImports.filter((d) => d.importKind !== 'type')\n }\n\n const importStatements = mergedImports.map(buildImportString)\n\n const rootRouteImport = getImportForRouteNode(\n rootRouteNode,\n config,\n this.generatedRouteTreePath,\n this.root,\n )\n routeImports.unshift(rootRouteImport)\n\n let footer: Array<string> = []\n if (config.routeTreeFileFooter) {\n if (Array.isArray(config.routeTreeFileFooter)) {\n footer = config.routeTreeFileFooter\n } else {\n footer = config.routeTreeFileFooter()\n }\n }\n const routeTreeContent = [\n ...config.routeTreeFileHeader,\n `// This file was automatically generated by TanStack Router.\n// You should NOT make any changes in this file as it will be overwritten.\n// Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified.`,\n [...importStatements].join('\\n'),\n mergeImportDeclarations(routeImports).map(buildImportString).join('\\n'),\n virtualRouteNodes.join('\\n'),\n createUpdateRoutes.join('\\n'),\n fileRoutesByFullPath,\n fileRoutesByPathInterface,\n routeTreeConfig.join('\\n'),\n routeTree,\n ...footer,\n ]\n .filter(Boolean)\n .join('\\n\\n')\n return {\n routeTreeContent,\n routeTree: acc.routeTree,\n routeNodes: acc.routeNodes,\n }\n }\n\n private async processRouteNodeFile(node: RouteNode): Promise<{\n shouldWriteTree: boolean\n cacheEntry: RouteNodeCacheEntry\n node: RouteNode\n } | null> {\n const result = await this.isRouteFileCacheFresh(node)\n\n if (result.status === 'fresh') {\n return {\n node: result.cacheEntry.node,\n shouldWriteTree: false,\n cacheEntry: result.cacheEntry,\n }\n }\n\n const previousCacheEntry = result.cacheEntry\n\n const existingRouteFile = await this.fs.readFile(node.fullPath)\n if (existingRouteFile === 'file-not-existing') {\n throw new Error(`⚠️ File ${node.fullPath} does not exist`)\n }\n\n if (node.routePath) {\n validateRouteParams(node.routePath, node.filePath, this.logger)\n }\n\n const updatedCacheEntry: RouteNodeCacheEntry = {\n fileContent: existingRouteFile.fileContent,\n mtimeMs: existingRouteFile.stat.mtimeMs,\n routeId: node.routePath ?? '$$TSR_NO_ROUTE_PATH_ASSIGNED$$',\n node,\n }\n\n const escapedRoutePath = node.routePath?.replaceAll('$', '$$') ?? ''\n\n let shouldWriteRouteFile = false\n let shouldWriteTree = false\n // now we need to either scaffold the file or transform it\n if (!existingRouteFile.fileContent) {\n shouldWriteRouteFile = true\n shouldWriteTree = true\n // Creating a new lazy route file\n if (node._fsRouteType === 'lazy') {\n const tLazyRouteTemplate = this.targetTemplate.lazyRoute\n // Check by default check if the user has a specific lazy route template\n // If not, check if the user has a route template and use that instead\n updatedCacheEntry.fileContent = await fillTemplate(\n this.config,\n (this.config.customScaffolding?.lazyRouteTemplate ||\n this.config.customScaffolding?.routeTemplate) ??\n tLazyRouteTemplate.template(),\n {\n tsrImports: tLazyRouteTemplate.imports.tsrImports(),\n tsrPath: escapedRoutePath.replaceAll(/\\{(.+?)\\}/gm, '$1'),\n tsrExportStart:\n tLazyRouteTemplate.imports.tsrExportStart(escapedRoutePath),\n tsrExportEnd: tLazyRouteTemplate.imports.tsrExportEnd(),\n },\n )\n } else if (\n // Creating a new normal route file\n (['layout', 'static'] satisfies Array<FsRouteType>).some(\n (d) => d === node._fsRouteType,\n ) ||\n (\n [\n 'component',\n 'pendingComponent',\n 'errorComponent',\n 'notFoundComponent',\n 'loader',\n ] satisfies Array<FsRouteType>\n ).every((d) => d !== node._fsRouteType)\n ) {\n const tRouteTemplate = this.targetTemplate.route\n updatedCacheEntry.fileContent = await fillTemplate(\n this.config,\n this.config.customScaffolding?.routeTemplate ??\n tRouteTemplate.template(),\n {\n tsrImports: tRouteTemplate.imports.tsrImports(),\n tsrPath: escapedRoutePath.replaceAll(/\\{(.+?)\\}/gm, '$1'),\n tsrExportStart:\n tRouteTemplate.imports.tsrExportStart(escapedRoutePath),\n tsrExportEnd: tRouteTemplate.imports.tsrExportEnd(),\n },\n )\n } else {\n return null\n }\n }\n\n // Check if this is a Vue component file\n // Vue SFC files (.vue) don't need transformation as they can't have a Route export\n const isVueFile = node.filePath.endsWith('.vue')\n\n if (!isVueFile) {\n // transform the file\n const transformResult = await transform({\n source: updatedCacheEntry.fileContent,\n filename: node.fullPath,\n ctx: {\n target: this.config.target,\n routeId: escapedRoutePath,\n lazy: node._fsRouteType === 'lazy',\n },\n node,\n })\n\n if (transformResult.result === 'no-route-export') {\n const fileName = path.basename(node.fullPath)\n const dirName = path.dirname(node.fullPath)\n const ignorePrefix = this.config.routeFileIgnorePrefix\n const ignorePattern = this.config.routeFileIgnorePattern\n const suggestedFileName = `${ignorePrefix}${fileName}`\n const suggestedFullPath = path.join(dirName, suggestedFileName)\n\n let message = `Warning: Route file \"${node.fullPath}\" does not export a Route. This file will not be included in the route tree.`\n message += `\\n\\nIf this file is not intended to be a route, you can exclude it using one of these options:`\n message += `\\n 1. Rename the file to \"${suggestedFullPath}\" (prefix with \"${ignorePrefix}\")`\n message += `\\n 2. Use 'routeFileIgnorePattern' in your config to match this file`\n message += `\\n\\nCurrent configuration:`\n message += `\\n routeFileIgnorePrefix: \"${ignorePrefix}\"`\n message += `\\n routeFileIgnorePattern: ${ignorePattern ? `\"${ignorePattern}\"` : 'undefined'}`\n\n this.logger.warn(message)\n return null\n }\n if (transformResult.result === 'error') {\n throw new Error(\n `Error transforming route file ${node.fullPath}: ${transformResult.error}`,\n )\n }\n if (transformResult.result === 'modified') {\n updatedCacheEntry.fileContent = transformResult.output\n shouldWriteRouteFile = true\n }\n }\n\n for (const plugin of this.plugins) {\n plugin.afterTransform?.({ node, prevNode: previousCacheEntry?.node })\n }\n\n // file was changed\n if (shouldWriteRouteFile) {\n const stats = await this.safeFileWrite({\n filePath: node.fullPath,\n newContent: updatedCacheEntry.fileContent,\n strategy: {\n type: 'mtime',\n expectedMtimeMs: updatedCacheEntry.mtimeMs,\n expectedContent: existingRouteFile.fileContent,\n },\n })\n updatedCacheEntry.mtimeMs = stats.mtimeMs\n }\n\n this.routeNodeShadowCache.set(node.fullPath, updatedCacheEntry)\n return {\n node,\n shouldWriteTree,\n cacheEntry: updatedCacheEntry,\n }\n }\n\n private async didRouteFileChangeComparedToCache(\n file: {\n path: string\n mtimeMs?: bigint\n },\n cache: 'routeNodeCache' | 'routeNodeShadowCache',\n ): Promise<FileCacheChange<RouteNodeCacheEntry>> {\n const cacheEntry = this[cache].get(file.path)\n return this.didFileChangeComparedToCache(file, cacheEntry)\n }\n\n private async didFileChangeComparedToCache<\n TCacheEntry extends GeneratorCacheEntry,\n >(\n file: {\n path: string\n mtimeMs?: bigint\n },\n cacheEntry: TCacheEntry | undefined,\n ): Promise<FileCacheChange<TCacheEntry>> {\n // for now we rely on the modification time of the file\n // to determine if the file has changed\n // we could also compare the file content but this would be slower as we would have to read the file\n\n if (!cacheEntry) {\n return { result: 'file-not-in-cache' }\n }\n let mtimeMs = file.mtimeMs\n\n if (mtimeMs === undefined) {\n try {\n const currentStat = await this.fs.stat(file.path)\n mtimeMs = currentStat.mtimeMs\n } catch {\n return { result: 'cannot-stat-file' }\n }\n }\n return { result: mtimeMs !== cacheEntry.mtimeMs, mtimeMs, cacheEntry }\n }\n\n private async safeFileWrite(opts: {\n filePath: string\n newContent: string\n strategy:\n | {\n type: 'mtime'\n expectedMtimeMs: bigint\n // An in-place save can truncate and rewrite a file within one mtime\n // tick, so user-authored files also compare the content.\n expectedContent?: string\n }\n | {\n type: 'new-file'\n }\n }) {\n const tmpPath = this.getTempFileName(opts.filePath)\n await this.fs.writeFile(tmpPath, opts.newContent)\n\n if (opts.strategy.type === 'mtime') {\n const { expectedMtimeMs, expectedContent } = opts.strategy\n const beforeStat = await this.fs.stat(opts.filePath)\n const newFileState = await this.fs.stat(tmpPath)\n if (newFileState.mode !== beforeStat.mode) {\n await this.fs.chmod(tmpPath, beforeStat.mode)\n }\n if (\n newFileState.uid !== beforeStat.uid ||\n newFileState.gid !== beforeStat.gid\n ) {\n try {\n await this.fs.chown(tmpPath, beforeStat.uid, beforeStat.gid)\n } catch (err) {\n if (\n typeof err === 'object' &&\n err !== null &&\n 'code' in err &&\n (err as any).code === 'EPERM'\n ) {\n console.warn(\n `[safeFileWrite] chown failed: ${(err as any).message}`,\n )\n } else {\n throw err\n }\n }\n }\n // Check right before the rename so that changes made while the\n // temporary file was prepared are not overwritten.\n let changed: boolean\n if (expectedContent === undefined) {\n const current = await this.fs.stat(opts.filePath)\n changed = current.mtimeMs !== expectedMtimeMs\n } else {\n const current = await this.fs.readFile(opts.filePath)\n changed =\n current === 'file-not-existing' ||\n current.stat.mtimeMs !== expectedMtimeMs ||\n current.fileContent !== expectedContent\n }\n if (changed) {\n throw rerun({\n msg: `File ${opts.filePath} was modified by another process during processing.`,\n event: { type: 'update', path: opts.filePath },\n })\n }\n } else {\n if (await checkFileExists(opts.filePath)) {\n throw rerun({\n msg: `File ${opts.filePath} already exists. Cannot overwrite.`,\n event: { type: 'update', path: opts.filePath },\n })\n }\n }\n\n await this.fs.rename(tmpPath, opts.filePath)\n\n // stat the target file AFTER rename so the cached mtime matches\n // what the filesystem reports for the actual file path.\n // Previously we stat'd the temp file before rename, but rename()\n // can assign a different mtime to the target on some filesystems,\n // causing the cache to be permanently stale.\n const stat = await this.fs.stat(opts.filePath)\n\n return stat\n }\n\n private getTempFileName(filePath: string) {\n const absPath = path.resolve(filePath)\n const hash = crypto.createHash('md5').update(absPath).digest('hex')\n // lazy initialize sessionId to only create tmpDir when it is first needed\n if (!this.sessionId) {\n // ensure the directory exists\n mkdirSync(this.config.tmpDir, { recursive: true })\n this.sessionId = crypto.randomBytes(4).toString('hex')\n }\n return path.join(this.config.tmpDir, `${this.sessionId}-${hash}`)\n }\n\n private async isRouteFileCacheFresh(node: RouteNode): Promise<\n | {\n status: 'fresh'\n cacheEntry: RouteNodeCacheEntry\n }\n | { status: 'stale'; cacheEntry?: RouteNodeCacheEntry }\n > {\n const fileChangedCache = await this.didRouteFileChangeComparedToCache(\n { path: node.fullPath },\n 'routeNodeCache',\n )\n if (fileChangedCache.result === false) {\n this.routeNodeShadowCache.set(node.fullPath, fileChangedCache.cacheEntry)\n return {\n status: 'fresh',\n cacheEntry: fileChangedCache.cacheEntry,\n }\n }\n if (fileChangedCache.result === 'cannot-stat-file') {\n throw new Error(`⚠️ expected route file to exist at ${node.fullPath}`)\n }\n const mtimeMs =\n fileChangedCache.result === true ? fileChangedCache.mtimeMs : undefined\n\n const shadowCacheFileChange = await this.didRouteFileChangeComparedToCache(\n { path: node.fullPath, mtimeMs },\n 'routeNodeShadowCache',\n )\n\n if (shadowCacheFileChange.result === 'cannot-stat-file') {\n throw new Error(`⚠️ expected route file to exist at ${node.fullPath}`)\n }\n\n if (shadowCacheFileChange.result === false) {\n // shadow cache has latest file state already\n if (fileChangedCache.result === true) {\n return {\n status: 'fresh',\n cacheEntry: shadowCacheFileChange.cacheEntry,\n }\n }\n }\n\n if (fileChangedCache.result === 'file-not-in-cache') {\n return {\n status: 'stale',\n }\n }\n return { status: 'stale', cacheEntry: fileChangedCache.cacheEntry }\n }\n\n private async handleRootNode(node: RouteNode) {\n const result = await this.isRouteFileCacheFresh(node)\n\n if (result.status === 'fresh') {\n this.routeNodeShadowCache.set(node.fullPath, result.cacheEntry)\n }\n const rootNodeFile = await this.fs.readFile(node.fullPath)\n if (rootNodeFile === 'file-not-existing') {\n throw new Error(`⚠️ expected root route to exist at ${node.fullPath}`)\n }\n\n const updatedCacheEntry: RouteNodeCacheEntry = {\n fileContent: rootNodeFile.fileContent,\n mtimeMs: rootNodeFile.stat.mtimeMs,\n routeId: node.routePath ?? '$$TSR_NO_ROOT_ROUTE_PATH_ASSIGNED$$',\n node,\n }\n\n // scaffold the root route\n if (!rootNodeFile.fileContent) {\n const rootTemplate = this.targetTemplate.rootRoute\n const rootRouteContent = await fillTemplate(\n this.config,\n rootTemplate.template(),\n {\n tsrImports: rootTemplate.imports.tsrImports(),\n tsrPath: rootPathId,\n tsrExportStart: rootTemplate.imports.tsrExportStart(),\n tsrExportEnd: rootTemplate.imports.tsrExportEnd(),\n },\n )\n\n this.logger.log(`🟡 Creating ${node.fullPath}`)\n const stats = await this.safeFileWrite({\n filePath: node.fullPath,\n newContent: rootRouteContent,\n strategy: {\n type: 'mtime',\n expectedMtimeMs: rootNodeFile.stat.mtimeMs,\n expectedContent: rootNodeFile.fileContent,\n },\n })\n updatedCacheEntry.fileContent = rootRouteContent\n updatedCacheEntry.mtimeMs = stats.mtimeMs\n }\n\n this.routeNodeShadowCache.set(node.fullPath, updatedCacheEntry)\n }\n\n public async getCrawlingResult(): Promise<CrawlingResult | undefined> {\n await this.runPromise\n return this.crawlingResult\n }\n\n private static handleNode(\n node: RouteNode,\n acc: HandleNodeAccumulator,\n prefixMap: RoutePrefixMap,\n config?: Config,\n ) {\n let parentRoute = hasParentRoute(prefixMap, node, node.routePath)\n\n // Check routeNodesByPath for a closer parent that may not be in prefixMap.\n //\n // Why: The prefixMap excludes lazy routes by design. When lazy-only routes are\n // nested inside a pathless layout, the virtual route created from the lazy file\n // won't be in the prefixMap, but it will be in routeNodesByPath.\n //\n // Example: Given files _layout/path.lazy.tsx and _layout/path.index.lazy.tsx:\n // - prefixMap contains: /_layout (from route.tsx)\n // - routeNodesByPath contains: /_layout AND /_layout/path (virtual from lazy)\n // - For /_layout/path/, hasParentRoute returns /_layout (wrong)\n // - But the correct parent is /_layout/path (the virtual route from path.lazy.tsx)\n //\n // We walk up the path segments to find the closest registered parent. This handles\n // cases where multiple path segments (e.g., $a/$b) don't have intermediate routes.\n if (node.routePath) {\n let searchPath = node.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 candidate = acc.routeNodesByPath.get(searchPath)\n if (candidate && candidate.routePath !== node.routePath) {\n // Found a parent in routeNodesByPath\n // If it's different from what prefixMap found AND is a closer match, use it\n if (candidate !== parentRoute) {\n // Check if this candidate is a closer parent than what prefixMap found\n // (longer path prefix means closer parent)\n if (\n !parentRoute ||\n (candidate.routePath?.length ?? 0) >\n (parentRoute.routePath?.length ?? 0)\n ) {\n parentRoute = candidate\n }\n }\n break\n }\n }\n }\n\n // Virtual routes may have an explicit parent from virtual config.\n // If we can find that exact parent, use it to prevent auto-nesting siblings\n // based on path prefix matching (#5822, #5431).\n if (node._virtualParentRoutePath !== undefined) {\n const explicitParent = acc.routeNodesByPath.get(\n node._virtualParentRoutePath,\n )\n if (explicitParent) {\n parentRoute = explicitParent\n } else if (node._virtualParentRoutePath === `/${rootPathId}`) {\n // The explicit parent is the root route (handled separately).\n // Override path-based inference so this node stays at root level.\n parentRoute = null\n }\n // Otherwise the explicit parent was a virtual file-less route that got\n // filtered out. Fall back to the path-based parentRoute already computed.\n }\n\n if (parentRoute) node.parent = parentRoute\n\n node.path = determineNodePath(node)\n\n const trimmedPath = trimPathLeft(node.path ?? '')\n const originalPath =\n node.originalRoutePath && node.parent?.originalRoutePath\n ? node.originalRoutePath.replace(node.parent.originalRoutePath, '') ||\n '/'\n : node.originalRoutePath\n const routePathSegmentMetadata = getRoutePathSegmentMetadataForPath(\n node,\n node.path ?? '/',\n node.parent?.routePath,\n )\n const trimmedOriginalPath = trimPathLeft(originalPath ?? '')\n\n const split = trimmedPath.split('/')\n const pathSplit = (node.path ?? '').split('/')\n const originalSplit = trimmedOriginalPath.split('/')\n const lastRouteSegment = split[split.length - 1] ?? trimmedPath\n const lastOriginalSegment =\n originalSplit[originalSplit.length - 1] ?? trimmedOriginalPath\n const lastRouteSegmentMetadata =\n routePathSegmentMetadata?.[pathSplit.length - 1]\n\n // A segment is non-path if it starts with underscore AND the underscore is not escaped\n node.isNonPath =\n (!lastRouteSegmentMetadata?.literalLeadingUnderscore &&\n isSegmentPathless(lastRouteSegment, lastOriginalSegment)) ||\n split.every((part) => this.routeGroupPatternRegex.test(part))\n\n // Use a single pass so layout removal does not desync escaped underscore checks.\n node.cleanedPath = removeGroups(\n removeLayoutSegmentsAndUnderscoresWithEscape(\n node.path,\n originalPath,\n routePathSegmentMetadata,\n ),\n )\n\n if (\n node._fsRouteType === 'layout' ||\n node._fsRouteType === 'pathless_layout'\n ) {\n node.cleanedPath = removeTrailingSlash(node.cleanedPath)\n }\n\n if (\n !node.isVirtual &&\n (\n [\n 'lazy',\n 'loader',\n 'component',\n 'pendingComponent',\n 'errorComponent',\n 'notFoundComponent',\n ] satisfies Array<FsRouteType>\n ).some((d) => d === node._fsRouteType)\n ) {\n acc.routePiecesByPath[node.routePath!] =\n acc.routePiecesByPath[node.routePath!] || {}\n\n const pieceKey =\n node._fsRouteType === 'lazy'\n ? 'lazy'\n : (node._fsRouteType as keyof (typeof acc.routePiecesByPath)[string])\n acc.routePiecesByPath[node.routePath!]![pieceKey] = node\n\n const anchorRoute = acc.routeNodesByPath.get(node.routePath!)\n\n // Don't create virtual routes for root route component pieces - the root route is handled separately\n if (!anchorRoute && node.routePath !== `/${rootPathId}`) {\n this.handleNode(\n {\n ...node,\n isVirtual: true,\n _fsRouteType: 'static',\n },\n acc,\n prefixMap,\n config,\n )\n }\n return\n }\n\n const isPathlessLayoutWithPath =\n node._fsRouteType === 'pathless_layout' &&\n node.cleanedPath &&\n node.cleanedPath.length > 0\n\n // Special handling: pathless layouts with path need to find real ancestor\n if (!node.isVirtual && isPathlessLayoutWithPath) {\n const immediateParentPath =\n removeLastSegmentFromPath(node.routePath) || '/'\n const immediateParentOriginalPath =\n removeLastSegmentFromPath(node.originalRoutePath) || '/'\n let searchPath = immediateParentPath\n\n // Find nearest real (non-virtual, non-index) parent\n while (searchPath) {\n const candidate = acc.routeNodesByPath.get(searchPath)\n if (candidate && !candidate.isVirtual && candidate.path !== '/') {\n node.parent = candidate\n node.path =\n node.routePath?.replace(candidate.routePath ?? '', '') || '/'\n const pathRelativeToParent =\n immediateParentPath.replace(candidate.routePath ?? '', '') || '/'\n const originalPathRelativeToParent =\n immediateParentOriginalPath.replace(\n candidate.originalRoutePath ?? '',\n '',\n ) || '/'\n const routePathSegmentMetadataRelativeToParent =\n getRoutePathSegmentMetadataForPath(\n node,\n pathRelativeToParent,\n candidate.routePath,\n )\n node.cleanedPath = removeGroups(\n removeLayoutSegmentsAndUnderscoresWithEscape(\n pathRelativeToParent,\n originalPathRelativeToParent,\n routePathSegmentMetadataRelativeToParent,\n ),\n )\n break\n }\n if (searchPath === '/') break\n searchPath = removeLastSegmentFromPath(searchPath) || '/'\n }\n }\n\n // Add to parent's children or to root\n if (node.parent) {\n node.parent.children = node.parent.children ?? []\n node.parent.children.push(node)\n } else {\n acc.routeTree.push(node)\n }\n\n acc.routeNodes.push(node)\n if (node.routePath) {\n // Always register routes by path so child routes can find parents.\n // Virtual routes (created from lazy-only files) also need to be registered\n // so that index routes like path.index.lazy.tsx can find their parent path.lazy.tsx.\n // If a non-virtual route is later processed for the same path, it will overwrite.\n acc.routeNodesByPath.set(node.routePath, node)\n }\n }\n\n // only process files that are relevant for the route tree generation\n private isFileRelevantForRouteTreeGeneration(filePath: string): boolean {\n // the generated route tree file\n if (filePath === this.generatedRouteTreePath) {\n return true\n }\n\n // files inside the routes folder\n if (filePath.startsWith(this.routesDirectoryPath)) {\n return true\n }\n\n // the virtual route config file passed into `virtualRouteConfig`\n if (\n typeof this.config.virtualRouteConfig === 'string' &&\n filePath === this.config.virtualRouteConfig\n ) {\n return true\n }\n\n // this covers all files that are mounted via `virtualRouteConfig` or any `__virtual.ts` files\n if (this.routeNodeCache.has(filePath)) {\n return true\n }\n\n // virtual config files such as`__virtual.ts`\n if (isVirtualConfigFile(path.basename(filePath))) {\n return true\n }\n\n // route files inside directories mounted via `physical()` inside a virtual route config\n if (this.physicalDirectories.some((dir) => filePath.startsWith(dir))) {\n return true\n }\n\n return false\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AA2EA,SAAS,mCACP,MACA,WACA,iBACyD;CACzD,IAAI,CAAC,KAAK,2BAA2B,OAAO,KAAA;CAE5C,MAAM,WAAW,UAAU,MAAM,GAAG;CACpC,MAAM,SAAS,IAAI,MACjB,SAAS,MACX;CACA,MAAM,qBAAqB,uBAAuB,eAAe;CACjE,IAAI,cAAc;CAClB,IAAI,eAAe;CAEnB,KAAK,IAAI,IAAI,GAAG,IAAI,SAAS,QAAQ,KAAK;EACxC,IAAI,CAAC,SAAS,IAAI;EAClB,MAAM,cAAc,qBAAqB,eAAe;EACxD,OAAO,KAAK,KAAK,0BAA0B;EAC3C,gBAAgB,CAAC,CAAC,OAAO;EACzB;CACF;CAEA,OAAO,cAAc,SAAS,KAAA;AAChC;AAEA,IAAM,oBAAwB;CAC5B,MAAM,OAAO,aAAa;EACxB,MAAM,MAAM,MAAM,IAAI,KAAK,UAAU,EAAE,QAAQ,KAAK,CAAC;EACrD,OAAO;GACL,SAAS,IAAI;GACb,MAAM,OAAO,IAAI,IAAI;GACrB,KAAK,OAAO,IAAI,GAAG;GACnB,KAAK,OAAO,IAAI,GAAG;EACrB;CACF;CACA,SAAS,SAAS,YAAY,IAAI,OAAO,SAAS,OAAO;CACzD,YAAY,UAAU,YAAY,IAAI,UAAU,UAAU,OAAO;CACjE,UAAU,OAAO,aAAqB;EACpC,IAAI;GACF,MAAM,aAAa,MAAM,IAAI,KAAK,UAAU,GAAG;GAC/C,MAAM,OAAO,MAAM,WAAW,KAAK,EAAE,QAAQ,KAAK,CAAC;GACnD,MAAM,eAAe,MAAM,WAAW,SAAS,EAAA,CAAG,SAAS;GAC3D,MAAM,WAAW,MAAM;GACvB,OAAO;IAAE;IAAM;GAAY;EAC7B,SAAS,GAAQ;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a,CAAC,UAAU,aAAa,UAAU,SAAS,KAAK;KAC/D,KAAK,SAAS;KACd,KAAK,OACH,KAAK,WAAW,QAAQ,UAAU,aAAa,IAAI,EAAE,KAAK;KAC5D,MAAM,uBACJ,oBAAoB,QAAQ,UAAU,aAAa,IAAI,EAAE,KAAK;KAChE,MAAM,+BACJ,4BAA4B,QAC1B,UAAU,qBAAqB,IAC/B,EACF,KAAK;KACP,MAAM,2CACJ,mCACE,MACA,sBACA,UAAU,SACZ;KACF,KAAK,cAAc,aACjB,6CACE,sBACA,8BACA,wCACF,CACF;KACA;IACF;IACA,IAAI,eAAe,KAAK;IACxB,aAAa,0BAA0B,UAAU,KAAK;GACxD;EACF;EAGA,IAAI,KAAK,QAAQ;GACf,KAAK,OAAO,WAAW,KAAK,OAAO,YAAY,CAAC;GAChD,KAAK,OAAO,SAAS,KAAK,IAAI;EAChC,OACE,IAAI,UAAU,KAAK,IAAI;EAGzB,IAAI,WAAW,KAAK,IAAI;EACxB,IAAI,KAAK,WAKP,IAAI,iBAAiB,IAAI,KAAK,WAAW,IAAI;CAEjD;CAGA,qCAA6C,UAA2B;EAEtE,IAAI,aAAa,KAAK,wBACpB,OAAO;EAIT,IAAI,SAAS,WAAW,KAAK,mBAAmB,GAC9C,OAAO;EAIT,IACE,OAAO,KAAK,OAAO,uBAAuB,YAC1C,aAAa,KAAK,OAAO,oBAEzB,OAAO;EAIT,IAAI,KAAK,eAAe,IAAI,QAAQ,GAClC,OAAO;EAIT,IAAI,oBAAoB,KAAK,SAAS,QAAQ,CAAC,GAC7C,OAAO;EAIT,IAAI,KAAK,oBAAoB,MAAM,QAAQ,SAAS,WAAW,GAAG,CAAC,GACjE,OAAO;EAGT,OAAO;CACT;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/router-generator",
3
- "version": "1.167.41",
3
+ "version": "1.167.42",
4
4
  "description": "Modern and scalable routing for React applications",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -54,7 +54,7 @@
54
54
  "magic-string": "^0.30.21",
55
55
  "prettier": "^3.9.6",
56
56
  "zod": "^4.5.4",
57
- "@tanstack/router-core": "1.171.35",
57
+ "@tanstack/router-core": "1.171.36",
58
58
  "@tanstack/router-utils": "1.162.3",
59
59
  "@tanstack/virtual-file-routes": "1.162.0"
60
60
  },
@@ -68,7 +68,7 @@
68
68
  "@arethetypeswrong/cli": "^0.18.4",
69
69
  "publint": "^0.3.16",
70
70
  "rimraf": "^6.1.2",
71
- "@tanstack/react-router": "1.170.42"
71
+ "@tanstack/react-router": "1.170.43"
72
72
  },
73
73
  "nx": {
74
74
  "targets": {
package/src/generator.ts CHANGED
@@ -1146,6 +1146,7 @@ ${acc.routeTree.map((child) => `${child.variableName}Route: typeof ${getResolved
1146
1146
  strategy: {
1147
1147
  type: 'mtime',
1148
1148
  expectedMtimeMs: updatedCacheEntry.mtimeMs,
1149
+ expectedContent: existingRouteFile.fileContent,
1149
1150
  },
1150
1151
  })
1151
1152
  updatedCacheEntry.mtimeMs = stats.mtimeMs
@@ -1206,6 +1207,9 @@ ${acc.routeTree.map((child) => `${child.variableName}Route: typeof ${getResolved
1206
1207
  | {
1207
1208
  type: 'mtime'
1208
1209
  expectedMtimeMs: bigint
1210
+ // An in-place save can truncate and rewrite a file within one mtime
1211
+ // tick, so user-authored files also compare the content.
1212
+ expectedContent?: string
1209
1213
  }
1210
1214
  | {
1211
1215
  type: 'new-file'
@@ -1215,13 +1219,8 @@ ${acc.routeTree.map((child) => `${child.variableName}Route: typeof ${getResolved
1215
1219
  await this.fs.writeFile(tmpPath, opts.newContent)
1216
1220
 
1217
1221
  if (opts.strategy.type === 'mtime') {
1222
+ const { expectedMtimeMs, expectedContent } = opts.strategy
1218
1223
  const beforeStat = await this.fs.stat(opts.filePath)
1219
- if (beforeStat.mtimeMs !== opts.strategy.expectedMtimeMs) {
1220
- throw rerun({
1221
- msg: `File ${opts.filePath} was modified by another process during processing.`,
1222
- event: { type: 'update', path: opts.filePath },
1223
- })
1224
- }
1225
1224
  const newFileState = await this.fs.stat(tmpPath)
1226
1225
  if (newFileState.mode !== beforeStat.mode) {
1227
1226
  await this.fs.chmod(tmpPath, beforeStat.mode)
@@ -1247,6 +1246,25 @@ ${acc.routeTree.map((child) => `${child.variableName}Route: typeof ${getResolved
1247
1246
  }
1248
1247
  }
1249
1248
  }
1249
+ // Check right before the rename so that changes made while the
1250
+ // temporary file was prepared are not overwritten.
1251
+ let changed: boolean
1252
+ if (expectedContent === undefined) {
1253
+ const current = await this.fs.stat(opts.filePath)
1254
+ changed = current.mtimeMs !== expectedMtimeMs
1255
+ } else {
1256
+ const current = await this.fs.readFile(opts.filePath)
1257
+ changed =
1258
+ current === 'file-not-existing' ||
1259
+ current.stat.mtimeMs !== expectedMtimeMs ||
1260
+ current.fileContent !== expectedContent
1261
+ }
1262
+ if (changed) {
1263
+ throw rerun({
1264
+ msg: `File ${opts.filePath} was modified by another process during processing.`,
1265
+ event: { type: 'update', path: opts.filePath },
1266
+ })
1267
+ }
1250
1268
  } else {
1251
1269
  if (await checkFileExists(opts.filePath)) {
1252
1270
  throw rerun({
@@ -1370,6 +1388,7 @@ ${acc.routeTree.map((child) => `${child.variableName}Route: typeof ${getResolved
1370
1388
  strategy: {
1371
1389
  type: 'mtime',
1372
1390
  expectedMtimeMs: rootNodeFile.stat.mtimeMs,
1391
+ expectedContent: rootNodeFile.fileContent,
1373
1392
  },
1374
1393
  })
1375
1394
  updatedCacheEntry.fileContent = rootRouteContent