@@ -6,13 +6,18 @@ import { posixify, rimraf, walk } from '../../../utils/filesystem.js';
66import { compact } from '../../../utils/array.js' ;
77import { ts } from '../ts.js' ;
88import { s } from '../../../utils/misc.js' ;
9+ import { get_route_segments } from '../../../utils/routing.js' ;
910
1011const remove_relative_parent_traversals = ( /** @type {string } */ path ) =>
1112 path . replace ( / \. \. \/ / g, '' ) ;
1213const replace_optional_params = ( /** @type {string } */ id ) =>
1314 id . replace ( / \/ \[ \[ [ ^ \] ] + \] \] / g, '${string}' ) ;
1415const replace_required_params = ( /** @type {string } */ id ) =>
1516 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+ } ;
1621const is_whitespace = ( /** @type {string } */ char ) => / \s / . test ( char ) ;
1722
1823/**
@@ -60,8 +65,8 @@ export function write_all_types(config, manifest_data) {
6065 }
6166 }
6267
63- /** @type {string[] } */
64- const pathnames = [ ] ;
68+ /** @type {Set< string> } */
69+ const pathnames = new Set ( ) ;
6570
6671 /** @type {string[] } */
6772 const dynamic_routes = [ ] ;
@@ -76,9 +81,11 @@ export function write_all_types(config, manifest_data) {
7681
7782 dynamic_routes . push ( route_type ) ;
7883
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 ) ) } \` & {}` ) ;
8086 } else {
81- pathnames . push ( s ( route . id ) ) ;
87+ const pathname = remove_group_segments ( route . id ) ;
88+ pathnames . add ( s ( pathname ) ) ;
8289 }
8390
8491 /** @type {Map<string, boolean> } */
@@ -113,7 +120,7 @@ export function write_all_types(config, manifest_data) {
113120 `export type RouteId = ${ manifest_data . routes . map ( ( r ) => s ( r . id ) ) . join ( ' | ' ) } ;` ,
114121 'export type RouteParams<T extends RouteId> = T extends keyof DynamicRoutes ? DynamicRoutes[T] : Record<string, never>;' ,
115122 '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 ( ' | ' ) } ;` ,
117124 'export type ResolvedPathname = `${"" | `/${string}`}${Pathname}`;' ,
118125 `export type Asset = ${ manifest_data . assets . map ( ( asset ) => s ( '/' + asset . file ) ) . join ( ' | ' ) || 'never' } ;`
119126 ] . join ( '\n\n' )
0 commit comments