Skip to content

Commit

Permalink
fix: preserve build in raw after inc
Browse files Browse the repository at this point in the history
Fixes: #562
  • Loading branch information
lukekarrys committed Jun 15, 2023
1 parent 2f738e9 commit 985a584
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
6 changes: 4 additions & 2 deletions classes/semver.js
Expand Up @@ -291,8 +291,10 @@ class SemVer {
default:
throw new Error(`invalid increment argument: ${release}`)
}
this.format()
this.raw = this.version
this.raw = this.format()
if (this.build.length) {
this.raw += `+${this.build.join('.')}`
}
return this
}
}
Expand Down
14 changes: 13 additions & 1 deletion test/classes/semver.js
Expand Up @@ -81,7 +81,7 @@ test('invalid version numbers', (t) => {
})

test('incrementing', t => {
t.plan(increments.length)
t.plan(increments.length + 1)
increments.forEach(([
version,
inc,
Expand All @@ -97,6 +97,18 @@ test('incrementing', t => {
t.equal(new SemVer(version, options).inc(inc, id, base).version, expect)
}
}))
t.test('preserve build in raw', t => {
// https://github.com/npm/node-semver/issues/562
t.plan(2)
t.equal(
new SemVer('1.0.0-rc.1+build.4').inc('prerelease', 'rc').raw,
'1.0.0-rc.2+build.4'
)
t.equal(
new SemVer('1.0.0-rc.1').inc('prerelease', 'rc').raw,
'1.0.0-rc.2'
)
})
})

test('compare main vs pre', (t) => {
Expand Down

0 comments on commit 985a584

Please sign in to comment.