Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: preserve build in raw after inc #565

Merged
merged 1 commit into from
Jun 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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