Added pnpm (#6148)

* Added pnpm

* Removed cache for npm.

* Fixed.

* Added pnpm

* Fixed install script.

* Fixed windows script.

* Fixed.

* Fixed.

* Fixed install.

* Only install direct dependencies.

* Only install direct dependencies.

* Only install direct dependencies.

* Fixed windows build.

* fixed.

* fixed deploy.

* Fixed docker build.

* Fixed windows deploy

* Fixed docker build

* Fixed healthcheck.

* fixed.

* Fixed detection of live plugin managers dependencies.

* fixed.

* Remove Node 19 as it is not supported.

* Fixed.

* Fixed installDeps.sh

* Fixed.

* Fixed windows install.

* Fixed cypress path.

* Fixed.

* Run etherpad in background.

* Install cypress.
This commit is contained in:
SamTV12345 2024-02-11 09:51:42 +01:00 committed by GitHub
parent 96c81906cb
commit 361b38ae50
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
28 changed files with 5804 additions and 10007 deletions

View file

@ -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 = ['npm', '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 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)
.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));
});
};

View file

@ -16,10 +16,10 @@ const logger = log4js.getLogger('plugins');
// Log the version of npm at startup.
(async () => {
try {
const version = await runCmd(['npm', '--version'], {stdio: [null, 'string']});
logger.info(`npm --version: ${version}`);
const version = await runCmd(['pnpm', '--version'], {stdio: [null, 'string']});
logger.info(`pnpm --version: ${version}`);
} catch (err) {
logger.error(`Failed to get npm version: ${err.stack || err}`);
logger.error(`Failed to get pnpm version: ${err.stack || err}`);
// This isn't a fatal error so don't re-throw.
}
})();