dependency-cruiser 18.0.0 → 18.1.1

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.
Files changed (111) hide show
  1. package/configs/plugins/3d-reporter-plugin.mjs +1 -1
  2. package/configs/plugins/stats-reporter-plugin.mjs +2 -2
  3. package/package.json +5 -5
  4. package/src/analyze/add-validations.mjs +1 -1
  5. package/src/analyze/derive/folders/utl.mjs +2 -2
  6. package/src/analyze/summarize/index.mjs +121 -4
  7. package/src/analyze/summarize/summarize-modules.mjs +1 -1
  8. package/src/cache/cache.mjs +5 -5
  9. package/src/cache/helpers.mjs +2 -2
  10. package/src/cli/format-meta-info.mjs +12 -14
  11. package/src/cli/index.mjs +3 -4
  12. package/src/cli/init-config/check-and-warn-inconsistencies.mjs +3 -3
  13. package/src/cli/init-config/environment-helpers.mjs +4 -4
  14. package/src/cli/init-config/get-user-input.mjs +1 -1
  15. package/src/cli/init-config/index.mjs +1 -1
  16. package/src/cli/init-config/normalize-init-options.mjs +3 -3
  17. package/src/cli/init-config/validators.mjs +1 -1
  18. package/src/cli/init-config/write-run-scripts-to-manifest.mjs +2 -2
  19. package/src/cli/listeners/ndjson.mjs +1 -1
  20. package/src/cli/listeners/performance-log/index.mjs +1 -1
  21. package/src/cli/normalize-cli-options.mjs +6 -4
  22. package/src/cli/utl/assert-file-existence.mjs +1 -1
  23. package/src/config-utl/extract-babel-config.mjs +3 -1
  24. package/src/config-utl/extract-depcruise-config/index.mjs +1 -1
  25. package/src/config-utl/extract-depcruise-config/merge-configs.mjs +5 -3
  26. package/src/config-utl/extract-ts-config.mjs +1 -1
  27. package/src/config-utl/extract-webpack-resolve-config.mjs +2 -2
  28. package/src/environment.mjs +17 -0
  29. package/src/extract/acorn/extract.mjs +1 -1
  30. package/src/extract/acorn/parse.mjs +2 -2
  31. package/src/extract/extract-dependencies.mjs +1 -1
  32. package/src/extract/extract-stats.mjs +1 -1
  33. package/src/extract/gather-initial-sources.mjs +1 -1
  34. package/src/extract/helpers.mjs +1 -1
  35. package/src/extract/index.mjs +1 -1
  36. package/src/extract/resolve/determine-dependency-types.mjs +3 -2
  37. package/src/extract/resolve/external-module-helpers.mjs +8 -8
  38. package/src/extract/resolve/get-manifest.mjs +7 -7
  39. package/src/extract/resolve/index.mjs +2 -1
  40. package/src/extract/resolve/merge-manifests.mjs +2 -2
  41. package/src/extract/resolve/module-classifiers.mjs +1 -1
  42. package/src/extract/resolve/resolve-amd.mjs +1 -1
  43. package/src/extract/resolve/resolve-cjs.mjs +2 -2
  44. package/src/extract/resolve/resolve-helpers.mjs +1 -1
  45. package/src/extract/resolve/resolve.mjs +2 -2
  46. package/src/extract/swc/dependency-visitor.mjs +1 -0
  47. package/src/extract/swc/parse.mjs +2 -2
  48. package/src/extract/transpile/index.mjs +1 -1
  49. package/src/extract/transpile/meta.mjs +1 -1
  50. package/src/extract/transpile/try-import-available.mjs +1 -1
  51. package/src/extract/transpile/typescript-wrap.mjs +1 -1
  52. package/src/extract/tsc/extract-typescript-deps.mjs +1 -1
  53. package/src/extract/tsc/parse.mjs +3 -3
  54. package/src/graph-utl/add-focus.mjs +1 -1
  55. package/src/graph-utl/consolidate-to-pattern.mjs +1 -0
  56. package/src/graph-utl/indexed-module-graph.mjs +6 -6
  57. package/src/graph-utl/module-graph-with-dependency-set.mjs +1 -1
  58. package/src/graph-utl/rule-set.mjs +3 -3
  59. package/src/main/cruise.mjs +1 -1
  60. package/src/main/helpers.mjs +1 -1
  61. package/src/main/options/normalize.mjs +2 -2
  62. package/src/main/report-wrap.mjs +1 -0
  63. package/src/main/resolve-options/normalize.mjs +2 -2
  64. package/src/main/rule-set/assert-validity.mjs +1 -1
  65. package/src/main/rule-set/normalize.mjs +1 -1
  66. package/src/meta.cjs +1 -1
  67. package/src/report/anon/anonymize-path-element.mjs +1 -1
  68. package/src/report/anon/index.mjs +1 -1
  69. package/src/report/anon/random-string.mjs +1 -1
  70. package/src/report/azure-devops.mjs +2 -2
  71. package/src/report/baseline.mjs +1 -1
  72. package/src/report/d2.mjs +3 -3
  73. package/src/report/dot/index.mjs +1 -1
  74. package/src/report/dot/module-utl.mjs +2 -2
  75. package/src/report/dot/theming.mjs +12 -6
  76. package/src/report/dot-webpage/svg-in-html-snippets/script.cjs +7 -7
  77. package/src/report/error-html/error-html-template.mjs +7 -0
  78. package/src/report/error.mjs +33 -2
  79. package/src/report/html/index.mjs +2 -2
  80. package/src/report/index.mjs +1 -0
  81. package/src/report/markdown.mjs +3 -3
  82. package/src/report/mermaid.mjs +3 -3
  83. package/src/report/metrics.mjs +2 -2
  84. package/src/report/plugins.mjs +2 -1
  85. package/src/report/teamcity.mjs +2 -2
  86. package/src/report/utl/dependency-to-incidence-transformer.mjs +1 -1
  87. package/src/report/utl/index.mjs +1 -1
  88. package/src/schema/cruise-result.validate.mjs +1 -1
  89. package/src/utl/array-util.mjs +1 -1
  90. package/src/utl/find-all-files.mjs +1 -1
  91. package/src/utl/get-extension.mjs +1 -1
  92. package/src/utl/path-to-posix.mjs +1 -1
  93. package/src/utl/regex-util.mjs +4 -2
  94. package/src/utl/try-import.mjs +1 -1
  95. package/src/utl/try-require.cjs +3 -3
  96. package/src/validate/index.mjs +2 -2
  97. package/types/config-utl/extract-babel-config.d.mts +1 -1
  98. package/types/config-utl/extract-depcruise-config.d.mts +1 -1
  99. package/types/config-utl/extract-depcruise-options.d.mts +1 -1
  100. package/types/config-utl/extract-ts-config.d.mts +1 -1
  101. package/types/config-utl/extract-webpack-resolve-config.d.mts +1 -1
  102. package/types/cruise-result.d.mts +27 -0
  103. package/types/dependency-cruiser.d.mts +5 -26
  104. package/types/environment.d.mts +29 -0
  105. package/types/options.d.mts +1 -4
  106. package/types/plugins/3d-reporter-plugin.d.mts +1 -1
  107. package/types/plugins/mermaid-reporter-plugin.d.mts +1 -1
  108. package/types/plugins/stats-reporter-plugin.d.mts +1 -1
  109. package/types/rule-set.d.mts +2 -5
  110. package/types/shared-types.d.mts +1 -5
  111. package/types/strict-rule-set.d.mts +2 -5
@@ -4,7 +4,7 @@
4
4
  *
5
5
  * @param {string[]} pLeftArray an array of strings
6
6
  * @param {string[]} pRightArray another array of strings
7
- * @return {boolean} true if there's at least one element in pLeftArray also in pRightArray
7
+ * @returns {boolean} true if there's at least one element in pLeftArray also in pRightArray
8
8
  */
9
9
  export function intersects(pLeftArray, pRightArray) {
10
10
  if (pLeftArray.length === 0 || pRightArray.length === 0) {
@@ -56,7 +56,7 @@ function walk(
56
56
  function readIgnoreFile(pFileName) {
57
57
  try {
58
58
  return readFileSync(pFileName, "utf8");
59
- } catch (pError) {
59
+ } catch {
60
60
  return "";
61
61
  }
62
62
  }
@@ -13,7 +13,7 @@ const EXTENSION_RE = /(?<extension>(?:(?:\.d\.(?:[cm])?ts)|\.coffee\.md)$)/;
13
13
  * .ts, .cts and .mts
14
14
  *
15
15
  * @param {string} pFileName path to the file to be parsed
16
- * @return {string} extension
16
+ * @returns {string} extension
17
17
  */
18
18
  export default function getExtension(pFileName) {
19
19
  const lMatchResult = EXTENSION_RE.exec(pFileName);
@@ -17,7 +17,7 @@ import path from "node:path";
17
17
  * @param {string} pFilePath the path to transform
18
18
  * @param {path} pPathModule? optional - the path module/ object to use (for testing
19
19
  * this module on posix platforms only; defaults to require('path'))
20
- * @return {string} the transformed path
20
+ * @returns {string} the transformed path
21
21
  */
22
22
  export default function pathToPosix(pFilePath, pPathModule = path) {
23
23
  const lPathModule = pPathModule || path;
@@ -29,7 +29,7 @@ export function clearRegExpCache() {
29
29
  * This fills our current need. Later we can expand it to return all group
30
30
  * matches.
31
31
  *
32
- * @param {import("../../types/restrictions").IFromRestriction} pFromRestriction
32
+ * @param {import("../../types/restrictions.mjs").IFromRestriction} pFromRestriction
33
33
  * @param {string} pActualPath
34
34
  * @returns {string[]|null}
35
35
  */
@@ -41,7 +41,9 @@ export function extractGroups(pFromRestriction, pActualPath) {
41
41
  // except before it enters here it has already been 'normalized' to a string
42
42
  // so it can be safely passed to match. The right solution here (TODO)
43
43
  // is to create a separate type for NormalizedFromRestriction
44
- let lMatchResult = getCachedRegExp(pFromRestriction.path).exec(pActualPath);
44
+ const lMatchResult = getCachedRegExp(pFromRestriction.path).exec(
45
+ pActualPath,
46
+ );
45
47
 
46
48
  if (lMatchResult && lMatchResult.length > 1) {
47
49
  lReturnValue = lMatchResult.filter(
@@ -60,7 +60,7 @@ export default async function tryImport(pModuleName, pSemanticVersion) {
60
60
  }
61
61
  const lModule = await import(pModuleName);
62
62
  return lModule.default ? lModule.default : lModule;
63
- } catch (pError) {
63
+ } catch {
64
64
  return false;
65
65
  }
66
66
  }
@@ -6,7 +6,7 @@ const extractRootModuleName = require("./extract-root-module-name.cjs");
6
6
  /**
7
7
  * @throws {Error}
8
8
  * @param pModuleName the name of the module to get the version for
9
- * @return the version of the module identified by pModuleName
9
+ * @returns the version of the module identified by pModuleName
10
10
  */
11
11
  function getVersion(pModuleName) {
12
12
  // @ts-expect-error TS2345 extractRootModuleName can return either a string or
@@ -26,7 +26,7 @@ function getVersion(pModuleName) {
26
26
  *
27
27
  * @param {string} pModuleName the name of the module to resolve
28
28
  * @param {string} [pSemanticVersion] (optional) a semantic version (range)
29
- * @return {NodeModule | false }the (resolved) module identified by pModuleName or false
29
+ * @returns {NodeModule | false }the (resolved) module identified by pModuleName or false
30
30
  */
31
31
  function tryRequire(pModuleName, pSemanticVersion) {
32
32
  try {
@@ -43,7 +43,7 @@ function tryRequire(pModuleName, pSemanticVersion) {
43
43
  }
44
44
  // eslint-disable-next-line import/no-dynamic-require, n/global-require, security/detect-non-literal-require
45
45
  return require(pModuleName);
46
- } catch (pError) {
46
+ } catch {
47
47
  return false;
48
48
  }
49
49
  }
@@ -18,7 +18,7 @@ function compareSeverity(pFirst, pSecond) {
18
18
  }
19
19
 
20
20
  function validateAgainstAllowedRules(pRuleSet, pMatchModule, pFrom, pTo) {
21
- let lFoundRuleViolations = [];
21
+ const lFoundRuleViolations = [];
22
22
 
23
23
  if (pRuleSet.allowed) {
24
24
  const lInterestingAllowedRules = pRuleSet.allowed.filter(
@@ -75,7 +75,7 @@ function validateAgainstRequiredRules(pRuleSet, pModule, pMatchModule) {
75
75
  */
76
76
  function validateAgainstRules(pRuleSet, pFrom, pTo, pMatchModule) {
77
77
  /** @type {IValidationResult} */
78
- let lReturnValue = { valid: true };
78
+ const lReturnValue = { valid: true };
79
79
 
80
80
  const lFoundRuleViolations = validateAgainstAllowedRules(
81
81
  pRuleSet,
@@ -5,7 +5,7 @@
5
5
  * Silently fails if a supported @babel/core version can't be found
6
6
  *
7
7
  * @param pBabelConfigFileName
8
- * @return babel config as an object
8
+ * @returns babel config as an object
9
9
  * @throws when the babel config has an unknown extension OR
10
10
  * when the babel config is invalid OR
11
11
  * when dependency-cruiser can't yet process it
@@ -17,7 +17,7 @@ import type { IConfiguration } from "../configuration.mjs";
17
17
  * @param pConfigFileName
18
18
  * @param pAlreadyVisited
19
19
  * @param pBaseDirectory
20
- * @return dependency-cruiser configuration
20
+ * @returns dependency-cruiser configuration
21
21
  * @throws when the config is not valid (/ does not exist/ isn't readable)
22
22
  */
23
23
  export default function extractDepcruiseConfig(
@@ -10,7 +10,7 @@ import type { ICruiseOptions } from "../options.mjs";
10
10
  * ```
11
11
  *
12
12
  * @param pConfigFileName
13
- * @return dependency-cruiser options
13
+ * @returns dependency-cruiser options
14
14
  * @throws when the config is not valid (/ does not exist/ isn't readable)
15
15
  */
16
16
  export default function extractDepcruiseOptions(
@@ -7,7 +7,7 @@ import type { ParsedCommandLine } from "typescript";
7
7
  * Silently fails if a supported version of the typescript compiler isn't available
8
8
  *
9
9
  * @param pTSConfigFileName
10
- * @return tsconfig as an object
10
+ * @returns tsconfig as an object
11
11
  * @throws {Error} when the tsconfig is invalid/ has errors
12
12
  * @throws {TypeError} when the tsconfig is unreadable
13
13
  */
@@ -8,7 +8,7 @@ import type { ResolveOptions } from "enhanced-resolve";
8
8
  * @param pWebpackConfigFilename
9
9
  * @param pEnvironment
10
10
  * @param pArguments
11
- * @return webpack resolve config as an object
11
+ * @returns webpack resolve config as an object
12
12
  * @throws when the webpack config isn't usable (e.g. because it
13
13
  * doesn't exist, or because it's invalid)
14
14
  */
@@ -6,10 +6,15 @@ import type {
6
6
  ModuleSystemType,
7
7
  ProtocolType,
8
8
  ExperimentalStatsType,
9
+ SeverityType,
9
10
  } from "./shared-types.mjs";
10
11
  import type { IViolation } from "./violations.mjs";
11
12
  import type { IRuleSummary } from "./rule-summary.mjs";
12
13
  import type { IChange } from "watskeburt";
14
+ import type {
15
+ IAvailableExtension,
16
+ IAvailableTranspiler,
17
+ } from "./environment.mjs";
13
18
 
14
19
  export interface IRevisionChange extends IChange {
15
20
  // optional because
@@ -359,6 +364,28 @@ export interface ISummary {
359
364
  * the number of warnings in the dependencies
360
365
  */
361
366
  warn: number;
367
+ /**
368
+ * information on the environment the cruise ran on
369
+ */
370
+ environment: {
371
+ version: string;
372
+ nodeVersionSupported: string;
373
+ nodeVersionFound: string;
374
+ osVersionFound: string;
375
+ transpilersFound: IAvailableTranspiler[];
376
+ extensionsFound: IAvailableExtension[];
377
+ /**
378
+ * Issues detected in the environment that might have influenced the cruise
379
+ * e.g. a missing (supported) typescript transpiler, while there's a tsconfig
380
+ */
381
+ issues?: IEnvironmentIssue[];
382
+ };
383
+ }
384
+
385
+ export interface IEnvironmentIssue {
386
+ severity: SeverityType;
387
+ name: string;
388
+ description: string;
362
389
  }
363
390
 
364
391
  /**
@@ -1,6 +1,10 @@
1
1
  import type { ICruiseResult } from "./cruise-result.mjs";
2
2
  import type { ICruiseOptions, IFormatOptions } from "./options.mjs";
3
3
  import type { IResolveOptions } from "./resolve-options.mjs";
4
+ import type {
5
+ IAvailableExtension,
6
+ IAvailableTranspiler,
7
+ } from "./environment.mjs";
4
8
 
5
9
  export type * from "./rule-set.mjs";
6
10
  export type * from "./options.mjs";
@@ -8,6 +12,7 @@ export type * from "./configuration.mjs";
8
12
  export type * from "./shared-types.mjs";
9
13
  export type * from "./cruise-result.mjs";
10
14
  export type * from "./resolve-options.mjs";
15
+ export type * from "./environment.mjs";
11
16
 
12
17
  /**
13
18
  * all supported extensions; for each extension whether or not
@@ -15,32 +20,6 @@ export type * from "./resolve-options.mjs";
15
20
  */
16
21
  export const allExtensions: IAvailableExtension[];
17
22
 
18
- export interface IAvailableExtension {
19
- /**
20
- * File extension (e.g. ".js", ".ts", ".jsx")
21
- */
22
- extension: string;
23
- /**
24
- * Whether or not the extension is available as supported in the current environment
25
- */
26
- available: boolean;
27
- }
28
-
29
- export interface IAvailableTranspiler {
30
- /**
31
- * The name of the transpiler (e.g. "typescript", "coffeescript")
32
- */
33
- name: string;
34
- /**
35
- * A semver version range (e.g. ">=2.0.0 <3.0.0")
36
- */
37
- version: string;
38
- /**
39
- * Whether or not the transpiler is available in the current environment
40
- */
41
- available: boolean;
42
- }
43
-
44
23
  export interface IReporterOutput {
45
24
  /**
46
25
  * The output proper of the reporter. For most reporters this will be
@@ -0,0 +1,29 @@
1
+ export interface IAvailableExtension {
2
+ /**
3
+ * File extension (e.g. ".js", ".ts", ".jsx")
4
+ */
5
+ extension: string;
6
+ /**
7
+ * Whether or not the extension is available as supported in the current environment
8
+ */
9
+ available: boolean;
10
+ }
11
+
12
+ export interface IAvailableTranspiler {
13
+ /**
14
+ * The name of the transpiler (e.g. "typescript", "coffeescript")
15
+ */
16
+ name: string;
17
+ /**
18
+ * A semver version range (e.g. ">=2.0.0 <3.0.0")
19
+ */
20
+ version: string;
21
+ /**
22
+ * The currently installed version (e.g. 2.3.4). '-' if not installed
23
+ */
24
+ currentVersion: string;
25
+ /**
26
+ * Whether or not the transpiler is available in the current environment
27
+ */
28
+ available: boolean;
29
+ }
@@ -14,10 +14,7 @@ import type { ModuleSystemType, OutputType } from "./shared-types.mjs";
14
14
 
15
15
  export type ExternalModuleResolutionStrategyType = "node_modules" | "yarn-pnp";
16
16
  export type ProgressType =
17
- | "cli-feedback"
18
- | "performance-log"
19
- | "ndjson"
20
- | "none";
17
+ "cli-feedback" | "performance-log" | "ndjson" | "none";
21
18
  export type ParserType = "acorn" | "tsc" | "swc";
22
19
 
23
20
  export interface ITsConfig {
@@ -5,7 +5,7 @@ declare module "3d-reporter-plugin" {
5
5
  * Sample plugin: 3d representation
6
6
  *
7
7
  * @param {ICruiseResult} pCruiseResult - the output of a dependency-cruise adhering to dependency-cruiser's cruise result schema
8
- * @return {IReporterOutput} - output: a string, exitCode: 0
8
+ * @returns {IReporterOutput} - output: a string, exitCode: 0
9
9
  */
10
10
  export default function ThreeDReporterPlugin(
11
11
  pCruiseResult: ICruiseResult,
@@ -6,7 +6,7 @@ declare module "mermaid-reporter-plugin" {
6
6
  *
7
7
  * @deprecated use the mermaid reporter baked into the dependency-cruiser itself (--output-type mermaid)
8
8
  * @param {ICruiseResult} pCruiseResult - the output of a dependency-cruise adhering to dependency-cruiser's cruise result schema
9
- * @return {IReporterOutput} - output: the module graph in mermaid format, exitCode: 0
9
+ * @returns {IReporterOutput} - output: the module graph in mermaid format, exitCode: 0
10
10
  */
11
11
  export default function statsReporterPlugin(
12
12
  pCruiseResult: ICruiseResult,
@@ -5,7 +5,7 @@ declare module "stats-reporter-plugin" {
5
5
  * Sample plugin: stats in json format
6
6
  *
7
7
  * @param {ICruiseResult} pCruiseResult - the output of a dependency-cruise adhering to dependency-cruiser's cruise result schema
8
- * @return {IReporterOutput} - output: output: some stats on modules and dependencies in json format, exitCode: 0
8
+ * @returns {IReporterOutput} - output: output: some stats on modules and dependencies in json format, exitCode: 0
9
9
  */
10
10
  export default function statsReporterPlugin(
11
11
  pCruiseResult: ICruiseResult,
@@ -128,13 +128,10 @@ export interface IRegularAllowedRuleType {
128
128
  }
129
129
 
130
130
  export type IAllowedRuleType =
131
- | IRegularAllowedRuleType
132
- | IReachabilityAllowedRuleType;
131
+ IRegularAllowedRuleType | IReachabilityAllowedRuleType;
133
132
 
134
133
  export type IAnyRuleType =
135
- | IForbiddenRuleType
136
- | IAllowedRuleType
137
- | IRequiredRuleType;
134
+ IForbiddenRuleType | IAllowedRuleType | IRequiredRuleType;
138
135
 
139
136
  export interface IFlattenedRuleSet {
140
137
  /**
@@ -75,11 +75,7 @@ export type DependencyType =
75
75
  export type ProtocolType = "data:" | "file:" | "node:";
76
76
 
77
77
  export type ViolationType =
78
- | "dependency"
79
- | "module"
80
- | "cycle"
81
- | "reachability"
82
- | "instability";
78
+ "dependency" | "module" | "cycle" | "reachability" | "instability";
83
79
 
84
80
  export type RuleScopeType = "module" | "folder";
85
81
 
@@ -54,13 +54,10 @@ export interface IStrictRegularAllowedRuleType extends IRegularAllowedRuleType {
54
54
  to: IStrictToRestriction;
55
55
  }
56
56
  export type IStrictAllowedRuleType =
57
- | IStrictRegularAllowedRuleType
58
- | IStrictReachabilityAllowedRuleType;
57
+ IStrictRegularAllowedRuleType | IStrictReachabilityAllowedRuleType;
59
58
 
60
59
  export type IStrictAnyRuleType =
61
- | IStrictForbiddenRuleType
62
- | IStrictAllowedRuleType
63
- | IStrictRequiredRuleType;
60
+ IStrictForbiddenRuleType | IStrictAllowedRuleType | IStrictRequiredRuleType;
64
61
 
65
62
  export interface IStrictRuleSet extends IFlattenedRuleSet {
66
63
  forbidden?: IStrictForbiddenRuleType[];