dependency-cruiser 17.3.3-beta-2 → 17.3.3-beta-3

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dependency-cruiser",
3
- "version": "17.3.3-beta-2",
3
+ "version": "17.3.3-beta-3",
4
4
  "description": "Validate and visualize dependencies. With your rules. JavaScript, TypeScript, CoffeeScript. ES6, CommonJS, AMD.",
5
5
  "keywords": [
6
6
  "static analysis",
@@ -1,3 +1,4 @@
1
+ /* eslint-disable security/detect-non-literal-regexp */
1
2
  /* eslint-disable security/detect-object-injection, no-inline-comments */
2
3
  import {
3
4
  matchToModulePath,
@@ -22,8 +23,9 @@ function isModuleInRuleFrom(pRule) {
22
23
  const lRuleFrom = pRule.from ?? pRule.module;
23
24
  if (lRuleFrom) {
24
25
  return (
25
- (!lRuleFrom.path || pModule.source.match(lRuleFrom.path)) &&
26
- (!lRuleFrom.pathNot || !pModule.source.match(lRuleFrom.pathNot))
26
+ (!lRuleFrom.path || new RegExp(lRuleFrom.path).test(pModule.source)) &&
27
+ (!lRuleFrom.pathNot ||
28
+ !new RegExp(lRuleFrom.pathNot).test(pModule.source))
27
29
  );
28
30
  }
29
31
  return false;
@@ -118,12 +120,11 @@ function shouldAddReachable(pRule, pModuleTo, pGraph) {
118
120
  }
119
121
 
120
122
  function addReachesToModule(pModule, pGraph, pIndexedGraph, pReachableRule) {
121
- const lToModules = pGraph.filter((pToModule) =>
122
- isModuleInRuleTo(pReachableRule, pToModule, pModule),
123
- );
124
-
125
- for (const lToModule of lToModules) {
126
- if (pModule.source !== lToModule.source) {
123
+ for (const lToModule of pGraph) {
124
+ if (
125
+ pModule.source !== lToModule.source &&
126
+ isModuleInRuleTo(pReachableRule, lToModule, pModule)
127
+ ) {
127
128
  const lPath = pIndexedGraph.getPath(pModule.source, lToModule.source);
128
129
 
129
130
  if (lPath.length > 0) {
@@ -164,25 +164,19 @@ export default class IndexedModuleGraph {
164
164
  if (!lFromNode) {
165
165
  return [];
166
166
  }
167
+ for (const lDependency of lFromNode.dependencies) {
168
+ if (!pVisited.has(lDependency.name)) {
169
+ if (lDependency.name === pTo) {
170
+ return [this.#geldEdge(lDependency)];
171
+ }
172
+ let lCandidatePath = this.getPath(lDependency.name, pTo, pVisited);
167
173
 
168
- const lDirectUnvisitedDependencies = lFromNode.dependencies
169
- .filter((pDependency) => !pVisited.has(pDependency.name))
170
- .map(this.#geldEdge);
171
- const lFoundDependency = lDirectUnvisitedDependencies.find(
172
- (pDependency) => pDependency.name === pTo,
173
- );
174
-
175
- if (lFoundDependency) {
176
- return [lFoundDependency];
177
- }
178
-
179
- for (const lNewFrom of lDirectUnvisitedDependencies) {
180
- let lCandidatePath = this.getPath(lNewFrom.name, pTo, pVisited);
181
-
182
- if (lCandidatePath.length > 0) {
183
- return [lNewFrom].concat(lCandidatePath);
174
+ if (lCandidatePath.length > 0) {
175
+ return [this.#geldEdge(lDependency)].concat(lCandidatePath);
176
+ }
184
177
  }
185
178
  }
179
+
186
180
  return [];
187
181
  }
188
182
 
@@ -64,7 +64,7 @@ function normalizeCollapse(pCollapse) {
64
64
  const lFolderBelowNodeModules = `node_modules/${lOneOrMoreNonSlashes}`;
65
65
  const lSingleDigitRe = /^\d$/;
66
66
 
67
- if (typeof pCollapse === "number" || pCollapse.match(lSingleDigitRe)) {
67
+ if (typeof pCollapse === "number" || lSingleDigitRe.test(pCollapse)) {
68
68
  lReturnValue = `${lFolderBelowNodeModules}|^${lFolderPattern.repeat(
69
69
  Number.parseInt(pCollapse, 10),
70
70
  )}`;
package/src/meta.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  /* generated - don't edit */
2
2
  module.exports = {
3
- version: "17.3.3-beta-2",
3
+ version: "17.3.3-beta-3",
4
4
  engines: {
5
5
  node: "^20.12||^22||>=24",
6
6
  },
@@ -149,8 +149,10 @@ function anonymize(pResults, pWordList) {
149
149
  function sanitizeWordList(pWordList) {
150
150
  return pWordList
151
151
  .map((pString) => pString.replace(/[^a-zA-Z-]/g, "_"))
152
- .filter((pString) => pString.match(/^[a-zA-Z-_]+$/g))
153
- .filter((pString) => !pString.match(WHITELIST_RE));
152
+ .filter(
153
+ (pString) =>
154
+ /^[a-zA-Z-_]+$/g.test(pString) && !WHITELIST_RE.test(pString),
155
+ );
154
156
  }
155
157
 
156
158
  /**
@@ -1,28 +1,34 @@
1
+ /* eslint-disable security/detect-non-literal-regexp */
1
2
  import { isModuleOnlyRule, isFolderScope } from "./rule-classifiers.mjs";
2
3
  import { propertyEquals, matchesToIsMoreUnstable } from "./matchers.mjs";
3
4
  import { extractGroups, replaceGroupPlaceholders } from "#utl/regex-util.mjs";
4
5
 
5
6
  function fromFolderPath(pRule, pFromFolder) {
6
- return Boolean(!pRule.from.path || pFromFolder.name.match(pRule.from.path));
7
+ return !pRule.from.path || new RegExp(pRule.from.path).test(pFromFolder.name);
7
8
  }
8
9
 
9
10
  function fromFolderPathNot(pRule, pFromFolder) {
10
- return Boolean(
11
- !pRule.from.pathNot || !pFromFolder.name.match(pRule.from.pathNot),
11
+ return (
12
+ !pRule.from.pathNot ||
13
+ !new RegExp(pRule.from.pathNot).test(pFromFolder.name)
12
14
  );
13
15
  }
14
16
 
15
17
  function toFolderPath(pRule, pToFolder, pGroups) {
16
- return Boolean(
18
+ return (
17
19
  !pRule.to.path ||
18
- pToFolder.name.match(replaceGroupPlaceholders(pRule.to.path, pGroups)),
20
+ new RegExp(replaceGroupPlaceholders(pRule.to.path, pGroups)).test(
21
+ pToFolder.name,
22
+ )
19
23
  );
20
24
  }
21
25
 
22
26
  function toFolderPathNot(pRule, pToFolder, pGroups) {
23
- return Boolean(
27
+ return (
24
28
  !pRule.to.pathNot ||
25
- !pToFolder.name.match(replaceGroupPlaceholders(pRule.to.pathNot, pGroups)),
29
+ !new RegExp(replaceGroupPlaceholders(pRule.to.pathNot, pGroups)).test(
30
+ pToFolder.name,
31
+ )
26
32
  );
27
33
  }
28
34
 
@@ -1,3 +1,4 @@
1
+ /* eslint-disable security/detect-non-literal-regexp */
1
2
  import {
2
3
  matchToModulePath,
3
4
  matchToModulePathNot,
@@ -98,8 +99,8 @@ export function matchesReachesRule(pRule, pModule) {
98
99
  function dependentsCountsMatch(pRule, pDependents) {
99
100
  const lMatchingDependentsCount = pDependents.filter(
100
101
  (pDependent) =>
101
- Boolean(!pRule.from.path || pDependent.match(pRule.from.path)) &&
102
- Boolean(!pRule.from.pathNot || !pDependent.match(pRule.from.pathNot)),
102
+ (!pRule.from.path || new RegExp(pRule.from.path).test(pDependent)) &&
103
+ (!pRule.from.pathNot || !new RegExp(pRule.from.pathNot).test(pDependent)),
103
104
  ).length;
104
105
  return (
105
106
  (!pRule.module.numberOfDependentsLessThan ||
@@ -1,3 +1,4 @@
1
+ /* eslint-disable security/detect-non-literal-regexp */
1
2
  /* eslint-disable security/detect-object-injection */
2
3
  import { dirname, resolve, sep } from "node:path/posix";
3
4
  import { replaceGroupPlaceholders } from "#utl/regex-util.mjs";
@@ -29,10 +30,10 @@ export function propertyEquals(pRule, pDependency, pProperty) {
29
30
  }
30
31
 
31
32
  export function propertyMatches(pRule, pDependency, pRuleProperty, pProperty) {
32
- return Boolean(
33
+ return (
33
34
  !pRule.to[pRuleProperty] ||
34
35
  (pDependency[pProperty] &&
35
- pDependency[pProperty].match(pRule.to[pRuleProperty])),
36
+ new RegExp(pRule.to[pRuleProperty]).test(pDependency[pProperty]))
36
37
  );
37
38
  }
38
39
 
@@ -42,37 +43,40 @@ export function propertyMatchesNot(
42
43
  pRuleProperty,
43
44
  pProperty,
44
45
  ) {
45
- return Boolean(
46
+ return (
46
47
  !pRule.to[pRuleProperty] ||
47
48
  (pDependency[pProperty] &&
48
- !pDependency[pProperty].match(pRule.to[pRuleProperty])),
49
+ !new RegExp(pRule.to[pRuleProperty]).test(pDependency[pProperty]))
49
50
  );
50
51
  }
51
52
 
52
53
  export function matchesFromPath(pRule, pModule) {
53
- return Boolean(!pRule.from.path || pModule.source.match(pRule.from.path));
54
+ return !pRule.from.path || new RegExp(pRule.from.path).test(pModule.source);
54
55
  }
55
56
 
56
57
  export function matchesFromPathNot(pRule, pModule) {
57
- return Boolean(
58
- !pRule.from.pathNot || !pModule.source.match(pRule.from.pathNot),
58
+ return (
59
+ !pRule.from.pathNot || !new RegExp(pRule.from.pathNot).test(pModule.source)
59
60
  );
60
61
  }
61
62
 
62
63
  export function matchesModulePath(pRule, pModule) {
63
- return Boolean(!pRule.module.path || pModule.source.match(pRule.module.path));
64
+ return (
65
+ !pRule.module.path || new RegExp(pRule.module.path).test(pModule.source)
66
+ );
64
67
  }
65
68
 
66
69
  export function matchesModulePathNot(pRule, pModule) {
67
- return Boolean(
68
- !pRule.module.pathNot || !pModule.source.match(pRule.module.pathNot),
70
+ return (
71
+ !pRule.module.pathNot ||
72
+ !new RegExp(pRule.module.pathNot).test(pModule.source)
69
73
  );
70
74
  }
71
75
 
72
76
  function _matchesToPath(pRule, pString, pGroups = []) {
73
- return Boolean(
77
+ return (
74
78
  !pRule.to.path ||
75
- pString.match(replaceGroupPlaceholders(pRule.to.path, pGroups)),
79
+ new RegExp(replaceGroupPlaceholders(pRule.to.path, pGroups)).test(pString)
76
80
  );
77
81
  }
78
82
 
@@ -87,7 +91,9 @@ export function matchToModulePath(pRule, pModule, pGroups) {
87
91
  function _matchesToPathNot(pRule, pString, pGroups = []) {
88
92
  return (
89
93
  !pRule.to.pathNot ||
90
- !pString.match(replaceGroupPlaceholders(pRule.to.pathNot, pGroups))
94
+ !new RegExp(replaceGroupPlaceholders(pRule.to.pathNot, pGroups)).test(
95
+ pString,
96
+ )
91
97
  );
92
98
  }
93
99
 
@@ -100,16 +106,16 @@ export function matchToModulePathNot(pRule, pModule, pGroups) {
100
106
  }
101
107
 
102
108
  export function matchesToDependencyTypes(pRule, pDependency) {
103
- return Boolean(
109
+ return (
104
110
  !pRule.to.dependencyTypes ||
105
- intersects(pDependency.dependencyTypes, pRule.to.dependencyTypes),
111
+ intersects(pDependency.dependencyTypes, pRule.to.dependencyTypes)
106
112
  );
107
113
  }
108
114
 
109
115
  export function matchesToDependencyTypesNot(pRule, pDependency) {
110
- return Boolean(
116
+ return (
111
117
  !pRule.to.dependencyTypesNot ||
112
- !intersects(pDependency.dependencyTypes, pRule.to.dependencyTypesNot),
118
+ !intersects(pDependency.dependencyTypes, pRule.to.dependencyTypesNot)
113
119
  );
114
120
  }
115
121
 
@@ -118,12 +124,16 @@ export function matchesToVia(pRule, pDependency, pGroups) {
118
124
  if (pRule.to.via && pDependency.cycle) {
119
125
  if (pRule.to.via.path) {
120
126
  lReturnValue = pDependency.cycle.some(({ name }) =>
121
- name.match(replaceGroupPlaceholders(pRule.to.via.path, pGroups)),
127
+ new RegExp(replaceGroupPlaceholders(pRule.to.via.path, pGroups)).test(
128
+ name,
129
+ ),
122
130
  );
123
131
  }
124
132
  if (pRule.to.via.pathNot) {
125
133
  lReturnValue = !pDependency.cycle.every(({ name }) =>
126
- name.match(replaceGroupPlaceholders(pRule.to.via.pathNot, pGroups)),
134
+ new RegExp(
135
+ replaceGroupPlaceholders(pRule.to.via.pathNot, pGroups),
136
+ ).test(name),
127
137
  );
128
138
  }
129
139
  if (pRule.to.via.dependencyTypes) {
@@ -149,12 +159,16 @@ export function matchesToViaOnly(pRule, pDependency, pGroups) {
149
159
  if (pRule.to.viaOnly && pDependency.cycle) {
150
160
  if (pRule.to.viaOnly.path) {
151
161
  lReturnValue = pDependency.cycle.every(({ name }) =>
152
- name.match(replaceGroupPlaceholders(pRule.to.viaOnly.path, pGroups)),
162
+ new RegExp(
163
+ replaceGroupPlaceholders(pRule.to.viaOnly.path, pGroups),
164
+ ).test(name),
153
165
  );
154
166
  }
155
167
  if (pRule.to.viaOnly.pathNot) {
156
168
  lReturnValue = !pDependency.cycle.some(({ name }) =>
157
- name.match(replaceGroupPlaceholders(pRule.to.viaOnly.pathNot, pGroups)),
169
+ new RegExp(
170
+ replaceGroupPlaceholders(pRule.to.viaOnly.pathNot, pGroups),
171
+ ).test(name),
158
172
  );
159
173
  }
160
174
  if (pRule.to.viaOnly.dependencyTypes) {