diff --git a/packages/nuxt/src/app/nuxt.ts b/packages/nuxt/src/app/nuxt.ts index 93d623cf24..ba82373afb 100644 --- a/packages/nuxt/src/app/nuxt.ts +++ b/packages/nuxt/src/app/nuxt.ts @@ -368,8 +368,9 @@ export async function applyPlugins (nuxtApp: NuxtApp, plugins: Array) { - 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) { diff --git a/test/nuxt/plugin.test.ts b/test/nuxt/plugin.test.ts index 2856feceb1..c924fa6eb8 100644 --- a/test/nuxt/plugin.test.ts +++ b/test/nuxt/plugin.test.ts @@ -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), + 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' + ]) + }) })