Skip to content

Commit dc34a9c

Browse files
committed
fix: Combining both release-as and prerelease now doesn't break package
Previously, as shown in conventional-changelog#542, using both options at the same time resulted in the bump file's version being set to null. This was validated in the first of the new unit tests. The other unit tests simply check that the rest of the behavior is correct in this case. With this combination the user can override the version, the purpose of `release-as`, while still starting or continuing a pre-release, the purpose of of the `prerelease`. Fixes conventional-changelog#542
1 parent 605c1ab commit dc34a9c

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

lib/lifecycles/bump.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ async function Bump (args, version) {
2727
const release = await bumpVersion(args.releaseAs, version, args)
2828
if (!args.firstRelease) {
2929
const releaseType = getReleaseType(args.prerelease, release.releaseType, version)
30-
newVersion = semver.valid(releaseType) || semver.inc(version, releaseType, args.prerelease)
30+
const releaseTypeAsVersion = releaseType === 'pre' + release.releaseType ? semver.valid(release.releaseType + '-' + args.prerelease + '.0') : semver.valid(releaseType)
31+
32+
newVersion = releaseTypeAsVersion || semver.inc(version, releaseType, args.prerelease)
3133
updateConfigs(args, newVersion)
3234
} else {
3335
checkpoint(args, 'skip version bump on first release', [], chalk.red(figures.cross))

test/core.spec.js

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const stdMocks = require('std-mocks')
1313
const cli = require('../command')
1414
const formatCommitMessage = require('../lib/format-commit-message')
1515

16-
require('chai').should()
16+
const should = require('chai').should()
1717

1818
// set by mock()
1919
let standardVersion
@@ -354,6 +354,42 @@ describe('cli', function () {
354354
await exec('--release-as 200.0.0-amazing')
355355
getPackageVersion().should.equal('200.0.0-amazing')
356356
})
357+
358+
it('releases as 100.0.0 with prerelease amazing', async function () {
359+
mock({
360+
bump: 'patch',
361+
fs: { 'CHANGELOG.md': 'legacy header format<a name="1.0.0">\n' },
362+
pkg: {
363+
version: '1.0.0'
364+
}
365+
})
366+
await exec('--release-as 100.0.0 --prerelease amazing')
367+
should.equal(getPackageVersion(), '100.0.0-amazing.0')
368+
})
369+
370+
it('release 100.0.0 with prerelease amazing bumps build', async function () {
371+
mock({
372+
bump: 'patch',
373+
fs: { 'CHANGELOG.md': 'legacy header format<a name="100.0.0-amazing.0">\n' },
374+
pkg: {
375+
version: '100.0.0-amazing.0'
376+
}
377+
})
378+
await exec('--release-as 100.0.0 --prerelease amazing')
379+
should.equal(getPackageVersion(), '100.0.0-amazing.1')
380+
})
381+
382+
it('release 100.0.0-amazing.0 with prerelease amazing bumps build', async function () {
383+
mock({
384+
bump: 'patch',
385+
fs: { 'CHANGELOG.md': 'legacy header format<a name="100.0.0-amazing.0">\n' },
386+
pkg: {
387+
version: '100.0.0-amazing.0'
388+
}
389+
})
390+
await exec('--release-as 100.0.0-amazing.0 --prerelease amazing')
391+
should.equal(getPackageVersion(), '100.0.0-amazing.1')
392+
})
357393
})
358394

359395
it('creates a prerelease with a new minor version after two prerelease patches', async function () {

0 commit comments

Comments
 (0)