Skip to content

chore: update nvm environment setup #487

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

Merged
merged 1 commit into from
Feb 11, 2022
Merged
Changes from all commits
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
53 changes: 39 additions & 14 deletions .evergreen/install-dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,34 @@ if [ -z "$NODE_VERSION" ]; then
exit 1
fi

set -o xtrace # Write all commands first to stderr
set -o errexit # Exit the script with error if any of the commands fail

NODE_ARTIFACTS_PATH="${PROJECT_DIRECTORY}/node-artifacts"
NPM_CACHE_DIR="${NODE_ARTIFACTS_PATH}/npm"
NPM_TMP_DIR="${NODE_ARTIFACTS_PATH}/tmp"

NVM_WINDOWS_URL="https://github.com/coreybutler/nvm-windows/releases/download/1.1.7/nvm-noinstall.zip"
NVM_URL="https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh"
BIN_DIR="$(pwd)/bin"
NVM_WINDOWS_URL="https://github.com/coreybutler/nvm-windows/releases/download/1.1.9/nvm-noinstall.zip"
NVM_URL="https://raw.githubusercontent.com/creationix/nvm/v0.38.0/install.sh"

# this needs to be explicitly exported for the nvm install below
export NVM_DIR="${NODE_ARTIFACTS_PATH}/nvm"
export XDG_CONFIG_HOME=${NODE_ARTIFACTS_PATH}

# create node artifacts path if needed
mkdir -p ${NVM_DIR}
mkdir -p ${NPM_CACHE_DIR}
mkdir -p "${NODE_ARTIFACTS_PATH}"
mkdir -p "${NPM_CACHE_DIR}"
mkdir -p "${NPM_TMP_DIR}"
mkdir -p "${BIN_DIR}"
mkdir -p "${NVM_DIR}"

# Add mongodb toolchain to path
export PATH="${BIN_DIR}:${PATH}"

# install Node.js
echo "--- Installing Node ${NODE_VERSION} --- "
echo "Installing Node ${NODE_LTS_NAME}"
if [ "$OS" == "Windows_NT" ]; then
set +o xtrace

export NVM_HOME=`cygpath -w "$NVM_DIR"`
export NVM_SYMLINK=`cygpath -w "$NODE_ARTIFACTS_PATH/bin"`
export PATH=`cygpath $NVM_SYMLINK`:`cygpath $NVM_HOME`:$PATH
Expand All @@ -40,17 +49,33 @@ root: $NVM_HOME
path: $NVM_SYMLINK
EOT

nvm install ${NODE_VERSION}
nvm install 10.22.0 # install lts for compilation only
nvm on
echo "Running: nvm install lts"
nvm install lts
echo "Running: nvm install ${NODE_VERSION}"
nvm install "${NODE_VERSION}"
echo "Running: nvm use lts"
nvm use lts
echo "Running: npm install -g [email protected]"
npm install -g [email protected] # https://github.com/npm/cli/issues/4341
set -o xtrace
else
set +o xtrace

echo " Downloading nvm"
curl -o- $NVM_URL | bash
[ -s "${NVM_DIR}/nvm.sh" ] && \. "${NVM_DIR}/nvm.sh"

nvm install --no-progress ${NODE_VERSION}
nvm install --no-progress 10.22.0 # install lts for compilation only
echo "Running: nvm install --lts --latest-npm"
nvm install --lts --latest-npm
echo "Running: nvm install ${NODE_VERSION}"
nvm install "${NODE_VERSION}"
echo "Running: nvm use --lts"
nvm use --lts

set -o xtrace
fi
nvm use 10.22.0 # use lts for setup, runtime node can be different



# setup npm cache in a local directory
cat <<EOT > .npmrc
Expand All @@ -63,4 +88,4 @@ EOT

# install node dependencies
npm install # npm prepare runs after install and will compile the library
nvm use ${NODE_VERSION} # Switch to the node version we want to test against
nvm use "${NODE_VERSION}" # Switch to the node version we want to test against