@@ -2,8 +2,8 @@ import { basename, extname, normalize, relative, resolve } from 'pathe'
22import { encodePath } from 'ufo'
33import { NuxtMiddleware , NuxtPage } from '@nuxt/schema'
44import { resolveFiles , useNuxt } from '@nuxt/kit'
5- import { kebabCase , pascalCase } from 'scule'
6- import { genImport , genDynamicImport , genArrayFromRaw } from 'knitwork'
5+ import { kebabCase } from 'scule'
6+ import { genImport , genDynamicImport , genArrayFromRaw , genSafeVariableName } from 'knitwork'
77import escapeRE from 'escape-string-regexp'
88
99enum SegmentParserState {
@@ -88,15 +88,11 @@ export function generateRoutesFromFiles (files: string[], pagesDir: string): Nux
8888 }
8989
9090 parent . push ( route )
91- // TODO: https://github.com/vuejs/router/issues/1435
92- parent . sort ( ( a , b ) => getSortablePath ( a . path ) . localeCompare ( getSortablePath ( b . path ) ) )
9391 }
9492
9593 return prepareRoutes ( routes )
9694}
9795
98- const getSortablePath = ( path : string ) => path . replace ( / ^ \/ / , '' ) . replace ( / : / , 'Z' )
99-
10096function getRoutePath ( tokens : SegmentToken [ ] ) : string {
10197 return tokens . reduce ( ( path , token ) => {
10298 return (
@@ -233,7 +229,7 @@ export function normalizeRoutes (routes: NuxtPage[], metaImports: Set<string> =
233229 imports : metaImports ,
234230 routes : genArrayFromRaw ( routes . map ( ( route ) => {
235231 const file = normalize ( route . file )
236- const metaImportName = getImportName ( file ) + 'Meta'
232+ const metaImportName = genSafeVariableName ( file ) + 'Meta'
237233 metaImports . add ( genImport ( `${ file } ?macro=true` , [ { name : 'meta' , as : metaImportName } ] ) )
238234 return {
239235 ...Object . fromEntries ( Object . entries ( route ) . map ( ( [ key , value ] ) => [ key , JSON . stringify ( value ) ] ) ) ,
@@ -271,10 +267,6 @@ function hasSuffix (path: string, suffix: string) {
271267 return basename ( path ) . replace ( extname ( path ) , '' ) . endsWith ( suffix )
272268}
273269
274- export function getImportName ( name : string ) {
275- return pascalCase ( name ) . replace ( / [ ^ \w ] / g, r => '_' + r . charCodeAt ( 0 ) )
276- }
277-
278270function uniqueBy < T , K extends keyof T > ( arr : T [ ] , key : K ) {
279271 const res : T [ ] = [ ]
280272 const seen = new Set < T [ K ] > ( )
0 commit comments