Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/router-generator/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ const tokenMatcherSchema = z.union([
tokenJsonRegexSchema,
])

const stringArrayFactorySchema = z.custom<() => Array<string>>(
(value) => typeof value === 'function',
)

export type TokenMatcherJson = string | z.infer<typeof tokenJsonRegexSchema>

export type TokenMatcher = z.infer<typeof tokenMatcherSchema>
Expand Down Expand Up @@ -61,7 +65,7 @@ export const configSchema = baseConfigSchema.extend({
routeTreeFileFooter: z
.union([
z.array(z.string()).optional().default([]),
z.function().returns(z.array(z.string())),
stringArrayFactorySchema,
])
.optional(),
autoCodeSplitting: z.boolean().optional(),
Expand Down
14 changes: 14 additions & 0 deletions packages/router-generator/tests/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,18 @@ describe('load config tests', () => {
)
},
)

it('accepts routeTreeFileFooter as a function', () => {
const routeTreeFileFooter = () => ['// append']
const resolvedConfig = getConfig({ routeTreeFileFooter })

expect(resolvedConfig.routeTreeFileFooter).toBe(routeTreeFileFooter)
})

it('accepts routeTreeFileFooter as an array', () => {
const routeTreeFileFooter = ['// append']
const resolvedConfig = getConfig({ routeTreeFileFooter })

expect(resolvedConfig.routeTreeFileFooter).toEqual(routeTreeFileFooter)
})
})
Loading