diff --git a/src/resolve/adapters/decomposedSourceAdapter.ts b/src/resolve/adapters/decomposedSourceAdapter.ts index 76eab18815..771166ec39 100644 --- a/src/resolve/adapters/decomposedSourceAdapter.ts +++ b/src/resolve/adapters/decomposedSourceAdapter.ts @@ -51,7 +51,6 @@ export class DecomposedSourceAdapter extends MixedContentSourceAdapter { rootMetadata = parseMetadataXml(rootMetadataPath); } } - let component: SourceComponent; if (rootMetadata) { const componentName = this.type.folderType @@ -81,40 +80,42 @@ export class DecomposedSourceAdapter extends MixedContentSourceAdapter { if (metaXml) { const pathToContent = this.trimPathToContent(trigger); const childTypeId = this.type.children.suffixes[metaXml.suffix]; - - // If the child is explicitly not addressable, return the parent SourceComponent. - const triggerIsAChild = !!childTypeId && this.type.children.types[childTypeId].isAddressable !== false; + const triggerIsAChild = !!childTypeId; const strategy = this.type.strategies.decomposition; - if (triggerIsAChild && (strategy === DecompositionStrategy.FolderPerType || isResolvingSource)) { - let parent = component; - if (!parent) { - parent = new SourceComponent( + + if (triggerIsAChild) { + if (strategy === DecompositionStrategy.FolderPerType || isResolvingSource) { + let parent = component; + if (!parent) { + parent = new SourceComponent( + { + name: baseName(pathToContent), + type: this.type, + }, + this.tree, + this.forceIgnore + ); + } + parent.content = pathToContent; + return new SourceComponent( { - name: baseName(pathToContent), - type: this.type, + name: metaXml.fullName, + type: this.type.children.types[childTypeId], + xml: trigger, + parent, }, this.tree, this.forceIgnore ); } - parent.content = pathToContent; - return new SourceComponent( - { - name: metaXml.fullName, - type: this.type.children.types[childTypeId], - xml: trigger, - parent, - }, - this.tree, - this.forceIgnore - ); - } - if (!triggerIsAChild) { + } else { if (!component) { // This is most likely metadata found within a CustomObject folder that is not a // child type of CustomObject. E.g., Layout, SharingRules, ApexClass. throw new TypeInferenceError('error_unexpected_child_type', [trigger, this.type.name]); } + } + if (component) { component.content = pathToContent; } } diff --git a/test/resolve/adapters/decomposedSourceAdapter.ts b/test/resolve/adapters/decomposedSourceAdapter.ts index 4a23d97bc1..0521cf2113 100644 --- a/test/resolve/adapters/decomposedSourceAdapter.ts +++ b/test/resolve/adapters/decomposedSourceAdapter.ts @@ -8,7 +8,7 @@ import { join } from 'path'; import { expect } from 'chai'; import { DecomposedSourceAdapter, DefaultSourceAdapter } from '../../../src/resolve/adapters'; import { mockRegistry, decomposed, decomposedtoplevel, mockRegistryData, xmlInFolder } from '../../mock/registry'; -import { VirtualTreeContainer, SourceComponent, MetadataType } from '../../../src'; +import { VirtualTreeContainer, SourceComponent } from '../../../src'; import { RegistryTestUtil } from '../registryTestUtil'; import { META_XML_SUFFIX } from '../../../src/common'; @@ -28,15 +28,17 @@ describe('DecomposedSourceAdapter', () => { expect(adapter.getComponent(decomposed.DECOMPOSED_CHILD_XML_PATH_1)).to.deep.equal(expectedChild); }); - it('should return parent SourceComponent when given a child xml of non-addressable type', () => { - const nonAddressableType = JSON.parse(JSON.stringify(mockRegistryData.types.decomposedtoplevel)) as MetadataType; - nonAddressableType.children.types.g.isAddressable = false; + it('should set the component.content for a child when isResolvingSource = false', () => { const decompTree = new VirtualTreeContainer(decomposedtoplevel.DECOMPOSED_VIRTUAL_FS); - const decompAdapter = new DecomposedSourceAdapter(nonAddressableType, mockRegistry, undefined, decompTree); + const decompAdapter = new DecomposedSourceAdapter( + mockRegistryData.types.decomposedtoplevel, + mockRegistry, + undefined, + decompTree + ); const expectedComp = new SourceComponent(decomposedtoplevel.DECOMPOSED_TOP_LEVEL_COMPONENT, decompTree); - expectedComp.type.children.types.g.isAddressable = false; const childComp = decomposedtoplevel.DECOMPOSED_TOP_LEVEL_CHILD_XML_PATHS[0]; - expect(decompAdapter.getComponent(childComp)).to.deep.equal(expectedComp); + expect(decompAdapter.getComponent(childComp, false)).to.deep.equal(expectedComp); }); it('should return expected SourceComponent when given a child xml in its decomposed folder', () => {