@tanstack/router-generator 1.121.0-alpha.26 → 1.121.0-alpha.28

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 (75) hide show
  1. package/dist/cjs/config.cjs +5 -5
  2. package/dist/cjs/config.cjs.map +1 -1
  3. package/dist/cjs/config.d.cts +3 -3
  4. package/dist/cjs/filesystem/physical/getRouteNodes.cjs +18 -4
  5. package/dist/cjs/filesystem/physical/getRouteNodes.cjs.map +1 -1
  6. package/dist/cjs/filesystem/physical/getRouteNodes.d.cts +1 -0
  7. package/dist/cjs/filesystem/virtual/config.cjs.map +1 -1
  8. package/dist/cjs/filesystem/virtual/getRouteNodes.cjs +18 -12
  9. package/dist/cjs/filesystem/virtual/getRouteNodes.cjs.map +1 -1
  10. package/dist/cjs/filesystem/virtual/getRouteNodes.d.cts +4 -1
  11. package/dist/cjs/filesystem/virtual/loadConfigFile.cjs.map +1 -1
  12. package/dist/cjs/generator.cjs +147 -98
  13. package/dist/cjs/generator.cjs.map +1 -1
  14. package/dist/cjs/generator.d.cts +11 -9
  15. package/dist/cjs/index.d.cts +1 -1
  16. package/dist/cjs/logger.cjs.map +1 -1
  17. package/dist/cjs/plugin/default-generator-plugin.cjs +16 -10
  18. package/dist/cjs/plugin/default-generator-plugin.cjs.map +1 -1
  19. package/dist/cjs/template.cjs.map +1 -1
  20. package/dist/cjs/transform/default-transform-plugin.cjs +6 -4
  21. package/dist/cjs/transform/default-transform-plugin.cjs.map +1 -1
  22. package/dist/cjs/transform/transform.cjs +48 -32
  23. package/dist/cjs/transform/transform.cjs.map +1 -1
  24. package/dist/cjs/transform/transform.d.cts +1 -1
  25. package/dist/cjs/transform/types.d.cts +1 -1
  26. package/dist/cjs/transform/utils.cjs.map +1 -1
  27. package/dist/cjs/transform/utils.d.cts +1 -1
  28. package/dist/cjs/types.d.cts +5 -0
  29. package/dist/cjs/utils.cjs +43 -24
  30. package/dist/cjs/utils.cjs.map +1 -1
  31. package/dist/cjs/utils.d.cts +6 -0
  32. package/dist/esm/config.d.ts +3 -3
  33. package/dist/esm/config.js +6 -6
  34. package/dist/esm/config.js.map +1 -1
  35. package/dist/esm/filesystem/physical/getRouteNodes.d.ts +1 -0
  36. package/dist/esm/filesystem/physical/getRouteNodes.js +19 -5
  37. package/dist/esm/filesystem/physical/getRouteNodes.js.map +1 -1
  38. package/dist/esm/filesystem/virtual/config.js.map +1 -1
  39. package/dist/esm/filesystem/virtual/getRouteNodes.d.ts +4 -1
  40. package/dist/esm/filesystem/virtual/getRouteNodes.js +19 -13
  41. package/dist/esm/filesystem/virtual/getRouteNodes.js.map +1 -1
  42. package/dist/esm/filesystem/virtual/loadConfigFile.js.map +1 -1
  43. package/dist/esm/generator.d.ts +11 -9
  44. package/dist/esm/generator.js +150 -101
  45. package/dist/esm/generator.js.map +1 -1
  46. package/dist/esm/index.d.ts +1 -1
  47. package/dist/esm/logger.js.map +1 -1
  48. package/dist/esm/plugin/default-generator-plugin.js +16 -10
  49. package/dist/esm/plugin/default-generator-plugin.js.map +1 -1
  50. package/dist/esm/template.js.map +1 -1
  51. package/dist/esm/transform/default-transform-plugin.js +6 -4
  52. package/dist/esm/transform/default-transform-plugin.js.map +1 -1
  53. package/dist/esm/transform/transform.d.ts +1 -1
  54. package/dist/esm/transform/transform.js +48 -32
  55. package/dist/esm/transform/transform.js.map +1 -1
  56. package/dist/esm/transform/types.d.ts +1 -1
  57. package/dist/esm/transform/utils.d.ts +1 -1
  58. package/dist/esm/transform/utils.js.map +1 -1
  59. package/dist/esm/types.d.ts +5 -0
  60. package/dist/esm/utils.d.ts +6 -0
  61. package/dist/esm/utils.js +43 -24
  62. package/dist/esm/utils.js.map +1 -1
  63. package/package.json +5 -5
  64. package/src/config.ts +6 -5
  65. package/src/filesystem/physical/getRouteNodes.ts +31 -11
  66. package/src/filesystem/virtual/getRouteNodes.ts +32 -23
  67. package/src/generator.ts +196 -72
  68. package/src/index.ts +2 -0
  69. package/src/plugin/default-generator-plugin.ts +16 -3
  70. package/src/transform/default-transform-plugin.ts +5 -2
  71. package/src/transform/transform.ts +68 -43
  72. package/src/transform/types.ts +1 -1
  73. package/src/transform/utils.ts +1 -1
  74. package/src/types.ts +7 -0
  75. package/src/utils.ts +79 -31
@@ -31,8 +31,15 @@ function _interopNamespaceDefault(e) {
31
31
  }
32
32
  const fsp__namespace = /* @__PURE__ */ _interopNamespaceDefault(fsp);
33
33
  const DefaultFileSystem = {
34
- stat: (filePath) => fsp__namespace.stat(filePath, { bigint: true }),
35
- mkdtempSync: node_fs.mkdtempSync,
34
+ stat: async (filePath) => {
35
+ const res = await fsp__namespace.stat(filePath, { bigint: true });
36
+ return {
37
+ mtimeMs: res.mtimeMs,
38
+ mode: Number(res.mode),
39
+ uid: Number(res.uid),
40
+ gid: Number(res.gid)
41
+ };
42
+ },
36
43
  rename: (oldPath, newPath) => fsp__namespace.rename(oldPath, newPath),
37
44
  writeFile: (filePath, content) => fsp__namespace.writeFile(filePath, content),
38
45
  readFile: async (filePath) => {
@@ -50,7 +57,9 @@ const DefaultFileSystem = {
50
57
  }
51
58
  throw e;
52
59
  }
53
- }
60
+ },
61
+ chmod: (filePath, mode) => fsp__namespace.chmod(filePath, mode),
62
+ chown: (filePath, uid, gid) => fsp__namespace.chown(filePath, uid, gid)
54
63
  };
55
64
  function rerun(opts) {
56
65
  const { event, ...rest } = opts;
@@ -68,13 +77,11 @@ class Generator {
68
77
  this.pluginsWithTransform = [];
69
78
  this.transformPlugins = [];
70
79
  this.routeGroupPatternRegex = /\(.+\)/g;
80
+ this.physicalDirectories = [];
71
81
  this.config = opts.config;
72
82
  this.logger = logger.logging({ disabled: this.config.disableLogging });
73
83
  this.root = opts.root;
74
84
  this.fs = opts.fs || DefaultFileSystem;
75
- this.tmpDir = this.fs.mkdtempSync(
76
- path.join(this.config.tmpDir, "tanstack-router-")
77
- );
78
85
  this.generatedRouteTreePath = path.resolve(this.config.generatedRouteTree);
79
86
  this.targetTemplate = template.getTargetTemplate(this.config);
80
87
  this.routesDirectoryPath = this.getRoutesDirectoryPath();
@@ -94,11 +101,17 @@ class Generator {
94
101
  getRoutesDirectoryPath() {
95
102
  return path.isAbsolute(this.config.routesDirectory) ? this.config.routesDirectory : path.resolve(this.root, this.config.routesDirectory);
96
103
  }
104
+ getRoutesByFileMap() {
105
+ return new Map(
106
+ [...this.routeNodeCache.entries()].map(([filePath, cacheEntry]) => [
107
+ filePath,
108
+ { routePath: cacheEntry.routeId }
109
+ ])
110
+ );
111
+ }
97
112
  async run(event) {
98
- if (event && event.type !== "rerun") {
99
- if (!(event.path === this.generatedRouteTreePath || event.path.startsWith(this.routesDirectoryPath))) {
100
- return;
101
- }
113
+ if (event && event.type !== "rerun" && !this.isFileRelevantForRouteTreeGeneration(event.path)) {
114
+ return;
102
115
  }
103
116
  this.fileEventQueue.push(event ?? { type: "rerun" });
104
117
  if (this.runPromise) {
@@ -169,7 +182,11 @@ class Generator {
169
182
  } else {
170
183
  getRouteNodesResult = await getRouteNodes$1.getRouteNodes(this.config, this.root);
171
184
  }
172
- const { rootRouteNode, routeNodes: beforeRouteNodes } = getRouteNodesResult;
185
+ const {
186
+ rootRouteNode,
187
+ routeNodes: beforeRouteNodes,
188
+ physicalDirectories
189
+ } = getRouteNodesResult;
173
190
  if (rootRouteNode === void 0) {
174
191
  let errorMessage = `rootRouteNode must not be undefined. Make sure you've added your root route into the route-tree.`;
175
192
  if (!this.config.virtualRouteConfig) {
@@ -179,22 +196,17 @@ Add the file in: "${this.config.routesDirectory}/${rootPathId.rootPathId}.${this
179
196
  }
180
197
  throw new Error(errorMessage);
181
198
  }
199
+ this.physicalDirectories = physicalDirectories;
182
200
  writeRouteTreeFile = await this.handleRootNode(rootRouteNode);
183
201
  const preRouteNodes = utils.multiSortBy(beforeRouteNodes, [
184
202
  (d) => d.routePath === "/" ? -1 : 1,
185
- (d) => {
186
- var _a;
187
- return (_a = d.routePath) == null ? void 0 : _a.split("/").length;
188
- },
203
+ (d) => d.routePath?.split("/").length,
189
204
  (d) => d.filePath.match(new RegExp(`[./]${this.config.indexToken}[.]`)) ? 1 : -1,
190
205
  (d) => d.filePath.match(
191
206
  /[./](component|errorComponent|pendingComponent|loader|lazy)[.]/
192
207
  ) ? 1 : -1,
193
208
  (d) => d.filePath.match(new RegExp(`[./]${this.config.routeToken}[.]`)) ? -1 : 1,
194
- (d) => {
195
- var _a;
196
- return ((_a = d.routePath) == null ? void 0 : _a.endsWith("/")) ? -1 : 1;
197
- },
209
+ (d) => d.routePath?.endsWith("/") ? -1 : 1,
198
210
  (d) => d.routePath
199
211
  ]).filter((d) => ![`/${rootPathId.rootPathId}`].includes(d.routePath || ""));
200
212
  const routeFileAllResult = await Promise.allSettled(
@@ -213,8 +225,7 @@ Add the file in: "${this.config.routesDirectory}/${rootPathId.rootPathId}.${this
213
225
  return [];
214
226
  });
215
227
  routeFileResult.forEach((result) => {
216
- var _a;
217
- if (!((_a = result.node.exports) == null ? void 0 : _a.length)) {
228
+ if (!result.node.exports?.length) {
218
229
  this.logger.warn(
219
230
  `Route file "${result.cacheEntry.fileContent}" does not export any route piece. This is likely a mistake.`
220
231
  );
@@ -232,8 +243,36 @@ Add the file in: "${this.config.routesDirectory}/${rootPathId.rootPathId}.${this
232
243
  };
233
244
  }
234
245
  writeRouteTreeFile = true;
246
+ } else {
247
+ const routeTreeFileChange = await this.didFileChangeComparedToCache(
248
+ { path: this.generatedRouteTreePath },
249
+ this.routeTreeFileCache
250
+ );
251
+ if (routeTreeFileChange.result !== false) {
252
+ writeRouteTreeFile = "force";
253
+ if (routeTreeFileChange.result === true) {
254
+ const routeTreeFile = await this.fs.readFile(
255
+ this.generatedRouteTreePath
256
+ );
257
+ if (routeTreeFile !== "file-not-existing") {
258
+ this.routeTreeFileCache = {
259
+ fileContent: routeTreeFile.fileContent,
260
+ mtimeMs: routeTreeFile.stat.mtimeMs
261
+ };
262
+ }
263
+ }
264
+ }
235
265
  }
236
266
  if (!writeRouteTreeFile) {
267
+ for (const fullPath of this.routeNodeCache.keys()) {
268
+ if (!this.routeNodeShadowCache.has(fullPath)) {
269
+ writeRouteTreeFile = true;
270
+ break;
271
+ }
272
+ }
273
+ }
274
+ if (!writeRouteTreeFile) {
275
+ this.swapCaches();
237
276
  return;
238
277
  }
239
278
  let routeTreeContent = this.buildRouteTreeFileContent(
@@ -244,7 +283,7 @@ Add the file in: "${this.config.routesDirectory}/${rootPathId.rootPathId}.${this
244
283
  routeTreeContent = this.config.enableRouteTreeFormatting ? await utils.format(routeTreeContent, this.config) : routeTreeContent;
245
284
  let newMtimeMs;
246
285
  if (this.routeTreeFileCache) {
247
- if (this.routeTreeFileCache.fileContent === routeTreeContent) ;
286
+ if (writeRouteTreeFile !== "force" && this.routeTreeFileCache.fileContent === routeTreeContent) ;
248
287
  else {
249
288
  const newRouteTreeFileStat = await this.safeFileWrite({
250
289
  filePath: this.generatedRouteTreePath,
@@ -272,13 +311,15 @@ Add the file in: "${this.config.routesDirectory}/${rootPathId.rootPathId}.${this
272
311
  mtimeMs: newMtimeMs
273
312
  };
274
313
  }
314
+ this.swapCaches();
315
+ }
316
+ swapCaches() {
275
317
  this.routeNodeCache = this.routeNodeShadowCache;
276
318
  this.routeNodeShadowCache = /* @__PURE__ */ new Map();
277
319
  }
278
320
  buildRouteTreeFileContent(rootRouteNode, preRouteNodes, routeFileResult) {
279
321
  const getImportForRouteNode = (node, exportName) => {
280
- var _a;
281
- if ((_a = node.exports) == null ? void 0 : _a.includes(exportName)) {
322
+ if (node.exports?.includes(exportName)) {
282
323
  return {
283
324
  source: `./${this.getImportPath(node)}`,
284
325
  specifiers: [
@@ -292,7 +333,6 @@ Add the file in: "${this.config.routesDirectory}/${rootPathId.rootPathId}.${this
292
333
  return void 0;
293
334
  };
294
335
  const buildRouteTreeForExport = (plugin) => {
295
- var _a, _b, _c;
296
336
  const exportName = plugin.transformPlugin.exportName;
297
337
  const acc = {
298
338
  routeTree: [],
@@ -300,23 +340,14 @@ Add the file in: "${this.config.routesDirectory}/${rootPathId.rootPathId}.${this
300
340
  routePiecesByPath: {}
301
341
  };
302
342
  for (const node of preRouteNodes) {
303
- if ((_a = node.exports) == null ? void 0 : _a.includes(plugin.transformPlugin.exportName)) {
343
+ if (node.exports?.includes(plugin.transformPlugin.exportName)) {
304
344
  this.handleNode(node, acc);
305
345
  }
306
346
  }
307
347
  const sortedRouteNodes = utils.multiSortBy(acc.routeNodes, [
308
- (d) => {
309
- var _a2;
310
- return ((_a2 = d.routePath) == null ? void 0 : _a2.includes(`/${rootPathId.rootPathId}`)) ? -1 : 1;
311
- },
312
- (d) => {
313
- var _a2;
314
- return (_a2 = d.routePath) == null ? void 0 : _a2.split("/").length;
315
- },
316
- (d) => {
317
- var _a2;
318
- return ((_a2 = d.routePath) == null ? void 0 : _a2.endsWith(this.config.indexToken)) ? -1 : 1;
319
- },
348
+ (d) => d.routePath?.includes(`/${rootPathId.rootPathId}`) ? -1 : 1,
349
+ (d) => d.routePath?.split("/").length,
350
+ (d) => d.routePath?.endsWith(this.config.indexToken) ? -1 : 1,
320
351
  (d) => d
321
352
  ]);
322
353
  const pluginConfig = plugin.config({
@@ -325,11 +356,11 @@ Add the file in: "${this.config.routesDirectory}/${rootPathId.rootPathId}.${this
325
356
  sortedRouteNodes
326
357
  });
327
358
  const routeImports2 = sortedRouteNodes.filter((d) => !d.isVirtual).flatMap((node) => getImportForRouteNode(node, exportName) ?? []);
328
- const hasMatchingRouteFiles = acc.routeNodes.length > 0 || ((_b = rootRouteNode.exports) == null ? void 0 : _b.includes(exportName));
359
+ const hasMatchingRouteFiles = acc.routeNodes.length > 0 || rootRouteNode.exports?.includes(exportName);
329
360
  const virtualRouteNodes = sortedRouteNodes.filter((d) => d.isVirtual).map((node) => {
330
361
  return `const ${node.variableName}${exportName}Import = ${plugin.createVirtualRouteCode({ node })}`;
331
362
  });
332
- if (!((_c = rootRouteNode.exports) == null ? void 0 : _c.includes(exportName)) && pluginConfig.virtualRootRoute) {
363
+ if (!rootRouteNode.exports?.includes(exportName) && pluginConfig.virtualRootRoute) {
333
364
  virtualRouteNodes.unshift(
334
365
  `const ${rootRouteNode.variableName}${exportName}Import = ${plugin.createRootRouteCode()}`
335
366
  );
@@ -346,12 +377,11 @@ Add the file in: "${this.config.routesDirectory}/${rootPathId.rootPathId}.${this
346
377
  this.config.disableTypes
347
378
  );
348
379
  const createUpdateRoutes = sortedRouteNodes.map((node) => {
349
- var _a2, _b2, _c2, _d, _e;
350
- const loaderNode = (_a2 = acc.routePiecesByPath[node.routePath]) == null ? void 0 : _a2.loader;
351
- const componentNode = (_b2 = acc.routePiecesByPath[node.routePath]) == null ? void 0 : _b2.component;
352
- const errorComponentNode = (_c2 = acc.routePiecesByPath[node.routePath]) == null ? void 0 : _c2.errorComponent;
353
- const pendingComponentNode = (_d = acc.routePiecesByPath[node.routePath]) == null ? void 0 : _d.pendingComponent;
354
- const lazyComponentNode = (_e = acc.routePiecesByPath[node.routePath]) == null ? void 0 : _e.lazy;
380
+ const loaderNode = acc.routePiecesByPath[node.routePath]?.loader;
381
+ const componentNode = acc.routePiecesByPath[node.routePath]?.component;
382
+ const errorComponentNode = acc.routePiecesByPath[node.routePath]?.errorComponent;
383
+ const pendingComponentNode = acc.routePiecesByPath[node.routePath]?.pendingComponent;
384
+ const lazyComponentNode = acc.routePiecesByPath[node.routePath]?.lazy;
355
385
  return [
356
386
  [
357
387
  `const ${node.variableName}${exportName} = ${node.variableName}${exportName}Import.update({
@@ -413,14 +443,12 @@ Add the file in: "${this.config.routesDirectory}/${rootPathId.rootPathId}.${this
413
443
  if (!this.config.disableTypes && hasMatchingRouteFiles) {
414
444
  fileRoutesByFullPathPerPlugin = [
415
445
  `export interface File${exportName}sByFullPath {
416
- ${[...utils.createRouteNodesByFullPath(acc.routeNodes).entries()].map(
417
- ([fullPath, routeNode]) => {
418
- return `'${fullPath}': typeof ${utils.getResolvedRouteNodeVariableName(routeNode, exportName)}`;
419
- }
420
- )}
446
+ ${[...utils.createRouteNodesByFullPath(acc.routeNodes).entries()].filter(([fullPath]) => fullPath).map(([fullPath, routeNode]) => {
447
+ return `'${fullPath}': typeof ${utils.getResolvedRouteNodeVariableName(routeNode, exportName)}`;
448
+ })}
421
449
  }`,
422
450
  `export interface File${exportName}sByTo {
423
- ${[...utils.createRouteNodesByTo(acc.routeNodes).entries()].map(([to, routeNode]) => {
451
+ ${[...utils.createRouteNodesByTo(acc.routeNodes).entries()].filter(([to]) => to).map(([to, routeNode]) => {
424
452
  return `'${to}': typeof ${utils.getResolvedRouteNodeVariableName(routeNode, exportName)}`;
425
453
  })}
426
454
  }`,
@@ -432,9 +460,9 @@ ${[...utils.createRouteNodesById(acc.routeNodes).entries()].map(([id, routeNode]
432
460
  }`,
433
461
  `export interface File${exportName}Types {
434
462
  file${exportName}sByFullPath: File${exportName}sByFullPath
435
- fullPaths: ${acc.routeNodes.length > 0 ? [...utils.createRouteNodesByFullPath(acc.routeNodes).keys()].map((fullPath) => `'${fullPath}'`).join("|") : "never"}
463
+ fullPaths: ${acc.routeNodes.length > 0 ? [...utils.createRouteNodesByFullPath(acc.routeNodes).keys()].filter((fullPath) => fullPath).map((fullPath) => `'${fullPath}'`).join("|") : "never"}
436
464
  file${exportName}sByTo: File${exportName}sByTo
437
- to: ${acc.routeNodes.length > 0 ? [...utils.createRouteNodesByTo(acc.routeNodes).keys()].map((to) => `'${to}'`).join("|") : "never"}
465
+ to: ${acc.routeNodes.length > 0 ? [...utils.createRouteNodesByTo(acc.routeNodes).keys()].filter((to) => to).map((to) => `'${to}'`).join("|") : "never"}
438
466
  id: ${[`'${routerCore.rootRouteId}'`, ...[...utils.createRouteNodesById(acc.routeNodes).keys()].map((id) => `'${id}'`)].join("|")}
439
467
  file${exportName}sById: File${exportName}sById
440
468
  }`,
@@ -442,9 +470,12 @@ file${exportName}sById: File${exportName}sById
442
470
  ${acc.routeTree.map((child) => `${child.variableName}${exportName}: typeof ${utils.getResolvedRouteNodeVariableName(child, exportName)}`).join(",")}
443
471
  }`
444
472
  ].join("\n");
445
- fileRoutesByPathInterfacePerPlugin = buildFileRoutesByPathInterface({
473
+ fileRoutesByPathInterfacePerPlugin = utils.buildFileRoutesByPathInterface({
446
474
  ...plugin.moduleAugmentation({ generator: this }),
447
- routeNodes: preRouteNodes,
475
+ routeNodes: this.config.verboseFileRoutes !== false ? sortedRouteNodes : [
476
+ ...routeFileResult.map(({ node }) => node),
477
+ ...sortedRouteNodes.filter((d) => d.isVirtual)
478
+ ],
448
479
  exportName
449
480
  });
450
481
  }
@@ -477,8 +508,7 @@ ${acc.routeTree.map((child) => `${child.variableName}${exportName}: typeof ${uti
477
508
  ...buildRouteTreeForExport(plugin)
478
509
  }));
479
510
  this.plugins.map((plugin) => {
480
- var _a;
481
- return (_a = plugin.onRouteTreesChanged) == null ? void 0 : _a.call(plugin, {
511
+ return plugin.onRouteTreesChanged?.({
482
512
  routeTrees,
483
513
  rootRouteNode,
484
514
  generator: this
@@ -547,7 +577,6 @@ ${acc.routeTree.map((child) => `${child.variableName}${exportName}: typeof ${uti
547
577
  );
548
578
  }
549
579
  async processRouteNodeFile(node) {
550
- var _a, _b, _c, _d, _e;
551
580
  const result = await this.isRouteFileCacheFresh(node);
552
581
  if (result.status === "fresh") {
553
582
  node.exports = result.cacheEntry.exports;
@@ -564,9 +593,10 @@ ${acc.routeTree.map((child) => `${child.variableName}${exportName}: typeof ${uti
564
593
  const updatedCacheEntry = {
565
594
  fileContent: existingRouteFile.fileContent,
566
595
  mtimeMs: existingRouteFile.stat.mtimeMs,
567
- exports: []
596
+ exports: [],
597
+ routeId: node.routePath ?? "$$TSR_NO_ROUTE_PATH_ASSIGNED$$"
568
598
  };
569
- const escapedRoutePath = ((_a = node.routePath) == null ? void 0 : _a.replaceAll("$", "$$")) ?? "";
599
+ const escapedRoutePath = node.routePath?.replaceAll("$", "$$") ?? "";
570
600
  let shouldWriteRouteFile = false;
571
601
  if (!existingRouteFile.fileContent) {
572
602
  shouldWriteRouteFile = true;
@@ -574,10 +604,10 @@ ${acc.routeTree.map((child) => `${child.variableName}${exportName}: typeof ${uti
574
604
  const tLazyRouteTemplate = this.targetTemplate.lazyRoute;
575
605
  updatedCacheEntry.fileContent = await template.fillTemplate(
576
606
  this.config,
577
- (((_b = this.config.customScaffolding) == null ? void 0 : _b.lazyRouteTemplate) || ((_c = this.config.customScaffolding) == null ? void 0 : _c.routeTemplate)) ?? tLazyRouteTemplate.template(),
607
+ (this.config.customScaffolding?.lazyRouteTemplate || this.config.customScaffolding?.routeTemplate) ?? tLazyRouteTemplate.template(),
578
608
  {
579
609
  tsrImports: tLazyRouteTemplate.imports.tsrImports(),
580
- tsrPath: escapedRoutePath.replaceAll(/\{(.+)\}/gm, "$1"),
610
+ tsrPath: escapedRoutePath.replaceAll(/\{(.+?)\}/gm, "$1"),
581
611
  tsrExportStart: tLazyRouteTemplate.imports.tsrExportStart(escapedRoutePath),
582
612
  tsrExportEnd: tLazyRouteTemplate.imports.tsrExportEnd()
583
613
  }
@@ -597,10 +627,10 @@ ${acc.routeTree.map((child) => `${child.variableName}${exportName}: typeof ${uti
597
627
  const tRouteTemplate = this.targetTemplate.route;
598
628
  updatedCacheEntry.fileContent = await template.fillTemplate(
599
629
  this.config,
600
- ((_d = this.config.customScaffolding) == null ? void 0 : _d.routeTemplate) ?? tRouteTemplate.template(),
630
+ this.config.customScaffolding?.routeTemplate ?? tRouteTemplate.template(),
601
631
  {
602
632
  tsrImports: tRouteTemplate.imports.tsrImports(),
603
- tsrPath: escapedRoutePath.replaceAll(/\{(.+)\}/gm, "$1"),
633
+ tsrPath: escapedRoutePath.replaceAll(/\{(.+?)\}/gm, "$1"),
604
634
  tsrExportStart: tRouteTemplate.imports.tsrExportStart(escapedRoutePath),
605
635
  tsrExportEnd: tRouteTemplate.imports.tsrExportEnd()
606
636
  }
@@ -645,7 +675,7 @@ ${acc.routeTree.map((child) => `${child.variableName}${exportName}: typeof ${uti
645
675
  this.routeNodeShadowCache.set(node.fullPath, updatedCacheEntry);
646
676
  node.exports = updatedCacheEntry.exports;
647
677
  const shouldWriteTree = !routerCore.deepEqual(
648
- (_e = result.cacheEntry) == null ? void 0 : _e.exports,
678
+ result.cacheEntry?.exports,
649
679
  updatedCacheEntry.exports
650
680
  );
651
681
  return {
@@ -684,6 +714,23 @@ ${acc.routeTree.map((child) => `${child.variableName}${exportName}: typeof ${uti
684
714
  event: { type: "update", path: opts.filePath }
685
715
  });
686
716
  }
717
+ const newFileState = await this.fs.stat(tmpPath);
718
+ if (newFileState.mode !== beforeStat.mode) {
719
+ await this.fs.chmod(tmpPath, beforeStat.mode);
720
+ }
721
+ if (newFileState.uid !== beforeStat.uid || newFileState.gid !== beforeStat.gid) {
722
+ try {
723
+ await this.fs.chown(tmpPath, beforeStat.uid, beforeStat.gid);
724
+ } catch (err) {
725
+ if (typeof err === "object" && err !== null && "code" in err && err.code === "EPERM") {
726
+ console.warn(
727
+ `[safeFileWrite] chown failed: ${err.message}`
728
+ );
729
+ } else {
730
+ throw err;
731
+ }
732
+ }
733
+ }
687
734
  } else {
688
735
  if (await utils.checkFileExists(opts.filePath)) {
689
736
  throw rerun({
@@ -699,7 +746,11 @@ ${acc.routeTree.map((child) => `${child.variableName}${exportName}: typeof ${uti
699
746
  getTempFileName(filePath) {
700
747
  const absPath = path.resolve(filePath);
701
748
  const hash = crypto.createHash("md5").update(absPath).digest("hex");
702
- return path.join(this.tmpDir, hash);
749
+ if (!this.sessionId) {
750
+ node_fs.mkdirSync(this.config.tmpDir, { recursive: true });
751
+ this.sessionId = crypto.randomBytes(4).toString("hex");
752
+ }
753
+ return path.join(this.config.tmpDir, `${this.sessionId}-${hash}`);
703
754
  }
704
755
  async isRouteFileCacheFresh(node) {
705
756
  const fileChangedCache = await this.didRouteFileChangeComparedToCache(
@@ -752,10 +803,11 @@ ${acc.routeTree.map((child) => `${child.variableName}${exportName}: typeof ${uti
752
803
  return { status: "stale", cacheEntry: fileChangedCache.cacheEntry };
753
804
  }
754
805
  async handleRootNode(node) {
755
- var _a;
756
806
  const result = await this.isRouteFileCacheFresh(node);
757
807
  if (result.status === "fresh") {
758
- return false;
808
+ node.exports = result.cacheEntry.exports;
809
+ this.routeNodeShadowCache.set(node.fullPath, result.cacheEntry);
810
+ return result.exportsChanged;
759
811
  }
760
812
  const rootNodeFile = await this.fs.readFile(node.fullPath);
761
813
  if (rootNodeFile === "file-not-existing") {
@@ -764,7 +816,8 @@ ${acc.routeTree.map((child) => `${child.variableName}${exportName}: typeof ${uti
764
816
  const updatedCacheEntry = {
765
817
  fileContent: rootNodeFile.fileContent,
766
818
  mtimeMs: rootNodeFile.stat.mtimeMs,
767
- exports: []
819
+ exports: [],
820
+ routeId: node.routePath ?? "$$TSR_NO_ROOT_ROUTE_PATH_ASSIGNED$$"
768
821
  };
769
822
  if (!rootNodeFile.fileContent) {
770
823
  const rootTemplate = this.targetTemplate.rootRoute;
@@ -801,16 +854,15 @@ ${acc.routeTree.map((child) => `${child.variableName}${exportName}: typeof ${uti
801
854
  node.exports = rootRouteExports;
802
855
  this.routeNodeShadowCache.set(node.fullPath, updatedCacheEntry);
803
856
  const shouldWriteTree = !routerCore.deepEqual(
804
- (_a = result.cacheEntry) == null ? void 0 : _a.exports,
857
+ result.cacheEntry?.exports,
805
858
  rootRouteExports
806
859
  );
807
860
  return shouldWriteTree;
808
861
  }
809
862
  handleNode(node, acc) {
810
- var _a;
811
863
  utils.resetRegex(this.routeGroupPatternRegex);
812
864
  let parentRoute = utils.hasParentRoute(acc.routeNodes, node, node.routePath);
813
- if ((parentRoute == null ? void 0 : parentRoute.isVirtualParentRoute) && ((_a = parentRoute.children) == null ? void 0 : _a.length)) {
865
+ if (parentRoute?.isVirtualParentRoute && parentRoute.children?.length) {
814
866
  const possibleParentRoute = utils.hasParentRoute(
815
867
  parentRoute.children,
816
868
  node,
@@ -825,7 +877,7 @@ ${acc.routeTree.map((child) => `${child.variableName}${exportName}: typeof ${uti
825
877
  const trimmedPath = utils.trimPathLeft(node.path ?? "");
826
878
  const split = trimmedPath.split("/");
827
879
  const lastRouteSegment = split[split.length - 1] ?? trimmedPath;
828
- node.isNonPath = lastRouteSegment.startsWith("_") || this.routeGroupPatternRegex.test(lastRouteSegment);
880
+ node.isNonPath = lastRouteSegment.startsWith("_") || split.every((part) => this.routeGroupPatternRegex.test(part));
829
881
  node.cleanedPath = utils.removeGroups(
830
882
  utils.removeUnderscores(utils.removeLayoutSegments(node.path)) ?? ""
831
883
  );
@@ -899,31 +951,28 @@ ${acc.routeTree.map((child) => `${child.variableName}${exportName}: typeof ${uti
899
951
  }
900
952
  acc.routeNodes.push(node);
901
953
  }
902
- }
903
- function buildFileRoutesByPathInterface(opts) {
904
- return `declare module '${opts.module}' {
905
- interface ${opts.interfaceName} {
906
- ${opts.routeNodes.map((routeNode) => {
907
- var _a;
908
- const filePathId = routeNode.routePath;
909
- let preloaderRoute = "";
910
- if ((_a = routeNode.exports) == null ? void 0 : _a.includes(opts.exportName)) {
911
- preloaderRoute = `typeof ${routeNode.variableName}${opts.exportName}Import`;
912
- } else {
913
- preloaderRoute = "unknown";
914
- }
915
- const parent = utils.findParent(routeNode, opts.exportName);
916
- return `'${filePathId}': {
917
- id: '${filePathId}'
918
- path: '${utils.inferPath(routeNode)}'
919
- fullPath: '${utils.inferFullPath(routeNode)}'
920
- preLoaderRoute: ${preloaderRoute}
921
- parentRoute: typeof ${parent}
922
- }`;
923
- }).join("\n")}
954
+ // only process files that are relevant for the route tree generation
955
+ isFileRelevantForRouteTreeGeneration(filePath) {
956
+ if (filePath === this.generatedRouteTreePath) {
957
+ return true;
958
+ }
959
+ if (filePath.startsWith(this.routesDirectoryPath)) {
960
+ return true;
961
+ }
962
+ if (typeof this.config.virtualRouteConfig === "string" && filePath === this.config.virtualRouteConfig) {
963
+ return true;
964
+ }
965
+ if (this.routeNodeCache.has(filePath)) {
966
+ return true;
967
+ }
968
+ if (getRouteNodes$1.isVirtualConfigFile(path.basename(filePath))) {
969
+ return true;
970
+ }
971
+ if (this.physicalDirectories.some((dir) => filePath.startsWith(dir))) {
972
+ return true;
973
+ }
974
+ return false;
924
975
  }
925
- }`;
926
976
  }
927
977
  exports.Generator = Generator;
928
- exports.buildFileRoutesByPathInterface = buildFileRoutesByPathInterface;
929
978
  //# sourceMappingURL=generator.cjs.map