dependency-cruiser 13.0.1 → 13.0.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": "13.0.1",
3
+ "version": "13.0.3",
4
4
  "description": "Validate and visualize dependencies. With your rules. JavaScript, TypeScript, CoffeeScript. ES6, CommonJS, AMD.",
5
5
  "keywords": [
6
6
  "static analysis",
@@ -50,17 +50,20 @@
50
50
  "types": "./types/dependency-cruiser.d.ts"
51
51
  },
52
52
  "./config-utl/extract-babel-config": {
53
- "import": "./src/config-utl/extract-babel-config.mjs"
53
+ "import": "./src/config-utl/extract-babel-config.mjs",
54
+ "types": "./types/extract-babel-config.d.ts"
54
55
  },
55
56
  "./config-utl/extract-depcruise-config": {
56
- "import": "./src/config-utl/extract-depcruise-config/index.mjs"
57
+ "import": "./src/config-utl/extract-depcruise-config/index.mjs",
58
+ "types": "./types/extract-depcruise-config.d.ts"
57
59
  },
58
60
  "./config-utl/extract-ts-config": {
59
61
  "import": "./src/config-utl/extract-ts-config.mjs",
60
62
  "types": "./types/extract-ts-config.d.ts"
61
63
  },
62
64
  "./config-utl/extract-webpack-resolve-config": {
63
- "import": "./src/config-utl/extract-webpack-resolve-config.mjs"
65
+ "import": "./src/config-utl/extract-webpack-resolve-config.mjs",
66
+ "types": "./types/extract-webpack-resolve-config.d.ts"
64
67
  },
65
68
  "./sample-reporter-plugin": "./configs/plugins/stats-reporter-plugin.js",
66
69
  "./sample-3d-reporter-plugin": "./configs/plugins/3d-reporter-plugin.js",
@@ -90,10 +93,10 @@
90
93
  "depcruise:baseline": "node ./bin/depcruise-baseline.mjs src bin test configs types tools",
91
94
  "depcruise:explain": "node ./bin/dependency-cruise.mjs src bin test configs types tools --output-type err-long --progress none",
92
95
  "depcruise:graph:doc": "npm-run-all depcruise:graph:doc:json --parallel depcruise:graph:doc:fmt-* depcruise:graph:doc:samples",
93
- "depcruise:graph:doc:json": "node ./bin/dependency-cruise.mjs bin src test --output-type json --output-to tmp_graph_deps.json --progress",
94
- "depcruise:graph:doc:fmt-detail": "./bin/depcruise-fmt.mjs -T dot -f - tmp_graph_deps.json | dot -T svg | tee doc/real-world-samples/dependency-cruiser-without-node_modules.svg | node bin/wrap-stream-in-html.mjs > docs/dependency-cruiser-dependency-graph.html",
95
- "depcruise:graph:doc:fmt-archi": "./bin/depcruise-fmt.mjs -T archi -f - tmp_graph_deps.json | dot -T svg -Gordering=in -Grankdir=TD | tee doc/real-world-samples/dependency-cruiser-archi-graph.svg | node bin/wrap-stream-in-html.mjs > docs/dependency-cruiser-archi-graph.html",
96
- "depcruise:graph:doc:fmt-dir": "./bin/depcruise-fmt.mjs -T ddot -f - tmp_graph_deps.json | dot -T svg -Grankdir=TD | tee doc/real-world-samples/dependency-cruiser-dir-graph.svg | node bin/wrap-stream-in-html.mjs > docs/dependency-cruiser-dir-graph.html",
96
+ "depcruise:graph:doc:json": "node ./bin/dependency-cruise.mjs bin src test --output-type json --output-to node_modules/.cache/tmp_graph_deps.json --progress",
97
+ "depcruise:graph:doc:fmt-detail": "./bin/depcruise-fmt.mjs -T dot -f - node_modules/.cache/tmp_graph_deps.json | dot -T svg | tee doc/real-world-samples/dependency-cruiser-without-node_modules.svg | node bin/wrap-stream-in-html.mjs > docs/dependency-cruiser-dependency-graph.html",
98
+ "depcruise:graph:doc:fmt-archi": "./bin/depcruise-fmt.mjs -T archi -f - node_modules/.cache/tmp_graph_deps.json | dot -T svg -Gordering=in -Grankdir=TD | tee doc/real-world-samples/dependency-cruiser-archi-graph.svg | node bin/wrap-stream-in-html.mjs > docs/dependency-cruiser-archi-graph.html",
99
+ "depcruise:graph:doc:fmt-dir": "./bin/depcruise-fmt.mjs -T ddot -f - node_modules/.cache/tmp_graph_deps.json | dot -T svg -Grankdir=TD | tee doc/real-world-samples/dependency-cruiser-dir-graph.svg | node bin/wrap-stream-in-html.mjs > docs/dependency-cruiser-dir-graph.html",
97
100
  "depcruise:graph:doc:fmt-schema": "cd tools/schema && node ../../bin/dependency-cruise.mjs . --output-type dot | dot -T svg | tee ../overview.svg | node ../../bin/wrap-stream-in-html.mjs > ../../docs/schema-overview.html && cd -",
98
101
  "depcruise:graph:doc:fmt-types": "cd types && node ../bin/dependency-cruise.mjs . --output-type dot | dot -T svg > overview.svg && cd -",
99
102
  "depcruise:graph:doc:samples": "sh tools/generate-samples.sh",
@@ -153,10 +156,9 @@
153
156
  "ajv": "8.12.0",
154
157
  "chalk": "5.2.0",
155
158
  "commander": "10.0.1",
156
- "enhanced-resolve": "5.14.0",
159
+ "enhanced-resolve": "5.14.1",
157
160
  "figures": "5.0.0",
158
- "get-stream": "^6.0.1",
159
- "glob": "10.2.4",
161
+ "glob": "10.2.6",
160
162
  "handlebars": "4.7.7",
161
163
  "ignore": "5.2.4",
162
164
  "indent-string": "5.0.0",
@@ -171,25 +173,25 @@
171
173
  "semver-try-require": "6.2.2",
172
174
  "teamcity-service-messages": "0.1.14",
173
175
  "tsconfig-paths-webpack-plugin": "4.0.1",
174
- "watskeburt": "0.11.2",
176
+ "watskeburt": "0.11.3",
175
177
  "wrap-ansi": "8.1.0"
176
178
  },
177
179
  "devDependencies": {
178
- "@babel/core": "7.21.8",
180
+ "@babel/core": "7.22.1",
179
181
  "@babel/plugin-transform-modules-commonjs": "7.21.5",
180
182
  "@babel/preset-typescript": "7.21.5",
181
- "@swc/core": "1.3.58",
182
- "@types/lodash": "4.14.194",
183
- "@types/node": "20.1.6",
183
+ "@swc/core": "1.3.62",
184
+ "@types/lodash": "4.14.195",
185
+ "@types/node": "20.2.5",
184
186
  "@types/prompts": "2.4.4",
185
- "@typescript-eslint/eslint-plugin": "5.59.6",
186
- "@typescript-eslint/parser": "5.59.6",
187
- "@vue/compiler-sfc": "3.3.2",
188
- "c8": "7.13.0",
187
+ "@typescript-eslint/eslint-plugin": "5.59.8",
188
+ "@typescript-eslint/parser": "5.59.8",
189
+ "@vue/compiler-sfc": "3.3.4",
190
+ "c8": "7.14.0",
189
191
  "chai": "4.3.7",
190
192
  "chai-json-schema": "1.5.1",
191
193
  "coffeescript": "2.7.0",
192
- "eslint": "8.40.0",
194
+ "eslint": "8.42.0",
193
195
  "eslint-config-moving-meadow": "4.0.2",
194
196
  "eslint-config-prettier": "8.8.0",
195
197
  "eslint-plugin-budapestian": "5.0.1",
@@ -210,7 +212,7 @@
210
212
  "shx": "0.3.4",
211
213
  "svelte": "3.59.1",
212
214
  "symlink-dir": "5.1.1",
213
- "typescript": "5.0.4",
215
+ "typescript": "5.1.3",
214
216
  "upem": "7.3.2",
215
217
  "vue-template-compiler": "2.7.14",
216
218
  "yarn": "1.22.19"
@@ -1,4 +1,3 @@
1
- import getStream from "get-stream";
2
1
  import _format from "../main/format.mjs";
3
2
  import validateFileExistence from "./utl/validate-file-existence.mjs";
4
3
  import normalizeOptions from "./normalize-cli-options.mjs";
@@ -8,7 +7,7 @@ import { getInStream, write } from "./utl/io.mjs";
8
7
  *
9
8
  * @param {string} pResultFile the name of the file with cruise results
10
9
  * @param {import("../../types/dependency-cruiser").IFormatOptions} pOptions
11
- * @returns {Number} an exitCode
10
+ * @returns {Promise<Number>} an exitCode
12
11
  */
13
12
  export default async function format(pResultFile, pOptions) {
14
13
  const lOptions = await normalizeOptions(pOptions);
@@ -17,10 +16,30 @@ export default async function format(pResultFile, pOptions) {
17
16
  validateFileExistence(pResultFile);
18
17
  }
19
18
 
20
- const lResult = await getStream(getInStream(pResultFile));
19
+ return new Promise((pResolve, pReject) => {
20
+ let lInputAsString = "";
21
+ const lInStream = getInStream(pResultFile);
21
22
 
22
- const lReportingResult = await _format(JSON.parse(lResult), lOptions);
23
+ lInStream
24
+ .on("data", (pChunk) => {
25
+ lInputAsString += pChunk;
26
+ })
27
+ .on(
28
+ "error",
29
+ /* c8 ignore start */
30
+ (pError) => {
31
+ pReject(pError);
32
+ }
33
+ /* c8 ignore stop */
34
+ )
35
+ .on("end", async () => {
36
+ const lReportingResult = await _format(
37
+ JSON.parse(lInputAsString),
38
+ lOptions
39
+ );
23
40
 
24
- write(lOptions.outputTo, lReportingResult.output);
25
- return lReportingResult.exitCode;
41
+ write(lOptions.outputTo, lReportingResult.output);
42
+ pResolve(lReportingResult.exitCode);
43
+ });
44
+ });
26
45
  }
@@ -76,11 +76,11 @@ async function getConfig(pBabelConfigFileName) {
76
76
  /**
77
77
  * Reads the file with name `pBabelConfigFileName` and returns its parsed
78
78
  * contents as an object
79
- *x
79
+ *
80
80
  * Silently fails if a supported @babel/core version can't be found
81
81
  *
82
82
  * @param {string} pBabelConfigFileName
83
- * @return {any} babel config as an object
83
+ * @return {object} babel config as an object
84
84
  * @throws {Error} when the babel config has an unknown extension OR
85
85
  * when the babel config is invalid OR
86
86
  * when dependency-cruiser can't yet process it
@@ -35,7 +35,7 @@ const FORMAT_DIAGNOSTICS_HOST = {
35
35
  *
36
36
  * @param {string} pTSConfigFileName
37
37
  * @return {import("typescript").ParsedCommandLine} tsconfig as an object
38
- * @throws {Error} when the tsconfig is invalid/ jas errors
38
+ * @throws {Error} when the tsconfig is invalid/ has errors
39
39
  * @throws {TypeError} when the tsconfig is unreadable
40
40
  */
41
41
  export default function extractTSConfig(pTSConfigFileName) {
@@ -2,6 +2,7 @@
2
2
  import tryImport from "semver-try-require";
3
3
  import meta from "../../meta.js";
4
4
 
5
+ /** @type {import("typescript")} */
5
6
  const typescript = await tryImport(
6
7
  "typescript",
7
8
  meta.supportedTranspilers.typescript
@@ -120,13 +121,26 @@ function firstArgumentIsAString(pASTNode) {
120
121
  }
121
122
 
122
123
  function isRequireCallExpression(pASTNode) {
123
- return (
124
+ if (
124
125
  typescript.SyntaxKind[pASTNode.kind] === "CallExpression" &&
125
- pASTNode.expression &&
126
- typescript.SyntaxKind[pASTNode.expression.originalKeywordKind] ===
127
- "RequireKeyword" &&
128
- firstArgumentIsAString(pASTNode)
129
- );
126
+ pASTNode.expression
127
+ ) {
128
+ /*
129
+ * from typescript 5.0.0 the `originalKeywordKind` attribute is deprecated
130
+ * and from 5.2.0 it will be gone. However, in typescript < 5.0.0 (still used
131
+ * heavily IRL) it's the only way to get it - hence this test for the
132
+ * existence of the * identifierToKeywordKind function to remain backwards
133
+ * compatible
134
+ */
135
+ const lSyntaxKind = typescript.identifierToKeywordKind
136
+ ? typescript.SyntaxKind[
137
+ typescript.identifierToKeywordKind(pASTNode.expression)
138
+ ]
139
+ : /* c8 ignore next 1 */
140
+ typescript.SyntaxKind[pASTNode.expression.originalKeywordKind];
141
+ return lSyntaxKind === "RequireKeyword" && firstArgumentIsAString(pASTNode);
142
+ }
143
+ return false;
130
144
  }
131
145
 
132
146
  function isSingleExoticRequire(pASTNode, pString) {
package/src/meta.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /* generated - don't edit */
2
2
 
3
3
  module.exports = {
4
- version: "13.0.1",
4
+ version: "13.0.3",
5
5
  engines: {
6
6
  node: "^16.14||>=18",
7
7
  },
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Reads the file with name `pBabelConfigFileName` and returns its parsed
3
+ * contents as an object
4
+ *x
5
+ * Silently fails if a supported @babel/core version can't be found
6
+ *
7
+ * @param pBabelConfigFileName
8
+ * @return babel config as an object
9
+ * @throws when the babel config has an unknown extension OR
10
+ * when the babel config is invalid OR
11
+ * when dependency-cruiser can't yet process it
12
+ */
13
+ export default function extractBabelConfig(
14
+ pBabelConfigFileName: string
15
+ ): Promise<object>;
16
+
17
+ // regarding the rather unspecific _object_ type - this is what's
18
+ // currently specified on definitelyTyped for @babel/core:
19
+ // https://github.com/DefinitelyTyped/DefinitelyTyped/blob/b93ba16b8e482e66f7a82c426096ae31e1311710/types/babel__core/index.d.ts#L614
@@ -0,0 +1,24 @@
1
+ import { ICruiseOptions } from "./options";
2
+
3
+ /**
4
+ * Reads the file with name `pConfigFileName` returns the parsed cruise
5
+ * options.
6
+ *
7
+ * You can safely ignore the optional parameters. Simply this should work (given
8
+ * `.dependency-cruiser.js` exists and contains a valid dependency-cruiser config)
9
+ *
10
+ * ```javascript
11
+ * const depcruiseConfig = extractDepcruiseConfig("./.dependency-cruiser.js")
12
+ * ```
13
+ *
14
+ * @param pConfigFileName
15
+ * @param pAlreadyVisited
16
+ * @param pBaseDirectory
17
+ * @return dependency-cruiser options
18
+ * @throws when the config is not valid (/ does not exist/ isn't readable)
19
+ */
20
+ export default function extractDepcruiseConfig(
21
+ pConfigFileName: string,
22
+ pAlreadyVisited?: Set<string>,
23
+ pBaseDirectory?: string
24
+ ): Promise<ICruiseOptions>;
@@ -1,5 +1,16 @@
1
1
  import { ParsedCommandLine } from "typescript";
2
2
 
3
+ /**
4
+ * Reads the file with name `pTSConfigFileName` and returns its parsed
5
+ * contents as an object
6
+ *
7
+ * Silently fails if a supported version of the typescript compiler isn't available
8
+ *
9
+ * @param pTSConfigFileName
10
+ * @return tsconfig as an object
11
+ * @throws {Error} when the tsconfig is invalid/ has errors
12
+ * @throws {TypeError} when the tsconfig is unreadable
13
+ */
3
14
  export default function extractTSConfig(
4
15
  pTSConfigFileName: string
5
16
  ): ParsedCommandLine;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Reads the file with name `pWebpackConfigFilename` and (applying the
3
+ * environment `pEnvironment` and the arguments `pArguments` (which can
4
+ * either be a string or a keys-values object)) returns the resolve config
5
+ * from it as an object.
6
+ *
7
+ * @param pWebpackConfigFilename
8
+ * @param pEnvironment
9
+ * @param pArguments
10
+ * @return webpack resolve config as an object
11
+ * @throws when the webpack config isn't usable (e.g. because it
12
+ * doesn't exist, or because it's invalid)
13
+ */
14
+ export default function extractWebpackResolveConfig(
15
+ pWebpackConfigFilename: string,
16
+ pEnvironment?: string,
17
+ pArguments?: string | any
18
+ ): Promise<any>;