From cb4cff7251855a8bc7b481636ab1e56c2bbe20ac Mon Sep 17 00:00:00 2001 From: Jason Jean Date: Mon, 24 Jun 2024 11:06:28 -0700 Subject: [PATCH] fix(core): pick up changes to plugins configuration in daemon (#26625) ## Current Behavior The previous set of plugins are reused even when the plugins configuration change (plugins are added/removed or have their options changed). ## Expected Behavior Plugins are cleaned up and reloaded when the plugins configuration change. ## Related Issue(s) Fixes # --- packages/nx/src/daemon/server/plugins.ts | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/packages/nx/src/daemon/server/plugins.ts b/packages/nx/src/daemon/server/plugins.ts index f886796ea843c..3e6da219c98a8 100644 --- a/packages/nx/src/daemon/server/plugins.ts +++ b/packages/nx/src/daemon/server/plugins.ts @@ -1,3 +1,4 @@ +import { hashObject } from '../../hasher/file-hasher'; import { readNxJson } from '../../config/nx-json'; import { LoadedNxPlugin, @@ -5,14 +6,28 @@ import { } from '../../project-graph/plugins/internal-api'; import { workspaceRoot } from '../../utils/workspace-root'; +let currentPluginsConfigurationHash: string; let loadedPlugins: LoadedNxPlugin[]; let cleanup: () => void; export async function getPlugins() { - if (loadedPlugins) { + const pluginsConfiguration = readNxJson().plugins ?? []; + const pluginsConfigurationHash = hashObject(pluginsConfiguration); + + // If the plugins configuration has not changed, reuse the current plugins + if ( + loadedPlugins && + pluginsConfigurationHash === currentPluginsConfigurationHash + ) { return loadedPlugins; } - const pluginsConfiguration = readNxJson().plugins ?? []; + + // Cleanup current plugins before loading new ones + if (cleanup) { + cleanup(); + } + + currentPluginsConfigurationHash = pluginsConfigurationHash; const [result, cleanupFn] = await loadNxPlugins( pluginsConfiguration, workspaceRoot