From b3d3d7f4fd0d5a439d18fad136eae7008a72b29d Mon Sep 17 00:00:00 2001 From: Aaron_Zhou Date: Thu, 12 Oct 2023 00:01:23 +0800 Subject: [PATCH] fix(nuxt): use import alias when checking if plugin is wrapped (#23617) --- packages/nuxt/src/core/plugins/plugin-metadata.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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') {