Skip to content

[Feature]: Update peer dependency versions at publish time #955

Closed

Description

@nicojs

Given this package structure:

root
| -- packages
     | -- foo
     | -- bar

And bar is a peerDependency of foo.

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?

Edit: Is this feature already implemented? https://github.com/lerna/lerna/blob/master/src/commands/PublishCommand.js#L452

Activity

  1. evocateur commented on Aug 4, 2017

    @evocateur
    Member

    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.

  2. nicojs commented on Aug 4, 2017

    @nicojs
    Author

    Hmm ok. So it works, but isn't tested or documented. What about my 2 questions?

    My opinion:

    1. 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".
    2. 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.

  3. Shepless commented on Aug 17, 2017

    @Shepless

    @evocateur So just to clarify - does lerna bump the peerDependencies between packages?

  4. evocateur commented on Aug 17, 2017

    @evocateur
    Member

    @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.

  5. TombolaShepless commented on Aug 17, 2017

    @TombolaShepless

    @evocateur I've done some tests (EDIT: not unit tests, by running lerna publish) and it does indeed bump peerDependencies

  6. evocateur commented on Aug 17, 2017

    @evocateur
    Member

    @TombolaShepless I would definitely accept a PR for those unit tests, if they exist. ;)

  7. TombolaShepless commented on Aug 17, 2017

    @TombolaShepless

    I'll see what I can do :)

  8. nicojs commented on Aug 18, 2017

    @nicojs
    Author

    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.

  9. TombolaShepless commented on Aug 18, 2017

    @TombolaShepless

    @nicojs confirmed it also does this for me, but I have my peerDependencies "paired" up with devDependencies for testing purposes.

  10. nicojs commented on Aug 18, 2017

    @nicojs
    Author

    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.

  11. smrq commented on Aug 29, 2017

    @smrq

    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?

  12. nicojs commented on Aug 30, 2017

    @nicojs
    Author

    In that case, I would prefer for them to always update.

  13. ljharb commented on Sep 26, 2017

    @ljharb

    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.

  14. stale commented on Dec 27, 2018

    @stale

    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.

  15. 10 remaining items

  16. simllll commented on Sep 14, 2019

    @simllll
    Contributor

    Lot o time has passed since this issue has been opened, any working workaround out there? Or how do you cope with that? Thanks

  17. vipcxj commented on Nov 6, 2019

    @vipcxj

    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.

  18. otakustay commented on Sep 10, 2020

    @otakustay

    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.

  19. ljharb commented on Sep 10, 2020

    @ljharb

    @otakustay relying on that new feature is in itself a breaking change, so in that case your library needs a semver-major bump.

  20. Quenty commented on Sep 5, 2021

    @Quenty

    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.

  21. zimtsui commented on Mar 10, 2023

    @zimtsui

    peer deps should be bumped if the command you invoke is already lerna version major.

  22. geometryzen commented on May 16, 2024

    @geometryzen
    Contributor

    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?

  23. JamesHenry commented on Mar 16, 2026

    @JamesHenry
    Member

    Hi Folks, I'll close this old one as having been addressed by #4203. Many thanks!

  24. locked as resolved and limited conversation to collaborators on Mar 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions