From 0a8a26c5680f159aa1bb3e379178e31950c8cdff Mon Sep 17 00:00:00 2001 From: Peter van Gulik Date: Fri, 21 Jun 2024 12:39:54 +0200 Subject: [PATCH] feat: skip deploy installed package if newer is installed in org --- .../salesforce/src/retrieveDeltaStrategy.ts | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/packages/salesforce/src/retrieveDeltaStrategy.ts b/packages/salesforce/src/retrieveDeltaStrategy.ts index 44432b63..64354622 100644 --- a/packages/salesforce/src/retrieveDeltaStrategy.ts +++ b/packages/salesforce/src/retrieveDeltaStrategy.ts @@ -26,6 +26,8 @@ export class RetrieveDeltaStrategy { 'metaXml': (a, b) => this.isMetaXmlEqual(a, b), 'binary': this.isBinaryEqual.bind(this), 'default': this.isStringEqual.bind(this), + // Custom comparers + 'InstalledPackage': (a, b) => this.isPackageNewer(a, b), } constructor( @@ -125,20 +127,22 @@ export class RetrieveDeltaStrategy { } private getComparer(packagePath: string, data: string | Buffer, type: MetadataType): CompareStrategy { + if (this.compareStrategies[type.name]) { + return this.compareStrategies[type.name]; + } + if (/\.(cls|trigger)-meta\.xml$/i.test(packagePath)) { return this.compareStrategies.metaXml; } if (type.name === 'FlexiPage' || - type.name === 'Layout') - { + type.name === 'Layout') { return this.compareStrategies.xmlStrictOrder; } if (type.name === 'StaticResource' || type.name === 'ContentAsset' || - type.name === 'Document') - { + type.name === 'Document') { return this.compareStrategies.binary; } @@ -171,6 +175,15 @@ export class RetrieveDeltaStrategy { return !!diff; } + private isPackageNewer(a: Buffer | string, b: Buffer | string): boolean { + const localMeta = XML.parse(a, { arrayMode: false, ignoreAttributes: true }); + const orgMeta = XML.parse(b, { arrayMode: false, ignoreAttributes: true }); + + const localVersion = parseFloat(localMeta.versionNumber); + const orgVersion = parseFloat(orgMeta.versionNumber); + return isNaN(localVersion) || isNaN(orgVersion) || localVersion > orgVersion; + } + private isMetaXmlEqual(a: Buffer | string, b: Buffer | string): boolean { // Note: this function does not yet properly deal with changes in the order of XML elements in an array // Parse XML and filter out attributes as they are not important for comparison of metadata