mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-25 23:22:02 +00:00
fix(nuxt): improve path resolve for import.d.ts
(#24413)
This commit is contained in:
parent
36aee52011
commit
338908e0f0
@ -145,12 +145,16 @@ function addDeclarationTemplates (ctx: Unimport, options: Partial<ImportsOptions
|
||||
|
||||
const resolvedImportPathMap = new Map<string, string>()
|
||||
const r = ({ from }: Import) => resolvedImportPathMap.get(from)
|
||||
async function cacheImportPaths (imports: Import[]) {
|
||||
for (const i of imports) {
|
||||
if (resolvedImportPathMap.has(i.from)) { continue }
|
||||
let path = resolveAlias(i.from)
|
||||
|
||||
async function cacheImportPaths(imports: Import[]) {
|
||||
const importSource = Array.from(new Set(imports.map(i => i.from)))
|
||||
await Promise.all(importSource.map(async (from) => {
|
||||
if (resolvedImportPathMap.has(from)) {
|
||||
return
|
||||
}
|
||||
let path = resolveAlias(from)
|
||||
if (!isAbsolute(path)) {
|
||||
path = await tryResolveModule(i.from, nuxt.options.modulesDir).then(async (r) => {
|
||||
path = await tryResolveModule(from, nuxt.options.modulesDir).then(async (r) => {
|
||||
if (!r) { return r }
|
||||
|
||||
const { dir, name } = parseNodeModulePath(r)
|
||||
@ -164,8 +168,8 @@ function addDeclarationTemplates (ctx: Unimport, options: Partial<ImportsOptions
|
||||
}
|
||||
|
||||
path = stripExtension(path)
|
||||
resolvedImportPathMap.set(i.from, path)
|
||||
}
|
||||
resolvedImportPathMap.set(from, path)
|
||||
}))
|
||||
}
|
||||
|
||||
addTemplate({
|
||||
@ -176,7 +180,7 @@ function addDeclarationTemplates (ctx: Unimport, options: Partial<ImportsOptions
|
||||
addTemplate({
|
||||
filename: 'types/imports.d.ts',
|
||||
getContents: async () => {
|
||||
const imports = await ctx.getImports().then(r => r.filter(i => !i.type))
|
||||
const imports = await ctx.getImports()
|
||||
await cacheImportPaths(imports)
|
||||
return '// Generated by auto imports\n' + (
|
||||
options.autoImport
|
||||
|
Loading…
Reference in New Issue
Block a user