dependency-cruiser 10.4.0-beta-2 → 10.4.0-beta-3

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": "10.4.0-beta-2",
3
+ "version": "10.4.0-beta-3",
4
4
  "description": "Validate and visualize dependencies. With your rules. JavaScript, TypeScript, CoffeeScript. ES6, CommonJS, AMD.",
5
5
  "keywords": [
6
6
  "static analysis",
@@ -1,5 +1,4 @@
1
1
  const path = require("path");
2
- const { builtinModules } = require("module");
3
2
  const _has = require("lodash/has");
4
3
  const {
5
4
  isRelativeModuleName,
@@ -167,8 +166,8 @@ module.exports = function determineDependencyTypes(
167
166
 
168
167
  if (pDependency.couldNotResolve) {
169
168
  lReturnValue = ["unknown"];
170
- } else if (builtinModules.includes(pModuleName)) {
171
- // this 'isCore' business seems duplicate (it's already in
169
+ } else if (pDependency.coreModule) {
170
+ // this business seems duplicate (it's already in
172
171
  // the passed object as `coreModule`- determined by the resolve-AMD or
173
172
  // resolve-commonJS module). I want to deprecate the `coreModule`
174
173
  // attribute in favor of this one and determining it here will make
@@ -142,7 +142,7 @@ module.exports = function resolve(
142
142
  pFileDirectory,
143
143
  pResolveOptions
144
144
  ) {
145
- let lResolvedModule = resolveWithRetry(
145
+ let lResolvedDependency = resolveWithRetry(
146
146
  pDependency,
147
147
  pBaseDirectory,
148
148
  pFileDirectory,
@@ -152,16 +152,16 @@ module.exports = function resolve(
152
152
  pDependency.module
153
153
  );
154
154
 
155
- lResolvedModule = {
156
- ...lResolvedModule,
155
+ lResolvedDependency = {
156
+ ...lResolvedDependency,
157
157
  ...resolveHelpers.addLicenseAttribute(
158
158
  lStrippedModuleName,
159
- lResolvedModule.resolved,
159
+ lResolvedDependency.resolved,
160
160
  { baseDirectory: pBaseDirectory, fileDirectory: pFileDirectory },
161
161
  pResolveOptions
162
162
  ),
163
163
  dependencyTypes: determineDependencyTypes(
164
- { ...pDependency, ...lResolvedModule },
164
+ { ...pDependency, ...lResolvedDependency },
165
165
  lStrippedModuleName,
166
166
  getManifest(
167
167
  pFileDirectory,
@@ -176,11 +176,11 @@ module.exports = function resolve(
176
176
 
177
177
  if (
178
178
  !pResolveOptions.symlinks &&
179
- !lResolvedModule.coreModule &&
180
- !lResolvedModule.couldNotResolve
179
+ !lResolvedDependency.coreModule &&
180
+ !lResolvedDependency.couldNotResolve
181
181
  ) {
182
182
  try {
183
- lResolvedModule.resolved = pathToPosix(
183
+ lResolvedDependency.resolved = pathToPosix(
184
184
  path.relative(
185
185
  pBaseDirectory,
186
186
  fs.realpathSync(
@@ -192,15 +192,15 @@ module.exports = function resolve(
192
192
  again corresponds with a real file on disk
193
193
  */
194
194
  // eslint-disable-next-line no-control-regex
195
- lResolvedModule.resolved.replace(/\u0000#/g, "#")
195
+ lResolvedDependency.resolved.replace(/\u0000#/g, "#")
196
196
  )
197
197
  )
198
198
  )
199
199
  )
200
200
  );
201
201
  } catch (pError) {
202
- lResolvedModule.couldNotResolve = true;
202
+ lResolvedDependency.couldNotResolve = true;
203
203
  }
204
204
  }
205
- return lResolvedModule;
205
+ return lResolvedDependency;
206
206
  };
@@ -10,6 +10,8 @@ const RE_PROPERTIES = [
10
10
  "licenseNot",
11
11
  "exoticRequire",
12
12
  "exoticRequireNot",
13
+ "via",
14
+ "viaNot",
13
15
  ];
14
16
 
15
17
  module.exports = function normalizeREProperties(
package/src/meta.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /* generated - don't edit */
2
2
 
3
3
  module.exports = {
4
- version: "10.4.0-beta-2",
4
+ version: "10.4.0-beta-3",
5
5
  engines: {
6
6
  node: "^12.20||^14||>=16",
7
7
  },
@@ -162,6 +162,8 @@ module.exports = {
162
162
  moreThanOneDependencyType: { type: "boolean" },
163
163
  license: { $ref: "#/definitions/REAsStringsType" },
164
164
  licenseNot: { $ref: "#/definitions/REAsStringsType" },
165
+ via: { $ref: "#/definitions/REAsStringsType" },
166
+ viaNot: { $ref: "#/definitions/REAsStringsType" },
165
167
  },
166
168
  },
167
169
  DependentsModuleRestrictionType: {
@@ -334,6 +334,8 @@ module.exports = {
334
334
  moreThanOneDependencyType: { type: "boolean" },
335
335
  license: { $ref: "#/definitions/REAsStringsType" },
336
336
  licenseNot: { $ref: "#/definitions/REAsStringsType" },
337
+ via: { $ref: "#/definitions/REAsStringsType" },
338
+ viaNot: { $ref: "#/definitions/REAsStringsType" },
337
339
  },
338
340
  },
339
341
  DependentsModuleRestrictionType: {
@@ -37,6 +37,8 @@ function match(pFrom, pTo) {
37
37
  matchers.toLicenseNot(pRule, pTo) &&
38
38
  matchers.toExoticRequire(pRule, pTo) &&
39
39
  matchers.toExoticRequireNot(pRule, pTo) &&
40
+ matchers.toVia(pRule, pTo) &&
41
+ matchers.toViaNot(pRule, pTo) &&
40
42
  // preCompilationOnly is not a mandatory attribute, but if the attribute
41
43
  // is in the rule but not in the dependency there won't be a match
42
44
  // anyway, so we can use the default propertyEquals method regardless
@@ -100,6 +100,22 @@ function toExoticRequireNot(pRule, pDependency) {
100
100
  );
101
101
  }
102
102
 
103
+ function toViaNot(pRule, pDependency) {
104
+ return Boolean(
105
+ !pRule.to.viaNot ||
106
+ (pDependency.cycle &&
107
+ !pDependency.cycle.some((pVia) => pVia.match(pRule.to.viaNot)))
108
+ );
109
+ }
110
+
111
+ function toVia(pRule, pDependency) {
112
+ return Boolean(
113
+ !pRule.to.via ||
114
+ (pDependency.cycle &&
115
+ pDependency.cycle.some((pVia) => pVia.match(pRule.to.via)))
116
+ );
117
+ }
118
+
103
119
  module.exports = {
104
120
  _replaceGroupPlaceholders,
105
121
  fromPath,
@@ -115,4 +131,6 @@ module.exports = {
115
131
  toLicenseNot,
116
132
  toExoticRequire,
117
133
  toExoticRequireNot,
134
+ toVia,
135
+ toViaNot,
118
136
  };
@@ -34,11 +34,18 @@ export interface IToRestriction extends IBaseRestrictionType {
34
34
  */
35
35
  circular?: boolean;
36
36
  /**
37
- * If following this dependency will ultimately return to the source
38
- * (circular === true), this attribute will contain an (ordered) array of module
39
- * names that shows (one of the) circular path(s)
37
+ * For circular dependencies - whether or not to match cycles that include include modules
38
+ * with this regular expression. E.g. to allow all cycles, except when they go through one
39
+ * specific module. Typically to temporarily disallow some cycles with a lower severity -
40
+ * setting up a rule with a viaNot that ignores them.
40
41
  */
41
- cycle?: string[];
42
+ via?: string | string[];
43
+ /**
44
+ * For circular dependencies - whether or not to match cycles that do NOT include modules
45
+ * with this regular expression. E.g. to disallow all cycles, except when they go through
46
+ * one specific module. Typically to temporarily allow some cycles until they're removed.
47
+ */
48
+ viaNot?: string | string[];
42
49
  /**
43
50
  * Whether or not to match when the dependency is a dynamic one.
44
51
  */