@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.
- package/dist/cjs/config.cjs +5 -5
- package/dist/cjs/config.cjs.map +1 -1
- package/dist/cjs/config.d.cts +3 -3
- package/dist/cjs/filesystem/physical/getRouteNodes.cjs +18 -4
- package/dist/cjs/filesystem/physical/getRouteNodes.cjs.map +1 -1
- package/dist/cjs/filesystem/physical/getRouteNodes.d.cts +1 -0
- package/dist/cjs/filesystem/virtual/config.cjs.map +1 -1
- package/dist/cjs/filesystem/virtual/getRouteNodes.cjs +18 -12
- package/dist/cjs/filesystem/virtual/getRouteNodes.cjs.map +1 -1
- package/dist/cjs/filesystem/virtual/getRouteNodes.d.cts +4 -1
- package/dist/cjs/filesystem/virtual/loadConfigFile.cjs.map +1 -1
- package/dist/cjs/generator.cjs +147 -98
- package/dist/cjs/generator.cjs.map +1 -1
- package/dist/cjs/generator.d.cts +11 -9
- package/dist/cjs/index.d.cts +1 -1
- package/dist/cjs/logger.cjs.map +1 -1
- package/dist/cjs/plugin/default-generator-plugin.cjs +16 -10
- package/dist/cjs/plugin/default-generator-plugin.cjs.map +1 -1
- package/dist/cjs/template.cjs.map +1 -1
- package/dist/cjs/transform/default-transform-plugin.cjs +6 -4
- package/dist/cjs/transform/default-transform-plugin.cjs.map +1 -1
- package/dist/cjs/transform/transform.cjs +48 -32
- package/dist/cjs/transform/transform.cjs.map +1 -1
- package/dist/cjs/transform/transform.d.cts +1 -1
- package/dist/cjs/transform/types.d.cts +1 -1
- package/dist/cjs/transform/utils.cjs.map +1 -1
- package/dist/cjs/transform/utils.d.cts +1 -1
- package/dist/cjs/types.d.cts +5 -0
- package/dist/cjs/utils.cjs +43 -24
- package/dist/cjs/utils.cjs.map +1 -1
- package/dist/cjs/utils.d.cts +6 -0
- package/dist/esm/config.d.ts +3 -3
- package/dist/esm/config.js +6 -6
- package/dist/esm/config.js.map +1 -1
- package/dist/esm/filesystem/physical/getRouteNodes.d.ts +1 -0
- package/dist/esm/filesystem/physical/getRouteNodes.js +19 -5
- package/dist/esm/filesystem/physical/getRouteNodes.js.map +1 -1
- package/dist/esm/filesystem/virtual/config.js.map +1 -1
- package/dist/esm/filesystem/virtual/getRouteNodes.d.ts +4 -1
- package/dist/esm/filesystem/virtual/getRouteNodes.js +19 -13
- package/dist/esm/filesystem/virtual/getRouteNodes.js.map +1 -1
- package/dist/esm/filesystem/virtual/loadConfigFile.js.map +1 -1
- package/dist/esm/generator.d.ts +11 -9
- package/dist/esm/generator.js +150 -101
- package/dist/esm/generator.js.map +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/logger.js.map +1 -1
- package/dist/esm/plugin/default-generator-plugin.js +16 -10
- package/dist/esm/plugin/default-generator-plugin.js.map +1 -1
- package/dist/esm/template.js.map +1 -1
- package/dist/esm/transform/default-transform-plugin.js +6 -4
- package/dist/esm/transform/default-transform-plugin.js.map +1 -1
- package/dist/esm/transform/transform.d.ts +1 -1
- package/dist/esm/transform/transform.js +48 -32
- package/dist/esm/transform/transform.js.map +1 -1
- package/dist/esm/transform/types.d.ts +1 -1
- package/dist/esm/transform/utils.d.ts +1 -1
- package/dist/esm/transform/utils.js.map +1 -1
- package/dist/esm/types.d.ts +5 -0
- package/dist/esm/utils.d.ts +6 -0
- package/dist/esm/utils.js +43 -24
- package/dist/esm/utils.js.map +1 -1
- package/package.json +5 -5
- package/src/config.ts +6 -5
- package/src/filesystem/physical/getRouteNodes.ts +31 -11
- package/src/filesystem/virtual/getRouteNodes.ts +32 -23
- package/src/generator.ts +196 -72
- package/src/index.ts +2 -0
- package/src/plugin/default-generator-plugin.ts +16 -3
- package/src/transform/default-transform-plugin.ts +5 -2
- package/src/transform/transform.ts +68 -43
- package/src/transform/types.ts +1 -1
- package/src/transform/utils.ts +1 -1
- package/src/types.ts +7 -0
- package/src/utils.ts +79 -31
package/src/config.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import path from 'node:path'
|
|
2
|
-
import {
|
|
3
|
-
import { existsSync, mkdirSync, readFileSync } from 'node:fs'
|
|
2
|
+
import { existsSync, readFileSync } from 'node:fs'
|
|
4
3
|
import { z } from 'zod'
|
|
5
4
|
import { virtualRootRouteSchema } from './filesystem/virtual/config'
|
|
6
5
|
import type { GeneratorPlugin } from './plugin/types'
|
|
@@ -121,11 +120,13 @@ export function getConfig(
|
|
|
121
120
|
}
|
|
122
121
|
}
|
|
123
122
|
|
|
124
|
-
const resolveTmpDir = (dir: string) => {
|
|
123
|
+
const resolveTmpDir = (dir: string | Array<string>) => {
|
|
124
|
+
if (Array.isArray(dir)) {
|
|
125
|
+
dir = path.join(...dir)
|
|
126
|
+
}
|
|
125
127
|
if (!path.isAbsolute(dir)) {
|
|
126
128
|
dir = path.resolve(process.cwd(), dir)
|
|
127
129
|
}
|
|
128
|
-
mkdirSync(dir, { recursive: true })
|
|
129
130
|
return dir
|
|
130
131
|
}
|
|
131
132
|
|
|
@@ -134,7 +135,7 @@ export function getConfig(
|
|
|
134
135
|
} else if (process.env.TSR_TMP_DIR) {
|
|
135
136
|
config.tmpDir = resolveTmpDir(process.env.TSR_TMP_DIR)
|
|
136
137
|
} else {
|
|
137
|
-
config.tmpDir =
|
|
138
|
+
config.tmpDir = resolveTmpDir(['.tanstack', 'tmp'])
|
|
138
139
|
}
|
|
139
140
|
|
|
140
141
|
validateConfig(config)
|
|
@@ -19,6 +19,11 @@ import type { Config } from '../../config'
|
|
|
19
19
|
|
|
20
20
|
const disallowedRouteGroupConfiguration = /\(([^)]+)\).(ts|js|tsx|jsx)/
|
|
21
21
|
|
|
22
|
+
const virtualConfigFileRegExp = /__virtual\.[mc]?[jt]s$/
|
|
23
|
+
export function isVirtualConfigFile(fileName: string): boolean {
|
|
24
|
+
return virtualConfigFileRegExp.test(fileName)
|
|
25
|
+
}
|
|
26
|
+
|
|
22
27
|
export async function getRouteNodes(
|
|
23
28
|
config: Pick<
|
|
24
29
|
Config,
|
|
@@ -34,10 +39,12 @@ export async function getRouteNodes(
|
|
|
34
39
|
): Promise<GetRouteNodesResult> {
|
|
35
40
|
const { routeFilePrefix, routeFileIgnorePrefix, routeFileIgnorePattern } =
|
|
36
41
|
config
|
|
42
|
+
|
|
37
43
|
const logger = logging({ disabled: config.disableLogging })
|
|
38
44
|
const routeFileIgnoreRegExp = new RegExp(routeFileIgnorePattern ?? '', 'g')
|
|
39
45
|
|
|
40
46
|
const routeNodes: Array<RouteNode> = []
|
|
47
|
+
const allPhysicalDirectories: Array<string> = []
|
|
41
48
|
|
|
42
49
|
async function recurse(dir: string) {
|
|
43
50
|
const fullDir = path.resolve(config.routesDirectory, dir)
|
|
@@ -52,6 +59,13 @@ export async function getRouteNodes(
|
|
|
52
59
|
}
|
|
53
60
|
|
|
54
61
|
if (routeFilePrefix) {
|
|
62
|
+
if (routeFileIgnorePattern) {
|
|
63
|
+
return (
|
|
64
|
+
d.name.startsWith(routeFilePrefix) &&
|
|
65
|
+
!d.name.match(routeFileIgnoreRegExp)
|
|
66
|
+
)
|
|
67
|
+
}
|
|
68
|
+
|
|
55
69
|
return d.name.startsWith(routeFilePrefix)
|
|
56
70
|
}
|
|
57
71
|
|
|
@@ -63,7 +77,7 @@ export async function getRouteNodes(
|
|
|
63
77
|
})
|
|
64
78
|
|
|
65
79
|
const virtualConfigFile = dirList.find((dirent) => {
|
|
66
|
-
return dirent.isFile() && dirent.name
|
|
80
|
+
return dirent.isFile() && isVirtualConfigFile(dirent.name)
|
|
67
81
|
})
|
|
68
82
|
|
|
69
83
|
if (virtualConfigFile !== undefined) {
|
|
@@ -81,14 +95,16 @@ export async function getRouteNodes(
|
|
|
81
95
|
file: '',
|
|
82
96
|
children: virtualRouteSubtreeConfig,
|
|
83
97
|
}
|
|
84
|
-
const { routeNodes: virtualRouteNodes } =
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
98
|
+
const { routeNodes: virtualRouteNodes, physicalDirectories } =
|
|
99
|
+
await getRouteNodesVirtual(
|
|
100
|
+
{
|
|
101
|
+
...config,
|
|
102
|
+
routesDirectory: fullDir,
|
|
103
|
+
virtualRouteConfig: dummyRoot,
|
|
104
|
+
},
|
|
105
|
+
root,
|
|
106
|
+
)
|
|
107
|
+
allPhysicalDirectories.push(...physicalDirectories)
|
|
92
108
|
virtualRouteNodes.forEach((node) => {
|
|
93
109
|
const filePath = replaceBackslash(path.join(dir, node.filePath))
|
|
94
110
|
const routePath = `/${dir}${node.routePath}`
|
|
@@ -107,7 +123,7 @@ export async function getRouteNodes(
|
|
|
107
123
|
|
|
108
124
|
await Promise.all(
|
|
109
125
|
dirList.map(async (dirent) => {
|
|
110
|
-
const fullPath = path.
|
|
126
|
+
const fullPath = replaceBackslash(path.join(fullDir, dirent.name))
|
|
111
127
|
const relativePath = path.posix.join(dir, dirent.name)
|
|
112
128
|
|
|
113
129
|
if (dirent.isDirectory()) {
|
|
@@ -192,7 +208,11 @@ export async function getRouteNodes(
|
|
|
192
208
|
rootRouteNode.variableName = 'root'
|
|
193
209
|
}
|
|
194
210
|
|
|
195
|
-
return {
|
|
211
|
+
return {
|
|
212
|
+
rootRouteNode,
|
|
213
|
+
routeNodes,
|
|
214
|
+
physicalDirectories: allPhysicalDirectories,
|
|
215
|
+
}
|
|
196
216
|
}
|
|
197
217
|
|
|
198
218
|
/**
|
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
removeExt,
|
|
4
4
|
removeLeadingSlash,
|
|
5
5
|
removeTrailingSlash,
|
|
6
|
+
replaceBackslash,
|
|
6
7
|
routePathToVariable,
|
|
7
8
|
} from '../../utils'
|
|
8
9
|
import { getRouteNodes as getRouteNodesPhysical } from '../physical/getRouteNodes'
|
|
@@ -53,7 +54,6 @@ export async function getRouteNodes(
|
|
|
53
54
|
throw new Error(`virtualRouteConfig is undefined`)
|
|
54
55
|
}
|
|
55
56
|
let virtualRouteConfig: VirtualRootRoute
|
|
56
|
-
let children: Array<RouteNode> = []
|
|
57
57
|
if (typeof tsrConfig.virtualRouteConfig === 'string') {
|
|
58
58
|
virtualRouteConfig = await getVirtualRouteConfigFromFileExport(
|
|
59
59
|
tsrConfig,
|
|
@@ -62,7 +62,7 @@ export async function getRouteNodes(
|
|
|
62
62
|
} else {
|
|
63
63
|
virtualRouteConfig = tsrConfig.virtualRouteConfig
|
|
64
64
|
}
|
|
65
|
-
children = await getRouteNodesRecursive(
|
|
65
|
+
const { children, physicalDirectories } = await getRouteNodesRecursive(
|
|
66
66
|
tsrConfig,
|
|
67
67
|
root,
|
|
68
68
|
fullDir,
|
|
@@ -71,7 +71,7 @@ export async function getRouteNodes(
|
|
|
71
71
|
const allNodes = flattenTree({
|
|
72
72
|
children,
|
|
73
73
|
filePath: virtualRouteConfig.file,
|
|
74
|
-
fullPath: join(fullDir, virtualRouteConfig.file),
|
|
74
|
+
fullPath: replaceBackslash(join(fullDir, virtualRouteConfig.file)),
|
|
75
75
|
variableName: 'root',
|
|
76
76
|
routePath: `/${rootPathId}`,
|
|
77
77
|
_fsRouteType: '__root',
|
|
@@ -80,7 +80,7 @@ export async function getRouteNodes(
|
|
|
80
80
|
const rootRouteNode = allNodes[0]
|
|
81
81
|
const routeNodes = allNodes.slice(1)
|
|
82
82
|
|
|
83
|
-
return { rootRouteNode, routeNodes }
|
|
83
|
+
return { rootRouteNode, routeNodes, physicalDirectories }
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
/**
|
|
@@ -135,20 +135,22 @@ export async function getRouteNodesRecursive(
|
|
|
135
135
|
fullDir: string,
|
|
136
136
|
nodes?: Array<VirtualRouteNode>,
|
|
137
137
|
parent?: RouteNode,
|
|
138
|
-
): Promise<Array<RouteNode
|
|
138
|
+
): Promise<{ children: Array<RouteNode>; physicalDirectories: Array<string> }> {
|
|
139
139
|
if (nodes === undefined) {
|
|
140
|
-
return []
|
|
140
|
+
return { children: [], physicalDirectories: [] }
|
|
141
141
|
}
|
|
142
|
+
const allPhysicalDirectories: Array<string> = []
|
|
142
143
|
const children = await Promise.all(
|
|
143
144
|
nodes.map(async (node) => {
|
|
144
145
|
if (node.type === 'physical') {
|
|
145
|
-
const { routeNodes } = await getRouteNodesPhysical(
|
|
146
|
+
const { routeNodes, physicalDirectories } = await getRouteNodesPhysical(
|
|
146
147
|
{
|
|
147
148
|
...tsrConfig,
|
|
148
149
|
routesDirectory: resolve(fullDir, node.directory),
|
|
149
150
|
},
|
|
150
151
|
root,
|
|
151
152
|
)
|
|
153
|
+
allPhysicalDirectories.push(node.directory)
|
|
152
154
|
routeNodes.forEach((subtreeNode) => {
|
|
153
155
|
subtreeNode.variableName = routePathToVariable(
|
|
154
156
|
`${node.pathPrefix}/${removeExt(subtreeNode.filePath)}`,
|
|
@@ -162,7 +164,7 @@ export async function getRouteNodesRecursive(
|
|
|
162
164
|
function getFile(file: string) {
|
|
163
165
|
const filePath = file
|
|
164
166
|
const variableName = routePathToVariable(removeExt(filePath))
|
|
165
|
-
const fullPath = join(fullDir, filePath)
|
|
167
|
+
const fullPath = replaceBackslash(join(fullDir, filePath))
|
|
166
168
|
return { filePath, variableName, fullPath }
|
|
167
169
|
}
|
|
168
170
|
const parentRoutePath = removeTrailingSlash(parent?.routePath ?? '/')
|
|
@@ -206,14 +208,16 @@ export async function getRouteNodesRecursive(
|
|
|
206
208
|
}
|
|
207
209
|
|
|
208
210
|
if (node.children !== undefined) {
|
|
209
|
-
const children
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
211
|
+
const { children, physicalDirectories } =
|
|
212
|
+
await getRouteNodesRecursive(
|
|
213
|
+
tsrConfig,
|
|
214
|
+
root,
|
|
215
|
+
fullDir,
|
|
216
|
+
node.children,
|
|
217
|
+
routeNode,
|
|
218
|
+
)
|
|
216
219
|
routeNode.children = children
|
|
220
|
+
allPhysicalDirectories.push(...physicalDirectories)
|
|
217
221
|
|
|
218
222
|
// If the route has children, it should be a layout
|
|
219
223
|
routeNode._fsRouteType = 'layout'
|
|
@@ -242,19 +246,24 @@ export async function getRouteNodesRecursive(
|
|
|
242
246
|
}
|
|
243
247
|
|
|
244
248
|
if (node.children !== undefined) {
|
|
245
|
-
const children
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
249
|
+
const { children, physicalDirectories } =
|
|
250
|
+
await getRouteNodesRecursive(
|
|
251
|
+
tsrConfig,
|
|
252
|
+
root,
|
|
253
|
+
fullDir,
|
|
254
|
+
node.children,
|
|
255
|
+
routeNode,
|
|
256
|
+
)
|
|
252
257
|
routeNode.children = children
|
|
258
|
+
allPhysicalDirectories.push(...physicalDirectories)
|
|
253
259
|
}
|
|
254
260
|
return routeNode
|
|
255
261
|
}
|
|
256
262
|
}
|
|
257
263
|
}),
|
|
258
264
|
)
|
|
259
|
-
return
|
|
265
|
+
return {
|
|
266
|
+
children: children.flat(),
|
|
267
|
+
physicalDirectories: allPhysicalDirectories,
|
|
268
|
+
}
|
|
260
269
|
}
|