Skip to content
Merged
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
2 changes: 1 addition & 1 deletion packages/router-plugin/src/core/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export const configSchema = generatorConfigSchema.extend({
export const getConfig = (inlineConfig: Partial<Config>, root: string) => {
const config = getGeneratorConfig(inlineConfig, root)

return configSchema.parse({ ...config, ...inlineConfig })
return configSchema.parse({ ...inlineConfig, ...config })
}

export type Config = z.infer<typeof configSchema>
Expand Down
112 changes: 112 additions & 0 deletions packages/router-plugin/tests/config.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import path from 'node:path'
import { readFileSync } from 'node:fs'
import { describe, expect, it } from 'vitest'
import { getConfig } from '../src'
import type { Config } from '../src'

describe('getConfig', () => {
const testCases = [
{
name: 'inline config',
inlineConfig: {
target: 'solid',
autoCodeSplitting: false,
enableRouteGeneration: true,
} as Partial<Config>,
withJson: false,
},
{
name: `inline config and relative paths`,
inlineConfig: {
target: 'solid',
autoCodeSplitting: false,
routesDirectory: 'src/paths',
generatedRouteTree: 'src/tree/routeTree.gen.ts',
enableRouteGeneration: true,
} as Partial<Config>,
withJson: false,
},
{
name: `inline config and "./" form relative paths`,
inlineConfig: {
target: 'solid',
autoCodeSplitting: true,
routesDirectory: './src/paths',
generatedRouteTree: './src/tree/routeTree.gen.ts',
enableRouteGeneration: true,
} as Partial<Config>,
withJson: false,
},
{
name: 'inline config and absolute paths',
inlineConfig: {
target: 'solid',
autoCodeSplitting: false,
routesDirectory: '/src/paths',
generatedRouteTree: '/src/tree/routeTree.gen.ts',
enableRouteGeneration: true,
} as Partial<Config>,
withJson: false,
},
{
name: 'json config',
inlineConfig: {} as Partial<Config>,
withJson: true,
},
{
name: 'combination of json and inline config',
inlineConfig: {
target: 'react',
autoCodeSplitting: true,
routesDirectory: './src/paths',
generatedRouteTree: './src/tree/routeTree.gen.ts',
enableRouteGeneration: true,
} as Partial<Config>,
withJson: true,
},
]

it.each(testCases)('must resolve $name', ({ inlineConfig, withJson }) => {
const rootPath = withJson ? 'withJson' : 'withoutJson'
const root = path.resolve(import.meta.dirname, 'config', rootPath)

const jsonConfig = withJson
? JSON.parse(readFileSync(path.resolve(root, 'tsr.config.json'), 'utf-8'))
: undefined

const routesPath =
inlineConfig.routesDirectory ??
jsonConfig?.routesDirectory ??
'src/routes'

const routeTreePath =
inlineConfig.generatedRouteTree ??
jsonConfig?.generatedRouteTree ??
'src/routeTree.gen.ts'

const routesDirectory = path.resolve(
import.meta.dirname,
'config',
rootPath,
routesPath,
)

const generatedRouteTree = path.resolve(
import.meta.dirname,
'config',
rootPath,
routeTreePath,
)

const resolvedConfig = getConfig(inlineConfig, root)

expect(resolvedConfig).toEqual(
expect.objectContaining({
...jsonConfig,
...inlineConfig,
routesDirectory,
generatedRouteTree,
}),
)
})
})
6 changes: 6 additions & 0 deletions packages/router-plugin/tests/config/withJson/tsr.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"routesDirectory": "./src/routes",
"generatedRouteTree": "./src/routeTree.gen.ts",
"target": "solid",
"autoCodeSplitting": false
}
Loading