mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-01-19 14:13:34 +01:00
plugins: Use npm
CLI to install/uninstall plugins
Using npm as a module has long been discouraged and will stop working with npm v7.
This commit is contained in:
parent
9633b98f92
commit
b3b5af3c3c
2 changed files with 5 additions and 17 deletions
|
@ -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)
|
||||
|
|
|
@ -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));
|
||||
|
|
Loading…
Reference in a new issue