1.0.2 • Published 2 months ago

identify-package-manager v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

identify-package-manager 📦📦📦📦

Version

Check the used package manager in a given repository (npm, pnpm, yarn classic, yarn berry).

Highlights

  • can be used as classical dependency or as cli/command line tool
  • cli tool can be run in the root of a repository as well as any subfolder (also inside monorepo sub "workspaces" for example) - it will detect the monorepo's root automatically.
  • written in Typescript

CLI

Global install

Via npm:

npm i -g identify-package-manager

Via yarn:

yarn global add identify-package-manager

npx

Instead of a global install you can also use it via npx:

npx identify-package-manager [options]

Usage

After installation you can use it by running the following command inside any given repository.

identify-package-manager [options]

If used without any option the tool will return info about both, the package manager's name and its version, if detectable.

An example output would be the following:

{
    "name": "yarn-berry",
    "version": {
        "simple": "2.0.1",
        "detailed": {
             "major": 2,
             "minor": 0,
             "patch": 1,
        }
    }
}

If you're only interested in the package manager's name, look at the --nameonly option below:

CLI options

optionexplanation
-h / --helpDisplay this package's help + usage info.
-v / --versionDisplay this package's version number.
-n / --nameonlyIf set, the cli tool will only return the used package manager's name (npm, yarn-classic, yarn-berry, pnpm or unknown)

Classical dependency

Install

npm install --save identify-package-manager

Or if you use Yarn:

yarn add identify-package-manager

Usage

import { identifyPackageManager } from "identify-package-manager";

// get name of package manager:
const packageManager = identifyPackageManager(true);
console.log(packageManager);
// ^ might output 'yarn-berry' for instance

// get entire info about package manager:
const packageManagerInfo = identifyPackageManager();
console.log(packageManagerInfo);
// ^ might output the following for instance:
// {
//     "name": "yarn-berry",
//     "version": {
//         "simple": "2.0.1",
//         "detailed": {
//              "major": 2,
//              "minor": 0,
//              "patch": 1,
//         }
//     }
// }