Skip to content

Commit 93ecb01

Browse files
committed
tools: add update-npm script
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: nodejs#35822 Reviewed-By: Jiawen Geng <technicalcute@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent bfd30cc commit 93ecb01

File tree

2 files changed

+64
-39
lines changed

2 files changed

+64
-39
lines changed

doc/guides/maintaining-npm.md

+7-39
Original file line numberDiff line numberDiff line change
@@ -10,52 +10,20 @@ are at the discretion of the release and LTS teams.
1010
This process only covers full updates to new versions of npm. Cherry-picked
1111
changes can be reviewed and landed via the normal consensus seeking process.
1212

13-
## Step 1: Clone npm
13+
## Step 1: Run the update script
1414

1515
```console
16-
$ git clone https://github.com/npm/cli.git npm
17-
$ cd npm
16+
$ ./tools/update-npm.sh
1817
```
1918

20-
or if you already have npm cloned make sure the repo is up to date
19+
## Step 2: Commit new npm
2120

2221
```console
23-
$ git remote update -p
24-
$ git reset --hard origin/latest
25-
```
26-
27-
## Step 2: Build release
28-
29-
```console
30-
$ git checkout vX.Y.Z
31-
$ make
32-
$ make release
33-
```
34-
35-
Note: please run `npm dist-tag ls npm` and make sure this is the `latest`
36-
**dist-tag**. `latest` on git is usually released as `next` when it's time to
37-
downstream
38-
39-
## Step 3: Remove old npm
40-
41-
```console
42-
$ cd /path/to/node
43-
$ git remote update -p
44-
$ git checkout -b npm-x.y.z origin/master
45-
$ cd deps
46-
$ rm -rf npm
47-
```
48-
49-
## Step 4: Extract and commit new npm
50-
51-
```console
52-
$ tar zxf /path/to/npm/release/npm-x.y.z.tgz
53-
$ git add -A npm
22+
$ git add -A deps/npm
5423
$ git commit -m "deps: upgrade npm to x.y.z"
55-
$ cd ..
5624
```
5725

58-
## Step 5: Update licenses
26+
## Step 3: Update licenses
5927

6028
```console
6129
$ ./configure
@@ -68,13 +36,13 @@ $ git commit -m "doc: update npm LICENSE using license-builder.sh"
6836

6937
Note: please ensure you are only making the updates that are changed by npm.
7038

71-
## Step 6: Apply Whitespace fix
39+
## Step 4: Apply Whitespace fix
7240

7341
```console
7442
$ git rebase --whitespace=fix master
7543
```
7644

77-
## Step 7: Test the build
45+
## Step 5: Test the build
7846

7947
```console
8048
$ make test-npm

tools/update-npm.sh

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
# Shell script to update npm in the source tree to a specific version
4+
5+
BASE_DIR="$( pwd )"/
6+
DEPS_DIR="$BASE_DIR"deps/
7+
NPM_VERSION=$1
8+
9+
if [ "$#" -le 0 ]; then
10+
echo "Error: please provide an npm version to update to"
11+
exit 1
12+
fi
13+
14+
WORKSPACE="$TMPDIR"update-npm-$NPM_VERSION/
15+
16+
if [ -d "$WORKSPACE" ]; then
17+
echo "Cleaning up old workspace"
18+
rm -rf "$WORKSPACE"
19+
fi
20+
21+
echo "Making temporary workspace"
22+
23+
mkdir -p "$WORKSPACE"
24+
25+
cd "$WORKSPACE"
26+
27+
git clone git@github.com:npm/cli.git
28+
cd cli
29+
30+
echo "Preparing npm release"
31+
32+
git checkout v"$NPM_VERSION"
33+
make
34+
make release
35+
36+
echo "Removing old npm"
37+
38+
cd "$DEPS_DIR"
39+
rm -rf npm/
40+
41+
echo "Copying new npm"
42+
43+
tar zxf "$WORKSPACE"cli/release/npm-"$NPM_VERSION".tgz
44+
45+
echo "Deleting temporary workspace"
46+
47+
rm -rf "$WORKSPACE"
48+
49+
echo ""
50+
echo "All done!"
51+
echo ""
52+
echo "Please git add npm, commit the new version, and whitespace-fix:"
53+
echo ""
54+
echo "$ git add -A deps/npm"
55+
echo "$ git commit -m \"deps: upgrade npm to $NPM_VERSION\""
56+
echo "$ git rebase --whitespace=fix master"
57+
echo ""

0 commit comments

Comments
 (0)