From 6ee0910bb8c38a0abe1538b8f6149e9e8614eefd Mon Sep 17 00:00:00 2001 From: jmills Date: Mon, 22 Jul 2019 17:46:47 -0700 Subject: [PATCH 1/5] Allow use of NVM_AUTO_USE alongside NVM_LAZY_LOAD --- zsh-nvm.plugin.zsh | 1 + 1 file changed, 1 insertion(+) diff --git a/zsh-nvm.plugin.zsh b/zsh-nvm.plugin.zsh index d3b23a4..6119684 100644 --- a/zsh-nvm.plugin.zsh +++ b/zsh-nvm.plugin.zsh @@ -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 && _zsh_nvm_auto_use $cmd \"\$@\" }" done From 6557d7e2ed8abcdf2e6c7218403ee254a5e239e1 Mon Sep 17 00:00:00 2001 From: Amir Tahvildaran Date: Sun, 28 Jul 2019 18:37:56 -0400 Subject: [PATCH 2/5] Add failing test for auto and lazy See https://github.com/lukechilds/zsh-nvm/pull/55 --- tests/options/NVM_AUTO_USE && NVM_LAZY_LOAD | 39 +++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100755 tests/options/NVM_AUTO_USE && NVM_LAZY_LOAD diff --git a/tests/options/NVM_AUTO_USE && NVM_LAZY_LOAD b/tests/options/NVM_AUTO_USE && NVM_LAZY_LOAD new file mode 100755 index 0000000..f878bb6 --- /dev/null +++ b/tests/options/NVM_AUTO_USE && NVM_LAZY_LOAD @@ -0,0 +1,39 @@ +#!/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" + +# 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" From 8df3e2bbad67da635201b24c2d84bb0f35a327ca Mon Sep 17 00:00:00 2001 From: jmills Date: Thu, 14 May 2020 20:20:07 -0700 Subject: [PATCH 3/5] remove extraneous _zsh_nvm_auto_use call nvm will already be called by the line above (_zsh_nvm_load) so this a) takes longer and b) causes duplicated output in the terminal, e.g.: Found '/Users/[...]/.nvmrc' with version <9.2.1> Now using node v9.2.1 (npm v5.5.1) Found '/Users/[...]/.nvmrc' with version <9.2.1> Now using node v9.2.1 (npm v5.5.1) --- zsh-nvm.plugin.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zsh-nvm.plugin.zsh b/zsh-nvm.plugin.zsh index 6119684..4d7bb34 100644 --- a/zsh-nvm.plugin.zsh +++ b/zsh-nvm.plugin.zsh @@ -102,7 +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 && _zsh_nvm_auto_use + [[ "$NVM_AUTO_USE" == true ]] && add-zsh-hook chpwd _zsh_nvm_auto_use $cmd \"\$@\" }" done From 9212aaf878801041cde0598eee124d3e843724b4 Mon Sep 17 00:00:00 2001 From: Jeremy Miller Date: Thu, 14 May 2020 21:25:10 -0700 Subject: [PATCH 4/5] helps to init lazy loader for this test --- tests/options/NVM_AUTO_USE && NVM_LAZY_LOAD | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/options/NVM_AUTO_USE && NVM_LAZY_LOAD b/tests/options/NVM_AUTO_USE && NVM_LAZY_LOAD index f878bb6..d285451 100755 --- a/tests/options/NVM_AUTO_USE && NVM_LAZY_LOAD +++ b/tests/options/NVM_AUTO_USE && NVM_LAZY_LOAD @@ -34,6 +34,18 @@ load_zsh_nvm # 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" From 0b1344de733189f19cc8c1890f79730fb4585c3c Mon Sep 17 00:00:00 2001 From: Jeremy Miller Date: Thu, 14 May 2020 22:35:05 -0700 Subject: [PATCH 5/5] also helps to escape quotes --- zsh-nvm.plugin.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zsh-nvm.plugin.zsh b/zsh-nvm.plugin.zsh index 4d7bb34..fdcd1ca 100644 --- a/zsh-nvm.plugin.zsh +++ b/zsh-nvm.plugin.zsh @@ -102,7 +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 + [[ \"$NVM_AUTO_USE\" == true ]] && add-zsh-hook chpwd _zsh_nvm_auto_use $cmd \"\$@\" }" done