Skip to content

Commit affb951

Browse files
committed
fix: align exported core Diff interface with previous 2.8 signature
This is a fix after the major upgrade of the CLI (in bump-sh#587) where we broke the interface of the exported core `Diff` class and made its usage as a lib more complicated. Let's align back to what it used to be, and even simplify the interface by making the constructor argument optional.
1 parent b3b30fd commit affb951

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

src/api/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,11 @@ class BumpApi {
5959
}
6060

6161
// Check https://oclif.io/docs/config for details about Config.IConfig
62-
public constructor(protected config: Config) {
62+
public constructor(protected config?: Config) {
6363
const baseURL = `${vars.apiUrl}${vars.apiBasePath}`
64+
const userAgent = config?.userAgent || 'bump-cli'
6465
const headers: {Authorization?: string; 'User-Agent': string} = {
65-
'User-Agent': vars.apiUserAgent(config.userAgent),
66+
'User-Agent': vars.apiUserAgent(userAgent),
6667
}
6768

6869
this.client = axios.create({

src/commands/diff.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export default class Diff extends BaseCommand<typeof Diff> {
105105

106106
ux.action.status = '...diff on Bump.sh in progress'
107107

108-
const diff: DiffResponse | undefined = await new CoreDiff(this.bump).run(
108+
const diff: DiffResponse | undefined = await new CoreDiff(this.config).run(
109109
args.file,
110110
args.otherFile,
111111
documentation,

src/core/diff.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import {Config} from '@oclif/core'
12
import {CLIError} from '@oclif/core/errors'
23
import debug from 'debug'
34

@@ -10,9 +11,17 @@ export class Diff {
1011
static readonly TIMEOUT = 120
1112

1213
private _bump!: BumpApi
14+
private _config: Config | undefined
1315

14-
public constructor(bumpClient: BumpApi) {
15-
this._bump = bumpClient
16+
public constructor(config?: Config) {
17+
if (config) {
18+
this._config = config
19+
}
20+
}
21+
22+
get bumpClient(): BumpApi {
23+
if (!this._bump) this._bump = new BumpApi(this._config!)
24+
return this._bump
1625
}
1726

1827
get pollingPeriod(): number {
@@ -32,7 +41,7 @@ export class Diff {
3241
references,
3342
}
3443

35-
const response = await this._bump.postDiff(request)
44+
const response = await this.bumpClient.postDiff(request)
3645

3746
switch (response.status) {
3847
case 201: {
@@ -68,7 +77,7 @@ export class Diff {
6877
unpublished: true,
6978
}
7079

71-
const response = await this._bump.postVersion(request, token)
80+
const response = await this.bumpClient.postVersion(request, token)
7281

7382
switch (response.status) {
7483
case 201: {
@@ -125,6 +134,8 @@ export class Diff {
125134
format: string,
126135
expires: string | undefined,
127136
): Promise<DiffResponse | undefined> {
137+
if (!this._config) this._config = await Config.load('../../')
138+
128139
let diffVersion: DiffResponse | VersionResponse | undefined
129140

130141
if (file2 && (!documentation || !token)) {
@@ -157,8 +168,8 @@ export class Diff {
157168
opts: {format: string; timeout: number},
158169
): Promise<DiffResponse> {
159170
const pollingResponse = await (this.isVersion(result) && token
160-
? this._bump.getVersion(result.id, token)
161-
: this._bump.getDiff(result.id, opts.format))
171+
? this.bumpClient.getVersion(result.id, token)
172+
: this.bumpClient.getDiff(result.id, opts.format))
162173

163174
if (opts.timeout <= 0) {
164175
throw new CLIError(

0 commit comments

Comments
 (0)