Compare commits

..

32 Commits

Author SHA1 Message Date
Jordan Harband
61709c1f97 v0.13.0 2014-08-02 19:24:39 -07:00
Jordan Harband
1a8479ed31 Merge pull request #491 from creationix/nvm_exec
Add `nvm exec` command.
2014-08-02 19:23:05 -07:00
Jordan Harband
a703d3591f Tweaking the readme description 2014-08-02 19:22:53 -07:00
Jordan Harband
1fa2acf5a7 Adding nvm exec tests. 2014-08-02 15:43:04 -07:00
Jordan Harband
d5c0e94166 Adding nvm exec command. 2014-08-01 01:26:33 -07:00
Jordan Harband
6dc602b521 Ensure that nvm ls node doesn't return "node_modules", for example. 2014-08-01 01:24:28 -07:00
Jordan Harband
1d37af162a v0.12.2 2014-07-29 00:35:27 -07:00
Jordan Harband
781373f7ce Make sure awk is referenced unaliased, per https://github.com/creationix/nvm/issues/162#issuecomment-50284503 2014-07-27 23:02:22 -07:00
Jordan Harband
68574cc7e8 v0.12.1 2014-07-24 14:07:26 -07:00
Jordan Harband
0f3b06320e Merge pull request #481 from johnloy/master
Changes $path var to $node_path. Fixes #482.
2014-07-24 14:07:05 -07:00
John Loy
d181abb628 Changes $path var to $node_path
Avoids obliteration of $path set earlier by Prezto/zsh. Stomping on $path causes dirname to not be in the PATH resulting in an error.
2014-07-24 15:28:33 -04:00
Jordan Harband
f5643dc7ea v0.12.0 2014-07-23 01:15:14 -07:00
Jordan Harband
6bcac7f638 Merge pull request #480 from fjakobs/patch-1
install.sh: make sure to not error out if master branch does not exist
2014-07-23 01:14:41 -07:00
Fabian Jakobs
ad71389dcc master branch might not exist
After a fresh install I was unable to run the installer again. It was breaking with the error

error: branch 'master' not found.

my fix makes sure that the installer continues after that.
2014-07-23 10:08:58 +02:00
Jordan Harband
8cbf149558 Merge pull request #408 from creationix/nvm_system_awareness
Add `system` awareness to `nvm use`, `nvm ls`, and `nvm current`.
2014-07-21 22:55:27 -07:00
Jordan Harband
e7ada80d08 nvm use system should work as expected. 2014-07-21 02:03:18 -07:00
Jordan Harband
9912f7cc46 If nvm is deactivated, display "none" or "system" instead of the system node version 2014-07-21 02:03:18 -07:00
Jordan Harband
6e02e5a54c If nvm_ls is called without a pattern, and node exists, tack on "system". 2014-07-21 02:03:18 -07:00
Jordan Harband
42b010775b Add system support to nvm_print_versions 2014-07-21 02:03:18 -07:00
Jordan Harband
1c50c5c7aa Add nvm_tree_contains_path function 2014-07-21 02:03:04 -07:00
Jordan Harband
200a9aa97e v0.11.2 2014-07-20 23:58:19 -07:00
Jordan Harband
4512337c11 Adding a slow nvm current test, since it needs an installed version of node. 2014-07-20 23:41:11 -07:00
Jordan Harband
55677dba4a Avoid calling "nvm_ls current" and call "nvm_ls_current" directly 2014-07-20 23:40:20 -07:00
Jordan Harband
ca43ca21f5 Fix curl/wget detection. Fixes #478 2014-07-18 13:18:09 -07:00
Jordan Harband
fafbeb8c59 Merge pull request #479 from koenpunt/fix-args-replacement
string replacement turns out not POSIX compliant
2014-07-18 13:15:13 -07:00
Koen Punt
9c2127ce33 string replacement turns out not POSIX compliant 2014-07-18 16:21:20 +02:00
Jordan Harband
5ec0ccec1b Fixing make release to also cover package.json.
Per a3de7f3222 (commitcomment-7057689)
2014-07-18 01:49:57 -07:00
Jordan Harband
7a423b7bb4 v0.11.1 2014-07-18 01:48:46 -07:00
Jordan Harband
a3de7f3222 Fixing make release - amending a tagged commit makes the commit not match the tag. 2014-07-17 00:25:14 -07:00
Jordan Harband
55d892adc8 Fix #476 by making sure to cd into $NVM_DIR before checking out the tag. Also delete the master branch, because we won't be needing that. 2014-07-17 00:20:33 -07:00
Jordan Harband
3b42df8d1d Merge pull request #474 from mzgol/wget-hotfix
Hotfix: correctly map curl's `-C -` to wget
2014-07-16 10:16:18 -07:00
Michał Gołębiowski
21fa84225c Hotfix: correctly map curl's -C - to wget
wget doesn't need or accept the `-` parameter to `-c`. This incorrect
mapping causes `nvm install` to fail on a curlless OS.
2014-07-16 11:00:56 +02:00
15 changed files with 238 additions and 37 deletions

View File

@@ -20,6 +20,7 @@ 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
replace "$${OLD_TAG/v/}" "$(TAG)" -- nvm.sh install.sh README.markdown package.json && \
git commit -m "v$(TAG)" nvm.sh install.sh README.markdown package.json && \
git tag "v$(TAG)"

View File

@@ -8,11 +8,11 @@ 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.11.0/install.sh | bash
curl https://raw.githubusercontent.com/creationix/nvm/v0.13.0/install.sh | bash
or Wget:
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.11.0/install.sh | bash
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.13.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>
@@ -38,7 +38,7 @@ Often I also put in a line to use a specific version of node.
## Usage
You can create an `.nvmrc` file containing version number in the project root directory (or any parent directory).
`nvm use`, `nvm install`, and `nvm run` will all respect an `.nvmrc` file.
`nvm use`, `nvm install`, `nvm exec`, and `nvm run` will all respect an `.nvmrc` file.
To download, compile, and install the latest v0.10.x release of node, do this:
@@ -52,6 +52,10 @@ Or you can just run it:
nvm run 0.10 --version
Or, you can run any arbitrary command in a subshell with the desired version of node:
nvm exec 0.10 node --version
If you want to see what versions are installed:
nvm ls
@@ -163,7 +167,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.11.0/install.sh
[2]: https://github.com/creationix/nvm/blob/v0.13.0/install.sh
[3]: https://travis-ci.org/creationix/nvm
[Urchin]: https://github.com/scraperwiki/urchin

View File

@@ -16,13 +16,12 @@ nvm_download() {
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 }
ARGS=$(echo "$*" | sed -e 's/--progress-bar /--progress=bar /' \
-e 's/-L //' \
-e 's/-I //' \
-e 's/-s /-q /' \
-e 's/-o /-O /' \
-e 's/-C - /-c /')
wget $ARGS
fi
}
@@ -35,8 +34,8 @@ install_nvm_from_git() {
if [ -d "$NVM_DIR/.git" ]; then
echo "=> nvm is already installed in $NVM_DIR, trying to update"
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
cd "$NVM_DIR" && (git fetch 2> /dev/null || {
echo >&2 "Failed to update nvm, run 'git fetch' in $NVM_DIR yourself." && exit 1
})
else
# Cloning to $NVM_DIR
@@ -45,12 +44,12 @@ install_nvm_from_git() {
mkdir -p "$NVM_DIR"
git clone "$NVM_SOURCE" "$NVM_DIR"
fi
git checkout v0.11.0
cd $NVM_DIR && git checkout v0.13.0 && git branch -D master || true
}
install_nvm_as_script() {
if [ -z "$NVM_SOURCE" ]; then
NVM_SOURCE="https://raw.githubusercontent.com/creationix/nvm/v0.11.0/nvm.sh"
NVM_SOURCE="https://raw.githubusercontent.com/creationix/nvm/v0.13.0/nvm.sh"
fi
# Downloading to $NVM_DIR

97
nvm.sh
View File

@@ -17,13 +17,12 @@ nvm_download() {
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 }
ARGS=$(echo "$*" | sed -e 's/--progress-bar /--progress=bar /' \
-e 's/-L //' \
-e 's/-I //' \
-e 's/-s /-q /' \
-e 's/-o /-O /' \
-e 's/-C - /-c /')
wget $ARGS
fi
}
@@ -54,6 +53,19 @@ if [ -z "$NVM_NODEJS_ORG_MIRROR" ]; then
export NVM_NODEJS_ORG_MIRROR="http://nodejs.org/dist"
fi
nvm_tree_contains_path() {
local tree
tree="$1"
local node_path
node_path="$2"
local pathdir
pathdir=$(dirname "$node_path")
while [ "$pathdir" != "" ] && [ "$pathdir" != "." ] && [ "$pathdir" != "/" ] && [ "$pathdir" != "$tree" ]; do
pathdir=$(dirname "$pathdir")
done
[ "$pathdir" = "$tree" ]
}
# Traverse up in directory tree to find containing folder
nvm_find_up() {
local path
@@ -93,6 +105,11 @@ nvm_version() {
PATTERN='current'
fi
if [ "$PATTERN" = "current" ]; then
nvm_ls_current
return $?
fi
VERSION=`nvm_ls $PATTERN | tail -n1`
echo "$VERSION"
@@ -114,7 +131,7 @@ nvm_remote_version() {
}
nvm_normalize_version() {
echo "$1" | sed -e 's/^v//' | awk -F. '{ printf("%d%03d%03d\n", $1,$2,$3); }'
echo "$1" | sed -e 's/^v//' | \awk -F. '{ printf("%d%03d%03d\n", $1,$2,$3); }'
}
nvm_format_version() {
@@ -143,7 +160,15 @@ nvm_binary_available() {
}
nvm_ls_current() {
echo `node -v 2>/dev/null`
local NODE_PATH
NODE_PATH="$(which node)"
if [ $? -ne 0 ]; then
echo 'none'
elif nvm_tree_contains_path "$NVM_DIR" "$NODE_PATH"; then
echo `node -v 2>/dev/null`
else
echo 'system'
fi
}
nvm_ls() {
@@ -171,12 +196,15 @@ nvm_ls() {
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 '^ *\.'`
| sort -t. -u -k 1.2,1n -k 2,2n -k 3,3n | \grep -v '^ *\.' | \grep -e '^v'`
fi
if [ -z "$VERSIONS" ]; then
echo "N/A"
return 3
fi
if [ -z "$PATTERN" ] && nvm_has_system_node; then
VERSIONS="$VERSIONS$(printf '\n%s' 'system')"
fi
echo "$VERSIONS"
return
}
@@ -206,11 +234,11 @@ nvm_ls_remote() {
nvm_checksum() {
if nvm_has "shasum"; then
checksum=$(shasum $1 | awk '{print $1}')
checksum=$(shasum $1 | \awk '{print $1}')
elif nvm_has "sha1"; then
checksum=$(sha1 -q $1)
else
checksum=$(sha1sum $1 | awk '{print $1}')
checksum=$(sha1sum $1 | \awk '{print $1}')
fi
if [ "$checksum" = "$2" ]; then
@@ -234,6 +262,8 @@ nvm_print_versions() {
FORMAT='\033[0;32m-> %9s\033[0m'
elif [ -d "$NVM_DIR/$VERSION" ]; then
FORMAT='\033[0;34m%12s\033[0m'
elif [ "$VERSION" = "system" ]; then
FORMAT='\033[0;33m%12s\033[0m'
else
FORMAT='%12s'
fi
@@ -318,7 +348,7 @@ nvm() {
version_not_provided=0
local provided_version
if ! nvm_has "nvm_download"; then
if ! nvm_has "curl" && ! nvm_has "wget"; then
echo 'nvm needs curl or wget to proceed.' >&2;
return 1
fi
@@ -382,7 +412,7 @@ nvm() {
if nvm_binary_available "$VERSION"; then
t="$VERSION-$os-$arch"
url="$NVM_NODEJS_ORG_MIRROR/$VERSION/node-${t}.tar.gz"
sum=`nvm_download -s $NVM_NODEJS_ORG_MIRROR/$VERSION/SHASUMS.txt -o - | \grep node-${t}.tar.gz | awk '{print $1}'`
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
@@ -421,7 +451,7 @@ nvm() {
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=`nvm_download -s $NVM_NODEJS_ORG_MIRROR/$VERSION/SHASUMS.txt -o - | \grep node-$VERSION.tar.gz | awk '{print $1}'`
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
@@ -520,7 +550,17 @@ nvm() {
VERSION=`nvm_version $NVM_RC_VERSION`
fi
else
VERSION=`nvm_version $2`
if [ $2 = 'system' ]; then
if nvm_has_system_node && nvm deactivate; then
echo "Now using system version of node: $(node -v 2>/dev/null)."
return
else
echo "System version of node not found." >&2
return 127
fi
else
VERSION=`nvm_version $2`
fi
fi
if [ -z "$VERSION" ]; then
nvm help
@@ -599,6 +639,29 @@ nvm() {
echo "Running node $VERSION"
NODE_PATH=$RUN_NODE_PATH $NVM_DIR/$VERSION/bin/node "$@"
;;
"exec" )
shift
local provided_version
provided_version=$1
if [ -n "$provided_version" ]; then
VERSION=`nvm_version $provided_version`
if [ $VERSION = "N/A" ]; then
provided_version=''
nvm_rc_version
VERSION=`nvm_version $NVM_RC_VERSION`
else
shift
fi
fi
if [ ! -d "$NVM_DIR/$VERSION" ]; then
echo "$VERSION version is not installed yet" >&2
return 1
fi
echo "Running node $VERSION"
NODE_VERSION=$VERSION $NVM_DIR/nvm-exec "$@"
;;
"ls" | "list" )
local NVM_LS_OUTPUT
local NVM_LS_EXIT_CODE
@@ -683,7 +746,7 @@ nvm() {
nvm_version $2
;;
"--version" )
echo "0.11.0"
echo "0.13.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

View File

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

View File

@@ -0,0 +1,7 @@
#!/bin/sh
. ../../../nvm.sh
nvm ls node
[ "$?" = "3" ]

View File

@@ -0,0 +1,21 @@
#!/bin/sh
die () { echo $@ ; exit 1; }
. ../../../nvm.sh
mkdir -p ../../../v0.0.1
mkdir -p ../../../v0.0.3
mkdir -p ../../../v0.0.9
mkdir -p ../../../v0.3.1
mkdir -p ../../../v0.3.3
mkdir -p ../../../v0.3.9
nvm_has_system_node() { return 0; }
nvm ls | grep system 2>&1 > /dev/null
[ $? -eq 0 ] || die '"nvm ls" did not contain "system" when system node is present'
nvm_has_system_node() { return 1; }
nvm ls | grep system 2>&1 > /dev/null
[ $? -ne 0 ] || die '"nvm ls" contained "system" when system node is not present'

View File

@@ -3,4 +3,8 @@
die () { echo $@ ; exit 1; }
. ../../nvm.sh
[ "$(nvm current)" = "$(node -v)" ] || die "Failed to find current version"
nvm deactivate 2>&1
[ "$(nvm current)" = "system" ] || [ "$(nvm current)" = "none" ] || die '"nvm current" did not report "system" or "none" when deactivated'

View File

@@ -0,0 +1,13 @@
#!/bin/sh
die () { echo $@ ; exit 1; }
. ../../nvm.sh
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_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 use system 2>&1 > /dev/null || [ $? -eq 127 ] || die "Did not return error code, system node not found"

View File

@@ -0,0 +1,27 @@
#!/bin/sh
cleanup () {
rm tmp/node
rmdir tmp
rm tmp2/node
rmdir tmp2
}
die () { echo $@ ; cleanup; exit 1; }
. ../../../nvm.sh
mkdir -p tmp
touch -p tmp/node
mkdir -p tmp2
touch -p tmp2/node
nvm_tree_contains_path tmp tmp/node || die '"tmp" should contain "tmp/node"'
nvm_tree_contains_path tmp tmp2/node && die '"tmp" should not contain "tmp2/node"'
nvm_tree_contains_path tmp2 tmp2/node || die '"tmp2" should contain "tmp2/node"'
nvm_tree_contains_path tmp2 tmp/node && die '"tmp2" should not contain "tmp/node"'
cleanup

View File

@@ -0,0 +1,10 @@
#!/bin/sh
die () { echo $@ ; exit 1; }
. ../../nvm.sh
nvm install 0.10
[ "$(nvm current)" = "$(node -v)" ] || die "Failed to find current version: got \"$(nvm current)\", expected \"$(node -v)\""

View File

@@ -0,0 +1,13 @@
#!/bin/sh
die () { echo $@ ; exit 1; }
. ../../../nvm.sh
nvm use 0.10
NPM_VERSION_TEN="$(npm --version)"
nvm use 0.11.7 && [ "$(node --version)" = "v0.11.7" ] || die "\`nvm use\` failed!"
[ "$(nvm exec 0.10 npm --version | tail -1)" = "$NPM_VERSION_TEN" ] || die "`nvm exec` failed to run with the correct version"

View File

@@ -0,0 +1,17 @@
#!/bin/sh
die () { echo $@ ; exit 1; }
. ../../../nvm.sh
nvm use 0.10.7
NPM_VERSION_TEN="$(npm --version)"
nvm use 0.11.7 && [ "$(node --version)" = "v0.11.7" ] || die "\`nvm use\` failed!"
echo "0.10.7" > .nvmrc
[ "$(nvm exec npm --version | tail -1)" = "$NPM_VERSION_TEN" ] || die "\`nvm exec\` failed to run with the .nvmrc version"
[ "$(nvm exec npm --version | head -1)" = "Found '$PWD/.nvmrc' with version <0.10.7>" ] || die "\`nvm exec\` failed to print out the \"found in .nvmrc\" message"

10
test/slow/nvm exec/setup_dir Executable file
View File

@@ -0,0 +1,10 @@
#!/bin/sh
. ../../../nvm.sh
nvm install 0.10.7
nvm install 0.11.7
if [ -f ".nvmrc" ]; then
mv .nvmrc .nvmrc.bak
fi

12
test/slow/nvm exec/teardown_dir Executable file
View File

@@ -0,0 +1,12 @@
#!/bin/sh
. ../../../nvm.sh
nvm uninstall v0.10.7
nvm uninstall v0.11.7
rm .nvmrc
if [ -f ".nvmrc.bak" ]; then
mv .nvmrc.bak .nvmrc
fi