Skip to content

Clarify vers representation of Elixir ~> range with pre-release semantics #49

Description

@maennchen

In Elixir, SemVer version requirements may use the ~> operator.

Examples (naive translation):

  • ~> 0.1 → >= 0.1.0, < 1.0.0
  • ~> 0.1.5 → >= 0.1.5, < 0.2.0

Ref: https://hexdocs.pm/elixir/Version.html#module-requirements

However, because pre-release versions (e.g. -alpha, -beta, etc.) are ordered before their corresponding release version, these translations are not accurate.

Example:

iex> Version.match?("0.2.0-alpha.7", "~> 0.1.5")
false

iex> Version.match?("0.2.0-alpha.7", ">= 0.1.5 and <= 0.2.0")
true

iex> Version.compare("0.2.0-alpha.7", "0.2.0")
:lt

Therefore:

~> 0.1.5 ≠ >= 0.1.5, < 0.2.0

How should ~> be represented in vers, considering pre-release ordering semantics?

I believe this also affects the ^ operator in NPM:

{
"description": "Construct VERS range from native npm range.",
"test_group": "advanced",
"test_type": "from_native",
"input": {
"native_range": "^2.0.18 || ^3.0.16 || ^3.1.6 || ^4.0.8 || ^5.0.0-beta.5",
"scheme": "npm"
},
"expected_output": "vers:npm/>=2.0.18|<3.0.0|>=3.0.16|>=3.1.6|<4.0.0|<4.0.0|>=4.0.8|>=5.0.0-beta.5|<5.0.0|<6.0.0"
},

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions