11cb0ef41Sopenharmony_ci#!/bin/sh 21cb0ef41Sopenharmony_ciset -e 31cb0ef41Sopenharmony_ci# Shell script to update npm in the source tree to a specific version 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ciBASE_DIR=$(cd "$(dirname "$0")/../.." && pwd) 61cb0ef41Sopenharmony_ciDEPS_DIR="$BASE_DIR/deps" 71cb0ef41Sopenharmony_ci[ -z "$NODE" ] && NODE="$BASE_DIR/out/Release/node" 81cb0ef41Sopenharmony_ci[ -x "$NODE" ] || NODE=$(command -v node) 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ci# shellcheck disable=SC1091 111cb0ef41Sopenharmony_ci. "$BASE_DIR/tools/dep_updaters/utils.sh" 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_ciNPM="$DEPS_DIR/npm/bin/npm-cli.js" 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_ciNPM_VERSION=$1 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_ciif [ "$#" -le 0 ]; then 181cb0ef41Sopenharmony_ci echo "Error: please provide an npm version to update to" 191cb0ef41Sopenharmony_ci exit 1 201cb0ef41Sopenharmony_cifi 211cb0ef41Sopenharmony_ci 221cb0ef41Sopenharmony_ciecho "Making temporary workspace" 231cb0ef41Sopenharmony_ci 241cb0ef41Sopenharmony_ciWORKSPACE=$(mktemp -d 2> /dev/null || mktemp -d -t 'tmp') 251cb0ef41Sopenharmony_ci 261cb0ef41Sopenharmony_cicleanup () { 271cb0ef41Sopenharmony_ci EXIT_CODE=$? 281cb0ef41Sopenharmony_ci [ -d "$WORKSPACE" ] && rm -rf "$WORKSPACE" 291cb0ef41Sopenharmony_ci exit $EXIT_CODE 301cb0ef41Sopenharmony_ci} 311cb0ef41Sopenharmony_ci 321cb0ef41Sopenharmony_citrap cleanup INT TERM EXIT 331cb0ef41Sopenharmony_ci 341cb0ef41Sopenharmony_cicd "$WORKSPACE" 351cb0ef41Sopenharmony_ci 361cb0ef41Sopenharmony_ciNPM_TGZ="npm-v$NPM_VERSION.tar.gz" 371cb0ef41Sopenharmony_ci 381cb0ef41Sopenharmony_ciNPM_TARBALL="$($NODE "$NPM" view npm@"$NPM_VERSION" dist.tarball)" 391cb0ef41Sopenharmony_ci 401cb0ef41Sopenharmony_cicurl -s "$NPM_TARBALL" > "$NPM_TGZ" 411cb0ef41Sopenharmony_ci 421cb0ef41Sopenharmony_cilog_and_verify_sha256sum "npm" "$NPM_TGZ" 431cb0ef41Sopenharmony_ci 441cb0ef41Sopenharmony_cirm -rf "$DEPS_DIR/npm" 451cb0ef41Sopenharmony_ci 461cb0ef41Sopenharmony_cimkdir "$DEPS_DIR/npm" 471cb0ef41Sopenharmony_ci 481cb0ef41Sopenharmony_citar zxvf "$NPM_TGZ" --strip-component=1 -C "$DEPS_DIR/npm" 491cb0ef41Sopenharmony_ci 501cb0ef41Sopenharmony_ciecho "" 511cb0ef41Sopenharmony_ciecho "All done!" 521cb0ef41Sopenharmony_ciecho "" 531cb0ef41Sopenharmony_ciecho "Please git add npm, commit the new version, and whitespace-fix:" 541cb0ef41Sopenharmony_ciecho "" 551cb0ef41Sopenharmony_ciecho "$ git add -A deps/npm" 561cb0ef41Sopenharmony_ciecho "$ git commit -m \"deps: upgrade npm to $NPM_VERSION\"" 571cb0ef41Sopenharmony_ciecho "" 581cb0ef41Sopenharmony_ci 591cb0ef41Sopenharmony_ci# The last line of the script should always print the new version, 601cb0ef41Sopenharmony_ci# as we need to add it to $GITHUB_ENV variable. 611cb0ef41Sopenharmony_ciecho "NEW_VERSION=$NPM_VERSION" 62