mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-30 01:17:16 +00:00
chore: add sort logic to handle /plugins/<name>/index
syntax
This commit is contained in:
parent
8f4ddeff27
commit
0cdd58157b
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user