Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ensure component.content is always assigned #485

Merged
merged 6 commits into from
Oct 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 24 additions & 23 deletions src/resolve/adapters/decomposedSourceAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ export class DecomposedSourceAdapter extends MixedContentSourceAdapter {
rootMetadata = parseMetadataXml(rootMetadataPath);
}
}

let component: SourceComponent;
if (rootMetadata) {
const componentName = this.type.folderType
Expand Down Expand Up @@ -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;
}
}
Expand Down
16 changes: 9 additions & 7 deletions test/resolve/adapters/decomposedSourceAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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', () => {
Expand Down