diff --git a/src/bin/release.js b/src/bin/release.js index 55df435b6..03dcfc203 100644 --- a/src/bin/release.js +++ b/src/bin/release.js @@ -137,7 +137,7 @@ try { writeJson('./src/package.json', pkg); // 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??? // Many users will be using the latest LTS version of npm, and the latest LTS version of npm uses diff --git a/src/bun.lockb b/src/bun.lockb index 18e0fe611..76fca1e23 100755 Binary files a/src/bun.lockb and b/src/bun.lockb differ diff --git a/src/package.json b/src/package.json index 2062cb7b8..f08acd8b3 100644 --- a/src/package.json +++ b/src/package.json @@ -33,6 +33,7 @@ "async": "^3.2.4", "axios": "^1.5.1", "clean-css": "^5.3.2", + "command-exists": "^1.2.9", "cookie-parser": "^1.4.6", "cross-spawn": "^7.0.3", "ejs": "^3.1.9", diff --git a/src/static/js/pluginfw/installer.js b/src/static/js/pluginfw/installer.js index 6c5784b00..d2f935e86 100644 --- a/src/static/js/pluginfw/installer.js +++ b/src/static/js/pluginfw/installer.js @@ -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 --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]); + await runCmd(['bun', 'uninstall', '--no-save', '--legacy-peer-deps', pluginName]); } catch (err) { logger.error(`Failed to uninstall plugin ${pluginName}`); 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 --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]); + await runCmd(['bun', 'install', '--no-save', '--legacy-peer-deps', pluginName]); } catch (err) { logger.error(`Failed to install plugin ${pluginName}`); cb(err || new Error(err)); @@ -72,19 +72,19 @@ exports.getAvailablePlugins = (maxCacheAge) => { const nowTimestamp = Math.round(Date.now() / 1000); return new Promise(async (resolve, reject) => { - // check cache age before making any request - if (exports.availablePlugins && maxCacheAge && (nowTimestamp - cacheTimestamp) <= maxCacheAge) { - return resolve(exports.availablePlugins); - } + // check cache age before making any request + if (exports.availablePlugins && maxCacheAge && (nowTimestamp - cacheTimestamp) <= maxCacheAge) { + return resolve(exports.availablePlugins); + } - await axios.get('https://static.etherpad.org/plugins.json') - .then(pluginsLoaded => { - exports.availablePlugins = pluginsLoaded.data; - cacheTimestamp = nowTimestamp; - resolve(exports.availablePlugins); - }) - }) -} + await axios.get('https://static.etherpad.org/plugins.json') + .then((pluginsLoaded) => { + exports.availablePlugins = pluginsLoaded.data; + cacheTimestamp = nowTimestamp; + resolve(exports.availablePlugins); + }); + }); +}; exports.search = (searchTerm, maxCacheAge) => exports.getAvailablePlugins(maxCacheAge).then( diff --git a/src/static/js/pluginfw/plugins.js b/src/static/js/pluginfw/plugins.js index e7ac500c3..73b72acf8 100644 --- a/src/static/js/pluginfw/plugins.js +++ b/src/static/js/pluginfw/plugins.js @@ -8,6 +8,7 @@ const runCmd = require('../../../node/utils/run_cmd'); const tsort = require('./tsort'); const pluginUtils = require('./shared'); const defs = require('./plugin_defs'); +const {cwd} = require("os"); 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 // 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(exports.prefix)) { - delete dependencies[pkg]; - return; - } - info.realPath = await fs.realpath(info.path); - })); - return dependencies; + const commandExists = require('command-exists').sync; + if (commandExists('bun')) { + const file = Bun.readFile('package.json'); + + const text = await file.text(); + const parsedJSON = JSON.parse(text); + const dependencies = parsedJSON.dependencies; + await Promise.all(Object.entries(dependencies).map(async (pkg) => { + const info = Object(); + 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) => {