Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
feat!: bump minor rather than major, if release is < 1.0.0 (#347)
BREAKING CHANGE: we now bump the minor rather than major if version < 1.0.0; --release-as can be used to bump to 1.0.0.
  • Loading branch information
bcoe committed May 5, 2019
1 parent 6718428 commit 5d972cf
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 14 deletions.
10 changes: 7 additions & 3 deletions lib/lifecycles/bump.js
Expand Up @@ -28,7 +28,7 @@ function Bump (args, version) {
.then(runLifecycleScript.bind(this, args, 'prebump'))
.then((stdout) => {
if (stdout && stdout.trim().length) args.releaseAs = stdout.trim()
return bumpVersion(args.releaseAs, args)
return bumpVersion(args.releaseAs, version, args)
})
.then((release) => {
if (!args.firstRelease) {
Expand Down Expand Up @@ -129,16 +129,20 @@ function getTypePriority (type) {
return TypeList.indexOf(type)
}

function bumpVersion (releaseAs, args) {
function bumpVersion (releaseAs, currentVersion, args) {
return new Promise((resolve, reject) => {
if (releaseAs) {
return resolve({
releaseType: releaseAs
})
} else {
const presetOptions = presetLoader(args)
if (typeof presetOptions === 'object') {
if (semver.lt(currentVersion, '1.0.0')) presetOptions.preMajor = true
}
conventionalRecommendedBump({
debug: args.verbose && console.info.bind(console, 'conventional-recommended-bump'),
preset: presetLoader(args),
preset: presetOptions,
path: args.path
}, function (err, release) {
if (err) return reject(err)
Expand Down
35 changes: 24 additions & 11 deletions test.js
Expand Up @@ -1034,17 +1034,6 @@ describe('standard-version', function () {

describe('configuration', () => {
it('reads config from .versionrc', function () {
// we currently skip several replacments in CHANGELOG
// generation if repository URL isn't set.
//
// TODO: consider modifying this logic in conventional-commits
// perhaps we should only skip the replacement if we rely on
// the {{host}} field?
writePackageJson('1.0.0', {
repository: {
url: 'https://github.com/yargs/yargs.git'
}
})
// write configuration that overrides default issue
// URL format.
fs.writeFileSync('.versionrc', JSON.stringify({
Expand All @@ -1057,4 +1046,28 @@ describe('standard-version', function () {
content.should.include('http://www.foo.com/1')
})
})

describe('pre-major', () => {
it('bumps the minor rather than major, if version < 1.0.0', function () {
writePackageJson('0.5.0', {
repository: {
url: 'https://github.com/yargs/yargs.git'
}
})
commit('feat!: this is a breaking change')
execCli()
getPackageVersion().should.equal('0.6.0')
})

it('bumps major if --release-as=major specified, if version < 1.0.0', function () {
writePackageJson('0.5.0', {
repository: {
url: 'https://github.com/yargs/yargs.git'
}
})
commit('feat!: this is a breaking change')
execCli('-r major')
getPackageVersion().should.equal('1.0.0')
})
})
})

0 comments on commit 5d972cf

Please sign in to comment.