dependency-cruiser 16.9.0-beta-1 → 16.9.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dependency-cruiser",
3
- "version": "16.9.0-beta-1",
3
+ "version": "16.9.0",
4
4
  "description": "Validate and visualize dependencies. With your rules. JavaScript, TypeScript, CoffeeScript. ES6, CommonJS, AMD.",
5
5
  "keywords": [
6
6
  "static analysis",
@@ -1,24 +1,22 @@
1
1
  /* eslint-disable security/detect-object-injection */
2
2
 
3
3
  /** @import { IFlattenedRuleSet } from "../../../types/rule-set.mjs" */
4
+
5
+ function isCycleRule(pRule) {
6
+ return (
7
+ /* c8 ignore start */
8
+ Object.hasOwn(pRule?.to ?? {}, "circular")
9
+ /* c8 ignore stop */
10
+ );
11
+ }
4
12
  /**
5
13
  * @param {IFlattenedRuleSet} pRuleSet
6
14
  * @returns {boolean}
7
15
  */
8
16
  export function hasCycleRule(pRuleSet) {
9
17
  return (
10
- (pRuleSet?.forbidden ?? []).some(
11
- (pRule) =>
12
- /* c8 ignore start */
13
- Object.hasOwn(pRule?.to ?? {}, "circular"),
14
- /* c8 ignore stop */
15
- ) ||
16
- (pRuleSet?.allowed ?? []).some(
17
- (pRule) =>
18
- /* c8 ignore start */
19
- Object.hasOwn(pRule?.to ?? {}, "circular"),
20
- /* c8 ignore stop */
21
- )
18
+ (pRuleSet?.forbidden ?? []).some(isCycleRule) ||
19
+ (pRuleSet?.allowed ?? []).some(isCycleRule)
22
20
  );
23
21
  }
24
22
 
@@ -2,31 +2,28 @@ import getDependents from "./get-dependents.mjs";
2
2
 
3
3
  /** @import { IFlattenedRuleSet } from "../../../../types/rule-set.mjs" */
4
4
 
5
+ function isDependentsRule(pRule) {
6
+ // used in folder rules and when moreUnstable is in the 'to' => governed by
7
+ // the 'metrics' flag in options, sot not going to repeat that here
8
+
9
+ // dependents are used in the orphans analsys. hHwever, there is a fall back
10
+ // where it does its own analysis, so not going to repeat that check here.
11
+ return (
12
+ /* c8 ignore start */
13
+ Object.hasOwn(pRule?.module ?? {}, "numberOfDependentsLessThan") ||
14
+ Object.hasOwn(pRule?.module ?? {}, "numberOfDependentsMoreThan")
15
+ /* c8 ignore stop */
16
+ );
17
+ }
18
+
5
19
  /**
6
20
  * @param {IFlattenedRuleSet} pRuleSet
7
21
  * @returns {boolean}
8
22
  */
9
23
  export function hasDependentsRule(pRuleSet) {
10
- // used in folder rules and when moreUnstable is in the 'to' => governed by
11
- // the 'metrics' flag in options, sot not going to repeat that here
12
-
13
- // dependents are used in the orphans analsys, however, there is a fall back
14
- // where it does its own analysis, so not going to repeat that check here.
15
24
  return (
16
- (pRuleSet?.forbidden ?? []).some(
17
- (pRule) =>
18
- /* c8 ignore start */
19
- Object.hasOwn(pRule?.module ?? {}, "numberOfDependentsLessThan") ||
20
- Object.hasOwn(pRule?.module ?? {}, "numberOfDependentsMoreThan"),
21
- /* c8 ignore stop */
22
- ) ||
23
- (pRuleSet?.allowed ?? []).some(
24
- (pRule) =>
25
- /* c8 ignore start */
26
- Object.hasOwn(pRule?.module ?? {}, "numberOfDependentsLessThan") ||
27
- Object.hasOwn(pRule?.module ?? {}, "numberOfDependentsMoreThan"),
28
- /* c8 ignore stop */
29
- )
25
+ (pRuleSet?.forbidden ?? []).some(isDependentsRule) ||
26
+ (pRuleSet?.allowed ?? []).some(isDependentsRule)
30
27
  );
31
28
  }
32
29
 
@@ -1,24 +1,22 @@
1
1
  import isOrphan from "./is-orphan.mjs";
2
2
 
3
3
  /** @import { IFlattenedRuleSet } from "../../../../types/rule-set.mjs" */
4
+
5
+ function isOrphanRule(pRule) {
6
+ return (
7
+ /* c8 ignore start */
8
+ Object.hasOwn(pRule?.from ?? {}, "orphan")
9
+ /* c8 ignore stop */
10
+ );
11
+ }
4
12
  /**
5
13
  * @param {IFlattenedRuleSet} pRuleSet
6
14
  * @returns {boolean}
7
15
  */
8
16
  export function hasOrphanRule(pRuleSet) {
9
17
  return (
10
- (pRuleSet?.forbidden ?? []).some(
11
- (pRule) =>
12
- /* c8 ignore start */
13
- Object.hasOwn(pRule?.from ?? {}, "orphan"),
14
- /* c8 ignore stop */
15
- ) ||
16
- (pRuleSet?.allowed ?? []).some(
17
- (pRule) =>
18
- /* c8 ignore start */
19
- Object.hasOwn(pRule?.from ?? {}, "orphan"),
20
- /* c8 ignore stop */
21
- )
18
+ (pRuleSet?.forbidden ?? []).some(isOrphanRule) ||
19
+ (pRuleSet?.allowed ?? []).some(isOrphanRule)
22
20
  );
23
21
  }
24
22
 
@@ -6,19 +6,15 @@ import {
6
6
  import IndexedModuleGraph from "#graph-utl/indexed-module-graph.mjs";
7
7
  import { extractGroups } from "#utl/regex-util.mjs";
8
8
 
9
+ function isReachableRule(pRule) {
10
+ return Object.hasOwn(pRule?.to ?? {}, "reachable");
11
+ }
12
+
9
13
  function getReachableRules(pRuleSet) {
10
14
  return (pRuleSet?.forbidden ?? [])
11
- .filter((pRule) => Object.hasOwn(pRule?.to ?? {}, "reachable"))
12
- .concat(
13
- (pRuleSet?.allowed ?? []).filter((pRule) =>
14
- Object.hasOwn(pRule?.to ?? {}, "reachable"),
15
- ),
16
- )
17
- .concat(
18
- (pRuleSet?.required ?? []).filter((pRule) =>
19
- Object.hasOwn(pRule?.to ?? {}, "reachable"),
20
- ),
21
- );
15
+ .filter(isReachableRule)
16
+ .concat((pRuleSet?.allowed ?? []).filter(isReachableRule))
17
+ .concat((pRuleSet?.required ?? []).filter(isReachableRule));
22
18
  }
23
19
 
24
20
  function isModuleInRuleFrom(pRule) {
@@ -193,12 +189,15 @@ function addReachabilityToGraph(pGraph, pIndexedGraph, pReachableRule) {
193
189
 
194
190
  export default function deriveReachables(pGraph, pRuleSet) {
195
191
  const lReachableRules = pRuleSet ? getReachableRules(pRuleSet) : [];
196
- const lIndexedGraph =
197
- lReachableRules.length > 0 ? new IndexedModuleGraph(pGraph) : {};
198
192
 
199
- return lReachableRules.reduce(
200
- (pReturnGraph, pRule) =>
201
- addReachabilityToGraph(pReturnGraph, lIndexedGraph, pRule),
202
- structuredClone(pGraph),
203
- );
193
+ if (lReachableRules.length > 0) {
194
+ const lIndexedGraph = new IndexedModuleGraph(pGraph);
195
+
196
+ return lReachableRules.reduce(
197
+ (pReturnGraph, pRule) =>
198
+ addReachabilityToGraph(pReturnGraph, lIndexedGraph, pRule),
199
+ structuredClone(pGraph),
200
+ );
201
+ }
202
+ return pGraph;
204
203
  }
package/src/meta.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  /* generated - don't edit */
2
2
 
3
3
  module.exports = {
4
- version: "16.9.0-beta-1",
4
+ version: "16.9.0",
5
5
  engines: {
6
6
  node: "^18.17||>=20",
7
7
  },