@@ -20,9 +20,7 @@ import { isIsolationEnabled } from './isolation/enabled';
2020 */
2121let currentPluginsConfigurationHash : string ;
2222let loadedPlugins : LoadedNxPlugin [ ] ;
23- let pendingPluginsPromise :
24- | Promise < readonly [ LoadedNxPlugin [ ] , ( ) => void ] >
25- | undefined ;
23+ let pendingPluginsPromise : Promise < LoadedNxPlugin [ ] > | undefined ;
2624let cleanupSpecifiedPlugins : ( ) => void | undefined ;
2725
2826const loadingMethod = (
@@ -48,24 +46,16 @@ export async function getPlugins(
4846 return loadedPlugins ;
4947 }
5048
51- // Cleanup current plugins before loading new ones
52- cleanupSpecifiedPlugins ?.( ) ;
53-
54- pendingPluginsPromise ??= loadSpecifiedNxPlugins ( pluginsConfiguration , root ) ;
55-
5649 currentPluginsConfigurationHash = pluginsConfigurationHash ;
57- const [ [ result , cleanupFn ] , defaultPlugins ] = await Promise . all ( [
58- pendingPluginsPromise ,
50+ const [ defaultPlugins , specifiedPlugins ] = await Promise . all ( [
5951 getOnlyDefaultPlugins ( root ) ,
52+ ( pendingPluginsPromise ??= loadSpecifiedNxPlugins (
53+ pluginsConfiguration ,
54+ root
55+ ) ) ,
6056 ] ) ;
6157
62- cleanupSpecifiedPlugins = ( ) => {
63- loadedPlugins = undefined ;
64- pendingPluginsPromise = undefined ;
65- cleanupFn ( ) ;
66- } ;
67-
68- loadedPlugins = result . concat ( defaultPlugins ) ;
58+ loadedPlugins = specifiedPlugins . concat ( defaultPlugins ) ;
6959
7060 return loadedPlugins ;
7161}
@@ -164,55 +154,61 @@ async function loadDefaultNxPlugins(root = workspaceRoot) {
164154}
165155
166156async function loadSpecifiedNxPlugins (
167- plugins : PluginConfiguration [ ] ,
157+ pluginsConfigurations : PluginConfiguration [ ] ,
168158 root = workspaceRoot
169- ) : Promise < readonly [ LoadedNxPlugin [ ] , ( ) => void ] > {
159+ ) : Promise < LoadedNxPlugin [ ] > {
160+ // Returning existing plugins is handled by getPlugins,
161+ // so, if we are here and there are existing plugins, they are stale
162+ if ( cleanupSpecifiedPlugins ) {
163+ cleanupSpecifiedPlugins ( ) ;
164+ }
165+
170166 performance . mark ( 'loadSpecifiedNxPlugins:start' ) ;
171167
172- plugins ??= [ ] ;
168+ pluginsConfigurations ??= [ ] ;
173169
174170 const cleanupFunctions : Array < ( ) => void > = [ ] ;
175- const ret = [
176- await Promise . all (
177- plugins . map ( async ( plugin , index ) => {
178- const pluginPath = typeof plugin === 'string' ? plugin : plugin . plugin ;
179- performance . mark ( `Load Nx Plugin: ${ pluginPath } - start` ) ;
180-
181- const [ loadedPluginPromise , cleanup ] = await loadingMethod (
182- plugin ,
183- root ,
184- index
185- ) ;
186-
187- cleanupFunctions . push ( cleanup ) ;
188- const res = await loadedPluginPromise ;
189- res . index = index ;
190- performance . mark ( `Load Nx Plugin: ${ pluginPath } - end` ) ;
191- performance . measure (
192- `Load Nx Plugin: ${ pluginPath } ` ,
193- `Load Nx Plugin: ${ pluginPath } - start` ,
194- `Load Nx Plugin: ${ pluginPath } - end`
195- ) ;
196-
197- return res ;
198- } )
199- ) ,
200- ( ) => {
201- for ( const fn of cleanupFunctions ) {
202- fn ( ) ;
203- }
204- if ( pluginTranspilerIsRegistered ( ) ) {
205- cleanupPluginTSTranspiler ( ) ;
206- }
207- } ,
208- ] as const ;
171+ const plugins = await Promise . all (
172+ pluginsConfigurations . map ( async ( plugin , index ) => {
173+ const pluginPath = typeof plugin === 'string' ? plugin : plugin . plugin ;
174+ performance . mark ( `Load Nx Plugin: ${ pluginPath } - start` ) ;
175+
176+ const [ loadedPluginPromise , cleanup ] = await loadingMethod (
177+ plugin ,
178+ root ,
179+ index
180+ ) ;
181+
182+ cleanupFunctions . push ( cleanup ) ;
183+ const res = await loadedPluginPromise ;
184+ res . index = index ;
185+ performance . mark ( `Load Nx Plugin: ${ pluginPath } - end` ) ;
186+ performance . measure (
187+ `Load Nx Plugin: ${ pluginPath } ` ,
188+ `Load Nx Plugin: ${ pluginPath } - start` ,
189+ `Load Nx Plugin: ${ pluginPath } - end`
190+ ) ;
191+
192+ return res ;
193+ } )
194+ ) ;
209195 performance . mark ( 'loadSpecifiedNxPlugins:end' ) ;
210196 performance . measure (
211197 'loadSpecifiedNxPlugins' ,
212198 'loadSpecifiedNxPlugins:start' ,
213199 'loadSpecifiedNxPlugins:end'
214200 ) ;
215- return ret ;
201+
202+ cleanupSpecifiedPlugins = ( ) => {
203+ for ( const fn of cleanupFunctions ) {
204+ fn ( ) ;
205+ }
206+ if ( pluginTranspilerIsRegistered ( ) ) {
207+ cleanupPluginTSTranspiler ( ) ;
208+ }
209+ } ;
210+
211+ return plugins ;
216212}
217213
218214function getDefaultPlugins ( root : string ) {
0 commit comments