From 574102c5235431f98e55635916223e1a1f7ed6d4 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Mon, 11 Sep 2023 19:17:42 +0100 Subject: [PATCH] fix(nuxt): default scanned layer components to priority `0` (#23127) --- packages/nuxt/src/components/module.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/packages/nuxt/src/components/module.ts b/packages/nuxt/src/components/module.ts index b7db1018b8..4c5a8f9846 100644 --- a/packages/nuxt/src/components/module.ts +++ b/packages/nuxt/src/components/module.ts @@ -42,20 +42,20 @@ export default defineNuxtModule({ : context.components } - const normalizeDirs = (dir: any, cwd: string): ComponentsDir[] => { + const normalizeDirs = (dir: any, cwd: string, options?: { priority?: number }): ComponentsDir[] => { if (Array.isArray(dir)) { - return dir.map(dir => normalizeDirs(dir, cwd)).flat().sort(compareDirByPathLength) + return dir.map(dir => normalizeDirs(dir, cwd, options)).flat().sort(compareDirByPathLength) } if (dir === true || dir === undefined) { return [ - { path: resolve(cwd, 'components/islands'), island: true }, - { path: resolve(cwd, 'components/global'), global: true }, - { path: resolve(cwd, 'components') } + { priority: options?.priority || 0, path: resolve(cwd, 'components/islands'), island: true }, + { priority: options?.priority || 0, path: resolve(cwd, 'components/global'), global: true }, + { priority: options?.priority || 0, path: resolve(cwd, 'components') } ] } if (typeof dir === 'string') { return [ - { path: resolve(cwd, resolveAlias(dir)) } + { priority: options?.priority || 0, path: resolve(cwd, resolveAlias(dir)) } ] } if (!dir) { @@ -63,6 +63,7 @@ export default defineNuxtModule({ } const dirs: ComponentsDir[] = (dir.dirs || [dir]).map((dir: any): ComponentsDir => typeof dir === 'string' ? { path: dir } : dir).filter((_dir: ComponentsDir) => _dir.path) return dirs.map(_dir => ({ + priority: options?.priority || 0, ..._dir, path: resolve(cwd, resolveAlias(_dir.path)) })) @@ -72,7 +73,7 @@ export default defineNuxtModule({ nuxt.hook('app:resolve', async () => { // components/ dirs from all layers const allDirs = nuxt.options._layers - .map(layer => normalizeDirs(layer.config.components, layer.config.srcDir)) + .map(layer => normalizeDirs(layer.config.components, layer.config.srcDir, { priority: layer.config.srcDir === nuxt.options.srcDir ? 1 : 0 })) .flat() await nuxt.callHook('components:dirs', allDirs)