dependency-cruiser 13.0.0-beta-4 → 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 +26 -0
- package/package.json +1 -1
- package/src/cli/format.mjs +1 -1
- package/src/cli/index.mjs +24 -18
- package/src/cli/listeners/performance-log/index.mjs +13 -2
- package/src/cli/tools/wrap-stream-in-html.mjs +8 -5
- package/src/config-utl/extract-babel-config.mjs +5 -5
- package/src/config-utl/extract-depcruise-config/read-config.mjs +6 -4
- package/src/config-utl/extract-known-violations.mjs +3 -3
- package/src/config-utl/extract-webpack-resolve-config.mjs +4 -2
- package/src/enrich/enrich-modules.mjs +1 -1
- package/src/extract/transpile/meta.d.ts +6 -7
- package/src/main/cruise.mjs +107 -0
- package/src/main/format.mjs +26 -0
- package/src/main/index.mjs +4 -123
- package/src/main/resolve-options/normalize.mjs +1 -2
- package/src/meta.js +1 -1
- package/src/report/dot/default-theme.mjs +4 -0
- package/src/report/index.mjs +1 -0
- package/src/report/null.mjs +12 -0
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
|

|
package/package.json
CHANGED
package/src/cli/format.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import getStream from "get-stream";
|
|
2
|
-
import
|
|
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,7 +6,7 @@ import set from "lodash/set.js";
|
|
|
6
6
|
import isInstalledGlobally from "is-installed-globally";
|
|
7
7
|
import chalk from "chalk";
|
|
8
8
|
|
|
9
|
-
import
|
|
9
|
+
import cruise from "../main/cruise.mjs";
|
|
10
10
|
import bus from "../utl/bus.mjs";
|
|
11
11
|
|
|
12
12
|
import busLogLevels from "../utl/bus-log-levels.mjs";
|
|
@@ -23,10 +23,10 @@ async function extractResolveOptions(pCruiseOptions) {
|
|
|
23
23
|
pCruiseOptions?.ruleSet?.options?.webpackConfig?.fileName ?? null;
|
|
24
24
|
|
|
25
25
|
if (lWebPackConfigFileName) {
|
|
26
|
-
const extractWebpackResolveConfig = await import(
|
|
26
|
+
const { default: extractWebpackResolveConfig } = await import(
|
|
27
27
|
"../config-utl/extract-webpack-resolve-config.mjs"
|
|
28
28
|
);
|
|
29
|
-
lResolveOptions = await extractWebpackResolveConfig
|
|
29
|
+
lResolveOptions = await extractWebpackResolveConfig(
|
|
30
30
|
lWebPackConfigFileName,
|
|
31
31
|
pCruiseOptions?.ruleSet?.options?.webpackConfig?.env ?? null,
|
|
32
32
|
pCruiseOptions?.ruleSet?.options?.webpackConfig?.arguments ?? null
|
|
@@ -37,10 +37,10 @@ async function extractResolveOptions(pCruiseOptions) {
|
|
|
37
37
|
|
|
38
38
|
async function addKnownViolations(pCruiseOptions) {
|
|
39
39
|
if (pCruiseOptions.knownViolationsFile) {
|
|
40
|
-
const extractKnownViolations = await import(
|
|
40
|
+
const { default: extractKnownViolations } = await import(
|
|
41
41
|
"../config-utl/extract-known-violations.mjs"
|
|
42
42
|
);
|
|
43
|
-
const lKnownViolations = extractKnownViolations
|
|
43
|
+
const lKnownViolations = await extractKnownViolations(
|
|
44
44
|
pCruiseOptions.knownViolationsFile
|
|
45
45
|
);
|
|
46
46
|
|
|
@@ -59,8 +59,10 @@ async function extractTSConfigOptions(pCruiseOptions) {
|
|
|
59
59
|
pCruiseOptions?.ruleSet?.options?.tsConfig?.fileName ?? null;
|
|
60
60
|
|
|
61
61
|
if (lTSConfigFileName) {
|
|
62
|
-
const extractTSConfig = await import(
|
|
63
|
-
|
|
62
|
+
const { default: extractTSConfig } = await import(
|
|
63
|
+
"../config-utl/extract-ts-config.mjs"
|
|
64
|
+
);
|
|
65
|
+
lReturnValue = extractTSConfig(lTSConfigFileName);
|
|
64
66
|
}
|
|
65
67
|
|
|
66
68
|
return lReturnValue;
|
|
@@ -71,10 +73,10 @@ async function extractBabelConfigOptions(pCruiseOptions) {
|
|
|
71
73
|
const lBabelConfigFileName =
|
|
72
74
|
pCruiseOptions?.ruleSet?.options?.babelConfig?.fileName ?? null;
|
|
73
75
|
if (lBabelConfigFileName) {
|
|
74
|
-
const extractBabelConfig = await import(
|
|
76
|
+
const { default: extractBabelConfig } = await import(
|
|
75
77
|
"../config-utl/extract-babel-config.mjs"
|
|
76
78
|
);
|
|
77
|
-
lReturnValue = extractBabelConfig
|
|
79
|
+
lReturnValue = extractBabelConfig(lBabelConfigFileName);
|
|
78
80
|
}
|
|
79
81
|
|
|
80
82
|
return lReturnValue;
|
|
@@ -118,14 +120,16 @@ async function runCruise(pFileDirectoryArray, pCruiseOptions) {
|
|
|
118
120
|
setUpListener(lCruiseOptions);
|
|
119
121
|
|
|
120
122
|
bus.emit("start");
|
|
123
|
+
const [lResolveOptions, tsConfig, babelConfig] = await Promise.all([
|
|
124
|
+
extractResolveOptions(lCruiseOptions),
|
|
125
|
+
extractTSConfigOptions(lCruiseOptions),
|
|
126
|
+
extractBabelConfigOptions(lCruiseOptions),
|
|
127
|
+
]);
|
|
121
128
|
const lReportingResult = await cruise(
|
|
122
129
|
pFileDirectoryArray,
|
|
123
130
|
lCruiseOptions,
|
|
124
|
-
|
|
125
|
-
{
|
|
126
|
-
tsConfig: await extractTSConfigOptions(lCruiseOptions),
|
|
127
|
-
babelConfig: await extractBabelConfigOptions(lCruiseOptions),
|
|
128
|
-
}
|
|
131
|
+
lResolveOptions,
|
|
132
|
+
{ tsConfig, babelConfig }
|
|
129
133
|
);
|
|
130
134
|
|
|
131
135
|
bus.emit("progress", "cli: writing results", { complete: 1 });
|
|
@@ -162,11 +166,13 @@ export default async function executeCli(pFileDirectoryArray, pCruiseOptions) {
|
|
|
162
166
|
}
|
|
163
167
|
/* c8 ignore stop */
|
|
164
168
|
if (lCruiseOptions.info === true) {
|
|
165
|
-
const formatMetaInfo = await import(
|
|
166
|
-
|
|
169
|
+
const { default: formatMetaInfo } = await import(
|
|
170
|
+
"./format-meta-info.mjs"
|
|
171
|
+
);
|
|
172
|
+
process.stdout.write(await formatMetaInfo());
|
|
167
173
|
} else if (lCruiseOptions.init) {
|
|
168
|
-
const initConfig = await import("./init-config/index.mjs");
|
|
169
|
-
initConfig
|
|
174
|
+
const { default: initConfig } = await import("./init-config/index.mjs");
|
|
175
|
+
initConfig(lCruiseOptions.init);
|
|
170
176
|
} else {
|
|
171
177
|
lExitCode = await runCruise(pFileDirectoryArray, lCruiseOptions);
|
|
172
178
|
}
|
|
@@ -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
|
-
|
|
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 {
|
|
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 =
|
|
30
|
-
|
|
31
|
-
|
|
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 {
|
|
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
|
|
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(
|
|
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 {
|
|
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
|
|
10
|
-
|
|
9
|
+
const { default: config } = await import(
|
|
10
|
+
`file://${pAbsolutePathToConfigFile}`
|
|
11
|
+
);
|
|
12
|
+
return config;
|
|
11
13
|
}
|
|
12
|
-
return json5.parse(
|
|
14
|
+
return json5.parse(await readFile(pAbsolutePathToConfigFile, "utf8"));
|
|
13
15
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
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
|
-
|
|
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(
|
|
82
|
-
|
|
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
|
|
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:
|
|
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
|
+
}
|
package/src/main/index.mjs
CHANGED
|
@@ -1,135 +1,16 @@
|
|
|
1
|
-
/* eslint-disable no-return-await */
|
|
2
|
-
/* eslint-disable no-magic-numbers */
|
|
3
|
-
|
|
4
|
-
import Ajv from "ajv";
|
|
5
|
-
|
|
6
|
-
import cruiseResultSchema from "../schema/cruise-result.schema.mjs";
|
|
7
|
-
import bus from "../utl/bus.mjs";
|
|
8
1
|
import {
|
|
9
2
|
allExtensions,
|
|
10
3
|
getAvailableTranspilers,
|
|
11
4
|
} from "../extract/transpile/meta.mjs";
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import {
|
|
15
|
-
validateCruiseOptions,
|
|
16
|
-
validateFormatOptions,
|
|
17
|
-
} from "./options/validate.mjs";
|
|
18
|
-
import {
|
|
19
|
-
normalizeCruiseOptions,
|
|
20
|
-
normalizeFormatOptions,
|
|
21
|
-
} from "./options/normalize.mjs";
|
|
22
|
-
import reportWrap from "./report-wrap.mjs";
|
|
23
|
-
|
|
24
|
-
const TOTAL_STEPS = 9;
|
|
25
|
-
|
|
26
|
-
function c(pComplete, pTotal = TOTAL_STEPS) {
|
|
27
|
-
return { complete: pComplete / pTotal };
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function validateResultAgainstSchema(pResult) {
|
|
31
|
-
const ajv = new Ajv();
|
|
32
|
-
|
|
33
|
-
if (!ajv.validate(cruiseResultSchema, pResult)) {
|
|
34
|
-
throw new Error(
|
|
35
|
-
`The supplied dependency-cruiser result is not valid: ${ajv.errorsText()}.\n`
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
/** @type {import("../../types/dependency-cruiser.js").format} */
|
|
40
|
-
export async function format(pResult, pFormatOptions = {}) {
|
|
41
|
-
const lFormatOptions = normalizeFormatOptions(pFormatOptions);
|
|
42
|
-
validateFormatOptions(lFormatOptions);
|
|
43
|
-
|
|
44
|
-
validateResultAgainstSchema(pResult);
|
|
45
|
-
|
|
46
|
-
return await reportWrap(pResult, lFormatOptions);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/** @type {import("../../types/dependency-cruiser.js").cruise} */
|
|
50
|
-
// eslint-disable-next-line max-lines-per-function, max-statements
|
|
51
|
-
export async function cruise(
|
|
52
|
-
pFileAndDirectoryArray,
|
|
53
|
-
pCruiseOptions,
|
|
54
|
-
pResolveOptions,
|
|
55
|
-
pTranspileOptions
|
|
56
|
-
) {
|
|
57
|
-
bus.emit("progress", "parsing options", c(1));
|
|
58
|
-
/** @type {import("../../types/strict-options.js").IStrictCruiseOptions} */
|
|
59
|
-
let lCruiseOptions = normalizeCruiseOptions(
|
|
60
|
-
validateCruiseOptions(pCruiseOptions),
|
|
61
|
-
pFileAndDirectoryArray
|
|
62
|
-
);
|
|
63
|
-
let lCache = null;
|
|
64
|
-
|
|
65
|
-
if (lCruiseOptions.cache) {
|
|
66
|
-
bus.emit(
|
|
67
|
-
"progress",
|
|
68
|
-
`cache: check freshness with ${lCruiseOptions.cache.strategy}`,
|
|
69
|
-
c(2)
|
|
70
|
-
);
|
|
71
|
-
|
|
72
|
-
const CacheModule = await import("../cache/cache.mjs");
|
|
73
|
-
const Cache = CacheModule.default;
|
|
74
|
-
lCache = new Cache(lCruiseOptions.cache.strategy);
|
|
75
|
-
const lCachedResults = lCache.read(lCruiseOptions.cache.folder);
|
|
76
|
-
|
|
77
|
-
if (lCache.canServeFromCache(lCruiseOptions, lCachedResults)) {
|
|
78
|
-
bus.emit("progress", "cache: reporting from cache", c(8));
|
|
79
|
-
return await reportWrap(lCachedResults, lCruiseOptions);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
if (Boolean(lCruiseOptions.ruleSet)) {
|
|
84
|
-
bus.emit("progress", "parsing rule set", c(3));
|
|
85
|
-
const normalizeRuleSet = await import("./rule-set/normalize.mjs");
|
|
86
|
-
lCruiseOptions.ruleSet = normalizeRuleSet.default(
|
|
87
|
-
validateRuleSet(lCruiseOptions.ruleSet)
|
|
88
|
-
);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
const lNormalizedFileAndDirectoryArray = normalizeFilesAndDirectories(
|
|
92
|
-
pFileAndDirectoryArray
|
|
93
|
-
);
|
|
94
|
-
|
|
95
|
-
bus.emit("progress", "determining how to resolve", c(4));
|
|
96
|
-
let normalizeResolveOptions = await import("./resolve-options/normalize.mjs");
|
|
97
|
-
const lNormalizedResolveOptions = await normalizeResolveOptions.default(
|
|
98
|
-
pResolveOptions,
|
|
99
|
-
lCruiseOptions,
|
|
100
|
-
pTranspileOptions?.tsConfig
|
|
101
|
-
);
|
|
102
|
-
|
|
103
|
-
bus.emit("progress", "reading files", c(5));
|
|
104
|
-
const extract = await import("../extract/index.mjs");
|
|
105
|
-
const lExtractionResult = extract.default(
|
|
106
|
-
lNormalizedFileAndDirectoryArray,
|
|
107
|
-
lCruiseOptions,
|
|
108
|
-
lNormalizedResolveOptions,
|
|
109
|
-
pTranspileOptions
|
|
110
|
-
);
|
|
111
|
-
|
|
112
|
-
bus.emit("progress", "analyzing", c(6));
|
|
113
|
-
const enrich = await import("../enrich/index.mjs");
|
|
114
|
-
const lCruiseResult = enrich.default(
|
|
115
|
-
lExtractionResult,
|
|
116
|
-
lCruiseOptions,
|
|
117
|
-
lNormalizedFileAndDirectoryArray
|
|
118
|
-
);
|
|
119
|
-
|
|
120
|
-
if (lCruiseOptions.cache) {
|
|
121
|
-
bus.emit("progress", "cache: save", c(7));
|
|
122
|
-
lCache.write(lCruiseOptions.cache.folder, lCruiseResult);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
bus.emit("progress", "reporting", c(8));
|
|
126
|
-
return await reportWrap(lCruiseResult, lCruiseOptions);
|
|
127
|
-
}
|
|
5
|
+
import format from "./format.mjs";
|
|
6
|
+
import cruise from "./cruise.mjs";
|
|
128
7
|
|
|
129
8
|
export {
|
|
130
9
|
allExtensions,
|
|
131
10
|
getAvailableTranspilers,
|
|
132
11
|
} from "../extract/transpile/meta.mjs";
|
|
12
|
+
export { default as cruise } from "./cruise.mjs";
|
|
13
|
+
export { default as format } from "./format.mjs";
|
|
133
14
|
|
|
134
15
|
export default {
|
|
135
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
|
|
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
|
@@ -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" },
|
package/src/report/index.mjs
CHANGED
|
@@ -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
|
+
}
|