From 9ac4da0616f77889c14a47491ec9ba996fc08bde Mon Sep 17 00:00:00 2001 From: Julien Huang Date: Tue, 23 Jul 2024 10:31:39 +0200 Subject: [PATCH] fix(schema): do not override user `serverDir` (#28249) --- packages/schema/src/config/common.ts | 2 +- packages/schema/test/folder-structure.spec.ts | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/packages/schema/src/config/common.ts b/packages/schema/src/config/common.ts index 3688ca662b..05ab786d49 100644 --- a/packages/schema/src/config/common.ts +++ b/packages/schema/src/config/common.ts @@ -158,7 +158,7 @@ export default defineUntypedSchema({ $resolve: async (val: string | undefined, get): Promise => { const isV4 = ((await get('future') as Record).compatibilityVersion === 4) - return resolve(await get('rootDir') as string, (val || isV4) ? 'server' : resolve(await get('srcDir') as string, 'server')) + return resolve(isV4 ? await get('rootDir') as string : await get('srcDir') as string, val ?? 'server') }, }, diff --git a/packages/schema/test/folder-structure.spec.ts b/packages/schema/test/folder-structure.spec.ts index 36e4e89745..ce1fe491f3 100644 --- a/packages/schema/test/folder-structure.spec.ts +++ b/packages/schema/test/folder-structure.spec.ts @@ -77,6 +77,23 @@ describe('nuxt folder structure', () => { } `) }) + + it('should not override value from user for serverDir', async () => { + const result = await applyDefaults(NuxtConfigSchema, { future: { compatibilityVersion: 4 }, serverDir: '/myServer' }) + expect(getDirs(result as unknown as NuxtOptions)).toMatchInlineSnapshot(` + { + "dir": { + "app": "/app", + "modules": "/modules", + "public": "/public", + }, + "rootDir": "", + "serverDir": "/myServer", + "srcDir": "/app", + "workspaceDir": "", + } + `) + }) }) function getDirs (options: NuxtOptions) {