@tanstack/router-generator 1.121.20 → 1.121.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/dist/cjs/config.cjs +140 -0
  2. package/dist/cjs/config.cjs.map +1 -0
  3. package/dist/cjs/config.d.cts +155 -0
  4. package/dist/cjs/filesystem/physical/getRouteNodes.cjs +204 -0
  5. package/dist/cjs/filesystem/physical/getRouteNodes.cjs.map +1 -0
  6. package/dist/cjs/filesystem/physical/getRouteNodes.d.cts +15 -0
  7. package/dist/cjs/filesystem/physical/rootPathId.cjs +5 -0
  8. package/dist/cjs/filesystem/physical/rootPathId.cjs.map +1 -0
  9. package/dist/cjs/filesystem/physical/rootPathId.d.cts +1 -0
  10. package/dist/cjs/filesystem/virtual/config.cjs +37 -0
  11. package/dist/cjs/filesystem/virtual/config.cjs.map +1 -0
  12. package/dist/cjs/filesystem/virtual/config.d.cts +3 -0
  13. package/dist/cjs/filesystem/virtual/getRouteNodes.cjs +192 -0
  14. package/dist/cjs/filesystem/virtual/getRouteNodes.cjs.map +1 -0
  15. package/dist/cjs/filesystem/virtual/getRouteNodes.d.cts +8 -0
  16. package/dist/cjs/filesystem/virtual/loadConfigFile.cjs +11 -0
  17. package/dist/cjs/filesystem/virtual/loadConfigFile.cjs.map +1 -0
  18. package/dist/cjs/filesystem/virtual/loadConfigFile.d.cts +1 -0
  19. package/dist/cjs/generator.cjs +974 -0
  20. package/dist/cjs/generator.cjs.map +1 -0
  21. package/dist/cjs/generator.d.cts +77 -0
  22. package/dist/cjs/index.cjs +35 -0
  23. package/dist/cjs/index.cjs.map +1 -0
  24. package/dist/cjs/index.d.cts +12 -0
  25. package/dist/cjs/logger.cjs +37 -0
  26. package/dist/cjs/logger.cjs.map +1 -0
  27. package/dist/cjs/logger.d.cts +10 -0
  28. package/dist/cjs/plugin/default-generator-plugin.cjs +101 -0
  29. package/dist/cjs/plugin/default-generator-plugin.cjs.map +1 -0
  30. package/dist/cjs/plugin/default-generator-plugin.d.cts +2 -0
  31. package/dist/cjs/plugin/types.d.cts +46 -0
  32. package/dist/cjs/template.cjs +110 -0
  33. package/dist/cjs/template.cjs.map +1 -0
  34. package/dist/cjs/template.d.cts +33 -0
  35. package/dist/cjs/transform/default-transform-plugin.cjs +95 -0
  36. package/dist/cjs/transform/default-transform-plugin.cjs.map +1 -0
  37. package/dist/cjs/transform/default-transform-plugin.d.cts +2 -0
  38. package/dist/cjs/transform/transform.cjs +374 -0
  39. package/dist/cjs/transform/transform.cjs.map +1 -0
  40. package/dist/cjs/transform/transform.d.cts +4 -0
  41. package/dist/cjs/transform/types.d.cts +43 -0
  42. package/dist/cjs/transform/utils.cjs +36 -0
  43. package/dist/cjs/transform/utils.cjs.map +1 -0
  44. package/dist/cjs/transform/utils.d.cts +2 -0
  45. package/dist/cjs/types.d.cts +47 -0
  46. package/dist/cjs/utils.cjs +438 -0
  47. package/dist/cjs/utils.cjs.map +1 -0
  48. package/dist/cjs/utils.d.cts +133 -0
  49. package/dist/esm/config.d.ts +155 -0
  50. package/dist/esm/config.js +140 -0
  51. package/dist/esm/config.js.map +1 -0
  52. package/dist/esm/filesystem/physical/getRouteNodes.d.ts +15 -0
  53. package/dist/esm/filesystem/physical/getRouteNodes.js +187 -0
  54. package/dist/esm/filesystem/physical/getRouteNodes.js.map +1 -0
  55. package/dist/esm/filesystem/physical/rootPathId.d.ts +1 -0
  56. package/dist/esm/filesystem/physical/rootPathId.js +5 -0
  57. package/dist/esm/filesystem/physical/rootPathId.js.map +1 -0
  58. package/dist/esm/filesystem/virtual/config.d.ts +3 -0
  59. package/dist/esm/filesystem/virtual/config.js +37 -0
  60. package/dist/esm/filesystem/virtual/config.js.map +1 -0
  61. package/dist/esm/filesystem/virtual/getRouteNodes.d.ts +8 -0
  62. package/dist/esm/filesystem/virtual/getRouteNodes.js +192 -0
  63. package/dist/esm/filesystem/virtual/getRouteNodes.js.map +1 -0
  64. package/dist/esm/filesystem/virtual/loadConfigFile.d.ts +1 -0
  65. package/dist/esm/filesystem/virtual/loadConfigFile.js +11 -0
  66. package/dist/esm/filesystem/virtual/loadConfigFile.js.map +1 -0
  67. package/dist/esm/generator.d.ts +77 -0
  68. package/dist/esm/generator.js +957 -0
  69. package/dist/esm/generator.js.map +1 -0
  70. package/dist/esm/index.d.ts +12 -0
  71. package/dist/esm/index.js +35 -0
  72. package/dist/esm/index.js.map +1 -0
  73. package/dist/esm/logger.d.ts +10 -0
  74. package/dist/esm/logger.js +37 -0
  75. package/dist/esm/logger.js.map +1 -0
  76. package/dist/esm/plugin/default-generator-plugin.d.ts +2 -0
  77. package/dist/esm/plugin/default-generator-plugin.js +101 -0
  78. package/dist/esm/plugin/default-generator-plugin.js.map +1 -0
  79. package/dist/esm/plugin/types.d.ts +46 -0
  80. package/dist/esm/template.d.ts +33 -0
  81. package/dist/esm/template.js +110 -0
  82. package/dist/esm/template.js.map +1 -0
  83. package/dist/esm/transform/default-transform-plugin.d.ts +2 -0
  84. package/dist/esm/transform/default-transform-plugin.js +95 -0
  85. package/dist/esm/transform/default-transform-plugin.js.map +1 -0
  86. package/dist/esm/transform/transform.d.ts +4 -0
  87. package/dist/esm/transform/transform.js +374 -0
  88. package/dist/esm/transform/transform.js.map +1 -0
  89. package/dist/esm/transform/types.d.ts +43 -0
  90. package/dist/esm/transform/utils.d.ts +2 -0
  91. package/dist/esm/transform/utils.js +36 -0
  92. package/dist/esm/transform/utils.js.map +1 -0
  93. package/dist/esm/types.d.ts +47 -0
  94. package/dist/esm/utils.d.ts +133 -0
  95. package/dist/esm/utils.js +420 -0
  96. package/dist/esm/utils.js.map +1 -0
  97. package/package.json +5 -5
  98. package/src/generator.ts +5 -1
@@ -0,0 +1,957 @@
1
+ import path from "node:path";
2
+ import * as fsp from "node:fs/promises";
3
+ import { mkdtempSync } from "node:fs";
4
+ import crypto from "node:crypto";
5
+ import { deepEqual, rootRouteId } from "@tanstack/router-core";
6
+ import { logging } from "./logger.js";
7
+ import { getRouteNodes as getRouteNodes$1, isVirtualConfigFile } from "./filesystem/physical/getRouteNodes.js";
8
+ import { getRouteNodes } from "./filesystem/virtual/getRouteNodes.js";
9
+ import { rootPathId } from "./filesystem/physical/rootPathId.js";
10
+ import { multiSortBy, format, mergeImportDeclarations, buildImportString, replaceBackslash, removeExt, checkFileExists, resetRegex, hasParentRoute, determineNodePath, trimPathLeft, removeGroups, removeUnderscores, removeLayoutSegments, removeLastSegmentFromPath, routePathToVariable, buildRouteTreeConfig, findParent, createRouteNodesByFullPath, createRouteNodesByTo, createRouteNodesById, getResolvedRouteNodeVariableName, buildFileRoutesByPathInterface, lowerCaseFirstChar, isRouteNodeValidForAugmentation } from "./utils.js";
11
+ import { getTargetTemplate, fillTemplate } from "./template.js";
12
+ import { transform } from "./transform/transform.js";
13
+ import { defaultGeneratorPlugin } from "./plugin/default-generator-plugin.js";
14
+ const DefaultFileSystem = {
15
+ stat: (filePath) => fsp.stat(filePath, { bigint: true }),
16
+ mkdtempSync,
17
+ rename: (oldPath, newPath) => fsp.rename(oldPath, newPath),
18
+ writeFile: (filePath, content) => fsp.writeFile(filePath, content),
19
+ readFile: async (filePath) => {
20
+ try {
21
+ const fileHandle = await fsp.open(filePath, "r");
22
+ const stat = await fileHandle.stat({ bigint: true });
23
+ const fileContent = (await fileHandle.readFile()).toString();
24
+ await fileHandle.close();
25
+ return { stat, fileContent };
26
+ } catch (e) {
27
+ if ("code" in e) {
28
+ if (e.code === "ENOENT") {
29
+ return "file-not-existing";
30
+ }
31
+ }
32
+ throw e;
33
+ }
34
+ }
35
+ };
36
+ function rerun(opts) {
37
+ const { event, ...rest } = opts;
38
+ return { rerun: true, event: event ?? { type: "rerun" }, ...rest };
39
+ }
40
+ function isRerun(result) {
41
+ return typeof result === "object" && result !== null && "rerun" in result && result.rerun === true;
42
+ }
43
+ class Generator {
44
+ constructor(opts) {
45
+ this.routeNodeCache = /* @__PURE__ */ new Map();
46
+ this.routeNodeShadowCache = /* @__PURE__ */ new Map();
47
+ this.fileEventQueue = [];
48
+ this.plugins = [defaultGeneratorPlugin()];
49
+ this.pluginsWithTransform = [];
50
+ this.transformPlugins = [];
51
+ this.routeGroupPatternRegex = /\(.+\)/g;
52
+ this.physicalDirectories = [];
53
+ this.config = opts.config;
54
+ this.logger = logging({ disabled: this.config.disableLogging });
55
+ this.root = opts.root;
56
+ this.fs = opts.fs || DefaultFileSystem;
57
+ this.tmpDir = this.fs.mkdtempSync(
58
+ path.join(this.config.tmpDir, "router-generator-")
59
+ );
60
+ this.generatedRouteTreePath = path.resolve(this.config.generatedRouteTree);
61
+ this.targetTemplate = getTargetTemplate(this.config);
62
+ this.routesDirectoryPath = this.getRoutesDirectoryPath();
63
+ this.plugins.push(...opts.config.plugins || []);
64
+ this.plugins.forEach((plugin) => {
65
+ if ("transformPlugin" in plugin) {
66
+ if (this.pluginsWithTransform.find((p) => p.name === plugin.name)) {
67
+ throw new Error(
68
+ `Plugin with name "${plugin.name}" is already registered for export ${plugin.transformPlugin.exportName}!`
69
+ );
70
+ }
71
+ this.pluginsWithTransform.push(plugin);
72
+ this.transformPlugins.push(plugin.transformPlugin);
73
+ }
74
+ });
75
+ }
76
+ getRoutesDirectoryPath() {
77
+ return path.isAbsolute(this.config.routesDirectory) ? this.config.routesDirectory : path.resolve(this.root, this.config.routesDirectory);
78
+ }
79
+ getRoutesByFileMap() {
80
+ return new Map(
81
+ [...this.routeNodeCache.entries()].map(([filePath, cacheEntry]) => [
82
+ filePath,
83
+ { routePath: cacheEntry.routeId }
84
+ ])
85
+ );
86
+ }
87
+ async run(event) {
88
+ if (event && event.type !== "rerun" && !this.isFileRelevantForRouteTreeGeneration(event.path)) {
89
+ return;
90
+ }
91
+ this.fileEventQueue.push(event ?? { type: "rerun" });
92
+ if (this.runPromise) {
93
+ return this.runPromise;
94
+ }
95
+ this.runPromise = (async () => {
96
+ do {
97
+ const tempQueue = this.fileEventQueue;
98
+ this.fileEventQueue = [];
99
+ const remainingEvents = (await Promise.all(
100
+ tempQueue.map(async (e) => {
101
+ if (e.type === "update") {
102
+ let cacheEntry;
103
+ if (e.path === this.generatedRouteTreePath) {
104
+ cacheEntry = this.routeTreeFileCache;
105
+ } else {
106
+ cacheEntry = this.routeNodeCache.get(e.path);
107
+ }
108
+ const change = await this.didFileChangeComparedToCache(
109
+ { path: e.path },
110
+ cacheEntry
111
+ );
112
+ if (change.result === false) {
113
+ return null;
114
+ }
115
+ }
116
+ return e;
117
+ })
118
+ )).filter((e) => e !== null);
119
+ if (remainingEvents.length === 0) {
120
+ break;
121
+ }
122
+ try {
123
+ const start = performance.now();
124
+ await this.generatorInternal();
125
+ const end = performance.now();
126
+ this.logger.info(
127
+ `Generated route tree in ${Math.round(end - start)}ms`
128
+ );
129
+ } catch (err) {
130
+ const errArray = !Array.isArray(err) ? [err] : err;
131
+ const recoverableErrors = errArray.filter((e) => isRerun(e));
132
+ if (recoverableErrors.length === errArray.length) {
133
+ this.fileEventQueue.push(...recoverableErrors.map((e) => e.event));
134
+ recoverableErrors.forEach((e) => {
135
+ if (e.msg) {
136
+ this.logger.info(e.msg);
137
+ }
138
+ });
139
+ } else {
140
+ const unrecoverableErrors = errArray.filter((e) => !isRerun(e));
141
+ this.runPromise = void 0;
142
+ throw new Error(
143
+ unrecoverableErrors.map((e) => e.message).join()
144
+ );
145
+ }
146
+ }
147
+ } while (this.fileEventQueue.length);
148
+ this.runPromise = void 0;
149
+ })();
150
+ return this.runPromise;
151
+ }
152
+ async generatorInternal() {
153
+ let writeRouteTreeFile = false;
154
+ let getRouteNodesResult;
155
+ if (this.config.virtualRouteConfig) {
156
+ getRouteNodesResult = await getRouteNodes(this.config, this.root);
157
+ } else {
158
+ getRouteNodesResult = await getRouteNodes$1(this.config, this.root);
159
+ }
160
+ const {
161
+ rootRouteNode,
162
+ routeNodes: beforeRouteNodes,
163
+ physicalDirectories
164
+ } = getRouteNodesResult;
165
+ if (rootRouteNode === void 0) {
166
+ let errorMessage = `rootRouteNode must not be undefined. Make sure you've added your root route into the route-tree.`;
167
+ if (!this.config.virtualRouteConfig) {
168
+ errorMessage += `
169
+ Make sure that you add a "${rootPathId}.${this.config.disableTypes ? "js" : "tsx"}" file to your routes directory.
170
+ Add the file in: "${this.config.routesDirectory}/${rootPathId}.${this.config.disableTypes ? "js" : "tsx"}"`;
171
+ }
172
+ throw new Error(errorMessage);
173
+ }
174
+ this.physicalDirectories = physicalDirectories;
175
+ writeRouteTreeFile = await this.handleRootNode(rootRouteNode);
176
+ const preRouteNodes = multiSortBy(beforeRouteNodes, [
177
+ (d) => d.routePath === "/" ? -1 : 1,
178
+ (d) => {
179
+ var _a;
180
+ return (_a = d.routePath) == null ? void 0 : _a.split("/").length;
181
+ },
182
+ (d) => d.filePath.match(new RegExp(`[./]${this.config.indexToken}[.]`)) ? 1 : -1,
183
+ (d) => d.filePath.match(
184
+ /[./](component|errorComponent|pendingComponent|loader|lazy)[.]/
185
+ ) ? 1 : -1,
186
+ (d) => d.filePath.match(new RegExp(`[./]${this.config.routeToken}[.]`)) ? -1 : 1,
187
+ (d) => {
188
+ var _a;
189
+ return ((_a = d.routePath) == null ? void 0 : _a.endsWith("/")) ? -1 : 1;
190
+ },
191
+ (d) => d.routePath
192
+ ]).filter((d) => ![`/${rootPathId}`].includes(d.routePath || ""));
193
+ const routeFileAllResult = await Promise.allSettled(
194
+ preRouteNodes.filter((n) => !n.isVirtualParentRoute && !n.isVirtual).map((n) => this.processRouteNodeFile(n))
195
+ );
196
+ const rejections = routeFileAllResult.filter(
197
+ (result) => result.status === "rejected"
198
+ );
199
+ if (rejections.length > 0) {
200
+ throw rejections.map((e) => e.reason);
201
+ }
202
+ const routeFileResult = routeFileAllResult.flatMap((result) => {
203
+ if (result.status === "fulfilled" && result.value !== null) {
204
+ return result.value;
205
+ }
206
+ return [];
207
+ });
208
+ routeFileResult.forEach((result) => {
209
+ var _a;
210
+ if (!((_a = result.node.exports) == null ? void 0 : _a.length)) {
211
+ this.logger.warn(
212
+ `Route file "${result.cacheEntry.fileContent}" does not export any route piece. This is likely a mistake.`
213
+ );
214
+ }
215
+ });
216
+ if (routeFileResult.find((r) => r.shouldWriteTree)) {
217
+ writeRouteTreeFile = true;
218
+ }
219
+ if (!this.routeTreeFileCache) {
220
+ const routeTreeFile = await this.fs.readFile(this.generatedRouteTreePath);
221
+ if (routeTreeFile !== "file-not-existing") {
222
+ this.routeTreeFileCache = {
223
+ fileContent: routeTreeFile.fileContent,
224
+ mtimeMs: routeTreeFile.stat.mtimeMs
225
+ };
226
+ }
227
+ writeRouteTreeFile = true;
228
+ } else {
229
+ const routeTreeFileChange = await this.didFileChangeComparedToCache(
230
+ { path: this.generatedRouteTreePath },
231
+ this.routeTreeFileCache
232
+ );
233
+ if (routeTreeFileChange.result !== false) {
234
+ writeRouteTreeFile = "force";
235
+ if (routeTreeFileChange.result === true) {
236
+ const routeTreeFile = await this.fs.readFile(
237
+ this.generatedRouteTreePath
238
+ );
239
+ if (routeTreeFile !== "file-not-existing") {
240
+ this.routeTreeFileCache = {
241
+ fileContent: routeTreeFile.fileContent,
242
+ mtimeMs: routeTreeFile.stat.mtimeMs
243
+ };
244
+ }
245
+ }
246
+ }
247
+ }
248
+ if (!writeRouteTreeFile) {
249
+ for (const fullPath of this.routeNodeCache.keys()) {
250
+ if (!this.routeNodeShadowCache.has(fullPath)) {
251
+ writeRouteTreeFile = true;
252
+ break;
253
+ }
254
+ }
255
+ }
256
+ if (!writeRouteTreeFile) {
257
+ this.swapCaches();
258
+ return;
259
+ }
260
+ let routeTreeContent = this.buildRouteTreeFileContent(
261
+ rootRouteNode,
262
+ preRouteNodes,
263
+ routeFileResult
264
+ );
265
+ routeTreeContent = this.config.enableRouteTreeFormatting ? await format(routeTreeContent, this.config) : routeTreeContent;
266
+ let newMtimeMs;
267
+ if (this.routeTreeFileCache) {
268
+ if (writeRouteTreeFile !== "force" && this.routeTreeFileCache.fileContent === routeTreeContent) ;
269
+ else {
270
+ const newRouteTreeFileStat = await this.safeFileWrite({
271
+ filePath: this.generatedRouteTreePath,
272
+ newContent: routeTreeContent,
273
+ strategy: {
274
+ type: "mtime",
275
+ expectedMtimeMs: this.routeTreeFileCache.mtimeMs
276
+ }
277
+ });
278
+ newMtimeMs = newRouteTreeFileStat.mtimeMs;
279
+ }
280
+ } else {
281
+ const newRouteTreeFileStat = await this.safeFileWrite({
282
+ filePath: this.generatedRouteTreePath,
283
+ newContent: routeTreeContent,
284
+ strategy: {
285
+ type: "new-file"
286
+ }
287
+ });
288
+ newMtimeMs = newRouteTreeFileStat.mtimeMs;
289
+ }
290
+ if (newMtimeMs !== void 0) {
291
+ this.routeTreeFileCache = {
292
+ fileContent: routeTreeContent,
293
+ mtimeMs: newMtimeMs
294
+ };
295
+ }
296
+ this.swapCaches();
297
+ }
298
+ swapCaches() {
299
+ this.routeNodeCache = this.routeNodeShadowCache;
300
+ this.routeNodeShadowCache = /* @__PURE__ */ new Map();
301
+ }
302
+ buildRouteTreeFileContent(rootRouteNode, preRouteNodes, routeFileResult) {
303
+ const getImportForRouteNode = (node, exportName) => {
304
+ var _a;
305
+ if ((_a = node.exports) == null ? void 0 : _a.includes(exportName)) {
306
+ return {
307
+ source: `./${this.getImportPath(node)}`,
308
+ specifiers: [
309
+ {
310
+ imported: exportName,
311
+ local: `${node.variableName}${exportName}Import`
312
+ }
313
+ ]
314
+ };
315
+ }
316
+ return void 0;
317
+ };
318
+ const buildRouteTreeForExport = (plugin) => {
319
+ var _a, _b, _c;
320
+ const exportName = plugin.transformPlugin.exportName;
321
+ const acc = {
322
+ routeTree: [],
323
+ routeNodes: [],
324
+ routePiecesByPath: {}
325
+ };
326
+ for (const node of preRouteNodes) {
327
+ if ((_a = node.exports) == null ? void 0 : _a.includes(plugin.transformPlugin.exportName)) {
328
+ this.handleNode(node, acc);
329
+ }
330
+ }
331
+ const sortedRouteNodes = multiSortBy(acc.routeNodes, [
332
+ (d) => {
333
+ var _a2;
334
+ return ((_a2 = d.routePath) == null ? void 0 : _a2.includes(`/${rootPathId}`)) ? -1 : 1;
335
+ },
336
+ (d) => {
337
+ var _a2;
338
+ return (_a2 = d.routePath) == null ? void 0 : _a2.split("/").length;
339
+ },
340
+ (d) => {
341
+ var _a2;
342
+ return ((_a2 = d.routePath) == null ? void 0 : _a2.endsWith(this.config.indexToken)) ? -1 : 1;
343
+ },
344
+ (d) => d
345
+ ]);
346
+ const pluginConfig = plugin.config({
347
+ generator: this,
348
+ rootRouteNode,
349
+ sortedRouteNodes
350
+ });
351
+ const routeImports2 = sortedRouteNodes.filter((d) => !d.isVirtual).flatMap((node) => getImportForRouteNode(node, exportName) ?? []);
352
+ const hasMatchingRouteFiles = acc.routeNodes.length > 0 || ((_b = rootRouteNode.exports) == null ? void 0 : _b.includes(exportName));
353
+ const virtualRouteNodes = sortedRouteNodes.filter((d) => d.isVirtual).map((node) => {
354
+ return `const ${node.variableName}${exportName}Import = ${plugin.createVirtualRouteCode({ node })}`;
355
+ });
356
+ if (!((_c = rootRouteNode.exports) == null ? void 0 : _c.includes(exportName)) && pluginConfig.virtualRootRoute) {
357
+ virtualRouteNodes.unshift(
358
+ `const ${rootRouteNode.variableName}${exportName}Import = ${plugin.createRootRouteCode()}`
359
+ );
360
+ }
361
+ const imports = plugin.imports({
362
+ sortedRouteNodes,
363
+ acc,
364
+ generator: this,
365
+ rootRouteNode
366
+ });
367
+ const routeTreeConfig = buildRouteTreeConfig(
368
+ acc.routeTree,
369
+ exportName,
370
+ this.config.disableTypes
371
+ );
372
+ const createUpdateRoutes = sortedRouteNodes.map((node) => {
373
+ var _a2, _b2, _c2, _d, _e;
374
+ const loaderNode = (_a2 = acc.routePiecesByPath[node.routePath]) == null ? void 0 : _a2.loader;
375
+ const componentNode = (_b2 = acc.routePiecesByPath[node.routePath]) == null ? void 0 : _b2.component;
376
+ const errorComponentNode = (_c2 = acc.routePiecesByPath[node.routePath]) == null ? void 0 : _c2.errorComponent;
377
+ const pendingComponentNode = (_d = acc.routePiecesByPath[node.routePath]) == null ? void 0 : _d.pendingComponent;
378
+ const lazyComponentNode = (_e = acc.routePiecesByPath[node.routePath]) == null ? void 0 : _e.lazy;
379
+ return [
380
+ [
381
+ `const ${node.variableName}${exportName} = ${node.variableName}${exportName}Import.update({
382
+ ${[
383
+ `id: '${node.path}'`,
384
+ !node.isNonPath ? `path: '${node.cleanedPath}'` : void 0,
385
+ `getParentRoute: () => ${findParent(node, exportName)}`
386
+ ].filter(Boolean).join(",")}
387
+ }${this.config.disableTypes ? "" : "as any"})`,
388
+ loaderNode ? `.updateLoader({ loader: lazyFn(() => import('./${replaceBackslash(
389
+ removeExt(
390
+ path.relative(
391
+ path.dirname(this.config.generatedRouteTree),
392
+ path.resolve(
393
+ this.config.routesDirectory,
394
+ loaderNode.filePath
395
+ )
396
+ ),
397
+ this.config.addExtensions
398
+ )
399
+ )}'), 'loader') })` : "",
400
+ componentNode || errorComponentNode || pendingComponentNode ? `.update({
401
+ ${[
402
+ ["component", componentNode],
403
+ ["errorComponent", errorComponentNode],
404
+ ["pendingComponent", pendingComponentNode]
405
+ ].filter((d) => d[1]).map((d) => {
406
+ return `${d[0]}: lazyRouteComponent(() => import('./${replaceBackslash(
407
+ removeExt(
408
+ path.relative(
409
+ path.dirname(this.config.generatedRouteTree),
410
+ path.resolve(
411
+ this.config.routesDirectory,
412
+ d[1].filePath
413
+ )
414
+ ),
415
+ this.config.addExtensions
416
+ )
417
+ )}'), '${d[0]}')`;
418
+ }).join("\n,")}
419
+ })` : "",
420
+ lazyComponentNode ? `.lazy(() => import('./${replaceBackslash(
421
+ removeExt(
422
+ path.relative(
423
+ path.dirname(this.config.generatedRouteTree),
424
+ path.resolve(
425
+ this.config.routesDirectory,
426
+ lazyComponentNode.filePath
427
+ )
428
+ ),
429
+ this.config.addExtensions
430
+ )
431
+ )}').then((d) => d.${exportName}))` : ""
432
+ ].join("")
433
+ ].join("\n\n");
434
+ });
435
+ let fileRoutesByPathInterfacePerPlugin = "";
436
+ let fileRoutesByFullPathPerPlugin = "";
437
+ if (!this.config.disableTypes && hasMatchingRouteFiles) {
438
+ fileRoutesByFullPathPerPlugin = [
439
+ `export interface File${exportName}sByFullPath {
440
+ ${[...createRouteNodesByFullPath(acc.routeNodes).entries()].filter(([fullPath]) => fullPath).map(([fullPath, routeNode]) => {
441
+ return `'${fullPath}': typeof ${getResolvedRouteNodeVariableName(routeNode, exportName)}`;
442
+ })}
443
+ }`,
444
+ `export interface File${exportName}sByTo {
445
+ ${[...createRouteNodesByTo(acc.routeNodes).entries()].filter(([to]) => to).map(([to, routeNode]) => {
446
+ return `'${to}': typeof ${getResolvedRouteNodeVariableName(routeNode, exportName)}`;
447
+ })}
448
+ }`,
449
+ `export interface File${exportName}sById {
450
+ '${rootRouteId}': typeof root${exportName}Import,
451
+ ${[...createRouteNodesById(acc.routeNodes).entries()].map(([id, routeNode]) => {
452
+ return `'${id}': typeof ${getResolvedRouteNodeVariableName(routeNode, exportName)}`;
453
+ })}
454
+ }`,
455
+ `export interface File${exportName}Types {
456
+ file${exportName}sByFullPath: File${exportName}sByFullPath
457
+ fullPaths: ${acc.routeNodes.length > 0 ? [...createRouteNodesByFullPath(acc.routeNodes).keys()].filter((fullPath) => fullPath).map((fullPath) => `'${fullPath}'`).join("|") : "never"}
458
+ file${exportName}sByTo: File${exportName}sByTo
459
+ to: ${acc.routeNodes.length > 0 ? [...createRouteNodesByTo(acc.routeNodes).keys()].filter((to) => to).map((to) => `'${to}'`).join("|") : "never"}
460
+ id: ${[`'${rootRouteId}'`, ...[...createRouteNodesById(acc.routeNodes).keys()].map((id) => `'${id}'`)].join("|")}
461
+ file${exportName}sById: File${exportName}sById
462
+ }`,
463
+ `export interface Root${exportName}Children {
464
+ ${acc.routeTree.map((child) => `${child.variableName}${exportName}: typeof ${getResolvedRouteNodeVariableName(child, exportName)}`).join(",")}
465
+ }`
466
+ ].join("\n");
467
+ fileRoutesByPathInterfacePerPlugin = buildFileRoutesByPathInterface({
468
+ ...plugin.moduleAugmentation({ generator: this }),
469
+ routeNodes: this.config.verboseFileRoutes !== false ? sortedRouteNodes : [
470
+ ...routeFileResult.map(({ node }) => node),
471
+ ...sortedRouteNodes.filter((d) => d.isVirtual)
472
+ ],
473
+ exportName
474
+ });
475
+ }
476
+ let routeTree = "";
477
+ if (hasMatchingRouteFiles) {
478
+ routeTree = [
479
+ `const root${exportName}Children${this.config.disableTypes ? "" : `: Root${exportName}Children`} = {
480
+ ${acc.routeTree.map(
481
+ (child) => `${child.variableName}${exportName}: ${getResolvedRouteNodeVariableName(child, exportName)}`
482
+ ).join(",")}
483
+ }`,
484
+ `export const ${lowerCaseFirstChar(exportName)}Tree = root${exportName}Import._addFileChildren(root${exportName}Children)${this.config.disableTypes ? "" : `._addFileTypes<File${exportName}Types>()`}`
485
+ ].join("\n");
486
+ }
487
+ return {
488
+ routeImports: routeImports2,
489
+ sortedRouteNodes,
490
+ acc,
491
+ virtualRouteNodes,
492
+ routeTreeConfig,
493
+ routeTree,
494
+ imports,
495
+ createUpdateRoutes,
496
+ fileRoutesByFullPathPerPlugin,
497
+ fileRoutesByPathInterfacePerPlugin
498
+ };
499
+ };
500
+ const routeTrees = this.pluginsWithTransform.map((plugin) => ({
501
+ exportName: plugin.transformPlugin.exportName,
502
+ ...buildRouteTreeForExport(plugin)
503
+ }));
504
+ this.plugins.map((plugin) => {
505
+ var _a;
506
+ return (_a = plugin.onRouteTreesChanged) == null ? void 0 : _a.call(plugin, {
507
+ routeTrees,
508
+ rootRouteNode,
509
+ generator: this
510
+ });
511
+ });
512
+ let mergedImports = mergeImportDeclarations(
513
+ routeTrees.flatMap((d) => d.imports)
514
+ );
515
+ if (this.config.disableTypes) {
516
+ mergedImports = mergedImports.filter((d) => d.importKind !== "type");
517
+ }
518
+ const importStatements = mergedImports.map(buildImportString);
519
+ let moduleAugmentation = "";
520
+ if (this.config.verboseFileRoutes === false && !this.config.disableTypes) {
521
+ moduleAugmentation = routeFileResult.map(({ node }) => {
522
+ const getModuleDeclaration = (routeNode) => {
523
+ if (!isRouteNodeValidForAugmentation(routeNode)) {
524
+ return "";
525
+ }
526
+ const moduleAugmentation2 = this.pluginsWithTransform.map((plugin) => {
527
+ return plugin.routeModuleAugmentation({
528
+ routeNode
529
+ });
530
+ }).filter(Boolean).join("\n");
531
+ return `declare module './${this.getImportPath(routeNode)}' {
532
+ ${moduleAugmentation2}
533
+ }`;
534
+ };
535
+ return getModuleDeclaration(node);
536
+ }).join("\n");
537
+ }
538
+ const routeImports = routeTrees.flatMap((t) => t.routeImports);
539
+ const rootRouteImports = this.pluginsWithTransform.flatMap(
540
+ (p) => getImportForRouteNode(rootRouteNode, p.transformPlugin.exportName) ?? []
541
+ );
542
+ if (rootRouteImports.length > 0) {
543
+ routeImports.unshift(...rootRouteImports);
544
+ }
545
+ const routeTreeContent = [
546
+ ...this.config.routeTreeFileHeader,
547
+ `// This file was automatically generated by TanStack Router.
548
+ // You should NOT make any changes in this file as it will be overwritten.
549
+ // Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified.`,
550
+ [...importStatements].join("\n"),
551
+ mergeImportDeclarations(routeImports).map(buildImportString).join("\n"),
552
+ routeTrees.flatMap((t) => t.virtualRouteNodes).join("\n"),
553
+ routeTrees.flatMap((t) => t.createUpdateRoutes).join("\n"),
554
+ routeTrees.map((t) => t.fileRoutesByFullPathPerPlugin).join("\n"),
555
+ routeTrees.map((t) => t.fileRoutesByPathInterfacePerPlugin).join("\n"),
556
+ moduleAugmentation,
557
+ routeTrees.flatMap((t) => t.routeTreeConfig).join("\n"),
558
+ routeTrees.map((t) => t.routeTree).join("\n"),
559
+ ...this.config.routeTreeFileFooter
560
+ ].filter(Boolean).join("\n\n");
561
+ return routeTreeContent;
562
+ }
563
+ getImportPath(node) {
564
+ return replaceBackslash(
565
+ removeExt(
566
+ path.relative(
567
+ path.dirname(this.config.generatedRouteTree),
568
+ path.resolve(this.config.routesDirectory, node.filePath)
569
+ ),
570
+ this.config.addExtensions
571
+ )
572
+ );
573
+ }
574
+ async processRouteNodeFile(node) {
575
+ var _a, _b, _c, _d, _e;
576
+ const result = await this.isRouteFileCacheFresh(node);
577
+ if (result.status === "fresh") {
578
+ node.exports = result.cacheEntry.exports;
579
+ return {
580
+ node,
581
+ shouldWriteTree: result.exportsChanged,
582
+ cacheEntry: result.cacheEntry
583
+ };
584
+ }
585
+ const existingRouteFile = await this.fs.readFile(node.fullPath);
586
+ if (existingRouteFile === "file-not-existing") {
587
+ throw new Error(`⚠️ File ${node.fullPath} does not exist`);
588
+ }
589
+ const updatedCacheEntry = {
590
+ fileContent: existingRouteFile.fileContent,
591
+ mtimeMs: existingRouteFile.stat.mtimeMs,
592
+ exports: [],
593
+ routeId: node.routePath ?? "$$TSR_NO_ROUTE_PATH_ASSIGNED$$"
594
+ };
595
+ const escapedRoutePath = ((_a = node.routePath) == null ? void 0 : _a.replaceAll("$", "$$")) ?? "";
596
+ let shouldWriteRouteFile = false;
597
+ if (!existingRouteFile.fileContent) {
598
+ shouldWriteRouteFile = true;
599
+ if (node._fsRouteType === "lazy") {
600
+ const tLazyRouteTemplate = this.targetTemplate.lazyRoute;
601
+ updatedCacheEntry.fileContent = await fillTemplate(
602
+ this.config,
603
+ (((_b = this.config.customScaffolding) == null ? void 0 : _b.lazyRouteTemplate) || ((_c = this.config.customScaffolding) == null ? void 0 : _c.routeTemplate)) ?? tLazyRouteTemplate.template(),
604
+ {
605
+ tsrImports: tLazyRouteTemplate.imports.tsrImports(),
606
+ tsrPath: escapedRoutePath.replaceAll(/\{(.+)\}/gm, "$1"),
607
+ tsrExportStart: tLazyRouteTemplate.imports.tsrExportStart(escapedRoutePath),
608
+ tsrExportEnd: tLazyRouteTemplate.imports.tsrExportEnd()
609
+ }
610
+ );
611
+ updatedCacheEntry.exports = ["Route"];
612
+ } else if (
613
+ // Creating a new normal route file
614
+ ["layout", "static"].some(
615
+ (d) => d === node._fsRouteType
616
+ ) || [
617
+ "component",
618
+ "pendingComponent",
619
+ "errorComponent",
620
+ "loader"
621
+ ].every((d) => d !== node._fsRouteType)
622
+ ) {
623
+ const tRouteTemplate = this.targetTemplate.route;
624
+ updatedCacheEntry.fileContent = await fillTemplate(
625
+ this.config,
626
+ ((_d = this.config.customScaffolding) == null ? void 0 : _d.routeTemplate) ?? tRouteTemplate.template(),
627
+ {
628
+ tsrImports: tRouteTemplate.imports.tsrImports(),
629
+ tsrPath: escapedRoutePath.replaceAll(/\{(.+)\}/gm, "$1"),
630
+ tsrExportStart: tRouteTemplate.imports.tsrExportStart(escapedRoutePath),
631
+ tsrExportEnd: tRouteTemplate.imports.tsrExportEnd()
632
+ }
633
+ );
634
+ updatedCacheEntry.exports = ["Route"];
635
+ } else {
636
+ return null;
637
+ }
638
+ } else {
639
+ const transformResult = await transform({
640
+ source: updatedCacheEntry.fileContent,
641
+ ctx: {
642
+ target: this.config.target,
643
+ routeId: escapedRoutePath,
644
+ lazy: node._fsRouteType === "lazy",
645
+ verboseFileRoutes: !(this.config.verboseFileRoutes === false)
646
+ },
647
+ plugins: this.transformPlugins
648
+ });
649
+ if (transformResult.result === "error") {
650
+ throw new Error(
651
+ `Error transforming route file ${node.fullPath}: ${transformResult.error}`
652
+ );
653
+ }
654
+ updatedCacheEntry.exports = transformResult.exports;
655
+ if (transformResult.result === "modified") {
656
+ updatedCacheEntry.fileContent = transformResult.output;
657
+ shouldWriteRouteFile = true;
658
+ }
659
+ }
660
+ if (shouldWriteRouteFile) {
661
+ const stats = await this.safeFileWrite({
662
+ filePath: node.fullPath,
663
+ newContent: updatedCacheEntry.fileContent,
664
+ strategy: {
665
+ type: "mtime",
666
+ expectedMtimeMs: updatedCacheEntry.mtimeMs
667
+ }
668
+ });
669
+ updatedCacheEntry.mtimeMs = stats.mtimeMs;
670
+ }
671
+ this.routeNodeShadowCache.set(node.fullPath, updatedCacheEntry);
672
+ node.exports = updatedCacheEntry.exports;
673
+ const shouldWriteTree = !deepEqual(
674
+ (_e = result.cacheEntry) == null ? void 0 : _e.exports,
675
+ updatedCacheEntry.exports
676
+ );
677
+ return {
678
+ node,
679
+ shouldWriteTree,
680
+ cacheEntry: updatedCacheEntry
681
+ };
682
+ }
683
+ async didRouteFileChangeComparedToCache(file, cache) {
684
+ const cacheEntry = this[cache].get(file.path);
685
+ return this.didFileChangeComparedToCache(file, cacheEntry);
686
+ }
687
+ async didFileChangeComparedToCache(file, cacheEntry) {
688
+ if (!cacheEntry) {
689
+ return { result: "file-not-in-cache" };
690
+ }
691
+ let mtimeMs = file.mtimeMs;
692
+ if (mtimeMs === void 0) {
693
+ try {
694
+ const currentStat = await this.fs.stat(file.path);
695
+ mtimeMs = currentStat.mtimeMs;
696
+ } catch {
697
+ return { result: "cannot-stat-file" };
698
+ }
699
+ }
700
+ return { result: mtimeMs !== cacheEntry.mtimeMs, mtimeMs, cacheEntry };
701
+ }
702
+ async safeFileWrite(opts) {
703
+ const tmpPath = this.getTempFileName(opts.filePath);
704
+ await this.fs.writeFile(tmpPath, opts.newContent);
705
+ if (opts.strategy.type === "mtime") {
706
+ const beforeStat = await this.fs.stat(opts.filePath);
707
+ if (beforeStat.mtimeMs !== opts.strategy.expectedMtimeMs) {
708
+ throw rerun({
709
+ msg: `File ${opts.filePath} was modified by another process during processing.`,
710
+ event: { type: "update", path: opts.filePath }
711
+ });
712
+ }
713
+ } else {
714
+ if (await checkFileExists(opts.filePath)) {
715
+ throw rerun({
716
+ msg: `File ${opts.filePath} already exists. Cannot overwrite.`,
717
+ event: { type: "update", path: opts.filePath }
718
+ });
719
+ }
720
+ }
721
+ const stat = await this.fs.stat(tmpPath);
722
+ await this.fs.rename(tmpPath, opts.filePath);
723
+ return stat;
724
+ }
725
+ getTempFileName(filePath) {
726
+ const absPath = path.resolve(filePath);
727
+ const hash = crypto.createHash("md5").update(absPath).digest("hex");
728
+ return path.join(this.tmpDir, hash);
729
+ }
730
+ async isRouteFileCacheFresh(node) {
731
+ const fileChangedCache = await this.didRouteFileChangeComparedToCache(
732
+ { path: node.fullPath },
733
+ "routeNodeCache"
734
+ );
735
+ if (fileChangedCache.result === false) {
736
+ this.routeNodeShadowCache.set(node.fullPath, fileChangedCache.cacheEntry);
737
+ return {
738
+ status: "fresh",
739
+ exportsChanged: false,
740
+ cacheEntry: fileChangedCache.cacheEntry
741
+ };
742
+ }
743
+ if (fileChangedCache.result === "cannot-stat-file") {
744
+ throw new Error(`⚠️ expected route file to exist at ${node.fullPath}`);
745
+ }
746
+ const mtimeMs = fileChangedCache.result === true ? fileChangedCache.mtimeMs : void 0;
747
+ const shadowCacheFileChange = await this.didRouteFileChangeComparedToCache(
748
+ { path: node.fullPath, mtimeMs },
749
+ "routeNodeShadowCache"
750
+ );
751
+ if (shadowCacheFileChange.result === "cannot-stat-file") {
752
+ throw new Error(`⚠️ expected route file to exist at ${node.fullPath}`);
753
+ }
754
+ if (shadowCacheFileChange.result === false) {
755
+ if (fileChangedCache.result === true) {
756
+ if (deepEqual(
757
+ fileChangedCache.cacheEntry.exports,
758
+ shadowCacheFileChange.cacheEntry.exports
759
+ )) {
760
+ return {
761
+ status: "fresh",
762
+ exportsChanged: false,
763
+ cacheEntry: shadowCacheFileChange.cacheEntry
764
+ };
765
+ }
766
+ return {
767
+ status: "fresh",
768
+ exportsChanged: true,
769
+ cacheEntry: shadowCacheFileChange.cacheEntry
770
+ };
771
+ }
772
+ }
773
+ if (fileChangedCache.result === "file-not-in-cache") {
774
+ return {
775
+ status: "stale"
776
+ };
777
+ }
778
+ return { status: "stale", cacheEntry: fileChangedCache.cacheEntry };
779
+ }
780
+ async handleRootNode(node) {
781
+ var _a;
782
+ const result = await this.isRouteFileCacheFresh(node);
783
+ if (result.status === "fresh") {
784
+ node.exports = result.cacheEntry.exports;
785
+ this.routeNodeShadowCache.set(node.fullPath, result.cacheEntry);
786
+ return result.exportsChanged;
787
+ }
788
+ const rootNodeFile = await this.fs.readFile(node.fullPath);
789
+ if (rootNodeFile === "file-not-existing") {
790
+ throw new Error(`⚠️ expected root route to exist at ${node.fullPath}`);
791
+ }
792
+ const updatedCacheEntry = {
793
+ fileContent: rootNodeFile.fileContent,
794
+ mtimeMs: rootNodeFile.stat.mtimeMs,
795
+ exports: [],
796
+ routeId: node.routePath ?? "$$TSR_NO_ROOT_ROUTE_PATH_ASSIGNED$$"
797
+ };
798
+ if (!rootNodeFile.fileContent) {
799
+ const rootTemplate = this.targetTemplate.rootRoute;
800
+ const rootRouteContent = await fillTemplate(
801
+ this.config,
802
+ rootTemplate.template(),
803
+ {
804
+ tsrImports: rootTemplate.imports.tsrImports(),
805
+ tsrPath: rootPathId,
806
+ tsrExportStart: rootTemplate.imports.tsrExportStart(),
807
+ tsrExportEnd: rootTemplate.imports.tsrExportEnd()
808
+ }
809
+ );
810
+ this.logger.log(`🟡 Creating ${node.fullPath}`);
811
+ const stats = await this.safeFileWrite({
812
+ filePath: node.fullPath,
813
+ newContent: rootRouteContent,
814
+ strategy: {
815
+ type: "mtime",
816
+ expectedMtimeMs: rootNodeFile.stat.mtimeMs
817
+ }
818
+ });
819
+ updatedCacheEntry.fileContent = rootRouteContent;
820
+ updatedCacheEntry.mtimeMs = stats.mtimeMs;
821
+ }
822
+ const rootRouteExports = [];
823
+ for (const plugin of this.pluginsWithTransform) {
824
+ const exportName = plugin.transformPlugin.exportName;
825
+ if (rootNodeFile.fileContent.includes(`export const ${exportName}`)) {
826
+ rootRouteExports.push(exportName);
827
+ }
828
+ }
829
+ updatedCacheEntry.exports = rootRouteExports;
830
+ node.exports = rootRouteExports;
831
+ this.routeNodeShadowCache.set(node.fullPath, updatedCacheEntry);
832
+ const shouldWriteTree = !deepEqual(
833
+ (_a = result.cacheEntry) == null ? void 0 : _a.exports,
834
+ rootRouteExports
835
+ );
836
+ return shouldWriteTree;
837
+ }
838
+ handleNode(node, acc) {
839
+ var _a;
840
+ resetRegex(this.routeGroupPatternRegex);
841
+ let parentRoute = hasParentRoute(acc.routeNodes, node, node.routePath);
842
+ if ((parentRoute == null ? void 0 : parentRoute.isVirtualParentRoute) && ((_a = parentRoute.children) == null ? void 0 : _a.length)) {
843
+ const possibleParentRoute = hasParentRoute(
844
+ parentRoute.children,
845
+ node,
846
+ node.routePath
847
+ );
848
+ if (possibleParentRoute) {
849
+ parentRoute = possibleParentRoute;
850
+ }
851
+ }
852
+ if (parentRoute) node.parent = parentRoute;
853
+ node.path = determineNodePath(node);
854
+ const trimmedPath = trimPathLeft(node.path ?? "");
855
+ const split = trimmedPath.split("/");
856
+ const lastRouteSegment = split[split.length - 1] ?? trimmedPath;
857
+ node.isNonPath = lastRouteSegment.startsWith("_") || this.routeGroupPatternRegex.test(lastRouteSegment);
858
+ node.cleanedPath = removeGroups(
859
+ removeUnderscores(removeLayoutSegments(node.path)) ?? ""
860
+ );
861
+ if (!node.isVirtual && [
862
+ "lazy",
863
+ "loader",
864
+ "component",
865
+ "pendingComponent",
866
+ "errorComponent"
867
+ ].some((d) => d === node._fsRouteType)) {
868
+ acc.routePiecesByPath[node.routePath] = acc.routePiecesByPath[node.routePath] || {};
869
+ acc.routePiecesByPath[node.routePath][node._fsRouteType === "lazy" ? "lazy" : node._fsRouteType === "loader" ? "loader" : node._fsRouteType === "errorComponent" ? "errorComponent" : node._fsRouteType === "pendingComponent" ? "pendingComponent" : "component"] = node;
870
+ const anchorRoute = acc.routeNodes.find(
871
+ (d) => d.routePath === node.routePath
872
+ );
873
+ if (!anchorRoute) {
874
+ this.handleNode(
875
+ {
876
+ ...node,
877
+ isVirtual: true,
878
+ _fsRouteType: "static"
879
+ },
880
+ acc
881
+ );
882
+ }
883
+ return;
884
+ }
885
+ const cleanedPathIsEmpty = (node.cleanedPath || "").length === 0;
886
+ const nonPathRoute = node._fsRouteType === "pathless_layout" && node.isNonPath;
887
+ node.isVirtualParentRequired = node._fsRouteType === "pathless_layout" || nonPathRoute ? !cleanedPathIsEmpty : false;
888
+ if (!node.isVirtual && node.isVirtualParentRequired) {
889
+ const parentRoutePath = removeLastSegmentFromPath(node.routePath) || "/";
890
+ const parentVariableName = routePathToVariable(parentRoutePath);
891
+ const anchorRoute = acc.routeNodes.find(
892
+ (d) => d.routePath === parentRoutePath
893
+ );
894
+ if (!anchorRoute) {
895
+ const parentNode = {
896
+ ...node,
897
+ path: removeLastSegmentFromPath(node.path) || "/",
898
+ filePath: removeLastSegmentFromPath(node.filePath) || "/",
899
+ fullPath: removeLastSegmentFromPath(node.fullPath) || "/",
900
+ routePath: parentRoutePath,
901
+ variableName: parentVariableName,
902
+ isVirtual: true,
903
+ _fsRouteType: "layout",
904
+ // layout since this route will wrap other routes
905
+ isVirtualParentRoute: true,
906
+ isVirtualParentRequired: false
907
+ };
908
+ parentNode.children = parentNode.children ?? [];
909
+ parentNode.children.push(node);
910
+ node.parent = parentNode;
911
+ if (node._fsRouteType === "pathless_layout") {
912
+ node.path = determineNodePath(node);
913
+ }
914
+ this.handleNode(parentNode, acc);
915
+ } else {
916
+ anchorRoute.children = anchorRoute.children ?? [];
917
+ anchorRoute.children.push(node);
918
+ node.parent = anchorRoute;
919
+ }
920
+ }
921
+ if (node.parent) {
922
+ if (!node.isVirtualParentRequired) {
923
+ node.parent.children = node.parent.children ?? [];
924
+ node.parent.children.push(node);
925
+ }
926
+ } else {
927
+ acc.routeTree.push(node);
928
+ }
929
+ acc.routeNodes.push(node);
930
+ }
931
+ // only process files that are relevant for the route tree generation
932
+ isFileRelevantForRouteTreeGeneration(filePath) {
933
+ if (filePath === this.generatedRouteTreePath) {
934
+ return true;
935
+ }
936
+ if (filePath.startsWith(this.routesDirectoryPath)) {
937
+ return true;
938
+ }
939
+ if (typeof this.config.virtualRouteConfig === "string" && filePath === this.config.virtualRouteConfig) {
940
+ return true;
941
+ }
942
+ if (this.routeNodeCache.has(filePath)) {
943
+ return true;
944
+ }
945
+ if (isVirtualConfigFile(path.basename(filePath))) {
946
+ return true;
947
+ }
948
+ if (this.physicalDirectories.some((dir) => filePath.startsWith(dir))) {
949
+ return true;
950
+ }
951
+ return false;
952
+ }
953
+ }
954
+ export {
955
+ Generator
956
+ };
957
+ //# sourceMappingURL=generator.js.map