diff --git a/packages/nuxt/src/core/plugins/plugin-metadata.ts b/packages/nuxt/src/core/plugins/plugin-metadata.ts index 77aaec22bb..fa3f3b43fc 100644 --- a/packages/nuxt/src/core/plugins/plugin-metadata.ts +++ b/packages/nuxt/src/core/plugins/plugin-metadata.ts @@ -132,6 +132,7 @@ export const RemovePluginMetadataPlugin = (nuxt: Nuxt) => createUnplugin(() => { } let wrapped = false + const wrapperNames = new Set(['defineNuxtPlugin', 'definePayloadPlugin']) try { walk(this.parse(code, { @@ -139,6 +140,9 @@ export const RemovePluginMetadataPlugin = (nuxt: Nuxt) => createUnplugin(() => { ecmaVersion: 'latest' }) as Node, { enter (_node) { + if (_node.type === 'ImportSpecifier' && (_node.imported.name === 'defineNuxtPlugin' || _node.imported.name === 'definePayloadPlugin')) { + wrapperNames.add(_node.local.name) + } if (_node.type === 'ExportDefaultDeclaration' && (_node.declaration.type === 'FunctionDeclaration' || _node.declaration.type === 'ArrowFunctionExpression')) { if ('params' in _node.declaration && _node.declaration.params.length > 1) { logger.warn(`Plugin \`${plugin.src}\` is in legacy Nuxt 2 format (context, inject) which is likely to be broken and will be ignored.`) @@ -150,7 +154,7 @@ export const RemovePluginMetadataPlugin = (nuxt: Nuxt) => createUnplugin(() => { if (_node.type !== 'CallExpression' || (_node as CallExpression).callee.type !== 'Identifier') { return } const node = _node as CallExpression & { start: number, end: number } const name = 'name' in node.callee && node.callee.name - if (name !== 'defineNuxtPlugin' && name !== 'definePayloadPlugin') { return } + if (!name || !wrapperNames.has(name)) { return } wrapped = true if (node.arguments[0].type !== 'ObjectExpression') {