Skip to content

Commit

Permalink
fix(linter): use projectGraph in hasher for calculating dependencies (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
meeroslav committed Mar 8, 2022
1 parent de7aa8e commit 445cd59
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions packages/linter/src/executors/eslint/hasher.ts
@@ -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 { appRootPath } from '@nrwl/tao/src/utils/app-root';
import { Workspaces } from '@nrwl/tao/src/shared/workspace';
import { readCachedProjectGraph } from '@nrwl/workspace/src/core/project-graph';

export default async function run(
task: Task,
Expand All @@ -11,14 +12,22 @@ export default async function run(
if (task.overrides['hasTypeAwareRules'] === true) {
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 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 deps = projectGraph
? allDeps(task.id, taskGraph, projectGraph)
: Object.keys(workspace.projects);
const tags = hasher.hashArray(
// deps.map((d) => (workspace.projects[d].tags || []).join('|'))
Object.values(workspace.projects).map((proj) => (proj.tags || []).join('|'))
deps.map((d) => (workspace.projects[d].tags || []).join('|'))
);
const context = await hasher.hashContext();
return {
Expand All @@ -38,13 +47,14 @@ export default async function run(
};
}

function allDeps(taskId: string, taskGraph: TaskGraph): string[] {
return [
...taskGraph.dependencies[taskId].map(
(task) => taskGraph.tasks[task].target.project
),
...taskGraph.dependencies[taskId].flatMap((task) =>
allDeps(task, taskGraph)
),
];
function allDeps(
taskId: string,
taskGraph: TaskGraph,
projectGraph: ProjectGraph
): string[] {
const project = taskGraph.tasks[taskId].target.project;
const dependencies = projectGraph.dependencies[project]
.filter((d) => !!projectGraph.nodes[d.target])
.map((d) => d.target);
return dependencies;
}

0 comments on commit 445cd59

Please sign in to comment.