-
Notifications
You must be signed in to change notification settings - Fork 746
feat: support semver #816
feat: support semver #816
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,9 +65,9 @@ function routes(app) { | |
|
||
// module | ||
// scope package: params: [$name] | ||
app.get(/^\/(@[\w\-\.]+\/[\w\-\.]+)$/, syncByInstall, listAllVersions); | ||
app.get(/^\/(@[\w\-\.]+\/[^\/]+)$/, syncByInstall, listAllVersions); | ||
// scope package: params: [$name, $version] | ||
app.get(/^\/(@[\w\-\.]+\/[\w\-\.]+)\/([\w\.\-]+)$/, syncByInstall, getOneVersion); | ||
app.get(/^\/(@[\w\-\.]+\/[\w\-\.]+)\/([^\/]+)$/, syncByInstall, getOneVersion); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这个正则范围会不会太广了。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 呃,不对,semver 会很复杂。。。还是你改的这样吧。如 |
||
|
||
app.get('/:name', syncByInstall, listAllVersions); | ||
app.get('/:name/:version', syncByInstall, getOneVersion); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
* Module dependencies. | ||
*/ | ||
|
||
var semver = require('semver'); | ||
var models = require('../models'); | ||
var common = require('./common'); | ||
var Tag = models.Tag; | ||
|
@@ -73,6 +74,18 @@ exports.getModuleByTag = function* (name, tag) { | |
return yield* exports.getModule(tag.name, tag.version); | ||
}; | ||
|
||
exports.getModuleByRange = function* (name, range) { | ||
var rows = yield* exports.listModulesByName(name); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 到处都是 |
||
var versionMap = {}; | ||
var versions = rows.map(function(row) { | ||
versionMap[row.version] = row; | ||
return row.version; | ||
}); | ||
|
||
var version = semver.maxSatisfying(versions, range); | ||
return versionMap[version]; | ||
}; | ||
|
||
exports.getLatestModule = function* (name) { | ||
return yield* exports.getModuleByTag(name, 'latest'); | ||
}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,7 +29,15 @@ describe('controllers/registry/package/show.test.js', function () { | |
.put('/' + pkg.name) | ||
.set('authorization', utils.adminAuth) | ||
.send(pkg) | ||
.expect(201, done); | ||
.expect(201, function(err) { | ||
should.not.exist(err); | ||
pkg = utils.getPackage('@cnpmtest/testmodule-show', '1.1.0', utils.admin); | ||
request(app.listen()) | ||
.put('/' + pkg.name) | ||
.set('authorization', utils.adminAuth) | ||
.send(pkg) | ||
.expect(201, done); | ||
}); | ||
}); | ||
|
||
it('should return one version', function (done) { | ||
|
@@ -45,6 +53,45 @@ describe('controllers/registry/package/show.test.js', function () { | |
}); | ||
}); | ||
|
||
it('should return max satisfied package with semver range', function (done) { | ||
request(app.listen()) | ||
.get('/@cnpmtest/testmodule-show/^1.0.0') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 加一些复杂的情况 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 测试补了 |
||
.expect(200, function (err, res) { | ||
should.not.exist(err); | ||
var data = res.body; | ||
data.name.should.equal('@cnpmtest/testmodule-show'); | ||
data.version.should.equal('1.1.0'); | ||
data.dist.tarball.should.containEql('/@cnpmtest/testmodule-show/download/@cnpmtest/testmodule-show-1.1.0.tgz'); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should return max satisfied package with complex semver range', function (done) { | ||
request(app.listen()) | ||
.get('/@cnpmtest/testmodule-show/>1.2.0 <=2 || 0.0.1') | ||
.expect(200, function (err, res) { | ||
should.not.exist(err); | ||
var data = res.body; | ||
data.name.should.equal('@cnpmtest/testmodule-show'); | ||
data.version.should.equal('0.0.1'); | ||
data.dist.tarball.should.containEql('/@cnpmtest/testmodule-show/download/@cnpmtest/testmodule-show-0.0.1.tgz'); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should return max satisfied package with *', function (done) { | ||
request(app.listen()) | ||
.get('/@cnpmtest/testmodule-show/*') | ||
.expect(200, function (err, res) { | ||
should.not.exist(err); | ||
var data = res.body; | ||
data.name.should.equal('@cnpmtest/testmodule-show'); | ||
data.version.should.equal('1.1.0'); | ||
data.dist.tarball.should.containEql('/@cnpmtest/testmodule-show/download/@cnpmtest/testmodule-show-1.1.0.tgz'); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should support jsonp', function (done) { | ||
request(app.listen()) | ||
.get('/@cnpmtest/testmodule-show/0.0.1?callback=jsonp') | ||
|
@@ -59,7 +106,7 @@ describe('controllers/registry/package/show.test.js', function () { | |
should.not.exist(err); | ||
var data = res.body; | ||
data.name.should.equal('@cnpmtest/testmodule-show'); | ||
data.version.should.equal('0.0.1'); | ||
data.version.should.equal('1.1.0'); | ||
done(); | ||
}); | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个不需要修改吧。