-
Notifications
You must be signed in to change notification settings - Fork 248
/
circular.mjs
47 lines (43 loc) · 1017 Bytes
/
circular.mjs
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
/* eslint-disable security/detect-object-injection */
function addCircularityCheckToDependency(
pIndexedGraph,
pFrom,
pToDep,
pDependencyName,
) {
let lReturnValue = {
...pToDep,
circular: false,
};
const lCycle = pIndexedGraph.getCycle(pFrom, pToDep[pDependencyName]);
if (lCycle.length > 0) {
lReturnValue = {
...lReturnValue,
circular: true,
cycle: lCycle,
};
}
return lReturnValue;
}
/**
* Runs through all dependencies of all pNodes, for each of them determines
* whether it's (part of a) circular (relationship) and returns the
* dependencies with that added.
*/
export default function detectAndAddCycles(
pNodes,
pIndexedNodes,
{ pSourceAttribute, pDependencyName },
) {
return pNodes.map((pModule) => ({
...pModule,
dependencies: pModule.dependencies.map((pToDep) =>
addCircularityCheckToDependency(
pIndexedNodes,
pModule[pSourceAttribute],
pToDep,
pDependencyName,
),
),
}));
}