Make nvm copy-packages refuse to copy packages from the currently activated version.

This commit is contained in:
Jordan Harband
2014-09-05 00:42:59 -07:00
parent 110e571c34
commit ff1781b95d
2 changed files with 22 additions and 2 deletions

12
nvm.sh
View File

@@ -792,9 +792,17 @@ nvm() {
nvm help
return 127
fi
VERSION="$(nvm_version "$2")"
# declare local INSTALLS first, otherwise it doesn't work in zsh
local PROVIDED_VERSION
PROVIDED_VERSION="$2"
if [ "$PROVIDED_VERSION" = "$(nvm_ls_current)" ]; then
echo 'Can not copy packages from the current version of node.' >&2
return 2
fi
local VERSION
VERSION="$(nvm_version "$PROVIDED_VERSION")"
local INSTALLS
INSTALLS=$(nvm use "$VERSION" > /dev/null && npm list -g --depth=0 | tail -n +2 | \grep -o -e ' [^@]*' | cut -c 2- | \grep -v npm | xargs)