Skip to content

Commit e2a8f16

Browse files
tools: move update-acorn.sh to dep_updaters and create maintaining md
1 parent 81bb1b0 commit e2a8f16

File tree

5 files changed

+138
-51
lines changed

5 files changed

+138
-51
lines changed

.github/workflows/tools.yml

+8-12
Original file line numberDiff line numberDiff line change
@@ -95,22 +95,18 @@ jobs:
9595
subsystem: deps
9696
label: dependencies
9797
run: |
98-
NEW_VERSION=$(npm view acorn dist-tags.latest)
99-
CURRENT_VERSION=$(node -p "require('./deps/acorn/acorn/package.json').version")
100-
if [ "$NEW_VERSION" != "$CURRENT_VERSION" ]; then
101-
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV
102-
./tools/update-acorn.sh
103-
fi
98+
./tools/dep_updaters/update-acorn.sh > temp-output
99+
cat temp-output
100+
tail -n1 temp-output | grep "NEW_VERSION=" >> "$GITHUB_ENV" || true
101+
rm temp-output
104102
- id: acorn-walk
105103
subsystem: deps
106104
label: dependencies
107105
run: |
108-
NEW_VERSION=$(npm view acorn-walk dist-tags.latest)
109-
CURRENT_VERSION=$(node -p "require('./deps/acorn/acorn-walk/package.json').version")
110-
if [ "$NEW_VERSION" != "$CURRENT_VERSION" ]; then
111-
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV
112-
./tools/update-acorn-walk.sh
113-
fi
106+
./tools/dep_updaters/update-acorn-walk.sh > temp-output
107+
cat temp-output
108+
tail -n1 temp-output | grep "NEW_VERSION=" >> "$GITHUB_ENV" || true
109+
rm temp-output
114110
- id: libuv
115111
subsystem: deps
116112
label: dependencies

doc/contributing/maintaining-acorn.md

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Maintaining acorn
2+
3+
The [acorn](https://github.com/acornjs/acorn) dependency is a JavaScript parser.
4+
[acorn-walk](https://github.com/acornjs/acorn/tree/master/acorn-walk) is
5+
an abstract syntax tree walker for the ESTree format.
6+
7+
## Updating acorn
8+
9+
The `tools/dep_updaters/update-acorn.sh` script automates the update of the
10+
acorn source files.
11+
12+
Check that Node.js still builds and tests.
13+
14+
## Committing acorn
15+
16+
1. Add acorn:
17+
```console
18+
$ git add deps/acorn
19+
```
20+
2. Commit the changes: `git commit`.
21+
3. Add a message like:
22+
```text
23+
deps: update acorn to <version>
24+
25+
Updated as described in doc/contributing/maintaining-acorn.md.
26+
```
27+
28+
## Updating acorn-walk
29+
30+
The `tools/dep_updaters/update-acorn-walk.sh` script automates the update of the
31+
acorn-walk source files.
32+
33+
Check that Node.js still builds and tests.
34+
35+
## Committing acorn-walk
36+
37+
1. Add acorn-walk:
38+
```console
39+
$ git add deps/acorn-walk
40+
```
41+
2. Commit the changes: `git commit`.
42+
3. Add a message like:
43+
```text
44+
deps: update acorn-walk to <version>
45+
46+
Updated as described in doc/contributing/maintaining-acorn.md.
47+
```
+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/bin/sh
2+
3+
# Shell script to update acorn-walk in the source tree to the latest release.
4+
5+
# This script must be in the tools directory when it runs because it uses the
6+
# script source file path to determine directories to work in.
7+
8+
set -ex
9+
10+
ROOT=$(cd "$(dirname "$0")/../.." && pwd)
11+
[ -z "$NODE" ] && NODE="$ROOT/out/Release/node"
12+
[ -x "$NODE" ] || NODE=$(command -v node)
13+
NPM="$ROOT/deps/npm/bin/npm-cli.js"
14+
15+
NEW_VERSION=$("$NODE" "$NPM" view acorn-walk dist-tags.latest)
16+
CURRENT_VERSION=$("$NODE" -p "require('./deps/acorn/acorn-walk/package.json').version")
17+
18+
echo "Comparing $NEW_VERSION with $CURRENT_VERSION"
19+
20+
if [ "$NEW_VERSION" = "$CURRENT_VERSION" ]; then
21+
echo "Skipped because Acorn-walk is on the latest version."
22+
exit 0
23+
fi
24+
25+
cd "$( dirname "$0" )/../.." || exit
26+
27+
rm -rf deps/acorn/acorn-walk
28+
29+
(
30+
rm -rf acorn-walk-tmp
31+
mkdir acorn-walk-tmp
32+
cd acorn-walk-tmp || exit
33+
34+
"$NODE" "$NPM" init --yes
35+
36+
"$NODE" "$NPM" install --global-style --no-bin-links --ignore-scripts acorn-walk
37+
)
38+
39+
mv acorn-walk-tmp/node_modules/acorn-walk deps/acorn
40+
41+
rm -rf acorn-walk-tmp/
42+
43+
echo "All done!"
44+
echo ""
45+
echo "Please git add acorn-walk, commit the new version:"
46+
echo ""
47+
echo "$ git add -A deps/acorn-walk"
48+
echo "$ git commit -m \"deps: update acorn-walk to $NEW_VERSION\""
49+
echo ""
50+
51+
# The last line of the script should always print the new version,
52+
# as we need to add it to $GITHUB_ENV variable.
53+
echo "NEW_VERSION=$NEW_VERSION"

tools/update-acorn.sh tools/dep_updaters/update-acorn.sh

+30-9
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,56 @@
77

88
set -ex
99

10-
cd "$( dirname "$0" )/.." || exit
10+
ROOT=$(cd "$(dirname "$0")/../.." && pwd)
11+
[ -z "$NODE" ] && NODE="$ROOT/out/Release/node"
12+
[ -x "$NODE" ] || NODE=$(command -v node)
13+
NPM="$ROOT/deps/npm/bin/npm-cli.js"
14+
15+
NEW_VERSION=$("$NODE" "$NPM" view acorn dist-tags.latest)
16+
CURRENT_VERSION=$("$NODE" -p "require('./deps/acorn/acorn/package.json').version")
17+
18+
echo "Comparing $NEW_VERSION with $CURRENT_VERSION"
19+
20+
if [ "$NEW_VERSION" = "$CURRENT_VERSION" ]; then
21+
echo "Skipped because Acorn is on the latest version."
22+
exit 0
23+
fi
24+
25+
cd "$( dirname "$0" )/../.." || exit
26+
1127
rm -rf deps/acorn/acorn
1228

1329
(
1430
rm -rf acorn-tmp
1531
mkdir acorn-tmp
1632
cd acorn-tmp || exit
1733

18-
ROOT="$PWD/.."
19-
[ -z "$NODE" ] && NODE="$ROOT/out/Release/node"
20-
[ -x "$NODE" ] || NODE=$(command -v node)
21-
NPM="$ROOT/deps/npm/bin/npm-cli.js"
22-
2334
"$NODE" "$NPM" init --yes
2435

2536
"$NODE" "$NPM" install --global-style --no-bin-links --ignore-scripts acorn
2637
cd node_modules/acorn
27-
# get acorn version
28-
ACORN_VERSION=$("$NODE" -p "require('./package.json').version")
2938
# update this version information in src/acorn_version.h
3039
FILE_PATH="$ROOT/src/acorn_version.h"
3140
echo "// This is an auto generated file, please do not edit." > "$FILE_PATH"
3241
echo "// Refer to tools/update-acorn.sh" >> "$FILE_PATH"
3342
echo "#ifndef SRC_ACORN_VERSION_H_" >> "$FILE_PATH"
3443
echo "#define SRC_ACORN_VERSION_H_" >> "$FILE_PATH"
35-
echo "#define ACORN_VERSION \"$ACORN_VERSION\"" >> "$FILE_PATH"
44+
echo "#define ACORN_VERSION \"$NEW_VERSION\"" >> "$FILE_PATH"
3645
echo "#endif // SRC_ACORN_VERSION_H_" >> "$FILE_PATH"
3746
)
3847

3948
mv acorn-tmp/node_modules/acorn deps/acorn
4049

4150
rm -rf acorn-tmp/
51+
52+
echo "All done!"
53+
echo ""
54+
echo "Please git add acorn, commit the new version:"
55+
echo ""
56+
echo "$ git add -A deps/acorn"
57+
echo "$ git commit -m \"deps: update acorn to $NEW_VERSION\""
58+
echo ""
59+
60+
# The last line of the script should always print the new version,
61+
# as we need to add it to $GITHUB_ENV variable.
62+
echo "NEW_VERSION=$NEW_VERSION"

tools/update-acorn-walk.sh

-30
This file was deleted.

0 commit comments

Comments
 (0)