diff --git a/doc/guides/maintaining-npm.md b/doc/guides/maintaining-npm.md index 986c202bb17a97..37099770726433 100644 --- a/doc/guides/maintaining-npm.md +++ b/doc/guides/maintaining-npm.md @@ -10,52 +10,20 @@ are at the discretion of the release and LTS teams. This process only covers full updates to new versions of npm. Cherry-picked changes can be reviewed and landed via the normal consensus seeking process. -## Step 1: Clone npm +## Step 1: Run the update script ```console -$ git clone https://github.com/npm/cli.git npm -$ cd npm +$ ./tools/update-npm.sh ``` -or if you already have npm cloned make sure the repo is up to date +## Step 2: Commit new npm ```console -$ git remote update -p -$ git reset --hard origin/latest -``` - -## Step 2: Build release - -```console -$ git checkout vX.Y.Z -$ make -$ make release -``` - -Note: please run `npm dist-tag ls npm` and make sure this is the `latest` -**dist-tag**. `latest` on git is usually released as `next` when it's time to -downstream - -## Step 3: Remove old npm - -```console -$ cd /path/to/node -$ git remote update -p -$ git checkout -b npm-x.y.z origin/master -$ cd deps -$ rm -rf npm -``` - -## Step 4: Extract and commit new npm - -```console -$ tar zxf /path/to/npm/release/npm-x.y.z.tgz -$ git add -A npm +$ git add -A deps/npm $ git commit -m "deps: upgrade npm to x.y.z" -$ cd .. ``` -## Step 5: Update licenses +## Step 3: Update licenses ```console $ ./configure @@ -68,13 +36,13 @@ $ git commit -m "doc: update npm LICENSE using license-builder.sh" Note: please ensure you are only making the updates that are changed by npm. -## Step 6: Apply Whitespace fix +## Step 4: Apply Whitespace fix ```console $ git rebase --whitespace=fix master ``` -## Step 7: Test the build +## Step 5: Test the build ```console $ make test-npm diff --git a/tools/update-npm.sh b/tools/update-npm.sh new file mode 100755 index 00000000000000..5865f7d4e8cd77 --- /dev/null +++ b/tools/update-npm.sh @@ -0,0 +1,57 @@ +#!/usr/bin/env bash +set -e +# Shell script to update npm in the source tree to a specific version + +BASE_DIR="$( pwd )"/ +DEPS_DIR="$BASE_DIR"deps/ +NPM_VERSION=$1 + +if [ "$#" -le 0 ]; then + echo "Error: please provide an npm version to update to" + exit 1 +fi + +WORKSPACE="$TMPDIR"update-npm-$NPM_VERSION/ + +if [ -d "$WORKSPACE" ]; then + echo "Cleaning up old workspace" + rm -rf "$WORKSPACE" +fi + +echo "Making temporary workspace" + +mkdir -p "$WORKSPACE" + +cd "$WORKSPACE" + +git clone git@github.com:npm/cli.git +cd cli + +echo "Preparing npm release" + +git checkout v"$NPM_VERSION" +make +make release + +echo "Removing old npm" + +cd "$DEPS_DIR" +rm -rf npm/ + +echo "Copying new npm" + +tar zxf "$WORKSPACE"cli/release/npm-"$NPM_VERSION".tgz + +echo "Deleting temporary workspace" + +rm -rf "$WORKSPACE" + +echo "" +echo "All done!" +echo "" +echo "Please git add npm, commit the new version, and whitespace-fix:" +echo "" +echo "$ git add -A deps/npm" +echo "$ git commit -m \"deps: upgrade npm to $NPM_VERSION\"" +echo "$ git rebase --whitespace=fix master" +echo ""