Created
June 18, 2017 15:24
-
-
Save toboid/f78eb25c8c071086bd1ac3bab4bc3a0b to your computer and use it in GitHub Desktop.
Use nvm to find which node versions a global module is installed for
This file contains hidden or 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
nvm_global () { | |
PKG_NAME=$1 | |
VERSIONS=() | |
I=0 | |
for VER in $(nvm_ls) | |
do | |
nvm exec --silent ${VER} npm ls -g ${PKG_NAME} --depth=0 >/dev/null 2>&1 | |
if [ $? -eq 0 ]; then | |
VERSIONS[I]=${VER} | |
fi | |
let I=${I}+1 | |
done | |
if [ ${#VERSIONS[@]} -eq 0 ]; then | |
echo "${PKG_NAME} not found for any node version installed through nvm" | |
else | |
echo "Found ${PKG_NAME} for node versions:" | |
for VERSION in "${VERSIONS[@]}" | |
do | |
echo -e "\t${VERSION}" | |
done | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment