iTranslated by AI
The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🐕
No more confusion between npm, yarn, and pnpm
To Engineers Facing These Problems
-
package-lock.jsonis committed in a Yarn project - Secretly using Yarn in a pnpm project because memorizing commands is a hassle
- Using
npxeven though you are using Yarn - Performing global installations (
-g) across various package managers
The list goes on and on. Here is an introduction to a handy tool that unifies these operations.
Solution: Use @antfu/ni
npm i -g @antfu/ni
Once you install this, you won't have to worry anymore.
The mechanism is simple: it determines which one to use by looking at the project's lock file (yarn.lock, package-lock.json, pnpm-lock.yaml).
ni react # Install with the appropriate package manager
ni -g firebase-tools # Global install
nr build # Build
nr # List of available scripts (The best!)
nr - # Run the previous script
nx gh-pages -d storybook-static # Execute npx, yarn dlx, or pnpm dlx
Specifying the Default Package Manager
Here is an example of using pnpm when no lock file is found.
Since it's used for global installs, it's a good idea to set it up.
; ~/.nirc
; fallback when no lock found
defaultAgent=pnpm
; for global installs
globalAgent=pnpm
Summary
It is also useful as a command alias, so if you haven't used it yet, please give it a try.
I look forward to hearing your feedback.
Discussion