Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added --upgrade-npm to install command #931

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions nvm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1463,6 +1463,7 @@ nvm() {
echo ' nvm --version Print out the latest released version of nvm'
echo ' nvm install [-s] <version> Download and install a <version>, [-s] from source. Uses .nvmrc if available'
echo ' --reinstall-packages-from=<version> When installing, reinstall packages installed in <node|iojs|node version number>'
echo ' --upgrade-npm=<version> When installing, upgrades NPM to the specified version'
echo ' nvm uninstall <version> Uninstall a version'
echo ' nvm use [--silent] <version> Modify PATH to use <version>. Uses .nvmrc if available'
echo ' nvm exec [--silent] <version> [<command>] Run <command> on <version>. Uses .nvmrc if available'
Expand All @@ -1478,6 +1479,7 @@ nvm() {
echo ' nvm alias <name> <version> Set an alias named <name> pointing to <version>'
echo ' nvm unalias <name> Deletes the alias named <name>'
echo ' nvm reinstall-packages <version> Reinstall global `npm` packages contained in <version> to current version'
echo ' nvm upgrade-npm <version> Upgrades NPM to the specified version'
echo ' nvm unload Unload `nvm` from shell'
echo ' nvm which [<version>] Display path to installed node version. Uses .nvmrc if available'
echo
Expand Down Expand Up @@ -1568,6 +1570,7 @@ nvm() {
ADDITIONAL_PARAMETERS=''
local PROVIDED_REINSTALL_PACKAGES_FROM
local REINSTALL_PACKAGES_FROM
local UPGRADE_NPM_VERSION

while [ $# -ne 0 ]
do
Expand All @@ -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"
;;
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions test/installation/node/install while upgrading npm
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/sh

die () { echo $@ ; exit 1; }

. ../../../nvm.sh

# Remove the stuff we're clobbering.
[ -e ../../../versions/node/v4.2.3 ] && rm -R ../../../versions/node/v4.2.3

# Install from binary
nvm install 4.2.3 --upgrade-npm=3.5.1

# Check
[ -d ../../../versions/node/v4.2.3 ] || die "nvm install 4.2.3 didn't install"

npm --version | grep 3.5.1 || die "nvm install did not upgrade NPM"

9 changes: 9 additions & 0 deletions test/slow/nvm upgrade-npm/setup_dir
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh

. ../../../nvm.sh

# ensure version does not already exist
[ -e ../../../versions/node/v4.2.3 ] && rm -R ../../../versions/node/v4.2.3

nvm install 4.2.3

15 changes: 15 additions & 0 deletions test/slow/nvm upgrade-npm/should work as expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh

die () { echo "$@" ; exit 1; }

. ../../../nvm.sh

EXPECTED_VERSION="3.5.1"

OLD_VERSION=$(npm --version)
[ "$EXPECTED_VERSION" != "$OLD_VERSION" ] || die "NPM version already at $EXPECTED_VERSION"

nvm upgrade-npm $EXPECTED_VERSION
ACTUAL_VERSION=$(npm --version)

[ "$EXPECTED_VERSION" = "$ACTUAL_VERSION" ] || die "NPM package was not upgraded"
6 changes: 6 additions & 0 deletions test/slow/nvm upgrade-npm/teardown_dir
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh

. ../../../nvm.sh

#remove installed version
[ -e ../../../versions/node/v4.2.3 ] && rm -R ../../../versions/node/v4.2.3