mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-25 07:05:11 +00:00
fix(nuxt): use import alias when checking if plugin is wrapped (#23617)
This commit is contained in:
parent
f3810b132a
commit
b3d3d7f4fd
@ -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') {
|
||||
|
Loading…
Reference in New Issue
Block a user