mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 08:33:53 +00:00
fix(nuxt): load plugin that depends on loaded and unloaded plugins
This commit is contained in:
parent
c266e82456
commit
e231357dbb
@ -368,8 +368,9 @@ export async function applyPlugins (nuxtApp: NuxtApp, plugins: Array<Plugin & Ob
|
|||||||
let promiseDepth = 0
|
let promiseDepth = 0
|
||||||
|
|
||||||
async function executePlugin (plugin: Plugin & ObjectPlugin<any>) {
|
async function executePlugin (plugin: Plugin & ObjectPlugin<any>) {
|
||||||
if (plugin.dependsOn && !plugin.dependsOn.every(name => resolvedPlugins.includes(name))) {
|
const unresolvedPluginsForThisPlugin = plugin.dependsOn?.filter(name => !resolvedPlugins.includes(name)) ?? []
|
||||||
unresolvedPlugins.push([new Set(plugin.dependsOn), plugin])
|
if (unresolvedPluginsForThisPlugin.length > 0) {
|
||||||
|
unresolvedPlugins.push([new Set(unresolvedPluginsForThisPlugin), plugin])
|
||||||
} else {
|
} else {
|
||||||
const promise = applyPlugin(nuxtApp, plugin).then(async () => {
|
const promise = applyPlugin(nuxtApp, plugin).then(async () => {
|
||||||
if (plugin._name) {
|
if (plugin._name) {
|
||||||
|
@ -244,4 +244,24 @@ describe('plugin dependsOn', () => {
|
|||||||
'end B'
|
'end B'
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('expect B to execute after A, C when B depends on A and C', async () => {
|
||||||
|
const nuxtApp = useNuxtApp()
|
||||||
|
const sequence: string[] = []
|
||||||
|
const plugins = [
|
||||||
|
pluginFactory('A', undefined, sequence),
|
||||||
|
pluginFactory('B', ['A', 'C'], sequence),
|
||||||
|
pluginFactory('C', undefined, sequence)
|
||||||
|
]
|
||||||
|
await applyPlugins(nuxtApp, plugins)
|
||||||
|
|
||||||
|
expect(sequence).toMatchObject([
|
||||||
|
'start A',
|
||||||
|
'start C',
|
||||||
|
'end A',
|
||||||
|
'end C',
|
||||||
|
'start B',
|
||||||
|
'end B'
|
||||||
|
])
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user