Skip to content

Commit 58bbbaa

Browse files
committed
tools: make undici updater build wasm from src
- modify updater to include all files required to rebuild wasm from what's stored in the deps/undici directory - modify updater to build wasm from source while updating Signed-off-by: Michael Dawson <mdawson@devrus.com>
1 parent 277ed9f commit 58bbbaa

File tree

1 file changed

+62
-19
lines changed

1 file changed

+62
-19
lines changed

tools/dep_updaters/update-undici.sh

Lines changed: 62 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,85 @@
55
# This script must be in the tools directory when it runs because it uses the
66
# script source file path to determine directories to work in.
77

8-
set -ex
8+
set -e
99

1010
ROOT=$(cd "$(dirname "$0")/../.." && pwd)
11+
DEPS_DIR="$ROOT/deps"
1112
[ -z "$NODE" ] && NODE="$ROOT/out/Release/node"
1213
[ -x "$NODE" ] || NODE=$(command -v node)
1314
NPM="$ROOT/deps/npm/bin/npm-cli.js"
1415

1516
# shellcheck disable=SC1091
1617
. "$ROOT/tools/dep_updaters/utils.sh"
1718

18-
NEW_VERSION=$("$NODE" "$NPM" view undici dist-tags.latest)
19-
CURRENT_VERSION=$("$NODE" -p "require('./deps/undici/src/package.json').version")
19+
NEW_VERSION="$("$NODE" --input-type=module <<'EOF'
20+
const res = await fetch('https://api.github.com/repos/nodejs/undici/releases/latest',
21+
process.env.GITHUB_TOKEN && {
22+
headers: {
23+
"Authorization": `Bearer ${process.env.GITHUB_TOKEN}`
24+
},
25+
});
26+
if (!res.ok) throw new Error(`FetchError: ${res.status} ${res.statusText}`, { cause: res });
27+
const { tag_name } = await res.json();
28+
console.log(tag_name.replace('v', ''));
29+
EOF
30+
)"
31+
32+
CURRENT_VERSION=$("$NODE" -p "require('$DEPS_DIR/undici/src/package.json').version")
33+
34+
echo "$CURRENT_VERSION"
35+
echo "$NEW_VERSION"
2036

2137
# This function exit with 0 if new version and current version are the same
2238
compare_dependency_version "undici" "$NEW_VERSION" "$CURRENT_VERSION"
2339

24-
cd "$( dirname "$0" )/../.." || exit
2540
rm -rf deps/undici/src
2641
rm -f deps/undici/undici.js
2742

43+
WORKSPACE=$(mktemp -d 2> /dev/null || mktemp -d -t 'tmp')
44+
echo "$WORKSPACE"
45+
cleanup () {
46+
EXIT_CODE=$?
47+
[ -d "$WORKSPACE" ] && rm -rf "$WORKSPACE"
48+
exit $EXIT_CODE
49+
}
50+
51+
trap cleanup INT TERM EXIT
52+
53+
UNDICI_ZIP="undici-$NEW_VERSION"
54+
cd "$WORKSPACE"
55+
56+
echo "Fetching UNDICI source archive..."
57+
curl -sL -o "$UNDICI_ZIP.zip" "https://github.com/nodejs/undici/archive/refs/tags/v$NEW_VERSION.zip"
58+
59+
log_and_verify_sha256sum "undici" "$UNDICI_ZIP.zip"
60+
61+
echo "Unzipping..."
62+
unzip "$UNDICI_ZIP.zip" -d "src"
63+
mv "src/$UNDICI_ZIP" "$DEPS_DIR/undici/src"
64+
rm "$UNDICI_ZIP.zip"
65+
cd "$ROOT"
66+
2867
(
29-
rm -rf undici-tmp
30-
mkdir undici-tmp
31-
cd undici-tmp || exit
32-
33-
"$NODE" "$NPM" init --yes
34-
35-
"$NODE" "$NPM" install --global-style --no-bin-links --ignore-scripts "undici@$NEW_VERSION"
36-
cd node_modules/undici
37-
"$NODE" "$NPM" install --no-bin-link --ignore-scripts
38-
"$NODE" "$NPM" run build:node
39-
"$NODE" "$NPM" prune --production
40-
rm node_modules/.package-lock.json
68+
cd "$DEPS_DIR/undici/src"
69+
70+
# remove components we don't need to keep in nodejs/deps
71+
rm -rf .husky || true
72+
rm -rf .github || true
73+
rm -rf test
74+
rm -rf benchmarks
75+
rm -rf docs-tmp
76+
mv docs docs-tmp
77+
mkdir docs
78+
mv docs-tmp/docs docs/docs
79+
rm -rf docs-tmp
80+
81+
# Rebuild components from source
82+
rm lib/llhttp/llhttp*.*
83+
"$NODE" "$NPM" install --no-bin-link --ignore-scripts
84+
"$NODE" "$NPM" run build:wasm > lib/llhttp/wasm_build_env.txt
85+
"$NODE" "$NPM" run build:node
86+
"$NODE" "$NPM" prune --production
4187
)
4288

4389
# update version information in src/undici_version.h
@@ -50,12 +96,9 @@ cat > "$ROOT/src/undici_version.h" <<EOF
5096
#endif // SRC_UNDICI_VERSION_H_
5197
EOF
5298

53-
mv undici-tmp/node_modules/undici deps/undici/src
5499
mv deps/undici/src/undici-fetch.js deps/undici/undici.js
55100
cp deps/undici/src/LICENSE deps/undici/LICENSE
56101

57-
rm -rf undici-tmp/
58-
59102
# Update the version number on maintaining-dependencies.md
60103
# and print the new version as the last line of the script as we need
61104
# to add it to $GITHUB_ENV variable

0 commit comments

Comments
 (0)