dependency-cruiser 18.4.0 → 18.5.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/package.json +4 -4
- package/src/analyze/summarize/summarize-options.mjs +1 -0
- package/src/cache/cache.mjs +1 -1
- package/src/cache/options-compatible.mjs +2 -0
- package/src/cli/init-config/build-config.mjs +14 -0
- package/src/cli/init-config/config-template.mjs +5 -0
- package/src/cli/init-config/environment-helpers.mjs +5 -1
- package/src/cli/init-config/get-user-input.mjs +11 -0
- package/src/cli/init-config/index.mjs +1 -0
- package/src/cli/init-config/normalize-init-options.mjs +1 -1
- package/src/cli/init-config/types.d.mts +4 -0
- package/src/cli/init-config/write-run-scripts-to-manifest.mjs +2 -2
- package/src/extract/transpile/meta.mjs +2 -2
- package/src/extract/transpile/try-import-available.mjs +1 -1
- package/src/extract/tsc/extract-typescript-deps.mjs +57 -12
- package/src/extract/tsc/extract.mjs +2 -0
- package/src/main/options/defaults.mjs +1 -0
- package/src/main/options/normalize.mjs +4 -1
- package/src/meta.cjs +1 -1
- package/src/report/markdown.mjs +73 -11
- package/src/schema/configuration.validate.mjs +1 -1
- package/src/schema/cruise-result.validate.mjs +1 -1
- package/types/options.d.mts +5 -0
- package/types/reporter-options.d.mts +30 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dependency-cruiser",
|
|
3
|
-
"version": "18.
|
|
3
|
+
"version": "18.5.0",
|
|
4
4
|
"description": "Validate and visualize dependencies. With your rules. JavaScript, TypeScript, CoffeeScript. ES6, CommonJS, AMD.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"static analysis",
|
|
@@ -149,10 +149,10 @@
|
|
|
149
149
|
"acorn-loose": "8.5.2",
|
|
150
150
|
"acorn-walk": "8.3.5",
|
|
151
151
|
"commander": "15.0.0",
|
|
152
|
-
"enhanced-resolve": "5.
|
|
153
|
-
"ignore": "7.0.
|
|
152
|
+
"enhanced-resolve": "5.26.0",
|
|
153
|
+
"ignore": "7.0.11",
|
|
154
154
|
"interpret": "3.1.1",
|
|
155
|
-
"is-installed-globally": "1.0.
|
|
155
|
+
"is-installed-globally": "1.0.1",
|
|
156
156
|
"json5": "2.2.3",
|
|
157
157
|
"picomatch": "4.0.7",
|
|
158
158
|
"prompts": "2.4.2",
|
package/src/cache/cache.mjs
CHANGED
|
@@ -33,7 +33,7 @@ const EMPTY_CACHE = {
|
|
|
33
33
|
};
|
|
34
34
|
|
|
35
35
|
// see ./cache-rationales.md#cache-format-versioning for rationale & bump instructions
|
|
36
|
-
const CACHE_FORMAT_VERSION = 18.
|
|
36
|
+
const CACHE_FORMAT_VERSION = 18.5;
|
|
37
37
|
|
|
38
38
|
export default class Cache {
|
|
39
39
|
/** @type {(IRevisionData | null)=} */
|
|
@@ -52,6 +52,8 @@ export function optionsAreCompatible(pOldOptions, pNewOptions) {
|
|
|
52
52
|
pOldOptions.preserveSymlinks === pNewOptions.preserveSymlinks &&
|
|
53
53
|
pOldOptions.combinedDependencies === pNewOptions.combinedDependencies &&
|
|
54
54
|
pOldOptions.experimentalStats === pNewOptions.experimentalStats &&
|
|
55
|
+
pOldOptions.detectImportsInAmbientModules ===
|
|
56
|
+
pNewOptions.detectImportsInAmbientModules &&
|
|
55
57
|
pOldOptions.detectJSDocImports === pNewOptions.detectJSDocImports &&
|
|
56
58
|
pOldOptions.detectProcessBuiltinModuleCalls ===
|
|
57
59
|
pNewOptions.detectProcessBuiltinModuleCalls &&
|
|
@@ -73,6 +73,16 @@ function buildDetectJSDocumentImportsAttribute(pInitOptions) {
|
|
|
73
73
|
: "// detectJSDocImports: true,";
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
+
/**
|
|
77
|
+
* @param {IInitConfig} pInitOptions
|
|
78
|
+
* @returns {string}
|
|
79
|
+
*/
|
|
80
|
+
function buildDetectImportsInAmbientModulesAttribute(pInitOptions) {
|
|
81
|
+
return pInitOptions.detectImportsInAmbientModules
|
|
82
|
+
? "detectImportsInAmbientModules: true,"
|
|
83
|
+
: "// detectImportsInAmbientModules: true,";
|
|
84
|
+
}
|
|
85
|
+
|
|
76
86
|
/**
|
|
77
87
|
*
|
|
78
88
|
* @param {IInitConfig} pInitOptions
|
|
@@ -224,6 +234,10 @@ export default function buildConfig(pInitOptions) {
|
|
|
224
234
|
"{{detectJSDocImportsAttribute}}",
|
|
225
235
|
buildDetectJSDocumentImportsAttribute(pInitOptions),
|
|
226
236
|
)
|
|
237
|
+
.replace(
|
|
238
|
+
"{{detectImportsInAmbientModulesAttribute}}",
|
|
239
|
+
buildDetectImportsInAmbientModulesAttribute(pInitOptions),
|
|
240
|
+
)
|
|
227
241
|
.replace(
|
|
228
242
|
"{{detectProcessBuiltinModuleCalls}}",
|
|
229
243
|
buildDetectProcessBuiltinModuleCalls(pInitOptions),
|
|
@@ -227,6 +227,11 @@ module.exports = {
|
|
|
227
227
|
// to be installed in the same spot you run dependency-cruiser from.
|
|
228
228
|
{{detectJSDocImportsAttribute}}
|
|
229
229
|
|
|
230
|
+
// false: don't look at imports in ambient module declarations (the default)
|
|
231
|
+
// true: detect imports, re-exports and import-equals declarations inside
|
|
232
|
+
// ambient modules and namespaces. Implies parser: 'tsc'.
|
|
233
|
+
{{detectImportsInAmbientModulesAttribute}}
|
|
234
|
+
|
|
230
235
|
// false: don't look at process.getBuiltinModule calls (the default)
|
|
231
236
|
// true: dependency-cruiser will detect calls to process.getBuiltinModule/
|
|
232
237
|
// globalThis.process.getBuiltinModule as imports.
|
|
@@ -105,6 +105,10 @@ export function isLikelyMonoRepo(pFolderNames = getFolderNames(process.cwd())) {
|
|
|
105
105
|
return pFolderNames.includes("packages");
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
+
/**
|
|
109
|
+
* @param {Record<string,any>} [pManifest]
|
|
110
|
+
* @returns
|
|
111
|
+
*/
|
|
108
112
|
function getPackageManager(pManifest) {
|
|
109
113
|
let lReturnValue = "";
|
|
110
114
|
try {
|
|
@@ -119,7 +123,7 @@ function getPackageManager(pManifest) {
|
|
|
119
123
|
}
|
|
120
124
|
|
|
121
125
|
/**
|
|
122
|
-
* @param {Record<string,any>} pManifest
|
|
126
|
+
* @param {Record<string,any>} [pManifest]
|
|
123
127
|
* @returns {boolean}
|
|
124
128
|
*/
|
|
125
129
|
export function likelyUsesBun(pManifest) {
|
|
@@ -21,6 +21,10 @@ import {
|
|
|
21
21
|
import { validateLocation } from "./validators.mjs";
|
|
22
22
|
import { isAvailable as tscIsAvailable } from "#extract/tsc/parse.mjs";
|
|
23
23
|
|
|
24
|
+
/**
|
|
25
|
+
* @param {string} pString
|
|
26
|
+
* @returns {{title:string;value:string}}
|
|
27
|
+
*/
|
|
24
28
|
function toPromptChoice(pString) {
|
|
25
29
|
return {
|
|
26
30
|
title: pString,
|
|
@@ -116,6 +120,13 @@ const QUESTIONS = [
|
|
|
116
120
|
message: "Do you want to detect JSDoc imports (slightly slower)?",
|
|
117
121
|
initial: false,
|
|
118
122
|
},
|
|
123
|
+
{
|
|
124
|
+
name: "detectImportsInAmbientModules",
|
|
125
|
+
type: () => (tscIsAvailable() ? "confirm" : false),
|
|
126
|
+
message:
|
|
127
|
+
"Do you want to detect imports inside ambient modules (slightly slower)?",
|
|
128
|
+
initial: false,
|
|
129
|
+
},
|
|
119
130
|
{
|
|
120
131
|
name: "detectProcessBuiltinModuleCalls",
|
|
121
132
|
type: "confirm",
|
|
@@ -46,6 +46,7 @@ function getOneShotConfig(pOneShotConfigId) {
|
|
|
46
46
|
useTsConfig: hasTSConfigCandidates(),
|
|
47
47
|
tsConfig: getTSConfigCandidates().shift(),
|
|
48
48
|
detectJSDocImports: false,
|
|
49
|
+
detectImportsInAmbientModules: false,
|
|
49
50
|
detectProcessBuiltinModuleCalls: true,
|
|
50
51
|
tsPreCompilationDeps: hasTSConfigCandidates(),
|
|
51
52
|
useWebpackConfig: hasWebpackConfigCandidates(),
|
|
@@ -20,7 +20,7 @@ function usesTypeScript(pInitOptions, pExtensions) {
|
|
|
20
20
|
return Boolean(
|
|
21
21
|
pInitOptions.tsConfig ||
|
|
22
22
|
pInitOptions.tsPreCompilationDeps ||
|
|
23
|
-
(pExtensions || []).some((pExtension) =>
|
|
23
|
+
(pExtensions /* c8 ignore next */ || []).some((pExtension) =>
|
|
24
24
|
[".ts", ".tsx", ".d.ts", ".mts", ".d.mts", ".cts", ".d.cts"].includes(
|
|
25
25
|
pExtension,
|
|
26
26
|
),
|
|
@@ -36,6 +36,10 @@ export interface IInitConfig {
|
|
|
36
36
|
* Whether or not to detect JSDoc imports
|
|
37
37
|
*/
|
|
38
38
|
detectJSDocImports?: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Whether or not to detect imports in ambient module and namespace declarations
|
|
41
|
+
*/
|
|
42
|
+
detectImportsInAmbientModules?: boolean;
|
|
39
43
|
/**
|
|
40
44
|
* Whether or not to detect calls to `process.getBuiltinModule`/
|
|
41
45
|
* `globalThis.process.getBuiltinModule` as imports
|
|
@@ -72,8 +72,8 @@ export function compileRunScripts(pInitOptions) {
|
|
|
72
72
|
|
|
73
73
|
lReturnValue = {
|
|
74
74
|
depcruise: `dependency-cruiser ${lSourceLocations} ${lTestLocations}`,
|
|
75
|
-
"depcruise:graph": `dependency-cruiser ${lSourceLocations} --include-only '${lSourceLocationRE}' --output-type dot
|
|
76
|
-
"depcruise:graph:dev": `dependency-cruiser ${lSourceLocations} --include-only '${lSourceLocationRE}' --prefix vscode://file/$(pwd)/ --output-type dot
|
|
75
|
+
"depcruise:graph": `dependency-cruiser ${lSourceLocations} --include-only '${lSourceLocationRE}' --output-type dot-webpage > dependency-graph.html`,
|
|
76
|
+
"depcruise:graph:dev": `dependency-cruiser ${lSourceLocations} --include-only '${lSourceLocationRE}' --prefix vscode://file/$(pwd)/ --output-type dot-webpage | browser`,
|
|
77
77
|
"depcruise:graph:archi": `dependency-cruiser ${lSourceLocations} --include-only '${lSourceLocationRE}' --output-type archi | dot -T svg | depcruise-wrap-stream-in-html > high-level-dependency-graph.html`,
|
|
78
78
|
"depcruise:html": `dependency-cruiser ${lSourceLocations} ${lTestLocations} --progress --output-type err-html --output-to dependency-violation-report.html`,
|
|
79
79
|
"depcruise:text": `dependency-cruiser ${lSourceLocations} ${lTestLocations} --progress --output-type text`,
|
|
@@ -30,8 +30,8 @@ function gotCoffee() {
|
|
|
30
30
|
tryImportAvailable(
|
|
31
31
|
"coffeescript",
|
|
32
32
|
meta.supportedTranspilers.coffeescript,
|
|
33
|
+
/* c8 ignore start */
|
|
33
34
|
) ||
|
|
34
|
-
/* c8 ignore start */
|
|
35
35
|
// fallback for ancient versions of the coffeescript compilers
|
|
36
36
|
tryImportAvailable(
|
|
37
37
|
"coffee-script",
|
|
@@ -96,7 +96,7 @@ export const EXTENSION2AVAILABLE = new Map([
|
|
|
96
96
|
[".d.mts", TRANSPILER2AVAILABLE.typescript],
|
|
97
97
|
[
|
|
98
98
|
".vue",
|
|
99
|
-
TRANSPILER2AVAILABLE["vue-template-compiler"] ||
|
|
99
|
+
TRANSPILER2AVAILABLE["vue-template-compiler"] /* c8 ignore next */ ||
|
|
100
100
|
TRANSPILER2AVAILABLE["@vue/compiler-sfc"],
|
|
101
101
|
],
|
|
102
102
|
[".svelte", TRANSPILER2AVAILABLE.svelte],
|
|
@@ -9,7 +9,7 @@ const SCOPED_PACKAGE_RE = "@[^/]+(?:/[^/]+)";
|
|
|
9
9
|
const ROOT_MODULE_RE = new RegExp(`^(${SCOPED_PACKAGE_RE}|${PACKAGE_RE})`, "g");
|
|
10
10
|
|
|
11
11
|
function extractRootModuleName(pModuleName) {
|
|
12
|
-
return (pModuleName.match(ROOT_MODULE_RE) || []).shift();
|
|
12
|
+
return (pModuleName.match(ROOT_MODULE_RE) || /* c8 ignore next */ []).shift();
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
function getVersion(pModuleName) {
|
|
@@ -55,11 +55,53 @@ function isTypeOnlyExport(pStatement) {
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
/*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
58
|
+
* The extractImport* below take their statements from getStatements, because
|
|
59
|
+
* imports and exports are allowed in one place besides the top level: inside a
|
|
60
|
+
* module block, which is what `declare module "some-package" { ... }` and
|
|
61
|
+
* `declare namespace Thing { ... }` compile to.
|
|
61
62
|
*/
|
|
62
63
|
|
|
64
|
+
/**
|
|
65
|
+
* Get the statements of the passed AST node, plus the statements of any module
|
|
66
|
+
* blocks nested in it
|
|
67
|
+
*
|
|
68
|
+
* @param {Node} pAST - an AST node with statements
|
|
69
|
+
* @returns {Node[]} - the node's statements, flattened over module blocks
|
|
70
|
+
*/
|
|
71
|
+
function getModuleBlock(pStatement) {
|
|
72
|
+
if (pStatement.kind !== typescript.SyntaxKind.ModuleDeclaration) {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// A qualified name nests: `declare namespace A.B {}` is a ModuleDeclaration
|
|
77
|
+
// whose body is another ModuleDeclaration, and only the innermost one holds
|
|
78
|
+
// the block.
|
|
79
|
+
let lBody = pStatement.body;
|
|
80
|
+
|
|
81
|
+
while (lBody?.kind === typescript.SyntaxKind.ModuleDeclaration) {
|
|
82
|
+
lBody = lBody.body;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return lBody?.kind === typescript.SyntaxKind.ModuleBlock ? lBody : null;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function getStatements(pAST, pDetectImportsInAmbientModules) {
|
|
89
|
+
if (!pDetectImportsInAmbientModules) {
|
|
90
|
+
return pAST.statements ?? [];
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return (pAST.statements ?? []).flatMap((pStatement) => {
|
|
94
|
+
const lModuleBlock = getModuleBlock(pStatement);
|
|
95
|
+
|
|
96
|
+
return lModuleBlock
|
|
97
|
+
? [
|
|
98
|
+
pStatement,
|
|
99
|
+
...getStatements(lModuleBlock, pDetectImportsInAmbientModules),
|
|
100
|
+
]
|
|
101
|
+
: [pStatement];
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
63
105
|
/**
|
|
64
106
|
* Get all import statements from the top level AST node
|
|
65
107
|
*
|
|
@@ -67,8 +109,8 @@ function isTypeOnlyExport(pStatement) {
|
|
|
67
109
|
* @returns {{module: string; moduleSystem: string; exoticallyRequired: boolean; dependencyTypes?: string[];}[]} -
|
|
68
110
|
* all import statements in the (top level) AST node
|
|
69
111
|
*/
|
|
70
|
-
function extractImports(pAST) {
|
|
71
|
-
return pAST
|
|
112
|
+
function extractImports(pAST, pDetectImportsInAmbientModules) {
|
|
113
|
+
return getStatements(pAST, pDetectImportsInAmbientModules)
|
|
72
114
|
.filter(
|
|
73
115
|
(pStatement) =>
|
|
74
116
|
pStatement.kind === typescript.SyntaxKind.ImportDeclaration &&
|
|
@@ -91,8 +133,8 @@ function extractImports(pAST) {
|
|
|
91
133
|
* @returns {{module: string; moduleSystem: string; exoticallyRequired: boolean; dependencyTypes?: string[];}[]} -
|
|
92
134
|
* all export statements in the (top level) AST node
|
|
93
135
|
*/
|
|
94
|
-
function extractExports(pAST) {
|
|
95
|
-
return pAST
|
|
136
|
+
function extractExports(pAST, pDetectImportsInAmbientModules) {
|
|
137
|
+
return getStatements(pAST, pDetectImportsInAmbientModules)
|
|
96
138
|
.filter(
|
|
97
139
|
(pStatement) =>
|
|
98
140
|
pStatement.kind === typescript.SyntaxKind.ExportDeclaration &&
|
|
@@ -119,8 +161,8 @@ function extractExports(pAST) {
|
|
|
119
161
|
* @returns {{module: string, moduleSystem: string;exoticallyRequired: boolean;}[]} - all import equals statements in the
|
|
120
162
|
* (top level) AST node
|
|
121
163
|
*/
|
|
122
|
-
function extractImportEquals(pAST) {
|
|
123
|
-
return pAST
|
|
164
|
+
function extractImportEquals(pAST, pDetectImportsInAmbientModules) {
|
|
165
|
+
return getStatements(pAST, pDetectImportsInAmbientModules)
|
|
124
166
|
.filter(
|
|
125
167
|
(pStatement) =>
|
|
126
168
|
pStatement.kind === typescript.SyntaxKind.ImportEqualsDeclaration &&
|
|
@@ -562,11 +604,14 @@ export default function extractTypeScriptDependencies(
|
|
|
562
604
|
pExoticRequireStrings,
|
|
563
605
|
pDetectJSDocImports,
|
|
564
606
|
pDetectProcessBuiltinModuleCalls,
|
|
607
|
+
pDetectImportsInAmbientModules,
|
|
565
608
|
) {
|
|
566
609
|
return typescript
|
|
567
|
-
? extractImports(pTypeScriptAST)
|
|
568
|
-
.concat(extractExports(pTypeScriptAST))
|
|
569
|
-
.concat(
|
|
610
|
+
? extractImports(pTypeScriptAST, pDetectImportsInAmbientModules)
|
|
611
|
+
.concat(extractExports(pTypeScriptAST, pDetectImportsInAmbientModules))
|
|
612
|
+
.concat(
|
|
613
|
+
extractImportEquals(pTypeScriptAST, pDetectImportsInAmbientModules),
|
|
614
|
+
)
|
|
570
615
|
.concat(extractTripleSlashDirectives(pTypeScriptAST))
|
|
571
616
|
.concat(
|
|
572
617
|
extractNestedDependencies(
|
|
@@ -19,6 +19,7 @@ export function extract(
|
|
|
19
19
|
moduleSystems,
|
|
20
20
|
detectJSDocImports,
|
|
21
21
|
detectProcessBuiltinModuleCalls,
|
|
22
|
+
detectImportsInAmbientModules,
|
|
22
23
|
},
|
|
23
24
|
pFileName,
|
|
24
25
|
pTranspileOptions,
|
|
@@ -28,6 +29,7 @@ export function extract(
|
|
|
28
29
|
exoticRequireStrings,
|
|
29
30
|
detectJSDocImports,
|
|
30
31
|
detectProcessBuiltinModuleCalls,
|
|
32
|
+
detectImportsInAmbientModules,
|
|
31
33
|
).filter(({ moduleSystem }) => moduleSystems.includes(moduleSystem));
|
|
32
34
|
}
|
|
33
35
|
|
|
@@ -223,7 +223,10 @@ export function normalizeCruiseOptions(pOptions, pFileAndDirectoryArray = []) {
|
|
|
223
223
|
if (lReturnValue.cache) {
|
|
224
224
|
lReturnValue.cache = normalizeCacheOptions(lReturnValue.cache);
|
|
225
225
|
}
|
|
226
|
-
if (
|
|
226
|
+
if (
|
|
227
|
+
lReturnValue.detectJSDocImports ||
|
|
228
|
+
lReturnValue.detectImportsInAmbientModules
|
|
229
|
+
) {
|
|
227
230
|
lReturnValue.parser = "tsc";
|
|
228
231
|
}
|
|
229
232
|
|
package/src/meta.cjs
CHANGED
package/src/report/markdown.mjs
CHANGED
|
@@ -4,7 +4,16 @@ import {
|
|
|
4
4
|
determineFromExtras,
|
|
5
5
|
} from "./error-html/utl.mjs";
|
|
6
6
|
import meta from "#meta.cjs";
|
|
7
|
+
import { diffViolationArrays } from "#graph-utl/compare.mjs";
|
|
7
8
|
|
|
9
|
+
/**
|
|
10
|
+
* @import { ICruiseResult, IViolation, ISummary } from "../../types/cruise-result.mjs"
|
|
11
|
+
* @import { IMarkdownReporterOptions } from "../../types/reporter-options.mjs"
|
|
12
|
+
* @import { IReporterOutput } from "../../types/dependency-cruiser.mjs"
|
|
13
|
+
* @import { SeverityType } from "../../types/shared-types.mjs"
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/** @type {IMarkdownReporterOptions} */
|
|
8
17
|
const REPORT_DEFAULTS = {
|
|
9
18
|
showTitle: true,
|
|
10
19
|
title: "## Forbidden dependency check - results",
|
|
@@ -27,6 +36,14 @@ const REPORT_DEFAULTS = {
|
|
|
27
36
|
noViolationsMessage:
|
|
28
37
|
":revolving_hearts: No violations found. Get gummy bears to celebrate.",
|
|
29
38
|
|
|
39
|
+
showStaleBaselineDetails: true,
|
|
40
|
+
staleBaselineHeader: "### :ghost: Stale entries in the baseline",
|
|
41
|
+
collapseStaleBaseline: true,
|
|
42
|
+
collapseStaleBaselineMessage:
|
|
43
|
+
"Stale violations in the baseline - click to expand",
|
|
44
|
+
staleBaselineIntro:
|
|
45
|
+
"These violations are in the baseline (typically `.dependency-cruiser-known-violations.json`) but don't match any real violations anymore, e.g. because they were fixed in the meantime. You can remove them with dependency-cruiser's [`--baseline --baseline-mode shrink-only`](https://github.com/sverweij/dependency-cruiser/blob/main/doc/cli.md#--baseline-create-or-update-a-known-violations-baseline) command line options.",
|
|
46
|
+
|
|
30
47
|
showFooter: true,
|
|
31
48
|
footer: `---\n[dependency-cruiser@${
|
|
32
49
|
meta.version
|
|
@@ -34,7 +51,7 @@ const REPORT_DEFAULTS = {
|
|
|
34
51
|
};
|
|
35
52
|
|
|
36
53
|
/**
|
|
37
|
-
* @param {
|
|
54
|
+
* @param {SeverityType} pSeverity
|
|
38
55
|
* @returns {string}
|
|
39
56
|
*/
|
|
40
57
|
function severity2Icon(pSeverity) {
|
|
@@ -48,7 +65,7 @@ function severity2Icon(pSeverity) {
|
|
|
48
65
|
}
|
|
49
66
|
|
|
50
67
|
/**
|
|
51
|
-
* @param {
|
|
68
|
+
* @param {ISummary} pSummary
|
|
52
69
|
* @returns {string}
|
|
53
70
|
*/
|
|
54
71
|
function formatStatsSummary(pSummary) {
|
|
@@ -69,7 +86,7 @@ function formatStatsSummary(pSummary) {
|
|
|
69
86
|
}
|
|
70
87
|
|
|
71
88
|
/**
|
|
72
|
-
* @param {
|
|
89
|
+
* @param {ICruiseResult} pCruiseResult
|
|
73
90
|
* @param {Boolean} pIncludeIgnoredInSummary
|
|
74
91
|
* @returns {string}
|
|
75
92
|
*/
|
|
@@ -95,9 +112,8 @@ function formatRulesSummary(pCruiseResult, pIncludeIgnoredInSummary) {
|
|
|
95
112
|
}
|
|
96
113
|
|
|
97
114
|
/**
|
|
98
|
-
*
|
|
99
|
-
* @param {
|
|
100
|
-
* @param {import("../../types/reporter-options.mjs").IMarkdownReporterOptions} pOptions
|
|
115
|
+
* @param {IViolation[]} pViolations
|
|
116
|
+
* @param {IMarkdownReporterOptions} pOptions
|
|
101
117
|
* @returns {string}
|
|
102
118
|
*/
|
|
103
119
|
function formatViolations(pViolations, pOptions) {
|
|
@@ -119,6 +135,39 @@ function formatViolations(pViolations, pOptions) {
|
|
|
119
135
|
}, lTableHead);
|
|
120
136
|
}
|
|
121
137
|
|
|
138
|
+
/**
|
|
139
|
+
* @param {IViolation[]} pViolations
|
|
140
|
+
* @param {IViolation[]} pKnownViolations
|
|
141
|
+
* @param {IMarkdownReporterOptions} pOptions
|
|
142
|
+
*/
|
|
143
|
+
function staleBaselineDetails(pViolations, pKnownViolations, pOptions) {
|
|
144
|
+
let lReturnValue = "";
|
|
145
|
+
|
|
146
|
+
if (!pKnownViolations) {
|
|
147
|
+
return lReturnValue;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const { old } = diffViolationArrays(pKnownViolations, pViolations);
|
|
151
|
+
|
|
152
|
+
if (old.length > 0) {
|
|
153
|
+
lReturnValue = `${pOptions.staleBaselineHeader}\n\n`;
|
|
154
|
+
if (pOptions.collapseStaleBaseline) {
|
|
155
|
+
lReturnValue += `<details><summary>${pOptions.collapseStaleBaselineMessage}</summary>\n\n`;
|
|
156
|
+
}
|
|
157
|
+
lReturnValue += `${pOptions.staleBaselineIntro}\n\n`;
|
|
158
|
+
lReturnValue += `${formatViolations(old, pOptions)}\n\n`;
|
|
159
|
+
if (pOptions.collapseStaleBaseline) {
|
|
160
|
+
lReturnValue += `</details>\n\n`;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return lReturnValue;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* @param {IViolation[]} pViolations
|
|
168
|
+
* @param {IMarkdownReporterOptions} pOptions
|
|
169
|
+
* @returns {string}
|
|
170
|
+
*/
|
|
122
171
|
function details(pViolations, pOptions) {
|
|
123
172
|
let lReturnValue = "";
|
|
124
173
|
if (pViolations.length > 0) {
|
|
@@ -138,6 +187,11 @@ function details(pViolations, pOptions) {
|
|
|
138
187
|
return lReturnValue;
|
|
139
188
|
}
|
|
140
189
|
|
|
190
|
+
/**
|
|
191
|
+
* @param {ICruiseResult} pResults
|
|
192
|
+
* @param {IMarkdownReporterOptions} pOptions
|
|
193
|
+
* @returns {string}
|
|
194
|
+
*/
|
|
141
195
|
function summary(pResults, pOptions) {
|
|
142
196
|
let lReturnValue = "";
|
|
143
197
|
|
|
@@ -156,8 +210,8 @@ function summary(pResults, pOptions) {
|
|
|
156
210
|
}
|
|
157
211
|
|
|
158
212
|
/**
|
|
159
|
-
* @param {
|
|
160
|
-
* @param {
|
|
213
|
+
* @param {ICruiseResult} pResults
|
|
214
|
+
* @param {IMarkdownReporterOptions} pOptions
|
|
161
215
|
* @returns {string}
|
|
162
216
|
*/
|
|
163
217
|
function report(pResults, pOptions) {
|
|
@@ -176,6 +230,14 @@ function report(pResults, pOptions) {
|
|
|
176
230
|
lReturnValue += details(pResults.summary.violations, lOptions);
|
|
177
231
|
}
|
|
178
232
|
|
|
233
|
+
if (lOptions.showStaleBaselineDetails) {
|
|
234
|
+
lReturnValue += staleBaselineDetails(
|
|
235
|
+
pResults.summary.violations,
|
|
236
|
+
pResults.summary.optionsUsed?.knownViolations,
|
|
237
|
+
lOptions,
|
|
238
|
+
);
|
|
239
|
+
}
|
|
240
|
+
|
|
179
241
|
if (lOptions.showFooter) {
|
|
180
242
|
lReturnValue += `${lOptions.footer}\n\n`;
|
|
181
243
|
}
|
|
@@ -186,9 +248,9 @@ function report(pResults, pOptions) {
|
|
|
186
248
|
/**
|
|
187
249
|
* Returns the violations from a cruise in markdown format
|
|
188
250
|
*
|
|
189
|
-
* @param {
|
|
190
|
-
* @param {
|
|
191
|
-
* @returns {
|
|
251
|
+
* @param {ICruiseResult} pResults
|
|
252
|
+
* @param {IMarkdownReporterOptions} pOptions
|
|
253
|
+
* @returns {IReporterOutput}
|
|
192
254
|
*/
|
|
193
255
|
export default function markdown(pResults, pOptions) {
|
|
194
256
|
return {
|