GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [BUG] 7.6.0 --> 7.7.0 inc behavior change · Issue #763 · npm/node-semver

[BUG] 7.6.0 --> 7.7.0 inc behavior change #763

New issue
Copy link
New issue
Copy link
Closed
#764
Closed
[BUG] 7.6.0 --> 7.7.0 inc behavior change#763
#764
Copy link
Assignees
wraithgar
Labels
Bugthing that needs fixingNeeds Triageneeds an initial review

Description

@danchurch-alphasights
danchurch-alphasights
opened on Feb 1, 2025
Issue body actions

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

We use auto in our CI to manage our versioning.

For canary releases, Auto uses a version format of <version>-canary.<pr#>.<hash>

We started to see our CI randomly failing (based on commit hash or build hash) the last few days with the following error:

Error: Running command 'npx' with args [lerna, publish, prepatch, --dist-tag, canary, --registry, <REDACT>, --yes, --no-git-reset, --no-git-tag-version, --exact, --no-verify-access, --preid, canary.661.2207bf7] failed


Changes:
 - <REDACT>: 0.127.2 => null
 - <REDACT>: 0.35.0 => null

...

lerna ERR! Cannot read properties of null (reading 'trim')
lerna ERR! errno "undefined" is not a valid exit code - exiting with code 1

After digging deep into Lerna / Auto, I found out the root cause was due to a change of the semver package between 7.6.0 and 7.7.0

semver.inc('1.0.0', 'prepatch', 'canary.661.2207bf') semver.valid('1.0.1-canary.661.2207bf.0')
7.6.0 1.0.1-canary.661.2207bf.0 1.0.1-canary.661.2207bf.0
7.7.0 null 1.0.1-canary.661.2207bf.0

Expected Behavior

I would expect semver.inc('1.0.0', 'prepatch', 'canary.661.2207bf') to continue to return a valid value or semver.valid('1.0.1-canary.661.2207bf.0') to return null

Steps To Reproduce

npm i [email protected] --save-exact

node -e "console.log(require('semver').inc('1.0.0', 'prepatch', 'canary.661.2207bf'));"
1.0.1-canary.661.2207bf.0

npm i [email protected] --save-exact

node -e "console.log(require('semver').inc('1.0.0', 'prepatch', 'canary.661.2207bf'));"
null

npm i [email protected] --save-exact

node -e "console.log(require('semver').valid('1.0.1-canary.661.2207bf.0'));"
1.0.1-canary.661.2207bf.0

Environment

  • npm: 8.3.1
  • Node: v16.14.0
  • OS: Mac Sonoma 14.7.2
  • platform: darwin
Reacted by Rodrigo Lungui and Aimee Gamble-Milner

Activity

  1. danchurch-alphasights
    added
    Bugthing that needs fixing
    Needs Triageneeds an initial review
    on Feb 1, 2025
  2. wraithgar commented on Feb 3, 2025

    @wraithgar
    wraithgar
    on Feb 3, 2025
    Contributor
    More actions

    Looks like there's something unexpected going on w/ our regexes. Both the Semver class constructor and .inc use the same regex to validate prereleases. This should work, and finding out why it doesn't is the next step.

    constructor:

        const m = version.trim().match(options.loose ? re[t.LOOSE] : re[t.FULL])
    
        if (!m) {
          throw new TypeError(`Invalid Version: ${version}`)
        }

    inc:

          // Avoid an invalid semver results
          if (identifier) {
            const match = `-${identifier}`.match(this.options.loose ? re[t.PRERELEASELOOSE] : re[t.PRERELEASE])
            if (!match || match[1] !== identifier) {
              throw new Error(`invalid identifier: ${identifier}`)
            }
          }

    regex:

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

    re[t.FULL]:

    /^v?(0|[1-9]\d{0,256})\.(0|[1-9]\d{0,256})\.(0|[1-9]\d{0,256})(?:-((?:0|[1-9]\d{0,256}|\d{0,256}[a-zA-Z-][a-zA-Z0-9-]{0,250})(?:\.(?:0|[1-9]\d{0,256}|\d{0,256}[a-zA-Z-][a-zA-Z0-9-]{0,250}))*))?(?:\+([a-zA-Z0-9-]{1,250}(?:\.[a-zA-Z0-9-]{1,250})*))?$/

    re[t.PRERELEASE]:

    /(?:-((?:0|[1-9]\d{0,256}|\d{0,256}[a-zA-Z-][a-zA-Z0-9-]{0,250})(?:\.(?:0|[1-9]\d{0,256}|\d{0,256}[a-zA-Z-][a-zA-Z0-9-]{0,250}))*))/

    regex is doing something unexpected here.

    re.PRERELEASE

    > '-canary.661.2207bf'.match(/(?:-((?:0|[1-9]\d{0,256}|\d{0,256}[a-zA-Z-][a-zA-Z0-9-]{0,250})(?:\.(?:0|[1-9]\d{0,256}|\d{0,256}[a-zA-Z-][a-zA-Z0-9-]{0,250}))*))/)
    [
      '-canary.661.2207',
      'canary.661.2207',
      index: 0,
      input: '-canary.661.2207bf',
      groups: undefined
    ]
    > 

    You'll see it's truncating the bf from the end of the prerelease id.

    re.FULL

    > '1.0.0-canary.661.2207bf'.match(/^v?(0|[1-9]\d{0,256})\.(0|[1-9]\d{0,256})\.(0|[1-9]\d{0,256})(?:-((?:0|[1-9]\d{0,256}|\d{0,256}[a-zA-Z-][a-zA-Z0-9-]{0,250})(?:\.(?:0|[1-9]\d{0,256}|\d{0,256}[a-zA-Z-][a-zA-Z0-9-]{0,250}))*))?(?:\+([a-zA-Z0-9-]{1,250}(?:\.[a-zA-Z0-9-]{1,250})*))?$/)
    [
      '1.0.0-canary.661.2207bf',
      '1',
      '0',
      '0',
      'canary.661.2207bf',
      undefined,
      index: 0,
      input: '1.0.0-canary.661.2207bf',
      groups: undefined
    ]

    But it's not here.

    It appears that when t.PREELEASE is being rolled into t.FULL something is altering its behavior. Some regex digging is in order now.

  3. wraithgar commented on Feb 3, 2025

    @wraithgar
    wraithgar
    on Feb 3, 2025
    Contributor
    More actions

    1a is a much simpler prerelease identifier that reproduces the same bug.

    > '-1a'.match(/(?:-((?:0|[1-9]\d{0,256}|\d{0,256}[a-zA-Z-][a-zA-Z0-9-]{0,250})(?:\.(?:0|[1-9]\d{0,256}|\d{0,256}[a-zA-Z-][a-zA-Z0-9-]{0,250}))*))?/)
    [ '-1', '1', index: 0, input: '-1a', groups: undefined ]
    
    > '1.0.0-1a'.match(/^v?(0|[1-9]\d{0,256})\.(0|[1-9]\d{0,256})\.(0|[1-9]\d{0,256})(?:-((?:0|[1-9]\d{0,256}|\d{0,256}[a-zA-Z-][a-zA-Z0-9-]{0,250})(?:\.(?:0|[1-9]\d{0,256}|\d{0,256}[a-zA-Z-][a-zA-Z0-9-]{0,250}))*))?(?:\+([a-zA-Z0-9-]{1,250}(?:\.[a-zA-Z0-9-]{1,250})*))?$/)
    [
      '1.0.0-1a',
      '1',
      '0',
      '0',
      '1a',
      undefined,
      index: 0,
      input: '1.0.0-1a',
      groups: undefined
    ]
  4. wraithgar commented on Feb 3, 2025

    @wraithgar
    wraithgar
    on Feb 3, 2025
    Contributor
    More actions

    Solved: the ^ and $ are load bearing.

    > '-1a'.match(/(?:-((?:0|[1-9]\d{0,256}|\d{0,256}[a-zA-Z-][a-zA-Z0-9-]{0,250})(?:\.(?:0|[1-9]\d{0,256}|\d{0,256}[a-zA-Z-][a-zA-Z0-9-]{0,250}))*))?/)
    [ '-1', '1', index: 0, input: '-1a', groups: undefined ]
    > '-1a'.match(/^(?:-((?:0|[1-9]\d{0,256}|\d{0,256}[a-zA-Z-][a-zA-Z0-9-]{0,250})(?:\.(?:0|[1-9]\d{0,256}|\d{0,256}[a-zA-Z-][a-zA-Z0-9-]{0,250}))*))?$/)
    [ '-1a', '1a', index: 0, input: '-1a', groups: undefined ]

    PR incoming

    Reacted by Marc Bernard
    Reacted by Rodrigo Lungui and danchurch-alphasights
  5. wraithgar
    added 2 commits that reference this issue on Feb 3, 2025

    fix(inc): fully capture prerelease identifier

    4c533fa

    fix(inc): fully capture prerelease identifier

    a367dcc
  6. wraithgar
    self-assigned this
    on Feb 3, 2025
  7. danchurch-alphasights commented on Feb 3, 2025

    @danchurch-alphasights
    danchurch-alphasights
    on Feb 3, 2025
    Author
    More actions

    Thank you @wraithgar!

  8. wraithgar
    closed this as completedin #764on Feb 3, 2025
  9. wraithgar
    closed this as completedin af761c0on Feb 3, 2025
  10. pull
    added a commit that references this issue on Feb 3, 2025

    fix(inc): fully capture prerelease identifier (npm#764)

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

Metadata

Metadata

Assignees

  • @wraithgar
    wraithgar

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

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.