forked from nrwl/nx
/
hasher.ts
49 lines (47 loc) · 1.43 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
import { Task, TaskGraph } from '@nrwl/devkit';
import { Hash, Hasher } from '@nrwl/workspace/src/core/hasher/hasher';
import { readJsonFile } from '@nrwl/workspace/src/utilities/fileutils';
import { appRootPath } from '@nrwl/tao/src/utils/app-root';
import { join } from 'path';
export default async function run(
task: Task,
taskGraph: TaskGraph,
hasher: Hasher
): Promise<Hash> {
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 nxJson = readJsonFile(join(appRootPath, 'nx.json'));
const tags = hasher.hashArray(
deps.map((d) => (nxJson.projects[d].tags || []).join('|'))
);
const context = await hasher.hashContext();
return {
value: hasher.hashArray([
command,
sources,
tags,
context.implicitDeps.value,
context.runtime.value,
]),
details: {
command,
nodes: { [task.target.project]: sources, tags },
implicitDeps: context.implicitDeps.files,
runtime: context.runtime.runtime,
},
};
}
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)
),
];
}