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 NVM_LAZY_LOAD_EXTRA_COMMANDS option #67

Merged
merged 3 commits into from
Jun 16, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,16 @@ Performance comparison:
( _zsh_nvm_lazy_load; ) 0.01s user 0.01s system 168% cpu 0.012 total
```

#### Extra commands to trigger lazy loading
By default lazy loading nvm is triggered by running the `nvm`, `node`, `npm` commands or any installed npm global binaries.
If you want to trigger the lazy loading via extra arbitrary commands you can define `NVM_LAZY_LOAD_EXTRA_COMMANDS` and set it to an array of commands as strings.
joerideg marked this conversation as resolved.
Show resolved Hide resolved

```shell
export NVM_LAZY_LOAD_EXTRA_COMMANDS=('vim', 'ls')
joerideg marked this conversation as resolved.
Show resolved Hide resolved
vim --version
#node is now loaded
```

### Don't autoload node

By default when `nvm` is loaded it'll automatically run `nvm use default` and load your default `node` version along with `npm` and any global modules. You can disable this behaviour by exporting the `NVM_NO_USE` environment variable and setting it to `true`. It must be set before `zsh-nvm` is loaded.
Expand Down
39 changes: 39 additions & 0 deletions tests/options/NVM_LAZY_LOAD_EXTRA_COMMANDS
Original file line number Diff line number Diff line change
@@ -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)"

# Set NVM_LAZY_LOAD to true
export NVM_LAZY_LOAD=true
export NVM_LAZY_LOAD_EXTRA_COMMANDS=('ls' 'whoami')
joerideg marked this conversation as resolved.
Show resolved Hide resolved

# 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
whoami || 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"
1 change: 1 addition & 0 deletions zsh-nvm.plugin.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ _zsh_nvm_lazy_load() {

# Add nvm
global_binaries+=('nvm')
global_binaries+=($NVM_LAZY_LOAD_EXTRA_COMMANDS)

# Remove any binaries that conflict with current aliases
local cmds
Expand Down