semver icon indicating copy to clipboard operation
semver copied to clipboard

feat: Implement MinVersion() for Constraints.

Open taeold opened this issue 2 years ago • 0 comments

MinVersion() returns return the lowest version that can possibly match the given constraint.

For examples:

  • MinVersion("1.0.1") = "1.0.1"
  • MinVersion("=1.0.1") = "1.0.1"
  • MinVersion("~1.0.1") = "1.0.1"
  • MinVersion(">1.0.1") = "1.0.2"
  • MinVersion(">=1.0.1") = "1.0.1"
  • MinVersion("<2.0.0 >1.0.1") = "1.0.2"

etc.

The implementation is based on node-semver:

https://github.com/npm/node-semver/blob/main/ranges/min-version.js

One minor difference is how prerelease versions are treated given >:

  • In node-semver, MinVersion(">1.0.0-beta') = "1.0.0-beta.0"
  • In the proposed impl, MinVersion(">1.0.0-beta') = "1.0.0"

This behavior made more sense to me given how Version("1.0.0-beta").IncPatch() behaves.

taeold avatar Dec 16 '23 17:12 taeold