fix(nuxt): add runtime check to filter plugins in dependsOn (#25409)

This commit is contained in:
Julien Huang 2024-01-27 23:14:18 +01:00 committed by GitHub
parent ca060288e6
commit de0ceaa72a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 1 deletions

View File

@ -368,7 +368,7 @@ 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>) {
const unresolvedPluginsForThisPlugin = plugin.dependsOn?.filter(name => !resolvedPlugins.includes(name)) ?? [] const unresolvedPluginsForThisPlugin = plugin.dependsOn?.filter(name => plugins.some(p => p._name === name) && !resolvedPlugins.includes(name)) ?? []
if (unresolvedPluginsForThisPlugin.length > 0) { if (unresolvedPluginsForThisPlugin.length > 0) {
unresolvedPlugins.push([new Set(unresolvedPluginsForThisPlugin), plugin]) unresolvedPlugins.push([new Set(unresolvedPluginsForThisPlugin), plugin])
} else { } else {

View File

@ -264,4 +264,21 @@ describe('plugin dependsOn', () => {
'end B', 'end B',
]) ])
}) })
it('expect to execute plugins if a plugin depends on a plugin that does not exist', async () => {
const nuxtApp = useNuxtApp()
const sequence: string[] = []
const plugins = [
pluginFactory('B', undefined, sequence,),
pluginFactory('C', ['A', 'B'], sequence,),
]
await applyPlugins(nuxtApp, plugins)
expect(sequence).toMatchObject([
'start B',
'end B',
'start C',
'end C',
])
})
}) })