diff --git a/.evergreen/init-node-and-npm-env.sh b/.evergreen/init-node-and-npm-env.sh new file mode 100644 index 00000000..b3cecf54 --- /dev/null +++ b/.evergreen/init-node-and-npm-env.sh @@ -0,0 +1,21 @@ +#! /usr/bin/env bash +## +## This script add the location of `npm` and `node` to the path. +## This is necessary because evergreen uses separate bash scripts for +## different functions in a given CI run but doesn't persist the environment +## across them. So we manually invoke this script everywhere we need +## access to `npm`, `node`, or need to install something globally from +## npm. + +NODE_ARTIFACTS_PATH="${PROJECT_DIRECTORY}/node-artifacts" +if [[ "$OS" == "Windows_NT" ]]; then + NODE_ARTIFACTS_PATH=$(cygpath --unix "$NODE_ARTIFACTS_PATH") +fi + +export NODE_ARTIFACTS_PATH +# npm uses this environment variable to determine where to install global packages +export npm_global_prefix=$NODE_ARTIFACTS_PATH/npm_global +export PATH="$npm_global_prefix/bin:$NODE_ARTIFACTS_PATH/nodejs/bin:$PATH" +hash -r + +export NODE_OPTIONS="--trace-deprecation --trace-warnings" diff --git a/.evergreen/init-nvm.sh b/.evergreen/init-nvm.sh deleted file mode 100644 index 28d14f16..00000000 --- a/.evergreen/init-nvm.sh +++ /dev/null @@ -1,13 +0,0 @@ -#! /usr/bin/env bash - -export PATH="/opt/mongodbtoolchain/v2/bin:$PATH" - -NODE_ARTIFACTS_PATH="${PROJECT_DIRECTORY}/node-artifacts" -if [[ "$OS" == "Windows_NT" ]]; then - NODE_ARTIFACTS_PATH=$(cygpath --unix "$NODE_ARTIFACTS_PATH") -fi - -export PATH="$NODE_ARTIFACTS_PATH/npm_global/bin:$NODE_ARTIFACTS_PATH/nodejs/bin:$PATH" -hash -r - -export NODE_OPTIONS="--trace-deprecation --trace-warnings" diff --git a/.evergreen/install-dependencies.sh b/.evergreen/install-dependencies.sh index 106ee595..152a4aa5 100755 --- a/.evergreen/install-dependencies.sh +++ b/.evergreen/install-dependencies.sh @@ -2,8 +2,11 @@ set -o errexit # Exit the script with error if any of the commands fail NODE_LTS_VERSION=${NODE_LTS_VERSION:-14} -NODE_ARTIFACTS_PATH="${PROJECT_DIRECTORY:-$(pwd)}/node-artifacts" -if [[ "$OS" = "Windows_NT" ]]; then NODE_ARTIFACTS_PATH=$(cygpath --unix "$NODE_ARTIFACTS_PATH"); fi + +source "${PROJECT_DIRECTORY}/.evergreen/init-node-and-npm-env.sh" + +if [[ -z "${npm_global_prefix}" ]]; then echo "npm_global_prefix is unset" && exit 1; fi +if [[ -z "${NODE_ARTIFACTS_PATH}" ]]; then echo "NODE_ARTIFACTS_PATH is unset" && exit 1; fi CURL_FLAGS=( --fail # Exit code 1 if request fails @@ -90,20 +93,13 @@ else mv "${NODE_ARTIFACTS_PATH}/${node_directory}" "${NODE_ARTIFACTS_PATH}/nodejs" fi -export PATH="$NODE_ARTIFACTS_PATH/npm_global/bin:$NODE_ARTIFACTS_PATH/nodejs/bin:$PATH" -hash -r - -# Set npm -g prefix to our local artifacts directory -cat < .npmrc -prefix=$NODE_ARTIFACTS_PATH/npm_global -EOT - if [[ $operating_system != "win" ]]; then # Update npm to latest when we can npm install --global npm@latest hash -r fi +echo "npm location: $(which npm)" echo "npm version: $(npm -v)" npm install "${NPM_OPTIONS}" diff --git a/.evergreen/run-bundling-test.sh b/.evergreen/run-bundling-test.sh index 5cc2db4c..f0b61e63 100644 --- a/.evergreen/run-bundling-test.sh +++ b/.evergreen/run-bundling-test.sh @@ -1,6 +1,6 @@ #! /usr/bin/env bash -source "${PROJECT_DIRECTORY}/.evergreen/init-nvm.sh" +source "${PROJECT_DIRECTORY}/.evergreen/init-node-and-npm-env.sh" set -o xtrace set -o errexit diff --git a/.evergreen/run-checks.sh b/.evergreen/run-checks.sh index 4d34cb27..65443ed1 100644 --- a/.evergreen/run-checks.sh +++ b/.evergreen/run-checks.sh @@ -1,6 +1,6 @@ #!/bin/bash set -o errexit # Exit the script with error if any of the commands fail -source "${PROJECT_DIRECTORY}/.evergreen/init-nvm.sh" +source "${PROJECT_DIRECTORY}/.evergreen/init-node-and-npm-env.sh" npm run check:lint diff --git a/.evergreen/run-eslint-plugin-test.sh b/.evergreen/run-eslint-plugin-test.sh index 0c30b0ba..c0c6693f 100644 --- a/.evergreen/run-eslint-plugin-test.sh +++ b/.evergreen/run-eslint-plugin-test.sh @@ -2,7 +2,7 @@ set -o errexit -source "${PROJECT_DIRECTORY}/.evergreen/init-nvm.sh" +source "${PROJECT_DIRECTORY}/.evergreen/init-node-and-npm-env.sh" cd etc/eslint/no-bigint-usage npm install diff --git a/.evergreen/run-tests.sh b/.evergreen/run-tests.sh index b2390ef1..71a7aa97 100755 --- a/.evergreen/run-tests.sh +++ b/.evergreen/run-tests.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -source "${PROJECT_DIRECTORY}/.evergreen/init-nvm.sh" +source "${PROJECT_DIRECTORY}/.evergreen/init-node-and-npm-env.sh" case $1 in "node") diff --git a/.evergreen/run-typescript.sh b/.evergreen/run-typescript.sh index 00153bce..30f3ca46 100644 --- a/.evergreen/run-typescript.sh +++ b/.evergreen/run-typescript.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash set -o errexit # Exit the script with error if any of the commands fail -source "${PROJECT_DIRECTORY}/.evergreen/init-nvm.sh" +source "${PROJECT_DIRECTORY}/.evergreen/init-node-and-npm-env.sh" set -o xtrace