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
This commit is contained in:
parent
ea1998f862
commit
529b2b4942
|
|
@ -1,4 +1,5 @@
|
||||||
import path from 'node:path'
|
import path from 'node:path'
|
||||||
|
import { existsSync } from 'node:fs'
|
||||||
import { cosmiconfig } from 'cosmiconfig'
|
import { cosmiconfig } from 'cosmiconfig'
|
||||||
import { loadConfig } from 'tsconfig-paths'
|
import { loadConfig } from 'tsconfig-paths'
|
||||||
import * as z from 'zod'
|
import * as z from 'zod'
|
||||||
|
|
@ -62,16 +63,18 @@ export async function getConfig(cwd: string) {
|
||||||
|
|
||||||
export async function resolveConfigPaths(cwd: string, config: RawConfig) {
|
export async function resolveConfigPaths(cwd: string, config: RawConfig) {
|
||||||
const TSCONFIG_PATH = config.framework === 'nuxt' ? '.nuxt/tsconfig.json' : './tsconfig.json'
|
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.
|
// Read tsconfig.json.
|
||||||
const tsconfigPath = path.resolve(cwd, TSCONFIG_PATH)
|
const tsconfigPath = path.resolve(cwd, TSCONFIG_PATH)
|
||||||
let tsConfig = loadConfig(tsconfigPath)
|
let tsConfig = loadConfig(tsconfigPath)
|
||||||
|
|
||||||
// If no paths were found, we load the fallback tsconfig
|
// In new Vue project, tsconfig has references to tsconfig.app.json, which is causing the path not resolving correctly
|
||||||
if ('paths' in tsConfig && Object.keys(tsConfig.paths).length === 0)
|
// If no paths were found, try to load tsconfig.app.json.
|
||||||
tsConfig = loadConfig(path.resolve(cwd, FALLBACK_TSCONFIG_PATH))
|
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') {
|
if (tsConfig.resultType === 'failed') {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user