fix(cli): shouldn't load tsconfig when typescript disabled

This commit is contained in:
Dunqing 2023-09-10 18:29:43 +08:00
parent 686ac00cab
commit 4c61fd6b96

View File

@ -1,6 +1,7 @@
import path from 'node:path'
import { existsSync } from 'node:fs'
import { cosmiconfig } from 'cosmiconfig'
import type { ConfigLoaderResult } from 'tsconfig-paths'
import { loadConfig } from 'tsconfig-paths'
import * as z from 'zod'
import { resolveImport } from '@/src/utils/resolve-import'
@ -62,11 +63,13 @@ export async function getConfig(cwd: string) {
}
export async function resolveConfigPaths(cwd: string, config: RawConfig) {
let tsConfig: ConfigLoaderResult | undefined
if (config.typescript) {
const TSCONFIG_PATH = config.framework === 'nuxt' ? '.nuxt/tsconfig.json' : './tsconfig.json'
// Read tsconfig.json.
const tsconfigPath = path.resolve(cwd, TSCONFIG_PATH)
let tsConfig = loadConfig(tsconfigPath)
tsConfig = loadConfig(tsconfigPath)
// 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.
@ -81,14 +84,15 @@ export async function resolveConfigPaths(cwd: string, config: RawConfig) {
`Failed to load tsconfig.json. ${tsConfig.message ?? ''}`.trim(),
)
}
}
return configSchema.parse({
...config,
resolvedPaths: {
tailwindConfig: path.resolve(cwd, config.tailwind.config),
tailwindCss: path.resolve(cwd, config.tailwind.css),
utils: await resolveImport(config.aliases.utils, tsConfig),
components: await resolveImport(config.aliases.components, tsConfig),
utils: tsConfig ? await resolveImport(config.aliases.utils, tsConfig) : config.aliases.utils,
components: tsConfig ? await resolveImport(config.aliases.components, tsConfig) : config.aliases.components,
},
})
}