diff --git a/modules/node/README.md b/modules/node/README.md index 315a7d2..2de4faa 100644 --- a/modules/node/README.md +++ b/modules/node/README.md @@ -3,23 +3,23 @@ Provides utility functions for [Node.js][1], loads the Node Version Manager, and enables [_npm_][2] completion. -## nvm - -[_nvm_][5] allows for managing multiple, isolated Node.js installations in the -home directory. - -This will be loaded automatically if nvm is installed in `$NVM_DIR`, -_`$XDG_CONFIG_HOME/nvm`_, _`~/.nvm`_, or is installed with homebrew. - ## nodenv -[_nodenv_][6] does one thing well - it is concerned solely with switching +[_nodenv_][5] does one thing well - it is concerned solely with switching Node versions. It is simple and predictable, Just Works, and is rock solid in -production. nodenv is forked from the popular [_rbenv_][7]. +production. nodenv is forked from the popular [_rbenv_][6]. This will be loaded automatically if nodenv is installed in `$NODENV_ROOT`, _`$XDG_CONFIG_HOME/nodenv`_, _`~/.nodenv`_, or `nodenv` is on the path. +## nvm + +[_nvm_][7] allows for managing multiple, isolated Node.js installations in the +home directory. + +This will be loaded automatically if nvm is installed in `$NVM_DIR`, +_`$XDG_CONFIG_HOME/nvm`_, _`~/.nvm`_, or is installed with homebrew. + ## Functions - `node-doc` opens the Node.js online [API documentation][3] in the default @@ -52,6 +52,6 @@ _The authors of this module should be contacted via the [issue tracker][4]._ [2]: http://npmjs.org [3]: http://nodejs.org/api [4]: https://github.com/sorin-ionescu/prezto/issues -[5]: https://github.com/nvm-sh/nvm -[6]: https://github.com/nodenv/nodenv -[7]: https://github.com/sstephenson/rbenv +[5]: https://github.com/nodenv/nodenv +[6]: https://github.com/sstephenson/rbenv +[7]: https://github.com/nvm-sh/nvm diff --git a/modules/node/functions/node-info b/modules/node/functions/node-info index c43759b..7a59127 100644 --- a/modules/node/functions/node-info +++ b/modules/node/functions/node-info @@ -15,12 +15,12 @@ local version_formatted unset node_info typeset -gA node_info -if (( $+functions[nvm_version] )); then - version="${$(nvm_version)#v}" -elif (( $+commands[nodenv] )); then +if (( $+commands[nodenv] )); then version="${${$(nodenv version)#v}[(w)0]}" +elif (( $+functions[nvm_version] )); then + version="${$(nvm_version)#v}" elif (( $+commands[node] )) ; then - version="${$(node -v)#v}" + version="${$(node -v)#v}" fi if [[ "$version" != (none|system) ]]; then diff --git a/modules/node/init.zsh b/modules/node/init.zsh index e83e888..b436a0d 100644 --- a/modules/node/init.zsh +++ b/modules/node/init.zsh @@ -8,11 +8,21 @@ # # Possible lookup locations. -local_nvm_paths=({$NVM_DIR,{$XDG_CONFIG_HOME/,$HOME/.}nvm}/nvm.sh(N)) local_nodenv_paths=({$NODENV_ROOT,{$XDG_CONFIG_HOME/,$HOME/.}nodenv}/bin/nodenv(N)) +local_nvm_paths=({$NVM_DIR,{$XDG_CONFIG_HOME/,$HOME/.}nvm}/nvm.sh(N)) + +# Load manually installed nodenv into the shell session. +if [[ -s ${local_nodenv::=$local_nodenv_paths[1]} ]]; then + path=("$local_nodenv:h" $path) + eval "$(nodenv init - --no-rehash zsh)" + unset local_nodenv{,_paths} + +# Load package manager installed nodenv into the shell session. +elif (( $+commands[nodenv] )); then + eval "$(nodenv init - --no-rehash zsh)" # Load manually installed NVM into the shell session. -if [[ -s ${local_nvm::=$local_nvm_paths[1]} ]]; then +elif [[ -s ${local_nvm::=$local_nvm_paths[1]} ]]; then source "$local_nvm --no-use" unset local_nvm{,_paths} @@ -22,16 +32,6 @@ elif (( $+commands[brew] )) \ source "$nvm_prefix/nvm.sh --no-use" unset nvm_prefix -# Load manually installed nodenv into the shell session. -elif [[ -s ${local_nodenv::=$local_nodenv_paths[1]} ]]; then - path=("$local_nodenv:h" $path) - eval "$(nodenv init - --no-rehash zsh)" - unset local_nodenv{,_paths} - -# Load package manager installed nodenv into the shell session. -elif (( $+commands[nodenv] )); then - eval "$(nodenv init - --no-rehash zsh)" - # Return if requirements are not found. elif (( ! $+commands[node] )); then return 1