Merge pull request #518 from creationix/nvm_copy_packages_system
Make `nvm copy-packages system` workmaster
commit
159d4c645e
22
nvm.sh
22
nvm.sh
|
@ -792,11 +792,27 @@ nvm() {
|
||||||
nvm help
|
nvm help
|
||||||
return 127
|
return 127
|
||||||
fi
|
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 INSTALLS
|
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)
|
if [ "$PROVIDED_VERSION" = "system" ]; then
|
||||||
|
if ! nvm_has_system_node; then
|
||||||
|
echo 'No system version of node detected.' >&2
|
||||||
|
return 3
|
||||||
|
fi
|
||||||
|
INSTALLS=$(nvm deactivate > /dev/null && npm list -g --depth=0 | tail -n +2 | \grep -o -e ' [^@]*' | cut -c 2- | \grep -v npm | xargs)
|
||||||
|
else
|
||||||
|
local VERSION
|
||||||
|
VERSION="$(nvm_version "$PROVIDED_VERSION")"
|
||||||
|
INSTALLS=$(nvm use "$VERSION" > /dev/null && npm list -g --depth=0 | tail -n +2 | \grep -o -e ' [^@]*' | cut -c 2- | \grep -v npm | xargs)
|
||||||
|
fi
|
||||||
|
|
||||||
echo "$INSTALLS" | xargs npm install -g --quiet
|
echo "$INSTALLS" | xargs npm install -g --quiet
|
||||||
;;
|
;;
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
die () { echo $@ ; exit 1; }
|
||||||
|
|
||||||
|
. ../../nvm.sh
|
||||||
|
|
||||||
|
local EXPECTED_MSG="Can not copy packages from the current version of node."
|
||||||
|
[ "$(nvm use 0.10.28 && nvm copy-packages 0.10.28 2&>1)" = "$EXPECTED_MSG" ] || die '"nvm use 0.10.28 && nvm copy-packages 0.10.28" did not fail with the right message'
|
||||||
|
|
||||||
|
$(nvm use 0.10.28 && nvm copy-packages 0.10.28)
|
||||||
|
[ $? = 2 ] || die '"nvm use 0.10.28 && nvm copy-packages 0.10.28" did not fail with the right error code'
|
||||||
|
|
Loading…
Reference in New Issue