dependency-cruiser 17.3.10 → 17.4.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.
@@ -3,6 +3,7 @@ import { styleText } from "node:util";
3
3
  import {
4
4
  formatPercentage,
5
5
  formatViolation as _formatViolation,
6
+ formatDependencyTo,
6
7
  } from "./utl/index.mjs";
7
8
  import { findRuleByName } from "#graph-utl/rule-set.mjs";
8
9
  import wrapAndIndent from "#utl/wrap-and-indent.mjs";
@@ -29,8 +30,8 @@ function formatModuleViolation(pViolation) {
29
30
  return styleText("bold", pViolation.from);
30
31
  }
31
32
 
32
- function formatDependencyViolation(pViolation) {
33
- return `${styleText("bold", pViolation.from)} → ${styleText("bold", pViolation.to)}`;
33
+ function formatDependencyViolation(pViolation, pOptions) {
34
+ return `${styleText("bold", pViolation.from)} → ${styleText("bold", formatDependencyTo(pViolation, pOptions))}`;
34
35
  }
35
36
 
36
37
  function formatCycleViolation(pViolation) {
@@ -41,8 +42,8 @@ function formatReachabilityViolation(pViolation) {
41
42
  return `${styleText("bold", pViolation.from)} → ${styleText("bold", pViolation.to)}${formatMiniDependency(pViolation.via)}`;
42
43
  }
43
44
 
44
- function formatInstabilityViolation(pViolation) {
45
- return `${formatDependencyViolation(pViolation)}${EOL}${styleText(
45
+ function formatInstabilityViolation(pViolation, pOptions) {
46
+ return `${formatDependencyViolation(pViolation, pOptions)}${EOL}${styleText(
46
47
  "dim",
47
48
  wrapAndIndent(
48
49
  `instability: ${formatPercentage(pViolation.metrics.from.instability)} → ${formatPercentage(pViolation.metrics.to.instability)}`,
@@ -51,7 +52,7 @@ function formatInstabilityViolation(pViolation) {
51
52
  )}`;
52
53
  }
53
54
 
54
- function formatViolation(pViolation) {
55
+ function formatViolation(pViolation, pOptions) {
55
56
  const lViolationType2Formatter = {
56
57
  module: formatModuleViolation,
57
58
  dependency: formatDependencyViolation,
@@ -63,6 +64,7 @@ function formatViolation(pViolation) {
63
64
  pViolation,
64
65
  lViolationType2Formatter,
65
66
  formatDependencyViolation,
67
+ pOptions,
66
68
  );
67
69
 
68
70
  return (
@@ -115,7 +117,13 @@ function formatIgnoreWarning(pNumberOfIgnoredViolations) {
115
117
  return "";
116
118
  }
117
119
 
118
- function report(pResults, pLong) {
120
+ function report(pResults, pOptions) {
121
+ const lOptions = {
122
+ long: false,
123
+ showExternalModulesUnresolved: false,
124
+ showAliasedModulesUnresolved: false,
125
+ ...pOptions,
126
+ };
119
127
  const lNonIgnorableViolations = pResults.summary.violations.filter(
120
128
  (pViolation) => pViolation.rule.severity !== "ignore",
121
129
  );
@@ -132,8 +140,11 @@ function report(pResults, pLong) {
132
140
 
133
141
  return lNonIgnorableViolations
134
142
  .reverse()
135
- .map(addExplanation(pResults.summary.ruleSetUsed, pLong))
136
- .reduce((pAll, pThis) => `${pAll} ${formatViolation(pThis)}${EOL}`, EOL)
143
+ .map(addExplanation(pResults.summary.ruleSetUsed, lOptions.long))
144
+ .reduce(
145
+ (pAll, pThis) => `${pAll} ${formatViolation(pThis, lOptions)}${EOL}`,
146
+ EOL,
147
+ )
137
148
  .concat(formatSummary(pResults.summary))
138
149
  .concat(formatIgnoreWarning(pResults.summary.ignore))
139
150
  .concat(EOL);
@@ -154,7 +165,7 @@ function report(pResults, pLong) {
154
165
  */
155
166
  export default function error(pResults, pOptions) {
156
167
  return {
157
- output: report(pResults, (pOptions || {}).long),
168
+ output: report(pResults, pOptions || {}),
158
169
  exitCode: pResults.summary.error,
159
170
  };
160
171
  }
@@ -22,6 +22,8 @@ const REPORT_DEFAULTS = {
22
22
  detailsHeader: "### :fire: All violations",
23
23
  collapseDetails: true,
24
24
  collapsedMessage: "Violations found - click to expand",
25
+ showExternalModulesUnresolved: false,
26
+ showAliasedModulesUnresolved: false,
25
27
  noViolationsMessage:
26
28
  ":revolving_hearts: No violations found. Get gummy bears to celebrate.",
27
29
 
@@ -84,20 +86,21 @@ function formatRulesSummary(pCruiseResult, pIncludeIgnoredInSummary) {
84
86
  /**
85
87
  *
86
88
  * @param {import("../../types/cruise-result.mjs").IViolation[]} pViolations
87
- * @param {boolean} pIncludeIgnoredInDetails
89
+ * @param {object} pOptions
88
90
  * @return {string}
89
91
  */
90
- function formatViolations(pViolations, pIncludeIgnoredInDetails) {
92
+ function formatViolations(pViolations, pOptions) {
91
93
  const lTableHead = "|violated rule|module|to|\n|:---|:---|:---|\n";
92
94
 
93
95
  return pViolations
94
96
  .filter(
95
97
  (pViolation) =>
96
- pViolation.rule.severity !== "ignore" || pIncludeIgnoredInDetails,
98
+ pViolation.rule.severity !== "ignore" ||
99
+ pOptions.includeIgnoredInDetails,
97
100
  )
98
101
  .reduce((pAll, pViolation) => {
99
102
  const lFromExtras = determineFromExtras(pViolation);
100
- const lTo = determineTo(pViolation);
103
+ const lTo = determineTo(pViolation, pOptions);
101
104
 
102
105
  return `${pAll}|${severity2Icon(pViolation.rule.severity)} _${
103
106
  pViolation.rule.name
@@ -116,7 +119,7 @@ function details(pResults, pOptions) {
116
119
  }
117
120
  lReturnValue += `${formatViolations(
118
121
  pResults.summary.violations,
119
- pOptions.includeIgnoredInDetails,
122
+ pOptions,
120
123
  )}\n\n`;
121
124
  if (pOptions.collapseDetails) {
122
125
  lReturnValue += "</details>\n\n";
@@ -14,9 +14,11 @@ export function formatViolation(
14
14
  pViolation,
15
15
  pViolationType2Formatter,
16
16
  pDefaultFormatter,
17
+ pOptions,
17
18
  ) {
18
19
  return (pViolationType2Formatter[pViolation.type] || pDefaultFormatter)(
19
20
  pViolation,
21
+ pOptions,
20
22
  );
21
23
  }
22
24
 
@@ -105,3 +107,61 @@ export function getURLForModule(pModule, pPrefix, pSuffix) {
105
107
  }
106
108
  return pModule.source;
107
109
  }
110
+
111
+ /**
112
+ *
113
+ * @param {import("../../../types/shared-types.mjs").DependencyType[]} pDependencyTypes
114
+ * @returns {string}
115
+ */
116
+ export function getOneLetterDependencyType(pDependencyTypes) {
117
+ if (pDependencyTypes) {
118
+ if (
119
+ pDependencyTypes.some((pDependencyType) =>
120
+ pDependencyType.startsWith("npm"),
121
+ )
122
+ ) {
123
+ return "n";
124
+ }
125
+ if (pDependencyTypes.includes("aliased-subpath-import")) {
126
+ return "#";
127
+ }
128
+ if (pDependencyTypes.includes("aliased")) {
129
+ return "@";
130
+ }
131
+ if (pDependencyTypes.includes("core")) {
132
+ return "c";
133
+ }
134
+ if (pDependencyTypes.includes("export")) {
135
+ return "x";
136
+ }
137
+ if (pDependencyTypes.includes("local")) {
138
+ return ".";
139
+ }
140
+ if (
141
+ pDependencyTypes.some((pDependencyType) =>
142
+ pDependencyType.startsWith("type-"),
143
+ )
144
+ ) {
145
+ return "T";
146
+ }
147
+ }
148
+
149
+ return "";
150
+ }
151
+ export function formatDependencyTo(pViolation, pOptions) {
152
+ if (pViolation.unresolvedTo) {
153
+ const lDependencyTypes = pViolation?.dependencyTypes ?? [];
154
+ const lShowUnresolvedExternal =
155
+ pOptions?.showExternalModulesUnresolved &&
156
+ lDependencyTypes.some((pDependencyType) =>
157
+ pDependencyType.startsWith("npm"),
158
+ );
159
+ const lShowUnresolvedAliased =
160
+ pOptions?.showAliasedModulesUnresolved &&
161
+ lDependencyTypes.includes("aliased");
162
+ return lShowUnresolvedExternal || lShowUnresolvedAliased
163
+ ? pViolation.unresolvedTo
164
+ : pViolation.to;
165
+ }
166
+ return pViolation.to;
167
+ }