From 1670986b820776d818a152e2b425d15264edb7ee Mon Sep 17 00:00:00 2001 From: Victor Savkin Date: Wed, 17 May 2023 15:23:26 -0400 Subject: [PATCH] fix(core): fix projectFileMap access in plugins --- .../nx/src/project-graph/build-project-graph.ts | 13 +++++-------- .../nx/src/project-graph/project-graph-builder.ts | 2 +- packages/nx/src/tasks-runner/run-command.ts | 3 +-- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/packages/nx/src/project-graph/build-project-graph.ts b/packages/nx/src/project-graph/build-project-graph.ts index 3aa8e938333d0..50c464fe6899e 100644 --- a/packages/nx/src/project-graph/build-project-graph.ts +++ b/packages/nx/src/project-graph/build-project-graph.ts @@ -30,15 +30,14 @@ import { readNxJson } from '../config/configuration'; import { existsSync } from 'fs'; import { PackageJson } from '../utils/package-json'; -let storedProjectGraph: ProjectGraph | null = null; let storedProjectFileMap: ProjectFileMap | null = null; let storedAllWorkspaceFiles: FileData[] | null = null; -export function getProjectFileMap(projectGraph: ProjectGraph): { +export function getProjectFileMap(): { projectFileMap: ProjectFileMap; allWorkspaceFiles: FileData[]; } { - if (projectGraph === storedProjectGraph) { + if (!!storedProjectFileMap) { return { projectFileMap: storedProjectFileMap, allWorkspaceFiles: storedAllWorkspaceFiles, @@ -58,6 +57,9 @@ export async function buildProjectGraphUsingProjectFileMap( projectGraph: ProjectGraph; projectFileMapCache: ProjectFileMapCache; }> { + storedProjectFileMap = projectFileMap; + storedAllWorkspaceFiles = allWorkspaceFiles; + const nxJson = readNxJson(); const projectGraphVersion = '6.0'; assertWorkspaceValidity(projectsConfigurations, nxJson); @@ -106,11 +108,6 @@ export async function buildProjectGraphUsingProjectFileMap( if (shouldWriteCache) { writeCache(projectFileMapCache, projectGraph); } - - storedProjectGraph = projectGraph; - storedProjectFileMap = projectFileMap; - storedAllWorkspaceFiles = allWorkspaceFiles; - return { projectGraph, projectFileMapCache, diff --git a/packages/nx/src/project-graph/project-graph-builder.ts b/packages/nx/src/project-graph/project-graph-builder.ts index 0c44c4f7a4b96..b3bb281a86d09 100644 --- a/packages/nx/src/project-graph/project-graph-builder.ts +++ b/packages/nx/src/project-graph/project-graph-builder.ts @@ -22,7 +22,7 @@ export class ProjectGraphBuilder { constructor(g?: ProjectGraph, fileMap?: ProjectFileMap) { if (g) { this.graph = g; - this.fileMap = fileMap || getProjectFileMap(g).projectFileMap; + this.fileMap = fileMap || getProjectFileMap().projectFileMap; } else { this.graph = { nodes: {}, diff --git a/packages/nx/src/tasks-runner/run-command.ts b/packages/nx/src/tasks-runner/run-command.ts index 7b3139e869b3b..ea61e8d6426b9 100644 --- a/packages/nx/src/tasks-runner/run-command.ts +++ b/packages/nx/src/tasks-runner/run-command.ts @@ -236,8 +236,7 @@ export async function invokeTasksRunner({ if (daemonClient.enabled()) { hasher = new DaemonBasedTaskHasher(daemonClient, runnerOptions); } else { - const { projectFileMap, allWorkspaceFiles } = - getProjectFileMap(projectGraph); + const { projectFileMap, allWorkspaceFiles } = getProjectFileMap(); hasher = new InProcessTaskHasher( projectFileMap, allWorkspaceFiles,