From 2d85d6a978a5ca8afc6a2b863ca9e9b848ceb7d5 Mon Sep 17 00:00:00 2001 From: Julien Huang Date: Mon, 26 Aug 2024 15:14:24 +0200 Subject: [PATCH] fix(schema): resolve user-provided `serverDir` relative to root (#28700) --- packages/schema/src/config/common.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/schema/src/config/common.ts b/packages/schema/src/config/common.ts index ad8e5f20b0..d28ea61d2e 100644 --- a/packages/schema/src/config/common.ts +++ b/packages/schema/src/config/common.ts @@ -1,7 +1,7 @@ import { existsSync } from 'node:fs' import { readdir } from 'node:fs/promises' import { defineUntypedSchema } from 'untyped' -import { basename, relative, resolve } from 'pathe' +import { basename, join, relative, resolve } from 'pathe' import { isDebug, isDevelopment, isTest } from 'std-env' import { defu } from 'defu' import { findWorkspaceDir } from 'pkg-types' @@ -156,9 +156,12 @@ export default defineUntypedSchema({ */ serverDir: { $resolve: async (val: string | undefined, get): Promise => { - const isV4 = ((await get('future') as Record).compatibilityVersion === 4) - - return resolve(isV4 ? await get('rootDir') as string : await get('srcDir') as string, val ?? 'server') + if (val) { + const rootDir = await get('rootDir') as string + return resolve(rootDir, val) + } + const isV4 = (await get('future') as Record).compatibilityVersion === 4 + return join(isV4 ? await get('rootDir') as string : await get('srcDir') as string, 'server') }, },