Skip to content

Commit dcbe398

Browse files
committed
fix: reuse already-generated registry for metadataKeys
1 parent ec63df0 commit dcbe398

2 files changed

Lines changed: 36 additions & 34 deletions

File tree

src/shared/metadataKeys.ts

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77
import { basename, dirname, join, normalize, sep } from 'node:path';
88
import { ComponentSet, RegistryAccess } from '@salesforce/source-deploy-retrieve';
9-
import { Lifecycle } from '@salesforce/core';
9+
import { Lifecycle } from '@salesforce/core/lifecycle';
1010
import { RemoteSyncInput } from './types';
1111
import { getMetadataKey } from './functions';
1212

@@ -20,13 +20,13 @@ const pathAfterFullName = (fileResponse: RemoteSyncInput): string =>
2020
).replace(/\\/gi, '/')
2121
: '';
2222

23-
const registry = new RegistryAccess();
23+
const registryAccess = new RegistryAccess();
2424

2525
// only compute once
26-
const aliasTypes: Array<[string, string]> = registry
26+
const aliasTypes: Array<[string, string]> = registryAccess
2727
.getAliasTypes()
2828
// allow assertion because aliasTypes are defined as having that property
29-
.map((aliasType) => [aliasType.name, registry.getTypeByName(aliasType.aliasFor!).name]);
29+
.map((aliasType) => [aliasType.name, registryAccess.getTypeByName(aliasType.aliasFor!).name]);
3030

3131
const reverseAliasTypes = new Map(aliasTypes.map(([alias, type]) => [type, alias]));
3232

@@ -79,32 +79,34 @@ export const mappingsForSourceMemberTypesToMetadataType = new Map<string, string
7979
['LightningComponentResource', 'LightningComponentBundle'],
8080
]);
8181

82-
export const registrySupportsType = (type: string): boolean => {
83-
if (mappingsForSourceMemberTypesToMetadataType.has(type)) {
84-
return true;
85-
}
86-
if (type === 'PicklistValue') {
87-
/* "PicklistValue" appears occasionally in sourceMembers, but it's not a real, addressable type in the registry
88-
* It only appears when a picklist value is reactivated, so I'd call this a SourceMember bug
89-
* 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
90-
* in both parent cases (GVS and CustomField), the the parent is marked as changed in SourceMembers, to the behavior is ok igoring the PicklistValue
91-
* This suppresses the warning, and could be removed if the SourceMember bug is fixed
92-
*/
93-
return false;
94-
}
95-
if (type === 'ExperienceResource') {
96-
/* ExperienceResource is a child of ExperienceBundle but fine-grained source tracking isn't supported for
97-
* ExperienceBundle since it's not defined that way in the SDR registry. Since ExperienceBundle is
98-
* essentially deprecated in favor of DigitalExperienceBundle this is not something we're going to support.
99-
*/
100-
return false;
101-
}
102-
try {
103-
// this must use getTypeByName because findType doesn't support addressable child types (ex: customField!)
104-
registry.getTypeByName(type);
105-
return true;
106-
} catch (e) {
107-
void Lifecycle.getInstance().emitWarning(`Unable to find type ${type} in registry`);
108-
return false;
109-
}
110-
};
82+
export const registrySupportsType =
83+
(registry: RegistryAccess) =>
84+
(type: string): boolean => {
85+
if (mappingsForSourceMemberTypesToMetadataType.has(type)) {
86+
return true;
87+
}
88+
if (type === 'PicklistValue') {
89+
/* "PicklistValue" appears occasionally in sourceMembers, but it's not a real, addressable type in the registry
90+
* It only appears when a picklist value is reactivated, so I'd call this a SourceMember bug
91+
* 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
92+
* in both parent cases (GVS and CustomField), the the parent is marked as changed in SourceMembers, to the behavior is ok igoring the PicklistValue
93+
* This suppresses the warning, and could be removed if the SourceMember bug is fixed
94+
*/
95+
return false;
96+
}
97+
if (type === 'ExperienceResource') {
98+
/* ExperienceResource is a child of ExperienceBundle but fine-grained source tracking isn't supported for
99+
* ExperienceBundle since it's not defined that way in the SDR registry. Since ExperienceBundle is
100+
* essentially deprecated in favor of DigitalExperienceBundle this is not something we're going to support.
101+
*/
102+
return false;
103+
}
104+
try {
105+
// this must use getTypeByName because findType doesn't support addressable child types (ex: customField!)
106+
registry.getTypeByName(type);
107+
return true;
108+
} catch (e) {
109+
void Lifecycle.getInstance().emitWarning(`Unable to find type ${type} in registry`);
110+
return false;
111+
}
112+
};

src/sourceTracking.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ export class SourceTracking extends AsyncCreatable {
320320
const filteredChanges = remoteChanges
321321
.filter(remoteFilterByState[options.state])
322322
// skip any remote types not in the registry. Will emit warnings
323-
.filter((rce) => registrySupportsType(rce.type));
323+
.filter((rce) => registrySupportsType(this.registry)(rce.type));
324324
if (options.format === 'ChangeResult') {
325325
return filteredChanges.map(remoteChangeElementToChangeResult);
326326
}

0 commit comments

Comments
 (0)