Skip to content

Commit

Permalink
fix: preserve build in raw after inc (#565)
Browse files Browse the repository at this point in the history
Fixes: #562
  • Loading branch information
lukekarrys authored Jun 15, 2023
1 parent 717534e commit 5c8efbc
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
6 changes: 4 additions & 2 deletions classes/semver.js
Original file line number Diff line number Diff line change
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
11 changes: 9 additions & 2 deletions test/classes/semver.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,18 @@ test('incrementing', t => {
id,
base,
]) => t.test(`${version} ${inc} ${id || ''}`.trim(), t => {
t.plan(1)
if (expect === null) {
t.plan(1)
t.throws(() => new SemVer(version, options).inc(inc, id, base))
} else {
t.equal(new SemVer(version, options).inc(inc, id, base).version, expect)
t.plan(2)
const incremented = new SemVer(version, options).inc(inc, id, base)
t.equal(incremented.version, expect)
if (incremented.build.length) {
t.equal(incremented.raw, `${expect}+${incremented.build.join('.')}`)
} else {
t.equal(incremented.raw, expect)
}
}
}))
})
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/increments.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,5 @@ module.exports = [
['1.2.0-dev', 'preminor', '1.3.0-beta', false, 'beta', false],
['1.2.0-dev', 'prepatch', '1.2.1-dev', false, 'dev', false],
['1.2.0', 'prerelease', null, false, '', false],
['1.0.0-rc.1+build.4', 'prerelease', '1.0.0-rc.2', 'rc', false],
]
10 changes: 9 additions & 1 deletion test/functions/inc.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@ test('increment versions test', (t) => {
if (wanted) {
parsed.inc(what, id, base)
t.equal(parsed.version, wanted, `${cmd} object version updated`)
t.equal(parsed.raw, wanted, `${cmd} object raw field updated`)
if (parsed.build.length) {
t.equal(
parsed.raw,
`${wanted}+${parsed.build.join('.')}`,
`${cmd} object raw field updated with build`
)
} else {
t.equal(parsed.raw, wanted, `${cmd} object raw field updated`)
}

const preIncObject = JSON.stringify(parsedAsInput)
inc(parsedAsInput, what, options, id, base)
Expand Down

0 comments on commit 5c8efbc

Please sign in to comment.