Skip to content

Commit bf0fc9b

Browse files
committed
fix: deterministic param parser types order
1 parent 2150ce0 commit bf0fc9b

2 files changed

Lines changed: 16 additions & 12 deletions

File tree

packages/router/src/unplugin/codegen/generateParamParsers.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,8 @@ describe('generateParamParsersTypesDeclarations', () => {
230230

231231
const result = generateParamParsersTypesDeclarations(paramParsers)
232232
expect(result).toMatchInlineSnapshot(`
233-
"type Param_uuid = _ExtractParamParserType<typeof import('./parsers/uuid').parser>
234-
type Param_slug = _ExtractParamParserType<typeof import('./parsers/slug').parser>"
233+
"type Param_slug = _ExtractParamParserType<typeof import('./parsers/slug').parser>
234+
type Param_uuid = _ExtractParamParserType<typeof import('./parsers/uuid').parser>"
235235
`)
236236
})
237237
})
@@ -667,8 +667,8 @@ describe('generateParamParserCustomType', () => {
667667

668668
expect(generateParamParsersTypesDeclarations(paramParsers))
669669
.toMatchInlineSnapshot(`
670-
"type Param_userId = _ExtractParamParserType<typeof import('./parsers/user-id').parser>
671-
type Param_dateWithDashes = _ExtractParamParserType<typeof import('./parsers/date-with-dashes').parser>"
670+
"type Param_dateWithDashes = _ExtractParamParserType<typeof import('./parsers/date-with-dashes').parser>
671+
type Param_userId = _ExtractParamParserType<typeof import('./parsers/user-id').parser>"
672672
`)
673673

674674
const param: TreePathParam = {

packages/router/src/unplugin/codegen/generateParamParsers.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,18 @@ export function collectMissingParamParsers(
9090
export function generateParamParsersTypesDeclarations(
9191
paramParsers: ParamParsersMap
9292
) {
93-
return Array.from(paramParsers.values())
94-
.map(({ typeName, relativePath }) => {
95-
const importPath = relativePath.startsWith('.')
96-
? relativePath
97-
: './' + relativePath
98-
return `type ${typeName} = _ExtractParamParserType<typeof import('${importPath}').parser>`
99-
})
100-
.join('\n')
93+
return (
94+
Array.from(paramParsers.values())
95+
.map(({ typeName, relativePath }) => {
96+
const importPath = relativePath.startsWith('.')
97+
? relativePath
98+
: './' + relativePath
99+
return `type ${typeName} = _ExtractParamParserType<typeof import('${importPath}').parser>`
100+
})
101+
// ensure deterministic order for testing, readability and git
102+
.sort()
103+
.join('\n')
104+
)
101105
}
102106

103107
export function generateParamsTypes(

0 commit comments

Comments
 (0)