Skip to content

Commit

Permalink
fix: emailTempalteFolder via aliased types
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc committed Jan 21, 2022
1 parent 8643883 commit f4c88f9
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/shared/metadataKeys.ts
Expand Up @@ -5,7 +5,7 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import * as path from 'path';
import { ComponentSet } from '@salesforce/source-deploy-retrieve';
import { ComponentSet, RegistryAccess } from '@salesforce/source-deploy-retrieve';
import { RemoteSyncInput } from './types';
import { getMetadataKey } from './functions';

Expand All @@ -15,6 +15,15 @@ const pathAfterFullName = (fileResponse: RemoteSyncInput): string =>
? fileResponse.filePath.substr(fileResponse.filePath.indexOf(fileResponse.fullName)).replace(/\\/gi, '/')
: '';

const registry = new RegistryAccess();

// only compute once
const aliasTypes: Array<[string, string]> = registry
.getAliasTypes()
.map((aliasType) => [aliasType.name, registry.getTypeByName(aliasType.aliasFor as string).name]);

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

// handle all "weird" type/name translation between SourceMember and SDR FileResponse
// These get de-duplicated in a set later, so it's ok to have one per file
export const getMetadataKeyFromFileResponse = (fileResponse: RemoteSyncInput): string[] => {
Expand Down Expand Up @@ -47,11 +56,19 @@ export const getMetadataKeyFromFileResponse = (fileResponse: RemoteSyncInput): s
.toArray()
.flatMap((component) => component.getChildren().map((child) => getMetadataKey('CustomLabel', child.fullName)));
}
// if we've aliased a type, we'll have to possibly sync both types--you can't tell from the sourceComponent retrieved which way it was stored on the server
if (reverseAliasTypes.has(fileResponse.type)) {
return [
getMetadataKey(fileResponse.type, fileResponse.fullName),
getMetadataKey(reverseAliasTypes.get(fileResponse.type) as string, fileResponse.fullName),
];
}
// standard key for everything else
return [getMetadataKey(fileResponse.type, fileResponse.fullName)];
};

export const mappingsForSourceMemberTypesToMetadataType = new Map<string, string>([
...aliasTypes,
['AuraDefinition', 'AuraDefinitionBundle'],
['LightningComponentResource', 'LightningComponentBundle'],
]);

0 comments on commit f4c88f9

Please sign in to comment.