dependency-cruiser 17.3.3 → 17.3.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dependency-cruiser",
3
- "version": "17.3.3",
3
+ "version": "17.3.4",
4
4
  "description": "Validate and visualize dependencies. With your rules. JavaScript, TypeScript, CoffeeScript. ES6, CommonJS, AMD.",
5
5
  "keywords": [
6
6
  "static analysis",
@@ -11,10 +11,10 @@ import { DEFAULT_CONFIG_FILE_NAME } from "../defaults.mjs";
11
11
  const LIKELY_SOURCE_FOLDERS = ["src", "lib", "app", "bin", "sources"];
12
12
  const LIKELY_TEST_FOLDERS = ["test", "spec", "tests", "specs", "bdd"];
13
13
  const LIKELY_PACKAGES_FOLDERS = ["packages"];
14
- const TSCONFIG_CANDIDATE_PATTERN = /.*tsconfig.*\.json$/gi;
15
- const JSCONFIG_CANDIDATE_PATTERN = /.*jsconfig.*\.json$/gi;
16
- const WEBPACK_CANDIDATE_PATTERN = /.*webpack.*\.(c?js|json5?|ts|ya?ml)$/gi;
17
- const BABEL_CONFIG_CANDIDATE_PATTERN = /^\.babelrc$|.*babel.*\.json/gi;
14
+ const TSCONFIG_CANDIDATE_PATTERN = /.*tsconfig.*\.json$/i;
15
+ const JSCONFIG_CANDIDATE_PATTERN = /.*jsconfig.*\.json$/i;
16
+ const WEBPACK_CANDIDATE_PATTERN = /.*webpack.*\.(c?js|json5?|ts|ya?ml)$/i;
17
+ const BABEL_CONFIG_CANDIDATE_PATTERN = /^\.babelrc$|.*babel.*\.json/i;
18
18
 
19
19
  /**
20
20
  * Read the package manifest ('package.json') and return it as a javascript object
@@ -93,7 +93,7 @@ function getMatchingFileNames(pPattern, pFolderName = process.cwd()) {
93
93
  return readdirSync(pFolderName, "utf8").filter(
94
94
  (pFileName) =>
95
95
  statSync(join(pFolderName, pFileName)).isFile() &&
96
- pFileName.match(pPattern),
96
+ pPattern.test(pFileName),
97
97
  );
98
98
  }
99
99
 
@@ -14,6 +14,7 @@ import {
14
14
  extractModuleAttributes,
15
15
  } from "./helpers.mjs";
16
16
  import { uniqBy, intersects } from "#utl/array-util.mjs";
17
+ import { getCachedRegExp } from "#utl/regex-util.mjs";
17
18
 
18
19
  /**
19
20
  * @import { IDependency } from "../../types/cruise-result.mjs";
@@ -79,7 +80,7 @@ function extractDependencies(pCruiseOptions, pFileName, pTranspileOptions) {
79
80
 
80
81
  function matchesDoNotFollow({ resolved, dependencyTypes }, pDoNotFollow) {
81
82
  const lMatchesPath = pDoNotFollow.path
82
- ? RegExp(pDoNotFollow.path, "g").test(resolved)
83
+ ? getCachedRegExp(pDoNotFollow.path).test(resolved)
83
84
  : false;
84
85
  const lMatchesDependencyTypes = pDoNotFollow.dependencyTypes
85
86
  ? intersects(dependencyTypes, pDoNotFollow.dependencyTypes)
@@ -114,7 +115,7 @@ function addResolutionAttributes(
114
115
  }
115
116
 
116
117
  function matchesPattern(pFullPathToFile, pPattern) {
117
- return RegExp(pPattern, "g").test(pFullPathToFile);
118
+ return getCachedRegExp(pPattern).test(pFullPathToFile);
118
119
  }
119
120
 
120
121
  /**
@@ -166,7 +167,6 @@ export default function getDependencies(
166
167
  extractDependencies(pCruiseOptions, pFileName, pTranspileOptions),
167
168
  getDependencyUniqueKey,
168
169
  )
169
- .sort(compareDeps)
170
170
  .map(
171
171
  addResolutionAttributes(
172
172
  pCruiseOptions,
@@ -181,7 +181,8 @@ export default function getDependencies(
181
181
  !matchesPattern(resolved, pCruiseOptions.exclude.path)) &&
182
182
  (!pCruiseOptions?.includeOnly?.path ||
183
183
  matchesPattern(resolved, pCruiseOptions.includeOnly.path)),
184
- );
184
+ )
185
+ .sort(compareDeps);
185
186
  } catch (pError) {
186
187
  throw new Error(
187
188
  `Extracting dependencies ran afoul of...\n\n ${pError.message}\n... in ${pFileName}\n\n`,
@@ -80,7 +80,6 @@ function extractFileDirectoryArray(
80
80
  const lResult = [];
81
81
  for (const lFilename of lInitialSources) {
82
82
  if (!lVisited.has(lFilename)) {
83
- lVisited.add(lFilename);
84
83
  lResult.push(
85
84
  ...extractRecursive(
86
85
  lFilename,
@@ -96,15 +95,7 @@ function extractFileDirectoryArray(
96
95
  return lResult;
97
96
  }
98
97
 
99
- function isNotFollowable({ followable }) {
100
- return !followable;
101
- }
102
-
103
- function notInFromListAlready(pFromList) {
104
- return ({ resolved }) => !pFromList.some(({ source }) => source === resolved);
105
- }
106
-
107
- function toDependencyToSource(pToListItem) {
98
+ function toDependencyAsModule(pToListItem) {
108
99
  return {
109
100
  source: pToListItem.resolved,
110
101
  followable: pToListItem.followable,
@@ -116,18 +107,20 @@ function toDependencyToSource(pToListItem) {
116
107
  };
117
108
  }
118
109
 
119
- function complete(pAll, pFromListItem) {
120
- return pAll
121
- .concat(pFromListItem)
110
+ function complete(pModules, pModule) {
111
+ return pModules
112
+ .concat(pModule)
122
113
  .concat(
123
- pFromListItem.dependencies
124
- .filter(isNotFollowable)
125
- .filter(notInFromListAlready(pAll))
126
- .map(toDependencyToSource),
114
+ pModule.dependencies
115
+ .filter(
116
+ ({ followable, resolved }) =>
117
+ !followable && !pModules.some(({ source }) => source === resolved),
118
+ )
119
+ .map(toDependencyAsModule),
127
120
  );
128
121
  }
129
122
 
130
- function filterExcludedDynamicDependencies(pModule, pExclude) {
123
+ function removeExcludedDynamicDependencies(pModule, pExclude) {
131
124
  // no need to do the 'path' thing as that was addressed in extractFileDirectoryArray already
132
125
  return {
133
126
  ...pModule,
@@ -164,7 +157,7 @@ export default function extract(
164
157
  )
165
158
  .reduce(complete, [])
166
159
  .map((pModule) =>
167
- filterExcludedDynamicDependencies(pModule, pCruiseOptions.exclude),
160
+ removeExcludedDynamicDependencies(pModule, pCruiseOptions.exclude),
168
161
  );
169
162
  pResolveOptions.fileSystem.purge();
170
163
  clearCaches();
@@ -15,13 +15,16 @@ const typescript = await tryImport(
15
15
  meta.supportedTranspilers.typescript,
16
16
  );
17
17
 
18
- const INTERESTING_NODE_KINDS = new Set([
19
- typescript.SyntaxKind.CallExpression,
20
- typescript.SyntaxKind.ExportDeclaration,
21
- typescript.SyntaxKind.ImportDeclaration,
22
- typescript.SyntaxKind.ImportEqualsDeclaration,
23
- typescript.SyntaxKind.LastTypeNode,
24
- ]);
18
+ const INTERESTING_NODE_KINDS = typescript
19
+ ? new Set([
20
+ typescript.SyntaxKind.CallExpression,
21
+ typescript.SyntaxKind.ExportDeclaration,
22
+ typescript.SyntaxKind.ImportDeclaration,
23
+ typescript.SyntaxKind.ImportEqualsDeclaration,
24
+ typescript.SyntaxKind.LastTypeNode,
25
+ ])
26
+ : /* c8 ignore next 1 */
27
+ new Set();
25
28
 
26
29
  function isTypeOnlyImport(pStatement) {
27
30
  return (
@@ -6,8 +6,8 @@ import { getAvailableReporters } from "#report/index.mjs";
6
6
  * @import { ICruiseOptions, IFormatOptions } from "../../../types/options.mjs";
7
7
  */
8
8
 
9
- const MODULE_SYSTEM_LIST_RE = /^(?:(?:cjs|amd|es6|tsd)(?:,|$)){1,4}/gi;
10
- const VALID_DEPTH_RE = /^\d{1,2}$/g;
9
+ const MODULE_SYSTEM_LIST_RE = /^(?:(?:cjs|amd|es6|tsd)(?:,|$)){1,4}/i;
10
+ const VALID_DEPTH_RE = /^\d{1,2}$/;
11
11
 
12
12
  function isObject(pObject) {
13
13
  return (
@@ -37,7 +37,7 @@ function assertModuleSystemsValid(pModuleSystems) {
37
37
  pModuleSystems &&
38
38
  Array.isArray(pModuleSystems) &&
39
39
  !pModuleSystems.every((pModuleSystem) =>
40
- pModuleSystem.match(MODULE_SYSTEM_LIST_RE),
40
+ MODULE_SYSTEM_LIST_RE.test(pModuleSystem),
41
41
  )
42
42
  ) {
43
43
  throw new Error(
@@ -65,7 +65,7 @@ function assertOutputTypeValid(pOutputType) {
65
65
  }
66
66
 
67
67
  function assertMaxDepthValid(pDepth) {
68
- if (pDepth && !pDepth.toString().match(VALID_DEPTH_RE)) {
68
+ if (pDepth && !VALID_DEPTH_RE.test(pDepth.toString())) {
69
69
  throw new Error(
70
70
  `'${pDepth}' is not a valid depth - use an integer between 0 and 99`,
71
71
  );
package/src/meta.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  /* generated - don't edit */
2
2
  module.exports = {
3
- version: "17.3.3",
3
+ version: "17.3.4",
4
4
  engines: {
5
5
  node: "^20.12||^22||>=24",
6
6
  },
@@ -34,7 +34,7 @@ function replaceFromWordList(pPathElement, pWordList, pCached) {
34
34
  export function anonymizePathElement(
35
35
  pPathElement,
36
36
  pWordList = [],
37
- pWhiteListRE = /^$/g,
37
+ pWhiteListRE = /^$/,
38
38
  pCached = true,
39
39
  ) {
40
40
  return pWhiteListRE.test(pPathElement)
@@ -151,8 +151,7 @@ function sanitizeWordList(pWordList) {
151
151
  return pWordList
152
152
  .map((pString) => pString.replaceAll(/[^a-zA-Z-]/g, "_"))
153
153
  .filter(
154
- (pString) =>
155
- /^[a-zA-Z-_]+$/g.test(pString) && !WHITELIST_RE.test(pString),
154
+ (pString) => /^[a-zA-Z-_]+$/.test(pString) && !WHITELIST_RE.test(pString),
156
155
  );
157
156
  }
158
157
 
@@ -1,15 +1,12 @@
1
1
  import DEFAULT_THEME from "./default-theme.mjs";
2
2
  import { attributizeObject } from "./module-utl.mjs";
3
3
  import { has, get } from "#utl/object-util.mjs";
4
-
5
- function matchesRE(pValue, pRE) {
6
- const lMatchResult = pValue.match && pValue.match(pRE);
7
-
8
- return lMatchResult && lMatchResult.length > 0;
9
- }
4
+ import { getCachedRegExp } from "#utl/regex-util.mjs";
10
5
 
11
6
  function matchesCriterion(pModuleKey, pCriterion) {
12
- return pModuleKey === pCriterion || matchesRE(pModuleKey, pCriterion);
7
+ return (
8
+ pModuleKey === pCriterion || getCachedRegExp(pCriterion).test(pModuleKey)
9
+ );
13
10
  }
14
11
 
15
12
  function moduleOrDependencyMatchesCriteria(pSchemeEntry, pModule) {
@@ -1,5 +1,5 @@
1
- const LOCAL_MODULE_RE = /^[.]{1,2}($|\/.*)/g;
2
- const ABSOLUTE_MODULE_RE = /^\/.*/g;
1
+ const LOCAL_MODULE_RE = /^[.]{1,2}($|\/.*)/;
2
+ const ABSOLUTE_MODULE_RE = /^\/.*/;
3
3
 
4
4
  const PACKAGE_RE = "[^/]+";
5
5
  const SCOPED_PACKAGE_RE = "@[^/]+(/[^/]+)";
@@ -13,8 +13,8 @@ const ROOT_MODULE_RE = new RegExp(`^(${SCOPED_PACKAGE_RE}|${PACKAGE_RE})`, "g");
13
13
  */
14
14
  module.exports = function extractRootModuleName(pModuleName) {
15
15
  if (
16
- pModuleName.match(LOCAL_MODULE_RE) ||
17
- pModuleName.match(ABSOLUTE_MODULE_RE)
16
+ LOCAL_MODULE_RE.test(pModuleName) ||
17
+ ABSOLUTE_MODULE_RE.test(pModuleName)
18
18
  ) {
19
19
  return pModuleName;
20
20
  } else {