From 8cede1f1b87e9da2d958cd12b7fb132cc03eed73 Mon Sep 17 00:00:00 2001 From: arturovt Date: Wed, 30 Aug 2023 12:52:20 +0300 Subject: [PATCH] fix(core): prepare Angular specific error only before throwing it This commit updates the implementation of the `readCachedProjectGraph` function and checks whether the `angular.json` file exists only when it's required, throwing the error afterward. This removes the redundant call to `statSync` if we encounter a cached graph. --- packages/nx/src/project-graph/project-graph.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/nx/src/project-graph/project-graph.ts b/packages/nx/src/project-graph/project-graph.ts index 7004f15d023a4..18286cecd05ab 100644 --- a/packages/nx/src/project-graph/project-graph.ts +++ b/packages/nx/src/project-graph/project-graph.ts @@ -24,14 +24,15 @@ import { readNxJson } from '../config/nx-json'; */ export function readCachedProjectGraph(): ProjectGraph { const projectGraphCache: ProjectGraph = readProjectGraphCache(); - const angularSpecificError = fileExists(`${workspaceRoot}/angular.json`) - ? stripIndents` + if (!projectGraphCache) { + const angularSpecificError = fileExists(`${workspaceRoot}/angular.json`) + ? stripIndents` Make sure invoke 'node ./decorate-angular-cli.js' in your postinstall script. The decorated CLI will compute the project graph. 'ng --help' should say 'Smart, Fast and Extensible Build System'. ` - : ''; - if (!projectGraphCache) { + : ''; + throw new Error(stripIndents` [readCachedProjectGraph] ERROR: No cached ProjectGraph is available.