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