Skip to content

Commit

Permalink
fix(core): hydrate root map when using cached graph
Browse files Browse the repository at this point in the history
  • Loading branch information
AgentEnder committed Dec 3, 2024
1 parent d9f3ee8 commit a892a30
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
10 changes: 10 additions & 0 deletions packages/nx/src/project-graph/build-project-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, ProjectConfiguration>,
externalNodes: Record<string, ProjectGraphExternalNode>,
Expand Down
17 changes: 15 additions & 2 deletions packages/nx/src/project-graph/project-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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.
Expand Down Expand Up @@ -239,7 +243,16 @@ export async function createProjectGraphAsync(
): Promise<ProjectGraph> {
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 {}
}
Expand Down

0 comments on commit a892a30

Please sign in to comment.