Skip to content

Commit

Permalink
fix: child components not being deployed (#220)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bryan Powell authored and brpowell committed Dec 8, 2020
1 parent 999501f commit d23056b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/collections/componentSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { SourceClient } from '../client';
import { MetadataDeployOptions, SourceDeployResult, SourceRetrieveResult } from '../client/types';
import { MetadataComponent, XML_DECL, XML_NS_KEY, XML_NS_URL } from '../common';
import { ComponentSetError } from '../errors';
import { nls } from '../i18n';
import {
MetadataResolver,
NodeFSTreeContainer,
Expand All @@ -28,6 +27,7 @@ import { ComponentLike } from '../common/types';

export class ComponentSet implements Iterable<MetadataComponent> {
private static readonly WILDCARD = '*';
private static readonly KEY_DELIMITER = '#';
public apiVersion: string;
private registry: RegistryAccess;
private components = new Map<string, Map<string, SourceComponent>>();
Expand Down Expand Up @@ -116,7 +116,7 @@ export class ComponentSet implements Iterable<MetadataComponent> {
const fullNames = Array.isArray(members) ? members : [members];
for (const fullName of fullNames) {
let type = registry.getTypeByName(typeName);
// if there is no delimeter and it's a type in folders, infer folder component
// if there is no / delimiter and it's a type in folders, infer folder component
if (type.folderType && !fullName.includes('/')) {
type = registry.getTypeByName(type.folderType);
}
Expand Down Expand Up @@ -183,7 +183,7 @@ export class ComponentSet implements Iterable<MetadataComponent> {
public getObject(): PackageManifestObject {
const typeMap = new Map<string, string[]>();
for (const key of this.components.keys()) {
const [typeId, fullName] = key.split('.');
const [typeId, fullName] = key.split(ComponentSet.KEY_DELIMITER);
let type = this.registry.getTypeByName(typeId);

if (type.folderContentType) {
Expand Down Expand Up @@ -302,7 +302,7 @@ export class ComponentSet implements Iterable<MetadataComponent> {
public *[Symbol.iterator](): Iterator<MetadataComponent> {
for (const [key, sourceComponents] of this.components.entries()) {
if (sourceComponents.size === 0) {
const [typeName, fullName] = key.split('.');
const [typeName, fullName] = key.split(ComponentSet.KEY_DELIMITER);
yield {
fullName,
type: this.registry.getTypeByName(typeName),
Expand Down Expand Up @@ -340,6 +340,6 @@ export class ComponentSet implements Iterable<MetadataComponent> {
private simpleKey(component: ComponentLike): string {
const typeName =
typeof component.type === 'string' ? component.type.toLowerCase().trim() : component.type.id;
return `${typeName}.${component.fullName}`;
return `${typeName}${ComponentSet.KEY_DELIMITER}${component.fullName}`;
}
}
16 changes: 15 additions & 1 deletion test/collections/componentSet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ describe('ComponentSet', () => {
]);
});

it('should interpret a member of a type in folders with no delimeter as its corresponding folder type', async () => {
it('should interpret a member of a type in folders with no delimiter as its corresponding folder type', async () => {
const set = await ComponentSet.fromManifestFile('folderComponent.xml', {
registry: mockRegistry,
tree,
Expand Down Expand Up @@ -343,6 +343,20 @@ describe('ComponentSet', () => {
},
]);
});

/**
* If component set keys are incorrectly handled, child component names may not be returned properly.
*/
it('should correctly return addressable child components', () => {
const set = new ComponentSet([{ fullName: 'MyParent__c.Child__c', type: 'x' }], mockRegistry);

expect(set.getObject().Package.types).to.deep.equal([
{
name: 'X',
members: ['MyParent__c.Child__c'],
},
]);
});
});

describe('resolveSourceComponents', () => {
Expand Down

0 comments on commit d23056b

Please sign in to comment.