Skip to content

Commit d77f475

Browse files
fix: ensure component.content is always assigned (#485)
* fix: ensure component.content is always assigned * fix: don't set content when no component Co-authored-by: Willie Ruemmele <[email protected]>
1 parent f13e786 commit d77f475

File tree

2 files changed

+33
-30
lines changed

2 files changed

+33
-30
lines changed

src/resolve/adapters/decomposedSourceAdapter.ts

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ export class DecomposedSourceAdapter extends MixedContentSourceAdapter {
5151
rootMetadata = parseMetadataXml(rootMetadataPath);
5252
}
5353
}
54-
5554
let component: SourceComponent;
5655
if (rootMetadata) {
5756
const componentName = this.type.folderType
@@ -81,40 +80,42 @@ export class DecomposedSourceAdapter extends MixedContentSourceAdapter {
8180
if (metaXml) {
8281
const pathToContent = this.trimPathToContent(trigger);
8382
const childTypeId = this.type.children.suffixes[metaXml.suffix];
84-
85-
// If the child is explicitly not addressable, return the parent SourceComponent.
86-
const triggerIsAChild = !!childTypeId && this.type.children.types[childTypeId].isAddressable !== false;
83+
const triggerIsAChild = !!childTypeId;
8784
const strategy = this.type.strategies.decomposition;
88-
if (triggerIsAChild && (strategy === DecompositionStrategy.FolderPerType || isResolvingSource)) {
89-
let parent = component;
90-
if (!parent) {
91-
parent = new SourceComponent(
85+
86+
if (triggerIsAChild) {
87+
if (strategy === DecompositionStrategy.FolderPerType || isResolvingSource) {
88+
let parent = component;
89+
if (!parent) {
90+
parent = new SourceComponent(
91+
{
92+
name: baseName(pathToContent),
93+
type: this.type,
94+
},
95+
this.tree,
96+
this.forceIgnore
97+
);
98+
}
99+
parent.content = pathToContent;
100+
return new SourceComponent(
92101
{
93-
name: baseName(pathToContent),
94-
type: this.type,
102+
name: metaXml.fullName,
103+
type: this.type.children.types[childTypeId],
104+
xml: trigger,
105+
parent,
95106
},
96107
this.tree,
97108
this.forceIgnore
98109
);
99110
}
100-
parent.content = pathToContent;
101-
return new SourceComponent(
102-
{
103-
name: metaXml.fullName,
104-
type: this.type.children.types[childTypeId],
105-
xml: trigger,
106-
parent,
107-
},
108-
this.tree,
109-
this.forceIgnore
110-
);
111-
}
112-
if (!triggerIsAChild) {
111+
} else {
113112
if (!component) {
114113
// This is most likely metadata found within a CustomObject folder that is not a
115114
// child type of CustomObject. E.g., Layout, SharingRules, ApexClass.
116115
throw new TypeInferenceError('error_unexpected_child_type', [trigger, this.type.name]);
117116
}
117+
}
118+
if (component) {
118119
component.content = pathToContent;
119120
}
120121
}

test/resolve/adapters/decomposedSourceAdapter.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { join } from 'path';
88
import { expect } from 'chai';
99
import { DecomposedSourceAdapter, DefaultSourceAdapter } from '../../../src/resolve/adapters';
1010
import { mockRegistry, decomposed, decomposedtoplevel, mockRegistryData, xmlInFolder } from '../../mock/registry';
11-
import { VirtualTreeContainer, SourceComponent, MetadataType } from '../../../src';
11+
import { VirtualTreeContainer, SourceComponent } from '../../../src';
1212
import { RegistryTestUtil } from '../registryTestUtil';
1313
import { META_XML_SUFFIX } from '../../../src/common';
1414

@@ -28,15 +28,17 @@ describe('DecomposedSourceAdapter', () => {
2828
expect(adapter.getComponent(decomposed.DECOMPOSED_CHILD_XML_PATH_1)).to.deep.equal(expectedChild);
2929
});
3030

31-
it('should return parent SourceComponent when given a child xml of non-addressable type', () => {
32-
const nonAddressableType = JSON.parse(JSON.stringify(mockRegistryData.types.decomposedtoplevel)) as MetadataType;
33-
nonAddressableType.children.types.g.isAddressable = false;
31+
it('should set the component.content for a child when isResolvingSource = false', () => {
3432
const decompTree = new VirtualTreeContainer(decomposedtoplevel.DECOMPOSED_VIRTUAL_FS);
35-
const decompAdapter = new DecomposedSourceAdapter(nonAddressableType, mockRegistry, undefined, decompTree);
33+
const decompAdapter = new DecomposedSourceAdapter(
34+
mockRegistryData.types.decomposedtoplevel,
35+
mockRegistry,
36+
undefined,
37+
decompTree
38+
);
3639
const expectedComp = new SourceComponent(decomposedtoplevel.DECOMPOSED_TOP_LEVEL_COMPONENT, decompTree);
37-
expectedComp.type.children.types.g.isAddressable = false;
3840
const childComp = decomposedtoplevel.DECOMPOSED_TOP_LEVEL_CHILD_XML_PATHS[0];
39-
expect(decompAdapter.getComponent(childComp)).to.deep.equal(expectedComp);
41+
expect(decompAdapter.getComponent(childComp, false)).to.deep.equal(expectedComp);
4042
});
4143

4244
it('should return expected SourceComponent when given a child xml in its decomposed folder', () => {

0 commit comments

Comments
 (0)