wasp icon indicating copy to clipboard operation
wasp copied to clipboard

Semantic version advanced

Open Martinsos opened this issue 3 years ago • 1 comments

Trying out an approach to follow node semver spec correctly for the special ranges.

Martinsos avatar Jun 17 '22 17:06 Martinsos

@sodic @shayneczyzewski @matijaSos I was very curious as to what would the improved Semantic Version solution look like, where special comparators like ^ are recognized as such in our code, so I gave it a try and this is what came out of it! What do you think? It seems to me it looks okish in this state. Further step could be to add quasiquoters that parse actual semver strings into our structures in SemanticVersion.hs during compile time, that would be the cherry on top if this was to be full blown library.

Martinsos avatar Jun 17 '22 19:06 Martinsos

I was playing around with @shayneczyzewski's idea and took it a step further. I got the thing working so I can even send you the code or update it myself if you decide it makes sense.

The main idea is to get rid of the types SpecialComparator and PrimitiveComparator altogether by changing the comparator type to this:

data Comparator
  = PrimitiveComparator Operator Version
  | Caret Version
  -- Here's where we'd put other special comparators in the future
  deriving (Eq)

And update the rest of the function accordingly. I won't list them all to avoid making the comment too long, but here's the most important one:

doesVersionSatisfyComparator :: Version -> Comparator -> Bool
doesVersionSatisfyComparator version (Caret refVersion) =
  all
    (doesVersionSatisfyComparator version)
    [ PrimitiveComparator GreaterThanOrEqual refVersion,
      PrimitiveComparator LessThan (nextBreakingChangeVersion refVersion)
    ]
doesVersionSatisfyComparator version (PrimitiveComparator operator compVersion) =
  case operator of
    Equal -> version == compVersion
    LessThan -> version < compVersion
    LessThanOrEqual -> version <= compVersion
    GreaterThan -> version > compVersion
    GreaterThanOrEqual -> version >= compVersion

This change allows us to delete a lot of code and makes the implementation easier to understand IMO. doesVersionSatisfyPrimitiveComparatorSet, comparatorSetToPrimitiveComparatorSet, comparatorToPrimitiveComparatorSet, specialComparatorToPrimitiveComparatorSet and several instance definitions would all go out the window, and other functions would become a bit shorter.

sodic avatar Aug 26 '22 09:08 sodic

@sodic let's do it, pls push!

Martinsos avatar Aug 26 '22 13:08 Martinsos