Shell functions are not automatically exported when declared, which
turned out to be problematic when sourcing the `nvm.sh` file from a
login shell. Non-login shells, which are children of the login shell,
do not see the `nvm` function when it's sourced from `~/.profile` and
other similar profile files.
Take the following code as an example (using bash):
$ foo() { echo 1; } # in login shell
$ foo
1
$ bash # in non-login shell now
$ foo
bash: foo: command not found
`foo` is not seen by the second bash instance, even though it has been
declared by its parent process.
One of the solutions is to export `foo` right after declaring it by
doing `export -f NAME`:
$ foo() { echo 1; } # in login shell
$ export -f foo
$ bash # in non-login shell now
$ foo
1
This commit does the same to the `nvm` function and its dependencies.
Adds the following information to the "Migrating global packages while installing" section:
- notification that the npm package is explicitly not updated when using the --reinstall-packages-from flag
- information about the --latest-npm flag
- recovery instructions if a user has already updated node with an incompatible npm version
- Operating system and version: Mac OS X Mojave
- What happened? $NVM_DIR was set to nvm
- What did you expect to happen? $NVM_DIR should be set to .nvm
I added the following line from the README to my .zshrc:
```
export NVM_DIR="${XDG_CONFIG_HOME/:-$HOME/.}nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
```
I couldn't figure out why nvm wasn't loading, until I realized that
`echo NVM_DIR="${XDG_CONFIG_HOME/:-$HOME/.}nvm"` outputs `NVM_DIR=nvm`.
Changing the line to `export NVM_DIR="${XDG_CONFIG_HOME/:-$HOME/}.nvm"` fixed the problem. This outputs `NVM_DIR=.nvm` as expected. I tested this and the same behavior holds true in Bash as well.
It was trying to read ./.nvmrc if you cd'ed into a subdirectory of the directory that has .nvmrc, which would give print `-bash: ./.nvmrc: No such file or directory` to stderr and potentially not doing the `nvm install`.
With the environment variable XDG_CONFIG_HOME set, the installation
script uses the directory $XDG_CONFIG_HOME/nvm now. Before the change
the variable's value with "/nvm" cut off was used, which usually results
in an installation without any subdirectory.
- fix test 'Running "nvm ls" should display all installed versions.': only expect versions created by this test, but no versions created by other tests