forked from npm/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deprecate.js
50 lines (41 loc) · 1.26 KB
/
deprecate.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
var npm = require('./npm.js')
var mapToRegistry = require('./utils/map-to-registry.js')
var 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
var path = '/-/by-user/'
mapToRegistry(path, npm.config, function (er, uri, c) {
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) {
if (er) return cb()
console.error(list)
return cb(null, list[c.username])
})
})
}
function deprecate (args, cb) {
var pkg = args[0]
var msg = args[1]
if (msg === undefined) return cb('Usage: ' + deprecate.usage)
// fetch the data and make sure it exists.
var p = npa(pkg)
mapToRegistry(p.name, npm.config, function (er, uri, auth) {
if (er) return cb(er)
var params = {
version: p.spec,
message: msg,
auth: auth
}
npm.registry.deprecate(uri, params, cb)
})
}