I would like to switch to using PNPM over NPM for the usual reasons. Unfortunately cut and paste, or muscle memory takes over sometimes and I will accidentally use NPM to install a package in a project that is using already using PNPM. Things do not go well for that project anymore.
I am hoping to block or alias NPM commands in favor of PNMP.
Things I have tried:
- Only Allow - although promoted on the PNPM site, it does not seem to work, at least not work for individual imports which is the most common use case.
- Since my terminal is Oh My ZSH, I found code to add to ~/.zshrc to block npm if in a directory containing a PNPM lockfile.
NPM_PATH=$(which npm)
npm () {
if [ -e PNPM-lock.yaml ]
then
echo "Please use PNPM with this project"
elif [ -e yarn.lock ]
then
echo "Please use Yarn with this project"
else
$NPM_PATH "$@"
fi
}
This seems to work for my purposes, but does anyone have any cleaner/less zsh specific alternatives?
And in the case where it does happen, what is the recommended steps to recover a PNMP projected tainted by an NPM install?