dependency-cruiser 17.3.2 → 17.3.3-beta-2
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/bin/depcruise-baseline.mjs +43 -43
- package/bin/depcruise-fmt.mjs +89 -89
- package/bin/dependency-cruise.mjs +171 -171
- package/configs/plugins/3d-reporter-plugin.mjs +36 -36
- package/configs/plugins/stats-reporter-plugin.mjs +51 -51
- package/configs/recommended-strict.cjs +5 -5
- package/configs/recommended-warn-only.cjs +5 -5
- package/configs/recommended.cjs +22 -22
- package/configs/rules/no-circular.cjs +10 -10
- package/configs/rules/no-deprecated-core.cjs +10 -10
- package/configs/rules/no-duplicate-dependency-types.cjs +17 -17
- package/configs/rules/no-non-package-json.cjs +11 -11
- package/configs/rules/no-orphans.cjs +18 -18
- package/configs/rules/not-to-deprecated.cjs +10 -10
- package/configs/rules/not-to-unresolvable.cjs +10 -10
- package/package.json +170 -170
- package/src/cache/cache.mjs +139 -139
- package/src/cache/content-strategy.mjs +88 -88
- package/src/cache/find-content-changes.mjs +58 -58
- package/src/cache/helpers.mjs +52 -52
- package/src/cache/metadata-strategy.mjs +83 -83
- package/src/cache/options-compatible.mjs +56 -109
- package/src/cli/assert-node-environment-suitable.mjs +7 -7
- package/src/cli/defaults.mjs +5 -5
- package/src/cli/format-meta-info.mjs +22 -22
- package/src/cli/format.mjs +28 -28
- package/src/cli/index.mjs +145 -145
- package/src/cli/init-config/build-config.mjs +94 -94
- package/src/cli/init-config/environment-helpers.mjs +77 -77
- package/src/cli/init-config/find-extensions.mjs +27 -27
- package/src/cli/init-config/get-user-input.mjs +151 -151
- package/src/cli/init-config/index.mjs +88 -88
- package/src/cli/init-config/normalize-init-options.mjs +47 -47
- package/src/cli/init-config/utl.mjs +4 -4
- package/src/cli/init-config/validators.mjs +10 -10
- package/src/cli/init-config/write-config.mjs +21 -21
- package/src/cli/init-config/write-run-scripts-to-manifest.mjs +103 -107
- package/src/cli/listeners/cli-feedback.mjs +49 -49
- package/src/cli/listeners/ndjson.mjs +66 -66
- package/src/cli/listeners/performance-log/format-helpers.mjs +63 -63
- package/src/cli/listeners/performance-log/handlers.mjs +56 -56
- package/src/cli/listeners/performance-log/index.mjs +37 -37
- package/src/cli/normalize-cli-options.mjs +182 -182
- package/src/cli/tools/wrap-stream-in-html.mjs +37 -37
- package/src/cli/utl/assert-file-existence.mjs +7 -7
- package/src/cli/utl/io.mjs +28 -31
- package/src/config-utl/extract-babel-config.mjs +69 -69
- package/src/config-utl/extract-depcruise-config/index.mjs +54 -54
- package/src/config-utl/extract-depcruise-config/merge-configs.mjs +63 -63
- package/src/config-utl/extract-depcruise-config/read-config.mjs +9 -9
- package/src/config-utl/extract-depcruise-options.mjs +9 -9
- package/src/config-utl/extract-known-violations.mjs +49 -49
- package/src/config-utl/extract-ts-config.mjs +46 -48
- package/src/config-utl/extract-webpack-resolve-config.mjs +88 -88
- package/src/config-utl/make-absolute.mjs +5 -5
- package/src/enrich/add-validations.mjs +13 -13
- package/src/enrich/derive/circular.mjs +49 -49
- package/src/enrich/derive/dependents.mjs +27 -27
- package/src/enrich/derive/folders/aggregate-to-folders.mjs +104 -104
- package/src/enrich/derive/folders/index.mjs +19 -19
- package/src/enrich/derive/folders/utl.mjs +18 -18
- package/src/enrich/derive/metrics/get-module-metrics.mjs +27 -27
- package/src/enrich/derive/metrics/index.mjs +8 -8
- package/src/enrich/derive/module-utl.mjs +18 -18
- package/src/enrich/derive/orphan/index.mjs +18 -18
- package/src/enrich/derive/orphan/is-orphan.mjs +9 -9
- package/src/enrich/derive/reachable.mjs +165 -168
- package/src/enrich/enrich-modules.mjs +25 -25
- package/src/enrich/index.mjs +15 -15
- package/src/enrich/soften-known-violations.mjs +90 -90
- package/src/enrich/summarize/add-rule-set-used.mjs +13 -13
- package/src/enrich/summarize/get-stats.mjs +17 -17
- package/src/enrich/summarize/index.mjs +18 -18
- package/src/enrich/summarize/is-same-violation.mjs +30 -30
- package/src/enrich/summarize/summarize-folders.mjs +35 -35
- package/src/enrich/summarize/summarize-modules.mjs +97 -97
- package/src/enrich/summarize/summarize-options.mjs +71 -71
- package/src/extract/acorn/estree-helpers.mjs +66 -66
- package/src/extract/acorn/extract-amd-deps.mjs +63 -64
- package/src/extract/acorn/extract-cjs-deps.mjs +83 -83
- package/src/extract/acorn/extract-es6-deps.mjs +54 -54
- package/src/extract/acorn/extract-stats.mjs +4 -4
- package/src/extract/acorn/extract.mjs +28 -28
- package/src/extract/acorn/parse.mjs +37 -37
- package/src/extract/clear-caches.mjs +7 -7
- package/src/extract/extract-dependencies.mjs +109 -109
- package/src/extract/extract-stats.mjs +21 -21
- package/src/extract/gather-initial-sources.mjs +64 -64
- package/src/extract/helpers.mjs +73 -71
- package/src/extract/index.mjs +120 -120
- package/src/extract/resolve/determine-dependency-types.mjs +166 -169
- package/src/extract/resolve/external-module-helpers.mjs +76 -76
- package/src/extract/resolve/get-manifest.mjs +79 -79
- package/src/extract/resolve/index.mjs +175 -164
- package/src/extract/resolve/is-built-in.mjs +22 -24
- package/src/extract/resolve/merge-manifests.mjs +43 -43
- package/src/extract/resolve/module-classifiers.mjs +229 -229
- package/src/extract/resolve/resolve-amd.mjs +44 -44
- package/src/extract/resolve/resolve-cjs.mjs +40 -40
- package/src/extract/resolve/resolve-helpers.mjs +20 -20
- package/src/extract/resolve/resolve.mjs +26 -26
- package/src/extract/swc/dependency-visitor.mjs +211 -211
- package/src/extract/swc/extract-swc-deps.mjs +4 -4
- package/src/extract/swc/extract.mjs +7 -7
- package/src/extract/swc/parse.mjs +12 -12
- package/src/extract/transpile/babel-wrap.mjs +9 -9
- package/src/extract/transpile/coffeescript-wrap.mjs +21 -21
- package/src/extract/transpile/index.mjs +47 -47
- package/src/extract/transpile/javascript-wrap.mjs +6 -6
- package/src/extract/transpile/livescript-wrap.mjs +5 -5
- package/src/extract/transpile/meta.mjs +80 -80
- package/src/extract/transpile/svelte-preprocess.mjs +73 -73
- package/src/extract/transpile/svelte-wrap.mjs +19 -19
- package/src/extract/transpile/try-import-available.mjs +26 -27
- package/src/extract/transpile/typescript-wrap.mjs +39 -39
- package/src/extract/transpile/vue-template-wrap.cjs +43 -43
- package/src/extract/tsc/extract-stats.mjs +4 -4
- package/src/extract/tsc/extract-typescript-deps.mjs +429 -398
- package/src/extract/tsc/extract.mjs +22 -22
- package/src/extract/tsc/parse.mjs +21 -21
- package/src/graph-utl/add-focus.mjs +35 -35
- package/src/graph-utl/compare.mjs +24 -24
- package/src/graph-utl/consolidate-module-dependencies.mjs +35 -35
- package/src/graph-utl/consolidate-modules.mjs +33 -33
- package/src/graph-utl/consolidate-to-folder.mjs +13 -13
- package/src/graph-utl/consolidate-to-pattern.mjs +34 -34
- package/src/graph-utl/filter-bank.mjs +74 -69
- package/src/graph-utl/indexed-module-graph.mjs +227 -225
- package/src/graph-utl/match-facade.mjs +3 -3
- package/src/graph-utl/rule-set.mjs +20 -20
- package/src/graph-utl/strip-self-transitions.mjs +6 -6
- package/src/main/cruise.mjs +81 -81
- package/src/main/files-and-dirs/normalize.mjs +7 -7
- package/src/main/format.mjs +11 -14
- package/src/main/helpers.mjs +25 -25
- package/src/main/index.mjs +8 -8
- package/src/main/options/assert-validity.mjs +100 -100
- package/src/main/options/defaults.mjs +11 -11
- package/src/main/options/normalize.mjs +158 -160
- package/src/main/report-wrap.mjs +37 -37
- package/src/main/resolve-options/normalize.mjs +127 -128
- package/src/main/rule-set/assert-validity.mjs +67 -73
- package/src/main/rule-set/normalize.mjs +81 -79
- package/src/meta.cjs +15 -16
- package/src/report/anon/anonymize-path-element.mjs +20 -34
- package/src/report/anon/anonymize-path.mjs +11 -11
- package/src/report/anon/index.mjs +119 -119
- package/src/report/anon/random-string.mjs +23 -23
- package/src/report/azure-devops.mjs +75 -99
- package/src/report/baseline.mjs +9 -9
- package/src/report/csv.mjs +13 -13
- package/src/report/d2.mjs +105 -105
- package/src/report/dot/default-theme.mjs +152 -152
- package/src/report/dot/index.mjs +146 -146
- package/src/report/dot/module-utl.mjs +72 -72
- package/src/report/dot/prepare-custom-level.mjs +20 -20
- package/src/report/dot/prepare-flat-level.mjs +11 -11
- package/src/report/dot/prepare-folder-level.mjs +12 -13
- package/src/report/dot/theming.mjs +73 -73
- package/src/report/dot-webpage/dot-module.mjs +36 -36
- package/src/report/dot-webpage/svg-in-html-snippets/script.cjs +208 -210
- package/src/report/dot-webpage/svg-in-html-snippets/style.css +51 -51
- package/src/report/dot-webpage/wrap-in-html.mjs +7 -7
- package/src/report/error-html/index.mjs +49 -49
- package/src/report/error-html/utl.mjs +99 -99
- package/src/report/error-long.mjs +1 -1
- package/src/report/error.mjs +93 -93
- package/src/report/html/index.mjs +48 -48
- package/src/report/identity.mjs +4 -4
- package/src/report/index.mjs +33 -33
- package/src/report/json.mjs +4 -4
- package/src/report/markdown.mjs +120 -120
- package/src/report/mermaid.mjs +111 -111
- package/src/report/metrics.mjs +185 -185
- package/src/report/null.mjs +4 -4
- package/src/report/plugins.mjs +41 -41
- package/src/report/teamcity.mjs +150 -150
- package/src/report/text.mjs +42 -42
- package/src/report/utl/dependency-to-incidence-transformer.mjs +32 -32
- package/src/report/utl/index.mjs +53 -53
- package/src/schema/configuration.validate.mjs +1 -0
- package/src/schema/cruise-result.validate.mjs +1 -0
- package/src/schema/utl.mjs +6 -0
- package/src/utl/array-util.mjs +25 -25
- package/src/utl/bus.mjs +12 -12
- package/src/utl/extract-root-module-name.cjs +8 -8
- package/src/utl/find-all-files.mjs +54 -54
- package/src/utl/get-extension.mjs +2 -2
- package/src/utl/object-util.mjs +21 -22
- package/src/utl/path-to-posix.mjs +5 -5
- package/src/utl/regex-util.mjs +20 -20
- package/src/utl/try-import.mjs +42 -41
- package/src/utl/try-require.cjs +23 -23
- package/src/utl/wrap-and-indent.mjs +33 -33
- package/src/validate/index.mjs +65 -65
- package/src/validate/match-dependency-rule.mjs +47 -47
- package/src/validate/match-folder-dependency-rule.mjs +27 -27
- package/src/validate/match-module-rule-helpers.mjs +76 -76
- package/src/validate/match-module-rule.mjs +12 -12
- package/src/validate/matchers.mjs +162 -162
- package/src/validate/rule-classifiers.mjs +9 -9
- package/src/validate/violates-required-rule.mjs +23 -23
- package/types/cache-options.d.mts +27 -27
- package/types/config-utl/extract-babel-config.d.mts +1 -1
- package/types/config-utl/extract-depcruise-config.d.mts +3 -3
- package/types/config-utl/extract-depcruise-options.d.mts +1 -1
- package/types/config-utl/extract-ts-config.d.mts +1 -1
- package/types/config-utl/extract-webpack-resolve-config.d.mts +3 -3
- package/types/configuration.d.mts +10 -10
- package/types/cruise-result.d.mts +414 -414
- package/types/dependency-cruiser.d.mts +52 -52
- package/types/filter-types.d.mts +45 -45
- package/types/options.d.mts +430 -430
- package/types/plugins/3d-reporter-plugin.d.mts +9 -9
- package/types/plugins/mermaid-reporter-plugin.d.mts +10 -10
- package/types/plugins/stats-reporter-plugin.d.mts +9 -9
- package/types/reporter-options.d.mts +196 -196
- package/types/resolve-options.d.mts +23 -23
- package/types/restrictions.d.mts +174 -174
- package/types/rule-set.d.mts +132 -132
- package/types/rule-summary.d.mts +14 -14
- package/types/shared-types.d.mts +89 -89
- package/types/strict-filter-types.d.mts +52 -52
- package/types/strict-options.d.mts +34 -34
- package/types/strict-restrictions.d.mts +25 -25
- package/types/strict-rule-set.d.mts +36 -36
- package/types/violations.d.mts +40 -40
- package/src/schema/README.md +0 -5
- package/src/schema/baseline-violations.schema.mjs +0 -1
- package/src/schema/configuration.schema.mjs +0 -1
- package/src/schema/cruise-result.schema.mjs +0 -1
- package/types/README.md +0 -1
package/src/report/markdown.mjs
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
aggregateViolations,
|
|
3
|
+
determineTo,
|
|
4
|
+
determineFromExtras,
|
|
5
5
|
} from "./error-html/utl.mjs";
|
|
6
6
|
import meta from "#meta.cjs";
|
|
7
7
|
|
|
8
8
|
const REPORT_DEFAULTS = {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
9
|
+
showTitle: true,
|
|
10
|
+
title: "## Forbidden dependency check - results",
|
|
11
|
+
|
|
12
|
+
showSummary: true,
|
|
13
|
+
showSummaryHeader: true,
|
|
14
|
+
summaryHeader: "### :chart_with_upwards_trend: Summary",
|
|
15
|
+
showStatsSummary: true,
|
|
16
|
+
showRulesSummary: true,
|
|
17
|
+
includeIgnoredInSummary: true,
|
|
18
|
+
|
|
19
|
+
showDetails: true,
|
|
20
|
+
includeIgnoredInDetails: true,
|
|
21
|
+
showDetailsHeader: true,
|
|
22
|
+
detailsHeader: "### :fire: All violations",
|
|
23
|
+
collapseDetails: true,
|
|
24
|
+
collapsedMessage: "Violations found - click to expand",
|
|
25
|
+
noViolationsMessage:
|
|
26
|
+
":revolving_hearts: No violations found. Get gummy bears to celebrate.",
|
|
27
|
+
|
|
28
|
+
showFooter: true,
|
|
29
|
+
footer: `---\n[dependency-cruiser@${
|
|
30
|
+
meta.version
|
|
31
|
+
}](https://www.github.com/sverweij/dependency-cruiser) / ${new Date().toISOString()}`,
|
|
32
32
|
};
|
|
33
33
|
|
|
34
34
|
/**
|
|
@@ -36,13 +36,13 @@ const REPORT_DEFAULTS = {
|
|
|
36
36
|
* @returns {string}
|
|
37
37
|
*/
|
|
38
38
|
function severity2Icon(pSeverity) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
const lSeverity2IconMap = new Map([
|
|
40
|
+
["error", ":exclamation:"],
|
|
41
|
+
["info", ":grey_exclamation:"],
|
|
42
|
+
["ignore", ":see_no_evil:"],
|
|
43
|
+
]);
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
return lSeverity2IconMap.get(pSeverity) || ":warning:";
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
/**
|
|
@@ -50,9 +50,9 @@ function severity2Icon(pSeverity) {
|
|
|
50
50
|
* @return {string}
|
|
51
51
|
*/
|
|
52
52
|
function formatStatsSummary(pSummary) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
const lSpacerLength = 4;
|
|
54
|
+
const lSpacer = " ".repeat(lSpacerLength);
|
|
55
|
+
return `**${pSummary.totalCruised}** modules${lSpacer}**${pSummary.totalDependenciesCruised}** dependencies${lSpacer}**${pSummary.error}** errors${lSpacer}**${pSummary.warn}** warnings${lSpacer}**${pSummary.info}** informational${lSpacer}**${pSummary.ignore}** ignored\n`;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
/**
|
|
@@ -61,24 +61,24 @@ function formatStatsSummary(pSummary) {
|
|
|
61
61
|
* @return {string}
|
|
62
62
|
*/
|
|
63
63
|
function formatRulesSummary(pCruiseResult, pIncludeIgnoredInSummary) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
64
|
+
const lTableHead =
|
|
65
|
+
"|rule|violations|ignored|explanation\n|:---|:---:|:---:|:---|\n";
|
|
66
|
+
|
|
67
|
+
return aggregateViolations(
|
|
68
|
+
pCruiseResult.summary.violations,
|
|
69
|
+
pCruiseResult.summary.ruleSetUsed,
|
|
70
|
+
)
|
|
71
|
+
.filter(
|
|
72
|
+
(pRule) =>
|
|
73
|
+
pRule.count > 0 || (pIncludeIgnoredInSummary && pRule.ignoredCount > 0),
|
|
74
|
+
)
|
|
75
|
+
.reduce(
|
|
76
|
+
(pAll, pRule) =>
|
|
77
|
+
`${pAll}|${severity2Icon(pRule.severity)} _${pRule.name}_|**${
|
|
78
|
+
pRule.count
|
|
79
|
+
}**|**${pRule.ignoredCount}**|${pRule.comment}|\n`,
|
|
80
|
+
lTableHead,
|
|
81
|
+
);
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
/**
|
|
@@ -88,60 +88,60 @@ function formatRulesSummary(pCruiseResult, pIncludeIgnoredInSummary) {
|
|
|
88
88
|
* @return {string}
|
|
89
89
|
*/
|
|
90
90
|
function formatViolations(pViolations, pIncludeIgnoredInDetails) {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
91
|
+
const lTableHead = "|violated rule|module|to|\n|:---|:---|:---|\n";
|
|
92
|
+
|
|
93
|
+
return pViolations
|
|
94
|
+
.filter(
|
|
95
|
+
(pViolation) =>
|
|
96
|
+
pViolation.rule.severity !== "ignore" || pIncludeIgnoredInDetails,
|
|
97
|
+
)
|
|
98
|
+
.reduce((pAll, pViolation) => {
|
|
99
|
+
const lFromExtras = determineFromExtras(pViolation);
|
|
100
|
+
const lTo = determineTo(pViolation);
|
|
101
|
+
|
|
102
|
+
return `${pAll}|${severity2Icon(pViolation.rule.severity)} _${
|
|
103
|
+
pViolation.rule.name
|
|
104
|
+
}_|${pViolation.from}${lFromExtras}|${lTo}|\n`;
|
|
105
|
+
}, lTableHead);
|
|
106
106
|
}
|
|
107
107
|
|
|
108
108
|
function details(pResults, pOptions) {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
109
|
+
let lReturnValue = "";
|
|
110
|
+
if (pResults.summary.violations.length > 0) {
|
|
111
|
+
if (pOptions.showDetailsHeader) {
|
|
112
|
+
lReturnValue += `${pOptions.detailsHeader}\n\n`;
|
|
113
|
+
}
|
|
114
|
+
if (pOptions.collapseDetails) {
|
|
115
|
+
lReturnValue += `<details><summary>${pOptions.collapsedMessage}</summary>\n\n`;
|
|
116
|
+
}
|
|
117
|
+
lReturnValue += `${formatViolations(
|
|
118
|
+
pResults.summary.violations,
|
|
119
|
+
pOptions.includeIgnoredInDetails,
|
|
120
|
+
)}\n\n`;
|
|
121
|
+
if (pOptions.collapseDetails) {
|
|
122
|
+
lReturnValue += "</details>\n\n";
|
|
123
|
+
}
|
|
124
|
+
} else {
|
|
125
|
+
lReturnValue += `${pOptions.noViolationsMessage}\n\n`;
|
|
126
|
+
}
|
|
127
|
+
return lReturnValue;
|
|
128
128
|
}
|
|
129
129
|
|
|
130
130
|
function summary(pResults, pOptions) {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
131
|
+
let lReturnValue = "";
|
|
132
|
+
|
|
133
|
+
if (pOptions.showSummaryHeader) {
|
|
134
|
+
lReturnValue += `${pOptions.summaryHeader}\n\n`;
|
|
135
|
+
}
|
|
136
|
+
lReturnValue += `${formatStatsSummary(pResults.summary)}\n\n`;
|
|
137
|
+
|
|
138
|
+
if (pResults.summary.violations.length > 0 && pOptions.showRulesSummary) {
|
|
139
|
+
lReturnValue += `${formatRulesSummary(
|
|
140
|
+
pResults,
|
|
141
|
+
pOptions.includeIgnoredInSummary,
|
|
142
|
+
)}\n\n`;
|
|
143
|
+
}
|
|
144
|
+
return lReturnValue;
|
|
145
145
|
}
|
|
146
146
|
|
|
147
147
|
/**
|
|
@@ -150,26 +150,26 @@ function summary(pResults, pOptions) {
|
|
|
150
150
|
* @returns {string}
|
|
151
151
|
*/
|
|
152
152
|
function report(pResults, pOptions) {
|
|
153
|
-
|
|
154
|
-
|
|
153
|
+
const lOptions = { ...REPORT_DEFAULTS, ...(pOptions || {}) };
|
|
154
|
+
let lReturnValue = "";
|
|
155
155
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
156
|
+
if (lOptions.showTitle) {
|
|
157
|
+
lReturnValue += `${lOptions.title}\n\n`;
|
|
158
|
+
}
|
|
159
159
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
160
|
+
if (lOptions.showSummary) {
|
|
161
|
+
lReturnValue += summary(pResults, lOptions);
|
|
162
|
+
}
|
|
163
163
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
164
|
+
if (lOptions.showDetails) {
|
|
165
|
+
lReturnValue += details(pResults, lOptions);
|
|
166
|
+
}
|
|
167
167
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
168
|
+
if (lOptions.showFooter) {
|
|
169
|
+
lReturnValue += `${lOptions.footer}\n\n`;
|
|
170
|
+
}
|
|
171
171
|
|
|
172
|
-
|
|
172
|
+
return lReturnValue;
|
|
173
173
|
}
|
|
174
174
|
|
|
175
175
|
/**
|
|
@@ -180,8 +180,8 @@ function report(pResults, pOptions) {
|
|
|
180
180
|
* @returns {import("../../types/dependency-cruiser.js").IReporterOutput}
|
|
181
181
|
*/
|
|
182
182
|
export default function markdown(pResults, pOptions) {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
183
|
+
return {
|
|
184
|
+
output: report(pResults, pOptions),
|
|
185
|
+
exitCode: 0,
|
|
186
|
+
};
|
|
187
187
|
}
|
package/src/report/mermaid.mjs
CHANGED
|
@@ -1,61 +1,61 @@
|
|
|
1
1
|
/* eslint-disable security/detect-object-injection */
|
|
2
2
|
const ACORN_DUMMY_VALUE = "✖";
|
|
3
3
|
const REPORT_DEFAULTS = {
|
|
4
|
-
|
|
4
|
+
minify: true,
|
|
5
5
|
};
|
|
6
6
|
|
|
7
7
|
const renderNode = (pNode, pText) =>
|
|
8
|
-
|
|
8
|
+
`${pNode}["${pText.length > 0 ? pText : " "}"]`;
|
|
9
9
|
|
|
10
10
|
const renderEdge = (pFrom, pTo) => `${pFrom.node}-->${pTo.node}`;
|
|
11
11
|
|
|
12
12
|
const renderEdges = (pEdges) =>
|
|
13
|
-
|
|
13
|
+
pEdges.map((pEdge) => renderEdge(pEdge.from, pEdge.to)).join("\n");
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* @param {import('../../types/dependency-cruiser').ICruiseResult} pCruiseResult
|
|
17
17
|
* @param {Map<string, string>} pNamesHashMap
|
|
18
18
|
*/
|
|
19
19
|
function convertEdgeSources(pCruiseResult, pNamesHashMap) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
20
|
+
return pCruiseResult.modules.flatMap((pModule) => {
|
|
21
|
+
const lFromNode = pNamesHashMap.get(pModule.source);
|
|
22
|
+
const lFrom = {
|
|
23
|
+
node: lFromNode,
|
|
24
|
+
text: pModule.source.split("/").slice(-1)[0],
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
return pModule.dependencies.map((pDependency) => {
|
|
28
|
+
const lToNode = pNamesHashMap.get(pDependency.resolved);
|
|
29
|
+
return {
|
|
30
|
+
from: lFrom,
|
|
31
|
+
to: {
|
|
32
|
+
node: lToNode,
|
|
33
|
+
text: pDependency.resolved.split("/").slice(-1)[0],
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
const indent = (pDepth, pMinify) => (pMinify ? "" : " ".repeat(pDepth));
|
|
41
41
|
|
|
42
42
|
const renderSubgraph = (pNode, pText, pChildren, pIndent) =>
|
|
43
|
-
|
|
43
|
+
`${pIndent}subgraph ${renderNode(pNode, pText)}
|
|
44
44
|
${pChildren}
|
|
45
45
|
${pIndent}end`;
|
|
46
46
|
|
|
47
47
|
function renderSubgraphs(pSource, pOptions, pDepth = 0) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
48
|
+
return Object.keys(pSource)
|
|
49
|
+
.map((pName) => {
|
|
50
|
+
const lIndent = indent(pDepth, pOptions.minify);
|
|
51
|
+
const source = pSource[pName];
|
|
52
|
+
const children = renderSubgraphs(source.children, pOptions, pDepth + 1);
|
|
53
|
+
if (children === "")
|
|
54
|
+
return `${lIndent}${renderNode(source.node, source.text)}`;
|
|
55
|
+
|
|
56
|
+
return renderSubgraph(source.node, source.text, children, lIndent);
|
|
57
|
+
})
|
|
58
|
+
.join("\n");
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
/**
|
|
@@ -63,25 +63,25 @@ function renderSubgraphs(pSource, pOptions, pDepth = 0) {
|
|
|
63
63
|
* @param {Map<string, string>} pNamesHashMap
|
|
64
64
|
*/
|
|
65
65
|
function convertSubgraphSources(pCruiseResult, pNamesHashMap) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
66
|
+
let lTree = {};
|
|
67
|
+
|
|
68
|
+
for (const lModule of pCruiseResult.modules) {
|
|
69
|
+
const lPaths = lModule.source.split("/");
|
|
70
|
+
|
|
71
|
+
lPaths.reduce((pChildren, pCurrentPath, pIndex) => {
|
|
72
|
+
if (!pChildren[pCurrentPath]) {
|
|
73
|
+
const node = lPaths.slice(0, pIndex + 1).join("/");
|
|
74
|
+
pChildren[pCurrentPath] = {
|
|
75
|
+
node: pNamesHashMap.get(node),
|
|
76
|
+
text: pCurrentPath,
|
|
77
|
+
children: {},
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
return pChildren[pCurrentPath].children;
|
|
81
|
+
}, lTree);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return lTree;
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
/**
|
|
@@ -89,27 +89,27 @@ function convertSubgraphSources(pCruiseResult, pNamesHashMap) {
|
|
|
89
89
|
* @param {Map<string, string>} pNamesHashMap
|
|
90
90
|
*/
|
|
91
91
|
function focusHighlights(pModules, pNamesHashMap) {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
92
|
+
const lHighLightStyle = "fill:lime,color:black";
|
|
93
|
+
|
|
94
|
+
return pModules
|
|
95
|
+
.filter(
|
|
96
|
+
(pModule) =>
|
|
97
|
+
pModule.matchesFocus ||
|
|
98
|
+
pModule.matchesReaches ||
|
|
99
|
+
pModule.matchesHighlight,
|
|
100
|
+
)
|
|
101
|
+
.reduce((pAll, pModule) => {
|
|
102
|
+
const lSource = pNamesHashMap.get(pModule.source);
|
|
103
|
+
return `${pAll}\nstyle ${lSource} ${lHighLightStyle}`;
|
|
104
|
+
}, "");
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
const hashToReadableNodeName = (pNode) =>
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
108
|
+
pNode
|
|
109
|
+
.replace(ACORN_DUMMY_VALUE, "__unknown__")
|
|
110
|
+
.replace(/^\.$|^\.\//g, "__currentPath__")
|
|
111
|
+
.replace(/^\.{2}$|^\.{2}\//g, "__prevPath__")
|
|
112
|
+
.replace(/[[\]/.@~-]/g, "_");
|
|
113
113
|
|
|
114
114
|
/**
|
|
115
115
|
* @param {import("../../types/cruise-result").IModule[]} pModules
|
|
@@ -117,38 +117,38 @@ const hashToReadableNodeName = (pNode) =>
|
|
|
117
117
|
* @return {Map<string, string>}
|
|
118
118
|
*/
|
|
119
119
|
function hashModuleNames(pModules, pMinify) {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
120
|
+
const lBase = 36;
|
|
121
|
+
const lNamesHashMap = new Map();
|
|
122
|
+
let lCount = 0;
|
|
123
|
+
|
|
124
|
+
for (const lModule of pModules) {
|
|
125
|
+
const lPaths = lModule.source.split("/");
|
|
126
|
+
|
|
127
|
+
for (let lIndex = 0; lIndex < lPaths.length; lIndex += 1) {
|
|
128
|
+
const lName = lPaths.slice(0, lIndex + 1).join("/");
|
|
129
|
+
if (!lNamesHashMap.has(lName)) {
|
|
130
|
+
// eslint-disable-next-line max-depth
|
|
131
|
+
if (pMinify) {
|
|
132
|
+
// toUpperCase because otherwise we generate e.g. o-->a and x-->a
|
|
133
|
+
// which are ambiguous in mermaid (o--> and x--> are edge shapes
|
|
134
|
+
// whereas e.g. a--> is node 'a' + the arrow shape -->). The only
|
|
135
|
+
// collision within alphanums are 'o' and 'x', so upper casing
|
|
136
|
+
// saves us...
|
|
137
|
+
// ref: https://mermaid.js.org/syntax/flowchart.html#new-arrow-types
|
|
138
|
+
// another way to solve this would be to place a space between the
|
|
139
|
+
// node name and the edge shape (x --> a) - however, this would make
|
|
140
|
+
// for a larger output, running into the mermaid max source size
|
|
141
|
+
// earlier
|
|
142
|
+
lNamesHashMap.set(lName, lCount.toString(lBase).toUpperCase());
|
|
143
|
+
lCount += 1;
|
|
144
|
+
} else {
|
|
145
|
+
lNamesHashMap.set(lName, hashToReadableNodeName(lName));
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return lNamesHashMap;
|
|
152
152
|
}
|
|
153
153
|
|
|
154
154
|
/**
|
|
@@ -156,12 +156,12 @@ function hashModuleNames(pModules, pMinify) {
|
|
|
156
156
|
* @param {import("../../types/reporter-options").IMermaidReporterOptions} pOptions
|
|
157
157
|
*/
|
|
158
158
|
function renderMermaidSource(pCruiseResult, pOptions) {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
159
|
+
const lOptions = { ...REPORT_DEFAULTS, ...(pOptions || {}) };
|
|
160
|
+
const lNamesHashMap = hashModuleNames(pCruiseResult.modules, lOptions.minify);
|
|
161
|
+
const lSubgraphs = convertSubgraphSources(pCruiseResult, lNamesHashMap);
|
|
162
|
+
const lEdges = convertEdgeSources(pCruiseResult, lNamesHashMap);
|
|
163
163
|
|
|
164
|
-
|
|
164
|
+
return `flowchart LR
|
|
165
165
|
|
|
166
166
|
${renderSubgraphs(lSubgraphs, lOptions)}
|
|
167
167
|
${renderEdges(lEdges)}
|
|
@@ -176,8 +176,8 @@ ${focusHighlights(pCruiseResult.modules, lNamesHashMap)}`;
|
|
|
176
176
|
* @return {import('../../types/dependency-cruiser').IReporterOutput}
|
|
177
177
|
*/
|
|
178
178
|
export default function mermaid(pCruiseResult, pOptions) {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
179
|
+
return {
|
|
180
|
+
output: renderMermaidSource(pCruiseResult, pOptions),
|
|
181
|
+
exitCode: 0,
|
|
182
|
+
};
|
|
183
183
|
}
|