UNPKG

1.44 kBJavaScriptView Raw
1var npm = require('./npm.js')
2var mapToRegistry = require('./utils/map-to-registry.js')
3var 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, c) {
16 if (er) return cb(er)
17
18 if (!(c && c.username)) return cb()
19
20 var params = {
21 timeout: 60000,
22 auth: c
23 }
24 npm.registry.get(uri + c.username, params, function (er, list) {
25 if (er) return cb()
26 console.error(list)
27 return cb(null, list[c.username])
28 })
29 })
30}
31
32function deprecate (args, cb) {
33 var pkg = args[0]
34 var msg = args[1]
35 if (msg === undefined) return cb('Usage: ' + deprecate.usage)
36
37 // fetch the data and make sure it exists.
38 var p = npa(pkg)
39
40 // npa makes the default spec "latest", but for deprecation
41 // "*" is the appropriate default.
42 var spec = p.rawSpec === '' ? '*' : p.fetchSpec
43
44 mapToRegistry(p.name, npm.config, function (er, uri, auth) {
45 if (er) return cb(er)
46
47 var params = {
48 version: spec,
49 message: msg,
50 auth: auth
51 }
52 npm.registry.deprecate(uri, params, cb)
53 })
54}