mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-18 01:15:58 +00:00
perf(kit,nuxt): don't resolve paths from local layers/modules (#30650)
This commit is contained in:
parent
00e0b3c136
commit
e4a6cdceb4
@ -19,11 +19,11 @@ export async function installModule<
|
||||
> (moduleToInstall: T, inlineOptions?: [Config] extends [never] ? any : Config[1], nuxt: Nuxt = useNuxt()) {
|
||||
const { nuxtModule, buildTimeModuleMeta, resolvedModulePath } = await loadNuxtModuleInstance(moduleToInstall, nuxt)
|
||||
|
||||
const localLayerModuleDirs = new Set<string>()
|
||||
const localLayerModuleDirs: string[] = []
|
||||
for (const l of nuxt.options._layers) {
|
||||
const srcDir = l.config.srcDir || l.cwd
|
||||
if (!NODE_MODULES_RE.test(srcDir)) {
|
||||
localLayerModuleDirs.add(resolve(srcDir, l.config?.dir?.modules || 'modules'))
|
||||
localLayerModuleDirs.push(resolve(srcDir, l.config?.dir?.modules || 'modules').replace(/\/?$/, '/'))
|
||||
}
|
||||
}
|
||||
|
||||
@ -38,8 +38,8 @@ export async function installModule<
|
||||
const parsed = parseNodeModulePath(modulePath)
|
||||
const moduleRoot = parsed.dir ? parsed.dir + parsed.name : modulePath
|
||||
nuxt.options.build.transpile.push(normalizeModuleTranspilePath(moduleRoot))
|
||||
const directory = parsed.dir ? moduleRoot : getDirectory(modulePath)
|
||||
if (directory !== moduleToInstall && !localLayerModuleDirs.has(directory)) {
|
||||
const directory = (parsed.dir ? moduleRoot : getDirectory(modulePath)).replace(/\/?$/, '/')
|
||||
if (directory !== moduleToInstall && !localLayerModuleDirs.some(dir => directory.startsWith(dir))) {
|
||||
nuxt.options.modulesDir.push(resolve(directory, 'node_modules'))
|
||||
}
|
||||
}
|
||||
|
@ -404,8 +404,11 @@ async function initNuxt (nuxt: Nuxt) {
|
||||
...nuxt.options._layers.filter(i => i.cwd.includes('node_modules')).map(i => i.cwd as string),
|
||||
)
|
||||
|
||||
// Ensure we can resolve dependencies within layers
|
||||
nuxt.options.modulesDir.push(...nuxt.options._layers.map(l => resolve(l.cwd, 'node_modules')))
|
||||
// Ensure we can resolve dependencies within layers - filtering out local `~/layers` directories
|
||||
const locallyScannedLayersDirs = nuxt.options._layers.map(l => resolve(l.cwd, 'layers').replace(/\/?$/, '/'))
|
||||
nuxt.options.modulesDir.push(...nuxt.options._layers
|
||||
.filter(l => l.cwd !== nuxt.options.rootDir && locallyScannedLayersDirs.every(dir => !l.cwd.startsWith(dir)))
|
||||
.map(l => resolve(l.cwd, 'node_modules')))
|
||||
|
||||
// Init user modules
|
||||
await nuxt.callHook('modules:before')
|
||||
@ -571,6 +574,7 @@ async function initNuxt (nuxt: Nuxt) {
|
||||
nuxt._ignore.add(resolveIgnorePatterns())
|
||||
|
||||
await nuxt.callHook('modules:done')
|
||||
console.log(nuxt.options.modulesDir, nuxt.options.modulesDir.length)
|
||||
|
||||
// Add <NuxtIsland>
|
||||
if (nuxt.options.experimental.componentIslands) {
|
||||
|
Loading…
Reference in New Issue
Block a user