Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implements nvm which #583

Merged
merged 9 commits into from
Dec 17, 2014
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ Or, you can run any arbitrary command in a subshell with the desired version of

nvm exec 0.10 node --version

You can also get the path to the executable to where it was installed:

nvm which 0.10

In place of a version pointer like "0.10", you can use the special default aliases "stable" and "unstable":

nvm install stable
Expand Down
38 changes: 38 additions & 0 deletions nvm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,7 @@ nvm() {
echo " nvm unalias <name> Deletes the alias named <name>"
echo " nvm copy-packages <version> Install global NPM packages contained in <version> to current version"
echo " nvm unload Unload NVM from shell"
echo " nvm which [<version>] Display path to installed node version"
echo
echo "Example:"
echo " nvm install v0.10.24 Install a specific version number"
Expand Down Expand Up @@ -949,6 +950,43 @@ nvm() {
"current" )
nvm_version current
;;
"which" )
if [ $# -eq 1 ]; then
nvm_rc_version
if [ -n "$NVM_RC_VERSION" ]; then
VERSION=$(nvm_version $NVM_RC_VERSION)
fi
elif [ "_$2" != '_system' ]; then
VERSION="$(nvm_version "$2")"
else
VERSION="$2"
fi
if [ -z "$VERSION" ]; then
nvm help
return 127
fi

if [ "_$VERSION" = '_system' ]; then
if nvm_has_system_node >/dev/null 2>&1; then
echo $(dirname `which node`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per the previous comments - with a system node of 0.10.33, nvm use 0.9 && nvm which system would return 0.9.x, unless as the subshell command you have "$(nvm use system && dirname "$(which node)")"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, thanks

return
else
echo "System version of node not found." >&2
return 127
fi
elif [ "_$VERSION" = "_∞" ]; then
echo "The alias \"$2\" leads to an infinite loop. Aborting." >&2
return 8
fi

local NVM_VERSION_DIR
NVM_VERSION_DIR="$(nvm_version_path "$VERSION")"
if [ ! -d "$NVM_VERSION_DIR" ]; then
echo "$VERSION version is not installed yet" >&2
return 1
fi
echo $NVM_DIR/$VERSION/bin
;;
"alias" )
mkdir -p "$NVM_DIR/alias"
if [ $# -le 2 ]; then
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/sh

mkdir ../../../v0.0.2
mkdir ../../../v0.0.20

. ../../../nvm.sh

die () { echo $@ ; exit 1; }

# The result should contain only the appropriate version numbers.

nvm which 0.0.2 | grep "$NVM_DIR/v0.0.2/bin" > /dev/null
if [ $? -ne 0 ]; then
die '"nvm which 0.0.2" did not contain the correct path'
fi

nvm which 0.0.20 | grep "$NVM_DIR/v0.0.20/bin" > /dev/null
if [ $? -ne 0 ]; then
die '"nvm which 0.0.2" did not contain the correct path'
fi
2 changes: 2 additions & 0 deletions test/fast/Listing paths/teardown
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
rmdir ../../../v0.0.2 >/dev/null 2>&1
rmdir ../../../v0.0.20 >/dev/null 2>&1