@tanstack/router-generator 1.120.5 → 1.121.0-alpha.3

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