@@ -195,14 +195,19 @@ class NonDecompositionFinalizer extends ConvertTransactionFinalizer<NonDecomposi
195
195
return ;
196
196
}
197
197
198
+ const unprocessedComponents = this . getUnprocessedComponents ( defaultDirectory ) ;
199
+ const parentPaths = Object . keys ( this . state . claimed ) . concat (
200
+ unprocessedComponents . map ( ( c ) => c . xml )
201
+ ) ;
202
+
198
203
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 ] ;
201
205
202
206
const claimedChildren = [
203
207
...this . getClaimedChildrenNames ( ) ,
204
- ...( await this . getChildrenOfUnprocessedComponents ( defaultDirectory ) ) ,
208
+ ...( await this . getChildrenOfUnprocessedComponents ( unprocessedComponents ) ) ,
205
209
] ;
210
+
206
211
// merge unclaimed children into default parent component
207
212
for ( const [ key , childIndex ] of Object . entries ( this . state . unclaimed ) ) {
208
213
const pruned = Object . entries ( childIndex . children ) . reduce ( ( result , [ childName , childXml ] ) => {
@@ -211,24 +216,26 @@ class NonDecompositionFinalizer extends ConvertTransactionFinalizer<NonDecomposi
211
216
: result ;
212
217
} , { } ) ;
213
218
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
+ }
219
226
}
220
227
}
221
228
222
229
/**
223
- * Returns the children of "unprocessed components"
230
+ * Returns the "unprocessed components"
224
231
*
225
232
* An unprocessed component is a component that was not resolved during component resolution.
226
233
* This typically only happens when a specific source path was resolved. This is problematic for
227
234
* nondecomposed metadata types (like CustomLabels) because we need to know the location of each
228
235
* child type before recomposing the final xml. So in order for each of the children to be properly
229
236
* claimed, we have to create new ComponentSet that will have all the parent components.
230
237
*/
231
- private async getChildrenOfUnprocessedComponents ( defaultDirectory : string ) : Promise < string [ ] > {
238
+ private getUnprocessedComponents ( defaultDirectory : string ) : SourceComponent [ ] {
232
239
if ( isEmpty ( this . state . unclaimed ) ) {
233
240
return [ ] ;
234
241
}
@@ -261,7 +268,15 @@ class NonDecompositionFinalizer extends ConvertTransactionFinalizer<NonDecomposi
261
268
const unprocessedComponents = ComponentSet . fromSource ( { fsPaths, include : filterSet } )
262
269
. getSourceComponents ( )
263
270
. filter ( ( component ) => ! this . state . claimed [ component . xml ] ) ;
271
+ return unprocessedComponents . toArray ( ) ;
272
+ }
264
273
274
+ /**
275
+ * Returns the children of "unprocessed components"
276
+ */
277
+ private async getChildrenOfUnprocessedComponents (
278
+ unprocessedComponents : SourceComponent [ ]
279
+ ) : Promise < string [ ] > {
265
280
const childrenOfUnprocessed = [ ] ;
266
281
for ( const component of unprocessedComponents ) {
267
282
for ( const child of component . getChildren ( ) ) {
0 commit comments