Yushaku blog
  • Articles
  • Contact
  • About me

I'm Done Typing npm

dev

I've typed npm for the last time.

As JavaScript developers, we have four package managers to choose from. And between personal, work, and open source projects, I use every last one of them. This is a problem because typing the wrong command costs time and irritation.

Below is a zsh function that I've used to eliminate package manager context switching heartache — typing npm start when we meant bun start or npm I when we mean shudders 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'