@tanstack/router-generator 1.121.0 → 1.121.2
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/dist/cjs/generator.cjs +33 -28
- package/dist/cjs/generator.cjs.map +1 -1
- package/dist/cjs/generator.d.cts +0 -7
- package/dist/cjs/utils.cjs +25 -0
- package/dist/cjs/utils.cjs.map +1 -1
- package/dist/cjs/utils.d.cts +6 -0
- package/dist/esm/generator.d.ts +0 -7
- package/dist/esm/generator.js +34 -29
- package/dist/esm/generator.js.map +1 -1
- package/dist/esm/utils.d.ts +6 -0
- package/dist/esm/utils.js +25 -0
- package/dist/esm/utils.js.map +1 -1
- package/package.json +5 -5
- package/src/generator.ts +43 -39
- package/src/utils.ts +34 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/router-generator",
|
|
3
|
-
"version": "1.121.
|
|
3
|
+
"version": "1.121.2",
|
|
4
4
|
"description": "Modern and scalable routing for React applications",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -54,12 +54,12 @@
|
|
|
54
54
|
"source-map": "^0.7.4",
|
|
55
55
|
"tsx": "^4.19.2",
|
|
56
56
|
"zod": "^3.24.2",
|
|
57
|
-
"@tanstack/router-core": "^1.121.
|
|
58
|
-
"@tanstack/
|
|
59
|
-
"@tanstack/
|
|
57
|
+
"@tanstack/router-core": "^1.121.2",
|
|
58
|
+
"@tanstack/virtual-file-routes": "^1.120.17",
|
|
59
|
+
"@tanstack/router-utils": "^1.121.0"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
|
-
"@tanstack/react-router": "^1.121.
|
|
62
|
+
"@tanstack/react-router": "^1.121.2"
|
|
63
63
|
},
|
|
64
64
|
"scripts": {}
|
|
65
65
|
}
|
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
|
|
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 (
|
|
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:
|
|
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
|
+
}
|