@@ -47,14 +47,35 @@ export async function getPlugins(
4747 }
4848
4949 currentPluginsConfigurationHash = pluginsConfigurationHash ;
50- const [ defaultPlugins , specifiedPlugins ] = await Promise . all ( [
50+ const results = await Promise . allSettled ( [
5151 getOnlyDefaultPlugins ( root ) ,
5252 ( pendingPluginsPromise ??= loadSpecifiedNxPlugins (
5353 pluginsConfiguration ,
5454 root
5555 ) ) ,
5656 ] ) ;
5757
58+ const errors : Error [ ] = [ ] ;
59+ const defaultPlugins : LoadedNxPlugin [ ] = [ ] ;
60+ const specifiedPlugins : LoadedNxPlugin [ ] = [ ] ;
61+
62+ for ( let i = 0 ; i < results . length ; i ++ ) {
63+ const result = results [ i ] ;
64+ if ( result . status === 'fulfilled' ) {
65+ ( i === 0 ? defaultPlugins : specifiedPlugins ) . push ( ...result . value ) ;
66+ } else {
67+ errors . push (
68+ result . reason instanceof Error
69+ ? result . reason
70+ : new Error ( String ( result . reason ) )
71+ ) ;
72+ }
73+ }
74+
75+ if ( errors . length > 0 ) {
76+ throw new AggregateError ( errors , errors . map ( ( e ) => e . message ) . join ( '\n' ) ) ;
77+ }
78+
5879 loadedPlugins = specifiedPlugins . concat ( defaultPlugins ) ;
5980
6081 return loadedPlugins ;
@@ -115,28 +136,58 @@ async function loadDefaultNxPlugins(root = workspaceRoot) {
115136 const plugins = getDefaultPlugins ( root ) ;
116137
117138 const cleanupFunctions : Array < ( ) => void > = [ ] ;
139+ const results = await Promise . allSettled (
140+ plugins . map ( async ( plugin ) => {
141+ performance . mark ( `Load Nx Plugin: ${ plugin } - start` ) ;
142+
143+ const [ loadedPluginPromise , cleanup ] = await loadingMethod ( plugin , root ) ;
144+
145+ cleanupFunctions . push ( cleanup ) ;
146+ const res = await loadedPluginPromise ;
147+ performance . mark ( `Load Nx Plugin: ${ plugin } - end` ) ;
148+ performance . measure (
149+ `Load Nx Plugin: ${ plugin } ` ,
150+ `Load Nx Plugin: ${ plugin } - start` ,
151+ `Load Nx Plugin: ${ plugin } - end`
152+ ) ;
153+
154+ return res ;
155+ } )
156+ ) ;
157+
158+ const defaultPluginResults : LoadedNxPlugin [ ] = [ ] ;
159+ const errors : Array < { pluginName : string ; error : Error } > = [ ] ;
160+
161+ for ( let i = 0 ; i < results . length ; i ++ ) {
162+ const result = results [ i ] ;
163+ if ( result . status === 'fulfilled' ) {
164+ defaultPluginResults . push ( result . value ) ;
165+ } else {
166+ errors . push ( {
167+ pluginName : plugins [ i ] ,
168+ error :
169+ result . reason instanceof Error
170+ ? result . reason
171+ : new Error ( String ( result . reason ) ) ,
172+ } ) ;
173+ }
174+ }
175+
176+ if ( errors . length > 0 ) {
177+ for ( const fn of cleanupFunctions ) {
178+ fn ( ) ;
179+ }
180+ const errorMessage = errors
181+ . map ( ( e ) => ` - ${ e . pluginName } : ${ e . error . message } ` )
182+ . join ( '\n' ) ;
183+ throw new AggregateError (
184+ errors . map ( ( e ) => e . error ) ,
185+ `Failed to load ${ errors . length } default Nx plugin(s):\n${ errorMessage } `
186+ ) ;
187+ }
188+
118189 const ret = [
119- await Promise . all (
120- plugins . map ( async ( plugin ) => {
121- performance . mark ( `Load Nx Plugin: ${ plugin } - start` ) ;
122-
123- const [ loadedPluginPromise , cleanup ] = await loadingMethod (
124- plugin ,
125- root
126- ) ;
127-
128- cleanupFunctions . push ( cleanup ) ;
129- const res = await loadedPluginPromise ;
130- performance . mark ( `Load Nx Plugin: ${ plugin } - end` ) ;
131- performance . measure (
132- `Load Nx Plugin: ${ plugin } ` ,
133- `Load Nx Plugin: ${ plugin } - start` ,
134- `Load Nx Plugin: ${ plugin } - end`
135- ) ;
136-
137- return res ;
138- } )
139- ) ,
190+ defaultPluginResults ,
140191 ( ) => {
141192 for ( const fn of cleanupFunctions ) {
142193 fn ( ) ;
@@ -170,7 +221,7 @@ async function loadSpecifiedNxPlugins(
170221 pluginsConfigurations ??= [ ] ;
171222
172223 const cleanupFunctions : Array < ( ) => void > = [ ] ;
173- const plugins = await Promise . all (
224+ const results = await Promise . allSettled (
174225 pluginsConfigurations . map ( async ( plugin , index ) => {
175226 const pluginPath = typeof plugin === 'string' ? plugin : plugin . plugin ;
176227 performance . mark ( `Load Nx Plugin: ${ pluginPath } - start` ) ;
@@ -201,6 +252,40 @@ async function loadSpecifiedNxPlugins(
201252 'loadSpecifiedNxPlugins:end'
202253 ) ;
203254
255+ const plugins : LoadedNxPlugin [ ] = [ ] ;
256+ const errors : Array < { pluginName : string ; error : Error } > = [ ] ;
257+
258+ for ( let i = 0 ; i < results . length ; i ++ ) {
259+ const result = results [ i ] ;
260+ if ( result . status === 'fulfilled' ) {
261+ plugins . push ( result . value ) ;
262+ } else {
263+ const pluginConfig = pluginsConfigurations [ i ] ;
264+ const pluginName =
265+ typeof pluginConfig === 'string' ? pluginConfig : pluginConfig . plugin ;
266+ errors . push ( {
267+ pluginName,
268+ error :
269+ result . reason instanceof Error
270+ ? result . reason
271+ : new Error ( String ( result . reason ) ) ,
272+ } ) ;
273+ }
274+ }
275+
276+ if ( errors . length > 0 ) {
277+ for ( const fn of cleanupFunctions ) {
278+ fn ( ) ;
279+ }
280+ const errorMessage = errors
281+ . map ( ( e ) => ` - ${ e . pluginName } : ${ e . error . message } ` )
282+ . join ( '\n' ) ;
283+ throw new AggregateError (
284+ errors . map ( ( e ) => e . error ) ,
285+ `Failed to load ${ errors . length } Nx plugin(s):\n${ errorMessage } `
286+ ) ;
287+ }
288+
204289 cleanupSpecifiedPlugins = ( ) => {
205290 for ( const fn of cleanupFunctions ) {
206291 fn ( ) ;
0 commit comments