@@ -56,9 +56,10 @@ export async function runCreateNodesInParallel(
56
56
) : Promise < CreateNodesResultWithContext [ ] > {
57
57
performance . mark ( `${ plugin . name } :createNodes - start` ) ;
58
58
59
- const promises : Array <
60
- CreateNodesResultWithContext | Promise < CreateNodesResultWithContext >
61
- > = configFiles . map ( ( file ) => {
59
+ const errors : CreateNodesError [ ] = [ ] ;
60
+ const results : CreateNodesResultWithContext [ ] = [ ] ;
61
+
62
+ const promises : Array < Promise < void > > = configFiles . map ( ( file ) => {
62
63
performance . mark ( `${ plugin . name } :createNodes:${ file } - start` ) ;
63
64
// Result is either static or a promise, using Promise.resolve lets us
64
65
// handle both cases with same logic
@@ -68,11 +69,14 @@ export async function runCreateNodesInParallel(
68
69
return value
69
70
. catch ( ( e ) => {
70
71
performance . mark ( `${ plugin . name } :createNodes:${ file } - end` ) ;
71
- return new CreateNodesError ( {
72
- error : e ,
73
- pluginName : plugin . name ,
74
- file,
75
- } ) ;
72
+ errors . push (
73
+ new CreateNodesError ( {
74
+ error : e ,
75
+ pluginName : plugin . name ,
76
+ file,
77
+ } )
78
+ ) ;
79
+ return null ;
76
80
} )
77
81
. then ( ( r ) => {
78
82
performance . mark ( `${ plugin . name } :createNodes:${ file } - end` ) ;
@@ -82,42 +86,25 @@ export async function runCreateNodesInParallel(
82
86
`${ plugin . name } :createNodes:${ file } - end`
83
87
) ;
84
88
85
- return { ...r , pluginName : plugin . name , file } ;
89
+ // Existing behavior is to ignore null results of
90
+ // createNodes function.
91
+ if ( r ) {
92
+ results . push ( r ) ;
93
+ }
86
94
} ) ;
87
95
} ) ;
88
- const results = await Promise . all ( promises ) . then ( ( results ) => {
96
+
97
+ await Promise . all ( promises ) . then ( ( ) => {
89
98
performance . mark ( `${ plugin . name } :createNodes - end` ) ;
90
99
performance . measure (
91
100
`${ plugin . name } :createNodes` ,
92
101
`${ plugin . name } :createNodes - start` ,
93
102
`${ plugin . name } :createNodes - end`
94
103
) ;
95
- return results ;
96
104
} ) ;
97
105
98
- const [ errors , successful ] = partition <
99
- CreateNodesError ,
100
- CreateNodesResultWithContext
101
- > ( results , ( r ) : r is CreateNodesError => r instanceof CreateNodesError ) ;
102
-
103
106
if ( errors . length > 0 ) {
104
- throw new AggregateCreateNodesError ( plugin . name , errors , successful ) ;
107
+ throw new AggregateCreateNodesError ( plugin . name , errors , results ) ;
105
108
}
106
109
return results ;
107
110
}
108
-
109
- function partition < T , T2 = T > (
110
- arr : Array < T | T2 > ,
111
- test : ( item : T | T2 ) => item is T
112
- ) : [ T [ ] , T2 [ ] ] {
113
- const pass : T [ ] = [ ] ;
114
- const fail : T2 [ ] = [ ] ;
115
- for ( const item of arr ) {
116
- if ( test ( item ) ) {
117
- pass . push ( item ) ;
118
- } else {
119
- fail . push ( item as any as T2 ) ;
120
- }
121
- }
122
- return [ pass , fail ] ;
123
- }
0 commit comments