Compare commits

..

19 Commits

Author SHA1 Message Date
Jordan Harband
21c3727955 v0.30.2 2016-01-21 00:23:01 -08:00
Jordan Harband
4fcf37fa29 [New] support --no-use on sourcing, in supported shells.
Fixes #972.
2016-01-20 12:50:45 -08:00
Nick Hwang
e76fe61d95 Add missing space before closing bracket 2016-01-19 13:03:11 -05:00
Jordan Harband
00a8b36b78 [Fix] handle unbound shell variables.
Fixes #868.
2016-01-17 15:12:02 -08:00
Dwayne Crooks
1e1a005a53 [Docs] Add manual upgrade instructions to README.markdown 2016-01-16 07:01:46 -04:00
Jordan Harband
1ba8a96ec9 Merge pull request #957 from matthew-campbell/fix-profile-var
[Fix] `install.sh`: honor PROFILE var.

Closes #888. Fixes #830.
2016-01-02 09:04:07 -08:00
Matthew Campbell
4f4ff208eb Improve error messages 2016-01-02 11:16:50 -05:00
Matthew Campbell
78fee866f5 Remove usage of declare 2016-01-01 22:33:45 -05:00
Matthew Campbell
8dc53d4dd5 Refactor and fix nvm_detect_profile tests
close #833
close #957
2016-01-01 20:45:36 -05:00
Matthew Campbell
645bda4987 Addresses comments to close #833 2016-01-01 14:09:35 -05:00
David Mankin
918fcb4bd2 PROFILE env var should override detected profile
Add tests for PROFILE overriding detected files
2016-01-01 14:00:36 -05:00
David Mankin
cb138a1815 Fix error messages in tests 2016-01-01 13:34:34 -05:00
Jordan Harband
6094dac1c1 [Fix] nvm debug was printing a red herring error message in non-zsh. 2015-12-30 09:45:13 -08:00
Jordan Harband
0aa3118de3 v0.30.1 2015-12-28 12:46:41 -08:00
Jordan Harband
2541baaf7d [Refactor] Create nvm_get_make_jobs to abstract out “-j” logic. 2015-12-28 12:20:14 -08:00
Jordan Harband
dc8b63cb25 [Fix] nvm install -s: fix syntax errors. 2015-12-28 12:19:50 -08:00
Jordan Harband
f3cc95bc66 Merge pull request #952 from davemay99/install-fix-quotes
[Fix] install.sh: quote `$DETECTED_PROFILE`
2015-12-28 09:24:42 -08:00
Dave May
00d4520d35 Merge remote-tracking branch 'creationix/master' into install-fix-quotes 2015-12-28 12:08:57 -05:00
Dave May
f113c5d030 fix quoting for usernames with space 2015-12-28 00:34:38 -05:00
7 changed files with 250 additions and 155 deletions

View File

@@ -25,11 +25,11 @@ Homebrew installation is not supported.
To install or update nvm, you can use the [install script][2] using cURL: To install or update nvm, you can use the [install script][2] using cURL:
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.30.0/install.sh | bash curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.30.2/install.sh | bash
or Wget: or Wget:
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.30.0/install.sh | bash wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.30.2/install.sh | bash
<sub>The script clones the nvm repository to `~/.nvm` and adds the source line to your profile (`~/.bash_profile`, `~/.zshrc` or `~/.profile`).</sub> <sub>The script clones the nvm repository to `~/.nvm` and adds the source line to your profile (`~/.bash_profile`, `~/.zshrc` or `~/.profile`).</sub>
@@ -55,6 +55,12 @@ Add these lines to your `~/.bashrc`, `~/.profile`, or `~/.zshrc` file to have it
export NVM_DIR="$HOME/.nvm" export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm
### Manual upgrade
For manual upgrade with `git`, change to the `$NVM_DIR`, pull down the latest changes, and check out the latest version:
cd "$NVM_DIR" && git pull origin master && git checkout `git describe --abbrev=0 --tags`
## Usage ## Usage
You can create an `.nvmrc` file containing version number in the project root directory (or any parent directory). You can create an `.nvmrc` file containing version number in the project root directory (or any parent directory).
@@ -254,7 +260,7 @@ After the v0.8.6 release of node, nvm tries to install from binary packages. But
If setting the `default` alias does not establish the node version in new shells (i.e. `nvm current` yields `system`), ensure that the system's node PATH is set before the `nvm.sh` source line in your shell profile (see [#658](https://github.com/creationix/nvm/issues/658)) If setting the `default` alias does not establish the node version in new shells (i.e. `nvm current` yields `system`), ensure that the system's node PATH is set before the `nvm.sh` source line in your shell profile (see [#658](https://github.com/creationix/nvm/issues/658))
[1]: https://github.com/creationix/nvm.git [1]: https://github.com/creationix/nvm.git
[2]: https://github.com/creationix/nvm/blob/v0.30.0/install.sh [2]: https://github.com/creationix/nvm/blob/v0.30.2/install.sh
[3]: https://travis-ci.org/creationix/nvm [3]: https://travis-ci.org/creationix/nvm
[Urchin]: https://github.com/scraperwiki/urchin [Urchin]: https://github.com/scraperwiki/urchin
[Fish]: http://fishshell.com [Fish]: http://fishshell.com

View File

@@ -11,7 +11,7 @@ if [ -z "$NVM_DIR" ]; then
fi fi
nvm_latest_version() { nvm_latest_version() {
echo "v0.30.0" echo "v0.30.2"
} }
# #
@@ -115,6 +115,10 @@ install_nvm_as_script() {
# Otherwise, an empty string is returned # Otherwise, an empty string is returned
# #
nvm_detect_profile() { nvm_detect_profile() {
if [ -n "$PROFILE" -a -f "$PROFILE" ]; then
echo "$PROFILE"
return
fi
local DETECTED_PROFILE local DETECTED_PROFILE
DETECTED_PROFILE='' DETECTED_PROFILE=''
@@ -131,10 +135,8 @@ nvm_detect_profile() {
DETECTED_PROFILE="$HOME/.zshrc" DETECTED_PROFILE="$HOME/.zshrc"
fi fi
if [ -z $DETECTED_PROFILE ]; then if [ -z "$DETECTED_PROFILE" ]; then
if [ -f "$PROFILE" ]; then if [ -f "$HOME/.profile" ]; then
DETECTED_PROFILE="$PROFILE"
elif [ -f "$HOME/.profile" ]; then
DETECTED_PROFILE="$HOME/.profile" DETECTED_PROFILE="$HOME/.profile"
elif [ -f "$HOME/.bashrc" ]; then elif [ -f "$HOME/.bashrc" ]; then
DETECTED_PROFILE="$HOME/.bashrc" DETECTED_PROFILE="$HOME/.bashrc"
@@ -145,7 +147,7 @@ nvm_detect_profile() {
fi fi
fi fi
if [ ! -z $DETECTED_PROFILE ]; then if [ ! -z "$DETECTED_PROFILE" ]; then
echo "$DETECTED_PROFILE" echo "$DETECTED_PROFILE"
fi fi
} }

View File

@@ -2,7 +2,7 @@
DIR="$(command cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" DIR="$(command cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$DIR/nvm.sh" . "$DIR/nvm.sh" --no-use
if [ -n "$NODE_VERSION" ]; then if [ -n "$NODE_VERSION" ]; then
nvm use $NODE_VERSION > /dev/null || (echo "NODE_VERSION not set" >&2 && exit 127) nvm use $NODE_VERSION > /dev/null || (echo "NODE_VERSION not set" >&2 && exit 127)

187
nvm.sh
View File

@@ -68,13 +68,16 @@ nvm_print_npm_version() {
# Make zsh glob matching behave same as bash # Make zsh glob matching behave same as bash
# This fixes the "zsh: no matches found" errors # This fixes the "zsh: no matches found" errors
if [ -z "${NVM_CD_FLAGS-}" ]; then
export NVM_CD_FLAGS=''
fi
if nvm_has "unsetopt"; then if nvm_has "unsetopt"; then
unsetopt nomatch 2>/dev/null unsetopt nomatch 2>/dev/null
NVM_CD_FLAGS="-q" NVM_CD_FLAGS="-q"
fi fi
# Auto detect the NVM_DIR when not set # Auto detect the NVM_DIR when not set
if [ -z "$NVM_DIR" ]; then if [ -z "${NVM_DIR-}" ]; then
if [ -n "$BASH_SOURCE" ]; then if [ -n "$BASH_SOURCE" ]; then
NVM_SCRIPT_SOURCE="${BASH_SOURCE[0]}" NVM_SCRIPT_SOURCE="${BASH_SOURCE[0]}"
fi fi
@@ -85,7 +88,7 @@ unset NVM_SCRIPT_SOURCE 2> /dev/null
# Setup mirror location if not already set # Setup mirror location if not already set
if [ -z "$NVM_NODEJS_ORG_MIRROR" ]; then if [ -z "${NVM_NODEJS_ORG_MIRROR-}" ]; then
export NVM_NODEJS_ORG_MIRROR="https://nodejs.org/dist" export NVM_NODEJS_ORG_MIRROR="https://nodejs.org/dist"
fi fi
@@ -529,7 +532,7 @@ nvm_strip_iojs_prefix() {
nvm_ls() { nvm_ls() {
local PATTERN local PATTERN
PATTERN="$1" PATTERN="${1-}"
local VERSIONS local VERSIONS
VERSIONS='' VERSIONS=''
if [ "$PATTERN" = 'current' ]; then if [ "$PATTERN" = 'current' ]; then
@@ -659,7 +662,7 @@ nvm_ls() {
fi fi
fi fi
if [ "$NVM_ADD_SYSTEM" = true ]; then if [ "${NVM_ADD_SYSTEM-}" = true ]; then
if [ -z "$PATTERN" ] || [ "_$PATTERN" = "_v" ]; then if [ -z "$PATTERN" ] || [ "_$PATTERN" = "_v" ]; then
VERSIONS="$VERSIONS$(command printf '\n%s' 'system')" VERSIONS="$VERSIONS$(command printf '\n%s' 'system')"
elif [ "$PATTERN" = 'system' ]; then elif [ "$PATTERN" = 'system' ]; then
@@ -700,6 +703,7 @@ nvm_ls_remote_index_tab() {
local TYPE local TYPE
TYPE="$1" TYPE="$1"
local PREFIX local PREFIX
PREFIX=''
case "$TYPE-$2" in case "$TYPE-$2" in
iojs-std) PREFIX="$(nvm_iojs_prefix)-" ;; iojs-std) PREFIX="$(nvm_iojs_prefix)-" ;;
node-std) PREFIX='' ;; node-std) PREFIX='' ;;
@@ -835,7 +839,7 @@ nvm_print_implicit_alias() {
local NVM_ADD_PREFIX_COMMAND local NVM_ADD_PREFIX_COMMAND
local LAST_TWO local LAST_TWO
case "$NVM_IMPLICIT" in case "$NVM_IMPLICIT" in
"$NVM_IOJS_PREFIX" | "$NVM_IOJS_RC_PREFIX") "$NVM_IOJS_PREFIX")
NVM_COMMAND="nvm_ls_remote_iojs" NVM_COMMAND="nvm_ls_remote_iojs"
NVM_ADD_PREFIX_COMMAND="nvm_add_iojs_prefix" NVM_ADD_PREFIX_COMMAND="nvm_add_iojs_prefix"
if [ "_$1" = "_local" ]; then if [ "_$1" = "_local" ]; then
@@ -1146,7 +1150,7 @@ nvm_install_node_binary() {
local REINSTALL_PACKAGES_FROM local REINSTALL_PACKAGES_FROM
REINSTALL_PACKAGES_FROM="$2" REINSTALL_PACKAGES_FROM="$2"
if nvm_is_iojs_version "$PREFIXED_VERSION"; then if nvm_is_iojs_version "$VERSION"; then
echo 'nvm_install_node_binary does not allow an iojs-prefixed version.' >&2 echo 'nvm_install_node_binary does not allow an iojs-prefixed version.' >&2
return 10 return 10
fi fi
@@ -1200,11 +1204,48 @@ nvm_install_node_binary() {
return 2 return 2
} }
nvm_get_make_jobs() {
if nvm_is_natural_num "${1-}"; then
NVM_MAKE_JOBS="$1"
echo "number of \`make\` jobs: $NVM_MAKE_JOBS"
return
elif [ -n "${1-}" ]; then
unset NVM_MAKE_JOBS
echo >&2 "$1 is invalid for number of \`make\` jobs, must be a natural number"
fi
local NVM_OS
NVM_OS="$(nvm_get_os)"
local NVM_CPU_THREADS
if [ "_$NVM_OS" = "_linux" ]; then
NVM_CPU_THREADS="$(grep -c 'core id' /proc/cpuinfo)"
elif [ "_$NVM_OS" = "_freebsd" ] || [ "_$NVM_OS" = "_darwin" ]; then
NVM_CPU_THREADS="$(sysctl -n hw.ncpu)"
elif [ "_$NVM_OS" = "_sunos" ]; then
NVM_CPU_THREADS="$(psrinfo | wc -l)"
fi
if ! nvm_is_natural_num "$NVM_CPU_THREADS" ; then
echo "Can not determine how many thread(s) we can use, set to only 1 now." >&2
echo "Please report an issue on GitHub to help us make it better and run it faster on your computer!" >&2
NVM_MAKE_JOBS=1
else
echo "Detected that you have $NVM_CPU_THREADS CPU thread(s)"
if [ $NVM_CPU_THREADS -gt 2 ]; then
NVM_MAKE_JOBS=$(($NVM_CPU_THREADS - 1))
echo "Set the number of jobs to $NVM_CPU_THREADS - 1 = $NVM_MAKE_JOBS jobs to speed up the build"
else
NVM_MAKE_JOBS=1
echo "Number of CPU thread(s) less or equal to 2 will have only one job a time for 'make'"
fi
fi
}
nvm_install_node_source() { nvm_install_node_source() {
local VERSION local VERSION
VERSION="$1" VERSION="$1"
local NVM_MAKE_JOBS
NVM_MAKE_JOBS="$2"
local ADDITIONAL_PARAMETERS local ADDITIONAL_PARAMETERS
ADDITIONAL_PARAMETERS="$2" ADDITIONAL_PARAMETERS="$3"
local NVM_ARCH local NVM_ARCH
NVM_ARCH="$(nvm_get_arch)" NVM_ARCH="$(nvm_get_arch)"
@@ -1232,29 +1273,6 @@ nvm_install_node_source() {
MAKE_CXX="CXX=c++" MAKE_CXX="CXX=c++"
fi fi
if [ -z "$NVM_MAKE_JOBS" ]; then
if [ "_$NVM_OS" = "_linux" ]; then
NVM_CPU_THREADS="$(grep -c 'core id' /proc/cpuinfo)"
elif [ "_$NVM_OS" = "_freebsd" ] || [ "_$NVM_OS" = "_darwin" ]; then
NVM_CPU_THREADS="$(sysctl -n hw.ncpu)"
elif [ "_$NVM_OS" = "_sunos" ]; then
NVM_CPU_THREADS="$(psrinfo | wc -l)"
fi
if [ ! nvm_is_natural_num "$NVM_CPU_THREADS" ] ; then
echo "Can not determine how many thread(s) we can use, set to only 1 now." 1>&2
echo "Please report an issue on GitHub to help us make it better and run it faster on your computer!" 1>&2
NVM_MAKE_JOBS="1"
else
echo "Detected that you have $NVM_CPU_THREADS CPU thread(s)"
if [ $NVM_CPU_THREADS -gt 2 ]; then
NVM_MAKE_JOBS=$(($NVM_CPU_THREADS - 1))
echo "Set the number of jobs to $NVM_CPU_THREADS - 1 = $NVM_MAKE_JOBS jobs to speed up the build"
else
NVM_MAKE_JOBS=1
echo "Number of CPU thread(s) less or equal to 2 will have only one job a time for 'make'"
fi
fi
fi
local tmpdir local tmpdir
tmpdir="$NVM_DIR/src" tmpdir="$NVM_DIR/src"
local tmptarball local tmptarball
@@ -1276,9 +1294,9 @@ nvm_install_node_source() {
command tar -xzf "$tmptarball" -C "$tmpdir" && \ command tar -xzf "$tmptarball" -C "$tmpdir" && \
cd "$tmpdir/node-$VERSION" && \ cd "$tmpdir/node-$VERSION" && \
./configure --prefix="$VERSION_PATH" $ADDITIONAL_PARAMETERS && \ ./configure --prefix="$VERSION_PATH" $ADDITIONAL_PARAMETERS && \
$make -j $NVM_MAKE_JOBS $MAKE_CXX && \ $make -j $NVM_MAKE_JOBS ${MAKE_CXX-} && \
command rm -f "$VERSION_PATH" 2>/dev/null && \ command rm -f "$VERSION_PATH" 2>/dev/null && \
$make -j $NVM_MAKE_JOBS $MAKE_CXX install $make -j $NVM_MAKE_JOBS ${MAKE_CXX-} install
) )
then then
if ! nvm_has "npm" ; then if ! nvm_has "npm" ; then
@@ -1357,14 +1375,14 @@ nvm_die_on_prefix() {
return 2 return 2
fi fi
if [ -n "$PREFIX" ] && ! (nvm_tree_contains_path "$NVM_DIR" "$PREFIX" >/dev/null 2>&1); then if [ -n "${PREFIX-}" ] && ! (nvm_tree_contains_path "$NVM_DIR" "$PREFIX" >/dev/null 2>&1); then
nvm deactivate >/dev/null 2>&1 nvm deactivate >/dev/null 2>&1
echo >&2 "nvm is not compatible with the \"PREFIX\" environment variable: currently set to \"$PREFIX\"" echo >&2 "nvm is not compatible with the \"PREFIX\" environment variable: currently set to \"$PREFIX\""
echo >&2 "Run \`unset PREFIX\` to unset it." echo >&2 "Run \`unset PREFIX\` to unset it."
return 3 return 3
fi fi
if [ -n "$NPM_CONFIG_PREFIX" ] && ! (nvm_tree_contains_path "$NVM_DIR" "$NPM_CONFIG_PREFIX" >/dev/null 2>&1); then if [ -n "${NPM_CONFIG_PREFIX-}" ] && ! (nvm_tree_contains_path "$NVM_DIR" "$NPM_CONFIG_PREFIX" >/dev/null 2>&1); then
nvm deactivate >/dev/null 2>&1 nvm deactivate >/dev/null 2>&1
echo >&2 "nvm is not compatible with the \"NPM_CONFIG_PREFIX\" environment variable: currently set to \"$NPM_CONFIG_PREFIX\"" echo >&2 "nvm is not compatible with the \"NPM_CONFIG_PREFIX\" environment variable: currently set to \"$NPM_CONFIG_PREFIX\""
echo >&2 "Run \`unset NPM_CONFIG_PREFIX\` to unset it." echo >&2 "Run \`unset NPM_CONFIG_PREFIX\` to unset it."
@@ -1532,6 +1550,7 @@ nvm() {
"debug" ) "debug" )
local ZHS_HAS_SHWORDSPLIT_UNSET local ZHS_HAS_SHWORDSPLIT_UNSET
ZHS_HAS_SHWORDSPLIT_UNSET=1
if nvm_has "setopt"; then if nvm_has "setopt"; then
ZHS_HAS_SHWORDSPLIT_UNSET=$(setopt | command grep shwordsplit > /dev/null ; echo $?) ZHS_HAS_SHWORDSPLIT_UNSET=$(setopt | command grep shwordsplit > /dev/null ; echo $?)
setopt shwordsplit setopt shwordsplit
@@ -1578,6 +1597,7 @@ nvm() {
local nobinary local nobinary
nobinary=0 nobinary=0
local make_jobs
while [ $# -ne 0 ] while [ $# -ne 0 ]
do do
case "$1" in case "$1" in
@@ -1587,13 +1607,7 @@ nvm() {
;; ;;
-j) -j)
shift # consume "-j" shift # consume "-j"
if [ nvm_is_natural_num "$1" ]; then nvm_get_make_jobs "$1"
NVM_MAKE_JOBS=$1
echo "number of \`make\` jobs: $NVM_MAKE_JOBS"
else
unset NVM_MAKE_JOBS
echo >&2 "$1 is invalid for number of \`make\` jobs, must be a natural number"
fi
shift # consume job count shift # consume job count
;; ;;
*) *)
@@ -1692,16 +1706,19 @@ nvm() {
fi fi
fi fi
if [ "$NVM_INSTALL_SUCCESS" != true ]; then if [ "$NVM_INSTALL_SUCCESS" != true ]; then
if [ -z "${NVM_MAKE_JOBS-}" ]; then
nvm_get_make_jobs
fi
if [ "$NVM_IOJS" != true ] && [ "$NVM_NODE_MERGED" != true ]; then if [ "$NVM_IOJS" != true ] && [ "$NVM_NODE_MERGED" != true ]; then
if nvm_install_node_source "$VERSION" "$ADDITIONAL_PARAMETERS"; then if nvm_install_node_source "$VERSION" "$NVM_MAKE_JOBS" "$ADDITIONAL_PARAMETERS"; then
NVM_INSTALL_SUCCESS=true NVM_INSTALL_SUCCESS=true
fi fi
elif [ "$NVM_IOJS" = true ]; then elif [ "$NVM_IOJS" = true ]; then
# nvm_install_iojs_source "$VERSION" "$ADDITIONAL_PARAMETERS" # nvm_install_iojs_source "$VERSION" "$NVM_MAKE_JOBS" "$ADDITIONAL_PARAMETERS"
echo "Installing iojs from source is not currently supported" >&2 echo "Installing iojs from source is not currently supported" >&2
return 105 return 105
elif [ "$NVM_NODE_MERGED" = true ]; then elif [ "$NVM_NODE_MERGED" = true ]; then
# nvm_install_merged_node_source "$VERSION" "$ADDITIONAL_PARAMETERS" # nvm_install_merged_node_source "$VERSION" "$NVM_MAKE_JOBS" "$ADDITIONAL_PARAMETERS"
echo "Installing node v1.0 and greater from source is not currently supported" >&2 echo "Installing node v1.0 and greater from source is not currently supported" >&2
return 106 return 106
fi fi
@@ -1784,18 +1801,22 @@ nvm() {
echo "$NVM_DIR/*/bin removed from \$PATH" echo "$NVM_DIR/*/bin removed from \$PATH"
fi fi
NEWPATH="$(nvm_strip_path "$MANPATH" "/share/man")" if [ -n "${MANPATH-}" ]; then
if [ "_$MANPATH" = "_$NEWPATH" ]; then NEWPATH="$(nvm_strip_path "$MANPATH" "/share/man")"
echo "Could not find $NVM_DIR/*/share/man in \$MANPATH" >&2 if [ "_$MANPATH" = "_$NEWPATH" ]; then
else echo "Could not find $NVM_DIR/*/share/man in \$MANPATH" >&2
export MANPATH="$NEWPATH" else
echo "$NVM_DIR/*/share/man removed from \$MANPATH" export MANPATH="$NEWPATH"
echo "$NVM_DIR/*/share/man removed from \$MANPATH"
fi
fi fi
NEWPATH="$(nvm_strip_path "$NODE_PATH" "/lib/node_modules")" if [ -n "${NODE_PATH-}" ]; then
if [ "_$NODE_PATH" != "_$NEWPATH" ]; then NEWPATH="$(nvm_strip_path "$NODE_PATH" "/lib/node_modules")"
export NODE_PATH="$NEWPATH" if [ "_$NODE_PATH" != "_$NEWPATH" ]; then
echo "$NVM_DIR/*/lib/node_modules removed from \$NODE_PATH" export NODE_PATH="$NEWPATH"
echo "$NVM_DIR/*/lib/node_modules removed from \$NODE_PATH"
fi
fi fi
;; ;;
"use" ) "use" )
@@ -1888,7 +1909,7 @@ nvm() {
hash -r hash -r
export NVM_PATH="$NVM_VERSION_DIR/lib/node" export NVM_PATH="$NVM_VERSION_DIR/lib/node"
export NVM_BIN="$NVM_VERSION_DIR/bin" export NVM_BIN="$NVM_VERSION_DIR/bin"
if [ "$NVM_SYMLINK_CURRENT" = true ]; then if [ "${NVM_SYMLINK_CURRENT-}" = true ]; then
command rm -f "$NVM_DIR/current" && ln -s "$NVM_VERSION_DIR" "$NVM_DIR/current" command rm -f "$NVM_DIR/current" && ln -s "$NVM_VERSION_DIR" "$NVM_DIR/current"
fi fi
local NVM_USE_OUTPUT local NVM_USE_OUTPUT
@@ -2047,7 +2068,7 @@ nvm() {
"ls" | "list" ) "ls" | "list" )
local NVM_LS_OUTPUT local NVM_LS_OUTPUT
local NVM_LS_EXIT_CODE local NVM_LS_EXIT_CODE
NVM_LS_OUTPUT=$(nvm_ls "$2") NVM_LS_OUTPUT=$(nvm_ls "${2-}")
NVM_LS_EXIT_CODE=$? NVM_LS_EXIT_CODE=$?
nvm_print_versions "$NVM_LS_OUTPUT" nvm_print_versions "$NVM_LS_OUTPUT"
if [ $# -eq 1 ]; then if [ $# -eq 1 ]; then
@@ -2057,7 +2078,7 @@ nvm() {
;; ;;
"ls-remote" | "list-remote" ) "ls-remote" | "list-remote" )
local PATTERN local PATTERN
PATTERN="$2" PATTERN="${2-}"
local NVM_IOJS_PREFIX local NVM_IOJS_PREFIX
NVM_IOJS_PREFIX="$(nvm_iojs_prefix)" NVM_IOJS_PREFIX="$(nvm_iojs_prefix)"
local NVM_NODE_PREFIX local NVM_NODE_PREFIX
@@ -2162,7 +2183,7 @@ $NVM_LS_REMOTE_POST_MERGED_OUTPUT" | command grep -v "N/A" | command sed '/^$/d'
command mkdir -p "$NVM_ALIAS_DIR" command mkdir -p "$NVM_ALIAS_DIR"
if [ $# -le 2 ]; then if [ $# -le 2 ]; then
local DEST local DEST
for ALIAS_PATH in "$NVM_ALIAS_DIR"/"$2"*; do for ALIAS_PATH in "$NVM_ALIAS_DIR"/"${2-}"*; do
ALIAS="$(command basename "$ALIAS_PATH")" ALIAS="$(command basename "$ALIAS_PATH")"
DEST="$(nvm_alias "$ALIAS" 2> /dev/null)" DEST="$(nvm_alias "$ALIAS" 2> /dev/null)"
if [ -n "$DEST" ]; then if [ -n "$DEST" ]; then
@@ -2192,7 +2213,7 @@ $NVM_LS_REMOTE_POST_MERGED_OUTPUT" | command grep -v "N/A" | command sed '/^$/d'
done done
return return
fi fi
if [ -z "$3" ]; then if [ -z "${3-}" ]; then
command rm -f "$NVM_ALIAS_DIR/$2" command rm -f "$NVM_ALIAS_DIR/$2"
echo "$2 -> *poof*" echo "$2 -> *poof*"
return return
@@ -2279,7 +2300,7 @@ $NVM_LS_REMOTE_POST_MERGED_OUTPUT" | command grep -v "N/A" | command sed '/^$/d'
nvm_remote_version "$2" nvm_remote_version "$2"
;; ;;
"--version" ) "--version" )
echo "0.30.0" echo "0.30.2"
;; ;;
"unload" ) "unload" )
unset -f nvm nvm_print_versions nvm_checksum \ unset -f nvm nvm_print_versions nvm_checksum \
@@ -2304,7 +2325,7 @@ $NVM_LS_REMOTE_POST_MERGED_OUTPUT" | command grep -v "N/A" | command sed '/^$/d'
nvm_print_npm_version nvm_npm_global_modules \ nvm_print_npm_version nvm_npm_global_modules \
nvm_has_system_node nvm_has_system_iojs \ nvm_has_system_node nvm_has_system_iojs \
nvm_download nvm_get_latest nvm_has nvm_get_latest \ nvm_download nvm_get_latest nvm_has nvm_get_latest \
nvm_supports_source_options nvm_supports_xz > /dev/null 2>&1 nvm_supports_source_options nvm_auto nvm_supports_xz > /dev/null 2>&1
unset RC_VERSION NVM_NODEJS_ORG_MIRROR NVM_DIR NVM_CD_FLAGS > /dev/null 2>&1 unset RC_VERSION NVM_NODEJS_ORG_MIRROR NVM_DIR NVM_CD_FLAGS > /dev/null 2>&1
;; ;;
* ) * )
@@ -2322,17 +2343,41 @@ nvm_supports_xz() {
command which xz >/dev/null 2>&1 && nvm_version_greater_than_or_equal_to "$1" "2.3.2" command which xz >/dev/null 2>&1 && nvm_version_greater_than_or_equal_to "$1" "2.3.2"
} }
NVM_VERSION="$(nvm_alias default 2>/dev/null || echo)" nvm_auto() {
if nvm_supports_source_options && [ "$#" -gt 0 ] && [ "_$1" = "_--install" ]; then local NVM_MODE
if [ -n "$NVM_VERSION" ]; then NVM_MODE="${1-}"
nvm install "$NVM_VERSION" >/dev/null local VERSION
elif nvm_rc_version >/dev/null 2>&1; then if [ "_$NVM_MODE" = '_install' ]; then
nvm install >/dev/null VERSION="$(nvm_alias default 2>/dev/null || echo)"
if [ -n "$VERSION" ]; then
nvm install "$VERSION" >/dev/null
elif nvm_rc_version >/dev/null 2>&1; then
nvm install >/dev/null
fi
elif [ "_$NVM_MODE" = '_use' ]; then
VERSION="$(nvm_alias default 2>/dev/null || echo)"
if [ -n "$VERSION" ]; then
nvm use --silent "$VERSION" >/dev/null
elif nvm_rc_version >/dev/null 2>&1; then
nvm use --silent >/dev/null
fi
elif [ "_$NVM_MODE" != '_none' ]; then
echo >&2 'Invalid auto mode supplied.'
return 1
fi fi
elif [ -n "$NVM_VERSION" ]; then }
nvm use --silent "$NVM_VERSION" >/dev/null
elif nvm_rc_version >/dev/null 2>&1; then NVM_AUTO_MODE='use'
nvm use --silent >/dev/null if nvm_supports_source_options; then
while [ $# -ne 0 ]
do
case "$1" in
--install) NVM_AUTO_MODE='install' ;;
--no-use) NVM_AUTO_MODE='none' ;;
esac
shift
done
fi fi
nvm_auto "$NVM_AUTO_MODE"
} # this ensures the entire script is downloaded # } # this ensures the entire script is downloaded #

View File

@@ -1,6 +1,6 @@
{ {
"name": "nvm", "name": "nvm",
"version": "0.30.0", "version": "0.30.2",
"description": "Node Version Manager - Simple bash script to manage multiple active node.js versions", "description": "Node Version Manager - Simple bash script to manage multiple active node.js versions",
"directories": { "directories": {
"test": "test" "test": "test"

View File

@@ -1,101 +1,111 @@
#!/bin/sh #!/bin/sh
cleanup () {
unset -f setup cleanup die
unset _PROFILE
rm -f .bashrc .bash_profile .zshrc .profile test_profile > /dev/null 2>&1
}
die () { echo $@ ; cleanup ; exit 1; }
NVM_ENV=testing . ../../install.sh
setup () { setup () {
touch .bashrc HOME="."
touch .bash_profile NVM_ENV=testing . ../../install.sh
touch .zshrc touch ".bashrc"
touch .profile touch ".bash_profile"
touch test_profile touch ".zshrc"
touch ".profile"
touch "test_profile"
} }
#Let's hack $HOME cleanup () {
HOME="." unset HOME
unset NVM_ENV
unset NVM_DETECT_PROFILE
unset -f setup cleanup die
rm -f ".bashrc" ".bash_profile" ".zshrc" ".profile" "test_profile" > "/dev/null" 2>&1
}
die () { echo "$@" '$NVM_DETECT_PROFILE:' "$NVM_DETECT_PROFILE"; cleanup; exit 1; }
setup setup
#Let's force $SHELL to be bash #
SHELL="/bin/bash" # Confirm profile detection via $SHELL works and that $PROFILE overrides profile detection
#
# $SHELL is set to bash and .bashrc is there, it must be detected # .bashrc should be detected for bash
_PROFILE=$(nvm_detect_profile) NVM_DETECT_PROFILE="$(SHELL="/bin/bash"; unset PROFILE; nvm_detect_profile)"
[ "_$_PROFILE" = "_$HOME/.bashrc" ] || echo "_\$HOME/.bashrc: _$HOME/.bashrc\n" \ if [ "$NVM_DETECT_PROFILE" != "$HOME/.bashrc" ]; then
echo "_\$_PROFILE: _$_PROFILE\n" \ die "nvm_detect_profile didn't pick \$HOME/.bashrc for bash"
die "nvm_detect_profile didn't pick $SHELL and $HOME/.bashrc" fi
#Let's force $SHELL to be zsh # $PROFILE should override .bashrc profile detection
SHELL="/usr/bin/zsh" NVM_DETECT_PROFILE="$(SHELL="/bin/bash"; PROFILE="test_profile"; nvm_detect_profile)"
if [ "$NVM_DETECT_PROFILE" != "test_profile" ]; then
die "nvm_detect_profile ignored \$PROFILE"
fi
# $SHELL is set to zsh and .zshrc is there, it must be detected # .zshrc should be detected for zsh
_PROFILE=$(nvm_detect_profile) NVM_DETECT_PROFILE="$(SHELL="/usr/bin/zsh"; unset PROFILE; nvm_detect_profile)"
[ "_$_PROFILE" = "_$HOME/.zshrc" ] || echo "_\$HOME/.zshrc: _$HOME/.zshrc\n" \ if [ "$NVM_DETECT_PROFILE" != "$HOME/.zshrc" ]; then
echo "_\$_PROFILE: _$_PROFILE\n" \ die "nvm_detect_profile didn't pick \$HOME/.zshrc for zsh"
die "nvm_detect_profile didn't pick $SHELL and $HOME/.zshrc" fi
# $PROFILE should override .zshrc profile detection
NVM_DETECT_PROFILE="$(SHELL="/usr/bin/zsh"; PROFILE="test_profile"; nvm_detect_profile)"
if [ "$NVM_DETECT_PROFILE" != "test_profile" ]; then
die "nvm_detect_profile ignored \$PROFILE"
fi
# if we unset shell it looks for the files #
unset SHELL # Confirm $PROFILE is only returned when it points to a valid file
#
# $PROFILE points to a valid file, its path must be returned # $PROFILE is a valid file
PROFILE="test_profile" NVM_DETECT_PROFILE="$(PROFILE="test_profile"; nvm_detect_profile)"
_PROFILE=$(nvm_detect_profile) if [ "$NVM_DETECT_PROFILE" != "test_profile" ]; then
[ "_$_PROFILE" = "_$PROFILE" ] || echo "_\$_PROFILE: _$_PROFILE\n" \ die "nvm_detect_profile didn't pick \$PROFILE when it was a valid file"
echo "_\$PROFILE: _$PROFILE\n" \ fi
die "nvm_detect_profile didn't pick \$PROFILE"
# $PROFILE doesn't point to a valid file, its path must not be returned # $PROFILE is not a valid file
PROFILE="invalid_profile" rm "test_profile"
_PROFILE=$(nvm_detect_profile) NVM_DETECT_PROFILE="$(PROFILE="test_profile"; nvm_detect_profile)"
[ "_$_PROFILE" != "_$PROFILE" ] || echo "_\$_PROFILE: _$_PROFILE\n" \ if [ "$NVM_DETECT_PROFILE" = "test_profile" ]; then
echo "_\$PROFILE: _$PROFILE\n" \ die "nvm_detect_profile picked \$PROFILE when it was an invalid file"
die "nvm_detect_profile shouldn't pick \$PROFILE when it's not a valid file" fi
#
# Below are tests for when $PROFILE is undefined # When profile detection fails via both $PROFILE and $SHELL, profile detection should select based on the existence of
rm test_profile # one of the following files is the following order: .profile, .bashrc, .bash_profile, .zshrc and
unset PROFILE # return an empty value if everything fails
#
# It should favor .profile if file exists # It should favor .profile if file exists
_PROFILE=$(nvm_detect_profile) NVM_DETECT_PROFILE="$(unset SHELL; nvm_detect_profile)"
[ "_$_PROFILE" = "_$HOME/.profile" ] || echo "_\$_PROFILE: _$_PROFILE\n" \ if [ "$NVM_DETECT_PROFILE" != "$HOME/.profile" ]; then
echo "_\$PROFILE: _$PROFILE\n" \ die "nvm_detect_profile should have selected .profile"
die "nvm_detect_profile should have selected .profile" fi
rm .profile
# Otherwise, it should favor .bashrc if file exists # Otherwise, it should favor .bashrc if file exists
_PROFILE=$(nvm_detect_profile) rm ".profile"
[ "_$_PROFILE" = "_$HOME/.bashrc" ] || echo "_\$_PROFILE: _$_PROFILE\n" \ NVM_DETECT_PROFILE="$(unset SHELL; nvm_detect_profile)"
echo "_\$PROFILE: _$PROFILE\n" \ if [ "$NVM_DETECT_PROFILE" != "$HOME/.bashrc" ]; then
die "nvm_detect_profile should have selected .bashrc" die "nvm_detect_profile should have selected .bashrc"
fi
rm .bashrc
# Otherwise, it should favor .bash_profile if file exists # Otherwise, it should favor .bash_profile if file exists
_PROFILE=$(nvm_detect_profile) rm ".bashrc"
[ "_$_PROFILE" = "_$HOME/.bash_profile" ] || echo "_\$_PROFILE: _$_PROFILE\n" \ NVM_DETECT_PROFILE="$(unset SHELL; nvm_detect_profile)"
echo "_\$PROFILE: _$PROFILE\n" \ if [ "$NVM_DETECT_PROFILE" != "$HOME/.bash_profile" ]; then
die "nvm_detect_profile should have selected .bash_profile" die "nvm_detect_profile should have selected .bash_profile"
fi
rm .bash_profile
# Otherwise, it should favor .zshrc if file exists # Otherwise, it should favor .zshrc if file exists
_PROFILE=$(nvm_detect_profile) rm ".bash_profile"
[ "_$_PROFILE" = "_$HOME/.zshrc" ] || echo "_\$_PROFILE: _$_PROFILE\n" \ NVM_DETECT_PROFILE="$(unset SHELL; nvm_detect_profile)"
echo "_\$PROFILE: _$PROFILE\n" \ if [ "$NVM_DETECT_PROFILE" != "$HOME/.zshrc" ]; then
die "nvm_detect_profile should have selected .zshrc" die "nvm_detect_profile should have selected .zshrc"
fi
rm .zshrc
# It should be empty if none is found # It should be empty if none is found
_PROFILE=$(nvm_detect_profile) rm ".zshrc"
[ -z "$_PROFILE" ] || echo "_\$_PROFILE: _$_PROFILE\n" \ NVM_DETECT_PROFILE="$(unset SHELL; nvm_detect_profile)"
echo "_\$PROFILE: _$PROFILE\n" \ if [ ! -z "$NVM_DETECT_PROFILE" ]; then
die "nvm_detect_profile should have echo'ed an empty value" die "nvm_detect_profile should have returned an empty value"
fi
cleanup cleanup

View File

@@ -0,0 +1,32 @@
#!/bin/sh
die () { echo $@ ; exit 1; }
supports_source_options () {
[ "_$(echo 'echo $1' | . /dev/stdin yes)" = "_yes" ]
}
if ! supports_source_options; then
echo 'this shell does not support passing options on sourcing'
exit 0;
fi
. ../../nvm.sh
nvm install 4.1.0 || die 'install of v4.1.0 failed'
nvm_version 4.1.0 >/dev/null 2>&1 || die "v4.1.0 not installed: $(nvm ls)"
nvm deactivate || die 'nvm deactivate failed'
NVM_CURRENT="$(nvm current)"
[ "_$NVM_CURRENT" = '_none' ] || [ "_$NVM_CURRENT" = '_system' ] || die "'nvm current' did not return 'none' or 'system', got '$NVM_CURRENT' `nvm ls`"
nvm unload || die 'nvm unload failed'
. ../../nvm.sh --no-use
EXIT_CODE="$(echo $?)"
echo 'sourcing complete.'
[ "_$EXIT_CODE" = "_0" ] || die "sourcing returned nonzero exit code: $EXIT_CODE"
NVM_CURRENT="$(nvm current)"
[ "_$NVM_CURRENT" = '_none' ] || [ "_$NVM_CURRENT" = '_system' ] || die "'nvm current' did not return 'none' or 'system', got '$NVM_CURRENT' `nvm ls`"