Compare commits
59 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4895aebf0a | ||
|
|
8a29122d0a | ||
|
|
26ed7a003a | ||
|
|
00ca5288b0 | ||
|
|
6d2912a2ab | ||
|
|
1d61584402 | ||
|
|
f6974744cd | ||
|
|
7171cbed6f | ||
|
|
8f66273922 | ||
|
|
1a9ab82e24 | ||
|
|
3fa004293c | ||
|
|
83efa2288d | ||
|
|
4cfe62d3d1 | ||
|
|
802f064178 | ||
|
|
c49cb68575 | ||
|
|
0534872e0f | ||
|
|
f1b8cf8fd6 | ||
|
|
78ff9a2215 | ||
|
|
b952be6f56 | ||
|
|
638ae5c6fa | ||
|
|
a7b6495172 | ||
|
|
703e43cc2b | ||
|
|
03636878d1 | ||
|
|
2ee4b6f414 | ||
|
|
10305f0791 | ||
|
|
276c031c60 | ||
|
|
63f72b37df | ||
|
|
cf5bfecec4 | ||
|
|
77c3f20956 | ||
|
|
e4ada9fa43 | ||
|
|
a0de15d0f7 | ||
|
|
df4689fbd2 | ||
|
|
018e47bec0 | ||
|
|
74cc1eb022 | ||
|
|
eda8ffbcc4 | ||
|
|
b9383c9016 | ||
|
|
25c0be1e20 | ||
|
|
a8233eb68c | ||
|
|
ea198c9a19 | ||
|
|
e0537ce3df | ||
|
|
cce5df35ba | ||
|
|
7e269961c3 | ||
|
|
f214ffaf1f | ||
|
|
d016fe010a | ||
|
|
fb5a51b1b7 | ||
|
|
3e5037a1be | ||
|
|
60fec40613 | ||
|
|
fb215546ee | ||
|
|
4b593bcda2 | ||
|
|
8349f0ff48 | ||
|
|
bb250b5730 | ||
|
|
b6f1c156da | ||
|
|
4c9a36e9ad | ||
|
|
bb01513eba | ||
|
|
ba7f27dead | ||
|
|
79ec957ee7 | ||
|
|
d8b55652a5 | ||
|
|
4c38f507f5 | ||
|
|
f213167ef0 |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -11,4 +11,4 @@ test/bak
|
||||
node_modules/
|
||||
|
||||
.DS_Store
|
||||
|
||||
current
|
||||
|
||||
12
Makefile
12
Makefile
@@ -2,7 +2,7 @@ URCHIN=`which urchin`
|
||||
SHELLS=sh bash dash ksh zsh
|
||||
TEST_SUITE=fast
|
||||
|
||||
.PHONY: $(SHELLS) test
|
||||
.PHONY: $(SHELLS) test verify-tag release
|
||||
|
||||
$(SHELLS):
|
||||
@printf '\n\033[0;34m%s\033[0m\n' "Running tests in $@"
|
||||
@@ -13,3 +13,13 @@ test: $(SHELLS)
|
||||
|
||||
default: test
|
||||
|
||||
verify-tag:
|
||||
ifndef TAG
|
||||
$(error TAG is undefined)
|
||||
endif
|
||||
|
||||
release: verify-tag
|
||||
@ OLD_TAG=`git describe --abbrev=0 --tags` && \
|
||||
npm version "$(TAG)" && \
|
||||
replace "$${OLD_TAG/v/}" "$(TAG)" -- nvm.sh install.sh README.markdown && \
|
||||
git commit --amend nvm.sh install.sh README.markdown package.json
|
||||
|
||||
@@ -8,17 +8,17 @@ First you'll need to make sure your system has a c++ compiler. For OSX, XCode w
|
||||
|
||||
To install you could use the [install script][2] using cURL:
|
||||
|
||||
curl https://raw.githubusercontent.com/creationix/nvm/v0.8.0/install.sh | sh
|
||||
curl https://raw.githubusercontent.com/creationix/nvm/v0.11.0/install.sh | bash
|
||||
|
||||
or Wget:
|
||||
|
||||
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.8.0/install.sh | sh
|
||||
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.11.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>
|
||||
|
||||
You can customize the install source, directory and profile using the `NVM_SOURCE`, `NVM_DIR` and `NVM_PROFILE` variables. Eg: `curl ... | NVM_DIR=/usr/local/nvm sh` for a global install.
|
||||
You can customize the install source, directory and profile using the `NVM_SOURCE`, `NVM_DIR` and `PROFILE` variables. Eg: `curl ... | NVM_DIR=/usr/local/nvm bash` for a global install.
|
||||
|
||||
<sub>*NB. The installer can use Git, cURL or Wget to download NVM, whatever is available.*</sub>
|
||||
<sub>*NB. The installer can use Git, curl, or wget to download NVM, whatever is available.*</sub>
|
||||
|
||||
### Manual install
|
||||
|
||||
@@ -163,7 +163,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.8.0/install.sh
|
||||
[2]: https://github.com/creationix/nvm/blob/v0.11.0/install.sh
|
||||
[3]: https://travis-ci.org/creationix/nvm
|
||||
[Urchin]: https://github.com/scraperwiki/urchin
|
||||
|
||||
|
||||
72
install.sh
72
install.sh
@@ -2,7 +2,7 @@
|
||||
|
||||
set -e
|
||||
|
||||
has() {
|
||||
nvm_has() {
|
||||
type "$1" > /dev/null 2>&1
|
||||
return $?
|
||||
}
|
||||
@@ -11,41 +11,46 @@ if [ -z "$NVM_DIR" ]; then
|
||||
NVM_DIR="$HOME/.nvm"
|
||||
fi
|
||||
|
||||
if ! has "curl"; then
|
||||
if has "wget"; then
|
||||
nvm_download() {
|
||||
if nvm_has "curl"; then
|
||||
curl $*
|
||||
elif nvm_has "wget"; then
|
||||
# Emulate curl with wget
|
||||
curl() {
|
||||
ARGS="$* "
|
||||
ARGS=${ARGS/-s /-q }
|
||||
ARGS=${ARGS/-o /-O }
|
||||
wget $ARGS
|
||||
}
|
||||
ARGS="$*"
|
||||
ARGS=${ARGS/--progress-bar /--progress=bar }
|
||||
ARGS=${ARGS/-L /}
|
||||
ARGS=${ARGS/-I /}
|
||||
ARGS=${ARGS/-s /-q }
|
||||
ARGS=${ARGS/-o /-O }
|
||||
ARGS=${ARGS/-C /-c }
|
||||
wget $ARGS
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
install_from_git() {
|
||||
install_nvm_from_git() {
|
||||
if [ -z "$NVM_SOURCE" ]; then
|
||||
NVM_SOURCE="https://github.com/creationix/nvm.git"
|
||||
fi
|
||||
|
||||
if [ -d "$NVM_DIR/.git" ]; then
|
||||
echo "=> nvm is already installed in $NVM_DIR, trying to update"
|
||||
echo -e "\r=> \c"
|
||||
cd "$NVM_DIR" && git pull 2> /dev/null || {
|
||||
echo >&2 "Failed to update nvm, run 'git pull' in $NVM_DIR yourself.."
|
||||
}
|
||||
printf "\r=> "
|
||||
cd "$NVM_DIR" && (git pull 2> /dev/null || {
|
||||
echo >&2 "Failed to update nvm, run 'git pull' in $NVM_DIR yourself.." && exit 1
|
||||
})
|
||||
else
|
||||
# Cloning to $NVM_DIR
|
||||
echo "=> Downloading nvm from git to '$NVM_DIR'"
|
||||
echo -e "\r=> \c"
|
||||
printf "\r=> "
|
||||
mkdir -p "$NVM_DIR"
|
||||
git clone "$NVM_SOURCE" "$NVM_DIR"
|
||||
fi
|
||||
git checkout v0.11.0
|
||||
}
|
||||
|
||||
install_as_script() {
|
||||
install_nvm_as_script() {
|
||||
if [ -z "$NVM_SOURCE" ]; then
|
||||
NVM_SOURCE="https://raw.githubusercontent.com/creationix/nvm/master/nvm.sh"
|
||||
NVM_SOURCE="https://raw.githubusercontent.com/creationix/nvm/v0.11.0/nvm.sh"
|
||||
fi
|
||||
|
||||
# Downloading to $NVM_DIR
|
||||
@@ -55,7 +60,7 @@ install_as_script() {
|
||||
else
|
||||
echo "=> Downloading nvm as script to '$NVM_DIR'"
|
||||
fi
|
||||
curl -s "$NVM_SOURCE" -o "$NVM_DIR/nvm.sh" || {
|
||||
nvm_download -s "$NVM_SOURCE" -o "$NVM_DIR/nvm.sh" || {
|
||||
echo >&2 "Failed to download '$NVM_SOURCE'.."
|
||||
return 1
|
||||
}
|
||||
@@ -63,28 +68,28 @@ install_as_script() {
|
||||
|
||||
if [ -z "$METHOD" ]; then
|
||||
# Autodetect install method
|
||||
if has "git"; then
|
||||
install_from_git
|
||||
elif has "curl"; then
|
||||
install_as_script
|
||||
if nvm_has "git"; then
|
||||
install_nvm_from_git
|
||||
elif nvm_has "nvm_download"; then
|
||||
install_nvm_as_script
|
||||
else
|
||||
echo >&2 "You need git, curl or wget to install nvm"
|
||||
echo >&2 "You need git, curl, or wget to install nvm"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
if [ "$METHOD" = "git" ]; then
|
||||
if ! has "git"; then
|
||||
if ! nvm_has "git"; then
|
||||
echo >&2 "You need git to install nvm"
|
||||
exit 1
|
||||
fi
|
||||
install_from_git
|
||||
install_nvm_from_git
|
||||
fi
|
||||
if [ "$METHOD" = "script" ]; then
|
||||
if ! has "curl"; then
|
||||
if ! nvm_has "nvm_download"; then
|
||||
echo >&2 "You need curl or wget to install nvm"
|
||||
exit 1
|
||||
fi
|
||||
install_as_script
|
||||
install_nvm_as_script
|
||||
fi
|
||||
fi
|
||||
|
||||
@@ -104,8 +109,8 @@ fi
|
||||
SOURCE_STR="\nexport NVM_DIR=\"$NVM_DIR\"\n[ -s \"\$NVM_DIR/nvm.sh\" ] && . \"\$NVM_DIR/nvm.sh\" # This loads nvm"
|
||||
|
||||
if [ -z "$PROFILE" ] || [ ! -f "$PROFILE" ] ; then
|
||||
if [ -z $PROFILE ]; then
|
||||
echo "=> Profile not found. Tried ~/.bash_profile ~/.zshrc and ~/.profile."
|
||||
if [ -z "$PROFILE" ]; then
|
||||
echo "=> Profile not found. Tried ~/.bash_profile, ~/.zshrc, and ~/.profile."
|
||||
echo "=> Create one of them and run this script again"
|
||||
else
|
||||
echo "=> Profile $PROFILE not found"
|
||||
@@ -113,16 +118,15 @@ if [ -z "$PROFILE" ] || [ ! -f "$PROFILE" ] ; then
|
||||
fi
|
||||
echo " OR"
|
||||
echo "=> Append the following lines to the correct file yourself:"
|
||||
echo -e "$SOURCE_STR"
|
||||
printf "$SOURCE_STR"
|
||||
echo
|
||||
else
|
||||
if ! grep -qc 'nvm.sh' $PROFILE; then
|
||||
if ! grep -qc 'nvm.sh' "$PROFILE"; then
|
||||
echo "=> Appending source string to $PROFILE"
|
||||
echo -e "$SOURCE_STR" >> "$PROFILE"
|
||||
printf "$SOURCE_STR\n" >> "$PROFILE"
|
||||
else
|
||||
echo "=> Source string already in $PROFILE"
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "=> Close and reopen your terminal to start using nvm"
|
||||
|
||||
|
||||
161
nvm.sh
161
nvm.sh
@@ -1,5 +1,6 @@
|
||||
# Node Version Manager
|
||||
# Implemented as a bash function
|
||||
# Implemented as a POSIX-compliant function
|
||||
# Should work on sh, dash, bash, ksh, zsh
|
||||
# To use source this file from your bash profile
|
||||
#
|
||||
# Implemented by Tim Caswell <tim@creationix.com>
|
||||
@@ -9,7 +10,26 @@ NVM_SCRIPT_SOURCE="$_"
|
||||
|
||||
nvm_has() {
|
||||
type "$1" > /dev/null 2>&1
|
||||
return $?
|
||||
}
|
||||
|
||||
nvm_download() {
|
||||
if nvm_has "curl"; then
|
||||
curl $*
|
||||
elif nvm_has "wget"; then
|
||||
# Emulate curl with wget
|
||||
ARGS="$*"
|
||||
ARGS=${ARGS/--progress-bar /--progress=bar }
|
||||
ARGS=${ARGS/-L /}
|
||||
ARGS=${ARGS/-I /}
|
||||
ARGS=${ARGS/-s /-q }
|
||||
ARGS=${ARGS/-o /-O }
|
||||
ARGS=${ARGS/-C /-c }
|
||||
wget $ARGS
|
||||
fi
|
||||
}
|
||||
|
||||
nvm_has_system_node() {
|
||||
[ "$(nvm deactivate 2> /dev/null && command -v node)" != '' ]
|
||||
}
|
||||
|
||||
# Make zsh glob matching behave same as bash
|
||||
@@ -46,7 +66,8 @@ nvm_find_up() {
|
||||
|
||||
|
||||
nvm_find_nvmrc() {
|
||||
local dir="$(nvm_find_up '.nvmrc')"
|
||||
local dir
|
||||
dir="$(nvm_find_up '.nvmrc')"
|
||||
if [ -e "$dir/.nvmrc" ]; then
|
||||
echo "$dir/.nvmrc"
|
||||
fi
|
||||
@@ -54,16 +75,18 @@ nvm_find_nvmrc() {
|
||||
|
||||
# Obtain nvm version from rc file
|
||||
nvm_rc_version() {
|
||||
local NVMRC_PATH="$(nvm_find_nvmrc)"
|
||||
local NVMRC_PATH
|
||||
NVMRC_PATH="$(nvm_find_nvmrc)"
|
||||
if [ -e "$NVMRC_PATH" ]; then
|
||||
NVM_RC_VERSION=`cat "$NVMRC_PATH" | head -n 1`
|
||||
read NVM_RC_VERSION < "$NVMRC_PATH"
|
||||
echo "Found '$NVMRC_PATH' with version <$NVM_RC_VERSION>"
|
||||
fi
|
||||
}
|
||||
|
||||
# Expand a version using the version cache
|
||||
nvm_version() {
|
||||
local PATTERN=$1
|
||||
local PATTERN
|
||||
PATTERN=$1
|
||||
local VERSION
|
||||
# The default version is the current one
|
||||
if [ -z "$PATTERN" ]; then
|
||||
@@ -74,18 +97,19 @@ nvm_version() {
|
||||
echo "$VERSION"
|
||||
|
||||
if [ "$VERSION" = 'N/A' ]; then
|
||||
return
|
||||
return 3
|
||||
fi
|
||||
}
|
||||
|
||||
nvm_remote_version() {
|
||||
local PATTERN=$1
|
||||
local PATTERN
|
||||
PATTERN=$1
|
||||
local VERSION
|
||||
VERSION=`nvm_ls_remote $PATTERN | tail -n1`
|
||||
echo "$VERSION"
|
||||
|
||||
if [ "$VERSION" = 'N/A' ]; then
|
||||
return
|
||||
return 3
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -111,16 +135,24 @@ nvm_prepend_path() {
|
||||
|
||||
nvm_binary_available() {
|
||||
# binaries started with node 0.8.6
|
||||
local MINIMAL="0.8.6"
|
||||
local VERSION=$1
|
||||
local MINIMAL
|
||||
MINIMAL="0.8.6"
|
||||
local VERSION
|
||||
VERSION=$1
|
||||
[ $(nvm_normalize_version $VERSION) -ge $(nvm_normalize_version $MINIMAL) ]
|
||||
}
|
||||
|
||||
nvm_ls_current() {
|
||||
echo `node -v 2>/dev/null`
|
||||
}
|
||||
|
||||
nvm_ls() {
|
||||
local PATTERN=$1
|
||||
local VERSIONS=''
|
||||
local PATTERN
|
||||
PATTERN=$1
|
||||
local VERSIONS
|
||||
VERSIONS=''
|
||||
if [ "$PATTERN" = 'current' ]; then
|
||||
echo `node -v 2>/dev/null`
|
||||
nvm_ls_current
|
||||
return
|
||||
fi
|
||||
|
||||
@@ -129,38 +161,44 @@ nvm_ls() {
|
||||
return
|
||||
fi
|
||||
# If it looks like an explicit version, don't do anything funny
|
||||
if [ `expr "$PATTERN" : "v[[:digit:]]*\.[[:digit:]]*\.[[:digit:]]*$"` != 0 ]; then
|
||||
if [ `expr "$PATTERN" : "v[0-9]*\.[0-9]*\.[0-9]*$"` != 0 ]; then
|
||||
if [ -d "$NVM_DIR/$PATTERN" ]; then
|
||||
VERSIONS="$PATTERN"
|
||||
fi
|
||||
else
|
||||
VERSIONS=`find "$NVM_DIR/" -maxdepth 1 -type d -name "$(nvm_format_version $PATTERN)*" -exec basename '{}' ';' \
|
||||
| sort -t. -u -k 1.2,1n -k 2,2n -k 3,3n | grep -v '^ *\.'`
|
||||
PATTERN=$(nvm_format_version $PATTERN)
|
||||
if [ `expr "$PATTERN" : "v[0-9]*\.[0-9]*$"` != 0 ]; then
|
||||
PATTERN="$PATTERN."
|
||||
fi
|
||||
VERSIONS=`find "$NVM_DIR/" -maxdepth 1 -type d -name "$PATTERN*" -exec basename '{}' ';' \
|
||||
| sort -t. -u -k 1.2,1n -k 2,2n -k 3,3n | \grep -v '^ *\.'`
|
||||
fi
|
||||
if [ -z "$VERSIONS" ]; then
|
||||
echo "N/A"
|
||||
return
|
||||
return 3
|
||||
fi
|
||||
echo "$VERSIONS"
|
||||
return
|
||||
}
|
||||
|
||||
nvm_ls_remote() {
|
||||
local PATTERN=$1
|
||||
local PATTERN
|
||||
PATTERN=$1
|
||||
local VERSIONS
|
||||
local GREP_OPTIONS=''
|
||||
local GREP_OPTIONS
|
||||
GREP_OPTIONS=''
|
||||
if [ -n "$PATTERN" ]; then
|
||||
PATTERN=`nvm_format_version "$PATTERN"`
|
||||
else
|
||||
PATTERN=".*"
|
||||
fi
|
||||
VERSIONS=`curl -s $NVM_NODEJS_ORG_MIRROR/ \
|
||||
VERSIONS=`nvm_download -s $NVM_NODEJS_ORG_MIRROR/ -o - \
|
||||
| \egrep -o 'v[0-9]+\.[0-9]+\.[0-9]+' \
|
||||
| \grep -w "${PATTERN}" \
|
||||
| sort -t. -u -k 1.2,1n -k 2,2n -k 3,3n`
|
||||
if [ -z "$VERSIONS" ]; then
|
||||
echo "N/A"
|
||||
return
|
||||
return 3
|
||||
fi
|
||||
echo "$VERSIONS"
|
||||
return
|
||||
@@ -189,9 +227,10 @@ nvm_checksum() {
|
||||
nvm_print_versions() {
|
||||
local VERSION
|
||||
local FORMAT
|
||||
local CURRENT=`nvm_version current`
|
||||
local NVM_CURRENT
|
||||
NVM_CURRENT=$(nvm_ls_current)
|
||||
echo "$1" | while read VERSION; do
|
||||
if [ "$VERSION" = "$CURRENT" ]; then
|
||||
if [ "$VERSION" = "$NVM_CURRENT" ]; then
|
||||
FORMAT='\033[0;32m-> %9s\033[0m'
|
||||
elif [ -d "$NVM_DIR/$VERSION" ]; then
|
||||
FORMAT='\033[0;34m%12s\033[0m'
|
||||
@@ -209,10 +248,13 @@ nvm() {
|
||||
fi
|
||||
|
||||
# Try to figure out the os and arch for binary fetching
|
||||
local uname="$(uname -a)"
|
||||
local os=
|
||||
local arch="$(uname -m)"
|
||||
local GREP_OPTIONS=''
|
||||
local uname
|
||||
uname="$(uname -a)"
|
||||
local os
|
||||
local arch
|
||||
arch="$(uname -m)"
|
||||
local GREP_OPTIONS
|
||||
GREP_OPTIONS=''
|
||||
case "$uname" in
|
||||
Linux\ *) os=linux ;;
|
||||
Darwin\ *) os=darwin ;;
|
||||
@@ -260,11 +302,11 @@ nvm() {
|
||||
echo " nvm alias default 0.10.24 Set default node version on a shell"
|
||||
echo
|
||||
echo "Note:"
|
||||
echo " to remove, delete or uninstall nvm - just remove ~/.nvm, ~/.npm and ~/.bower folders"
|
||||
echo " to remove, delete, or uninstall nvm - just remove ~/.nvm, ~/.npm, and ~/.bower folders"
|
||||
echo
|
||||
;;
|
||||
|
||||
"install" )
|
||||
"install" | "i" )
|
||||
# initialize local variables
|
||||
local binavail
|
||||
local t
|
||||
@@ -272,11 +314,12 @@ nvm() {
|
||||
local sum
|
||||
local tarball
|
||||
local nobinary
|
||||
local version_not_provided=0
|
||||
local version_not_provided
|
||||
version_not_provided=0
|
||||
local provided_version
|
||||
|
||||
if ! nvm_has "curl"; then
|
||||
echo 'NVM Needs curl to proceed.' >&2;
|
||||
if ! nvm_has "nvm_download"; then
|
||||
echo 'nvm needs curl or wget to proceed.' >&2;
|
||||
return 1
|
||||
fi
|
||||
|
||||
@@ -339,12 +382,14 @@ nvm() {
|
||||
if nvm_binary_available "$VERSION"; then
|
||||
t="$VERSION-$os-$arch"
|
||||
url="$NVM_NODEJS_ORG_MIRROR/$VERSION/node-${t}.tar.gz"
|
||||
sum=`curl -s $NVM_NODEJS_ORG_MIRROR/$VERSION/SHASUMS.txt | \grep node-${t}.tar.gz | awk '{print $1}'`
|
||||
local tmpdir="$NVM_DIR/bin/node-${t}"
|
||||
local tmptarball="$tmpdir/node-${t}.tar.gz"
|
||||
sum=`nvm_download -s $NVM_NODEJS_ORG_MIRROR/$VERSION/SHASUMS.txt -o - | \grep node-${t}.tar.gz | awk '{print $1}'`
|
||||
local tmpdir
|
||||
tmpdir="$NVM_DIR/bin/node-${t}"
|
||||
local tmptarball
|
||||
tmptarball="$tmpdir/node-${t}.tar.gz"
|
||||
if (
|
||||
mkdir -p "$tmpdir" && \
|
||||
curl -L -C - --progress-bar $url -o "$tmptarball" && \
|
||||
nvm_download -L -C - --progress-bar $url -o "$tmptarball" && \
|
||||
nvm_checksum "$tmptarball" $sum && \
|
||||
tar -xzf "$tmptarball" -C "$tmpdir" --strip-components 1 && \
|
||||
rm -f "$tmptarball" && \
|
||||
@@ -352,7 +397,7 @@ nvm() {
|
||||
)
|
||||
then
|
||||
nvm use $VERSION
|
||||
return;
|
||||
return $?
|
||||
else
|
||||
echo "Binary download failed, trying source." >&2
|
||||
rm -rf "$tmptarball" "$tmpdir"
|
||||
@@ -370,18 +415,20 @@ nvm() {
|
||||
make='gmake'
|
||||
MAKE_CXX="CXX=c++"
|
||||
fi
|
||||
local tmpdir="$NVM_DIR/src"
|
||||
local tmptarball="$tmpdir/node-$VERSION.tar.gz"
|
||||
if [ "`curl -Is "$NVM_NODEJS_ORG_MIRROR/$VERSION/node-$VERSION.tar.gz" | \grep '200 OK'`" != '' ]; then
|
||||
local tmpdir
|
||||
tmpdir="$NVM_DIR/src"
|
||||
local tmptarball
|
||||
tmptarball="$tmpdir/node-$VERSION.tar.gz"
|
||||
if [ "`nvm_download -s -I "$NVM_NODEJS_ORG_MIRROR/$VERSION/node-$VERSION.tar.gz" -o - | \grep '200 OK'`" != '' ]; then
|
||||
tarball="$NVM_NODEJS_ORG_MIRROR/$VERSION/node-$VERSION.tar.gz"
|
||||
sum=`curl -s $NVM_NODEJS_ORG_MIRROR/$VERSION/SHASUMS.txt | \grep node-$VERSION.tar.gz | awk '{print $1}'`
|
||||
elif [ "`curl -Is "$NVM_NODEJS_ORG_MIRROR/node-$VERSION.tar.gz" | \grep '200 OK'`" != '' ]; then
|
||||
sum=`nvm_download -s $NVM_NODEJS_ORG_MIRROR/$VERSION/SHASUMS.txt -o - | \grep node-$VERSION.tar.gz | awk '{print $1}'`
|
||||
elif [ "`nvm_download -s -I "$NVM_NODEJS_ORG_MIRROR/node-$VERSION.tar.gz" -o - | \grep '200 OK'`" != '' ]; then
|
||||
tarball="$NVM_NODEJS_ORG_MIRROR/node-$VERSION.tar.gz"
|
||||
fi
|
||||
if (
|
||||
[ -n "$tarball" ] && \
|
||||
mkdir -p "$tmpdir" && \
|
||||
curl -L --progress-bar $tarball -o "$tmptarball" && \
|
||||
nvm_download -L --progress-bar $tarball -o "$tmptarball" && \
|
||||
nvm_checksum "$tmptarball" $sum && \
|
||||
tar -xzf "$tmptarball" -C "$tmpdir" && \
|
||||
cd "$tmpdir/node-$VERSION" && \
|
||||
@@ -400,10 +447,10 @@ nvm() {
|
||||
if [ "`expr "$VERSION" : '\(^v0\.2\.[0-2]$\)'`" != '' ]; then
|
||||
echo "npm requires node v0.2.3 or higher" >&2
|
||||
else
|
||||
curl https://npmjs.org/install.sh | clean=yes npm_install=0.2.19 sh
|
||||
nvm_download https://npmjs.org/install.sh -o - | clean=yes npm_install=0.2.19 sh
|
||||
fi
|
||||
else
|
||||
curl https://npmjs.org/install.sh | clean=yes sh
|
||||
nvm_download https://npmjs.org/install.sh -o - | clean=yes sh
|
||||
fi
|
||||
fi
|
||||
else
|
||||
@@ -507,11 +554,13 @@ nvm() {
|
||||
export NODE_PATH
|
||||
export NVM_PATH="$NVM_DIR/$VERSION/lib/node"
|
||||
export NVM_BIN="$NVM_DIR/$VERSION/bin"
|
||||
rm -f "$NVM_DIR/current" && ln -s "$NVM_DIR/$VERSION" "$NVM_DIR/current"
|
||||
echo "Now using node $VERSION"
|
||||
;;
|
||||
"run" )
|
||||
local provided_version
|
||||
local has_checked_nvmrc=0
|
||||
local has_checked_nvmrc
|
||||
has_checked_nvmrc=0
|
||||
# run given version of node
|
||||
shift
|
||||
if [ $# -lt 1 ]; then
|
||||
@@ -543,7 +592,7 @@ nvm() {
|
||||
|
||||
if [ ! -d "$NVM_DIR/$VERSION" ]; then
|
||||
echo "$VERSION version is not installed yet" >&2
|
||||
return;
|
||||
return 1
|
||||
fi
|
||||
RUN_NODE_PATH=`nvm_strip_path "$NODE_PATH" "/lib/node_modules"`
|
||||
RUN_NODE_PATH=`nvm_prepend_path "$NODE_PATH" "$NVM_DIR/$VERSION/lib/node_modules"`
|
||||
@@ -551,11 +600,15 @@ nvm() {
|
||||
NODE_PATH=$RUN_NODE_PATH $NVM_DIR/$VERSION/bin/node "$@"
|
||||
;;
|
||||
"ls" | "list" )
|
||||
nvm_print_versions "`nvm_ls $2`"
|
||||
local NVM_LS_OUTPUT
|
||||
local NVM_LS_EXIT_CODE
|
||||
NVM_LS_OUTPUT=$(nvm_ls "$2")
|
||||
NVM_LS_EXIT_CODE=$?
|
||||
nvm_print_versions "$NVM_LS_OUTPUT"
|
||||
if [ $# -eq 1 ]; then
|
||||
nvm alias
|
||||
fi
|
||||
return
|
||||
return $NVM_LS_EXIT_CODE
|
||||
;;
|
||||
"ls-remote" | "list-remote" )
|
||||
nvm_print_versions "`nvm_ls_remote $2`"
|
||||
@@ -611,8 +664,10 @@ nvm() {
|
||||
return 127
|
||||
fi
|
||||
VERSION=`nvm_version $2`
|
||||
local ROOT=`(nvm use $VERSION && npm -g root)`
|
||||
local ROOTDEPTH=$((`echo $ROOT | sed 's/[^\/]//g'|wc -m` -1))
|
||||
local ROOT
|
||||
ROOT=`(nvm use $VERSION && npm -g root)`
|
||||
local ROOTDEPTH
|
||||
ROOTDEPTH=$((`echo $ROOT | sed 's/[^\/]//g'|wc -m` -1))
|
||||
|
||||
# declare local INSTALLS first, otherwise it doesn't work in zsh
|
||||
local INSTALLS
|
||||
@@ -628,7 +683,7 @@ nvm() {
|
||||
nvm_version $2
|
||||
;;
|
||||
"--version" )
|
||||
echo "0.8.0"
|
||||
echo "0.11.0"
|
||||
;;
|
||||
"unload" )
|
||||
unset -f nvm nvm_print_versions nvm_checksum nvm_ls_remote nvm_ls nvm_remote_version nvm_version nvm_rc_version > /dev/null 2>&1
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "nvm",
|
||||
"version": "0.8.0",
|
||||
"version": "0.11.0",
|
||||
"description": "Node Version Manager - Simple bash script to manage multiple active node.js versions",
|
||||
"directories": {
|
||||
"test": "test"
|
||||
|
||||
@@ -2,11 +2,40 @@
|
||||
|
||||
mkdir ../../../v0.1.3
|
||||
mkdir ../../../v0.2.3
|
||||
mkdir ../../../v0.20.3
|
||||
|
||||
. ../../../nvm.sh
|
||||
|
||||
die () { echo $@ ; exit 1; }
|
||||
|
||||
# The result should contain only the appropriate version numbers.
|
||||
nvm ls 0.2 | grep v0.2.3 &&
|
||||
nvm ls 0.1 | grep -v v0.2.3 &&
|
||||
nvm ls 0.1 | grep v0.1.3 &&
|
||||
nvm ls v0.2 | grep v0.2.3
|
||||
|
||||
nvm ls 0.1 | grep 'v0.2.3' > /dev/null
|
||||
if [ $? -eq 0 ]; then
|
||||
echo '"nvm ls 0.1" contained v0.2.3'
|
||||
fi
|
||||
|
||||
nvm ls 0.1 | grep 'v0.20.3' > /dev/null
|
||||
if [ $? -eq 0 ]; then
|
||||
die '"nvm ls 0.1" contained v0.20.3'
|
||||
fi
|
||||
|
||||
nvm ls 0.1 | grep 'v0.1.3' > /dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
die '"nvm ls 0.1" did not contain v0.1.3'
|
||||
fi
|
||||
|
||||
nvm ls 0.2 | grep 'v0.2.3' > /dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
die '"nvm ls 0.2" did not contain v0.2.3'
|
||||
fi
|
||||
|
||||
nvm ls 0.2 | grep 'v0.20.3' > /dev/null
|
||||
if [ $? -eq 0 ]; then
|
||||
die '"nvm ls 0.2" contained v0.20.3'
|
||||
fi
|
||||
|
||||
nvm ls 0.2 | grep 'v0.2.3' > /dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
die '"nvm ls 0.2" did not contain v0.2.3'
|
||||
fi
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
#!/bin/sh
|
||||
|
||||
. ../../../nvm.sh
|
||||
|
||||
nvm ls nonexistent_version
|
||||
[ "$?" = "3" ]
|
||||
|
||||
@@ -8,3 +8,4 @@ nvm ls v0.1 | grep v0.1.2 &&
|
||||
nvm ls v0.1.2 | grep v0.1.2 &&
|
||||
nvm ls v0.1. | grep N/A &&
|
||||
nvm ls v0.1.1 | grep N/A
|
||||
|
||||
|
||||
11
test/fast/Listing versions/teardown
Normal file
11
test/fast/Listing versions/teardown
Normal file
@@ -0,0 +1,11 @@
|
||||
rmdir ../../../v0.0.1
|
||||
rmdir ../../../v0.0.3
|
||||
rmdir ../../../v0.0.9
|
||||
rmdir ../../../v0.1.2
|
||||
rmdir ../../../v0.1.3
|
||||
rmdir ../../../v0.2.3
|
||||
rmdir ../../../v0.3.1
|
||||
rmdir ../../../v0.3.3
|
||||
rmdir ../../../v0.3.9
|
||||
unalias nvm_has_system_node
|
||||
|
||||
32
test/fast/Running "nvm use x" should create and change the "current" symlink
Executable file
32
test/fast/Running "nvm use x" should create and change the "current" symlink
Executable file
@@ -0,0 +1,32 @@
|
||||
#!/bin/bash
|
||||
|
||||
. ../../nvm.sh
|
||||
|
||||
rm -rf ../../v0.10.29
|
||||
mkdir ../../v0.10.29
|
||||
nvm use 0.10.29
|
||||
rmdir ../../v0.10.29
|
||||
|
||||
if [ ! -L ../../current ];then
|
||||
echo "Expected 'current' symlink to be created!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
oldLink="$(readlink ../../current)"
|
||||
|
||||
if [ "$(basename $oldLink)" != 'v0.10.29' ];then
|
||||
echo "Expected 'current' to point to v0.10.29 but was $oldLink"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
rm -rf ../../v0.11.13
|
||||
mkdir ../../v0.11.13
|
||||
nvm use 0.11.13
|
||||
rmdir ../../v0.11.13
|
||||
|
||||
newLink="$(readlink ../../current)"
|
||||
|
||||
if [ "$(basename $newLink)" != 'v0.11.13' ];then
|
||||
echo "Expected 'current' to point to v0.11.13 but was $newLink"
|
||||
exit 1
|
||||
fi
|
||||
29
test/fast/Unit tests/nvm_has_system_node
Executable file
29
test/fast/Unit tests/nvm_has_system_node
Executable file
@@ -0,0 +1,29 @@
|
||||
#!/bin/sh
|
||||
|
||||
cleanup () {
|
||||
rm ../../../v0.1.2/node
|
||||
rmdir ../../../v0.1.2
|
||||
}
|
||||
die () { echo $@ ; exit 1; }
|
||||
|
||||
. ../../../nvm.sh
|
||||
|
||||
mkdir ../../../v0.1.2
|
||||
touch ../../../v0.1.2/node
|
||||
|
||||
nvm use 0.1.2
|
||||
|
||||
if command -v node; then
|
||||
nvm_has_system_node
|
||||
else
|
||||
! nvm_has_system_node
|
||||
fi
|
||||
|
||||
nvm deactivate /dev/null 2>&1
|
||||
|
||||
if command -v node; then
|
||||
nvm_has_system_node
|
||||
else
|
||||
! nvm_has_system_node
|
||||
fi
|
||||
|
||||
@@ -9,7 +9,7 @@ set -e
|
||||
|
||||
# Install from binary
|
||||
nvm install 0.9.7
|
||||
nvm install 0.9.12
|
||||
nvm i 0.9.12
|
||||
|
||||
# Check
|
||||
[ -d ../../../v0.9.7 ]
|
||||
|
||||
Reference in New Issue
Block a user