From 529b2b4942e054157a177936c80269ceb2668d17 Mon Sep 17 00:00:00 2001 From: Dunqing Date: Sat, 9 Sep 2023 17:21:17 +0800 Subject: [PATCH] fix(cli): break caused by non-existence of `tsconfig.app.json` (#38) * fix(cli): break caused by non-existence of `tsconfig.app.json` * feat: better --- packages/cli/src/utils/get-config.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/cli/src/utils/get-config.ts b/packages/cli/src/utils/get-config.ts index 28d50add..00e10c9c 100644 --- a/packages/cli/src/utils/get-config.ts +++ b/packages/cli/src/utils/get-config.ts @@ -1,4 +1,5 @@ import path from 'node:path' +import { existsSync } from 'node:fs' import { cosmiconfig } from 'cosmiconfig' import { loadConfig } from 'tsconfig-paths' import * as z from 'zod' @@ -62,16 +63,18 @@ export async function getConfig(cwd: string) { export async function resolveConfigPaths(cwd: string, config: RawConfig) { const TSCONFIG_PATH = config.framework === 'nuxt' ? '.nuxt/tsconfig.json' : './tsconfig.json' - // In new Vue project, tsconfig has references to tsconfig.app.json, which is causing the path not resolving correctly - const FALLBACK_TSCONFIG_PATH = './tsconfig.app.json' // Read tsconfig.json. const tsconfigPath = path.resolve(cwd, TSCONFIG_PATH) let tsConfig = loadConfig(tsconfigPath) - // If no paths were found, we load the fallback tsconfig - if ('paths' in tsConfig && Object.keys(tsConfig.paths).length === 0) - tsConfig = loadConfig(path.resolve(cwd, FALLBACK_TSCONFIG_PATH)) + // In new Vue project, tsconfig has references to tsconfig.app.json, which is causing the path not resolving correctly + // If no paths were found, try to load tsconfig.app.json. + if ('paths' in tsConfig && Object.keys(tsConfig.paths).length === 0) { + const FALLBACK_TSCONFIG_PATH = path.resolve(cwd, './tsconfig.app.json') + if (existsSync(FALLBACK_TSCONFIG_PATH)) + tsConfig = loadConfig(FALLBACK_TSCONFIG_PATH) + } if (tsConfig.resultType === 'failed') { throw new Error(