Skip to content
Permalink
Browse files
feat: allows seperate prefixTag version sequences (#573)
  • Loading branch information
jahead committed Apr 6, 2021
1 parent f5bff12 commit 3bbba025057ba40c3e15880fede2af851841165b
Showing with 29 additions and 4 deletions.
  1. +1 −1 index.js
  2. +4 −2 lib/latest-semver-tag.js
  3. +24 −1 test/git.spec.js
@@ -56,7 +56,7 @@ module.exports = async function standardVersion (argv) {
if (pkg) {
version = pkg.version
} else if (args.gitTagFallback) {
version = await latestSemverTag()
version = await latestSemverTag(args.tagPrefix)
} else {
throw new Error('no package file found')
}
@@ -1,11 +1,13 @@
const gitSemverTags = require('git-semver-tags')
const semver = require('semver')

module.exports = function () {
module.exports = function (tagPrefix = undefined) {
return new Promise((resolve, reject) => {
gitSemverTags(function (err, tags) {
gitSemverTags({ tagPrefix }, function (err, tags) {
if (err) return reject(err)
else if (!tags.length) return resolve('1.0.0')
// Respect tagPrefix
tags = tags.map(tag => tag.replace(new RegExp('^' + tagPrefix), ''))
// ensure that the largest semver tag is at the head.
tags = tags.map(tag => { return semver.clean(tag) })
tags.sort(semver.rcompare)
@@ -66,7 +66,7 @@ function mock ({ bump, changelog, tags }) {
}
}))

mockery.registerMock('git-semver-tags', function (cb) {
mockery.registerMock('git-semver-tags', function (_, cb) {
if (tags instanceof Error) cb(tags)
else cb(null, tags || [])
})
@@ -103,6 +103,29 @@ describe('git', function () {
}
})

describe('tagPrefix', () => {
// TODO: Use unmocked git-semver-tags and stage a git environment
it('will add prefix onto tag based on version from package', async function () {
writePackageJson('1.2.0')
mock({ bump: 'minor', tags: ['p-v1.2.0'] })
await exec('--tag-prefix p-v')
shell.exec('git tag').stdout.should.match(/p-v1\.3\.0/)
})

it('will add prefix onto tag via when gitTagFallback is true and no package [cli]', async function () {
shell.rm('package.json')
mock({ bump: 'minor', tags: ['android/production/v1.2.0', 'android/production/v1.0.0'] })
await exec('--tag-prefix android/production/v')
shell.exec('git tag').stdout.should.match(/android\/production\/v1\.3\.0/)
})

it('will add prefix onto tag via when gitTagFallback is true and no package [options]', async function () {
mock({ bump: 'minor', tags: ['android/production/v1.2.0', 'android/production/v1.0.0'] })
await exec({ tagPrefix: 'android/production/v', packageFiles: [] })
shell.exec('git tag').stdout.should.match(/android\/production\/v1\.3\.0/)
})
})

it('formats the commit and tag messages appropriately', async function () {
mock({ bump: 'minor', tags: ['v1.0.0'] })
await exec({})

0 comments on commit 3bbba02

Please sign in to comment.