Skip to content

Commit 8d82c7b

Browse files
authored
feat: use CLI's own version when adding checkly to package.json on import (#1107)
1 parent 9df4dbe commit 8d82c7b

3 files changed

Lines changed: 19 additions & 3 deletions

File tree

packages/cli/src/commands/baseCommand.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Command } from '@oclif/core'
44
import { api } from '../rest/api'
55
import { CommandStyle } from '../helpers/command-style'
66
import { PackageFilesResolver } from '../services/check-parser/package-files/resolver'
7+
import { PackageJsonFile } from '../services/check-parser/package-files/package-json-file'
78

89
export type BaseCommandClass = typeof Command & {
910
coreCommand: boolean
@@ -14,6 +15,16 @@ export abstract class BaseCommand extends Command {
1415
static hidden = true
1516
fancy = true
1617
style = new CommandStyle(this)
18+
#packageJsonLoader?: Promise<PackageJsonFile | undefined>
19+
20+
async loadPackageJsonOfSelf (): Promise<PackageJsonFile | undefined> {
21+
if (!this.#packageJsonLoader) {
22+
const resolver = new PackageFilesResolver()
23+
this.#packageJsonLoader = resolver.loadPackageJsonFile(__filename)
24+
}
25+
26+
return this.#packageJsonLoader
27+
}
1728

1829
async checkEngineCompatibility (): Promise<void> {
1930
const nodeVersion = process.versions.node
@@ -23,8 +34,7 @@ export abstract class BaseCommand extends Command {
2334
return
2435
}
2536

26-
const resolver = new PackageFilesResolver()
27-
const packageJson = await resolver.loadPackageJsonFile(__filename)
37+
const packageJson = await this.loadPackageJsonOfSelf()
2838
if (packageJson === undefined) {
2939
// Do nothing if there's no package.json.
3040
return

packages/cli/src/commands/import/plan.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,8 +663,10 @@ ${chalk.cyan('For safety, resources are not deletable until the plan has been co
663663
}
664664
})()
665665

666+
const ownPackageJson = await this.loadPackageJsonOfSelf()
667+
666668
const updated = packageJson.upsertDevDependencies({
667-
checkly: `^5`,
669+
checkly: `^${ownPackageJson?.version ?? '6'}`,
668670
jiti: '^2',
669671
})
670672

packages/cli/src/services/check-parser/package-files/package-json-file.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ export class PackageJsonFile {
5151
return this.jsonFile.meta
5252
}
5353

54+
public get version () {
55+
return this.jsonFile.data.version
56+
}
57+
5458
public get dependencies () {
5559
return this.jsonFile.data.dependencies
5660
}

0 commit comments

Comments
 (0)