-
Notifications
You must be signed in to change notification settings - Fork 609
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
[rush-lib] Fix PreferredVersions
being ignored when projects have overlapping dependencies
#4835
Conversation
Regarding the test cases you mentioned, I do believe we should add these to the test suite, they're valid scenarios. In terms of specifics for each case:
|
@D4N14L thanks for the review! Some news regarding the extra test cases - looks like there was a misunderstanding on my part. It turns out that the
If we wanted to support overlapping SemVer ranges with Based on #1466, it seems like we do want that support. The changes for that might look something like this:
Maintainers - LMK if that change is something you'd want added to this PR. 🙂 |
For a static validator a while back I wrote a semver-compatible range-intersection library, though I didn't have occasion to open-source it. If we end up needing that functionality I can contribute it to rushstack. |
Circling back on this - @D4N14L I met with @octogonz and @iclanton today; they're broadly on board with this PR save for one question. When
In practice, I feel like this is a tradeoff between package freshness and disk space.
Thoughts? |
@ace-n-msft Hmm. So let me write a few things out to help frame this discussion (and to be honest, for myself to re-acclimate to the question at hand 😊):
Referring to the above, the
implicitlyPreferredVersion with the explicit preferredVersion if and only if the explicit preferredVersion is entirely a subset of the implicitlyPreferredVersion . Essentially, this means that:
One side-effect of this is that |
@D4N14L a question we considered in Rush Hour: Should an implicitly preferred version be used to /narrow/ a preferred version? Or should an explicit preferred version always /replace/ it? |
@octogonz I think it should always replace it, as long as it is entirely a subset of the implicit version. This is the logic we follow in the pnpmfile shim, and this would make it consistent. If we want to limit it using the implicit version if it's a partial subset, that could be a future feature, but the base feature should align with what we already do IMO |
Summary
Fixes #3205
This PR changes
rush-lib
to prefer the most-restrictive SemVer range available across bothpreferredVersions
and Rush projects.Details
Motivation
The repos my team works with specify some dependencies on a repo-wide basis. We want these dependencies to be included in each project and the ability to bump repo-wide dependency pins with a single file change.
We tried to solve this by setting the individual project
package.json
files to SemVer ranges (e.g.8.x
or*
) and providing pinned dependency versions in thepreferredVersions
section ofcommon-versions.json
.In the course of testing this approach, we ran into #3205 - hence this PR.
Alternate approach: test isolation
Right now, this PR applies
common/config/rush/*
to all the tests in thelibraries/rush-lib/src/logic/pnpm/test
. This isn't causing any issues right now, but it may need to be refactored if other tests start depending on thecommon/config/rush
directory.If it's worth refactoring this, please let me know.
Alternate approach: conditional
Map
overwritingFor this PR, I needed a mechanism to conditionally overwrite the keys in a
Map
.I was considering modifying the
MapExtensions.mergeFromMap()
function to accept a third parametershouldOverwrite
that would allow an end-user to control when existing keys should be overwritten.Instead, I chose to do a "manual" merge in
PnpmfileConfiguration.ts
using aforEach()
loop.Possible breaking change: conflicting dependency versions across projects
According to the Implicitly Preferred Versions section in the Rush docs, Rush has no specific convention for resolving dependency conflicts between projects.
As such, I wasn't sure if I should add automated tests for that case. Please let me know if I should change this, and what those test cases might look like.
Here are a few (additional) test cases that I thought might be worth implementing:
How it was tested
I've added automated tests for the common cases I could think of and documented some potential edge cases above.
(If those edge cases are things we should test for, I'm 100% onboard with adding automated tests for them as well.)
Impacted documentation
We should consider adding a note to this page explaining that Rush (now) prefers the most specific version of a dependency available.