-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
semver 和 publish 的调整 #81
Changes from 3 commits
bc8aed6
9a79839
8ba5fa9
01fb67e
a508752
88ba264
ff3baea
a6a22bb
a191fed
ecc88b2
8446a19
aed50af
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 |
---|---|---|
|
@@ -5,6 +5,7 @@ var fs = require('fs-extra'); | |
var path = require('path'); | ||
var tempfile = require('tempfile'); | ||
var tar = require('tarball-extract'); | ||
var semver = require('semver'); | ||
var hook = require('../lib/hook'); | ||
var history = require('../lib/history'); | ||
var elastical = require('elastical'); | ||
|
@@ -68,9 +69,14 @@ exports.project = { | |
var Cache = {}; | ||
exports.package = { | ||
get: function(req, res) { | ||
var project = new Project({ | ||
name: req.params.name | ||
}); | ||
var version = semver.maxSatisfying(Object.keys(project.packages), req.params.version); | ||
|
||
var p = new Package({ | ||
name: req.params.name, | ||
version: req.params.version | ||
version: version | ||
}); | ||
if (!p.md5) { | ||
abortify(res, { code: 404 }); | ||
|
@@ -142,25 +148,23 @@ exports.package = { | |
|
||
Cache.package = new Package(data); | ||
|
||
var force = req.headers['x-yuan-force']; | ||
if(Cache.package.md5 && !force) { | ||
if(Cache.package.md5) { | ||
return abortify(res, { code: 444 }); | ||
} | ||
|
||
var isNewProject; | ||
Cache.project = new Project(data); | ||
var isNewProject = !Cache.project['created_at']; | ||
if (isNewProject) { | ||
data.owners = [data.publisher]; | ||
} | ||
Cache.project.update(data); | ||
delete Cache.project.unpublished; | ||
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. 创建时为什么需要删除 unpublished ? 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. Project unpublish 后重新 publish,需删除 |
||
if (isNewProject) { | ||
hook.emit('create:project', Cache.project, data.publisher); | ||
} | ||
res.send(200, {}); | ||
}, | ||
put: function(req, res) { | ||
var data = req.body; | ||
var package = Cache.package; | ||
var project = Cache.project; | ||
if (!package) { | ||
|
@@ -361,7 +365,7 @@ function abortify(res, options) { | |
406: 'Not acceptable.', | ||
415: 'Unsupported media type.', | ||
426: 'Upgrade required.', | ||
444: 'Force option required.' | ||
444: 'Cannot modify pre-existing version.' | ||
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. pre-existing -> existed ? 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. 从 npm 上 copy 来的。。两个意思差不多。 |
||
}; | ||
message = options.message || msgs[code]; | ||
res.send(code, { | ||
|
@@ -370,3 +374,5 @@ function abortify(res, options) { | |
message: message | ||
}); | ||
} | ||
|
||
|
||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
这个方法其实已经同时支持了
~
^
*
1.x
>1.0.0
等各种情况吧?会不会太激进了。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.
版本的问题我觉得可以让使用者自己判断,信任一个库才使用他,如果一个库使用了
*
这样的版本范围,则可以选择不用他。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.
内部组件(arale, alipay, anima)可以约定下只能用 patch range
~1.1.x
。另外,内部工具在构建时候可以判断下范围是否过大,然后给予提示。