From 0cdd58157b2ae3d35b15a48d0024916f4adc3b43 Mon Sep 17 00:00:00 2001 From: userquin Date: Wed, 30 Aug 2023 10:54:34 +0200 Subject: [PATCH] chore: add sort logic to handle `/plugins//index` syntax --- packages/nuxt/src/core/app.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/nuxt/src/core/app.ts b/packages/nuxt/src/core/app.ts index 9f7e351cdf..7a7eb916d2 100644 --- a/packages/nuxt/src/core/app.ts +++ b/packages/nuxt/src/core/app.ts @@ -141,12 +141,16 @@ async function resolveApp (nuxt: Nuxt, app: NuxtApp) { : [] ].map(plugin => normalizePlugin(plugin as NuxtPlugin))) } + + // sort scanned plugins by order and name + const pluginNameRegex = /\/index\.[cm]?[jt]s$/ app.plugins.push(...plugins.sort((a, b) => { const sortMapResult = (a.order ?? orderMap.default) - (b.order ?? orderMap.default) if (sortMapResult !== 0) { return sortMapResult } - // TODO: update this when TODO in L139 is resolved - return basename(a.src).localeCompare(basename(b.src)) + const aName = pluginNameRegex.test(a.src) ? basename(dirname(a.src)) : basename(a.src) + const bName = pluginNameRegex.test(b.src) ? basename(dirname(b.src)) : basename(b.src) + return aName.localeCompare(bName) })) // Normalize and de-duplicate plugins and middleware