Skip to content

Commit 5eed2c9

Browse files
committed
fix(start): preserve route path defaults
1 parent cc71fed commit 5eed2c9

5 files changed

Lines changed: 50 additions & 7 deletions

File tree

‎packages/router-core/skills/router-core/search-params/references/validation-patterns.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ const schema = z.object({
7474
.optional(),
7575
}),
7676
{},
77-
).prefault({}),
77+
).default({}),
7878
})
7979
```
8080

‎packages/start-plugin-core/src/rsbuild/schema.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ export function parseStartConfig(
2121
corePluginOpts: { framework: CompileStartFrameworkOptions },
2222
root: string,
2323
) {
24-
const { rsbuild: _rsbuild, ...coreOptions } =
25-
tanstackStartRsbuildOptionsSchema.parse(opts)
24+
tanstackStartRsbuildOptionsSchema.parse(opts)
25+
const { rsbuild: _rsbuild, ...coreOptions } = opts ?? {}
2626

2727
return parseCoreStartConfig(coreOptions, corePluginOpts, root)
2828
}

‎packages/start-plugin-core/src/schema.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,20 +60,22 @@ export function parseStartConfig(
6060
corePluginOpts: { framework: CompileStartFrameworkOptions },
6161
root: string,
6262
) {
63+
const rawOptions = opts ?? {}
64+
const rawRouterOptions = rawOptions.router ?? {}
6365
const options = tanstackStartOptionsSchema.parse(opts)
6466

6567
const srcDirectory = options.srcDirectory
6668

6769
const routesDirectory = path.resolve(
6870
root,
6971
srcDirectory,
70-
options.router.routesDirectory ?? 'routes',
72+
rawRouterOptions.routesDirectory ?? 'routes',
7173
)
7274

7375
const generatedRouteTree = path.resolve(
7476
root,
7577
srcDirectory,
76-
options.router.generatedRouteTree ?? 'routeTree.gen.ts',
78+
rawRouterOptions.generatedRouteTree ?? 'routeTree.gen.ts',
7779
)
7880

7981
return {

‎packages/start-plugin-core/src/vite/schema.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ export function parseStartConfig(
2020
corePluginOpts: { framework: CompileStartFrameworkOptions },
2121
root: string,
2222
) {
23-
const { vite: _vite, ...coreOptions } =
24-
tanstackStartViteOptionsSchema.parse(opts)
23+
tanstackStartViteOptionsSchema.parse(opts)
24+
const { vite: _vite, ...coreOptions } = opts ?? {}
2525

2626
return parseCoreStartConfig(coreOptions, corePluginOpts, root)
2727
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import path from 'node:path'
2+
import { describe, expect, test } from 'vitest'
3+
import { parseStartConfig as parseViteStartConfig } from '../src/vite/schema'
4+
import { parseStartConfig as parseRsbuildStartConfig } from '../src/rsbuild/schema'
5+
6+
const root = process.cwd()
7+
const corePluginOpts = { framework: 'react' as const }
8+
9+
describe('start config schema', () => {
10+
test('uses Start route defaults relative to srcDirectory', () => {
11+
const config = parseViteStartConfig({}, corePluginOpts, root)
12+
13+
expect(config.router.routesDirectory).toBe(
14+
path.resolve(root, 'src', 'routes'),
15+
)
16+
expect(config.router.generatedRouteTree).toBe(
17+
path.resolve(root, 'src', 'routeTree.gen.ts'),
18+
)
19+
})
20+
21+
test('uses router path overrides relative to srcDirectory', () => {
22+
const config = parseRsbuildStartConfig(
23+
{
24+
srcDirectory: 'app',
25+
router: {
26+
routesDirectory: 'pages',
27+
generatedRouteTree: 'routes.gen.ts',
28+
},
29+
},
30+
corePluginOpts,
31+
root,
32+
)
33+
34+
expect(config.router.routesDirectory).toBe(
35+
path.resolve(root, 'app', 'pages'),
36+
)
37+
expect(config.router.generatedRouteTree).toBe(
38+
path.resolve(root, 'app', 'routes.gen.ts'),
39+
)
40+
})
41+
})

0 commit comments

Comments
 (0)