Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions command.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ const yargs = require('yargs')
default: defaults.npmPublishHint,
describe: 'Customized publishing hint'
})
.option('noBumpWhenEmptyChanges', {
type: 'boolean',
default: false,
describe: 'Avoid bumping files and generating changelog if there are no changes.'
})
.check((argv) => {
if (typeof argv.scripts !== 'object' || Array.isArray(argv.scripts)) {
throw Error('scripts must be an object')
Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ module.exports = async function standardVersion (argv) {
}

const newVersion = await bump(args, version)
if (!newVersion) return
await changelog(args, newVersion)
await commit(args, newVersion)
await tag(newVersion, pkg ? pkg.private : false, args)
Expand Down
55 changes: 53 additions & 2 deletions lib/lifecycles/bump.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,45 @@ const runLifecycleScript = require('../run-lifecycle-script')
const semver = require('semver')
const writeFile = require('../write-file')
const { resolveUpdaterObjectFromArgument } = require('../updaters')
const addBangNotes = require('conventional-changelog-conventionalcommits/add-bang-notes')
let configsToUpdate = {}

function _whatBump (config, commits) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this perhaps be named noBumpWhenEmptyChanges ?

let level = 2
let breakings = 0
let features = 0
let fix = 0

commits.forEach(commit => {
addBangNotes(commit)
if (commit.notes.length > 0) {
breakings += commit.notes.length
level = 0
} else if (commit.type === 'feat' || commit.type === 'feature') {
features += 1
if (level === 2) {
level = 1
}
}
if (commit.type === 'fix') {
fix += 1
}
})

if (config.preMajor && level < 2) {
level++
}

if (!breakings && !features && !fix) return {}

return {
level,
reason: breakings === 1
Comment thread
hazzo marked this conversation as resolved.
? `There is ${breakings} BREAKING CHANGE and ${features} features`
: `There are ${breakings} BREAKING CHANGES and ${features} features`
}
}

async function Bump (args, version) {
// reset the cache of updated config files each
// time we perform the version bump step.
Expand All @@ -25,6 +62,14 @@ async function Bump (args, version) {
const stdout = await runLifecycleScript(args, 'prebump')
if (stdout && stdout.trim().length) args.releaseAs = stdout.trim()
const release = await bumpVersion(args.releaseAs, version, args)
if (!Object.keys(release).length) {
checkpoint(
args,
'no commits found, so not bumping version',
[]
)
return null
}
if (!args.firstRelease) {
const releaseType = getReleaseType(args.prerelease, release.releaseType, version)
const releaseTypeAsVersion = releaseType === 'pre' + release.releaseType ? semver.valid(release.releaseType + '-' + args.prerelease + '.0') : semver.valid(releaseType)
Expand Down Expand Up @@ -108,7 +153,8 @@ function getTypePriority (type) {
}

function bumpVersion (releaseAs, currentVersion, args) {
return new Promise((resolve, reject) => {
// eslint-disable-next-line no-async-promise-executor
return new Promise(async (resolve, reject) => {
Comment on lines +156 to +157
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// eslint-disable-next-line no-async-promise-executor
return new Promise(async (resolve, reject) => {
return new Promise((resolve, reject) => {

Unless I'm missing something, you don't need this async

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I'll remove it it's from an old implementation.

if (releaseAs) {
return resolve({
releaseType: releaseAs
Expand All @@ -123,7 +169,12 @@ function bumpVersion (releaseAs, currentVersion, args) {
preset: presetOptions,
path: args.path,
tagPrefix: args.tagPrefix,
lernaPackage: args.lernaPackage
lernaPackage: args.lernaPackage,
...args.noBumpWhenEmptyChanges && {
whatBump (commits) {
return _whatBump(presetOptions, commits)
}
Comment on lines +173 to +176
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
...args.noBumpWhenEmptyChanges && {
whatBump (commits) {
return _whatBump(presetOptions, commits)
}
...(args.noBumpWhenEmptyChanges
? {
whatBump (commits) {
return _whatBump(presetOptions, commits)
}
}
: {})

^ I think this is a bit more idiomatic

}
}, args.parserOpts, function (err, release) {
if (err) return reject(err)
else return resolve(release)
Expand Down