nest icon indicating copy to clipboard operation
nest copied to clipboard

unpin fastify/express hard dependency from `@nestjs/platform-*`

Open micalevisk opened this issue 1 year ago • 0 comments
trafficstars

Is there an existing issue that is already proposing this?

  • [X] I have searched the existing issues

Is your feature request related to a problem? Please describe it

When we install @nestjs/[email protected] we'll get fastify v4.27.0 because this version is pinned

https://github.com/nestjs/nest/blob/15cb568e40f42fb3c40c4cb2ad432b23a5ec7bcd/packages/platform-fastify/package.json#L20-L28

but when we want have fastify as hard dep of our project, we'll download its latest version (v4.28.0)

And so our dependency graph (npm ls fastify) will look like this:

image

meaning that we have 2 versions of fastify installed instead of just the latest one.

This will lead to build problems when we want (for whatever reason) to use types from ./node_modules/fastify against types from ./node_modules/@nestjs/platform-fastify/fastify

like this one:

image

because of this:

image image

in the above case we can safely drop the explicit typing because the .getInstance() method will return a proper type definition (FastifyInstance from the nested version of fastify).

Describe the solution you'd like

Changing "fastify": "4.28.0" to "fastify": "^4.28.0" should be enough. Same for express.

We'd have to configure the Renovatebot to prevent it from reverting this change.

Teachability, documentation, adoption, migration strategy

N/A

What is the motivation / use case for changing the behavior?

DX improvements:

  1. People will face those errors and might not understand why is that
  2. People won't need to rely on upgrades on @nestjs/platform-fastify/@nestjs/platform-express when they want to upgrade fastify/express on their side (as long as they respect the major slice), avoiding issues like #13607 and questions at our Discord community

micalevisk avatar Jun 25 '24 12:06 micalevisk