From 21143c3a78f4b685129e9f4df2e0fab299585bed Mon Sep 17 00:00:00 2001 From: Erick Cardenas Date: Thu, 26 Oct 2023 18:14:01 -0400 Subject: [PATCH 1/5] fix: set front-end to Node v20, fix use of ts-node --- .github/workflows/deploy-preview-branch.yml | 4 ++-- .github/workflows/deploy-staging.yml | 4 ++-- .github/workflows/eslint.yml | 4 ++-- .github/workflows/jsonlint.yml | 4 ++-- .github/workflows/prettier.yml | 4 ++-- .github/workflows/typecheck.yml | 4 ++-- .github/workflows/unit_test.yml | 4 ++-- .github/workflows/validate_generate_files.yml | 4 ++-- .github/workflows/validate_generated_files.yml | 4 ++-- mockserver/.node-version | 1 + web/.node-version | 1 + web/package.json | 6 +++--- web/scripts/register-tsNodeESM.js | 3 +++ 13 files changed, 26 insertions(+), 21 deletions(-) create mode 100644 mockserver/.node-version create mode 100644 web/.node-version create mode 100644 web/scripts/register-tsNodeESM.js diff --git a/.github/workflows/deploy-preview-branch.yml b/.github/workflows/deploy-preview-branch.yml index f8730e1a8b..ae190dd216 100644 --- a/.github/workflows/deploy-preview-branch.yml +++ b/.github/workflows/deploy-preview-branch.yml @@ -21,10 +21,10 @@ jobs: uses: pnpm/action-setup@v2 with: version: 8 - - name: Setup Node v18.x + - name: Setup Node uses: actions/setup-node@v3 with: - node-version: 18 + node-version-file: './web/.node-version' - name: Restore node_modules for web id: cache-web uses: actions/cache@v3 diff --git a/.github/workflows/deploy-staging.yml b/.github/workflows/deploy-staging.yml index 3a39c8ba5a..02b36bf154 100644 --- a/.github/workflows/deploy-staging.yml +++ b/.github/workflows/deploy-staging.yml @@ -17,10 +17,10 @@ jobs: uses: pnpm/action-setup@v2 with: version: 8 - - name: Setup Node v18.x + - name: Setup Node uses: actions/setup-node@v3 with: - node-version: 18 + node-version-file: './web/.node-version' - name: Restore node_modules for web id: cache-web uses: actions/cache@v3 diff --git a/.github/workflows/eslint.yml b/.github/workflows/eslint.yml index ef7e752113..25bd00daf1 100644 --- a/.github/workflows/eslint.yml +++ b/.github/workflows/eslint.yml @@ -21,10 +21,10 @@ jobs: uses: pnpm/action-setup@v2 with: version: 8 - - name: Setup Node v18.x + - name: Setup Node uses: actions/setup-node@v3 with: - node-version: 18 + node-version-file: './web/.node-version' - name: Restore node_modules for web id: cache-web uses: actions/cache@v3 diff --git a/.github/workflows/jsonlint.yml b/.github/workflows/jsonlint.yml index b3ee41e351..b1e3b93e69 100644 --- a/.github/workflows/jsonlint.yml +++ b/.github/workflows/jsonlint.yml @@ -11,10 +11,10 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 - - name: Setup Node LTS + - name: Setup Node uses: actions/setup-node@v3 with: - node-version: 18 + node-version-file: './web/.node-version' - name: Install jsonlint-mod run: | npm install -g jsonlint-mod diff --git a/.github/workflows/prettier.yml b/.github/workflows/prettier.yml index 186350697e..c6552ec5a2 100644 --- a/.github/workflows/prettier.yml +++ b/.github/workflows/prettier.yml @@ -15,10 +15,10 @@ jobs: uses: pnpm/action-setup@v2 with: version: 8 - - name: Setup Node v18.x + - name: Setup Node uses: actions/setup-node@v3 with: - node-version: 18 + node-version-file: './web/.node-version' - name: Restore node_modules for web id: cache-web uses: actions/cache@v3 diff --git a/.github/workflows/typecheck.yml b/.github/workflows/typecheck.yml index e77aa71cea..58df5566f6 100644 --- a/.github/workflows/typecheck.yml +++ b/.github/workflows/typecheck.yml @@ -16,10 +16,10 @@ jobs: uses: pnpm/action-setup@v2 with: version: 8 - - name: Setup Node v18.x + - name: Setup Node uses: actions/setup-node@v3 with: - node-version: 18 + node-version-file: './web/.node-version' - name: Restore node_modules for web id: cache-web uses: actions/cache@v3 diff --git a/.github/workflows/unit_test.yml b/.github/workflows/unit_test.yml index fdbf74b41b..8a5cd99c73 100644 --- a/.github/workflows/unit_test.yml +++ b/.github/workflows/unit_test.yml @@ -16,10 +16,10 @@ jobs: uses: pnpm/action-setup@v2 with: version: 8 - - name: Setup Node v18.x + - name: Setup Node uses: actions/setup-node@v3 with: - node-version: 18 + node-version-file: './web/.node-version' - name: Restore node_modules for web id: cache-web uses: actions/cache@v3 diff --git a/.github/workflows/validate_generate_files.yml b/.github/workflows/validate_generate_files.yml index 2800b208c2..0fc5f3c6aa 100644 --- a/.github/workflows/validate_generate_files.yml +++ b/.github/workflows/validate_generate_files.yml @@ -16,10 +16,10 @@ jobs: uses: pnpm/action-setup@v2 with: version: 8 - - name: Setup Node v18.x + - name: Setup Node uses: actions/setup-node@v3 with: - node-version: 18 + node-version-file: './web/.node-version' - name: Restore node_modules for web id: cache-web uses: actions/cache@v3 diff --git a/.github/workflows/validate_generated_files.yml b/.github/workflows/validate_generated_files.yml index 164bfa29ff..2a2493e005 100644 --- a/.github/workflows/validate_generated_files.yml +++ b/.github/workflows/validate_generated_files.yml @@ -16,10 +16,10 @@ jobs: uses: pnpm/action-setup@v2 with: version: 8 - - name: Setup Node v18.x + - name: Setup Node uses: actions/setup-node@v3 with: - node-version: 18 + node-version-file: './web/.node-version' - name: Restore node_modules id: cache uses: actions/cache@v3 diff --git a/mockserver/.node-version b/mockserver/.node-version new file mode 100644 index 0000000000..209e3ef4b6 --- /dev/null +++ b/mockserver/.node-version @@ -0,0 +1 @@ +20 diff --git a/web/.node-version b/web/.node-version new file mode 100644 index 0000000000..209e3ef4b6 --- /dev/null +++ b/web/.node-version @@ -0,0 +1 @@ +20 diff --git a/web/package.json b/web/package.json index cb3c8522bf..51233c6230 100644 --- a/web/package.json +++ b/web/package.json @@ -14,8 +14,8 @@ "build": "pnpm update-version && vite build", "update-version": "echo '{\"version\": \"'$npm_package_version'\"}' > public/client-version.json", "create-generated-files": "pnpm run generate-world && pnpm run generate-zones-config", - "generate-world": "ts-node --esm ./geo/generateWorld.ts", - "generate-zones-config": "ts-node --esm ./scripts/generateZonesConfig.ts", + "generate-world": "node --import=./scripts/register-tsNodeESM.js ./geo/generateWorld.ts", + "generate-zones-config": "node --import=./scripts/register-tsNodeESM.js ./scripts/generateZonesConfig.ts", "predev": "pnpm run create-generated-files", "dev": "vite --open", "cy:component": "cypress open --component -b electron", @@ -195,7 +195,7 @@ "workbox-window": "7.0.0" }, "engines": { - "node": ">=18", + "node": "^20", "pnpm": "^8" } } diff --git a/web/scripts/register-tsNodeESM.js b/web/scripts/register-tsNodeESM.js new file mode 100644 index 0000000000..8d68effb8f --- /dev/null +++ b/web/scripts/register-tsNodeESM.js @@ -0,0 +1,3 @@ +import { register } from 'node:module'; +import { pathToFileURL } from 'node:url'; +register('ts-node/esm', pathToFileURL('./')); From 94c553e0e3027dc0fbb0d22bd9378c5d99e8b185 Mon Sep 17 00:00:00 2001 From: Erick Cardenas Date: Mon, 30 Oct 2023 11:07:20 -0400 Subject: [PATCH 2/5] fix: Cypress CI workflow now uses required Node version and dependencies cache --- .github/workflows/cypress.yml | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/.github/workflows/cypress.yml b/.github/workflows/cypress.yml index 290fbf4ae0..485e900117 100644 --- a/.github/workflows/cypress.yml +++ b/.github/workflows/cypress.yml @@ -12,6 +12,20 @@ jobs: uses: pnpm/action-setup@v2 with: version: 8 + - name: Setup Node + uses: actions/setup-node@v3 + with: + node-version-file: './web/.node-version' + - name: Restore node_modules for web + id: cache-web + uses: actions/cache@v3 + with: + path: web/node_modules + key: ${{ runner.os }}-node_modules-${{ hashFiles('./web/pnpm-lock.yaml') }} + - name: Install web dependencies + if: steps.cache-web.outputs.cache-hit != 'true' + run: pnpm install --frozen-lockfile + working-directory: ./web - name: Cypress run component tests uses: cypress-io/github-action@v6 env: @@ -38,6 +52,20 @@ jobs: uses: pnpm/action-setup@v2 with: version: 8 + - name: Setup Node + uses: actions/setup-node@v3 + with: + node-version-file: './web/.node-version' + - name: Restore node_modules for web + id: cache-web + uses: actions/cache@v3 + with: + path: web/node_modules + key: ${{ runner.os }}-node_modules-${{ hashFiles('./web/pnpm-lock.yaml') }} + - name: Install web dependencies + if: steps.cache-web.outputs.cache-hit != 'true' + run: pnpm install --frozen-lockfile + working-directory: ./web - name: Cypress run e2e tests uses: cypress-io/github-action@v6 env: From ee7ed176142bc941d0b0d05b12e0ca8649450040 Mon Sep 17 00:00:00 2001 From: Erick Cardenas Date: Mon, 30 Oct 2023 11:24:03 -0400 Subject: [PATCH 3/5] fix: Add install=false for cypress-io/github-action --- .github/workflows/cypress.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/cypress.yml b/.github/workflows/cypress.yml index 485e900117..48e865f536 100644 --- a/.github/workflows/cypress.yml +++ b/.github/workflows/cypress.yml @@ -32,7 +32,7 @@ jobs: TZ: Europe/Copenhagen with: working-directory: ./web - install: true + install: false # to run component tests we need to use "component: true" component: true - name: Upload screenshots @@ -72,6 +72,7 @@ jobs: TZ: Europe/Copenhagen with: working-directory: ./web + install: false build: pnpm run build --mode testing start: pnpm run preview config: baseUrl=http://127.0.0.1:4173/ From 62f0b70b13013b2f9d16595ab0e09dde92f4439a Mon Sep 17 00:00:00 2001 From: Erick Cardenas Date: Tue, 31 Oct 2023 10:28:21 -0400 Subject: [PATCH 4/5] fix: in CI workflow, install and cache Cypress binary --- .github/workflows/cypress.yml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/.github/workflows/cypress.yml b/.github/workflows/cypress.yml index 48e865f536..cb1bb4647c 100644 --- a/.github/workflows/cypress.yml +++ b/.github/workflows/cypress.yml @@ -16,6 +16,12 @@ jobs: uses: actions/setup-node@v3 with: node-version-file: './web/.node-version' + - name: Cache Cypress binary + id: cache-cypress + uses: actions/cache@v3 + with: + path: ~/.cache/Cypress + key: ${{ runner.os }}-cypress-${{ hashFiles('./web/pnpm-lock.yaml') }} - name: Restore node_modules for web id: cache-web uses: actions/cache@v3 @@ -26,6 +32,10 @@ jobs: if: steps.cache-web.outputs.cache-hit != 'true' run: pnpm install --frozen-lockfile working-directory: ./web + - name: Install Cypress binary + if: steps.cache-cypress.outputs.cache-hit != 'true' + run: pnpm exec cypress install + working-directory: ./web - name: Cypress run component tests uses: cypress-io/github-action@v6 env: @@ -56,6 +66,12 @@ jobs: uses: actions/setup-node@v3 with: node-version-file: './web/.node-version' + - name: Cache Cypress binary + id: cache-cypress + uses: actions/cache@v3 + with: + path: ~/.cache/Cypress + key: ${{ runner.os }}-cypress-${{ hashFiles('./web/pnpm-lock.yaml') }} - name: Restore node_modules for web id: cache-web uses: actions/cache@v3 @@ -66,6 +82,10 @@ jobs: if: steps.cache-web.outputs.cache-hit != 'true' run: pnpm install --frozen-lockfile working-directory: ./web + - name: Install Cypress binary + if: steps.cache-cypress.outputs.cache-hit != 'true' + run: pnpm exec cypress install + working-directory: ./web - name: Cypress run e2e tests uses: cypress-io/github-action@v6 env: From dfac6675d7298963e0e317c4a7660c0e528bb5c7 Mon Sep 17 00:00:00 2001 From: Erick Cardenas Date: Tue, 31 Oct 2023 10:36:14 -0400 Subject: [PATCH 5/5] docs: add JSDoc description to register-tsNodeESM.js file --- web/scripts/register-tsNodeESM.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/web/scripts/register-tsNodeESM.js b/web/scripts/register-tsNodeESM.js index 8d68effb8f..b4124d0e8e 100644 --- a/web/scripts/register-tsNodeESM.js +++ b/web/scripts/register-tsNodeESM.js @@ -1,3 +1,8 @@ +/** + * This script is meant to be used with 'node --import=register-tsNodeESM.js', and allows + * node v20 to use ts-node to execute Typescript files that contain ESM modules, without + * outputting JS files. + */ import { register } from 'node:module'; import { pathToFileURL } from 'node:url'; register('ts-node/esm', pathToFileURL('./'));