-
Notifications
You must be signed in to change notification settings - Fork 746
feat: support semver #816
feat: support semver #816
Changes from 1 commit
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 |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
|
||
var should = require('should'); | ||
var request = require('supertest'); | ||
var pedding = require('pedding'); | ||
var mm = require('mm'); | ||
var app = require('../../../../servers/registry'); | ||
var utils = require('../../../utils'); | ||
|
@@ -24,12 +25,20 @@ describe('controllers/registry/package/show.test.js', function () { | |
afterEach(mm.restore); | ||
|
||
before(function (done) { | ||
done = pedding(done, 2); | ||
var pkg = utils.getPackage('@cnpmtest/testmodule-show', '0.0.1', utils.admin); | ||
request(app.listen()) | ||
.put('/' + pkg.name) | ||
.set('authorization', utils.adminAuth) | ||
.send(pkg) | ||
.expect(201, done); | ||
|
||
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 +54,19 @@ 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 support jsonp', function (done) { | ||
request(app.listen()) | ||
.get('/@cnpmtest/testmodule-show/0.0.1?callback=jsonp') | ||
|
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.
这个不需要修改吧。