()
| 1 | export type PackageManager = "npm" | "pnpm" | "yarn" | "bun"; |
| 2 | |
| 3 | export const getUserPkgManager: () => PackageManager = () => { |
| 4 | // This environment variable is set by npm and yarn but pnpm seems less consistent |
| 5 | const userAgent = process.env.npm_config_user_agent; |
| 6 | |
| 7 | if (userAgent) { |
| 8 | if (userAgent.startsWith("yarn")) { |
| 9 | return "yarn"; |
| 10 | } else if (userAgent.startsWith("pnpm")) { |
| 11 | return "pnpm"; |
| 12 | } else if (userAgent.startsWith("bun")) { |
| 13 | return "bun"; |
| 14 | } else { |
| 15 | return "npm"; |
| 16 | } |
| 17 | } else { |
| 18 | // If no user agent is set, assume npm |
| 19 | return "npm"; |
| 20 | } |
| 21 | }; |
no outgoing calls
no test coverage detected