dependency-cruiser 11.14.1 → 11.15.0-beta-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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dependency-cruiser",
3
- "version": "11.14.1",
3
+ "version": "11.15.0-beta-1",
4
4
  "description": "Validate and visualize dependencies. With your rules. JavaScript, TypeScript, CoffeeScript. ES6, CommonJS, AMD.",
5
5
  "keywords": [
6
6
  "static analysis",
@@ -188,12 +188,14 @@
188
188
  "eslint-plugin-unicorn": "^43.0.1",
189
189
  "husky": "^4.3.8",
190
190
  "intercept-stdout": "0.1.2",
191
+ "interpret": "^2.2.0",
191
192
  "lint-staged": "12.3.4",
192
193
  "mocha": "10.0.0",
193
194
  "normalize-newline": "^3.0.0",
194
195
  "npm-run-all": "4.1.5",
195
196
  "prettier": "2.7.1",
196
197
  "proxyquire": "2.1.3",
198
+ "rechoir": "^0.8.0",
197
199
  "shx": "0.3.4",
198
200
  "svelte": "3.49.0",
199
201
  "symlink-dir": "5.0.1",
@@ -234,6 +236,11 @@
234
236
  "policy": "wanted",
235
237
  "because": "version 5 only exports ejs - and we use cjs and don't transpile"
236
238
  },
239
+ {
240
+ "package": "interpret",
241
+ "policy": "wanted",
242
+ "because": "we want to keep interpret ~similar to what webpack-cli is using (which is ^2.2.0)"
243
+ },
237
244
  {
238
245
  "package": "lint-staged",
239
246
  "policy": "pin",
@@ -244,6 +251,11 @@
244
251
  "policy": "wanted",
245
252
  "because": "version 4 only exports ejs - and we use cjs and don't transpile (this only used in unit tests - but one of'em is a cjs one ...)"
246
253
  },
254
+ {
255
+ "package": "rechoir",
256
+ "policy": "wanted",
257
+ "because": "we want to keep rechoir ~similar to what webpack-cli is using (which is ^0.7.0, but ^0.8.0 is similar enough and more recent anyway)"
258
+ },
247
259
  {
248
260
  "package": "wrap-ansi",
249
261
  "policy": "wanted",
@@ -1,3 +1,5 @@
1
+ const { extname } = require("path");
2
+ const tryRequire = require("semver-try-require");
1
3
  const makeAbsolute = require("./make-absolute");
2
4
 
3
5
  function pryConfigFromTheConfig(
@@ -22,6 +24,61 @@ function pryConfigFromTheConfig(
22
24
  return lReturnValue;
23
25
  }
24
26
 
27
+ function suggestModules(pSuggestionList, pWebpackConfigFilename) {
28
+ let lReturnValue = "";
29
+ let lSuggestionList = pSuggestionList;
30
+
31
+ if (pSuggestionList && typeof pSuggestionList === "string") {
32
+ lSuggestionList = [pSuggestionList];
33
+ }
34
+
35
+ if (Array.isArray(lSuggestionList) && lSuggestionList.length > 0) {
36
+ lReturnValue = lSuggestionList.reduce(
37
+ (pAll, pCurrent) =>
38
+ (pAll += ` - ${pCurrent.module || pCurrent}\n`),
39
+ `\n Some npm modules that might fix that problem (one of which you'll` +
40
+ `\n need so '${pWebpackConfigFilename}' works with webpack anyway):\n`
41
+ );
42
+ }
43
+ return lReturnValue;
44
+ }
45
+
46
+ function tryRegisterNonNative(pWebpackConfigFilename) {
47
+ const lConfigExtension = extname(pWebpackConfigFilename);
48
+
49
+ if (lConfigExtension === ".mjs") {
50
+ throw new Error(
51
+ `dependency-cruiser currently does not support webpack configurations in` +
52
+ `\n ES Module format (like '${pWebpackConfigFilename}').\n`
53
+ );
54
+ }
55
+
56
+ const interpret = tryRequire("interpret", "^2.2.0");
57
+ const rechoir = tryRequire("rechoir", "^0.7.0||^0.8.0");
58
+
59
+ if (interpret.extensions && rechoir) {
60
+ try {
61
+ rechoir.prepare(interpret.extensions, pWebpackConfigFilename);
62
+ } catch (pError) {
63
+ throw new Error(
64
+ `${pError.message}` +
65
+ `\n${suggestModules(
66
+ // eslint-disable-next-line security/detect-object-injection
67
+ interpret.extensions[lConfigExtension],
68
+ pWebpackConfigFilename
69
+ )}`
70
+ );
71
+ }
72
+ } else {
73
+ throw new Error(
74
+ `The webpack config '${pWebpackConfigFilename}' needs to be transpiled before\n` +
75
+ ` dependency-cruiser can pass it to webpack.\n\n` +
76
+ ` To fix that:\n\n` +
77
+ ` npm install --development interpret@^2.2.0 rechoir@^0.7.0\n\n`
78
+ );
79
+ }
80
+ }
81
+
25
82
  /**
26
83
  * Reads the file with name `pWebpackConfigFilename` and (applying the
27
84
  * environment `pEnvironment` and the arguments `pArguments` (which can
@@ -35,16 +92,23 @@ function pryConfigFromTheConfig(
35
92
  * @throws {Error} when the webpack config isn't usable (e.g. because it
36
93
  * doesn't exist, or because it's invalid)
37
94
  */
95
+ // eslint-disable-next-line max-lines-per-function, complexity
38
96
  module.exports = function extractWebpackResolveConfig(
39
97
  pWebpackConfigFilename,
40
98
  pEnvironment,
41
99
  pArguments
42
100
  ) {
43
101
  let lReturnValue = {};
102
+ const lNativelySupportedExtensions = [".js", ".cjs", ".json", ".node"];
103
+ const lWebpackConfigFilename = makeAbsolute(pWebpackConfigFilename);
104
+
105
+ if (!lNativelySupportedExtensions.includes(extname(pWebpackConfigFilename))) {
106
+ tryRegisterNonNative(pWebpackConfigFilename);
107
+ }
44
108
 
45
109
  try {
46
110
  /* eslint node/global-require:0, security/detect-non-literal-require:0, import/no-dynamic-require:0 */
47
- const lWebpackConfigModule = require(makeAbsolute(pWebpackConfigFilename));
111
+ const lWebpackConfigModule = require(lWebpackConfigFilename);
48
112
  const lWebpackConfig = pryConfigFromTheConfig(
49
113
  lWebpackConfigModule,
50
114
  pEnvironment,
package/src/meta.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /* generated - don't edit */
2
2
 
3
3
  module.exports = {
4
- version: "11.14.1",
4
+ version: "11.15.0-beta-1",
5
5
  engines: {
6
6
  node: "^12.20||^14||>=16",
7
7
  },