0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2025-01-13 22:48:31 -05:00

making loose semver versions work, ref #38

This commit is contained in:
Alex Kocharin 2014-01-18 22:57:44 +04:00
parent 8987ee0b2a
commit e522347667
4 changed files with 37 additions and 11 deletions

View file

@ -116,19 +116,20 @@ module.exports = function(config_hash) {
info = utils.filter_tarball_urls(info, req, config) info = utils.filter_tarball_urls(info, req, config)
var version = req.params.version var version = req.params.version
, t
if (!version) { if (!version) {
return res.send(info) return res.send(info)
} }
if (info.versions[version] != null) { if ((t = utils.get_version(info, version)) != null) {
return res.send(info.versions[version]) return res.send(t)
} }
if (info['dist-tags'] != null) { if (info['dist-tags'] != null) {
if (info['dist-tags'][version] != null) { if (info['dist-tags'][version] != null) {
version = info['dist-tags'][version] version = info['dist-tags'][version]
if (info.versions[version] != null) { if ((t = utils.get_version(info, version)) != null) {
return res.send(info.versions[version]) return res.send(t)
} }
} }
} }

View file

@ -107,6 +107,22 @@ module.exports.tag_version = function(data, version, tag) {
} }
} }
// gets version from a package object taking into account semver weirdness
module.exports.get_version = function(object, version) {
if (object.versions[version] != null) return object.versions[version]
try {
version = semver.parse(version, true)
for (var k in object.versions) {
if (version.compare(semver.parse(k, true)) === 0) {
return object.versions[k]
}
}
} catch(err) {
return undefined
}
}
// function filters out bad semver versions and sorts the array // function filters out bad semver versions and sorts the array
module.exports.semver_sort = function semver_sort(array) { module.exports.semver_sort = function semver_sort(array) {
return array return array

View file

@ -3,7 +3,7 @@
"versions": { "versions": {
"0.1.0": { "0.1.0": {
"name": "testexp_tags", "name": "testexp_tags",
"version": "0.0.0", "version": "0.1.0",
"dist": { "dist": {
"shasum": "fake", "shasum": "fake",
"tarball": "http://localhost:55551/testexp_tags/-/blahblah" "tarball": "http://localhost:55551/testexp_tags/-/blahblah"
@ -11,7 +11,7 @@
}, },
"0.1.1alpha": { "0.1.1alpha": {
"name": "testexp_tags", "name": "testexp_tags",
"version": "0.0.0", "version": "0.1.1alpha",
"dist": { "dist": {
"shasum": "fake", "shasum": "fake",
"tarball": "http://localhost:55551/testexp_tags/-/blahblah" "tarball": "http://localhost:55551/testexp_tags/-/blahblah"
@ -19,7 +19,7 @@
}, },
"0.1.2": { "0.1.2": {
"name": "testexp_tags", "name": "testexp_tags",
"version": "0.0.0", "version": "0.1.2",
"dist": { "dist": {
"shasum": "fake", "shasum": "fake",
"tarball": "http://localhost:55551/testexp_tags/-/blahblah" "tarball": "http://localhost:55551/testexp_tags/-/blahblah"
@ -27,7 +27,7 @@
}, },
"0.1.3alpha": { "0.1.3alpha": {
"name": "testexp_tags", "name": "testexp_tags",
"version": "0.0.0", "version": "0.1.3alpha",
"dist": { "dist": {
"shasum": "fake", "shasum": "fake",
"tarball": "http://localhost:55551/testexp_tags/-/blahblah" "tarball": "http://localhost:55551/testexp_tags/-/blahblah"
@ -35,7 +35,7 @@
}, },
"1.1": { "1.1": {
"name": "testexp_tags", "name": "testexp_tags",
"version": "0.0.0", "version": "1.1",
"dist": { "dist": {
"shasum": "fake", "shasum": "fake",
"tarball": "http://localhost:55551/testexp_tags/-/blahblah" "tarball": "http://localhost:55551/testexp_tags/-/blahblah"

View file

@ -28,7 +28,6 @@ module.exports = function() {
it('fetching package again', function(cb) { it('fetching package again', function(cb) {
server.get_package('testexp_tags', function(res, body) { server.get_package('testexp_tags', function(res, body) {
// shouldn't exist yet
assert.equal(res.statusCode, 200) assert.equal(res.statusCode, 200)
assert.equal(typeof(body.versions['1.1']), 'object') assert.equal(typeof(body.versions['1.1']), 'object')
assert.equal(body['dist-tags'].something, '0.1.1alpha') assert.equal(body['dist-tags'].something, '0.1.1alpha')
@ -37,5 +36,15 @@ module.exports = function() {
cb() cb()
}) })
}) })
;['0.1.1alpha', '0.1.1-alpha', '0000.00001.001-alpha'].forEach(function(ver) {
it('fetching '+ver, function(cb) {
server.request({uri:'/testexp_tags/'+ver}, function(err, res, body) {
assert.equal(res.statusCode, 200)
assert.equal(body.version, '0.1.1alpha')
cb()
})
})
})
}) })
} }