• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2set -e
3# Shell script to update npm in the source tree to a specific version
4
5BASE_DIR=$(cd "$(dirname "$0")/../.." && pwd)
6DEPS_DIR="$BASE_DIR/deps"
7[ -z "$NODE" ] && NODE="$BASE_DIR/out/Release/node"
8[ -x "$NODE" ] || NODE=$(command -v node)
9
10# shellcheck disable=SC1091
11. "$BASE_DIR/tools/dep_updaters/utils.sh"
12
13NPM="$DEPS_DIR/npm/bin/npm-cli.js"
14
15NPM_VERSION=$1
16
17if [ "$#" -le 0 ]; then
18  echo "Error: please provide an npm version to update to"
19  exit 1
20fi
21
22echo "Making temporary workspace"
23
24WORKSPACE=$(mktemp -d 2> /dev/null || mktemp -d -t 'tmp')
25
26cleanup () {
27  EXIT_CODE=$?
28  [ -d "$WORKSPACE" ] && rm -rf "$WORKSPACE"
29  exit $EXIT_CODE
30}
31
32trap cleanup INT TERM EXIT
33
34cd "$WORKSPACE"
35
36NPM_TGZ="npm-v$NPM_VERSION.tar.gz"
37
38NPM_TARBALL="$($NODE "$NPM" view npm@"$NPM_VERSION" dist.tarball)"
39
40curl -s "$NPM_TARBALL" > "$NPM_TGZ"
41
42log_and_verify_sha256sum "npm" "$NPM_TGZ"
43
44rm -rf "$DEPS_DIR/npm"
45
46mkdir "$DEPS_DIR/npm"
47
48tar zxvf "$NPM_TGZ" --strip-component=1 -C "$DEPS_DIR/npm"
49
50echo ""
51echo "All done!"
52echo ""
53echo "Please git add npm, commit the new version, and whitespace-fix:"
54echo ""
55echo "$ git add -A deps/npm"
56echo "$ git commit -m \"deps: upgrade npm to $NPM_VERSION\""
57echo ""
58
59# The last line of the script should always print the new version,
60# as we need to add it to $GITHUB_ENV variable.
61echo "NEW_VERSION=$NPM_VERSION"
62