diff --git a/src/package.json b/src/package.json index 04c9c78c4..49c1d9497 100644 --- a/src/package.json +++ b/src/package.json @@ -49,7 +49,7 @@ "jsdom": "^24.0.0", "jsonminify": "0.4.2", "languages4translatewiki": "0.1.3", - "live-plugin-manager": "^0.18.1", + "live-plugin-manager-pnpm": "^0.18.1", "lodash.clonedeep": "4.5.0", "log4js": "^6.9.1", "measured-core": "^2.0.0", diff --git a/src/pnpm-lock.yaml b/src/pnpm-lock.yaml index 38aa8dd07..e1a94829e 100644 --- a/src/pnpm-lock.yaml +++ b/src/pnpm-lock.yaml @@ -62,7 +62,7 @@ dependencies: languages4translatewiki: specifier: 0.1.3 version: 0.1.3 - live-plugin-manager: + live-plugin-manager-pnpm: specifier: ^0.18.1 version: 0.18.1 lodash.clonedeep: @@ -3524,8 +3524,8 @@ packages: wrap-ansi: 7.0.0 dev: true - /live-plugin-manager@0.18.1: - resolution: {integrity: sha512-GvLMSaZ1Cc18o91NiHLRuPXm1z7xDiUXUGgQ6jAwGM/x0FY8vXXHa/+LMNb2zrkAV2bWULCs0FEwX9yRsmFZmw==} + /live-plugin-manager-pnpm@0.18.1: + resolution: {integrity: sha512-B+H8lL1LrXS8VIXyyVAoX9NPQx4aVFRvjbQEfBLiaxEMEH/MqI/+Yxyetps9/TfVdes8LCLzDMTWoo/lxZpnSw==} dependencies: '@types/debug': 4.1.12 '@types/fs-extra': 9.0.13 diff --git a/src/static/js/pluginfw/installer.js b/src/static/js/pluginfw/installer.js index 7092ac36c..8d23e13a9 100644 --- a/src/static/js/pluginfw/installer.js +++ b/src/static/js/pluginfw/installer.js @@ -6,10 +6,10 @@ const hooks = require('./hooks'); const runCmd = require('../../../node/utils/run_cmd'); const settings = require('../../../node/utils/Settings'); const axios = require('axios'); -const {PluginManager} = require("live-plugin-manager"); -const {promises: fs} = require("fs"); -const path = require("path"); -const {findEtherpadRoot} = require("../../../node/utils/AbsolutePaths"); +const {PluginManager} = require('live-plugin-manager-pnpm'); +const {promises: fs} = require('fs'); +const path = require('path'); +const {findEtherpadRoot} = require('../../../node/utils/AbsolutePaths'); const logger = log4js.getLogger('plugins'); exports.manager = new PluginManager(); @@ -25,8 +25,8 @@ const onAllTasksFinished = async () => { }; const headers = { - 'User-Agent': 'Etherpad/' + settings.getEpVersion(), -} + 'User-Agent': `Etherpad/${settings.getEpVersion()}`, +}; let tasks = 0; @@ -41,24 +41,25 @@ const wrapTaskCb = (cb) => { }; const migratePluginsFromNodeModules = async () => { - logger.info('start migration of plugins in node_modules') + logger.info('start migration of plugins in node_modules'); // 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 // 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). const cmd = ['pnpm', 'ls', '--long', '--json', '--depth=0', '--no-production']; - const {dependencies = {}} = JSON.parse(await runCmd(cmd, {stdio: [null, 'string']})); - await Promise.all(Object.entries(dependencies).map(async ([pkg, info]) => { - if (pkg.startsWith(plugins.prefix) && pkg !== 'ep_etherpad-lite') { - if (!info._resolved) { - // Install from node_modules directory - await exports.manager.installFromPath(`${findEtherpadRoot()}/node_modules/${pkg}`); - } else { - await exports.manager.install(pkg); - } - } - })); + const [{dependencies = {}}] = JSON.parse(await runCmd(cmd, + {stdio: [null, 'string']})); + await Promise.all(Object.entries(dependencies) + .filter(([pkg, info]) => pkg.startsWith(plugins.prefix) && pkg !== 'ep_etherpad-lite') + .map(async ([pkg, info]) => { + if (!info._resolved) { + // Install from node_modules directory + await exports.manager.installFromPath(`${findEtherpadRoot()}/node_modules/${pkg}`); + } else { + await exports.manager.install(pkg); + } + })); await persistInstalledPlugins(); }; @@ -76,22 +77,22 @@ exports.checkForMigration = async () => { for (const plugin of installedPlugins.plugins) { 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 () => { - let installedPlugins = { plugins: []}; + const installedPlugins = {plugins: []}; for (const pkg of Object.values(await plugins.getPackages())) { installedPlugins.plugins.push({ name: pkg.name, version: pkg.version, - }) + }); } installedPlugins.plugins = [...new Set(installedPlugins.plugins)]; await fs.writeFile(installedPluginsPath, JSON.stringify(installedPlugins)); -} +}; exports.uninstall = async (pluginName, cb = null) => { cb = wrapTaskCb(cb); @@ -123,14 +124,13 @@ exports.getAvailablePlugins = (maxCacheAge) => { 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) => { exports.availablePlugins = pluginsLoaded.data; cacheTimestamp = nowTimestamp; - resolve(exports.availablePlugins);}) - .catch(async err => { - return reject(err); - }); + resolve(exports.availablePlugins); + }) + .catch(async (err) => reject(err)); }); };