Skip to content

Commit 6660e28

Browse files
authored
Merge pull request #551 from salesforcecli/sm/validate-async
refactor: validate --async returns immediately
2 parents a465ad3 + e787c43 commit 6660e28

File tree

4 files changed

+30
-22
lines changed

4 files changed

+30
-22
lines changed

src/commands/project/deploy/resume.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ export default class DeployMetadataResume extends SfCommand<DeployResultJson> {
8181
const [{ flags }, cache] = await Promise.all([this.parse(DeployMetadataResume), DeployCache.create()]);
8282
const jobId = cache.resolveLatest(flags['use-most-recent'], flags['job-id']);
8383

84-
const deployOpts = cache.get(jobId);
84+
// if it was async before, then it should not be async now.
85+
const deployOpts = { ...cache.get(jobId), async: false };
8586

8687
if (isNotResumable(deployOpts.status)) {
8788
throw messages.createError('error.DeployNotResumable', [jobId, deployOpts.status]);

src/commands/project/deploy/validate.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,15 @@ export default class DeployMetadataValidate extends SfCommand<DeployResultJson>
135135

136136
this.log(getVersionMessage('Validating Deployment', componentSet, api));
137137
this.log(`Deploy ID: ${bold(deploy.id)}`);
138-
new DeployProgress(deploy, this.jsonEnabled()).start();
139138

140139
if (flags.async) {
141140
const asyncFormatter = new AsyncDeployResultFormatter(deploy.id);
142141
if (!this.jsonEnabled()) asyncFormatter.display();
143142
return asyncFormatter.getJson();
144143
}
145144

145+
new DeployProgress(deploy, this.jsonEnabled()).start();
146+
146147
const result = await deploy.pollStatus(500, flags.wait?.seconds);
147148
process.exitCode = determineExitCode(result);
148149
const formatter = new DeployResultFormatter(result, flags);

src/formatters/deployResultFormatter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ export class DeployResultFormatter implements Formatter<DeployResultJson> {
219219
type: { header: 'Type' },
220220
filePath: { header: 'Path' },
221221
};
222-
const title = 'Deployed Source';
222+
const title = this.result.response.checkOnly ? 'Validated Source' : 'Deployed Source';
223223
const options = { title: tableHeader(title) };
224224
ux.log();
225225

src/utils/progressBar.ts

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
import { envVars as env, EnvironmentVariable } from '@salesforce/core';
9-
import { MetadataApiDeploy } from '@salesforce/source-deploy-retrieve';
9+
import { MetadataApiDeploy, MetadataApiDeployStatus } from '@salesforce/source-deploy-retrieve';
1010
import { Messages } from '@salesforce/core';
1111
import { Progress } from '@salesforce/sf-plugins-core';
1212

@@ -28,25 +28,14 @@ export class DeployProgress extends Progress {
2828

2929
public start(): void {
3030
super.start(0, { status: 'Waiting' }, DeployProgress.OPTIONS);
31-
this.deploy.onUpdate((data) => {
32-
// the numCompTot. isn't computed right away, wait to start until we know how many we have
33-
if (data.numberComponentsTotal) {
34-
this.setTotal(data.numberComponentsTotal + data.numberTestsTotal);
35-
this.update(data.numberComponentsDeployed + data.numberTestsCompleted, {
36-
status: mdTrasferMessages.getMessage(data.status),
37-
});
38-
} else {
39-
this.update(0, { status: mdTrasferMessages.getMessage(data.status) ?? 'Waiting' });
40-
}
41-
42-
// the numTestsTot. isn't computed until validated as tests by the server, update the PB once we know
43-
if (data.numberTestsTotal && data.numberComponentsTotal) {
44-
this.setTotal(data.numberComponentsTotal + data.numberTestsTotal);
45-
}
46-
});
4731

48-
// any thing else should stop the progress bar
49-
this.deploy.onFinish((data) => this.finish({ status: mdTrasferMessages.getMessage(data.response.status) }));
32+
this.deploy.onUpdate((data) => this.updateProgress(data));
33+
34+
// any thing else should make one final update, then stop the progress bar
35+
this.deploy.onFinish((data) => {
36+
this.updateProgress(data.response);
37+
this.finish({ status: mdTrasferMessages.getMessage(data.response.status) });
38+
});
5039

5140
this.deploy.onCancel(() => this.stop());
5241

@@ -55,4 +44,21 @@ export class DeployProgress extends Progress {
5544
throw error;
5645
});
5746
}
47+
48+
private updateProgress(data: MetadataApiDeployStatus): void {
49+
// the numCompTot. isn't computed right away, wait to start until we know how many we have
50+
if (data.numberComponentsTotal) {
51+
this.setTotal(data.numberComponentsTotal + data.numberTestsTotal);
52+
this.update(data.numberComponentsDeployed + data.numberTestsCompleted, {
53+
status: mdTrasferMessages.getMessage(data.status),
54+
});
55+
} else {
56+
this.update(0, { status: mdTrasferMessages.getMessage(data.status) ?? 'Waiting' });
57+
}
58+
59+
// the numTestsTot. isn't computed until validated as tests by the server, update the PB once we know
60+
if (data.numberTestsTotal && data.numberComponentsTotal) {
61+
this.setTotal(data.numberComponentsTotal + data.numberTestsTotal);
62+
}
63+
}
5864
}

0 commit comments

Comments
 (0)