From d12055f0bc2640b4b5a047743b69f37c943f8ae0 Mon Sep 17 00:00:00 2001 From: Jason Jean Date: Fri, 21 Apr 2023 15:56:00 -0400 Subject: [PATCH] fix(core): fix cache recalculation (#16468) (cherry picked from commit a10b6b129012b7a95e2929595aa7a44707f5196c) --- .../nx/src/project-graph/nx-deps-cache.spec.ts | 14 +++++--------- packages/nx/src/project-graph/nx-deps-cache.ts | 12 ++++++------ 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/packages/nx/src/project-graph/nx-deps-cache.spec.ts b/packages/nx/src/project-graph/nx-deps-cache.spec.ts index fbf14c30b150d6..7d7bfcc0a2527f 100644 --- a/packages/nx/src/project-graph/nx-deps-cache.spec.ts +++ b/packages/nx/src/project-graph/nx-deps-cache.spec.ts @@ -7,6 +7,7 @@ import { import { ProjectGraph } from '../config/project-graph'; import { WorkspaceJsonConfiguration } from '../config/workspace-json-project-json'; import { NxJsonConfiguration } from '../config/nx-json'; +import { nxVersion } from '../utils/versions'; describe('nx deps utils', () => { describe('shouldRecomputeWholeGraph', () => { @@ -34,14 +35,11 @@ describe('nx deps utils', () => { ).toEqual(true); }); - it('should be true when version of nrwl/workspace changes', () => { + it('should be true when version of nx changes', () => { expect( shouldRecomputeWholeGraph( createCache({ - deps: { - '@nrwl/workspace': '12.0.1', - plugin: '1.0.0', - }, + nxVersion: '12.0.1', }), createPackageJsonDeps({}), createWorkspaceJson({}), @@ -317,10 +315,8 @@ describe('nx deps utils', () => { function createCache(p: Partial): ProjectGraphCache { const defaults: ProjectGraphCache = { version: '5.1', - deps: { - '@nrwl/workspace': '12.0.0', - plugin: '1.0.0', - }, + nxVersion: nxVersion, + deps: {}, pathMappings: { mylib: ['libs/mylib/index.ts'], }, diff --git a/packages/nx/src/project-graph/nx-deps-cache.ts b/packages/nx/src/project-graph/nx-deps-cache.ts index 8ce7214754b34a..0490062dcd555f 100644 --- a/packages/nx/src/project-graph/nx-deps-cache.ts +++ b/packages/nx/src/project-graph/nx-deps-cache.ts @@ -19,9 +19,11 @@ import { readJsonFile, writeJsonFile, } from '../utils/fileutils'; +import { nxVersion } from '../utils/versions'; export interface ProjectGraphCache { version: string; + nxVersion: string; deps: Record; pathMappings: Record; nxJsonPlugins: { name: string; version: string }[]; @@ -93,8 +95,9 @@ export function createCache( })); const newValue: ProjectGraphCache = { version: projectGraph.version || '5.1', - deps: packageJsonDeps, - // compilerOptions may not exist, especially for repos converted through add-nx-to-monorepo + nxVersion: nxVersion, + deps: packageJsonDeps, // TODO(v18): We can remove this in favor of nxVersion + // compilerOptions may not exist, especially for package-based repos pathMappings: tsConfig?.compilerOptions?.paths || {}, nxJsonPlugins, pluginsConfig: nxJson.pluginsConfig, @@ -149,10 +152,7 @@ export function shouldRecomputeWholeGraph( if (cache.version !== '5.1') { return true; } - if (cache.deps['@nrwl/workspace'] !== packageJsonDeps['@nrwl/workspace']) { - return true; - } - if (cache.deps['nx'] !== packageJsonDeps['nx']) { + if (cache.nxVersion !== nxVersion) { return true; }