From 40100534c1ab5e2303c598d7b4c0ac3cad689bfe Mon Sep 17 00:00:00 2001 From: eudika Date: Fri, 28 Aug 2020 19:12:49 +0900 Subject: [PATCH] Load NVM lazily $NVM_DIR/nvm.sh is a slow script and has doubled time to load zsh. In this commit, the script is not loaded until required. cf. https://github.com/nvm-sh/nvm/issues/1277 --- modules/node/init.zsh | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/modules/node/init.zsh b/modules/node/init.zsh index 6fb68f307d..9175d4527d 100644 --- a/modules/node/init.zsh +++ b/modules/node/init.zsh @@ -8,7 +8,15 @@ # Load manually installed NVM into the shell session. if [[ -s "${NVM_DIR:=$HOME/.nvm}/nvm.sh" ]]; then - source "${NVM_DIR}/nvm.sh" + # Add latest node to the path. + path=("$NVM_DIR/versions/node/$(ls $NVM_DIR/versions/node | sort -V | tail -n1)/bin/": $path) + # Load NVM lazily. + nvm() { + unset nvm; + # This line is very slow. + source "$NVM_DIR/nvm.sh" + nvm "$@" + } # Load package manager installed NVM into the shell session. elif (( $+commands[brew] )) && \