• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2
3# Shell script to update undici 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
8set -ex
9
10ROOT=$(cd "$(dirname "$0")/../.." && pwd)
11[ -z "$NODE" ] && NODE="$ROOT/out/Release/node"
12[ -x "$NODE" ] || NODE=$(command -v node)
13NPM="$ROOT/deps/npm/bin/npm-cli.js"
14
15NEW_VERSION=$("$NODE" "$NPM" view undici dist-tags.latest)
16CURRENT_VERSION=$("$NODE" -p "require('./deps/undici/src/package.json').version")
17
18echo "Comparing $NEW_VERSION with $CURRENT_VERSION"
19
20if [ "$NEW_VERSION" = "$CURRENT_VERSION" ]; then
21  echo "Skipped because Undici is on the latest version."
22  exit 0
23fi
24
25cd "$( dirname "$0" )/../.." || exit
26rm -rf deps/undici/src
27rm -f deps/undici/undici.js
28
29(
30    rm -rf undici-tmp
31    mkdir undici-tmp
32    cd undici-tmp || exit
33
34    "$NODE" "$NPM" init --yes
35
36    "$NODE" "$NPM" install --global-style --no-bin-links --ignore-scripts "undici@$NEW_VERSION"
37    cd node_modules/undici
38    "$NODE" "$NPM" install --no-bin-link --ignore-scripts
39    "$NODE" "$NPM" run build:node
40    "$NODE" "$NPM" prune --production
41    rm node_modules/.package-lock.json
42)
43
44# update version information in src/undici_version.h
45cat > "$ROOT/src/undici_version.h" <<EOF
46// This is an auto generated file, please do not edit.
47// Refer to tools/update-undici.sh
48#ifndef SRC_UNDICI_VERSION_H_
49#define SRC_UNDICI_VERSION_H_
50#define UNDICI_VERSION "$NEW_VERSION"
51#endif  // SRC_UNDICI_VERSION_H_
52EOF
53
54mv undici-tmp/node_modules/undici deps/undici/src
55mv deps/undici/src/undici-fetch.js deps/undici/undici.js
56cp deps/undici/src/LICENSE deps/undici/LICENSE
57
58rm -rf undici-tmp/
59
60echo "All done!"
61echo ""
62echo "Please git add and commit the new version:"
63echo ""
64echo "$ git add -A deps/undici src/undici_version.h"
65echo "$ git commit -m \"deps: update Undici to $NEW_VERSION\""
66echo ""
67
68# The last line of the script should always print the new version,
69# as we need to add it to $GITHUB_ENV variable.
70echo "NEW_VERSION=$NEW_VERSION"
71