Skip to content
This repository has been archived by the owner on Dec 6, 2023. It is now read-only.

[WIP] Alias support #8

Merged
merged 17 commits into from
Jul 13, 2018
Merged

[WIP] Alias support #8

merged 17 commits into from
Jul 13, 2018

Conversation

duckontheweb
Copy link
Contributor

@duckontheweb duckontheweb commented Nov 14, 2017

Adds support for aliased version names recognized by nvm including lts/<release_name>, default, system.

Changes to Tests

Since we are now making more calls using child.spawn than just the nvm list command it was necessary to be more specific in how sinon mocked each all. The beforeEach hook now has logic to return different mocked responses based on the arguments.

Also added tests for alias and system support

Resolving Aliases v. System Node

The system alias case had to be handled separately from other aliases, primarily due to the difference in the way nvm handles those two cases. For most aliases, we use nvm version "<alias_name>" to resolve a specific installed version number, then nvm use <version_number> to activate that version. However, with system we need to use nvm use system rather than the specific version the system node, since that version was not installed via nvm and therefore will throw an error.

I wanted to be able to still log the actual version of node being used to keep things consistent with the logging for other version types, so I ended up propagating the value of system down through all of the methods that resolve a version and only find the actual version number at the end so that we can log out that info.

Addresses wbyoung/avn#43, wbyoung/avn#53

@wbyoung Let me know what suggestions/feedback you have.

@duckontheweb duckontheweb mentioned this pull request Nov 14, 2017
1 task
@duckontheweb duckontheweb changed the title [WIP] Alias support Alias support Nov 17, 2017
@duckontheweb
Copy link
Contributor Author

Changed to use nvm run --silent system --version to get system version according to comments by @ljharb here:

wbyoung/avn#43 (comment)

@duckontheweb
Copy link
Contributor Author

Build failures appear to be related to wbyoung/avn#66. All tests and jshint checks pass locally.

Copy link

@ljharb ljharb left a comment

Choose a reason for hiding this comment

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

LGTM overall

@@ -9,6 +9,32 @@ var name = require('./package.json').name;

var VERSION_REGEX = /(\w+)-(.+)/;

/**
Copy link

Choose a reason for hiding this comment

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

This comment appears inaccurate; if not present, it seems to be a rejected promise.

*
* @param {Promise} matching
*/
var parseMatching = function(matching) {
Copy link

Choose a reason for hiding this comment

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

String(x) is always preferable to x.toString()

@duckontheweb
Copy link
Contributor Author

Great, thanks for the feedback @ljharb. I've fixed those items.

@wbyoung
Copy link
Owner

wbyoung commented Nov 18, 2017

Looks great to me! Can you rebase on master to get the tests passing?

@coveralls
Copy link

Coverage Status

Coverage decreased (-1.3%) to 98.701% when pulling 54cbb2c on duckontheweb:alias-support into fd47799 on wbyoung:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage decreased (-1.3%) to 98.701% when pulling 54cbb2c on duckontheweb:alias-support into fd47799 on wbyoung:master.

@duckontheweb duckontheweb changed the title Alias support [WIP] Alias support Nov 18, 2017
@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 5dac9c3 on duckontheweb:alias-support into fd47799 on wbyoung:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 5dac9c3 on duckontheweb:alias-support into fd47799 on wbyoung:master.

@duckontheweb
Copy link
Contributor Author

@wbyoung Added a test for the case when the system node is not found, so the coverage is back up to 100% now.

})
.then(function(useVersion) {
var use = (useVersion && useVersion.indexOf('system') === 0) ?
'system' : useVersion;
Copy link
Owner

Choose a reason for hiding this comment

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

This has the ability to conflict with an alias defined as something like system-x, doesn’t it?

Perhaps the then handler above that decides to get the system node should also update a variable define in the scope of the match function body to store that choice & use it here.

Copy link
Contributor Author

@duckontheweb duckontheweb Nov 19, 2017

Choose a reason for hiding this comment

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

@wbyoung Actually, in this case useVersion will only ever start with system if the .nvmrc string is simply system, and not if it is something like system-x. The reason is that resolveVersion will resolve to an actual version number for aliases like system-x, which will then be propagated throughout the rest of the match method. I've added a test to check that this is the case in 42a4dbb.

@coveralls
Copy link

coveralls commented Nov 19, 2017

Coverage Status

Coverage decreased (-81.3%) to 18.667% when pulling 42a4dbb on duckontheweb:alias-support into fd47799 on wbyoung:master.

@glennreyes
Copy link

Anything left here to get this merged?

@wbyoung wbyoung merged commit 5056ef1 into wbyoung:master Jul 13, 2018
@mattduggan
Copy link

Is there a release slated for this?

@wbyoung
Copy link
Owner

wbyoung commented Feb 19, 2019

@mattduggan just published avn-nvm@0.2.2 which should include this. Thanks for the nudge. And sorry for the delay — kid number two has just arrived & is demanding a lot of attention. 😉

@glennreyes
Copy link

@wbyoung Thank you for publishing this! Congrats & enjoy the time!

@mattduggan
Copy link

Thank you @wbyoung! And congrats!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants