(env: NodeJS.ProcessEnv = process.env)
| 106 | } |
| 107 | |
| 108 | export function detectInstallMethod(env: NodeJS.ProcessEnv = process.env): InstallMethod { |
| 109 | const execPath = env.npm_execpath?.toLowerCase() ?? ""; |
| 110 | const npmCommand = env.npm_command?.toLowerCase() ?? ""; |
| 111 | const userAgent = env.npm_config_user_agent?.toLowerCase() ?? ""; |
| 112 | |
| 113 | if (execPath.includes("pnpm") && npmCommand === "dlx") return "pnpm-dlx"; |
| 114 | if (execPath.includes("pnpm")) return "pnpm-global"; |
| 115 | if (execPath.includes("bun") && npmCommand === "x") return "bunx"; |
| 116 | if (execPath.includes("bun")) return "bun-global"; |
| 117 | if (execPath.includes("npm") && npmCommand === "exec") return "npx"; |
| 118 | if (execPath.includes("npm")) return "npm-global"; |
| 119 | |
| 120 | if (userAgent.startsWith("pnpm/")) return "pnpm-global"; |
| 121 | if (userAgent.startsWith("bun/")) return "bun-global"; |
| 122 | if (userAgent.startsWith("npm/")) return "npm-global"; |
| 123 | |
| 124 | return "unknown"; |
| 125 | } |
| 126 | |
| 127 | export function getUpgradePlan( |
| 128 | installMethod = detectInstallMethod(), |
no outgoing calls
no test coverage detected