@tanstack/router-generator 1.120.4-alpha.4 → 1.120.5
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 +14 -14
- package/dist/cjs/config.cjs.map +1 -1
- package/dist/cjs/config.d.cts +31 -68
- package/dist/cjs/filesystem/physical/getRouteNodes.cjs +5 -1
- package/dist/cjs/filesystem/physical/getRouteNodes.cjs.map +1 -1
- package/dist/cjs/filesystem/physical/getRouteNodes.d.cts +2 -2
- package/dist/cjs/filesystem/virtual/getRouteNodes.cjs.map +1 -1
- package/dist/cjs/filesystem/virtual/getRouteNodes.d.cts +2 -2
- package/dist/cjs/generator.cjs +172 -160
- package/dist/cjs/generator.cjs.map +1 -1
- package/dist/cjs/generator.d.cts +59 -0
- package/dist/cjs/index.cjs +2 -23
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +4 -8
- package/dist/cjs/template.cjs +12 -4
- package/dist/cjs/template.cjs.map +1 -1
- package/dist/cjs/template.d.cts +1 -0
- package/dist/cjs/types.d.cts +1 -1
- package/dist/cjs/utils.cjs +2 -61
- package/dist/cjs/utils.cjs.map +1 -1
- package/dist/cjs/utils.d.cts +2 -4
- package/dist/esm/config.d.ts +31 -68
- package/dist/esm/config.js +14 -14
- package/dist/esm/config.js.map +1 -1
- package/dist/esm/filesystem/physical/getRouteNodes.d.ts +2 -2
- package/dist/esm/filesystem/physical/getRouteNodes.js +6 -2
- package/dist/esm/filesystem/physical/getRouteNodes.js.map +1 -1
- package/dist/esm/filesystem/virtual/getRouteNodes.d.ts +2 -2
- package/dist/esm/filesystem/virtual/getRouteNodes.js.map +1 -1
- package/dist/esm/generator.d.ts +59 -0
- package/dist/esm/generator.js +175 -163
- package/dist/esm/generator.js.map +1 -1
- package/dist/esm/index.d.ts +4 -8
- package/dist/esm/index.js +4 -25
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/template.d.ts +1 -0
- package/dist/esm/template.js +12 -4
- package/dist/esm/template.js.map +1 -1
- package/dist/esm/types.d.ts +1 -1
- package/dist/esm/utils.d.ts +2 -4
- package/dist/esm/utils.js +2 -61
- package/dist/esm/utils.js.map +1 -1
- package/package.json +3 -3
- package/src/config.ts +11 -14
- package/src/filesystem/physical/getRouteNodes.ts +14 -13
- package/src/filesystem/virtual/getRouteNodes.ts +3 -18
- package/src/generator.ts +221 -242
- package/src/index.ts +7 -32
- package/src/template.ts +15 -4
- package/src/types.ts +1 -0
- package/src/utils.ts +4 -85
package/src/config.ts
CHANGED
|
@@ -3,16 +3,23 @@ import { existsSync, readFileSync } from 'node:fs'
|
|
|
3
3
|
import { z } from 'zod'
|
|
4
4
|
import { virtualRootRouteSchema } from './filesystem/virtual/config'
|
|
5
5
|
|
|
6
|
-
export const
|
|
6
|
+
export const configSchema = z.object({
|
|
7
7
|
target: z.enum(['react', 'solid']).optional().default('react'),
|
|
8
8
|
virtualRouteConfig: virtualRootRouteSchema.or(z.string()).optional(),
|
|
9
9
|
routeFilePrefix: z.string().optional(),
|
|
10
10
|
routeFileIgnorePrefix: z.string().optional().default('-'),
|
|
11
11
|
routeFileIgnorePattern: z.string().optional(),
|
|
12
12
|
routesDirectory: z.string().optional().default('./src/routes'),
|
|
13
|
+
generatedRouteTree: z.string().optional().default('./src/routeTree.gen.ts'),
|
|
13
14
|
quoteStyle: z.enum(['single', 'double']).optional().default('single'),
|
|
14
15
|
semicolons: z.boolean().optional().default(false),
|
|
16
|
+
disableTypes: z.boolean().optional().default(false),
|
|
17
|
+
addExtensions: z.boolean().optional().default(false),
|
|
15
18
|
disableLogging: z.boolean().optional().default(false),
|
|
19
|
+
disableManifestGeneration: z.boolean().optional().default(false),
|
|
20
|
+
enableRouteTreeFormatting: z.boolean().optional().default(true),
|
|
21
|
+
__enableAPIRoutesGeneration: z.boolean().optional(), // Internal flag to be turned on for TanStack Start
|
|
22
|
+
apiBase: z.string().optional().default('/api'),
|
|
16
23
|
routeTreeFileHeader: z
|
|
17
24
|
.array(z.string())
|
|
18
25
|
.optional()
|
|
@@ -21,28 +28,18 @@ export const baseConfigSchema = z.object({
|
|
|
21
28
|
'// @ts-nocheck',
|
|
22
29
|
'// noinspection JSUnusedGlobalSymbols',
|
|
23
30
|
]),
|
|
31
|
+
routeTreeFileFooter: z.array(z.string()).optional().default([]),
|
|
32
|
+
autoCodeSplitting: z.boolean().optional(),
|
|
24
33
|
indexToken: z.string().optional().default('index'),
|
|
25
34
|
routeToken: z.string().optional().default('route'),
|
|
26
35
|
pathParamsAllowedCharacters: z
|
|
27
36
|
.array(z.enum([';', ':', '@', '&', '=', '+', '$', ',']))
|
|
28
37
|
.optional(),
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
export type BaseConfig = z.infer<typeof baseConfigSchema>
|
|
32
|
-
|
|
33
|
-
export const configSchema = baseConfigSchema.extend({
|
|
34
|
-
generatedRouteTree: z.string().optional().default('./src/routeTree.gen.ts'),
|
|
35
|
-
disableTypes: z.boolean().optional().default(false),
|
|
36
|
-
verboseFileRoutes: z.boolean().optional(),
|
|
37
|
-
addExtensions: z.boolean().optional().default(false),
|
|
38
|
-
disableManifestGeneration: z.boolean().optional().default(false),
|
|
39
|
-
enableRouteTreeFormatting: z.boolean().optional().default(true),
|
|
40
|
-
routeTreeFileFooter: z.array(z.string()).optional().default([]),
|
|
41
|
-
autoCodeSplitting: z.boolean().optional(),
|
|
42
38
|
customScaffolding: z
|
|
43
39
|
.object({
|
|
44
40
|
routeTemplate: z.string().optional(),
|
|
45
41
|
lazyRouteTemplate: z.string().optional(),
|
|
42
|
+
apiTemplate: z.string().optional(),
|
|
46
43
|
})
|
|
47
44
|
.optional(),
|
|
48
45
|
experimental: z
|
|
@@ -4,6 +4,8 @@ import {
|
|
|
4
4
|
determineInitialRoutePath,
|
|
5
5
|
logging,
|
|
6
6
|
removeExt,
|
|
7
|
+
removeLeadingSlash,
|
|
8
|
+
removeTrailingSlash,
|
|
7
9
|
replaceBackslash,
|
|
8
10
|
routePathToVariable,
|
|
9
11
|
} from '../../utils'
|
|
@@ -20,16 +22,7 @@ import type { Config } from '../../config'
|
|
|
20
22
|
const disallowedRouteGroupConfiguration = /\(([^)]+)\).(ts|js|tsx|jsx)/
|
|
21
23
|
|
|
22
24
|
export async function getRouteNodes(
|
|
23
|
-
config:
|
|
24
|
-
Config,
|
|
25
|
-
| 'routesDirectory'
|
|
26
|
-
| 'routeFilePrefix'
|
|
27
|
-
| 'routeFileIgnorePrefix'
|
|
28
|
-
| 'routeFileIgnorePattern'
|
|
29
|
-
| 'disableLogging'
|
|
30
|
-
| 'routeToken'
|
|
31
|
-
| 'indexToken'
|
|
32
|
-
>,
|
|
25
|
+
config: Config,
|
|
33
26
|
root: string,
|
|
34
27
|
): Promise<GetRouteNodesResult> {
|
|
35
28
|
const { routeFilePrefix, routeFileIgnorePrefix, routeFileIgnorePattern } =
|
|
@@ -203,7 +196,7 @@ export async function getRouteNodes(
|
|
|
203
196
|
*/
|
|
204
197
|
export function getRouteMeta(
|
|
205
198
|
routePath: string,
|
|
206
|
-
config:
|
|
199
|
+
config: Config,
|
|
207
200
|
): {
|
|
208
201
|
// `__root` is can be more easily determined by filtering down to routePath === /${rootPathId}
|
|
209
202
|
// `pathless` is needs to determined after `lazy` has been cleaned up from the routePath
|
|
@@ -222,7 +215,15 @@ export function getRouteMeta(
|
|
|
222
215
|
} {
|
|
223
216
|
let fsRouteType: FsRouteType = 'static'
|
|
224
217
|
|
|
225
|
-
if (
|
|
218
|
+
if (
|
|
219
|
+
removeLeadingSlash(routePath).startsWith(
|
|
220
|
+
`${removeTrailingSlash(removeLeadingSlash(config.apiBase))}/`,
|
|
221
|
+
) &&
|
|
222
|
+
config.__enableAPIRoutesGeneration
|
|
223
|
+
) {
|
|
224
|
+
// api routes, i.e. `/api/foo.ts`
|
|
225
|
+
fsRouteType = 'api'
|
|
226
|
+
} else if (routePath.endsWith(`/${config.routeToken}`)) {
|
|
226
227
|
// layout routes, i.e `/foo/route.tsx` or `/foo/_layout/route.tsx`
|
|
227
228
|
fsRouteType = 'layout'
|
|
228
229
|
} else if (routePath.endsWith('/lazy')) {
|
|
@@ -256,7 +257,7 @@ export function getRouteMeta(
|
|
|
256
257
|
function isValidPathlessLayoutRoute(
|
|
257
258
|
normalizedRoutePath: string,
|
|
258
259
|
routeType: FsRouteType,
|
|
259
|
-
config:
|
|
260
|
+
config: Config,
|
|
260
261
|
): boolean {
|
|
261
262
|
if (routeType === 'lazy') {
|
|
262
263
|
return false
|
|
@@ -37,15 +37,7 @@ function flattenTree(node: RouteNode): Array<RouteNode> {
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
export async function getRouteNodes(
|
|
40
|
-
tsrConfig:
|
|
41
|
-
Config,
|
|
42
|
-
| 'routesDirectory'
|
|
43
|
-
| 'virtualRouteConfig'
|
|
44
|
-
| 'routeFileIgnorePrefix'
|
|
45
|
-
| 'disableLogging'
|
|
46
|
-
| 'indexToken'
|
|
47
|
-
| 'routeToken'
|
|
48
|
-
>,
|
|
40
|
+
tsrConfig: Config,
|
|
49
41
|
root: string,
|
|
50
42
|
): Promise<GetRouteNodesResult> {
|
|
51
43
|
const fullDir = resolve(tsrConfig.routesDirectory)
|
|
@@ -98,7 +90,7 @@ export async function getRouteNodes(
|
|
|
98
90
|
*
|
|
99
91
|
*/
|
|
100
92
|
async function getVirtualRouteConfigFromFileExport(
|
|
101
|
-
tsrConfig:
|
|
93
|
+
tsrConfig: Config,
|
|
102
94
|
root: string,
|
|
103
95
|
): Promise<VirtualRootRoute> {
|
|
104
96
|
if (
|
|
@@ -123,14 +115,7 @@ async function getVirtualRouteConfigFromFileExport(
|
|
|
123
115
|
}
|
|
124
116
|
|
|
125
117
|
export async function getRouteNodesRecursive(
|
|
126
|
-
tsrConfig:
|
|
127
|
-
Config,
|
|
128
|
-
| 'routesDirectory'
|
|
129
|
-
| 'routeFileIgnorePrefix'
|
|
130
|
-
| 'disableLogging'
|
|
131
|
-
| 'indexToken'
|
|
132
|
-
| 'routeToken'
|
|
133
|
-
>,
|
|
118
|
+
tsrConfig: Config,
|
|
134
119
|
root: string,
|
|
135
120
|
fullDir: string,
|
|
136
121
|
nodes?: Array<VirtualRouteNode>,
|