From e016674ea7df5c43e04884dafbc334e6b6626167 Mon Sep 17 00:00:00 2001 From: Marco Ippolito Date: Mon, 10 Apr 2023 21:38:08 +0200 Subject: [PATCH] tools: move update-acorn.sh to dep_updaters and create maintaining md PR-URL: https://github.com/nodejs/node/pull/47382 Refs: https://github.com/nodejs/security-wg/issues/828 Reviewed-By: Paolo Insogna Reviewed-By: Rafael Gonzaga Reviewed-By: Luigi Pinca --- .github/workflows/tools.yml | 20 ++++----- doc/contributing/maintaining-acorn.md | 47 +++++++++++++++++++++ tools/dep_updaters/update-acorn-walk.sh | 53 ++++++++++++++++++++++++ tools/{ => dep_updaters}/update-acorn.sh | 39 +++++++++++++---- tools/update-acorn-walk.sh | 30 -------------- 5 files changed, 138 insertions(+), 51 deletions(-) create mode 100644 doc/contributing/maintaining-acorn.md create mode 100755 tools/dep_updaters/update-acorn-walk.sh rename tools/{ => dep_updaters}/update-acorn.sh (50%) delete mode 100644 tools/update-acorn-walk.sh diff --git a/.github/workflows/tools.yml b/.github/workflows/tools.yml index be8c57f5dfc1f1..b8706753f3965d 100644 --- a/.github/workflows/tools.yml +++ b/.github/workflows/tools.yml @@ -95,22 +95,18 @@ jobs: subsystem: deps label: dependencies run: | - NEW_VERSION=$(npm view acorn dist-tags.latest) - CURRENT_VERSION=$(node -p "require('./deps/acorn/acorn/package.json').version") - if [ "$NEW_VERSION" != "$CURRENT_VERSION" ]; then - echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV - ./tools/update-acorn.sh - fi + ./tools/dep_updaters/update-acorn.sh > temp-output + cat temp-output + tail -n1 temp-output | grep "NEW_VERSION=" >> "$GITHUB_ENV" || true + rm temp-output - id: acorn-walk subsystem: deps label: dependencies run: | - NEW_VERSION=$(npm view acorn-walk dist-tags.latest) - CURRENT_VERSION=$(node -p "require('./deps/acorn/acorn-walk/package.json').version") - if [ "$NEW_VERSION" != "$CURRENT_VERSION" ]; then - echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV - ./tools/update-acorn-walk.sh - fi + ./tools/dep_updaters/update-acorn-walk.sh > temp-output + cat temp-output + tail -n1 temp-output | grep "NEW_VERSION=" >> "$GITHUB_ENV" || true + rm temp-output - id: libuv subsystem: deps label: dependencies diff --git a/doc/contributing/maintaining-acorn.md b/doc/contributing/maintaining-acorn.md new file mode 100644 index 00000000000000..ef73c07627a31b --- /dev/null +++ b/doc/contributing/maintaining-acorn.md @@ -0,0 +1,47 @@ +# Maintaining acorn + +The [acorn](https://github.com/acornjs/acorn) dependency is a JavaScript parser. +[acorn-walk](https://github.com/acornjs/acorn/tree/master/acorn-walk) is +an abstract syntax tree walker for the ESTree format. + +## Updating acorn + +The `tools/dep_updaters/update-acorn.sh` script automates the update of the +acorn source files. + +Check that Node.js still builds and tests. + +## Committing acorn + +1. Add acorn: + ```console + $ git add deps/acorn + ``` +2. Commit the changes: `git commit`. +3. Add a message like: + ```text + deps: update acorn to + + Updated as described in doc/contributing/maintaining-acorn.md. + ``` + +## Updating acorn-walk + +The `tools/dep_updaters/update-acorn-walk.sh` script automates the update of the +acorn-walk source files. + +Check that Node.js still builds and tests. + +## Committing acorn-walk + +1. Add acorn-walk: + ```console + $ git add deps/acorn-walk + ``` +2. Commit the changes: `git commit`. +3. Add a message like: + ```text + deps: update acorn-walk to + + Updated as described in doc/contributing/maintaining-acorn.md. + ``` diff --git a/tools/dep_updaters/update-acorn-walk.sh b/tools/dep_updaters/update-acorn-walk.sh new file mode 100755 index 00000000000000..c90da38bce2cee --- /dev/null +++ b/tools/dep_updaters/update-acorn-walk.sh @@ -0,0 +1,53 @@ +#!/bin/sh + +# Shell script to update acorn-walk in the source tree to the latest release. + +# This script must be in the tools directory when it runs because it uses the +# script source file path to determine directories to work in. + +set -ex + +ROOT=$(cd "$(dirname "$0")/../.." && pwd) +[ -z "$NODE" ] && NODE="$ROOT/out/Release/node" +[ -x "$NODE" ] || NODE=$(command -v node) +NPM="$ROOT/deps/npm/bin/npm-cli.js" + +NEW_VERSION=$("$NODE" "$NPM" view acorn-walk dist-tags.latest) +CURRENT_VERSION=$("$NODE" -p "require('./deps/acorn/acorn-walk/package.json').version") + +echo "Comparing $NEW_VERSION with $CURRENT_VERSION" + +if [ "$NEW_VERSION" = "$CURRENT_VERSION" ]; then + echo "Skipped because Acorn-walk is on the latest version." + exit 0 +fi + +cd "$( dirname "$0" )/../.." || exit + +rm -rf deps/acorn/acorn-walk + +( + rm -rf acorn-walk-tmp + mkdir acorn-walk-tmp + cd acorn-walk-tmp || exit + + "$NODE" "$NPM" init --yes + + "$NODE" "$NPM" install --global-style --no-bin-links --ignore-scripts acorn-walk +) + +mv acorn-walk-tmp/node_modules/acorn-walk deps/acorn + +rm -rf acorn-walk-tmp/ + +echo "All done!" +echo "" +echo "Please git add acorn-walk, commit the new version:" +echo "" +echo "$ git add -A deps/acorn-walk" +echo "$ git commit -m \"deps: update acorn-walk to $NEW_VERSION\"" +echo "" + +# The last line of the script should always print the new version, +# as we need to add it to $GITHUB_ENV variable. +echo "NEW_VERSION=$NEW_VERSION" diff --git a/tools/update-acorn.sh b/tools/dep_updaters/update-acorn.sh similarity index 50% rename from tools/update-acorn.sh rename to tools/dep_updaters/update-acorn.sh index 514b5e509706d2..6e43973c4f73d9 100755 --- a/tools/update-acorn.sh +++ b/tools/dep_updaters/update-acorn.sh @@ -7,7 +7,23 @@ set -ex -cd "$( dirname "$0" )/.." || exit +ROOT=$(cd "$(dirname "$0")/../.." && pwd) +[ -z "$NODE" ] && NODE="$ROOT/out/Release/node" +[ -x "$NODE" ] || NODE=$(command -v node) +NPM="$ROOT/deps/npm/bin/npm-cli.js" + +NEW_VERSION=$("$NODE" "$NPM" view acorn dist-tags.latest) +CURRENT_VERSION=$("$NODE" -p "require('./deps/acorn/acorn/package.json').version") + +echo "Comparing $NEW_VERSION with $CURRENT_VERSION" + +if [ "$NEW_VERSION" = "$CURRENT_VERSION" ]; then + echo "Skipped because Acorn is on the latest version." + exit 0 +fi + +cd "$( dirname "$0" )/../.." || exit + rm -rf deps/acorn/acorn ( @@ -15,27 +31,32 @@ rm -rf deps/acorn/acorn mkdir acorn-tmp cd acorn-tmp || exit - ROOT="$PWD/.." - [ -z "$NODE" ] && NODE="$ROOT/out/Release/node" - [ -x "$NODE" ] || NODE=$(command -v node) - NPM="$ROOT/deps/npm/bin/npm-cli.js" - "$NODE" "$NPM" init --yes "$NODE" "$NPM" install --global-style --no-bin-links --ignore-scripts acorn cd node_modules/acorn - # get acorn version - ACORN_VERSION=$("$NODE" -p "require('./package.json').version") # update this version information in src/acorn_version.h FILE_PATH="$ROOT/src/acorn_version.h" echo "// This is an auto generated file, please do not edit." > "$FILE_PATH" echo "// Refer to tools/update-acorn.sh" >> "$FILE_PATH" echo "#ifndef SRC_ACORN_VERSION_H_" >> "$FILE_PATH" echo "#define SRC_ACORN_VERSION_H_" >> "$FILE_PATH" - echo "#define ACORN_VERSION \"$ACORN_VERSION\"" >> "$FILE_PATH" + echo "#define ACORN_VERSION \"$NEW_VERSION\"" >> "$FILE_PATH" echo "#endif // SRC_ACORN_VERSION_H_" >> "$FILE_PATH" ) mv acorn-tmp/node_modules/acorn deps/acorn rm -rf acorn-tmp/ + +echo "All done!" +echo "" +echo "Please git add acorn, commit the new version:" +echo "" +echo "$ git add -A deps/acorn" +echo "$ git commit -m \"deps: update acorn to $NEW_VERSION\"" +echo "" + +# The last line of the script should always print the new version, +# as we need to add it to $GITHUB_ENV variable. +echo "NEW_VERSION=$NEW_VERSION" diff --git a/tools/update-acorn-walk.sh b/tools/update-acorn-walk.sh deleted file mode 100644 index 0d8670742728ea..00000000000000 --- a/tools/update-acorn-walk.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/sh - -# Shell script to update acorn-walk in the source tree to the latest release. - -# This script must be in the tools directory when it runs because it uses the -# script source file path to determine directories to work in. - -set -ex - -cd "$( dirname "$0" )/.." || exit -rm -rf deps/acorn/acorn-walk - -( - rm -rf acorn-walk-tmp - mkdir acorn-walk-tmp - cd acorn-walk-tmp || exit - - ROOT="$PWD/.." - [ -z "$NODE" ] && NODE="$ROOT/out/Release/node" - [ -x "$NODE" ] || NODE=$(command -v node) - NPM="$ROOT/deps/npm/bin/npm-cli.js" - - "$NODE" "$NPM" init --yes - - "$NODE" "$NPM" install --global-style --no-bin-links --ignore-scripts acorn-walk -) - -mv acorn-walk-tmp/node_modules/acorn-walk deps/acorn - -rm -rf acorn-walk-tmp/