You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Feature]: Update peer dependency versions at publish time #955
When we publish a new version of foo and bar also update of the peerDependency in foo to the latest version.
We should only update the peer dependency on bar if the following conditions are met:
When the peerDependency on bar was an exact version. So "bar": "^0.14 || ^15.0.0" should not be updated, but "bar": "0.5.6" should be updated. Question: what about "bar": "^0.5.6"?
When the foo dependency is being published. i.e. we should not force a release of foo if bar is updated and we're running in independent versioning mode. Question: or should we force it?
That line in PublishCommand would seem to indicate the intention, but I don't see any tests validating it.
Package##dependencies() is being iterated over in PublishCommand##updatePackageDepsObject(), which among other things notably lacks devDependencies. I'm not sure Package##allDependencies() is needed here (it's used in BootstrapCommand and PackageGraph, exclusively), and in any case, that doesn't include peerDependencies.
A test of PublishCommand that makes assertions about sibling peer dependency updates seems in order.
Hmm ok. So it works, but isn't tested or documented. What about my 2 questions?
My opinion:
we might want to update "^0.5.6" as well if bar gets a major update (1.0.0 or 0.6.0), but not if it is only patched to 0.5.7, as 0.5.7 also obeys "^0.5.6".
In the same line, i think we should force a new release of foo if bar is updated to a version that is no longer obeying the peer dependent version of bar.
Its pretty complicated, but i don't see another way that would work for plugin use cases. When releasing new versions, you generally tested that all plugins integrate together (that's one of the reasons to use lerna, easier integration testing). So we should publish new versions where needed to make sure all things work nicely together.
@Shepless As I noted above, there are no tests to validate this assumption, and I don't use peerDependencies very much, myself. So, "maybe"?
@nicojs We've had lots of discussions about when to bump dependent versions, and what it boils down to is this: we always bump because versions are cheap and failures due to missing changes are expensive. It is prohibitively beyond the scope of lerna's responsibilities to statically analyze code and their dependencies to validate that any new features from a given release are (or are not) being used by a given consumer (direct or peer).
Peer dependencies are a weird animal, though, given the strange semver concoctions one tends to see in such fields. Independent versioning adds another layer of complexity, exacerbated by any leniency when deciding what to bump. Tests would be helpful when talking about anything more detailed.
I've done some tests (EDIT: not unit tests, by running lerna publish) and it does indeed bump peerDependencies
@TombolaShepless
The bumping of the peerDependencies seems to only work if it is also a devDependency. Can you confirm that?
You can see the behavior in this commit: stryker-mutator/stryker-js@a7257f6. The peerDependency on "stryker" in "grunt-stryker" did not update, but the peerDependency on "stryker-api" in "stryker" did.
Reacted by Dmitriy Pushkov, Owen Buckley and Fujita Hitoshi
In my project I have peerDeps with no corresponding devDeps. We found it error-prone to set both correctly when adding new deps, since less-experienced devs weren't sure when things had to be peerDeps or not. Cross-linking packages at dev time still works via Webpack aliases.
It seems strange to me that peerDeps sometimes get updated, but only when they also happen to be another type of dep. Wouldn't it make more sense to update either always or never?
peer deps should never be forcefully updated; updating a minimum peer dep range is a breaking change. Peer dep ranges should always remain as broad as is possible.
Reacted by Miroslav Bajtoš, Fujita Hitoshi and Zim
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
I don't see peerDependencies update even if corresponding devDependencies exists, and I believe peers should be updated on minor versions, one may rely on a new feature introduced in a minor version, a previous version of peer can possibly break.
There's an easier edge-case I would like here, which is if the peer dependency is linked with file:../mypackage then we should just write this to the current known version of that package.
I've been working on the use case of a Lerna repo with multiple packages that contain peer dependencies with the intention that the versions of all packages are maintained at the same level and all packages are published together. In my case the peer dependency is expressed using the "file:" protocol. The code change in this case seems quite simple and I have successfully tried it using verdaccio. Is this appropriate to this issue and would such a PR be interesting to the Lerna maintainers?
Activity
evocateur commentedon Aug 4, 2017
That line in PublishCommand would seem to indicate the intention, but I don't see any tests validating it.
Package##dependencies() is being iterated over in PublishCommand##updatePackageDepsObject(), which among other things notably lacks
devDependencies. I'm not surePackage##allDependencies()is needed here (it's used inBootstrapCommandandPackageGraph, exclusively), and in any case, that doesn't includepeerDependencies.A test of PublishCommand that makes assertions about sibling peer dependency updates seems in order.
nicojs commentedon Aug 4, 2017
Hmm ok. So it works, but isn't tested or documented. What about my 2 questions?
My opinion:
"^0.5.6"as well ifbargets a major update (1.0.0or0.6.0), but not if it is only patched to0.5.7, as0.5.7also obeys"^0.5.6".fooifbaris updated to a version that is no longer obeying the peer dependent version ofbar.Its pretty complicated, but i don't see another way that would work for plugin use cases. When releasing new versions, you generally tested that all plugins integrate together (that's one of the reasons to use lerna, easier integration testing). So we should publish new versions where needed to make sure all things work nicely together.
Shepless commentedon Aug 17, 2017
@evocateur So just to clarify - does lerna bump the peerDependencies between packages?
evocateur commentedon Aug 17, 2017
@Shepless As I noted above, there are no tests to validate this assumption, and I don't use
peerDependenciesvery much, myself. So, "maybe"?@nicojs We've had lots of discussions about when to bump dependent versions, and what it boils down to is this: we always bump because versions are cheap and failures due to missing changes are expensive. It is prohibitively beyond the scope of lerna's responsibilities to statically analyze code and their dependencies to validate that any new features from a given release are (or are not) being used by a given consumer (direct or peer).
Peer dependencies are a weird animal, though, given the strange semver concoctions one tends to see in such fields. Independent versioning adds another layer of complexity, exacerbated by any leniency when deciding what to bump. Tests would be helpful when talking about anything more detailed.
TombolaShepless commentedon Aug 17, 2017
@evocateur I've done some tests (EDIT: not unit tests, by running
lerna publish) and it does indeed bumppeerDependenciesevocateur commentedon Aug 17, 2017
@TombolaShepless I would definitely accept a PR for those unit tests, if they exist. ;)
TombolaShepless commentedon Aug 17, 2017
I'll see what I can do :)
nicojs commentedon Aug 18, 2017
@TombolaShepless
The bumping of the peerDependencies seems to only work if it is also a
devDependency. Can you confirm that?You can see the behavior in this commit: stryker-mutator/stryker-js@a7257f6. The
peerDependencyon "stryker" in "grunt-stryker" did not update, but thepeerDependencyon "stryker-api" in "stryker" did.TombolaShepless commentedon Aug 18, 2017
@nicojs confirmed it also does this for me, but I have my
peerDependencies"paired" up withdevDependenciesfor testing purposes.nicojs commentedon Aug 18, 2017
Ok, this is probably by design than? In that case we will add the devDependency. It isn't a lot of work and fixes this issue for us.
smrq commentedon Aug 29, 2017
In my project I have peerDeps with no corresponding devDeps. We found it error-prone to set both correctly when adding new deps, since less-experienced devs weren't sure when things had to be peerDeps or not. Cross-linking packages at dev time still works via Webpack aliases.
It seems strange to me that peerDeps sometimes get updated, but only when they also happen to be another type of dep. Wouldn't it make more sense to update either always or never?
nicojs commentedon Aug 30, 2017
In that case, I would prefer for them to always update.
ljharb commentedon Sep 26, 2017
peer deps should never be forcefully updated; updating a minimum peer dep range is a breaking change. Peer dep ranges should always remain as broad as is possible.
stale commentedon Dec 27, 2018
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
10 remaining items
simllll commentedon Sep 14, 2019
Lot o time has passed since this issue has been opened, any working workaround out there? Or how do you cope with that? Thanks
vipcxj commentedon Nov 6, 2019
I have to face the same issue. And I come here to prevent the crazy bot to close this old issue. I hope it will be resolved in my life.
otakustay commentedon Sep 10, 2020
I don't see
peerDependenciesupdate even if correspondingdevDependenciesexists, and I believe peers should be updated on minor versions, one may rely on a new feature introduced in a minor version, a previous version of peer can possibly break.ljharb commentedon Sep 10, 2020
@otakustay relying on that new feature is in itself a breaking change, so in that case your library needs a semver-major bump.
Quenty commentedon Sep 5, 2021
There's an easier edge-case I would like here, which is if the peer dependency is linked with
file:../mypackagethen we should just write this to the current known version of that package.zimtsui commentedon Mar 10, 2023
peer deps should be bumped if the command you invoke is already
lerna version major.geometryzen commentedon May 16, 2024
I've been working on the use case of a Lerna repo with multiple packages that contain peer dependencies with the intention that the versions of all packages are maintained at the same level and all packages are published together. In my case the peer dependency is expressed using the "file:" protocol. The code change in this case seems quite simple and I have successfully tried it using verdaccio. Is this appropriate to this issue and would such a PR be interesting to the Lerna maintainers?
chore: add design-tokens as dev dependency for Lerna updates (#11990)
chore: add design-tokens as dev dependency for Lerna updates (#11990)
JamesHenry commentedon Mar 16, 2026
Hi Folks, I'll close this old one as having been addressed by #4203. Many thanks!