-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
hasher.ts
69 lines (64 loc) · 1.65 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
57
58
59
60
61
62
63
64
65
66
67
68
69
import {
ProjectGraph,
Task,
TaskGraph,
ProjectsConfigurations,
Hasher,
Hash,
} from '@nrwl/devkit';
export default async function run(
task: Task,
context: {
hasher: Hasher;
projectGraph: ProjectGraph;
taskGraph: TaskGraph;
projectsConfigurations: ProjectsConfigurations;
}
): Promise<Hash> {
const res = await context.hasher.hashTask(task);
if (task.overrides['hasTypeAwareRules'] === true) {
return res;
}
const deps = allDeps(task.id, context.taskGraph, context.projectGraph);
const tags = context.hasher.hashArray(
deps.map((d) =>
(context.projectsConfigurations.projects[d].tags || []).join('|')
)
);
const command = res.details['command'];
let selfSource = '';
for (let n of Object.keys(res.details)) {
if (n.startsWith(`${task.target.project}:`)) {
selfSource = res.details.nodes[n];
}
}
const nodes = {};
const hashes = [] as string[];
for (const d of Object.keys(res.details.nodes)) {
if (d.indexOf('$fileset') === -1) {
nodes[d] = res.details.nodes[d];
hashes.push(res.details.nodes[d]);
}
}
return {
value: context.hasher.hashArray([command, selfSource, ...hashes, tags]),
details: {
command,
nodes: { [task.target.project]: selfSource, tags, ...nodes },
},
};
}
function allDeps(
taskId: string,
taskGraph: TaskGraph,
projectGraph: ProjectGraph
): string[] {
if (!taskGraph.tasks) {
return [];
}
const project = taskGraph.tasks[taskId].target.project;
const dependencies = projectGraph.dependencies[project]
.filter((d) => !!projectGraph.nodes[d.target])
.map((d) => d.target);
return dependencies;
}