Skip to content

Commit

Permalink
Add support for simple, non-semver version tags in the format "v1". #747
Browse files Browse the repository at this point in the history
  • Loading branch information
raineorshine committed Oct 23, 2020
1 parent ec2f628 commit 0f75be0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/package-managers/gitTags.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const greatest = async (name, version, options) => {

// eslint-disable-next-line fp/no-mutating-methods
const tags = [...tagMap.keys()]
.map(tag => versionUtil.isSimpleVersion(tag) ? tag + '.0.0' : tag)
.filter(semver.valid)
.sort(versionUtil.compareVersions)
const latestVersion = tags[tags.length - 1]
Expand Down
7 changes: 6 additions & 1 deletion lib/version-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,13 @@ const getGithubUrlTag = declaration => {
*/
const upgradeGithubUrl = (declaration, upgraded) => {
const tag = parseGithubUrl(declaration).branch
return declaration.replace(tag, upgraded)
const upgradedWithSimpleStripped = isSimpleVersion(tag) ? upgraded.replace('.0.0', '') : upgraded
return declaration.replace(tag, upgradedWithSimpleStripped)
}

/** Checks if a string is a simple version in the format "v1". */
const isSimpleVersion = s => /^[vV]\d+$/.test(s)

module.exports = {
compareVersions,
numParts,
Expand All @@ -298,6 +302,7 @@ module.exports = {
setPrecision,
addWildCard,
isPre,
isSimpleVersion,
isWildCard,
isWildPart,
colorizeDiff,
Expand Down
13 changes: 12 additions & 1 deletion test/test-versionmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ describe('versionmanager', () => {
})
})

it('skip github url tags that are not valid semver', async () => {
it('ignore tags that are not valid semver', async () => {
const upgrades = await vm.queryVersions({
// this repo has tag "1.0" which is not valid semver
'ncu-test-invalid-tag': 'raineorshine/ncu-test-invalid-tag.git#v3.0.0'
Expand All @@ -508,6 +508,17 @@ describe('versionmanager', () => {
})
})

it('support the non-semver tag "v1"', async () => {
const upgrades = await vm.queryVersions({
// this repo has tag "1.0" which is not valid semver
'ncu-test-invalid-tag': 'git+https://github.com/raineorshine/ncu-test-simple-tag#v1'
}, { loglevel: 'silent' })

upgrades.should.deep.equal({
'ncu-test-invalid-tag': 'git+https://github.com/raineorshine/ncu-test-simple-tag#v3'
})
})

it('private github urls with tags should be ignored', async () => {
const upgrades = await vm.queryVersions({
'ncu-test-alpha': 'git+https://username:dh9dnas0nndnjnjasd4@bitbucket.org/somename/common.git#v283',
Expand Down

0 comments on commit 0f75be0

Please sign in to comment.