dependency-cruiser 18.7.0 → 18.7.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.
package/README.md CHANGED
@@ -193,7 +193,6 @@ You've come to the right place :-) :
193
193
  ## Build status
194
194
 
195
195
  [![GitHub Workflow Status](https://github.com/sverweij/dependency-cruiser/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/sverweij/dependency-cruiser/actions/workflows/ci.yml)
196
- [![coverage](https://gitlab.com/sverweij/dependency-cruiser/badges/master/coverage.svg)](https://gitlab.com/sverweij/dependency-cruiser/builds)
197
196
  [![total downloads on npm](https://img.shields.io/npm/dt/dependency-cruiser.svg?maxAge=2591999)](https://npmjs.com/package/dependency-cruiser)
198
197
 
199
198
  Made with :metal: in Holland.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dependency-cruiser",
3
- "version": "18.7.0",
3
+ "version": "18.7.1",
4
4
  "description": "Validate and visualize dependencies. With your rules. JavaScript, TypeScript, CoffeeScript. ES6, CommonJS, AMD.",
5
5
  "keywords": [
6
6
  "static analysis",
@@ -150,7 +150,7 @@
150
150
  "acorn-walk": "8.3.5",
151
151
  "commander": "15.0.0",
152
152
  "enhanced-resolve": "5.26.0",
153
- "ignore": "7.0.12",
153
+ "ignore": "7.0.14",
154
154
  "interpret": "3.1.1",
155
155
  "is-installed-globally": "1.0.1",
156
156
  "json5": "2.2.3",
@@ -11,10 +11,10 @@ import { bus } from "#utl/bus.mjs";
11
11
  * used in the cruise, so consumers of the cruise result (reporters, depcruise-fmt,
12
12
  * caching) can use that.
13
13
  *
14
- * @param {import("../../types/dependency-cruiser.js").IModule[]} pModules
14
+ * @param {import("../../types/dependency-cruiser.mjs").IModule[]} pModules
15
15
  * @param {import("../../types/options.mjs").ICruiseOptions} pOptions
16
16
  * @param {string[]} pFileAndDirectoryArray
17
- * @returns {import("../../types/dependency-cruiser.js").ICruiseResult}
17
+ * @returns {import("../../types/dependency-cruiser.mjs").ICruiseResult}
18
18
  */
19
19
  export default function analyze(pModules, pOptions, pFileAndDirectoryArray) {
20
20
  const lModules = analyzeModules(pModules, pOptions);
@@ -17,4 +17,3 @@ export const BABEL_CONFIG = ".babelrc";
17
17
  export const PACKAGE_MANIFEST = "package.json";
18
18
  export const OUTPUT_TYPE = "err";
19
19
  export const OUTPUT_TO = "-";
20
- export const CACHE_FOLDER = "node_modules/.cache/dependency-cruiser";
@@ -57,7 +57,7 @@ export default function extractTSConfig(pTSConfigFileName) {
57
57
  typescript.sys,
58
58
  dirname(resolve(pTSConfigFileName)),
59
59
  {},
60
- pTSConfigFileName,
60
+ resolve(pTSConfigFileName),
61
61
  );
62
62
 
63
63
  if (lReturnValue.errors.length > 0) {
@@ -30,7 +30,7 @@ const CACHE = new Map();
30
30
  * @param {string} pFileName
31
31
  * @returns {ParseOptions}
32
32
  */
33
- export function getOptionsFor(pFileName) {
33
+ function getOptionsFor(pFileName) {
34
34
  return /[.](?:tsx|jsx)$/.test(pFileName)
35
35
  ? { ...SWC_PARSE_OPTIONS, tsx: true }
36
36
  : SWC_PARSE_OPTIONS;
@@ -13,7 +13,7 @@ const coffeeVanillaWrap = coffeeWrap();
13
13
  const litCoffeeWrap = coffeeWrap(true);
14
14
  const svelteWrap = svelteDingus(typeScriptVanillaWrap);
15
15
 
16
- export const EXTENSION2WRAPPER = new Map([
16
+ const EXTENSION2WRAPPER = new Map([
17
17
  [".js", javaScriptWrap],
18
18
  [".cjs", javaScriptWrap],
19
19
  [".mjs", javaScriptWrap],
@@ -1,3 +1,4 @@
1
+ import { resolve } from "node:path";
1
2
  import tryImport from "#utl/try-import.mjs";
2
3
  import meta from "#meta.cjs";
3
4
 
@@ -6,6 +7,16 @@ const typescript = await tryImport(
6
7
  meta.supportedTranspilers.typescript,
7
8
  );
8
9
 
10
+ // This RE matches
11
+ // - filename.d.ts (, .cts, .mts), but also
12
+ // - filename.d.something.ts (, .cts., .mts).
13
+ // That second one seems a bit odd, but it _is_ possible; see for instance
14
+ // https://www.typescriptlang.org/tsconfig/#allowArbitraryExtensions
15
+ // (and I guess, but haven't seen this confirmed in the field or documentation
16
+ // that it could be possible to have a declaration file variant of
17
+ // https://www.typescriptlang.org/tsconfig/#moduleSuffixes)
18
+ const DECLARATION_FILE_RE = /[.]d([.][^./\\]+)?([.][cm]?ts)$/;
19
+
9
20
  function getCompilerOptions(pFlavor, pTSConfig) {
10
21
  const lCompilerOptions = {};
11
22
 
@@ -32,15 +43,26 @@ function getCompilerOptions(pFlavor, pTSConfig) {
32
43
  };
33
44
  }
34
45
 
46
+ function getTranspilableFileName(pFileName) {
47
+ if (typeof pFileName !== "string") {
48
+ return undefined;
49
+ }
50
+ // Declaration files (.d.ts, .d.mts, .d.cts, .d.css.ts) get their
51
+ // non-declaration name, because TypeScript emits nothing for a declaration
52
+ // file and throws "Debug Failure. Output generation failed".
53
+ return resolve(pFileName).replace(DECLARATION_FILE_RE, "$1$2");
54
+ }
55
+
35
56
  export default function typescriptWrap(pFlavor) {
36
57
  return {
37
58
  isAvailable: () => typescript !== false,
38
59
 
39
60
  version: () => `typescript@${typescript.version}`,
40
61
 
41
- transpile: (pSource, _pFileName, pTranspileOptions = {}) =>
62
+ transpile: (pSource, pFileName, pTranspileOptions = {}) =>
42
63
  typescript.transpileModule(pSource, {
43
64
  ...(pTranspileOptions.tsConfig || {}),
65
+ fileName: getTranspilableFileName(pFileName),
44
66
  compilerOptions: getCompilerOptions(
45
67
  pFlavor,
46
68
  pTranspileOptions.tsConfig || {},
@@ -23,8 +23,8 @@ function scrub(pModuleNamesSet) {
23
23
 
24
24
  /**
25
25
  *
26
- * @param {import("../../types/dependency-cruiser.js").IModule[]} pModules
27
- * @param {import("../../types/strict-filter-types.js").IStrictFocusType} pFilter
26
+ * @param {import("../../types/dependency-cruiser.mjs").IModule[]} pModules
27
+ * @param {import("../../types/strict-filter-types.mjs").IStrictFocusType} pFilter
28
28
  * @returns
29
29
  */
30
30
  export default function addFocus(pModules, pFilter) {
@@ -7,7 +7,7 @@ import { clearRegExpCache } from "#utl/regex-util.mjs";
7
7
 
8
8
  const TOTAL_STEPS = 10;
9
9
 
10
- export function c(pComplete, pTotal = TOTAL_STEPS) {
10
+ function c(pComplete, pTotal = TOTAL_STEPS) {
11
11
  return { complete: pComplete / pTotal };
12
12
  }
13
13
 
@@ -81,7 +81,6 @@ export default async function cruise(
81
81
  const lNormalizedResolveOptions = await normalizeResolveOptions(
82
82
  pResolveOptions,
83
83
  lCruiseOptions,
84
- pTranspileOptions?.tsConfig,
85
84
  );
86
85
 
87
86
  bus.summary("extract", c(6));
@@ -11,7 +11,7 @@ function validateResultAgainstSchema(pResult) {
11
11
  );
12
12
  }
13
13
  }
14
- /** @type {import("../../types/dependency-cruiser.js").format} */
14
+ /** @type {import("../../types/dependency-cruiser.mjs").format} */
15
15
  export default async function format(pResult, pFormatOptions = {}) {
16
16
  const lFormatOptions = normalizeFormatOptions(pFormatOptions);
17
17
  assertFormatOptionsValid(lFormatOptions);
@@ -68,7 +68,6 @@ function pushPlugin(pPlugins, pPluginToPush) {
68
68
  // eslint-disable-next-line max-lines-per-function
69
69
  async function compileResolveOptions(
70
70
  pResolveOptions,
71
- pTSConfig,
72
71
  pResolveOptionsFromDCConfig,
73
72
  ) {
74
73
  const lResolveOptions = {};
@@ -86,29 +85,6 @@ async function compileResolveOptions(
86
85
  // @ts-expect-error TS2351 "TsConfPathsPlugin is not constructable" - is unjustified
87
86
  new TsConfigPathsPlugin({
88
87
  configFile: pResolveOptions.tsConfig,
89
- // TsConfigPathsPlugin requires a baseUrl to be present in the tsconfig,
90
- // otherwise it prints scary messages that it didn't and read the tsConfig
91
- // (potentially making users think it's dependency-cruiser disregarding the
92
- // tsconfig). Hence up till version 13.0.4 dependency-cruiser only loaded
93
- // TsConfigPathsPlugin when an options.baseUrl existed. However, this
94
- // isn't necessary anymore:
95
- // - [tsconfig#baseUrl documentation](https://www.typescriptlang.org/tsconfig#baseUrl)
96
- // UNrecommends the use of the baseUrl for non-AMD projects
97
- // - [tsconfig-paths PR #207](https://github.com/dividab/tsconfig-paths/pull/208)
98
- // 'tolerates' undefined baseUrls
99
- //
100
- // Hence, until
101
- // [tpwp issue #99](https://github.com/dividab/tsconfig-paths-webpack-plugin/issues/99)
102
- // lands:
103
- // - pass a default baseUrl to TsConfigPathsPlugin if the baseUrl isn't available
104
- // - pass undefined in all other cases; TsConfigPathsPlugin will read
105
- // it from the tsconfig.json in that case. Passing the processed baseUrl
106
- // (pTSConfig?.options?.baseUrl) instead would've been more obvious, but
107
- // doesn't work, as that is an absolute path and tsconfig-paths(-wpp)
108
- // seems to process that again resulting in invalid paths and unresolved
109
- // or erroneous dependencies
110
- // eslint-disable-next-line no-undefined
111
- baseUrl: pTSConfig?.options?.baseUrl ? undefined : "./",
112
88
  // TsConfigPathsPlugin doesn't (can't) read enhanced-resolve's
113
89
  // list of extensions, and the default it uses for extensions
114
90
  // so we do it ourselves - either with the extensions passed
@@ -136,14 +112,12 @@ async function compileResolveOptions(
136
112
  /**
137
113
  * @param {IResolveOptions} pResolveOptions
138
114
  * @param {ICruiseOptions} pOptions
139
- * @param {import("typescript").ParsedTsconfig} pTSConfig
140
115
  * @returns
141
116
  */
142
117
  // eslint-disable-next-line complexity
143
118
  export default async function normalizeResolveOptions(
144
119
  pResolveOptions,
145
120
  pOptions,
146
- pTSConfig,
147
121
  ) {
148
122
  const lRuleSet = pOptions?.ruleSet ?? {};
149
123
 
@@ -174,7 +148,6 @@ export default async function normalizeResolveOptions(
174
148
  resolveDeprecations: ruleSetHasDeprecationRule(lRuleSet),
175
149
  ...pResolveOptions,
176
150
  },
177
- pTSConfig || {},
178
151
  pOptions?.enhancedResolveOptions ?? {},
179
152
  );
180
153
  }
package/src/meta.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  /* generated - don't edit */
2
2
  module.exports = {
3
- version: "18.7.0",
3
+ version: "18.7.1",
4
4
  engines: {
5
5
  node: "^22||^24||>=26",
6
6
  },
@@ -174,7 +174,7 @@ function sanitizeWordList(pWordList) {
174
174
  * not passed the reporter uses the string passed
175
175
  * in the options (reporterOptions.anon.wordlist)
176
176
  * or - if that doesn't exist - the empty array
177
- * @returns {import("../../../types/dependency-cruiser.js").IReporterOutput} - output: the results in JSON format (hence adhering to the same json schema)
177
+ * @returns {import("../../../types/dependency-cruiser.mjs").IReporterOutput} - output: the results in JSON format (hence adhering to the same json schema)
178
178
  * exitCode: 0
179
179
  */
180
180
  export default function reportAnonymous(pResults, pAnonymousReporterOptions) {
@@ -13,7 +13,7 @@ const SEVERITY2VSO_TYPE = new Map([
13
13
  ]);
14
14
 
15
15
  /**
16
- * @param {import("../../types/shared-types.js").SeverityType} pSeverity
16
+ * @param {import("../../types/shared-types.mjs").SeverityType} pSeverity
17
17
  * @returns {string}
18
18
  */
19
19
  function formatSeverity(pSeverity) {
@@ -21,7 +21,7 @@ function formatSeverity(pSeverity) {
21
21
  }
22
22
 
23
23
  /**
24
- * @param {import("../../types/violations.js").IViolation} pViolation
24
+ * @param {import("../../types/violations.mjs").IViolation} pViolation
25
25
  * @returns {string}
26
26
  */
27
27
  function formatModuleViolation(pViolation) {
@@ -29,7 +29,7 @@ function formatModuleViolation(pViolation) {
29
29
  }
30
30
 
31
31
  /**
32
- * @param {import("../../types/violations.js").IViolation} pViolation
32
+ * @param {import("../../types/violations.mjs").IViolation} pViolation
33
33
  * @returns {string}
34
34
  */
35
35
  function formatDependencyViolation(pViolation) {
@@ -37,7 +37,7 @@ function formatDependencyViolation(pViolation) {
37
37
  }
38
38
 
39
39
  /**
40
- * @param {import("../../types/violations.js").IViolation} pViolation
40
+ * @param {import("../../types/violations.mjs").IViolation} pViolation
41
41
  * @returns {string}
42
42
  */
43
43
  function formatCycleViolation(pViolation) {
@@ -47,7 +47,7 @@ function formatCycleViolation(pViolation) {
47
47
  }
48
48
 
49
49
  /**
50
- * @param {import("../../types/violations.js").IViolation} pViolation
50
+ * @param {import("../../types/violations.mjs").IViolation} pViolation
51
51
  * @returns {string}
52
52
  */
53
53
  function formatReachabilityViolation(pViolation) {
@@ -57,7 +57,7 @@ function formatReachabilityViolation(pViolation) {
57
57
  }
58
58
 
59
59
  /**
60
- * @param {import("../../types/violations.js").IViolation} pViolation
60
+ * @param {import("../../types/violations.mjs").IViolation} pViolation
61
61
  * @returns {string}
62
62
  */
63
63
  function formatInstabilityViolation(pViolation) {
@@ -69,7 +69,7 @@ function formatInstabilityViolation(pViolation) {
69
69
  }
70
70
 
71
71
  /**
72
- * @param {import("../../types/violations.js").IViolation} pViolation
72
+ * @param {import("../../types/violations.mjs").IViolation} pViolation
73
73
  * @returns {string}
74
74
  */
75
75
  function formatViolation(pViolation) {
@@ -167,8 +167,8 @@ function formatSummary(pSummary) {
167
167
  * Background documentation:
168
168
  * https://learn.microsoft.com/en-us/azure/devops/pipelines/scripts/logging-commands?view=azure-devops&tabs=bash#task-commands
169
169
  *
170
- * @param {import("../../types/dependency-cruiser.js").ICruiseResult} pResults
171
- * @returns {import("../../types/dependency-cruiser.js").IReporterOutput}
170
+ * @param {import("../../types/dependency-cruiser.mjs").ICruiseResult} pResults
171
+ * @returns {import("../../types/dependency-cruiser.mjs").IReporterOutput}
172
172
  */
173
173
  // eslint-disable-next-line unicorn/prevent-abbreviations
174
174
  export default function azureDevOps(pResults) {
@@ -27,7 +27,7 @@ function report(pModules) {
27
27
  *
28
28
  * @param {import("../../types/cruise-result.mjs").ICruiseResult} pResults -
29
29
  * the output of a dependency-cruise adhering to ../../schema/cruise-result.schema.json
30
- * @returns {import("../../types/dependency-cruiser.js").IReporterOutput}
30
+ * @returns {import("../../types/dependency-cruiser.mjs").IReporterOutput}
31
31
  */
32
32
  export default function csv(pResults) {
33
33
  return {
@@ -214,7 +214,7 @@ function normalizeDotReporterOptions(
214
214
  * @param {string} pGranularity - either "module" (for fine grained module
215
215
  * level) or "folder" (for a report consolidated
216
216
  * to folders)
217
- * @returns {(pResults, pDotReporterOptions) => import("../../../types/dependency-cruiser.js").IReporterOutput}
217
+ * @returns {(pResults, pDotReporterOptions) => import("../../../types/dependency-cruiser.mjs").IReporterOutput}
218
218
  */
219
219
  export default function produceDotReporter(pGranularity) {
220
220
  return function dot(pResults, pDotReporterOptions) {
@@ -11,7 +11,7 @@ import wrapAndIndent from "#utl/wrap-and-indent.mjs";
11
11
  /**
12
12
  * @import { ICruiseResult, IEnvironmentIssue } from "../../types/cruise-result.mjs"
13
13
  * @import { IErrorReporterOptions } from "../../types/reporter-options.mjs"
14
- * @import { IReporterOutput } from "../../types/dependency-cruiser.js"
14
+ * @import { IReporterOutput } from "../../types/dependency-cruiser.mjs"
15
15
  * @import { SeverityType } from "../../types/shared-types.mjs"
16
16
  */
17
17
 
@@ -110,7 +110,7 @@ function report(pResults) {
110
110
  * Returns the results of a cruise in an 'incidence matrix'
111
111
  *
112
112
  * @param {import("../../../types/cruise-result.mjs").ICruiseResult} pResults
113
- * @returns {import("../../../types/dependency-cruiser.js").IReporterOutput}
113
+ * @returns {import("../../../types/dependency-cruiser.mjs").IReporterOutput}
114
114
  */
115
115
  export default function html(pResults) {
116
116
  return {
@@ -31,7 +31,7 @@ const TYPE2MODULE = new Map([
31
31
  * Returns the reporter function associated with given output type,
32
32
  * or the identity reporter if that output type wasn't found
33
33
  *
34
- * @param {import("../../types/shared-types.js").OutputType} pOutputType -
34
+ * @param {import("../../types/shared-types.mjs").OutputType} pOutputType -
35
35
  * @returns {function} - a function that takes an ICruiseResult, optionally
36
36
  * an options object (specific to that function)
37
37
  * and returns an IReporterOutput
@@ -52,7 +52,7 @@ export async function getReporter(pOutputType) {
52
52
  /**
53
53
  * Returns a list of all currently available reporters
54
54
  *
55
- * @returns {import("../../types/shared-types.js").OutputType[]} -
55
+ * @returns {import("../../types/shared-types.mjs").OutputType[]} -
56
56
  */
57
57
  export function getAvailableReporters() {
58
58
  return Array.from(TYPE2MODULE.keys());
@@ -266,9 +266,9 @@ function transformMetricsToTable(
266
266
  * Potential future features:
267
267
  * - additional output formats (csv?, html?)
268
268
  *
269
- * @param {import('../../types/dependency-cruiser.js').ICruiseResult} pCruiseResult -
270
- * @param {import("../../types/reporter-options.js").IMetricsReporterOptions} pReporterOptions
271
- * @returns {import('../../types/dependency-cruiser.js').IReporterOutput} -
269
+ * @param {import('../../types/dependency-cruiser.mjs').ICruiseResult} pCruiseResult -
270
+ * @param {import("../../types/reporter-options.mjs").IMetricsReporterOptions} pReporterOptions
271
+ * @returns {import('../../types/dependency-cruiser.mjs').IReporterOutput} -
272
272
  */
273
273
  export default function metrics(pCruiseResult, pReporterOptions) {
274
274
  const lReporterOptions = pReporterOptions || {};