dependency-cruiser 13.0.0-beta-3 → 13.0.0-beta-5

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/README.md CHANGED
@@ -59,6 +59,19 @@ a one liner:
59
59
  npx depcruise src --include-only "^src" --output-type dot | dot -T svg > dependency-graph.svg
60
60
  ```
61
61
 
62
+ > <details>
63
+ > <summary>dependency-cruiser v12 and older: add --config option</summary>
64
+ >
65
+ > While not necessary from dependency-cruiser v13, in v12 and older you'll have
66
+ > to pass the --config option to make it find the .dependency-cruiser.js
67
+ > configuration file:
68
+ >
69
+ > ```shell
70
+ > npx depcruise src --include-only "^src" --config --output-type dot | dot -T svg > dependency-graph.svg
71
+ > ```
72
+
73
+ </details>
74
+
62
75
  - You can read more about what you can do with `--include-only` and other command line
63
76
  options in the [command line interface](./doc/cli.md) documentation.
64
77
  - _[Real world samples](./doc/real-world-samples.md)_
@@ -110,6 +123,19 @@ Sample rule:
110
123
  npx depcruise src
111
124
  ```
112
125
 
126
+ > <details>
127
+ > <summary>dependency-cruiser v12 and older: add --config option</summary>
128
+ >
129
+ > While not necessary from dependency-cruiser v13, in v12 and older you'll have
130
+ > to pass the --config option to make it find the .dependency-cruiser.js
131
+ > configuration file:
132
+ >
133
+ > ```shell
134
+ > npx depcruise --config .dependency-cruiser.js src
135
+ > ```
136
+
137
+ </details>
138
+
113
139
  This will validate against your rules and shows any violations in an eslint-like format:
114
140
 
115
141
  ![sample err output](https://raw.githubusercontent.com/sverweij/dependency-cruiser/master/doc/assets/sample-err-output.png)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dependency-cruiser",
3
- "version": "13.0.0-beta-3",
3
+ "version": "13.0.0-beta-5",
4
4
  "description": "Validate and visualize dependencies. With your rules. JavaScript, TypeScript, CoffeeScript. ES6, CommonJS, AMD.",
5
5
  "keywords": [
6
6
  "static analysis",
@@ -97,7 +97,7 @@
97
97
  "depcruise:graph:doc:samples": "sh tools/generate-samples.sh",
98
98
  "depcruise:graph:mermaid": "node ./bin/dependency-cruise.mjs bin src --include-only ^src/ --collapse 2 --output-type mermaid",
99
99
  "depcruise:graph:mermaid:diff": "node ./bin/dependency-cruise.mjs bin src test types tools --config configs/.dependency-cruiser-unlimited.json --output-type mermaid --reaches \"$(watskeburt $SHA)\"",
100
- "depcruise:graph:view": "node ./bin/dependency-cruise.mjs bin src --prefix vscode://file/$(pwd)/ --config configs/.dependency-cruiser-show-metrics-config.mjs --output-type dot --progress cli-feedback --highlight \"$(watskeburt v13)\" | dot -T svg | node ./bin/wrap-stream-in-html.mjs | browser",
100
+ "depcruise:graph:view": "node ./bin/dependency-cruise.mjs bin src --prefix vscode://file/$(pwd)/ --config configs/.dependency-cruiser-show-metrics-config.mjs --output-type dot --progress cli-feedback --highlight \"$(watskeburt develop)\" | dot -T svg | node ./bin/wrap-stream-in-html.mjs | browser",
101
101
  "depcruise:graph:view:diff": "node ./bin/dependency-cruise.mjs bin src test --prefix vscode://file/$(pwd)/ --config configs/.dependency-cruiser-unlimited.json --output-type dot --progress cli-feedback --reaches \"$(watskeburt develop)\" | dot -T svg | node ./bin/wrap-stream-in-html.mjs | browser",
102
102
  "depcruise:report": "node ./bin/dependency-cruise.mjs src bin test configs types --output-type err-html --config configs/.dependency-cruiser-show-metrics-config.mjs --output-to dependency-violations.html",
103
103
  "depcruise:report:view": "node ./bin/dependency-cruise.mjs src bin test configs types --output-type err-html --config configs/.dependency-cruiser-show-metrics-config.mjs --output-to - | browser",
@@ -126,14 +126,16 @@
126
126
  "scm:push:gitlab-mirror:commits": "git push gitlab-mirror",
127
127
  "scm:push:gitlab-mirror:tags": "git push --tags gitlab-mirror",
128
128
  "scm:stage": "git add .",
129
- "test": "LANG=en_US.UTF-8 mocha",
130
- "test:i": "LANG=en_US.UTF-8 mocha --grep \"^\\[[I]\\]\"",
131
- "test:u": "LANG=en_US.UTF-8 mocha --grep \"^\\[[U]\\]\"",
132
- "test:e": "LANG=en_US.UTF-8 mocha --grep \"^\\[[E]\\]\"",
133
- "test:cover": "LANG=en_US.UTF-8 c8 mocha",
129
+ "test": "LANG=en_US.UTF-8 NODE_OPTIONS=--no-warnings mocha",
130
+ "test:i": "LANG=en_US.UTF-8 NODE_OPTIONS=--no-warnings mocha --grep \"^\\[[I]\\]\"",
131
+ "test:u": "LANG=en_US.UTF-8 NODE_OPTIONS=--no-warnings mocha --grep \"^\\[[U]\\]\"",
132
+ "test:e": "LANG=en_US.UTF-8 NODE_OPTIONS=--no-warnings mocha --grep \"^\\[[E]\\]\"",
133
+ "test:cover": "LANG=en_US.UTF-8 NODE_OPTIONS=--no-warnings c8 mocha",
134
134
  "test:glob": "set -f && test \"`bin/dependency-cruise.mjs --no-config test/extract/__mocks__/gather-globbing/packages/**/src/**/*.js | grep \"no dependency violations found\"`\" = \"✔ no dependency violations found (6 modules, 0 dependencies cruised)\"",
135
135
  "test:load": "hyperfine --warmup 3 --runs 30 \"bin/dependency-cruise.mjs src bin test configs types tools --ignore-known --no-cache --no-progress\"",
136
136
  "test:load:short": "hyperfine --warmup 1 --runs 5 \"bin/dependency-cruise.mjs src bin test configs types tools --ignore-known --no-cache --no-progress\"",
137
+ "test:load:cached": "hyperfine --warmup 3 --runs 30 \"bin/dependency-cruise.mjs src bin test configs types tools --ignore-known --cache node_modules/.cache/dependency-cruiser/load-cached --no-progress\"",
138
+ "test:load:cached:short": "hyperfine --warmup 1 --runs 5 \"bin/dependency-cruise.mjs src bin test configs types tools --ignore-known --cache node_modules/.cache/dependency-cruiser/load-cached --no-progress\"",
137
139
  "update-dependencies": "npm-run-all upem:update upem:install build:clean build lint:eslint:clear-caches lint:fix depcruise test:cover",
138
140
  "upem-outdated": "npm outdated --json --long | upem --dry-run",
139
141
  "upem:install": "npm install",
@@ -152,7 +154,7 @@
152
154
  "enhanced-resolve": "5.13.0",
153
155
  "figures": "5.0.0",
154
156
  "get-stream": "^6.0.1",
155
- "glob": "10.2.1",
157
+ "glob": "10.2.2",
156
158
  "handlebars": "4.7.7",
157
159
  "ignore": "5.2.4",
158
160
  "indent-string": "5.0.0",
@@ -176,7 +178,7 @@
176
178
  "@babel/preset-typescript": "7.21.4",
177
179
  "@swc/core": "1.3.53",
178
180
  "@types/lodash": "4.14.194",
179
- "@types/node": "18.15.13",
181
+ "@types/node": "18.16.0",
180
182
  "@types/prompts": "2.4.4",
181
183
  "@typescript-eslint/eslint-plugin": "5.59.0",
182
184
  "@typescript-eslint/parser": "5.59.0",
@@ -201,7 +203,7 @@
201
203
  "mocha": "10.2.0",
202
204
  "normalize-newline": "4.1.0",
203
205
  "npm-run-all": "4.1.5",
204
- "prettier": "2.8.7",
206
+ "prettier": "2.8.8",
205
207
  "proxyquire": "2.1.3",
206
208
  "shx": "0.3.4",
207
209
  "svelte": "3.58.0",
@@ -1,5 +1,5 @@
1
1
  import getStream from "get-stream";
2
- import { format as _format } from "../main/index.mjs";
2
+ import _format from "../main/format.mjs";
3
3
  import validateFileExistence from "./utl/validate-file-existence.mjs";
4
4
  import normalizeOptions from "./normalize-cli-options.mjs";
5
5
  import { getInStream, write } from "./utl/io.mjs";
package/src/cli/index.mjs CHANGED
@@ -6,22 +6,16 @@ import set from "lodash/set.js";
6
6
  import isInstalledGlobally from "is-installed-globally";
7
7
  import chalk from "chalk";
8
8
 
9
- import { cruise } from "../main/index.mjs";
9
+ import cruise from "../main/cruise.mjs";
10
10
  import bus from "../utl/bus.mjs";
11
11
 
12
- import extractTSConfig from "../config-utl/extract-ts-config.mjs";
13
- import extractBabelConfig from "../config-utl/extract-babel-config.mjs";
14
- import extractWebpackResolveConfig from "../config-utl/extract-webpack-resolve-config.mjs";
15
- import extractKnownViolations from "../config-utl/extract-known-violations.mjs";
16
12
  import busLogLevels from "../utl/bus-log-levels.mjs";
17
13
  import validateFileExistence from "./utl/validate-file-existence.mjs";
18
14
  import normalizeCliOptions from "./normalize-cli-options.mjs";
19
15
  import { write } from "./utl/io.mjs";
20
- import formatMetaInfo from "./format-meta-info.mjs";
21
16
  import setUpCliFeedbackListener from "./listeners/cli-feedback.mjs";
22
17
  import setUpPerformanceLogListener from "./listeners/performance-log/index.mjs";
23
18
  import setUpNDJSONListener from "./listeners/ndjson.mjs";
24
- import initConfig from "./init-config/index.mjs";
25
19
 
26
20
  async function extractResolveOptions(pCruiseOptions) {
27
21
  let lResolveOptions = {};
@@ -29,6 +23,9 @@ async function extractResolveOptions(pCruiseOptions) {
29
23
  pCruiseOptions?.ruleSet?.options?.webpackConfig?.fileName ?? null;
30
24
 
31
25
  if (lWebPackConfigFileName) {
26
+ const { default: extractWebpackResolveConfig } = await import(
27
+ "../config-utl/extract-webpack-resolve-config.mjs"
28
+ );
32
29
  lResolveOptions = await extractWebpackResolveConfig(
33
30
  lWebPackConfigFileName,
34
31
  pCruiseOptions?.ruleSet?.options?.webpackConfig?.env ?? null,
@@ -38,9 +35,12 @@ async function extractResolveOptions(pCruiseOptions) {
38
35
  return lResolveOptions;
39
36
  }
40
37
 
41
- function addKnownViolations(pCruiseOptions) {
38
+ async function addKnownViolations(pCruiseOptions) {
42
39
  if (pCruiseOptions.knownViolationsFile) {
43
- const lKnownViolations = extractKnownViolations(
40
+ const { default: extractKnownViolations } = await import(
41
+ "../config-utl/extract-known-violations.mjs"
42
+ );
43
+ const lKnownViolations = await extractKnownViolations(
44
44
  pCruiseOptions.knownViolationsFile
45
45
  );
46
46
 
@@ -53,24 +53,29 @@ function addKnownViolations(pCruiseOptions) {
53
53
  return pCruiseOptions;
54
54
  }
55
55
 
56
- function extractTSConfigOptions(pCruiseOptions) {
56
+ async function extractTSConfigOptions(pCruiseOptions) {
57
57
  let lReturnValue = {};
58
58
  const lTSConfigFileName =
59
59
  pCruiseOptions?.ruleSet?.options?.tsConfig?.fileName ?? null;
60
60
 
61
61
  if (lTSConfigFileName) {
62
+ const { default: extractTSConfig } = await import(
63
+ "../config-utl/extract-ts-config.mjs"
64
+ );
62
65
  lReturnValue = extractTSConfig(lTSConfigFileName);
63
66
  }
64
67
 
65
68
  return lReturnValue;
66
69
  }
67
70
 
68
- function extractBabelConfigOptions(pCruiseOptions) {
71
+ async function extractBabelConfigOptions(pCruiseOptions) {
69
72
  let lReturnValue = {};
70
73
  const lBabelConfigFileName =
71
74
  pCruiseOptions?.ruleSet?.options?.babelConfig?.fileName ?? null;
72
-
73
75
  if (lBabelConfigFileName) {
76
+ const { default: extractBabelConfig } = await import(
77
+ "../config-utl/extract-babel-config.mjs"
78
+ );
74
79
  lReturnValue = extractBabelConfig(lBabelConfigFileName);
75
80
  }
76
81
 
@@ -99,7 +104,7 @@ function setUpListener(pCruiseOptions) {
99
104
  }
100
105
 
101
106
  async function runCruise(pFileDirectoryArray, pCruiseOptions) {
102
- const lCruiseOptions = addKnownViolations(
107
+ const lCruiseOptions = await addKnownViolations(
103
108
  await normalizeCliOptions(pCruiseOptions)
104
109
  );
105
110
 
@@ -115,14 +120,16 @@ async function runCruise(pFileDirectoryArray, pCruiseOptions) {
115
120
  setUpListener(lCruiseOptions);
116
121
 
117
122
  bus.emit("start");
123
+ const [lResolveOptions, tsConfig, babelConfig] = await Promise.all([
124
+ extractResolveOptions(lCruiseOptions),
125
+ extractTSConfigOptions(lCruiseOptions),
126
+ extractBabelConfigOptions(lCruiseOptions),
127
+ ]);
118
128
  const lReportingResult = await cruise(
119
129
  pFileDirectoryArray,
120
130
  lCruiseOptions,
121
- await extractResolveOptions(lCruiseOptions),
122
- {
123
- tsConfig: extractTSConfigOptions(lCruiseOptions),
124
- babelConfig: await extractBabelConfigOptions(lCruiseOptions),
125
- }
131
+ lResolveOptions,
132
+ { tsConfig, babelConfig }
126
133
  );
127
134
 
128
135
  bus.emit("progress", "cli: writing results", { complete: 1 });
@@ -159,8 +166,12 @@ export default async function executeCli(pFileDirectoryArray, pCruiseOptions) {
159
166
  }
160
167
  /* c8 ignore stop */
161
168
  if (lCruiseOptions.info === true) {
162
- process.stdout.write(formatMetaInfo());
169
+ const { default: formatMetaInfo } = await import(
170
+ "./format-meta-info.mjs"
171
+ );
172
+ process.stdout.write(await formatMetaInfo());
163
173
  } else if (lCruiseOptions.init) {
174
+ const { default: initConfig } = await import("./init-config/index.mjs");
164
175
  initConfig(lCruiseOptions.init);
165
176
  } else {
166
177
  lExitCode = await runCruise(pFileDirectoryArray, lCruiseOptions);
@@ -1,6 +1,9 @@
1
+ import chalk from "chalk";
1
2
  import busLogLevels from "../../../utl/bus-log-levels.mjs";
2
3
  import { getHeader, getProgressLine, getEndText } from "./handlers.mjs";
3
4
 
5
+ let gUnderline = false;
6
+
4
7
  function getHeaderWriter(pStream, pMaxLevel) {
5
8
  return (_pMessage, pOptions) => {
6
9
  const lOptions = { level: busLogLevels.SUMMARY, ...(pOptions || {}) };
@@ -12,8 +15,16 @@ function getHeaderWriter(pStream, pMaxLevel) {
12
15
  function getProgressWriter(pStream, pState, pMaxLevel) {
13
16
  return (pMessage, pOptions) => {
14
17
  const lOptions = { level: busLogLevels.SUMMARY, ...(pOptions || {}) };
15
-
16
- pStream.write(getProgressLine(pMessage, pState, lOptions.level, pMaxLevel));
18
+ const lProgressLine = getProgressLine(
19
+ pMessage,
20
+ pState,
21
+ lOptions.level,
22
+ pMaxLevel
23
+ );
24
+ pStream.write(
25
+ gUnderline ? `${chalk.underline(lProgressLine)}` : lProgressLine
26
+ );
27
+ gUnderline = !gUnderline;
17
28
  };
18
29
  }
19
30
 
@@ -1,4 +1,4 @@
1
- import { readFileSync } from "node:fs";
1
+ import { readFile } from "node:fs/promises";
2
2
  import { fileURLToPath } from "node:url";
3
3
 
4
4
  const HEADER_FILE = fileURLToPath(
@@ -25,10 +25,13 @@ const FOOTER_FILE = fileURLToPath(
25
25
  * @param {readStream} pStream stream whose characters are to be slapped between header and footer
26
26
  * @param {writeStream} pOutStream stream to write to
27
27
  */
28
- export default function wrap(pInStream, pOutStream) {
29
- const lHeader = readFileSync(HEADER_FILE, "utf8");
30
- const lScript = readFileSync(SCRIPT_FILE, "utf8");
31
- const lEnd = readFileSync(FOOTER_FILE, "utf8");
28
+ export default async function wrap(pInStream, pOutStream) {
29
+ const [lHeader, lScript, lEnd] = await Promise.all([
30
+ readFile(HEADER_FILE, "utf8"),
31
+ readFile(SCRIPT_FILE, "utf8"),
32
+ readFile(FOOTER_FILE, "utf8"),
33
+ ]);
34
+
32
35
  const lFooter = `<script>${lScript}</script>${lEnd}`;
33
36
 
34
37
  pOutStream.write(lHeader);
@@ -1,4 +1,4 @@
1
- import { readFileSync } from "node:fs";
1
+ import { readFile } from "node:fs/promises";
2
2
 
3
3
  import { extname } from "node:path";
4
4
  import json5 from "json5";
@@ -11,10 +11,10 @@ async function getJSConfig(pBabelConfigFileName) {
11
11
  let lReturnValue = {};
12
12
 
13
13
  try {
14
- const lModule = await import(
14
+ const { default: lModule } = await import(
15
15
  `file://${makeAbsolute(pBabelConfigFileName)}`
16
16
  );
17
- lReturnValue = lModule.default;
17
+ lReturnValue = lModule;
18
18
  } catch (pError) {
19
19
  throw new Error(
20
20
  `${
@@ -35,11 +35,11 @@ async function getJSConfig(pBabelConfigFileName) {
35
35
  return lReturnValue;
36
36
  }
37
37
 
38
- function getJSON5Config(pBabelConfigFileName) {
38
+ async function getJSON5Config(pBabelConfigFileName) {
39
39
  let lReturnValue = {};
40
40
 
41
41
  try {
42
- lReturnValue = json5.parse(readFileSync(pBabelConfigFileName, "utf8"));
42
+ lReturnValue = json5.parse(await readFile(pBabelConfigFileName, "utf8"));
43
43
  } catch (pError) {
44
44
  throw new Error(
45
45
  `Encountered an error while parsing the babel config '${pBabelConfigFileName}':` +
@@ -1,4 +1,4 @@
1
- import { readFileSync } from "node:fs";
1
+ import { readFile } from "node:fs/promises";
2
2
  import { extname } from "node:path";
3
3
  import json5 from "json5";
4
4
 
@@ -6,8 +6,10 @@ export default async function readConfig(pAbsolutePathToConfigFile) {
6
6
  if (
7
7
  [".js", ".cjs", ".mjs", ""].includes(extname(pAbsolutePathToConfigFile))
8
8
  ) {
9
- const lConfig = await import(`file://${pAbsolutePathToConfigFile}`);
10
- return lConfig.default;
9
+ const { default: config } = await import(
10
+ `file://${pAbsolutePathToConfigFile}`
11
+ );
12
+ return config;
11
13
  }
12
- return json5.parse(readFileSync(pAbsolutePathToConfigFile, "utf8"));
14
+ return json5.parse(await readFile(pAbsolutePathToConfigFile, "utf8"));
13
15
  }
@@ -1,11 +1,11 @@
1
- import { readFileSync } from "node:fs";
1
+ import { readFile } from "node:fs/promises";
2
2
  import json5 from "json5";
3
3
  import makeAbsolute from "./make-absolute.mjs";
4
4
 
5
- export default function extractKnownViolations(pKnownViolationsFileName) {
5
+ export default async function extractKnownViolations(pKnownViolationsFileName) {
6
6
  try {
7
7
  return json5.parse(
8
- readFileSync(makeAbsolute(pKnownViolationsFileName), "utf8")
8
+ await readFile(makeAbsolute(pKnownViolationsFileName), "utf8")
9
9
  );
10
10
  } catch (pError) {
11
11
  if (pError instanceof SyntaxError) {
@@ -78,8 +78,10 @@ function isNativelySupported(pWebpackConfigFilename) {
78
78
  async function attemptImport(pAbsoluteWebpackConfigFileName) {
79
79
  try {
80
80
  if (isNativelySupported(pAbsoluteWebpackConfigFileName)) {
81
- const lModule = await import(`file://${pAbsoluteWebpackConfigFileName}`);
82
- return lModule.default;
81
+ const { default: lModule } = await import(
82
+ `file://${pAbsoluteWebpackConfigFileName}`
83
+ );
84
+ return lModule;
83
85
  } else {
84
86
  tryRegisterNonNative(pAbsoluteWebpackConfigFileName);
85
87
  /* we're using still using require instead of dynamic imports here because
@@ -18,7 +18,7 @@ export default function enrichModules(pModules, pOptions) {
18
18
  pDependencyName: "resolved",
19
19
  });
20
20
  bus.emit("progress", "analyzing: dependents", { level: busLogLevels.INFO });
21
- lModules = addDependents(lModules, pOptions);
21
+ lModules = addDependents(lModules);
22
22
  bus.emit("progress", "analyzing: orphans", { level: busLogLevels.INFO });
23
23
  lModules = deriveOrphans(lModules);
24
24
  bus.emit("progress", "analyzing: reachables", { level: busLogLevels.INFO });
@@ -1,3 +1,8 @@
1
+ import {
2
+ IAvailableExtension,
3
+ IAvailableTranspiler,
4
+ } from "../../../types/dependency-cruiser.d.ts";
5
+
1
6
  export interface ITranspilerWrapper {
2
7
  isAvailable: () => boolean;
3
8
  transpile: (
@@ -11,12 +16,6 @@ export function getWrapper(pExtension, pTranspileOptions): ITranspilerWrapper;
11
16
 
12
17
  export const scannableExtensions: string[];
13
18
 
14
- export const allExtensions: string[];
15
-
16
- export interface IAvailableTranspiler {
17
- name: string;
18
- version: string;
19
- available: boolean;
20
- }
19
+ export const allExtensions: IAvailableExtension[];
21
20
 
22
21
  export function getAvailableTranspilers(): IAvailableTranspiler[];
@@ -0,0 +1,107 @@
1
+ /* eslint-disable no-return-await */
2
+ /* eslint-disable no-magic-numbers */
3
+
4
+ import bus from "../utl/bus.mjs";
5
+ import { validateCruiseOptions } from "./options/validate.mjs";
6
+ import { normalizeCruiseOptions } from "./options/normalize.mjs";
7
+ import reportWrap from "./report-wrap.mjs";
8
+
9
+ const TOTAL_STEPS = 10;
10
+
11
+ export function c(pComplete, pTotal = TOTAL_STEPS) {
12
+ return { complete: pComplete / pTotal };
13
+ }
14
+
15
+ /** @type {import("../../types/dependency-cruiser.js").cruise} */
16
+ // eslint-disable-next-line max-lines-per-function, max-statements
17
+ export default async function cruise(
18
+ pFileAndDirectoryArray,
19
+ pCruiseOptions,
20
+ pResolveOptions,
21
+ pTranspileOptions
22
+ ) {
23
+ bus.emit("progress", "parsing options", c(1));
24
+ /** @type {import("../../types/strict-options.js").IStrictCruiseOptions} */
25
+ let lCruiseOptions = normalizeCruiseOptions(
26
+ validateCruiseOptions(pCruiseOptions),
27
+ pFileAndDirectoryArray
28
+ );
29
+ let lCache = null;
30
+
31
+ if (lCruiseOptions.cache) {
32
+ bus.emit(
33
+ "progress",
34
+ `cache: check freshness with ${lCruiseOptions.cache.strategy}`,
35
+ c(2)
36
+ );
37
+
38
+ const { default: Cache } = await import("../cache/cache.mjs");
39
+ lCache = new Cache(lCruiseOptions.cache.strategy);
40
+ const lCachedResults = lCache.read(lCruiseOptions.cache.folder);
41
+
42
+ if (lCache.canServeFromCache(lCruiseOptions, lCachedResults)) {
43
+ bus.emit("progress", "cache: reporting from cache", c(8));
44
+ return await reportWrap(lCachedResults, lCruiseOptions);
45
+ }
46
+ }
47
+
48
+ bus.emit("progress", "importing analytical modules", c(3));
49
+ const [
50
+ { default: normalizeRuleSet },
51
+ { default: validateRuleSet },
52
+ { default: normalizeFilesAndDirectories },
53
+ { default: normalizeResolveOptions },
54
+ { default: extract },
55
+ { default: enrich },
56
+ ] = await Promise.all([
57
+ // despite rule set parsing being behind an if, it's the 'normal' use case
58
+ // for dependency-cruiser, so import it unconditionally nonetheless
59
+ import("./rule-set/normalize.mjs"),
60
+ import("./rule-set/validate.mjs"),
61
+ import("./files-and-dirs/normalize.mjs"),
62
+ import("./resolve-options/normalize.mjs"),
63
+ import("../extract/index.mjs"),
64
+ import("../enrich/index.mjs"),
65
+ ]);
66
+
67
+ if (Boolean(lCruiseOptions.ruleSet)) {
68
+ bus.emit("progress", "parsing rule set", c(4));
69
+ lCruiseOptions.ruleSet = normalizeRuleSet(
70
+ validateRuleSet(lCruiseOptions.ruleSet)
71
+ );
72
+ }
73
+
74
+ const lNormalizedFileAndDirectoryArray = normalizeFilesAndDirectories(
75
+ pFileAndDirectoryArray
76
+ );
77
+
78
+ bus.emit("progress", "determining how to resolve", c(5));
79
+ const lNormalizedResolveOptions = await normalizeResolveOptions(
80
+ pResolveOptions,
81
+ lCruiseOptions,
82
+ pTranspileOptions?.tsConfig
83
+ );
84
+
85
+ bus.emit("progress", "reading files", c(6));
86
+ const lExtractionResult = extract(
87
+ lNormalizedFileAndDirectoryArray,
88
+ lCruiseOptions,
89
+ lNormalizedResolveOptions,
90
+ pTranspileOptions
91
+ );
92
+
93
+ bus.emit("progress", "analyzing", c(7));
94
+ const lCruiseResult = enrich(
95
+ lExtractionResult,
96
+ lCruiseOptions,
97
+ lNormalizedFileAndDirectoryArray
98
+ );
99
+
100
+ if (lCruiseOptions.cache) {
101
+ bus.emit("progress", "cache: save", c(8));
102
+ lCache.write(lCruiseOptions.cache.folder, lCruiseResult);
103
+ }
104
+
105
+ bus.emit("progress", "reporting", c(9));
106
+ return await reportWrap(lCruiseResult, lCruiseOptions);
107
+ }
@@ -0,0 +1,26 @@
1
+ import Ajv from "ajv";
2
+
3
+ import cruiseResultSchema from "../schema/cruise-result.schema.mjs";
4
+ import { validateFormatOptions } from "./options/validate.mjs";
5
+ import { normalizeFormatOptions } from "./options/normalize.mjs";
6
+ import reportWrap from "./report-wrap.mjs";
7
+
8
+ function validateResultAgainstSchema(pResult) {
9
+ const ajv = new Ajv();
10
+
11
+ if (!ajv.validate(cruiseResultSchema, pResult)) {
12
+ throw new Error(
13
+ `The supplied dependency-cruiser result is not valid: ${ajv.errorsText()}.\n`
14
+ );
15
+ }
16
+ }
17
+ /** @type {import("../../types/dependency-cruiser.js").format} */
18
+ export default async function format(pResult, pFormatOptions = {}) {
19
+ const lFormatOptions = normalizeFormatOptions(pFormatOptions);
20
+ validateFormatOptions(lFormatOptions);
21
+
22
+ validateResultAgainstSchema(pResult);
23
+
24
+ // eslint-disable-next-line no-return-await
25
+ return await reportWrap(pResult, lFormatOptions);
26
+ }
@@ -1,134 +1,16 @@
1
- /* eslint-disable no-return-await */
2
- /* eslint-disable no-magic-numbers */
3
-
4
- import Ajv from "ajv";
5
-
6
- import extract from "../extract/index.mjs";
7
- import enrich from "../enrich/index.mjs";
8
- import cruiseResultSchema from "../schema/cruise-result.schema.mjs";
9
- import bus from "../utl/bus.mjs";
10
- import Cache from "../cache/cache.mjs";
11
1
  import {
12
2
  allExtensions,
13
3
  getAvailableTranspilers,
14
4
  } from "../extract/transpile/meta.mjs";
15
- import normalizeFilesAndDirectories from "./files-and-dirs/normalize.mjs";
16
- import validateRuleSet from "./rule-set/validate.mjs";
17
- import normalizeRuleSet from "./rule-set/normalize.mjs";
18
- import {
19
- validateCruiseOptions,
20
- validateFormatOptions,
21
- } from "./options/validate.mjs";
22
- import {
23
- normalizeCruiseOptions,
24
- normalizeFormatOptions,
25
- } from "./options/normalize.mjs";
26
- import normalizeResolveOptions from "./resolve-options/normalize.mjs";
27
- import reportWrap from "./report-wrap.mjs";
28
-
29
- const TOTAL_STEPS = 9;
30
-
31
- function c(pComplete, pTotal = TOTAL_STEPS) {
32
- return { complete: pComplete / pTotal };
33
- }
34
-
35
- function validateResultAgainstSchema(pResult) {
36
- const ajv = new Ajv();
37
-
38
- if (!ajv.validate(cruiseResultSchema, pResult)) {
39
- throw new Error(
40
- `The supplied dependency-cruiser result is not valid: ${ajv.errorsText()}.\n`
41
- );
42
- }
43
- }
44
- /** @type {import("../../types/dependency-cruiser.js").format} */
45
- export async function format(pResult, pFormatOptions = {}) {
46
- const lFormatOptions = normalizeFormatOptions(pFormatOptions);
47
- validateFormatOptions(lFormatOptions);
48
-
49
- validateResultAgainstSchema(pResult);
50
-
51
- return await reportWrap(pResult, lFormatOptions);
52
- }
53
-
54
- /** @type {import("../../types/dependency-cruiser.js").cruise} */
55
- // eslint-disable-next-line max-lines-per-function, max-statements
56
- export async function cruise(
57
- pFileAndDirectoryArray,
58
- pCruiseOptions,
59
- pResolveOptions,
60
- pTranspileOptions
61
- ) {
62
- bus.emit("progress", "parsing options", c(1));
63
- /** @type {import("../../types/strict-options.js").IStrictCruiseOptions} */
64
- let lCruiseOptions = normalizeCruiseOptions(
65
- validateCruiseOptions(pCruiseOptions),
66
- pFileAndDirectoryArray
67
- );
68
- let lCache = null;
69
-
70
- if (lCruiseOptions.cache) {
71
- bus.emit(
72
- "progress",
73
- `cache: check freshness with ${lCruiseOptions.cache.strategy}`,
74
- c(2)
75
- );
76
-
77
- lCache = new Cache(lCruiseOptions.cache.strategy);
78
- const lCachedResults = lCache.read(lCruiseOptions.cache.folder);
79
-
80
- if (lCache.canServeFromCache(lCruiseOptions, lCachedResults)) {
81
- bus.emit("progress", "cache: reporting from cache", c(8));
82
- return await reportWrap(lCachedResults, lCruiseOptions);
83
- }
84
- }
85
-
86
- if (Boolean(lCruiseOptions.ruleSet)) {
87
- bus.emit("progress", "parsing rule set", c(3));
88
- lCruiseOptions.ruleSet = normalizeRuleSet(
89
- validateRuleSet(lCruiseOptions.ruleSet)
90
- );
91
- }
92
-
93
- const lNormalizedFileAndDirectoryArray = normalizeFilesAndDirectories(
94
- pFileAndDirectoryArray
95
- );
96
-
97
- bus.emit("progress", "determining how to resolve", c(4));
98
- const lNormalizedResolveOptions = await normalizeResolveOptions(
99
- pResolveOptions,
100
- lCruiseOptions,
101
- pTranspileOptions?.tsConfig
102
- );
103
-
104
- bus.emit("progress", "reading files", c(5));
105
- const lExtractionResult = extract(
106
- lNormalizedFileAndDirectoryArray,
107
- lCruiseOptions,
108
- lNormalizedResolveOptions,
109
- pTranspileOptions
110
- );
111
-
112
- bus.emit("progress", "analyzing", c(6));
113
- const lCruiseResult = enrich(
114
- lExtractionResult,
115
- lCruiseOptions,
116
- lNormalizedFileAndDirectoryArray
117
- );
118
-
119
- if (lCruiseOptions.cache) {
120
- bus.emit("progress", "cache: save", c(7));
121
- lCache.write(lCruiseOptions.cache.folder, lCruiseResult);
122
- }
123
-
124
- bus.emit("progress", "reporting", c(8));
125
- return await reportWrap(lCruiseResult, lCruiseOptions);
126
- }
5
+ import format from "./format.mjs";
6
+ import cruise from "./cruise.mjs";
127
7
 
128
8
  export {
129
9
  allExtensions,
130
10
  getAvailableTranspilers,
131
11
  } from "../extract/transpile/meta.mjs";
12
+ export { default as cruise } from "./cruise.mjs";
13
+ export { default as format } from "./format.mjs";
132
14
 
133
15
  export default {
134
16
  cruise,
@@ -84,10 +84,9 @@ async function compileResolveOptions(
84
84
  // Also: requiring the plugin only when it's necessary will save some
85
85
  // startup time (especially on a cold require cache)
86
86
  if (pResolveOptions.tsConfig && isTsConfigPathsEligible(pTSConfig)) {
87
- const TsConfigPathsPluginModule = await import(
87
+ const { default: TsConfigPathsPlugin } = await import(
88
88
  "tsconfig-paths-webpack-plugin"
89
89
  );
90
- const TsConfigPathsPlugin = TsConfigPathsPluginModule.default;
91
90
  lResolveOptions.plugins = pushPlugin(
92
91
  lResolveOptions.plugins,
93
92
  // @ts-expect-error TS2351 "TsConfPathsPlugin is not constructable" - is unjustified
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.0-beta-3",
4
+ version: "13.0.0-beta-5",
5
5
  engines: {
6
6
  node: "^16.14||>=18",
7
7
  },
@@ -127,6 +127,10 @@ export default {
127
127
  criteria: { "rules[0].severity": "info" },
128
128
  attributes: { fontcolor: "blue", color: "blue" },
129
129
  },
130
+ {
131
+ criteria: { dynamic: true },
132
+ attributes: { style: "dashed" },
133
+ },
130
134
  {
131
135
  criteria: { valid: false },
132
136
  attributes: { fontcolor: "red", color: "red" },
@@ -0,0 +1,3 @@
1
+ import dotBase from "./index.mjs";
2
+
3
+ export default dotBase("custom");
@@ -0,0 +1,3 @@
1
+ import dotBase from "./index.mjs";
2
+
3
+ export default dotBase("flat");
@@ -0,0 +1,3 @@
1
+ import dotBase from "./index.mjs";
2
+
3
+ export default dotBase("folder");
@@ -0,0 +1,3 @@
1
+ import dotBase from "./index.mjs";
2
+
3
+ export default dotBase("module");
@@ -1,45 +1,26 @@
1
- import anon from "./anon/index.mjs";
2
- import csv from "./csv.mjs";
3
- import dotBase from "./dot/index.mjs";
4
- import errorHtml from "./error-html/index.mjs";
5
- import error from "./error.mjs";
6
- import errorLong from "./error-long.mjs";
7
- import html from "./html/index.mjs";
8
- import identity from "./identity.mjs";
9
- import json from "./json.mjs";
10
- import teamcity from "./teamcity.mjs";
11
- import text from "./text.mjs";
12
- import baseline from "./baseline.mjs";
13
- import metrics from "./metrics.mjs";
14
1
  import { getExternalPluginReporter } from "./plugins.mjs";
15
- import markdown from "./markdown.mjs";
16
- import mermaid from "./mermaid.mjs";
17
2
 
18
- const dot = dotBase("module");
19
- const ddot = dotBase("folder");
20
- const cdot = dotBase("custom");
21
- const fdot = dotBase("flat");
22
-
23
- const TYPE2REPORTER = {
24
- anon,
25
- csv,
26
- dot,
27
- ddot,
28
- cdot,
29
- archi: cdot,
30
- fdot,
31
- flat: fdot,
32
- "err-html": errorHtml,
33
- markdown,
34
- "err-long": errorLong,
35
- err: error,
36
- html,
37
- json,
38
- teamcity,
39
- text,
40
- baseline,
41
- metrics,
42
- mermaid,
3
+ const TYPE2MODULE = {
4
+ anon: "./anon/index.mjs",
5
+ csv: "./csv.mjs",
6
+ dot: "./dot/dot-module.mjs",
7
+ ddot: "./dot/dot-folder.mjs",
8
+ cdot: "./dot/dot-custom.mjs",
9
+ archi: "./dot/dot-custom.mjs",
10
+ fdot: "./dot/dot-flat.mjs",
11
+ flat: "./dot/dot-flat.mjs",
12
+ "err-html": "./error-html/index.mjs",
13
+ markdown: "./markdown.mjs",
14
+ "err-long": "./error-long.mjs",
15
+ err: "./error.mjs",
16
+ html: "./html/index.mjs",
17
+ json: "./json.mjs",
18
+ teamcity: "./teamcity.mjs",
19
+ text: "./text.mjs",
20
+ baseline: "./baseline.mjs",
21
+ metrics: "./metrics.mjs",
22
+ mermaid: "./mermaid.mjs",
23
+ null: "./null.mjs",
43
24
  };
44
25
 
45
26
  /**
@@ -52,12 +33,17 @@ const TYPE2REPORTER = {
52
33
  * and returns an IReporterOutput
53
34
  */
54
35
  async function getReporter(pOutputType) {
55
- return (
56
- // eslint-disable-next-line security/detect-object-injection
57
- TYPE2REPORTER[pOutputType] ||
58
- (await getExternalPluginReporter(pOutputType)) ||
59
- identity
60
- );
36
+ let lReturnValue = {};
37
+ if (pOutputType?.startsWith("plugin:")) {
38
+ lReturnValue = await getExternalPluginReporter(pOutputType);
39
+ } else {
40
+ const lModuleToImport =
41
+ // eslint-disable-next-line security/detect-object-injection
42
+ TYPE2MODULE[pOutputType] || "./identity.mjs";
43
+ const lModule = await import(lModuleToImport);
44
+ lReturnValue = lModule.default;
45
+ }
46
+ return lReturnValue;
61
47
  }
62
48
 
63
49
  /**
@@ -66,7 +52,7 @@ async function getReporter(pOutputType) {
66
52
  * @returns {import("../../types/shared-types.js").OutputType[]} -
67
53
  */
68
54
  function getAvailableReporters() {
69
- return Object.keys(TYPE2REPORTER);
55
+ return Object.keys(TYPE2MODULE);
70
56
  }
71
57
 
72
58
  export default {
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Returns the results of a cruise in JSON
3
+ *
4
+ * @param {import("../../types/cruise-result").ICruiseResult} pResults
5
+ * @returns {import("../../types/dependency-cruiser").IReporterOutput}
6
+ */
7
+ export default function nullReporter(pResults) {
8
+ return {
9
+ output: "",
10
+ exitCode: pResults.summary.error,
11
+ };
12
+ }