diff options
author | Rebecca Turner <me@re-becca.org> | 2015-06-18 19:59:11 +0300 |
---|---|---|
committer | Rebecca Turner <me@re-becca.org> | 2015-06-26 03:27:30 +0300 |
commit | 3cdbce36758ac2da6dd5a002664ac162f5380792 (patch) | |
tree | 529ca4befeff8abacbd5ee8aa78769569ceb19f8 /lib/install | |
parent | 9e030f7426958c8df7f292acc823d97d979916fd (diff) |
install: Refactor --link to behave better
Diffstat (limited to 'lib/install')
-rw-r--r-- | lib/install/action/global-install.js | 10 | ||||
-rw-r--r-- | lib/install/decompose-actions.js | 34 |
2 files changed, 7 insertions, 37 deletions
diff --git a/lib/install/action/global-install.js b/lib/install/action/global-install.js index 5d4054bab..25c61aebd 100644 --- a/lib/install/action/global-install.js +++ b/lib/install/action/global-install.js @@ -1,12 +1,16 @@ 'use strict' +var path = require('path') var npm = require('../../npm.js') +var Installer = require('../../install.js').Installer module.exports = function (top, buildpath, pkg, log, next) { log.silly('global-install', pkg.package.name) - var oldGlobal = npm.config.get('global') + var globalRoot = path.resolve(npm.globalDir, '..') npm.config.set('global', true) - npm.install(pkg.package._resolved, function () { - npm.config.set('global', oldGlobal) + var install = new Installer(globalRoot, false, [pkg.package.name + '@' + pkg.package._requested.spec]) + install.link = false + install.run(function () { + npm.config.set('global', false) next.apply(null, arguments) }) } diff --git a/lib/install/decompose-actions.js b/lib/install/decompose-actions.js index 2cc23fbf7..2921fccba 100644 --- a/lib/install/decompose-actions.js +++ b/lib/install/decompose-actions.js @@ -13,11 +13,7 @@ module.exports = function (differences, decomposed, next) { switch (cmd) { case 'add': case 'update': - if (npm.config.get('link') && !npm.config.get('global')) { - linkSteps(decomposed, pkg, done) - } else { addSteps(decomposed, pkg, done) - } break case 'move': moveSteps(decomposed, pkg, done) @@ -30,36 +26,6 @@ module.exports = function (differences, decomposed, next) { }, next) } -function safeJSONparse (data) { - try { - return JSON.parse(data) - } - catch (ex) { - return - } -} - -function linkSteps(decomposed, pkg, done) { - // is pkg not installed globally or the wrong version: - // push on a 'global-install', pkg step - var globalPackage = path.resolve(npm.globalPrefix, 'lib', 'node_modules', pkg.package.name) - var globalPackageJson = path.resolve(globalPackage, 'package.json') - fs.stat(globalPackage, function (er) { - if (er) { - decomposed.push(['global-install', pkg]) - decomposed.push(['global-link', pkg]) - return done() - } - fs.readFile(globalPackageJson, function (err, data) { - var json = safeJSONparse(data) - if (!json || json.version !== pkg.package.version) return addSteps(decomposed, pkg, done) - - decomposed.push(['global-link', pkg]) - return done() - }) - }) -} - function addSteps(decomposed, pkg, done) { decomposed.push(['fetch', pkg]) decomposed.push(['extract', pkg]) |