1. nypm
Unified Package Manager for Node.js
nypm
Package: nypm
Created by: unjs
Last modified: Sun, 03 Mar 2024 17:33:23 GMT
Version: 0.3.8
License: MIT
Downloads: 8,106,595
Repository: https://github.com/unjs/nypm

Install

npm install nypm
yarn add nypm

🌈 nypm

npm version
npm downloads
Github Actions
Codecov

Unified Package Manager for Node.js and Bun

What does nypm do?

✅ Supports npm, yarn, pnpm and bun 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.

✅ Auto-installs and use exactly expected version of supported package managers using nodejs/corepack when available.

✅ Minimal implementation.

nypm, detects package manager type and version and converts command into package manager CLI arguments. It then uses corepack or proper command to execute package manager's command and download it if necessary.

  +------------------------------------------------+
  |                nypm                            |
  +------------------------------------------------+
  +-----------------------------------+  +---------+
  |              Corepack             |  |  bun    |
  +-----------------------------------+  +---------+
  +---------+  +---------+  +---------+
  |   npm   |  |  yarn   |  |  pnpm   |
  +---------+  +---------+  +---------+

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 i nypm

# npm
npm install nypm

# yarn
yarn add nypm

# pnpm
pnpm install nypm

# bun
bun 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.

💻 Development

  • Clone this repository
  • Play Nyan Cat in the background (really important!)
  • Enable Corepack using corepack enable (use npm i -g corepack for Node.js < 16.10)
  • Install dependencies using pnpm install
  • Run interactive tests using pnpm dev

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

License

Made with 💛

Published under MIT License.

RELATED POST

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin