@@ -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}
@@ -111,6 +101,8 @@ export async function getOnlyDefaultPlugins(root = workspaceRoot) {
111101export function cleanupPlugins ( ) {
112102 cleanupSpecifiedPlugins ?.( ) ;
113103 cleanupDefaultPlugins ?.( ) ;
104+ pendingPluginsPromise = undefined ;
105+ pendingDefaultPluginPromise = undefined ;
114106}
115107
116108/**
@@ -164,55 +156,62 @@ async function loadDefaultNxPlugins(root = workspaceRoot) {
164156}
165157
166158async function loadSpecifiedNxPlugins (
167- plugins : PluginConfiguration [ ] ,
159+ pluginsConfigurations : PluginConfiguration [ ] ,
168160 root = workspaceRoot
169- ) : Promise < readonly [ LoadedNxPlugin [ ] , ( ) => void ] > {
161+ ) : Promise < LoadedNxPlugin [ ] > {
162+ // Returning existing plugins is handled by getPlugins,
163+ // so, if we are here and there are existing plugins, they are stale
164+ if ( cleanupSpecifiedPlugins ) {
165+ cleanupSpecifiedPlugins ( ) ;
166+ }
167+
170168 performance . mark ( 'loadSpecifiedNxPlugins:start' ) ;
171169
172- plugins ??= [ ] ;
170+ pluginsConfigurations ??= [ ] ;
173171
174172 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 ;
173+ const plugins = await Promise . all (
174+ pluginsConfigurations . map ( async ( plugin , index ) => {
175+ const pluginPath = typeof plugin === 'string' ? plugin : plugin . plugin ;
176+ performance . mark ( `Load Nx Plugin: ${ pluginPath } - start` ) ;
177+
178+ const [ loadedPluginPromise , cleanup ] = await loadingMethod (
179+ plugin ,
180+ root ,
181+ index
182+ ) ;
183+
184+ cleanupFunctions . push ( cleanup ) ;
185+ const res = await loadedPluginPromise ;
186+ res . index = index ;
187+ performance . mark ( `Load Nx Plugin: ${ pluginPath } - end` ) ;
188+ performance . measure (
189+ `Load Nx Plugin: ${ pluginPath } ` ,
190+ `Load Nx Plugin: ${ pluginPath } - start` ,
191+ `Load Nx Plugin: ${ pluginPath } - end`
192+ ) ;
193+
194+ return res ;
195+ } )
196+ ) ;
209197 performance . mark ( 'loadSpecifiedNxPlugins:end' ) ;
210198 performance . measure (
211199 'loadSpecifiedNxPlugins' ,
212200 'loadSpecifiedNxPlugins:start' ,
213201 'loadSpecifiedNxPlugins:end'
214202 ) ;
215- return ret ;
203+
204+ cleanupSpecifiedPlugins = ( ) => {
205+ for ( const fn of cleanupFunctions ) {
206+ fn ( ) ;
207+ }
208+ if ( pluginTranspilerIsRegistered ( ) ) {
209+ cleanupPluginTSTranspiler ( ) ;
210+ }
211+ pendingPluginsPromise = undefined ;
212+ } ;
213+
214+ return plugins ;
216215}
217216
218217function getDefaultPlugins ( root : string ) {
0 commit comments