fastify / fastify-plugin

Plugin helper for Fastify
MIT License
202 stars 43 forks source link

Add fastify as peer dependency #93

Closed mekwall closed 4 years ago

mekwall commented 4 years ago

This PR adds fastify as a peer dependency so that it works properly with Yarn v2 without having to override the package. Without it you'll get the following message in your log for every plugin since it is trying to require fastify/package.json:

fastify not found, proceeding anyway

Yarn v2 enforces packages to list all dependencies that are used by that package. In this case, fastify is provided by the user so it should be a peer dependency.

Checklist

jsumners commented 4 years ago

I don't think this is correct. It is actually a mistake to use fastify-plugin without a parent fastify instance, i.e. the tree should always look like app => fastify => plugin => fastify-plugin.

This issue also exhibits itself when using pnpm to install modules. In this case, the warning is nothing more than an annoyance.

The solution we decided upon, and no one has had time to implement yet, was discussed in https://github.com/fastify/fastify/issues/1780#issuecomment-569044068

mcollina commented 4 years ago
const fastify = require(require.resolve('fastify', {paths: [require.main.filename]}))
mcollina commented 4 years ago

Fixed in https://github.com/fastify/fastify-plugin/pull/94