From 5c24e599d7d6804ead6b79690a98ba691ca90a1a Mon Sep 17 00:00:00 2001 From: Craigory Coppola Date: Wed, 28 Feb 2024 11:38:38 -0500 Subject: [PATCH] fix(misc): migration should shutdown plugin workers if it starts them --- packages/nx/src/config/workspaces.spec.ts | 18 +----------------- .../project-graph-incremental-recomputation.ts | 5 ++++- .../update-15-1-0/set-project-names.ts | 2 ++ .../src/project-graph/build-project-graph.ts | 5 ----- packages/nx/src/project-graph/project-graph.ts | 3 ++- .../utils/project-configuration-utils.ts | 2 -- .../utils/retrieve-workspace-files.ts | 12 ++++++++++-- 7 files changed, 19 insertions(+), 28 deletions(-) diff --git a/packages/nx/src/config/workspaces.spec.ts b/packages/nx/src/config/workspaces.spec.ts index 95b2a2d636750..9e229bb6fb5e0 100644 --- a/packages/nx/src/config/workspaces.spec.ts +++ b/packages/nx/src/config/workspaces.spec.ts @@ -1,24 +1,10 @@ -import { toProjectName, Workspaces } from './workspaces'; +import { toProjectName } from './workspaces'; import { TempFs } from '../internal-testing-utils/temp-fs'; import { withEnvironmentVariables } from '../internal-testing-utils/with-environment'; import { retrieveProjectConfigurations } from '../project-graph/utils/retrieve-workspace-files'; import { readNxJson } from './configuration'; import { shutdownPluginWorkers } from '../project-graph/plugins/plugin-pool'; -const libConfig = (root, name?: string) => ({ - name: name ?? toProjectName(`${root}/some-file`), - projectType: 'library', - root: `libs/${root}`, - sourceRoot: `libs/${root}/src`, - targets: { - 'nx-release-publish': { - dependsOn: ['^nx-release-publish'], - executor: '@nx/js:release-publish', - options: {}, - }, - }, -}); - describe('Workspaces', () => { let fs: TempFs; beforeEach(() => { @@ -53,7 +39,6 @@ describe('Workspaces', () => { }, () => retrieveProjectConfigurations(fs.tempDir, readNxJson(fs.tempDir)) ); - await shutdownPluginWorkers(); expect(projects['my-package']).toEqual({ name: 'my-package', root: 'packages/my-package', @@ -67,7 +52,6 @@ describe('Workspaces', () => { }, }, }); - await shutdownPluginWorkers(); }); }); }); diff --git a/packages/nx/src/daemon/server/project-graph-incremental-recomputation.ts b/packages/nx/src/daemon/server/project-graph-incremental-recomputation.ts index 7610d4d4f03a8..05c59fa50b04b 100644 --- a/packages/nx/src/daemon/server/project-graph-incremental-recomputation.ts +++ b/packages/nx/src/daemon/server/project-graph-incremental-recomputation.ts @@ -217,6 +217,7 @@ async function processFilesAndCreateAndSerializeProjectGraph(): Promise f.endsWith('project.json')); for (let f of projectJsons) { diff --git a/packages/nx/src/project-graph/build-project-graph.ts b/packages/nx/src/project-graph/build-project-graph.ts index 865c2c841b015..f0a985ec8c313 100644 --- a/packages/nx/src/project-graph/build-project-graph.ts +++ b/packages/nx/src/project-graph/build-project-graph.ts @@ -300,9 +300,6 @@ async function updateProjectGraphWithPlugins( createDependencyPlugins.map(async (plugin) => { performance.mark(`${plugin.name}:createDependencies - start`); - // Set this globally to allow plugins to know if they are being called from the project graph creation - global.NX_GRAPH_CREATION = true; - try { // TODO: we shouldn't have to pass null here const dependencies = await plugin.createDependencies(null, { @@ -326,8 +323,6 @@ async function updateProjectGraphWithPlugins( throw new Error(message); } - delete global.NX_GRAPH_CREATION; - performance.mark(`${plugin.name}:createDependencies - end`); performance.measure( `${plugin.name}:createDependencies`, diff --git a/packages/nx/src/project-graph/project-graph.ts b/packages/nx/src/project-graph/project-graph.ts index 134c155682fa9..ff2c0eac8ccad 100644 --- a/packages/nx/src/project-graph/project-graph.ts +++ b/packages/nx/src/project-graph/project-graph.ts @@ -77,6 +77,7 @@ export function readProjectsConfigurationFromProjectGraph( } export async function buildProjectGraphAndSourceMapsWithoutDaemon() { + global.NX_GRAPH_CREATION = true; const nxJson = readNxJson(); performance.mark('retrieve-project-configurations:start'); @@ -103,7 +104,7 @@ export async function buildProjectGraphAndSourceMapsWithoutDaemon() { ) ).projectGraph; performance.mark('build-project-graph-using-project-file-map:end'); - + delete global.NX_GRAPH_CREATION; return { projectGraph, sourceMaps }; } diff --git a/packages/nx/src/project-graph/utils/project-configuration-utils.ts b/packages/nx/src/project-graph/utils/project-configuration-utils.ts index 4f202d43d7879..d4562f265e32e 100644 --- a/packages/nx/src/project-graph/utils/project-configuration-utils.ts +++ b/packages/nx/src/project-graph/utils/project-configuration-utils.ts @@ -218,8 +218,6 @@ export function buildProjectsConfigurationsFromProjectPathsAndPlugins( const matchedFiles = []; performance.mark(`${plugin.name}:createNodes - start`); - // Set this globally to allow plugins to know if they are being called from the project graph creation - global.NX_GRAPH_CREATION = true; for (const file of projectFiles) { if (minimatch(file, pattern, { dot: true })) { diff --git a/packages/nx/src/project-graph/utils/retrieve-workspace-files.ts b/packages/nx/src/project-graph/utils/retrieve-workspace-files.ts index d07fb705d7802..34061f6173ad2 100644 --- a/packages/nx/src/project-graph/utils/retrieve-workspace-files.ts +++ b/packages/nx/src/project-graph/utils/retrieve-workspace-files.ts @@ -17,6 +17,7 @@ import { } from '../../utils/workspace-context'; import { buildAllWorkspaceFiles } from './build-all-workspace-files'; import { join } from 'path'; +import { shutdownPluginWorkers } from '../plugins/plugin-pool'; /** * Walks the workspace directory to create the `projectFileMap`, `ProjectConfigurations` and `allWorkspaceFiles` @@ -68,8 +69,15 @@ export async function retrieveProjectConfigurations( nxJson: NxJsonConfiguration ): Promise { const plugins = await loadNxPlugins(nxJson?.plugins ?? [], workspaceRoot); - - return _retrieveProjectConfigurations(workspaceRoot, nxJson, plugins); + const projects = await _retrieveProjectConfigurations( + workspaceRoot, + nxJson, + plugins + ); + if (!global.NX_GRAPH_CREATION) { + await shutdownPluginWorkers(); + } + return projects; } export async function retrieveProjectConfigurationsWithAngularProjects(