Skip to content

Commit a03a580

Browse files
feat: zipSize and zipFileCount in DeployResult (#1138)
* feat: handle event from SDR to display zip file size and file count * feat: zipSize and zipFileCount in DeployResult * test: tests for verbose zip file size and file count * test: tests for verbose zip file size and file count * fix: always add zipSize and zipFileCount to JSON * chore: bump SDR * fix: check size range to allow for OS differences --------- Co-authored-by: Cristian Dominguez <[email protected]>
1 parent 06b3982 commit a03a580

File tree

13 files changed

+255
-40
lines changed

13 files changed

+255
-40
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"@salesforce/kit": "^3.2.1",
1212
"@salesforce/plugin-info": "^3.3.28",
1313
"@salesforce/sf-plugins-core": "^11.3.2",
14-
"@salesforce/source-deploy-retrieve": "^12.5.1",
14+
"@salesforce/source-deploy-retrieve": "^12.6.0",
1515
"@salesforce/source-tracking": "^7.1.7",
1616
"@salesforce/ts-types": "^2.0.12",
1717
"ansis": "^3.3.2"

schemas/project-deploy-cancel.json

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
"type": "object",
99
"additionalProperties": false,
1010
"properties": {
11+
"files": {
12+
"type": "array",
13+
"items": {
14+
"$ref": "#/definitions/FileResponse"
15+
}
16+
},
1117
"replacements": {
1218
"type": "object",
1319
"additionalProperties": {
@@ -17,11 +23,11 @@
1723
}
1824
}
1925
},
20-
"files": {
21-
"type": "array",
22-
"items": {
23-
"$ref": "#/definitions/FileResponse"
24-
}
26+
"zipSize": {
27+
"type": "number"
28+
},
29+
"zipFileCount": {
30+
"type": "number"
2531
},
2632
"id": {
2733
"type": "string"
@@ -496,6 +502,12 @@
496502
"$ref": "#/definitions/FileResponse"
497503
}
498504
},
505+
"zipSize": {
506+
"type": "number"
507+
},
508+
"zipFileCount": {
509+
"type": "number"
510+
},
499511
"canceledBy": {
500512
"type": "string"
501513
},

schemas/project-deploy-quick.json

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
"type": "object",
99
"additionalProperties": false,
1010
"properties": {
11+
"files": {
12+
"type": "array",
13+
"items": {
14+
"$ref": "#/definitions/FileResponse"
15+
}
16+
},
1117
"replacements": {
1218
"type": "object",
1319
"additionalProperties": {
@@ -17,11 +23,11 @@
1723
}
1824
}
1925
},
20-
"files": {
21-
"type": "array",
22-
"items": {
23-
"$ref": "#/definitions/FileResponse"
24-
}
26+
"zipSize": {
27+
"type": "number"
28+
},
29+
"zipFileCount": {
30+
"type": "number"
2531
},
2632
"id": {
2733
"type": "string"
@@ -496,6 +502,12 @@
496502
"$ref": "#/definitions/FileResponse"
497503
}
498504
},
505+
"zipSize": {
506+
"type": "number"
507+
},
508+
"zipFileCount": {
509+
"type": "number"
510+
},
499511
"canceledBy": {
500512
"type": "string"
501513
},

schemas/project-deploy-report.json

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
"type": "object",
99
"additionalProperties": false,
1010
"properties": {
11+
"files": {
12+
"type": "array",
13+
"items": {
14+
"$ref": "#/definitions/FileResponse"
15+
}
16+
},
1117
"replacements": {
1218
"type": "object",
1319
"additionalProperties": {
@@ -17,11 +23,11 @@
1723
}
1824
}
1925
},
20-
"files": {
21-
"type": "array",
22-
"items": {
23-
"$ref": "#/definitions/FileResponse"
24-
}
26+
"zipSize": {
27+
"type": "number"
28+
},
29+
"zipFileCount": {
30+
"type": "number"
2531
},
2632
"id": {
2733
"type": "string"
@@ -496,6 +502,12 @@
496502
"$ref": "#/definitions/FileResponse"
497503
}
498504
},
505+
"zipSize": {
506+
"type": "number"
507+
},
508+
"zipFileCount": {
509+
"type": "number"
510+
},
499511
"canceledBy": {
500512
"type": "string"
501513
},

schemas/project-deploy-resume.json

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
"type": "object",
99
"additionalProperties": false,
1010
"properties": {
11+
"files": {
12+
"type": "array",
13+
"items": {
14+
"$ref": "#/definitions/FileResponse"
15+
}
16+
},
1117
"replacements": {
1218
"type": "object",
1319
"additionalProperties": {
@@ -17,11 +23,11 @@
1723
}
1824
}
1925
},
20-
"files": {
21-
"type": "array",
22-
"items": {
23-
"$ref": "#/definitions/FileResponse"
24-
}
26+
"zipSize": {
27+
"type": "number"
28+
},
29+
"zipFileCount": {
30+
"type": "number"
2531
},
2632
"id": {
2733
"type": "string"
@@ -496,6 +502,12 @@
496502
"$ref": "#/definitions/FileResponse"
497503
}
498504
},
505+
"zipSize": {
506+
"type": "number"
507+
},
508+
"zipFileCount": {
509+
"type": "number"
510+
},
499511
"canceledBy": {
500512
"type": "string"
501513
},

schemas/project-deploy-start.json

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
"type": "object",
99
"additionalProperties": false,
1010
"properties": {
11+
"files": {
12+
"type": "array",
13+
"items": {
14+
"$ref": "#/definitions/FileResponse"
15+
}
16+
},
1117
"replacements": {
1218
"type": "object",
1319
"additionalProperties": {
@@ -17,11 +23,11 @@
1723
}
1824
}
1925
},
20-
"files": {
21-
"type": "array",
22-
"items": {
23-
"$ref": "#/definitions/FileResponse"
24-
}
26+
"zipSize": {
27+
"type": "number"
28+
},
29+
"zipFileCount": {
30+
"type": "number"
2531
},
2632
"id": {
2733
"type": "string"
@@ -496,6 +502,12 @@
496502
"$ref": "#/definitions/FileResponse"
497503
}
498504
},
505+
"zipSize": {
506+
"type": "number"
507+
},
508+
"zipFileCount": {
509+
"type": "number"
510+
},
499511
"canceledBy": {
500512
"type": "string"
501513
},

schemas/project-deploy-validate.json

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
"type": "object",
99
"additionalProperties": false,
1010
"properties": {
11+
"files": {
12+
"type": "array",
13+
"items": {
14+
"$ref": "#/definitions/FileResponse"
15+
}
16+
},
1117
"replacements": {
1218
"type": "object",
1319
"additionalProperties": {
@@ -17,11 +23,11 @@
1723
}
1824
}
1925
},
20-
"files": {
21-
"type": "array",
22-
"items": {
23-
"$ref": "#/definitions/FileResponse"
24-
}
26+
"zipSize": {
27+
"type": "number"
28+
},
29+
"zipFileCount": {
30+
"type": "number"
2531
},
2632
"id": {
2733
"type": "string"
@@ -496,6 +502,12 @@
496502
"$ref": "#/definitions/FileResponse"
497503
}
498504
},
505+
"zipSize": {
506+
"type": "number"
507+
},
508+
"zipFileCount": {
509+
"type": "number"
510+
},
499511
"canceledBy": {
500512
"type": "string"
501513
},

src/commands/project/deploy/start.ts

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,22 @@
77

88
import ansis from 'ansis';
99
import { EnvironmentVariable, Lifecycle, Messages, OrgConfigProperties, SfError } from '@salesforce/core';
10-
import { DeployVersionData } from '@salesforce/source-deploy-retrieve';
10+
import { type DeployVersionData, DeployZipData } from '@salesforce/source-deploy-retrieve';
1111
import { Duration } from '@salesforce/kit';
1212
import { SfCommand, toHelpSection, Flags } from '@salesforce/sf-plugins-core';
1313
import { SourceConflictError } from '@salesforce/source-tracking';
1414
import { AsyncDeployResultFormatter } from '../../../formatters/asyncDeployResultFormatter.js';
1515
import { DeployResultFormatter } from '../../../formatters/deployResultFormatter.js';
16+
import { AsyncDeployResultJson, DeployResultJson, TestLevel } from '../../../utils/types.js';
1617
import { DeployProgress } from '../../../utils/progressBar.js';
17-
import { DeployResultJson, TestLevel } from '../../../utils/types.js';
1818
import { executeDeploy, resolveApi, validateTests, determineExitCode } from '../../../utils/deploy.js';
1919
import { DeployCache } from '../../../utils/deployCache.js';
2020
import { DEPLOY_STATUS_CODES_DESCRIPTIONS } from '../../../utils/errorCodes.js';
2121
import { ConfigVars } from '../../../configMeta.js';
2222
import { coverageFormattersFlag, fileOrDirFlag, testLevelFlag, testsFlag } from '../../../utils/flags.js';
2323
import { writeConflictTable } from '../../../utils/conflicts.js';
2424
import { getOptionalProject } from '../../../utils/project.js';
25+
import { getZipFileSize } from '../../../utils/output.js';
2526

2627
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
2728
const messages = Messages.loadMessages('@salesforce/plugin-deploy-retrieve', 'deploy.metadata');
@@ -176,6 +177,9 @@ export default class DeployMetadata extends SfCommand<DeployResultJson> {
176177

177178
public static errorCodes = toHelpSection('ERROR CODES', DEPLOY_STATUS_CODES_DESCRIPTIONS);
178179

180+
private zipSize?: number;
181+
private zipFileCount?: number;
182+
179183
public async run(): Promise<DeployResultJson> {
180184
const { flags } = await this.parse(DeployMetadata);
181185
const project = await getOptionalProject();
@@ -214,6 +218,16 @@ export default class DeployMetadata extends SfCommand<DeployResultJson> {
214218
);
215219
});
216220

221+
// eslint-disable-next-line @typescript-eslint/require-await
222+
Lifecycle.getInstance().on('deployZipData', async (zipData: DeployZipData) => {
223+
this.zipSize = zipData.zipSize;
224+
if (flags.verbose && this.zipSize) this.log(`Deploy size: ${getZipFileSize(this.zipSize)} of ~39 MB limit`);
225+
if (zipData.zipFileCount) {
226+
this.zipFileCount = zipData.zipFileCount;
227+
if (flags.verbose && this.zipSize) this.log(`Deployed files count: ${this.zipFileCount} of 10,000 limit`);
228+
}
229+
});
230+
217231
const { deploy } = await executeDeploy(
218232
{
219233
...flags,
@@ -239,7 +253,8 @@ export default class DeployMetadata extends SfCommand<DeployResultJson> {
239253
}
240254
const asyncFormatter = new AsyncDeployResultFormatter(deploy.id);
241255
if (!this.jsonEnabled()) asyncFormatter.display();
242-
return asyncFormatter.getJson();
256+
257+
return this.mixinZipMeta(await asyncFormatter.getJson());
243258
}
244259

245260
new DeployProgress(deploy, this.jsonEnabled()).start();
@@ -255,7 +270,7 @@ export default class DeployMetadata extends SfCommand<DeployResultJson> {
255270

256271
await DeployCache.update(deploy.id, { status: result.response.status });
257272

258-
return formatter.getJson();
273+
return this.mixinZipMeta(await formatter.getJson());
259274
}
260275

261276
protected catch(error: Error | SfError): Promise<never> {
@@ -281,4 +296,14 @@ export default class DeployMetadata extends SfCommand<DeployResultJson> {
281296
}
282297
return super.catch(error);
283298
}
299+
300+
private mixinZipMeta(json: AsyncDeployResultJson | DeployResultJson): AsyncDeployResultJson | DeployResultJson {
301+
if (this.zipSize) {
302+
json.zipSize = this.zipSize;
303+
}
304+
if (this.zipFileCount) {
305+
json.zipFileCount = this.zipFileCount;
306+
}
307+
return json;
308+
}
284309
}

src/utils/output.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ export const exitCodeAsNumber = (): number | undefined => {
3838
}
3939
};
4040

41+
export const getZipFileSize = (bytes: number): string => {
42+
const units = ['B', 'KB', 'MB', 'GB'];
43+
while (bytes > 1024 && units.length) {
44+
bytes /= 1024;
45+
units.shift();
46+
}
47+
return parseFloat(bytes.toFixed(2)) + ' ' + units[0];
48+
};
49+
4150
/** oclif table doesn't like "interface" but likes "type". SDR exports an interface */
4251
export const getFileResponseSuccessProps = (
4352
s: FileResponseSuccess

src/utils/types.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ export type Verbosity = 'verbose' | 'concise' | 'normal';
4343
export type AsyncDeployResultJson = Omit<Partial<MetadataApiDeployStatus>, 'status'> & {
4444
status: RequestStatus | 'Queued' | 'Nothing to deploy';
4545
files: FileResponse[];
46+
zipSize?: number;
47+
zipFileCount?: number;
4648
};
4749

4850
type ConvertEntry = {
@@ -72,7 +74,12 @@ export type DeleteSourceJson = {
7274
export type CoverageResultsFileInfo = Record<keyof Partial<typeof DefaultReportOptions>, string>;
7375

7476
export type DeployResultJson =
75-
| (MetadataApiDeployStatus & { files: FileResponse[] } & { replacements?: Record<string, string[]> })
77+
| (MetadataApiDeployStatus & {
78+
files: FileResponse[];
79+
replacements?: Record<string, string[]>;
80+
zipSize?: number;
81+
zipFileCount?: number;
82+
})
7683
| AsyncDeployResultJson;
7784

7885
export type MetadataRetrieveResultJson = Omit<MetadataApiRetrieveStatus, 'zipFile'> & {

0 commit comments

Comments
 (0)