@tanstack/router-generator 1.121.0 → 1.121.1

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/router-generator",
3
- "version": "1.121.0",
3
+ "version": "1.121.1",
4
4
  "description": "Modern and scalable routing for React applications",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
package/src/generator.ts CHANGED
@@ -8,6 +8,7 @@ import { getRouteNodes as physicalGetRouteNodes } from './filesystem/physical/ge
8
8
  import { getRouteNodes as virtualGetRouteNodes } from './filesystem/virtual/getRouteNodes'
9
9
  import { rootPathId } from './filesystem/physical/rootPathId'
10
10
  import {
11
+ buildFileRoutesByPathInterface,
11
12
  buildImportString,
12
13
  buildRouteTreeConfig,
13
14
  checkFileExists,
@@ -19,8 +20,6 @@ import {
19
20
  format,
20
21
  getResolvedRouteNodeVariableName,
21
22
  hasParentRoute,
22
- inferFullPath,
23
- inferPath,
24
23
  isRouteNodeValidForAugmentation,
25
24
  lowerCaseFirstChar,
26
25
  mergeImportDeclarations,
@@ -292,7 +291,7 @@ export class Generator {
292
291
  }
293
292
 
294
293
  private async generatorInternal() {
295
- let writeRouteTreeFile = false as boolean
294
+ let writeRouteTreeFile: boolean | 'force' = false
296
295
 
297
296
  let getRouteNodesResult: GetRouteNodesResult
298
297
 
@@ -376,6 +375,36 @@ export class Generator {
376
375
  }
377
376
  }
378
377
  writeRouteTreeFile = true
378
+ } else {
379
+ const routeTreeFileChange = await this.didFileChangeComparedToCache(
380
+ { path: this.generatedRouteTreePath },
381
+ this.routeTreeFileCache,
382
+ )
383
+ if (routeTreeFileChange.result !== false) {
384
+ writeRouteTreeFile = 'force'
385
+ if (routeTreeFileChange.result === true) {
386
+ const routeTreeFile = await this.fs.readFile(
387
+ this.generatedRouteTreePath,
388
+ )
389
+ if (routeTreeFile !== 'file-not-existing') {
390
+ this.routeTreeFileCache = {
391
+ fileContent: routeTreeFile.fileContent,
392
+ mtimeMs: routeTreeFile.stat.mtimeMs,
393
+ }
394
+ }
395
+ }
396
+ }
397
+ }
398
+
399
+ if (!writeRouteTreeFile) {
400
+ // only needs to be done if no other changes have been detected yet
401
+ // compare shadowCache and cache to identify deleted routes
402
+ for (const fullPath of this.routeNodeCache.keys()) {
403
+ if (!this.routeNodeShadowCache.has(fullPath)) {
404
+ writeRouteTreeFile = true
405
+ break
406
+ }
407
+ }
379
408
  }
380
409
 
381
410
  if (!writeRouteTreeFile) {
@@ -393,7 +422,10 @@ export class Generator {
393
422
 
394
423
  let newMtimeMs: bigint | undefined
395
424
  if (this.routeTreeFileCache) {
396
- if (this.routeTreeFileCache.fileContent === routeTreeContent) {
425
+ if (
426
+ writeRouteTreeFile !== 'force' &&
427
+ this.routeTreeFileCache.fileContent === routeTreeContent
428
+ ) {
397
429
  // existing route tree file is already up-to-date, don't write it
398
430
  // we should only get here in the initial run when the route cache is not filled yet
399
431
  } else {
@@ -634,7 +666,13 @@ ${acc.routeTree.map((child) => `${child.variableName}${exportName}: typeof ${get
634
666
 
635
667
  fileRoutesByPathInterfacePerPlugin = buildFileRoutesByPathInterface({
636
668
  ...plugin.moduleAugmentation({ generator: this }),
637
- routeNodes: preRouteNodes,
669
+ routeNodes:
670
+ this.config.verboseFileRoutes !== false
671
+ ? sortedRouteNodes
672
+ : [
673
+ ...routeFileResult.map(({ node }) => node),
674
+ ...sortedRouteNodes.filter((d) => d.isVirtual),
675
+ ],
638
676
  exportName,
639
677
  })
640
678
  }
@@ -1255,37 +1293,3 @@ ${acc.routeTree.map((child) => `${child.variableName}${exportName}: typeof ${get
1255
1293
  acc.routeNodes.push(node)
1256
1294
  }
1257
1295
  }
1258
-
1259
- export function buildFileRoutesByPathInterface(opts: {
1260
- routeNodes: Array<RouteNode>
1261
- module: string
1262
- interfaceName: string
1263
- exportName: string
1264
- }): string {
1265
- return `declare module '${opts.module}' {
1266
- interface ${opts.interfaceName} {
1267
- ${opts.routeNodes
1268
- .map((routeNode) => {
1269
- const filePathId = routeNode.routePath
1270
- let preloaderRoute = ''
1271
-
1272
- if (routeNode.exports?.includes(opts.exportName)) {
1273
- preloaderRoute = `typeof ${routeNode.variableName}${opts.exportName}Import`
1274
- } else {
1275
- preloaderRoute = 'unknown'
1276
- }
1277
-
1278
- const parent = findParent(routeNode, opts.exportName)
1279
-
1280
- return `'${filePathId}': {
1281
- id: '${filePathId}'
1282
- path: '${inferPath(routeNode)}'
1283
- fullPath: '${inferFullPath(routeNode)}'
1284
- preLoaderRoute: ${preloaderRoute}
1285
- parentRoute: typeof ${parent}
1286
- }`
1287
- })
1288
- .join('\n')}
1289
- }
1290
- }`
1291
- }
package/src/utils.ts CHANGED
@@ -583,3 +583,37 @@ export const findParent = (
583
583
  }
584
584
  return findParent(node.parent, exportName)
585
585
  }
586
+
587
+ export function buildFileRoutesByPathInterface(opts: {
588
+ routeNodes: Array<RouteNode>
589
+ module: string
590
+ interfaceName: string
591
+ exportName: string
592
+ }): string {
593
+ return `declare module '${opts.module}' {
594
+ interface ${opts.interfaceName} {
595
+ ${opts.routeNodes
596
+ .map((routeNode) => {
597
+ const filePathId = routeNode.routePath
598
+ let preloaderRoute = ''
599
+
600
+ if (routeNode.exports?.includes(opts.exportName)) {
601
+ preloaderRoute = `typeof ${routeNode.variableName}${opts.exportName}Import`
602
+ } else {
603
+ preloaderRoute = 'unknown'
604
+ }
605
+
606
+ const parent = findParent(routeNode, opts.exportName)
607
+
608
+ return `'${filePathId}': {
609
+ id: '${filePathId}'
610
+ path: '${inferPath(routeNode)}'
611
+ fullPath: '${inferFullPath(routeNode)}'
612
+ preLoaderRoute: ${preloaderRoute}
613
+ parentRoute: typeof ${parent}
614
+ }`
615
+ })
616
+ .join('\n')}
617
+ }
618
+ }`
619
+ }