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))) {
continue
}
const path = aliases[alias].replace(/(?<=\w)\.\w+$/g, '') /* remove extension */
const relativePath = isAbsolute(path)
? relative(nuxt.options.rootDir, path) || '.'
: path
tsConfig.compilerOptions.paths[alias] = [relativePath]
const relativePath = isAbsolute(aliases[alias])
? relative(nuxt.options.rootDir, aliases[alias]) || '.'
: aliases[alias]
try {
const { isDirectory } = await fsp.stat(resolve(nuxt.options.rootDir, relativePath))
if (isDirectory) {
tsConfig.compilerOptions.paths[`${alias}/*`] = [`${relativePath}/*`]
}
} catch { }
const stats = await fsp.stat(resolve(nuxt.options.rootDir, relativePath)).catch(() => null /* file does not exist */)
if (stats?.isDirectory()) {
tsConfig.compilerOptions.paths[alias] = [relativePath]
tsConfig.compilerOptions.paths[`${alias}/*`] = [`${relativePath}/*`]
} else {
tsConfig.compilerOptions.paths[alias] = [relativePath.replace(/(?<=\w)\.\w+$/g, '')] /* remove extension */
}
}
const references: TSReference[] = [