perf(kit): remove iterations when resolving module path (#30562)

This commit is contained in:
Daniel Roe 2025-01-13 14:25:21 +00:00
parent 23b9682899
commit 60f7d15edd
No known key found for this signature in database
GPG Key ID: 3714AB03996F442B

View File

@ -101,11 +101,10 @@ export async function loadNuxtModuleInstance (nuxtModule: string | NuxtModule, n
paths.add(nuxtModule)
for (const path of paths) {
for (const parentURL of nuxt.options.modulesDir) {
try {
const src = isAbsolute(path)
? pathToFileURL(await resolvePath(path, { cwd: parentURL, fallbackToOriginal: false, extensions: nuxt.options.extensions })).href
: await resolveModule(path, { url: pathToFileURL(parentURL.replace(/\/node_modules\/?$/, '')), extensions: nuxt.options.extensions })
? pathToFileURL(await resolvePath(path, { fallbackToOriginal: false, extensions: nuxt.options.extensions })).href
: await resolveModule(path, { url: nuxt.options.modulesDir.map(m => pathToFileURL(m.replace(/\/node_modules\/?$/, ''))), extensions: nuxt.options.extensions })
nuxtModule = await jiti.import(src, { default: true }) as NuxtModule
resolvedModulePath = fileURLToPath(new URL(src))
@ -125,8 +124,6 @@ export async function loadNuxtModuleInstance (nuxtModule: string | NuxtModule, n
throw error
}
}
if (typeof nuxtModule !== 'string') { break }
}
}
// Throw error if module could not be found