npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

packmorph

v1.4.1

Published

Translate package manager install commands between npm, pnpm, Yarn, and Bun

Readme

packmorph

Translate package manager commands between npm, pnpm, Yarn, and Bun.

npm version License: MIT

import { packmorph } from "packmorph";

// Install commands (default)
const result = packmorph("npm install -D typescript");
if (result.ok) {
  console.log(result.npm); // npm install -D typescript
  console.log(result.pnpm); // pnpm add -D typescript
  console.log(result.yarn); // yarn add --dev typescript
  console.log(result.bun); // bun add --dev typescript
}

Install

npm install packmorph

What it does

Converts package manager commands between npm, pnpm, Yarn, and Bun. Supports install, exec, run, and create commands.

Command Types

Install (default)

packmorph("npm install react");
packmorph("pnpm add -D vitest");
packmorph("yarn global add eslint");
packmorph("bun add --exact lodash");

Exec (opt-in)

packmorph("npx prettier .", { parseExec: true });
// → npm: npx prettier .
// → pnpm: pnpm dlx prettier .
// → yarn: yarn dlx prettier .
// → bun: bunx prettier .

Run (opt-in)

packmorph("npm run dev", { parseRun: true });
// → npm: npm run dev
// → pnpm: pnpm run dev
// → yarn: yarn run dev
// → bun: bun run dev

Create (opt-in)

packmorph("npm create vite@latest my-app", { parseCreate: true });
// → npm: npm create vite@latest -- my-app
// → pnpm: pnpm create vite@latest my-app
// → yarn: yarn create vite@latest my-app
// → bun: bun create vite@latest my-app

Note: npm create requires -- before additional args. Packmorph handles this automatically.

Multi-line (opt-in)

const result = packmorph(
  `# Install dependencies
npm install react
npm install -D typescript
cd my-project
npx prettier --write .`,
  { parseMultiLine: true, parseExec: true },
);

if (result.ok) {
  console.log(result.npm);
  // # Install dependencies
  // npm install react
  // npm install -D typescript
  // cd my-project
  // npx prettier --write .

  console.log(result.pnpm);
  // # Install dependencies
  // pnpm add react
  // pnpm add -D typescript
  // cd my-project
  // pnpm dlx prettier --write .
}

Note: Multi-line mode automatically preserves comments (#), empty lines, and non-package-manager commands (like cd, mkdir, echo). Only package manager commands are transformed - everything else passes through unchanged.

Important: Multi-line parsing requires all package manager commands to use the same package manager. Mixing different package managers will return an error:

const result = packmorph(
  `npm install react
pnpm add typescript`,
  { parseMultiLine: true },
);
// → { ok: false, reason: "mixed-package-managers" }

This ensures consistent command conversion across all package managers.

Options

interface PackmorphOptions {
  parseInstall?: boolean; // default: true
  parseExec?: boolean; // default: false
  parseRun?: boolean; // default: false
  parseCreate?: boolean; // default: false
  parseMultiLine?: boolean; // default: false
}

Enable multiple command types:

const result = packmorph(command, {
  parseInstall: true,
  parseExec: true,
  parseRun: true,
  parseCreate: true,
  parseMultiLine: true,
});

Supported Commands

Install

  • npm install / npm i
  • pnpm add / pnpm install
  • yarn add / yarn install / yarn global add
  • bun add / bun install

Exec

  • npx <package>
  • pnpm dlx <package>
  • yarn dlx <package>
  • bunx <package>

Run

  • npm run <script>
  • pnpm run <script>
  • yarn run <script>
  • bun run <script>

Create

  • npm create <template>
  • pnpm create <template>
  • yarn create <template>
  • bun create <template>

Flags

Install commands support: -D (dev), -g (global), -E (exact), -O (optional), -P (peer), --frozen-lockfile.

Flags are automatically normalized:

  • yarn add --devnpm install -D
  • bun add -dnpm install -D
  • yarn add --exactnpm install -E

API

packmorph(command: string, options?: PackmorphOptions): PackmorphResult

Success:

{
  ok: true,
  type: "install" | "exec" | "run" | "create",
  npm: string,
  pnpm: string,
  yarn: string,
  bun: string,
  meta: { /* command-specific metadata */ }
}

Error:

{
  ok: false,
  reason: "not-install-command" | "parse-error" | "not-supported-command" | "disabled-command-type" | "mixed-package-managers"
}

Multi-line Success:

When parseMultiLine: true, the result has the same structure as single-line mode:

{
  ok: true,
  type: "install" | "exec" | "run" | "create",
  npm: string,
  pnpm: string,
  yarn: string,
  bun: string,
  meta: { /* command-specific metadata */ }
}

The npm, pnpm, yarn, and bun properties contain the full transformed multi-line text with non-package-manager lines preserved.

License

MIT