Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

method to check if plugin version is matching the Fastify version #5356

Open
2 tasks done
matthyk opened this issue Mar 12, 2024 · 3 comments
Open
2 tasks done

method to check if plugin version is matching the Fastify version #5356

matthyk opened this issue Mar 12, 2024 · 3 comments

Comments

@matthyk
Copy link
Contributor

matthyk commented Mar 12, 2024

Prerequisites

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

馃殌 Feature Proposal

If you register a plugin that does not match the Fastify version, an error is thrown. It would be helpful to have a function like 'checkPluginVersion' that follows the same logic to check if the given plugin version matches the Fastify version.

Motivation

No response

Example

import fp from 'fastify-plugin'
import Fastify from 'fastify'

const plugin = fp(async app => {}, {
  fastify: '4.x'
}) 

const app = Fastify()

if (app.checkPluginVersion(plugin)) {
  console.log('plugin version does match' )
} else {
  console.log('plugin version does not match' )
}
@metcoder95
Copy link
Member

I'm kind of over the fence, it seems like a good fit for a plugin, but also do not have a strong argument for not add it to core; what use cases do you have in mind?

@matthyk
Copy link
Contributor Author

matthyk commented Mar 13, 2024

My use case is as follows: I have a CLI that receives a file path/several file paths to plugins from the user. This CLI then registers the given plugins in a self-created Fastify instance. Now it would be handy to be able to check whether the version of the Fastify plugins matches the Fastify version. Currently this is possible via a register, where you can see if an error is thrown. But I would prefer to have a method to easily check this without having to catch an error.

@metcoder95
Copy link
Member

It kind of sounds pretty well for a plugin, fastify already exposes the version from the instance that be consumed by a meta-plugin that decorates app with the API you propose to validate plugins.

e.g.

const metaPlugin = require('<the_name_of_the_plugin>');
const app = fastify().register(metaPlugin, { throw: true, /* ... other opts */ });

app.verifyPlugin(plugin) //throws or returns false.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants