-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Inherit peer dependency ranges from your own dependencies. #3
Comments
This is essentially how DefinitelyTyped "implements" its peer dependencies. It actually generates Yarn currently just always treats I do think that these should be specified as |
What's the recommendation here, when I encounter a package that hasn't re-declared peerDependencies of its dependencies, should I raise an issue with the author to add those peerDependencies in? Should they copy the version across, or just use Also, is there a way to use resolutions in Yarn 2 to work around the problem temporarily while waiting for upstream packages to be patched and released? |
On the flipside if that dependency changes it's peer dependency version it's a breaking change for my library as well. So if I bump the major of that dependency I would have to release a major as well. If the peer is just "inherit" it's not obvious what the breaking change is because a new major of a dependency doesn't necessarily mean it's a breaking change for my library (e.g. when it's only used internally). While this is a bit annoying now because it adds churn to the ecosystem it might actually be a healthy change in the long term with regard to SemVer. |
Yarn treats
I'd advise the affected packages to simply list the same range as the library they depend on. Worst case scenario they'll get some warnings if their dependency is updated, by which point whether they want to expand their own range or restrict the version of their dependency to keep the peer dependency in sync with their own.
Not with
Yep, maybe 🤔 I think we'll see whether there's an ask for this feature before considering implementing it. So far maintainers I've spoke with were fairly understanding. |
A possible way of dealing with the |
FWIW what I do in yarn 1 for this is run yarn-deduplicate after every time I install a new package. The yarn docs say It is annoying and would be great if yarn did actually deduplicate by default, but the idea of needing to do a "second pass" afterwards to deduplicate doesn't bother me too much. If it was baked in as a |
Quick note: I think we're going off-topic here. This issue is about inheritable peer dependency ranges. The We may do a dedupe pass later, but DefinitelyTyped is still definitely using incorrect semantics, and I won't act based on their experience alone. For the record, between this topic, this other topic, this article, and various sub-issues I can't find, I wrote more than 15,000 symbols just about this. Everything is documented, including the proper fix. I don't want to add new semantic constraints to package managers just because one project used them wrong and noone else wants to deal with fixing it. |
@arcanis Is it possible to consider not listing anything as inheriting? Maybe make this an option in the rc file? I've successfully changed the Project.ts locally to do just this with only a few lines and wanted to get your thoughts before opening a PR. The only downside is a package may be less explicit. However, does adding a peerDependency entry and making it optional provide that much value? The information has the potential to become stale if the peer dependency is removed (which can possibly be a minor change in semver). Also, the typical use case (for me at least) is to look at a packages dependencies, verify i'm happy with them and do a add/install. If any warnings show, which they would if the peer still isn't satisfied, i handle those appropriately. |
@lroling8350 sharing is caring |
Shouldn't this proposed behavior be automatic when no peer dependency is specified by a parent? Or does this break some expectation of PnP? It seems feasible for Yarn to use the entire ancestor list for satisfying peer dependencies rather than the immediate parent. I think this is what @lroling8350 is proposing. So far, most of my Below is a basic scenario where this automatic behavior is useful (the Storybook repo is full of these) Consider the following packages
When inspecting
Now consider a new project that depends on
This configuration would allow |
No - on top of being algorithmically difficult to implement (it's easier with nm because nm has limitations that make certain scenarios non-problems because they can't be supported in the first place), it would also prevent various very convenient assumptions (like "a package without peer dependencies will only ever be instantiated once"), which would have far-reaching effects. I understand it may look easy (and I myself made a few attempts to rethink this, trying to see whether it was just me being stubborn), but my final conclusion is that implicit inheritance of peer dependencies is an antipattern that only provides some convenience at the cost of soundness and maintainability (as in, maintenance of a package manager). Given that:
Given those two parameters I don't feel too bad not implementing this shortcut. Still, if someone wants to prove me wrong I'd certainly review a PR - but I believe this will be a difficult endeavor, and as such it's unlikely I'll spend further time investigating this. |
I'm also going to close this issue because Yarn now supports range aggregates¹, which solves the initial use case of this thread (ie "explicitly opt-in to a peer dep, but inherit the peer dependency range from the children"). ¹ If a package A lists, say, |
IMO this doesn't quite solve the problem either. If the package (call it "A") doesn't actually need the peer dependency ("P") at all and is just forwarding it for its dependency ("B") [and puts peerDependency |
Describe the user story
I'm a package author, and my package depends on another package which has a peer dependency on
react
. Since I don't want to provide this package I must indicate that my own package has a peer dependency onreact
, but I also need to convey that the requiredreact
version simply is the same one has the one requested by my dependency. I currently have to manually copy it, which is error-prone since it won't be automatically updated when my dependency is upgraded and starts using a different range.Describe the solution you'd like
Yarn should support a new special range specifier for peer dependencies:
inherit
. Wheninherit
is specified, the peer dependency will automatically become the union of all the ranges of the matching peer dependencies of dependencies of the package.Describe the drawbacks of your solution
From a technical standpoint it can be seen as making a parent depend on its children (since the exact peer dependency will only be resolvable if the children are available). In practice this shouldn't be a problem though, because the peer dependencies aren't taken into account until after the dependency tree has been computed (because they are a non-binding suggestion that the user is responsible for getting right).
The
inherit
range keyword will not be properly understood by lower Yarn versions, which might cause some warnings to appear in such cases. Given that only the packages that deemed this feature useful enough to warrant the potential warning will be affected I don't think it's a blocker.Describe alternatives you've considered
Instead of an
inherit
keyword the*
range could be repurposed. I'm afraid this would be a surprising change, and it would wildly break the semver expectations.Instead of encoding the inherit status into the range, it could be moved into the
peerDependenciesMeta
field. This would mean that the range described in thepeerDependencies
field would have no actual impact, which would be quite unexpected. I believe the range is where this feature has the most sense semantically speaking.The text was updated successfully, but these errors were encountered: