Skip to content

Commit

Permalink
feat: skip deploy installed package if newer is installed in org
Browse files Browse the repository at this point in the history
  • Loading branch information
Codeneos committed Jun 21, 2024
1 parent 74cc6fc commit 0a8a26c
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions packages/salesforce/src/retrieveDeltaStrategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0a8a26c

Please sign in to comment.