fix(schema): do not override user serverDir (#28249)

This commit is contained in:
Julien Huang 2024-07-23 10:31:39 +02:00 committed by GitHub
parent b327651de3
commit ed54884c20
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 1 deletions

View File

@ -158,7 +158,7 @@ export default defineUntypedSchema({
$resolve: async (val: string | undefined, get): Promise<string> => {
const isV4 = ((await get('future') as Record<string, unknown>).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')
},
},

View File

@ -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": "<cwd>/app",
"modules": "<cwd>/modules",
"public": "<cwd>/public",
},
"rootDir": "<cwd>",
"serverDir": "/myServer",
"srcDir": "<cwd>/app",
"workspaceDir": "<cwd>",
}
`)
})
})
function getDirs (options: NuxtOptions) {