diff --git a/src/client/index.ts b/src/client/index.ts index 6419c67b6..345249dcf 100644 --- a/src/client/index.ts +++ b/src/client/index.ts @@ -43,7 +43,7 @@ export { PackageOptions, RetrieveOptions, DeployVersionData, - DeployData, + DeployZipData, RetrieveVersionData, MetadataApiRetrieveOptions, } from './types'; diff --git a/src/client/metadataApiDeploy.ts b/src/client/metadataApiDeploy.ts index 6a9b0dcba..beb8ff862 100644 --- a/src/client/metadataApiDeploy.ts +++ b/src/client/metadataApiDeploy.ts @@ -207,7 +207,10 @@ export class MetadataApiDeploy extends MetadataTransfer< }) ); - const [zipBuffer] = await Promise.all([this.getZipBuffer(), this.maybeSaveTempDirectory('metadata')]); + const [{ zipBuffer, zipFileCount }] = await Promise.all([ + this.getZipBuffer(), + this.maybeSaveTempDirectory('metadata'), + ]); // SDR modifies what the mdapi expects by adding a rest param const { rest, ...optionsWithoutRest } = this.options.apiOptions ?? {}; @@ -217,8 +220,16 @@ export class MetadataApiDeploy extends MetadataTransfer< const manifestMsg = manifestVersion ? ` in v${manifestVersion} shape` : ''; const debugMsg = format(`Deploying metadata source%s using ${webService} v${apiVersion}`, manifestMsg); this.logger.debug(debugMsg); + + // Event and Debug output for the zip file used for deploy const zipSize = zipBuffer.byteLength; - await LifecycleInstance.emit('deployData', { webService, manifestVersion, apiVersion, zipSize }); + let zipMessage = `Deployment zip file size = ${zipSize} Bytes`; + if (zipFileCount) { + zipMessage += ` containing ${zipFileCount} files`; + } + this.logger.debug(zipMessage); + await LifecycleInstance.emit('apiVersionDeploy', { webService, manifestVersion, apiVersion }); + await LifecycleInstance.emit('deployZipData', { zipSize, zipFileCount }); return this.isRestDeploy ? connection.metadata.deployRest(zipBuffer, optionsWithoutRest) @@ -293,14 +304,17 @@ export class MetadataApiDeploy extends MetadataTransfer< return deployResult; } - private async getZipBuffer(): Promise { + private async getZipBuffer(): Promise<{ zipBuffer: Buffer; zipFileCount?: number }> { const mdapiPath = this.options.mdapiPath; + + // Zip a directory of metadata format source if (mdapiPath) { if (!fs.existsSync(mdapiPath) || !fs.lstatSync(mdapiPath).isDirectory()) { throw messages.createError('error_directory_not_found_or_not_directory', [mdapiPath]); } const zip = JSZip(); + let zipFileCount = 0; const zipDirRecursive = (dir: string): void => { const dirents = fs.readdirSync(dir, { withFileTypes: true }); @@ -314,33 +328,38 @@ export class MetadataApiDeploy extends MetadataTransfer< // Ensure only posix paths are added to zip files const relPosixPath = relPath.replace(/\\/g, '/'); zip.file(relPosixPath, fs.createReadStream(fullPath)); + zipFileCount++; } } }; this.logger.debug('Zipping directory for metadata deploy:', mdapiPath); zipDirRecursive(mdapiPath); - return zip.generateAsync({ - type: 'nodebuffer', - compression: 'DEFLATE', - compressionOptions: { level: 9 }, - }); + return { + zipBuffer: await zip.generateAsync({ + type: 'nodebuffer', + compression: 'DEFLATE', + compressionOptions: { level: 9 }, + }), + zipFileCount, + }; } - // read the zip into a buffer + // Read a zip of metadata format source into a buffer if (this.options.zipPath) { if (!fs.existsSync(this.options.zipPath)) { throw new SfError(messages.getMessage('error_path_not_found', [this.options.zipPath])); } // does encoding matter for zip files? I don't know - return fs.promises.readFile(this.options.zipPath); + return { zipBuffer: await fs.promises.readFile(this.options.zipPath) }; } + // Convert a ComponentSet of metadata in source format and zip if (this.options.components && this.components) { const converter = new MetadataConverter(this.registry); - const { zipBuffer } = await converter.convert(this.components, 'metadata', { type: 'zip' }); + const { zipBuffer, zipFileCount } = await converter.convert(this.components, 'metadata', { type: 'zip' }); if (!zipBuffer) { throw new SfError(messages.getMessage('zipBufferError')); } - return zipBuffer; + return { zipBuffer, zipFileCount }; } throw new Error('Options should include components, zipPath, or mdapiPath'); } diff --git a/src/client/types.ts b/src/client/types.ts index 883c789eb..035bbdb4b 100644 --- a/src/client/types.ts +++ b/src/client/types.ts @@ -372,10 +372,11 @@ export type DeployVersionData = { }; /** - * Data about a deployment about to be sent to the Metadata API + * Data about a deployment zip file being sent to the Metadata API. */ -export type DeployData = DeployVersionData & { +export type DeployZipData = { zipSize: number; + zipFileCount: number; }; export type RetrieveVersionData = { diff --git a/src/convert/metadataConverter.ts b/src/convert/metadataConverter.ts index 7c1cd64d9..48b9c9286 100644 --- a/src/convert/metadataConverter.ts +++ b/src/convert/metadataConverter.ts @@ -89,10 +89,9 @@ const getResult = async (writer: StandardWriter | ZipWriter): Promise => { // union type discrimination if ('addToZip' in writer) { - // console.log('zip file count =', writer.fileCount); const buffer = writer.buffer; if (!packagePath) { - return { packagePath, zipBuffer: buffer }; + return { packagePath, zipBuffer: buffer, zipFileCount: writer.fileCount }; } else if (buffer) { await promises.writeFile(packagePath, buffer); return { packagePath }; diff --git a/src/convert/streams.ts b/src/convert/streams.ts index a3572b338..07b366749 100644 --- a/src/convert/streams.ts +++ b/src/convert/streams.ts @@ -183,6 +183,9 @@ export class StandardWriter extends ComponentWriter { } export class ZipWriter extends ComponentWriter { + /** + * Count of files (not directories) added to the zip file. + */ public fileCount: number = 0; private zip = JSZip(); private zipBuffer?: Buffer; diff --git a/src/convert/types.ts b/src/convert/types.ts index e0e790a5b..625196553 100644 --- a/src/convert/types.ts +++ b/src/convert/types.ts @@ -107,6 +107,10 @@ export type ConvertResult = { * Buffer of converted package. `Undefined` if `outputDirectory` is omitted from zip output config. */ zipBuffer?: Buffer; + /** + * When a zip buffer is created, this is the number of files in the zip. + */ + zipFileCount?: number; /** * Converted source components. Not set if archiving the package. */ diff --git a/src/index.ts b/src/index.ts index b8df13e3e..5c4804d41 100644 --- a/src/index.ts +++ b/src/index.ts @@ -44,7 +44,7 @@ export { PackageOptions, RetrieveOptions, DeployVersionData, - DeployData, + DeployZipData, RetrieveVersionData, } from './client'; export {