From 00658756945c3c84097233c84f686d1c0d210eee Mon Sep 17 00:00:00 2001 From: Matthias Rolke Date: Wed, 6 Apr 2022 14:34:13 +0200 Subject: [PATCH] fix: omit pure container types for --children flag Some parent types are only a container for their children. These parent types shouldn't be retrieved because they lack control. Instead use the addressable child types. Examples: - omit CustomLabels in favor of CustomLabel - omit Workflow in favor of WorkflowAlert, etc - but use CustomObject because it has own properties like description, etc --- src/commands/force/mdapi/listallmetadata.ts | 4 ++++ src/commands/package.xml/generate.ts | 6 ------ src/filters.ts | 16 ++++++++++++++++ 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/commands/force/mdapi/listallmetadata.ts b/src/commands/force/mdapi/listallmetadata.ts index 117a0548..d7af5144 100644 --- a/src/commands/force/mdapi/listallmetadata.ts +++ b/src/commands/force/mdapi/listallmetadata.ts @@ -175,6 +175,10 @@ export default class MdapiListAllMetadataCommand extends SfdxCommand { } } } + if (this.flags.children) { + // omit parent types which don't have own properties + ignoreFunctions.push(filters.isPureContainerType); + } let fileProperties = await listAllMetadata( conn, this.flags, diff --git a/src/commands/package.xml/generate.ts b/src/commands/package.xml/generate.ts index e43dde8c..159bade8 100644 --- a/src/commands/package.xml/generate.ts +++ b/src/commands/package.xml/generate.ts @@ -89,12 +89,6 @@ export default class PackageXmlGenerateCommand extends SfdxCommand { if (this.flags.defaultignore) { ignorePatterns.push(...this.flags.defaultignore); } - // don't list 'CustomLabels:CustomLabels' if specific 'CustomLabel:XXX' are given - if (fileProperties.find((fp) => fp.type === 'CustomLabel') !== null) { - fileProperties = fileProperties.filter( - (fp) => fp.type !== 'CustomLabels' - ); - } const [, keep] = match( fileProperties, ignorePatterns, diff --git a/src/filters.ts b/src/filters.ts index fd179218..b41dd4a7 100644 --- a/src/filters.ts +++ b/src/filters.ts @@ -21,6 +21,18 @@ const MANAGED_READONLY_TYPES = [ 'ApexPage' ]; +// parent types which don't have own properties +const PURE_CONTAINER_TYPES = [ + 'AssignmentRules', + 'AutoResponseRules', + 'CustomLabels', + 'EscalationRules', + 'ManagedTopics', + 'MatchingRules', + 'SharingRules', + 'Workflow' +]; + const STANDARD_USERNAMES = ['Automated Process', 'salesforce.com']; export function isManaged(fileProperties: FileProperties): boolean { @@ -76,3 +88,7 @@ export function isStandard(fileProperties: FileProperties): boolean { fileProperties.namespacePrefix === 'standard' ); } + +export function isPureContainerType(fileProperties: FileProperties): boolean { + return PURE_CONTAINER_TYPES.includes(fileProperties.type); +}