Skip to content

Commit a3f7a67

Browse files
committed
chore: remove unused constructor prop, break inheritance chain
1 parent 650e132 commit a3f7a67

File tree

9 files changed

+59
-79
lines changed

9 files changed

+59
-79
lines changed

src/commands/force/mdapi/deploy.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import {
2525
} from '../../../deployCommand.js';
2626
import { DeployCommandAsyncResult } from '../../../formatters/source/deployAsyncResultFormatter.js';
2727
import { MdDeployResult, MdDeployResultFormatter } from '../../../formatters/mdapi/mdDeployResultFormatter.js';
28-
import { ProgressFormatter } from '../../../formatters/progressFormatter.js';
2928
import { DeployProgressBarFormatter } from '../../../formatters/deployProgressBarFormatter.js';
3029
import { DeployProgressStatusFormatter } from '../../../formatters/deployProgressStatusFormatter.js';
3130
import { MdDeployAsyncResultFormatter } from '../../../formatters/mdapi/mdDeployAsyncResultFormatter.js';
@@ -205,8 +204,8 @@ export class Deploy extends DeployCommand {
205204

206205
if (!this.isAsync) {
207206
if (!this.jsonEnabled()) {
208-
const progressFormatter: ProgressFormatter = env.getBoolean('SF_USE_PROGRESS_BAR', true)
209-
? new DeployProgressBarFormatter(new Ux({ jsonEnabled: this.jsonEnabled() }))
207+
const progressFormatter = env.getBoolean('SF_USE_PROGRESS_BAR', true)
208+
? new DeployProgressBarFormatter()
210209
: new DeployProgressStatusFormatter(new Ux({ jsonEnabled: this.jsonEnabled() }));
211210
progressFormatter.progress(deploy);
212211
}

src/commands/force/mdapi/deploy/report.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import {
1919
import { Interfaces } from '@oclif/core';
2020
import { MdDeployResult, MdDeployResultFormatter } from '../../../../formatters/mdapi/mdDeployResultFormatter.js';
2121
import { DeployCommand, getCoverageFormattersOptions, reportsFormatters } from '../../../../deployCommand.js';
22-
import { ProgressFormatter } from '../../../../formatters/progressFormatter.js';
2322
import { DeployProgressBarFormatter } from '../../../../formatters/deployProgressBarFormatter.js';
2423
import { DeployProgressStatusFormatter } from '../../../../formatters/deployProgressStatusFormatter.js';
2524

@@ -112,8 +111,8 @@ export class Report extends DeployCommand {
112111

113112
const deploy = this.createDeploy(this.org.getConnection(), deployId);
114113
if (!this.jsonEnabled()) {
115-
const progressFormatter: ProgressFormatter = env.getBoolean('SF_USE_PROGRESS_BAR', true)
116-
? new DeployProgressBarFormatter(new Ux({ jsonEnabled: this.jsonEnabled() }))
114+
const progressFormatter = env.getBoolean('SF_USE_PROGRESS_BAR', true)
115+
? new DeployProgressBarFormatter()
117116
: new DeployProgressStatusFormatter(new Ux({ jsonEnabled: this.jsonEnabled() }));
118117
progressFormatter.progress(deploy);
119118
}

src/commands/force/source/deploy.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import {
2929
DeployAsyncResultFormatter,
3030
DeployCommandAsyncResult,
3131
} from '../../../formatters/source/deployAsyncResultFormatter.js';
32-
import { ProgressFormatter } from '../../../formatters/progressFormatter.js';
3332
import { DeployProgressBarFormatter } from '../../../formatters/deployProgressBarFormatter.js';
3433
import { DeployProgressStatusFormatter } from '../../../formatters/deployProgressStatusFormatter.js';
3534
import { filterConflictsByComponentSet, trackingSetup, updateTracking } from '../../../trackingFunctions.js';
@@ -283,8 +282,8 @@ export class Deploy extends DeployCommand {
283282
if (!this.isAsync) {
284283
// we're not print JSON output
285284
if (!this.jsonEnabled()) {
286-
const progressFormatter: ProgressFormatter = env.getBoolean('SF_USE_PROGRESS_BAR', true)
287-
? new DeployProgressBarFormatter(new Ux({ jsonEnabled: this.jsonEnabled() }))
285+
const progressFormatter = env.getBoolean('SF_USE_PROGRESS_BAR', true)
286+
? new DeployProgressBarFormatter()
288287
: new DeployProgressStatusFormatter(new Ux({ jsonEnabled: this.jsonEnabled() }), {
289288
verbose: this.flags.verbose,
290289
});

src/commands/force/source/deploy/report.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import {
2323
DeployReportCommandResult,
2424
DeployReportResultFormatter,
2525
} from '../../../../formatters/deployReportResultFormatter.js';
26-
import { ProgressFormatter } from '../../../../formatters/progressFormatter.js';
2726
import { DeployProgressBarFormatter } from '../../../../formatters/deployProgressBarFormatter.js';
2827
import { DeployProgressStatusFormatter } from '../../../../formatters/deployProgressStatusFormatter.js';
2928
import { ResultFormatterOptions } from '../../../../formatters/resultFormatter.js';
@@ -112,8 +111,8 @@ export class Report extends DeployCommand {
112111
const waitDuration = this.flags.wait;
113112
const deploy = this.createDeploy(this.flags['target-org'].getConnection(), deployId);
114113
if (!this.jsonEnabled()) {
115-
const progressFormatter: ProgressFormatter = env.getBoolean('SF_USE_PROGRESS_BAR', true)
116-
? new DeployProgressBarFormatter(new Ux({ jsonEnabled: this.jsonEnabled() }))
114+
const progressFormatter = env.getBoolean('SF_USE_PROGRESS_BAR', true)
115+
? new DeployProgressBarFormatter()
117116
: new DeployProgressStatusFormatter(new Ux({ jsonEnabled: this.jsonEnabled() }));
118117
progressFormatter.progress(deploy);
119118
}

src/commands/force/source/push.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import {
2020
import { Interfaces } from '@oclif/core';
2121
import { DeployCommand } from '../../../deployCommand.js';
2222
import { PushResponse, PushResultFormatter } from '../../../formatters/source/pushResultFormatter.js';
23-
import { ProgressFormatter } from '../../../formatters/progressFormatter.js';
2423
import { DeployProgressBarFormatter } from '../../../formatters/deployProgressBarFormatter.js';
2524
import { DeployProgressStatusFormatter } from '../../../formatters/deployProgressStatusFormatter.js';
2625
import { trackingSetup, updateTracking } from '../../../trackingFunctions.js';
@@ -149,8 +148,8 @@ export default class Push extends DeployCommand {
149148

150149
// we're not print JSON output
151150
if (!this.jsonEnabled()) {
152-
const progressFormatter: ProgressFormatter = env.getBoolean('SF_USE_PROGRESS_BAR', true)
153-
? new DeployProgressBarFormatter(new Ux({ jsonEnabled: this.jsonEnabled() }))
151+
const progressFormatter = env.getBoolean('SF_USE_PROGRESS_BAR', true)
152+
? new DeployProgressBarFormatter()
154153
: new DeployProgressStatusFormatter(new Ux({ jsonEnabled: this.jsonEnabled() }));
155154
progressFormatter.progress(deploy);
156155
}

src/formatters/deployProgressBarFormatter.ts

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,42 +5,38 @@
55
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
66
*/
77

8-
import { MetadataApiDeploy } from '@salesforce/source-deploy-retrieve';
9-
import { once } from '@salesforce/kit';
8+
import { MetadataApiDeploy, MetadataApiDeployStatus } from '@salesforce/source-deploy-retrieve';
109
import { SingleBar } from 'cli-progress';
11-
import { Ux } from '@salesforce/sf-plugins-core';
12-
import { ProgressFormatter } from './progressFormatter.js';
1310

14-
export class DeployProgressBarFormatter extends ProgressFormatter {
11+
export class DeployProgressBarFormatter {
1512
protected progressBar = new SingleBar({
1613
format: 'DEPLOY PROGRESS | {bar} | {value}/{total} Components',
1714
barCompleteChar: '\u2588',
1815
barIncompleteChar: '\u2591',
1916
linewrap: true,
17+
noTTYOutput: Boolean(process.env.TERM === 'dumb' || !process.stdin.isTTY),
2018
});
21-
public constructor(ux: Ux) {
22-
super(ux);
23-
}
19+
20+
public constructor() {}
2421

2522
// displays the progress of the Deployment
2623
public progress(deploy: MetadataApiDeploy): void {
27-
const startProgressBar = once((componentTotal: number) => {
28-
this.progressBar.start(componentTotal, 0);
29-
});
30-
31-
deploy.onUpdate((data) => {
32-
// the numCompTot. isn't computed right away, wait to start until we know how many we have
33-
const total = data.numberComponentsTotal + data.numberTestsTotal;
34-
if (data.numberComponentsTotal) {
35-
startProgressBar(total);
36-
this.progressBar.update(data.numberComponentsDeployed + data.numberTestsCompleted);
24+
this.progressBar.start(0, 0);
25+
deploy.onUpdate(
26+
({
27+
numberComponentsTotal,
28+
numberTestsTotal,
29+
numberComponentsDeployed,
30+
numberTestsCompleted,
31+
}: MetadataApiDeployStatus) => {
32+
// the numberComponentsTotal isn't computed right away, wait to start until we know how many we have
33+
const total = numberComponentsTotal + numberTestsTotal;
34+
if (this.progressBar.getTotal() !== total) {
35+
this.progressBar.setTotal(total);
36+
}
37+
this.progressBar.update(numberComponentsDeployed + numberTestsCompleted);
3738
}
38-
39-
// the numTestsTot. isn't computed until validated as tests by the server, update the PB once we know
40-
if (data.numberTestsTotal && data.numberComponentsTotal) {
41-
this.progressBar.setTotal(total);
42-
}
43-
});
39+
);
4440

4541
// any thing else should stop the progress bar
4642
deploy.onFinish((data) => {

src/sourceCommand.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ import { ComponentSet } from '@salesforce/source-deploy-retrieve';
1313
import { getString, Optional } from '@salesforce/ts-types';
1414
import { SingleBar } from 'cli-progress';
1515
import { SfCommand } from '@salesforce/sf-plugins-core';
16-
import { EnsureFsFlagOptions, FsError, ProgressBar } from './types.js';
16+
import { EnsureFsFlagOptions, FsError } from './types.js';
1717

1818
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
1919
const messages = Messages.loadMessages('@salesforce/plugin-source', 'flags.validation');
2020

2121
export abstract class SourceCommand extends SfCommand<unknown> {
2222
public static readonly DEFAULT_WAIT_MINUTES = 33;
2323

24-
protected progressBar?: ProgressBar;
24+
protected progressBar?: SingleBar;
2525
protected componentSet?: ComponentSet;
2626

2727
protected initProgressBar(): void {
@@ -31,7 +31,7 @@ export abstract class SourceCommand extends SfCommand<unknown> {
3131
barCompleteChar: '\u2588',
3232
barIncompleteChar: '\u2591',
3333
linewrap: true,
34-
}) as ProgressBar;
34+
});
3535
}
3636

3737
/**

src/types.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,11 @@
77

88
export type FsError = {
99
code: string;
10-
} & Error
10+
} & Error;
1111

1212
export type EnsureFsFlagOptions = {
1313
flagName: string;
1414
path?: string;
1515
type: 'dir' | 'file' | 'any';
1616
throwOnENOENT?: boolean;
17-
}
18-
19-
export type ProgressBar = {
20-
total?: number;
21-
value?: number;
22-
start: (total: number, startValue: number, payload?: object) => void;
23-
update: (num: number, payload?: object) => void;
24-
setTotal: (num: number) => void;
25-
stop: () => void;
2617
};

test/commands/source/progressBarFormatter.test.ts

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,33 @@ import { EventEmitter } from 'node:events';
88
import { MetadataApiDeploy } from '@salesforce/source-deploy-retrieve';
99
import { spyMethod } from '@salesforce/ts-sinon';
1010
import { assert, expect } from 'chai';
11-
import { Ux } from '@salesforce/sf-plugins-core';
1211
import { TestContext } from '@salesforce/core/testSetup';
12+
import { SingleBar } from 'cli-progress';
1313
import { DeployProgressBarFormatter } from '../../../src/formatters/deployProgressBarFormatter.js';
14-
import { ProgressBar } from '../../../src/types.js';
1514

1615
describe('Progress Bar Events', () => {
1716
const sandbox = new TestContext().SANDBOX;
1817
const username = 'me@my.org';
1918
const deploy = new MetadataApiDeploy({ usernameOrConnection: username, id: '123' });
20-
const progressBarFormatter = new DeployProgressBarFormatter(Ux.prototype);
21-
let bar: ProgressBar;
19+
let progressBarFormatter: DeployProgressBarFormatter;
20+
let bar: SingleBar;
2221
let events: EventEmitter;
2322

2423
const overrideEvent = (event: EventEmitter) => {
25-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
26-
// @ts-ignore the deploy must be listening to the same EventEmitter emitting events
24+
// @ts-expect-error the deploy must be listening to the same EventEmitter emitting events
2725
deploy.event = event;
2826
};
2927

30-
const getProgressbar = () =>
31-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
32-
// @ts-ignore protected member access
33-
progressBarFormatter.progressBar;
28+
// @ts-expect-error protected member access
29+
const getProgressbar = () => progressBarFormatter.progressBar;
30+
3431
afterEach(() => {
3532
sandbox.restore();
3633
});
3734

3835
beforeEach(() => {
3936
events = new EventEmitter();
37+
progressBarFormatter = new DeployProgressBarFormatter();
4038
overrideEvent(events);
4139
progressBarFormatter.progress(deploy);
4240
bar = getProgressbar();
@@ -49,8 +47,8 @@ describe('Progress Bar Events', () => {
4947
numberTestsCompleted: 0,
5048
numberTestsTotal: 0,
5149
});
52-
expect(bar.value).to.equal(3);
53-
expect(bar.total).to.equal(5);
50+
expect(bar.getTotal()).to.equal(5);
51+
expect(bar.getProgress()).to.equal(3 / 5);
5452
events.emit('finish', {
5553
response: {
5654
numberComponentsTotal: 5,
@@ -68,17 +66,17 @@ describe('Progress Bar Events', () => {
6866
numberTestsCompleted: 0,
6967
numberTestsTotal: 0,
7068
});
71-
expect(bar.total).to.equal(10);
72-
expect(bar.value).to.equal(3);
69+
expect(bar.getTotal()).to.equal(10);
70+
expect(bar.getProgress()).to.equal(3 / 10);
7371
// deploy done, tests running
7472
events.emit('update', {
7573
numberComponentsTotal: 10,
7674
numberComponentsDeployed: 10,
7775
numberTestsCompleted: 5,
7876
numberTestsTotal: 10,
7977
});
80-
expect(bar.total).to.equal(20);
81-
expect(bar.value).to.equal(15);
78+
expect(bar.getTotal()).to.equal(20);
79+
expect(bar.getProgress()).to.equal(15 / 20);
8280
// all done
8381
events.emit('finish', {
8482
response: {
@@ -88,7 +86,7 @@ describe('Progress Bar Events', () => {
8886
numberTestsTotal: 10,
8987
},
9088
});
91-
expect(bar.value).to.equal(20);
89+
expect(bar.getProgress()).to.equal(20 / 20);
9290
});
9391

9492
it('should update progress bar when server returns different calculated value', () => {
@@ -98,17 +96,17 @@ describe('Progress Bar Events', () => {
9896
numberTestsCompleted: 0,
9997
numberTestsTotal: 0,
10098
});
101-
expect(bar.total).to.equal(20);
102-
expect(bar.value).to.equal(3);
99+
expect(bar.getTotal()).to.equal(20);
100+
expect(bar.getProgress()).to.equal(3 / 20);
103101
// deploy done, tests running
104102
events.emit('update', {
105103
numberComponentsTotal: 20,
106104
numberComponentsDeployed: 10,
107105
numberTestsCompleted: 5,
108106
numberTestsTotal: 10,
109107
});
110-
expect(bar.total).to.equal(30);
111-
expect(bar.value).to.equal(15);
108+
expect(bar.getTotal()).to.equal(30);
109+
expect(bar.getProgress()).to.equal(15 / 30);
112110
// all done - notice 19 comps. deployed
113111
events.emit('finish', {
114112
response: {
@@ -118,8 +116,8 @@ describe('Progress Bar Events', () => {
118116
numberTestsTotal: 10,
119117
},
120118
});
121-
expect(bar.value).to.equal(29);
122-
expect(bar.total).to.equal(29);
119+
expect(bar.getProgress()).to.equal(29 / 29);
120+
expect(bar.getTotal()).to.equal(29);
123121
});
124122

125123
it('should stop progress bar onCancel', () => {
@@ -131,8 +129,8 @@ describe('Progress Bar Events', () => {
131129
numberTestsCompleted: 0,
132130
numberTestsTotal: 0,
133131
});
134-
expect(bar.total).to.equal(10);
135-
expect(bar.value).to.equal(3);
132+
expect(bar.getTotal()).to.equal(10);
133+
expect(bar.getProgress()).to.equal(3 / 10);
136134

137135
events.emit('cancel');
138136
expect(stopSpy.calledOnce).to.be.true;
@@ -148,8 +146,8 @@ describe('Progress Bar Events', () => {
148146
numberTestsTotal: 0,
149147
});
150148

151-
expect(bar.total).to.equal(10);
152-
expect(bar.value).to.equal(3);
149+
expect(bar.getTotal()).to.equal(10);
150+
expect(bar.getProgress()).to.equal(3 / 10);
153151

154152
try {
155153
events.emit('error', new Error('error on deploy'));

0 commit comments

Comments
 (0)