renovate icon indicating copy to clipboard operation
renovate copied to clipboard

New versioning: same-major

Open rarkins opened this issue 2 years ago • 1 comments

Describe the proposed change(s).

We have a need in multiple areas to support the concept that a version like X.Y.Z means "Greater than or equal to X.Y.Z and less than X+1". e.g. "1.20.0" means the equivalent of "^1.20.0".

A recent example is https://github.com/renovatebot/renovate/discussions/27296#discussioncomment-8468506

I think we can create a simple versioning based off semver-coerced where every version is a constraint, and satisfies() returns true if the two versions are the same major version.

rarkins avatar Feb 15 '24 10:02 rarkins

Possible use cases:

  • Go.mod directive
  • dotnet rollForward
  • Cargo?

rarkins avatar Feb 15 '24 10:02 rarkins

Checking my understanding.

The new versioning will use existing methods from semver-coerced for functions like isValid, isStable and so on, which do not deal with ranges. For the methods that deal with ranges such as : matches, isLessThanRange, etc.. we will need to treat non-range versions like 1.0.0 as ^1.0.0, and if the version is already a range no change needed.

ie.

function matches( versions, range ) {
     let newRange = range;
     if( rangeIsVersion(range) ) {
         newRange = `^${range}`
     };

     return semver-coerced.matches(versions, newRange);
}

RahulGautamSingh avatar Apr 10 '24 12:04 RahulGautamSingh

I think that "greater than" and "less than" will be simpler primitives than "matches"

rarkins avatar Apr 10 '24 12:04 rarkins