Skip to content

Commit 5cc497d

Browse files
author
Roy Razon
committed
remove import assertion
- remove single usage of import assertion (import ... with/assert) which was breaking compat with older node 18 versions (see https://github.com/nodejs/node/pull/52104\#issuecomment-2000337367)
1 parent d804e84 commit 5cc497d

File tree

5 files changed

+20
-10
lines changed

5 files changed

+20
-10
lines changed

packages/driver-kube-pod/src/driver/client/common.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@ export const bodyOrUndefined = async <T, Response extends { body: T } = { body:
1515
export type HasMetadata = { metadata?: k8s.V1ObjectMeta }
1616
export type HasKind = { kind?: string }
1717
export type Package = { version: string; name: string }
18+
19+
export const defaultPackage: Package = { name: 'preevy', version: 'unknown' } as const

packages/driver-kube-pod/src/driver/client/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import {
3131
addAllTypesAnnotation,
3232
readAllTypesAnnotation,
3333
} from './metadata.js'
34-
import { Package } from './common.js'
34+
import { Package, defaultPackage } from './common.js'
3535
import { logError } from './log-error.js'
3636

3737
const stringify = stringifyModule.default
@@ -186,7 +186,7 @@ export const kubeCreationClient = ({
186186
namespace: string
187187
profileId: string
188188
template: Buffer | string | Promise<Buffer | string>
189-
package: Package | Promise<Package>
189+
package: Package | undefined | Promise<Package | undefined>
190190
storageClass: string | undefined
191191
storageSize: number
192192
}) => {
@@ -278,7 +278,7 @@ export const kubeCreationClient = ({
278278
})
279279
),
280280
strategy: serverSideApply
281-
? applyStrategies.serverSideApply({ fieldManager: (await packageDetails).name })
281+
? applyStrategies.serverSideApply({ fieldManager: (await packageDetails ?? defaultPackage).name })
282282
: applyStrategies.clientSideApply,
283283
})
284284

packages/driver-kube-pod/src/driver/client/metadata.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { ensureDefined, extractDefined, randomString, truncatePrefix } from '@pr
33
import { pick } from 'lodash-es'
44
import { tryParseJson } from '@preevy/common'
55
import { sanitizeLabel, sanitizeLabels } from './labels.js'
6-
import { HasMetadata, Package } from './common.js'
6+
import { HasMetadata, Package, defaultPackage } from './common.js'
77
import { KubernetesType } from './dynamic/index.js'
88

99
export const MAX_LABEL_LENGTH = 63
@@ -70,12 +70,12 @@ export const addAllTypesAnnotation = (
7070
}
7171

7272
export const addEnvMetadata = (
73-
{ profileId, envId, createdAt, instance, package: { name, version }, templateHash }: {
73+
{ profileId, envId, createdAt, instance, package: { name, version } = defaultPackage, templateHash }: {
7474
profileId: string
7575
envId: string
7676
createdAt: Date
7777
instance: string
78-
package: Package
78+
package?: Package
7979
templateHash: string
8080
},
8181
) => (

packages/driver-kube-pod/src/driver/creation-driver.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import { inspect } from 'util'
88
import { DeploymentMachine, ResourceType, StatefulSetMachine, k8sObjectToMachine } from './common.js'
99
import { clientFromConfiguration, listMachines, machineConnection, flags as machineDriverFlags, parseRfc1123Flag } from './driver.js'
1010
import { Client, CreationClient, kubeCreationClient, loadKubeConfig } from './client/index.js'
11-
import { DEFAULT_TEMPLATE, packageJson } from '../static.js'
11+
import { DEFAULT_TEMPLATE, packageJsonPath } from '../static.js'
12+
import { Package } from './client/common.js'
1213

1314
export const flags = {
1415
...machineDriverFlags,
@@ -103,6 +104,14 @@ const machineCreationDriver = (
103104

104105
type FlagTypes = Omit<Interfaces.InferredFlags<typeof flags>, 'json'>
105106

107+
const tryReadPackage = async (): Promise<Package | undefined> => {
108+
try {
109+
return JSON.parse(await fs.promises.readFile(packageJsonPath, 'utf-8'))
110+
} catch (e) {
111+
return undefined
112+
}
113+
}
114+
106115
const creationClientFromConfiguration = ({ flags: f, profileId, log, kc }: {
107116
flags: FlagTypes
108117
profileId: string
@@ -113,7 +122,7 @@ const creationClientFromConfiguration = ({ flags: f, profileId, log, kc }: {
113122
namespace: f.namespace,
114123
kc,
115124
profileId,
116-
package: packageJson,
125+
package: tryReadPackage(),
117126
template: fs.readFileSync(f.template || DEFAULT_TEMPLATE, 'utf-8'),
118127
storageClass: f['storage-class'],
119128
storageSize: f['storage-size'],
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import path from 'path'
22
import url from 'url'
3-
import packageJsonImport from '../package.json' with { type: 'json' }
43

54
// eslint-disable-next-line no-underscore-dangle
65
const __dirname = url.fileURLToPath(new URL('.', import.meta.url))
76

87
export const DIR = path.join(__dirname, '../static')
98
export const DEFAULT_TEMPLATE = path.join(DIR, './default-template.yaml.njk')
10-
export const packageJson = packageJsonImport
9+
export const packageJsonPath = path.join(__dirname, '../package.json')

0 commit comments

Comments
 (0)