From bbd6e47b92d453dd2aaee292e7dfb9b82a4b5592 Mon Sep 17 00:00:00 2001 From: Nico Lynzaad Date: Tue, 25 Nov 2025 19:35:09 +0200 Subject: [PATCH 1/2] do not overwrite resolved config with unprocessed inline input --- packages/router-plugin/src/core/config.ts | 2 +- packages/router-plugin/tests/config.test.ts | 112 ++++++++++++++++++ .../tests/config/withJson/tsr.config.json | 6 + 3 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 packages/router-plugin/tests/config.test.ts create mode 100644 packages/router-plugin/tests/config/withJson/tsr.config.json diff --git a/packages/router-plugin/src/core/config.ts b/packages/router-plugin/src/core/config.ts index d776c7cd5b2..f93166d3929 100644 --- a/packages/router-plugin/src/core/config.ts +++ b/packages/router-plugin/src/core/config.ts @@ -105,7 +105,7 @@ export const configSchema = generatorConfigSchema.extend({ export const getConfig = (inlineConfig: Partial, root: string) => { const config = getGeneratorConfig(inlineConfig, root) - return configSchema.parse({ ...config, ...inlineConfig }) + return configSchema.parse({ ...inlineConfig, ...config }) } export type Config = z.infer diff --git a/packages/router-plugin/tests/config.test.ts b/packages/router-plugin/tests/config.test.ts new file mode 100644 index 00000000000..2f3e8cc7db9 --- /dev/null +++ b/packages/router-plugin/tests/config.test.ts @@ -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, + 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, + 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, + 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, + withJson: false, + }, + { + name: 'json config', + inlineConfig: {} as Partial, + 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, + 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, + }), + ) + }) +}) diff --git a/packages/router-plugin/tests/config/withJson/tsr.config.json b/packages/router-plugin/tests/config/withJson/tsr.config.json new file mode 100644 index 00000000000..aa5a4f0c02f --- /dev/null +++ b/packages/router-plugin/tests/config/withJson/tsr.config.json @@ -0,0 +1,6 @@ +{ + "routesDirectory": "./src/routes", + "generatedRouteTree": "./src/routeTree.gen.ts", + "target": "solid", + "autoCodeSplitting": false +} From 1319827e69bc58e6983cde337fddee1428d82706 Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Tue, 25 Nov 2025 17:41:51 +0000 Subject: [PATCH 2/2] ci: apply automated fixes --- packages/router-plugin/tests/config/withJson/tsr.config.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/router-plugin/tests/config/withJson/tsr.config.json b/packages/router-plugin/tests/config/withJson/tsr.config.json index aa5a4f0c02f..367f00064c1 100644 --- a/packages/router-plugin/tests/config/withJson/tsr.config.json +++ b/packages/router-plugin/tests/config/withJson/tsr.config.json @@ -1,6 +1,6 @@ { "routesDirectory": "./src/routes", "generatedRouteTree": "./src/routeTree.gen.ts", - "target": "solid", - "autoCodeSplitting": false + "target": "solid", + "autoCodeSplitting": false }