From 316f7ef1a368d3042f9a475c40c0f00e9d1e083f Mon Sep 17 00:00:00 2001 From: Roy Razon Date: Tue, 28 May 2024 18:46:06 +0300 Subject: [PATCH] fix compatibility with node v22 (#493) - remove import `with` keyword, see https://github.com/livecycle/preevy/issues/492. tried replacing with newer `assert` syntax but it was [breaking](https://github.com/nodejs/node/pull/52104#issuecomment-2000337367) older node 18 versions. - upgrade azure package to support node v22 - bump packaged oclif node version to latest LTS (20.13.1) - bump node version for CI workflows to 20.x - keep supported version in package.json to >=18.0.0 --------- Co-authored-by: Roy Razon --- .github/workflows/awesome-lint.yaml | 2 +- .../workflows/check-package-mismatches.yaml | 2 +- .github/workflows/gh-release.yaml | 2 +- .github/workflows/lint.yaml | 2 +- .github/workflows/npm-publish-canary.yaml | 2 +- .github/workflows/test.yaml | 4 +- packages/cli/package.json | 4 +- packages/driver-azure/package.json | 4 +- .../src/driver/client/common.ts | 2 + .../src/driver/client/index.ts | 6 +-- .../src/driver/client/metadata.ts | 6 +-- .../src/driver/creation-driver.ts | 13 +++++- packages/driver-kube-pod/src/static.ts | 3 +- yarn.lock | 44 +++++++++---------- 14 files changed, 53 insertions(+), 43 deletions(-) diff --git a/.github/workflows/awesome-lint.yaml b/.github/workflows/awesome-lint.yaml index 22eab2dc..74ab2e00 100644 --- a/.github/workflows/awesome-lint.yaml +++ b/.github/workflows/awesome-lint.yaml @@ -14,7 +14,7 @@ jobs: fetch-depth: 0 - uses: actions/setup-node@v4 with: - node-version: 18 + node-version: '20.x' - name: Check awesome-list linter # https://github.com/sindresorhus/awesome/blob/main/pull_request_template.md run: npx --yes awesome-lint ./README.md diff --git a/.github/workflows/check-package-mismatches.yaml b/.github/workflows/check-package-mismatches.yaml index 991218d5..77d015f3 100644 --- a/.github/workflows/check-package-mismatches.yaml +++ b/.github/workflows/check-package-mismatches.yaml @@ -12,6 +12,6 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: - node-version: 18 + node-version: '20.x' - name: Check mismatched dependencies in workspace run: npx --yes syncpack@11.2.1 check-mismatches diff --git a/.github/workflows/gh-release.yaml b/.github/workflows/gh-release.yaml index 5f99b30c..94216d13 100644 --- a/.github/workflows/gh-release.yaml +++ b/.github/workflows/gh-release.yaml @@ -27,7 +27,7 @@ jobs: - uses: actions/setup-node@v4 with: - node-version: '18.x' + node-version: '20.x' cache: yarn - run: yarn diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index 1b9f9e52..b49aab35 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -15,7 +15,7 @@ jobs: - uses: actions/setup-node@v4 with: - node-version: '18.x' + node-version: '20.x' cache: yarn - run: yarn diff --git a/.github/workflows/npm-publish-canary.yaml b/.github/workflows/npm-publish-canary.yaml index b8fea1fe..93d57dde 100644 --- a/.github/workflows/npm-publish-canary.yaml +++ b/.github/workflows/npm-publish-canary.yaml @@ -26,7 +26,7 @@ jobs: - uses: actions/setup-node@v4 with: - node-version: '18.x' + node-version: '20.x' cache: yarn - run: yarn diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index db184310..c5b336df 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -13,7 +13,7 @@ jobs: - uses: actions/setup-node@v4 with: - node-version: '18.x' + node-version: '20.x' cache: yarn - run: yarn @@ -31,7 +31,7 @@ jobs: - uses: actions/setup-node@v4 with: - node-version: '18.x' + node-version: '20.x' cache: yarn - run: yarn diff --git a/packages/cli/package.json b/packages/cli/package.json index 7f257d42..455eeb30 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -94,9 +94,9 @@ "topicSeparator": " ", "update": { "node": { - "version": "18.19.0", + "version": "20.13.1", "options": [ - "--no-warnings=ExperimentalWarning", + "--disable-warning=ExperimentalWarning", "--enable-source-maps" ] }, diff --git a/packages/driver-azure/package.json b/packages/driver-azure/package.json index 5622c23a..b741d3cd 100644 --- a/packages/driver-azure/package.json +++ b/packages/driver-azure/package.json @@ -18,7 +18,7 @@ "@azure/arm-resources": "^5.2.0", "@azure/arm-storage": "^18.2.0", "@azure/arm-subscriptions": "^5.1.0", - "@azure/identity": "^3.2.2", + "@azure/identity": "^4.2.0", "@azure/logger": "^1.0.4", "@azure/storage-blob": "^12.17.0", "@inquirer/prompts": "^3.3.0", @@ -59,4 +59,4 @@ "prepack": "yarn clean && yarn build", "prepare": "cd ../.. && husky install" } -} +} \ No newline at end of file diff --git a/packages/driver-kube-pod/src/driver/client/common.ts b/packages/driver-kube-pod/src/driver/client/common.ts index ab5602bd..ef0c28e5 100644 --- a/packages/driver-kube-pod/src/driver/client/common.ts +++ b/packages/driver-kube-pod/src/driver/client/common.ts @@ -15,3 +15,5 @@ export const bodyOrUndefined = async - package: Package | Promise + package: Package | undefined | Promise storageClass: string | undefined storageSize: number }) => { @@ -278,7 +278,7 @@ export const kubeCreationClient = ({ }) ), strategy: serverSideApply - ? applyStrategies.serverSideApply({ fieldManager: (await packageDetails).name }) + ? applyStrategies.serverSideApply({ fieldManager: (await packageDetails ?? defaultPackage).name }) : applyStrategies.clientSideApply, }) diff --git a/packages/driver-kube-pod/src/driver/client/metadata.ts b/packages/driver-kube-pod/src/driver/client/metadata.ts index b5ff3069..e453e124 100644 --- a/packages/driver-kube-pod/src/driver/client/metadata.ts +++ b/packages/driver-kube-pod/src/driver/client/metadata.ts @@ -3,7 +3,7 @@ import { ensureDefined, extractDefined, randomString, truncatePrefix } from '@pr import { pick } from 'lodash-es' import { tryParseJson } from '@preevy/common' import { sanitizeLabel, sanitizeLabels } from './labels.js' -import { HasMetadata, Package } from './common.js' +import { HasMetadata, Package, defaultPackage } from './common.js' import { KubernetesType } from './dynamic/index.js' export const MAX_LABEL_LENGTH = 63 @@ -70,12 +70,12 @@ export const addAllTypesAnnotation = ( } export const addEnvMetadata = ( - { profileId, envId, createdAt, instance, package: { name, version }, templateHash }: { + { profileId, envId, createdAt, instance, package: { name, version } = defaultPackage, templateHash }: { profileId: string envId: string createdAt: Date instance: string - package: Package + package?: Package templateHash: string }, ) => ( diff --git a/packages/driver-kube-pod/src/driver/creation-driver.ts b/packages/driver-kube-pod/src/driver/creation-driver.ts index 811d1e71..efabe705 100644 --- a/packages/driver-kube-pod/src/driver/creation-driver.ts +++ b/packages/driver-kube-pod/src/driver/creation-driver.ts @@ -8,7 +8,8 @@ import { inspect } from 'util' import { DeploymentMachine, ResourceType, StatefulSetMachine, k8sObjectToMachine } from './common.js' import { clientFromConfiguration, listMachines, machineConnection, flags as machineDriverFlags, parseRfc1123Flag } from './driver.js' import { Client, CreationClient, kubeCreationClient, loadKubeConfig } from './client/index.js' -import { DEFAULT_TEMPLATE, packageJson } from '../static.js' +import { DEFAULT_TEMPLATE, packageJsonPath } from '../static.js' +import { Package } from './client/common.js' export const flags = { ...machineDriverFlags, @@ -103,6 +104,14 @@ const machineCreationDriver = ( type FlagTypes = Omit, 'json'> +const tryReadPackage = async (): Promise => { + try { + return JSON.parse(await fs.promises.readFile(packageJsonPath, 'utf-8')) + } catch (e) { + return undefined + } +} + const creationClientFromConfiguration = ({ flags: f, profileId, log, kc }: { flags: FlagTypes profileId: string @@ -113,7 +122,7 @@ const creationClientFromConfiguration = ({ flags: f, profileId, log, kc }: { namespace: f.namespace, kc, profileId, - package: packageJson, + package: tryReadPackage(), template: fs.readFileSync(f.template || DEFAULT_TEMPLATE, 'utf-8'), storageClass: f['storage-class'], storageSize: f['storage-size'], diff --git a/packages/driver-kube-pod/src/static.ts b/packages/driver-kube-pod/src/static.ts index c8723301..034ba4ea 100644 --- a/packages/driver-kube-pod/src/static.ts +++ b/packages/driver-kube-pod/src/static.ts @@ -1,10 +1,9 @@ import path from 'path' import url from 'url' -import packageJsonImport from '../package.json' assert { type: 'json' } // eslint-disable-next-line no-underscore-dangle const __dirname = url.fileURLToPath(new URL('.', import.meta.url)) export const DIR = path.join(__dirname, '../static') export const DEFAULT_TEMPLATE = path.join(DIR, './default-template.yaml.njk') -export const packageJson = packageJsonImport +export const packageJsonPath = path.join(__dirname, '../package.json') diff --git a/yarn.lock b/yarn.lock index cdf22335..4caba32d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -910,7 +910,7 @@ dependencies: tslib "^2.2.0" -"@azure/core-util@^1.0.0", "@azure/core-util@^1.1.0", "@azure/core-util@^1.1.1", "@azure/core-util@^1.2.0", "@azure/core-util@^1.3.0", "@azure/core-util@^1.6.1": +"@azure/core-util@^1.0.0", "@azure/core-util@^1.1.0", "@azure/core-util@^1.1.1", "@azure/core-util@^1.2.0", "@azure/core-util@^1.3.0": version "1.7.0" resolved "https://registry.npmjs.org/@azure/core-util/-/core-util-1.7.0.tgz#3a2f73e8c7eed0666e8b6ff9ca2c1951e175feba" integrity sha512-Zq2i3QO6k9DA8vnm29mYM4G8IE9u1mhF1GUabVEqPNX8Lj833gdxQ2NAFxt2BZsfAL+e9cT8SyVN7dFVJ/Hf0g== @@ -918,20 +918,20 @@ "@azure/abort-controller" "^2.0.0" tslib "^2.2.0" -"@azure/identity@^3.2.2": - version "3.4.2" - resolved "https://registry.yarnpkg.com/@azure/identity/-/identity-3.4.2.tgz#6b01724c9caac7cadab6b63c76584345bda8e2de" - integrity sha512-0q5DL4uyR0EZ4RXQKD8MadGH6zTIcloUoS/RVbCpNpej4pwte0xpqYxk8K97Py2RiuUvI7F4GXpoT4046VfufA== +"@azure/identity@^4.2.0": + version "4.2.0" + resolved "https://registry.yarnpkg.com/@azure/identity/-/identity-4.2.0.tgz#acaee2f50785cc87778ec7eedcc20d6e72c1da23" + integrity sha512-ve3aYv79qXOJ8wRxQ5jO0eIz2DZ4o0TyME4m4vlGV5YyePddVZ+pFMzusAMODNAflYAAv1cBIhKnd4xytmXyig== dependencies: "@azure/abort-controller" "^1.0.0" "@azure/core-auth" "^1.5.0" "@azure/core-client" "^1.4.0" "@azure/core-rest-pipeline" "^1.1.0" "@azure/core-tracing" "^1.0.0" - "@azure/core-util" "^1.6.1" + "@azure/core-util" "^1.3.0" "@azure/logger" "^1.0.0" - "@azure/msal-browser" "^3.5.0" - "@azure/msal-node" "^2.5.1" + "@azure/msal-browser" "^3.11.1" + "@azure/msal-node" "^2.6.6" events "^3.0.0" jws "^4.0.0" open "^8.0.0" @@ -945,24 +945,24 @@ dependencies: tslib "^2.6.2" -"@azure/msal-browser@^3.5.0": - version "3.5.0" - resolved "https://registry.yarnpkg.com/@azure/msal-browser/-/msal-browser-3.5.0.tgz#eb64c931c78c2b75c70807f618e1284bbb183380" - integrity sha512-2NtMuel4CI3UEelCPKkNRXgKzpWEX48fvxIvPz7s0/sTcCaI08r05IOkH2GkXW+czUOtuY6+oGafJCpumnjRLg== +"@azure/msal-browser@^3.11.1": + version "3.14.0" + resolved "https://registry.yarnpkg.com/@azure/msal-browser/-/msal-browser-3.14.0.tgz#1cb5cab438a9943212aa50c403d11f775c787b21" + integrity sha512-Un85LhOoecJ3HDTS3Uv3UWnXC9/43ZSO+Kc+anSqpZvcEt58SiO/3DuVCAe1A3I5UIBYJNMgTmZPGXQ0MVYrwA== dependencies: - "@azure/msal-common" "14.4.0" + "@azure/msal-common" "14.10.0" -"@azure/msal-common@14.4.0": - version "14.4.0" - resolved "https://registry.yarnpkg.com/@azure/msal-common/-/msal-common-14.4.0.tgz#f938c1d96bb73d65baab985c96faaa273c97cfd5" - integrity sha512-ffCymScQuMKVj+YVfwNI52A5Tu+uiZO2eTf+c+3TXxdAssks4nokJhtr+uOOMxH0zDi6d1OjFKFKeXODK0YLSg== +"@azure/msal-common@14.10.0": + version "14.10.0" + resolved "https://registry.yarnpkg.com/@azure/msal-common/-/msal-common-14.10.0.tgz#215449726717b53d549953db77562cad6cb8421c" + integrity sha512-Zk6DPDz7e1wPgLoLgAp0349Yay9RvcjPM5We/ehuenDNsz/t9QEFI7tRoHpp/e47I4p20XE3FiDlhKwAo3utDA== -"@azure/msal-node@^2.5.1": - version "2.5.1" - resolved "https://registry.yarnpkg.com/@azure/msal-node/-/msal-node-2.5.1.tgz#d180a1ba5fdc611a318a8f018a2db3453e2e2898" - integrity sha512-PsPRISqCG253HQk1cAS7eJW7NWTbnBGpG+vcGGz5z4JYRdnM2EIXlj1aBpXCdozenEPtXEVvHn2ELleW1w82nQ== +"@azure/msal-node@^2.6.6": + version "2.8.1" + resolved "https://registry.yarnpkg.com/@azure/msal-node/-/msal-node-2.8.1.tgz#aded28d37eea2e7278c9bd44f2016647390f239c" + integrity sha512-VcZZM+5VvCWRBTOF7SxMKaxrz+EXjntx2u5AQe7QE06e6FuPJElGBrImgNgCh5QmFaNCfVFO+3qNR7UoFD/Gfw== dependencies: - "@azure/msal-common" "14.4.0" + "@azure/msal-common" "14.10.0" jsonwebtoken "^9.0.0" uuid "^8.3.0"