Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
install-node: Upgrade Node.js to 18.14.0; manage Yarn with Corepack.
Anders Kaseorgec58b6790d9e
diff --git a/docs/subsystems/dependencies.md b/docs/subsystems/dependencies.mdindex 4fa35122753..8e63cc51b01 100644--- a/docs/subsystems/dependencies.md+++ b/docs/subsystems/dependencies.md@@ -250,16 +250,15 @@ reasoning here.## Node.js and YarnNode.js is installed by `scripts/lib/install-node` to-`/srv/zulip-node` and symlinked to `/usr/local/bin/node`. Yarn is-installed by `scripts/lib/install-yarn` to `/srv/zulip-yarn` and-symlinked to `/usr/bin/yarn`.+`/srv/zulip-node` and symlinked to `/usr/local/bin/node`. A Yarn+symlink at `/usr/local/bin/yarn` is managed by+[Corepack](https://nodejs.org/api/corepack.html).We don't do anything special to try to manage multiple versions of-Node.js or Yarn. (Previous versions of Zulip installed multiple-versions of Node.js using the third-party `nvm` installer, but the-current version no longer uses `nvm`; if it’s present in-`/usr/local/nvm` where previous versions installed it, it will now be-removed.)+Node.js. (Previous versions of Zulip installed multiple versions of+Node.js using the third-party `nvm` installer, but the current version+no longer uses `nvm`; if it’s present in `/usr/local/nvm` where+previous versions installed it, it will now be removed.)## ShellCheck and shfmtdiff --git a/frontend_tests/node_tests/timerender.js b/frontend_tests/node_tests/timerender.jsindex c3c94310e78..6716923bad6 100644--- a/frontend_tests/node_tests/timerender.js+++ b/frontend_tests/node_tests/timerender.js@@ -158,7 +158,7 @@ run_test("format_time_modern_different_timezones", () => {assert.equal(timerender.format_time_modern(yesterday, today), "translated: Yesterday");process.env.TZ = "America/Juneau";- let expected = "translated: 5/16/2017 at 11:12:53 PM AKDT (UTC-08:00)";+ let expected = "translated: 5/16/2017 at 11:12:53 PM AKDT (UTC-08:00)";assert.equal(timerender.get_full_datetime(yesterday), expected);assert.equal(timerender.format_time_modern(yesterday, today), "Tuesday");process.env.TZ = utc_tz;@@ -169,7 +169,7 @@ run_test("format_time_modern_different_timezones", () => {assert.equal(timerender.format_time_modern(yesterday, today), "Tuesday");process.env.TZ = "Asia/Brunei";- expected = "translated: 5/17/2017 at 5:12:53 AM (UTC+08:00)";+ expected = "translated: 5/17/2017 at 5:12:53 AM (UTC+08:00)";assert.equal(timerender.get_full_datetime(yesterday), expected);assert.equal(timerender.format_time_modern(yesterday, today), "translated: Yesterday");process.env.TZ = utc_tz;@@ -180,7 +180,7 @@ run_test("format_time_modern_different_timezones", () => {assert.equal(timerender.format_time_modern(yesterday, today), "Friday");process.env.TZ = "America/Juneau";- expected = "translated: 5/11/2017 at 11:12:53 PM AKDT (UTC-08:00)";+ expected = "translated: 5/11/2017 at 11:12:53 PM AKDT (UTC-08:00)";assert.equal(timerender.get_full_datetime(yesterday), expected);assert.equal(timerender.format_time_modern(yesterday, today), "May 11");process.env.TZ = utc_tz;@@ -340,7 +340,7 @@ run_test("absolute_time_24_hour", () => {run_test("get_full_datetime", () => {const time = date_2017_PM;- let expected = "translated: 5/18/2017 at 9:12:53 PM UTC";+ let expected = "translated: 5/18/2017 at 9:12:53 PM UTC";assert.equal(timerender.get_full_datetime(time), expected);// test 24 hour time setting.@@ -353,7 +353,7 @@ run_test("get_full_datetime", () => {// Test the GMT[+-]x:y logic.const previous_env_tz = process.env.TZ;process.env.TZ = "Asia/Kolkata";- expected = "translated: 5/19/2017 at 2:42:53 AM (UTC+05:30)";+ expected = "translated: 5/19/2017 at 2:42:53 AM (UTC+05:30)";assert.equal(timerender.get_full_datetime(time), expected);process.env.TZ = previous_env_tz;});diff --git a/package.json b/package.jsonindex f54fed3a922..8db4d3745ef 100644--- a/package.json+++ b/package.json@@ -5,6 +5,7 @@"description": "","private": true,"main": "",+ "packageManager": "[email protected]+sha256.732620bac8b1690d507274f025f3c6cfdc3627a84d9642e38a07452cc00e0f2e","dependencies": {"@babel/core": "^7.5.5","@babel/preset-env": "^7.5.5",diff --git a/scripts/lib/install b/scripts/lib/installindex 6e5df0aa59e..3c48e7c04e7 100755--- a/scripts/lib/install+++ b/scripts/lib/install@@ -390,7 +390,6 @@ if [ "$VIRTUALENV_NEEDED" = "yes" ]; thenfi"$ZULIP_PATH"/scripts/lib/install-node-"$ZULIP_PATH"/scripts/lib/install-yarn# Generate /etc/zulip/zulip.conf .mkdir -p /etc/zulipdiff --git a/scripts/lib/install-node b/scripts/lib/install-nodeindex 58296f4b98e..0a1df94f6b5 100755--- a/scripts/lib/install-node+++ b/scripts/lib/install-node@@ -1,23 +1,24 @@#!/usr/bin/env bashset -euo pipefail-version=18.12.1+version=18.14.0arch="$(uname -m)"case $arch inx86_64)tarball="node-v$version-linux-x64.tar.xz"- sha256=4481a34bf32ddb9a9ff9540338539401320e8c3628af39929b4211ea3552a19e+ sha256=1ccec74b6240fce8754813e31fdbc93ad520df2e814729cea29efe9075e48350;;aarch64)tarball="node-v$version-linux-arm64.tar.xz"- sha256=3904869935b7ecc51130b4b86486d2356539a174d11c9181180cab649f32cd2a+ sha256=30ef375f0b8006759c0e08bee9d4b74915b95abfa924006c289d2d474a8b152e;;esaccheck_version() {- out="$(node --version)" && [ "$out" = "v$version" ]+ out="$(node --version)" && [ "$out" = "v$version" ] \+ && [ /usr/local/bin/yarn -ef /srv/zulip-node/lib/node_modules/corepack/dist/yarn.js ]}if ! check_version 2>/dev/null; then@@ -33,7 +34,11 @@ if ! check_version 2>/dev/null; thenrm -rf /srv/zulip-nodemkdir -p /srv/zulip-nodetar -xJf "$tarball" --no-same-owner --strip-components=1 -C /srv/zulip-node- ln -sf /srv/zulip-node/bin/{node,npm,npx} /usr/local/bin- rm -rf /usr/local/nvm+ ln -sf /srv/zulip-node/bin/{corepack,node,npm,npx} /usr/local/bin+ COREPACK_DEFAULT_TO_LATEST=0 /usr/local/bin/corepack enable++ # Clean up after previous versions of this script+ rm -rf /srv/zulip-yarn /usr/bin/yarn /usr/local/nvm+check_versionfidiff --git a/scripts/lib/install-yarn b/scripts/lib/install-yarndeleted file mode 100755index c4574289983..00000000000--- a/scripts/lib/install-yarn+++ /dev/null@@ -1,25 +0,0 @@-#!/usr/bin/env bash-set -euo pipefail--version=1.22.19-sha256=732620bac8b1690d507274f025f3c6cfdc3627a84d9642e38a07452cc00e0f2e-tarball="yarn-$version.tgz"--check_version() {- # Reading the version of Yarn from its package.json is much faster- # than running yarn --version.- current_version="$(jq -r '.version' /srv/zulip-yarn/package.json)" \- && [ "$current_version" = "$version" ]-}--if ! check_version; then- tmpdir="$(mktemp -d)"- trap 'rm -r "$tmpdir"' EXIT- cd "$tmpdir"- curl -fLO --retry 3 "https://registry.npmjs.org/yarn/-/$tarball"- sha256sum -c <<<"$sha256 $tarball"- rm -rf /srv/zulip-yarn- mkdir /srv/zulip-yarn- tar -xzf "$tarball" --no-same-owner --strip-components=1 -C /srv/zulip-yarn- check_version-fidiff --git a/scripts/lib/node_cache.py b/scripts/lib/node_cache.pyindex 5857d5a74a5..dc0e15ed84c 100644--- a/scripts/lib/node_cache.py+++ b/scripts/lib/node_cache.py@@ -11,8 +11,7 @@ ZULIP_PATH = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__fZULIP_SRV_PATH = "/srv"NODE_MODULES_CACHE_PATH = os.path.join(ZULIP_SRV_PATH, "zulip-npm-cache")-YARN_BIN = os.path.join(ZULIP_SRV_PATH, "zulip-yarn/bin/yarn")-YARN_PACKAGE_JSON = os.path.join(ZULIP_SRV_PATH, "zulip-yarn/package.json")+YARN_BIN = "/usr/local/bin/yarn"DEFAULT_PRODUCTION = False@@ -40,8 +39,6 @@ def generate_sha1sum_node_modules(# For backwards compatibility, we can't assume yarn.lock existswith open(YARN_LOCK_FILE_PATH) as f:data[YARN_LOCK_FILE_PATH] = f.read().strip()- with open(YARN_PACKAGE_JSON) as f:- data["yarn-package-version"] = json.load(f)["version"]data["node-version"] = subprocess.check_output(["node", "--version"], text=True).strip()data["yarn-args"] = get_yarn_args(production=production)diff --git a/scripts/lib/setup_venv.py b/scripts/lib/setup_venv.pyindex 4f016f388fd..2f0346100b2 100644--- a/scripts/lib/setup_venv.py+++ b/scripts/lib/setup_venv.py@@ -29,11 +29,7 @@ VENV_DEPENDENCIES = [# Needed by python-xmlsec:"libxmlsec1-dev","pkg-config",- # This is technically a node dependency, but we add it here- # because we don't have another place that we install apt packages- # on upgrade of a production server, and it's not worth adding- # another call to `apt install` for.- "jq", # Used by scripts/lib/install-yarn to check yarn version+ "jq", # No longer used in production (clean me up later)"libsasl2-dev", # For building python-ldap from source]diff --git a/scripts/lib/upgrade-zulip-stage-2 b/scripts/lib/upgrade-zulip-stage-2index d619d8e151c..c0031a0b1d2 100755--- a/scripts/lib/upgrade-zulip-stage-2+++ b/scripts/lib/upgrade-zulip-stage-2@@ -263,7 +263,6 @@ if not args.skip_downgrade_check:# Make sure the right version of node is installedsubprocess.check_call([os.path.join(deploy_path, "scripts", "lib", "install-node")])-subprocess.check_call([os.path.join(deploy_path, "scripts", "lib", "install-yarn")])# Generate any new secrets that were added in the new version required.# TODO: Do caching to only run this when it has changed.diff --git a/tools/ci/production-build b/tools/ci/production-buildindex a524afec753..a097dc30ebe 100755--- a/tools/ci/production-build+++ b/tools/ci/production-build@@ -45,7 +45,7 @@ cp -a \# Check that webpack bundles use only ES2019 syntax.# Use the yarn binary installed by tools/provision.-YARN="/srv/zulip-yarn/bin/yarn"+YARN="/usr/local/bin/yarn"tar -C /tmp -xzf /tmp/production-build/zulip-server-test.tar.gz zulip-server-test/prod-static/serve/webpack-bundles(GLOBIGNORE=/tmp/zulip-server-test/prod-static/serve/webpack-bundles/katex-cli.jsdiff --git a/tools/lib/provision.py b/tools/lib/provision.pyindex 9849f1009a7..4c8e70866ff 100755--- a/tools/lib/provision.py+++ b/tools/lib/provision.py@@ -399,7 +399,6 @@ def main(options: argparse.Namespace) -> NoReturn:"no_proxy=" + os.environ.get("no_proxy", ""),]run_as_root([*proxy_env, "scripts/lib/install-node"], sudo_args=["-H"])- run_as_root([*proxy_env, "scripts/lib/install-yarn"])if not os.access(NODE_MODULES_CACHE_PATH, os.W_OK):run_as_root(["mkdir", "-p", NODE_MODULES_CACHE_PATH])diff --git a/tools/setup/optimize-svg b/tools/setup/optimize-svgindex 23efbb42955..8dc6f28db7b 100755--- a/tools/setup/optimize-svg+++ b/tools/setup/optimize-svg@@ -42,7 +42,7 @@ if [ "$#" -gt 0 ]; thenfiZULIP_PATH="$(readlink -f "$(dirname "$0")"/../..)"-YARN="/srv/zulip-yarn/bin/yarn"+YARN="/usr/local/bin/yarn"if [ -n "$CHECK_UNOPTIMIZED" ]; thenif [ "$(node_modules/.bin/svgo -f static/images/integrations/logos | grep -o '\.[0-9]% = ' | wc -l)" -ge 1 ]; thendiff --git a/version.py b/version.pyindex 2d36d9eb12b..23a8ecec1b3 100644--- a/version.py+++ b/version.py@@ -48,4 +48,4 @@ API_FEATURE_LEVEL = 162# historical commits sharing the same major version, in which case a# minor version bump suffices.-PROVISION_VERSION = (221, 0)+PROVISION_VERSION = (222, 0)