Skip to content

feat: support decomposed components across multiple directories #224

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

Merged
merged 26 commits into from
Jan 14, 2021

Conversation

brpowell
Copy link
Contributor

What does this PR do?

Supports the use case of dividing a single decomposed component across different folders (package directories). For instance - a CustomObject can have some of its fields in one package, while the rest of its parts live in another.

What issues does this PR fix or reference?

@W-8527909@

Comment on lines 87 to 102
private async recompose(children: SourceComponent[], baseXmlObj: any): Promise<JsonMap> {
for (const child of children) {
const { directoryName: groupNode } = child.type;
const { name: parentName } = child.parent.type;
const childContents = (await child.parseXml())[child.type.name];
if (!baseXmlObj[parentName]) {
baseXmlObj[parentName] = { '@_xmlns': XML_NS_URL };
}

if (!baseXmlObj[parentName][groupNode]) {
baseXmlObj[parentName][groupNode] = [];
}
(baseXmlObj[parentName][groupNode] as JsonArray).push(childContents);
}
return baseXmlObj;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved this logic from the source adapter to the finalizer since its only used here now


return [DecomposedMetadataTransformer.createParentWriteInfo(component, recomposedXmlObj)];
// noop since the finalizer will push the writes to the component writer
return [];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

toMetadataFormat now only ever contributes to the convert transaction and doesn't directly create write infos anymore.

type: this.type,
},
this.tree,
this.forceIgnore
);
}
parent.content = pathToContent;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We now assign the CustomObject bundle path to the content property, like how bundle types work. This is so that even if there isn't a CustomObject xml, we can walk the folder to see all the children present.

registry?: RegistryAccess;
}

export interface FromSourceOptions extends ComponentSetOptions {
filter?: Iterable<ComponentLike> | ComponentSet;
resolveChildrenWithParent?: boolean;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new option allows us to directly include children in component resolution when we encounter parent components

@brpowell brpowell marked this pull request as ready for review December 11, 2020 15:20
@brpowell brpowell requested a review from a team as a code owner December 11, 2020 15:20
@brpowell brpowell marked this pull request as draft December 11, 2020 19:36
@brpowell brpowell marked this pull request as ready for review January 7, 2021 20:25
@@ -0,0 +1,131 @@
/*
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a refactor of the ConvertTransaction concept, but performs the same job

Comment on lines +104 to +105
for await (const finalizerResult of this.context.executeFinalizers()) {
finalizerResult.forEach((result) => this.push(result));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could simplify this

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe a map?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh sorry, I meant that I did simplify it. push is a stream method.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah ok cool

Comment on lines -29 to -54
public static async recompose(
children: SourceComponent[],
baseXmlObj: XmlJson = {}
): Promise<JsonMap> {
for (const child of children) {
const { directoryName: groupNode } = child.type;
const { name: parentName } = child.parent.type;
const childContents = (await child.parseXml())[child.type.name];
if (!baseXmlObj[parentName]) {
baseXmlObj[parentName] = { '@_xmlns': XML_NS_URL };
}

if (!baseXmlObj[parentName][groupNode]) {
baseXmlObj[parentName][groupNode] = [];
}
(baseXmlObj[parentName][groupNode] as JsonArray).push(childContents);
}
return baseXmlObj;
}

public static createParentWriteInfo(trigger: SourceComponent, xmlObject: JsonMap): WriteInfo {
return {
source: new JsToXml(xmlObject),
output: join(trigger.type.directoryName, `${trigger.fullName}.${trigger.type.suffix}`),
};
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved this logic to the RecompositionFinalizer in ConvertContext

@brpowell
Copy link
Contributor Author

brpowell commented Jan 8, 2021

Apologies for the big change - feature was a bit complex

@brpowell brpowell merged commit 29dbdc7 into develop Jan 14, 2021
@brpowell brpowell deleted the bp/segmentedDecomposedComponents branch January 14, 2021 01:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants