dependency-cruiser 10.3.1-beta-3 → 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.3.1-beta-3",
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",
@@ -139,10 +139,10 @@
139
139
  "ajv": "8.6.3",
140
140
  "chalk": "4.1.2",
141
141
  "commander": "8.2.0",
142
- "enhanced-resolve": "5.8.2",
142
+ "enhanced-resolve": "5.8.3",
143
143
  "figures": "^3.2.0",
144
144
  "get-stream": "^6.0.1",
145
- "glob": "7.1.7",
145
+ "glob": "7.2.0",
146
146
  "handlebars": "4.7.7",
147
147
  "indent-string": "^4.0.0",
148
148
  "inquirer": "8.1.5",
@@ -159,13 +159,13 @@
159
159
  "@babel/core": "7.15.5",
160
160
  "@babel/plugin-transform-modules-commonjs": "7.15.4",
161
161
  "@babel/preset-typescript": "7.15.0",
162
- "@swc/core": "1.2.88",
163
- "@typescript-eslint/eslint-plugin": "4.31.1",
164
- "@typescript-eslint/parser": "4.31.1",
162
+ "@swc/core": "1.2.91",
163
+ "@typescript-eslint/eslint-plugin": "4.31.2",
164
+ "@typescript-eslint/parser": "4.31.2",
165
165
  "c8": "7.9.0",
166
166
  "chai": "4.3.4",
167
167
  "chai-json-schema": "1.5.1",
168
- "coffeescript": "2.5.1",
168
+ "coffeescript": "2.6.0",
169
169
  "eslint": "7.32.0",
170
170
  "eslint-config-moving-meadow": "2.0.9",
171
171
  "eslint-config-prettier": "8.3.0",
@@ -178,12 +178,12 @@
178
178
  "husky": "^4.3.8",
179
179
  "intercept-stdout": "0.1.2",
180
180
  "lint-staged": "11.1.2",
181
- "mocha": "9.1.1",
181
+ "mocha": "9.1.2",
182
182
  "normalize-newline": "4.1.0",
183
183
  "npm-run-all": "4.1.5",
184
184
  "prettier": "2.4.1",
185
185
  "shx": "0.3.3",
186
- "svelte": "3.42.6",
186
+ "svelte": "3.43.0",
187
187
  "symlink-dir": "5.0.1",
188
188
  "typescript": "4.4.3",
189
189
  "upem": "^7.0.0",
@@ -30,6 +30,9 @@ function extractImportsAndExports(pAST) {
30
30
  module: pStatement.moduleSpecifier.text,
31
31
  moduleSystem: "es6",
32
32
  exoticallyRequired: false,
33
+ ...(pStatement.importClause && pStatement.importClause.isTypeOnly
34
+ ? { dependencyTypes: ["type-only"] }
35
+ : {}),
33
36
  }));
34
37
  }
35
38
 
@@ -162,8 +162,8 @@ function addResolutionAttributes(pOptions, pFileName, pResolveOptions) {
162
162
  );
163
163
 
164
164
  return {
165
- ...lResolved,
166
165
  ...pDependency,
166
+ ...lResolved,
167
167
  followable: lResolved.followable && !lMatchesDoNotFollow,
168
168
  matchesDoNotFollow: lMatchesDoNotFollow,
169
169
  };
@@ -196,22 +196,12 @@ function compareDeps(pLeft, pRight) {
196
196
  *
197
197
  *
198
198
  * @param {string} pFileName path to the file
199
- * @param {object} pCruiseOptions an object with one or more of these properties:
200
- * - baseDir - the directory to consider as the
201
- * base for all files
202
- * Default: the current working directory
203
- * - moduleSystems - an array of module systems to
204
- * consider.
205
- * Default: ["cjs", "es6", "amd"]
206
- * - exclude - a regular expression string
207
- * with a pattern of modules to exclude
208
- * (e.g. "(node_modules)"). Default: none
209
- * - preserveSymlinks - don't resolve symlinks.
210
- * @param {object} pResolveOptions an object with webpack 'enhanced-resolve' options
199
+ * @param {import("../../../types/dependency-cruiser").ICruiseOptions} pCruiseOptions cruise options
200
+ * @param {import("../../types/resolve-options").IResolveOptions} pResolveOptions webpack 'enhanced-resolve' options
211
201
  * @param {any} pTranspileOptions an object with tsconfig ('typescript project') options
212
202
  * ('flattened' so there's no need for file access on any
213
203
  * 'extends' option in there)
214
- * @return {array} an array of dependency objects (see above)
204
+ * @return {import("../../types/dependency-cruiser").IDependency[]} an array of dependency objects (see above)
215
205
  */
216
206
  module.exports = function getDependencies(
217
207
  pFileName,
@@ -2,7 +2,6 @@ const path = require("path");
2
2
  const _has = require("lodash/has");
3
3
  const {
4
4
  isRelativeModuleName,
5
- isCore,
6
5
  isExternalModule,
7
6
  isAliassy,
8
7
  } = require("./module-classifiers");
@@ -144,7 +143,7 @@ function determineExternalModuleDependencyTypes(
144
143
  /* eslint max-params:0, complexity:0 */
145
144
  /**
146
145
  *
147
- * @param {import("../../../types/cruise-result").IModule} pModule the dependency object with all information found hitherto
146
+ * @param {import("../../../types/cruise-result").IDependency} pDependency the dependency object with all information found hitherto
148
147
  * @param {string} pModuleName the module name as found in the source
149
148
  * @param {any} pManifest a package.json, in object format
150
149
  * @param {string} pFileDirectory the directory relative to which to resolve (only used for npm deps here)
@@ -154,7 +153,7 @@ function determineExternalModuleDependencyTypes(
154
153
  * @return {import("../../../types/shared-types").DependencyType[]} an array of dependency types for the dependency
155
154
  */
156
155
  module.exports = function determineDependencyTypes(
157
- pModule,
156
+ pDependency,
158
157
  pModuleName,
159
158
  pManifest,
160
159
  pFileDirectory,
@@ -165,10 +164,10 @@ module.exports = function determineDependencyTypes(
165
164
  let lReturnValue = ["undetermined"];
166
165
  pResolveOptions = pResolveOptions || {};
167
166
 
168
- if (pModule.couldNotResolve) {
167
+ if (pDependency.couldNotResolve) {
169
168
  lReturnValue = ["unknown"];
170
- } else if (isCore(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
@@ -177,21 +176,25 @@ module.exports = function determineDependencyTypes(
177
176
  } else if (isRelativeModuleName(pModuleName)) {
178
177
  lReturnValue = ["local"];
179
178
  } else if (
180
- isExternalModule(pModule.resolved, pResolveOptions.modules, pBaseDirectory)
179
+ isExternalModule(
180
+ pDependency.resolved,
181
+ pResolveOptions.modules,
182
+ pBaseDirectory
183
+ )
181
184
  ) {
182
185
  lReturnValue = determineExternalModuleDependencyTypes(
183
- pModule,
186
+ pDependency,
184
187
  pModuleName,
185
188
  pManifest,
186
189
  pFileDirectory,
187
190
  pResolveOptions,
188
191
  pBaseDirectory
189
192
  );
190
- } else if (isAliassy(pModuleName, pModule.resolved, pResolveOptions)) {
193
+ } else if (isAliassy(pModuleName, pDependency.resolved, pResolveOptions)) {
191
194
  lReturnValue = ["aliased"];
192
195
  }
193
196
 
194
- return lReturnValue;
197
+ return lReturnValue.concat(pDependency.dependencyTypes || []);
195
198
  };
196
199
 
197
200
  /* eslint security/detect-object-injection: 0*/
@@ -7,6 +7,8 @@ const { isRelativeModuleName } = require("./module-classifiers");
7
7
  const resolveAMD = require("./resolve-amd");
8
8
  const resolveCommonJS = require("./resolve-cjs");
9
9
  const resolveHelpers = require("./resolve-helpers");
10
+ const determineDependencyTypes = require("./determine-dependency-types");
11
+ const getManifest = require("./get-manifest");
10
12
 
11
13
  function resolveModule(
12
14
  pModule,
@@ -16,20 +18,20 @@ function resolveModule(
16
18
  ) {
17
19
  let lReturnValue = null;
18
20
 
19
- const lModuleName = resolveHelpers.stripToModuleName(pModule.module);
21
+ const lStrippedModuleName = resolveHelpers.stripToModuleName(pModule.module);
20
22
  if (
21
- isRelativeModuleName(lModuleName) ||
23
+ isRelativeModuleName(lStrippedModuleName) ||
22
24
  ["cjs", "es6", "tsd"].includes(pModule.moduleSystem)
23
25
  ) {
24
26
  lReturnValue = resolveCommonJS(
25
- pModule.module,
27
+ lStrippedModuleName,
26
28
  pBaseDirectory,
27
29
  pFileDirectory,
28
30
  pResolveOptions
29
31
  );
30
32
  } else {
31
33
  lReturnValue = resolveAMD(
32
- pModule.module,
34
+ lStrippedModuleName,
33
35
  pBaseDirectory,
34
36
  pFileDirectory,
35
37
  pResolveOptions
@@ -48,7 +50,7 @@ function isTypeScriptishExtension(pModuleName) {
48
50
  function resolveYarnVirtual(pPath) {
49
51
  const pnpAPI = get(monkeyPatchedModule, "findPnpApi", () => false)(pPath);
50
52
 
51
- // the pnp api only works in plug'n play environemnts, and resolveVirtual
53
+ // the pnp api only works in plug'n play environments, and resolveVirtual
52
54
  // only under yarn(berry). As we can't run a 'regular' nodejs environment
53
55
  // and a yarn(berry) one at the same time, ignore in the test coverage and
54
56
  // cover it in a separate integration test.
@@ -72,7 +74,7 @@ function resolveWithRetry(
72
74
  pFileDirectory,
73
75
  pResolveOptions
74
76
  );
75
- const lModuleName = resolveHelpers.stripToModuleName(pModule.module);
77
+ const lStrippedModuleName = resolveHelpers.stripToModuleName(pModule.module);
76
78
 
77
79
  // when we feed the typescript compiler an import with an explicit .js(x) extension
78
80
  // and the .js(x) file does not exist, it tries files with the .ts, .tsx or
@@ -87,8 +89,14 @@ function resolveWithRetry(
87
89
  //
88
90
  // This should eventually probably land in either enhanced_resolve or in a
89
91
  // plugin/ extension for it (tsconfig-paths-webpack-plugin?)
90
- if (lReturnValue.couldNotResolve && canBeResolvedToTsVariant(lModuleName)) {
91
- const lModuleWithOutExtension = lModuleName.replace(/\.js(x)?$/g, "");
92
+ if (
93
+ lReturnValue.couldNotResolve &&
94
+ canBeResolvedToTsVariant(lStrippedModuleName)
95
+ ) {
96
+ const lModuleWithOutExtension = lStrippedModuleName.replace(
97
+ /\.js(x)?$/g,
98
+ ""
99
+ );
92
100
 
93
101
  const lReturnValueCandidate = resolveModule(
94
102
  { ...pModule, module: lModuleWithOutExtension },
@@ -106,14 +114,13 @@ function resolveWithRetry(
106
114
  /**
107
115
  * resolves the module name of the pDependency to a file on disk.
108
116
  *
109
- * @param {import("../../../types/cruise-result").IModule} pModule an object with a module and the moduleSystem
110
- * according to which this is a dependency
117
+ * @param {Partial <import("../../../types/cruise-result").IDependency>} pDependency
111
118
  * @param {string} pBaseDirectory the directory to consider as base (or 'root')
112
119
  * for resolved files.
113
120
  * @param {string} pFileDirectory the directory of the file the dependency was
114
121
  * detected in
115
122
  * @param {import(../../../types/resolve-options").IResolveOptions} pResolveOptions
116
- * @return {object} an object with as attributes:
123
+ * @return {Partial <import("../../../types/cruise-result").IDependency>} an object with as attributes:
117
124
  * - resolved: a string representing the pDependency
118
125
  * resolved to a file on disk (or the pDependency
119
126
  * name itself when it could not be resolved)
@@ -128,26 +135,52 @@ function resolveWithRetry(
128
135
  * - dependencyTypes: an array of dependencyTypes
129
136
  *
130
137
  */
138
+ // eslint-disable-next-line max-lines-per-function
131
139
  module.exports = function resolve(
132
- pModule,
140
+ pDependency,
133
141
  pBaseDirectory,
134
142
  pFileDirectory,
135
143
  pResolveOptions
136
144
  ) {
137
- let lResolvedModule = resolveWithRetry(
138
- pModule,
145
+ let lResolvedDependency = resolveWithRetry(
146
+ pDependency,
139
147
  pBaseDirectory,
140
148
  pFileDirectory,
141
149
  pResolveOptions
142
150
  );
151
+ const lStrippedModuleName = resolveHelpers.stripToModuleName(
152
+ pDependency.module
153
+ );
154
+
155
+ lResolvedDependency = {
156
+ ...lResolvedDependency,
157
+ ...resolveHelpers.addLicenseAttribute(
158
+ lStrippedModuleName,
159
+ lResolvedDependency.resolved,
160
+ { baseDirectory: pBaseDirectory, fileDirectory: pFileDirectory },
161
+ pResolveOptions
162
+ ),
163
+ dependencyTypes: determineDependencyTypes(
164
+ { ...pDependency, ...lResolvedDependency },
165
+ lStrippedModuleName,
166
+ getManifest(
167
+ pFileDirectory,
168
+ pBaseDirectory,
169
+ pResolveOptions.combinedDependencies
170
+ ),
171
+ pFileDirectory,
172
+ pResolveOptions,
173
+ pBaseDirectory
174
+ ),
175
+ };
143
176
 
144
177
  if (
145
178
  !pResolveOptions.symlinks &&
146
- !lResolvedModule.coreModule &&
147
- !lResolvedModule.couldNotResolve
179
+ !lResolvedDependency.coreModule &&
180
+ !lResolvedDependency.couldNotResolve
148
181
  ) {
149
182
  try {
150
- lResolvedModule.resolved = pathToPosix(
183
+ lResolvedDependency.resolved = pathToPosix(
151
184
  path.relative(
152
185
  pBaseDirectory,
153
186
  fs.realpathSync(
@@ -159,15 +192,15 @@ module.exports = function resolve(
159
192
  again corresponds with a real file on disk
160
193
  */
161
194
  // eslint-disable-next-line no-control-regex
162
- lResolvedModule.resolved.replace(/\u0000#/g, "#")
195
+ lResolvedDependency.resolved.replace(/\u0000#/g, "#")
163
196
  )
164
197
  )
165
198
  )
166
199
  )
167
200
  );
168
201
  } catch (pError) {
169
- lResolvedModule.couldNotResolve = true;
202
+ lResolvedDependency.couldNotResolve = true;
170
203
  }
171
204
  }
172
- return lResolvedModule;
205
+ return lResolvedDependency;
173
206
  };
@@ -1,4 +1,3 @@
1
- const { builtinModules } = require("module");
2
1
  const path = require("path");
3
2
  const getExtension = require("../utl/get-extension");
4
3
 
@@ -19,10 +18,6 @@ function isRelativeModuleName(pModuleName) {
19
18
  );
20
19
  }
21
20
 
22
- function isCore(pModuleName) {
23
- return builtinModules.includes(pModuleName);
24
- }
25
-
26
21
  function isExternalModule(
27
22
  pResolvedModuleName,
28
23
  pModuleFolderNames = ["node_modules"],
@@ -124,7 +119,6 @@ function isAliassy(pModuleName, pResolvedModuleName, pResolveOptions) {
124
119
  module.exports = {
125
120
  isScoped,
126
121
  isRelativeModuleName,
127
- isCore,
128
122
  isExternalModule,
129
123
  isFollowable,
130
124
  isAliassy,
@@ -1,11 +1,8 @@
1
1
  const fs = require("fs");
2
2
  const path = require("path");
3
+ const { builtinModules } = require("module");
3
4
  const memoize = require("lodash/memoize");
4
5
  const pathToPosix = require("../utl/path-to-posix");
5
- const determineDependencyTypes = require("./determine-dependency-types");
6
- const { isCore } = require("./module-classifiers");
7
- const getManifest = require("./get-manifest");
8
- const resolveHelpers = require("./resolve-helpers");
9
6
 
10
7
  const fileExists = memoize((pFile) => {
11
8
  try {
@@ -27,7 +24,7 @@ function guessPath(pBaseDirectory, pFileDirectory, pStrippedModuleName) {
27
24
  }
28
25
 
29
26
  function guessLikelyPath(pBaseDirectory, pFileDirectory, pStrippedModuleName) {
30
- let lReturnValue =
27
+ return (
31
28
  [".js", ""]
32
29
  .map((pExtension) =>
33
30
  guessPath(
@@ -36,16 +33,14 @@ function guessLikelyPath(pBaseDirectory, pFileDirectory, pStrippedModuleName) {
36
33
  `${pStrippedModuleName}${pExtension}`
37
34
  )
38
35
  )
39
- .find(fileExists) || pStrippedModuleName;
40
-
41
- return lReturnValue;
36
+ .find(fileExists) || pStrippedModuleName
37
+ );
42
38
  }
43
39
 
44
40
  module.exports = function resolveAMD(
45
- pRawModuleName,
41
+ pStrippedModuleName,
46
42
  pBaseDirectory,
47
- pFileDirectory,
48
- pResolveOptions
43
+ pFileDirectory
49
44
  ) {
50
45
  // lookups:
51
46
  // - [x] could be relative in the end (implemented)
@@ -53,41 +48,19 @@ module.exports = function resolveAMD(
53
48
  // - [ ] maybe use mrjoelkemp/module-lookup-amd ?
54
49
  // - [ ] or https://github.com/jaredhanson/amd-resolve ?
55
50
  // - [x] funky plugins (json!wappie, ./screeching-cat!sabertooth)
56
- const lModuleName = resolveHelpers.stripToModuleName(pRawModuleName);
57
51
  const lResolvedPath = guessLikelyPath(
58
52
  pBaseDirectory,
59
53
  pFileDirectory,
60
- lModuleName
54
+ pStrippedModuleName
61
55
  );
62
56
 
63
- let lReturnValue = {
57
+ return {
64
58
  resolved: lResolvedPath,
65
- coreModule: Boolean(isCore(pRawModuleName)),
59
+ coreModule: builtinModules.includes(pStrippedModuleName),
66
60
  followable: fileExists(lResolvedPath) && lResolvedPath.endsWith(".js"),
67
61
  couldNotResolve:
68
- !Boolean(isCore(pRawModuleName)) && !fileExists(lResolvedPath),
69
- };
70
-
71
- return {
72
- ...lReturnValue,
73
- ...resolveHelpers.addLicenseAttribute(
74
- lModuleName,
75
- pBaseDirectory,
76
- pResolveOptions,
77
- lReturnValue.resolved
78
- ),
79
- dependencyTypes: determineDependencyTypes(
80
- lReturnValue,
81
- lModuleName,
82
- getManifest(
83
- pFileDirectory,
84
- pBaseDirectory,
85
- pResolveOptions.combinedDependencies
86
- ),
87
- pFileDirectory,
88
- pResolveOptions,
89
- pBaseDirectory
90
- ),
62
+ !builtinModules.includes(pStrippedModuleName) &&
63
+ !fileExists(lResolvedPath),
91
64
  };
92
65
  };
93
66
 
@@ -1,9 +1,7 @@
1
1
  const path = require("path");
2
+ const { builtinModules } = require("module");
2
3
  const pathToPosix = require("../utl/path-to-posix");
3
- const determineDependencyTypes = require("./determine-dependency-types");
4
- const { isCore, isFollowable } = require("./module-classifiers");
5
- const getManifest = require("./get-manifest");
6
- const resolveHelpers = require("./resolve-helpers");
4
+ const { isFollowable } = require("./module-classifiers");
7
5
  const resolve = require("./resolve");
8
6
 
9
7
  function addResolutionAttributes(
@@ -14,7 +12,7 @@ function addResolutionAttributes(
14
12
  ) {
15
13
  let lReturnValue = {};
16
14
 
17
- if (isCore(pModuleName)) {
15
+ if (builtinModules.includes(pModuleName)) {
18
16
  lReturnValue.coreModule = true;
19
17
  } else {
20
18
  try {
@@ -39,47 +37,21 @@ function addResolutionAttributes(
39
37
  * resolves both CommonJS and ES6
40
38
  */
41
39
  module.exports = function resolveCommonJS(
42
- pRawModuleName,
40
+ pStrippedModuleName,
43
41
  pBaseDirectory,
44
42
  pFileDirectory,
45
43
  pResolveOptions
46
44
  ) {
47
- const lModuleName = resolveHelpers.stripToModuleName(pRawModuleName);
48
- const lManifest = getManifest(
49
- pFileDirectory,
50
- pBaseDirectory,
51
- pResolveOptions.combinedDependencies
52
- );
53
-
54
- let lReturnValue = {
55
- resolved: lModuleName,
45
+ return {
46
+ resolved: pStrippedModuleName,
56
47
  coreModule: false,
57
48
  followable: false,
58
49
  couldNotResolve: false,
59
- dependencyTypes: ["undetermined"],
60
50
  ...addResolutionAttributes(
61
51
  pBaseDirectory,
62
- lModuleName,
52
+ pStrippedModuleName,
63
53
  pFileDirectory,
64
54
  pResolveOptions
65
55
  ),
66
56
  };
67
-
68
- return {
69
- ...lReturnValue,
70
- ...resolveHelpers.addLicenseAttribute(
71
- lModuleName,
72
- lReturnValue.resolved,
73
- { baseDirectory: pBaseDirectory, fileDirectory: pFileDirectory },
74
- pResolveOptions
75
- ),
76
- dependencyTypes: determineDependencyTypes(
77
- lReturnValue,
78
- lModuleName,
79
- lManifest,
80
- pFileDirectory,
81
- pResolveOptions,
82
- pBaseDirectory
83
- ),
84
- };
85
57
  };
@@ -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.3.1-beta-3",
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: {
@@ -234,6 +236,7 @@ module.exports = {
234
236
  "npm-unknown",
235
237
  "undetermined",
236
238
  "unknown",
239
+ "type-only",
237
240
  ],
238
241
  },
239
242
  REAsStringsType: {
@@ -116,6 +116,7 @@ module.exports = {
116
116
  matchesDoNotFollow: { type: "boolean" },
117
117
  couldNotResolve: { type: "boolean" },
118
118
  preCompilationOnly: { type: "boolean" },
119
+ typeOnly: { type: "boolean" },
119
120
  circular: { type: "boolean" },
120
121
  cycle: { type: "array", items: { type: "string" } },
121
122
  moduleSystem: { $ref: "#/definitions/ModuleSystemType" },
@@ -143,6 +144,7 @@ module.exports = {
143
144
  "npm-unknown",
144
145
  "undetermined",
145
146
  "unknown",
147
+ "type-only",
146
148
  ],
147
149
  },
148
150
  ModuleSystemType: { type: "string", enum: ["cjs", "es6", "amd", "tsd"] },
@@ -332,6 +334,8 @@ module.exports = {
332
334
  moreThanOneDependencyType: { type: "boolean" },
333
335
  license: { $ref: "#/definitions/REAsStringsType" },
334
336
  licenseNot: { $ref: "#/definitions/REAsStringsType" },
337
+ via: { $ref: "#/definitions/REAsStringsType" },
338
+ viaNot: { $ref: "#/definitions/REAsStringsType" },
335
339
  },
336
340
  },
337
341
  DependentsModuleRestrictionType: {
@@ -37,11 +37,13 @@ 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
43
45
  propertyEquals(pTo, pRule, "preCompilationOnly") &&
44
- // couldNotResolve, circular, dynamic and exoticallyRequired are
46
+ // couldNotResolve, circular, dynamic and exoticallyRequired _are_ mandatory
45
47
  propertyEquals(pTo, pRule, "couldNotResolve") &&
46
48
  propertyEquals(pTo, pRule, "circular") &&
47
49
  propertyEquals(pTo, pRule, "dynamic") &&
@@ -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
  };
@@ -122,6 +122,13 @@ export interface IDependency {
122
122
  * then only when the option 'tsPreCompilationDeps' has the value 'specify'.
123
123
  */
124
124
  preCompilationOnly?: boolean;
125
+ /**
126
+ * 'true' when the module included the module explicitly as type only with the '
127
+ * type' keyword e.g. import type { IThingus } from 'thing' Dependency-cruiser
128
+ * will only specify this attribute for TypeScript and when the 'tsPreCompilationDeps'
129
+ * option has either the value true or 'specify'.
130
+ */
131
+ typeOnly?: boolean;
125
132
  /**
126
133
  * If following this dependency will ultimately return to the source (circular === true),
127
134
  * this attribute will contain an (ordered) array of module names that shows (one of) the
@@ -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
  */
@@ -37,6 +37,7 @@ export type DependencyType =
37
37
  | "npm-peer"
38
38
  | "npm-unknown"
39
39
  | "undetermined"
40
- | "unknown";
40
+ | "unknown"
41
+ | "type-only";
41
42
 
42
- export type ProtocolType = "data:" | "file:" | "node";
43
+ export type ProtocolType = "data:" | "file:" | "node:";