@@ -43,7 +43,8 @@ export class DeployResult implements MetadataTransferResult {
4343  public  constructor ( 
4444    public  readonly  response : MetadataApiDeployStatus , 
4545    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  } 
4748  )  { } 
4849
4950  public  getFileResponses ( ) : FileResponse [ ]  { 
@@ -97,6 +98,8 @@ export class MetadataApiDeploy extends MetadataTransfer<
9798  // from the apiOptions and we need it for telemetry. 
9899  private  readonly  isRestDeploy : boolean ; 
99100  private  readonly  registry : RegistryAccess ; 
101+   private  zipSize ?: number ; 
102+   private  zipFileCount ?: number ; 
100103
101104  public  constructor ( options : MetadataApiDeployOptions )  { 
102105    super ( options ) ; 
@@ -207,7 +210,10 @@ export class MetadataApiDeploy extends MetadataTransfer<
207210        } ) 
208211    ) ; 
209212
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+     ] ) ; 
211217    // SDR modifies what the mdapi expects by adding a rest param 
212218    const  {  rest,  ...optionsWithoutRest  }  =  this . options . apiOptions  ??  { } ; 
213219
@@ -217,7 +223,17 @@ export class MetadataApiDeploy extends MetadataTransfer<
217223    const  manifestMsg  =  manifestVersion  ? ` in v${ manifestVersion }   shape`  : '' ; 
218224    const  debugMsg  =  format ( `Deploying metadata source%s using ${ webService }   v${ apiVersion }  ` ,  manifestMsg ) ; 
219225    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 ) ; 
220235    await  LifecycleInstance . emit ( 'apiVersionDeploy' ,  {  webService,  manifestVersion,  apiVersion } ) ; 
236+     await  LifecycleInstance . emit ( 'deployZipData' ,  {  zipSize : this . zipSize ,  zipFileCount } ) ; 
221237
222238    return  this . isRestDeploy 
223239      ? connection . metadata . deployRest ( zipBuffer ,  optionsWithoutRest ) 
@@ -266,6 +282,8 @@ export class MetadataApiDeploy extends MetadataTransfer<
266282        numberTestsTotal : result . numberTestsTotal , 
267283        testsTotalTime : result . details ?. runTestResult ?. totalTime , 
268284        filesWithReplacementsQuantity : this . replacements . size  ??  0 , 
285+         zipSize : this . zipSize  ??  0 , 
286+         zipFileCount : this . zipFileCount  ??  0 , 
269287      } ) ; 
270288    }  catch  ( err )  { 
271289      const  error  =  err  as  Error ; 
@@ -278,7 +296,8 @@ export class MetadataApiDeploy extends MetadataTransfer<
278296    const  deployResult  =  new  DeployResult ( 
279297      result , 
280298      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  } 
282301    ) ; 
283302    // only do event hooks if source, (NOT a metadata format) deploy 
284303    if  ( this . options . components )  { 
@@ -292,14 +311,17 @@ export class MetadataApiDeploy extends MetadataTransfer<
292311    return  deployResult ; 
293312  } 
294313
295-   private  async  getZipBuffer ( ) : Promise < Buffer >  { 
314+   private  async  getZipBuffer ( ) : Promise < {   zipBuffer :  Buffer ;   zipFileCount ?:  number   } >  { 
296315    const  mdapiPath  =  this . options . mdapiPath ; 
316+ 
317+     // Zip a directory of metadata format source 
297318    if  ( mdapiPath )  { 
298319      if  ( ! fs . existsSync ( mdapiPath )  ||  ! fs . lstatSync ( mdapiPath ) . isDirectory ( ) )  { 
299320        throw  messages . createError ( 'error_directory_not_found_or_not_directory' ,  [ mdapiPath ] ) ; 
300321      } 
301322
302323      const  zip  =  JSZip ( ) ; 
324+       let  zipFileCount  =  0 ; 
303325
304326      const  zipDirRecursive  =  ( dir : string ) : void   =>  { 
305327        const  dirents  =  fs . readdirSync ( dir ,  {  withFileTypes : true  } ) ; 
@@ -313,33 +335,38 @@ export class MetadataApiDeploy extends MetadataTransfer<
313335            // Ensure only posix paths are added to zip files 
314336            const  relPosixPath  =  relPath . replace ( / \\ / g,  '/' ) ; 
315337            zip . file ( relPosixPath ,  fs . createReadStream ( fullPath ) ) ; 
338+             zipFileCount ++ ; 
316339          } 
317340        } 
318341      } ; 
319342      this . logger . debug ( 'Zipping directory for metadata deploy:' ,  mdapiPath ) ; 
320343      zipDirRecursive ( mdapiPath ) ; 
321344
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+       } ; 
327353    } 
328-     // read the  zip into a buffer 
354+     // Read a  zip of metadata format source  into a buffer 
329355    if  ( this . options . zipPath )  { 
330356      if  ( ! fs . existsSync ( this . options . zipPath ) )  { 
331357        throw  new  SfError ( messages . getMessage ( 'error_path_not_found' ,  [ this . options . zipPath ] ) ) ; 
332358      } 
333359      // 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 )   } ; 
335361    } 
362+     // Convert a ComponentSet of metadata in source format and zip 
336363    if  ( this . options . components  &&  this . components )  { 
337364      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'  } ) ; 
339366      if  ( ! zipBuffer )  { 
340367        throw  new  SfError ( messages . getMessage ( 'zipBufferError' ) ) ; 
341368      } 
342-       return  zipBuffer ; 
369+       return  {   zipBuffer,  zipFileCount  } ; 
343370    } 
344371    throw  new  Error ( 'Options should include components, zipPath, or mdapiPath' ) ; 
345372  } 
0 commit comments