fix(linter): use projectGraph in hasher for calculating dependencies (#9118)
This commit is contained in:
parent
de7aa8ed3d
commit
445cd59c70
@ -1,7 +1,8 @@
|
|||||||
import { Task, TaskGraph } from '@nrwl/devkit';
|
import { ProjectGraph, Task, TaskGraph } from '@nrwl/devkit';
|
||||||
import { Hash, Hasher } from '@nrwl/workspace/src/core/hasher/hasher';
|
import { Hash, Hasher } from '@nrwl/workspace/src/core/hasher/hasher';
|
||||||
import { appRootPath } from '@nrwl/tao/src/utils/app-root';
|
import { appRootPath } from '@nrwl/tao/src/utils/app-root';
|
||||||
import { Workspaces } from '@nrwl/tao/src/shared/workspace';
|
import { Workspaces } from '@nrwl/tao/src/shared/workspace';
|
||||||
|
import { readCachedProjectGraph } from '@nrwl/workspace/src/core/project-graph';
|
||||||
|
|
||||||
export default async function run(
|
export default async function run(
|
||||||
task: Task,
|
task: Task,
|
||||||
@ -11,14 +12,22 @@ export default async function run(
|
|||||||
if (task.overrides['hasTypeAwareRules'] === true) {
|
if (task.overrides['hasTypeAwareRules'] === true) {
|
||||||
return hasher.hashTaskWithDepsAndContext(task);
|
return hasher.hashTaskWithDepsAndContext(task);
|
||||||
}
|
}
|
||||||
|
if (!(global as any).projectGraph) {
|
||||||
|
try {
|
||||||
|
(global as any).projectGraph = readCachedProjectGraph();
|
||||||
|
} catch {
|
||||||
|
// do nothing, if project graph is unavailable we fallback to using all projects
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const projectGraph = (global as any).projectGraph;
|
||||||
const command = hasher.hashCommand(task);
|
const command = hasher.hashCommand(task);
|
||||||
const sources = await hasher.hashSource(task);
|
const sources = await hasher.hashSource(task);
|
||||||
// TODO: This will be used once we pass hasher's projectGraph
|
|
||||||
// const deps = allDeps(task.id, taskGraph);
|
|
||||||
const workspace = new Workspaces(appRootPath).readWorkspaceConfiguration();
|
const workspace = new Workspaces(appRootPath).readWorkspaceConfiguration();
|
||||||
|
const deps = projectGraph
|
||||||
|
? allDeps(task.id, taskGraph, projectGraph)
|
||||||
|
: Object.keys(workspace.projects);
|
||||||
const tags = hasher.hashArray(
|
const tags = hasher.hashArray(
|
||||||
// deps.map((d) => (workspace.projects[d].tags || []).join('|'))
|
deps.map((d) => (workspace.projects[d].tags || []).join('|'))
|
||||||
Object.values(workspace.projects).map((proj) => (proj.tags || []).join('|'))
|
|
||||||
);
|
);
|
||||||
const context = await hasher.hashContext();
|
const context = await hasher.hashContext();
|
||||||
return {
|
return {
|
||||||
@ -38,13 +47,14 @@ export default async function run(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function allDeps(taskId: string, taskGraph: TaskGraph): string[] {
|
function allDeps(
|
||||||
return [
|
taskId: string,
|
||||||
...taskGraph.dependencies[taskId].map(
|
taskGraph: TaskGraph,
|
||||||
(task) => taskGraph.tasks[task].target.project
|
projectGraph: ProjectGraph
|
||||||
),
|
): string[] {
|
||||||
...taskGraph.dependencies[taskId].flatMap((task) =>
|
const project = taskGraph.tasks[taskId].target.project;
|
||||||
allDeps(task, taskGraph)
|
const dependencies = projectGraph.dependencies[project]
|
||||||
),
|
.filter((d) => !!projectGraph.nodes[d.target])
|
||||||
];
|
.map((d) => d.target);
|
||||||
|
return dependencies;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user