Skip to content

Commit

Permalink
tools: add update-npm script
Browse files Browse the repository at this point in the history
I've had to update this one too many times, and much of it can be
automated, so let's do that!

The maintenance instructions have also been updated.

PR-URL: #35822
Reviewed-By: Jiawen Geng <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
  • Loading branch information
MylesBorins authored and Trott committed Oct 29, 2020
1 parent a3cc239 commit 4bd1fba
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 39 deletions.
46 changes: 7 additions & 39 deletions doc/guides/maintaining-npm.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
57 changes: 57 additions & 0 deletions tools/update-npm.sh
Original file line number Diff line number Diff line change
@@ -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 [email protected]: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 ""

0 comments on commit 4bd1fba

Please sign in to comment.