JamieMason / syncpack

Consistent dependency versions in large JavaScript Monorepos.
https://jamiemason.github.io/syncpack/
MIT License
1.41k stars 49 forks source link

Allow version groups to pin to latest matching version in the group #227

Closed sgarfinkel closed 2 months ago

sgarfinkel commented 3 months ago

Description

The usecase here is for something Lerna packages like Jest, where each subpackage shares the same version. It would be convenient to have a way to say "in this version group, pick the highest version that matches and uses it for all matches". Our specific usecase here is an internal monorepo with several libraries and we'd like to have them all pin to the same version, without needing to manage that pinned version directly in syncpack.

Suggested Solution

See above, all matches in a version group should be, with configuration, able to share the highest version of the matches.

Help Needed

JamieMason commented 3 months ago

I might be misunderstanding you @sgarfinkel but this is what a version group will do by default, if you use eg jest multiple times in that group, syncpack will suggest that you use the highest valid semver version in use from that set.

Another feature that came to mind while reading was a Snapped To version group, which lets packages copy the versions another package uses.

I might be missing something though, let me know 👍

sgarfinkel commented 3 months ago

Hi @JamieMason--maybe I'm misunderstanding things. Suppose the following monorepo:

packages/
  a/
    package.json
  b/
    package.json

If a/package.json has:

{
  "dependencies": {
    "jest": "^5.0.0",
  }
}

And b/package.json has:

{
  "dependencies": {
    "jest-config": "^6.0.0",
  }
}

And my syncpackrc was:

{
  "versionGroups": [
    {
      "packages": ["**"]
      "dependencies": ["jest*"]
    }
  ]
}

Then the expectation is that the jest dependency in a/package.json would get bumped up to ^6.0.0, but in my testing this wasn't happening.

JamieMason commented 3 months ago

Thanks @sgarfinkel, I think I've got you now.

This isn't possible at the moment but is something which has come up before (there might be another open issue I'm not sure).

I think what might be needed is to come up with some kind of merging or aliasing configuration, some way of saying that you want eg jest and jest-config to be treated by syncpack as if they're actually one package – from a version point of view. Their original names would be preserved. but their versions would be combined when being compared.

Let me know if we're thinking of the same thing, and I can stick this on the backlog 👍

sgarfinkel commented 3 months ago

@JamieMason Yup, that sounds exactly like what I'm looking for here!

JamieMason commented 2 months ago

This isn't possible at the moment but is something which has come up before (there might be another open issue I'm not sure).

I think what might be needed is to come up with some kind of merging or aliasing configuration, some way of saying that you want eg jest and jest-config to be treated by syncpack as if they're actually one package – from a version point of view. Their original names would be preserved. but their versions would be combined when being compared.

204 is the issue I was thinking of, I was just reminded of it by a new comment.

I'll close this as a duplicate but it can still be referred to for notes.