UNPKG

1.22 kBJavaScriptView Raw
1var npm = require("./npm.js")
2 , mapToRegistry = require("./utils/map-to-registry.js")
3 , npa = require("npm-package-arg")
4
5module.exports = deprecate
6
7deprecate.usage = "npm deprecate <pkg>[@<version>] <message>"
8
9deprecate.completion = function (opts, cb) {
10 // first, get a list of remote packages this user owns.
11 // once we have a user account, then don't complete anything.
12 if (opts.conf.argv.remain.length > 2) return cb()
13 // get the list of packages by user
14 var path = "/-/by-user/"
15 mapToRegistry(path, npm.config, function (er, uri) {
16 if (er) return cb(er)
17
18 var c = npm.config.getCredentialsByURI(uri)
19 if (!(c && c.username)) return cb()
20
21 npm.registry.get(uri + c.username, { timeout : 60000 }, function (er, list) {
22 if (er) return cb()
23 console.error(list)
24 return cb(null, list[c.username])
25 })
26 })
27}
28
29function deprecate (args, cb) {
30 var pkg = args[0]
31 , msg = args[1]
32 if (msg === undefined) return cb("Usage: " + deprecate.usage)
33
34 // fetch the data and make sure it exists.
35 var p = npa(pkg)
36
37 mapToRegistry(p.name, npm.config, next)
38
39 function next (er, uri) {
40 if (er) return cb(er)
41
42 npm.registry.deprecate(uri, p.spec, msg, cb)
43 }
44}