dependency-cruiser 10.3.1-beta-2 → 10.4.0-beta-2
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 +9 -9
- package/src/enrich/soften-known-violations.js +2 -20
- package/src/enrich/summarize/is-same-violation.js +18 -0
- package/src/enrich/summarize/summarize-modules.js +5 -3
- package/src/extract/ast-extractors/extract-typescript-deps.js +3 -0
- package/src/extract/get-dependencies.js +4 -14
- package/src/extract/resolve/determine-dependency-types.js +13 -9
- package/src/extract/resolve/index.js +46 -13
- package/src/extract/resolve/module-classifiers.js +0 -6
- package/src/extract/resolve/resolve-amd.js +11 -38
- package/src/extract/resolve/resolve-cjs.js +7 -35
- package/src/meta.js +1 -1
- package/src/schema/configuration.schema.js +1 -0
- package/src/schema/cruise-result.schema.js +2 -0
- package/src/validate/match-dependency-rule.js +1 -1
- package/types/cruise-result.d.ts +7 -0
- package/types/shared-types.d.ts +3 -2
- package/src/enrich/summarize/de-duplicate-violations.js +0 -20
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dependency-cruiser",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.4.0-beta-2",
|
|
4
4
|
"description": "Validate and visualize dependencies. With your rules. JavaScript, TypeScript, CoffeeScript. ES6, CommonJS, AMD.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"static analysis",
|
|
@@ -139,10 +139,10 @@
|
|
|
139
139
|
"ajv": "8.6.3",
|
|
140
140
|
"chalk": "4.1.2",
|
|
141
141
|
"commander": "8.2.0",
|
|
142
|
-
"enhanced-resolve": "5.8.
|
|
142
|
+
"enhanced-resolve": "5.8.3",
|
|
143
143
|
"figures": "^3.2.0",
|
|
144
144
|
"get-stream": "^6.0.1",
|
|
145
|
-
"glob": "7.
|
|
145
|
+
"glob": "7.2.0",
|
|
146
146
|
"handlebars": "4.7.7",
|
|
147
147
|
"indent-string": "^4.0.0",
|
|
148
148
|
"inquirer": "8.1.5",
|
|
@@ -159,13 +159,13 @@
|
|
|
159
159
|
"@babel/core": "7.15.5",
|
|
160
160
|
"@babel/plugin-transform-modules-commonjs": "7.15.4",
|
|
161
161
|
"@babel/preset-typescript": "7.15.0",
|
|
162
|
-
"@swc/core": "1.2.
|
|
163
|
-
"@typescript-eslint/eslint-plugin": "4.31.
|
|
164
|
-
"@typescript-eslint/parser": "4.31.
|
|
162
|
+
"@swc/core": "1.2.91",
|
|
163
|
+
"@typescript-eslint/eslint-plugin": "4.31.2",
|
|
164
|
+
"@typescript-eslint/parser": "4.31.2",
|
|
165
165
|
"c8": "7.9.0",
|
|
166
166
|
"chai": "4.3.4",
|
|
167
167
|
"chai-json-schema": "1.5.1",
|
|
168
|
-
"coffeescript": "2.
|
|
168
|
+
"coffeescript": "2.6.0",
|
|
169
169
|
"eslint": "7.32.0",
|
|
170
170
|
"eslint-config-moving-meadow": "2.0.9",
|
|
171
171
|
"eslint-config-prettier": "8.3.0",
|
|
@@ -178,12 +178,12 @@
|
|
|
178
178
|
"husky": "^4.3.8",
|
|
179
179
|
"intercept-stdout": "0.1.2",
|
|
180
180
|
"lint-staged": "11.1.2",
|
|
181
|
-
"mocha": "9.1.
|
|
181
|
+
"mocha": "9.1.2",
|
|
182
182
|
"normalize-newline": "4.1.0",
|
|
183
183
|
"npm-run-all": "4.1.5",
|
|
184
184
|
"prettier": "2.4.1",
|
|
185
185
|
"shx": "0.3.3",
|
|
186
|
-
"svelte": "3.
|
|
186
|
+
"svelte": "3.43.0",
|
|
187
187
|
"symlink-dir": "5.0.1",
|
|
188
188
|
"typescript": "4.4.3",
|
|
189
189
|
"upem": "^7.0.0",
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const bus = require("../utl/bus");
|
|
2
2
|
const busLogLevels = require("../utl/bus-log-levels");
|
|
3
|
+
const isSameViolation = require("./summarize/is-same-violation");
|
|
3
4
|
|
|
4
5
|
function softenModuleViolation(
|
|
5
6
|
pRule,
|
|
@@ -19,25 +20,6 @@ function softenModuleViolation(
|
|
|
19
20
|
};
|
|
20
21
|
}
|
|
21
22
|
|
|
22
|
-
function knownErrorMatchesViolation(pKnownError, pViolationKey) {
|
|
23
|
-
if (pKnownError.rule.name === pViolationKey.rule.name) {
|
|
24
|
-
if (pViolationKey.cycle && pKnownError.cycle) {
|
|
25
|
-
return (
|
|
26
|
-
pKnownError.cycle.length === pViolationKey.cycle.length &&
|
|
27
|
-
pKnownError.cycle.every((pModule) =>
|
|
28
|
-
pViolationKey.cycle.includes(pModule)
|
|
29
|
-
)
|
|
30
|
-
);
|
|
31
|
-
} else {
|
|
32
|
-
return (
|
|
33
|
-
pKnownError.from === pViolationKey.from &&
|
|
34
|
-
pKnownError.to === pViolationKey.to
|
|
35
|
-
);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
return false;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
23
|
function softenDependencyViolation(
|
|
42
24
|
pViolationKey,
|
|
43
25
|
pKnownDependencyViolations,
|
|
@@ -46,7 +28,7 @@ function softenDependencyViolation(
|
|
|
46
28
|
return {
|
|
47
29
|
...pViolationKey.rule,
|
|
48
30
|
severity: pKnownDependencyViolations.some((pKnownError) =>
|
|
49
|
-
|
|
31
|
+
isSameViolation(pKnownError, pViolationKey)
|
|
50
32
|
)
|
|
51
33
|
? pSoftenedSeverity
|
|
52
34
|
: pViolationKey.rule.severity,
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
module.exports = function isSameViolation(pLeftViolation, pRightViolation) {
|
|
2
|
+
let lReturnValue = false;
|
|
3
|
+
|
|
4
|
+
if (pLeftViolation.rule.name === pRightViolation.rule.name) {
|
|
5
|
+
if (pRightViolation.cycle && pLeftViolation.cycle) {
|
|
6
|
+
lReturnValue =
|
|
7
|
+
pLeftViolation.cycle.length === pRightViolation.cycle.length &&
|
|
8
|
+
pLeftViolation.cycle.every((pModule) =>
|
|
9
|
+
pRightViolation.cycle.includes(pModule)
|
|
10
|
+
);
|
|
11
|
+
} else {
|
|
12
|
+
lReturnValue =
|
|
13
|
+
pLeftViolation.from === pRightViolation.from &&
|
|
14
|
+
pLeftViolation.to === pRightViolation.to;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return lReturnValue;
|
|
18
|
+
};
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
const _flattenDeep = require("lodash/flattenDeep");
|
|
2
2
|
const _get = require("lodash/get");
|
|
3
|
+
const _uniqWith = require("lodash/uniqWith");
|
|
3
4
|
const { findRuleByName } = require("../../graph-utl/rule-set");
|
|
4
5
|
const compare = require("../../graph-utl/compare");
|
|
5
|
-
const
|
|
6
|
+
const isSameViolation = require("./is-same-violation");
|
|
6
7
|
|
|
7
8
|
function cutNonTransgressions(pSourceEntry) {
|
|
8
9
|
return {
|
|
@@ -129,10 +130,11 @@ function extractModuleViolations(pModules, pRuleSet) {
|
|
|
129
130
|
}
|
|
130
131
|
|
|
131
132
|
module.exports = function summarizeModules(pModules, pRuleSet) {
|
|
132
|
-
const lViolations =
|
|
133
|
+
const lViolations = _uniqWith(
|
|
133
134
|
extractDependencyViolations(pModules, pRuleSet)
|
|
134
135
|
.concat(extractModuleViolations(pModules, pRuleSet))
|
|
135
|
-
.sort(compare.violations)
|
|
136
|
+
.sort(compare.violations),
|
|
137
|
+
isSameViolation
|
|
136
138
|
);
|
|
137
139
|
|
|
138
140
|
return {
|
|
@@ -30,6 +30,9 @@ function extractImportsAndExports(pAST) {
|
|
|
30
30
|
module: pStatement.moduleSpecifier.text,
|
|
31
31
|
moduleSystem: "es6",
|
|
32
32
|
exoticallyRequired: false,
|
|
33
|
+
...(pStatement.importClause && pStatement.importClause.isTypeOnly
|
|
34
|
+
? { dependencyTypes: ["type-only"] }
|
|
35
|
+
: {}),
|
|
33
36
|
}));
|
|
34
37
|
}
|
|
35
38
|
|
|
@@ -162,8 +162,8 @@ function addResolutionAttributes(pOptions, pFileName, pResolveOptions) {
|
|
|
162
162
|
);
|
|
163
163
|
|
|
164
164
|
return {
|
|
165
|
-
...lResolved,
|
|
166
165
|
...pDependency,
|
|
166
|
+
...lResolved,
|
|
167
167
|
followable: lResolved.followable && !lMatchesDoNotFollow,
|
|
168
168
|
matchesDoNotFollow: lMatchesDoNotFollow,
|
|
169
169
|
};
|
|
@@ -196,22 +196,12 @@ function compareDeps(pLeft, pRight) {
|
|
|
196
196
|
*
|
|
197
197
|
*
|
|
198
198
|
* @param {string} pFileName path to the file
|
|
199
|
-
* @param {
|
|
200
|
-
*
|
|
201
|
-
* base for all files
|
|
202
|
-
* Default: the current working directory
|
|
203
|
-
* - moduleSystems - an array of module systems to
|
|
204
|
-
* consider.
|
|
205
|
-
* Default: ["cjs", "es6", "amd"]
|
|
206
|
-
* - exclude - a regular expression string
|
|
207
|
-
* with a pattern of modules to exclude
|
|
208
|
-
* (e.g. "(node_modules)"). Default: none
|
|
209
|
-
* - preserveSymlinks - don't resolve symlinks.
|
|
210
|
-
* @param {object} pResolveOptions an object with webpack 'enhanced-resolve' options
|
|
199
|
+
* @param {import("../../../types/dependency-cruiser").ICruiseOptions} pCruiseOptions cruise options
|
|
200
|
+
* @param {import("../../types/resolve-options").IResolveOptions} pResolveOptions webpack 'enhanced-resolve' options
|
|
211
201
|
* @param {any} pTranspileOptions an object with tsconfig ('typescript project') options
|
|
212
202
|
* ('flattened' so there's no need for file access on any
|
|
213
203
|
* 'extends' option in there)
|
|
214
|
-
* @return {
|
|
204
|
+
* @return {import("../../types/dependency-cruiser").IDependency[]} an array of dependency objects (see above)
|
|
215
205
|
*/
|
|
216
206
|
module.exports = function getDependencies(
|
|
217
207
|
pFileName,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
const path = require("path");
|
|
2
|
+
const { builtinModules } = require("module");
|
|
2
3
|
const _has = require("lodash/has");
|
|
3
4
|
const {
|
|
4
5
|
isRelativeModuleName,
|
|
5
|
-
isCore,
|
|
6
6
|
isExternalModule,
|
|
7
7
|
isAliassy,
|
|
8
8
|
} = require("./module-classifiers");
|
|
@@ -144,7 +144,7 @@ function determineExternalModuleDependencyTypes(
|
|
|
144
144
|
/* eslint max-params:0, complexity:0 */
|
|
145
145
|
/**
|
|
146
146
|
*
|
|
147
|
-
* @param {import("../../../types/cruise-result").
|
|
147
|
+
* @param {import("../../../types/cruise-result").IDependency} pDependency the dependency object with all information found hitherto
|
|
148
148
|
* @param {string} pModuleName the module name as found in the source
|
|
149
149
|
* @param {any} pManifest a package.json, in object format
|
|
150
150
|
* @param {string} pFileDirectory the directory relative to which to resolve (only used for npm deps here)
|
|
@@ -154,7 +154,7 @@ function determineExternalModuleDependencyTypes(
|
|
|
154
154
|
* @return {import("../../../types/shared-types").DependencyType[]} an array of dependency types for the dependency
|
|
155
155
|
*/
|
|
156
156
|
module.exports = function determineDependencyTypes(
|
|
157
|
-
|
|
157
|
+
pDependency,
|
|
158
158
|
pModuleName,
|
|
159
159
|
pManifest,
|
|
160
160
|
pFileDirectory,
|
|
@@ -165,9 +165,9 @@ module.exports = function determineDependencyTypes(
|
|
|
165
165
|
let lReturnValue = ["undetermined"];
|
|
166
166
|
pResolveOptions = pResolveOptions || {};
|
|
167
167
|
|
|
168
|
-
if (
|
|
168
|
+
if (pDependency.couldNotResolve) {
|
|
169
169
|
lReturnValue = ["unknown"];
|
|
170
|
-
} else if (
|
|
170
|
+
} else if (builtinModules.includes(pModuleName)) {
|
|
171
171
|
// this 'isCore' business seems duplicate (it's already in
|
|
172
172
|
// the passed object as `coreModule`- determined by the resolve-AMD or
|
|
173
173
|
// resolve-commonJS module). I want to deprecate the `coreModule`
|
|
@@ -177,21 +177,25 @@ module.exports = function determineDependencyTypes(
|
|
|
177
177
|
} else if (isRelativeModuleName(pModuleName)) {
|
|
178
178
|
lReturnValue = ["local"];
|
|
179
179
|
} else if (
|
|
180
|
-
isExternalModule(
|
|
180
|
+
isExternalModule(
|
|
181
|
+
pDependency.resolved,
|
|
182
|
+
pResolveOptions.modules,
|
|
183
|
+
pBaseDirectory
|
|
184
|
+
)
|
|
181
185
|
) {
|
|
182
186
|
lReturnValue = determineExternalModuleDependencyTypes(
|
|
183
|
-
|
|
187
|
+
pDependency,
|
|
184
188
|
pModuleName,
|
|
185
189
|
pManifest,
|
|
186
190
|
pFileDirectory,
|
|
187
191
|
pResolveOptions,
|
|
188
192
|
pBaseDirectory
|
|
189
193
|
);
|
|
190
|
-
} else if (isAliassy(pModuleName,
|
|
194
|
+
} else if (isAliassy(pModuleName, pDependency.resolved, pResolveOptions)) {
|
|
191
195
|
lReturnValue = ["aliased"];
|
|
192
196
|
}
|
|
193
197
|
|
|
194
|
-
return lReturnValue;
|
|
198
|
+
return lReturnValue.concat(pDependency.dependencyTypes || []);
|
|
195
199
|
};
|
|
196
200
|
|
|
197
201
|
/* eslint security/detect-object-injection: 0*/
|
|
@@ -7,6 +7,8 @@ const { isRelativeModuleName } = require("./module-classifiers");
|
|
|
7
7
|
const resolveAMD = require("./resolve-amd");
|
|
8
8
|
const resolveCommonJS = require("./resolve-cjs");
|
|
9
9
|
const resolveHelpers = require("./resolve-helpers");
|
|
10
|
+
const determineDependencyTypes = require("./determine-dependency-types");
|
|
11
|
+
const getManifest = require("./get-manifest");
|
|
10
12
|
|
|
11
13
|
function resolveModule(
|
|
12
14
|
pModule,
|
|
@@ -16,20 +18,20 @@ function resolveModule(
|
|
|
16
18
|
) {
|
|
17
19
|
let lReturnValue = null;
|
|
18
20
|
|
|
19
|
-
const
|
|
21
|
+
const lStrippedModuleName = resolveHelpers.stripToModuleName(pModule.module);
|
|
20
22
|
if (
|
|
21
|
-
isRelativeModuleName(
|
|
23
|
+
isRelativeModuleName(lStrippedModuleName) ||
|
|
22
24
|
["cjs", "es6", "tsd"].includes(pModule.moduleSystem)
|
|
23
25
|
) {
|
|
24
26
|
lReturnValue = resolveCommonJS(
|
|
25
|
-
|
|
27
|
+
lStrippedModuleName,
|
|
26
28
|
pBaseDirectory,
|
|
27
29
|
pFileDirectory,
|
|
28
30
|
pResolveOptions
|
|
29
31
|
);
|
|
30
32
|
} else {
|
|
31
33
|
lReturnValue = resolveAMD(
|
|
32
|
-
|
|
34
|
+
lStrippedModuleName,
|
|
33
35
|
pBaseDirectory,
|
|
34
36
|
pFileDirectory,
|
|
35
37
|
pResolveOptions
|
|
@@ -48,7 +50,7 @@ function isTypeScriptishExtension(pModuleName) {
|
|
|
48
50
|
function resolveYarnVirtual(pPath) {
|
|
49
51
|
const pnpAPI = get(monkeyPatchedModule, "findPnpApi", () => false)(pPath);
|
|
50
52
|
|
|
51
|
-
// the pnp api only works in plug'n play
|
|
53
|
+
// the pnp api only works in plug'n play environments, and resolveVirtual
|
|
52
54
|
// only under yarn(berry). As we can't run a 'regular' nodejs environment
|
|
53
55
|
// and a yarn(berry) one at the same time, ignore in the test coverage and
|
|
54
56
|
// cover it in a separate integration test.
|
|
@@ -72,7 +74,7 @@ function resolveWithRetry(
|
|
|
72
74
|
pFileDirectory,
|
|
73
75
|
pResolveOptions
|
|
74
76
|
);
|
|
75
|
-
const
|
|
77
|
+
const lStrippedModuleName = resolveHelpers.stripToModuleName(pModule.module);
|
|
76
78
|
|
|
77
79
|
// when we feed the typescript compiler an import with an explicit .js(x) extension
|
|
78
80
|
// and the .js(x) file does not exist, it tries files with the .ts, .tsx or
|
|
@@ -87,8 +89,14 @@ function resolveWithRetry(
|
|
|
87
89
|
//
|
|
88
90
|
// This should eventually probably land in either enhanced_resolve or in a
|
|
89
91
|
// plugin/ extension for it (tsconfig-paths-webpack-plugin?)
|
|
90
|
-
if (
|
|
91
|
-
|
|
92
|
+
if (
|
|
93
|
+
lReturnValue.couldNotResolve &&
|
|
94
|
+
canBeResolvedToTsVariant(lStrippedModuleName)
|
|
95
|
+
) {
|
|
96
|
+
const lModuleWithOutExtension = lStrippedModuleName.replace(
|
|
97
|
+
/\.js(x)?$/g,
|
|
98
|
+
""
|
|
99
|
+
);
|
|
92
100
|
|
|
93
101
|
const lReturnValueCandidate = resolveModule(
|
|
94
102
|
{ ...pModule, module: lModuleWithOutExtension },
|
|
@@ -106,14 +114,13 @@ function resolveWithRetry(
|
|
|
106
114
|
/**
|
|
107
115
|
* resolves the module name of the pDependency to a file on disk.
|
|
108
116
|
*
|
|
109
|
-
* @param {import("../../../types/cruise-result").
|
|
110
|
-
* according to which this is a dependency
|
|
117
|
+
* @param {Partial <import("../../../types/cruise-result").IDependency>} pDependency
|
|
111
118
|
* @param {string} pBaseDirectory the directory to consider as base (or 'root')
|
|
112
119
|
* for resolved files.
|
|
113
120
|
* @param {string} pFileDirectory the directory of the file the dependency was
|
|
114
121
|
* detected in
|
|
115
122
|
* @param {import(../../../types/resolve-options").IResolveOptions} pResolveOptions
|
|
116
|
-
* @return {
|
|
123
|
+
* @return {Partial <import("../../../types/cruise-result").IDependency>} an object with as attributes:
|
|
117
124
|
* - resolved: a string representing the pDependency
|
|
118
125
|
* resolved to a file on disk (or the pDependency
|
|
119
126
|
* name itself when it could not be resolved)
|
|
@@ -128,18 +135,44 @@ function resolveWithRetry(
|
|
|
128
135
|
* - dependencyTypes: an array of dependencyTypes
|
|
129
136
|
*
|
|
130
137
|
*/
|
|
138
|
+
// eslint-disable-next-line max-lines-per-function
|
|
131
139
|
module.exports = function resolve(
|
|
132
|
-
|
|
140
|
+
pDependency,
|
|
133
141
|
pBaseDirectory,
|
|
134
142
|
pFileDirectory,
|
|
135
143
|
pResolveOptions
|
|
136
144
|
) {
|
|
137
145
|
let lResolvedModule = resolveWithRetry(
|
|
138
|
-
|
|
146
|
+
pDependency,
|
|
139
147
|
pBaseDirectory,
|
|
140
148
|
pFileDirectory,
|
|
141
149
|
pResolveOptions
|
|
142
150
|
);
|
|
151
|
+
const lStrippedModuleName = resolveHelpers.stripToModuleName(
|
|
152
|
+
pDependency.module
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
lResolvedModule = {
|
|
156
|
+
...lResolvedModule,
|
|
157
|
+
...resolveHelpers.addLicenseAttribute(
|
|
158
|
+
lStrippedModuleName,
|
|
159
|
+
lResolvedModule.resolved,
|
|
160
|
+
{ baseDirectory: pBaseDirectory, fileDirectory: pFileDirectory },
|
|
161
|
+
pResolveOptions
|
|
162
|
+
),
|
|
163
|
+
dependencyTypes: determineDependencyTypes(
|
|
164
|
+
{ ...pDependency, ...lResolvedModule },
|
|
165
|
+
lStrippedModuleName,
|
|
166
|
+
getManifest(
|
|
167
|
+
pFileDirectory,
|
|
168
|
+
pBaseDirectory,
|
|
169
|
+
pResolveOptions.combinedDependencies
|
|
170
|
+
),
|
|
171
|
+
pFileDirectory,
|
|
172
|
+
pResolveOptions,
|
|
173
|
+
pBaseDirectory
|
|
174
|
+
),
|
|
175
|
+
};
|
|
143
176
|
|
|
144
177
|
if (
|
|
145
178
|
!pResolveOptions.symlinks &&
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
const { builtinModules } = require("module");
|
|
2
1
|
const path = require("path");
|
|
3
2
|
const getExtension = require("../utl/get-extension");
|
|
4
3
|
|
|
@@ -19,10 +18,6 @@ function isRelativeModuleName(pModuleName) {
|
|
|
19
18
|
);
|
|
20
19
|
}
|
|
21
20
|
|
|
22
|
-
function isCore(pModuleName) {
|
|
23
|
-
return builtinModules.includes(pModuleName);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
21
|
function isExternalModule(
|
|
27
22
|
pResolvedModuleName,
|
|
28
23
|
pModuleFolderNames = ["node_modules"],
|
|
@@ -124,7 +119,6 @@ function isAliassy(pModuleName, pResolvedModuleName, pResolveOptions) {
|
|
|
124
119
|
module.exports = {
|
|
125
120
|
isScoped,
|
|
126
121
|
isRelativeModuleName,
|
|
127
|
-
isCore,
|
|
128
122
|
isExternalModule,
|
|
129
123
|
isFollowable,
|
|
130
124
|
isAliassy,
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
const fs = require("fs");
|
|
2
2
|
const path = require("path");
|
|
3
|
+
const { builtinModules } = require("module");
|
|
3
4
|
const memoize = require("lodash/memoize");
|
|
4
5
|
const pathToPosix = require("../utl/path-to-posix");
|
|
5
|
-
const determineDependencyTypes = require("./determine-dependency-types");
|
|
6
|
-
const { isCore } = require("./module-classifiers");
|
|
7
|
-
const getManifest = require("./get-manifest");
|
|
8
|
-
const resolveHelpers = require("./resolve-helpers");
|
|
9
6
|
|
|
10
7
|
const fileExists = memoize((pFile) => {
|
|
11
8
|
try {
|
|
@@ -27,7 +24,7 @@ function guessPath(pBaseDirectory, pFileDirectory, pStrippedModuleName) {
|
|
|
27
24
|
}
|
|
28
25
|
|
|
29
26
|
function guessLikelyPath(pBaseDirectory, pFileDirectory, pStrippedModuleName) {
|
|
30
|
-
|
|
27
|
+
return (
|
|
31
28
|
[".js", ""]
|
|
32
29
|
.map((pExtension) =>
|
|
33
30
|
guessPath(
|
|
@@ -36,16 +33,14 @@ function guessLikelyPath(pBaseDirectory, pFileDirectory, pStrippedModuleName) {
|
|
|
36
33
|
`${pStrippedModuleName}${pExtension}`
|
|
37
34
|
)
|
|
38
35
|
)
|
|
39
|
-
.find(fileExists) || pStrippedModuleName
|
|
40
|
-
|
|
41
|
-
return lReturnValue;
|
|
36
|
+
.find(fileExists) || pStrippedModuleName
|
|
37
|
+
);
|
|
42
38
|
}
|
|
43
39
|
|
|
44
40
|
module.exports = function resolveAMD(
|
|
45
|
-
|
|
41
|
+
pStrippedModuleName,
|
|
46
42
|
pBaseDirectory,
|
|
47
|
-
pFileDirectory
|
|
48
|
-
pResolveOptions
|
|
43
|
+
pFileDirectory
|
|
49
44
|
) {
|
|
50
45
|
// lookups:
|
|
51
46
|
// - [x] could be relative in the end (implemented)
|
|
@@ -53,41 +48,19 @@ module.exports = function resolveAMD(
|
|
|
53
48
|
// - [ ] maybe use mrjoelkemp/module-lookup-amd ?
|
|
54
49
|
// - [ ] or https://github.com/jaredhanson/amd-resolve ?
|
|
55
50
|
// - [x] funky plugins (json!wappie, ./screeching-cat!sabertooth)
|
|
56
|
-
const lModuleName = resolveHelpers.stripToModuleName(pRawModuleName);
|
|
57
51
|
const lResolvedPath = guessLikelyPath(
|
|
58
52
|
pBaseDirectory,
|
|
59
53
|
pFileDirectory,
|
|
60
|
-
|
|
54
|
+
pStrippedModuleName
|
|
61
55
|
);
|
|
62
56
|
|
|
63
|
-
|
|
57
|
+
return {
|
|
64
58
|
resolved: lResolvedPath,
|
|
65
|
-
coreModule:
|
|
59
|
+
coreModule: builtinModules.includes(pStrippedModuleName),
|
|
66
60
|
followable: fileExists(lResolvedPath) && lResolvedPath.endsWith(".js"),
|
|
67
61
|
couldNotResolve:
|
|
68
|
-
!
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
return {
|
|
72
|
-
...lReturnValue,
|
|
73
|
-
...resolveHelpers.addLicenseAttribute(
|
|
74
|
-
lModuleName,
|
|
75
|
-
pBaseDirectory,
|
|
76
|
-
pResolveOptions,
|
|
77
|
-
lReturnValue.resolved
|
|
78
|
-
),
|
|
79
|
-
dependencyTypes: determineDependencyTypes(
|
|
80
|
-
lReturnValue,
|
|
81
|
-
lModuleName,
|
|
82
|
-
getManifest(
|
|
83
|
-
pFileDirectory,
|
|
84
|
-
pBaseDirectory,
|
|
85
|
-
pResolveOptions.combinedDependencies
|
|
86
|
-
),
|
|
87
|
-
pFileDirectory,
|
|
88
|
-
pResolveOptions,
|
|
89
|
-
pBaseDirectory
|
|
90
|
-
),
|
|
62
|
+
!builtinModules.includes(pStrippedModuleName) &&
|
|
63
|
+
!fileExists(lResolvedPath),
|
|
91
64
|
};
|
|
92
65
|
};
|
|
93
66
|
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
const path = require("path");
|
|
2
|
+
const { builtinModules } = require("module");
|
|
2
3
|
const pathToPosix = require("../utl/path-to-posix");
|
|
3
|
-
const
|
|
4
|
-
const { isCore, isFollowable } = require("./module-classifiers");
|
|
5
|
-
const getManifest = require("./get-manifest");
|
|
6
|
-
const resolveHelpers = require("./resolve-helpers");
|
|
4
|
+
const { isFollowable } = require("./module-classifiers");
|
|
7
5
|
const resolve = require("./resolve");
|
|
8
6
|
|
|
9
7
|
function addResolutionAttributes(
|
|
@@ -14,7 +12,7 @@ function addResolutionAttributes(
|
|
|
14
12
|
) {
|
|
15
13
|
let lReturnValue = {};
|
|
16
14
|
|
|
17
|
-
if (
|
|
15
|
+
if (builtinModules.includes(pModuleName)) {
|
|
18
16
|
lReturnValue.coreModule = true;
|
|
19
17
|
} else {
|
|
20
18
|
try {
|
|
@@ -39,47 +37,21 @@ function addResolutionAttributes(
|
|
|
39
37
|
* resolves both CommonJS and ES6
|
|
40
38
|
*/
|
|
41
39
|
module.exports = function resolveCommonJS(
|
|
42
|
-
|
|
40
|
+
pStrippedModuleName,
|
|
43
41
|
pBaseDirectory,
|
|
44
42
|
pFileDirectory,
|
|
45
43
|
pResolveOptions
|
|
46
44
|
) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
pFileDirectory,
|
|
50
|
-
pBaseDirectory,
|
|
51
|
-
pResolveOptions.combinedDependencies
|
|
52
|
-
);
|
|
53
|
-
|
|
54
|
-
let lReturnValue = {
|
|
55
|
-
resolved: lModuleName,
|
|
45
|
+
return {
|
|
46
|
+
resolved: pStrippedModuleName,
|
|
56
47
|
coreModule: false,
|
|
57
48
|
followable: false,
|
|
58
49
|
couldNotResolve: false,
|
|
59
|
-
dependencyTypes: ["undetermined"],
|
|
60
50
|
...addResolutionAttributes(
|
|
61
51
|
pBaseDirectory,
|
|
62
|
-
|
|
52
|
+
pStrippedModuleName,
|
|
63
53
|
pFileDirectory,
|
|
64
54
|
pResolveOptions
|
|
65
55
|
),
|
|
66
56
|
};
|
|
67
|
-
|
|
68
|
-
return {
|
|
69
|
-
...lReturnValue,
|
|
70
|
-
...resolveHelpers.addLicenseAttribute(
|
|
71
|
-
lModuleName,
|
|
72
|
-
lReturnValue.resolved,
|
|
73
|
-
{ baseDirectory: pBaseDirectory, fileDirectory: pFileDirectory },
|
|
74
|
-
pResolveOptions
|
|
75
|
-
),
|
|
76
|
-
dependencyTypes: determineDependencyTypes(
|
|
77
|
-
lReturnValue,
|
|
78
|
-
lModuleName,
|
|
79
|
-
lManifest,
|
|
80
|
-
pFileDirectory,
|
|
81
|
-
pResolveOptions,
|
|
82
|
-
pBaseDirectory
|
|
83
|
-
),
|
|
84
|
-
};
|
|
85
57
|
};
|
package/src/meta.js
CHANGED
|
@@ -116,6 +116,7 @@ module.exports = {
|
|
|
116
116
|
matchesDoNotFollow: { type: "boolean" },
|
|
117
117
|
couldNotResolve: { type: "boolean" },
|
|
118
118
|
preCompilationOnly: { type: "boolean" },
|
|
119
|
+
typeOnly: { type: "boolean" },
|
|
119
120
|
circular: { type: "boolean" },
|
|
120
121
|
cycle: { type: "array", items: { type: "string" } },
|
|
121
122
|
moduleSystem: { $ref: "#/definitions/ModuleSystemType" },
|
|
@@ -143,6 +144,7 @@ module.exports = {
|
|
|
143
144
|
"npm-unknown",
|
|
144
145
|
"undetermined",
|
|
145
146
|
"unknown",
|
|
147
|
+
"type-only",
|
|
146
148
|
],
|
|
147
149
|
},
|
|
148
150
|
ModuleSystemType: { type: "string", enum: ["cjs", "es6", "amd", "tsd"] },
|
|
@@ -41,7 +41,7 @@ function match(pFrom, pTo) {
|
|
|
41
41
|
// is in the rule but not in the dependency there won't be a match
|
|
42
42
|
// anyway, so we can use the default propertyEquals method regardless
|
|
43
43
|
propertyEquals(pTo, pRule, "preCompilationOnly") &&
|
|
44
|
-
// couldNotResolve, circular, dynamic and exoticallyRequired
|
|
44
|
+
// couldNotResolve, circular, dynamic and exoticallyRequired _are_ mandatory
|
|
45
45
|
propertyEquals(pTo, pRule, "couldNotResolve") &&
|
|
46
46
|
propertyEquals(pTo, pRule, "circular") &&
|
|
47
47
|
propertyEquals(pTo, pRule, "dynamic") &&
|
package/types/cruise-result.d.ts
CHANGED
|
@@ -122,6 +122,13 @@ export interface IDependency {
|
|
|
122
122
|
* then only when the option 'tsPreCompilationDeps' has the value 'specify'.
|
|
123
123
|
*/
|
|
124
124
|
preCompilationOnly?: boolean;
|
|
125
|
+
/**
|
|
126
|
+
* 'true' when the module included the module explicitly as type only with the '
|
|
127
|
+
* type' keyword e.g. import type { IThingus } from 'thing' Dependency-cruiser
|
|
128
|
+
* will only specify this attribute for TypeScript and when the 'tsPreCompilationDeps'
|
|
129
|
+
* option has either the value true or 'specify'.
|
|
130
|
+
*/
|
|
131
|
+
typeOnly?: boolean;
|
|
125
132
|
/**
|
|
126
133
|
* If following this dependency will ultimately return to the source (circular === true),
|
|
127
134
|
* this attribute will contain an (ordered) array of module names that shows (one of) the
|
package/types/shared-types.d.ts
CHANGED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
const _uniqWith = require("lodash/uniqWith");
|
|
2
|
-
|
|
3
|
-
function violationIsEqual(pLeftViolation, pRightViolation) {
|
|
4
|
-
let lReturnValue = false;
|
|
5
|
-
if (
|
|
6
|
-
pLeftViolation.rule.name === pRightViolation.rule.name &&
|
|
7
|
-
pLeftViolation.cycle
|
|
8
|
-
) {
|
|
9
|
-
lReturnValue =
|
|
10
|
-
pLeftViolation.cycle.length === pRightViolation.cycle.length &&
|
|
11
|
-
pLeftViolation.cycle.every((pModuleName) =>
|
|
12
|
-
pRightViolation.cycle.includes(pModuleName)
|
|
13
|
-
);
|
|
14
|
-
}
|
|
15
|
-
return lReturnValue;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
module.exports = function deDuplicateViolations(pViolations) {
|
|
19
|
-
return _uniqWith(pViolations, violationIsEqual);
|
|
20
|
-
};
|