Skip to content

[QUESTION] Inconsistent definition of version prefix #690

Closed

Description

@mbtools

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

The readme contains the following about "Versions":

"A leading "=" or "v" character is stripped off and ignored."

Currently, 1.2.3 and v1.2.3 are valid versions. However, =1.2.3 is not a valid version (it is a valid equal-range).

node-semver/internal/re.js

Lines 115 to 117 in ac9b357

createToken('FULLPLAIN', `v?${src[t.MAINVERSION]
}${src[t.PRERELEASE]}?${
src[t.BUILD]}?`)

Expected Behavior

"=" should be added as a valid prefix for versions.

Versions inside a range allow "=", "v", and "v=" as prefixes (see #689). It therefore makes sense to allow the same for individual versions.

Suggested change (after #689):

createToken('FULLPLAIN', `v?${src[t.MAINVERSION]}${src[t.PRERELEASE]}?${src[t.BUILD]}?`) // old
createToken('FULLPLAIN', `${src[t.PREFIX]}${src[t.MAINVERSION]}${src[t.PRERELEASE]}?${src[t.BUILD]}?`) // new

Steps To Reproduce

valid('1.2.3') // 1.2.3
valid('v1.2.3') // 1.2.3
valid('=1.2.3') // null
valid('v=1.2.3') // null

Environment

  • node-semver: 7.6.0

Activity

  1. wraithgar commented on Mar 20, 2024

    @wraithgar
    Contributor

    The reason v is removed has more to do w/ how this module grew up alongside npm itself than anything else. Folks would include that in their package.json for the version field. This was mostly due to the fact that npm added the v when outputting the version to the console, and also because it was added to the git tag for a given version.

    =/v= does not have that same history so there is no need to support it. We are trying to move away from "helpfully" altering user data, and instead erroring and having them fix it. Guessing what the user wanted leads to unforeseen bugs.

  2. mbtools commented on Mar 20, 2024

    @mbtools
    ContributorAuthor

    I fully agree with supporting just v

    But a) The readme says otherwise, and b) with a range it support =/v= (and crap like vv==v) as well.

    I'm happy to update the docs and #689 to allow only a single, optional v in ranges but that's probably a breaking-change. Just comment on #689.

  3. wraithgar commented on Mar 20, 2024

    @wraithgar
    Contributor

    Oh by all means let's make the docs reflect reality! Thanks for all the recent PRs.

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

    Bugthing that needs fixingNeeds Triageneeds an initial review

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions