fix(nuxt): handle plugin dependencies with mixed load state (#25318)

This commit is contained in:
hitochan777 2024-01-22 18:57:17 +09:00 committed by GitHub
parent 89541f4164
commit 95a5213766
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 2 deletions

View File

@ -368,8 +368,9 @@ export async function applyPlugins (nuxtApp: NuxtApp, plugins: Array<Plugin & Ob
let promiseDepth = 0
async function executePlugin (plugin: Plugin & ObjectPlugin<any>) {
if (plugin.dependsOn && !plugin.dependsOn.every(name => resolvedPlugins.includes(name))) {
unresolvedPlugins.push([new Set(plugin.dependsOn), plugin])
const unresolvedPluginsForThisPlugin = plugin.dependsOn?.filter(name => !resolvedPlugins.includes(name)) ?? []
if (unresolvedPluginsForThisPlugin.length > 0) {
unresolvedPlugins.push([new Set(unresolvedPluginsForThisPlugin), plugin])
} else {
const promise = applyPlugin(nuxtApp, plugin).then(async () => {
if (plugin._name) {

View File

@ -244,4 +244,24 @@ describe('plugin dependsOn', () => {
'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, false),
pluginFactory('B', ['A', 'C'], sequence, false),
pluginFactory('C', undefined, sequence, false),
]
await applyPlugins(nuxtApp, plugins)
expect(sequence).toMatchObject([
'start A',
'end A',
'start C',
'end C',
'start B',
'end B',
])
})
})