diff --git a/src/node/server.js b/src/node/server.js index e890a020c..aec0d442f 100755 --- a/src/node/server.js +++ b/src/node/server.js @@ -43,11 +43,9 @@ const UpdateCheck = require('./utils/UpdateCheck'); const db = require('./db/DB'); const express = require('./hooks/express'); const hooks = require('../static/js/pluginfw/hooks'); -const npm = require('npm/lib/npm.js'); const pluginDefs = require('../static/js/pluginfw/plugin_defs'); const plugins = require('../static/js/pluginfw/plugins'); const settings = require('./utils/Settings'); -const util = require('util'); const logger = log4js.getLogger('server'); @@ -138,7 +136,6 @@ exports.start = async () => { }); } - await util.promisify(npm.load)(); await db.init(); await plugins.update(); const installedPlugins = Object.values(pluginDefs.plugins) diff --git a/src/static/js/pluginfw/installer.js b/src/static/js/pluginfw/installer.js index 5f2e6ea16..8908dbaaa 100644 --- a/src/static/js/pluginfw/installer.js +++ b/src/static/js/pluginfw/installer.js @@ -3,20 +3,11 @@ const log4js = require('log4js'); const plugins = require('./plugins'); const hooks = require('./hooks'); -const npm = require('npm'); const request = require('request'); -const util = require('util'); +const runCmd = require('../../../node/utils/run_cmd'); const logger = log4js.getLogger('plugins'); -let npmIsLoaded = false; -const loadNpm = async () => { - if (npmIsLoaded) return; - await util.promisify(npm.load)({}); - npmIsLoaded = true; - npm.on('log', log4js.getLogger('npm').log); -}; - const onAllTasksFinished = () => { hooks.aCallAll('restartServer', {}, () => {}); }; @@ -37,8 +28,8 @@ exports.uninstall = async (pluginName, cb = null) => { cb = wrapTaskCb(cb); logger.info(`Uninstalling plugin ${pluginName}...`); try { - await loadNpm(); - await util.promisify(npm.commands.uninstall)([pluginName]); + // The --no-save flag prevents npm from creating package.json or package-lock.json. + await runCmd(['npm', 'uninstall', '--no-save', pluginName]); } catch (err) { logger.error(`Failed to uninstall plugin ${pluginName}`); cb(err || new Error(err)); @@ -54,8 +45,8 @@ exports.install = async (pluginName, cb = null) => { cb = wrapTaskCb(cb); logger.info(`Installing plugin ${pluginName}...`); try { - await loadNpm(); - await util.promisify(npm.commands.install)([`${pluginName}@latest`]); + // The --no-save flag prevents npm from creating package.json or package-lock.json. + await runCmd(['npm', 'install', '--no-save', pluginName]); } catch (err) { logger.error(`Failed to install plugin ${pluginName}`); cb(err || new Error(err));