dependency-cruiser 12.1.0 → 12.2.0
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/README.md +1 -1
- package/configs/plugins/3d-reporter-plugin.js +3 -3
- package/configs/plugins/stats-reporter-plugin.js +3 -3
- package/package.json +26 -29
- package/src/cache/cache.js +4 -4
- package/src/cache/revision-data.js +13 -6
- package/src/cache/utl.js +1 -0
- package/src/cli/format.js +2 -2
- package/src/cli/index.js +9 -10
- package/src/cli/init-config/build-config.js +2 -2
- package/src/cli/init-config/environment-helpers.js +6 -3
- package/src/cli/init-config/get-user-input.js +2 -2
- package/src/cli/init-config/index.js +15 -8
- package/src/cli/init-config/{inquirer-validators.js → validators.js} +1 -9
- package/src/cli/init-config/write-config.js +1 -1
- package/src/cli/listeners/performance-log/format-helpers.js +75 -15
- package/src/cli/listeners/performance-log/handlers.js +32 -14
- package/src/cli/listeners/performance-log/index.js +6 -0
- package/src/config-utl/extract-depcruise-config/index.js +12 -9
- package/src/config-utl/extract-depcruise-config/read-config.js +1 -1
- package/src/config-utl/extract-webpack-resolve-config.js +1 -2
- package/src/config-utl/make-absolute.js +1 -1
- package/src/enrich/add-validations.js +1 -1
- package/src/enrich/derive/circular/get-cycle.js +3 -4
- package/src/enrich/derive/folders/index.js +3 -3
- package/src/enrich/derive/orphan/index.js +3 -2
- package/src/enrich/derive/orphan/is-orphan.js +1 -1
- package/src/enrich/derive/reachable/index.js +1 -1
- package/src/enrich/index.js +3 -3
- package/src/enrich/summarize/index.js +1 -1
- package/src/extract/ast-extractors/swc-dependency-visitor.js +1 -1
- package/src/extract/gather-initial-sources.js +1 -1
- package/src/extract/get-dependencies.js +14 -21
- package/src/extract/index.js +4 -4
- package/src/extract/resolve/determine-dependency-types.js +6 -6
- package/src/extract/resolve/index.js +2 -2
- package/src/graph-utl/add-focus.js +1 -1
- package/src/graph-utl/consolidate-module-dependencies.js +6 -4
- package/src/graph-utl/consolidate-modules.js +1 -1
- package/src/graph-utl/consolidate-to-folder.js +3 -2
- package/src/graph-utl/rule-set.js +3 -3
- package/src/main/index.js +4 -4
- package/src/main/options/normalize.js +6 -6
- package/src/main/options/validate.js +2 -2
- package/src/main/report-wrap.js +6 -6
- package/src/main/resolve-options/normalize.js +4 -4
- package/src/main/rule-set/normalize.js +1 -1
- package/src/meta.js +1 -1
- package/src/report/anon/index.js +1 -1
- package/src/report/baseline.js +12 -10
- package/src/report/csv.js +7 -5
- package/src/report/dot/index.js +12 -10
- package/src/report/dot/module-utl.js +2 -2
- package/src/report/dot/prepare-custom-level.js +6 -1
- package/src/report/dot/prepare-flat-level.js +1 -1
- package/src/report/dot/prepare-folder-level.js +6 -1
- package/src/report/error-html/index.js +7 -5
- package/src/report/error-html/utl.js +5 -5
- package/src/report/error.js +10 -8
- package/src/report/html/index.js +7 -5
- package/src/report/identity.js +7 -5
- package/src/report/json.js +7 -5
- package/src/report/markdown.js +9 -7
- package/src/report/mermaid.js +14 -11
- package/src/report/metrics.js +7 -8
- package/src/report/{plugins/index.js → plugins.js} +5 -2
- package/src/report/teamcity.js +5 -5
- package/src/report/text.js +7 -5
- package/src/report/utl/dependency-to-incidence-transformer.js +3 -2
- package/src/report/utl/index.js +4 -5
- package/src/validate/match-dependency-rule.js +2 -2
- package/types/README.md +1 -0
- package/types/init-config.d.ts +8 -11
package/src/main/report-wrap.js
CHANGED
|
@@ -9,9 +9,9 @@ const report = require("../report");
|
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
*
|
|
12
|
-
* @param {import('
|
|
13
|
-
* @param {import('
|
|
14
|
-
* @returns {import('
|
|
12
|
+
* @param {import('../..').ICruiseResult} pResult
|
|
13
|
+
* @param {import('../..').IFormatOptions} pFormatOptions
|
|
14
|
+
* @returns {import('../..').ICruiseResult}
|
|
15
15
|
*/
|
|
16
16
|
function reSummarizeResults(pResult, pFormatOptions) {
|
|
17
17
|
let lModules = filterBank.applyFilters(pResult.modules, pFormatOptions);
|
|
@@ -41,9 +41,9 @@ function reSummarizeResults(pResult, pFormatOptions) {
|
|
|
41
41
|
}
|
|
42
42
|
/**
|
|
43
43
|
*
|
|
44
|
-
* @param {import("
|
|
45
|
-
* @param {import("
|
|
46
|
-
* @returns {import("
|
|
44
|
+
* @param {import("../..).ICruiseResult} pResult result of a previous run of dependency-cruiser
|
|
45
|
+
* @param {import("../..").IFormatOptions} pFormatOptions
|
|
46
|
+
* @returns {import("../..").IReporterOutput}
|
|
47
47
|
*/
|
|
48
48
|
module.exports = function reportWrap(pResult, pFormatOptions) {
|
|
49
49
|
const lReportFunction = report.getReporter(pFormatOptions.outputType);
|
|
@@ -10,7 +10,7 @@ const {
|
|
|
10
10
|
} = require("../../graph-utl/rule-set");
|
|
11
11
|
|
|
12
12
|
const DEFAULT_CACHE_DURATION = 4000;
|
|
13
|
-
/** @type {Partial<import("
|
|
13
|
+
/** @type {Partial<import("../../..").IResolveOptions>} */
|
|
14
14
|
const DEFAULT_RESOLVE_OPTIONS = {
|
|
15
15
|
// for later: check semantics of enhanced-resolve symlinks and
|
|
16
16
|
// node's preserveSymlinks. They seem to be
|
|
@@ -44,7 +44,7 @@ const DEFAULT_RESOLVE_OPTIONS = {
|
|
|
44
44
|
/**
|
|
45
45
|
*
|
|
46
46
|
* @param {Number} pCacheDuration
|
|
47
|
-
* @returns {Partial<import("
|
|
47
|
+
* @returns {Partial<import("../../..").IResolveOptions>}
|
|
48
48
|
*/
|
|
49
49
|
function getNonOverridableResolveOptions(pCacheDuration) {
|
|
50
50
|
return {
|
|
@@ -120,8 +120,8 @@ function compileResolveOptions(
|
|
|
120
120
|
}
|
|
121
121
|
|
|
122
122
|
/**
|
|
123
|
-
* @param {import("
|
|
124
|
-
* @param {import("
|
|
123
|
+
* @param {import("../../..").IResolveOptions} pResolveOptions
|
|
124
|
+
* @param {import("../../..").ICruiseOptions} pOptions
|
|
125
125
|
* @param {import("typescript").ParsedTsconfig} pTSConfig
|
|
126
126
|
* @returns
|
|
127
127
|
*/
|
|
@@ -55,7 +55,7 @@ function normalizeRule(pRule) {
|
|
|
55
55
|
* - rule name (default 'unnamed')
|
|
56
56
|
* - severity (default 'warn')
|
|
57
57
|
*
|
|
58
|
-
* @param {import("
|
|
58
|
+
* @param {import("../../..").IFlattenedRuleSet} pRuleSet
|
|
59
59
|
* @return {import("../../../types/strict-rule-set").IStrictRuleSet}
|
|
60
60
|
*/
|
|
61
61
|
module.exports = function normalizeRuleSet(pRuleSet) {
|
package/src/meta.js
CHANGED
package/src/report/anon/index.js
CHANGED
|
@@ -155,7 +155,7 @@ function sanitizeWordList(pWordList) {
|
|
|
155
155
|
* not passed the reporter uses the string passed
|
|
156
156
|
* in the options (reporterOptions.anon.wordlist)
|
|
157
157
|
* or - if that doesn't exist - the empty array
|
|
158
|
-
* @returns {import("
|
|
158
|
+
* @returns {import("../../..").IReporterOutput} - output: the results in JSON format (hence adhering to the same json schema)
|
|
159
159
|
* exitCode: 0
|
|
160
160
|
*/
|
|
161
161
|
module.exports = function reportAnonymous(pResults, pAnonymousReporterOptions) {
|
package/src/report/baseline.js
CHANGED
|
@@ -3,18 +3,20 @@ const DEFAULT_JSON_INDENT = 2;
|
|
|
3
3
|
/**
|
|
4
4
|
* Sample plugin
|
|
5
5
|
*
|
|
6
|
-
* @param {import('
|
|
6
|
+
* @param {import('../..').ICruiseResult} pCruiseResult -
|
|
7
7
|
* the output of a dependency-cruise adhering to dependency-cruiser's
|
|
8
8
|
* cruise result schema
|
|
9
|
-
* @return {import('
|
|
9
|
+
* @return {import('../..').IReporterOutput} -
|
|
10
10
|
* output: some stats on modules and dependencies in json format
|
|
11
11
|
* exitCode: 0
|
|
12
12
|
*/
|
|
13
|
-
module.exports = (pCruiseResult)
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
13
|
+
module.exports = function baseline(pCruiseResult) {
|
|
14
|
+
return {
|
|
15
|
+
output: JSON.stringify(
|
|
16
|
+
pCruiseResult.summary.violations,
|
|
17
|
+
null,
|
|
18
|
+
DEFAULT_JSON_INDENT
|
|
19
|
+
),
|
|
20
|
+
exitCode: 0,
|
|
21
|
+
};
|
|
22
|
+
};
|
package/src/report/csv.js
CHANGED
|
@@ -25,9 +25,11 @@ function report(pModules) {
|
|
|
25
25
|
*
|
|
26
26
|
* @param {import("../../types/cruise-result").ICruiseResult} pResults -
|
|
27
27
|
* the output of a dependency-cruise adhering to ../../schema/cruise-result.schema.json
|
|
28
|
-
* @returns {import("
|
|
28
|
+
* @returns {import("../..").IReporterOutput}
|
|
29
29
|
*/
|
|
30
|
-
module.exports = (pResults)
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
module.exports = function csv(pResults) {
|
|
31
|
+
return {
|
|
32
|
+
output: report(dependencyToIncidenceTransformer(pResults.modules)),
|
|
33
|
+
exitCode: 0,
|
|
34
|
+
};
|
|
35
|
+
};
|
package/src/report/dot/index.js
CHANGED
|
@@ -130,17 +130,19 @@ function normalizeDotReporterOptions(
|
|
|
130
130
|
* @param {string} pGranularity - either "module" (for fine grained module
|
|
131
131
|
* level) or "folder" (for a report consolidated
|
|
132
132
|
* to folders)
|
|
133
|
-
* @returns {(pResults, pDotReporterOptions) => import("
|
|
133
|
+
* @returns {(pResults, pDotReporterOptions) => import("../../..").IReporterOutput}
|
|
134
134
|
*/
|
|
135
|
-
module.exports = (pGranularity)
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
135
|
+
module.exports = function produceDotReporter(pGranularity) {
|
|
136
|
+
return function dot(pResults, pDotReporterOptions) {
|
|
137
|
+
const lDotReporterOptions = normalizeDotReporterOptions(
|
|
138
|
+
pDotReporterOptions,
|
|
139
|
+
pGranularity,
|
|
140
|
+
pResults
|
|
141
|
+
);
|
|
141
142
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
143
|
+
return {
|
|
144
|
+
output: report(pResults, pGranularity, lDotReporterOptions),
|
|
145
|
+
exitCode: 0,
|
|
146
|
+
};
|
|
145
147
|
};
|
|
146
148
|
};
|
|
@@ -67,9 +67,9 @@ function makeInstabilityString(pModule, pShowMetrics = false) {
|
|
|
67
67
|
let lInstabilityString = "";
|
|
68
68
|
|
|
69
69
|
if (pShowMetrics && has(pModule, "instability") && !pModule.consolidated) {
|
|
70
|
-
lInstabilityString = ` <FONT color="#808080" point-size="8">${utl.
|
|
70
|
+
lInstabilityString = ` <FONT color="#808080" point-size="8">${utl.formatPercentage(
|
|
71
71
|
pModule.instability
|
|
72
|
-
)}
|
|
72
|
+
)}</FONT>`;
|
|
73
73
|
}
|
|
74
74
|
return lInstabilityString;
|
|
75
75
|
}
|
|
@@ -4,7 +4,12 @@ const compare = require("../../graph-utl/compare");
|
|
|
4
4
|
const stripSelfTransitions = require("../../graph-utl/strip-self-transitions");
|
|
5
5
|
const moduleUtl = require("./module-utl");
|
|
6
6
|
|
|
7
|
-
module.exports = (
|
|
7
|
+
module.exports = function prepareCustomLevel(
|
|
8
|
+
pResults,
|
|
9
|
+
pTheme,
|
|
10
|
+
pCollapsePattern,
|
|
11
|
+
pShowMetrics
|
|
12
|
+
) {
|
|
8
13
|
return (
|
|
9
14
|
pCollapsePattern
|
|
10
15
|
? consolidateToPattern(pResults.modules, pCollapsePattern)
|
|
@@ -2,7 +2,7 @@ const get = require("lodash/get");
|
|
|
2
2
|
const compare = require("../../graph-utl/compare");
|
|
3
3
|
const moduleUtl = require("./module-utl");
|
|
4
4
|
|
|
5
|
-
module.exports = (pResults, pTheme, _, pShowMetrics)
|
|
5
|
+
module.exports = function prepareFlatLevel(pResults, pTheme, _, pShowMetrics) {
|
|
6
6
|
return pResults.modules
|
|
7
7
|
.sort(compare.modules)
|
|
8
8
|
.map(moduleUtl.flatLabel(pShowMetrics))
|
|
@@ -3,7 +3,12 @@ const compare = require("../../graph-utl/compare");
|
|
|
3
3
|
const stripSelfTransitions = require("../../graph-utl/strip-self-transitions");
|
|
4
4
|
const moduleUtl = require("./module-utl");
|
|
5
5
|
|
|
6
|
-
module.exports = (
|
|
6
|
+
module.exports = function prepareFolderLevel(
|
|
7
|
+
pResults,
|
|
8
|
+
pTheme,
|
|
9
|
+
_,
|
|
10
|
+
pShowMetrics
|
|
11
|
+
) {
|
|
7
12
|
return consolidateToFolder(pResults.modules)
|
|
8
13
|
.sort(compare.modules)
|
|
9
14
|
.map(moduleUtl.extractFirstTransgression)
|
|
@@ -27,10 +27,12 @@ function report(pResults) {
|
|
|
27
27
|
* Returns the results of a cruise in an 'incidence matrix'
|
|
28
28
|
*
|
|
29
29
|
* @param {import("../../../types/cruise-result").ICruiseResult} pResults - the output of a dependency-cruise adhering to ../../schema/cruise-result.schema.json
|
|
30
|
-
* @returns {import("
|
|
30
|
+
* @returns {import("../../..").IReporterOutput} - output: an html program showing the summary & the violations (if any)
|
|
31
31
|
* exitCode: 0
|
|
32
32
|
*/
|
|
33
|
-
module.exports = (pResults)
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
module.exports = function errorHtml(pResults) {
|
|
34
|
+
return {
|
|
35
|
+
output: report(pResults),
|
|
36
|
+
exitCode: 0,
|
|
37
|
+
};
|
|
38
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const has = require("lodash/has");
|
|
2
2
|
const { version } = require("../../../src/meta.js");
|
|
3
|
-
const { formatViolation,
|
|
3
|
+
const { formatViolation, formatPercentage } = require("../utl/index.js");
|
|
4
4
|
|
|
5
5
|
function getFormattedAllowedRule(pRuleSetUsed) {
|
|
6
6
|
const lAllowed = pRuleSetUsed?.allowed ?? [];
|
|
@@ -46,9 +46,9 @@ function formatModuleTo() {
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
function formatInstabilityTo(pViolation) {
|
|
49
|
-
return `${pViolation.to} <span class="extra">(I: ${
|
|
49
|
+
return `${pViolation.to} <span class="extra">(I: ${formatPercentage(
|
|
50
50
|
pViolation.metrics.to.instability
|
|
51
|
-
)}
|
|
51
|
+
)})</span>`;
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
function determineTo(pViolation) {
|
|
@@ -67,9 +67,9 @@ function determineTo(pViolation) {
|
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
function formatInstabilityFromExtras(pViolation) {
|
|
70
|
-
return ` <span class="extra">(I: ${
|
|
70
|
+
return ` <span class="extra">(I: ${formatPercentage(
|
|
71
71
|
pViolation.metrics.from.instability
|
|
72
|
-
)}
|
|
72
|
+
)})</span>`;
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
function determineFromExtras(pViolation) {
|
package/src/report/error.js
CHANGED
|
@@ -47,11 +47,11 @@ function formatReachabilityViolation(pViolation) {
|
|
|
47
47
|
function formatInstabilityViolation(pViolation) {
|
|
48
48
|
return `${formatDependencyViolation(pViolation)}\n${wrapAndIndent(
|
|
49
49
|
chalk.dim(
|
|
50
|
-
`instability: ${utl.
|
|
50
|
+
`instability: ${utl.formatPercentage(
|
|
51
51
|
pViolation.metrics.from.instability
|
|
52
|
-
)}
|
|
52
|
+
)} ${figures.arrowRight} ${utl.formatPercentage(
|
|
53
53
|
pViolation.metrics.to.instability
|
|
54
|
-
)}
|
|
54
|
+
)}`
|
|
55
55
|
),
|
|
56
56
|
EXTRA_PATH_INFORMATION_INDENT
|
|
57
57
|
)}`;
|
|
@@ -153,10 +153,12 @@ function report(pResults, pLong) {
|
|
|
153
153
|
* @param {any} pOptions - An object with options;
|
|
154
154
|
* {boolean} long - whether or not to include an explanation
|
|
155
155
|
* (/ comment) which each violation
|
|
156
|
-
* @returns {import("
|
|
156
|
+
* @returns {import("../..").IReporterOutput} - output: the formatted text in a string
|
|
157
157
|
* exitCode: the number of errors found
|
|
158
158
|
*/
|
|
159
|
-
module.exports = (pResults, pOptions)
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
159
|
+
module.exports = function error(pResults, pOptions) {
|
|
160
|
+
return {
|
|
161
|
+
output: report(pResults, (pOptions || {}).long),
|
|
162
|
+
exitCode: pResults.summary.error,
|
|
163
|
+
};
|
|
164
|
+
};
|
package/src/report/html/index.js
CHANGED
|
@@ -26,9 +26,11 @@ function report(pResults) {
|
|
|
26
26
|
* Returns the results of a cruise in an 'incidence matrix'
|
|
27
27
|
*
|
|
28
28
|
* @param {import("../../../types/cruise-result").ICruiseResult} pResults
|
|
29
|
-
* @returns {import("
|
|
29
|
+
* @returns {import("../../..").IReporterOutput}
|
|
30
30
|
*/
|
|
31
|
-
module.exports = (pResults)
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
module.exports = function html(pResults) {
|
|
32
|
+
return {
|
|
33
|
+
output: report(pResults),
|
|
34
|
+
exitCode: 0,
|
|
35
|
+
};
|
|
36
|
+
};
|
package/src/report/identity.js
CHANGED
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
* Returns the results of a cruise in a javascript object
|
|
3
3
|
*
|
|
4
4
|
* @param {import("../../types/cruise-result").ICruiseResult} pResults
|
|
5
|
-
* @returns {import("
|
|
5
|
+
* @returns {import("../..").IReporterOutput}
|
|
6
6
|
*/
|
|
7
|
-
module.exports = (pResults)
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
module.exports = function identity(pResults) {
|
|
8
|
+
return {
|
|
9
|
+
output: pResults,
|
|
10
|
+
exitCode: 0,
|
|
11
|
+
};
|
|
12
|
+
};
|
package/src/report/json.js
CHANGED
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
* Returns the results of a cruise in JSON
|
|
3
3
|
*
|
|
4
4
|
* @param {import("../../types/cruise-result").ICruiseResult} pResults
|
|
5
|
-
* @returns {import("
|
|
5
|
+
* @returns {import("../..").IReporterOutput}
|
|
6
6
|
*/
|
|
7
|
-
module.exports = (pResults)
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
module.exports = function json(pResults) {
|
|
8
|
+
return {
|
|
9
|
+
output: JSON.stringify(pResults, null, " "),
|
|
10
|
+
exitCode: 0,
|
|
11
|
+
};
|
|
12
|
+
};
|
package/src/report/markdown.js
CHANGED
|
@@ -73,9 +73,9 @@ function formatRulesSummary(pCruiseResult, pIncludeIgnoredInSummary) {
|
|
|
73
73
|
)
|
|
74
74
|
.reduce(
|
|
75
75
|
(pAll, pRule) =>
|
|
76
|
-
|
|
76
|
+
`${pAll}|${severity2Icon(pRule.severity)} _${pRule.name}_|**${
|
|
77
77
|
pRule.count
|
|
78
|
-
}**|**${pRule.ignoredCount}**|${pRule.comment}|\n
|
|
78
|
+
}**|**${pRule.ignoredCount}**|${pRule.comment}|\n`,
|
|
79
79
|
lTableHead
|
|
80
80
|
);
|
|
81
81
|
}
|
|
@@ -164,9 +164,11 @@ function report(pResults, pOptions) {
|
|
|
164
164
|
*
|
|
165
165
|
* @param {import("../../types/cruise-result").ICruiseResult} pResults
|
|
166
166
|
* @param {import("../../types/reporter-options").IMarkdownReporterOptions} pOptions
|
|
167
|
-
* @returns {import("
|
|
167
|
+
* @returns {import("../..").IReporterOutput}
|
|
168
168
|
*/
|
|
169
|
-
module.exports = (pResults, pOptions)
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
169
|
+
module.exports = function markdown(pResults, pOptions) {
|
|
170
|
+
return {
|
|
171
|
+
output: report(pResults, pOptions),
|
|
172
|
+
exitCode: 0,
|
|
173
|
+
};
|
|
174
|
+
};
|
package/src/report/mermaid.js
CHANGED
|
@@ -4,7 +4,8 @@ const REPORT_DEFAULTS = {
|
|
|
4
4
|
minify: true,
|
|
5
5
|
};
|
|
6
6
|
|
|
7
|
-
const renderNode = (pNode, pText) =>
|
|
7
|
+
const renderNode = (pNode, pText) =>
|
|
8
|
+
`${pNode}["${pText.length > 0 ? pText : " "}"]`;
|
|
8
9
|
|
|
9
10
|
const renderEdge = (pFrom, pTo) => `${pFrom.node}-->${pTo.node}`;
|
|
10
11
|
|
|
@@ -12,7 +13,7 @@ const renderEdges = (pEdges) =>
|
|
|
12
13
|
pEdges.map((pEdge) => renderEdge(pEdge.from, pEdge.to)).join("\n");
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
|
-
* @param {import('
|
|
16
|
+
* @param {import('../..').ICruiseResult} pCruiseResult
|
|
16
17
|
* @param {Map<string, string>} pNamesHashMap
|
|
17
18
|
*/
|
|
18
19
|
function convertEdgeSources(pCruiseResult, pNamesHashMap) {
|
|
@@ -58,7 +59,7 @@ function renderSubgraphs(pSource, pOptions, pDepth = 0) {
|
|
|
58
59
|
}
|
|
59
60
|
|
|
60
61
|
/**
|
|
61
|
-
* @param {import('
|
|
62
|
+
* @param {import('../..').ICruiseResult} pCruiseResult
|
|
62
63
|
* @param {Map<string, string>} pNamesHashMap
|
|
63
64
|
*/
|
|
64
65
|
function convertSubgraphSources(pCruiseResult, pNamesHashMap) {
|
|
@@ -99,7 +100,7 @@ function focusHighlights(pModules, pNamesHashMap) {
|
|
|
99
100
|
)
|
|
100
101
|
.reduce((pAll, pModule) => {
|
|
101
102
|
const lSource = pNamesHashMap.get(pModule.source);
|
|
102
|
-
return
|
|
103
|
+
return `${pAll}\nstyle ${lSource} ${lHighLightStyle}`;
|
|
103
104
|
}, "");
|
|
104
105
|
}
|
|
105
106
|
|
|
@@ -140,7 +141,7 @@ function hashModuleNames(pModules, pMinify) {
|
|
|
140
141
|
}
|
|
141
142
|
|
|
142
143
|
/**
|
|
143
|
-
* @param {import('
|
|
144
|
+
* @param {import('../..').ICruiseResult} pCruiseResult
|
|
144
145
|
* @param {import("../../types/reporter-options").IMermaidReporterOptions} pOptions
|
|
145
146
|
*/
|
|
146
147
|
function renderMermaidSource(pCruiseResult, pOptions) {
|
|
@@ -159,11 +160,13 @@ ${focusHighlights(pCruiseResult.modules, lNamesHashMap)}`;
|
|
|
159
160
|
/**
|
|
160
161
|
* mermaid reporter
|
|
161
162
|
*
|
|
162
|
-
* @param {import('
|
|
163
|
+
* @param {import('../..').ICruiseResult} pCruiseResult
|
|
163
164
|
* @param {import("../../types/reporter-options").IMermaidReporterOptions} pOptions
|
|
164
|
-
* @return {import('
|
|
165
|
+
* @return {import('../..').IReporterOutput}
|
|
165
166
|
*/
|
|
166
|
-
module.exports = (pCruiseResult, pOptions)
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
167
|
+
module.exports = function mermaid(pCruiseResult, pOptions) {
|
|
168
|
+
return {
|
|
169
|
+
output: renderMermaidSource(pCruiseResult, pOptions),
|
|
170
|
+
exitCode: 0,
|
|
171
|
+
};
|
|
172
|
+
};
|
package/src/report/metrics.js
CHANGED
|
@@ -3,7 +3,7 @@ const chalk = require("chalk");
|
|
|
3
3
|
const utl = require("./utl");
|
|
4
4
|
|
|
5
5
|
const DECIMAL_BASE = 10;
|
|
6
|
-
const METRIC_WIDTH =
|
|
6
|
+
const METRIC_WIDTH = 5;
|
|
7
7
|
const COMPONENT_HEADER = "name";
|
|
8
8
|
|
|
9
9
|
function getHeader(pMaxNameWidth) {
|
|
@@ -11,7 +11,7 @@ function getHeader(pMaxNameWidth) {
|
|
|
11
11
|
METRIC_WIDTH + 1
|
|
12
12
|
)} ${"Ca".padStart(METRIC_WIDTH + 1)} ${"Ce".padStart(
|
|
13
13
|
METRIC_WIDTH + 1
|
|
14
|
-
)}
|
|
14
|
+
)} ${"I (%)".padStart(METRIC_WIDTH + 1)}`;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
function getDemarcationLine(pMaxNameWidth) {
|
|
@@ -19,7 +19,7 @@ function getDemarcationLine(pMaxNameWidth) {
|
|
|
19
19
|
METRIC_WIDTH + 1
|
|
20
20
|
)} ${"-".repeat(METRIC_WIDTH + 1)} ${"-".repeat(
|
|
21
21
|
METRIC_WIDTH + 1
|
|
22
|
-
)}
|
|
22
|
+
)} ${"-".repeat(METRIC_WIDTH + 1)}`;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
function getMetricsTable(pMetrics, pMaxNameWidth) {
|
|
@@ -38,8 +38,7 @@ function getMetricsTable(pMetrics, pMaxNameWidth) {
|
|
|
38
38
|
.padStart(METRIC_WIDTH)} ${efferentCouplings
|
|
39
39
|
.toString(DECIMAL_BASE)
|
|
40
40
|
.padStart(METRIC_WIDTH)} ${utl
|
|
41
|
-
.
|
|
42
|
-
.toString(DECIMAL_BASE)
|
|
41
|
+
.formatPercentage(instability)
|
|
43
42
|
.padStart(METRIC_WIDTH)}`
|
|
44
43
|
);
|
|
45
44
|
}
|
|
@@ -113,11 +112,11 @@ function transformMetricsToTable(
|
|
|
113
112
|
* Potential future features:
|
|
114
113
|
* - additional output formats (csv?, html?)
|
|
115
114
|
*
|
|
116
|
-
* @param {import('
|
|
115
|
+
* @param {import('../..').ICruiseResult} pCruiseResult -
|
|
117
116
|
* @param {import("../../types/reporter-options").IMetricsReporterOptions} pReporterOptions
|
|
118
|
-
* @return {import('
|
|
117
|
+
* @return {import('../..').IReporterOutput} -
|
|
119
118
|
*/
|
|
120
|
-
module.exports = (pCruiseResult, pReporterOptions)
|
|
119
|
+
module.exports = function metrics(pCruiseResult, pReporterOptions) {
|
|
121
120
|
const lReporterOptions = pReporterOptions || {};
|
|
122
121
|
if (pCruiseResult.folders) {
|
|
123
122
|
return {
|
|
@@ -2,13 +2,14 @@ const has = require("lodash/has");
|
|
|
2
2
|
|
|
3
3
|
function isValidPlugin(pPluginFunction) {
|
|
4
4
|
let lReturnValue = false;
|
|
5
|
-
/** @type {import('
|
|
5
|
+
/** @type {import('../..').ICruiseResult} */
|
|
6
6
|
const lMinimalCruiseResult = {
|
|
7
7
|
modules: [],
|
|
8
8
|
summary: {
|
|
9
9
|
error: 0,
|
|
10
10
|
info: 0,
|
|
11
11
|
warn: 0,
|
|
12
|
+
ignore: 0,
|
|
12
13
|
totalCruised: 0,
|
|
13
14
|
violations: [],
|
|
14
15
|
optionsUsed: {},
|
|
@@ -32,7 +33,9 @@ function getPluginReporter(pOutputType) {
|
|
|
32
33
|
// eslint-disable-next-line import/no-dynamic-require, node/global-require, security/detect-non-literal-require
|
|
33
34
|
lReturnValue = require(pOutputType);
|
|
34
35
|
} catch (pError) {
|
|
35
|
-
throw new Error(
|
|
36
|
+
throw new Error(
|
|
37
|
+
`Could not find reporter plugin '${pOutputType}' (or it isn't valid)`
|
|
38
|
+
);
|
|
36
39
|
}
|
|
37
40
|
if (!isValidPlugin(lReturnValue)) {
|
|
38
41
|
throw new Error(`${pOutputType} is not a valid plugin`);
|
package/src/report/teamcity.js
CHANGED
|
@@ -89,9 +89,9 @@ function formatReachabilityViolation(pViolation) {
|
|
|
89
89
|
function formatInstabilityViolation(pViolation) {
|
|
90
90
|
return `${formatDependencyViolation(
|
|
91
91
|
pViolation
|
|
92
|
-
)} (instability: ${utl.
|
|
92
|
+
)} (instability: ${utl.formatPercentage(
|
|
93
93
|
pViolation.metrics.from.instability
|
|
94
|
-
)}
|
|
94
|
+
)} -> ${utl.formatPercentage(pViolation.metrics.to.instability)})`;
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
function bakeViolationMessage(pViolation) {
|
|
@@ -140,10 +140,10 @@ function reportViolations(pViolations, pIgnoredCount) {
|
|
|
140
140
|
* - for each violated rule in the passed results: an `inspectionType` with the name and comment of that rule
|
|
141
141
|
* - for each violation in the passed results: an `inspection` with the violated rule name and the tos and froms
|
|
142
142
|
*
|
|
143
|
-
* @param {import("
|
|
144
|
-
* @returns {import("
|
|
143
|
+
* @param {import("../..").ICruiseResult} pResults
|
|
144
|
+
* @returns {import("../..").IReporterOutput}
|
|
145
145
|
*/
|
|
146
|
-
module.exports = (pResults)
|
|
146
|
+
module.exports = function teamcity(pResults) {
|
|
147
147
|
// this is the documented way to get tsm to emit strings
|
|
148
148
|
// Alternatively we could've used the 'low level API', which
|
|
149
149
|
// involves creating new `Message`s and stringifying those.
|
package/src/report/text.js
CHANGED
|
@@ -82,9 +82,11 @@ function report(pResults, pOptions) {
|
|
|
82
82
|
* - for each dependency the from and the two, separated by an arrow.
|
|
83
83
|
* @param {import("../../types/cruise-result").ICruiseResult} pResults
|
|
84
84
|
* @param {import("../../types/reporter-options").ITextReporterOptions} pOptions
|
|
85
|
-
* @returns {import("
|
|
85
|
+
* @returns {import("../..").IReporterOutput}
|
|
86
86
|
*/
|
|
87
|
-
module.exports = (pResults, pOptions)
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
87
|
+
module.exports = function text(pResults, pOptions) {
|
|
88
|
+
return {
|
|
89
|
+
output: report(pResults, pOptions || {}),
|
|
90
|
+
exitCode: 0,
|
|
91
|
+
};
|
|
92
|
+
};
|
|
@@ -45,5 +45,6 @@ function addIncidences(pFromList) {
|
|
|
45
45
|
/*
|
|
46
46
|
|
|
47
47
|
*/
|
|
48
|
-
module.exports = (pFromList)
|
|
49
|
-
pFromList.sort(compareOnSource).map(addIncidences(pFromList));
|
|
48
|
+
module.exports = function transformDependenciesToIncidences(pFromList) {
|
|
49
|
+
return pFromList.sort(compareOnSource).map(addIncidences(pFromList));
|
|
50
|
+
};
|
package/src/report/utl/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}
|
|
1
|
+
// eslint-disable-next-line no-undefined
|
|
2
|
+
const formatPercentage = new Intl.NumberFormat(undefined, { style: "percent" })
|
|
3
|
+
.format;
|
|
5
4
|
|
|
6
5
|
function formatViolation(
|
|
7
6
|
pViolation,
|
|
@@ -13,4 +12,4 @@ function formatViolation(
|
|
|
13
12
|
);
|
|
14
13
|
}
|
|
15
14
|
|
|
16
|
-
module.exports = { formatViolation,
|
|
15
|
+
module.exports = { formatViolation, formatPercentage };
|
|
@@ -4,8 +4,8 @@ const matchers = require("./matchers");
|
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
*
|
|
7
|
-
* @param {import("
|
|
8
|
-
* @param {import("
|
|
7
|
+
* @param {import("../..").IModule} pFrom
|
|
8
|
+
* @param {import("../..").IDependency} pTo
|
|
9
9
|
* @returns {(pRule) => boolean}
|
|
10
10
|
*/
|
|
11
11
|
function match(pFrom, pTo) {
|
package/types/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+

|