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
diff options
context:
space:
mode:
authorRebecca Turner <me@re-becca.org>2015-07-09 11:30:10 +0300
committerRebecca Turner <me@re-becca.org>2015-07-10 12:04:44 +0300
commit9babfd63f19f2d80b2d2624e0963b0bdb0d76ef4 (patch)
treecb024d5a14666c7344b1fd8a77c7035803c60871 /lib/install.js
parent148a8c5b21ea6e8df793a8aa500bdedffde09d6e (diff)
install: uninstall: Limit global tree manipulation to named pkgs
PR-URL: https://github.com/npm/npm/pull/8876 Fixes: https://github.com/npm/npm/issues/8608
Diffstat (limited to 'lib/install.js')
-rw-r--r--lib/install.js61
1 files changed, 39 insertions, 22 deletions
diff --git a/lib/install.js b/lib/install.js
index cf6916d34..b422764ac 100644
--- a/lib/install.js
+++ b/lib/install.js
@@ -116,6 +116,7 @@ var readShrinkwrap = require('./install/read-shrinkwrap.js')
var recalculateMetadata = require('./install/deps.js').recalculateMetadata
var loadDeps = require('./install/deps.js').loadDeps
var loadDevDeps = require('./install/deps.js').loadDevDeps
+var getAllMetadata = require('./install/deps.js').getAllMetadata
var loadRequestedDeps = require('./install/deps.js').loadRequestedDeps
var loadExtraneous = require('./install/deps.js').loadExtraneous
var pruneTree = require('./install/prune-tree.js')
@@ -284,6 +285,14 @@ Installer.prototype.run = function (cb) {
})
}
+Installer.prototype.loadArgMetadata = function (next) {
+ var self = this
+ getAllMetadata(this.args, this.currentTree, iferr(next, function (args) {
+ self.args = args
+ next()
+ }))
+}
+
Installer.prototype.newTracker = function (tracker, name, size) {
validate('OS', [tracker, name])
if (size) validate('N', [size])
@@ -305,10 +314,15 @@ Installer.prototype.finishTracker = function (name, cb) {
Installer.prototype.loadCurrentTree = function (cb) {
validate('F', arguments)
log.silly('install', 'loadCurrentTree')
- chain([
- [this, this.readLocalPackageData],
- [this, this.normalizeTree, log.newGroup('normalizeTree')]
- ], cb)
+ var todo = []
+ if (this.global) {
+ todo.push([this, this.readGlobalPackageData])
+ } else {
+ todo.push([this, this.readLocalPackageData])
+ }
+ todo.push(
+ [this, this.normalizeTree, log.newGroup('normalizeTree')])
+ chain(todo, cb)
}
Installer.prototype.loadIdealTree = function (cb) {
@@ -345,9 +359,6 @@ Installer.prototype.loadAllDepsIntoIdealTree = function (cb) {
if (installNewModules) {
steps.push([loadRequestedDeps, this.args, this.idealTree, saveDeps, cg.newGroup('loadRequestedDeps')])
- if (this.global) {
- steps.push([this, this.filterGlobalTrees])
- }
} else {
steps.push(
[loadDeps, this.idealTree, cg.newGroup('loadDeps')])
@@ -361,20 +372,6 @@ Installer.prototype.loadAllDepsIntoIdealTree = function (cb) {
chain(steps, cb)
}
-Installer.prototype.filterGlobalTrees = function (cb) {
- validate('F', arguments)
- log.silly('install', 'filterGlobalTrees')
- var modules = {}
- this.idealTree.children = this.idealTree.children.filter(function (child) {
- if (child.isGlobal) { modules[child.package.name] = true }
- return child.isGlobal
- })
- this.currentTree.children = this.currentTree.children.filter(function (child) {
- return modules[child.package.name]
- })
- cb()
-}
-
Installer.prototype.generateActionsToTake = function (cb) {
validate('F', arguments)
log.silly('install', 'generateActionsToTake')
@@ -541,6 +538,26 @@ Installer.prototype.saveToDependencies = function (cb) {
saveRequested(this.args, this.idealTree, cb)
}
+Installer.prototype.readGlobalPackageData = function (cb) {
+ validate('F', arguments)
+ log.silly('install', 'readGlobalPackageData')
+ var self = this
+ this.currentTree = new readPackageTree.Node(null, this.where, this.where, null, {})
+ this.loadArgMetadata(iferr(cb, function () {
+ mkdirp(self.where, iferr(cb, function () {
+ asyncMap(self.args, function (pkg, done) {
+ readPackageTree(path.resolve(self.where, 'node_modules', pkg.name), function (err, subTree) {
+ if (subTree) {
+ subTree.parent = self.currentTree
+ self.currentTree.children.push(subTree)
+ }
+ done()
+ })
+ }, cb)
+ }))
+ }))
+}
+
Installer.prototype.readLocalPackageData = function (cb) {
validate('F', arguments)
log.silly('install', 'readLocalPackageData')
@@ -565,7 +582,7 @@ Installer.prototype.readLocalPackageData = function (cb) {
} catch (ex) {
return cb(ex)
}
- return cb()
+ return this.loadArgMetadata(cb)
})
}))
}))