2022-03-07 16:36:29 +01:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
# Shell script to update undici 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.
|
|
|
|
|
2024-07-31 03:27:39 +02:00
|
|
|
set -e
|
2022-03-07 16:36:29 +01:00
|
|
|
|
2023-04-03 11:52:59 +02:00
|
|
|
ROOT=$(cd "$(dirname "$0")/../.." && pwd)
|
2024-07-31 03:27:39 +02:00
|
|
|
DEPS_DIR="$ROOT/deps"
|
2023-04-03 11:52:59 +02:00
|
|
|
[ -z "$NODE" ] && NODE="$ROOT/out/Release/node"
|
|
|
|
[ -x "$NODE" ] || NODE=$(command -v node)
|
|
|
|
NPM="$ROOT/deps/npm/bin/npm-cli.js"
|
|
|
|
|
2023-06-06 11:07:34 +02:00
|
|
|
# shellcheck disable=SC1091
|
|
|
|
. "$ROOT/tools/dep_updaters/utils.sh"
|
|
|
|
|
2024-07-31 03:27:39 +02:00
|
|
|
NEW_VERSION="$("$NODE" --input-type=module <<'EOF'
|
|
|
|
const res = await fetch('https://api.github.com/repos/nodejs/undici/releases/latest',
|
|
|
|
process.env.GITHUB_TOKEN && {
|
|
|
|
headers: {
|
|
|
|
"Authorization": `Bearer ${process.env.GITHUB_TOKEN}`
|
|
|
|
},
|
|
|
|
});
|
|
|
|
if (!res.ok) throw new Error(`FetchError: ${res.status} ${res.statusText}`, { cause: res });
|
|
|
|
const { tag_name } = await res.json();
|
|
|
|
console.log(tag_name.replace('v', ''));
|
|
|
|
EOF
|
|
|
|
)"
|
|
|
|
|
|
|
|
CURRENT_VERSION=$("$NODE" -p "require('$DEPS_DIR/undici/src/package.json').version")
|
|
|
|
|
|
|
|
echo "$CURRENT_VERSION"
|
|
|
|
echo "$NEW_VERSION"
|
2023-04-03 11:52:59 +02:00
|
|
|
|
2023-06-06 11:07:34 +02:00
|
|
|
# This function exit with 0 if new version and current version are the same
|
|
|
|
compare_dependency_version "undici" "$NEW_VERSION" "$CURRENT_VERSION"
|
2023-04-03 11:52:59 +02:00
|
|
|
|
2022-03-07 16:36:29 +01:00
|
|
|
rm -rf deps/undici/src
|
|
|
|
rm -f deps/undici/undici.js
|
|
|
|
|
2024-07-31 03:27:39 +02:00
|
|
|
WORKSPACE=$(mktemp -d 2> /dev/null || mktemp -d -t 'tmp')
|
|
|
|
echo "$WORKSPACE"
|
|
|
|
cleanup () {
|
|
|
|
EXIT_CODE=$?
|
|
|
|
[ -d "$WORKSPACE" ] && rm -rf "$WORKSPACE"
|
|
|
|
exit $EXIT_CODE
|
|
|
|
}
|
|
|
|
|
|
|
|
trap cleanup INT TERM EXIT
|
|
|
|
|
|
|
|
UNDICI_ZIP="undici-$NEW_VERSION"
|
|
|
|
cd "$WORKSPACE"
|
|
|
|
|
|
|
|
echo "Fetching UNDICI source archive..."
|
|
|
|
curl -sL -o "$UNDICI_ZIP.zip" "https://github.com/nodejs/undici/archive/refs/tags/v$NEW_VERSION.zip"
|
|
|
|
|
|
|
|
log_and_verify_sha256sum "undici" "$UNDICI_ZIP.zip"
|
|
|
|
|
|
|
|
echo "Unzipping..."
|
|
|
|
unzip "$UNDICI_ZIP.zip" -d "src"
|
|
|
|
mv "src/$UNDICI_ZIP" "$DEPS_DIR/undici/src"
|
|
|
|
rm "$UNDICI_ZIP.zip"
|
|
|
|
cd "$ROOT"
|
|
|
|
|
2022-03-07 16:36:29 +01:00
|
|
|
(
|
2024-07-31 03:27:39 +02:00
|
|
|
cd "$DEPS_DIR/undici/src"
|
|
|
|
|
|
|
|
# remove components we don't need to keep in nodejs/deps
|
|
|
|
rm -rf .husky || true
|
|
|
|
rm -rf .github || true
|
|
|
|
rm -rf test
|
|
|
|
rm -rf benchmarks
|
|
|
|
rm -rf docs-tmp
|
|
|
|
mv docs docs-tmp
|
|
|
|
mkdir docs
|
|
|
|
mv docs-tmp/docs docs/docs
|
|
|
|
rm -rf docs-tmp
|
|
|
|
|
|
|
|
# Rebuild components from source
|
|
|
|
rm lib/llhttp/llhttp*.*
|
|
|
|
"$NODE" "$NPM" install --no-bin-link --ignore-scripts
|
|
|
|
"$NODE" "$NPM" run build:wasm > lib/llhttp/wasm_build_env.txt
|
|
|
|
"$NODE" "$NPM" run build:node
|
|
|
|
"$NODE" "$NPM" prune --production
|
2022-03-07 16:36:29 +01:00
|
|
|
)
|
|
|
|
|
2023-05-29 12:59:52 +02:00
|
|
|
# update version information in src/undici_version.h
|
|
|
|
cat > "$ROOT/src/undici_version.h" <<EOF
|
|
|
|
// This is an auto generated file, please do not edit.
|
2023-10-15 22:28:23 +02:00
|
|
|
// Refer to tools/dep_updaters/update-undici.sh
|
2023-05-29 12:59:52 +02:00
|
|
|
#ifndef SRC_UNDICI_VERSION_H_
|
|
|
|
#define SRC_UNDICI_VERSION_H_
|
|
|
|
#define UNDICI_VERSION "$NEW_VERSION"
|
|
|
|
#endif // SRC_UNDICI_VERSION_H_
|
|
|
|
EOF
|
|
|
|
|
2022-05-02 14:15:50 +02:00
|
|
|
mv deps/undici/src/undici-fetch.js deps/undici/undici.js
|
2022-03-07 16:36:29 +01:00
|
|
|
cp deps/undici/src/LICENSE deps/undici/LICENSE
|
|
|
|
|
2023-06-06 11:07:34 +02:00
|
|
|
# Update the version number on maintaining-dependencies.md
|
|
|
|
# and print the new version as the last line of the script as we need
|
|
|
|
# to add it to $GITHUB_ENV variable
|
|
|
|
finalize_version_update "undici" "$NEW_VERSION" "src/undici_version.h"
|