Butterwire / serverless-plugin-monorepo

A Serverless plugin that allows use of serverless in a JS mono repo.
Mozilla Public License 2.0
167 stars 31 forks source link

Duplicate dependecies of dependencies #8

Open afreakk opened 5 years ago

afreakk commented 5 years ago

It would be nice if this plugin hoisted all dependencies up to node_module root and avoided duplicates.
Currently you can end up with very deep structures, with tons of duplicate dependencies. Like if your sls-function depend on A and B, and A depend on externalA, but B also depend on externalA.
both A and B could also depend on local dependency C, which would end up like this:

sls-function/node_modules/A/node_modules/externalA
sls-function/node_modules/A/node_modules/C
sls-function/node_modules/B/node_modules/externalA
sls-function/node_modules/B/node_modules/C

When you have duplicate dependencies like this, instanceof wont work properly across duplications either.

martin-css commented 5 years ago

Sorry for the long delay in replying, I'd forgotten about the notification for this issue and was just reminded when another issue came in today.

I agree, this would be a nice feature to have. However, it's not trivial to implement as we are starting to venture into package manager dependency management territory. There's a lot of hidden complexity in matching versions, deciding which module(s) should be hoisted and which one's shouldn't (when different versions of the same package are required).

The ideal solution would be to bypass this and rely upon the decisions that the existing package manager has made when hoisting dependencies, e,g, examine the file tree to determine where to place the symlinks.

I'll have a look at this in the near future when time permits. In the meantime, if anyone else would like to contribute, please feel free! :+1: