pmex
Version:
Run dynamic NPM or YARN or PNPM
55 lines (54 loc) • 1.61 kB
JavaScript
;
var _a, _b, _c, _d;
Object.defineProperty(exports, "__esModule", { value: true });
function resolver(command) {
var _a, _b;
const [runner, fnName, ...params] = command.split(' ');
// @ts-expect-error
const newFnName = (_b = (_a = aliases[fnName]) === null || _a === void 0 ? void 0 : _a[runner]) !== null && _b !== void 0 ? _b : fnName;
let newCommand = `${newFnName} ${params.join(' ')}`;
if (runner === 'npm' && newFnName === 'run') {
newCommand = newCommand.replace(/-/, '-- -');
}
if (fnName !== 'x' && fnName !== 'dlx') {
newCommand = `${runner} ${newCommand}`;
}
return newCommand.trim();
}
exports.default = resolver;
const isYarnLegacy = (_d = (_c = (_b = (_a = process === null || process === void 0 ? void 0 : process.env) === null || _a === void 0 ? void 0 : _a.npm_config_user_agent) === null || _b === void 0 ? void 0 : _b.match(/^yarn\/(\S+)/)) === null || _c === void 0 ? void 0 : _c[1]) === null || _d === void 0 ? void 0 : _d.startsWith('1.');
const add = {
npm: 'install',
yarn: 'add',
pnpm: 'add',
bun: 'add',
};
const del = {
npm: 'uninstall',
yarn: 'remove',
pnpm: 'remove',
bun: 'remove',
};
const dlx = {
npm: 'npx',
yarn: isYarnLegacy ? 'npx' : 'yarn dlx',
pnpm: 'pnpm dlx',
bun: 'bunx',
};
const cc = {
npm: 'cache clean --force',
yarn: 'cache clean --all',
pnpm: 'store prune',
bun: 'pm cache rm',
};
const aliases = {
add,
remove: del,
uninstall: del,
del,
dlx,
x: dlx,
cc,
'cache-clean': cc,
'cache-clear': cc,
};