mirror of
				https://github.com/nvm-sh/nvm.git
				synced 2025-11-04 06:57:12 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			42 lines
		
	
	
		
			840 B
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			42 lines
		
	
	
		
			840 B
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
#!/usr/bin/env bash
 | 
						|
 | 
						|
function nvm_fail() {
 | 
						|
  echo "$1" >&2
 | 
						|
  exit 127
 | 
						|
}
 | 
						|
 | 
						|
has_realpath=""
 | 
						|
 | 
						|
function find_nvm_dir() {
 | 
						|
  if which realpath >& /dev/null; then
 | 
						|
    has_realpath=yes
 | 
						|
    dirname "$(realpath "$0")"
 | 
						|
  else
 | 
						|
    command cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd
 | 
						|
  fi
 | 
						|
}
 | 
						|
 | 
						|
DIR="$(find_nvm_dir)"
 | 
						|
 | 
						|
function check_nvm_sh() {
 | 
						|
  if [ ! -f "$DIR/nvm.sh" ]; then
 | 
						|
    local rp_msg=""
 | 
						|
    [ "$has_realpath" == "yes" ] || rp_msg="; missing realpath command for finding nvm-exec's realpath to search for nvm.sh"
 | 
						|
    nvm_fail "Unable to find nvm.sh at $DIR$rp_msg"
 | 
						|
  fi
 | 
						|
}
 | 
						|
 | 
						|
check_nvm_sh
 | 
						|
 | 
						|
# shellcheck disable=SC1090
 | 
						|
\. "$DIR/nvm.sh" --no-use
 | 
						|
 | 
						|
if [ -n "$NODE_VERSION" ]; then
 | 
						|
  nvm use "$NODE_VERSION" > /dev/null || exit 127
 | 
						|
elif ! nvm use >/dev/null 2>&1; then
 | 
						|
  echo "No NODE_VERSION provided; no .nvmrc file found" >&2
 | 
						|
  exit 127
 | 
						|
fi
 | 
						|
 | 
						|
exec "$@"
 |