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

Allow use of NVM_AUTO_USE alongside NVM_LAZY_LOAD on init #55

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions tests/options/NVM_AUTO_USE && NVM_LAZY_LOAD
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/sh
source ../common.sh

# Node.js version to install
node_version=v5.11.0

# Load zsh-nvm and install Node.js in subshell
(load_zsh_nvm && nvm install "$node_version" && [[ "$(node --version)" == "$node_version" ]]) || die "node wasn't installed"

# Check node isn't available
[[ "$(node --version)" != "$node_version" ]] || die "node shouldn't be available $(node --version)"

# Setup .nvmrc dir
local nvmrc_dir="$test_dir/nvmrc2"
local no_nvmrc_dir="$test_dir/no-nvmrc2"
local nvmrc="$nvmrc_dir/.nvmrc"
mkdir "$no_nvmrc_dir"
mkdir "$nvmrc_dir"
touch "$nvmrc"

# Set NVM_LAZY_LOAD to true
export NVM_LAZY_LOAD=true
export NVM_AUTO_USE=true

# Load zsh-nvm
load_zsh_nvm

# Check nvm is a lazy load function
[[ $(which nvm) == *"_zsh_nvm_load"* ]] || die "nvm should be a lazy load function"

# Check node is a lazy load function
[[ $(command -v node) == "node" ]] || die "node should be a shell function"

# Check npm is a lazy load function
[[ $(command -v npm) == "npm" ]] || die "npm should be a shell function"

# Init lazy loader
node --version || die "couldn't run lazy loader"

# Check nvm is not a lazy load function
[[ $(which nvm) != *"_zsh_nvm_load"* ]] || die "nvm should not be a lazy load function"

# Check node is a binary
[[ "$(command -v node)" == "$(nvm_version_path $node_version)/bin/node" ]] || die "node should now be a binary"

# Check npm is a binary
[[ "$(command -v npm)" == "$(nvm_version_path $node_version)/bin/npm" ]] || die "npm should now be a binary"

# Check cd into folder with .nvmrc keeps v6
echo 6 > "$nvmrc"
(cd "$nvmrc_dir" && [[ "$(node --version | tail -1)" == "v6."* ]]) || die "Didn't switch to node 6"
1 change: 1 addition & 0 deletions zsh-nvm.plugin.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ _zsh_nvm_lazy_load() {
eval "$cmd(){
unset -f $cmds > /dev/null 2>&1
_zsh_nvm_load
[[ \"$NVM_AUTO_USE\" == true ]] && add-zsh-hook chpwd _zsh_nvm_auto_use
Copy link
Owner

Choose a reason for hiding this comment

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

Why do we need to setup the chpwd hook here?

Shouldn't it already be set here?

https://github.com/lukechilds/zsh-nvm/pull/55/files#diff-dfc5680d74f94037e00d26cbeba9485eR212

Copy link
Owner

Choose a reason for hiding this comment

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

The tests all still pass if this line is removed:

https://travis-ci.org/github/lukechilds/zsh-nvm/jobs/687714916

30f8555

Choose a reason for hiding this comment

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

This is what you should do here:

[[ \"$NVM_AUTO_USE\" == true ]] && _zsh_nvm_auto_use

The hooks are already loaded, you just need to run _zsh_nvm_auto_use after loading nvm

$cmd \"\$@\"
}"
done
Expand Down