2020-11-11 00:26:07 +01:00
|
|
|
#!/bin/sh
|
2020-10-26 17:46:12 -04:00
|
|
|
set -e
|
|
|
|
# Shell script to update npm in the source tree to a specific version
|
|
|
|
|
2023-04-26 16:10:29 +02:00
|
|
|
BASE_DIR=$(cd "$(dirname "$0")/../.." && pwd)
|
2022-11-01 07:36:44 -05:00
|
|
|
DEPS_DIR="$BASE_DIR/deps"
|
2023-04-26 16:10:29 +02:00
|
|
|
[ -z "$NODE" ] && NODE="$BASE_DIR/out/Release/node"
|
|
|
|
[ -x "$NODE" ] || NODE=$(command -v node)
|
|
|
|
|
2023-05-25 21:46:07 +02:00
|
|
|
# shellcheck disable=SC1091
|
|
|
|
. "$BASE_DIR/tools/dep_updaters/utils.sh"
|
|
|
|
|
2023-04-26 16:10:29 +02:00
|
|
|
NPM="$DEPS_DIR/npm/bin/npm-cli.js"
|
|
|
|
|
2020-10-26 17:46:12 -04:00
|
|
|
NPM_VERSION=$1
|
|
|
|
|
|
|
|
if [ "$#" -le 0 ]; then
|
|
|
|
echo "Error: please provide an npm version to update to"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-04-27 10:52:02 +02:00
|
|
|
echo "Making temporary workspace"
|
2020-10-26 17:46:12 -04:00
|
|
|
|
2021-04-27 10:52:02 +02:00
|
|
|
WORKSPACE=$(mktemp -d 2> /dev/null || mktemp -d -t 'tmp')
|
2020-10-26 17:46:12 -04:00
|
|
|
|
2021-04-27 10:52:02 +02:00
|
|
|
cleanup () {
|
|
|
|
EXIT_CODE=$?
|
|
|
|
[ -d "$WORKSPACE" ] && rm -rf "$WORKSPACE"
|
|
|
|
exit $EXIT_CODE
|
|
|
|
}
|
2020-10-26 17:46:12 -04:00
|
|
|
|
2021-04-27 10:52:02 +02:00
|
|
|
trap cleanup INT TERM EXIT
|
2020-10-26 17:46:12 -04:00
|
|
|
|
|
|
|
cd "$WORKSPACE"
|
|
|
|
|
2023-05-25 21:46:07 +02:00
|
|
|
NPM_TGZ="npm-v$NPM_VERSION.tar.gz"
|
2020-10-26 17:46:12 -04:00
|
|
|
|
2023-04-26 16:10:29 +02:00
|
|
|
NPM_TARBALL="$($NODE "$NPM" view npm@"$NPM_VERSION" dist.tarball)"
|
2020-10-26 17:46:12 -04:00
|
|
|
|
2023-04-26 16:10:29 +02:00
|
|
|
curl -s "$NPM_TARBALL" > "$NPM_TGZ"
|
2020-10-26 17:46:12 -04:00
|
|
|
|
2023-05-25 21:46:07 +02:00
|
|
|
log_and_verify_sha256sum "npm" "$NPM_TGZ"
|
|
|
|
|
2023-04-26 16:10:29 +02:00
|
|
|
rm -rf "$DEPS_DIR/npm"
|
2020-10-26 17:46:12 -04:00
|
|
|
|
2023-04-26 16:10:29 +02:00
|
|
|
mkdir "$DEPS_DIR/npm"
|
2020-10-26 17:46:12 -04:00
|
|
|
|
2023-04-26 16:10:29 +02:00
|
|
|
tar zxvf "$NPM_TGZ" --strip-component=1 -C "$DEPS_DIR/npm"
|
2020-10-26 17:46:12 -04:00
|
|
|
|
2023-06-06 11:07:34 +02:00
|
|
|
# Update the version number on maintaining-dependencies.md
|
|
|
|
# and print the new version as the last line of the script as we need
|
|
|
|
# to add it to $GITHUB_ENV variable
|
|
|
|
finalize_version_update "npm" "$NPM_VERSION"
|