Compare commits

..

35 Commits

Author SHA1 Message Date
Jordan Harband
2176894a5b v0.31.0 2016-02-15 09:18:15 -08:00
Jordan Harband
cf7d5d8042 Merge pull request #1011 from dohse/keep-parameters
[Fix] Do not modify args of sourcing script when parsing `--install`/`--no-use` arg

Fixes #976.
2016-02-15 09:17:24 -08:00
Jonas Dohse
7135873f80 Do not modify parameters of sourcing script in zsh
When sourcing a script without parameters in zsh the sourced scripts
gets the same parameters as the sourcing file and is able to modify
these parameters. Prevent nvm from removing all parameters of sourcing
script by processing a copy of the parameters in a function.
2016-02-15 17:49:46 +01:00
Jordan Harband
dc9020b133 Merge pull request #1004 from tlevine/env-bash
[Fix] use env bash rather than /bin/bash
2016-02-14 12:05:10 -08:00
Thomas Levine
0eaa7e0bde use env bash in nvm-exec and install.sh 2016-02-14 19:34:19 +00:00
Thomas Levine
06b81f0f36 use env bash rather than /bin/bash
My bash is not installed in /bin/bash.
2016-02-14 19:34:19 +00:00
gmisra
8a20234586 Document how to reload nvm after upgrading 2016-02-09 19:12:22 -08:00
Jordan Harband
44541b416f [New] After installing, ensure that the default is set. 2016-02-04 00:26:33 -08:00
Jordan Harband
731c2f3f70 Add nvm_get_minor_version 2016-02-04 11:16:09 -08:00
Jordan Harband
de64a2d95f [Fix] nvm_format_version should only return 3 version groups 2016-02-06 22:34:49 -08:00
Jordan Harband
77e0449c89 [Fix] nvm-exec: properly exit when failing; improve error messages, suppress nvm use --help output
Fixes #997.
2016-02-04 11:19:34 -08:00
Sébastien Larivière
649e416017 [Refactor]Double quote to prevent globbing and word splitting. 2016-01-30 22:17:15 -05:00
Jordan Harband
754a0d7c5b Merge pull request #981 from woodb/node-v4-checksums
[New] Added support for sha256 checksums on `io.js` / merged `node`.

Fixes #664, relates to #736 and #687.
2016-01-24 10:40:06 -08:00
Brandon Wood
f73bfb6578 Updated warning message when sha256sum utility not found
Relates to @ljharb's comment on the warning message not including all of the
utilties searched for.

https://github.com/creationix/nvm/pull/981#discussion_r50638351
2016-01-24 11:53:19 -06:00
Brandon Wood
f1bca106a8 Added (optional) support for sha256 checksum utils
This commit adds (optional) support for additional sha256 checksum utilities
for newer versions of node.js and io.js that use sha256 checksums rather than
sha1.

If nothing is found to do a sha256 checksum on the client machine, a warning is
printed and things continue on as normal.

Following comments from @ljharb on incorporating some of @DomT4's PR
creationix/nvm#664, and making this checksum optional.  If I could I would
gladly include this as an addon to the now closed PR creationix/nvm#664. I am
choosing not to file it onto that PR because it's closed and (currently)
significantly behind the master branch.

@DomT4 did the hard work of actually finding all the different ways in which
one could verify a sha256 checksum, I've just included those here in an effort
to move forward with sha256 checksum support.
2016-01-24 10:31:26 -06:00
Brandon Wood
560c8c9500 Added support for sha256 checksums 2016-01-23 21:25:03 -06:00
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
15 changed files with 412 additions and 185 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.31.0/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.31.0/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,16 @@ 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`
After upgrading, don't forget to activate the new version:
. "$NVM_DIR/nvm.sh"
## 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 +264,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.31.0/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

@@ -1,4 +1,4 @@
#!/bin/bash #!/usr/bin/env bash
{ # this ensures the entire script is downloaded # { # this ensures the entire script is downloaded #
@@ -11,7 +11,7 @@ if [ -z "$NVM_DIR" ]; then
fi fi
nvm_latest_version() { nvm_latest_version() {
echo "v0.30.0" echo "v0.31.0"
} }
# #
@@ -69,7 +69,7 @@ install_nvm_from_git() {
mkdir -p "$NVM_DIR" mkdir -p "$NVM_DIR"
command git clone "$(nvm_source git)" "$NVM_DIR" command git clone "$(nvm_source git)" "$NVM_DIR"
fi fi
cd "$NVM_DIR" && command git checkout --quiet $(nvm_latest_version) cd "$NVM_DIR" && command git checkout --quiet "$(nvm_latest_version)"
if [ ! -z "$(cd "$NVM_DIR" && git show-ref refs/heads/master)" ]; then if [ ! -z "$(cd "$NVM_DIR" && git show-ref refs/heads/master)" ]; then
if git branch --quiet 2>/dev/null; then if git branch --quiet 2>/dev/null; then
cd "$NVM_DIR" && command git branch --quiet -D master >/dev/null 2>&1 cd "$NVM_DIR" && command git branch --quiet -D master >/dev/null 2>&1
@@ -115,26 +115,28 @@ 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=''
local SHELLTYPE local SHELLTYPE
SHELLTYPE="$(basename /$SHELL)" SHELLTYPE="$(basename "/$SHELL")"
if [ $SHELLTYPE = "bash" ]; then if [ "$SHELLTYPE" = "bash" ]; then
if [ -f "$HOME/.bashrc" ]; then if [ -f "$HOME/.bashrc" ]; then
DETECTED_PROFILE="$HOME/.bashrc" DETECTED_PROFILE="$HOME/.bashrc"
elif [ -f "$HOME/.bash_profile" ]; then elif [ -f "$HOME/.bash_profile" ]; then
DETECTED_PROFILE="$HOME/.bash_profile" DETECTED_PROFILE="$HOME/.bash_profile"
fi fi
elif [ $SHELLTYPE = "zsh" ]; then elif [ "$SHELLTYPE" = "zsh" ]; then
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

@@ -1,13 +1,14 @@
#!/bin/bash #!/usr/bin/env bash
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 || exit 127
else elif ! nvm use >/dev/null 2>&1; then
nvm use > /dev/null || (echo "No .nvmrc file found" >&2 && exit 127) echo "No NODE_VERSION provided; no .nvmrc file found" >&2
exit 127
fi fi
exec "$@" exec "$@"

275
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
@@ -336,10 +339,12 @@ nvm_ensure_version_prefix() {
nvm_format_version() { nvm_format_version() {
local VERSION local VERSION
VERSION="$(nvm_ensure_version_prefix "$1")" VERSION="$(nvm_ensure_version_prefix "$1")"
if [ "_$(nvm_num_version_groups "$VERSION")" != "_3" ]; then local NUM_GROUPS
NUM_GROUPS="$(nvm_num_version_groups "$VERSION")"
if [ $NUM_GROUPS -lt 3 ]; then
nvm_format_version "${VERSION%.}.0" nvm_format_version "${VERSION%.}.0"
else else
echo "$VERSION" echo "$VERSION" | cut -f1-3 -d.
fi fi
} }
@@ -529,7 +534,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 +664,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 +705,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='' ;;
@@ -755,15 +761,37 @@ nvm_ls_remote_index_tab() {
nvm_checksum() { nvm_checksum() {
local NVM_CHECKSUM local NVM_CHECKSUM
if nvm_has "sha1sum" && ! nvm_is_alias "sha1sum"; then if [ -z "$3" ] || [ "$3" == "sha1" ]; then
NVM_CHECKSUM="$(command sha1sum "$1" | command awk '{print $1}')" if nvm_has "sha1sum" && ! nvm_is_alias "sha1sum"; then
elif nvm_has "sha1" && ! nvm_is_alias "sha1"; then NVM_CHECKSUM="$(command sha1sum "$1" | command awk '{print $1}')"
NVM_CHECKSUM="$(command sha1 -q "$1")" elif nvm_has "sha1" && ! nvm_is_alias "sha1"; then
elif nvm_has "shasum" && ! nvm_is_alias "shasum"; then NVM_CHECKSUM="$(command sha1 -q "$1")"
NVM_CHECKSUM="$(shasum "$1" | command awk '{print $1}')" elif nvm_has "shasum" && ! nvm_is_alias "shasum"; then
NVM_CHECKSUM="$(shasum "$1" | command awk '{print $1}')"
else
echo "Unaliased sha1sum, sha1, or shasum not found." >&2
return 2
fi
else else
echo "Unaliased sha1sum, sha1, or shasum not found." >&2 if nvm_has "sha256sum" && ! nvm_is_alias "sha256sum"; then
return 2 NVM_CHECKSUM="$(sha256sum "$1" | awk '{print $1}')"
elif nvm_has "shasum" && ! nvm_is_alias "shasum"; then
NVM_CHECKSUM="$(shasum -a 256 "$1" | awk '{print $1}')"
elif nvm_has "sha256" && ! nvm_is_alias "sha256"; then
NVM_CHECKSUM="$(sha256 -q "$1" | awk '{print $1}')"
elif nvm_has "gsha256sum" && ! nvm_is_alias "gsha256sum"; then
NVM_CHECKSUM="$(gsha256sum "$1" | awk '{print $1}')"
elif nvm_has "openssl" && ! nvm_is_alias "openssl"; then
NVM_CHECKSUM="$(openssl dgst -sha256 "$1" | rev | awk '{print $1}' | rev)"
elif nvm_has "libressl" && ! nvm_is_alias "libressl"; then
NVM_CHECKSUM="$(libressl dgst -sha256 "$1" | rev | awk '{print $1}' | rev)"
elif nvm_has "bssl" && ! nvm_is_alias "bssl"; then
NVM_CHECKSUM="$(bssl sha256sum "$1" | awk '{print $1}')"
else
echo "Unaliased sha256sum, shasum, sha256, gsha256sum, openssl, libressl, or bssl not found." >&2
echo "WARNING: Continuing *without checksum verification*" >&2
return
fi
fi fi
if [ "_$NVM_CHECKSUM" = "_$2" ]; then if [ "_$NVM_CHECKSUM" = "_$2" ]; then
@@ -835,7 +863,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
@@ -967,6 +995,34 @@ nvm_get_arch() {
echo "$NVM_ARCH" echo "$NVM_ARCH"
} }
nvm_get_minor_version() {
local VERSION
VERSION="$1"
if [ -z "$VERSION" ]; then
echo 'a version is required' >&2
return 1
fi
case "$VERSION" in
v | .* | *..* | v*[!.0123456789]* | [!v]*[!.0123456789]* | [!v0123456789]* | v[!0123456789]*)
echo 'invalid version number' >&2
return 2
;;
esac
local PREFIXED_VERSION
PREFIXED_VERSION="$(nvm_format_version "$VERSION")"
local MINOR
MINOR="$(echo "$PREFIXED_VERSION" | command grep -e '^v' | command cut -c2- | command cut -d . -f 1,2)"
if [ -z "$MINOR" ]; then
echo 'invalid version number! (please report this)' >&2
return 3
fi
echo "$MINOR"
}
nvm_ensure_default_set() { nvm_ensure_default_set() {
local VERSION local VERSION
VERSION="$1" VERSION="$1"
@@ -1047,8 +1103,7 @@ nvm_install_merged_node_binary() {
fi fi
if ( if (
[ "$NVM_INSTALL_ERRORED" != true ] && \ [ "$NVM_INSTALL_ERRORED" != true ] && \
echo "WARNING: checksums are currently disabled for node.js v4.0 and later" >&2 && \ nvm_checksum "$tmptarball" "$sum" "sha256" && \
# nvm_checksum "$tmptarball" "$sum" && \
command tar -x${tar_compression_flag}f "$tmptarball" -C "$tmpdir" --strip-components 1 && \ command tar -x${tar_compression_flag}f "$tmptarball" -C "$tmpdir" --strip-components 1 && \
command rm -f "$tmptarball" && \ command rm -f "$tmptarball" && \
command mkdir -p "$VERSION_PATH" && \ command mkdir -p "$VERSION_PATH" && \
@@ -1122,8 +1177,7 @@ nvm_install_iojs_binary() {
fi fi
if ( if (
[ "$NVM_INSTALL_ERRORED" != true ] && \ [ "$NVM_INSTALL_ERRORED" != true ] && \
echo "WARNING: checksums are currently disabled for io.js" >&2 && \ nvm_checksum "$tmptarball" "$sum" "sha256" && \
# nvm_checksum "$tmptarball" "$sum" && \
command tar -x${tar_compression_flag}f "$tmptarball" -C "$tmpdir" --strip-components 1 && \ command tar -x${tar_compression_flag}f "$tmptarball" -C "$tmpdir" --strip-components 1 && \
command rm -f "$tmptarball" && \ command rm -f "$tmptarball" && \
command mkdir -p "$VERSION_PATH" && \ command mkdir -p "$VERSION_PATH" && \
@@ -1146,7 +1200,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 +1254,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 +1323,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 +1344,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 +1425,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 +1600,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 +1647,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 +1657,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
;; ;;
*) *)
@@ -1666,6 +1730,7 @@ nvm() {
if nvm use "$VERSION" && [ ! -z "$REINSTALL_PACKAGES_FROM" ] && [ "_$REINSTALL_PACKAGES_FROM" != "_N/A" ]; then if nvm use "$VERSION" && [ ! -z "$REINSTALL_PACKAGES_FROM" ] && [ "_$REINSTALL_PACKAGES_FROM" != "_N/A" ]; then
nvm reinstall-packages "$REINSTALL_PACKAGES_FROM" nvm reinstall-packages "$REINSTALL_PACKAGES_FROM"
fi fi
nvm_ensure_default_set "$provided_version"
return $? return $?
fi fi
@@ -1692,22 +1757,26 @@ 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
fi fi
if [ "$NVM_INSTALL_SUCCESS" = true ] && nvm use "$VERSION"; then if [ "$NVM_INSTALL_SUCCESS" = true ] && nvm use "$VERSION"; then
nvm_ensure_default_set "$provided_version"
if [ ! -z "$REINSTALL_PACKAGES_FROM" ] \ if [ ! -z "$REINSTALL_PACKAGES_FROM" ] \
&& [ "_$REINSTALL_PACKAGES_FROM" != "_N/A" ]; then && [ "_$REINSTALL_PACKAGES_FROM" != "_N/A" ]; then
nvm reinstall-packages "$REINSTALL_PACKAGES_FROM" nvm reinstall-packages "$REINSTALL_PACKAGES_FROM"
@@ -1784,18 +1853,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 +1961,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 +2120,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 +2130,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 +2235,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 +2265,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 +2352,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.31.0"
;; ;;
"unload" ) "unload" )
unset -f nvm nvm_print_versions nvm_checksum \ unset -f nvm nvm_print_versions nvm_checksum \
@@ -2304,7 +2377,8 @@ $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 \
nvm_process_parameters > /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 +2396,46 @@ 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_process_parameters() {
nvm use --silent >/dev/null local NVM_AUTO_MODE
fi NVM_AUTO_MODE='use'
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
nvm_auto "$NVM_AUTO_MODE"
}
nvm_process_parameters "$@"
} # 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.31.0",
"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,4 +1,4 @@
#!/bin/bash #!/usr/bin/env bash
export NVM_SYMLINK_CURRENT=true export NVM_SYMLINK_CURRENT=true
. ../../nvm.sh . ../../nvm.sh

View File

@@ -1,4 +1,4 @@
#!/bin/bash #!/usr/bin/env bash
. ../../nvm.sh . ../../nvm.sh

View File

@@ -0,0 +1,5 @@
#!/bin/sh
set -- yes
. ../../nvm.sh
[ "$1" = yes ]

View File

@@ -4,11 +4,18 @@ die () { echo $@ ; exit 1; }
. ../../../nvm.sh . ../../../nvm.sh
OUTPUT="$(nvm_format_version 0.1.2)" INPUT="0.1.2"
OUTPUT="$(nvm_format_version "$INPUT")"
EXPECTED_OUTPUT="v0.1.2" EXPECTED_OUTPUT="v0.1.2"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_format_version 0.1.2 did not return $EXPECTED_OUTPUT; got $OUTPUT" [ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_format_version $INPUT did not return $EXPECTED_OUTPUT; got $OUTPUT"
OUTPUT="$(nvm_format_version 0.1)" INPUT="0.1"
OUTPUT="$(nvm_format_version "$INPUT")"
EXPECTED_OUTPUT="v0.1.0" EXPECTED_OUTPUT="v0.1.0"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_format_version 0.1.0 did not return $EXPECTED_OUTPUT; got $OUTPUT" [ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_format_version $INPUT did not return $EXPECTED_OUTPUT; got $OUTPUT"
INPUT="1.2.3.4.5"
OUTPUT="$(nvm_format_version "$INPUT")"
EXPECTED_OUTPUT="v1.2.3"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_format_version $INPUT did not return $EXPECTED_OUTPUT; got $OUTPUT"

View File

@@ -0,0 +1,45 @@
#!/bin/sh
die () { echo $@ ; exit 1; }
. ../../../nvm.sh
expect () {
INPUT="$1"
EXPECTED_OUTPUT="$2"
OUTPUT="$(nvm_get_minor_version "$INPUT")"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_get_minor_version $INPUT did not return $EXPECTED_OUTPUT; got $OUTPUT"
V_OUTPUT="$(nvm_get_minor_version "v$INPUT")"
[ "_$V_OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_get_minor_version v$INPUT did not return $EXPECTED_OUTPUT; got $V_OUTPUT"
}
fail_with () {
INPUT="$1"
EXPECTED_CODE="$2"
EXIT_CODE="$(nvm_get_minor_version "$INPUT" >/dev/null 2>&1; echo $?)"
[ "_$EXIT_CODE" = "_$EXPECTED_CODE" ] || die "nvm_get_minor_version "$INPUT" did not fail with code "$EXPECTED_CODE"; got $EXIT_CODE"
}
expect 1 1.0
expect 1. 1.0
expect 1.2 1.2
expect 1.2. 1.2
expect 1.2.3 1.2
expect 1.2.3. 1.2
expect 1.2.3.4 1.2
fail_with '' 1
fail_with '.' 2
fail_with '..' 2
fail_with v 2
fail_with .a 2
fail_with .1 2
fail_with v.1 2
fail_with a.b 2
fail_with 1.a 2
fail_with a.1 2
fail_with v1.a 2
fail_with va.1 2

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

@@ -4,6 +4,8 @@ die () { echo $@ ; exit 1; }
. ../../../nvm.sh . ../../../nvm.sh
nvm unalias default || die 'unable to unalias default'
NVM_TEST_VERSION=v0.10.7 NVM_TEST_VERSION=v0.10.7
# Remove the stuff we're clobbering. # Remove the stuff we're clobbering.
@@ -16,3 +18,6 @@ nvm install $NVM_TEST_VERSION || die "install $NVM_TEST_VERSION failed"
[ -d ../../../$NVM_TEST_VERSION ] [ -d ../../../$NVM_TEST_VERSION ]
nvm run $NVM_TEST_VERSION --version | grep $NVM_TEST_VERSION || die "'nvm run $NVM_TEST_VERSION --version | grep $NVM_TEST_VERSION' failed" nvm run $NVM_TEST_VERSION --version | grep $NVM_TEST_VERSION || die "'nvm run $NVM_TEST_VERSION --version | grep $NVM_TEST_VERSION' failed"
# ensure default is set
NVM_CURRENT_DEFAULT="$(nvm_alias default)"
[ "$NVM_CURRENT_DEFAULT" = "$NVM_TEST_VERSION" ] || die "wrong default alias: $(nvm alias)"

View File

@@ -4,6 +4,8 @@ die () { echo $@ ; exit 1; }
. ../../../nvm.sh . ../../../nvm.sh
nvm unalias default || die 'unable to unalias default'
NVM_TEST_VERSION=v0.10.7 NVM_TEST_VERSION=v0.10.7
# Remove the stuff we're clobbering. # Remove the stuff we're clobbering.
@@ -16,3 +18,6 @@ nvm install -s $NVM_TEST_VERSION || die "'nvm install -s $NVM_TEST_VERSION' fail
[ -d ../../../$NVM_TEST_VERSION ] [ -d ../../../$NVM_TEST_VERSION ]
nvm run $NVM_TEST_VERSION --version | grep $NVM_TEST_VERSION || "'nvm run $NVM_TEST_VERSION --version | grep $NVM_TEST_VERSION' failed" nvm run $NVM_TEST_VERSION --version | grep $NVM_TEST_VERSION || "'nvm run $NVM_TEST_VERSION --version | grep $NVM_TEST_VERSION' failed"
# ensure default is set
NVM_CURRENT_DEFAULT="$(nvm_alias default)"
[ "$NVM_CURRENT_DEFAULT" = "$NVM_TEST_VERSION" ] || die "wrong default alias: $(nvm alias)"

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`"

View File

@@ -1,6 +1,7 @@
#!/bin/sh #!/bin/sh
mkdir -p ../../alias mkdir -p ../../alias
rm -rf ../../alias/default
rm -f ../../.nvmrc rm -f ../../.nvmrc
rm -rf ../../v0.10.7 rm -rf ../../v0.10.7
rm -rf ../../v0.9.7 rm -rf ../../v0.9.7
@@ -8,5 +9,6 @@ rm -rf ../../v0.9.12
. ../../nvm.sh . ../../nvm.sh
nvm install 0.10.1 || echo >&2 'nvm install 0.10.1 failed' nvm install 0.10.1 || echo >&2 'nvm install 0.10.1 failed'
nvm unalias default || 'removing default alias failed'
nvm unload || echo >&2 'nvm unload failed' nvm unload || echo >&2 'nvm unload failed'