From e575c49c3ec3fa85f2a29ca8feccd5e92f92d0a4 Mon Sep 17 00:00:00 2001 From: Craigory Coppola Date: Fri, 17 Feb 2023 16:17:03 -0500 Subject: [PATCH] fix(core): nx plugin cache should load new plugins (#15072) --- packages/nx/src/utils/nx-plugin.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/packages/nx/src/utils/nx-plugin.ts b/packages/nx/src/utils/nx-plugin.ts index a1266d54fde04..d3de42ca7c70f 100644 --- a/packages/nx/src/utils/nx-plugin.ts +++ b/packages/nx/src/utils/nx-plugin.ts @@ -47,7 +47,7 @@ export interface NxPlugin { // holding resolved nx plugin objects. // Allows loadNxPlugins to be called multiple times w/o // executing resolution mulitple times. -let nxPluginCache: NxPlugin[] = null; +let nxPluginCache: Map = new Map(); function loadNxPlugin(moduleName: string, paths: string[], root: string) { let pluginPath: string; @@ -98,13 +98,16 @@ export function loadNxPlugins( result.push(jsPlugin as NxPlugin); plugins ??= []; - if (!nxPluginCache) { - nxPluginCache = plugins.map((moduleName) => - loadNxPlugin(moduleName, paths, root) - ); + for (const plugin of plugins) { + let pluginModule = nxPluginCache.get(plugin); + if (!pluginModule) { + pluginModule = loadNxPlugin(plugin, paths, root); + nxPluginCache.set(plugin, pluginModule); + } + result.push(pluginModule); } - return result.concat(nxPluginCache); + return result; } export function mergePluginTargetsWithNxTargets(