Skip to content

Commit

Permalink
fix: reuse already-generated registry for metadataKeys
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc committed Aug 9, 2024
1 parent ec63df0 commit dcbe398
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 34 deletions.
68 changes: 35 additions & 33 deletions src/shared/metadataKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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]));

Expand Down Expand Up @@ -79,32 +79,34 @@ export const mappingsForSourceMemberTypesToMetadataType = new Map<string, string
['LightningComponentResource', 'LightningComponentBundle'],
]);

export const registrySupportsType = (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;
}
};
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;
}
};
2 changes: 1 addition & 1 deletion src/sourceTracking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit dcbe398

Please sign in to comment.