dependency-cruiser 17.3.4-beta-1 → 17.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/cache/metadata-strategy.mjs +0 -1
- package/src/enrich/derive/circular.mjs +9 -14
- package/src/enrich/derive/dependents.mjs +10 -19
- package/src/enrich/derive/folders/aggregate-to-folders.mjs +2 -1
- package/src/enrich/derive/metrics/get-module-metrics.mjs +7 -4
- package/src/enrich/derive/metrics/index.mjs +3 -7
- package/src/enrich/enrich-modules.mjs +3 -2
- package/src/meta.cjs +1 -1
package/package.json
CHANGED
|
@@ -21,7 +21,6 @@ export default class MetaDataStrategy {
|
|
|
21
21
|
/**
|
|
22
22
|
* @param {string} _pDirectory
|
|
23
23
|
* @param {ICruiseResult} _pCachedCruiseResult
|
|
24
|
-
* @param {IStrictCruiseOptions} pCruiseOptions
|
|
25
24
|
* @param {Object} pOptions
|
|
26
25
|
* @param {Set<string>} pOptions.extensions
|
|
27
26
|
* @param {Set<changeType>=} pOptions.interestingChangeTypes
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/* eslint-disable security/detect-object-injection */
|
|
2
|
-
import IndexedModuleGraph from "#graph-utl/indexed-module-graph.mjs";
|
|
3
2
|
|
|
4
3
|
/** @import { IFlattenedRuleSet } from "../../../types/rule-set.mjs" */
|
|
5
4
|
|
|
@@ -45,33 +44,29 @@ function addCircularityCheckToDependency(
|
|
|
45
44
|
}
|
|
46
45
|
|
|
47
46
|
/**
|
|
48
|
-
* Runs through all dependencies of all
|
|
47
|
+
* Runs through all dependencies of all pNodes, for each of them determines
|
|
49
48
|
* whether it's (part of a) circular (relationship) and returns the
|
|
50
49
|
* dependencies with that added.
|
|
51
50
|
*/
|
|
52
51
|
export default function detectAndAddCycles(
|
|
53
|
-
|
|
52
|
+
pNodes,
|
|
53
|
+
pIndexedNodes,
|
|
54
54
|
{ pSourceAttribute, pDependencyName, pSkipAnalysisNotInRules, pRuleSet },
|
|
55
55
|
) {
|
|
56
56
|
if (!pSkipAnalysisNotInRules || hasCycleRule(pRuleSet)) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
);
|
|
61
|
-
|
|
62
|
-
return pModulesOrFolders.map((pModuleOrFolder) => ({
|
|
63
|
-
...pModuleOrFolder,
|
|
64
|
-
dependencies: pModuleOrFolder.dependencies.map((pToDep) =>
|
|
57
|
+
return pNodes.map((pModule) => ({
|
|
58
|
+
...pModule,
|
|
59
|
+
dependencies: pModule.dependencies.map((pToDep) =>
|
|
65
60
|
addCircularityCheckToDependency(
|
|
66
|
-
|
|
67
|
-
|
|
61
|
+
pIndexedNodes,
|
|
62
|
+
pModule[pSourceAttribute],
|
|
68
63
|
pToDep,
|
|
69
64
|
pDependencyName,
|
|
70
65
|
),
|
|
71
66
|
),
|
|
72
67
|
}));
|
|
73
68
|
}
|
|
74
|
-
return
|
|
69
|
+
return pNodes.map((pModule) => ({
|
|
75
70
|
...pModule,
|
|
76
71
|
dependencies: pModule.dependencies.map((pToDep) => ({
|
|
77
72
|
...pToDep,
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
+
import { isDependent } from "./module-utl.mjs";
|
|
2
|
+
|
|
1
3
|
/** @import { IFlattenedRuleSet } from "../../../types/rule-set.mjs" */
|
|
2
4
|
|
|
3
5
|
function isDependentsRule(pRule) {
|
|
4
6
|
// used in folder rules and when moreUnstable is in the 'to' => governed by
|
|
5
|
-
// the 'metrics' flag in options,
|
|
7
|
+
// the 'metrics' flag in options, sot not going to repeat that here
|
|
6
8
|
|
|
7
|
-
// dependents are used in the orphans
|
|
8
|
-
// where it does its own analysis
|
|
9
|
-
// to repeat that check here either.
|
|
9
|
+
// dependents are used in the orphans analsys. However, there is a fall back
|
|
10
|
+
// where it does its own analysis, so not going to repeat that check here.
|
|
10
11
|
return (
|
|
11
12
|
/* c8 ignore start */
|
|
12
13
|
Object.hasOwn(pRule?.module ?? {}, "numberOfDependentsLessThan") ||
|
|
@@ -15,10 +16,10 @@ function isDependentsRule(pRule) {
|
|
|
15
16
|
);
|
|
16
17
|
}
|
|
17
18
|
|
|
18
|
-
export function getDependents(pModule,
|
|
19
|
-
// perf O(n)
|
|
20
|
-
return
|
|
21
|
-
.filter((
|
|
19
|
+
export function getDependents(pModule, pModules) {
|
|
20
|
+
// perf between O(n) in an unconnected graph and O(n^2) in a fully connected one
|
|
21
|
+
return pModules
|
|
22
|
+
.filter(isDependent(pModule.source))
|
|
22
23
|
.map((pDependentModule) => pDependentModule.source);
|
|
23
24
|
}
|
|
24
25
|
|
|
@@ -38,19 +39,9 @@ export default function addDependents(
|
|
|
38
39
|
{ skipAnalysisNotInRules, metrics, ruleSet },
|
|
39
40
|
) {
|
|
40
41
|
if (!skipAnalysisNotInRules || metrics || hasDependentsRule(ruleSet)) {
|
|
41
|
-
// creating this optimized structure here might seem overkill, but on
|
|
42
|
-
// large graphs it pays off significantly - creation is a few centiseconds
|
|
43
|
-
// but it cuts analysis in half on large graphs (and even on smaller
|
|
44
|
-
// graphs it's a win, even though just a few milliseconds)
|
|
45
|
-
const lModulesWithDependencySet = pModules.map((pModule) => ({
|
|
46
|
-
source: pModule.source,
|
|
47
|
-
dependencies: new Set(
|
|
48
|
-
pModule.dependencies.map((pDependency) => pDependency.resolved),
|
|
49
|
-
),
|
|
50
|
-
}));
|
|
51
42
|
return pModules.map((pModule) => ({
|
|
52
43
|
...pModule,
|
|
53
|
-
dependents: getDependents(pModule,
|
|
44
|
+
dependents: getDependents(pModule, pModules),
|
|
54
45
|
}));
|
|
55
46
|
}
|
|
56
47
|
return pModules;
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
getParentFolders,
|
|
10
10
|
object2Array,
|
|
11
11
|
} from "./utl.mjs";
|
|
12
|
+
import IndexedModuleGraph from "#graph-utl/indexed-module-graph.mjs";
|
|
12
13
|
import { uniq } from "#utl/array-util.mjs";
|
|
13
14
|
|
|
14
15
|
function upsertCouplings(pAllDependents, pNewDependents) {
|
|
@@ -147,7 +148,7 @@ export default function aggregateToFolders(pModules, pOptions = {}) {
|
|
|
147
148
|
.map(deNormalizeInstability);
|
|
148
149
|
lFolders = lFolders.concat(getSinks(lFolders));
|
|
149
150
|
|
|
150
|
-
return detectCycles(lFolders, {
|
|
151
|
+
return detectCycles(lFolders, new IndexedModuleGraph(lFolders, "name"), {
|
|
151
152
|
pSourceAttribute: "name",
|
|
152
153
|
pDependencyName: "name",
|
|
153
154
|
pSkipAnalysisNotInRules: pOptions.skipAnalysisNotInRules,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { calculateInstability, metricsAreCalculable } from "../module-utl.mjs";
|
|
2
|
+
import IndexedModuleGraph from "#graph-utl/indexed-module-graph.mjs";
|
|
2
3
|
|
|
3
4
|
export function addInstabilityMetric(pModule) {
|
|
4
5
|
return {
|
|
@@ -14,23 +15,25 @@ export function addInstabilityMetric(pModule) {
|
|
|
14
15
|
};
|
|
15
16
|
}
|
|
16
17
|
|
|
17
|
-
function addInstabilityToDependency(
|
|
18
|
+
function addInstabilityToDependency(pAllModules) {
|
|
19
|
+
const lIndexedModules = new IndexedModuleGraph(pAllModules);
|
|
18
20
|
return (pDependency) => ({
|
|
19
21
|
...pDependency,
|
|
20
22
|
instability:
|
|
21
|
-
(
|
|
23
|
+
(lIndexedModules.findVertexByName(pDependency.resolved) || {})
|
|
22
24
|
.instability || 0,
|
|
23
25
|
});
|
|
24
26
|
}
|
|
25
27
|
|
|
26
28
|
export function deNormalizeInstabilityMetricsToDependencies(
|
|
27
29
|
pModule,
|
|
28
|
-
|
|
30
|
+
_,
|
|
31
|
+
pAllModules,
|
|
29
32
|
) {
|
|
30
33
|
return {
|
|
31
34
|
...pModule,
|
|
32
35
|
dependencies: pModule.dependencies.map(
|
|
33
|
-
addInstabilityToDependency(
|
|
36
|
+
addInstabilityToDependency(pAllModules),
|
|
34
37
|
),
|
|
35
38
|
};
|
|
36
39
|
}
|
|
@@ -2,16 +2,12 @@ import {
|
|
|
2
2
|
addInstabilityMetric,
|
|
3
3
|
deNormalizeInstabilityMetricsToDependencies,
|
|
4
4
|
} from "./get-module-metrics.mjs";
|
|
5
|
-
import IndexedModuleGraph from "#graph-utl/indexed-module-graph.mjs";
|
|
6
5
|
|
|
7
6
|
export default function deriveModulesMetrics(pModules, pOptions) {
|
|
8
7
|
if (pOptions.metrics) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
return lModules.map((pModule) =>
|
|
13
|
-
deNormalizeInstabilityMetricsToDependencies(pModule, lIndexedModules),
|
|
14
|
-
);
|
|
8
|
+
return pModules
|
|
9
|
+
.map(addInstabilityMetric)
|
|
10
|
+
.map(deNormalizeInstabilityMetricsToDependencies);
|
|
15
11
|
}
|
|
16
12
|
return pModules;
|
|
17
13
|
}
|
|
@@ -5,6 +5,7 @@ import deriveReachable from "./derive/reachable.mjs";
|
|
|
5
5
|
import addValidations from "./add-validations.mjs";
|
|
6
6
|
import softenKnownViolations from "./soften-known-violations.mjs";
|
|
7
7
|
import deriveModuleMetrics from "./derive/metrics/index.mjs";
|
|
8
|
+
import IndexedModuleGraph from "#graph-utl/indexed-module-graph.mjs";
|
|
8
9
|
import addFocus from "#graph-utl/add-focus.mjs";
|
|
9
10
|
import { bus } from "#utl/bus.mjs";
|
|
10
11
|
|
|
@@ -17,8 +18,8 @@ import { bus } from "#utl/bus.mjs";
|
|
|
17
18
|
*/
|
|
18
19
|
export default function enrichModules(pModules, pOptions) {
|
|
19
20
|
bus.info("analyze: cycles");
|
|
20
|
-
|
|
21
|
-
let lModules = deriveCycles(pModules, {
|
|
21
|
+
const lIndexedModules = new IndexedModuleGraph(pModules);
|
|
22
|
+
let lModules = deriveCycles(pModules, lIndexedModules, {
|
|
22
23
|
pSourceAttribute: "source",
|
|
23
24
|
pDependencyName: "resolved",
|
|
24
25
|
pSkipAnalysisNotInRules: pOptions.skipAnalysisNotInRules,
|