Skip to content

Commit

Permalink
fix(core): fix cache recalculation (#16468)
Browse files Browse the repository at this point in the history
(cherry picked from commit a10b6b1)
  • Loading branch information
FrozenPandaz committed Apr 24, 2023
1 parent 9168f09 commit df55630
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
14 changes: 5 additions & 9 deletions packages/nx/src/project-graph/nx-deps-cache.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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({}),
Expand Down Expand Up @@ -317,10 +315,8 @@ describe('nx deps utils', () => {
function createCache(p: Partial<ProjectGraphCache>): 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'],
},
Expand Down
12 changes: 6 additions & 6 deletions packages/nx/src/project-graph/nx-deps-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ import {
readJsonFile,
writeJsonFile,
} from '../utils/fileutils';
import { nxVersion } from '../utils/versions';

export interface ProjectGraphCache {
version: string;
nxVersion: string;
deps: Record<string, string>;
pathMappings: Record<string, any>;
nxJsonPlugins: { name: string; version: string }[];
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit df55630

Please sign in to comment.