Skip to content

Commit 5c8efbc

Browse files
authoredJun 15, 2023
fix: preserve build in raw after inc (#565)
Fixes: #562
1 parent 717534e commit 5c8efbc

File tree

4 files changed

+23
-5
lines changed

4 files changed

+23
-5
lines changed
 

‎classes/semver.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,10 @@ class SemVer {
291291
default:
292292
throw new Error(`invalid increment argument: ${release}`)
293293
}
294-
this.format()
295-
this.raw = this.version
294+
this.raw = this.format()
295+
if (this.build.length) {
296+
this.raw += `+${this.build.join('.')}`
297+
}
296298
return this
297299
}
298300
}

‎test/classes/semver.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,18 @@ test('incrementing', t => {
9090
id,
9191
base,
9292
]) => t.test(`${version} ${inc} ${id || ''}`.trim(), t => {
93-
t.plan(1)
9493
if (expect === null) {
94+
t.plan(1)
9595
t.throws(() => new SemVer(version, options).inc(inc, id, base))
9696
} else {
97-
t.equal(new SemVer(version, options).inc(inc, id, base).version, expect)
97+
t.plan(2)
98+
const incremented = new SemVer(version, options).inc(inc, id, base)
99+
t.equal(incremented.version, expect)
100+
if (incremented.build.length) {
101+
t.equal(incremented.raw, `${expect}+${incremented.build.join('.')}`)
102+
} else {
103+
t.equal(incremented.raw, expect)
104+
}
98105
}
99106
}))
100107
})

‎test/fixtures/increments.js

+1
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,5 @@ module.exports = [
123123
['1.2.0-dev', 'preminor', '1.3.0-beta', false, 'beta', false],
124124
['1.2.0-dev', 'prepatch', '1.2.1-dev', false, 'dev', false],
125125
['1.2.0', 'prerelease', null, false, '', false],
126+
['1.0.0-rc.1+build.4', 'prerelease', '1.0.0-rc.2', 'rc', false],
126127
]

‎test/functions/inc.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,15 @@ test('increment versions test', (t) => {
1414
if (wanted) {
1515
parsed.inc(what, id, base)
1616
t.equal(parsed.version, wanted, `${cmd} object version updated`)
17-
t.equal(parsed.raw, wanted, `${cmd} object raw field updated`)
17+
if (parsed.build.length) {
18+
t.equal(
19+
parsed.raw,
20+
`${wanted}+${parsed.build.join('.')}`,
21+
`${cmd} object raw field updated with build`
22+
)
23+
} else {
24+
t.equal(parsed.raw, wanted, `${cmd} object raw field updated`)
25+
}
1826

1927
const preIncObject = JSON.stringify(parsedAsInput)
2028
inc(parsedAsInput, what, options, id, base)

0 commit comments

Comments
 (0)
Please sign in to comment.