diff --git a/package.json b/package.json index ad8202986f..e1a026cf2e 100644 --- a/package.json +++ b/package.json @@ -56,7 +56,6 @@ "nodebb-theme-vanilla": "5.0.28", "nodebb-widget-essentials": "2.0.5", "nodemailer": "0.7.1", - "npm": "^2.1.4", "passport": "^0.3.0", "passport-local": "1.0.0", "postcss": "^5.0.13", diff --git a/src/plugins/install.js b/src/plugins/install.js index cdc8743b69..1ea826784c 100644 --- a/src/plugins/install.js +++ b/src/plugins/install.js @@ -87,10 +87,8 @@ module.exports = function(Plugins) { next(); }, function(next) { - require('npm').load({}, next); - }, - function(res, next) { - require('npm').commands[type](installed ? id : [id + '@' + (version || 'latest')], next); + var command = installed ? ('npm uninstall ' + id) : ('npm install ' + id + '@' + (version || 'latest')); + runNpmCommand(command, next); } ], function(err) { if (err) { @@ -105,6 +103,16 @@ module.exports = function(Plugins) { }); } + function runNpmCommand(command, callback) { + require('child_process').exec(command, function (err, stdout) { + if (err) { + return callback(err); + } + winston.info('[plugins] ' + stdout); + callback(err); + }); + } + Plugins.upgrade = function(id, version, callback) { pubsub.publish('plugins:upgrade', {hostname: os.hostname(), id: id, version: version}); upgrade(id, version, callback); @@ -113,12 +121,7 @@ module.exports = function(Plugins) { function upgrade(id, version, callback) { async.waterfall([ function(next) { - require('npm').load({}, next); - }, - function(res, next) { - require('npm').commands.install([id + '@' + (version || 'latest')], function(err, a, b) { - next(err); - }); + runNpmCommand('npm install ' + id + '@' + (version || 'latest'), next); }, function(next) { Plugins.isActive(id, next);