node/deps/npm/node_modules/npm-registry-client/lib/deprecate.js

28 lines
814 B
JavaScript
Raw Normal View History

2013-12-17 08:23:13 +08:00
module.exports = deprecate
2014-08-01 00:05:30 +08:00
var url = require("url")
2013-12-17 08:23:13 +08:00
var semver = require("semver")
2014-08-01 00:05:30 +08:00
function deprecate (uri, ver, message, cb) {
2014-09-25 05:41:07 +08:00
var c = this.conf.getCredentialsByURI(uri)
if (!(c.token || c.auth)) {
2013-12-17 08:23:13 +08:00
return cb(new Error("Must be logged in to deprecate a package"))
}
if (semver.validRange(ver) === null) {
return cb(new Error("invalid version range: "+ver))
}
2014-08-01 00:05:30 +08:00
this.get(uri + '?write=true', null, function (er, data) {
2013-12-17 08:23:13 +08:00
if (er) return cb(er)
// filter all the versions that match
Object.keys(data.versions).filter(function (v) {
return semver.satisfies(v, ver)
}).forEach(function (v) {
data.versions[v].deprecated = message
})
// now update the doc on the registry
2014-08-01 00:05:30 +08:00
this.request('PUT', url.resolve(uri, data._id), { body : data }, cb)
2013-12-17 08:23:13 +08:00
}.bind(this))
}