Compare commits

...

15 Commits

Author SHA1 Message Date
Jordan Harband
0a142b7e7a v0.22.1 2015-01-10 19:43:36 -08:00
Jordan Harband
3fc82d6b2f Use command sed for people who alias sed.
Fixes #493.
2015-01-09 01:50:05 -08:00
Jordan Harband
c6489440dc Add nvm_ls_current test for #605 and zsh. 2015-01-01 23:31:55 -08:00
Jordan Harband
67e8939311 Merge pull request #605 from dhcmrlchtdj/fix_which
Fix which command in zsh (#604).
2015-01-01 22:28:30 -08:00
niris
a26007ec0d fix test suit 2015-01-02 12:51:59 +08:00
niris
3f5ce8b93a Fix which command in zsh (#604). 2015-01-02 10:20:57 +08:00
Jordan Harband
8328741792 Removing an unnecessary return $? 2014-12-28 22:29:26 -08:00
Jordan Harband
8e45afb9f1 Move the version to a single location, nvm_latest_version. 2014-12-28 15:59:06 -08:00
Jordan Harband
fd2fb24b03 Refactor nvm_source a bit. 2014-12-28 15:55:44 -08:00
Jordan Harband
4708cc73ef Update semver 2014-12-27 01:39:48 -08:00
Jordan Harband
c91e8d0ba2 v0.22.0 2014-12-26 16:30:21 -08:00
Jordan Harband
f8b143c594 Merge pull request #602 from ljharb/install_on_source
Support `--install` option on sourcing `nvm.sh`
2014-12-26 14:03:22 -08:00
Jordan Harband
9a4e9060d8 Don't bother testing --install option on source, or supporting it, unless the shell supports passing options upon sourcing. 2014-12-26 13:33:33 -08:00
Jordan Harband
3df0caefa5 Support --install option upon sourcing. 2014-12-26 12:19:35 -08:00
Jordan Harband
274369dc40 Remove trailing whitespace 2014-12-22 23:08:03 -08:00
8 changed files with 121 additions and 46 deletions

View File

@@ -12,11 +12,11 @@ Note: `nvm` does not support Windows (see [#284](https://github.com/creationix/n
To install you could use the [install script][2] using cURL:
curl https://raw.githubusercontent.com/creationix/nvm/v0.21.0/install.sh | bash
curl https://raw.githubusercontent.com/creationix/nvm/v0.22.1/install.sh | bash
or Wget:
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.21.0/install.sh | bash
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.22.1/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>
@@ -191,7 +191,7 @@ After the v0.8.6 release of node, nvm tries to install from binary packages. But
nvm install -s 0.8.6
[1]: https://github.com/creationix/nvm.git
[2]: https://github.com/creationix/nvm/blob/v0.21.0/install.sh
[2]: https://github.com/creationix/nvm/blob/v0.22.1/install.sh
[3]: https://travis-ci.org/creationix/nvm
[Urchin]: https://github.com/scraperwiki/urchin

View File

@@ -4,13 +4,16 @@ set -e
nvm_has() {
type "$1" > /dev/null 2>&1
return $?
}
if [ -z "$NVM_DIR" ]; then
NVM_DIR="$HOME/.nvm"
fi
nvm_latest_version() {
echo "v0.22.1"
}
#
# Outputs the location to NVM depending on:
# * The availability of $NVM_SOURCE
@@ -22,19 +25,16 @@ nvm_source() {
NVM_METHOD="$1"
if [ -z "$NVM_SOURCE" ]; then
local NVM_SOURCE
else
echo "$NVM_SOURCE"
return 0
fi
if [ "_$NVM_METHOD" = "_script" ]; then
NVM_SOURCE="https://raw.githubusercontent.com/creationix/nvm/v0.21.0/nvm.sh"
elif [ "_$NVM_METHOD" = "_script-nvm-exec" ]; then
NVM_SOURCE="https://raw.githubusercontent.com/creationix/nvm/v0.21.0/nvm-exec"
elif [ "_$NVM_METHOD" = "_git" ] || [ -z "$NVM_METHOD" ]; then
NVM_SOURCE="https://github.com/creationix/nvm.git"
else
echo >&2 "Unexpected value \"$NVM_METHOD\" for \$NVM_METHOD"
return 1
if [ "_$NVM_METHOD" = "_script" ]; then
NVM_SOURCE="https://raw.githubusercontent.com/creationix/nvm/$(nvm_latest_version)/nvm.sh"
elif [ "_$NVM_METHOD" = "_script-nvm-exec" ]; then
NVM_SOURCE="https://raw.githubusercontent.com/creationix/nvm/$(nvm_latest_version)/nvm-exec"
elif [ "_$NVM_METHOD" = "_git" ] || [ -z "$NVM_METHOD" ]; then
NVM_SOURCE="https://github.com/creationix/nvm.git"
else
echo >&2 "Unexpected value \"$NVM_METHOD\" for \$NVM_METHOD"
return 1
fi
fi
echo "$NVM_SOURCE"
return 0
@@ -45,7 +45,7 @@ nvm_download() {
curl $*
elif nvm_has "wget"; then
# Emulate curl with wget
ARGS=$(echo "$*" | sed -e 's/--progress-bar /--progress=bar /' \
ARGS=$(echo "$*" | command sed -e 's/--progress-bar /--progress=bar /' \
-e 's/-L //' \
-e 's/-I /--server-response /' \
-e 's/-s /-q /' \
@@ -67,17 +67,17 @@ install_nvm_from_git() {
echo "=> Downloading nvm from git to '$NVM_DIR'"
printf "\r=> "
mkdir -p "$NVM_DIR"
git clone "$(nvm_source "git")" "$NVM_DIR"
git clone "$(nvm_source git)" "$NVM_DIR"
fi
cd "$NVM_DIR" && git checkout --quiet v0.21.0 && git branch --quiet -D master >/dev/null 2>&1
cd "$NVM_DIR" && git checkout --quiet $(nvm_latest_version) && git branch --quiet -D master >/dev/null 2>&1
return
}
install_nvm_as_script() {
local NVM_SOURCE
NVM_SOURCE=$(nvm_source "script")
NVM_SOURCE=$(nvm_source script)
local NVM_EXEC_SOURCE
NVM_EXEC_SOURCE=$(nvm_source "script-nvm-exec")
NVM_EXEC_SOURCE=$(nvm_source script-nvm-exec)
# Downloading to $NVM_DIR
mkdir -p "$NVM_DIR"
@@ -178,7 +178,7 @@ nvm_do_install() {
# during the execution of the install script
#
nvm_reset() {
unset -f nvm_do_install nvm_has nvm_download install_nvm_as_script install_nvm_from_git nvm_reset nvm_detect_profile
unset -f nvm_do_install nvm_has nvm_download install_nvm_as_script install_nvm_from_git nvm_reset nvm_detect_profile nvm_latest_version
}
[ "_$NVM_ENV" = "_testing" ] || nvm_do_install

35
nvm.sh
View File

@@ -35,7 +35,7 @@ nvm_download() {
curl $*
elif nvm_has "wget"; then
# Emulate curl with wget
ARGS=$(echo "$*" | sed -e 's/--progress-bar /--progress=bar /' \
ARGS=$(echo "$*" | command sed -e 's/--progress-bar /--progress=bar /' \
-e 's/-L //' \
-e 's/-I /--server-response /' \
-e 's/-s /-q /' \
@@ -201,18 +201,18 @@ nvm_remote_version() {
}
nvm_normalize_version() {
echo "$1" | sed -e 's/^v//' | \awk -F. '{ printf("%d%06d%06d\n", $1,$2,$3); }'
echo "$1" | command sed -e 's/^v//' | \awk -F. '{ printf("%d%06d%06d\n", $1,$2,$3); }'
}
nvm_ensure_version_prefix() {
echo "$1" | sed -e 's/^\([0-9]\)/v\1/g'
echo "$1" | command sed -e 's/^\([0-9]\)/v\1/g'
}
nvm_format_version() {
local VERSION
VERSION="$(nvm_ensure_version_prefix "$1")"
if [ "_$(nvm_num_version_groups "$VERSION")" != "_3" ]; then
VERSION="$(echo "$VERSION" | sed -e 's/\.*$/.0/')"
VERSION="$(echo "$VERSION" | command sed -e 's/\.*$/.0/')"
nvm_format_version "$VERSION"
else
echo "$VERSION"
@@ -227,14 +227,14 @@ nvm_num_version_groups() {
return
fi
local NVM_NUM_DOTS
NVM_NUM_DOTS=$(echo "$VERSION" | sed -e 's/^v//' | sed -e 's/\.$//' | sed -e 's/[^\.]//g')
NVM_NUM_DOTS=$(echo "$VERSION" | command sed -e 's/^v//' | command sed -e 's/\.$//' | command sed -e 's/[^\.]//g')
local NVM_NUM_GROUPS
NVM_NUM_GROUPS=".$NVM_NUM_DOTS"
echo "${#NVM_NUM_GROUPS}"
}
nvm_strip_path() {
echo "$1" | sed -e "s#$NVM_DIR/[^/]*$2[^:]*:##g" -e "s#:$NVM_DIR/[^/]*$2[^:]*##g" -e "s#$NVM_DIR/[^/]*$2[^:]*##g"
echo "$1" | command sed -e "s#$NVM_DIR/[^/]*$2[^:]*:##g" -e "s#:$NVM_DIR/[^/]*$2[^:]*##g" -e "s#$NVM_DIR/[^/]*$2[^:]*##g"
}
nvm_prepend_path() {
@@ -272,7 +272,7 @@ nvm_alias() {
nvm_ls_current() {
local NVM_LS_CURRENT_NODE_PATH
NVM_LS_CURRENT_NODE_PATH="$(which node 2> /dev/null)"
NVM_LS_CURRENT_NODE_PATH="$(command which node 2> /dev/null)"
if [ $? -ne 0 ]; then
echo 'none'
elif nvm_tree_contains_path "$NVM_DIR" "$NVM_LS_CURRENT_NODE_PATH"; then
@@ -366,7 +366,7 @@ nvm_ls() {
local NUM_VERSION_GROUPS
NUM_VERSION_GROUPS="$(nvm_num_version_groups "$PATTERN")"
if [ "_$NUM_VERSION_GROUPS" = "_2" ] || [ "_$NUM_VERSION_GROUPS" = "_1" ]; then
PATTERN="$(echo "$PATTERN" | sed -e 's/\.*$//g')."
PATTERN="$(echo "$PATTERN" | command sed -e 's/\.*$//g')."
fi
fi
if [ -d "$(nvm_version_dir new)" ]; then
@@ -984,7 +984,7 @@ nvm() {
if [ "_$VERSION" = '_system' ]; then
if nvm_has_system_node >/dev/null 2>&1; then
local NVM_BIN
NVM_BIN="$(nvm use system >/dev/null 2>&1 && which node)"
NVM_BIN="$(nvm use system >/dev/null 2>&1 && command which node)"
if [ -n "$NVM_BIN" ]; then
echo "$NVM_BIN"
return
@@ -1099,10 +1099,10 @@ nvm() {
nvm_version $2
;;
"--version" )
echo "0.21.0"
echo "0.22.1"
;;
"unload" )
unset -f nvm nvm_print_versions nvm_checksum nvm_ls_remote nvm_ls nvm_remote_version nvm_version nvm_rc_version nvm_version_greater nvm_version_greater_than_or_equal_to > /dev/null 2>&1
unset -f nvm nvm_print_versions nvm_checksum nvm_ls_remote nvm_ls nvm_remote_version nvm_version nvm_rc_version nvm_version_greater nvm_version_greater_than_or_equal_to nvm_supports_source_options > /dev/null 2>&1
unset RC_VERSION NVM_NODEJS_ORG_MIRROR NVM_DIR NVM_CD_FLAGS > /dev/null 2>&1
;;
* )
@@ -1111,7 +1111,18 @@ nvm() {
esac
}
if nvm ls default >/dev/null; then
nvm_supports_source_options() {
[ "_$(echo 'echo $1' | . /dev/stdin yes)" = "_yes" ]
}
if nvm_supports_source_options && [ "_$1" = "_--install" ]; then
VERSION="$(nvm_alias default 2>/dev/null)"
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 ls default >/dev/null; then
nvm use default >/dev/null
elif nvm_rc_version >/dev/null 2>&1; then
nvm use >/dev/null

View File

@@ -1,6 +1,6 @@
{
"name": "nvm",
"version": "0.21.0",
"version": "0.22.1",
"description": "Node Version Manager - Simple bash script to manage multiple active node.js versions",
"directories": {
"test": "test"
@@ -31,7 +31,7 @@
"homepage": "https://github.com/creationix/nvm",
"devDependencies": {
"replace": "~0.3.0",
"semver": "~4.1.1",
"semver": "~4.2.0",
"urchin": "~0.0.5"
}
}

View File

@@ -1,6 +1,10 @@
#!/bin/sh
die () { echo $@ ; exit 1; }
TEST_PWD=$(pwd)
TEST_DIR="$TEST_PWD/nvm_ls_current_tmp"
cleanup() { rm -rf "$TEST_DIR"; unset -f return_zero; unalias node; }
die () { echo $@ ; cleanup ; exit 1; }
. ../../../nvm.sh
@@ -8,12 +12,10 @@ return_zero () { return 0; }
[ "$(nvm deactivate > /dev/null 2>&1 ; nvm_ls_current)" = "system" ] || die 'when deactivated, did not return "system"'
TEST_PWD=$(pwd)
TEST_DIR="$TEST_PWD/nvm_ls_current_tmp"
rm -rf "$TEST_DIR"
mkdir "$TEST_DIR"
ln -s "$(which which)" "$TEST_DIR/which"
ln -s "$(which dirname)" "$TEST_DIR/dirname"
ln -s "$(command which which)" "$TEST_DIR/which"
ln -s "$(command which dirname)" "$TEST_DIR/dirname"
[ "$(PATH="$TEST_DIR" nvm_ls_current)" = "none" ] || die 'when node not installed, nvm_ls_current did not return "none"'
[ "@$(PATH="$TEST_DIR" nvm_ls_current 2> /dev/stdout 1> /dev/null)@" = "@@" ] || die 'when node not installed, nvm_ls_current returned error output'
@@ -24,5 +26,7 @@ chmod a+x "$TEST_DIR/node"
[ "$(alias nvm_tree_contains_path='return_zero' && PATH="$TEST_DIR" nvm_ls_current)" = "VERSION FOO!" ] || die 'when activated, did not return nvm node version'
rm -rf "$TEST_DIR"
alias node='node --harmony'
[ "$(alias nvm_tree_contains_path='return_zero' && PATH="$TEST_DIR" nvm_ls_current)" = "VERSION FOO!" ] || die 'when activated and node aliased, did not return nvm node version'
cleanup

View File

@@ -31,7 +31,7 @@ wget() {
--2014-12-21 18:11:14-- http://latest.nvm.sh/
Resolving latest.nvm.sh... 50.31.209.229
Connecting to latest.nvm.sh|50.31.209.229|:80... connected.
HTTP request sent, awaiting response...
HTTP request sent, awaiting response...
HTTP/1.1 301 Moved Permanently
Location: https://github.com/creationix/nvm/releases/latest
Content-Type: text/html; charset=utf-8
@@ -41,7 +41,7 @@ Location: https://github.com/creationix/nvm/releases/latest [following]
--2014-12-21 18:11:15-- https://github.com/creationix/nvm/releases/latest
Resolving github.com... 192.30.252.130
Connecting to github.com|192.30.252.130|:443... connected.
HTTP request sent, awaiting response...
HTTP request sent, awaiting response...
HTTP/1.1 302 Found
Server: GitHub.com
Date: Mon, 22 Dec 2014 02:11:15 GMT
@@ -68,7 +68,7 @@ HTTP request sent, awaiting response...
Location: $URL [following]
--2014-12-21 18:11:15-- $URL
Reusing existing connection to github.com:443.
HTTP request sent, awaiting response...
HTTP request sent, awaiting response...
HTTP/1.1 200 OK
Server: GitHub.com
Date: Mon, 22 Dec 2014 02:11:15 GMT

View File

@@ -0,0 +1,28 @@
#!/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
echo '0.10.2' > ../../.nvmrc || die 'creation of .nvmrc failed'
. ../../nvm.sh --install
EXIT_CODE="$(echo $?)"
echo 'sourcing complete.'
nvm_version 0.10.2 >/dev/null 2>&1 || die "v0.10.2 not installed: $(nvm ls)"
[ "_$(nvm_rc_version | \grep -o -e 'with version .*$')" = "_with version <0.10.2>" ] || die "nvm_rc_version $(nvm_rc_version)"
[ "_$EXIT_CODE" = "_0" ] || die "sourcing returned nonzero exit code: $EXIT_CODE"
NVM_LS_CURRENT="$(nvm ls current | \grep -o v0.10.2)"
[ "_$NVM_LS_CURRENT" = '_v0.10.2' ] || die "'nvm ls current' did not return '-> v0.10.2', got '$NVM_LS_CURRENT' `nvm ls`"

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
echo '0.10.2' > ../../alias/default || die 'creation of default alias failed'
echo 'sourcing nvm with --install...'
. ../../nvm.sh --install
EXIT_CODE="$(echo $?)"
echo 'sourcing complete.'
nvm_version 0.10.2 >/dev/null 2>&1 || die "v0.10.2 not installed: $(nvm ls)"
[ "_$EXIT_CODE" = "_0" ] || die "sourcing returned nonzero exit code: $EXIT_CODE"
NVM_LS_CURRENT="$(nvm ls current | \grep -o v0.10.2)"
[ "_$NVM_LS_CURRENT" = '_v0.10.2' ] || die "'nvm ls current' did not return '-> v0.10.2', got '$NVM_LS_CURRENT'"
NVM_ALIAS_DEFAULT="$(nvm alias default)"
[ "_$NVM_ALIAS_DEFAULT" = "_default -> 0.10.2 (-> v0.10.2)" ] \
|| die "'nvm alias default did not return 'default -> 0.10.2 (-> v0.10.2)', got '$NVM_ALIAS_DEFAULT'"