1 | var npm = require('./npm.js')
|
2 | var mapToRegistry = require('./utils/map-to-registry.js')
|
3 | var npa = require('npm-package-arg')
|
4 |
|
5 | module.exports = deprecate
|
6 |
|
7 | deprecate.usage = 'npm deprecate <pkg>[@<version>] <message>'
|
8 |
|
9 | deprecate.completion = function (opts, cb) {
|
10 |
|
11 |
|
12 | if (opts.conf.argv.remain.length > 2) return cb()
|
13 |
|
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 |
|
32 | function deprecate (args, cb) {
|
33 | var pkg = args[0]
|
34 | var msg = args[1]
|
35 | if (msg === undefined) return cb('Usage: ' + deprecate.usage)
|
36 |
|
37 |
|
38 | var p = npa(pkg)
|
39 |
|
40 |
|
41 |
|
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 | }
|