Compare commits

...

36 Commits

Author SHA1 Message Date
Jordan Harband
96c96ec714 v0.25.2 2015-05-19 14:05:43 -07:00
Jordan Harband
475b8bd6b4 Update semver 2015-05-17 21:12:03 -07:00
Jordan Harband
5e805905ca Add undocumented nvm debug to print out helpful debugging info. 2015-05-14 14:56:26 -07:00
Jordan Harband
2dec01da9c nvm reinstall-packages: On systems where npm ls -g --depth=0 does not include npm for some reason, make sure to filter out (empty). 2015-05-08 14:24:51 -07:00
Jordan Harband
63672641a5 Add wrapping curly braces to ensure that the entire scripts are downloaded.
If the closing curly brace isn't present, the script will error out.
2015-05-11 01:46:18 -07:00
Jordan Harband
94bba31de3 Make sure that nvm reinstall-packages system has the right std output. 2015-05-08 14:15:42 -07:00
Jordan Harband
f70530ef18 Fix installation instructions. 2015-05-07 10:43:47 -07:00
Jordan Harband
ec33e8b720 v0.25.1 2015-05-03 15:31:54 -07:00
Jordan Harband
a4f89c6223 Make sure to ignore ~/.curlrc if it exists. 2015-05-01 02:00:49 -07:00
Jordan Harband
517817f1a3 Actually try to install from source when the error message says "binary failed, trying source". 2015-04-27 14:02:45 -07:00
Jordan Harband
a6f5eff0f3 Use uname -m instead of uname -a.
Fixes #744.
2015-04-28 22:56:43 -07:00
Jordan Harband
0aac462b15 Improve the error message when the binary tarball URL 404s.
Fixes #743
2015-04-27 13:48:22 -07:00
Jordan Harband
bb2fe618cb The install script only runs in bash. 2015-04-27 16:55:21 -07:00
Jordan Harband
eb5cecc970 v0.25.0 2015-04-26 12:58:05 -07:00
Jordan Harband
36f933984d Remove trailing whitespace. 2015-04-25 11:21:33 -07:00
Jordan Harband
54d2d70048 Merge pull request #742 from sjasperse/bugfix/rasp-pi-2-arch-detect
adding architecture detection for Raspberry Pi 2
2015-04-26 00:04:00 -07:00
Scott Jasperse
e1009149c9 adding architecture detection for Raspberry Pi 2 2015-04-25 19:10:02 -04:00
Jordan Harband
153ee6887e Merge pull request #741 from phillipsj/master
Adding .gitattributes to force unix line endings.

Fixes #728
2015-04-25 10:58:52 -07:00
Jamie Phillips
295f2b7db4 Adding .gitattributes to force unix line endings.
Hopefully this helps with issue #728
2015-04-25 10:35:22 -04:00
Jordan Harband
356ac7a697 install.sh: Ensure that the --quiet option is available before trying to use it.
Fixes #738, #657.
2015-04-22 00:40:27 -07:00
Jordan Harband
64c88ce62e Merge pull request #735 from madarche/fix-doc
Remove source bashism
2015-04-19 10:32:48 -07:00
Marc-Aurèle DARCHE
4612d8d827 Remove source bashism
Using `.` and not `source`, since it's more portable

cf. #704 and https://wiki.ubuntu.com/DashAsBinSh#source
2015-04-19 16:25:34 +02:00
Jordan Harband
6644f33a77 Update semver, use ^ instead of ~ 2015-04-17 00:24:44 -07:00
Jordan Harband
cbf0f12aac Create nvm_print_npm_version and use that when printing the npm version. 2015-04-12 10:59:17 -07:00
Jordan Harband
de93dc46d0 Merge pull request #726 from SeeThruHead/master
README: Add note about `~/.npmrc` compatibility issues.

Relates to #606.
2015-04-13 13:58:53 -07:00
Shane Keulen
7ea15a7618 Added compatibility issues section
Sections includes warnings for cretain nonstandard path settings and environment variables that conflict with nvm.
2015-04-13 16:54:20 -04:00
Jordan Harband
6a114eddcc Merge pull request #722 from ajcrites/list-npm-version
Include npm version when displaying results of switch.
2015-04-12 10:53:37 -07:00
Andrew Crites
e4149c380b Only print npm version if it exists 2015-04-09 02:31:57 -04:00
Andrew Crites
caa69bc500 npm version: shell compatibility, test update
* Update test string that checks printed node version to pass with additional npm version display
* Remove echo -n for compatibility with shells that do not support it
2015-04-09 02:12:35 -04:00
Andrew Crites
e01bcb740b Include npm version when displaying results of switch.
When running nvm use, successful changing of versions lists the new node version.  The npm version may also be switched, but this is not listed.

This commit updates nvm to display the npm version that was switched to alongside the node version
2015-04-09 01:20:51 -04:00
Jordan Harband
276d55c912 Merge pull request #718 from joliss/performance
Consolidate and avoid sed/cut calls, clean up pattern matches
2015-04-06 21:06:46 -07:00
Jo Liss
0dc177bf9c Consolidate and avoid sed/cut calls, clean up pattern matches
Some patterns contained a no-op `*`; the `*` would match the empty string
because # or % replacement (unlike ## or %%) tries to find the shortest match.
2015-04-06 20:30:38 +00:00
Jordan Harband
c34502ebc2 nvm_num_version_groups should report 0 when given just a v or a . 2015-04-06 11:10:43 -07:00
Jordan Harband
3d764e6833 Add nvm_ensure_default_set 2015-04-05 16:49:29 -07:00
Jordan Harband
a26ef4f1be Consolidate reinstall-packages-from logic to one place nvm install 2015-04-05 16:09:47 -07:00
Jordan Harband
d68f667464 When no arguments are passed to nvm run X, use nvm exec to open a REPL.
Fixes #625. Tests will be in #717.
2015-04-05 15:13:35 -07:00
15 changed files with 217 additions and 71 deletions

1
.gitattributes vendored Normal file
View File

@@ -0,0 +1 @@
*.sh eol=lf

View File

@@ -10,11 +10,7 @@ install:
script: script:
- NVM_DIR=$TRAVIS_BUILD_DIR make TEST_SUITE=$TEST_SUITE URCHIN=/tmp/urchin/package/urchin test-$SHELL - NVM_DIR=$TRAVIS_BUILD_DIR make TEST_SUITE=$TEST_SUITE URCHIN=/tmp/urchin/package/urchin test-$SHELL
env: env:
- SHELL=sh TEST_SUITE=install_script
- SHELL=dash TEST_SUITE=install_script
- SHELL=bash TEST_SUITE=install_script - SHELL=bash TEST_SUITE=install_script
- SHELL=zsh TEST_SUITE=install_script
# - SHELL=ksh TEST_SUITE=install_script
- SHELL=sh TEST_SUITE=fast - SHELL=sh TEST_SUITE=fast
- SHELL=dash TEST_SUITE=fast - SHELL=dash TEST_SUITE=fast
- SHELL=bash TEST_SUITE=fast - SHELL=bash TEST_SUITE=fast

View File

@@ -16,11 +16,11 @@ Note: `nvm` does not support [Fish] either (see [#303](https://github.com/creati
To install you could use the [install script][2] using cURL: To install you could use the [install script][2] using cURL:
curl https://raw.githubusercontent.com/creationix/nvm/v0.24.1/install.sh | bash curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.25.2/install.sh | bash
or Wget: or Wget:
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.24.1/install.sh | bash wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.25.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>
@@ -39,7 +39,7 @@ Or if you have `git` installed, then just clone it, and check out the latest ver
To activate nvm, you need to source it from your shell: To activate nvm, you need to source it from your shell:
source ~/.nvm/nvm.sh . ~/.nvm/nvm.sh
I always add this line to my `~/.bashrc`, `~/.profile`, or `~/.zshrc` file to have it automatically sourced upon login. I always add this line to my `~/.bashrc`, `~/.profile`, or `~/.zshrc` file to have it automatically sourced upon login.
Often I also put in a line to use a specific version of node. Often I also put in a line to use a specific version of node.
@@ -187,6 +187,20 @@ nvm uninstall
$ nvm uninstall [tab][tab] $ nvm uninstall [tab][tab]
my_alias default v0.6.21 v0.8.26 v0.10.28 my_alias default v0.6.21 v0.8.26 v0.10.28
## Compatibility Issues
`nvm` will encounter some issues if you have some non-default settings set. (see [#606](/../../issues/606))
The following are known to cause issues:
Inside `~/.npmrc`
```
prefix='some/path'
```
Environment Variables:
```
$NPM_CONFIG_PREFIX
$PREFIX
```
## Problems ## Problems
If you try to install a node version and the installation fails, be sure to delete the node downloads from src (~/.nvm/src/) or you might get an error when trying to reinstall them again or you might get an error like the following: If you try to install a node version and the installation fails, be sure to delete the node downloads from src (~/.nvm/src/) or you might get an error when trying to reinstall them again or you might get an error like the following:
@@ -206,7 +220,7 @@ After the v0.8.6 release of node, nvm tries to install from binary packages. But
nvm install -s 0.8.6 nvm install -s 0.8.6
[1]: https://github.com/creationix/nvm.git [1]: https://github.com/creationix/nvm.git
[2]: https://github.com/creationix/nvm/blob/v0.24.1/install.sh [2]: https://github.com/creationix/nvm/blob/v0.25.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

@@ -2,6 +2,8 @@
set -e set -e
{ # this ensures the entire script is downloaded #
nvm_has() { nvm_has() {
type "$1" > /dev/null 2>&1 type "$1" > /dev/null 2>&1
} }
@@ -11,7 +13,7 @@ if [ -z "$NVM_DIR" ]; then
fi fi
nvm_latest_version() { nvm_latest_version() {
echo "v0.24.1" echo "v0.25.2"
} }
# #
@@ -42,7 +44,7 @@ nvm_source() {
nvm_download() { nvm_download() {
if nvm_has "curl"; then if nvm_has "curl"; then
curl $* curl -q $*
elif nvm_has "wget"; then elif nvm_has "wget"; then
# Emulate curl with wget # Emulate curl with wget
ARGS=$(echo "$*" | command sed -e 's/--progress-bar /--progress=bar /' \ ARGS=$(echo "$*" | command sed -e 's/--progress-bar /--progress=bar /' \
@@ -71,7 +73,12 @@ install_nvm_from_git() {
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
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
else
echo >&2 "Your version of git is out of date. Please update it!"
cd "$NVM_DIR" && command git branch -D master >/dev/null 2>&1
fi
fi fi
return return
} }
@@ -236,3 +243,5 @@ nvm_reset() {
} }
[ "_$NVM_ENV" = "_testing" ] || nvm_do_install [ "_$NVM_ENV" = "_testing" ] || nvm_do_install
} # this ensures the entire script is downloaded #

View File

@@ -11,4 +11,3 @@ else
fi fi
exec $@ exec $@

155
nvm.sh
View File

@@ -6,6 +6,8 @@
# Implemented by Tim Caswell <tim@creationix.com> # Implemented by Tim Caswell <tim@creationix.com>
# with much bash help from Matthew Ranney # with much bash help from Matthew Ranney
{ # this ensures the entire script is downloaded #
NVM_SCRIPT_SOURCE="$_" NVM_SCRIPT_SOURCE="$_"
nvm_has() { nvm_has() {
@@ -20,7 +22,7 @@ nvm_is_alias() {
nvm_get_latest() { nvm_get_latest() {
local NVM_LATEST_URL local NVM_LATEST_URL
if nvm_has "curl"; then if nvm_has "curl"; then
NVM_LATEST_URL="$(curl -w "%{url_effective}\n" -L -s -S http://latest.nvm.sh -o /dev/null)" NVM_LATEST_URL="$(curl -q -w "%{url_effective}\n" -L -s -S http://latest.nvm.sh -o /dev/null)"
elif nvm_has "wget"; then elif nvm_has "wget"; then
NVM_LATEST_URL="$(wget http://latest.nvm.sh --server-response -O /dev/null 2>&1 | awk '/^ Location: /{DEST=$2} END{ print DEST }')" NVM_LATEST_URL="$(wget http://latest.nvm.sh --server-response -O /dev/null 2>&1 | awk '/^ Location: /{DEST=$2} END{ print DEST }')"
else else
@@ -37,7 +39,7 @@ nvm_get_latest() {
nvm_download() { nvm_download() {
if nvm_has "curl"; then if nvm_has "curl"; then
curl $* curl -q $*
elif nvm_has "wget"; then elif nvm_has "wget"; then
# Emulate curl with wget # Emulate curl with wget
ARGS=$(echo "$*" | command sed -e 's/--progress-bar /--progress=bar /' \ ARGS=$(echo "$*" | command sed -e 's/--progress-bar /--progress=bar /' \
@@ -58,6 +60,12 @@ nvm_has_system_iojs() {
[ "$(nvm deactivate >/dev/null 2>&1 && command -v iojs)" != '' ] [ "$(nvm deactivate >/dev/null 2>&1 && command -v iojs)" != '' ]
} }
nvm_print_npm_version() {
if nvm_has "npm"; then
npm --version 2>/dev/null | command xargs printf " (npm v%s)"
fi
}
# 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 nvm_has "unsetopt"; then if nvm_has "unsetopt"; then
@@ -307,7 +315,7 @@ nvm_is_valid_version() {
} }
nvm_normalize_version() { nvm_normalize_version() {
echo "${1#v*}" | command awk -F. '{ printf("%d%06d%06d\n", $1,$2,$3); }' echo "${1#v}" | command awk -F. '{ printf("%d%06d%06d\n", $1,$2,$3); }'
} }
nvm_ensure_version_prefix() { nvm_ensure_version_prefix() {
@@ -324,7 +332,7 @@ 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 if [ "_$(nvm_num_version_groups "$VERSION")" != "_3" ]; then
nvm_format_version "${VERSION%*\.}.0" nvm_format_version "${VERSION%.}.0"
else else
echo "$VERSION" echo "$VERSION"
fi fi
@@ -333,12 +341,12 @@ nvm_format_version() {
nvm_num_version_groups() { nvm_num_version_groups() {
local VERSION local VERSION
VERSION="$1" VERSION="$1"
VERSION="${VERSION#v}"
VERSION="${VERSION%.}"
if [ -z "$VERSION" ]; then if [ -z "$VERSION" ]; then
echo "0" echo "0"
return return
fi fi
VERSION="${VERSION#v*}"
VERSION="${VERSION%\.}"
local NVM_NUM_DOTS local NVM_NUM_DOTS
NVM_NUM_DOTS=$(echo "$VERSION" | command sed -e 's/[^\.]//g') NVM_NUM_DOTS=$(echo "$VERSION" | command sed -e 's/[^\.]//g')
local NVM_NUM_GROUPS local NVM_NUM_GROUPS
@@ -510,7 +518,7 @@ nvm_strip_iojs_prefix() {
if [ "_$1" = "_$NVM_IOJS_PREFIX" ]; then if [ "_$1" = "_$NVM_IOJS_PREFIX" ]; then
echo echo
else else
echo "${1#"$NVM_IOJS_PREFIX"-*}" echo "${1#"$NVM_IOJS_PREFIX"-}"
fi fi
} }
@@ -565,7 +573,7 @@ nvm_ls() {
local NUM_VERSION_GROUPS local NUM_VERSION_GROUPS
NUM_VERSION_GROUPS="$(nvm_num_version_groups "$PATTERN")" NUM_VERSION_GROUPS="$(nvm_num_version_groups "$PATTERN")"
if [ "_$NUM_VERSION_GROUPS" = "_2" ] || [ "_$NUM_VERSION_GROUPS" = "_1" ]; then if [ "_$NUM_VERSION_GROUPS" = "_2" ] || [ "_$NUM_VERSION_GROUPS" = "_1" ]; then
PATTERN="${PATTERN%*\.}." PATTERN="${PATTERN%.}."
fi fi
;; ;;
esac esac
@@ -681,9 +689,10 @@ nvm_ls_remote_iojs() {
PATTERN=".*" PATTERN=".*"
fi fi
VERSIONS="$(nvm_download -L -s $NVM_IOJS_ORG_VERSION_LISTING -o - \ VERSIONS="$(nvm_download -L -s $NVM_IOJS_ORG_VERSION_LISTING -o - \
| command sed 1d \ | command sed "
| command sed "s/^/$(nvm_iojs_prefix)-/" \ 1d;
| command cut -f1 \ s/^/$(nvm_iojs_prefix)-/;
s/[[:blank:]].*//" \
| command grep -w "$PATTERN" \ | command grep -w "$PATTERN" \
| command sort)" | command sort)"
if [ -z "$VERSIONS" ]; then if [ -z "$VERSIONS" ]; then
@@ -863,16 +872,35 @@ nvm_get_os() {
nvm_get_arch() { nvm_get_arch() {
local NVM_UNAME local NVM_UNAME
NVM_UNAME="$(uname -a)" NVM_UNAME="$(uname -m)"
local NVM_ARCH local NVM_ARCH
case "$NVM_UNAME" in case "$NVM_UNAME" in
*x86_64*) NVM_ARCH=x64 ;; x86_64) NVM_ARCH="x64" ;;
*i*86*) NVM_ARCH=x86 ;; i*86) NVM_ARCH="x86" ;;
*) NVM_ARCH="$(uname -m)" ;; *) NVM_ARCH="$NVM_UNAME" ;;
esac esac
echo "$NVM_ARCH" echo "$NVM_ARCH"
} }
nvm_ensure_default_set() {
local VERSION
VERSION="$1"
if [ -z "$VERSION" ]; then
echo 'nvm_ensure_default_set: a version is required' >&2
return 1
fi
if nvm_alias default >/dev/null 2>&1; then
# default already set
return 0
fi
local OUTPUT
OUTPUT="$(nvm alias default "$VERSION")"
local EXIT_CODE
EXIT_CODE="$?"
echo "Creating default alias: $OUTPUT"
return $EXIT_CODE
}
nvm_install_iojs_binary() { nvm_install_iojs_binary() {
local PREFIXED_VERSION local PREFIXED_VERSION
PREFIXED_VERSION="$1" PREFIXED_VERSION="$1"
@@ -903,9 +931,16 @@ nvm_install_iojs_binary() {
tmpdir="$NVM_DIR/bin/iojs-${t}" tmpdir="$NVM_DIR/bin/iojs-${t}"
local tmptarball local tmptarball
tmptarball="$tmpdir/iojs-${t}.tar.gz" tmptarball="$tmpdir/iojs-${t}.tar.gz"
if ( local NVM_INSTALL_ERRORED
command mkdir -p "$tmpdir" && \ command mkdir -p "$tmpdir" && \
nvm_download -L -C - --progress-bar $url -o "$tmptarball" && \ nvm_download -L -C - --progress-bar $url -o "$tmptarball" || \
NVM_INSTALL_ERRORED=true
if grep '404 Not Found' "$tmptarball" >/dev/null; then
NVM_INSTALL_ERRORED=true
echo >&2 "HTTP 404 at URL $url";
fi
if (
[ "$NVM_INSTALL_ERRORED" != true ] && \
echo "WARNING: checksums are currently disabled for io.js" >&2 && \ echo "WARNING: checksums are currently disabled for io.js" >&2 && \
# nvm_checksum "$tmptarball" $sum && \ # nvm_checksum "$tmptarball" $sum && \
command tar -xzf "$tmptarball" -C "$tmpdir" --strip-components 1 && \ command tar -xzf "$tmptarball" -C "$tmpdir" --strip-components 1 && \
@@ -915,7 +950,7 @@ nvm_install_iojs_binary() {
); then ); then
return 0 return 0
else else
echo "Binary download failed, trying source." >&2 echo >&2 "Binary download failed, trying source." >&2
command rm -rf "$tmptarball" "$tmpdir" command rm -rf "$tmptarball" "$tmpdir"
return 1 return 1
fi fi
@@ -947,7 +982,7 @@ nvm_install_node_binary() {
if nvm_binary_available "$VERSION"; then if nvm_binary_available "$VERSION"; then
local NVM_ARCH local NVM_ARCH
NVM_ARCH="$(nvm_get_arch)" NVM_ARCH="$(nvm_get_arch)"
if [ $NVM_ARCH = "armv6l" ]; then if [ $NVM_ARCH = "armv6l" ] || [ $NVM_ARCH = "armv7l" ]; then
NVM_ARCH="arm-pi" NVM_ARCH="arm-pi"
fi fi
t="$VERSION-$NVM_OS-$NVM_ARCH" t="$VERSION-$NVM_OS-$NVM_ARCH"
@@ -957,9 +992,16 @@ nvm_install_node_binary() {
tmpdir="$NVM_DIR/bin/node-${t}" tmpdir="$NVM_DIR/bin/node-${t}"
local tmptarball local tmptarball
tmptarball="$tmpdir/node-${t}.tar.gz" tmptarball="$tmpdir/node-${t}.tar.gz"
if ( local NVM_INSTALL_ERRORED
command mkdir -p "$tmpdir" && \ command mkdir -p "$tmpdir" && \
nvm_download -L -C - --progress-bar $url -o "$tmptarball" && \ nvm_download -L -C - --progress-bar $url -o "$tmptarball" || \
NVM_INSTALL_ERRORED=true
if grep '404 Not Found' "$tmptarball" >/dev/null; then
NVM_INSTALL_ERRORED=true
echo >&2 "HTTP 404 at URL $url";
fi
if (
[ "$NVM_INSTALL_ERRORED" != true ] && \
nvm_checksum "$tmptarball" $sum && \ nvm_checksum "$tmptarball" $sum && \
command tar -xzf "$tmptarball" -C "$tmpdir" --strip-components 1 && \ command tar -xzf "$tmptarball" -C "$tmpdir" --strip-components 1 && \
command rm -f "$tmptarball" && \ command rm -f "$tmptarball" && \
@@ -968,7 +1010,7 @@ nvm_install_node_binary() {
); then ); then
return 0 return 0
else else
echo "Binary download failed, trying source." >&2 echo >&2 "Binary download failed, trying source."
command rm -rf "$tmptarball" "$tmpdir" command rm -rf "$tmptarball" "$tmpdir"
return 1 return 1
fi fi
@@ -980,10 +1022,8 @@ nvm_install_node_binary() {
nvm_install_node_source() { nvm_install_node_source() {
local VERSION local VERSION
VERSION="$1" VERSION="$1"
local REINSTALL_PACKAGES_FROM
REINSTALL_PACKAGES_FROM="$2"
local ADDITIONAL_PARAMETERS local ADDITIONAL_PARAMETERS
ADDITIONAL_PARAMETERS="$3" ADDITIONAL_PARAMETERS="$2"
if [ -n "$ADDITIONAL_PARAMETERS" ]; then if [ -n "$ADDITIONAL_PARAMETERS" ]; then
echo "Additional options while compiling: $ADDITIONAL_PARAMETERS" echo "Additional options while compiling: $ADDITIONAL_PARAMETERS"
@@ -1029,9 +1069,6 @@ nvm_install_node_source() {
$make $MAKE_CXX install $make $MAKE_CXX install
) )
then then
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 if ! nvm_has "npm" ; then
echo "Installing npm..." echo "Installing npm..."
if nvm_version_greater 0.2.0 "$VERSION"; then if nvm_version_greater 0.2.0 "$VERSION"; then
@@ -1104,6 +1141,17 @@ nvm() {
echo echo
;; ;;
"debug" )
echo >&2 "\$SHELL: $SHELL"
echo >&2 "\$NVM_DIR: $(echo $NVM_DIR | sed "s#$HOME#\$HOME#g")"
for NVM_DEBUG_COMMAND in 'nvm current' 'which node' 'which iojs' 'which npm' 'npm config get prefix' 'npm root -g'
do
local NVM_DEBUG_OUTPUT="$($NVM_DEBUG_COMMAND | sed "s#$NVM_DIR#\$NVM_DIR#g")"
echo >&2 "$NVM_DEBUG_COMMAND: ${NVM_DEBUG_OUTPUT}"
done
return 42
;;
"install" | "i" ) "install" | "i" )
local nobinary local nobinary
local version_not_provided local version_not_provided
@@ -1204,31 +1252,32 @@ nvm() {
# io.js does not have a SunOS binary # io.js does not have a SunOS binary
nobinary=1 nobinary=1
fi fi
local NVM_INSTALL_SUCCESS
# skip binary install if "nobinary" option specified. # skip binary install if "nobinary" option specified.
if [ $nobinary -ne 1 ] && nvm_binary_available "$VERSION"; then if [ $nobinary -ne 1 ] && nvm_binary_available "$VERSION"; then
local NVM_INSTALL_SUCCESS
if [ "$NVM_IOJS" = true ] && nvm_install_iojs_binary "$VERSION" "$REINSTALL_PACKAGES_FROM"; then if [ "$NVM_IOJS" = true ] && nvm_install_iojs_binary "$VERSION" "$REINSTALL_PACKAGES_FROM"; then
NVM_INSTALL_SUCCESS=true NVM_INSTALL_SUCCESS=true
elif [ "$NVM_IOJS" != true ] && nvm_install_node_binary "$VERSION" "$REINSTALL_PACKAGES_FROM"; then elif [ "$NVM_IOJS" != true ] && nvm_install_node_binary "$VERSION" "$REINSTALL_PACKAGES_FROM"; then
NVM_INSTALL_SUCCESS=true NVM_INSTALL_SUCCESS=true
fi fi
fi
if [ "$NVM_INSTALL_SUCCESS" != true ]; then
if [ "$NVM_IOJS" = true ]; then
# nvm_install_iojs_source "$VERSION" "$ADDITIONAL_PARAMETERS"
echo "Installing iojs from source is not currently supported" >&2
return 105
elif nvm_install_node_source "$VERSION" "$ADDITIONAL_PARAMETERS"; then
NVM_INSTALL_SUCCESS=true
fi
fi
if [ "$NVM_INSTALL_SUCCESS" = true ] \ if [ "$NVM_INSTALL_SUCCESS" = true ] && nvm use "$VERSION"; then
&& nvm use "$VERSION" \ if [ ! -z "$REINSTALL_PACKAGES_FROM" ] \
&& [ ! -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"
fi fi
fi
return $? return $?
fi
if [ "$NVM_IOJS" = true ]; then
# nvm_install_iojs_source "$VERSION" "$REINSTALL_PACKAGES_FROM" "$ADDITIONAL_PARAMETERS"
echo "Installing iojs from source is not currently supported" >&2
return 105
else
nvm_install_node_source "$VERSION" "$REINSTALL_PACKAGES_FROM" "$ADDITIONAL_PARAMETERS"
fi
;; ;;
"uninstall" ) "uninstall" )
if [ $# -ne 2 ]; then if [ $# -ne 2 ]; then
@@ -1347,10 +1396,10 @@ nvm() {
if [ "_$VERSION" = '_system' ]; then if [ "_$VERSION" = '_system' ]; then
if nvm_has_system_node && nvm deactivate >/dev/null 2>&1; then if nvm_has_system_node && nvm deactivate >/dev/null 2>&1; then
echo "Now using system version of node: $(node -v 2>/dev/null)." echo "Now using system version of node: $(node -v 2>/dev/null)$(nvm_print_npm_version)"
return return
elif nvm_has_system_iojs && nvm deactivate >/dev/null 2>&1; then elif nvm_has_system_iojs && nvm deactivate >/dev/null 2>&1; then
echo "Now using system version of io.js: $(iojs --version 2>/dev/null)." echo "Now using system version of io.js: $(iojs --version 2>/dev/null)$(nvm_print_npm_version)"
return return
else else
echo "System version of node not found." >&2 echo "System version of node not found." >&2
@@ -1394,9 +1443,9 @@ nvm() {
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
if nvm_is_iojs_version "$VERSION"; then if nvm_is_iojs_version "$VERSION"; then
echo "Now using io.js $(nvm_strip_iojs_prefix "$VERSION")" echo "Now using io.js $(nvm_strip_iojs_prefix "$VERSION")$(nvm_print_npm_version)"
else else
echo "Now using node $VERSION" echo "Now using node $VERSION$(nvm_print_npm_version)"
fi fi
;; ;;
"run" ) "run" )
@@ -1451,6 +1500,13 @@ nvm() {
if [ "_$VERSION" = "_N/A" ]; then if [ "_$VERSION" = "_N/A" ]; then
echo "$(nvm_ensure_version_prefix "$provided_version") is not installed yet" >&2 echo "$(nvm_ensure_version_prefix "$provided_version") is not installed yet" >&2
EXIT_CODE=1 EXIT_CODE=1
elif [ -z "$ARGS" ]; then
if [ "$NVM_IOJS" = true ]; then
nvm exec "$VERSION" iojs
else
nvm exec "$VERSION" node
fi
EXIT_CODE="$?"
elif [ "$NVM_IOJS" = true ]; then elif [ "$NVM_IOJS" = true ]; then
echo "Running io.js $(nvm_strip_iojs_prefix "$VERSION")" echo "Running io.js $(nvm_strip_iojs_prefix "$VERSION")"
OUTPUT="$(nvm use "$VERSION" >/dev/null && iojs $ARGS)" OUTPUT="$(nvm use "$VERSION" >/dev/null && iojs $ARGS)"
@@ -1669,20 +1725,21 @@ $NVM_LS_REMOTE_IOJS_OUTPUT" | command grep -v "N/A" | sed '/^$/d')"
fi fi
local NPMLIST local NPMLIST
local VERSION
if [ "_$PROVIDED_VERSION" = "_system" ]; then if [ "_$PROVIDED_VERSION" = "_system" ]; then
if ! nvm_has_system_node && ! nvm_has_system_iojs; then if ! nvm_has_system_node && ! nvm_has_system_iojs; then
echo 'No system version of node or io.js detected.' >&2 echo 'No system version of node or io.js detected.' >&2
return 3 return 3
fi fi
VERSION="system"
NPMLIST=$(nvm deactivate > /dev/null && npm list -g --depth=0 | command tail -n +2) NPMLIST=$(nvm deactivate > /dev/null && npm list -g --depth=0 | command tail -n +2)
else else
local VERSION
VERSION="$(nvm_version "$PROVIDED_VERSION")" VERSION="$(nvm_version "$PROVIDED_VERSION")"
NPMLIST=$(nvm use "$VERSION" > /dev/null && npm list -g --depth=0 | command tail -n +2) NPMLIST=$(nvm use "$VERSION" > /dev/null && npm list -g --depth=0 | command tail -n +2)
fi fi
local INSTALLS local INSTALLS
INSTALLS=$(echo "$NPMLIST" | command sed -e '/ -> / d' -e 's/^.* \(.*\)@.*/\1/' -e '/^npm$/ d' | command xargs) INSTALLS=$(echo "$NPMLIST" | command sed -e '/ -> / d' -e '/\(empty\)/ d' -e 's/^.* \(.*\)@.*/\1/' -e '/^npm$/ d' | command xargs)
echo "Copying global packages from $VERSION..." echo "Copying global packages from $VERSION..."
echo "$INSTALLS" | command xargs npm install -g --quiet echo "$INSTALLS" | command xargs npm install -g --quiet
@@ -1703,7 +1760,7 @@ $NVM_LS_REMOTE_IOJS_OUTPUT" | command grep -v "N/A" | sed '/^$/d')"
nvm_version $2 nvm_version $2
;; ;;
"--version" ) "--version" )
echo "0.24.1" echo "0.25.2"
;; ;;
"unload" ) "unload" )
unset -f nvm nvm_print_versions nvm_checksum \ unset -f nvm nvm_print_versions nvm_checksum \
@@ -1739,3 +1796,5 @@ elif [ -n "$VERSION" ]; then
elif nvm_rc_version >/dev/null 2>&1; then elif nvm_rc_version >/dev/null 2>&1; then
nvm use >/dev/null nvm use >/dev/null
fi fi
} # this ensures the entire script is downloaded #

View File

@@ -1,6 +1,6 @@
{ {
"name": "nvm", "name": "nvm",
"version": "0.24.1", "version": "0.25.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"
@@ -30,8 +30,8 @@
}, },
"homepage": "https://github.com/creationix/nvm", "homepage": "https://github.com/creationix/nvm",
"devDependencies": { "devDependencies": {
"replace": "~0.3.0", "replace": "^0.3.0",
"semver": "~4.2.0", "semver": "^4.3.4",
"urchin": "~0.0.5" "urchin": "^0.0.5"
} }
} }

View File

@@ -0,0 +1,18 @@
#!/bin/sh
die () { echo $@ ; exit 1; }
. ../../../nvm.sh
nvm alias default 0.1 >/dev/null || die "'nvm alias default 0.1' failed"
nvm_ensure_default_set 0.3 || die "'nvm_ensure_default_set' with an existing default alias exits 0"
nvm unalias default || die "'nvm unalias default' failed"
OUTPUT="$(nvm_ensure_default_set 0.2)"
EXPECTED_OUTPUT="Creating default alias: default -> 0.2 (-> iojs-v0.2.10)"
EXIT_CODE="$?"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "'nvm_ensure_default_set 0.2' did not output '$EXPECTED_OUTPUT', got '$OUTPUT'"
[ "_$EXIT_CODE" = "_0" ] || die "'nvm_ensure_default_set 0.2' did not exit with 0, got $EXIT_CODE"

View File

@@ -14,3 +14,4 @@ rm -f "../../../alias/stable"
rm -f "../../../alias/unstable" rm -f "../../../alias/unstable"
rm -f "../../../alias/node" rm -f "../../../alias/node"
rm -f "../../../alias/iojs" rm -f "../../../alias/iojs"
rm -f "../../../alias/default"

View File

@@ -5,9 +5,13 @@ die () { echo $@ ; exit 1; }
. ../../nvm.sh . ../../nvm.sh
nvm_has_system_node() { return 0; } nvm_has_system_node() { return 0; }
[ "$(nvm use system 2>&1 | tail -n1)" = "Now using system version of node: $(node -v)." ] || die "Could not use system version of node" nvm_print_npm_version() { return ' (npm v1.2.3)'; }
EXPECTED_OUTPUT="Now using system version of node: $(node -v)$(nvm_print_npm_version)"
[ "$(nvm use system 2>&1 | tail -n1)" = "$EXPECTED_OUTPUT" ] || die "Could not use system version of node"
nvm_has_system_node() { return 1; } nvm_has_system_node() { return 1; }
[ "$(nvm use system 2>&1 | tail -n1)" = "System version of node not found." ] || die "Did not report error, system node not found" nvm_print_npm_version() { return ''; }
EXPECTED_OUTPUT="System version of node not found."
[ "$(nvm use system 2>&1 | tail -n1)" = "$EXPECTED_OUTPUT" ] || die "Did not report error, system node not found"
nvm use system 2>&1 > /dev/null || [ $? -eq 127 ] || die "Did not return error code, system node not found" nvm use system 2>&1 > /dev/null || [ $? -eq 127 ] || die "Did not return error code, system node not found"

View File

@@ -0,0 +1,13 @@
#!/bin/sh
die () { echo $@ ; exit 1; }
. ../../../nvm.sh
EXPECTED_OUTPUT="nvm_ensure_default_set: a version is required"
OUTPUT="$(nvm_ensure_default_set 2>&1 >/dev/null)"
EXIT_CODE="$?"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "'nvm_ensure_default_set' did not output "$EXPECTED_OUTPUT", got "$OUTPUT""
[ "_$EXIT_CODE" = "_1" ] || die "'nvm_ensure_default_set' did not exit with 1, got "$EXIT_CODE""
# see test/fast/Aliases for remaining nvm_ensure_default_set tests

View File

@@ -5,13 +5,17 @@ die () { echo $@ ; exit 1; }
. ../../../nvm.sh . ../../../nvm.sh
[ "~$(nvm_num_version_groups)" = "~0" ] || die "no args should give 0" [ "~$(nvm_num_version_groups)" = "~0" ] || die "no args should give 0"
[ "~$(nvm_num_version_groups v)" = "~0" ] || die "just "v" should give 0"
[ "~$(nvm_num_version_groups .)" = "~0" ] || die "just "." should give 0"
[ "~$(nvm_num_version_groups a)" = "~1" ] || die "one letter should give 1" [ "~$(nvm_num_version_groups a)" = "~1" ] || die "one letter should give 1"
[ "~$(nvm_num_version_groups 1)" = "~1" ] || die "1 should give 1" [ "~$(nvm_num_version_groups 1)" = "~1" ] || die "1 should give 1"
[ "~$(nvm_num_version_groups 1.)" = "~1" ] || die "1. should give 1"
[ "~$(nvm_num_version_groups v1)" = "~1" ] || die "v1 should give 1" [ "~$(nvm_num_version_groups v1)" = "~1" ] || die "v1 should give 1"
[ "~$(nvm_num_version_groups v1.)" = "~1" ] || die "v1. should give 1" [ "~$(nvm_num_version_groups v1.)" = "~1" ] || die "v1. should give 1"
[ "~$(nvm_num_version_groups 1.2)" = "~2" ] || die "1.2 should give 2" [ "~$(nvm_num_version_groups 1.2)" = "~2" ] || die "1.2 should give 2"
[ "~$(nvm_num_version_groups 1.2.)" = "~2" ] || die "1.2. should give 2"
[ "~$(nvm_num_version_groups v1.2)" = "~2" ] || die "v1.2 should give 2" [ "~$(nvm_num_version_groups v1.2)" = "~2" ] || die "v1.2 should give 2"
[ "~$(nvm_num_version_groups v1.2.)" = "~2" ] || die "v1.2. should give 2" [ "~$(nvm_num_version_groups v1.2.)" = "~2" ] || die "v1.2. should give 2"

View File

@@ -0,0 +1,28 @@
#!/bin/sh
cleanup () {
alias nvm_has='\nvm_has'
alias npm='\npm'
unset -f nvm_has npm
}
die () { echo $@ ; exit 1; }
. ../../../nvm.sh
nvm_has() { return 1; }
OUTPUT="$(nvm_print_npm_version)"
[ -z "$OUTPUT" ] || die "nvm_print_npm_version did not return empty when nvm_has returns 1, got '$OUTPUT'"
nvm_has() { return 0; }
npm() {
if [ "_$@" = "_--version" ]; then
echo "1.2.3"
else
echo "error"
fi
}
OUTPUT="$(nvm_print_npm_version)"
EXPECTED_OUTPUT=" (npm v1.2.3)"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_print_npm_version did not provided '$EXPECTED_OUTPUT', got '$OUTPUT'"
cleanup

View File

@@ -15,7 +15,7 @@ safe_type() {
safe_type nvm_reset || die 'nvm_reset is not available' safe_type nvm_reset || die 'nvm_reset is not available'
# Apply nvm_reset # Apply nvm_reset
nvm_reset nvm_reset || die 'nvm_reset failed'
# The names should be unset # The names should be unset
! safe_type nvm_do_install || die 'nvm_do_install is still available' ! safe_type nvm_do_install || die 'nvm_do_install is still available'

View File

@@ -10,12 +10,12 @@ cleanup() {
EXPECTED_VERSION="v12.3.456" EXPECTED_VERSION="v12.3.456"
URL="https://github.com/creationix/nvm/releases/tag/$EXPECTED_VERSION" URL="https://github.com/creationix/nvm/releases/tag/$EXPECTED_VERSION"
EXPECTED_CURL_ARGS="-w %{url_effective}\n -L -s -S http://latest.nvm.sh -o /dev/null" EXPECTED_CURL_ARGS="-q -w %{url_effective}\n -L -s -S http://latest.nvm.sh -o /dev/null"
EXPECTED_WGET_ARGS="http://latest.nvm.sh --server-response -O /dev/null" EXPECTED_WGET_ARGS="http://latest.nvm.sh --server-response -O /dev/null"
curl() { curl() {
if [ "_$*" != "_$EXPECTED_CURL_ARGS" ]; then if [ "_$*" != "_$EXPECTED_CURL_ARGS" ]; then
echo 2>& "expected args ($EXPECTED_CURL_ARGS), got ($*)" echo >&2 "expected args ($EXPECTED_CURL_ARGS), got ($*)"
return 1 return 1
else else
echo $URL echo $URL
@@ -23,7 +23,7 @@ curl() {
} }
wget() { wget() {
if [ "_$*" != "_$EXPECTED_WGET_ARGS" ]; then if [ "_$*" != "_$EXPECTED_WGET_ARGS" ]; then
echo 2>& "expected args ($EXPECTED_WGET_ARGS), got ($*)" echo >&2 "expected args ($EXPECTED_WGET_ARGS), got ($*)"
return 1 return 1
else else
local WGET_CONTENTS local WGET_CONTENTS
@@ -100,7 +100,7 @@ Saving to: /dev/null
" "
"$WGET_CONTENTS" | while read line "$WGET_CONTENTS" | while read line
do do
2>& echo "$line" >&2 echo "$line"
done done
fi fi
} }