@@ -6,13 +6,18 @@ import { posixify, rimraf, walk } from '../../../utils/filesystem.js';
6
6
import { compact } from '../../../utils/array.js' ;
7
7
import { ts } from '../ts.js' ;
8
8
import { s } from '../../../utils/misc.js' ;
9
+ import { get_route_segments } from '../../../utils/routing.js' ;
9
10
10
11
const remove_relative_parent_traversals = ( /** @type {string } */ path ) =>
11
12
path . replace ( / \. \. \/ / g, '' ) ;
12
13
const replace_optional_params = ( /** @type {string } */ id ) =>
13
14
id . replace ( / \/ \[ \[ [ ^ \] ] + \] \] / g, '${string}' ) ;
14
15
const replace_required_params = ( /** @type {string } */ id ) =>
15
16
id . replace ( / \/ \[ [ ^ \] ] + \] / g, '/${string}' ) ;
17
+ /** Convert route ID to pathname by removing layout groups */
18
+ const remove_group_segments = ( /** @type {string } */ id ) => {
19
+ return '/' + get_route_segments ( id ) . join ( '/' ) ;
20
+ } ;
16
21
const is_whitespace = ( /** @type {string } */ char ) => / \s / . test ( char ) ;
17
22
18
23
/**
@@ -60,8 +65,8 @@ export function write_all_types(config, manifest_data) {
60
65
}
61
66
}
62
67
63
- /** @type {string[] } */
64
- const pathnames = [ ] ;
68
+ /** @type {Set< string> } */
69
+ const pathnames = new Set ( ) ;
65
70
66
71
/** @type {string[] } */
67
72
const dynamic_routes = [ ] ;
@@ -76,9 +81,11 @@ export function write_all_types(config, manifest_data) {
76
81
77
82
dynamic_routes . push ( route_type ) ;
78
83
79
- pathnames . push ( `\`${ replace_required_params ( replace_optional_params ( route . id ) ) } \` & {}` ) ;
84
+ const pathname = remove_group_segments ( route . id ) ;
85
+ pathnames . add ( `\`${ replace_required_params ( replace_optional_params ( pathname ) ) } \` & {}` ) ;
80
86
} else {
81
- pathnames . push ( s ( route . id ) ) ;
87
+ const pathname = remove_group_segments ( route . id ) ;
88
+ pathnames . add ( s ( pathname ) ) ;
82
89
}
83
90
84
91
/** @type {Map<string, boolean> } */
@@ -113,7 +120,7 @@ export function write_all_types(config, manifest_data) {
113
120
`export type RouteId = ${ manifest_data . routes . map ( ( r ) => s ( r . id ) ) . join ( ' | ' ) } ;` ,
114
121
'export type RouteParams<T extends RouteId> = T extends keyof DynamicRoutes ? DynamicRoutes[T] : Record<string, never>;' ,
115
122
'export type LayoutParams<T extends RouteId> = Layouts[T] | Record<string, never>;' ,
116
- `export type Pathname = ${ pathnames . join ( ' | ' ) } ;` ,
123
+ `export type Pathname = ${ Array . from ( pathnames ) . join ( ' | ' ) } ;` ,
117
124
'export type ResolvedPathname = `${"" | `/${string}`}${Pathname}`;' ,
118
125
`export type Asset = ${ manifest_data . assets . map ( ( asset ) => s ( '/' + asset . file ) ) . join ( ' | ' ) || 'never' } ;`
119
126
] . join ( '\n\n' )
0 commit comments