@skarab/detect-package-manager
    TypeScript icon, indicating that this package has built-in type declarations

    1.0.0 • Public • Published

    @skarab/detect-package-manager

    Detects which package manager (bun, pnpm, yarn, npm) is used based on the current working directory.

    Features

    • Support packageManager field in package.json.
    • Detect PM agent version from lock file name, format or version.
    • Fully typed and well tested!

    TODO

    • Resolve external lock file such as lockfile-directory in .npmrc (PR welcome).

    Installation

    pnpm add @skarab/detect-package-manager

    Usage

    Detect the PM agent from the current working directory.

    import { detectAgent } from '@skarab/detect-package-manager';
    
    const agent = await detectAgent();
    
    console.log(agent); // { name: 'pnpm', version: '7.6.0' }

    Detect the PM agent from a provided directory.

    import { detectAgent } from '@skarab/detect-package-manager';
    
    const agent = await detectAgent('path/to/yarn/project');
    
    console.log(agent); // { name: 'yarn', version: '1.22.17' }

    Detect all installed and known agents.

    import { detectInstalledAgents } from '@skarab/detect-package-manager';
    
    const agents = await api.detectInstalledAgents();
    
    console.log(agents.has('pnpm')); // true
    
    // agents === Map(3) {
    //   'pnpm' => { name: 'pnpm', version: '7.6.0' },
    //   'yarn' => { name: 'yarn', version: '1.22.17' },
    //   'npm' => { name: 'npm', version: '8.13.2' }
    // }

    Known agents

    • bun Bun is a fast all-in-one JavaScript runtime.
    • pnpm Fast, disk space efficient package manager.
    • yarn Yarn is a package manager that doubles down as project manager.
    • npm A JavaScript package manager.

    Related


    Scaffolded with @skarab/skaffold

    Install

    npm i @skarab/detect-package-manager

    DownloadsWeekly Downloads

    3

    Version

    1.0.0

    License

    MIT

    Unpacked Size

    18 kB

    Total Files

    13

    Last publish

    Collaborators

    • skarab