dependency-cruiser 18.8.0-beta-1 → 18.8.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/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.8.0-beta-1",
3
+ "version": "18.8.0",
4
4
  "description": "Validate and visualize dependencies. With your rules. JavaScript, TypeScript, CoffeeScript. ES6, CommonJS, AMD.",
5
5
  "keywords": [
6
6
  "static analysis",
@@ -20,6 +20,7 @@
20
20
  "contributors": [
21
21
  "0xflotus (https://github.com/0xflotus)",
22
22
  "Álvaro Cuesta (https://github.com/alvaro-cuesta)",
23
+ "Arpit Jain (https://github.com/arpitjain099)",
23
24
  "anna (https://github.com/annamooseity)",
24
25
  "Bastian Hess (https://github.com/bashess)",
25
26
  "Bin (https://github.com/soulhat)",
@@ -30,6 +31,7 @@
30
31
  "Daniel Edholm Ignat (https://github.com/dignite)",
31
32
  "Daniel Rodríguez Rivero (https://danielorodriguez.com)",
32
33
  "davidparkagoda (https://github.com/davidparkagoda)",
34
+ "Dmytro Kurovskyi (https://github.com/kurovskyiii)",
33
35
  "electrovir (https://github.com/electrovir)",
34
36
  "Emily Marigold Klassen (https://forivall.com)",
35
37
  "Frederik Schubert (https://github.com/ferdynator)",
@@ -40,6 +42,7 @@
40
42
  "Ivan (https://github.com/Winner95)",
41
43
  "Jeremy Magland (https://github.com/magland)",
42
44
  "Jessica Kerr (https://jessitron.com)",
45
+ "João Ribeiro (https://github.com/JonnyBGod)",
43
46
  "Jon Lauridsen (https://jonlauridsen.com)",
44
47
  "Joshua T (https://github.com/radiantly)",
45
48
  "KenjiroKubota (https://github.com/kubotak-is)",
@@ -55,12 +58,15 @@
55
58
  "Radosław Kłos (https://klos.dev)",
56
59
  "Richard Musiol (https://github.com/neelance)",
57
60
  "Roy Swinkels (https://github.com/donroyco)",
61
+ "Samuel Gunter (https://github.com/Samathingamajig)",
62
+ "Sebastian Danielsson (https://github.com/sebdanielsson)",
58
63
  "Sebastian Landwehr (https://sebastianlandwehr.com)",
59
64
  "Sharang Pai (https://sharangpai.me)",
60
65
  "Stefan Gojan (https://stefan-gojan.de)",
61
66
  "Tharun Rajendran (https://github.com/tharun208)",
62
67
  "TruongSinh Tran-Nguyen (https://truongsinh.pro)",
63
68
  "Valentin Semirulnik (https://github.com/7rulnik)",
69
+ "Yohannes (https://github.com/Johannes7549)",
64
70
  "Yuanhai He (https://bestmike007.com)",
65
71
  "정건우 (https://www.zigae.com/)"
66
72
  ],
@@ -148,9 +154,9 @@
148
154
  "acorn-jsx-walk": "2.0.0",
149
155
  "acorn-loose": "8.5.2",
150
156
  "acorn-walk": "8.3.5",
151
- "commander": "15.0.0",
152
- "enhanced-resolve": "5.26.0",
153
- "ignore": "7.0.12",
157
+ "commander": "15.1.0",
158
+ "enhanced-resolve": "5.27.0",
159
+ "ignore": "7.0.14",
154
160
  "interpret": "3.1.1",
155
161
  "is-installed-globally": "1.0.1",
156
162
  "json5": "2.2.3",
@@ -158,7 +164,7 @@
158
164
  "prompts": "2.4.2",
159
165
  "rechoir": "0.8.0",
160
166
  "safe-regex": "2.1.1",
161
- "semver": "7.8.5",
167
+ "semver": "7.8.6",
162
168
  "tsconfig-paths-webpack-plugin": "4.2.0",
163
169
  "watskeburt": "6.0.0"
164
170
  },
@@ -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";
@@ -89,17 +89,22 @@ function determineManifestDependencyTypes(
89
89
  * an array, and not an object, hence needs different treatment
90
90
  */
91
91
  function dependencyIsBundled(pModule, pPackageDeps) {
92
- let lReturnValue = false;
93
-
94
92
  if (pPackageDeps) {
95
93
  const lBundledDependencies =
96
94
  pPackageDeps.bundledDependencies || pPackageDeps.bundleDependencies;
95
+ // "bundledDependencies": true means: all production dependencies get
96
+ // bundled
97
+ if (lBundledDependencies === true) {
98
+ return Object.hasOwn(pPackageDeps.dependencies || {}, pModule);
99
+ }
97
100
 
98
101
  if (lBundledDependencies) {
99
- lReturnValue = lBundledDependencies.includes(pModule);
102
+ return lBundledDependencies.includes(pModule);
100
103
  }
101
104
  }
102
- return lReturnValue;
105
+ // false when there's no bundledDependencies or
106
+ // when bundledDependencies equals false
107
+ return false;
103
108
  }
104
109
 
105
110
  /**
@@ -116,9 +121,10 @@ function determineNodeModuleDependencyTypes(
116
121
  pFileDirectory,
117
122
  pResolveOptions,
118
123
  ) {
124
+ const lPackageRoot = getPackageRoot(pModuleName);
119
125
  /** @type { DependencyType[] } */
120
126
  const lReturnValue = determineManifestDependencyTypes(
121
- getPackageRoot(pModuleName),
127
+ lPackageRoot,
122
128
  pPackageDeps,
123
129
  pResolveOptions.modules,
124
130
  );
@@ -128,7 +134,7 @@ function determineNodeModuleDependencyTypes(
128
134
  ) {
129
135
  lReturnValue.push("deprecated");
130
136
  }
131
- if (dependencyIsBundled(pModuleName, pPackageDeps)) {
137
+ if (dependencyIsBundled(lPackageRoot, pPackageDeps)) {
132
138
  lReturnValue.push("npm-bundled");
133
139
  }
134
140
  return lReturnValue;
@@ -1,7 +1,7 @@
1
1
  import { uniq } from "#utl/array-util.mjs";
2
2
 
3
3
  /* eslint-disable security/detect-object-injection */
4
- function normalizeManifestKeys(pManifest) {
4
+ function normalizeBundleManifestKeys(pManifest) {
5
5
  const lReturnValue = pManifest;
6
6
 
7
7
  if (pManifest.bundleDependencies) {
@@ -10,6 +10,9 @@ function normalizeManifestKeys(pManifest) {
10
10
  );
11
11
  Reflect.deleteProperty(pManifest, "bundleDependencies");
12
12
  }
13
+ if (pManifest.bundledDependencies === true) {
14
+ pManifest.bundledDependencies = Object.keys(pManifest.dependencies || {});
15
+ }
13
16
  return lReturnValue;
14
17
  }
15
18
 
@@ -64,8 +67,8 @@ function isAnArrayKey(pKey) {
64
67
  */
65
68
  export default function mergeManifests(pClosestManifest, pFurtherManifest) {
66
69
  return getJointUniqueDependencyKeys(
67
- normalizeManifestKeys(pClosestManifest),
68
- normalizeManifestKeys(pFurtherManifest),
70
+ normalizeBundleManifestKeys(pClosestManifest),
71
+ normalizeBundleManifestKeys(pFurtherManifest),
69
72
  )
70
73
  .map((pKey) => ({
71
74
  key: pKey,
@@ -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,5 +1,16 @@
1
+ import { resolve } from "node:path";
1
2
  import typescript from "#utl/typescript-facade.mjs";
2
3
 
4
+ // This RE matches
5
+ // - filename.d.ts (, .cts, .mts), but also
6
+ // - filename.d.something.ts (, .cts., .mts).
7
+ // That second one seems a bit odd, but it _is_ possible; see for instance
8
+ // https://www.typescriptlang.org/tsconfig/#allowArbitraryExtensions
9
+ // (and I guess, but haven't seen this confirmed in the field or documentation
10
+ // that it could be possible to have a declaration file variant of
11
+ // https://www.typescriptlang.org/tsconfig/#moduleSuffixes)
12
+ const DECLARATION_FILE_RE = /[.]d([.][^./\\]+)?([.][cm]?ts)$/;
13
+
3
14
  function getCompilerOptions(pFlavor, pTSConfig) {
4
15
  const lCompilerOptions = {};
5
16
 
@@ -26,15 +37,26 @@ function getCompilerOptions(pFlavor, pTSConfig) {
26
37
  };
27
38
  }
28
39
 
40
+ function getTranspilableFileName(pFileName) {
41
+ if (typeof pFileName !== "string") {
42
+ return undefined;
43
+ }
44
+ // Declaration files (.d.ts, .d.mts, .d.cts, .d.css.ts) get their
45
+ // non-declaration name, because TypeScript emits nothing for a declaration
46
+ // file and throws "Debug Failure. Output generation failed".
47
+ return resolve(pFileName).replace(DECLARATION_FILE_RE, "$1$2");
48
+ }
49
+
29
50
  export default function typescriptWrap(pFlavor) {
30
51
  return {
31
52
  isAvailable: () => typescript !== false,
32
53
 
33
54
  version: () => `typescript@${typescript.version}`,
34
55
 
35
- transpile: (pSource, _pFileName, pTranspileOptions = {}) =>
56
+ transpile: (pSource, pFileName, pTranspileOptions = {}) =>
36
57
  typescript.transpileModule(pSource, {
37
58
  ...(pTranspileOptions.tsConfig || {}),
59
+ fileName: getTranspilableFileName(pFileName),
38
60
  compilerOptions: getCompilerOptions(
39
61
  pFlavor,
40
62
  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) {
@@ -0,0 +1,133 @@
1
+ /**
2
+ * Groups the modules that are on a cycle, so callers can quickly tell whether
3
+ * a dependency could be part of one.
4
+ *
5
+ * Two modules end up in the same group when each one can reach the other by
6
+ * following dependencies. So a dependency from a to b can only be part of a
7
+ * cycle when a and b are in the same group. Modules that aren't on any cycle
8
+ * don't get a group.
9
+ *
10
+ * Uses Tarjan's algorithm for strongly connected components.
11
+ *
12
+ * @param {Map<string, string[]>} pGraph module name => names of the modules it depends on
13
+ * @returns {Map<string, number>} module name => group number
14
+ */
15
+ export default function findCycleComponents(pGraph) {
16
+ /** @type {Map<string, number>} */
17
+ const lIndexOf = new Map();
18
+ /** @type {Map<string, number>} */
19
+ const lLowLinkOf = new Map();
20
+ /** @type {string[]} */
21
+ const lComponentStack = [];
22
+ const lOnComponentStack = new Set();
23
+ /** @type {Map<string, number>} */
24
+ const lReturnValue = new Map();
25
+ let lNextIndex = 0;
26
+ let lNextComponent = 0;
27
+
28
+ /**
29
+ * A module, the modules it depends on, and the index of the next one to follow
30
+ * @typedef {{name: string, successors: string[], nextEdge: number}} IFrame
31
+ */
32
+
33
+ /** @returns {IFrame} */
34
+ function visit(pName) {
35
+ lIndexOf.set(pName, lNextIndex);
36
+ lLowLinkOf.set(pName, lNextIndex);
37
+ lNextIndex += 1;
38
+ lComponentStack.push(pName);
39
+ lOnComponentStack.add(pName);
40
+
41
+ return { name: pName, successors: pGraph.get(pName), nextEdge: 0 };
42
+ }
43
+
44
+ function lowerLowLink(pName, pCandidate) {
45
+ lLowLinkOf.set(pName, Math.min(lLowLinkOf.get(pName), pCandidate));
46
+ }
47
+
48
+ /** @param {IFrame} pRoot */
49
+ function closeComponent(pRoot) {
50
+ const lMembers = [];
51
+ let lMember;
52
+
53
+ do {
54
+ lMember = lComponentStack.pop();
55
+ lOnComponentStack.delete(lMember);
56
+ lMembers.push(lMember);
57
+ } while (lMember !== pRoot.name);
58
+
59
+ if (lMembers.length > 1 || pRoot.successors.includes(pRoot.name)) {
60
+ for (const lName of lMembers) {
61
+ lReturnValue.set(lName, lNextComponent);
62
+ }
63
+ lNextComponent += 1;
64
+ }
65
+ }
66
+
67
+ /**
68
+ * Follows the next edge of the frame on top of the stack: visits the
69
+ * successor when it's new, or takes its index into account when it's on
70
+ * the component stack.
71
+ *
72
+ * @param {IFrame[]} pFrames
73
+ */
74
+ function followNextEdge(pFrames) {
75
+ const lFrame = pFrames.at(-1);
76
+ const lSuccessor = lFrame.successors[lFrame.nextEdge];
77
+
78
+ lFrame.nextEdge += 1;
79
+ if (!pGraph.has(lSuccessor)) {
80
+ return;
81
+ }
82
+ if (!lIndexOf.has(lSuccessor)) {
83
+ pFrames.push(visit(lSuccessor));
84
+ } else if (lOnComponentStack.has(lSuccessor)) {
85
+ lowerLowLink(lFrame.name, lIndexOf.get(lSuccessor));
86
+ }
87
+ }
88
+
89
+ /**
90
+ * Pops the frame on top of the stack once all its edges are followed,
91
+ * passes its low link on to its parent and closes the component when
92
+ * it's the component's root.
93
+ *
94
+ * @param {IFrame[]} pFrames
95
+ */
96
+ function finishFrame(pFrames) {
97
+ const lFrame = pFrames.pop();
98
+
99
+ if (pFrames.length > 0) {
100
+ lowerLowLink(pFrames.at(-1).name, lLowLinkOf.get(lFrame.name));
101
+ }
102
+ if (lLowLinkOf.get(lFrame.name) === lIndexOf.get(lFrame.name)) {
103
+ closeComponent(lFrame);
104
+ }
105
+ }
106
+
107
+ /**
108
+ * Runs the depth-first search from pStart, with an explicit stack instead
109
+ * of recursion so deep graphs don't exhaust the call stack.
110
+ *
111
+ * @param {string} pStart
112
+ */
113
+ function strongConnect(pStart) {
114
+ const lFrames = [visit(pStart)];
115
+
116
+ while (lFrames.length > 0) {
117
+ const lFrame = lFrames.at(-1);
118
+
119
+ if (lFrame.nextEdge < lFrame.successors.length) {
120
+ followNextEdge(lFrames);
121
+ } else {
122
+ finishFrame(lFrames);
123
+ }
124
+ }
125
+ }
126
+
127
+ for (const lStart of pGraph.keys()) {
128
+ if (!lIndexOf.has(lStart)) {
129
+ strongConnect(lStart);
130
+ }
131
+ }
132
+ return lReturnValue;
133
+ }
@@ -1,4 +1,6 @@
1
1
  /* eslint-disable security/detect-object-injection */
2
+ import findCycleComponents from "./find-cycle-components.mjs";
3
+
2
4
  /**
3
5
  * @import { IFolderDependency, IDependency, IFolder, IModule } from "../../types/cruise-result.mjs"
4
6
  * @import { DependencyType, IMiniDependency } from "../../types/shared-types.mjs"
@@ -10,6 +12,8 @@
10
12
 
11
13
  export default class IndexedModuleGraph {
12
14
  #indexedGraph;
15
+ /** @type {Map<string, number>|undefined} */
16
+ #cycleComponents;
13
17
  /**
14
18
  * @param {IModuleOrFolder} pModule
15
19
  * @returns {IVertex}
@@ -180,6 +184,24 @@ export default class IndexedModuleGraph {
180
184
  return [];
181
185
  }
182
186
 
187
+ /**
188
+ * Computed once per graph, on first use.
189
+ *
190
+ * @returns {Map<string, number>} module name => the strongly connected
191
+ * component it's in. Only has entries for modules on a cycle.
192
+ */
193
+ #getCycleComponents() {
194
+ this.#cycleComponents ??= findCycleComponents(
195
+ new Map(
196
+ Array.from(this.#indexedGraph, ([pName, pVertex]) => [
197
+ pName,
198
+ pVertex.dependencies.map(({ name }) => name),
199
+ ]),
200
+ ),
201
+ );
202
+ return this.#cycleComponents;
203
+ }
204
+
183
205
  /**
184
206
  * Returns the first non-zero length path from pInitialSource to pInitialSource
185
207
  * Returns the empty array if there is no such path
@@ -191,10 +213,18 @@ export default class IndexedModuleGraph {
191
213
  */
192
214
  #getCycle(pInitialSource, pCurrentDependency, pVisited) {
193
215
  const lVisited = pVisited || new Set();
216
+ const lCycleComponents = this.#getCycleComponents();
217
+ const lCycleComponent = lCycleComponents.get(pInitialSource);
194
218
  /** @type {IVertex} */
195
219
  const lCurrentVertex = this.#indexedGraph.get(pCurrentDependency.name);
220
+ // A vertex outside pInitialSource's strongly connected component can't
221
+ // lead back to it, and neither can anything it leads to. Skipping those
222
+ // keeps the search from exploring the rest of the graph, while it visits
223
+ // the remaining vertices in the same order - so it finds the same cycle.
196
224
  const lEdges = lCurrentVertex.dependencies.filter(
197
- (pDependency) => !lVisited.has(pDependency.name),
225
+ (pDependency) =>
226
+ !lVisited.has(pDependency.name) &&
227
+ lCycleComponents.get(pDependency.name) === lCycleComponent,
198
228
  );
199
229
  const lInitialAsDependency = lEdges.find(
200
230
  (pDependency) => pDependency.name === pInitialSource,
@@ -242,6 +272,17 @@ export default class IndexedModuleGraph {
242
272
  * @returns {Array<IMiniDependency>} see description above
243
273
  */
244
274
  getCycle(pInitialSource, pCurrentSource) {
275
+ const lCycleComponents = this.#getCycleComponents();
276
+ const lCycleComponent = lCycleComponents.get(pInitialSource);
277
+
278
+ // no cycle can contain the dependency unless both ends are in the same
279
+ // strongly connected component
280
+ if (
281
+ lCycleComponent === undefined ||
282
+ lCycleComponent !== lCycleComponents.get(pCurrentSource)
283
+ ) {
284
+ return [];
285
+ }
245
286
  /** @type {IVertex} */
246
287
  const lInitialNode = this.#indexedGraph.get(pInitialSource);
247
288
  const lCurrentDependency = lInitialNode.dependencies.find(
@@ -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.8.0-beta-1",
3
+ version: "18.8.0",
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) {
@@ -233,25 +233,32 @@ function report(pResults, pOptions) {
233
233
  showAliasedModulesUnresolved: false,
234
234
  ...pOptions,
235
235
  };
236
+ // replacer functions so '$&', "$'" and '$$' in rule comments or module names
237
+ // are inserted as is instead of being interpreted as replacement patterns
236
238
  return template
237
- .replace("{{totalCruised}}", pResults.summary.totalCruised)
239
+ .replace("{{totalCruised}}", () => pResults.summary.totalCruised)
238
240
  .replace(
239
241
  "{{totalDependenciesCruised}}",
240
- pResults.summary.totalDependenciesCruised,
242
+ () => pResults.summary.totalDependenciesCruised,
241
243
  )
242
- .replace("{{error}}", pResults.summary.error)
243
- .replace("{{warn}}", pResults.summary.warn)
244
- .replace("{{info}}", pResults.summary.info)
245
- .replace("{{ignore}}", pResults.summary.ignore ?? 0)
246
- .replace("{{staleDiv}}", constructStaleDiv(pResults.summary.baselineStale))
247
- .replace("{{violatedRulesTable}}", constructViolatedRulesTable(pResults))
248
- .replace("{{violationsList}}", constructViolationsList(pResults, lOptions))
249
- .replace(
250
- "{{baselineStaleTable}}",
244
+ .replace("{{error}}", () => pResults.summary.error)
245
+ .replace("{{warn}}", () => pResults.summary.warn)
246
+ .replace("{{info}}", () => pResults.summary.info)
247
+ .replace("{{ignore}}", () => pResults.summary.ignore ?? 0)
248
+ .replace("{{staleDiv}}", () =>
249
+ constructStaleDiv(pResults.summary.baselineStale),
250
+ )
251
+ .replace("{{violatedRulesTable}}", () =>
252
+ constructViolatedRulesTable(pResults),
253
+ )
254
+ .replace("{{violationsList}}", () =>
255
+ constructViolationsList(pResults, lOptions),
256
+ )
257
+ .replace("{{baselineStaleTable}}", () =>
251
258
  constructBaselineStaleTable(pResults, pOptions),
252
259
  )
253
- .replace("{{depcruiseVersion}}", `dependency-cruiser@${meta.version}`)
254
- .replace("{{runDate}}", new Date().toISOString());
260
+ .replace("{{depcruiseVersion}}", () => `dependency-cruiser@${meta.version}`)
261
+ .replace("{{runDate}}", () => new Date().toISOString());
255
262
  }
256
263
 
257
264
  /**
@@ -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
 
@@ -103,14 +103,14 @@ function report(pResults) {
103
103
  const lModules = dependencyToIncidenceTransformer(pResults.modules).map(
104
104
  addShowTitle,
105
105
  );
106
- return templateText.replace("{{table-here}}", constructTable(lModules));
106
+ return templateText.replace("{{table-here}}", () => constructTable(lModules));
107
107
  }
108
108
 
109
109
  /**
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 || {};
@@ -86,14 +86,14 @@ export function getURLForModule(pModule, pPrefix, pSuffix) {
86
86
  // Default to Node.js API documentation
87
87
  return "https://nodejs.org/api/{{packageName}}.html".replace(
88
88
  "{{packageName}}",
89
- lPackageName,
89
+ () => lPackageName,
90
90
  );
91
91
  } else if (
92
92
  pModule.dependencyTypes?.some((pType) => pType.startsWith("npm"))
93
93
  ) {
94
94
  return "https://www.npmjs.com/package/{{packageName}}".replace(
95
95
  "{{packageName}}",
96
- deriveExternalPackageName(pModule.source),
96
+ () => deriveExternalPackageName(pModule.source),
97
97
  );
98
98
  } else if (pPrefix || pSuffix) {
99
99
  let lURL = pModule.source;
@@ -88,7 +88,7 @@ function getClassicFacade(pTypeScript) {
88
88
  pTypeScript.sys,
89
89
  dirname(resolve(pFileName)),
90
90
  {},
91
- pFileName,
91
+ resolve(pFileName),
92
92
  ),
93
93
  formatDiagnostics: (pDiagnostics) =>
94
94
  pTypeScript.formatDiagnostics(pDiagnostics, lFormatDiagnosticsHost),
@@ -15,7 +15,7 @@ function splitLine(pLine, pMaxWidth) {
15
15
  let lCurrentWidth = 0;
16
16
 
17
17
  for (const lWord of lWords) {
18
- if (lCurrentWidth + lWord.length > pMaxWidth) {
18
+ if (lCurrentLine && lCurrentWidth + lWord.length > pMaxWidth) {
19
19
  lWrappedLines.push(lCurrentLine.trimEnd());
20
20
  lCurrentLine = "";
21
21
  lCurrentWidth = 0;