fix(nuxt): only strip supported extensions when generating import types (#26218)

This commit is contained in:
Mehmet 2024-03-12 20:25:28 +03:00 committed by GitHub
parent a04b88bfcd
commit 8010b04f69
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -145,6 +145,8 @@ function addDeclarationTemplates (ctx: Unimport, options: Partial<ImportsOptions
const resolvedImportPathMap = new Map<string, string>()
const r = ({ from }: Import) => resolvedImportPathMap.get(from)
const SUPPORTED_EXTENSION_RE = new RegExp(`\\.(${nuxt.options.extensions.map(i => i.replace('.', '')).join('|')})$`)
async function cacheImportPaths (imports: Import[]) {
const importSource = Array.from(new Set(imports.map(i => i.from)))
await Promise.all(importSource.map(async (from) => {
@ -164,7 +166,7 @@ function addDeclarationTemplates (ctx: Unimport, options: Partial<ImportsOptions
}
if (existsSync(path) && !(await isDirectory(path))) {
path = path.replace(/\.[a-z]+$/, '')
path = path.replace(SUPPORTED_EXTENSION_RE, '')
}
if (isAbsolute(path)) {