Skip to content
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

Add 'node-semver' version range comparison functions #18

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

McSherry
Copy link
Owner

Under node-semver, it's possible to compare a version range against a semantic version to determine more than just whether the version range is satisfied. Similarly, version ranges can be compared and operated on with each other. Supporting this in McSherry.SemanticVersioning seems beneficial as it maintains parity with node-semver on version ranges.

The functions are:

  • outside / gtr / ltr — comparisons to determine whether a semantic version is outwith the range covered by the version range

  • intersects — determines whether two version ranges overlap

  • subset — determines whether one version range entirely includes another

Something to review in doing this will be changes to the node-semver version range specification. At present, we claim compatibility with v6.0.0, but node-semver is now on v7.3.2. Revising our claim to a later version is just good housekeeping.

@McSherry McSherry added the enhancement A new feature addition. label May 24, 2020
@McSherry McSherry added this to the 1.4.0 milestone May 24, 2020
@McSherry McSherry self-assigned this May 24, 2020
The way [VersionRange] comparators were structured before, not enough
information was retained for [CompareTo] to work without effectively
repeating the implementations of the comparators. Broadly, changes in
this commit restructure [VersionRange] to hold necessary information.

More specifically, this commit:

 o Adds [SemanticVersion.MaxValue] and [MinValue] fields, with their
   documentation.

 o Adds [IComparable<SemanticVersion>] to the [IComparator] internal
   interface, allowing comparators to provide their own methods that
   the higher-level [VersionRange.CompareTo] can defer to.

 o Adds a [ContiguousComparator] class from which [UnaryComparator]
   and [BinaryComparator] derive, providing a common implementation
   where almost every comparator (except 'less than' and 'greater
   than') is decomposed into an inclusive range 'm <= x <= n'.

 o For 'less than' and 'greater than' comparators, adds a special
   class [ComparatorShell], which takes delegates to implement the
   [IComparator] interface in these two special cases.

The effect of this on performance will probably be minimal. The worst
contributor will be the introduction of an abstract class, but apart
from this roughly the same number of objects are created as before.

This commit knowingly breaks the following tests:

 o [RangeIntlParsingTests.BasicIdentification]

 o [RangeIntlParsingTests.MultipleComparatorParsing]

 o [RangeIntlParsingTests.MultipleSetParsing]

These tests rely on inspecting hidden implementation detail in the
instances of [IComparator] returned, using it to directly verify the
output of the parser (rather than relying on functionality tests). It
may be reasonable to delete these tests as functionality tests should
indirectly verify the same behaviour.
This implementation passes many tests (156 of 234). Of those that it
doesn't pass, all but 3 appear related to issues #19 and #20.

Two of those three are surprising. They are:

 o '0.7.2-beta' > '0.7.x'

 o '1.3.0-alpha' < '>1.2.3'

These are tests taken directly from 'node-semver', and at the moment
they don't make sense to me. To start with, I would have said that it
isn't possible for both to be true at once.

Following on, '0.7.x' ---> '>=0.7.0 <0.8.0', and so '0.7.2-beta' does
not seem like it should be greater (because it is lower in precedence
than '0.8.0'). The code in this commit produces a result that says as
much, which is the result I would expect.

For the second case, the Semantic Versioning spec says precedence is
based on the first difference evaluating two versions left-to-right
which, if you ask me, is the minor version. Although '1.3.0-alpha' is
a pre-release version, its minor version is above '1.2.3' and so it
should have higher precedence. As '>1.2.3' includes anything with a
precedence higher than '1.2.3', versions with a higher precedence
than '1.3.0-alpha' will be matched and so I would expect comparison
to say 'neither greater nor lesser', i.e. 0. This is the result that
this code gives, but the 'node-semver' tests say otherwise.

It might be worth raising an issue with 'node-semver'.
@McSherry McSherry removed this from the 1.4.0 milestone Jun 4, 2020
@McSherry
Copy link
Owner Author

McSherry commented Jun 4, 2020

Until the situation 5a48a1c mentions is resolved, this feature is on hold (and so won't be included in the v1.4.0 release unless things change soon).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement A new feature addition.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant