I'm Done Typing npm

1 min read

I've typed npm for the last time.
As JavaScript developers, we have four package managers to choose from. In my personal, work, and open source projects, I use all of them. This is a problem because using the wrong command wastes time and causes frustration.
Below is a zsh function I've used to avoid the hassle of switching between package managers—like typing npm start when I meant bun start or npm i when I meant yarn.
function _package_manager() {
if [[ -f bun.lockb ]]; then
command bun "$@"
elif [[ -f pnpm-lock.yaml ]]; then
command pnpm "$@"
elif [[ -f yarn.lock ]]; then
command yarn "$@"
elif [[ -f package-lock.json ]]; then
command npm "$@"
else
command pnpm "$@"
fi
}
alias p='_package_manager'
alias pi='_package_manager install'
alias pa='_package_manager add'
alias pad='_package_manager add -D'
alias prm='_package_manager remove'
alias pb='_package_manager build'
0
Subscribe to my newsletter
Read articles from Lê Văn Sơn directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
