Giter Club home page Giter Club logo

Comments (5)

mcollina avatar mcollina commented on July 30, 2024

Can you please make an example of what you think it's happening right now vs what it should be happening according to you?

from fastify-plugin.

lependu avatar lependu commented on July 30, 2024

@mcollina I like how it works now, but I would improve the README:

I think it should be something like this You can also pass some metadata that will be handled by Fastify, such as the dependencies of your plugin.
const fp = require('fastify-plugin')

function plugin (fastify, opts, next) {
  // your plugin code
  next()
}

module.exports = fp(plugin, {
  fastify: '0.x',
  // You need to define only one of the [dependency|decorator] properties.
  decorators: {
    fastify: ['plugin1', 'plugin2'],
    reply: ['compress']
  },
  dependencies: ['plugin1-name, plugin2-name']
})
And I think we should update Ecosystem plugins with name property, because

dependency only works if the name property defined int the plugin's meta.
For example:

plugin.js

const fp = require('fastify-plugin')

function plugin (fastify, opts, next) {
  // your plugin code
  next()
}

module.exports = fp(plugin, {
  fastify: '0.x',
  dependencies: ['fastify-redis']
})

server.js

const Fastify = require('fastify')                                              
const redis = require('fastify-redis')                                          
const plugin = require('./plugin')   

module.exports = (options) => {                                                    
  const instance = Fastify()                                                    
  instance
   .register(redis)
   .register(plugin)
   // more code
  return instance
}

This will throw error (even if the dependency registered), simply because fastify-redis does not have name property in its plugin definition.

from fastify-plugin.

delvedor avatar delvedor commented on July 30, 2024

@lependu why You need to define only one of the [dependency|decorator] properties.?
You may need both.

from fastify-plugin.

lependu avatar lependu commented on July 30, 2024

@delvedor Corrected.

One more question: May I create PRs which updates Ecosystem plugins with name property?

from fastify-plugin.

delvedor avatar delvedor commented on July 30, 2024

Sure!

from fastify-plugin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.