New versioning: same-major
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.
Possible use cases:
- Go.mod directive
- dotnet rollForward
- Cargo?
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);
}
I think that "greater than" and "less than" will be simpler primitives than "matches"