Added alternative to loading plugins.

feature/bun
SamTV12345 2023-10-03 16:56:30 +02:00
parent e319711e80
commit 0e9020ee1f
5 changed files with 44 additions and 25 deletions

View File

@ -137,7 +137,7 @@ try {
writeJson('./src/package.json', pkg); writeJson('./src/package.json', pkg);
// run npm version `release` where release is patch, minor or major // run npm version `release` where release is patch, minor or major
run('npm install --package-lock-only', {cwd: 'src/'}); run('bun install --package-lock-only', {cwd: 'src/'});
// run npm install --package-lock-only <-- required??? // run npm install --package-lock-only <-- required???
// Many users will be using the latest LTS version of npm, and the latest LTS version of npm uses // Many users will be using the latest LTS version of npm, and the latest LTS version of npm uses

Binary file not shown.

View File

@ -33,6 +33,7 @@
"async": "^3.2.4", "async": "^3.2.4",
"axios": "^1.5.1", "axios": "^1.5.1",
"clean-css": "^5.3.2", "clean-css": "^5.3.2",
"command-exists": "^1.2.9",
"cookie-parser": "^1.4.6", "cookie-parser": "^1.4.6",
"cross-spawn": "^7.0.3", "cross-spawn": "^7.0.3",
"ejs": "^3.1.9", "ejs": "^3.1.9",

View File

@ -34,7 +34,7 @@ exports.uninstall = async (pluginName, cb = null) => {
// The --no-save flag prevents npm from creating package.json or package-lock.json. // 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: // The --legacy-peer-deps flag is required to work around a bug in npm v7:
// https://github.com/npm/cli/issues/2199 // https://github.com/npm/cli/issues/2199
await runCmd(['npm', 'uninstall', '--no-save', '--legacy-peer-deps', pluginName]); await runCmd(['bun', 'uninstall', '--no-save', '--legacy-peer-deps', pluginName]);
} catch (err) { } catch (err) {
logger.error(`Failed to uninstall plugin ${pluginName}`); logger.error(`Failed to uninstall plugin ${pluginName}`);
cb(err || new Error(err)); cb(err || new Error(err));
@ -53,7 +53,7 @@ exports.install = async (pluginName, cb = null) => {
// The --no-save flag prevents npm from creating package.json or package-lock.json. // 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: // The --legacy-peer-deps flag is required to work around a bug in npm v7:
// https://github.com/npm/cli/issues/2199 // https://github.com/npm/cli/issues/2199
await runCmd(['npm', 'install', '--no-save', '--legacy-peer-deps', pluginName]); await runCmd(['bun', 'install', '--no-save', '--legacy-peer-deps', pluginName]);
} catch (err) { } catch (err) {
logger.error(`Failed to install plugin ${pluginName}`); logger.error(`Failed to install plugin ${pluginName}`);
cb(err || new Error(err)); cb(err || new Error(err));
@ -72,19 +72,19 @@ exports.getAvailablePlugins = (maxCacheAge) => {
const nowTimestamp = Math.round(Date.now() / 1000); const nowTimestamp = Math.round(Date.now() / 1000);
return new Promise(async (resolve, reject) => { return new Promise(async (resolve, reject) => {
// check cache age before making any request // check cache age before making any request
if (exports.availablePlugins && maxCacheAge && (nowTimestamp - cacheTimestamp) <= maxCacheAge) { if (exports.availablePlugins && maxCacheAge && (nowTimestamp - cacheTimestamp) <= maxCacheAge) {
return resolve(exports.availablePlugins); return resolve(exports.availablePlugins);
} }
await axios.get('https://static.etherpad.org/plugins.json') await axios.get('https://static.etherpad.org/plugins.json')
.then(pluginsLoaded => { .then((pluginsLoaded) => {
exports.availablePlugins = pluginsLoaded.data; exports.availablePlugins = pluginsLoaded.data;
cacheTimestamp = nowTimestamp; cacheTimestamp = nowTimestamp;
resolve(exports.availablePlugins); resolve(exports.availablePlugins);
}) });
}) });
} };
exports.search = (searchTerm, maxCacheAge) => exports.getAvailablePlugins(maxCacheAge).then( exports.search = (searchTerm, maxCacheAge) => exports.getAvailablePlugins(maxCacheAge).then(

View File

@ -8,6 +8,7 @@ const runCmd = require('../../../node/utils/run_cmd');
const tsort = require('./tsort'); const tsort = require('./tsort');
const pluginUtils = require('./shared'); const pluginUtils = require('./shared');
const defs = require('./plugin_defs'); const defs = require('./plugin_defs');
const {cwd} = require("os");
const logger = log4js.getLogger('plugins'); const logger = log4js.getLogger('plugins');
@ -111,16 +112,33 @@ exports.getPackages = async () => {
// * 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 = ['npm', 'ls', '--long', '--json', '--depth=0', '--no-production']; const commandExists = require('command-exists').sync;
const {dependencies = {}} = JSON.parse(await runCmd(cmd, {stdio: [null, 'string']})); if (commandExists('bun')) {
await Promise.all(Object.entries(dependencies).map(async ([pkg, info]) => { const file = Bun.readFile('package.json');
if (!pkg.startsWith(exports.prefix)) {
delete dependencies[pkg]; const text = await file.text();
return; const parsedJSON = JSON.parse(text);
} const dependencies = parsedJSON.dependencies;
info.realPath = await fs.realpath(info.path); await Promise.all(Object.entries(dependencies).map(async (pkg) => {
})); const info = Object();
return dependencies; if (!pkg.startsWith(exports.prefix)) {
delete dependencies[pkg];
return;
}
info.realPath = `${cwd}/node_modules/${pkg}`;
}));
} else {
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(exports.prefix)) {
delete dependencies[pkg];
return;
}
info.realPath = await fs.realpath(info.path);
}));
return dependencies;
}
}; };
const loadPlugin = async (packages, pluginName, plugins, parts) => { const loadPlugin = async (packages, pluginName, plugins, parts) => {