mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-18 09:25:54 +00:00
perf(kit): remove iterations when resolving module path (#30562)
This commit is contained in:
parent
2974ecfe0f
commit
bc1d39c825
@ -95,31 +95,28 @@ export async function loadNuxtModuleInstance (nuxtModule: string | NuxtModule, n
|
|||||||
paths.add(nuxtModule)
|
paths.add(nuxtModule)
|
||||||
|
|
||||||
for (const path of paths) {
|
for (const path of paths) {
|
||||||
for (const parentURL of nuxt.options.modulesDir) {
|
try {
|
||||||
try {
|
const src = isAbsolute(path)
|
||||||
const src = isAbsolute(path)
|
? pathToFileURL(await resolvePath(path, { fallbackToOriginal: false, extensions: nuxt.options.extensions })).href
|
||||||
? pathToFileURL(await resolvePath(path, { cwd: parentURL, 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 })
|
||||||
: await resolveModule(path, { url: pathToFileURL(parentURL.replace(/\/node_modules\/?$/, '')), extensions: nuxt.options.extensions })
|
|
||||||
|
|
||||||
nuxtModule = await jiti.import(src, { default: true }) as NuxtModule
|
nuxtModule = await jiti.import(src, { default: true }) as NuxtModule
|
||||||
resolvedModulePath = fileURLToPath(new URL(src))
|
resolvedModulePath = fileURLToPath(new URL(src))
|
||||||
|
|
||||||
// nuxt-module-builder generates a module.json with metadata including the version
|
// nuxt-module-builder generates a module.json with metadata including the version
|
||||||
const moduleMetadataPath = new URL('module.json', src)
|
const moduleMetadataPath = new URL('module.json', src)
|
||||||
if (existsSync(moduleMetadataPath)) {
|
if (existsSync(moduleMetadataPath)) {
|
||||||
buildTimeModuleMeta = JSON.parse(await fsp.readFile(moduleMetadataPath, 'utf-8'))
|
buildTimeModuleMeta = JSON.parse(await fsp.readFile(moduleMetadataPath, 'utf-8'))
|
||||||
}
|
|
||||||
break
|
|
||||||
} catch (error: unknown) {
|
|
||||||
const code = (error as Error & { code?: string }).code
|
|
||||||
if (code === 'MODULE_NOT_FOUND' || code === 'ERR_PACKAGE_PATH_NOT_EXPORTED' || code === 'ERR_MODULE_NOT_FOUND' || code === 'ERR_UNSUPPORTED_DIR_IMPORT' || code === 'ENOTDIR') {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
logger.error(`Error while importing module \`${nuxtModule}\`: ${error}`)
|
|
||||||
throw error
|
|
||||||
}
|
}
|
||||||
|
break
|
||||||
|
} catch (error: unknown) {
|
||||||
|
const code = (error as Error & { code?: string }).code
|
||||||
|
if (code === 'MODULE_NOT_FOUND' || code === 'ERR_PACKAGE_PATH_NOT_EXPORTED' || code === 'ERR_MODULE_NOT_FOUND' || code === 'ERR_UNSUPPORTED_DIR_IMPORT' || code === 'ENOTDIR') {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
logger.error(`Error while importing module \`${nuxtModule}\`: ${error}`)
|
||||||
|
throw error
|
||||||
}
|
}
|
||||||
if (typeof nuxtModule !== 'string') { break }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user