dependency-cruiser 11.18.0 → 12.0.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.
Files changed (31) hide show
  1. package/configs/rules/no-orphans.js +2 -2
  2. package/package.json +17 -17
  3. package/src/cli/index.js +13 -24
  4. package/src/config-utl/extract-babel-config.js +1 -2
  5. package/src/config-utl/extract-known-violations.js +1 -6
  6. package/src/config-utl/extract-ts-config.js +1 -2
  7. package/src/enrich/derive/reachable/index.js +4 -5
  8. package/src/enrich/enrich-modules.js +1 -2
  9. package/src/enrich/summarize/add-rule-set-used.js +4 -5
  10. package/src/enrich/summarize/summarize-modules.js +2 -6
  11. package/src/enrich/summarize/summarize-options.js +1 -2
  12. package/src/extract/ast-extractors/estree-helpers.js +1 -6
  13. package/src/extract/parse/to-javascript-ast.js +1 -2
  14. package/src/extract/resolve/get-manifest/merge-manifests.js +5 -5
  15. package/src/extract/resolve/index.js +5 -6
  16. package/src/extract/transpile/meta.js +5 -4
  17. package/src/extract/transpile/svelte-preprocess.js +3 -5
  18. package/src/extract/transpile/typescript-wrap.js +1 -2
  19. package/src/extract/utl/get-extension.js +7 -9
  20. package/src/graph-utl/consolidate-module-dependencies.js +1 -2
  21. package/src/graph-utl/consolidate-modules.js +1 -2
  22. package/src/graph-utl/rule-set.js +7 -8
  23. package/src/main/options/validate.js +2 -3
  24. package/src/main/resolve-options/normalize.js +4 -5
  25. package/src/meta.js +2 -2
  26. package/src/report/dot/module-utl.js +1 -1
  27. package/src/report/dot/prepare-folder-level.js +1 -2
  28. package/src/report/error-html/utl.js +6 -7
  29. package/src/report/error.js +3 -8
  30. package/src/report/teamcity.js +1 -1
  31. package/src/validate/rule-classifiers.js +1 -2
@@ -1,5 +1,5 @@
1
1
  const DOT_FILE_PATTERN = "(^|/)\\.[^/]+\\.(js|cjs|mjs|ts|json)$";
2
- const TS_DECLARATION_FILE_PATTERN = "\\.d\\.ts$";
2
+ const TS_DECLARATION_FILE_PATTERN = "\\.d\\.(c|m)?ts$";
3
3
  const TS_CONFIG_FILE_PATTERN = "(^|/)tsconfig\\.json$";
4
4
  const OTHER_CONFIG_FILES_PATTERN =
5
5
  "(^|/)(babel|webpack)\\.config\\.(js|cjs|mjs|ts|json)$";
@@ -18,7 +18,7 @@ module.exports = {
18
18
  "remove it. If it's logical this module is an orphan (i.e. it's a config file), " +
19
19
  "add an exception for it in your dependency-cruiser configuration. By default " +
20
20
  "this rule does not scrutinize dotfiles (e.g. .eslintrc.js), TypeScript declaration " +
21
- "files (.d.ts), tsconfig.json and some of the babel and webpack configs.",
21
+ "files (.d.ts/ .d.cts/ .d.mts), tsconfig.json and some of the babel and webpack configs.",
22
22
  severity: "warn",
23
23
  from: {
24
24
  orphan: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dependency-cruiser",
3
- "version": "11.18.0",
3
+ "version": "12.0.0",
4
4
  "description": "Validate and visualize dependencies. With your rules. JavaScript, TypeScript, CoffeeScript. ES6, CommonJS, AMD.",
5
5
  "keywords": [
6
6
  "static analysis",
@@ -145,7 +145,7 @@
145
145
  "acorn-jsx-walk": "2.0.0",
146
146
  "acorn-loose": "8.3.0",
147
147
  "acorn-walk": "8.2.0",
148
- "ajv": "8.11.0",
148
+ "ajv": "8.11.2",
149
149
  "chalk": "^4.1.2",
150
150
  "commander": "9.4.1",
151
151
  "enhanced-resolve": "5.10.0",
@@ -169,21 +169,21 @@
169
169
  "wrap-ansi": "^7.0.0"
170
170
  },
171
171
  "devDependencies": {
172
- "@babel/core": "7.19.6",
172
+ "@babel/core": "7.20.2",
173
173
  "@babel/plugin-transform-modules-commonjs": "7.19.6",
174
174
  "@babel/preset-typescript": "7.18.6",
175
- "@swc/core": "1.3.10",
176
- "@types/lodash": "4.14.186",
177
- "@types/node": "18.11.5",
175
+ "@swc/core": "1.3.18",
176
+ "@types/lodash": "4.14.189",
177
+ "@types/node": "18.11.9",
178
178
  "@types/prompts": "2.4.1",
179
- "@typescript-eslint/eslint-plugin": "5.41.0",
180
- "@typescript-eslint/parser": "5.41.0",
181
- "@vue/compiler-sfc": "3.2.41",
179
+ "@typescript-eslint/eslint-plugin": "5.43.0",
180
+ "@typescript-eslint/parser": "5.43.0",
181
+ "@vue/compiler-sfc": "3.2.45",
182
182
  "c8": "7.12.0",
183
- "chai": "4.3.6",
183
+ "chai": "4.3.7",
184
184
  "chai-json-schema": "1.5.1",
185
185
  "coffeescript": "2.7.0",
186
- "eslint": "8.26.0",
186
+ "eslint": "8.27.0",
187
187
  "eslint-config-moving-meadow": "4.0.2",
188
188
  "eslint-config-prettier": "8.5.0",
189
189
  "eslint-plugin-budapestian": "5.0.1",
@@ -193,7 +193,7 @@
193
193
  "eslint-plugin-node": "11.1.0",
194
194
  "eslint-plugin-security": "1.5.0",
195
195
  "eslint-plugin-unicorn": "^44.0.2",
196
- "husky": "8.0.1",
196
+ "husky": "8.0.2",
197
197
  "intercept-stdout": "0.1.2",
198
198
  "lint-staged": "12.3.4",
199
199
  "mocha": "10.1.0",
@@ -202,11 +202,11 @@
202
202
  "prettier": "2.7.1",
203
203
  "proxyquire": "2.1.3",
204
204
  "shx": "0.3.4",
205
- "svelte": "3.52.0",
205
+ "svelte": "3.53.1",
206
206
  "symlink-dir": "5.0.1",
207
- "typescript": "4.8.4",
208
- "upem": "7.3.0",
209
- "vue-template-compiler": "2.7.13",
207
+ "typescript": "4.9.3",
208
+ "upem": "7.3.1",
209
+ "vue-template-compiler": "2.7.14",
210
210
  "yarn": "1.22.19"
211
211
  },
212
212
  "upem": {
@@ -276,7 +276,7 @@
276
276
  "types/**"
277
277
  ],
278
278
  "engines": {
279
- "node": "^12.20||^14||>=16"
279
+ "node": "^14||^16||>=18"
280
280
  },
281
281
  "supportedTranspilers": {
282
282
  "babel": ">=7.0.0 <8.0.0",
package/src/cli/index.js CHANGED
@@ -1,5 +1,4 @@
1
1
  const glob = require("glob");
2
- const get = require("lodash/get");
3
2
  const clone = require("lodash/clone");
4
3
  const set = require("lodash/set");
5
4
  const isInstalledGlobally = require("is-installed-globally");
@@ -21,17 +20,14 @@ const setUpPerformanceLogListener = require("./listeners/performance-log");
21
20
 
22
21
  function extractResolveOptions(pCruiseOptions) {
23
22
  let lResolveOptions = {};
24
- const lWebPackConfigFileName = get(
25
- pCruiseOptions,
26
- "ruleSet.options.webpackConfig.fileName",
27
- null
28
- );
23
+ const lWebPackConfigFileName =
24
+ pCruiseOptions?.ruleSet?.options?.webpackConfig?.fileName ?? null;
29
25
 
30
26
  if (lWebPackConfigFileName) {
31
27
  lResolveOptions = extractWebpackResolveConfig(
32
28
  lWebPackConfigFileName,
33
- get(pCruiseOptions, "ruleSet.options.webpackConfig.env", null),
34
- get(pCruiseOptions, "ruleSet.options.webpackConfig.arguments", null)
29
+ pCruiseOptions?.ruleSet?.options?.webpackConfig?.env ?? null,
30
+ pCruiseOptions?.ruleSet?.options?.webpackConfig?.arguments ?? null
35
31
  );
36
32
  }
37
33
  return lResolveOptions;
@@ -54,11 +50,8 @@ function addKnownViolations(pCruiseOptions) {
54
50
 
55
51
  function extractTSConfigOptions(pCruiseOptions) {
56
52
  let lReturnValue = {};
57
- const lTSConfigFileName = get(
58
- pCruiseOptions,
59
- "ruleSet.options.tsConfig.fileName",
60
- null
61
- );
53
+ const lTSConfigFileName =
54
+ pCruiseOptions?.ruleSet?.options?.tsConfig?.fileName ?? null;
62
55
 
63
56
  if (lTSConfigFileName) {
64
57
  lReturnValue = extractTSConfig(lTSConfigFileName);
@@ -69,11 +62,8 @@ function extractTSConfigOptions(pCruiseOptions) {
69
62
 
70
63
  function extractBabelConfigOptions(pCruiseOptions) {
71
64
  let lReturnValue = {};
72
- const lBabelConfigFileName = get(
73
- pCruiseOptions,
74
- "ruleSet.options.babelConfig.fileName",
75
- null
76
- );
65
+ const lBabelConfigFileName =
66
+ pCruiseOptions?.ruleSet?.options?.babelConfig?.fileName ?? null;
77
67
 
78
68
  if (lBabelConfigFileName) {
79
69
  lReturnValue = extractBabelConfig(lBabelConfigFileName);
@@ -87,12 +77,11 @@ function setUpListener(pCruiseOptions) {
87
77
  "cli-feedback": setUpCliFeedbackListener,
88
78
  "performance-log": setUpPerformanceLogListener,
89
79
  };
90
- const lListenerID = get(
91
- pCruiseOptions,
92
- "progress",
93
- get(pCruiseOptions, "ruleSet.options.progress.type")
94
- );
95
- const lListenerFunction = get(lString2Listener, lListenerID);
80
+ const lListenerID =
81
+ pCruiseOptions?.progress ??
82
+ pCruiseOptions?.ruleSet?.options?.progress?.type;
83
+ // eslint-disable-next-line security/detect-object-injection
84
+ const lListenerFunction = lString2Listener?.[lListenerID];
96
85
  /* c8 ignore next 3 */
97
86
  if (Boolean(lListenerFunction)) {
98
87
  lListenerFunction(bus);
@@ -4,7 +4,6 @@
4
4
  const fs = require("fs");
5
5
  const path = require("path");
6
6
  const json5 = require("json5");
7
- const get = require("lodash/get");
8
7
  const has = require("lodash/has");
9
8
  const tryRequire = require("semver-try-require");
10
9
  const { supportedTranspilers } = require("../../src/meta.js");
@@ -48,7 +47,7 @@ function getJSON5Config(pBabelConfigFileName) {
48
47
  }
49
48
 
50
49
  if (pBabelConfigFileName.endsWith("package.json")) {
51
- lReturnValue = get(lReturnValue, "babel", {});
50
+ lReturnValue = lReturnValue?.babel ?? {};
52
51
  }
53
52
  return lReturnValue;
54
53
  }
@@ -7,10 +7,6 @@ module.exports = function extractKnownViolations(pKnownViolationsFileName) {
7
7
  return json5.parse(
8
8
  readFileSync(makeAbsolute(pKnownViolationsFileName), "utf8")
9
9
  );
10
- // TODO: apparently node12 native coverage doesn't see this is covered with UT
11
- // (node 14 and 16 do), so c8 doesn't either. The ignore can be removed
12
- // once we stop supporting node 12
13
- /* c8 ignore start */
14
10
  } catch (pError) {
15
11
  if (pError instanceof SyntaxError) {
16
12
  throw new SyntaxError(
@@ -19,9 +15,8 @@ module.exports = function extractKnownViolations(pKnownViolationsFileName) {
19
15
  }
20
16
  throw pError;
21
17
  }
22
- /* c8 ignore stop */
23
18
 
24
- // TODO: validate the json against the schme? (might be more clear to do it here,
19
+ // TODO: validate the json against the schema? (might be more clear to do it here,
25
20
  // even if (in context of the cli) it's done again when validating the whole
26
21
  // config
27
22
  };
@@ -1,6 +1,5 @@
1
1
  const path = require("path");
2
2
  const tryRequire = require("semver-try-require");
3
- const get = require("lodash/get");
4
3
  const { supportedTranspilers } = require("../../src/meta.js");
5
4
 
6
5
  const typescript = tryRequire("typescript", supportedTranspilers.typescript);
@@ -11,7 +10,7 @@ const FORMAT_DIAGNOSTICS_HOST = {
11
10
 
12
11
  // depends on the platform which branch is taken, hence the c8 ignore
13
12
  /* c8 ignore start */
14
- if (get(typescript, "sys.useCaseSensitiveFileNames", false)) {
13
+ if (typescript?.sys?.useCaseSensitiveFileNames ?? false) {
15
14
  lReturnValue = pFileName;
16
15
  }
17
16
  /* c8 ignore stop */
@@ -1,17 +1,16 @@
1
1
  /* eslint-disable security/detect-object-injection, no-inline-comments */
2
2
 
3
3
  const clone = require("lodash/clone");
4
- const get = require("lodash/get");
5
4
  const has = require("lodash/has");
6
5
  const matchers = require("../../../validate/matchers");
7
6
  const { extractGroups } = require("../../../utl/regex-util");
8
7
  const getPath = require("./get-path");
9
8
 
10
9
  function getReachableRules(pRuleSet) {
11
- return get(pRuleSet, "forbidden", [])
10
+ return (pRuleSet?.forbidden ?? [])
12
11
  .filter((pRule) => has(pRule.to, "reachable"))
13
12
  .concat(
14
- get(pRuleSet, "allowed", []).filter((pRule) => has(pRule.to, "reachable"))
13
+ (pRuleSet?.allowed ?? []).filter((pRule) => has(pRule.to, "reachable"))
15
14
  );
16
15
  }
17
16
 
@@ -85,8 +84,8 @@ function hasCapturingGroups(pRule) {
85
84
  const lCapturingGroupPlaceholderRe = "\\$[0-9]+";
86
85
 
87
86
  return Boolean(
88
- get(pRule, "to.path", "").match(lCapturingGroupPlaceholderRe) ||
89
- get(pRule, "to.pathNot", "").match(lCapturingGroupPlaceholderRe)
87
+ (pRule?.to?.path ?? "").match(lCapturingGroupPlaceholderRe) ||
88
+ (pRule?.to?.pathNot ?? "").match(lCapturingGroupPlaceholderRe)
90
89
  );
91
90
  }
92
91
  function shouldAddReachable(pRule, pModuleTo, pGraph) {
@@ -1,4 +1,3 @@
1
- const get = require("lodash/get");
2
1
  const bus = require("../utl/bus");
3
2
  const busLogLevels = require("../utl/bus-log-levels");
4
3
  const addFocus = require("../../src/graph-utl/add-focus");
@@ -31,7 +30,7 @@ module.exports = function enrichModules(pModules, pOptions) {
31
30
  bus.emit("progress", "analyzing: add focus (if any)", {
32
31
  level: busLogLevels.INFO,
33
32
  });
34
- lModules = addFocus(lModules, get(pOptions, "focus"));
33
+ lModules = addFocus(lModules, pOptions.focus);
35
34
 
36
35
  // when validate === false we might want to skip the addValidations.
37
36
  // We don't at this time, however, as "valid" is a mandatory
@@ -1,4 +1,3 @@
1
- const get = require("lodash/get");
2
1
  const clone = require("lodash/clone");
3
2
 
4
3
  // the fixed name for allowed rules served a purpose during the extraction
@@ -11,10 +10,10 @@ function removeNames(pRule) {
11
10
  }
12
11
 
13
12
  module.exports = function addRuleSetUsed(pOptions) {
14
- const lForbidden = get(pOptions, "ruleSet.forbidden");
15
- const lAllowed = get(pOptions, "ruleSet.allowed");
16
- const lAllowedSeverity = get(pOptions, "ruleSet.allowedSeverity");
17
- const lRequired = get(pOptions, "ruleSet.required");
13
+ const lForbidden = pOptions?.ruleSet?.forbidden;
14
+ const lAllowed = pOptions?.ruleSet?.allowed;
15
+ const lAllowedSeverity = pOptions?.ruleSet?.allowedSeverity;
16
+ const lRequired = pOptions?.ruleSet?.required;
18
17
 
19
18
  return Object.assign(
20
19
  lForbidden ? { forbidden: lForbidden } : {},
@@ -1,5 +1,4 @@
1
1
  const _flattenDeep = require("lodash/flattenDeep");
2
- const get = require("lodash/get");
3
2
  const has = require("lodash/has");
4
3
  const uniqWith = require("lodash/uniqWith");
5
4
  const { findRuleByName } = require("../../graph-utl/rule-set");
@@ -25,7 +24,7 @@ function toDependencyViolationSummary(pRule, pModule, pDependency, pRuleSet) {
25
24
 
26
25
  if (
27
26
  has(pDependency, "cycle") &&
28
- get(findRuleByName(pRuleSet, pRule.name), "to.circular")
27
+ findRuleByName(pRuleSet, pRule.name)?.to?.circular
29
28
  ) {
30
29
  lReturnValue = {
31
30
  ...lReturnValue,
@@ -88,10 +87,7 @@ function toModuleViolationSummary(pRule, pModule, pRuleSet) {
88
87
  let lReturnValue = [
89
88
  { type: "module", from: pModule.source, to: pModule.source, rule: pRule },
90
89
  ];
91
- if (
92
- pModule.reaches &&
93
- get(findRuleByName(pRuleSet, pRule.name), "to.reachable")
94
- ) {
90
+ if (pModule.reaches && findRuleByName(pRuleSet, pRule.name)?.to?.reachable) {
95
91
  lReturnValue = pModule.reaches
96
92
  .filter((pReachable) => pReachable.asDefinedInRule === pRule.name)
97
93
  .reduce(
@@ -1,4 +1,3 @@
1
- const get = require("lodash/get");
2
1
  const has = require("lodash/has");
3
2
 
4
3
  const SHAREABLE_OPTIONS = [
@@ -62,7 +61,7 @@ function makeIncludeOnlyBackwardsCompatible(pOptions) {
62
61
  return pOptions.includeOnly
63
62
  ? {
64
63
  ...pOptions,
65
- includeOnly: get(pOptions, "includeOnly.path"),
64
+ includeOnly: pOptions?.includeOnly?.path,
66
65
  }
67
66
  : pOptions;
68
67
  }
@@ -1,5 +1,3 @@
1
- const get = require("lodash/get");
2
-
3
1
  function isStringLiteral(pArgument) {
4
2
  return pArgument.type === "Literal" && typeof pArgument.value === "string";
5
3
  }
@@ -40,10 +38,7 @@ function isMemberCallExpression(pNode, pObjectName, pPropertyName) {
40
38
  }
41
39
 
42
40
  function isCalleeIdentifier(pNode, pName) {
43
- return (
44
- "Identifier" === get(pNode, "callee.type") &&
45
- pName === get(pNode, "callee.name")
46
- );
41
+ return "Identifier" === pNode?.callee?.type && pName === pNode?.callee?.name;
47
42
  }
48
43
 
49
44
  function isRequireOfSomeSort(pNode, pName) {
@@ -2,7 +2,6 @@ const fs = require("fs");
2
2
  const acorn = require("acorn");
3
3
  const acornLoose = require("acorn-loose");
4
4
  const acornJsx = require("acorn-jsx");
5
- const get = require("lodash/get");
6
5
  const memoize = require("lodash/memoize");
7
6
  const transpile = require("../transpile");
8
7
  const getExtension = require("../utl/get-extension");
@@ -22,7 +21,7 @@ function needsJSXTreatment(pFileRecord, pTranspileOptions) {
22
21
  return (
23
22
  pFileRecord.extension === ".jsx" ||
24
23
  (pFileRecord.extension === ".tsx" &&
25
- get(pTranspileOptions, "tsConfig.options.jsx") ===
24
+ pTranspileOptions?.tsConfig?.options?.jsx ===
26
25
  TSCONFIG_CONSTANTS.PRESERVE_JSX)
27
26
  );
28
27
  }
@@ -1,5 +1,5 @@
1
+ /* eslint-disable security/detect-object-injection */
1
2
  const uniq = require("lodash/uniq");
2
- const get = require("lodash/get");
3
3
  const clone = require("lodash/clone");
4
4
 
5
5
  function normalizeManifestKeys(pManifest) {
@@ -64,12 +64,12 @@ module.exports = function mergeManifests(pClosestManifest, pFurtherManifest) {
64
64
  key: pKey,
65
65
  value: pKey.startsWith("bundle")
66
66
  ? mergeDependencyArray(
67
- get(pClosestManifest, pKey, []),
68
- get(pFurtherManifest, pKey, [])
67
+ pClosestManifest?.[pKey] ?? [],
68
+ pFurtherManifest?.[pKey] ?? []
69
69
  )
70
70
  : mergeDependencyKey(
71
- get(pClosestManifest, pKey, {}),
72
- get(pFurtherManifest, pKey, {})
71
+ pClosestManifest?.[pKey] ?? {},
72
+ pFurtherManifest?.[pKey] ?? {}
73
73
  ),
74
74
  }))
75
75
  .reduce((pJoinedObject, pJoinedKey) => {
@@ -1,7 +1,6 @@
1
1
  const fs = require("fs");
2
2
  const path = require("path");
3
3
  const monkeyPatchedModule = require("module");
4
- const get = require("lodash/get");
5
4
  const pathToPosix = require("../utl/path-to-posix");
6
5
  const { isRelativeModuleName } = require("./module-classifiers");
7
6
  const resolveAMD = require("./resolve-amd");
@@ -51,18 +50,18 @@ function canBeResolvedToTsVariant(pModuleName) {
51
50
  return [".js", ".jsx"].includes(path.extname(pModuleName));
52
51
  }
53
52
 
54
- function isTypeScriptishExtension(pModuleName) {
55
- return [".ts", ".tsx"].includes(path.extname(pModuleName));
53
+ function isTypeScriptIshExtension(pModuleName) {
54
+ return [".ts", ".tsx", ".cts", ".mts"].includes(path.extname(pModuleName));
56
55
  }
57
56
  function resolveYarnVirtual(pPath) {
58
- const pnpAPI = get(monkeyPatchedModule, "findPnpApi", () => false)(pPath);
57
+ const pnpAPI = (monkeyPatchedModule?.findPnpApi ?? (() => false))(pPath);
59
58
 
60
59
  // the pnp api only works in plug'n play environments, and resolveVirtual
61
60
  // only under yarn(berry). As we can't run a 'regular' nodejs environment
62
61
  // and a yarn(berry) one at the same time, ignore in the test coverage and
63
62
  // cover it in a separate integration test.
64
63
  /* c8 ignore start */
65
- if (pnpAPI && get(pnpAPI, "VERSIONS.resolveVirtual", 0) === 1) {
64
+ if (pnpAPI && (pnpAPI?.VERSIONS?.resolveVirtual ?? 0) === 1) {
66
65
  return pnpAPI.resolveVirtual(path.resolve(pPath)) || pPath;
67
66
  }
68
67
  /* c8 ignore stop */
@@ -113,7 +112,7 @@ function resolveWithRetry(
113
112
  pResolveOptions
114
113
  );
115
114
 
116
- if (isTypeScriptishExtension(lReturnValueCandidate.resolved)) {
115
+ if (isTypeScriptIshExtension(lReturnValueCandidate.resolved)) {
117
116
  lReturnValue = lReturnValueCandidate;
118
117
  }
119
118
  }
@@ -1,4 +1,3 @@
1
- const get = require("lodash/get");
2
1
  const { supportedTranspilers } = require("../../../src/meta.js");
3
2
  const swc = require("../parse/to-swc-ast");
4
3
  const javaScriptWrap = require("./javascript-wrap");
@@ -21,7 +20,9 @@ const EXTENSION2WRAPPER = {
21
20
  ".tsx": typeScriptTsxWrap,
22
21
  ".d.ts": typeScriptWrap,
23
22
  ".cts": typeScriptWrap,
23
+ ".d.cts": typeScriptWrap,
24
24
  ".mts": typeScriptESMWrap,
25
+ ".d.mts": typeScriptESMWrap,
25
26
  ".vue": vueWrap,
26
27
  ".svelte": svelteWrap,
27
28
  ".ls": liveScriptWrap,
@@ -86,7 +87,7 @@ function extensionIsAvailable(pExtension) {
86
87
  */
87
88
  module.exports.getWrapper = (pExtension, pTranspilerOptions) => {
88
89
  if (
89
- Object.keys(get(pTranspilerOptions, "babelConfig", {})).length > 0 &&
90
+ Object.keys(pTranspilerOptions?.babelConfig ?? {}).length > 0 &&
90
91
  BABELEABLE_EXTENSIONS.includes(pExtension)
91
92
  ) {
92
93
  return babelWrap;
@@ -109,7 +110,7 @@ module.exports.allExtensions = Object.keys(EXTENSION2WRAPPER).map(
109
110
 
110
111
  /**
111
112
  * an array of extensions that are 'scannable' (have a valid transpiler
112
- * available for) in the current environemnt.
113
+ * available for) in the current environment.
113
114
  *
114
115
  * @type {string[]}
115
116
  */
@@ -117,7 +118,7 @@ module.exports.scannableExtensions =
117
118
  Object.keys(EXTENSION2WRAPPER).filter(extensionIsAvailable);
118
119
 
119
120
  /**
120
- * returns an array of supported transpilers, whith for each transpiler:
121
+ * returns an array of supported transpilers, with for each transpiler:
121
122
  * - the version (range) supported
122
123
  * - whether or not it is available in the current environment
123
124
  *
@@ -1,6 +1,4 @@
1
- /* eslint-disable no-magic-numbers */
2
- /* eslint-disable security/detect-object-injection */
3
- const get = require("lodash/get");
1
+ /* eslint-disable no-magic-numbers, security/detect-object-injection */
4
2
 
5
3
  /*
6
4
  parseAttributes copied verbatim from
@@ -35,9 +33,9 @@ function composeTranspilerOptions(pTranspilerOptions) {
35
33
  return {
36
34
  ...pTranspilerOptions,
37
35
  tsConfig: {
38
- ...get(pTranspilerOptions, "tsConfig", {}),
36
+ ...(pTranspilerOptions?.tsConfig ?? {}),
39
37
  options: {
40
- ...get(pTranspilerOptions, "tsConfig.options", {}),
38
+ ...(pTranspilerOptions?.tsConfig?.options ?? {}),
41
39
  importsNotUsedAsValues: "preserve",
42
40
  jsx: "preserve",
43
41
  },
@@ -1,5 +1,4 @@
1
1
  const tryRequire = require("semver-try-require");
2
- const get = require("lodash/get");
3
2
  const { supportedTranspilers } = require("../../../src/meta.js");
4
3
 
5
4
  const typescript = tryRequire("typescript", supportedTranspilers.typescript);
@@ -26,7 +25,7 @@ function getCompilerOptions(pFlavor, pTSConfig) {
26
25
  // compatibility.
27
26
  target: "es2015",
28
27
  ...lCompilerOptions,
29
- ...get(pTSConfig, "options", {}),
28
+ ...(pTSConfig?.options ?? {}),
30
29
  };
31
30
  }
32
31
 
@@ -1,24 +1,22 @@
1
+ // @ts-check
1
2
  const path = require("path");
2
3
 
4
+ const EXTENSION_RE = /(?<extension>((\.d\.(c|m)?ts)|\.coffee\.md)$)/;
5
+
3
6
  /**
4
7
  * Returns the extension of the given file name path.
5
8
  *
6
9
  * Just using path.extname would be fine for most cases,
7
10
  * except for coffeescript, where a markdown extension can
8
11
  * mean literate coffeescript, and for typescript where
9
- * .d.ts and .ts are slightly different beasts
12
+ * .d.ts, .d.cts, .d.mts are slightly different beasts from
13
+ * .ts, .cts and .mts
10
14
  *
11
15
  * @param {string} pFileName path to the file to be parsed
12
16
  * @return {string} extension
13
17
  */
14
18
  module.exports = function getExtensions(pFileName) {
15
- if (pFileName.endsWith(".d.ts")) {
16
- return ".d.ts";
17
- }
18
-
19
- if (pFileName.endsWith(".coffee.md")) {
20
- return ".coffee.md";
21
- }
19
+ const lMatchResult = pFileName.match(EXTENSION_RE);
22
20
 
23
- return path.extname(pFileName);
21
+ return lMatchResult?.groups?.extension ?? path.extname(pFileName);
24
22
  };
@@ -1,5 +1,4 @@
1
1
  const clone = require("lodash/clone");
2
- const get = require("lodash/get");
3
2
  const _reject = require("lodash/reject");
4
3
  const uniq = require("lodash/uniq");
5
4
  const compare = require("./compare");
@@ -12,7 +11,7 @@ function mergeDependency(pLeftDependency, pRightDependency) {
12
11
  pLeftDependency.dependencyTypes.concat(pRightDependency.dependencyTypes)
13
12
  ),
14
13
  rules: pLeftDependency.rules
15
- .concat(get(pRightDependency, "rules", []))
14
+ .concat(pRightDependency?.rules ?? [])
16
15
  .sort(compare.rules),
17
16
  valid: pLeftDependency.valid && pRightDependency.valid,
18
17
  };
@@ -1,5 +1,4 @@
1
1
  const clone = require("lodash/clone");
2
- const get = require("lodash/get");
3
2
  const _reject = require("lodash/reject");
4
3
  const uniqBy = require("lodash/uniqBy");
5
4
  const compare = require("./compare");
@@ -13,7 +12,7 @@ function mergeModule(pLeftModule, pRightModule) {
13
12
  (pDependency) => pDependency.resolved
14
13
  ),
15
14
  rules: pLeftModule.rules
16
- .concat(get(pRightModule, "rules", []))
15
+ .concat(pRightModule?.rules ?? [])
17
16
  .sort(compare.rules),
18
17
  valid: pLeftModule.valid && pRightModule.valid,
19
18
  consolidated:
@@ -1,4 +1,3 @@
1
- const get = require("lodash/get");
2
1
  const has = require("lodash/has");
3
2
 
4
3
  /**
@@ -13,7 +12,7 @@ const has = require("lodash/has");
13
12
  * @return {import("../../types/rule-set").IForbiddenRuleType|undefined} - a rule (or 'undefined' if nothing found)
14
13
  */
15
14
  function findRuleByName(pRuleSet, pName) {
16
- return get(pRuleSet, "forbidden", []).find(
15
+ return (pRuleSet?.forbidden ?? []).find(
17
16
  (pForbiddenRule) => pForbiddenRule.name === pName
18
17
  );
19
18
  }
@@ -29,10 +28,10 @@ function findRuleByName(pRuleSet, pName) {
29
28
  */
30
29
  function ruleSetHasLicenseRule(pRuleSet) {
31
30
  return (
32
- get(pRuleSet, "forbidden", []).some(
31
+ (pRuleSet?.forbidden ?? []).some(
33
32
  (pRule) => has(pRule, "to.license") || has(pRule, "to.licenseNot")
34
33
  ) ||
35
- get(pRuleSet, "allowed", []).some(
34
+ (pRuleSet?.allowed ?? []).some(
36
35
  (pRule) => has(pRule, "to.license") || has(pRule, "to.licenseNot")
37
36
  )
38
37
  );
@@ -44,11 +43,11 @@ function ruleSetHasLicenseRule(pRuleSet) {
44
43
  */
45
44
  function ruleSetHasDeprecationRule(pRuleSet) {
46
45
  return (
47
- get(pRuleSet, "forbidden", []).some((pRule) =>
48
- get(pRule, "to.dependencyTypes", []).includes("deprecated")
46
+ (pRuleSet?.forbidden ?? []).some((pRule) =>
47
+ (pRule?.to?.dependencyTypes ?? []).includes("deprecated")
49
48
  ) ||
50
- get(pRuleSet, "allowed", []).some((pRule) =>
51
- get(pRule, "to.dependencyTypes", []).includes("deprecated")
49
+ (pRuleSet?.allowed ?? []).some((pRule) =>
50
+ (pRule?.to?.dependencyTypes ?? []).includes("deprecated")
52
51
  )
53
52
  );
54
53
  }
@@ -1,4 +1,3 @@
1
- const get = require("lodash/get");
2
1
  const has = require("lodash/has");
3
2
  const safeRegex = require("safe-regex");
4
3
  const report = require("../../report");
@@ -67,8 +66,8 @@ function validatePathsSafety(pFilterOption) {
67
66
  validateRegExpSafety(pFilterOption);
68
67
  }
69
68
 
70
- validateRegExpSafety(get(pFilterOption, "path", ""));
71
- validateRegExpSafety(get(pFilterOption, "pathNot", ""));
69
+ validateRegExpSafety(pFilterOption?.path ?? "");
70
+ validateRegExpSafety(pFilterOption?.pathNot ?? "");
72
71
  }
73
72
 
74
73
  /**
@@ -14,7 +14,7 @@ const DEFAULT_CACHE_DURATION = 4000;
14
14
  const DEFAULT_RESOLVE_OPTIONS = {
15
15
  // for later: check semantics of enhanced-resolve symlinks and
16
16
  // node's preserveSymlinks. They seem to be
17
- // symlink === !preserveSynlinks - but using it that way
17
+ // symlink === !preserveSymlinks - but using it that way
18
18
  // breaks backwards compatibility
19
19
  //
20
20
  // Someday we'll rely on this and remove the code that manually
@@ -55,7 +55,7 @@ function getNonOverridableResolveOptions(pCacheDuration) {
55
55
  // worse.
56
56
  fileSystem: new enhancedResolve.CachedInputFileSystem(fs, pCacheDuration),
57
57
  // our code depends on sync behavior, so having this
58
- // overriden is not an option
58
+ // overridden is not an option
59
59
  useSyncFileSystemCalls: true,
60
60
  };
61
61
  }
@@ -91,7 +91,7 @@ function compileResolveOptions(
91
91
  const TsConfigPathsPlugin = require("tsconfig-paths-webpack-plugin");
92
92
  lResolveOptions.plugins = pushPlugin(
93
93
  lResolveOptions.plugins,
94
- // @ts-ignore TS2351 "TsConfPathsPlugin is not constructuable" - is unjustified
94
+ // @ts-ignore TS2351 "TsConfPathsPlugin is not constructable" - is unjustified
95
95
  new TsConfigPathsPlugin({
96
96
  configFile: pResolveOptions.tsConfig,
97
97
  // TsConfigPathsPlugin doesn't (can't) read enhanced-resolve's
@@ -120,7 +120,6 @@ function compileResolveOptions(
120
120
  }
121
121
 
122
122
  /**
123
- *
124
123
  * @param {import("../../../types/dependency-cruiser").IResolveOptions} pResolveOptions
125
124
  * @param {import("../../../types/dependency-cruiser").ICruiseOptions} pOptions
126
125
  * @param {import("typescript").ParsedTsconfig} pTSConfig
@@ -143,7 +142,7 @@ module.exports = function normalizeResolveOptions(
143
142
  symlinks: get(pOptions, "preserveSymlinks", null),
144
143
  tsConfig: get(pOptions, "ruleSet.options.tsConfig.fileName", null),
145
144
 
146
- /* squirel the externalModuleResolutionStrategy and combinedDependencies
145
+ /* squirrel the externalModuleResolutionStrategy and combinedDependencies
147
146
  thing into the resolve options
148
147
  - they're not for enhanced resolve, but they are for what we consider
149
148
  resolve options ...
package/src/meta.js CHANGED
@@ -1,9 +1,9 @@
1
1
  /* generated - don't edit */
2
2
 
3
3
  module.exports = {
4
- version: "11.18.0",
4
+ version: "12.0.0",
5
5
  engines: {
6
- node: "^12.20||^14||>=16",
6
+ node: "^14||^16||>=18",
7
7
  },
8
8
  supportedTranspilers: {
9
9
  babel: ">=7.0.0 <8.0.0",
@@ -69,7 +69,7 @@ function makeInstabilityString(pModule, pShowMetrics = false) {
69
69
  if (pShowMetrics && has(pModule, "instability") && !pModule.consolidated) {
70
70
  lInstabilityString = ` <FONT color="#808080" point-size="8">${utl.formatInstability(
71
71
  pModule.instability
72
- )}</FONT>`;
72
+ )}%</FONT>`;
73
73
  }
74
74
  return lInstabilityString;
75
75
  }
@@ -1,4 +1,3 @@
1
- const get = require("lodash/get");
2
1
  const consolidateToFolder = require("../../graph-utl/consolidate-to-folder");
3
2
  const compare = require("../../graph-utl/compare");
4
3
  const stripSelfTransitions = require("../../graph-utl/strip-self-transitions");
@@ -11,5 +10,5 @@ module.exports = (pResults, pTheme, _, pShowMetrics) => {
11
10
  .map(moduleUtl.folderify(pShowMetrics))
12
11
  .map(stripSelfTransitions)
13
12
  .map(moduleUtl.applyTheme(pTheme))
14
- .map(moduleUtl.addURL(get(pResults, "summary.optionsUsed.prefix", "")));
13
+ .map(moduleUtl.addURL(pResults?.summary?.optionsUsed?.prefix ?? ""));
15
14
  };
@@ -1,10 +1,9 @@
1
- const get = require("lodash/get");
2
1
  const has = require("lodash/has");
3
2
  const { version } = require("../../../src/meta.js");
4
3
  const { formatViolation, formatInstability } = require("../utl/index.js");
5
4
 
6
5
  function getFormattedAllowedRule(pRuleSetUsed) {
7
- const lAllowed = get(pRuleSetUsed, "allowed", []);
6
+ const lAllowed = pRuleSetUsed?.allowed ?? [];
8
7
  const lCommentedRule = lAllowed.find((pRule) => has(pRule, "comment"));
9
8
  const lComment = lCommentedRule ? lCommentedRule.comment : "-";
10
9
 
@@ -12,7 +11,7 @@ function getFormattedAllowedRule(pRuleSetUsed) {
12
11
  ? {
13
12
  name: "not-in-allowed",
14
13
  comment: lComment,
15
- severity: get(pRuleSetUsed, "allowedSeverity", "warn"),
14
+ severity: pRuleSetUsed?.allowedSeverity ?? "warn",
16
15
  }
17
16
  : [];
18
17
  }
@@ -49,7 +48,7 @@ function formatModuleTo() {
49
48
  function formatInstabilityTo(pViolation) {
50
49
  return `${pViolation.to}&nbsp;<span class="extra">(I: ${formatInstability(
51
50
  pViolation.metrics.to.instability
52
- )})</span>`;
51
+ )}%)</span>`;
53
52
  }
54
53
 
55
54
  function determineTo(pViolation) {
@@ -70,7 +69,7 @@ function determineTo(pViolation) {
70
69
  function formatInstabilityFromExtras(pViolation) {
71
70
  return `&nbsp;<span class="extra">(I: ${formatInstability(
72
71
  pViolation.metrics.from.instability
73
- )})</span>`;
72
+ )}%)</span>`;
74
73
  }
75
74
 
76
75
  function determineFromExtras(pViolation) {
@@ -125,8 +124,8 @@ function aggregateCountsPerRule(pViolations) {
125
124
  function aggregateViolations(pViolations, pRuleSetUsed) {
126
125
  const lViolationCounts = aggregateCountsPerRule(pViolations);
127
126
 
128
- return get(pRuleSetUsed, "forbidden", [])
129
- .concat(get(pRuleSetUsed, "required", []))
127
+ return (pRuleSetUsed?.forbidden ?? [])
128
+ .concat(pRuleSetUsed?.required ?? [])
130
129
  .concat(getFormattedAllowedRule(pRuleSetUsed))
131
130
  .map((pRule) => mergeCountsIntoRule(pRule, lViolationCounts))
132
131
  .sort(
@@ -1,6 +1,5 @@
1
1
  const chalk = require("chalk");
2
2
  const figures = require("figures");
3
- const get = require("lodash/get");
4
3
  const { findRuleByName } = require("../graph-utl/rule-set");
5
4
  const wrapAndIndent = require("../utl/wrap-and-indent");
6
5
  const utl = require("./utl/index.js");
@@ -50,9 +49,9 @@ function formatInstabilityViolation(pViolation) {
50
49
  chalk.dim(
51
50
  `instability: ${utl.formatInstability(
52
51
  pViolation.metrics.from.instability
53
- )} ${figures.arrowRight} ${utl.formatInstability(
52
+ )}% ${figures.arrowRight} ${utl.formatInstability(
54
53
  pViolation.metrics.to.instability
55
- )}`
54
+ )}%`
56
55
  ),
57
56
  EXTRA_PATH_INFORMATION_INDENT
58
57
  )}`;
@@ -106,11 +105,7 @@ function addExplanation(pRuleSet, pLong) {
106
105
  return pLong
107
106
  ? (pViolation) => ({
108
107
  ...pViolation,
109
- comment: get(
110
- findRuleByName(pRuleSet, pViolation.rule.name),
111
- "comment",
112
- "-"
113
- ),
108
+ comment: findRuleByName(pRuleSet, pViolation.rule.name)?.comment ?? "-",
114
109
  })
115
110
  : (pViolation) => pViolation;
116
111
  }
@@ -91,7 +91,7 @@ function formatInstabilityViolation(pViolation) {
91
91
  pViolation
92
92
  )} (instability: ${utl.formatInstability(
93
93
  pViolation.metrics.from.instability
94
- )} -> ${utl.formatInstability(pViolation.metrics.to.instability)})`;
94
+ )}% -> ${utl.formatInstability(pViolation.metrics.to.instability)}%)`;
95
95
  }
96
96
 
97
97
  function bakeViolationMessage(pViolation) {
@@ -1,5 +1,4 @@
1
1
  const has = require("lodash/has");
2
- const get = require("lodash/get");
3
2
 
4
3
  /**
5
4
  * @param {import("../../types/strict-rule-set").IStrictAnyRuleType} pRule a dependency-cruiser rule
@@ -21,7 +20,7 @@ function isModuleOnlyRule(pRule) {
21
20
  function isFolderScope(pRule) {
22
21
  // TODO might be possible to just rule pRule.scope as it's now
23
22
  // normalized away before getting here.
24
- return get(pRule, "scope", "module") === "folder";
23
+ return (pRule?.scope ?? module) === "folder";
25
24
  }
26
25
 
27
26
  module.exports = { isModuleOnlyRule, isFolderScope };