diff --git a/README.markdown b/README.markdown index bdf9007fd2..29372e96bd 100644 --- a/README.markdown +++ b/README.markdown @@ -146,8 +146,9 @@ Put the above sourcing line just below the sourcing line for NVM in your profile nvm $ nvm [tab][tab] - alias copy-packages help list run uninstall version - clear-cache deactivate install ls unalias use + alias deactivate install ls run unload + clear-cache exec list ls-remote unalias use + current help list-remote reinstall-packages uninstall version nvm alias diff --git a/bash_completion b/bash_completion index 4287e206da..27d882e6d0 100644 --- a/bash_completion +++ b/bash_completion @@ -18,10 +18,10 @@ __nvm_commands () current_word="${COMP_WORDS[COMP_CWORD]}" COMMANDS='\ - help install uninstall use run exec\ - alias unalias copy-packages - current list ls list-remote ls-remote\ - clear-cache deactivate unload + help install uninstall use run exec \ + alias unalias reinstall-packages \ + current list ls list-remote ls-remote \ + clear-cache deactivate unload \ version' if [ ${#COMP_WORDS[@]} == 4 ]; then diff --git a/nvm.sh b/nvm.sh index 54ec1175d8..40a4aa9086 100644 --- a/nvm.sh +++ b/nvm.sh @@ -545,7 +545,7 @@ nvm() { echo " nvm alias [] Show all aliases beginning with " echo " nvm alias Set an alias named pointing to " echo " nvm unalias Deletes the alias named " - echo " nvm copy-packages Install global \`npm\` packages contained in to current version" + echo " nvm reinstall-packages Reinstall global \`npm\` packages contained in to current version" echo " nvm unload Unload \`nvm\` from shell" echo echo "Example:" @@ -611,32 +611,35 @@ nvm() { VERSION="$(nvm_remote_version "$provided_version")" ADDITIONAL_PARAMETERS='' - local PROVIDED_COPY_PACKAGES_FROM - local COPY_PACKAGES_FROM + local PROVIDED_REINSTALL_PACKAGES_FROM + local REINSTALL_PACKAGES_FROM while [ $# -ne 0 ] do - if [ "_$(echo "$1" | cut -c 1-21)" = "_--copy-packages-from=" ]; then - PROVIDED_COPY_PACKAGES_FROM="$(echo "$1" | cut -c 22-)" - COPY_PACKAGES_FROM="$(nvm_version "$PROVIDED_COPY_PACKAGES_FROM")" + if [ "_$(echo "$1" | cut -c 1-26)" = "_--reinstall-packages-from=" ]; then + PROVIDED_REINSTALL_PACKAGES_FROM="$(echo "$1" | cut -c 27-)" + REINSTALL_PACKAGES_FROM="$(nvm_version "$PROVIDED_REINSTALL_PACKAGES_FROM")" + elif [ "_$(echo "$1" | cut -c 1-21)" = "_--copy-packages-from=" ]; then + PROVIDED_REINSTALL_PACKAGES_FROM="$(echo "$1" | cut -c 22-)" + REINSTALL_PACKAGES_FROM="$(nvm_version "$PROVIDED_REINSTALL_PACKAGES_FROM")" else ADDITIONAL_PARAMETERS="$ADDITIONAL_PARAMETERS $1" fi shift done - if [ "_$(nvm_ensure_version_prefix "$PROVIDED_COPY_PACKAGES_FROM")" = "_$VERSION" ]; then - echo "You can't copy global packages from the same version of node you're installing." >&2 + if [ "_$(nvm_ensure_version_prefix "$PROVIDED_REINSTALL_PACKAGES_FROM")" = "_$VERSION" ]; then + echo "You can't reinstall global packages from the same version of node you're installing." >&2 return 4 - elif [ ! -z "$PROVIDED_COPY_PACKAGES_FROM" ] && [ "_$COPY_PACKAGES_FROM" = "_N/A" ]; then - echo "If --copy-packages-from is provided, it must point to an installed version of node." >&2 + elif [ ! -z "$PROVIDED_REINSTALL_PACKAGES_FROM" ] && [ "_$REINSTALL_PACKAGES_FROM" = "_N/A" ]; then + echo "If --reinstall-packages-from is provided, it must point to an installed version of node." >&2 return 5 fi if [ -d "$(nvm_version_path "$VERSION")" ]; then echo "$VERSION is already installed." >&2 - if nvm use "$VERSION" && [ ! -z "$COPY_PACKAGES_FROM" ] && [ "_$COPY_PACKAGES_FROM" != "_N/A" ]; then - nvm copy-packages "$COPY_PACKAGES_FROM" + if nvm use "$VERSION" && [ ! -z "$REINSTALL_PACKAGES_FROM" ] && [ "_$REINSTALL_PACKAGES_FROM" != "_N/A" ]; then + nvm reinstall-packages "$REINSTALL_PACKAGES_FROM" fi return $? fi @@ -667,8 +670,8 @@ nvm() { mv "$tmpdir" "$(nvm_version_path "$VERSION")" ) then - if nvm use "$VERSION" && [ ! -z "$COPY_PACKAGES_FROM" ] && [ "_$COPY_PACKAGES_FROM" != "_N/A" ]; then - nvm copy-packages "$COPY_PACKAGES_FROM" + if nvm use "$VERSION" && [ ! -z "$REINSTALL_PACKAGES_FROM" ] && [ "_$REINSTALL_PACKAGES_FROM" != "_N/A" ]; then + nvm reinstall-packages "$REINSTALL_PACKAGES_FROM" fi return $? else @@ -713,8 +716,8 @@ nvm() { $make $MAKE_CXX install ) then - if nvm use "$VERSION" && [ ! -z "$COPY_PACKAGES_FROM" ] && [ "_$COPY_PACKAGES_FROM" != "_N/A" ]; then - nvm copy-packages "$COPY_PACKAGES_FROM" + if nvm use "$VERSION" && [ ! -z "$REINSTALL_PACKAGES_FROM" ] && [ "_$REINSTALL_PACKAGES_FROM" != "_N/A" ]; then + nvm reinstall-packages "$REINSTALL_PACKAGES_FROM" fi if ! nvm_has "npm" ; then echo "Installing npm..." @@ -1003,7 +1006,7 @@ nvm() { rm -f $NVM_DIR/alias/$2 echo "Deleted alias $2" ;; - "copy-packages" ) + "reinstall-packages" | "copy-packages" ) if [ $# -ne 2 ]; then nvm help return 127 @@ -1013,7 +1016,7 @@ nvm() { PROVIDED_VERSION="$2" if [ "$PROVIDED_VERSION" = "$(nvm_ls_current)" ] || [ "$(nvm_version $PROVIDED_VERSION)" = "$(nvm_ls_current)" ]; then - echo 'Can not copy packages from the current version of node.' >&2 + echo 'Can not reinstall packages from the current version of node.' >&2 return 2 fi diff --git "a/test/fast/Running \"nvm install\" with \"--copy-packages-from\" requires a valid version" "b/test/fast/Running \"nvm install\" with \"--copy-packages-from\" requires a valid version" deleted file mode 100755 index bbd7cbb4c9..0000000000 --- "a/test/fast/Running \"nvm install\" with \"--copy-packages-from\" requires a valid version" +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/sh - -die () { echo $@ ; cleanup ; exit 1; } -cleanup () { - rm -rf ../../v0.10.4 -} - -mkdir ../../v0.10.4 - -. ../../nvm.sh - -nvm deactivate >/dev/null 2>&1 - -INSTALL_ERROR_MSG="$(nvm install v0.10.5 --copy-packages-from=0.11 2>&1)" -EXPECTED_ERROR_MSG="If --copy-packages-from is provided, it must point to an installed version of node." -[ "~$INSTALL_ERROR_MSG" = "~$EXPECTED_ERROR_MSG" ] \ - || die ""nvm install --copy-packages" should fail when given an uninstalled version: expected '$EXPECTED_ERROR_MSG', got '$INSTALL_ERROR_MSG'" - -INSTALL_EXIT_CODE="$(nvm install v0.10.5 --copy-packages-from=0.11 >/dev/null 2>&1; echo $?)" -[ "~$INSTALL_EXIT_CODE" = "~5" ] \ - || die ""nvm install --copy-packages" should exit with code 5 when given an uninstalled version, got $INSTALL_EXIT_CODE" - -INSTALL_ERROR_MSG="$(nvm install v0.10.5 --copy-packages-from=0.10.5 2>&1)" -EXPECTED_ERROR_MSG="You can't copy global packages from the same version of node you're installing." -[ "~$INSTALL_ERROR_MSG" = "~$EXPECTED_ERROR_MSG" ] \ - || die ""nvm install --copy-packages" should fail when given the same version: expected '$EXPECTED_ERROR_MSG', got '$INSTALL_ERROR_MSG'" - -INSTALL_EXIT_CODE="$(nvm install v0.10.5 --copy-packages-from=0.10.5 >/dev/null 2>&1; echo $?)" -[ "~$INSTALL_EXIT_CODE" = "~4" ] \ - || die ""nvm install --copy-packages" should exit with code 4 when given the same version, got $INSTALL_EXIT_CODE" - diff --git "a/test/fast/Running \"nvm install\" with \"--reinstall-packages-from\" requires a valid version" "b/test/fast/Running \"nvm install\" with \"--reinstall-packages-from\" requires a valid version" new file mode 100755 index 0000000000..00b6bc60fd --- /dev/null +++ "b/test/fast/Running \"nvm install\" with \"--reinstall-packages-from\" requires a valid version" @@ -0,0 +1,31 @@ +#!/bin/sh + +die () { echo $@ ; cleanup ; exit 1; } +cleanup () { + rm -rf ../../v0.10.4 +} + +mkdir ../../v0.10.4 + +. ../../nvm.sh + +nvm deactivate >/dev/null 2>&1 + +INSTALL_ERROR_MSG="$(nvm install v0.10.5 --reinstall-packages-from=0.11 2>&1)" +EXPECTED_ERROR_MSG="If --reinstall-packages-from is provided, it must point to an installed version of node." +[ "~$INSTALL_ERROR_MSG" = "~$EXPECTED_ERROR_MSG" ] \ + || die ""nvm install --reinstall-packages-from" should fail when given an uninstalled version: expected '$EXPECTED_ERROR_MSG', got '$INSTALL_ERROR_MSG'" + +INSTALL_EXIT_CODE="$(nvm install v0.10.5 --reinstall-packages-from=0.11 >/dev/null 2>&1; echo $?)" +[ "~$INSTALL_EXIT_CODE" = "~5" ] \ + || die ""nvm install --reinstall-packages-from" should exit with code 5 when given an uninstalled version, got $INSTALL_EXIT_CODE" + +INSTALL_ERROR_MSG="$(nvm install v0.10.5 --reinstall-packages-from=0.10.5 2>&1)" +EXPECTED_ERROR_MSG="You can't reinstall global packages from the same version of node you're installing." +[ "~$INSTALL_ERROR_MSG" = "~$EXPECTED_ERROR_MSG" ] \ + || die ""nvm install --reinstall-packages-from" should fail when given the same version: expected '$EXPECTED_ERROR_MSG', got '$INSTALL_ERROR_MSG'" + +INSTALL_EXIT_CODE="$(nvm install v0.10.5 --reinstall-packages-from=0.10.5 >/dev/null 2>&1; echo $?)" +[ "~$INSTALL_EXIT_CODE" = "~4" ] \ + || die ""nvm install --reinstall-packages-from" should exit with code 4 when given the same version, got $INSTALL_EXIT_CODE" + diff --git a/test/installation/install while copying packages b/test/installation/install while reinstalling packages similarity index 88% rename from test/installation/install while copying packages rename to test/installation/install while reinstalling packages index 45cafb5dfd..76eb7e570d 100755 --- a/test/installation/install while copying packages +++ b/test/installation/install while reinstalling packages @@ -23,7 +23,7 @@ npm list --global | grep is-nan > /dev/null || die "is-nan isn't installed" nvm ls 0.9 | grep v0.9.7 > /dev/null || die "nvm ls 0.9 didn't show v0.9.7" -nvm install 0.9.12 --copy-packages-from=0.9 || die "nvm install 0.9.12 --copy-packages-from=0.9 failed" +nvm install 0.9.12 --reinstall-packages-from=0.9 || die "nvm install 0.9.12 --reinstall-packages-from=0.9 failed" [ -d ../../v0.9.12 ] || die "nvm install 0.9.12 didn't install" diff --git "a/test/slow/nvm copy-packages/Running \"nvm copy-packages $(nvm ls current)\" should error out" "b/test/slow/nvm copy-packages/Running \"nvm copy-packages $(nvm ls current)\" should error out" deleted file mode 100755 index e296e7ccd7..0000000000 --- "a/test/slow/nvm copy-packages/Running \"nvm copy-packages $(nvm ls current)\" should error out" +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/sh - -die () { echo $@ ; exit 1; } - -. ../../../nvm.sh - -nvm use 0.10.28 > /dev/null - -EXPECTED_MSG="Can not copy packages from the current version of node." -ACTUAL_MSG="$(nvm copy-packages 0.10.28 2>&1 > /dev/null)" -[ "~$ACTUAL_MSG" = "~$EXPECTED_MSG" ] || die "'nvm use 0.10.28 && nvm copy-packages 0.10.28' did not fail with the right message: '$ACTUAL_MESSAGE'" - -EXPECTED_ERROR_CODE="2" -ACTUAL_ERROR_CODE="$(nvm copy-packages 0.10.28 > /dev/null 2>&1 ; echo $?)" -[ "~$ACTUAL_ERROR_CODE" = "~$EXPECTED_ERROR_CODE" ] || die "'nvm use 0.10.28 && nvm copy-packages 0.10.28' did not fail with the right error code: expected '$EXPECTED_ERROR_CODE', got '$ACTUAL_ERROR_CODE'" - diff --git "a/test/slow/nvm reinstall-packages/Running \"nvm copy-packages $(nvm ls current)\" should error out" "b/test/slow/nvm reinstall-packages/Running \"nvm copy-packages $(nvm ls current)\" should error out" new file mode 100755 index 0000000000..1951b12f20 --- /dev/null +++ "b/test/slow/nvm reinstall-packages/Running \"nvm copy-packages $(nvm ls current)\" should error out" @@ -0,0 +1,16 @@ +#!/bin/sh + +die () { echo $@ ; exit 1; } + +. ../../../nvm.sh + +nvm use 0.10.28 > /dev/null + +EXPECTED_MSG="Can not reinstall packages from the current version of node." +ACTUAL_MSG="$(nvm reinstall-packages 0.10.28 2>&1 > /dev/null)" +[ "~$ACTUAL_MSG" = "~$EXPECTED_MSG" ] || die "'nvm use 0.10.28 && nvm reinstall-packages 0.10.28' did not fail with the right message: '$ACTUAL_MESSAGE'" + +EXPECTED_ERROR_CODE="2" +ACTUAL_ERROR_CODE="$(nvm reinstall-packages 0.10.28 > /dev/null 2>&1 ; echo $?)" +[ "~$ACTUAL_ERROR_CODE" = "~$EXPECTED_ERROR_CODE" ] || die "'nvm use 0.10.28 && nvm reinstall-packages 0.10.28' did not fail with the right error code: expected '$EXPECTED_ERROR_CODE', got '$ACTUAL_ERROR_CODE'" + diff --git a/test/slow/nvm copy-packages/setup_dir b/test/slow/nvm reinstall-packages/setup_dir similarity index 100% rename from test/slow/nvm copy-packages/setup_dir rename to test/slow/nvm reinstall-packages/setup_dir diff --git a/test/slow/nvm copy-packages/should work as expected b/test/slow/nvm reinstall-packages/should work as expected similarity index 96% rename from test/slow/nvm copy-packages/should work as expected rename to test/slow/nvm reinstall-packages/should work as expected index e599609243..4942e6ea15 100755 --- a/test/slow/nvm copy-packages/should work as expected +++ b/test/slow/nvm reinstall-packages/should work as expected @@ -13,7 +13,7 @@ echo "$EXPECTED_PACKAGES" | xargs npm install -g --quiet nvm use 0.10.29 ORIGINAL_PACKAGES=$(npm list -g --depth=0 | tail -n +2 | \grep -o -e ' [^@]*' | cut -c 2- | \grep -v npm | sort | uniq | xargs) -nvm copy-packages 0.10.28 +nvm reinstall-packages 0.10.28 FINAL_PACKAGES=$(npm list -g --depth=0 | tail -n +2 | \grep -o -e ' [^@]*' | cut -c 2- | \grep -v npm | sort | uniq | xargs) [ "$FINAL_PACKAGES" = "$EXPECTED_PACKAGES" ] || die "final packages ($FINAL_PACKAGES) did not match expected packages ($EXPECTED_PACKAGES)" diff --git a/test/slow/nvm copy-packages/teardown_dir b/test/slow/nvm reinstall-packages/teardown_dir similarity index 100% rename from test/slow/nvm copy-packages/teardown_dir rename to test/slow/nvm reinstall-packages/teardown_dir