Rename `nvm copy-packages` to `nvm reinstall-packages`, and `--copy-packages-from` install option to `--reinstall-packages-from`
For #341. `nvm copy-packages` and install option `--copy-packages-from` will continue to be supported for for at least a full minor release version.master
parent
c33074cb54
commit
e728577627
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
39
nvm.sh
39
nvm.sh
|
@ -545,7 +545,7 @@ nvm() {
|
|||
echo " nvm alias [<pattern>] Show all aliases beginning with <pattern>"
|
||||
echo " nvm alias <name> <version> Set an alias named <name> pointing to <version>"
|
||||
echo " nvm unalias <name> Deletes the alias named <name>"
|
||||
echo " nvm copy-packages <version> Install global \`npm\` packages contained in <version> to current version"
|
||||
echo " nvm reinstall-packages <version> Reinstall global \`npm\` packages contained in <version> 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
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
|
@ -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"
|
||||
|
|
@ -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"
|
||||
|
|
@ -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'"
|
||||
|
|
@ -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'"
|
||||
|
|
@ -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)"
|
Loading…
Reference in New Issue