fastify / fastify-plugin

Plugin helper for Fastify
MIT License
197 stars 42 forks source link

Introduce an option to encapsulate the plugin #197

Closed dwickern closed 1 year ago

dwickern commented 1 year ago

Prerequisites

🚀 Feature Proposal

Introduce an option encapsulate?: boolean. Defaults to false. When set to true, keep the plugin encapsulated.

Motivation

fastify-plugin currently makes all plugins accessible by setting skip-override. It would be nice to have an option to keep it encapsulated, so you can set a plugin's name, metadata, etc without affecting the plugin's scope.

Would you consider a PR for this?

Example

module.exports = fp(plugin, {
  fastify: '4.x',
  decorators: {
    fastify: ['plugin1', 'plugin2'],
    reply: ['compress']
  },
  dependencies: ['plugin1-name', 'plugin2-name'],
  encapsulate: true,
})
Eomm commented 1 year ago

I think it is a good suggestion, but I suspect that something will not work (such as the name option) - so we will need a good test suite to cover the use cases

climba03003 commented 1 year ago

I suspect that something will not work

I do not get what's you mean by name option would not works? The name doesn't matter if it is encapsulated or not. It will be pushed to the registered list and plugin chain in any case.