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

Add --install option when sourcing nvm.sh #545

Closed
mgol opened this issue Oct 6, 2014 · 7 comments · Fixed by #602
Closed

Add --install option when sourcing nvm.sh #545

mgol opened this issue Oct 6, 2014 · 7 comments · Fixed by #602
Assignees
Labels
feature requests I want a new feature in nvm! installing node Issues with installing node/io.js versions.
Milestone

Comments

@mgol
Copy link
Contributor

mgol commented Oct 6, 2014

In my Jenkins setup, running on Bash 4.3.11(1) on Ubuntu 14.04.1 LTS, nvm is installed in the following way:

git clone https://github.com/creationix/nvm.git ~/.nvm
cd ~/.nvm
git checkout `git describe --abbrev=0 --tags`

This results in checking out 0.17.2 currently. Then, in the run script it's activated via:

. ~/.nvm/nvm.sh

which errors with N/A version is not installed yet, breaking the build. If I don't require all commands to end with status 0, and invoke nvm install with .nvmrc concaining 0.10 afterwards, it works fine.

The only problem seems to be the initial error.

@ljharb
Copy link
Member

ljharb commented Oct 6, 2014

The code at the end of nvm.sh is designed to always return a zero exit code - when I have no default specified or .nvmrc file present, I get no error sourcing nvm.sh.

However, I do see that if I have a .nvmrc file referencing a not-yet-installed version, it will output that error.

Certainly this might be surprising the first time you source nvm.sh - but what would you expect to happen every time you open a shell, if you have a .nvmrc that refers to an uninstalled node version?

Could you perhaps wait to create a .nvmrc file until after you've installed the version you want to use?

@mgol
Copy link
Contributor Author

mgol commented Oct 6, 2014

Could you perhaps wait to create a .nvmrc file until after you've installed the version you want to use?

That doesn't fit the scenario... We have the .nvmrc file in the repo so that it's clear on which Node version we need to test. Then, in the Jenkins run we download nvm, activate it and do nvm install in the repo directory to download and activate the requested Node version.

We would have to cache the .nvmrc contents, delete the file, install nvm, activate it, then recreate .nvmrc and do nvm install... You can see it's not exactly an ideal solution. :)

@mgol
Copy link
Contributor Author

mgol commented Oct 6, 2014

There are many solutions to my problem that doesn't require to resign from the logic you describe; perhaps ~/.nvm/nvm.sh --install could try to install the requested version and not fail if that succeeds?

@ljharb
Copy link
Member

ljharb commented Oct 6, 2014

I like that suggestion; I'll take a look at that.

@ljharb
Copy link
Member

ljharb commented Oct 6, 2014

@mzgol I can definitely add support for . $NVM_DIR/nvm.sh --install - however, if it was already installed, that would output something like "v0.10.32 is already installed." to stderr. Would that be acceptable, since it would still exit zero and otherwise function?

@mgol
Copy link
Contributor Author

mgol commented Oct 6, 2014

@ljharb Sure! I just care so that it doesn't error. :)

@ljharb ljharb self-assigned this Oct 7, 2014
@ljharb ljharb added this to the v1.0.0 milestone Oct 7, 2014
@ljharb ljharb added installing node Issues with installing node/io.js versions. feature requests I want a new feature in nvm! labels Oct 15, 2014
@ljharb
Copy link
Member

ljharb commented Nov 26, 2014

I'm having trouble with this since it seems like dash and sh don't allow options to be passed when sourcing something. I also tried using environment variables, but it seems that dash, at least, will automatically export env vars - ie, FOO=1 bar will leave $FOO set to "1" if it was previously unset.

(see http://unix.stackexchange.com/questions/5024/passing-a-variable-to-a-bash-script-when-sourcing-it-in-another-bash-script)

@ljharb ljharb changed the title "N/A version is not installed yet" on nvm 0.17.2 Add --install option when sourcing nvm.sh Dec 21, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature requests I want a new feature in nvm! installing node Issues with installing node/io.js versions.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants