Implemented PoC for managing plugins with live-plugin-manager

This commit is contained in:
Stefan Müller 2023-10-29 16:58:11 +01:00 committed by SamTV12345
parent 71a29884d6
commit 69de1608e2
4 changed files with 16 additions and 23 deletions

View file

@ -37,16 +37,7 @@ const wrapTaskCb = (cb) => {
exports.uninstall = async (pluginName, cb = null) => {
cb = wrapTaskCb(cb);
logger.info(`Uninstalling plugin ${pluginName}...`);
try {
// The --no-save flag prevents npm from creating package.json or package-lock.json.
// The --legacy-peer-deps flag is required to work around a bug in npm v7:
// https://github.com/npm/cli/issues/2199
await runCmd(['npm', 'uninstall', '--no-save', '--legacy-peer-deps', pluginName]);
} catch (err) {
logger.error(`Failed to uninstall plugin ${pluginName}`);
cb(err || new Error(err));
throw err;
}
await exports.manager.uninstall(pluginName);
logger.info(`Successfully uninstalled plugin ${pluginName}`);
await hooks.aCallAll('pluginUninstall', {pluginName});
await plugins.update();
@ -56,16 +47,7 @@ exports.uninstall = async (pluginName, cb = null) => {
exports.install = async (pluginName, cb = null) => {
cb = wrapTaskCb(cb);
logger.info(`Installing plugin ${pluginName}...`);
try {
// The --no-save flag prevents npm from creating package.json or package-lock.json.
// The --legacy-peer-deps flag is required to work around a bug in npm v7:
// https://github.com/npm/cli/issues/2199
await runCmd(['npm', 'install', '--no-save', '--legacy-peer-deps', pluginName]);
} catch (err) {
logger.error(`Failed to install plugin ${pluginName}`);
cb(err || new Error(err));
throw err;
}
await exports.manager.install(pluginName);
logger.info(`Successfully installed plugin ${pluginName}`);
await hooks.aCallAll('pluginInstall', {pluginName});
await plugins.update();

View file

@ -84,6 +84,8 @@ exports.pathNormalization = (part, hookFnName, hookName) => {
};
exports.update = async () => {
await manager.install('ep_bookmark')
await manager.install('ep_align')
const packages = await exports.getPackages();
const parts = {}; // Key is full name. sortParts converts this into a topologically sorted array.
const plugins = {};
@ -107,6 +109,13 @@ exports.update = async () => {
exports.getPackages = async () => {
logger.info('Running npm to get a list of installed plugins...');
let plugins = manager.list()
let newDependencies = {}
for (const plugin of plugins) {
plugin.realPath = await fs.realpath(plugin.location);
plugin.path = plugin.realPath;
newDependencies[plugin.name] = plugin
}
// Notes:
// * Do not pass `--prod` otherwise `npm ls` will fail if there is no `package.json`.
// * The `--no-production` flag is required (or the `NODE_ENV` environment variable must be
@ -121,11 +130,12 @@ exports.getPackages = async () => {
}
info.realPath = await fs.realpath(info.path);
}));
return dependencies;
let newList = Object.assign({}, dependencies, newDependencies)
console.log('blub', newList)
return newList;
};
const loadPlugin = async (packages, pluginName, plugins, parts) => {
console.log('Plugins', manager.list());
const pluginPath = path.resolve(packages[pluginName].path, 'ep.json');
try {
const data = await fs.readFile(pluginPath);