1"use strict"; 2Object.defineProperty(exports, "__esModule", { value: true }); 3exports.formatRunCommand = exports.resolvePackageManager = void 0; 4const child_process_1 = require("child_process"); 5/** Determine which package manager to use for installing dependencies based on how the process was started. */ 6function resolvePackageManager() { 7 // Attempt to detect if the user started the command using `yarn` or `pnpm` 8 const userAgent = process.env.npm_config_user_agent; 9 if (userAgent?.startsWith('yarn')) { 10 return 'yarn'; 11 } 12 else if (userAgent?.startsWith('pnpm')) { 13 return 'pnpm'; 14 } 15 else if (userAgent?.startsWith('npm')) { 16 return 'npm'; 17 } 18 else if (userAgent?.startsWith('bun')) { 19 return 'bun'; 20 } 21 // Try availability 22 if (isPackageManagerAvailable('yarn')) { 23 return 'yarn'; 24 } 25 else if (isPackageManagerAvailable('pnpm')) { 26 return 'pnpm'; 27 } 28 else if (isPackageManagerAvailable('bun')) { 29 return 'bun'; 30 } 31 return 'npm'; 32} 33exports.resolvePackageManager = resolvePackageManager; 34function isPackageManagerAvailable(manager) { 35 try { 36 (0, child_process_1.execSync)(`${manager} --version`, { stdio: 'ignore' }); 37 return true; 38 } 39 catch { } 40 return false; 41} 42function formatRunCommand(manager, cmd) { 43 switch (manager) { 44 case 'pnpm': 45 return `pnpm run ${cmd}`; 46 case 'yarn': 47 return `yarn ${cmd}`; 48 case 'bun': 49 return `bun run ${cmd}`; 50 case 'npm': 51 default: 52 return `npm run ${cmd}`; 53 } 54} 55exports.formatRunCommand = formatRunCommand; 56//# sourceMappingURL=resolvePackageManager.js.map