dependency-cruiser 18.6.0 → 18.7.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/README.md +0 -1
- package/configs/rules/no-duplicate-dependency-types.cjs +1 -1
- package/package.json +2 -2
- package/src/analyze/index.mjs +2 -2
- package/src/analyze/summarize/index.mjs +1 -102
- package/src/analyze/summarize/verify-environment.mjs +146 -0
- package/src/cli/defaults.mjs +0 -1
- package/src/cli/init-config/config-template.mjs +1 -1
- package/src/config-utl/extract-ts-config.mjs +1 -1
- package/src/extract/resolve/determine-dependency-types.mjs +3 -1
- package/src/extract/swc/dependency-visitor.mjs +4 -2
- package/src/extract/swc/parse.mjs +1 -1
- package/src/extract/transpile/index.mjs +1 -1
- package/src/extract/transpile/meta.mjs +13 -1
- package/src/extract/transpile/typescript-wrap.mjs +23 -1
- package/src/graph-utl/add-focus.mjs +2 -2
- package/src/main/cruise.mjs +1 -2
- package/src/main/format.mjs +1 -1
- package/src/main/resolve-options/normalize.mjs +0 -27
- package/src/meta.cjs +1 -1
- package/src/report/anon/index.mjs +1 -1
- package/src/report/azure-devops.mjs +9 -9
- package/src/report/csv.mjs +1 -1
- package/src/report/dot/index.mjs +1 -1
- package/src/report/error.mjs +1 -1
- package/src/report/html/index.mjs +1 -1
- package/src/report/index.mjs +2 -2
- package/src/report/metrics.mjs +3 -3
package/README.md
CHANGED
|
@@ -193,7 +193,6 @@ You've come to the right place :-) :
|
|
|
193
193
|
## Build status
|
|
194
194
|
|
|
195
195
|
[](https://github.com/sverweij/dependency-cruiser/actions/workflows/ci.yml)
|
|
196
|
-
[](https://gitlab.com/sverweij/dependency-cruiser/builds)
|
|
197
196
|
[](https://npmjs.com/package/dependency-cruiser)
|
|
198
197
|
|
|
199
198
|
Made with :metal: in Holland.
|
|
@@ -2,7 +2,7 @@ module.exports = {
|
|
|
2
2
|
name: "no-duplicate-dep-types",
|
|
3
3
|
comment:
|
|
4
4
|
"Likely this module depends on an external ('npm') package that occurs more " +
|
|
5
|
-
"than once in your package.json i.e.
|
|
5
|
+
"than once in your package.json i.e. both as a devDependencies and in dependencies. " +
|
|
6
6
|
"This will cause maintenance problems later on. If it's intentional, you can " +
|
|
7
7
|
"disable this rule by adding this override as a rule in the 'forbidden' section " +
|
|
8
8
|
"of your dependency-cruiser configuration: " +
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dependency-cruiser",
|
|
3
|
-
"version": "18.
|
|
3
|
+
"version": "18.7.1",
|
|
4
4
|
"description": "Validate and visualize dependencies. With your rules. JavaScript, TypeScript, CoffeeScript. ES6, CommonJS, AMD.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"static analysis",
|
|
@@ -150,7 +150,7 @@
|
|
|
150
150
|
"acorn-walk": "8.3.5",
|
|
151
151
|
"commander": "15.0.0",
|
|
152
152
|
"enhanced-resolve": "5.26.0",
|
|
153
|
-
"ignore": "7.0.
|
|
153
|
+
"ignore": "7.0.14",
|
|
154
154
|
"interpret": "3.1.1",
|
|
155
155
|
"is-installed-globally": "1.0.1",
|
|
156
156
|
"json5": "2.2.3",
|
package/src/analyze/index.mjs
CHANGED
|
@@ -11,10 +11,10 @@ import { bus } from "#utl/bus.mjs";
|
|
|
11
11
|
* used in the cruise, so consumers of the cruise result (reporters, depcruise-fmt,
|
|
12
12
|
* caching) can use that.
|
|
13
13
|
*
|
|
14
|
-
* @param {import("../../types/dependency-cruiser.
|
|
14
|
+
* @param {import("../../types/dependency-cruiser.mjs").IModule[]} pModules
|
|
15
15
|
* @param {import("../../types/options.mjs").ICruiseOptions} pOptions
|
|
16
16
|
* @param {string[]} pFileAndDirectoryArray
|
|
17
|
-
* @returns {import("../../types/dependency-cruiser.
|
|
17
|
+
* @returns {import("../../types/dependency-cruiser.mjs").ICruiseResult}
|
|
18
18
|
*/
|
|
19
19
|
export default function analyze(pModules, pOptions, pFileAndDirectoryArray) {
|
|
20
20
|
const lModules = analyzeModules(pModules, pOptions);
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { EOL } from "node:os";
|
|
2
1
|
import addRuleSetUsed from "./add-rule-set-used.mjs";
|
|
3
2
|
import summarizeModules from "./summarize-modules.mjs";
|
|
4
3
|
import summarizeFolders from "./summarize-folders.mjs";
|
|
@@ -11,6 +10,7 @@ import {
|
|
|
11
10
|
} from "./get-stats.mjs";
|
|
12
11
|
import { compareViolations } from "#graph-utl/compare.mjs";
|
|
13
12
|
import { getEnvironmentInfo } from "#environment.mjs";
|
|
13
|
+
import { determineEnvironmentIssues } from "./verify-environment.mjs";
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* @import { IOptions, IEnvironmentIssue, ISummary, IModule, IFolder } from "../../../types/cruise-result.mjs"
|
|
@@ -18,107 +18,6 @@ import { getEnvironmentInfo } from "#environment.mjs";
|
|
|
18
18
|
* @import { IStrictCruiseOptions } from "../../../types/strict-options.mjs"
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
|
-
/**
|
|
22
|
-
* @param { IOptions } pOptions
|
|
23
|
-
* @param { IAvailableTranspiler[] } pAvailableTranspilers
|
|
24
|
-
* @returns { boolean }
|
|
25
|
-
*/
|
|
26
|
-
function swcIsConsistent(pOptions, pAvailableTranspilers) {
|
|
27
|
-
const lSWCNeeded = (pOptions?.parser ?? "acorn") === "swc";
|
|
28
|
-
return lSWCNeeded
|
|
29
|
-
? pAvailableTranspilers.some(
|
|
30
|
-
(pTranspiler) => pTranspiler.name === "swc" && pTranspiler.available,
|
|
31
|
-
)
|
|
32
|
-
: true;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* @param { IOptions } pOptions
|
|
37
|
-
* @param { IAvailableTranspiler[] } pAvailableTranspilers
|
|
38
|
-
* @returns { boolean }
|
|
39
|
-
*/
|
|
40
|
-
function typescriptIsConsistent(pOptions, pAvailableTranspilers) {
|
|
41
|
-
const lTypeScriptNeeded =
|
|
42
|
-
Boolean(pOptions?.tsConfig) ||
|
|
43
|
-
Boolean(pOptions?.tsPreCompilationDeps) ||
|
|
44
|
-
Boolean(pOptions?.detectJSDocImports) ||
|
|
45
|
-
(pOptions?.parser ?? "acorn") === "tsc";
|
|
46
|
-
return lTypeScriptNeeded
|
|
47
|
-
? pAvailableTranspilers.some(
|
|
48
|
-
(pTranspiler) =>
|
|
49
|
-
pTranspiler.name === "typescript" && pTranspiler.available,
|
|
50
|
-
)
|
|
51
|
-
: true;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* @param { IOptions } pOptions
|
|
55
|
-
* @param { IAvailableTranspiler[] } pAvailableTranspilers
|
|
56
|
-
* @returns { boolean }
|
|
57
|
-
*/
|
|
58
|
-
function babelIsConsistent(pOptions, pAvailableTranspilers) {
|
|
59
|
-
return Boolean(pOptions?.babelConfig)
|
|
60
|
-
? pAvailableTranspilers.some(
|
|
61
|
-
(pTranspiler) => pTranspiler.name === "babel" && pTranspiler.available,
|
|
62
|
-
)
|
|
63
|
-
: true;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* @param {IOptions} pOptions
|
|
68
|
-
* @param {IAvailableTranspiler[]} pAvailableTranspilers
|
|
69
|
-
* @returns {{issues?: IEnvironmentIssue[]}}
|
|
70
|
-
*/
|
|
71
|
-
function determineEnvironmentIssues(pOptions, pAvailableTranspilers) {
|
|
72
|
-
const lIssues = [];
|
|
73
|
-
if (!typescriptIsConsistent(pOptions, pAvailableTranspilers)) {
|
|
74
|
-
const tsTranspiler = pAvailableTranspilers.find(
|
|
75
|
-
(pTranspiler) => pTranspiler.name === "typescript",
|
|
76
|
-
);
|
|
77
|
-
|
|
78
|
-
lIssues.push({
|
|
79
|
-
severity: "warn",
|
|
80
|
-
name: "missing-typescript-transpiler",
|
|
81
|
-
description:
|
|
82
|
-
`dependency-cruiser detected a TypeScript environment,${EOL}` +
|
|
83
|
-
` but not a compatible TypeScript compiler (${tsTranspiler.name}: ${tsTranspiler.version}). This means${EOL}` +
|
|
84
|
-
` it's likely to have missed TypeScript sources and dependencies.${EOL}${EOL}` +
|
|
85
|
-
` Install typescript to get better results (e.g. npm i -D typescript@^6).${EOL}${EOL}` +
|
|
86
|
-
` => Support for typescript@>=7 will follow when its API is published and stable.${EOL}`,
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
if (!swcIsConsistent(pOptions, pAvailableTranspilers)) {
|
|
90
|
-
const swcTranspiler = pAvailableTranspilers.find(
|
|
91
|
-
(pTranspiler) => pTranspiler.name === "swc",
|
|
92
|
-
);
|
|
93
|
-
|
|
94
|
-
lIssues.push({
|
|
95
|
-
severity: "warn",
|
|
96
|
-
name: "missing-swc-transpiler",
|
|
97
|
-
description:
|
|
98
|
-
`dependency-cruiser found swc configured as parser, but ${EOL}` +
|
|
99
|
-
` it did not find a compatible version of swc (${swcTranspiler.name}: ${swcTranspiler.version}).${EOL}` +
|
|
100
|
-
` dependency-cruiser might have missed some sources or dependencies.${EOL}${EOL}` +
|
|
101
|
-
` Install swc (e.g. npm i -D @swc/core) to get better results.${EOL}`,
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
if (!babelIsConsistent(pOptions, pAvailableTranspilers)) {
|
|
105
|
-
const babelTranspiler = pAvailableTranspilers.find(
|
|
106
|
-
(pTranspiler) => pTranspiler.name === "babel",
|
|
107
|
-
);
|
|
108
|
-
|
|
109
|
-
lIssues.push({
|
|
110
|
-
severity: "warn",
|
|
111
|
-
name: "missing-babel-transpiler",
|
|
112
|
-
description:
|
|
113
|
-
`dependency-cruiser detected a babel configuration, but not a${EOL}` +
|
|
114
|
-
` compatible babel transpiler (${babelTranspiler.name}: ${babelTranspiler.version}). If you indeed use babel,${EOL}` +
|
|
115
|
-
` dependency-cruiser might have missed some sources or dependencies.${EOL}${EOL}` +
|
|
116
|
-
` Install babel (e.g. npm i -D @babel/core@^7) to get better results.${EOL}`,
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
return lIssues.length > 0 ? { issues: lIssues } : {};
|
|
120
|
-
}
|
|
121
|
-
|
|
122
21
|
function getAdvisedExitCode(
|
|
123
22
|
pErrorCount,
|
|
124
23
|
pBaselineStaleCount,
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { EOL } from "node:os";
|
|
2
|
+
/**
|
|
3
|
+
* @import { IOptions, IEnvironmentIssue } from "../../../types/cruise-result.mjs"
|
|
4
|
+
* @import { IAvailableTranspiler } from "../../../types/environment.mjs"
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @param { IOptions } pOptions
|
|
9
|
+
* @param { IAvailableTranspiler[] } pAvailableTranspilers
|
|
10
|
+
* @returns { boolean }
|
|
11
|
+
*/
|
|
12
|
+
function swcIsConsistent(pOptions, pAvailableTranspilers) {
|
|
13
|
+
const lSWCNeeded = (pOptions?.parser ?? "acorn") === "swc";
|
|
14
|
+
return lSWCNeeded
|
|
15
|
+
? pAvailableTranspilers.some(
|
|
16
|
+
(pTranspiler) => pTranspiler.name === "swc" && pTranspiler.available,
|
|
17
|
+
)
|
|
18
|
+
: true;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @param { IOptions } pOptions
|
|
23
|
+
* @param { IAvailableTranspiler[] } pAvailableTranspilers
|
|
24
|
+
* @returns { boolean }
|
|
25
|
+
*/
|
|
26
|
+
function tscIsConsistent(pOptions, pAvailableTranspilers) {
|
|
27
|
+
const lTSCNeeded =
|
|
28
|
+
Boolean(pOptions?.tsPreCompilationDeps) ||
|
|
29
|
+
Boolean(pOptions?.detectJSDocImports) ||
|
|
30
|
+
(pOptions?.parser ?? "acorn") === "tsc";
|
|
31
|
+
return lTSCNeeded
|
|
32
|
+
? pAvailableTranspilers.some(
|
|
33
|
+
(pTranspiler) =>
|
|
34
|
+
pTranspiler.name === "typescript" && pTranspiler.available,
|
|
35
|
+
)
|
|
36
|
+
: true;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function typeScriptIsConsistent(pOptions, pAvailableTranspilers) {
|
|
40
|
+
const lTypeScriptNeeded =
|
|
41
|
+
Boolean(pOptions?.tsConfig) &&
|
|
42
|
+
!(
|
|
43
|
+
// these two options require tsc (covered in tscIsConsistent), so
|
|
44
|
+
// to prevent typeScriptIsConsistent from also firing (and printing
|
|
45
|
+
// two messages) we exclude them here
|
|
46
|
+
Boolean(pOptions?.tsPreCompilationDeps) ||
|
|
47
|
+
Boolean(pOptions?.detectJSDocImports)
|
|
48
|
+
);
|
|
49
|
+
return lTypeScriptNeeded
|
|
50
|
+
? pAvailableTranspilers.some(
|
|
51
|
+
(pTranspiler) =>
|
|
52
|
+
(pTranspiler.name === "typescript" ||
|
|
53
|
+
(pTranspiler.name === "swc" && pOptions?.parser === "swc")) &&
|
|
54
|
+
pTranspiler.available,
|
|
55
|
+
)
|
|
56
|
+
: true;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* @param { IOptions } pOptions
|
|
61
|
+
* @param { IAvailableTranspiler[] } pAvailableTranspilers
|
|
62
|
+
* @returns { boolean }
|
|
63
|
+
*/
|
|
64
|
+
function babelIsConsistent(pOptions, pAvailableTranspilers) {
|
|
65
|
+
return Boolean(pOptions?.babelConfig)
|
|
66
|
+
? pAvailableTranspilers.some(
|
|
67
|
+
(pTranspiler) => pTranspiler.name === "babel" && pTranspiler.available,
|
|
68
|
+
)
|
|
69
|
+
: true;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* @param {IOptions} pOptions
|
|
74
|
+
* @param {IAvailableTranspiler[]} pAvailableTranspilers
|
|
75
|
+
* @returns {{issues?: IEnvironmentIssue[]}}
|
|
76
|
+
*/
|
|
77
|
+
export function determineEnvironmentIssues(pOptions, pAvailableTranspilers) {
|
|
78
|
+
const lIssues = [];
|
|
79
|
+
if (!tscIsConsistent(pOptions, pAvailableTranspilers)) {
|
|
80
|
+
const tsTranspiler = pAvailableTranspilers.find(
|
|
81
|
+
(pTranspiler) => pTranspiler.name === "typescript",
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
lIssues.push({
|
|
85
|
+
severity: "warn",
|
|
86
|
+
name: "missing-tsc-transpiler",
|
|
87
|
+
description:
|
|
88
|
+
`dependency-cruiser detected a TypeScript environment,${EOL}` +
|
|
89
|
+
` but not a compatible TypeScript compiler (${tsTranspiler.name}: ${tsTranspiler.version}). This means${EOL}` +
|
|
90
|
+
` it's likely to have missed TypeScript sources and dependencies.${EOL}${EOL}` +
|
|
91
|
+
` Install typescript to get better results (e.g. npm i -D typescript@^6).${EOL}${EOL}` +
|
|
92
|
+
` => Support for typescript@>=7 will follow when its API is published and stable.${EOL}`,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
if (!typeScriptIsConsistent(pOptions, pAvailableTranspilers)) {
|
|
96
|
+
const tsTranspilersString = pAvailableTranspilers
|
|
97
|
+
.filter(
|
|
98
|
+
(pTranspiler) =>
|
|
99
|
+
pTranspiler.name === "typescript" || pTranspiler.name === "swc",
|
|
100
|
+
)
|
|
101
|
+
.map((pTranspiler) => `${pTranspiler.name}: ${pTranspiler.version}`)
|
|
102
|
+
.join(", ");
|
|
103
|
+
lIssues.push({
|
|
104
|
+
severity: "warn",
|
|
105
|
+
name: "missing-typescript-transpiler",
|
|
106
|
+
description:
|
|
107
|
+
`dependency-cruiser detected an environment that needs a TypeScript compiler of some sort,${EOL}` +
|
|
108
|
+
` but did not find one of the supported ones (${tsTranspilersString}).${EOL}` +
|
|
109
|
+
` This means it's likely to have missed TypeScript sources and dependencies.${EOL}${EOL}` +
|
|
110
|
+
` Install one of the above for better results.${EOL}${EOL}` +
|
|
111
|
+
` => if you choose to use swc don't forget to set the "parser" option to "swc"${EOL}` +
|
|
112
|
+
` => Support for typescript@>=7 will follow when its API is published and stable.${EOL}`,
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
if (!swcIsConsistent(pOptions, pAvailableTranspilers)) {
|
|
116
|
+
const swcTranspiler = pAvailableTranspilers.find(
|
|
117
|
+
(pTranspiler) => pTranspiler.name === "swc",
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
lIssues.push({
|
|
121
|
+
severity: "warn",
|
|
122
|
+
name: "missing-swc-transpiler",
|
|
123
|
+
description:
|
|
124
|
+
`dependency-cruiser found swc configured as compiler, but ${EOL}` +
|
|
125
|
+
` it did not find a compatible version of swc (${swcTranspiler.name}: ${swcTranspiler.version}).${EOL}` +
|
|
126
|
+
` dependency-cruiser might have missed some sources or dependencies.${EOL}${EOL}` +
|
|
127
|
+
` Install swc (e.g. npm i -D @swc/core) to get better results.${EOL}`,
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
if (!babelIsConsistent(pOptions, pAvailableTranspilers)) {
|
|
131
|
+
const babelTranspiler = pAvailableTranspilers.find(
|
|
132
|
+
(pTranspiler) => pTranspiler.name === "babel",
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
lIssues.push({
|
|
136
|
+
severity: "warn",
|
|
137
|
+
name: "missing-babel-transpiler",
|
|
138
|
+
description:
|
|
139
|
+
`dependency-cruiser detected a babel configuration, but not a${EOL}` +
|
|
140
|
+
` compatible babel transpiler (${babelTranspiler.name}: ${babelTranspiler.version}). If you indeed use babel,${EOL}` +
|
|
141
|
+
` dependency-cruiser might have missed some sources or dependencies.${EOL}${EOL}` +
|
|
142
|
+
` Install babel (e.g. npm i -D @babel/core@^7) to get better results.${EOL}`,
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
return lIssues.length > 0 ? { issues: lIssues } : {};
|
|
146
|
+
}
|
package/src/cli/defaults.mjs
CHANGED
|
@@ -112,7 +112,7 @@ module.exports = {
|
|
|
112
112
|
name: 'no-duplicate-dep-types',
|
|
113
113
|
comment:
|
|
114
114
|
"Likely this module depends on an external ('npm') package that occurs more than once " +
|
|
115
|
-
"in your package.json i.e.
|
|
115
|
+
"in your package.json i.e. both as a devDependencies and in dependencies. This will cause " +
|
|
116
116
|
"maintenance problems later on.",
|
|
117
117
|
severity: 'warn',
|
|
118
118
|
from: {},
|
|
@@ -22,7 +22,9 @@ function dependencyKeyHasModuleName(
|
|
|
22
22
|
pPrefix,
|
|
23
23
|
) {
|
|
24
24
|
return (pKey) =>
|
|
25
|
-
|
|
25
|
+
// dependencies, devDependencies, peerDependencies, optionalDependencies, bundleDependencies, bundledDependencies.
|
|
26
|
+
// But not peerDependenciesMeta. Or dependenciesIDoNotWantToTalkabout.
|
|
27
|
+
pKey.endsWith("ependencies") &&
|
|
26
28
|
Object.hasOwn(pPackageDependencies[pKey], join(pPrefix, pModuleName));
|
|
27
29
|
}
|
|
28
30
|
|
|
@@ -123,7 +123,7 @@ function nodeIsTypeOnly(pNode) {
|
|
|
123
123
|
return true;
|
|
124
124
|
}
|
|
125
125
|
return (
|
|
126
|
-
pNode?.specifiers
|
|
126
|
+
pNode?.specifiers?.length > 0 &&
|
|
127
127
|
pNode.specifiers.every((pSpecifier) => pSpecifier.isTypeOnly)
|
|
128
128
|
);
|
|
129
129
|
}
|
|
@@ -144,7 +144,9 @@ export default Visitor
|
|
|
144
144
|
module: pNode.source.value,
|
|
145
145
|
moduleSystem: "es6",
|
|
146
146
|
exoticallyRequired: false,
|
|
147
|
-
dependencyTypes:
|
|
147
|
+
dependencyTypes: nodeIsTypeOnly(pNode)
|
|
148
|
+
? ["export", "type-only"]
|
|
149
|
+
: ["export"],
|
|
148
150
|
});
|
|
149
151
|
}
|
|
150
152
|
}
|
|
@@ -30,7 +30,7 @@ const CACHE = new Map();
|
|
|
30
30
|
* @param {string} pFileName
|
|
31
31
|
* @returns {ParseOptions}
|
|
32
32
|
*/
|
|
33
|
-
|
|
33
|
+
function getOptionsFor(pFileName) {
|
|
34
34
|
return /[.](?:tsx|jsx)$/.test(pFileName)
|
|
35
35
|
? { ...SWC_PARSE_OPTIONS, tsx: true }
|
|
36
36
|
: SWC_PARSE_OPTIONS;
|
|
@@ -13,7 +13,7 @@ const coffeeVanillaWrap = coffeeWrap();
|
|
|
13
13
|
const litCoffeeWrap = coffeeWrap(true);
|
|
14
14
|
const svelteWrap = svelteDingus(typeScriptVanillaWrap);
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
const EXTENSION2WRAPPER = new Map([
|
|
17
17
|
[".js", javaScriptWrap],
|
|
18
18
|
[".cjs", javaScriptWrap],
|
|
19
19
|
[".mjs", javaScriptWrap],
|
|
@@ -109,7 +109,19 @@ export const EXTENSION2AVAILABLE = new Map([
|
|
|
109
109
|
]);
|
|
110
110
|
|
|
111
111
|
const EXTENSIONS_PER_PARSER = {
|
|
112
|
-
swc: new Set([
|
|
112
|
+
swc: new Set([
|
|
113
|
+
".js",
|
|
114
|
+
".cjs",
|
|
115
|
+
".mjs",
|
|
116
|
+
".jsx",
|
|
117
|
+
".ts",
|
|
118
|
+
".tsx",
|
|
119
|
+
".d.ts",
|
|
120
|
+
".cts",
|
|
121
|
+
".d.cts",
|
|
122
|
+
".mts",
|
|
123
|
+
".d.mts",
|
|
124
|
+
]),
|
|
113
125
|
// tsc: [".js", ".cjs", ".mjs", ".jsx", ".ts", ".tsx", ".d.ts"],
|
|
114
126
|
// acorn: [".js", ".cjs", ".mjs", ".jsx"],
|
|
115
127
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { resolve } from "node:path";
|
|
1
2
|
import tryImport from "#utl/try-import.mjs";
|
|
2
3
|
import meta from "#meta.cjs";
|
|
3
4
|
|
|
@@ -6,6 +7,16 @@ const typescript = await tryImport(
|
|
|
6
7
|
meta.supportedTranspilers.typescript,
|
|
7
8
|
);
|
|
8
9
|
|
|
10
|
+
// This RE matches
|
|
11
|
+
// - filename.d.ts (, .cts, .mts), but also
|
|
12
|
+
// - filename.d.something.ts (, .cts., .mts).
|
|
13
|
+
// That second one seems a bit odd, but it _is_ possible; see for instance
|
|
14
|
+
// https://www.typescriptlang.org/tsconfig/#allowArbitraryExtensions
|
|
15
|
+
// (and I guess, but haven't seen this confirmed in the field or documentation
|
|
16
|
+
// that it could be possible to have a declaration file variant of
|
|
17
|
+
// https://www.typescriptlang.org/tsconfig/#moduleSuffixes)
|
|
18
|
+
const DECLARATION_FILE_RE = /[.]d([.][^./\\]+)?([.][cm]?ts)$/;
|
|
19
|
+
|
|
9
20
|
function getCompilerOptions(pFlavor, pTSConfig) {
|
|
10
21
|
const lCompilerOptions = {};
|
|
11
22
|
|
|
@@ -32,15 +43,26 @@ function getCompilerOptions(pFlavor, pTSConfig) {
|
|
|
32
43
|
};
|
|
33
44
|
}
|
|
34
45
|
|
|
46
|
+
function getTranspilableFileName(pFileName) {
|
|
47
|
+
if (typeof pFileName !== "string") {
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
// Declaration files (.d.ts, .d.mts, .d.cts, .d.css.ts) get their
|
|
51
|
+
// non-declaration name, because TypeScript emits nothing for a declaration
|
|
52
|
+
// file and throws "Debug Failure. Output generation failed".
|
|
53
|
+
return resolve(pFileName).replace(DECLARATION_FILE_RE, "$1$2");
|
|
54
|
+
}
|
|
55
|
+
|
|
35
56
|
export default function typescriptWrap(pFlavor) {
|
|
36
57
|
return {
|
|
37
58
|
isAvailable: () => typescript !== false,
|
|
38
59
|
|
|
39
60
|
version: () => `typescript@${typescript.version}`,
|
|
40
61
|
|
|
41
|
-
transpile: (pSource,
|
|
62
|
+
transpile: (pSource, pFileName, pTranspileOptions = {}) =>
|
|
42
63
|
typescript.transpileModule(pSource, {
|
|
43
64
|
...(pTranspileOptions.tsConfig || {}),
|
|
65
|
+
fileName: getTranspilableFileName(pFileName),
|
|
44
66
|
compilerOptions: getCompilerOptions(
|
|
45
67
|
pFlavor,
|
|
46
68
|
pTranspileOptions.tsConfig || {},
|
|
@@ -23,8 +23,8 @@ function scrub(pModuleNamesSet) {
|
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
25
|
*
|
|
26
|
-
* @param {import("../../types/dependency-cruiser.
|
|
27
|
-
* @param {import("../../types/strict-filter-types.
|
|
26
|
+
* @param {import("../../types/dependency-cruiser.mjs").IModule[]} pModules
|
|
27
|
+
* @param {import("../../types/strict-filter-types.mjs").IStrictFocusType} pFilter
|
|
28
28
|
* @returns
|
|
29
29
|
*/
|
|
30
30
|
export default function addFocus(pModules, pFilter) {
|
package/src/main/cruise.mjs
CHANGED
|
@@ -7,7 +7,7 @@ import { clearRegExpCache } from "#utl/regex-util.mjs";
|
|
|
7
7
|
|
|
8
8
|
const TOTAL_STEPS = 10;
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
function c(pComplete, pTotal = TOTAL_STEPS) {
|
|
11
11
|
return { complete: pComplete / pTotal };
|
|
12
12
|
}
|
|
13
13
|
|
|
@@ -81,7 +81,6 @@ export default async function cruise(
|
|
|
81
81
|
const lNormalizedResolveOptions = await normalizeResolveOptions(
|
|
82
82
|
pResolveOptions,
|
|
83
83
|
lCruiseOptions,
|
|
84
|
-
pTranspileOptions?.tsConfig,
|
|
85
84
|
);
|
|
86
85
|
|
|
87
86
|
bus.summary("extract", c(6));
|
package/src/main/format.mjs
CHANGED
|
@@ -11,7 +11,7 @@ function validateResultAgainstSchema(pResult) {
|
|
|
11
11
|
);
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
|
-
/** @type {import("../../types/dependency-cruiser.
|
|
14
|
+
/** @type {import("../../types/dependency-cruiser.mjs").format} */
|
|
15
15
|
export default async function format(pResult, pFormatOptions = {}) {
|
|
16
16
|
const lFormatOptions = normalizeFormatOptions(pFormatOptions);
|
|
17
17
|
assertFormatOptionsValid(lFormatOptions);
|
|
@@ -68,7 +68,6 @@ function pushPlugin(pPlugins, pPluginToPush) {
|
|
|
68
68
|
// eslint-disable-next-line max-lines-per-function
|
|
69
69
|
async function compileResolveOptions(
|
|
70
70
|
pResolveOptions,
|
|
71
|
-
pTSConfig,
|
|
72
71
|
pResolveOptionsFromDCConfig,
|
|
73
72
|
) {
|
|
74
73
|
const lResolveOptions = {};
|
|
@@ -86,29 +85,6 @@ async function compileResolveOptions(
|
|
|
86
85
|
// @ts-expect-error TS2351 "TsConfPathsPlugin is not constructable" - is unjustified
|
|
87
86
|
new TsConfigPathsPlugin({
|
|
88
87
|
configFile: pResolveOptions.tsConfig,
|
|
89
|
-
// TsConfigPathsPlugin requires a baseUrl to be present in the tsconfig,
|
|
90
|
-
// otherwise it prints scary messages that it didn't and read the tsConfig
|
|
91
|
-
// (potentially making users think it's dependency-cruiser disregarding the
|
|
92
|
-
// tsconfig). Hence up till version 13.0.4 dependency-cruiser only loaded
|
|
93
|
-
// TsConfigPathsPlugin when an options.baseUrl existed. However, this
|
|
94
|
-
// isn't necessary anymore:
|
|
95
|
-
// - [tsconfig#baseUrl documentation](https://www.typescriptlang.org/tsconfig#baseUrl)
|
|
96
|
-
// UNrecommends the use of the baseUrl for non-AMD projects
|
|
97
|
-
// - [tsconfig-paths PR #207](https://github.com/dividab/tsconfig-paths/pull/208)
|
|
98
|
-
// 'tolerates' undefined baseUrls
|
|
99
|
-
//
|
|
100
|
-
// Hence, until
|
|
101
|
-
// [tpwp issue #99](https://github.com/dividab/tsconfig-paths-webpack-plugin/issues/99)
|
|
102
|
-
// lands:
|
|
103
|
-
// - pass a default baseUrl to TsConfigPathsPlugin if the baseUrl isn't available
|
|
104
|
-
// - pass undefined in all other cases; TsConfigPathsPlugin will read
|
|
105
|
-
// it from the tsconfig.json in that case. Passing the processed baseUrl
|
|
106
|
-
// (pTSConfig?.options?.baseUrl) instead would've been more obvious, but
|
|
107
|
-
// doesn't work, as that is an absolute path and tsconfig-paths(-wpp)
|
|
108
|
-
// seems to process that again resulting in invalid paths and unresolved
|
|
109
|
-
// or erroneous dependencies
|
|
110
|
-
// eslint-disable-next-line no-undefined
|
|
111
|
-
baseUrl: pTSConfig?.options?.baseUrl ? undefined : "./",
|
|
112
88
|
// TsConfigPathsPlugin doesn't (can't) read enhanced-resolve's
|
|
113
89
|
// list of extensions, and the default it uses for extensions
|
|
114
90
|
// so we do it ourselves - either with the extensions passed
|
|
@@ -136,14 +112,12 @@ async function compileResolveOptions(
|
|
|
136
112
|
/**
|
|
137
113
|
* @param {IResolveOptions} pResolveOptions
|
|
138
114
|
* @param {ICruiseOptions} pOptions
|
|
139
|
-
* @param {import("typescript").ParsedTsconfig} pTSConfig
|
|
140
115
|
* @returns
|
|
141
116
|
*/
|
|
142
117
|
// eslint-disable-next-line complexity
|
|
143
118
|
export default async function normalizeResolveOptions(
|
|
144
119
|
pResolveOptions,
|
|
145
120
|
pOptions,
|
|
146
|
-
pTSConfig,
|
|
147
121
|
) {
|
|
148
122
|
const lRuleSet = pOptions?.ruleSet ?? {};
|
|
149
123
|
|
|
@@ -174,7 +148,6 @@ export default async function normalizeResolveOptions(
|
|
|
174
148
|
resolveDeprecations: ruleSetHasDeprecationRule(lRuleSet),
|
|
175
149
|
...pResolveOptions,
|
|
176
150
|
},
|
|
177
|
-
pTSConfig || {},
|
|
178
151
|
pOptions?.enhancedResolveOptions ?? {},
|
|
179
152
|
);
|
|
180
153
|
}
|
package/src/meta.cjs
CHANGED
|
@@ -174,7 +174,7 @@ function sanitizeWordList(pWordList) {
|
|
|
174
174
|
* not passed the reporter uses the string passed
|
|
175
175
|
* in the options (reporterOptions.anon.wordlist)
|
|
176
176
|
* or - if that doesn't exist - the empty array
|
|
177
|
-
* @returns {import("../../../types/dependency-cruiser.
|
|
177
|
+
* @returns {import("../../../types/dependency-cruiser.mjs").IReporterOutput} - output: the results in JSON format (hence adhering to the same json schema)
|
|
178
178
|
* exitCode: 0
|
|
179
179
|
*/
|
|
180
180
|
export default function reportAnonymous(pResults, pAnonymousReporterOptions) {
|
|
@@ -13,7 +13,7 @@ const SEVERITY2VSO_TYPE = new Map([
|
|
|
13
13
|
]);
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
|
-
* @param {import("../../types/shared-types.
|
|
16
|
+
* @param {import("../../types/shared-types.mjs").SeverityType} pSeverity
|
|
17
17
|
* @returns {string}
|
|
18
18
|
*/
|
|
19
19
|
function formatSeverity(pSeverity) {
|
|
@@ -21,7 +21,7 @@ function formatSeverity(pSeverity) {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
|
-
* @param {import("../../types/violations.
|
|
24
|
+
* @param {import("../../types/violations.mjs").IViolation} pViolation
|
|
25
25
|
* @returns {string}
|
|
26
26
|
*/
|
|
27
27
|
function formatModuleViolation(pViolation) {
|
|
@@ -29,7 +29,7 @@ function formatModuleViolation(pViolation) {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
/**
|
|
32
|
-
* @param {import("../../types/violations.
|
|
32
|
+
* @param {import("../../types/violations.mjs").IViolation} pViolation
|
|
33
33
|
* @returns {string}
|
|
34
34
|
*/
|
|
35
35
|
function formatDependencyViolation(pViolation) {
|
|
@@ -37,7 +37,7 @@ function formatDependencyViolation(pViolation) {
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
/**
|
|
40
|
-
* @param {import("../../types/violations.
|
|
40
|
+
* @param {import("../../types/violations.mjs").IViolation} pViolation
|
|
41
41
|
* @returns {string}
|
|
42
42
|
*/
|
|
43
43
|
function formatCycleViolation(pViolation) {
|
|
@@ -47,7 +47,7 @@ function formatCycleViolation(pViolation) {
|
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
/**
|
|
50
|
-
* @param {import("../../types/violations.
|
|
50
|
+
* @param {import("../../types/violations.mjs").IViolation} pViolation
|
|
51
51
|
* @returns {string}
|
|
52
52
|
*/
|
|
53
53
|
function formatReachabilityViolation(pViolation) {
|
|
@@ -57,7 +57,7 @@ function formatReachabilityViolation(pViolation) {
|
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
/**
|
|
60
|
-
* @param {import("../../types/violations.
|
|
60
|
+
* @param {import("../../types/violations.mjs").IViolation} pViolation
|
|
61
61
|
* @returns {string}
|
|
62
62
|
*/
|
|
63
63
|
function formatInstabilityViolation(pViolation) {
|
|
@@ -69,7 +69,7 @@ function formatInstabilityViolation(pViolation) {
|
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
/**
|
|
72
|
-
* @param {import("../../types/violations.
|
|
72
|
+
* @param {import("../../types/violations.mjs").IViolation} pViolation
|
|
73
73
|
* @returns {string}
|
|
74
74
|
*/
|
|
75
75
|
function formatViolation(pViolation) {
|
|
@@ -167,8 +167,8 @@ function formatSummary(pSummary) {
|
|
|
167
167
|
* Background documentation:
|
|
168
168
|
* https://learn.microsoft.com/en-us/azure/devops/pipelines/scripts/logging-commands?view=azure-devops&tabs=bash#task-commands
|
|
169
169
|
*
|
|
170
|
-
* @param {import("../../types/dependency-cruiser.
|
|
171
|
-
* @returns {import("../../types/dependency-cruiser.
|
|
170
|
+
* @param {import("../../types/dependency-cruiser.mjs").ICruiseResult} pResults
|
|
171
|
+
* @returns {import("../../types/dependency-cruiser.mjs").IReporterOutput}
|
|
172
172
|
*/
|
|
173
173
|
// eslint-disable-next-line unicorn/prevent-abbreviations
|
|
174
174
|
export default function azureDevOps(pResults) {
|
package/src/report/csv.mjs
CHANGED
|
@@ -27,7 +27,7 @@ function report(pModules) {
|
|
|
27
27
|
*
|
|
28
28
|
* @param {import("../../types/cruise-result.mjs").ICruiseResult} pResults -
|
|
29
29
|
* the output of a dependency-cruise adhering to ../../schema/cruise-result.schema.json
|
|
30
|
-
* @returns {import("../../types/dependency-cruiser.
|
|
30
|
+
* @returns {import("../../types/dependency-cruiser.mjs").IReporterOutput}
|
|
31
31
|
*/
|
|
32
32
|
export default function csv(pResults) {
|
|
33
33
|
return {
|
package/src/report/dot/index.mjs
CHANGED
|
@@ -214,7 +214,7 @@ function normalizeDotReporterOptions(
|
|
|
214
214
|
* @param {string} pGranularity - either "module" (for fine grained module
|
|
215
215
|
* level) or "folder" (for a report consolidated
|
|
216
216
|
* to folders)
|
|
217
|
-
* @returns {(pResults, pDotReporterOptions) => import("../../../types/dependency-cruiser.
|
|
217
|
+
* @returns {(pResults, pDotReporterOptions) => import("../../../types/dependency-cruiser.mjs").IReporterOutput}
|
|
218
218
|
*/
|
|
219
219
|
export default function produceDotReporter(pGranularity) {
|
|
220
220
|
return function dot(pResults, pDotReporterOptions) {
|
package/src/report/error.mjs
CHANGED
|
@@ -11,7 +11,7 @@ import wrapAndIndent from "#utl/wrap-and-indent.mjs";
|
|
|
11
11
|
/**
|
|
12
12
|
* @import { ICruiseResult, IEnvironmentIssue } from "../../types/cruise-result.mjs"
|
|
13
13
|
* @import { IErrorReporterOptions } from "../../types/reporter-options.mjs"
|
|
14
|
-
* @import { IReporterOutput } from "../../types/dependency-cruiser.
|
|
14
|
+
* @import { IReporterOutput } from "../../types/dependency-cruiser.mjs"
|
|
15
15
|
* @import { SeverityType } from "../../types/shared-types.mjs"
|
|
16
16
|
*/
|
|
17
17
|
|
|
@@ -110,7 +110,7 @@ function report(pResults) {
|
|
|
110
110
|
* Returns the results of a cruise in an 'incidence matrix'
|
|
111
111
|
*
|
|
112
112
|
* @param {import("../../../types/cruise-result.mjs").ICruiseResult} pResults
|
|
113
|
-
* @returns {import("../../../types/dependency-cruiser.
|
|
113
|
+
* @returns {import("../../../types/dependency-cruiser.mjs").IReporterOutput}
|
|
114
114
|
*/
|
|
115
115
|
export default function html(pResults) {
|
|
116
116
|
return {
|
package/src/report/index.mjs
CHANGED
|
@@ -31,7 +31,7 @@ const TYPE2MODULE = new Map([
|
|
|
31
31
|
* Returns the reporter function associated with given output type,
|
|
32
32
|
* or the identity reporter if that output type wasn't found
|
|
33
33
|
*
|
|
34
|
-
* @param {import("../../types/shared-types.
|
|
34
|
+
* @param {import("../../types/shared-types.mjs").OutputType} pOutputType -
|
|
35
35
|
* @returns {function} - a function that takes an ICruiseResult, optionally
|
|
36
36
|
* an options object (specific to that function)
|
|
37
37
|
* and returns an IReporterOutput
|
|
@@ -52,7 +52,7 @@ export async function getReporter(pOutputType) {
|
|
|
52
52
|
/**
|
|
53
53
|
* Returns a list of all currently available reporters
|
|
54
54
|
*
|
|
55
|
-
* @returns {import("../../types/shared-types.
|
|
55
|
+
* @returns {import("../../types/shared-types.mjs").OutputType[]} -
|
|
56
56
|
*/
|
|
57
57
|
export function getAvailableReporters() {
|
|
58
58
|
return Array.from(TYPE2MODULE.keys());
|
package/src/report/metrics.mjs
CHANGED
|
@@ -266,9 +266,9 @@ function transformMetricsToTable(
|
|
|
266
266
|
* Potential future features:
|
|
267
267
|
* - additional output formats (csv?, html?)
|
|
268
268
|
*
|
|
269
|
-
* @param {import('../../types/dependency-cruiser.
|
|
270
|
-
* @param {import("../../types/reporter-options.
|
|
271
|
-
* @returns {import('../../types/dependency-cruiser.
|
|
269
|
+
* @param {import('../../types/dependency-cruiser.mjs').ICruiseResult} pCruiseResult -
|
|
270
|
+
* @param {import("../../types/reporter-options.mjs").IMetricsReporterOptions} pReporterOptions
|
|
271
|
+
* @returns {import('../../types/dependency-cruiser.mjs').IReporterOutput} -
|
|
272
272
|
*/
|
|
273
273
|
export default function metrics(pCruiseResult, pReporterOptions) {
|
|
274
274
|
const lReporterOptions = pReporterOptions || {};
|