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

feat!: bump minor rather than major, if release is < 1.0.0 #347

Merged
merged 3 commits into from May 5, 2019
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
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')
})
})
})