-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
Improve nvm_is_version_installed to check for a node executable instead of root dir #1824
Improve nvm_is_version_installed to check for a node executable instead of root dir #1824
Conversation
…le instead of root dir
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I think this is a great change.
As for making it even stricter, I don't think invoking node
is worth the slowdown.
@@ -130,7 +130,7 @@ nvm_has_system_iojs() { | |||
} | |||
|
|||
nvm_is_version_installed() { | |||
[ -n "${1-}" ] && [ -d "$(nvm_version_path "${1-}" 2> /dev/null)" ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll need to keep the [ -n "${1-}" ]
test, since nvm_version_path
will error on empty input.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That check was actually unnecessary before as without it, nvm_version_path
will print "version is required" to stderr which is eaten by /dev/null
, and so [ -d "" ]
will always exit with 1 as expected.
But with the new change, the check is actually required since we don't want the test argument to evaluate to /bin/node
if $1
isn't present. Good catch!
See e5be6b8.
oh also, could you add a test that would have failed without this change? Thanks! |
Added a test in |
test/installation_node/install hook
Outdated
@@ -19,6 +19,13 @@ fail() { | |||
|
|||
! nvm_is_version_installed "${VERSION}" || nvm uninstall "${VERSION}" || die 'uninstall failed' | |||
|
|||
# an existing but empty VERSION_PATH directory should not be enough to satisfy nvm_is_version_installed | |||
mkdir -p "${VERSION_PATH}" | |||
if [ -z "$(ls -A ${VERSION_PATH})" ]; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when would the dir be non-empty here, and wouldn't we want to fail the test if this is the case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you saying that the -z
test on ls -A
for empty dir is unnecessary? I guess in other words, am I right to assume that the $VERSION
is uninstalled after line 20 finishes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If uninstallation fails, line 20 would exit.
You could rm -rf "${VERSION_PATH} && mkdir -p "${VERSION_PATH}"
instead, though, just in case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, so assuming uninstallation is successful, $VERSION_PATH
shouldn't even exist after line 20. I did initially consider a rm -rf
but opted for a sanity check instead - that's what the if was for.
If we're 100% confident about the correctness of the non-zero exit code from nvm uninstall
, then we don't need to do anything just in case, and can remove the if statement altogether. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the if statement, with a non-empty folder, it silently skips this test. That's not good.
With nothing, with a non-empty folder, it silently tests the wrong thing. That's not good either.
In other words, if the precondition fails, either the whole test should blow up, or, it should be silently cleaned up so that the next test is actually testing something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good points! I can't really think of a better approach at the moment. 5b8da24
@ljharb The fast test suites have been failing across all my commits in this PR - does it look like a problem to you? |
@joshuarli hmm, yes it does :-/ it's possible that your change to make the check more strict, means that the mocks in tests need to fake node more thoroughly |
@ljharb Hey, sorry for the delay. So that seems to be correct - only the fast tests are failing since they mock node installations by just creating the dir (hence, fast). Conveniently, I started substituting a lot of the
Can you clarify what that is, and do you think it would be okay to just substitute the mkdir calls with
For reference, this is |
lol, i must have added it in preparation for other branches and never used it. Good catch! In that case, I think it should be two |
But
|
All versions < 0.12 are placed in the top-level dir. |
So would this be correct?
|
I would expect: make_fake_node v0.12.1
make_fake_node v0.1.3 since 186eb88#diff-daaa154e22be44798ffcddf12a70e03eR33 will handle the right version path |
Thanks, just wanted to make sure. You know |
I'm going to peel out the make_fake_node commit directly into master, and will rebase this PR once i do. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I'll fix this comment in the commit I land on master prior to rebasing this PR)
@@ -1,10 +1,11 @@ | |||
#!/bin/sh | |||
|
|||
\. ../../../nvm.sh | |||
\. ../../../common.sh |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there's a number of places where this path is incorrect; common.sh
is not a sibling of nvm.sh
, it's inside test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops! Sorry I missed that, staring at all those dots can get confusing sometimes 😆
@joshuarli the make_fake_node commit is now in master (thanks!), and this PR is rebased. Tests are still failing, however. |
Right, so there are some stray tests that looked out of the ordinary, so I didn't modify them with the previous commit (hence
What's the
|
In that case, it's the extracted source files for a to-be-compiled version of node v0.0.1 - it's not the same as |
Alright, down from 11 to 6 to 3 tests failed. Do you know what's going on here? I can't figure this out. This is line 594+ in the
|
The first test is doing these steps:
I think the |
@ljharb Thanks, that helped. Everything's green now :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
No problem, thanks for being a big help. |
For some context, this was causing issues described in getsentry/sentry#8623.
nvm_is_version_installed
should not be checking for the presence of an installed node version by simply checking the presence of a directory inversions/node
. It just isn't a strict enough check. One step would be to check for the presence of an executablebin/node
, which is what this PR implements.Even more strict would be to actually try and invoke
bin/node
itself afterwards, and comparing[ "$(node -v)" = "v${1}" ]
. Please let me know if that sounds good, or if you have any questions.