0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-12-16 21:56:25 -05:00

tag_version should return if tag is fresh

This commit is contained in:
Alex Kocharin 2014-09-18 00:04:15 +04:00
parent 92a33acf45
commit 8d1781489b
2 changed files with 58 additions and 1 deletions

View file

@ -98,7 +98,7 @@ function can_add_tag(tag, config) {
} }
module.exports.tag_version = function(data, version, tag, config) { module.exports.tag_version = function(data, version, tag, config) {
if (!can_add_tag(tag, config)) return if (!can_add_tag(tag, config)) return false
switch(typeof(data['dist-tags'][tag])) { switch(typeof(data['dist-tags'][tag])) {
case 'string': case 'string':
@ -112,7 +112,9 @@ module.exports.tag_version = function(data, version, tag, config) {
if (data['dist-tags'][tag].indexOf(version) === -1) { if (data['dist-tags'][tag].indexOf(version) === -1) {
data['dist-tags'][tag].push(version) data['dist-tags'][tag].push(version)
data['dist-tags'][tag] = module.exports.semver_sort(data['dist-tags'][tag]) data['dist-tags'][tag] = module.exports.semver_sort(data['dist-tags'][tag])
return data['dist-tags'][tag][data['dist-tags'][tag].length - 1] === version
} }
return false
} }
// gets version from a package object taking into account semver weirdness // gets version from a package object taking into account semver weirdness

55
test/unit/tag_version.js Normal file
View file

@ -0,0 +1,55 @@
var assert = require('assert')
, tag_version = require('../../lib/utils').tag_version
require('../../lib/logger').setup([])
describe('tag_version', function() {
it('add new one', function() {
var x = {
versions: {},
'dist-tags': {},
}
assert(tag_version(x, '1.1.1', 'foo', {}))
assert.deepEqual(x, {
versions: {},
'dist-tags': {foo: ['1.1.1']},
})
})
it('add (compat)', function() {
var x = {
versions: {},
'dist-tags': {foo: '1.1.0'},
}
assert(tag_version(x, '1.1.1', 'foo', {}))
assert.deepEqual(x, {
versions: {},
'dist-tags': {foo: ['1.1.0', '1.1.1']},
})
})
it('add fresh tag', function() {
var x = {
versions: {},
'dist-tags': {foo: ['1.1.0']},
}
assert(tag_version(x, '1.1.1', 'foo', {}))
assert.deepEqual(x, {
versions: {},
'dist-tags': {foo: ['1.1.0', '1.1.1']},
})
})
it('add stale tag', function() {
var x = {
versions: {},
'dist-tags': {foo: ['1.1.2']},
}
assert(!tag_version(x, '1.1.1', 'foo', {}))
assert.deepEqual(x, {
versions: {},
'dist-tags': {foo: ['1.1.1', '1.1.2']},
})
})
})