Skip to content

Commit 34f0ed4

Browse files
ci(NODE-5331): install npm to node_artifacts directory (#656)
1 parent 5811eba commit 34f0ed4

File tree

3 files changed

+28
-24
lines changed

3 files changed

+28
-24
lines changed

.evergreen/init-node-and-npm-env.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#! /usr/bin/env bash
2+
##
3+
## This script add the location of `npm` and `node` to the path.
4+
## This is necessary because evergreen uses separate bash scripts for
5+
## different functions in a given CI run but doesn't persist the environment
6+
## across them. So we manually invoke this script everywhere we need
7+
## access to `npm`, `node`, or need to install something globally from
8+
## npm.
9+
10+
NODE_ARTIFACTS_PATH="${PROJECT_DIRECTORY}/node-artifacts"
11+
if [[ "$OS" == "Windows_NT" ]]; then
12+
NODE_ARTIFACTS_PATH=$(cygpath --unix "$NODE_ARTIFACTS_PATH")
13+
fi
14+
15+
export NODE_ARTIFACTS_PATH
16+
# npm uses this environment variable to determine where to install global packages
17+
export npm_global_prefix=$NODE_ARTIFACTS_PATH/npm_global
18+
export PATH="$npm_global_prefix/bin:$NODE_ARTIFACTS_PATH/nodejs/bin:$PATH"
19+
hash -r
20+
21+
export NODE_OPTIONS="--trace-deprecation --trace-warnings"

.evergreen/init-nvm.sh

Lines changed: 0 additions & 13 deletions
This file was deleted.

.evergreen/install-dependencies.sh

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22
set -o errexit # Exit the script with error if any of the commands fail
33

44
NODE_LTS_VERSION=${NODE_LTS_VERSION:-16}
5-
NODE_ARTIFACTS_PATH="${PROJECT_DIRECTORY:-$(pwd)}/node-artifacts"
6-
if [[ "$OS" = "Windows_NT" ]]; then NODE_ARTIFACTS_PATH=$(cygpath --unix "$NODE_ARTIFACTS_PATH"); fi
5+
6+
source "${PROJECT_DIRECTORY}/libmongocrypt/bindings/node/.evergreen/init-node-and-npm-env.sh"
7+
8+
if [[ -z "${npm_global_prefix}" ]]; then echo "npm_global_prefix is unset" && exit 1; fi
9+
if [[ -z "${NODE_ARTIFACTS_PATH}" ]]; then echo "NODE_ARTIFACTS_PATH is unset" && exit 1; fi
710

811
CURL_FLAGS=(
912
--fail # Exit code 1 if request fails
@@ -90,24 +93,17 @@ else
9093
mv "${NODE_ARTIFACTS_PATH}/${node_directory}" "${NODE_ARTIFACTS_PATH}/nodejs"
9194
fi
9295

93-
export PATH="$NODE_ARTIFACTS_PATH/npm_global/bin:$NODE_ARTIFACTS_PATH/nodejs/bin:$PATH"
94-
hash -r
95-
96-
# Set npm -g prefix to our local artifacts directory
97-
cat <<EOT > .npmrc
98-
prefix=$NODE_ARTIFACTS_PATH/npm_global
99-
EOT
100-
10196
if [[ $operating_system != "win" ]]; then
10297
# Update npm to latest when we can
10398
npm install --global npm@latest
10499
hash -r
105100
fi
106101

102+
echo "npm location: $(which npm)"
107103
echo "npm version: $(npm -v)"
108104

109105
# other repos that use this script run npm install after installing Node.
110-
# we can't in mongodb-client-encryption, because when releasing
106+
# we can't in mongodb-client-encryption, because when releasing
111107
# npm install will attempt to build from source, which fails
112108
# because we haven't built libmongocrypt yet.
113109
# npm install "${NPM_OPTIONS}"

0 commit comments

Comments
 (0)