Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] install peer dependencies for packages #3710

Closed
1 of 2 tasks
mmahalwy opened this issue Nov 9, 2021 · 2 comments
Closed
1 of 2 tasks

[Feature] install peer dependencies for packages #3710

mmahalwy opened this issue Nov 9, 2021 · 2 comments
Labels
enhancement New feature or request

Comments

@mmahalwy
Copy link

mmahalwy commented Nov 9, 2021

  • I'd be willing to implement this feature (contributing guide)
  • This feature is important to have in this repository; a contrib plugin wouldn't do

Describe the user story
Package authors/maintainers who specify peerDependencies often have to include the same package as a devDependency for testing, editors seeing types and more. While this is a workaround that works, often the versions can have a mismatch (peer: 3.x while dev can be 3.5 and the consumer would have 3.7).

npm 7 and npm 8 support installing peer dependencies automatically.

The goal of this feature is to implement the same

Describe the solution you'd like

Automatically install dependencies listed in peerDependencies in package.json. This is NOT installing the peers for a package (ie react-select).

Describe the drawbacks of your solution

There can be confusion where consumers think this would install all peer dependencies of libraries listed in their package.json. This is not the case. This only solves installing the packages in peerDependencies for the current package.json.

Describe alternatives you've considered

As described above, a workaround is to specify the peerDependencies and devDependencies.
Another is this package: https://www.npmjs.com/package/install-peers. This only worked with a fresh install of node_modules

@mmahalwy mmahalwy added the enhancement New feature or request label Nov 9, 2021
@mmahalwy mmahalwy changed the title [Feature] install peer dependencies [Feature] install peer dependencies for packages Nov 9, 2021
@arcanis
Copy link
Member

arcanis commented Nov 9, 2021

  1. Peer dependencies apply on the resolved dependency ranges, and don't determine fetches. This is significant, because peer dependency ranges can only be semver (and thus any "auto install" with this syntax would only be possible with the default registry, quite convenient...).
  2. A change like this would be a breaking change, and unlike npm we don't believe it's impactful enough to be worth the cost.
  3. We already told npm we believed this change was going the wrong way and we wouldn't support/implement it under the form they tried to enforce. This position didn't change.

With that being said, Yarn supports "peer dependencies with defaults": if you list a dependency as both a peer and regular dependency, Yarn will use the parent-provided dependency, but will fallback to the regular one if missing. Pnpm supports it too, and I believe even npm supports that somewhat accidentally due to how their "auto-installs" work.

@arcanis arcanis closed this as completed Nov 9, 2021
@arcanis
Copy link
Member

arcanis commented Nov 9, 2021

Also note that for the "keep the ranges in sync between peer and dev", "enforce that peers have a dev counterpart", etc use cases, the recommended solution would generally be to use constraints.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants