fix(nuxi): don't strip file extensions from dirs in tsconfig (#4595)

This commit is contained in:
Daniel Roe 2022-04-25 18:07:01 +01:00 committed by GitHub
parent b8d2e64c78
commit 2d202b59e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -43,18 +43,17 @@ export const writeTypes = async (nuxt: Nuxt) => {
if (excludedAlias.some(re => re.test(alias))) { if (excludedAlias.some(re => re.test(alias))) {
continue continue
} }
const path = aliases[alias].replace(/(?<=\w)\.\w+$/g, '') /* remove extension */ const relativePath = isAbsolute(aliases[alias])
const relativePath = isAbsolute(path) ? relative(nuxt.options.rootDir, aliases[alias]) || '.'
? relative(nuxt.options.rootDir, path) || '.' : aliases[alias]
: path
tsConfig.compilerOptions.paths[alias] = [relativePath]
try { const stats = await fsp.stat(resolve(nuxt.options.rootDir, relativePath)).catch(() => null /* file does not exist */)
const { isDirectory } = await fsp.stat(resolve(nuxt.options.rootDir, relativePath)) if (stats?.isDirectory()) {
if (isDirectory) { tsConfig.compilerOptions.paths[alias] = [relativePath]
tsConfig.compilerOptions.paths[`${alias}/*`] = [`${relativePath}/*`] tsConfig.compilerOptions.paths[`${alias}/*`] = [`${relativePath}/*`]
} else {
tsConfig.compilerOptions.paths[alias] = [relativePath.replace(/(?<=\w)\.\w+$/g, '')] /* remove extension */
} }
} catch { }
} }
const references: TSReference[] = [ const references: TSReference[] = [