2021-04-02 23:55:18 +03:00
|
|
|
#!/bin/bash
|
2021-12-31 02:08:43 +03:00
|
|
|
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
2021-04-02 23:55:18 +03:00
|
|
|
#
|
|
|
|
# This source code is licensed under the MIT license found in the
|
|
|
|
# LICENSE file in the root directory of this source tree.
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
2021-10-01 01:00:27 +03:00
|
|
|
# remove global prefix if it's already set
|
|
|
|
# the running shell process will choose a node binary and a global package directory breaks version managers
|
|
|
|
unset PREFIX
|
|
|
|
|
2021-06-08 21:18:36 +03:00
|
|
|
# Support Homebrew on M1
|
|
|
|
HOMEBREW_M1_BIN=/opt/homebrew/bin
|
|
|
|
if [[ -d $HOMEBREW_M1_BIN && ! $PATH =~ $HOMEBREW_M1_BIN ]]; then
|
|
|
|
export PATH="$HOMEBREW_M1_BIN:$PATH"
|
|
|
|
fi
|
|
|
|
|
2021-04-02 23:55:18 +03:00
|
|
|
# Define NVM_DIR and source the nvm.sh setup script
|
|
|
|
[ -z "$NVM_DIR" ] && export NVM_DIR="$HOME/.nvm"
|
|
|
|
|
2021-12-07 01:02:11 +03:00
|
|
|
# Source nvm with '--no-use' and then `nvm use` to respect .nvmrc
|
|
|
|
# See: https://github.com/nvm-sh/nvm/issues/2053
|
2021-04-02 23:55:18 +03:00
|
|
|
if [[ -s "$HOME/.nvm/nvm.sh" ]]; then
|
|
|
|
# shellcheck source=/dev/null
|
2021-12-07 01:02:11 +03:00
|
|
|
. "$HOME/.nvm/nvm.sh" --no-use
|
|
|
|
nvm use 2> /dev/null || nvm use default
|
2021-04-02 23:55:18 +03:00
|
|
|
elif [[ -x "$(command -v brew)" && -s "$(brew --prefix nvm)/nvm.sh" ]]; then
|
|
|
|
# shellcheck source=/dev/null
|
2021-12-07 01:02:11 +03:00
|
|
|
. "$(brew --prefix nvm)/nvm.sh" --no-use
|
|
|
|
nvm use 2> /dev/null || nvm use default
|
2021-04-02 23:55:18 +03:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Set up the nodenv node version manager if present
|
|
|
|
if [[ -x "$HOME/.nodenv/bin/nodenv" ]]; then
|
|
|
|
eval "$("$HOME/.nodenv/bin/nodenv" init -)"
|
|
|
|
elif [[ -x "$(command -v brew)" && -x "$(brew --prefix nodenv)/bin/nodenv" ]]; then
|
|
|
|
eval "$("$(brew --prefix nodenv)/bin/nodenv" init -)"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Set up the ndenv of anyenv if preset
|
|
|
|
if [[ ! -x node && -d ${HOME}/.anyenv/bin ]]; then
|
|
|
|
export PATH=${HOME}/.anyenv/bin:${PATH}
|
|
|
|
if [[ "$(anyenv envs | grep -c ndenv )" -eq 1 ]]; then
|
|
|
|
eval "$(anyenv init -)"
|
|
|
|
fi
|
|
|
|
fi
|
2021-09-28 20:53:40 +03:00
|
|
|
|
|
|
|
# Set up asdf-vm if present
|
|
|
|
if [[ -f "$HOME/.asdf/asdf.sh" ]]; then
|
|
|
|
# shellcheck source=/dev/null
|
|
|
|
. "$HOME/.asdf/asdf.sh"
|
|
|
|
elif [[ -x "$(command -v brew)" && -f "$(brew --prefix asdf)/asdf.sh" ]]; then
|
|
|
|
# shellcheck source=/dev/null
|
|
|
|
. "$(brew --prefix asdf)/asdf.sh"
|
|
|
|
fi
|
2021-11-19 16:26:24 +03:00
|
|
|
|
|
|
|
# Set up volta if present
|
|
|
|
if [[ -x "$HOME/.volta/bin/node" ]]; then
|
|
|
|
export VOLTA_HOME="$HOME/.volta"
|
|
|
|
export PATH="$VOLTA_HOME/bin:$PATH"
|
|
|
|
fi
|
2022-01-26 18:39:36 +03:00
|
|
|
|
|
|
|
# Set up the fnm node version manager if present
|
|
|
|
if [[ -x "$HOME/.fnm/fnm" ]]; then
|
|
|
|
eval "$("$HOME/.fnm/fnm" env)"
|
|
|
|
elif [[ -x "$(command -v brew)" && -x "$(brew --prefix fnm)/bin/fnm" ]]; then
|
|
|
|
eval "$("$(brew --prefix fnm)/bin/fnm" env)"
|
|
|
|
fi
|