From ecc1385b8a081416bbb2dc86296c19edc2d65606 Mon Sep 17 00:00:00 2001 From: Vytenis Date: Sun, 10 Nov 2024 11:37:25 +0200 Subject: [PATCH] Add bunjs support --- packages/mrm-core/src/npm.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/packages/mrm-core/src/npm.js b/packages/mrm-core/src/npm.js index 11cd841b..1849d32d 100644 --- a/packages/mrm-core/src/npm.js +++ b/packages/mrm-core/src/npm.js @@ -104,6 +104,8 @@ function getRunFunction(options = {}) { return runYarn; } else if (options.pnpm || isUsingPnpm()) { return runPnpm; + } else if (options.bun || isUsingBun()) { + return runBun; } else { return runNpm; } @@ -192,6 +194,24 @@ function runPnpm(deps, options = {}, exec) { }); } +/** + * Install or uninstall given Bun packages + * + * @param {string[]} deps + * @param {RunOptions} [options={}] + * @param {Function} [exec] + */ +function runBun(deps, options = {}, exec) { + const args = [ + options.remove ? 'remove' : 'add', + ].concat(deps); + + return execCommand(exec, 'bun', args, { + stdio: options.stdio === undefined ? 'inherit' : options.stdio, + cwd: options.cwd, + }); +} + /** * Add version or latest to package name * @param {string} dep @@ -308,6 +328,13 @@ function isUsingPnpm() { return fs.existsSync('pnpm-lock.yaml'); } +/** + * Is project using Bun? + */ +function isUsingBun() { + return fs.existsSync('bun.lockb'); +} + module.exports = { install, uninstall,