Skip to content

hasPlugin does not check outer scopes #4925

@mwstr

Description

@mwstr

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Fastify version

4.20.0

Plugin version

No response

Node.js version

18.16.1

Operating system

Windows

Operating system version (i.e. 20.04, 11.3, 10)

11

Description

hasPlugin does not check outer scopes for registered plugins

Steps to Reproduce

import fastify from 'fastify'
import fastifyPlugin from 'fastify-plugin'

const server = fastify()

const pluginCallback = (server, options, done) => {
    done()
}
const pluginName = 'awesome-plugin'
const plugin = fastifyPlugin(pluginCallback, {name: pluginName})

await server.register(plugin)

await server.register(async (server) => {
    const hasPlugin = server.hasPlugin(pluginName)
    console.log(hasPlugin) // prints: false

    const hasPluginWorkaround =
    server[Symbol.for('registered-plugin')]
        .includes(pluginName)
    console.log(hasPluginWorkaround) // prints: true
})

Expected Behavior

hasPlugin should be true

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions