dependency-cruiser 10.9.0 → 11.2.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 (45) hide show
  1. package/package.json +5 -5
  2. package/src/cli/format.js +0 -1
  3. package/src/enrich/clear-caches.js +1 -1
  4. package/src/enrich/derive/circular/get-cycle.js +1 -1
  5. package/src/enrich/derive/dependents/get-dependents.js +1 -1
  6. package/src/enrich/derive/{metrics/get-stability-metrics.js → folders/aggregate-to-folders.js} +37 -28
  7. package/src/enrich/derive/folders/index.js +9 -0
  8. package/src/enrich/derive/folders/utl.js +44 -0
  9. package/src/enrich/derive/metrics/get-module-metrics.js +39 -0
  10. package/src/enrich/derive/metrics/index.js +14 -0
  11. package/src/enrich/derive/{utl.js → module-utl.js} +28 -0
  12. package/src/enrich/derive/orphan/is-orphan.js +1 -1
  13. package/src/enrich/derive/reachable/get-path.js +1 -1
  14. package/src/enrich/derive/reachable/index.js +1 -1
  15. package/src/enrich/enrich-modules.js +1 -1
  16. package/src/enrich/index.js +2 -2
  17. package/src/enrich/summarize/summarize-modules.js +24 -5
  18. package/src/extract/get-dependencies.js +11 -6
  19. package/src/extract/parse/to-typescript-ast.js +24 -8
  20. package/src/extract/utl/get-extension.js +9 -5
  21. package/src/meta.js +1 -1
  22. package/src/report/dot/module-utl.js +3 -3
  23. package/src/report/error-html/error-html.template.js +1 -1
  24. package/src/report/error-html/utl.js +50 -7
  25. package/src/report/error.js +55 -21
  26. package/src/report/teamcity.js +37 -11
  27. package/src/report/utl/index.js +16 -0
  28. package/src/schema/baseline-violations.schema.js +1 -35
  29. package/src/schema/configuration.schema.js +1 -496
  30. package/src/schema/cruise-result.schema.js +1 -646
  31. package/src/utl/regex-util.js +57 -0
  32. package/src/validate/match-dependency-rule.js +19 -33
  33. package/src/validate/match-module-rule.js +1 -1
  34. package/src/validate/matchers.js +50 -52
  35. package/src/validate/violates-required-rule.js +1 -1
  36. package/types/cruise-result.d.ts +2 -2
  37. package/types/dependency-cruiser.d.ts +2 -3
  38. package/types/options.d.ts +32 -0
  39. package/types/shared-types.d.ts +7 -0
  40. package/types/violations.d.ts +19 -0
  41. package/src/enrich/derive/metrics/folder.js +0 -8
  42. package/src/enrich/derive/metrics/module-utl.js +0 -27
  43. package/src/enrich/derive/metrics/module.js +0 -28
  44. package/src/enrich/derive/metrics/utl.js +0 -23
  45. package/src/validate/utl.js +0 -31
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dependency-cruiser",
3
- "version": "10.9.0",
3
+ "version": "11.2.1",
4
4
  "description": "Validate and visualize dependencies. With your rules. JavaScript, TypeScript, CoffeeScript. ES6, CommonJS, AMD.",
5
5
  "keywords": [
6
6
  "static analysis",
@@ -160,9 +160,9 @@
160
160
  "@babel/core": "7.16.5",
161
161
  "@babel/plugin-transform-modules-commonjs": "7.16.5",
162
162
  "@babel/preset-typescript": "7.16.5",
163
- "@swc/core": "1.2.120",
164
- "@typescript-eslint/eslint-plugin": "5.7.0",
165
- "@typescript-eslint/parser": "5.7.0",
163
+ "@swc/core": "1.2.123",
164
+ "@typescript-eslint/eslint-plugin": "5.8.0",
165
+ "@typescript-eslint/parser": "5.8.0",
166
166
  "@vue/compiler-sfc": "3.2.26",
167
167
  "c8": "7.10.0",
168
168
  "chai": "4.3.4",
@@ -179,7 +179,7 @@
179
179
  "eslint-plugin-unicorn": "39.0.0",
180
180
  "husky": "^4.3.8",
181
181
  "intercept-stdout": "0.1.2",
182
- "lint-staged": "12.1.2",
182
+ "lint-staged": "12.1.4",
183
183
  "mocha": "9.1.3",
184
184
  "normalize-newline": "^3.0.0",
185
185
  "npm-run-all": "4.1.5",
package/src/cli/format.js CHANGED
@@ -6,7 +6,6 @@ const io = require("./utl/io");
6
6
 
7
7
  const KNOWN_FMT_OPTIONS = [
8
8
  "collapse",
9
- "doNotFollow",
10
9
  "exclude",
11
10
  "focus",
12
11
  "help",
@@ -1,4 +1,4 @@
1
- const utl = require("./derive/utl");
1
+ const utl = require("./derive/module-utl");
2
2
 
3
3
  module.exports = function clearCaches() {
4
4
  utl.clearCache();
@@ -1,4 +1,4 @@
1
- const { findModuleByName } = require("../utl");
1
+ const { findModuleByName } = require("../module-utl");
2
2
  /* about the absence of checks whether attributes/ objects actually
3
3
  * exist:
4
4
  * - it saves CPU cycles to the effect of being ~30% faster than with the
@@ -1,4 +1,4 @@
1
- const { isDependent } = require("../utl");
1
+ const { isDependent } = require("../module-utl");
2
2
 
3
3
  module.exports = function getDependents(pModule, pModules) {
4
4
  // perf between O(n) in an unconnected graph and O(n^2) in a fully connected one
@@ -1,11 +1,12 @@
1
1
  /* eslint-disable security/detect-object-injection */
2
2
  const path = require("path").posix;
3
- const { object2Array, getParentFolders } = require("./utl");
3
+ const { calculateInstability, metricsAreCalculable } = require("../module-utl");
4
4
  const {
5
5
  getAfferentCouplings,
6
6
  getEfferentCouplings,
7
- metricsAreCalculable,
8
- } = require("./module-utl");
7
+ getParentFolders,
8
+ object2Array,
9
+ } = require("./utl");
9
10
 
10
11
  function upsertCouplings(pAllDependents, pNewDependents) {
11
12
  pNewDependents.forEach((pNewDependent) => {
@@ -34,16 +35,14 @@ function upsertFolderAttributes(pAllMetrics, pModule, pDirname) {
34
35
  )
35
36
  );
36
37
  pAllMetrics[pDirname].moduleCount += 1;
37
-
38
38
  return pAllMetrics;
39
39
  }
40
40
 
41
- function orderFolderMetrics(pLeftMetric, pRightMetric) {
42
- // return pLeft.name.localeCompare(pRight.name);
43
- // For intended use in a table it's probably more useful to sort by
44
- // instability. Might need to be either configurable or flexible
45
- // in the output, though
46
- return pRightMetric.instability - pLeftMetric.instability;
41
+ function aggregateToFolder(pAllFolders, pModule) {
42
+ getParentFolders(path.dirname(pModule.source)).forEach((pParentDirectory) =>
43
+ upsertFolderAttributes(pAllFolders, pModule, pParentDirectory)
44
+ );
45
+ return pAllFolders;
47
46
  }
48
47
 
49
48
  function sumCounts(pAll, pCurrent) {
@@ -59,12 +58,15 @@ function getFolderLevelCouplings(pCouplingArray) {
59
58
  : path.dirname(pCoupling.name)
60
59
  )
61
60
  )
62
- );
61
+ ).map((pCoupling) => ({ name: pCoupling }));
63
62
  }
64
63
 
65
64
  function calculateFolderMetrics(pFolder) {
66
65
  const lModuleDependents = object2Array(pFolder.dependents);
67
66
  const lModuleDependencies = object2Array(pFolder.dependencies);
67
+ // this calculation might look superfluous (why not just .length the dependents
68
+ // and dependencies?), but it isn't because there can be > 1 relation between
69
+ // two folders
68
70
  const lAfferentCouplings = lModuleDependents.reduce(sumCounts, 0);
69
71
  const lEfferentCouplings = lModuleDependencies.reduce(sumCounts, 0);
70
72
 
@@ -72,26 +74,33 @@ function calculateFolderMetrics(pFolder) {
72
74
  ...pFolder,
73
75
  afferentCouplings: lAfferentCouplings,
74
76
  efferentCouplings: lEfferentCouplings,
75
- // when both afferentCouplings and efferentCouplings equal 0 instability will
76
- // yield NaN. Judging Bob Martin's intention, a component with no outgoing
77
- // dependencies is maximum stable (0)
78
- instability:
79
- lEfferentCouplings / (lEfferentCouplings + lAfferentCouplings) || 0,
77
+ instability: calculateInstability(lEfferentCouplings, lAfferentCouplings),
80
78
  dependents: getFolderLevelCouplings(lModuleDependents),
81
79
  dependencies: getFolderLevelCouplings(lModuleDependencies),
82
80
  };
83
81
  }
84
82
 
85
- module.exports = function getStabilityMetrics(pModules) {
86
- return object2Array(
87
- pModules.filter(metricsAreCalculable).reduce((pAllFolders, pModule) => {
88
- getParentFolders(path.dirname(pModule.source)).forEach(
89
- (pParentDirectory) =>
90
- upsertFolderAttributes(pAllFolders, pModule, pParentDirectory)
91
- );
92
- return pAllFolders;
93
- }, {})
94
- )
95
- .map(calculateFolderMetrics)
96
- .sort(orderFolderMetrics);
83
+ function findFolderByName(pAllFolders, pName) {
84
+ return pAllFolders.find((pFolder) => pFolder.name === pName);
85
+ }
86
+
87
+ function denormalizeInstability(pAllFolders) {
88
+ return (pFolder) => ({
89
+ ...pFolder,
90
+ dependencies: pFolder.dependencies.map((pDependency) => {
91
+ const lFolder = findFolderByName(pAllFolders, pDependency.name) || {};
92
+ return {
93
+ ...pDependency,
94
+ instability: lFolder.instability >= 0 ? lFolder.instability : 0,
95
+ };
96
+ }),
97
+ });
98
+ }
99
+
100
+ module.exports = function aggregateToFolders(pModules) {
101
+ const lFolders = object2Array(
102
+ pModules.filter(metricsAreCalculable).reduce(aggregateToFolder, {})
103
+ ).map(calculateFolderMetrics);
104
+
105
+ return lFolders.map(denormalizeInstability(lFolders));
97
106
  };
@@ -0,0 +1,9 @@
1
+ const aggregateToFolders = require("./aggregate-to-folders");
2
+
3
+ module.exports = function deriveFolderMetrics(pModules, pOptions) {
4
+ let lReturnValue = {};
5
+ if (pOptions.metrics) {
6
+ lReturnValue = { folders: aggregateToFolders(pModules) };
7
+ }
8
+ return lReturnValue;
9
+ };
@@ -0,0 +1,44 @@
1
+ /* eslint-disable security/detect-object-injection */
2
+ const path = require("path").posix;
3
+
4
+ function getAfferentCouplings(pModule, pDirname) {
5
+ return pModule.dependents.filter(
6
+ (pDependent) => !pDependent.startsWith(pDirname.concat(path.sep))
7
+ );
8
+ }
9
+
10
+ function getEfferentCouplings(pModule, pDirname) {
11
+ return pModule.dependencies.filter(
12
+ (pDependency) => !pDependency.resolved.startsWith(pDirname.concat(path.sep))
13
+ );
14
+ }
15
+
16
+ /**
17
+ *
18
+ * @param {string} pPath
19
+ * @returns string[]
20
+ */
21
+ function getParentFolders(pPath) {
22
+ let lFragments = pPath.split("/");
23
+ let lReturnValue = [];
24
+
25
+ while (lFragments.length > 0) {
26
+ lReturnValue.push(lFragments.join("/"));
27
+ lFragments.pop();
28
+ }
29
+ return lReturnValue.reverse();
30
+ }
31
+
32
+ function object2Array(pObject) {
33
+ return Object.keys(pObject).map((pKey) => ({
34
+ name: pKey,
35
+ ...pObject[pKey],
36
+ }));
37
+ }
38
+
39
+ module.exports = {
40
+ getAfferentCouplings,
41
+ getEfferentCouplings,
42
+ getParentFolders,
43
+ object2Array,
44
+ };
@@ -0,0 +1,39 @@
1
+ const { findModuleByName } = require("../module-utl");
2
+ const { calculateInstability, metricsAreCalculable } = require("../module-utl");
3
+
4
+ function addInstabilityMetric(pModule) {
5
+ return {
6
+ ...pModule,
7
+ ...(metricsAreCalculable(pModule)
8
+ ? {
9
+ instability: calculateInstability(
10
+ pModule.dependencies.length,
11
+ pModule.dependents.length
12
+ ),
13
+ }
14
+ : {}),
15
+ };
16
+ }
17
+
18
+ function addInstabilityToDependency(pAllModules) {
19
+ return (pDependency) => ({
20
+ ...pDependency,
21
+ instability:
22
+ (findModuleByName(pAllModules, pDependency.resolved) || {}).instability ||
23
+ 0,
24
+ });
25
+ }
26
+
27
+ function deNormalizeInstabilityMetricsToDependencies(pModule, _, pAllModules) {
28
+ return {
29
+ ...pModule,
30
+ dependencies: pModule.dependencies.map(
31
+ addInstabilityToDependency(pAllModules)
32
+ ),
33
+ };
34
+ }
35
+
36
+ module.exports = {
37
+ addInstabilityMetric,
38
+ deNormalizeInstabilityMetricsToDependencies,
39
+ };
@@ -0,0 +1,14 @@
1
+ const { clearCache } = require("../module-utl");
2
+ const {
3
+ addInstabilityMetric,
4
+ deNormalizeInstabilityMetricsToDependencies,
5
+ } = require("./get-module-metrics");
6
+
7
+ module.exports = function deriveModulesMetrics(pModules, pOptions) {
8
+ if (pOptions.metrics) {
9
+ const lModules = pModules.map(addInstabilityMetric);
10
+ clearCache();
11
+ return lModules.map(deNormalizeInstabilityMetricsToDependencies);
12
+ }
13
+ return pModules;
14
+ };
@@ -28,6 +28,32 @@ function isDependent(pResolvedName) {
28
28
  );
29
29
  }
30
30
 
31
+ function metricsAreCalculable(pModule) {
32
+ return (
33
+ !pModule.coreModule &&
34
+ !pModule.couldNotResolve &&
35
+ !pModule.matchesDoNotFollow
36
+ );
37
+ }
38
+
39
+ /**
40
+ * returns the Instability of a component given the number of incoming (afferent)
41
+ * and outgoign (efferent) connections ('couplings')
42
+ *
43
+ * @param {number} pEfferentCouplingCount
44
+ * @param {number} pAfferentCouplingCount
45
+ * @returns number
46
+ */
47
+ function calculateInstability(pEfferentCouplingCount, pAfferentCouplingCount) {
48
+ // when both afferentCouplings and efferentCouplings equal 0 instability will
49
+ // yield NaN. Judging Bob Martin's intention, a component with no outgoing
50
+ // dependencies is maximum stable (0)
51
+ return (
52
+ pEfferentCouplingCount /
53
+ (pEfferentCouplingCount + pAfferentCouplingCount) || 0
54
+ );
55
+ }
56
+
31
57
  function clearCache() {
32
58
  gIndexedGraph = null;
33
59
  }
@@ -36,4 +62,6 @@ module.exports = {
36
62
  findModuleByName,
37
63
  clearCache,
38
64
  isDependent,
65
+ metricsAreCalculable,
66
+ calculateInstability,
39
67
  };
@@ -1,4 +1,4 @@
1
- const { isDependent } = require("../utl");
1
+ const { isDependent } = require("../module-utl");
2
2
 
3
3
  module.exports = (pModule, pGraph) => {
4
4
  if (pModule.dependencies.length > 0) {
@@ -1,4 +1,4 @@
1
- const { findModuleByName } = require("../utl");
1
+ const { findModuleByName } = require("../module-utl");
2
2
 
3
3
  function getPath(pGraph, pFrom, pTo, pVisited = new Set()) {
4
4
  let lReturnValue = [];
@@ -4,7 +4,7 @@ const _clone = require("lodash/clone");
4
4
  const _get = require("lodash/get");
5
5
  const _has = require("lodash/has");
6
6
  const matchers = require("../../../validate/matchers");
7
- const { extractGroups } = require("../../../validate/utl");
7
+ const { extractGroups } = require("../../../utl/regex-util");
8
8
  const getPath = require("./get-path");
9
9
 
10
10
  function getReachableRules(pRuleSet) {
@@ -8,7 +8,7 @@ const addDependents = require("./derive/dependents");
8
8
  const deriveReachable = require("./derive/reachable");
9
9
  const addValidations = require("./add-validations");
10
10
  const softenKnownViolations = require("./soften-known-violations");
11
- const deriveModuleMetrics = require("./derive/metrics/module");
11
+ const deriveModuleMetrics = require("./derive/metrics");
12
12
 
13
13
  module.exports = function enrichModules(pModules, pOptions) {
14
14
  bus.emit("progress", "analyzing: cycles", { level: busLogLevels.INFO });
@@ -1,5 +1,5 @@
1
1
  const enrichModules = require("./enrich-modules");
2
- const deriveFolderMetrics = require("./derive/metrics/folder.js");
2
+ const aggregateToFolders = require("./derive/folders");
3
3
  const summarize = require("./summarize");
4
4
  const clearCaches = require("./clear-caches");
5
5
 
@@ -10,7 +10,7 @@ module.exports = function enrich(pModules, pOptions, pFileAndDirectoryArray) {
10
10
  clearCaches();
11
11
  return {
12
12
  modules: lModules,
13
- ...deriveFolderMetrics(lModules, pOptions),
13
+ ...aggregateToFolders(lModules, pOptions),
14
14
  summary: summarize(lModules, pOptions, pFileAndDirectoryArray),
15
15
  };
16
16
  };
@@ -1,14 +1,15 @@
1
1
  const _flattenDeep = require("lodash/flattenDeep");
2
2
  const _get = require("lodash/get");
3
+ const _has = require("lodash/has");
3
4
  const _uniqWith = require("lodash/uniqWith");
4
5
  const { findRuleByName } = require("../../graph-utl/rule-set");
5
6
  const compare = require("../../graph-utl/compare");
6
7
  const isSameViolation = require("./is-same-violation");
7
8
 
8
- function cutNonTransgressions(pSourceEntry) {
9
+ function cutNonTransgressions(pModule) {
9
10
  return {
10
- source: pSourceEntry.source,
11
- dependencies: pSourceEntry.dependencies.filter(
11
+ ...pModule,
12
+ dependencies: pModule.dependencies.filter(
12
13
  (pDependency) => pDependency.valid === false
13
14
  ),
14
15
  };
@@ -30,21 +31,38 @@ function extractMetaData(pViolations) {
30
31
  }
31
32
  function toDependencyViolationSummary(pRule, pModule, pDependency, pRuleSet) {
32
33
  let lReturnValue = {
34
+ type: "dependency",
33
35
  from: pModule.source,
34
36
  to: pDependency.resolved,
35
37
  rule: pRule,
36
38
  };
37
39
 
38
40
  if (
39
- pDependency.cycle &&
41
+ _has(pDependency, "cycle") &&
40
42
  _get(findRuleByName(pRuleSet, pRule.name), "to.circular")
41
43
  ) {
42
44
  lReturnValue = {
43
45
  ...lReturnValue,
46
+ type: "cycle",
44
47
  cycle: pDependency.cycle,
45
48
  };
46
49
  }
47
50
 
51
+ if (
52
+ _has(pModule, "instability") &&
53
+ _has(pDependency, "instability") &&
54
+ _has(findRuleByName(pRuleSet, pRule.name), "to.moreUnstable")
55
+ ) {
56
+ lReturnValue = {
57
+ ...lReturnValue,
58
+ type: "instability",
59
+ metrics: {
60
+ from: { instability: pModule.instability },
61
+ to: { instability: pDependency.instability },
62
+ },
63
+ };
64
+ }
65
+
48
66
  return lReturnValue;
49
67
  }
50
68
 
@@ -82,7 +100,7 @@ function extractDependencyViolations(pModules, pRuleSet) {
82
100
 
83
101
  function toModuleViolationSummary(pRule, pModule, pRuleSet) {
84
102
  let lReturnValue = [
85
- { from: pModule.source, to: pModule.source, rule: pRule },
103
+ { type: "module", from: pModule.source, to: pModule.source, rule: pRule },
86
104
  ];
87
105
  if (
88
106
  pModule.reaches &&
@@ -101,6 +119,7 @@ function toModuleViolationSummary(pRule, pModule, pRuleSet) {
101
119
  []
102
120
  )
103
121
  .map((pToModule) => ({
122
+ type: "reachability",
104
123
  from: pModule.source,
105
124
  to: pToModule.to,
106
125
  rule: pRule,
@@ -21,15 +21,18 @@ function extractFromSwcAST(pOptions, pFileName) {
21
21
  );
22
22
  }
23
23
 
24
- function extractFromTypeScriptAST(pOptions, pFileName) {
24
+ function extractFromTypeScriptAST(pOptions, pFileName, pTranspileOptions) {
25
25
  return extractTypeScriptDeps(
26
- toTypescriptAST.getASTCached(path.join(pOptions.baseDir, pFileName)),
26
+ toTypescriptAST.getASTCached(
27
+ path.join(pOptions.baseDir, pFileName),
28
+ pTranspileOptions
29
+ ),
27
30
  pOptions.exoticRequireStrings
28
31
  );
29
32
  }
30
33
 
31
34
  function isTypeScriptCompatible(pFileName) {
32
- return [".ts", ".tsx", ".js", ".mjs", ".cjs"].includes(
35
+ return [".ts", ".tsx", ".js", ".mjs", ".cjs", ".vue"].includes(
33
36
  path.extname(pFileName)
34
37
  );
35
38
  }
@@ -88,9 +91,11 @@ function extractWithTsc(
88
91
  pFileName,
89
92
  pTranspileOptions
90
93
  ) {
91
- pDependencies = extractFromTypeScriptAST(pCruiseOptions, pFileName).filter(
92
- (pDep) => pCruiseOptions.moduleSystems.includes(pDep.moduleSystem)
93
- );
94
+ pDependencies = extractFromTypeScriptAST(
95
+ pCruiseOptions,
96
+ pFileName,
97
+ pTranspileOptions
98
+ ).filter((pDep) => pCruiseOptions.moduleSystems.includes(pDep.moduleSystem));
94
99
 
95
100
  if (pCruiseOptions.tsPreCompilationDeps === "specify") {
96
101
  pDependencies = detectPreCompilationNess(
@@ -2,21 +2,28 @@ const fs = require("fs");
2
2
  const tryRequire = require("semver-try-require");
3
3
  const _memoize = require("lodash/memoize");
4
4
  const { supportedTranspilers } = require("../../../src/meta.js");
5
+ const transpile = require("../transpile");
6
+ const getExtension = require("../utl/get-extension");
5
7
 
6
8
  const typescript = tryRequire("typescript", supportedTranspilers.typescript);
7
9
 
8
10
  /**
9
11
  * Compiles pTypescriptSource into a (typescript) AST
10
12
  *
11
- * @param {string} pTypescriptSource - the source to compile
12
- * @param {string} [pFileName] - (optional) file name the typescript
13
- * compiler can use in error messages
13
+ * @param {object} pFileRecord Record with source code, an extension and a filename
14
+ * @param {any} [pTranspileOptions] options for the transpiler(s) - a tsconfig or
15
+ * a babel config
14
16
  * @return {object} - a (typescript) AST
15
17
  */
16
- function getASTFromSource(pTypescriptSource, pFileName) {
18
+ function getASTFromSource(pFileRecord, pTranspileOptions) {
19
+ let lSource = pFileRecord.source;
20
+ if (pFileRecord.extension === ".vue") {
21
+ lSource = transpile(pFileRecord, pTranspileOptions);
22
+ }
23
+
17
24
  return typescript.createSourceFile(
18
- pFileName || "$internal-file-name",
19
- pTypescriptSource,
25
+ pFileRecord.filename || "$internal-file-name",
26
+ lSource,
20
27
  typescript.ScriptTarget.Latest,
21
28
  false
22
29
  );
@@ -27,10 +34,19 @@ function getASTFromSource(pTypescriptSource, pFileName) {
27
34
  * AST and returns it
28
35
  *
29
36
  * @param {string} pFileName - the name of the file to compile
37
+ * @param {any} [pTranspileOptions] options for the transpiler(s) - a tsconfig or
38
+ * a babel config
30
39
  * @return {object} - a (typescript) AST
31
40
  */
32
- function getAST(pFileName) {
33
- return getASTFromSource(fs.readFileSync(pFileName, "utf8"), pFileName);
41
+ function getAST(pFileName, pTranspileOptions) {
42
+ return getASTFromSource(
43
+ {
44
+ source: fs.readFileSync(pFileName, "utf8"),
45
+ extension: getExtension(pFileName),
46
+ filename: pFileName,
47
+ },
48
+ pTranspileOptions
49
+ );
34
50
  }
35
51
 
36
52
  const getASTCached = _memoize(getAST);
@@ -5,16 +5,20 @@ const path = require("path");
5
5
  *
6
6
  * Just using path.extname would be fine for most cases,
7
7
  * except for coffeescript, where a markdown extension can
8
- * mean literate coffeescript.
8
+ * mean literate coffeescript, and for typescript where
9
+ * .d.ts and .ts are slightly different beasts
9
10
  *
10
11
  * @param {string} pFileName path to the file to be parsed
11
12
  * @return {string} extension
12
13
  */
13
14
  module.exports = function getExtensions(pFileName) {
14
- let lReturnValue = path.extname(pFileName);
15
+ if (pFileName.endsWith(".d.ts")) {
16
+ return ".d.ts";
17
+ }
15
18
 
16
- if (lReturnValue === ".md") {
17
- return pFileName.endsWith(".coffee.md") ? ".coffee.md" : lReturnValue;
19
+ if (pFileName.endsWith(".coffee.md")) {
20
+ return ".coffee.md";
18
21
  }
19
- return lReturnValue;
22
+
23
+ return path.extname(pFileName);
20
24
  };
package/src/meta.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /* generated - don't edit */
2
2
 
3
3
  module.exports = {
4
- version: "10.9.0",
4
+ version: "11.2.1",
5
5
  engines: {
6
6
  node: "^12.20||^14||>=16",
7
7
  },
@@ -1,5 +1,6 @@
1
1
  const path = require("path").posix;
2
2
  const _has = require("lodash/has");
3
+ const utl = require("../utl/index.js");
3
4
  const theming = require("./theming");
4
5
 
5
6
  const PROTOCOL_PREFIX_RE = /^[a-z]+:\/\//;
@@ -66,9 +67,8 @@ function makeInstabilityString(pModule, pShowMetrics = false) {
66
67
  let lInstabilityString = "";
67
68
 
68
69
  if (pShowMetrics && _has(pModule, "instability") && !pModule.consolidated) {
69
- lInstabilityString = ` <FONT color="#808080" point-size="8">${Math.round(
70
- // eslint-disable-next-line no-magic-numbers
71
- 100 * pModule.instability
70
+ lInstabilityString = ` <FONT color="#808080" point-size="8">${utl.formatInstability(
71
+ pModule.instability
72
72
  )}</FONT>`;
73
73
  }
74
74
  return lInstabilityString;