diff --git a/packages/linter/src/executors/eslint/hasher.ts b/packages/linter/src/executors/eslint/hasher.ts index 8b6f7b2cc6ca0f..996fb21e9ece22 100644 --- a/packages/linter/src/executors/eslint/hasher.ts +++ b/packages/linter/src/executors/eslint/hasher.ts @@ -1,4 +1,4 @@ -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'; @@ -6,14 +6,15 @@ import { Workspaces } from '@nrwl/tao/src/shared/workspace'; export default async function run( task: Task, taskGraph: TaskGraph, - hasher: Hasher + hasher: Hasher, + projectGraph: ProjectGraph ): Promise { if (task.overrides['hasTypeAwareRules'] === true) { return hasher.hashTaskWithDepsAndContext(task); } const command = hasher.hashCommand(task); const sources = await hasher.hashSource(task); - const deps = allDeps(task.id, taskGraph); + const deps = allDeps(task.id, taskGraph, projectGraph); const workspace = new Workspaces(appRootPath).readWorkspaceConfiguration(); const tags = hasher.hashArray( deps.map((d) => (workspace.projects[d].tags || []).join('|')) @@ -36,13 +37,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; } diff --git a/packages/workspace/src/tasks-runner/task-orchestrator.ts b/packages/workspace/src/tasks-runner/task-orchestrator.ts index 24ea9c2d7183b6..fd0f33dea81f65 100644 --- a/packages/workspace/src/tasks-runner/task-orchestrator.ts +++ b/packages/workspace/src/tasks-runner/task-orchestrator.ts @@ -26,7 +26,8 @@ export class TaskOrchestrator { this.hasher, this.taskGraph, this.workspace, - this.options + this.options, + this.projectGraph ); // region internal state diff --git a/packages/workspace/src/tasks-runner/tasks-schedule.spec.ts b/packages/workspace/src/tasks-runner/tasks-schedule.spec.ts index dc56bd193b7391..b3224e721b6e1e 100644 --- a/packages/workspace/src/tasks-runner/tasks-schedule.spec.ts +++ b/packages/workspace/src/tasks-runner/tasks-schedule.spec.ts @@ -1,5 +1,5 @@ import { TasksSchedule } from './tasks-schedule'; -import { Task, TaskGraph } from '@nrwl/devkit'; +import { ProjectGraph, Task, TaskGraph } from '@nrwl/devkit'; import { Workspaces } from '@nrwl/tao/src/shared/workspace'; import { removeTasksFromTaskGraph } from '@nrwl/workspace/src/tasks-runner/utils'; @@ -82,6 +82,11 @@ describe('TasksSchedule', () => { }, }; + const projectGraph: ProjectGraph = { + nodes: {}, + dependencies: {}, + }; + const hasher = { hashTaskWithDepsAndContext: () => 'hash', } as any; @@ -96,7 +101,8 @@ describe('TasksSchedule', () => { endTask: jest.fn(), scheduleTask: jest.fn(), }, - } + }, + projectGraph ); }); diff --git a/packages/workspace/src/tasks-runner/tasks-schedule.ts b/packages/workspace/src/tasks-runner/tasks-schedule.ts index bd1ef2c96ded09..22e1f765522f40 100644 --- a/packages/workspace/src/tasks-runner/tasks-schedule.ts +++ b/packages/workspace/src/tasks-runner/tasks-schedule.ts @@ -1,4 +1,4 @@ -import { Task, TaskGraph } from '@nrwl/devkit'; +import { ProjectGraph, Task, TaskGraph } from '@nrwl/devkit'; import { Workspaces } from '@nrwl/tao/src/shared/workspace'; @@ -31,7 +31,8 @@ export class TasksSchedule { private readonly hasher: Hasher, private taskGraph: TaskGraph, private workspace: Workspaces, - private options: DefaultTasksRunnerOptions + private options: DefaultTasksRunnerOptions, + private readonly projectGraph: ProjectGraph ) {} public async scheduleNextTasks() { @@ -163,7 +164,7 @@ export class TasksSchedule { private async hashTask(task: Task) { const customHasher = getCustomHasher(task, this.workspace); const { value, details } = await (customHasher - ? customHasher(task, this.taskGraph, this.hasher) + ? customHasher(task, this.taskGraph, this.hasher, this.projectGraph) : this.hasher.hashTaskWithDepsAndContext(task)); task.hash = value; task.hashDetails = details;