diff --git a/packages/nx/src/project-graph/build-project-graph.ts b/packages/nx/src/project-graph/build-project-graph.ts index 0ef18c56050a7c..8cd52231b01645 100644 --- a/packages/nx/src/project-graph/build-project-graph.ts +++ b/packages/nx/src/project-graph/build-project-graph.ts @@ -72,6 +72,16 @@ export function getFileMap(): { } } +export function hydrateFileMap( + fileMap: FileMap, + allWorkspaceFiles: FileData[], + rustReferences: NxWorkspaceFilesExternals +) { + storedFileMap = fileMap; + storedAllWorkspaceFiles = allWorkspaceFiles; + storedRustReferences = rustReferences; +} + export async function buildProjectGraphUsingProjectFileMap( projectRootMap: Record, externalNodes: Record, diff --git a/packages/nx/src/project-graph/project-graph.ts b/packages/nx/src/project-graph/project-graph.ts index 06fce0155621c5..ff13ea9790f757 100644 --- a/packages/nx/src/project-graph/project-graph.ts +++ b/packages/nx/src/project-graph/project-graph.ts @@ -12,7 +12,10 @@ import { fileExists } from '../utils/fileutils'; import { output } from '../utils/output'; import { stripIndents } from '../utils/strip-indents'; import { workspaceRoot } from '../utils/workspace-root'; -import { buildProjectGraphUsingProjectFileMap } from './build-project-graph'; +import { + buildProjectGraphUsingProjectFileMap, + hydrateFileMap, +} from './build-project-graph'; import { AggregateProjectGraphError, isAggregateProjectGraphError, @@ -30,6 +33,7 @@ import { retrieveProjectConfigurations, retrieveWorkspaceFiles, } from './utils/retrieve-workspace-files'; +import { createProjectRootMappings } from './utils/find-project-for-path'; /** * Synchronously reads the latest cached copy of the workspace's ProjectGraph. @@ -239,7 +243,16 @@ export async function createProjectGraphAsync( ): Promise { if (process.env.NX_FORCE_REUSE_CACHED_GRAPH === 'true') { try { - return readCachedProjectGraph(); + const graph = readCachedProjectGraph(); + const projectRootMap = Object.fromEntries( + Object.entries(graph.nodes).map(([project, { data }]) => [ + data.root, + project, + ]) + ); + const { allWorkspaceFiles, fileMap, rustReferences } = + await retrieveWorkspaceFiles(workspaceRoot, projectRootMap); + hydrateFileMap(fileMap, allWorkspaceFiles, rustReferences); // If no cached graph is found, we will fall through to the normal flow } catch {} }