Fixed detection of live plugin managers dependencies.

This commit is contained in:
SamTV12345 2024-02-10 20:46:43 +01:00
parent 04898c0e5f
commit 0c02ac0f91
3 changed files with 31 additions and 31 deletions

View file

@ -49,7 +49,7 @@
"jsdom": "^24.0.0", "jsdom": "^24.0.0",
"jsonminify": "0.4.2", "jsonminify": "0.4.2",
"languages4translatewiki": "0.1.3", "languages4translatewiki": "0.1.3",
"live-plugin-manager": "^0.18.1", "live-plugin-manager-pnpm": "^0.18.1",
"lodash.clonedeep": "4.5.0", "lodash.clonedeep": "4.5.0",
"log4js": "^6.9.1", "log4js": "^6.9.1",
"measured-core": "^2.0.0", "measured-core": "^2.0.0",

6
src/pnpm-lock.yaml generated
View file

@ -62,7 +62,7 @@ dependencies:
languages4translatewiki: languages4translatewiki:
specifier: 0.1.3 specifier: 0.1.3
version: 0.1.3 version: 0.1.3
live-plugin-manager: live-plugin-manager-pnpm:
specifier: ^0.18.1 specifier: ^0.18.1
version: 0.18.1 version: 0.18.1
lodash.clonedeep: lodash.clonedeep:
@ -3524,8 +3524,8 @@ packages:
wrap-ansi: 7.0.0 wrap-ansi: 7.0.0
dev: true dev: true
/live-plugin-manager@0.18.1: /live-plugin-manager-pnpm@0.18.1:
resolution: {integrity: sha512-GvLMSaZ1Cc18o91NiHLRuPXm1z7xDiUXUGgQ6jAwGM/x0FY8vXXHa/+LMNb2zrkAV2bWULCs0FEwX9yRsmFZmw==} resolution: {integrity: sha512-B+H8lL1LrXS8VIXyyVAoX9NPQx4aVFRvjbQEfBLiaxEMEH/MqI/+Yxyetps9/TfVdes8LCLzDMTWoo/lxZpnSw==}
dependencies: dependencies:
'@types/debug': 4.1.12 '@types/debug': 4.1.12
'@types/fs-extra': 9.0.13 '@types/fs-extra': 9.0.13

View file

@ -6,10 +6,10 @@ const hooks = require('./hooks');
const runCmd = require('../../../node/utils/run_cmd'); const runCmd = require('../../../node/utils/run_cmd');
const settings = require('../../../node/utils/Settings'); const settings = require('../../../node/utils/Settings');
const axios = require('axios'); const axios = require('axios');
const {PluginManager} = require("live-plugin-manager"); const {PluginManager} = require('live-plugin-manager-pnpm');
const {promises: fs} = require("fs"); const {promises: fs} = require('fs');
const path = require("path"); const path = require('path');
const {findEtherpadRoot} = require("../../../node/utils/AbsolutePaths"); const {findEtherpadRoot} = require('../../../node/utils/AbsolutePaths');
const logger = log4js.getLogger('plugins'); const logger = log4js.getLogger('plugins');
exports.manager = new PluginManager(); exports.manager = new PluginManager();
@ -25,8 +25,8 @@ const onAllTasksFinished = async () => {
}; };
const headers = { const headers = {
'User-Agent': 'Etherpad/' + settings.getEpVersion(), 'User-Agent': `Etherpad/${settings.getEpVersion()}`,
} };
let tasks = 0; let tasks = 0;
@ -41,24 +41,25 @@ const wrapTaskCb = (cb) => {
}; };
const migratePluginsFromNodeModules = async () => { const migratePluginsFromNodeModules = async () => {
logger.info('start migration of plugins in node_modules') logger.info('start migration of plugins in node_modules');
// Notes: // Notes:
// * Do not pass `--prod` otherwise `npm ls` will fail if there is no `package.json`. // * 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 // * The `--no-production` flag is required (or the `NODE_ENV` environment variable must be
// unset or set to `development`) because otherwise `npm ls` will not mention any packages // unset or set to `development`) because otherwise `npm ls` will not mention any packages
// that are not included in `package.json` (which is expected to not exist). // that are not included in `package.json` (which is expected to not exist).
const cmd = ['pnpm', 'ls', '--long', '--json', '--depth=0', '--no-production']; const cmd = ['pnpm', 'ls', '--long', '--json', '--depth=0', '--no-production'];
const {dependencies = {}} = JSON.parse(await runCmd(cmd, {stdio: [null, 'string']})); const [{dependencies = {}}] = JSON.parse(await runCmd(cmd,
await Promise.all(Object.entries(dependencies).map(async ([pkg, info]) => { {stdio: [null, 'string']}));
if (pkg.startsWith(plugins.prefix) && pkg !== 'ep_etherpad-lite') { await Promise.all(Object.entries(dependencies)
if (!info._resolved) { .filter(([pkg, info]) => pkg.startsWith(plugins.prefix) && pkg !== 'ep_etherpad-lite')
// Install from node_modules directory .map(async ([pkg, info]) => {
await exports.manager.installFromPath(`${findEtherpadRoot()}/node_modules/${pkg}`); if (!info._resolved) {
} else { // Install from node_modules directory
await exports.manager.install(pkg); await exports.manager.installFromPath(`${findEtherpadRoot()}/node_modules/${pkg}`);
} } else {
} await exports.manager.install(pkg);
})); }
}));
await persistInstalledPlugins(); await persistInstalledPlugins();
}; };
@ -76,22 +77,22 @@ exports.checkForMigration = async () => {
for (const plugin of installedPlugins.plugins) { for (const plugin of installedPlugins.plugins) {
if (plugin.name.startsWith(plugins.prefix) && plugin.name !== 'ep_etherpad-lite') { if (plugin.name.startsWith(plugins.prefix) && plugin.name !== 'ep_etherpad-lite') {
await exports.manager.install(plugin.name, plugin.version) await exports.manager.install(plugin.name, plugin.version);
} }
} }
}; };
const persistInstalledPlugins = async () => { const persistInstalledPlugins = async () => {
let installedPlugins = { plugins: []}; const installedPlugins = {plugins: []};
for (const pkg of Object.values(await plugins.getPackages())) { for (const pkg of Object.values(await plugins.getPackages())) {
installedPlugins.plugins.push({ installedPlugins.plugins.push({
name: pkg.name, name: pkg.name,
version: pkg.version, version: pkg.version,
}) });
} }
installedPlugins.plugins = [...new Set(installedPlugins.plugins)]; installedPlugins.plugins = [...new Set(installedPlugins.plugins)];
await fs.writeFile(installedPluginsPath, JSON.stringify(installedPlugins)); await fs.writeFile(installedPluginsPath, JSON.stringify(installedPlugins));
} };
exports.uninstall = async (pluginName, cb = null) => { exports.uninstall = async (pluginName, cb = null) => {
cb = wrapTaskCb(cb); cb = wrapTaskCb(cb);
@ -123,14 +124,13 @@ exports.getAvailablePlugins = (maxCacheAge) => {
return resolve(exports.availablePlugins); return resolve(exports.availablePlugins);
} }
await axios.get('https://static.etherpad.org/plugins.json', {headers: headers}) await axios.get('https://static.etherpad.org/plugins.json', {headers})
.then((pluginsLoaded) => { .then((pluginsLoaded) => {
exports.availablePlugins = pluginsLoaded.data; exports.availablePlugins = pluginsLoaded.data;
cacheTimestamp = nowTimestamp; cacheTimestamp = nowTimestamp;
resolve(exports.availablePlugins);}) resolve(exports.availablePlugins);
.catch(async err => { })
return reject(err); .catch(async (err) => reject(err));
});
}); });
}; };