* Parses the `npm_config_user_agent` environment variable and returns its name and version. * * Code taken from https://github.com/zkochan/packages/tree/main/which-pm-runs/ | which-pm-runs.
()
| 59 | * Code taken from {@link https://github.com/zkochan/packages/tree/main/which-pm-runs/ | which-pm-runs}. |
| 60 | */ |
| 61 | function pmFromUserAgent() { |
| 62 | const userAgent = process.env.npm_config_user_agent; |
| 63 | if (!userAgent) { |
| 64 | return undefined; |
| 65 | } |
| 66 | const pmSpec = userAgent.split(' ', 1)[0]; |
| 67 | const separatorPos = pmSpec.lastIndexOf('/'); |
| 68 | const name = pmSpec.substring(0, separatorPos); |
| 69 | return { |
| 70 | name: name === 'npminstall' ? 'cnpm' : name, |
| 71 | version: pmSpec.substring(separatorPos + 1), |
| 72 | }; |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * Resolves the package manager to use. In order, it checks the following: |
no outgoing calls
no test coverage detected