pnpm.io icon indicating copy to clipboard operation
pnpm.io copied to clipboard

Add information about dependenciesMeta.*.injected

Open klingenm opened this issue 2 years ago • 2 comments

When using Workspaces with a log of dependencies, I have encountered many times that a dependency gets duplicated between the packages if the peer dependencies are satisfied differently. Since packages may have optional peer dependencies this is a valid case that should not require the package to be duplicated.

It took a long time to find a solution to the problem since the solution is only documented under the package.json documentation page.

klingenm avatar Sep 23 '22 10:09 klingenm

I think a better solution might be to force single version of that package using overrides.

zkochan avatar Sep 23 '22 12:09 zkochan

Problem is that having single versions is not enough.

If you satisfyoptional peer dependencies differently in two packages, the "real" dependency gets duplicated.

Lets say we have two packages in our workspace called A and B. They both depend on external package C, that has two optional dependencies D and E.

Now if A only needs D, B only needs E then C will be duplicated, once with D as a peer dependency and once with E as a peer dependency.

The only way to get around that duplication is to take the sum of all peer dependencies used throughout the workspace and apply them to all who import C.

This example probably would not have any side-effects. But if the peer dependency is in a common lib F, that is imported in A and B we can have a lot of issues if C e.g is @nestjs/core that has a bunch of optional dependencies.

klingenm avatar Sep 27 '22 07:09 klingenm