Skip to content

Instantly share code, notes, and snippets.

@zakmandhro
Last active September 26, 2024 23:42
Show Gist options
  • Save zakmandhro/828e857ae6180a00beb4750984bb8871 to your computer and use it in GitHub Desktop.
Save zakmandhro/828e857ae6180a00beb4750984bb8871 to your computer and use it in GitHub Desktop.
Run appropriate package manager (`yarn`, `npm`, or `pnpm`) with single `nn` command
# run the appropriate package manager
npm-etc() {
if [[ -f package-lock.json ]]; then
npm run "$@"
elif [[ -f yarn.lock ]]; then
yarn "$@"
elif [[ -f pnpm-lock.yaml ]]; then
pnpm "$@"
else
echo "Error: Could not detect package manager."
fi
}
alias nn="npm-etc"
@zakmandhro
Copy link
Author

zakmandhro commented Sep 26, 2024

Instead of having to think about which package manager you use per project, append the above gist into your ~/.zshrc and simply use nn command everywhere.

# Example yarn project
> nn install lodash

# Example pnpm project
> nn install lodash

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment