dependency-cruiser 10.8.0 → 11.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/extract/get-dependencies.js +11 -6
- package/src/extract/parse/to-typescript-ast.js +24 -8
- package/src/extract/utl/get-extension.js +9 -5
- package/src/meta.js +1 -1
- package/types/baseline-violations.d.ts +1 -1
- package/types/cruise-result.d.ts +6 -50
- package/types/rule-summary.d.ts +23 -0
- package/types/violations.d.ts +24 -0
package/package.json
CHANGED
|
@@ -21,15 +21,18 @@ function extractFromSwcAST(pOptions, pFileName) {
|
|
|
21
21
|
);
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
function extractFromTypeScriptAST(pOptions, pFileName) {
|
|
24
|
+
function extractFromTypeScriptAST(pOptions, pFileName, pTranspileOptions) {
|
|
25
25
|
return extractTypeScriptDeps(
|
|
26
|
-
toTypescriptAST.getASTCached(
|
|
26
|
+
toTypescriptAST.getASTCached(
|
|
27
|
+
path.join(pOptions.baseDir, pFileName),
|
|
28
|
+
pTranspileOptions
|
|
29
|
+
),
|
|
27
30
|
pOptions.exoticRequireStrings
|
|
28
31
|
);
|
|
29
32
|
}
|
|
30
33
|
|
|
31
34
|
function isTypeScriptCompatible(pFileName) {
|
|
32
|
-
return [".ts", ".tsx", ".js", ".mjs", ".cjs"].includes(
|
|
35
|
+
return [".ts", ".tsx", ".js", ".mjs", ".cjs", ".vue"].includes(
|
|
33
36
|
path.extname(pFileName)
|
|
34
37
|
);
|
|
35
38
|
}
|
|
@@ -88,9 +91,11 @@ function extractWithTsc(
|
|
|
88
91
|
pFileName,
|
|
89
92
|
pTranspileOptions
|
|
90
93
|
) {
|
|
91
|
-
pDependencies = extractFromTypeScriptAST(
|
|
92
|
-
|
|
93
|
-
|
|
94
|
+
pDependencies = extractFromTypeScriptAST(
|
|
95
|
+
pCruiseOptions,
|
|
96
|
+
pFileName,
|
|
97
|
+
pTranspileOptions
|
|
98
|
+
).filter((pDep) => pCruiseOptions.moduleSystems.includes(pDep.moduleSystem));
|
|
94
99
|
|
|
95
100
|
if (pCruiseOptions.tsPreCompilationDeps === "specify") {
|
|
96
101
|
pDependencies = detectPreCompilationNess(
|
|
@@ -2,21 +2,28 @@ const fs = require("fs");
|
|
|
2
2
|
const tryRequire = require("semver-try-require");
|
|
3
3
|
const _memoize = require("lodash/memoize");
|
|
4
4
|
const { supportedTranspilers } = require("../../../src/meta.js");
|
|
5
|
+
const transpile = require("../transpile");
|
|
6
|
+
const getExtension = require("../utl/get-extension");
|
|
5
7
|
|
|
6
8
|
const typescript = tryRequire("typescript", supportedTranspilers.typescript);
|
|
7
9
|
|
|
8
10
|
/**
|
|
9
11
|
* Compiles pTypescriptSource into a (typescript) AST
|
|
10
12
|
*
|
|
11
|
-
* @param {
|
|
12
|
-
* @param {
|
|
13
|
-
*
|
|
13
|
+
* @param {object} pFileRecord Record with source code, an extension and a filename
|
|
14
|
+
* @param {any} [pTranspileOptions] options for the transpiler(s) - a tsconfig or
|
|
15
|
+
* a babel config
|
|
14
16
|
* @return {object} - a (typescript) AST
|
|
15
17
|
*/
|
|
16
|
-
function getASTFromSource(
|
|
18
|
+
function getASTFromSource(pFileRecord, pTranspileOptions) {
|
|
19
|
+
let lSource = pFileRecord.source;
|
|
20
|
+
if (pFileRecord.extension === ".vue") {
|
|
21
|
+
lSource = transpile(pFileRecord, pTranspileOptions);
|
|
22
|
+
}
|
|
23
|
+
|
|
17
24
|
return typescript.createSourceFile(
|
|
18
|
-
|
|
19
|
-
|
|
25
|
+
pFileRecord.filename || "$internal-file-name",
|
|
26
|
+
lSource,
|
|
20
27
|
typescript.ScriptTarget.Latest,
|
|
21
28
|
false
|
|
22
29
|
);
|
|
@@ -27,10 +34,19 @@ function getASTFromSource(pTypescriptSource, pFileName) {
|
|
|
27
34
|
* AST and returns it
|
|
28
35
|
*
|
|
29
36
|
* @param {string} pFileName - the name of the file to compile
|
|
37
|
+
* @param {any} [pTranspileOptions] options for the transpiler(s) - a tsconfig or
|
|
38
|
+
* a babel config
|
|
30
39
|
* @return {object} - a (typescript) AST
|
|
31
40
|
*/
|
|
32
|
-
function getAST(pFileName) {
|
|
33
|
-
return getASTFromSource(
|
|
41
|
+
function getAST(pFileName, pTranspileOptions) {
|
|
42
|
+
return getASTFromSource(
|
|
43
|
+
{
|
|
44
|
+
source: fs.readFileSync(pFileName, "utf8"),
|
|
45
|
+
extension: getExtension(pFileName),
|
|
46
|
+
filename: pFileName,
|
|
47
|
+
},
|
|
48
|
+
pTranspileOptions
|
|
49
|
+
);
|
|
34
50
|
}
|
|
35
51
|
|
|
36
52
|
const getASTCached = _memoize(getAST);
|
|
@@ -5,16 +5,20 @@ const path = require("path");
|
|
|
5
5
|
*
|
|
6
6
|
* Just using path.extname would be fine for most cases,
|
|
7
7
|
* except for coffeescript, where a markdown extension can
|
|
8
|
-
* mean literate coffeescript
|
|
8
|
+
* mean literate coffeescript, and for typescript where
|
|
9
|
+
* .d.ts and .ts are slightly different beasts
|
|
9
10
|
*
|
|
10
11
|
* @param {string} pFileName path to the file to be parsed
|
|
11
12
|
* @return {string} extension
|
|
12
13
|
*/
|
|
13
14
|
module.exports = function getExtensions(pFileName) {
|
|
14
|
-
|
|
15
|
+
if (pFileName.endsWith(".d.ts")) {
|
|
16
|
+
return ".d.ts";
|
|
17
|
+
}
|
|
15
18
|
|
|
16
|
-
if (
|
|
17
|
-
return
|
|
19
|
+
if (pFileName.endsWith(".coffee.md")) {
|
|
20
|
+
return ".coffee.md";
|
|
18
21
|
}
|
|
19
|
-
|
|
22
|
+
|
|
23
|
+
return path.extname(pFileName);
|
|
20
24
|
};
|
package/src/meta.js
CHANGED
package/types/cruise-result.d.ts
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import { ICruiseOptions } from "./options";
|
|
2
2
|
import { IFlattenedRuleSet } from "./rule-set";
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
SeverityType,
|
|
7
|
-
ProtocolType,
|
|
8
|
-
} from "./shared-types";
|
|
3
|
+
import { DependencyType, ModuleSystemType, ProtocolType } from "./shared-types";
|
|
4
|
+
import { IViolation } from "./violations";
|
|
5
|
+
import { IRuleSummary } from "./rule-summary";
|
|
9
6
|
|
|
10
7
|
export interface ICruiseResult {
|
|
11
8
|
/**
|
|
@@ -226,27 +223,6 @@ export interface IDependency {
|
|
|
226
223
|
valid: boolean;
|
|
227
224
|
}
|
|
228
225
|
|
|
229
|
-
/**
|
|
230
|
-
* If there was a rule violation (valid === false), this object contains the name of the
|
|
231
|
-
* rule and severity of violating it.
|
|
232
|
-
*/
|
|
233
|
-
export interface IRuleSummary {
|
|
234
|
-
/**
|
|
235
|
-
* The (short, eslint style) name of the violated rule. Typically something like
|
|
236
|
-
* 'no-core-punycode' or 'no-outside-deps'.
|
|
237
|
-
*/
|
|
238
|
-
name: string;
|
|
239
|
-
/**
|
|
240
|
-
* How severe a violation of a rule is. The 'error' severity will make some reporters return
|
|
241
|
-
* a non-zero exit code, so if you want e.g. a build to stop when there's a rule violated:
|
|
242
|
-
* use that. The absence of the 'ignore' severity here is by design; ignored rules don't
|
|
243
|
-
* show up in the output.
|
|
244
|
-
*
|
|
245
|
-
* Severity to use when a dependency is not in the 'allowed' set of rules. Defaults to 'warn'
|
|
246
|
-
*/
|
|
247
|
-
severity: SeverityType;
|
|
248
|
-
}
|
|
249
|
-
|
|
250
226
|
export interface IReachable {
|
|
251
227
|
/**
|
|
252
228
|
* The name of the rule where the reachability was defined
|
|
@@ -389,29 +365,6 @@ export interface IWebpackConfig {
|
|
|
389
365
|
*/
|
|
390
366
|
export type WebpackEnvType = { [key: string]: any } | string;
|
|
391
367
|
|
|
392
|
-
export interface IViolation {
|
|
393
|
-
/**
|
|
394
|
-
* The violated rule
|
|
395
|
-
*/
|
|
396
|
-
rule: IRuleSummary;
|
|
397
|
-
/**
|
|
398
|
-
* The from part of the dependency this violation is about
|
|
399
|
-
*/
|
|
400
|
-
from: string;
|
|
401
|
-
/**
|
|
402
|
-
* The to part of the dependency this violation is about
|
|
403
|
-
*/
|
|
404
|
-
to: string;
|
|
405
|
-
/**
|
|
406
|
-
* The circular path if the violation is about circularity
|
|
407
|
-
*/
|
|
408
|
-
cycle?: string[];
|
|
409
|
-
/**
|
|
410
|
-
* The path from the from to the to if the violation is transitive
|
|
411
|
-
*/
|
|
412
|
-
via?: string[];
|
|
413
|
-
}
|
|
414
|
-
|
|
415
368
|
export interface IFolder {
|
|
416
369
|
/**
|
|
417
370
|
* The name of the folder. FOlder names are normalized to posix (so
|
|
@@ -455,3 +408,6 @@ export interface IFolder {
|
|
|
455
408
|
*/
|
|
456
409
|
instability?: number;
|
|
457
410
|
}
|
|
411
|
+
|
|
412
|
+
export * from "./violations";
|
|
413
|
+
export * from "./rule-summary";
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { SeverityType } from "./shared-types";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* If there was a rule violation (valid === false), this object contains the name of the
|
|
5
|
+
* rule and severity of violating it.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export interface IRuleSummary {
|
|
9
|
+
/**
|
|
10
|
+
* The (short, eslint style) name of the violated rule. Typically something like
|
|
11
|
+
* 'no-core-punycode' or 'no-outside-deps'.
|
|
12
|
+
*/
|
|
13
|
+
name: string;
|
|
14
|
+
/**
|
|
15
|
+
* How severe a violation of a rule is. The 'error' severity will make some reporters return
|
|
16
|
+
* a non-zero exit code, so if you want e.g. a build to stop when there's a rule violated:
|
|
17
|
+
* use that. The absence of the 'ignore' severity here is by design; ignored rules don't
|
|
18
|
+
* show up in the output.
|
|
19
|
+
*
|
|
20
|
+
* Severity to use when a dependency is not in the 'allowed' set of rules. Defaults to 'warn'
|
|
21
|
+
*/
|
|
22
|
+
severity: SeverityType;
|
|
23
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { IRuleSummary } from "./rule-summary";
|
|
2
|
+
|
|
3
|
+
export interface IViolation {
|
|
4
|
+
/**
|
|
5
|
+
* The violated rule
|
|
6
|
+
*/
|
|
7
|
+
rule: IRuleSummary;
|
|
8
|
+
/**
|
|
9
|
+
* The from part of the dependency this violation is about
|
|
10
|
+
*/
|
|
11
|
+
from: string;
|
|
12
|
+
/**
|
|
13
|
+
* The to part of the dependency this violation is about
|
|
14
|
+
*/
|
|
15
|
+
to: string;
|
|
16
|
+
/**
|
|
17
|
+
* The circular path if the violation is about circularity
|
|
18
|
+
*/
|
|
19
|
+
cycle?: string[];
|
|
20
|
+
/**
|
|
21
|
+
* The path from the from to the to if the violation is transitive
|
|
22
|
+
*/
|
|
23
|
+
via?: string[];
|
|
24
|
+
}
|