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    // Try availability
19    if (isPackageManagerAvailable('yarn')) {
20        return 'yarn';
21    }
22    else if (isPackageManagerAvailable('pnpm')) {
23        return 'pnpm';
24    }
25    return 'npm';
26}
27exports.resolvePackageManager = resolvePackageManager;
28function isPackageManagerAvailable(manager) {
29    try {
30        (0, child_process_1.execSync)(`${manager} --version`, { stdio: 'ignore' });
31        return true;
32    }
33    catch { }
34    return false;
35}
36function formatRunCommand(manager, cmd) {
37    switch (manager) {
38        case 'pnpm':
39            return `pnpm run ${cmd}`;
40        case 'yarn':
41            return `yarn ${cmd}`;
42        case 'npm':
43        default:
44            return `npm run ${cmd}`;
45    }
46}
47exports.formatRunCommand = formatRunCommand;
48//# sourceMappingURL=resolvePackageManager.js.map