From ec7e55326789bfd8b1d888ccdb0575246599ae53 Mon Sep 17 00:00:00 2001 From: dclayton Date: Tue, 8 Dec 2015 19:50:13 -0700 Subject: [PATCH] added --upgrade-npm to install command --- nvm.sh | 48 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 11 deletions(-) diff --git a/nvm.sh b/nvm.sh index c6b8f83..73b71de 100755 --- a/nvm.sh +++ b/nvm.sh @@ -1463,6 +1463,7 @@ nvm() { echo ' nvm --version Print out the latest released version of nvm' echo ' nvm install [-s] Download and install a , [-s] from source. Uses .nvmrc if available' echo ' --reinstall-packages-from= When installing, reinstall packages installed in ' + echo ' --upgrade-npm= When installing, upgrades NPM to the specified version' echo ' nvm uninstall Uninstall a version' echo ' nvm use [--silent] Modify PATH to use . Uses .nvmrc if available' echo ' nvm exec [--silent] [] Run on . Uses .nvmrc if available' @@ -1478,6 +1479,7 @@ nvm() { echo ' nvm alias Set an alias named pointing to ' echo ' nvm unalias Deletes the alias named ' echo ' nvm reinstall-packages Reinstall global `npm` packages contained in to current version' + echo ' nvm upgrade-npm Upgrades NPM to the specified version' echo ' nvm unload Unload `nvm` from shell' echo ' nvm which [] Display path to installed node version. Uses .nvmrc if available' echo @@ -1568,6 +1570,7 @@ nvm() { ADDITIONAL_PARAMETERS='' local PROVIDED_REINSTALL_PACKAGES_FROM local REINSTALL_PACKAGES_FROM + local UPGRADE_NPM_VERSION while [ $# -ne 0 ] do @@ -1580,6 +1583,9 @@ nvm() { PROVIDED_REINSTALL_PACKAGES_FROM="$(echo "$1" | command cut -c 22-)" REINSTALL_PACKAGES_FROM="$(nvm_version "$PROVIDED_REINSTALL_PACKAGES_FROM")" ;; + --upgrade-npm=*) + UPGRADE_NPM_VERSION="$(echo "$1" | command cut -c 15-)" + ;; *) ADDITIONAL_PARAMETERS="$ADDITIONAL_PARAMETERS $1" ;; @@ -1652,6 +1658,10 @@ nvm() { fi if [ "$NVM_INSTALL_SUCCESS" = true ] && nvm use "$VERSION"; then + if [ ! -z "$UPGRADE_NPM_VERSION" ]; then + nvm upgrade-npm "$UPGRADE_NPM_VERSION" + fi + if [ ! -z "$REINSTALL_PACKAGES_FROM" ] \ && [ "_$REINSTALL_PACKAGES_FROM" != "_N/A" ]; then nvm reinstall-packages "$REINSTALL_PACKAGES_FROM" @@ -2166,6 +2176,18 @@ $NVM_LS_REMOTE_POST_MERGED_OUTPUT" | command grep -v "N/A" | command sed '/^$/d' command rm -f "$NVM_ALIAS_DIR/$2" echo "Deleted alias $2" ;; + "upgrade-npm" ) + if [ $# -ne 2 ]; then + >&2 nvm help + return 127 + fi + + local NPM_VERSION + NPM_VERSION="$2" + + echo "Upgrading npm version to $NPM_VERSION" + npm install -g "npm@$NPM_VERSION" + ;; "reinstall-packages" | "copy-packages" ) if [ $# -ne 2 ]; then >&2 nvm help @@ -2199,18 +2221,22 @@ $NVM_LS_REMOTE_POST_MERGED_OUTPUT" | command grep -v "N/A" | command sed '/^$/d' LINKS="${NPMLIST##* //// }" echo "Reinstalling global packages from $VERSION..." - echo "$INSTALLS" | command xargs npm install -g --quiet + if [ "$INSTALLS" != '' ]; then + echo "$INSTALLS" | command xargs npm install -g --quiet + fi - echo "Linking global packages from $VERSION..." - set -f; IFS=' -' # necessary to turn off variable expansion except for newlines - for LINK in $LINKS; do - set +f; unset IFS # restore variable expansion - if [ -n "$LINK" ]; then - (cd "$LINK" && npm link) - fi - done - set +f; unset IFS # restore variable expansion in case $LINKS was empty + if [ "$LINKS" != '' ]; then + echo "Linking global packages from $VERSION..." + set -f; IFS=' + ' # necessary to turn off variable expansion except for newlines + for LINK in $LINKS; do + set +f; unset IFS # restore variable expansion + if [ -n "$LINK" ]; then + (cd "$LINK" && npm link) + fi + done + set +f; unset IFS # restore variable expansion in case $LINKS was empty + fi ;; "clear-cache" ) command rm -f "$NVM_DIR/v*" "$(nvm_version_dir)" 2>/dev/null