Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRebecca Turner <me@re-becca.org>2015-06-04 13:40:29 +0300
committerRebecca Turner <me@re-becca.org>2015-06-26 03:27:08 +0300
commit2caff812d8022722092a6d5dc076ad639d401e77 (patch)
tree30f403f3d514c91d15801bcf637354cc1c57f40f /lib
parent0cbd644fcd04eaddda60397191f50a3bfcdde477 (diff)
Make `npm uninstall -g` uninstall the current package
Diffstat (limited to 'lib')
-rw-r--r--lib/uninstall.js19
1 files changed, 15 insertions, 4 deletions
diff --git a/lib/uninstall.js b/lib/uninstall.js
index 1ec37eab8..33de8da64 100644
--- a/lib/uninstall.js
+++ b/lib/uninstall.js
@@ -11,6 +11,7 @@ var util = require('util')
var path = require('path')
var validate = require('aproba')
var chain = require('slide').chain
+var readJson = require('read-package-json')
var npm = require('./npm.js')
var Installer = require('./install.js').Installer
var getSaveType = require('./install/save.js').getSaveType
@@ -23,16 +24,26 @@ uninstall.completion = require('./utils/completion/installed-shallow.js')
function uninstall (args, cb) {
validate('AF', arguments)
// the /path/to/node_modules/..
- var where = path.resolve(npm.dir, '..')
+ var where = npm.config.get('global')
+ ? path.resolve(npm.globalDir, '..')
+ : npm.prefix
var dryrun = !!npm.config.get('dry-run')
+ if (args.length === 1 && args[0] === ".") args = []
args = args.filter(function (a) {
return path.resolve(a) !== where
})
- if (!args.length) return cb(uninstall.usage)
-
- new Uninstaller(where, dryrun, args).run(cb)
+ if (args.length) {
+ new Uninstaller(where, dryrun, args).run(cb)
+ } else {
+ // remove this package from the global space, if it's installed there
+ readJson(path.resolve(npm.localPrefix, "package.json"), function (er, pkg) {
+ if (er && er.code !== "ENOENT" && er.code !== "ENOTDIR") return cb(er)
+ if (er) return cb(uninstall.usage)
+ new Uninstaller(where, dryrun, [pkg.name]).run(cb)
+ })
+ }
}
function Uninstaller (where, dryrun, args) {