fix(core): fix cache recalculation (#16468)
This commit is contained in:
parent
dbce22a499
commit
a10b6b1290
@ -7,6 +7,7 @@ import {
|
|||||||
import { ProjectGraph } from '../config/project-graph';
|
import { ProjectGraph } from '../config/project-graph';
|
||||||
import { ProjectsConfigurations } from '../config/workspace-json-project-json';
|
import { ProjectsConfigurations } from '../config/workspace-json-project-json';
|
||||||
import { NxJsonConfiguration } from '../config/nx-json';
|
import { NxJsonConfiguration } from '../config/nx-json';
|
||||||
|
import { nxVersion } from '../utils/versions';
|
||||||
|
|
||||||
describe('nx deps utils', () => {
|
describe('nx deps utils', () => {
|
||||||
describe('shouldRecomputeWholeGraph', () => {
|
describe('shouldRecomputeWholeGraph', () => {
|
||||||
@ -34,14 +35,11 @@ describe('nx deps utils', () => {
|
|||||||
).toEqual(true);
|
).toEqual(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be true when version of nrwl/workspace changes', () => {
|
it('should be true when version of nx changes', () => {
|
||||||
expect(
|
expect(
|
||||||
shouldRecomputeWholeGraph(
|
shouldRecomputeWholeGraph(
|
||||||
createCache({
|
createCache({
|
||||||
deps: {
|
nxVersion: '12.0.1',
|
||||||
'@nx/workspace': '12.0.1',
|
|
||||||
plugin: '1.0.0',
|
|
||||||
},
|
|
||||||
}),
|
}),
|
||||||
createPackageJsonDeps({}),
|
createPackageJsonDeps({}),
|
||||||
createProjectsConfiguration({}),
|
createProjectsConfiguration({}),
|
||||||
@ -317,10 +315,8 @@ describe('nx deps utils', () => {
|
|||||||
function createCache(p: Partial<ProjectGraphCache>): ProjectGraphCache {
|
function createCache(p: Partial<ProjectGraphCache>): ProjectGraphCache {
|
||||||
const defaults: ProjectGraphCache = {
|
const defaults: ProjectGraphCache = {
|
||||||
version: '5.1',
|
version: '5.1',
|
||||||
deps: {
|
nxVersion: nxVersion,
|
||||||
'@nx/workspace': '12.0.0',
|
deps: {},
|
||||||
plugin: '1.0.0',
|
|
||||||
},
|
|
||||||
pathMappings: {
|
pathMappings: {
|
||||||
mylib: ['libs/mylib/index.ts'],
|
mylib: ['libs/mylib/index.ts'],
|
||||||
},
|
},
|
||||||
|
|||||||
@ -19,9 +19,11 @@ import {
|
|||||||
readJsonFile,
|
readJsonFile,
|
||||||
writeJsonFile,
|
writeJsonFile,
|
||||||
} from '../utils/fileutils';
|
} from '../utils/fileutils';
|
||||||
|
import { nxVersion } from '../utils/versions';
|
||||||
|
|
||||||
export interface ProjectGraphCache {
|
export interface ProjectGraphCache {
|
||||||
version: string;
|
version: string;
|
||||||
|
nxVersion: string;
|
||||||
deps: Record<string, string>;
|
deps: Record<string, string>;
|
||||||
pathMappings: Record<string, any>;
|
pathMappings: Record<string, any>;
|
||||||
nxJsonPlugins: { name: string; version: string }[];
|
nxJsonPlugins: { name: string; version: string }[];
|
||||||
@ -93,7 +95,8 @@ export function createCache(
|
|||||||
}));
|
}));
|
||||||
const newValue: ProjectGraphCache = {
|
const newValue: ProjectGraphCache = {
|
||||||
version: projectGraph.version || '5.1',
|
version: projectGraph.version || '5.1',
|
||||||
deps: packageJsonDeps,
|
nxVersion: nxVersion,
|
||||||
|
deps: packageJsonDeps, // TODO(v18): We can remove this in favor of nxVersion
|
||||||
// compilerOptions may not exist, especially for package-based repos
|
// compilerOptions may not exist, especially for package-based repos
|
||||||
pathMappings: tsConfig?.compilerOptions?.paths || {},
|
pathMappings: tsConfig?.compilerOptions?.paths || {},
|
||||||
nxJsonPlugins,
|
nxJsonPlugins,
|
||||||
@ -149,13 +152,7 @@ export function shouldRecomputeWholeGraph(
|
|||||||
if (cache.version !== '5.1') {
|
if (cache.version !== '5.1') {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (
|
if (cache.nxVersion !== nxVersion) {
|
||||||
cache.deps['@nx/workspace'] !== packageJsonDeps['@nx/workspace'] ||
|
|
||||||
cache.deps['@nrwl/workspace'] !== packageJsonDeps['@nrwl/workspace']
|
|
||||||
) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (cache.deps['nx'] !== packageJsonDeps['nx']) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user