mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 21:55:11 +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 resolvedImportPathMap = new Map<string, string>()
|
||||||
const r = ({ from }: Import) => resolvedImportPathMap.get(from)
|
const r = ({ from }: Import) => resolvedImportPathMap.get(from)
|
||||||
async function cacheImportPaths (imports: Import[]) {
|
|
||||||
for (const i of imports) {
|
async function cacheImportPaths(imports: Import[]) {
|
||||||
if (resolvedImportPathMap.has(i.from)) { continue }
|
const importSource = Array.from(new Set(imports.map(i => i.from)))
|
||||||
let path = resolveAlias(i.from)
|
await Promise.all(importSource.map(async (from) => {
|
||||||
|
if (resolvedImportPathMap.has(from)) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
let path = resolveAlias(from)
|
||||||
if (!isAbsolute(path)) {
|
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 }
|
if (!r) { return r }
|
||||||
|
|
||||||
const { dir, name } = parseNodeModulePath(r)
|
const { dir, name } = parseNodeModulePath(r)
|
||||||
@ -164,8 +168,8 @@ function addDeclarationTemplates (ctx: Unimport, options: Partial<ImportsOptions
|
|||||||
}
|
}
|
||||||
|
|
||||||
path = stripExtension(path)
|
path = stripExtension(path)
|
||||||
resolvedImportPathMap.set(i.from, path)
|
resolvedImportPathMap.set(from, path)
|
||||||
}
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
addTemplate({
|
addTemplate({
|
||||||
@ -176,7 +180,7 @@ function addDeclarationTemplates (ctx: Unimport, options: Partial<ImportsOptions
|
|||||||
addTemplate({
|
addTemplate({
|
||||||
filename: 'types/imports.d.ts',
|
filename: 'types/imports.d.ts',
|
||||||
getContents: async () => {
|
getContents: async () => {
|
||||||
const imports = await ctx.getImports().then(r => r.filter(i => !i.type))
|
const imports = await ctx.getImports()
|
||||||
await cacheImportPaths(imports)
|
await cacheImportPaths(imports)
|
||||||
return '// Generated by auto imports\n' + (
|
return '// Generated by auto imports\n' + (
|
||||||
options.autoImport
|
options.autoImport
|
||||||
|
Loading…
Reference in New Issue
Block a user