node/deps/npm/lib/deprecate.js

51 lines
1.3 KiB
JavaScript
Raw Normal View History

2014-09-25 05:41:07 +08:00
var npm = require("./npm.js")
, mapToRegistry = require("./utils/map-to-registry.js")
, npa = require("npm-package-arg")
module.exports = deprecate
deprecate.usage = "npm deprecate <pkg>[@<version>] <message>"
deprecate.completion = function (opts, cb) {
// first, get a list of remote packages this user owns.
// once we have a user account, then don't complete anything.
if (opts.conf.argv.remain.length > 2) return cb()
// get the list of packages by user
2014-09-25 05:41:07 +08:00
var path = "/-/by-user/"
mapToRegistry(path, npm.config, function (er, uri, c) {
2014-09-25 05:41:07 +08:00
if (er) return cb(er)
if (!(c && c.username)) return cb()
var params = {
timeout : 60000,
auth : c
}
npm.registry.get(uri + c.username, params, function (er, list) {
2014-09-25 05:41:07 +08:00
if (er) return cb()
console.error(list)
return cb(null, list[c.username])
})
})
}
function deprecate (args, cb) {
var pkg = args[0]
, msg = args[1]
2013-01-10 07:21:30 +08:00
if (msg === undefined) return cb("Usage: " + deprecate.usage)
2014-09-25 05:41:07 +08:00
// fetch the data and make sure it exists.
2014-09-25 05:41:07 +08:00
var p = npa(pkg)
mapToRegistry(p.name, npm.config, function (er, uri, auth) {
2014-09-25 05:41:07 +08:00
if (er) return cb(er)
2014-08-01 00:05:30 +08:00
var params = {
version : p.spec,
message : msg,
auth : auth
}
npm.registry.deprecate(uri, params, cb)
})
}