chore: add sort logic to handle /plugins/<name>/index syntax

This commit is contained in:
userquin 2023-08-30 10:54:34 +02:00
parent 8f4ddeff27
commit 0cdd58157b

View File

@ -141,12 +141,16 @@ async function resolveApp (nuxt: Nuxt, app: NuxtApp) {
: [] : []
].map(plugin => normalizePlugin(plugin as NuxtPlugin))) ].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) => { app.plugins.push(...plugins.sort((a, b) => {
const sortMapResult = (a.order ?? orderMap.default) - (b.order ?? orderMap.default) const sortMapResult = (a.order ?? orderMap.default) - (b.order ?? orderMap.default)
if (sortMapResult !== 0) { return sortMapResult } if (sortMapResult !== 0) { return sortMapResult }
// TODO: update this when TODO in L139 is resolved const aName = pluginNameRegex.test(a.src) ? basename(dirname(a.src)) : basename(a.src)
return basename(a.src).localeCompare(basename(b.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 // Normalize and de-duplicate plugins and middleware