np-cli

Crates.ionp-cli
lib.rsnp-cli
version0.1.0
created_at2025-10-19 19:56:53.644393+00
updated_at2025-10-19 19:56:53.644393+00
descriptionA blazingly fast, intelligent package manager proxy that automatically detects and forwards commands to npm, yarn, or pnpm
homepage
repositoryhttps://github.com/jordyfontoura/np
max_upload_size
id1890888
size79,725
Jordy Fontoura (jordyfontoura)

documentation

README

np - The Universal Package Manager Proxy ๐Ÿš€

Rust License

Stop memorizing commands. Start building.

np is a blazingly fast, intelligent package manager proxy that automatically detects and forwards commands to the right package manager (npm, yarn, or pnpm) in your project. Write once, run anywhere.

๐Ÿค” The Problem

Ever switched between projects and typed the wrong command?

# In a pnpm project
$ npm install axios
# โŒ Wrong package manager!

# In a yarn project  
$ pnpm add lodash
# โŒ Wrong again!

Managing multiple projects with different package managers is painful. You need to:

  • โœ‹ Remember which package manager each project uses
  • โœ‹ Check for lock files before running commands
  • โœ‹ Context-switch between npm, yarn, and pnpm commands

โœจ The Solution

np does the thinking for you.

# Works everywhere, automatically
$ np install axios
$ np add lodash
$ np run dev
$ np --version

One command to rule them all. np automatically:

  • ๐Ÿ” Detects the package manager from package.json or lock files
  • โšก Forwards all commands and arguments seamlessly
  • ๐Ÿ’พ Optionally saves your choice for future runs
  • ๐Ÿš€ Runs with near-zero overhead (written in Rust)

๐ŸŽฏ Features

  • ๐Ÿง  Smart Detection: Reads packageManager field in package.json or scans lock files
  • โšก Zero Config: Works out of the box, no setup required
  • ๐Ÿ”„ Full Compatibility: All npm/yarn/pnpm commands work exactly as expected
  • ๐Ÿ’ช Blazingly Fast: Built with Rust for maximum performance
  • ๐ŸŽจ Interactive Mode: Prompts you when multiple package managers are detected
  • ๐Ÿ’พ Persistent Choices: Save your selection to package.json automatically
  • ๐Ÿ”ง Battle-Tested: Comprehensive test suite with 34+ tests

๐Ÿ“ฆ Installation

Using Cargo (Recommended)

cargo install np

From Source

git clone https://github.com/jordyfontoura/np.git
cd np
cargo build --release
sudo mv target/release/np /usr/local/bin/

Pre-built Binaries

Download the latest binary from Releases

๐Ÿš€ Quick Start

Once installed, just replace your package manager command with np:

# Instead of:
npm install
yarn install  
pnpm install

# Just use:
np install

That's it! np will figure out the rest.

๐Ÿ’ก Usage

Basic Commands

All your favorite commands work exactly the same:

# Installing dependencies
np install
np add axios
np add -D typescript

# Running scripts
np run dev
np run build
np test

# Getting info
np --version
np list

First-Time Setup in a Project

When np can't determine the package manager, it will ask you:

$ np install

๐Ÿค” Could not determine the package manager.
? Which package manager would you like to use? 
  > npm
    yarn
    pnpm
    
? Would you like to save this choice in the 'packageManager' field in package.json? (Y/n)

Select your preferred package manager, and optionally save it to avoid future prompts.

Package Manager Detection Priority

np follows this detection order:

  1. packageManager field in package.json (highest priority)

    {
      "packageManager": "pnpm@9.9.0"
    }
    
  2. Lock files in the project directory:

    • package-lock.json โ†’ npm
    • yarn.lock โ†’ yarn
    • pnpm-lock.yaml โ†’ pnpm
  3. Interactive prompt (when multiple or none are detected)

๐ŸŽฏ Real-World Examples

Monorepo with Mixed Package Managers

cd frontend/          # Uses yarn
np install           # โœ… Runs: yarn install

cd ../backend/       # Uses pnpm
np install          # โœ… Runs: pnpm install

cd ../legacy/        # Uses npm
np install          # โœ… Runs: npm install

Contributing to Open Source

# Clone any project
git clone https://github.com/some/project.git
cd project

# Just use np - it adapts automatically
np install
np run test
np run build

CI/CD Integration

# .github/workflows/ci.yml
- name: Install dependencies
  run: np install
  
- name: Run tests  
  run: np test
  
- name: Build
  run: np run build

๐Ÿ—๏ธ How It Works

  1. Detection Phase:

    • Scans package.json for packageManager field
    • Falls back to detecting lock files (package-lock.json, yarn.lock, pnpm-lock.yaml)
    • Prompts user if detection is ambiguous
  2. Execution Phase:

    • Spawns the detected package manager with all original arguments
    • Inherits stdin/stdout/stderr for seamless integration
    • Preserves exit codes and signals
  3. Persistence (Optional):

    • Saves user choice to package.json โ†’ packageManager field
    • Ensures consistent behavior across team members

๐Ÿงช Testing

np comes with a comprehensive test suite:

# Run all tests
cargo test

# Run specific test suites
cargo test --test package_detector_tests
cargo test --test script_handler_tests
cargo test --test command_executor_tests

Test Coverage:

  • โœ… 10 package detection tests
  • โœ… 15 package.json read/write tests
  • โœ… 9 command execution tests

๐Ÿค Contributing

Contributions are welcome! Here's how to get started:

  1. Fork the repository
  2. Create your feature branch: git checkout -b feature/amazing-feature
  3. Make your changes and add tests
  4. Run the test suite: cargo test
  5. Commit your changes: git commit -m 'Add amazing feature'
  6. Push to the branch: git push origin feature/amazing-feature
  7. Open a Pull Request

๐Ÿ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ™ Acknowledgments

  • Built with the amazing Rust ecosystem
  • Thanks to all contributors and users!

โญ Show Your Support

If np saves you time and mental overhead, please consider:

  • โญ Starring the repository
  • ๐Ÿ› Reporting bugs and suggesting features
  • ๐Ÿ“ข Sharing with your team and friends

Made with โค๏ธ and Rust

Report Bug ยท Request Feature


Discord LinkedIn
Commit count: 0

cargo fmt