From dcbe398bdb4578cf993f823c40655ece5901ee5d Mon Sep 17 00:00:00 2001 From: mshanemc Date: Fri, 9 Aug 2024 07:35:42 -0500 Subject: [PATCH] fix: reuse already-generated registry for metadataKeys --- src/shared/metadataKeys.ts | 68 ++++++++++++++++++++------------------ src/sourceTracking.ts | 2 +- 2 files changed, 36 insertions(+), 34 deletions(-) diff --git a/src/shared/metadataKeys.ts b/src/shared/metadataKeys.ts index d2f5d436..e4252e77 100644 --- a/src/shared/metadataKeys.ts +++ b/src/shared/metadataKeys.ts @@ -6,7 +6,7 @@ */ import { basename, dirname, join, normalize, sep } from 'node:path'; import { ComponentSet, RegistryAccess } from '@salesforce/source-deploy-retrieve'; -import { Lifecycle } from '@salesforce/core'; +import { Lifecycle } from '@salesforce/core/lifecycle'; import { RemoteSyncInput } from './types'; import { getMetadataKey } from './functions'; @@ -20,13 +20,13 @@ const pathAfterFullName = (fileResponse: RemoteSyncInput): string => ).replace(/\\/gi, '/') : ''; -const registry = new RegistryAccess(); +const registryAccess = new RegistryAccess(); // only compute once -const aliasTypes: Array<[string, string]> = registry +const aliasTypes: Array<[string, string]> = registryAccess .getAliasTypes() // allow assertion because aliasTypes are defined as having that property - .map((aliasType) => [aliasType.name, registry.getTypeByName(aliasType.aliasFor!).name]); + .map((aliasType) => [aliasType.name, registryAccess.getTypeByName(aliasType.aliasFor!).name]); const reverseAliasTypes = new Map(aliasTypes.map(([alias, type]) => [type, alias])); @@ -79,32 +79,34 @@ export const mappingsForSourceMemberTypesToMetadataType = new Map { - if (mappingsForSourceMemberTypesToMetadataType.has(type)) { - return true; - } - if (type === 'PicklistValue') { - /* "PicklistValue" appears occasionally in sourceMembers, but it's not a real, addressable type in the registry - * It only appears when a picklist value is reactivated, so I'd call this a SourceMember bug - * We also can't make it a child type in the SDR registry because it it can be a parent of either CustomField/Picklist OR GlobalValueSet - * in both parent cases (GVS and CustomField), the the parent is marked as changed in SourceMembers, to the behavior is ok igoring the PicklistValue - * This suppresses the warning, and could be removed if the SourceMember bug is fixed - */ - return false; - } - if (type === 'ExperienceResource') { - /* ExperienceResource is a child of ExperienceBundle but fine-grained source tracking isn't supported for - * ExperienceBundle since it's not defined that way in the SDR registry. Since ExperienceBundle is - * essentially deprecated in favor of DigitalExperienceBundle this is not something we're going to support. - */ - return false; - } - try { - // this must use getTypeByName because findType doesn't support addressable child types (ex: customField!) - registry.getTypeByName(type); - return true; - } catch (e) { - void Lifecycle.getInstance().emitWarning(`Unable to find type ${type} in registry`); - return false; - } -}; +export const registrySupportsType = + (registry: RegistryAccess) => + (type: string): boolean => { + if (mappingsForSourceMemberTypesToMetadataType.has(type)) { + return true; + } + if (type === 'PicklistValue') { + /* "PicklistValue" appears occasionally in sourceMembers, but it's not a real, addressable type in the registry + * It only appears when a picklist value is reactivated, so I'd call this a SourceMember bug + * We also can't make it a child type in the SDR registry because it it can be a parent of either CustomField/Picklist OR GlobalValueSet + * in both parent cases (GVS and CustomField), the the parent is marked as changed in SourceMembers, to the behavior is ok igoring the PicklistValue + * This suppresses the warning, and could be removed if the SourceMember bug is fixed + */ + return false; + } + if (type === 'ExperienceResource') { + /* ExperienceResource is a child of ExperienceBundle but fine-grained source tracking isn't supported for + * ExperienceBundle since it's not defined that way in the SDR registry. Since ExperienceBundle is + * essentially deprecated in favor of DigitalExperienceBundle this is not something we're going to support. + */ + return false; + } + try { + // this must use getTypeByName because findType doesn't support addressable child types (ex: customField!) + registry.getTypeByName(type); + return true; + } catch (e) { + void Lifecycle.getInstance().emitWarning(`Unable to find type ${type} in registry`); + return false; + } + }; diff --git a/src/sourceTracking.ts b/src/sourceTracking.ts index 769c6791..4e218632 100644 --- a/src/sourceTracking.ts +++ b/src/sourceTracking.ts @@ -320,7 +320,7 @@ export class SourceTracking extends AsyncCreatable { const filteredChanges = remoteChanges .filter(remoteFilterByState[options.state]) // skip any remote types not in the registry. Will emit warnings - .filter((rce) => registrySupportsType(rce.type)); + .filter((rce) => registrySupportsType(this.registry)(rce.type)); if (options.format === 'ChangeResult') { return filteredChanges.map(remoteChangeElementToChangeResult); }