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
51
52
53
54
55
56
57
58
59
60
|
// remove a package.
module.exports = uninstall
uninstall.usage = "npm uninstall <name>[@<version> [<name>[@<version>] ...]"
+ "\nnpm rm <name>[@<version> [<name>[@<version>] ...]"
uninstall.completion = require("./utils/completion/installed-shallow.js")
var fs = require("graceful-fs")
, log = require("npmlog")
, readJson = require("./utils/read-json.js")
, path = require("path")
, npm = require("./npm.js")
, semver = require("semver")
, asyncMap = require("slide").asyncMap
function uninstall (args, cb) {
// this is super easy
// get the list of args that correspond to package names in either
// the global npm.dir,
// then call unbuild on all those folders to pull out their bins
// and mans and whatnot, and then delete the folder.
var nm = npm.dir
if (args.length === 1 && args[0] === ".") args = []
if (args.length) return uninstall_(args, nm, cb)
// remove this package from the global space, if it's installed there
if (npm.config.get("global")) return cb(uninstall.usage)
readJson(path.resolve(npm.prefix, "package.json"), function (er, pkg) {
if (er) return cb(uninstall.usage)
uninstall_( [pkg.name]
, npm.dir
, cb )
})
}
function uninstall_ (args, nm, cb) {
asyncMap(args, function (arg, cb) {
// uninstall .. should not delete /usr/local/lib/node_modules/..
var p = path.join(path.resolve(nm), path.join("/", arg))
if (path.resolve(p) === nm) {
log.warn("uninstall", "invalid argument: %j", arg)
return cb(null, [])
}
fs.lstat(p, function (er) {
if (er) {
log.warn("uninstall", "not installed in %s: %j", nm, arg)
return cb(null, [])
}
cb(null, p)
})
}, function (er, folders) {
if (er) return cb(er)
asyncMap(folders, npm.commands.unbuild, cb)
})
}
|