From d2239b823cf2627b6356bb796fbbed96121993b5 Mon Sep 17 00:00:00 2001 From: Rebecca Turner Date: Wed, 1 Jul 2015 01:45:10 -0400 Subject: install: determine globalness based on install dir not config PR-URL: https://github.com/npm/npm/pull/8782 --- lib/install.js | 27 +++++++++++++++++++++++---- lib/ls.js | 4 +--- 2 files changed, 24 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/install.js b/lib/install.js index c29ec5e9a..db01693bc 100644 --- a/lib/install.js +++ b/lib/install.js @@ -160,16 +160,17 @@ function install (where, args, cb) { args = where where = null } + var globalTop = path.resolve(npm.globalDir, '..') if (!where) { where = npm.config.get('global') - ? path.resolve(npm.globalDir, '..') + ? globalTop : npm.prefix } validate('SAF', [where, args, cb]) // the /path/to/node_modules/.. var dryrun = !!npm.config.get('dry-run') - if (npm.config.get('global') && !args.length) { + if (where === globalTop && !args.length) { args = ['.'] } args = args.filter(function (a) { @@ -195,12 +196,30 @@ function Installer (where, dryrun, args) { this.dev = npm.config.get('dev') || !npm.config.get('production') this.rollback = npm.config.get('rollback') this.link = npm.config.get('link') + this.global = this.where === path.resolve(npm.globalDir, '..') } Installer.prototype = {} Installer.prototype.run = function (cb) { validate('F', arguments) + // FIXME: This is bad and I should feel bad. + // lib/install needs to have some way of sharing _limited_ + // state with the things it calls. Passing the object is too + // much. The global config is WAY too much. =( =( + // But not having this is gonna break linked modules in + // subtle stupid ways, and refactoring all this code isn't + // the right thing to do just yet. + if (this.global) { + var prevGlobal = npm.config.get('global') + npm.config.set('global', true) + var next = cb + cb = function () { + npm.config.set('global', prevGlobal) + next.apply(null, arguments) + } + } + var installSteps = [] var postInstallSteps = [] installSteps.push( @@ -323,7 +342,7 @@ Installer.prototype.loadAllDepsIntoIdealTree = function (cb) { if (installNewModules) { steps.push([loadRequestedDeps, this.args, this.idealTree, saveDeps, cg.newGroup('loadRequestedDeps')]) - if (npm.config.get('global')) { + if (this.global) { steps.push([this, this.filterGlobalTrees]) } } else { @@ -369,7 +388,7 @@ Installer.prototype.generateActionsToTake = function (cb) { Installer.prototype.computeLinked = function (cb) { validate('F', arguments) - if (!this.link || npm.config.get('global')) return cb() + if (!this.link || this.global) return cb() var linkTodoList = [] var self = this asyncMap(this.differences, function (action, next) { diff --git a/lib/ls.js b/lib/ls.js index 4d86d1ac2..3903c5a13 100644 --- a/lib/ls.js +++ b/lib/ls.js @@ -142,9 +142,7 @@ function getLite (data, noname) { if (data.extraneous) { lite.extraneous = true lite.problems = lite.problems || [] - lite.problems.push('extraneous: ' + - data.name + '@' + data.version + - ' ' + (data.path || '')) + lite.problems.push('extraneous: ' + data._id + ' ' + (data.path || '')) } if (data._from) { -- cgit v1.2.3