mirror of
https://github.com/verdaccio/verdaccio.git
synced 2024-11-08 23:25:51 +01:00
making loose semver versions work, ref #38
This commit is contained in:
parent
8987ee0b2a
commit
e522347667
@ -116,19 +116,20 @@ module.exports = function(config_hash) {
|
||||
info = utils.filter_tarball_urls(info, req, config)
|
||||
|
||||
var version = req.params.version
|
||||
, t
|
||||
if (!version) {
|
||||
return res.send(info)
|
||||
}
|
||||
|
||||
if (info.versions[version] != null) {
|
||||
return res.send(info.versions[version])
|
||||
if ((t = utils.get_version(info, version)) != null) {
|
||||
return res.send(t)
|
||||
}
|
||||
|
||||
if (info['dist-tags'] != null) {
|
||||
if (info['dist-tags'][version] != null) {
|
||||
version = info['dist-tags'][version]
|
||||
if (info.versions[version] != null) {
|
||||
return res.send(info.versions[version])
|
||||
if ((t = utils.get_version(info, version)) != null) {
|
||||
return res.send(t)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
16
lib/utils.js
16
lib/utils.js
@ -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
|
||||
module.exports.semver_sort = function semver_sort(array) {
|
||||
return array
|
||||
|
@ -3,7 +3,7 @@
|
||||
"versions": {
|
||||
"0.1.0": {
|
||||
"name": "testexp_tags",
|
||||
"version": "0.0.0",
|
||||
"version": "0.1.0",
|
||||
"dist": {
|
||||
"shasum": "fake",
|
||||
"tarball": "http://localhost:55551/testexp_tags/-/blahblah"
|
||||
@ -11,7 +11,7 @@
|
||||
},
|
||||
"0.1.1alpha": {
|
||||
"name": "testexp_tags",
|
||||
"version": "0.0.0",
|
||||
"version": "0.1.1alpha",
|
||||
"dist": {
|
||||
"shasum": "fake",
|
||||
"tarball": "http://localhost:55551/testexp_tags/-/blahblah"
|
||||
@ -19,7 +19,7 @@
|
||||
},
|
||||
"0.1.2": {
|
||||
"name": "testexp_tags",
|
||||
"version": "0.0.0",
|
||||
"version": "0.1.2",
|
||||
"dist": {
|
||||
"shasum": "fake",
|
||||
"tarball": "http://localhost:55551/testexp_tags/-/blahblah"
|
||||
@ -27,7 +27,7 @@
|
||||
},
|
||||
"0.1.3alpha": {
|
||||
"name": "testexp_tags",
|
||||
"version": "0.0.0",
|
||||
"version": "0.1.3alpha",
|
||||
"dist": {
|
||||
"shasum": "fake",
|
||||
"tarball": "http://localhost:55551/testexp_tags/-/blahblah"
|
||||
@ -35,7 +35,7 @@
|
||||
},
|
||||
"1.1": {
|
||||
"name": "testexp_tags",
|
||||
"version": "0.0.0",
|
||||
"version": "1.1",
|
||||
"dist": {
|
||||
"shasum": "fake",
|
||||
"tarball": "http://localhost:55551/testexp_tags/-/blahblah"
|
||||
@ -47,4 +47,4 @@
|
||||
"something": "0.1.1alpha",
|
||||
"bad": "1.1"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,6 @@ module.exports = function() {
|
||||
|
||||
it('fetching package again', function(cb) {
|
||||
server.get_package('testexp_tags', function(res, body) {
|
||||
// shouldn't exist yet
|
||||
assert.equal(res.statusCode, 200)
|
||||
assert.equal(typeof(body.versions['1.1']), 'object')
|
||||
assert.equal(body['dist-tags'].something, '0.1.1alpha')
|
||||
@ -37,5 +36,15 @@ module.exports = function() {
|
||||
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()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user