Skip to content

Commit 992830b

Browse files
committed
fix: allow unprocessed component to be the default component
1 parent 66ddda0 commit 992830b

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

src/convert/convertContext.ts

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -195,14 +195,19 @@ class NonDecompositionFinalizer extends ConvertTransactionFinalizer<NonDecomposi
195195
return;
196196
}
197197

198+
const unprocessedComponents = this.getUnprocessedComponents(defaultDirectory);
199+
const parentPaths = Object.keys(this.state.claimed).concat(
200+
unprocessedComponents.map((c) => c.xml)
201+
);
202+
198203
const defaultComponentKey =
199-
Object.keys(this.state.claimed).find((k) => k.startsWith(defaultDirectory)) ||
200-
Object.keys(this.state.claimed)[0];
204+
parentPaths.find((p) => p.startsWith(defaultDirectory)) || parentPaths[0];
201205

202206
const claimedChildren = [
203207
...this.getClaimedChildrenNames(),
204-
...(await this.getChildrenOfUnprocessedComponents(defaultDirectory)),
208+
...(await this.getChildrenOfUnprocessedComponents(unprocessedComponents)),
205209
];
210+
206211
// merge unclaimed children into default parent component
207212
for (const [key, childIndex] of Object.entries(this.state.unclaimed)) {
208213
const pruned = Object.entries(childIndex.children).reduce((result, [childName, childXml]) => {
@@ -211,24 +216,26 @@ class NonDecompositionFinalizer extends ConvertTransactionFinalizer<NonDecomposi
211216
: result;
212217
}, {});
213218
delete this.state.unclaimed[key];
214-
this.state.claimed[defaultComponentKey].children = Object.assign(
215-
{},
216-
this.state.claimed[defaultComponentKey].children,
217-
pruned
218-
);
219+
if (this.state.claimed[defaultComponentKey]) {
220+
this.state.claimed[defaultComponentKey].children = Object.assign(
221+
{},
222+
this.state.claimed[defaultComponentKey].children,
223+
pruned
224+
);
225+
}
219226
}
220227
}
221228

222229
/**
223-
* Returns the children of "unprocessed components"
230+
* Returns the "unprocessed components"
224231
*
225232
* An unprocessed component is a component that was not resolved during component resolution.
226233
* This typically only happens when a specific source path was resolved. This is problematic for
227234
* nondecomposed metadata types (like CustomLabels) because we need to know the location of each
228235
* child type before recomposing the final xml. So in order for each of the children to be properly
229236
* claimed, we have to create new ComponentSet that will have all the parent components.
230237
*/
231-
private async getChildrenOfUnprocessedComponents(defaultDirectory: string): Promise<string[]> {
238+
private getUnprocessedComponents(defaultDirectory: string): SourceComponent[] {
232239
if (isEmpty(this.state.unclaimed)) {
233240
return [];
234241
}
@@ -261,7 +268,15 @@ class NonDecompositionFinalizer extends ConvertTransactionFinalizer<NonDecomposi
261268
const unprocessedComponents = ComponentSet.fromSource({ fsPaths, include: filterSet })
262269
.getSourceComponents()
263270
.filter((component) => !this.state.claimed[component.xml]);
271+
return unprocessedComponents.toArray();
272+
}
264273

274+
/**
275+
* Returns the children of "unprocessed components"
276+
*/
277+
private async getChildrenOfUnprocessedComponents(
278+
unprocessedComponents: SourceComponent[]
279+
): Promise<string[]> {
265280
const childrenOfUnprocessed = [];
266281
for (const component of unprocessedComponents) {
267282
for (const child of component.getChildren()) {

0 commit comments

Comments
 (0)