dependency-cruiser 11.9.0-beta-2 → 11.10.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/configs/plugins/mermaid-reporter-plugin.js +1 -111
- package/package.json +9 -9
- package/src/cli/index.js +13 -13
- package/src/cli/init-config/environment-helpers.js +4 -4
- package/src/cli/init-config/normalize-init-options.js +2 -2
- package/src/cli/normalize-cli-options.js +16 -16
- package/src/config-utl/extract-babel-config.js +4 -4
- package/src/config-utl/extract-depcruise-config/index.js +2 -2
- package/src/config-utl/extract-depcruise-config/merge-configs.js +16 -16
- package/src/config-utl/extract-ts-config.js +2 -2
- package/src/enrich/derive/reachable/index.js +10 -12
- package/src/enrich/enrich-modules.js +2 -2
- package/src/enrich/summarize/add-rule-set-used.js +7 -7
- package/src/enrich/summarize/summarize-modules.js +10 -10
- package/src/enrich/summarize/summarize-options.js +4 -4
- package/src/extract/ast-extractors/estree-helpers.js +3 -3
- package/src/extract/get-dependencies.js +5 -5
- package/src/extract/index.js +2 -2
- package/src/extract/parse/to-javascript-ast.js +4 -4
- package/src/extract/parse/to-swc-ast.js +2 -2
- package/src/extract/parse/to-typescript-ast.js +2 -2
- package/src/extract/resolve/determine-dependency-types.js +2 -2
- package/src/extract/resolve/external-module-helpers.js +5 -5
- package/src/extract/resolve/get-manifest/index.js +3 -3
- package/src/extract/resolve/get-manifest/merge-manifests.js +10 -10
- package/src/extract/transpile/meta.js +2 -2
- package/src/extract/transpile/svelte-preprocess.js +3 -3
- package/src/extract/transpile/typescript-wrap.js +2 -2
- package/src/extract/transpile/vue-template-wrap.js +5 -9
- package/src/graph-utl/add-focus.js +2 -2
- package/src/graph-utl/consolidate-module-dependencies.js +6 -6
- package/src/graph-utl/consolidate-modules.js +6 -6
- package/src/graph-utl/filterbank.js +2 -2
- package/src/graph-utl/rule-set.js +11 -11
- package/src/main/options/normalize.js +16 -0
- package/src/main/options/validate.js +3 -3
- package/src/main/report-wrap.js +5 -5
- package/src/main/resolve-options/normalize.js +9 -9
- package/src/main/rule-set/normalize.js +1 -1
- package/src/main/rule-set/validate.js +3 -3
- package/src/meta.js +1 -1
- package/src/report/anon/anonymize-path-element.js +2 -2
- package/src/report/dot/index.js +8 -8
- package/src/report/dot/module-utl.js +3 -3
- package/src/report/dot/prepare-custom-level.js +2 -2
- package/src/report/dot/prepare-flat-level.js +2 -2
- package/src/report/dot/prepare-folder-level.js +2 -2
- package/src/report/dot/theming.js +7 -7
- package/src/report/error.js +2 -2
- package/src/report/index.js +2 -0
- package/src/report/{markdown/index.js → markdown.js} +51 -24
- package/src/report/mermaid.js +122 -0
- package/src/report/metrics.js +8 -0
- package/src/report/teamcity.js +7 -7
- package/src/schema/configuration.schema.js +1 -1
- package/src/schema/cruise-result.schema.js +1 -1
- package/src/validate/index.js +2 -2
- package/src/validate/matchers.js +4 -4
- package/types/reporter-options.d.ts +80 -0
- package/types/shared-types.d.ts +4 -0
|
@@ -1,111 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
/* eslint-disable security/detect-object-injection */
|
|
4
|
-
const mermaidNode = (pNode, pText) => {
|
|
5
|
-
const lNode = pNode
|
|
6
|
-
.replace(ACORN_DUMMY_VALUE, "__unknown__")
|
|
7
|
-
.replace(/^\.$|^\.\//g, "__currentPath__")
|
|
8
|
-
.replace(/^\.{2}$|^\.{2}\//g, "__prevPath__")
|
|
9
|
-
.replace(/[[\]/.@]/g, "_");
|
|
10
|
-
const lText = pText ? `["${pText}"]` : "";
|
|
11
|
-
return `${lNode}${lText}`;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
const mermaidEdge = (pFrom, pTo) => {
|
|
15
|
-
const lFromNode = mermaidNode(pFrom.node);
|
|
16
|
-
const lToNode = mermaidNode(pTo.node);
|
|
17
|
-
return `${lFromNode} --> ${lToNode}`;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const mermaidEdges = (pEdges) => {
|
|
21
|
-
return pEdges.map((pEdge) => mermaidEdge(pEdge.from, pEdge.to)).join("\n");
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
const convertedEdgeSources = (pCruiseResult) => {
|
|
25
|
-
return pCruiseResult.modules.flatMap((pModule) => {
|
|
26
|
-
const lFrom = {
|
|
27
|
-
node: pModule.source,
|
|
28
|
-
text: pModule.source.split("/").slice(-1)[0],
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
return pModule.dependencies.map((pDep) => {
|
|
32
|
-
return {
|
|
33
|
-
from: lFrom,
|
|
34
|
-
to: {
|
|
35
|
-
node: pDep.resolved,
|
|
36
|
-
text: pDep.resolved.split("/").slice(-1)[0],
|
|
37
|
-
},
|
|
38
|
-
};
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
const indent = (pDepth = 0) => {
|
|
44
|
-
return " ".repeat(pDepth);
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
const mermaidSubgraph = (pNode, pText, pChildren, pDepth) => {
|
|
48
|
-
return `${indent(pDepth)}subgraph ${mermaidNode(pNode, pText)}
|
|
49
|
-
${pChildren}
|
|
50
|
-
${indent(pDepth)}end`;
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
const mermaidSubgraphs = (pSource, pDepth = 0) => {
|
|
54
|
-
return Object.keys(pSource)
|
|
55
|
-
.map((pName) => {
|
|
56
|
-
const source = pSource[pName];
|
|
57
|
-
const children = mermaidSubgraphs(source.children, pDepth + 1);
|
|
58
|
-
if (children === "")
|
|
59
|
-
return `${indent(pDepth)}${mermaidNode(source.node, source.text)}`;
|
|
60
|
-
|
|
61
|
-
return mermaidSubgraph(source.node, source.text, children, pDepth);
|
|
62
|
-
})
|
|
63
|
-
.join("\n");
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
const convertedSubgraphSources = (pCruiseResult) => {
|
|
67
|
-
let lTree = {};
|
|
68
|
-
|
|
69
|
-
pCruiseResult.modules.forEach((pModule) => {
|
|
70
|
-
const paths = pModule.source.split("/");
|
|
71
|
-
|
|
72
|
-
paths.reduce((pChildren, pCurrentPath, pIndex) => {
|
|
73
|
-
if (!pChildren[pCurrentPath]) {
|
|
74
|
-
pChildren[pCurrentPath] = {
|
|
75
|
-
node: paths.slice(0, pIndex + 1).join("/"),
|
|
76
|
-
text: pCurrentPath,
|
|
77
|
-
children: {},
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
return pChildren[pCurrentPath].children;
|
|
81
|
-
}, lTree);
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
return lTree;
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
const renderMermaidThing = (pCruiseResult) => {
|
|
88
|
-
const subgraphs = convertedSubgraphSources(pCruiseResult);
|
|
89
|
-
const edges = convertedEdgeSources(pCruiseResult);
|
|
90
|
-
|
|
91
|
-
return `flowchart LR
|
|
92
|
-
|
|
93
|
-
${mermaidSubgraphs(subgraphs)}
|
|
94
|
-
${mermaidEdges(edges)}
|
|
95
|
-
`;
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* mermaid reporter plugin
|
|
100
|
-
*
|
|
101
|
-
* @param {import('../../types/dependency-cruiser').ICruiseResult} pCruiseResult -
|
|
102
|
-
* the output of a dependency-cruise adhering to dependency-cruiser's
|
|
103
|
-
* cruise result schema
|
|
104
|
-
* @return {import('../../types/dependency-cruiser').IReporterOutput} -
|
|
105
|
-
* output: a string
|
|
106
|
-
* exitCode: 0
|
|
107
|
-
*/
|
|
108
|
-
module.exports = (pCruiseResult) => ({
|
|
109
|
-
output: renderMermaidThing(pCruiseResult),
|
|
110
|
-
exitCode: 0,
|
|
111
|
-
});
|
|
1
|
+
module.exports = require("../../src/report/mermaid");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dependency-cruiser",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.10.0",
|
|
4
4
|
"description": "Validate and visualize dependencies. With your rules. JavaScript, TypeScript, CoffeeScript. ES6, CommonJS, AMD.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"static analysis",
|
|
@@ -117,7 +117,7 @@
|
|
|
117
117
|
"test:i": "mocha --timeout 4000 \"test/**/*.spec.{js,mjs,cjs}\" -g \"^\\[[I]\\]\"",
|
|
118
118
|
"test:u": "mocha --timeout 4000 \"test/**/*.spec.{js,mjs,cjs}\" --grep \"^\\[[U]\\]\"",
|
|
119
119
|
"test:e": "mocha --timeout 4000 \"test/**/*.spec.{js,mjs,cjs}\" --grep \"^\\[[E]\\]\"",
|
|
120
|
-
"test:cover": "c8 --check-coverage --statements 99.9 --branches 99.7 --functions 100 --lines 99.9 --exclude \"{bin,configs,doc,docs,coverage,test,tools,webpack.conf.js,tmp*,src/**/*.template.js,src/cli/tools/svg-in-html-snippets/script.snippet.js,src/cli/init-config/get-user-input.js,src/cli/listeners/*/index.js}\" --reporter text-summary --reporter html --reporter json-summary npm test",
|
|
120
|
+
"test:cover": "c8 --check-coverage --statements 99.9 --branches 99.7 --functions 100 --lines 99.9 --exclude \"{bin,configs/*.js,configs/rules,configs/plugins/3d-*.js,configs/plugins/stats-*.js,doc,docs,coverage,test,tools,webpack.conf.js,tmp*,src/**/*.template.js,src/cli/tools/svg-in-html-snippets/script.snippet.js,src/cli/init-config/get-user-input.js,src/cli/listeners/*/index.js}\" --reporter text-summary --reporter html --reporter json-summary npm test",
|
|
121
121
|
"test:glob": "set -f && test \"`bin/dependency-cruise.js test/extract/__mocks__/gather-globbing/packages/**/src/**/*.js | grep \"no dependency violations found\"`\" = \"✔ no dependency violations found (6 modules, 0 dependencies cruised)\"",
|
|
122
122
|
"test:yarn-pnp": "npm-run-all test:yarn-pnp:cleanup test:yarn-pnp:pack test:yarn-pnp:copy test:yarn-pnp:install test:yarn-pnp:version test:yarn-pnp:run test:yarn-pnp:test test:yarn-pnp:cleanup",
|
|
123
123
|
"test:yarn-pnp:pack": "npm pack",
|
|
@@ -164,17 +164,17 @@
|
|
|
164
164
|
"@babel/core": "7.18.2",
|
|
165
165
|
"@babel/plugin-transform-modules-commonjs": "7.18.2",
|
|
166
166
|
"@babel/preset-typescript": "7.17.12",
|
|
167
|
-
"@swc/core": "1.2.
|
|
167
|
+
"@swc/core": "1.2.197",
|
|
168
168
|
"@types/lodash": "4.14.182",
|
|
169
|
-
"@types/node": "17.0.
|
|
170
|
-
"@typescript-eslint/eslint-plugin": "5.
|
|
171
|
-
"@typescript-eslint/parser": "5.
|
|
172
|
-
"@vue/compiler-sfc": "3.2.
|
|
169
|
+
"@types/node": "17.0.40",
|
|
170
|
+
"@typescript-eslint/eslint-plugin": "5.27.1",
|
|
171
|
+
"@typescript-eslint/parser": "5.27.1",
|
|
172
|
+
"@vue/compiler-sfc": "3.2.37",
|
|
173
173
|
"c8": "7.11.3",
|
|
174
174
|
"chai": "4.3.6",
|
|
175
175
|
"chai-json-schema": "1.5.1",
|
|
176
176
|
"coffeescript": "2.7.0",
|
|
177
|
-
"eslint": "^8.
|
|
177
|
+
"eslint": "^8.17.0",
|
|
178
178
|
"eslint-config-moving-meadow": "3.0.0",
|
|
179
179
|
"eslint-config-prettier": "8.5.0",
|
|
180
180
|
"eslint-plugin-budapestian": "3.0.2",
|
|
@@ -194,7 +194,7 @@
|
|
|
194
194
|
"shx": "0.3.4",
|
|
195
195
|
"svelte": "3.48.0",
|
|
196
196
|
"symlink-dir": "5.0.1",
|
|
197
|
-
"typescript": "4.7.
|
|
197
|
+
"typescript": "4.7.3",
|
|
198
198
|
"upem": "^7.0.0",
|
|
199
199
|
"vue-template-compiler": "2.6.14",
|
|
200
200
|
"yarn": "1.22.18"
|
package/src/cli/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const glob = require("glob");
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
const
|
|
2
|
+
const get = require("lodash/get");
|
|
3
|
+
const clone = require("lodash/clone");
|
|
4
|
+
const set = require("lodash/set");
|
|
5
5
|
|
|
6
6
|
const main = require("../main");
|
|
7
7
|
const bus = require("../utl/bus");
|
|
@@ -19,7 +19,7 @@ const setUpPerformanceLogListener = require("./listeners/performance-log");
|
|
|
19
19
|
|
|
20
20
|
function extractResolveOptions(pCruiseOptions) {
|
|
21
21
|
let lResolveOptions = {};
|
|
22
|
-
const lWebPackConfigFileName =
|
|
22
|
+
const lWebPackConfigFileName = get(
|
|
23
23
|
pCruiseOptions,
|
|
24
24
|
"ruleSet.options.webpackConfig.fileName",
|
|
25
25
|
null
|
|
@@ -28,8 +28,8 @@ function extractResolveOptions(pCruiseOptions) {
|
|
|
28
28
|
if (lWebPackConfigFileName) {
|
|
29
29
|
lResolveOptions = extractWebpackResolveConfig(
|
|
30
30
|
lWebPackConfigFileName,
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
get(pCruiseOptions, "ruleSet.options.webpackConfig.env", null),
|
|
32
|
+
get(pCruiseOptions, "ruleSet.options.webpackConfig.arguments", null)
|
|
33
33
|
);
|
|
34
34
|
}
|
|
35
35
|
return lResolveOptions;
|
|
@@ -43,8 +43,8 @@ function addKnownViolations(pCruiseOptions) {
|
|
|
43
43
|
|
|
44
44
|
// Check against json schema is already done in src/main/options/validate
|
|
45
45
|
// so here we can just concentrate on the io
|
|
46
|
-
let lCruiseOptions =
|
|
47
|
-
|
|
46
|
+
let lCruiseOptions = clone(pCruiseOptions);
|
|
47
|
+
set(lCruiseOptions, "ruleSet.options.knownViolations", lKnownViolations);
|
|
48
48
|
return lCruiseOptions;
|
|
49
49
|
}
|
|
50
50
|
return pCruiseOptions;
|
|
@@ -52,7 +52,7 @@ function addKnownViolations(pCruiseOptions) {
|
|
|
52
52
|
|
|
53
53
|
function extractTSConfigOptions(pCruiseOptions) {
|
|
54
54
|
let lReturnValue = {};
|
|
55
|
-
const lTSConfigFileName =
|
|
55
|
+
const lTSConfigFileName = get(
|
|
56
56
|
pCruiseOptions,
|
|
57
57
|
"ruleSet.options.tsConfig.fileName",
|
|
58
58
|
null
|
|
@@ -67,7 +67,7 @@ function extractTSConfigOptions(pCruiseOptions) {
|
|
|
67
67
|
|
|
68
68
|
function extractBabelConfigOptions(pCruiseOptions) {
|
|
69
69
|
let lReturnValue = {};
|
|
70
|
-
const lBabelConfigFileName =
|
|
70
|
+
const lBabelConfigFileName = get(
|
|
71
71
|
pCruiseOptions,
|
|
72
72
|
"ruleSet.options.babelConfig.fileName",
|
|
73
73
|
null
|
|
@@ -85,12 +85,12 @@ function setUpListener(pCruiseOptions) {
|
|
|
85
85
|
"cli-feedback": setUpCliFeedbackListener,
|
|
86
86
|
"performance-log": setUpPerformanceLogListener,
|
|
87
87
|
};
|
|
88
|
-
const lListenerID =
|
|
88
|
+
const lListenerID = get(
|
|
89
89
|
pCruiseOptions,
|
|
90
90
|
"progress",
|
|
91
|
-
|
|
91
|
+
get(pCruiseOptions, "ruleSet.options.progress.type")
|
|
92
92
|
);
|
|
93
|
-
const lListenerFunction =
|
|
93
|
+
const lListenerFunction = get(lString2Listener, lListenerID);
|
|
94
94
|
/* c8 ignore next 3 */
|
|
95
95
|
if (Boolean(lListenerFunction)) {
|
|
96
96
|
lListenerFunction(bus);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const fs = require("fs");
|
|
2
2
|
const path = require("path");
|
|
3
|
-
const
|
|
4
|
-
const
|
|
3
|
+
const has = require("lodash/has");
|
|
4
|
+
const get = require("lodash/get");
|
|
5
5
|
const { DEFAULT_CONFIG_FILE_NAME } = require("../defaults");
|
|
6
6
|
|
|
7
7
|
const LIKELY_SOURCE_FOLDERS = ["src", "lib", "app", "bin", "sources"];
|
|
@@ -41,7 +41,7 @@ function babelIsConfiguredInManifest() {
|
|
|
41
41
|
let lReturnValue = false;
|
|
42
42
|
|
|
43
43
|
try {
|
|
44
|
-
lReturnValue =
|
|
44
|
+
lReturnValue = has(readManifest(), "babel");
|
|
45
45
|
} catch (pError) {
|
|
46
46
|
// silently ignore - we'll return false anyway then
|
|
47
47
|
}
|
|
@@ -52,7 +52,7 @@ function isTypeModule() {
|
|
|
52
52
|
let lReturnValue = false;
|
|
53
53
|
|
|
54
54
|
try {
|
|
55
|
-
lReturnValue =
|
|
55
|
+
lReturnValue = get(readManifest(), "type", "commonjs") === "module";
|
|
56
56
|
} catch (pError) {
|
|
57
57
|
// silently ignore - we'll return false anyway then
|
|
58
58
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const has = require("lodash/has");
|
|
2
2
|
const { version } = require("../../../src/meta.js");
|
|
3
3
|
const {
|
|
4
4
|
getSourceFolderCandidates,
|
|
@@ -40,7 +40,7 @@ module.exports = function normalizeInitOptions(pInitOptions) {
|
|
|
40
40
|
if (lReturnValue.configType === "preset" && !lReturnValue.preset) {
|
|
41
41
|
lReturnValue.preset = "dependency-cruiser/configs/recommended-warn-only";
|
|
42
42
|
}
|
|
43
|
-
if (!
|
|
43
|
+
if (!has(lReturnValue, "hasTestsOutsideSource")) {
|
|
44
44
|
lReturnValue.hasTestsOutsideSource =
|
|
45
45
|
!pInitOptions.isMonoRepo &&
|
|
46
46
|
!hasTestsWithinSource(
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
const fs = require("fs");
|
|
2
2
|
const path = require("path");
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
3
|
+
const set = require("lodash/set");
|
|
4
|
+
const get = require("lodash/get");
|
|
5
|
+
const has = require("lodash/has");
|
|
6
|
+
const clone = require("lodash/clone");
|
|
7
7
|
const loadConfig = require("../config-utl/extract-depcruise-config");
|
|
8
8
|
const defaults = require("./defaults");
|
|
9
9
|
|
|
@@ -68,10 +68,10 @@ function ejectNonCLIOptions(pCliOptions, pKnownCliOptions) {
|
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
function normalizeConfigFileName(pCliOptions, pConfigWrapperName, pDefault) {
|
|
71
|
-
let lOptions =
|
|
71
|
+
let lOptions = clone(pCliOptions);
|
|
72
72
|
|
|
73
|
-
if (
|
|
74
|
-
|
|
73
|
+
if (has(lOptions, pConfigWrapperName)) {
|
|
74
|
+
set(
|
|
75
75
|
lOptions,
|
|
76
76
|
`ruleSet.options.${pConfigWrapperName}.fileName`,
|
|
77
77
|
getOptionValue(pDefault)(lOptions[pConfigWrapperName])
|
|
@@ -81,10 +81,10 @@ function normalizeConfigFileName(pCliOptions, pConfigWrapperName, pDefault) {
|
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
if (
|
|
84
|
-
|
|
85
|
-
!
|
|
84
|
+
get(lOptions, `ruleSet.options.${pConfigWrapperName}`, null) &&
|
|
85
|
+
!get(lOptions, `ruleSet.options.${pConfigWrapperName}.fileName`, null)
|
|
86
86
|
) {
|
|
87
|
-
|
|
87
|
+
set(lOptions, `ruleSet.options.${pConfigWrapperName}.fileName`, pDefault);
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
return lOptions;
|
|
@@ -153,7 +153,7 @@ function validateAndGetKnownViolationsFileName(pKnownViolations) {
|
|
|
153
153
|
}
|
|
154
154
|
|
|
155
155
|
function normalizeKnownViolationsOption(pCliOptions) {
|
|
156
|
-
if (
|
|
156
|
+
if (has(pCliOptions, "ignoreKnown")) {
|
|
157
157
|
const lReturnValue = {
|
|
158
158
|
knownViolationsFile: validateAndGetKnownViolationsFileName(
|
|
159
159
|
pCliOptions.ignoreKnown
|
|
@@ -165,7 +165,7 @@ function normalizeKnownViolationsOption(pCliOptions) {
|
|
|
165
165
|
}
|
|
166
166
|
|
|
167
167
|
function normalizeValidationOption(pCliOptions) {
|
|
168
|
-
if (
|
|
168
|
+
if (has(pCliOptions, "validate")) {
|
|
169
169
|
const rulesFile = validateAndNormalizeRulesFileName(pCliOptions.validate);
|
|
170
170
|
return {
|
|
171
171
|
rulesFile,
|
|
@@ -184,8 +184,8 @@ function normalizeValidationOption(pCliOptions) {
|
|
|
184
184
|
function normalizeProgress(pCliOptions) {
|
|
185
185
|
let lProgress = null;
|
|
186
186
|
|
|
187
|
-
if (
|
|
188
|
-
lProgress =
|
|
187
|
+
if (has(pCliOptions, "progress")) {
|
|
188
|
+
lProgress = get(pCliOptions, "progress");
|
|
189
189
|
if (lProgress === true) {
|
|
190
190
|
lProgress = "cli-feedback";
|
|
191
191
|
}
|
|
@@ -211,13 +211,13 @@ module.exports = function normalizeOptions(
|
|
|
211
211
|
...ejectNonCLIOptions(pOptionsAsPassedFromCommander, pKnownCliOptions),
|
|
212
212
|
};
|
|
213
213
|
|
|
214
|
-
if (
|
|
214
|
+
if (has(lOptions, "moduleSystems")) {
|
|
215
215
|
lOptions.moduleSystems = lOptions.moduleSystems
|
|
216
216
|
.split(",")
|
|
217
217
|
.map((pString) => pString.trim());
|
|
218
218
|
}
|
|
219
219
|
|
|
220
|
-
if (
|
|
220
|
+
if (has(lOptions, "config")) {
|
|
221
221
|
lOptions.validate = lOptions.config;
|
|
222
222
|
}
|
|
223
223
|
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
const fs = require("fs");
|
|
5
5
|
const path = require("path");
|
|
6
6
|
const json5 = require("json5");
|
|
7
|
-
const
|
|
8
|
-
const
|
|
7
|
+
const get = require("lodash/get");
|
|
8
|
+
const has = require("lodash/has");
|
|
9
9
|
const tryRequire = require("semver-try-require");
|
|
10
10
|
const { supportedTranspilers } = require("../../src/meta.js");
|
|
11
11
|
const makeAbsolute = require("./make-absolute");
|
|
@@ -48,7 +48,7 @@ function getJSON5Config(pBabelConfigFileName) {
|
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
if (pBabelConfigFileName.endsWith("package.json")) {
|
|
51
|
-
lReturnValue =
|
|
51
|
+
lReturnValue = get(lReturnValue, "babel", {});
|
|
52
52
|
}
|
|
53
53
|
return lReturnValue;
|
|
54
54
|
}
|
|
@@ -63,7 +63,7 @@ function getConfig(pBabelConfigFileName) {
|
|
|
63
63
|
};
|
|
64
64
|
const lExtension = path.extname(pBabelConfigFileName);
|
|
65
65
|
|
|
66
|
-
if (!
|
|
66
|
+
if (!has(lExtensionToParseFunction, lExtension)) {
|
|
67
67
|
throw new Error(
|
|
68
68
|
`The babel config '${pBabelConfigFileName}' is in a format ('${lExtension}')\n` +
|
|
69
69
|
" dependency-cruiser doesn't support yet.\n"
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const path = require("path");
|
|
2
|
-
const
|
|
2
|
+
const has = require("lodash/has");
|
|
3
3
|
const resolve = require("../../extract/resolve/resolve");
|
|
4
4
|
const normalizeResolveOptions = require("../../main/resolve-options/normalize");
|
|
5
5
|
const readConfig = require("./read-config");
|
|
@@ -78,7 +78,7 @@ function extractDepcruiseConfig(
|
|
|
78
78
|
|
|
79
79
|
let lReturnValue = readConfig(lResolvedFileName, pBaseDirectory);
|
|
80
80
|
|
|
81
|
-
if (
|
|
81
|
+
if (has(lReturnValue, "extends")) {
|
|
82
82
|
lReturnValue = processExtends(
|
|
83
83
|
lReturnValue,
|
|
84
84
|
pAlreadyVisited,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const util = require("util");
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
const
|
|
2
|
+
const get = require("lodash/get");
|
|
3
|
+
const uniqBy = require("lodash/uniqBy");
|
|
4
|
+
const uniqWith = require("lodash/uniqWith");
|
|
5
5
|
|
|
6
6
|
function extendNamedRule(pExtendedRule, pForbiddenArrayBase) {
|
|
7
7
|
return pForbiddenArrayBase
|
|
@@ -31,7 +31,7 @@ function extendNamedRule(pExtendedRule, pForbiddenArrayBase) {
|
|
|
31
31
|
*/
|
|
32
32
|
function mergeRules(pRuleArrayExtended, pRuleArrayBase) {
|
|
33
33
|
// merge anonymous on 100% equality
|
|
34
|
-
let lAnonymousRules =
|
|
34
|
+
let lAnonymousRules = uniqWith(
|
|
35
35
|
pRuleArrayExtended.concat(pRuleArrayBase).filter((pRule) => !pRule.name),
|
|
36
36
|
util.isDeepStrictEqual
|
|
37
37
|
);
|
|
@@ -41,7 +41,7 @@ function mergeRules(pRuleArrayExtended, pRuleArrayBase) {
|
|
|
41
41
|
.map((pNamedRule) => extendNamedRule(pNamedRule, pRuleArrayBase));
|
|
42
42
|
|
|
43
43
|
// merge named rules based on unique name
|
|
44
|
-
lNamedRules =
|
|
44
|
+
lNamedRules = uniqBy(
|
|
45
45
|
// ordered extended => base because the uniqBy picks the
|
|
46
46
|
// first it encounters and we want the ones from the
|
|
47
47
|
// extended in case of a conflict
|
|
@@ -66,7 +66,7 @@ function mergeRules(pRuleArrayExtended, pRuleArrayBase) {
|
|
|
66
66
|
* @return {Array} - the merged array
|
|
67
67
|
*/
|
|
68
68
|
function mergeAllowedRules(pAllowedArrayExtended, pAllowedArrayBase) {
|
|
69
|
-
return
|
|
69
|
+
return uniqWith(
|
|
70
70
|
pAllowedArrayExtended.concat(pAllowedArrayBase),
|
|
71
71
|
util.isDeepStrictEqual
|
|
72
72
|
);
|
|
@@ -87,10 +87,10 @@ function mergeOptions(pOptionsExtended, pOptionsBase) {
|
|
|
87
87
|
* @returns {string} - a string from the SeverityType value set
|
|
88
88
|
*/
|
|
89
89
|
function mergeAllowedSeverities(pConfigExtended, pConfigBase) {
|
|
90
|
-
return
|
|
90
|
+
return get(
|
|
91
91
|
pConfigExtended,
|
|
92
92
|
"allowedSeverity",
|
|
93
|
-
|
|
93
|
+
get(pConfigBase, "allowedSeverity", "warn")
|
|
94
94
|
);
|
|
95
95
|
}
|
|
96
96
|
|
|
@@ -110,16 +110,16 @@ function mergeAllowedSeverities(pConfigExtended, pConfigBase) {
|
|
|
110
110
|
*/
|
|
111
111
|
module.exports = (pConfigExtended, pConfigBase) => {
|
|
112
112
|
const lForbidden = mergeRules(
|
|
113
|
-
|
|
114
|
-
|
|
113
|
+
get(pConfigExtended, "forbidden", []),
|
|
114
|
+
get(pConfigBase, "forbidden", [])
|
|
115
115
|
);
|
|
116
116
|
const lRequired = mergeRules(
|
|
117
|
-
|
|
118
|
-
|
|
117
|
+
get(pConfigExtended, "required", []),
|
|
118
|
+
get(pConfigBase, "required", [])
|
|
119
119
|
);
|
|
120
120
|
const lAllowed = mergeAllowedRules(
|
|
121
|
-
|
|
122
|
-
|
|
121
|
+
get(pConfigExtended, "allowed", []),
|
|
122
|
+
get(pConfigBase, "allowed", [])
|
|
123
123
|
);
|
|
124
124
|
|
|
125
125
|
return {
|
|
@@ -132,8 +132,8 @@ module.exports = (pConfigExtended, pConfigBase) => {
|
|
|
132
132
|
}
|
|
133
133
|
: {}),
|
|
134
134
|
options: mergeOptions(
|
|
135
|
-
|
|
136
|
-
|
|
135
|
+
get(pConfigExtended, "options", {}),
|
|
136
|
+
get(pConfigBase, "options", {})
|
|
137
137
|
),
|
|
138
138
|
};
|
|
139
139
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const path = require("path");
|
|
2
2
|
const tryRequire = require("semver-try-require");
|
|
3
|
-
const
|
|
3
|
+
const get = require("lodash/get");
|
|
4
4
|
const { supportedTranspilers } = require("../../src/meta.js");
|
|
5
5
|
|
|
6
6
|
const typescript = tryRequire("typescript", supportedTranspilers.typescript);
|
|
@@ -11,7 +11,7 @@ const FORMAT_DIAGNOSTICS_HOST = {
|
|
|
11
11
|
|
|
12
12
|
// depends on the platform which branch is taken, hence the c8 ignore
|
|
13
13
|
/* c8 ignore start */
|
|
14
|
-
if (
|
|
14
|
+
if (get(typescript, "sys.useCaseSensitiveFileNames", false)) {
|
|
15
15
|
lReturnValue = pFileName;
|
|
16
16
|
}
|
|
17
17
|
/* c8 ignore stop */
|
|
@@ -1,19 +1,17 @@
|
|
|
1
1
|
/* eslint-disable security/detect-object-injection, no-inline-comments */
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
3
|
+
const clone = require("lodash/clone");
|
|
4
|
+
const get = require("lodash/get");
|
|
5
|
+
const has = require("lodash/has");
|
|
6
6
|
const matchers = require("../../../validate/matchers");
|
|
7
7
|
const { extractGroups } = require("../../../utl/regex-util");
|
|
8
8
|
const getPath = require("./get-path");
|
|
9
9
|
|
|
10
10
|
function getReachableRules(pRuleSet) {
|
|
11
|
-
return
|
|
12
|
-
.filter((pRule) =>
|
|
11
|
+
return get(pRuleSet, "forbidden", [])
|
|
12
|
+
.filter((pRule) => has(pRule.to, "reachable"))
|
|
13
13
|
.concat(
|
|
14
|
-
|
|
15
|
-
_has(pRule.to, "reachable")
|
|
16
|
-
)
|
|
14
|
+
get(pRuleSet, "allowed", []).filter((pRule) => has(pRule.to, "reachable"))
|
|
17
15
|
);
|
|
18
16
|
}
|
|
19
17
|
|
|
@@ -87,8 +85,8 @@ function hasCapturingGroups(pRule) {
|
|
|
87
85
|
const lCapturingGroupPlaceholderRe = "\\$[0-9]+";
|
|
88
86
|
|
|
89
87
|
return Boolean(
|
|
90
|
-
|
|
91
|
-
|
|
88
|
+
get(pRule, "to.path", "").match(lCapturingGroupPlaceholderRe) ||
|
|
89
|
+
get(pRule, "to.pathNot", "").match(lCapturingGroupPlaceholderRe)
|
|
92
90
|
);
|
|
93
91
|
}
|
|
94
92
|
function shouldAddReachable(pRule, pModuleTo, pGraph) {
|
|
@@ -156,7 +154,7 @@ function addReachableToModule(pModule, pGraph, pReachableRule) {
|
|
|
156
154
|
|
|
157
155
|
function addReachabilityToGraph(pGraph, pReachableRule) {
|
|
158
156
|
return pGraph.map((pModule) => {
|
|
159
|
-
let lClonedModule =
|
|
157
|
+
let lClonedModule = clone(pModule);
|
|
160
158
|
|
|
161
159
|
if (shouldAddReaches(pReachableRule, lClonedModule)) {
|
|
162
160
|
lClonedModule = addReachesToModule(lClonedModule, pGraph, pReachableRule);
|
|
@@ -177,6 +175,6 @@ module.exports = (pGraph, pRuleSet) => {
|
|
|
177
175
|
|
|
178
176
|
return lReachableRules.reduce(
|
|
179
177
|
(pReturnGraph, pRule) => addReachabilityToGraph(pReturnGraph, pRule),
|
|
180
|
-
|
|
178
|
+
clone(pGraph)
|
|
181
179
|
);
|
|
182
180
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const get = require("lodash/get");
|
|
2
2
|
const bus = require("../utl/bus");
|
|
3
3
|
const busLogLevels = require("../utl/bus-log-levels");
|
|
4
4
|
const addFocus = require("../../src/graph-utl/add-focus");
|
|
@@ -31,7 +31,7 @@ module.exports = function enrichModules(pModules, pOptions) {
|
|
|
31
31
|
bus.emit("progress", "analyzing: add focus (if any)", {
|
|
32
32
|
level: busLogLevels.INFO,
|
|
33
33
|
});
|
|
34
|
-
lModules = addFocus(lModules,
|
|
34
|
+
lModules = addFocus(lModules, get(pOptions, "focus"));
|
|
35
35
|
|
|
36
36
|
// when validate === false we might want to skip the addValidations.
|
|
37
37
|
// We don't at this time, however, as "valid" is a mandatory
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
const
|
|
2
|
-
const
|
|
1
|
+
const get = require("lodash/get");
|
|
2
|
+
const clone = require("lodash/clone");
|
|
3
3
|
|
|
4
4
|
// the fixed name for allowed rules served a purpose during the extraction
|
|
5
5
|
// process - but it's not necessary to reflect it in the output.
|
|
6
6
|
function removeNames(pRule) {
|
|
7
|
-
const lReturnValue =
|
|
7
|
+
const lReturnValue = clone(pRule);
|
|
8
8
|
|
|
9
9
|
Reflect.deleteProperty(lReturnValue, "name");
|
|
10
10
|
return lReturnValue;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
module.exports = function addRuleSetUsed(pOptions) {
|
|
14
|
-
const lForbidden =
|
|
15
|
-
const lAllowed =
|
|
16
|
-
const lAllowedSeverity =
|
|
17
|
-
const lRequired =
|
|
14
|
+
const lForbidden = get(pOptions, "ruleSet.forbidden");
|
|
15
|
+
const lAllowed = get(pOptions, "ruleSet.allowed");
|
|
16
|
+
const lAllowedSeverity = get(pOptions, "ruleSet.allowedSeverity");
|
|
17
|
+
const lRequired = get(pOptions, "ruleSet.required");
|
|
18
18
|
|
|
19
19
|
return Object.assign(
|
|
20
20
|
lForbidden ? { forbidden: lForbidden } : {},
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const _flattenDeep = require("lodash/flattenDeep");
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
const
|
|
2
|
+
const get = require("lodash/get");
|
|
3
|
+
const has = require("lodash/has");
|
|
4
|
+
const uniqWith = require("lodash/uniqWith");
|
|
5
5
|
const { findRuleByName } = require("../../graph-utl/rule-set");
|
|
6
6
|
const compare = require("../../graph-utl/compare");
|
|
7
7
|
const isSameViolation = require("./is-same-violation");
|
|
@@ -24,8 +24,8 @@ function toDependencyViolationSummary(pRule, pModule, pDependency, pRuleSet) {
|
|
|
24
24
|
};
|
|
25
25
|
|
|
26
26
|
if (
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
has(pDependency, "cycle") &&
|
|
28
|
+
get(findRuleByName(pRuleSet, pRule.name), "to.circular")
|
|
29
29
|
) {
|
|
30
30
|
lReturnValue = {
|
|
31
31
|
...lReturnValue,
|
|
@@ -35,9 +35,9 @@ function toDependencyViolationSummary(pRule, pModule, pDependency, pRuleSet) {
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
if (
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
has(pModule, "instability") &&
|
|
39
|
+
has(pDependency, "instability") &&
|
|
40
|
+
has(findRuleByName(pRuleSet, pRule.name), "to.moreUnstable")
|
|
41
41
|
) {
|
|
42
42
|
lReturnValue = {
|
|
43
43
|
...lReturnValue,
|
|
@@ -90,7 +90,7 @@ function toModuleViolationSummary(pRule, pModule, pRuleSet) {
|
|
|
90
90
|
];
|
|
91
91
|
if (
|
|
92
92
|
pModule.reaches &&
|
|
93
|
-
|
|
93
|
+
get(findRuleByName(pRuleSet, pRule.name), "to.reachable")
|
|
94
94
|
) {
|
|
95
95
|
lReturnValue = pModule.reaches
|
|
96
96
|
.filter((pReachable) => pReachable.asDefinedInRule === pRule.name)
|
|
@@ -135,7 +135,7 @@ function extractModuleViolations(pModules, pRuleSet) {
|
|
|
135
135
|
}
|
|
136
136
|
|
|
137
137
|
module.exports = function summarizeModules(pModules, pRuleSet) {
|
|
138
|
-
return
|
|
138
|
+
return uniqWith(
|
|
139
139
|
extractDependencyViolations(pModules, pRuleSet)
|
|
140
140
|
.concat(extractModuleViolations(pModules, pRuleSet))
|
|
141
141
|
.sort(compare.violations),
|