Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

nypm

unjs8.2mMIT0.5.1TypeScript support: included

Unified Package Manager for Node.js

readme

🌈 nypm

npm version npm downloads codecov

🌈 Unified Package Manager for Node.js (npm, pnpm, yarn), Bun and Deno.

✅ Supports npm, yarn, pnpm and bun and deno out of the box with a unified API.

✅ Provides an API interface to interact with package managers.

Autodetects project's package manager using package.json and known lockfiles.

corepack integration for pnpm and yarn.

nypm command

Install dependencies:

npx nypm i

Add a dependency:

npx nypm add defu

Remove a dependency:

npx nypm remove defu

API Usage

Install package:

# ✨ Auto-detect
npx nypm install nypm

# npm
npm install nypm

# yarn
yarn add nypm

# pnpm
pnpm install nypm

# bun
bun install nypm

# deno
deno install nypm

Import:

// ESM
import { addDependency } from "nypm";

// CommonJS
const { addDependency } = require("nypm");

addDependency(name, options)

Adds dependency to the project.

addDevDependency(name, options)

Adds dev dependency to the project.

detectPackageManager(cwd, options)

Detect the package manager used in a directory (and up) by checking various sources:

  1. Use packageManager field from package.json
  2. Known lock files and other files

ensureDependencyInstalled(name, options)

Ensures dependency is installed.

installDependencies(options)

Installs project dependencies.

removeDependency(name, options)

Removes dependency from the project.

dedupeDependencies(options)

Dedupe project dependencies.

[!NOTE] For bun and deno it will remove the lockfile and reinstall all dependencies.

💻 Development

  • Clone this repository
  • Play Nyan Cat in the background (really important!)
  • Enable Corepack using corepack enable
  • Install dependencies using pnpm install
  • Run interactive tests using pnpm dev

NYPM is inspired from previous attempts and projects for unifying package manager experience.

License

Made with 💛

Published under MIT License.

changelog

Changelog

v0.5.1

compare changes

🚀 Enhancements

  • Normalize packageManager field when parsing (#184)

🏡 Chore

❤️ Contributors

v0.5.0

compare changes

🚀 Enhancements

  • Add dedupeDependencies utility (#175)

🔥 Performance

  • Avoid lazy import (#182)

🩹 Fixes

  • Correctly detect corepack for fallback (#179)

🏡 Chore

✅ Tests

❤️ Contributors

v0.4.1

compare changes

🩹 Fixes

  • addDependency: Compare name from resolved package.json (#165)

❤️ Contributors

v0.4.0

compare changes

🚀 Enhancements

  • Experimental support for deno v2 (#158)

🔥 Performance

  • ⚠️ Replace execa with tinyexec (#151)

🏡 Chore

⚠️ Breaking Changes

  • ⚠️ Replace execa with tinyexec (#151)

❤️ Contributors

v0.3.12

compare changes

🚀 Enhancements

  • Detect bun.lock (#153)

🏡 Chore

❤️ Contributors

  • Pooya Parsa (@pi0)

v0.3.11

compare changes

🩹 Fixes

  • Correct yarn detection (#140)

❤️ Contributors

v0.3.10

compare changes

🩹 Fixes

  • Do not call addDependency with empty array (#147)

🏡 Chore

  • Update link to nyan cat video (#137)
  • Apply automated lint fixes (909ac19)
  • Update deps (80b25a6)
  • Update vitest config (8925eec)

❤️ Contributors

v0.3.9

compare changes

🚀 Enhancements

  • Allow installing peerDeps when using addDependency (#135)
  • cli: Support pnpm (rm, uninstall, un) aliases for removing packages (#126)
  • Add option to install dependencies with a frozen lockfile (#121)

🩹 Fixes

  • Use correct flag when getting pnpm workspace args (#130)

🏡 Chore

❤️ Contributors

v0.3.8

compare changes

🚀 Enhancements

🩹 Fixes

  • Findup until root from user cwd (0309498)

🏡 Chore

❤️ Contributors

  • Pooya Parsa (@pi0)

v0.3.7

compare changes

🚀 Enhancements

  • Add global mode support (#113)
  • Detect based on dlx command as fallback (#117)

🩹 Fixes

  • yarn: Handle global for yarn 1.x only (f5e4a39)

📖 Documentation

  • Add jsdocs for detectPackageManager (a7dfce7)

🏡 Chore

❤️ Contributors

v0.3.6

compare changes

🚀 Enhancements

  • Allow installing multiple dependencies (#107)

📦 Build

  • cli: Only import required fields from package.json to the bundle (591dd4d)

🏡 Chore

🤖 CI

  • Increase timeout for windows (da4a986)

❤️ Contributors

  • Pooya Parsa (@pi0)

v0.3.4

compare changes

🚀 Enhancements

  • Allow specify packageManager by name (5376aeb)

🩹 Fixes

  • detectPackageManager: Check parent dirs by default (4cf3346)

🏡 Chore

❤️ Contributors

  • Pooya Parsa (@pi0)

v0.3.3

compare changes

🚀 Enhancements

  • Basic nypm cli (#95)

🩹 Fixes

  • Fallback to local package manager when corepack not installed (#94)

🏡 Chore

❤️ Contributors

  • Pooya Parsa (@pi0)

v0.3.2

compare changes

🩹 Fixes

  • Remove extra console.log (251c374)
  • Buffer stdio in silent mode (b81da19)
  • Pass appropriate workspace args and improve tests (#90)

🏡 Chore

  • Set git-checks: false to allow publish (af83d2d)
  • Update dependencies (84357e0)

✅ Tests

  • bun: Add packageManager field to allow tests passing (a731666)

❤️ Contributors

  • Pooya Parsa (@pi0)

v0.3.1

compare changes

🚀 Enhancements

  • Add support for bun (#87)

🏡 Chore

❤️ Contributors

v0.3.0

compare changes

💅 Refactors

  • ⚠️ Improve library (#75)

📖 Documentation

  • Fix typo (#77)

🏡 Chore

  • Update badge (#81)
  • Add autofix ci (b326b98)
  • Update ci node veriosion (b048b6c)
  • Always ignore .npm.loader.mjs (7bebeaf)
  • Add test:types script (a8a0c94)
  • Update .pnp.loader.mjs snapshot (10e10b0)
  • Update fixtures with autofix ci as well (c16de18)
  • Ignore .pnp.cjs as well (c4c79bd)

🎨 Styles

🤖 CI

  • Run lint step only once (333c077)

⚠️ Breaking Changes

  • ⚠️ Improve library (#75)

❤️ Contributors

v0.2.2

compare changes

🚀 Enhancements

  • Allow installing project dependencies (#72)

🏡 Chore

❤️ Contributors

  • Damian Głowala
  • Pooya Parsa (@pi0)

v0.2.1

compare changes

🩹 Fixes

  • pkg: Allow installing in node 20 (#67)
  • pkg: Simplify upper node version constraint (#70)

🏡 Chore

❤️ Contributors

v0.2.0

compare changes

🚀 Enhancements

  • ⚠️ Refactor detection to support multi versions (#42)
  • Use execa for cross platform search path support (#54)
  • removeDependency and addDevDependency (#55)
  • Add workspace flag (#57)

🏡 Chore

  • Add egoist/dum to readme (#21)
  • Update dev dependencies (6db58c4)
  • Update lockfile (ccbe0a5)
  • Include yarn berry build in test fixtures (cabbe7b)
  • Update release script (f45608f)

✅ Tests

  • Add fixture for yarn berry version detect (019a2ac)
  • Disable silent to debug (81975cd)

⚠️ Breaking Changes

  • ⚠️ Refactor detection to support multi versions (#42)

❤️ Contributors