Skip to content

Commit aa8feea

Browse files
marco-ippolitotargos
authored andcommitted
tools: improve update acorn-walk script
PR-URL: #50473 Refs: nodejs/security-wg#1037 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Paolo Insogna <paolo@cowtech.it>
1 parent 03c730b commit aa8feea

File tree

2 files changed

+47
-28
lines changed

2 files changed

+47
-28
lines changed

tools/dep_updaters/update-acorn-walk.sh

+8-11
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ DEPS_DIR="$BASE_DIR/deps"
1717
. "$BASE_DIR/tools/dep_updaters/utils.sh"
1818

1919
NEW_VERSION=$("$NODE" "$NPM" view acorn-walk dist-tags.latest)
20-
CURRENT_VERSION=$("$NODE" -p "require('./deps/acorn/acorn-walk/package.json').version")
20+
CURRENT_VERSION=$("$NODE" "$NPM" --prefix './deps/acorn/acorn-walk/' pkg get version)
2121

2222
# This function exit with 0 if new version and current version are the same
2323
compare_dependency_version "acorn-walk" "$NEW_VERSION" "$CURRENT_VERSION"
@@ -40,21 +40,17 @@ cd "$WORKSPACE"
4040

4141
echo "Fetching acorn-walk source archive..."
4242

43-
DIST_URL=$(curl -sL "https://registry.npmjs.org/acorn-walk/$NEW_VERSION" | perl -n -e '/"dist".*?"tarball":"(.*?)"/ && print $1')
43+
"$NODE" "$NPM" pack "acorn-walk@$NEW_VERSION"
4444

45-
ACORN_WALK_TGZ="acorn-walk.tgz"
46-
47-
curl -sL -o "$ACORN_WALK_TGZ" "$DIST_URL"
45+
ACORN_WALK_TGZ="acorn-walk-$NEW_VERSION.tgz"
4846

4947
log_and_verify_sha256sum "acorn-walk" "$ACORN_WALK_TGZ"
5048

5149
rm -r "$DEPS_DIR/acorn/acorn-walk"/*
5250

5351
tar -xf "$ACORN_WALK_TGZ"
5452

55-
mv "$WORKSPACE/package"/* "$DEPS_DIR/acorn/acorn-walk"
56-
57-
rm "$ACORN_WALK_TGZ"
53+
mv package/* "$DEPS_DIR/acorn/acorn-walk"
5854

5955
echo "All done!"
6056
echo ""
@@ -64,6 +60,7 @@ echo "$ git add -A deps/acorn-walk"
6460
echo "$ git commit -m \"deps: update acorn-walk to $NEW_VERSION\""
6561
echo ""
6662

67-
# The last line of the script should always print the new version,
68-
# as we need to add it to $GITHUB_ENV variable.
69-
echo "NEW_VERSION=$NEW_VERSION"
63+
# Update the version number on maintaining-dependencies.md
64+
# and print the new version as the last line of the script as we need
65+
# to add it to $GITHUB_ENV variable
66+
finalize_version_update "acorn-walk" "$NEW_VERSION"

tools/dep_updaters/update-acorn.sh

+39-17
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,53 @@
77

88
set -ex
99

10-
ROOT=$(cd "$(dirname "$0")/../.." && pwd)
11-
[ -z "$NODE" ] && NODE="$ROOT/out/Release/node"
10+
BASE_DIR=$(cd "$(dirname "$0")/../.." && pwd)
11+
[ -z "$NODE" ] && NODE="$BASE_DIR/out/Release/node"
1212
[ -x "$NODE" ] || NODE=$(command -v node)
13-
NPM="$ROOT/deps/npm/bin/npm-cli.js"
13+
NPM="$BASE_DIR/deps/npm/bin/npm-cli.js"
14+
DEPS_DIR="$BASE_DIR/deps"
1415

1516
# shellcheck disable=SC1091
16-
. "$ROOT/tools/dep_updaters/utils.sh"
17+
. "$BASE_DIR/tools/dep_updaters/utils.sh"
1718

1819
NEW_VERSION=$("$NODE" "$NPM" view acorn dist-tags.latest)
19-
CURRENT_VERSION=$("$NODE" -p "require('./deps/acorn/acorn/package.json').version")
20+
CURRENT_VERSION=$("$NODE" "$NPM" --prefix './deps/acorn/acorn/' pkg get version)
2021

2122
# This function exit with 0 if new version and current version are the same
2223
compare_dependency_version "acorn" "$NEW_VERSION" "$CURRENT_VERSION"
2324

2425
cd "$( dirname "$0" )/../.." || exit
2526

26-
rm -rf deps/acorn/acorn
27+
echo "Making temporary workspace..."
2728

28-
(
29-
rm -rf acorn-tmp
30-
mkdir acorn-tmp
31-
cd acorn-tmp || exit
29+
WORKSPACE=$(mktemp -d 2> /dev/null || mktemp -d -t 'tmp')
3230

33-
"$NODE" "$NPM" init --yes
31+
cleanup () {
32+
EXIT_CODE=$?
33+
[ -d "$WORKSPACE" ] && rm -rf "$WORKSPACE"
34+
exit $EXIT_CODE
35+
}
3436

35-
"$NODE" "$NPM" install --global-style --no-bin-links --ignore-scripts "acorn@$NEW_VERSION"
36-
)
37+
trap cleanup INT TERM EXIT
38+
39+
cd "$WORKSPACE"
40+
41+
echo "Fetching acorn source archive..."
42+
43+
"$NODE" "$NPM" pack "acorn@$NEW_VERSION"
44+
45+
ACORN_TGZ="acorn-$NEW_VERSION.tgz"
46+
47+
log_and_verify_sha256sum "acorn" "$ACORN_TGZ"
48+
49+
rm -r "$DEPS_DIR/acorn/acorn"/*
50+
51+
tar -xf "$ACORN_TGZ"
52+
53+
mv package/* "$DEPS_DIR/acorn/acorn"
3754

3855
# update version information in src/acorn_version.h
39-
cat > "$ROOT/src/acorn_version.h" <<EOF
56+
cat > "$BASE_DIR/src/acorn_version.h" <<EOF
4057
// This is an auto generated file, please do not edit.
4158
// Refer to tools/dep_updaters/update-acorn.sh
4259
#ifndef SRC_ACORN_VERSION_H_
@@ -45,9 +62,14 @@ cat > "$ROOT/src/acorn_version.h" <<EOF
4562
#endif // SRC_ACORN_VERSION_H_
4663
EOF
4764

48-
mv acorn-tmp/node_modules/acorn deps/acorn
49-
50-
rm -rf acorn-tmp/
65+
echo "All done!"
66+
echo ""
67+
echo "Please git add acorn, commit the new version:"
68+
echo ""
69+
echo "$ git add -A deps/acorn/acorn"
70+
echo "$ git add $BASE_DIR/src/acorn_version.h"
71+
echo "$ git commit -m \"deps: update acorn to $NEW_VERSION\""
72+
echo ""
5173

5274
# Update the version number on maintaining-dependencies.md
5375
# and print the new version as the last line of the script as we need

0 commit comments

Comments
 (0)