Last active
January 6, 2024 20:19
-
-
Save satinP/a8a201ee59ea90bc1de540de12457c42 to your computer and use it in GitHub Desktop.
Shell function that runs nodejs package manager based on lockfile (npm, yarn, pnpm, bun)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function pm() { | |
if [ -f package-lock.json ]; then | |
echo "Running with $(tput bold)npm" | |
command npm "$@" | |
elif [ -f yarn.lock ]; then | |
echo "Running with $(tput bold)yarn" | |
command yarn "$@" | |
elif [ -f pnpm-lock.yaml ]; then | |
echo "Running with $(tput bold)pnpm" | |
command pnpm "$@" | |
elif [ -f bun.lockb ]; then | |
echo "Running with $(tput bold)bun" | |
command bun "$@" | |
else | |
echo "No lockfile found for npm, yarn, pnpm or bun.\nRunning with $(tput bold)npm as the default package manager." | |
command npm "$@" | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It can also be written with
case
statement: