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
|
@@ -8,227 +8,227 @@ import { intersects } from "#utl/array-util.mjs";
|
|
|
8
8
|
// occur paired with 'local', 'npm' or core. Hence we only include
|
|
9
9
|
// a subset of dependency types where we _care_ if they are duplicates
|
|
10
10
|
const DEPENDENCY_TYPE_DUPLICATES_THAT_MATTER = new Set([
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
11
|
+
"core",
|
|
12
|
+
"local",
|
|
13
|
+
"localmodule",
|
|
14
|
+
"npm",
|
|
15
|
+
"npm-bundled",
|
|
16
|
+
"npm-dev",
|
|
17
|
+
"npm-no-pkg",
|
|
18
|
+
"npm-optional",
|
|
19
|
+
"npm-peer",
|
|
20
|
+
"npm-unknown",
|
|
21
21
|
]);
|
|
22
22
|
|
|
23
23
|
export function propertyEquals(pRule, pDependency, pProperty) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
// The properties can be booleans, so we can't use !pRule.to[pProperty]
|
|
25
|
+
if (Object.hasOwn(pRule.to, pProperty)) {
|
|
26
|
+
return pDependency[pProperty] === pRule.to[pProperty];
|
|
27
|
+
}
|
|
28
|
+
return true;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
export function propertyMatches(pRule, pDependency, pRuleProperty, pProperty) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
32
|
+
return Boolean(
|
|
33
|
+
!pRule.to[pRuleProperty] ||
|
|
34
|
+
(pDependency[pProperty] &&
|
|
35
|
+
pDependency[pProperty].match(pRule.to[pRuleProperty])),
|
|
36
|
+
);
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
export function propertyMatchesNot(
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
pRule,
|
|
41
|
+
pDependency,
|
|
42
|
+
pRuleProperty,
|
|
43
|
+
pProperty,
|
|
44
44
|
) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
45
|
+
return Boolean(
|
|
46
|
+
!pRule.to[pRuleProperty] ||
|
|
47
|
+
(pDependency[pProperty] &&
|
|
48
|
+
!pDependency[pProperty].match(pRule.to[pRuleProperty])),
|
|
49
|
+
);
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
export function matchesFromPath(pRule, pModule) {
|
|
53
|
-
|
|
53
|
+
return Boolean(!pRule.from.path || pModule.source.match(pRule.from.path));
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
export function matchesFromPathNot(pRule, pModule) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
57
|
+
return Boolean(
|
|
58
|
+
!pRule.from.pathNot || !pModule.source.match(pRule.from.pathNot),
|
|
59
|
+
);
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
export function matchesModulePath(pRule, pModule) {
|
|
63
|
-
|
|
63
|
+
return Boolean(!pRule.module.path || pModule.source.match(pRule.module.path));
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
export function matchesModulePathNot(pRule, pModule) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
return Boolean(
|
|
68
|
+
!pRule.module.pathNot || !pModule.source.match(pRule.module.pathNot),
|
|
69
|
+
);
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
function _matchesToPath(pRule, pString, pGroups = []) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
73
|
+
return Boolean(
|
|
74
|
+
!pRule.to.path ||
|
|
75
|
+
pString.match(replaceGroupPlaceholders(pRule.to.path, pGroups)),
|
|
76
|
+
);
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
export function matchesToPath(pRule, pDependency, pGroups) {
|
|
80
|
-
|
|
80
|
+
return _matchesToPath(pRule, pDependency.resolved, pGroups);
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
export function matchToModulePath(pRule, pModule, pGroups) {
|
|
84
|
-
|
|
84
|
+
return _matchesToPath(pRule, pModule.source, pGroups);
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
function _matchesToPathNot(pRule, pString, pGroups = []) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
88
|
+
return (
|
|
89
|
+
!pRule.to.pathNot ||
|
|
90
|
+
!pString.match(replaceGroupPlaceholders(pRule.to.pathNot, pGroups))
|
|
91
|
+
);
|
|
92
92
|
}
|
|
93
93
|
|
|
94
94
|
export function matchesToPathNot(pRule, pDependency, pGroups) {
|
|
95
|
-
|
|
95
|
+
return _matchesToPathNot(pRule, pDependency.resolved, pGroups);
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
export function matchToModulePathNot(pRule, pModule, pGroups) {
|
|
99
|
-
|
|
99
|
+
return _matchesToPathNot(pRule, pModule.source, pGroups);
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
export function matchesToDependencyTypes(pRule, pDependency) {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
103
|
+
return Boolean(
|
|
104
|
+
!pRule.to.dependencyTypes ||
|
|
105
|
+
intersects(pDependency.dependencyTypes, pRule.to.dependencyTypes),
|
|
106
|
+
);
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
export function matchesToDependencyTypesNot(pRule, pDependency) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
110
|
+
return Boolean(
|
|
111
|
+
!pRule.to.dependencyTypesNot ||
|
|
112
|
+
!intersects(pDependency.dependencyTypes, pRule.to.dependencyTypesNot),
|
|
113
|
+
);
|
|
114
114
|
}
|
|
115
115
|
|
|
116
116
|
export function matchesToVia(pRule, pDependency, pGroups) {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
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
|
-
|
|
117
|
+
let lReturnValue = true;
|
|
118
|
+
if (pRule.to.via && pDependency.cycle) {
|
|
119
|
+
if (pRule.to.via.path) {
|
|
120
|
+
lReturnValue = pDependency.cycle.some(({ name }) =>
|
|
121
|
+
name.match(replaceGroupPlaceholders(pRule.to.via.path, pGroups)),
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
if (pRule.to.via.pathNot) {
|
|
125
|
+
lReturnValue = !pDependency.cycle.every(({ name }) =>
|
|
126
|
+
name.match(replaceGroupPlaceholders(pRule.to.via.pathNot, pGroups)),
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
if (pRule.to.via.dependencyTypes) {
|
|
130
|
+
lReturnValue &&= pDependency.cycle.some(({ dependencyTypes }) =>
|
|
131
|
+
pRule.to.via.dependencyTypes.some((pRuleDependencyType) =>
|
|
132
|
+
dependencyTypes.includes(pRuleDependencyType),
|
|
133
|
+
),
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
if (pRule.to.via.dependencyTypesNot) {
|
|
137
|
+
lReturnValue &&= !pDependency.cycle.every(({ dependencyTypes }) =>
|
|
138
|
+
pRule.to.via.dependencyTypesNot.some((pRuleDependencyType) =>
|
|
139
|
+
dependencyTypes.includes(pRuleDependencyType),
|
|
140
|
+
),
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return lReturnValue;
|
|
145
145
|
}
|
|
146
146
|
|
|
147
147
|
export function matchesToViaOnly(pRule, pDependency, pGroups) {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
148
|
+
let lReturnValue = true;
|
|
149
|
+
if (pRule.to.viaOnly && pDependency.cycle) {
|
|
150
|
+
if (pRule.to.viaOnly.path) {
|
|
151
|
+
lReturnValue = pDependency.cycle.every(({ name }) =>
|
|
152
|
+
name.match(replaceGroupPlaceholders(pRule.to.viaOnly.path, pGroups)),
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
if (pRule.to.viaOnly.pathNot) {
|
|
156
|
+
lReturnValue = !pDependency.cycle.some(({ name }) =>
|
|
157
|
+
name.match(replaceGroupPlaceholders(pRule.to.viaOnly.pathNot, pGroups)),
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
if (pRule.to.viaOnly.dependencyTypes) {
|
|
161
|
+
lReturnValue &&= pDependency.cycle.every(({ dependencyTypes }) =>
|
|
162
|
+
pRule.to.viaOnly.dependencyTypes.some((pRuleDependencyType) =>
|
|
163
|
+
dependencyTypes.includes(pRuleDependencyType),
|
|
164
|
+
),
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
if (pRule.to.viaOnly.dependencyTypesNot) {
|
|
168
|
+
lReturnValue &&= !pDependency.cycle.some(({ dependencyTypes }) =>
|
|
169
|
+
pRule.to.viaOnly.dependencyTypesNot.some((pRuleDependencyType) =>
|
|
170
|
+
dependencyTypes.includes(pRuleDependencyType),
|
|
171
|
+
),
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return lReturnValue;
|
|
176
176
|
}
|
|
177
177
|
|
|
178
178
|
export function matchesToIsMoreUnstable(pRule, pModule, pDependency) {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
179
|
+
if (Object.hasOwn(pRule.to, "moreUnstable")) {
|
|
180
|
+
return (
|
|
181
|
+
(pRule.to.moreUnstable &&
|
|
182
|
+
pModule.instability < pDependency.instability) ||
|
|
183
|
+
(!pRule.to.moreUnstable && pModule.instability >= pDependency.instability)
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
return true;
|
|
187
187
|
}
|
|
188
188
|
|
|
189
189
|
export function matchesMoreThanOneDependencyType(pRule, pDependency) {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
190
|
+
/**
|
|
191
|
+
* this rule exists to weed out i.e. dependencies declared in both
|
|
192
|
+
* dependencies and devDependencies. We, however, also use the dependencyTypes
|
|
193
|
+
* to specify closer to the source what kind of dependency it is (aliased via
|
|
194
|
+
* a subpath import => both 'aliased' and 'aliased-subpath-import').
|
|
195
|
+
*
|
|
196
|
+
* Moreover an alias per definition is also a regular dependency. So we also
|
|
197
|
+
* need to exclude those.
|
|
198
|
+
*
|
|
199
|
+
* Something similar goes for dependencies that are imported as 'type-only' -
|
|
200
|
+
* which are some sort of regular dependency as well. Hence the use of the
|
|
201
|
+
* DEPENDENCY_TYPE_DUPLICATES_THAT_MATTER set.
|
|
202
|
+
*/
|
|
203
|
+
|
|
204
|
+
if (Object.hasOwn(pRule.to, "moreThanOneDependencyType")) {
|
|
205
|
+
return (
|
|
206
|
+
pRule.to.moreThanOneDependencyType ===
|
|
207
|
+
pDependency.dependencyTypes.filter((pDependencyType) =>
|
|
208
|
+
DEPENDENCY_TYPE_DUPLICATES_THAT_MATTER.has(pDependencyType),
|
|
209
|
+
).length >
|
|
210
|
+
1
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
return true;
|
|
214
214
|
}
|
|
215
215
|
|
|
216
216
|
export function matchesAncestor(pRule, pModule, pDependency) {
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
217
|
+
if (Object.hasOwn(pRule.to, "ancestor")) {
|
|
218
|
+
if (pDependency.coreModule || pDependency.couldNotResolve) {
|
|
219
|
+
return false;
|
|
220
|
+
}
|
|
221
|
+
const lModulePath = dirname(resolve(pModule.source)) + sep;
|
|
222
|
+
const lDependencyPath = dirname(resolve(pDependency.resolved)) + sep;
|
|
223
|
+
const lDoesMatchAncestor =
|
|
224
|
+
lModulePath.startsWith(lDependencyPath) &&
|
|
225
|
+
lModulePath.length > lDependencyPath.length;
|
|
226
|
+
|
|
227
|
+
if (pRule.to.ancestor) {
|
|
228
|
+
return lDoesMatchAncestor;
|
|
229
|
+
} else {
|
|
230
|
+
return !lDoesMatchAncestor;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
return true;
|
|
234
234
|
}
|
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
* @returns {boolean} whether or not the rule is 'module only'
|
|
4
4
|
*/
|
|
5
5
|
export function isModuleOnlyRule(pRule) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
return (
|
|
7
|
+
Object.hasOwn(pRule?.from ?? {}, "orphan") ||
|
|
8
|
+
// note: the to might become optional for required rules
|
|
9
|
+
Object.hasOwn(pRule?.to ?? {}, "reachable") ||
|
|
10
|
+
Object.hasOwn(pRule, "module")
|
|
11
|
+
);
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
14
14
|
*
|
|
@@ -16,7 +16,7 @@ export function isModuleOnlyRule(pRule) {
|
|
|
16
16
|
* @returns {boolean} whether or not the scope of the rule is "folder" or something else
|
|
17
17
|
*/
|
|
18
18
|
export function isFolderScope(pRule) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
// TODO might be possible to just rule pRule.scope as it's now
|
|
20
|
+
// normalized away before getting here.
|
|
21
|
+
return (pRule?.scope ?? "module") === "folder";
|
|
22
22
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
matchesToPath,
|
|
3
|
+
matchesModulePath,
|
|
4
|
+
matchesModulePathNot,
|
|
5
|
+
matchToModulePath,
|
|
6
6
|
} from "./matchers.mjs";
|
|
7
7
|
import { matchesReachesRule } from "./match-module-rule-helpers.mjs";
|
|
8
8
|
import { extractGroups } from "#utl/regex-util.mjs";
|
|
@@ -16,25 +16,25 @@ import { extractGroups } from "#utl/regex-util.mjs";
|
|
|
16
16
|
* @returns {boolean}
|
|
17
17
|
*/
|
|
18
18
|
export default function violatesRequiredRule(pRule, pModule) {
|
|
19
|
-
|
|
19
|
+
let lReturnValue = false;
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
21
|
+
if (
|
|
22
|
+
matchesModulePath(pRule, pModule) &&
|
|
23
|
+
matchesModulePathNot(pRule, pModule)
|
|
24
|
+
) {
|
|
25
|
+
if (pRule.to.reachable) {
|
|
26
|
+
lReturnValue = !matchesReachesRule(pRule, pModule);
|
|
27
|
+
}
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
29
|
+
if (lReturnValue || !pRule.to.reachable) {
|
|
30
|
+
const lGroups = extractGroups(pRule.module, pModule.source);
|
|
31
|
+
const lMatchesSelf = matchToModulePath(pRule, pModule, lGroups);
|
|
32
|
+
lReturnValue =
|
|
33
|
+
!lMatchesSelf &&
|
|
34
|
+
!pModule.dependencies.some((pDependency) =>
|
|
35
|
+
matchesToPath(pRule, pDependency, lGroups),
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return lReturnValue;
|
|
40
40
|
}
|
|
@@ -1,31 +1,31 @@
|
|
|
1
1
|
export type cacheStrategyType = "metadata" | "content";
|
|
2
2
|
|
|
3
3
|
export interface ICacheOptions {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
4
|
+
/**
|
|
5
|
+
* The folder to store the cache in.
|
|
6
|
+
*
|
|
7
|
+
* Defaults to node_modules/.cache/dependency-cruiser/
|
|
8
|
+
*/
|
|
9
|
+
folder: string;
|
|
10
|
+
/**
|
|
11
|
+
* The strategy to use for caching.
|
|
12
|
+
* - 'metadata': use git metadata to detect changes;
|
|
13
|
+
* - 'content': use (a checksum of) the contents of files to detect changes.
|
|
14
|
+
*
|
|
15
|
+
* 'content'is useful if you're not on git or work on partial clones
|
|
16
|
+
* (which is typical on CI's). Trade-of: the 'content' strategy is typically
|
|
17
|
+
* slower.
|
|
18
|
+
*
|
|
19
|
+
* Defaults to 'metadata'
|
|
20
|
+
*/
|
|
21
|
+
strategy: cacheStrategyType;
|
|
22
|
+
/**
|
|
23
|
+
* Whether to compress the cache or not
|
|
24
|
+
*
|
|
25
|
+
* Setting this to true adds a few ms to the execution time, but
|
|
26
|
+
* typically reduces the cache size by 80-90%.
|
|
27
|
+
*
|
|
28
|
+
* Defaults to false.
|
|
29
|
+
*/
|
|
30
|
+
compress: boolean;
|
|
31
31
|
}
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* when dependency-cruiser can't yet process it
|
|
12
12
|
*/
|
|
13
13
|
export default function extractBabelConfig(
|
|
14
|
-
|
|
14
|
+
pBabelConfigFileName: string,
|
|
15
15
|
): Promise<object>;
|
|
16
16
|
|
|
17
17
|
// regarding the rather unspecific _object_ type - this is what's
|
|
@@ -21,7 +21,7 @@ import type { IConfiguration } from "../configuration.mjs";
|
|
|
21
21
|
* @throws when the config is not valid (/ does not exist/ isn't readable)
|
|
22
22
|
*/
|
|
23
23
|
export default function extractDepcruiseConfig(
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
pConfigFileName: string,
|
|
25
|
+
pAlreadyVisited?: Set<string>,
|
|
26
|
+
pBaseDirectory?: string,
|
|
27
27
|
): Promise<IConfiguration>;
|
|
@@ -14,5 +14,5 @@ import type { ICruiseOptions } from "../options.mjs";
|
|
|
14
14
|
* @throws when the config is not valid (/ does not exist/ isn't readable)
|
|
15
15
|
*/
|
|
16
16
|
export default function extractDepcruiseOptions(
|
|
17
|
-
|
|
17
|
+
pConfigFileName: string,
|
|
18
18
|
): Promise<ICruiseOptions>;
|
|
@@ -13,7 +13,7 @@ import type { ResolveOptions } from "enhanced-resolve";
|
|
|
13
13
|
* doesn't exist, or because it's invalid)
|
|
14
14
|
*/
|
|
15
15
|
export default function extractWebpackResolveConfig(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
pWebpackConfigFilename: string,
|
|
17
|
+
pEnvironment?: { [key: string]: any },
|
|
18
|
+
pArguments?: { [key: string]: any } | string,
|
|
19
19
|
): Promise<ResolveOptions>;
|
|
@@ -2,16 +2,16 @@ import type { ICruiseOptions } from "./options.mjs";
|
|
|
2
2
|
import type { IFlattenedRuleSet } from "./rule-set.mjs";
|
|
3
3
|
|
|
4
4
|
export interface IConfiguration extends IFlattenedRuleSet {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
5
|
+
/**
|
|
6
|
+
* A (node require resolvable) file path to a dependency-cruiser config
|
|
7
|
+
* that serves as the base for this one...
|
|
8
|
+
* ... or an array of these
|
|
9
|
+
*/
|
|
10
|
+
extends?: string | string[];
|
|
11
|
+
/**
|
|
12
|
+
* Runtime configuration options
|
|
13
|
+
*/
|
|
14
|
+
options?: ICruiseOptions;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
// for backwards compatibility:
|