@@ -43,7 +43,8 @@ export class DeployResult implements MetadataTransferResult {
43
43
public constructor (
44
44
public readonly response : MetadataApiDeployStatus ,
45
45
public readonly components ?: ComponentSet ,
46
- public readonly replacements = new Map < string , string [ ] > ( )
46
+ public readonly replacements = new Map < string , string [ ] > ( ) ,
47
+ public readonly zipMeta ?: { zipSize : number ; zipFileCount ?: number }
47
48
) { }
48
49
49
50
public getFileResponses ( ) : FileResponse [ ] {
@@ -97,6 +98,8 @@ export class MetadataApiDeploy extends MetadataTransfer<
97
98
// from the apiOptions and we need it for telemetry.
98
99
private readonly isRestDeploy : boolean ;
99
100
private readonly registry : RegistryAccess ;
101
+ private zipSize ?: number ;
102
+ private zipFileCount ?: number ;
100
103
101
104
public constructor ( options : MetadataApiDeployOptions ) {
102
105
super ( options ) ;
@@ -207,7 +210,10 @@ export class MetadataApiDeploy extends MetadataTransfer<
207
210
} )
208
211
) ;
209
212
210
- const [ zipBuffer ] = await Promise . all ( [ this . getZipBuffer ( ) , this . maybeSaveTempDirectory ( 'metadata' ) ] ) ;
213
+ const [ { zipBuffer, zipFileCount } ] = await Promise . all ( [
214
+ this . getZipBuffer ( ) ,
215
+ this . maybeSaveTempDirectory ( 'metadata' ) ,
216
+ ] ) ;
211
217
// SDR modifies what the mdapi expects by adding a rest param
212
218
const { rest, ...optionsWithoutRest } = this . options . apiOptions ?? { } ;
213
219
@@ -217,7 +223,17 @@ export class MetadataApiDeploy extends MetadataTransfer<
217
223
const manifestMsg = manifestVersion ? ` in v${ manifestVersion } shape` : '' ;
218
224
const debugMsg = format ( `Deploying metadata source%s using ${ webService } v${ apiVersion } ` , manifestMsg ) ;
219
225
this . logger . debug ( debugMsg ) ;
226
+
227
+ // Event and Debug output for the zip file used for deploy
228
+ this . zipSize = zipBuffer . byteLength ;
229
+ let zipMessage = `Deployment zip file size = ${ this . zipSize } Bytes` ;
230
+ if ( zipFileCount ) {
231
+ this . zipFileCount = zipFileCount ;
232
+ zipMessage += ` containing ${ zipFileCount } files` ;
233
+ }
234
+ this . logger . debug ( zipMessage ) ;
220
235
await LifecycleInstance . emit ( 'apiVersionDeploy' , { webService, manifestVersion, apiVersion } ) ;
236
+ await LifecycleInstance . emit ( 'deployZipData' , { zipSize : this . zipSize , zipFileCount } ) ;
221
237
222
238
return this . isRestDeploy
223
239
? connection . metadata . deployRest ( zipBuffer , optionsWithoutRest )
@@ -266,6 +282,8 @@ export class MetadataApiDeploy extends MetadataTransfer<
266
282
numberTestsTotal : result . numberTestsTotal ,
267
283
testsTotalTime : result . details ?. runTestResult ?. totalTime ,
268
284
filesWithReplacementsQuantity : this . replacements . size ?? 0 ,
285
+ zipSize : this . zipSize ?? 0 ,
286
+ zipFileCount : this . zipFileCount ?? 0 ,
269
287
} ) ;
270
288
} catch ( err ) {
271
289
const error = err as Error ;
@@ -278,7 +296,8 @@ export class MetadataApiDeploy extends MetadataTransfer<
278
296
const deployResult = new DeployResult (
279
297
result ,
280
298
this . components ,
281
- new Map ( Array . from ( this . replacements ) . map ( ( [ k , v ] ) => [ k , Array . from ( v ) ] ) )
299
+ new Map ( Array . from ( this . replacements ) . map ( ( [ k , v ] ) => [ k , Array . from ( v ) ] ) ) ,
300
+ { zipSize : this . zipSize ?? 0 , zipFileCount : this . zipFileCount }
282
301
) ;
283
302
// only do event hooks if source, (NOT a metadata format) deploy
284
303
if ( this . options . components ) {
@@ -292,14 +311,17 @@ export class MetadataApiDeploy extends MetadataTransfer<
292
311
return deployResult ;
293
312
}
294
313
295
- private async getZipBuffer ( ) : Promise < Buffer > {
314
+ private async getZipBuffer ( ) : Promise < { zipBuffer : Buffer ; zipFileCount ?: number } > {
296
315
const mdapiPath = this . options . mdapiPath ;
316
+
317
+ // Zip a directory of metadata format source
297
318
if ( mdapiPath ) {
298
319
if ( ! fs . existsSync ( mdapiPath ) || ! fs . lstatSync ( mdapiPath ) . isDirectory ( ) ) {
299
320
throw messages . createError ( 'error_directory_not_found_or_not_directory' , [ mdapiPath ] ) ;
300
321
}
301
322
302
323
const zip = JSZip ( ) ;
324
+ let zipFileCount = 0 ;
303
325
304
326
const zipDirRecursive = ( dir : string ) : void => {
305
327
const dirents = fs . readdirSync ( dir , { withFileTypes : true } ) ;
@@ -313,33 +335,38 @@ export class MetadataApiDeploy extends MetadataTransfer<
313
335
// Ensure only posix paths are added to zip files
314
336
const relPosixPath = relPath . replace ( / \\ / g, '/' ) ;
315
337
zip . file ( relPosixPath , fs . createReadStream ( fullPath ) ) ;
338
+ zipFileCount ++ ;
316
339
}
317
340
}
318
341
} ;
319
342
this . logger . debug ( 'Zipping directory for metadata deploy:' , mdapiPath ) ;
320
343
zipDirRecursive ( mdapiPath ) ;
321
344
322
- return zip . generateAsync ( {
323
- type : 'nodebuffer' ,
324
- compression : 'DEFLATE' ,
325
- compressionOptions : { level : 9 } ,
326
- } ) ;
345
+ return {
346
+ zipBuffer : await zip . generateAsync ( {
347
+ type : 'nodebuffer' ,
348
+ compression : 'DEFLATE' ,
349
+ compressionOptions : { level : 9 } ,
350
+ } ) ,
351
+ zipFileCount,
352
+ } ;
327
353
}
328
- // read the zip into a buffer
354
+ // Read a zip of metadata format source into a buffer
329
355
if ( this . options . zipPath ) {
330
356
if ( ! fs . existsSync ( this . options . zipPath ) ) {
331
357
throw new SfError ( messages . getMessage ( 'error_path_not_found' , [ this . options . zipPath ] ) ) ;
332
358
}
333
359
// does encoding matter for zip files? I don't know
334
- return fs . promises . readFile ( this . options . zipPath ) ;
360
+ return { zipBuffer : await fs . promises . readFile ( this . options . zipPath ) } ;
335
361
}
362
+ // Convert a ComponentSet of metadata in source format and zip
336
363
if ( this . options . components && this . components ) {
337
364
const converter = new MetadataConverter ( this . registry ) ;
338
- const { zipBuffer } = await converter . convert ( this . components , 'metadata' , { type : 'zip' } ) ;
365
+ const { zipBuffer, zipFileCount } = await converter . convert ( this . components , 'metadata' , { type : 'zip' } ) ;
339
366
if ( ! zipBuffer ) {
340
367
throw new SfError ( messages . getMessage ( 'zipBufferError' ) ) ;
341
368
}
342
- return zipBuffer ;
369
+ return { zipBuffer, zipFileCount } ;
343
370
}
344
371
throw new Error ( 'Options should include components, zipPath, or mdapiPath' ) ;
345
372
}
0 commit comments