From 423c58d8c968d63069bd367b0add710ef9bc17a2 Mon Sep 17 00:00:00 2001 From: Dominik Henneke Date: Fri, 4 Aug 2023 14:16:57 +0200 Subject: [PATCH] Upgrade to Node.js 20 Signed-off-by: Dominik Henneke --- .github/workflows/ci.yml | 8 +++--- README.md | 2 +- e2e/package.json | 8 +++--- e2e/src/pages/elementWebPage.ts | 1 - e2e/src/util/deactivateUser.ts | 1 - e2e/src/util/registerUser.ts | 1 - matrix-meetings-bot/Dockerfile | 4 +-- matrix-meetings-bot/package.json | 6 ++--- matrix-meetings-bot/src/client/JitsiClient.ts | 1 - .../src/controller/HealthCheckController.ts | 1 - .../src/middleware/MatrixAuthMiddleware.ts | 1 - matrix-meetings-widget/package.json | 4 +-- .../useDownloadIcsFile.test.tsx | 2 +- .../src/timezoneMockUtils.ts | 26 ++++++++++++++----- yarn.lock | 20 +++++--------- 15 files changed, 40 insertions(+), 46 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ba19b0d9..b310299c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,7 @@ jobs: - uses: actions/setup-node@v3 with: - node-version: '16' + node-version: '20' cache: 'yarn' - name: yarn install @@ -96,7 +96,7 @@ jobs: - uses: actions/setup-node@v3 with: - node-version: '16' + node-version: '20' cache: 'yarn' - name: yarn install @@ -184,7 +184,7 @@ jobs: - uses: actions/setup-node@v3 with: - node-version: '16' + node-version: '20' cache: 'yarn' - name: yarn install @@ -221,7 +221,7 @@ jobs: - uses: actions/setup-node@v3 with: - node-version: '16' + node-version: '20' cache: 'yarn' - name: yarn install diff --git a/README.md b/README.md index 9f5beb1d..f0bf5000 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ Check the following steps to develop for the widget: ### Requirements -You need to install Node.js (`>= 16.0.0`, prefer using an LTS version) and run +You need to install Node.js (`>= 20.0.0`, prefer using an LTS version) and run `yarn` to work on this package. The minimal Element version to use this widget is `1.11.29`. diff --git a/e2e/package.json b/e2e/package.json index 3e01d29f..7b09d6b6 100644 --- a/e2e/package.json +++ b/e2e/package.json @@ -5,14 +5,12 @@ "license": "Apache-2.0", "version": "0.0.0", "private": true, - "dependencies": { - "cross-fetch": "^3.1.5" - }, + "dependencies": {}, "devDependencies": { "@axe-core/playwright": "^4.7.3", "@playwright/test": "^1.37.1", "@types/lodash": "^4.14.197", - "@types/node": "^16.18.44", + "@types/node": "^20.4.6", "eslint": "^8.47.0", "eslint-plugin-playwright": "^0.15.3", "lodash": "^4.17.21", @@ -20,7 +18,7 @@ "typescript": "^5.1.6" }, "engines": { - "node": ">=16", + "node": ">=20", "yarn": ">=1.22.1 <2.0.0" }, "scripts": { diff --git a/e2e/src/pages/elementWebPage.ts b/e2e/src/pages/elementWebPage.ts index d948c2de..86e33ed8 100644 --- a/e2e/src/pages/elementWebPage.ts +++ b/e2e/src/pages/elementWebPage.ts @@ -15,7 +15,6 @@ */ import { expect, FrameLocator, Locator, Page } from '@playwright/test'; -import fetch from 'cross-fetch'; import { Credentials, getElementWebUrl, getSynapseUrl } from '../util'; export type OpenIdToken = { diff --git a/e2e/src/util/deactivateUser.ts b/e2e/src/util/deactivateUser.ts index ec448f65..a516df5f 100644 --- a/e2e/src/util/deactivateUser.ts +++ b/e2e/src/util/deactivateUser.ts @@ -14,7 +14,6 @@ * limitations under the License. */ -import fetch from 'cross-fetch'; import { getSynapseUrl } from './config'; import { User } from './registerUser'; diff --git a/e2e/src/util/registerUser.ts b/e2e/src/util/registerUser.ts index 09b6603c..1f4d304d 100644 --- a/e2e/src/util/registerUser.ts +++ b/e2e/src/util/registerUser.ts @@ -14,7 +14,6 @@ * limitations under the License. */ -import fetch from 'cross-fetch'; import { createHmac } from 'crypto'; import { getSynapseRegistrationSecret, getSynapseUrl } from './config'; diff --git a/matrix-meetings-bot/Dockerfile b/matrix-meetings-bot/Dockerfile index 1e59be30..1fcee986 100644 --- a/matrix-meetings-bot/Dockerfile +++ b/matrix-meetings-bot/Dockerfile @@ -1,11 +1,11 @@ -FROM node:16-bullseye AS node_modules +FROM node:20-bullseye AS node_modules WORKDIR /build COPY package.json yarn.lock ./ COPY matrix-meetings-bot/package.json ./matrix-meetings-bot/ COPY resolutions/matrix-sdk-crypto-nodejs ./resolutions/matrix-sdk-crypto-nodejs/ RUN yarn install --production --frozen-lockfile --network-timeout 1000000 -FROM node:16-bullseye-slim +FROM node:20-bullseye-slim ENV NODE_ENV=production WORKDIR /app RUN set -x\ diff --git a/matrix-meetings-bot/package.json b/matrix-meetings-bot/package.json index 3f48a6e3..d151831d 100644 --- a/matrix-meetings-bot/package.json +++ b/matrix-meetings-bot/package.json @@ -27,7 +27,7 @@ "generate-disclaimer": "cp ../LICENSE ./lib/LICENSE.txt && cp NOTICE ./lib/NOTICE.txt && yarn licenses generate-disclaimer --prod >> ./lib/NOTICE.txt && yarn licenses list --prod --json --no-progress > ./lib/licenses.json" }, "engines": { - "node": ">=16", + "node": ">=20", "yarn": ">=1.22.1 <2.0.0" }, "dependencies": { @@ -54,7 +54,6 @@ "moment-timezone": "^0.5.43", "mustache": "^4.2.0", "nestjs-pino": "^3.4.0", - "node-fetch": "^2.6.13", "pino": "^8.15.0", "pino-http": "^8.4.0", "reflect-metadata": "^0.1.13", @@ -70,8 +69,7 @@ "@types/luxon": "^3.2.0", "@types/mime-types": "^2.1.1", "@types/mustache": "^4.2.2", - "@types/node": "^16.18.44", - "@types/node-fetch": "^2.6.4", + "@types/node": "^20.4.6", "@types/uuid": "^9.0.2", "copyfiles": "^2.4.1", "depcheck": "^1.4.5", diff --git a/matrix-meetings-bot/src/client/JitsiClient.ts b/matrix-meetings-bot/src/client/JitsiClient.ts index 3757b412..b27c4145 100644 --- a/matrix-meetings-bot/src/client/JitsiClient.ts +++ b/matrix-meetings-bot/src/client/JitsiClient.ts @@ -15,7 +15,6 @@ */ import { Inject, Injectable, Logger } from '@nestjs/common'; -import fetch from 'node-fetch'; import { base32 } from 'rfc4648'; import { IAppConfiguration } from '../IAppConfiguration'; import { ModuleProviderToken } from '../ModuleProviderToken'; diff --git a/matrix-meetings-bot/src/controller/HealthCheckController.ts b/matrix-meetings-bot/src/controller/HealthCheckController.ts index 63bdf3ac..fc389517 100644 --- a/matrix-meetings-bot/src/controller/HealthCheckController.ts +++ b/matrix-meetings-bot/src/controller/HealthCheckController.ts @@ -15,7 +15,6 @@ */ import { Controller, Get, HttpException, Inject } from '@nestjs/common'; -import fetch from 'node-fetch'; import { IAppConfiguration } from '../IAppConfiguration'; import { ModuleProviderToken } from '../ModuleProviderToken'; diff --git a/matrix-meetings-bot/src/middleware/MatrixAuthMiddleware.ts b/matrix-meetings-bot/src/middleware/MatrixAuthMiddleware.ts index 75a2aff4..497e2151 100644 --- a/matrix-meetings-bot/src/middleware/MatrixAuthMiddleware.ts +++ b/matrix-meetings-bot/src/middleware/MatrixAuthMiddleware.ts @@ -17,7 +17,6 @@ import { Inject, Injectable, Logger, NestMiddleware } from '@nestjs/common'; import base64url from 'base64url'; import { NextFunction, Request, Response } from 'express'; -import fetch from 'node-fetch'; import { IAppConfiguration } from '../IAppConfiguration'; import { MatrixEndpoint } from '../MatrixEndpoint'; import { ModuleProviderToken } from '../ModuleProviderToken'; diff --git a/matrix-meetings-widget/package.json b/matrix-meetings-widget/package.json index e56ec623..bd6c19f6 100644 --- a/matrix-meetings-widget/package.json +++ b/matrix-meetings-widget/package.json @@ -53,7 +53,7 @@ "@types/lodash": "^4.14.197", "@types/luxon": "^3.2.0", "@types/mustache": "^4.2.2", - "@types/node": "^16.18.44", + "@types/node": "^20.4.6", "@types/react": "^17.0.53", "@types/react-dom": "^17.0.19", "@types/react-i18next": "^8.1.0", @@ -68,7 +68,7 @@ "typescript": "^5.1.6" }, "engines": { - "node": ">=16", + "node": ">=20", "yarn": ">=1.22.1 <2.0.0" }, "scripts": { diff --git a/matrix-meetings-widget/src/components/meetings/MeetingCardShareMeetingContent/useDownloadIcsFile.test.tsx b/matrix-meetings-widget/src/components/meetings/MeetingCardShareMeetingContent/useDownloadIcsFile.test.tsx index e1ec6981..a7c5aa09 100644 --- a/matrix-meetings-widget/src/components/meetings/MeetingCardShareMeetingContent/useDownloadIcsFile.test.tsx +++ b/matrix-meetings-widget/src/components/meetings/MeetingCardShareMeetingContent/useDownloadIcsFile.test.tsx @@ -85,7 +85,7 @@ describe('useDownloadIcsFile', () => { slice: jest.fn(), stream: jest.fn(), text: jest.fn(), - }); + } as unknown as Blob); (URL.createObjectURL as jest.Mock).mockReturnValue('blob:url'); diff --git a/matrix-meetings-widget/src/timezoneMockUtils.ts b/matrix-meetings-widget/src/timezoneMockUtils.ts index 39f1804f..2d4f39fa 100644 --- a/matrix-meetings-widget/src/timezoneMockUtils.ts +++ b/matrix-meetings-widget/src/timezoneMockUtils.ts @@ -20,13 +20,25 @@ import { Settings } from 'luxon'; const DateTimeFormat = Intl.DateTimeFormat; export function mockDateTimeFormatTimeZone(timeZone: string): void { - jest.spyOn(Intl, 'DateTimeFormat').mockImplementation( - (locale, options) => - new DateTimeFormat(locale, { - ...options, - timeZone: options?.timeZone ?? timeZone, - }) - ); + jest.spyOn(Intl, 'DateTimeFormat').mockImplementation((locale, options) => { + const format = new DateTimeFormat(locale, { + ...options, + timeZone: options?.timeZone ?? timeZone, + }); + + // replace all uncommon whitespace characters with ' '. Relates to https://github.com/nodejs/node/pull/45068 + // where the unicode standard decided to use U+2009 in some cases. This breaks some of our tests + const originalFormatRange = format.formatRange; + jest + .spyOn(format, 'formatRange') + .mockImplementation((startDate, endDate) => + originalFormatRange + .call(format, startDate, endDate) + .replace(/\s+/g, ' ') + ); + + return format; + }); // make sure getTimezoneOffset is based on the provided timezone and // not the system diff --git a/yarn.lock b/yarn.lock index 33e48b53..7b6d70eb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2950,18 +2950,10 @@ resolved "https://registry.yarnpkg.com/@types/mustache/-/mustache-4.2.2.tgz#825bf5c214c3ab84d0b23fef2c8eb898f3ff8717" integrity sha512-MUSpfpW0yZbTgjekDbH0shMYBUD+X/uJJJMm9LXN1d5yjl5lCY1vN/eWKD6D1tOtjA6206K0zcIPnUaFMurdNA== -"@types/node-fetch@^2.6.4": - version "2.6.4" - resolved "https://registry.yarnpkg.com/@types/node-fetch/-/node-fetch-2.6.4.tgz#1bc3a26de814f6bf466b25aeb1473fa1afe6a660" - integrity sha512-1ZX9fcN4Rvkvgv4E6PAY5WXUFWFcRWxZa3EW83UjycOB9ljJCedb2CupIP4RZMEwF/M3eTcCihbBRgwtGbg5Rg== - dependencies: - "@types/node" "*" - form-data "^3.0.0" - -"@types/node@*", "@types/node@^16.18.44": - version "16.18.44" - resolved "https://registry.yarnpkg.com/@types/node/-/node-16.18.44.tgz#3c3ea2a832014b869f0f370630d98bb026171e76" - integrity sha512-PZXtT+wqSMHnLPVExTh+tMt1VK+GvjRLsGZMbcQ4Mb/cG63xJig/TUmgrDa9aborl2i22UnpIzHYNu7s97NbBQ== +"@types/node@*", "@types/node@^20.4.6": + version "20.5.4" + resolved "https://registry.yarnpkg.com/@types/node/-/node-20.5.4.tgz#4666fb40f9974d60c53c4ff554315860ba4feab8" + integrity sha512-Y9vbIAoM31djQZrPYjpTLo0XlaSwOIsrlfE3LpulZeRblttsLQRFRlBAppW0LOxyT3ALj2M5vU1ucQQayQH3jA== "@types/node@^12.7.1": version "12.20.52" @@ -4996,7 +4988,7 @@ cross-env@^7.0.3: dependencies: cross-spawn "^7.0.1" -cross-fetch@3.1.5, cross-fetch@^3.0.4, cross-fetch@^3.1.5: +cross-fetch@3.1.5, cross-fetch@^3.0.4: version "3.1.5" resolved "https://registry.yarnpkg.com/cross-fetch/-/cross-fetch-3.1.5.tgz#e1389f44d9e7ba767907f7af8454787952ab534f" integrity sha512-lvb1SBsI0Z7GDwmuid+mU3kWVBwTVUbe7S0H52yaaAdQOXq2YktTCZdlAcNKFzE6QtRz0snpw9bNiPeOIkkQvw== @@ -9489,7 +9481,7 @@ node-fetch@2.6.7: dependencies: whatwg-url "^5.0.0" -node-fetch@^2.6.1, node-fetch@^2.6.12, node-fetch@^2.6.13, node-fetch@^2.6.7: +node-fetch@^2.6.1, node-fetch@^2.6.12, node-fetch@^2.6.7: version "2.6.13" resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.13.tgz#a20acbbec73c2e09f9007de5cda17104122e0010" integrity sha512-StxNAxh15zr77QvvkmveSQ8uCQ4+v5FkvNTj0OESmiHu+VRi/gXArXtkWMElOsOUNLtUEvI4yS+rdtOHZTwlQA==