What is which-pm?
The 'which-pm' npm package is designed to detect which package manager was used to install the current project. This can be particularly useful in environments where multiple package managers (like npm, yarn, or pnpm) might be used across different projects. It helps in scripting and automation by allowing the script to adapt based on the package manager used.
What are which-pm's main functionalities?
Detect package manager
This feature allows you to detect which package manager was used for the current project. The function takes the current working directory as an argument and returns a promise that resolves with the name of the package manager.
const whichPM = require('which-pm');
whichPM(process.cwd()).then(pm => {
console.log(`This project uses ${pm.name}`);
});
Other packages similar to which-pm
check-package-manager
Similar to 'which-pm', 'check-package-manager' also checks and validates the package manager used in a project. However, it focuses more on ensuring that the correct package manager is used based on a configuration file, rather than just detecting it.
npm-which
While 'npm-which' is designed to locate the binaries of locally installed npm packages, it serves a different purpose but is similar in the sense that it helps in identifying tools related to npm. It does not detect the package manager but locates npm package binaries.
which-pm
Detects what package manager was used for installation
Can detect npm, pnpm and yarn.
Installation
<pnpm|yarn|npm> add which-pm
Usage
'use strict'
const whichpm = require('which-pm')
whichpm(process.cwd())
.then(pm => console.log(pm))
.catch(err => console.error(err))
Related
- preferred-pm - Returns the preferred package manager of a project
- which-pm-runs - Detects what package manager executes the process
License
MIT © Zoltan Kochan