/
hasher.ts
56 lines (53 loc) · 1.52 KB
/
hasher.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import {
ProjectGraph,
Task,
TaskGraph,
WorkspaceJsonConfiguration,
} from '@nrwl/devkit';
import { Hash, Hasher } from '@nrwl/workspace/src/core/hasher/hasher';
export default async function run(
task: Task,
context: {
hasher: Hasher;
projectGraph: ProjectGraph;
taskGraph: TaskGraph;
workspaceConfig: WorkspaceJsonConfiguration;
}
): Promise<Hash> {
if (task.overrides['hasTypeAwareRules'] === true) {
return context.hasher.hashTaskWithDepsAndContext(task);
}
const command = context.hasher.hashCommand(task);
const source = await context.hasher.hashSource(task);
const deps = allDeps(task.id, context.taskGraph, context.projectGraph);
const tags = context.hasher.hashArray(
deps.map((d) => (context.workspaceConfig.projects[d].tags || []).join('|'))
);
const taskContext = await context.hasher.hashContext();
return {
value: context.hasher.hashArray([
command,
source,
tags,
taskContext.implicitDeps.value,
taskContext.runtime.value,
]),
details: {
command,
nodes: { [task.target.project]: source, tags },
implicitDeps: taskContext.implicitDeps.files,
runtime: taskContext.runtime.runtime,
},
};
}
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;
}