Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Adding a symlink in .nvm to the current version. #467

Merged
merged 1 commit into from

4 participants

@jsdevel

While working on some c++ add-ons, I thought it would be handy to have this change in my IDE.

@koenpunt

Duplicate of #447

@ljharb
Collaborator

Thanks for the contribution! However, I think #447's approach is more appropriate - this will show up in the output of nvm ls, and current makes more sense to me (and is more consistent with rvm/rbenv) than node.

In addition, this would need tests before I'd merge it.

@ljharb ljharb self-assigned this
@jsdevel

I added a test. @danielb2 I apologize for duplicating the effort. Feel free to use my tests if you'd rather have your Pull Request accepted.

@ljharb @koenpunt feedback is welcomed on the testing approach.

@ljharb
Collaborator

Thanks for the test! I think this could actually be a fast test - there's no need to actually do the install, just mkdir should be enough to verify. The bonus is that then it'd get tested on all the shells.

...use x" should create and change the "current" symlink
@@ -0,0 +1,24 @@
+#!/bin/bash
+
+. ../../nvm.sh
+
+nvm install 0.10
@ljharb Collaborator
ljharb added a note

fast tests can't call nvm install - this should make a directory. Check out the other fast tests for examples. (same below)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@danielb2

My test is using the fast test already and should be good to go. Thoughts on it?

@jsdevel

@ljharb updated the test to not install.

@jsdevel

@danielb2 I found the test in #447 harder to understand.

@jsdevel

@ljharb I removed the line in nvm.sh and the tests failed, so once the Travis build passes I think we're good to go (barring any other style / code changes recommended). @danielb2 again sorry for the dupe.

nvm.sh
@@ -542,6 +542,7 @@ 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
@ljharb Collaborator
ljharb added a note

not a blocker, but it would be good to wrap each of the file paths in double quotes, in case there's any spaces or special chars in $NVM_DIR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@ljharb
Collaborator

It looks like your test is checking that the link is created, and changed - but not checking what it points to. Could you add checks that its path includes the expected version number in both cases?

...use x" should create and change the "current" symlink
((17 lines not shown))
+ echo "Expected 'current' to point to $oldLink"
+ exit 1
+fi
+
+rm -rf ../../v0.11.13
+mkdir ../../v0.11.13
+nvm use 0.11.13
+
+newLink="$(readlink ../../current)"
+
+if [ "$(basename $newLink)" != 'v0.11.13' ];then
+ echo "Expected 'current' to point to $newLink"
+ exit 1
+fi
+
+if [ "$oldLink" == "$newLink" ];then
@jsdevel
jsdevel added a note

@ljharb this test is probably redundant now. Thoughts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@ljharb
Collaborator

This looks great. I'll think on it a bit before merging, but I'm thinking I will soon :-)

@jsdevel

Thanks @ljharb! Please let me know if you'd like me to make any more updates. I look forward to having the symlink there in master for my c++ add-on development :)

@ljharb ljharb merged commit 8f66273 into creationix:master
@jsdevel jsdevel deleted the jsdevel:adding-current-symlink branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 12, 2014
  1. @jsdevel
This page is out of date. Refresh to see the latest.
View
2  .gitignore
@@ -11,4 +11,4 @@ test/bak
node_modules/
.DS_Store
-
+current
View
1  nvm.sh
@@ -542,6 +542,7 @@ 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" )
View
30 test/fast/Running "nvm use x" should create and change the "current" symlink
@@ -0,0 +1,30 @@
+#!/bin/bash
+
+. ../../nvm.sh
+
+rm -rf ../../v0.10.29
+mkdir ../../v0.10.29
+nvm use 0.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
+
+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
Something went wrong with that request. Please try again.