Skip to content

Commit 237d568

Browse files
anderskUjjwalAggarwal-1
authored andcommitted
install-node: Upgrade Node.js to 18.14.0; manage Yarn with Corepack.
Corepack manages multiple per-project version of Yarn and PNPM, which means we have to maintain less installation code, and could help us switch away from Yarn 1 without making the system unusable for development of other Yarn 1 projects. https://nodejs.org/api/corepack.html The Unicode spaces in the timerender test resulted from an ICU upgrade: nodejs/node#45068. Signed-off-by: Anders Kaseorg <anders@zulip.com>
1 parent c44cd88 commit 237d568

13 files changed

+29
-59
lines changed

docs/subsystems/dependencies.md

+7-8
Original file line numberDiff line numberDiff line change
@@ -250,16 +250,15 @@ reasoning here.
250250
## Node.js and Yarn
251251

252252
Node.js is installed by `scripts/lib/install-node` to
253-
`/srv/zulip-node` and symlinked to `/usr/local/bin/node`. Yarn is
254-
installed by `scripts/lib/install-yarn` to `/srv/zulip-yarn` and
255-
symlinked to `/usr/bin/yarn`.
253+
`/srv/zulip-node` and symlinked to `/usr/local/bin/node`. A Yarn
254+
symlink at `/usr/local/bin/yarn` is managed by
255+
[Corepack](https://nodejs.org/api/corepack.html).
256256

257257
We don't do anything special to try to manage multiple versions of
258-
Node.js or Yarn. (Previous versions of Zulip installed multiple
259-
versions of Node.js using the third-party `nvm` installer, but the
260-
current version no longer uses `nvm`; if it’s present in
261-
`/usr/local/nvm` where previous versions installed it, it will now be
262-
removed.)
258+
Node.js. (Previous versions of Zulip installed multiple versions of
259+
Node.js using the third-party `nvm` installer, but the current version
260+
no longer uses `nvm`; if it’s present in `/usr/local/nvm` where
261+
previous versions installed it, it will now be removed.)
263262

264263
## ShellCheck and shfmt
265264

frontend_tests/node_tests/timerender.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ run_test("format_time_modern_different_timezones", () => {
158158
assert.equal(timerender.format_time_modern(yesterday, today), "translated: Yesterday");
159159

160160
process.env.TZ = "America/Juneau";
161-
let expected = "translated: 5/16/2017 at 11:12:53 PM AKDT (UTC-08:00)";
161+
let expected = "translated: 5/16/2017 at 11:12:53PM AKDT (UTC-08:00)";
162162
assert.equal(timerender.get_full_datetime(yesterday), expected);
163163
assert.equal(timerender.format_time_modern(yesterday, today), "Tuesday");
164164
process.env.TZ = utc_tz;
@@ -169,7 +169,7 @@ run_test("format_time_modern_different_timezones", () => {
169169
assert.equal(timerender.format_time_modern(yesterday, today), "Tuesday");
170170

171171
process.env.TZ = "Asia/Brunei";
172-
expected = "translated: 5/17/2017 at 5:12:53 AM (UTC+08:00)";
172+
expected = "translated: 5/17/2017 at 5:12:53AM (UTC+08:00)";
173173
assert.equal(timerender.get_full_datetime(yesterday), expected);
174174
assert.equal(timerender.format_time_modern(yesterday, today), "translated: Yesterday");
175175
process.env.TZ = utc_tz;
@@ -180,7 +180,7 @@ run_test("format_time_modern_different_timezones", () => {
180180
assert.equal(timerender.format_time_modern(yesterday, today), "Friday");
181181

182182
process.env.TZ = "America/Juneau";
183-
expected = "translated: 5/11/2017 at 11:12:53 PM AKDT (UTC-08:00)";
183+
expected = "translated: 5/11/2017 at 11:12:53PM AKDT (UTC-08:00)";
184184
assert.equal(timerender.get_full_datetime(yesterday), expected);
185185
assert.equal(timerender.format_time_modern(yesterday, today), "May 11");
186186
process.env.TZ = utc_tz;
@@ -340,7 +340,7 @@ run_test("absolute_time_24_hour", () => {
340340
run_test("get_full_datetime", () => {
341341
const time = date_2017_PM;
342342

343-
let expected = "translated: 5/18/2017 at 9:12:53 PM UTC";
343+
let expected = "translated: 5/18/2017 at 9:12:53PM UTC";
344344
assert.equal(timerender.get_full_datetime(time), expected);
345345

346346
// test 24 hour time setting.
@@ -353,7 +353,7 @@ run_test("get_full_datetime", () => {
353353
// Test the GMT[+-]x:y logic.
354354
const previous_env_tz = process.env.TZ;
355355
process.env.TZ = "Asia/Kolkata";
356-
expected = "translated: 5/19/2017 at 2:42:53 AM (UTC+05:30)";
356+
expected = "translated: 5/19/2017 at 2:42:53AM (UTC+05:30)";
357357
assert.equal(timerender.get_full_datetime(time), expected);
358358
process.env.TZ = previous_env_tz;
359359
});

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"description": "",
66
"private": true,
77
"main": "",
8+
"packageManager": "yarn@1.22.19+sha256.732620bac8b1690d507274f025f3c6cfdc3627a84d9642e38a07452cc00e0f2e",
89
"dependencies": {
910
"@babel/core": "^7.5.5",
1011
"@babel/preset-env": "^7.5.5",

scripts/lib/install

-1
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,6 @@ if [ "$VIRTUALENV_NEEDED" = "yes" ]; then
390390
fi
391391

392392
"$ZULIP_PATH"/scripts/lib/install-node
393-
"$ZULIP_PATH"/scripts/lib/install-yarn
394393

395394
# Generate /etc/zulip/zulip.conf .
396395
mkdir -p /etc/zulip

scripts/lib/install-node

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
#!/usr/bin/env bash
22
set -euo pipefail
33

4-
version=18.12.1
4+
version=18.14.0
55
arch="$(uname -m)"
66

77
case $arch in
88
x86_64)
99
tarball="node-v$version-linux-x64.tar.xz"
10-
sha256=4481a34bf32ddb9a9ff9540338539401320e8c3628af39929b4211ea3552a19e
10+
sha256=1ccec74b6240fce8754813e31fdbc93ad520df2e814729cea29efe9075e48350
1111
;;
1212

1313
aarch64)
1414
tarball="node-v$version-linux-arm64.tar.xz"
15-
sha256=3904869935b7ecc51130b4b86486d2356539a174d11c9181180cab649f32cd2a
15+
sha256=30ef375f0b8006759c0e08bee9d4b74915b95abfa924006c289d2d474a8b152e
1616
;;
1717
esac
1818

1919
check_version() {
20-
out="$(node --version)" && [ "$out" = "v$version" ]
20+
out="$(node --version)" && [ "$out" = "v$version" ] \
21+
&& [ /usr/local/bin/yarn -ef /srv/zulip-node/lib/node_modules/corepack/dist/yarn.js ]
2122
}
2223

2324
if ! check_version 2>/dev/null; then
@@ -33,7 +34,11 @@ if ! check_version 2>/dev/null; then
3334
rm -rf /srv/zulip-node
3435
mkdir -p /srv/zulip-node
3536
tar -xJf "$tarball" --no-same-owner --strip-components=1 -C /srv/zulip-node
36-
ln -sf /srv/zulip-node/bin/{node,npm,npx} /usr/local/bin
37-
rm -rf /usr/local/nvm
37+
ln -sf /srv/zulip-node/bin/{corepack,node,npm,npx} /usr/local/bin
38+
COREPACK_DEFAULT_TO_LATEST=0 /usr/local/bin/corepack enable
39+
40+
# Clean up after previous versions of this script
41+
rm -rf /srv/zulip-yarn /usr/bin/yarn /usr/local/nvm
42+
3843
check_version
3944
fi

scripts/lib/install-yarn

-25
This file was deleted.

scripts/lib/node_cache.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
ZULIP_SRV_PATH = "/srv"
1212

1313
NODE_MODULES_CACHE_PATH = os.path.join(ZULIP_SRV_PATH, "zulip-npm-cache")
14-
YARN_BIN = os.path.join(ZULIP_SRV_PATH, "zulip-yarn/bin/yarn")
15-
YARN_PACKAGE_JSON = os.path.join(ZULIP_SRV_PATH, "zulip-yarn/package.json")
14+
YARN_BIN = "/usr/local/bin/yarn"
1615

1716
DEFAULT_PRODUCTION = False
1817

@@ -40,8 +39,6 @@ def generate_sha1sum_node_modules(
4039
# For backwards compatibility, we can't assume yarn.lock exists
4140
with open(YARN_LOCK_FILE_PATH) as f:
4241
data[YARN_LOCK_FILE_PATH] = f.read().strip()
43-
with open(YARN_PACKAGE_JSON) as f:
44-
data["yarn-package-version"] = json.load(f)["version"]
4542
data["node-version"] = subprocess.check_output(["node", "--version"], text=True).strip()
4643
data["yarn-args"] = get_yarn_args(production=production)
4744

scripts/lib/setup_venv.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,7 @@
2929
# Needed by python-xmlsec:
3030
"libxmlsec1-dev",
3131
"pkg-config",
32-
# This is technically a node dependency, but we add it here
33-
# because we don't have another place that we install apt packages
34-
# on upgrade of a production server, and it's not worth adding
35-
# another call to `apt install` for.
36-
"jq", # Used by scripts/lib/install-yarn to check yarn version
32+
"jq", # No longer used in production (clean me up later)
3733
"libsasl2-dev", # For building python-ldap from source
3834
]
3935

scripts/lib/upgrade-zulip-stage-2

-1
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,6 @@ if not args.skip_downgrade_check:
263263

264264
# Make sure the right version of node is installed
265265
subprocess.check_call([os.path.join(deploy_path, "scripts", "lib", "install-node")])
266-
subprocess.check_call([os.path.join(deploy_path, "scripts", "lib", "install-yarn")])
267266

268267
# Generate any new secrets that were added in the new version required.
269268
# TODO: Do caching to only run this when it has changed.

tools/ci/production-build

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ cp -a \
4545

4646
# Check that webpack bundles use only ES2019 syntax.
4747
# Use the yarn binary installed by tools/provision.
48-
YARN="/srv/zulip-yarn/bin/yarn"
48+
YARN="/usr/local/bin/yarn"
4949
tar -C /tmp -xzf /tmp/production-build/zulip-server-test.tar.gz zulip-server-test/prod-static/serve/webpack-bundles
5050
(
5151
GLOBIGNORE=/tmp/zulip-server-test/prod-static/serve/webpack-bundles/katex-cli.js

tools/lib/provision.py

-1
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,6 @@ def main(options: argparse.Namespace) -> NoReturn:
399399
"no_proxy=" + os.environ.get("no_proxy", ""),
400400
]
401401
run_as_root([*proxy_env, "scripts/lib/install-node"], sudo_args=["-H"])
402-
run_as_root([*proxy_env, "scripts/lib/install-yarn"])
403402

404403
if not os.access(NODE_MODULES_CACHE_PATH, os.W_OK):
405404
run_as_root(["mkdir", "-p", NODE_MODULES_CACHE_PATH])

tools/setup/optimize-svg

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ if [ "$#" -gt 0 ]; then
4242
fi
4343

4444
ZULIP_PATH="$(readlink -f "$(dirname "$0")"/../..)"
45-
YARN="/srv/zulip-yarn/bin/yarn"
45+
YARN="/usr/local/bin/yarn"
4646

4747
if [ -n "$CHECK_UNOPTIMIZED" ]; then
4848
if [ "$(node_modules/.bin/svgo -f static/images/integrations/logos | grep -o '\.[0-9]% = ' | wc -l)" -ge 1 ]; then

version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,4 @@
4848
# historical commits sharing the same major version, in which case a
4949
# minor version bump suffices.
5050

51-
PROVISION_VERSION = (221, 0)
51+
PROVISION_VERSION = (222, 0)

0 commit comments

Comments
 (0)