From 5d972cf1fede448001e30283e3258d07bed41658 Mon Sep 17 00:00:00 2001 From: "Benjamin E. Coe" Date: Sun, 5 May 2019 14:16:40 -0700 Subject: [PATCH] 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. --- lib/lifecycles/bump.js | 10 +++++++--- test.js | 35 ++++++++++++++++++++++++----------- 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/lib/lifecycles/bump.js b/lib/lifecycles/bump.js index 0fd0a1ac7..a7638b904 100644 --- a/lib/lifecycles/bump.js +++ b/lib/lifecycles/bump.js @@ -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) { @@ -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) diff --git a/test.js b/test.js index 0054a2419..3c0923284 100644 --- a/test.js +++ b/test.js @@ -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({ @@ -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') + }) + }) })