diff --git a/packages/nx/src/hasher/task-hasher.ts b/packages/nx/src/hasher/task-hasher.ts index 5cf07b2c8d1964..f9edc4d139bf5f 100644 --- a/packages/nx/src/hasher/task-hasher.ts +++ b/packages/nx/src/hasher/task-hasher.ts @@ -21,6 +21,8 @@ import { workspaceRoot } from '../utils/workspace-root'; import { join, relative } from 'path'; import { normalizePath } from '../utils/path'; import { findAllProjectNodeDependencies } from '../utils/project-graph-utils'; +import { Simulate } from 'react-dom/test-utils'; +import input = Simulate.input; type ExpandedSelfInput = | { fileset: string } @@ -59,8 +61,19 @@ export interface Hash { } export interface TaskHasher { - hashTask(task: Task, taskGraph?: TaskGraph): Promise; - hashTasks(tasks: Task[], taskGraph?: TaskGraph): Promise; + /** + * @deprecated use hashTask(task:Task, taskGraph: TaskGraph) + * @param task + */ + hashTask(task: Task): Promise; + hashTask(task: Task, taskGraph: TaskGraph): Promise; + + /** + * @deprecated use hashTasks(tasks:Task[], taskGraph: TaskGraph) + * @param tasks + */ + hashTasks(tasks: Task[]): Promise; + hashTasks(tasks: Task[], taskGraph: TaskGraph): Promise; } export type Hasher = TaskHasher; @@ -71,11 +84,11 @@ export class DaemonBasedTaskHasher implements TaskHasher { private readonly runnerOptions: any ) {} - async hashTasks(tasks: Task[], taskGraph: TaskGraph): Promise { + async hashTasks(tasks: Task[], taskGraph?: TaskGraph): Promise { return this.daemonClient.hashTasks(this.runnerOptions, tasks, taskGraph); } - async hashTask(task: Task, taskGraph: TaskGraph): Promise { + async hashTask(task: Task, taskGraph?: TaskGraph): Promise { return ( await this.daemonClient.hashTasks(this.runnerOptions, [task], taskGraph) )[0]; @@ -124,11 +137,11 @@ export class InProcessTaskHasher implements TaskHasher { ); } - async hashTasks(tasks: Task[], taskGraph: TaskGraph): Promise { + async hashTasks(tasks: Task[], taskGraph?: TaskGraph): Promise { return await Promise.all(tasks.map((t) => this.hashTask(t, taskGraph))); } - async hashTask(task: Task, taskGraph: TaskGraph): Promise { + async hashTask(task: Task, taskGraph?: TaskGraph): Promise { const res = await this.taskHasher.hashTask(task, taskGraph, [ task.target.project, ]); diff --git a/packages/nx/src/tasks-runner/run-command.ts b/packages/nx/src/tasks-runner/run-command.ts index 93b1af773f6e28..c3cd0981b4c12a 100644 --- a/packages/nx/src/tasks-runner/run-command.ts +++ b/packages/nx/src/tasks-runner/run-command.ts @@ -28,6 +28,7 @@ import { Workspaces } from '../config/workspaces'; import { DaemonBasedTaskHasher, InProcessTaskHasher, + TaskHasher, } from '../hasher/task-hasher'; import { hashTasksThatDoNotDependOnOutputsOfOtherTasks } from '../hasher/hash-task'; import { daemonClient } from '../daemon/client/client'; @@ -231,7 +232,7 @@ export async function invokeTasksRunner({ const { tasksRunner, runnerOptions } = getRunner(nxArgs, nxJson); - let hasher; + let hasher: TaskHasher; if (daemonClient.enabled()) { hasher = new DaemonBasedTaskHasher(daemonClient, runnerOptions); } else { @@ -272,7 +273,33 @@ export async function invokeTasksRunner({ nxJson, nxArgs, taskGraph, - hasher, + hasher: { + hashTask(task: Task, taskGraph_?: TaskGraph) { + if (!taskGraph_) { + output.warn({ + title: `TaskGraph is now required as an argument to hashTasks`, + bodyLines: [ + `The TaskGraph object can be retrieved from the context`, + ], + }); + taskGraph_ = taskGraph; + } + return hasher.hashTask(task, taskGraph_); + }, + hashTasks(task: Task[], taskGraph_?: TaskGraph) { + if (!taskGraph_) { + output.warn({ + title: `TaskGraph is now required as an argument to hashTasks`, + bodyLines: [ + `The TaskGraph object can be retrieved from the context`, + ], + }); + taskGraph_ = taskGraph; + } + + return hasher.hashTasks(task, taskGraph_); + }, + }, daemon: daemonClient, } ); diff --git a/packages/plugin/src/generators/executor/files/hasher/__fileName__/hasher.ts__tmpl__ b/packages/plugin/src/generators/executor/files/hasher/__fileName__/hasher.ts__tmpl__ index 90639ebc53b6a3..e8150a49950d52 100644 --- a/packages/plugin/src/generators/executor/files/hasher/__fileName__/hasher.ts__tmpl__ +++ b/packages/plugin/src/generators/executor/files/hasher/__fileName__/hasher.ts__tmpl__ @@ -6,7 +6,7 @@ import { CustomHasher } from '@nx/devkit'; * you can consume workspace details from the context. */ export const <%=propertyName%>Hasher: CustomHasher = async (task, context) => { - return context.hasher.hashTask(task); + return context.hasher.hashTask(task, context.taskGraph); }; export default <%=propertyName%>Hasher;