fix(linter): ensure target project locator is using stale graph in IDE (#16534)
This commit is contained in:
parent
3d5b849826
commit
d47df3d676
@ -168,7 +168,8 @@ export default createESLintRule<Options, MessageIds>({
|
||||
);
|
||||
const fileName = normalizePath(context.getFilename());
|
||||
|
||||
const { projectGraph, projectRootMappings } = readProjectGraph(RULE_NAME);
|
||||
const { projectGraph, projectRootMappings, targetProjectLocator } =
|
||||
readProjectGraph(RULE_NAME);
|
||||
|
||||
if (!projectGraph) {
|
||||
return {};
|
||||
@ -176,15 +177,6 @@ export default createESLintRule<Options, MessageIds>({
|
||||
|
||||
const workspaceLayout = (global as any).workspaceLayout;
|
||||
|
||||
if (!(global as any).targetProjectLocator) {
|
||||
(global as any).targetProjectLocator = new TargetProjectLocator(
|
||||
projectGraph.nodes,
|
||||
projectGraph.externalNodes
|
||||
);
|
||||
}
|
||||
const targetProjectLocator = (global as any)
|
||||
.targetProjectLocator as TargetProjectLocator;
|
||||
|
||||
function run(
|
||||
node:
|
||||
| TSESTree.ImportDeclaration
|
||||
|
||||
@ -6,6 +6,7 @@ import {
|
||||
ProjectRootMappings,
|
||||
} from 'nx/src/project-graph/utils/find-project-for-path';
|
||||
import { readNxJson } from 'nx/src/project-graph/file-utils';
|
||||
import { TargetProjectLocator } from '@nx/js/src/internal';
|
||||
|
||||
export function ensureGlobalProjectGraph(ruleName: string) {
|
||||
/**
|
||||
@ -25,9 +26,14 @@ export function ensureGlobalProjectGraph(ruleName: string) {
|
||||
* the ProjectGraph may or may not exist by the time the lint rule is invoked for the first time.
|
||||
*/
|
||||
try {
|
||||
(global as any).projectGraph = readCachedProjectGraph();
|
||||
const projectGraph = readCachedProjectGraph();
|
||||
(global as any).projectGraph = projectGraph;
|
||||
(global as any).projectRootMappings = createProjectRootMappings(
|
||||
(global as any).projectGraph.nodes
|
||||
projectGraph.nodes
|
||||
);
|
||||
(global as any).targetProjectLocator = new TargetProjectLocator(
|
||||
projectGraph.nodes,
|
||||
projectGraph.externalNodes
|
||||
);
|
||||
} catch {
|
||||
const WARNING_PREFIX = `${chalk.reset.keyword('orange')('warning')}`;
|
||||
@ -43,10 +49,12 @@ export function ensureGlobalProjectGraph(ruleName: string) {
|
||||
export function readProjectGraph(ruleName: string): {
|
||||
projectGraph: ProjectGraph;
|
||||
projectRootMappings: ProjectRootMappings;
|
||||
targetProjectLocator: TargetProjectLocator;
|
||||
} {
|
||||
ensureGlobalProjectGraph(ruleName);
|
||||
return {
|
||||
projectGraph: (global as any).projectGraph,
|
||||
projectRootMappings: (global as any).projectRootMappings,
|
||||
targetProjectLocator: (global as any).targetProjectLocator,
|
||||
};
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user