dependency-cruiser 11.14.0 → 11.15.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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dependency-cruiser",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.15.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",
|
|
@@ -152,9 +152,11 @@
|
|
|
152
152
|
"glob": "7.2.0",
|
|
153
153
|
"handlebars": "4.7.7",
|
|
154
154
|
"indent-string": "^4.0.0",
|
|
155
|
-
"
|
|
155
|
+
"interpret": "^2.2.0",
|
|
156
156
|
"json5": "2.2.1",
|
|
157
157
|
"lodash": "4.17.21",
|
|
158
|
+
"prompts": "2.4.2",
|
|
159
|
+
"rechoir": "^0.8.0",
|
|
158
160
|
"safe-regex": "2.1.1",
|
|
159
161
|
"semver": "^7.3.7",
|
|
160
162
|
"semver-try-require": "^5.0.2",
|
|
@@ -170,6 +172,7 @@
|
|
|
170
172
|
"@swc/core": "1.2.220",
|
|
171
173
|
"@types/lodash": "4.14.182",
|
|
172
174
|
"@types/node": "18.6.2",
|
|
175
|
+
"@types/prompts": "2.0.14",
|
|
173
176
|
"@typescript-eslint/eslint-plugin": "5.31.0",
|
|
174
177
|
"@typescript-eslint/parser": "5.31.0",
|
|
175
178
|
"@vue/compiler-sfc": "3.2.37",
|
|
@@ -225,14 +228,14 @@
|
|
|
225
228
|
"because": "https://github.com/typicode/husky/issues/822"
|
|
226
229
|
},
|
|
227
230
|
{
|
|
228
|
-
"package": "
|
|
231
|
+
"package": "indent-string",
|
|
229
232
|
"policy": "wanted",
|
|
230
|
-
"because": "version
|
|
233
|
+
"because": "version 5 only exports ejs - and we use cjs and don't transpile"
|
|
231
234
|
},
|
|
232
235
|
{
|
|
233
|
-
"package": "
|
|
236
|
+
"package": "interpret",
|
|
234
237
|
"policy": "wanted",
|
|
235
|
-
"because": "
|
|
238
|
+
"because": "we want to keep interpret ~similar to what webpack-cli is using (which is ^2.2.0)"
|
|
236
239
|
},
|
|
237
240
|
{
|
|
238
241
|
"package": "lint-staged",
|
|
@@ -244,6 +247,11 @@
|
|
|
244
247
|
"policy": "wanted",
|
|
245
248
|
"because": "version 4 only exports ejs - and we use cjs and don't transpile (this only used in unit tests - but one of'em is a cjs one ...)"
|
|
246
249
|
},
|
|
250
|
+
{
|
|
251
|
+
"package": "rechoir",
|
|
252
|
+
"policy": "wanted",
|
|
253
|
+
"because": "we want to keep rechoir ~similar to what webpack-cli is using (which is ^0.7.0, but ^0.8.0 is similar enough and more recent anyway)"
|
|
254
|
+
},
|
|
247
255
|
{
|
|
248
256
|
"package": "wrap-ansi",
|
|
249
257
|
"policy": "wanted",
|
|
@@ -1,141 +1,141 @@
|
|
|
1
|
-
const
|
|
1
|
+
const prompts = require("prompts");
|
|
2
2
|
const {
|
|
3
|
+
isLikelyMonoRepo,
|
|
4
|
+
getMonoRepoPackagesCandidates,
|
|
3
5
|
getSourceFolderCandidates,
|
|
4
6
|
getTestFolderCandidates,
|
|
5
|
-
hasBabelConfigCandidates,
|
|
6
|
-
getBabelConfigCandidates,
|
|
7
7
|
hasJSConfigCandidates,
|
|
8
|
-
getJSConfigCandidates,
|
|
9
8
|
hasTSConfigCandidates,
|
|
9
|
+
hasTestsWithinSource,
|
|
10
|
+
toSourceLocationArray,
|
|
11
|
+
getJSConfigCandidates,
|
|
10
12
|
getTSConfigCandidates,
|
|
13
|
+
hasBabelConfigCandidates,
|
|
14
|
+
getBabelConfigCandidates,
|
|
11
15
|
hasWebpackConfigCandidates,
|
|
12
16
|
getWebpackConfigCandidates,
|
|
13
|
-
getMonoRepoPackagesCandidates,
|
|
14
|
-
hasTestsWithinSource,
|
|
15
|
-
isLikelyMonoRepo,
|
|
16
|
-
toSourceLocationArray,
|
|
17
17
|
} = require("./environment-helpers");
|
|
18
18
|
const { validateLocation } = require("./inquirer-validators");
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
function toPromptChoice(pString) {
|
|
21
|
+
return {
|
|
22
|
+
title: pString,
|
|
23
|
+
value: pString,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** @type {import('@types/prompts').PromptObject[]} */
|
|
28
|
+
const QUESTIONS = [
|
|
21
29
|
{
|
|
22
30
|
name: "isMonoRepo",
|
|
23
|
-
type: "confirm",
|
|
24
|
-
message: "This looks like
|
|
25
|
-
|
|
26
|
-
when: () => isLikelyMonoRepo(),
|
|
31
|
+
type: () => (isLikelyMonoRepo() ? "confirm" : false),
|
|
32
|
+
message: "This looks like mono repo. Is that correct?",
|
|
33
|
+
initial: isLikelyMonoRepo(),
|
|
27
34
|
},
|
|
28
35
|
{
|
|
29
36
|
name: "sourceLocation",
|
|
30
|
-
type: "
|
|
37
|
+
type: (_, pAnswers) => (pAnswers.isMonoRepo ? "text" : false),
|
|
31
38
|
message: "Mono repo it is! Where do your packages live?",
|
|
32
|
-
|
|
39
|
+
initial: getMonoRepoPackagesCandidates(),
|
|
33
40
|
validate: validateLocation,
|
|
34
|
-
when: (pAnswers) => pAnswers.isMonoRepo,
|
|
35
41
|
},
|
|
36
42
|
{
|
|
37
43
|
name: "combinedDependencies",
|
|
38
|
-
type: "confirm",
|
|
44
|
+
type: (_, pAnswers) => (pAnswers.isMonoRepo ? "confirm" : false),
|
|
39
45
|
message:
|
|
40
46
|
"Do your packages use dependencies declared in the root of your repo?",
|
|
41
|
-
|
|
42
|
-
when: (pAnswers) => pAnswers.isMonoRepo,
|
|
47
|
+
initial: false,
|
|
43
48
|
},
|
|
44
49
|
{
|
|
45
50
|
name: "sourceLocation",
|
|
46
|
-
type: "
|
|
51
|
+
type: (_, pAnswers) => (pAnswers.isMonoRepo ? false : "text"),
|
|
47
52
|
message: "Where do your source files live?",
|
|
48
|
-
|
|
53
|
+
initial: getSourceFolderCandidates(),
|
|
49
54
|
validate: validateLocation,
|
|
50
|
-
when: (pAnswers) => !pAnswers.isMonoRepo,
|
|
51
55
|
},
|
|
52
56
|
{
|
|
53
57
|
name: "hasTestsOutsideSource",
|
|
54
|
-
type: "confirm",
|
|
58
|
+
type: (_, pAnswers) => (pAnswers.isMonoRepo ? false : "confirm"),
|
|
55
59
|
message: "Do your test files live in a separate folder?",
|
|
56
|
-
|
|
60
|
+
initial: (_, pAnswers) => {
|
|
57
61
|
return !hasTestsWithinSource(
|
|
58
62
|
getTestFolderCandidates(),
|
|
59
63
|
toSourceLocationArray(pAnswers.sourceLocation)
|
|
60
64
|
);
|
|
61
65
|
},
|
|
62
|
-
when: (pAnswers) => !pAnswers.isMonoRepo,
|
|
63
66
|
},
|
|
64
67
|
{
|
|
65
68
|
name: "testLocation",
|
|
66
|
-
type:
|
|
69
|
+
type: (_, pAnswers) =>
|
|
70
|
+
pAnswers.hasTestsOutsideSource && !pAnswers.isMonoRepo ? "text" : false,
|
|
67
71
|
message: "Where do your test files live?",
|
|
68
|
-
|
|
72
|
+
initial: getTestFolderCandidates(),
|
|
69
73
|
validate: validateLocation,
|
|
70
|
-
when: (pAnswers) => pAnswers.hasTestsOutsideSource && !pAnswers.isMonoRepo,
|
|
71
74
|
},
|
|
72
75
|
{
|
|
73
76
|
name: "useJsConfig",
|
|
74
|
-
type:
|
|
77
|
+
type: () =>
|
|
78
|
+
hasJSConfigCandidates() && !hasTSConfigCandidates() ? "confirm" : false,
|
|
75
79
|
message: "Looks like you're using a 'jsconfig.json'. Use that?",
|
|
76
|
-
|
|
77
|
-
when: () => hasJSConfigCandidates() && !hasTSConfigCandidates(),
|
|
80
|
+
initial: true,
|
|
78
81
|
},
|
|
79
82
|
{
|
|
80
83
|
name: "jsConfig",
|
|
81
|
-
type: "
|
|
82
|
-
message: "Full path to your 'jsconfig.json
|
|
83
|
-
choices: getJSConfigCandidates()
|
|
84
|
-
|
|
84
|
+
type: (_, pAnswers) => (pAnswers.useJsConfig ? "select" : false),
|
|
85
|
+
message: "Full path to your 'jsconfig.json",
|
|
86
|
+
choices: getJSConfigCandidates().map((pCandidate) => ({
|
|
87
|
+
title: pCandidate,
|
|
88
|
+
value: pCandidate,
|
|
89
|
+
})),
|
|
85
90
|
},
|
|
86
91
|
{
|
|
87
92
|
name: "useTsConfig",
|
|
88
|
-
type: "confirm",
|
|
89
|
-
message: "Looks like you're using
|
|
90
|
-
|
|
91
|
-
when: () => hasTSConfigCandidates(),
|
|
93
|
+
type: () => (hasTSConfigCandidates() ? "confirm" : false),
|
|
94
|
+
message: "Looks like you're using a 'tsconfig.json'. Use that?",
|
|
95
|
+
initial: true,
|
|
92
96
|
},
|
|
93
97
|
{
|
|
94
98
|
name: "tsConfig",
|
|
95
|
-
type: "
|
|
96
|
-
message: "Full path to your 'tsconfig.json
|
|
97
|
-
choices: getTSConfigCandidates(),
|
|
98
|
-
when: (pAnswers) => pAnswers.useTsConfig,
|
|
99
|
+
type: (_, pAnswers) => (pAnswers.useTsConfig ? "select" : false),
|
|
100
|
+
message: "Full path to your 'tsconfig.json",
|
|
101
|
+
choices: getTSConfigCandidates().map(toPromptChoice),
|
|
99
102
|
},
|
|
100
103
|
{
|
|
101
104
|
name: "tsPreCompilationDeps",
|
|
102
|
-
type: "confirm",
|
|
105
|
+
type: (_, pAnswers) => (pAnswers.useTsConfig ? "confirm" : false),
|
|
103
106
|
message:
|
|
104
107
|
"Also regard TypeScript dependencies that exist only before compilation?",
|
|
105
|
-
|
|
108
|
+
initial: true,
|
|
106
109
|
},
|
|
107
110
|
{
|
|
108
111
|
name: "useBabelConfig",
|
|
109
|
-
type: "confirm",
|
|
112
|
+
type: () => (hasBabelConfigCandidates() ? "confirm" : false),
|
|
110
113
|
message: "Looks like you're using Babel. Use a babel config?",
|
|
111
|
-
|
|
112
|
-
when: () => hasBabelConfigCandidates(),
|
|
114
|
+
initial: true,
|
|
113
115
|
},
|
|
114
116
|
{
|
|
115
117
|
name: "babelConfig",
|
|
116
|
-
type: "
|
|
118
|
+
type: (_, pAnswers) => (pAnswers.useBabelConfig ? "select" : false),
|
|
117
119
|
message: "Full path to your babel config:",
|
|
118
|
-
choices: getBabelConfigCandidates(),
|
|
119
|
-
when: (pAnswers) => pAnswers.useBabelConfig,
|
|
120
|
+
choices: getBabelConfigCandidates().map(toPromptChoice),
|
|
120
121
|
},
|
|
121
122
|
{
|
|
122
|
-
name: "
|
|
123
|
-
type: "confirm",
|
|
123
|
+
name: "useWebPackConfig",
|
|
124
|
+
type: () => (hasWebpackConfigCandidates() ? "confirm" : false),
|
|
124
125
|
message: "Looks like you're using webpack - specify a webpack config?",
|
|
125
|
-
|
|
126
|
-
when: () => hasWebpackConfigCandidates(),
|
|
126
|
+
initial: true,
|
|
127
127
|
},
|
|
128
128
|
{
|
|
129
129
|
name: "webpackConfig",
|
|
130
|
-
type: "
|
|
130
|
+
type: (_, pAnswers) => (pAnswers.useWebpackConfig ? "select" : false),
|
|
131
131
|
message: "Full path to your webpack config:",
|
|
132
|
-
choices: getWebpackConfigCandidates(),
|
|
133
|
-
when: (pAnswers) => pAnswers.useWebpackConfig,
|
|
132
|
+
choices: getWebpackConfigCandidates().map(toPromptChoice),
|
|
134
133
|
},
|
|
135
134
|
];
|
|
135
|
+
|
|
136
136
|
/**
|
|
137
137
|
* @return {Promise<import("../../../types/init-config").IPartialInitConfig>}
|
|
138
138
|
*/
|
|
139
139
|
module.exports = function getUserInput() {
|
|
140
|
-
return
|
|
140
|
+
return prompts(QUESTIONS);
|
|
141
141
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const { extname } = require("path");
|
|
1
2
|
const makeAbsolute = require("./make-absolute");
|
|
2
3
|
|
|
3
4
|
function pryConfigFromTheConfig(
|
|
@@ -22,6 +23,52 @@ function pryConfigFromTheConfig(
|
|
|
22
23
|
return lReturnValue;
|
|
23
24
|
}
|
|
24
25
|
|
|
26
|
+
function suggestModules(pSuggestionList, pWebpackConfigFilename) {
|
|
27
|
+
let lReturnValue = "";
|
|
28
|
+
let lSuggestionList = pSuggestionList;
|
|
29
|
+
|
|
30
|
+
if (pSuggestionList && typeof pSuggestionList === "string") {
|
|
31
|
+
lSuggestionList = [pSuggestionList];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (Array.isArray(lSuggestionList) && lSuggestionList.length > 0) {
|
|
35
|
+
lReturnValue = lSuggestionList.reduce(
|
|
36
|
+
(pAll, pCurrent) =>
|
|
37
|
+
(pAll += ` - ${pCurrent.module || pCurrent}\n`),
|
|
38
|
+
`\n Some npm modules that might fix that problem (one of which you'll` +
|
|
39
|
+
`\n need so '${pWebpackConfigFilename}' works with webpack anyway):\n`
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
return lReturnValue;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function tryRegisterNonNative(pWebpackConfigFilename) {
|
|
46
|
+
const lConfigExtension = extname(pWebpackConfigFilename);
|
|
47
|
+
|
|
48
|
+
if (lConfigExtension === ".mjs") {
|
|
49
|
+
throw new Error(
|
|
50
|
+
`dependency-cruiser currently does not support webpack configurations in` +
|
|
51
|
+
`\n ES Module format (like '${pWebpackConfigFilename}').\n`
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const interpret = require("interpret");
|
|
56
|
+
const rechoir = require("rechoir");
|
|
57
|
+
|
|
58
|
+
try {
|
|
59
|
+
rechoir.prepare(interpret.extensions, pWebpackConfigFilename);
|
|
60
|
+
} catch (pError) {
|
|
61
|
+
throw new Error(
|
|
62
|
+
`${pError.message}` +
|
|
63
|
+
`\n${suggestModules(
|
|
64
|
+
// eslint-disable-next-line security/detect-object-injection
|
|
65
|
+
interpret.extensions[lConfigExtension],
|
|
66
|
+
pWebpackConfigFilename
|
|
67
|
+
)}`
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
25
72
|
/**
|
|
26
73
|
* Reads the file with name `pWebpackConfigFilename` and (applying the
|
|
27
74
|
* environment `pEnvironment` and the arguments `pArguments` (which can
|
|
@@ -35,16 +82,23 @@ function pryConfigFromTheConfig(
|
|
|
35
82
|
* @throws {Error} when the webpack config isn't usable (e.g. because it
|
|
36
83
|
* doesn't exist, or because it's invalid)
|
|
37
84
|
*/
|
|
85
|
+
// eslint-disable-next-line max-lines-per-function, complexity
|
|
38
86
|
module.exports = function extractWebpackResolveConfig(
|
|
39
87
|
pWebpackConfigFilename,
|
|
40
88
|
pEnvironment,
|
|
41
89
|
pArguments
|
|
42
90
|
) {
|
|
43
91
|
let lReturnValue = {};
|
|
92
|
+
const lNativelySupportedExtensions = [".js", ".cjs", ".json", ".node"];
|
|
93
|
+
const lWebpackConfigFilename = makeAbsolute(pWebpackConfigFilename);
|
|
94
|
+
|
|
95
|
+
if (!lNativelySupportedExtensions.includes(extname(pWebpackConfigFilename))) {
|
|
96
|
+
tryRegisterNonNative(pWebpackConfigFilename);
|
|
97
|
+
}
|
|
44
98
|
|
|
45
99
|
try {
|
|
46
100
|
/* eslint node/global-require:0, security/detect-non-literal-require:0, import/no-dynamic-require:0 */
|
|
47
|
-
const lWebpackConfigModule = require(
|
|
101
|
+
const lWebpackConfigModule = require(lWebpackConfigFilename);
|
|
48
102
|
const lWebpackConfig = pryConfigFromTheConfig(
|
|
49
103
|
lWebpackConfigModule,
|
|
50
104
|
pEnvironment,
|
|
@@ -7,7 +7,7 @@ export interface ITranspilerWrapper {
|
|
|
7
7
|
) => string;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
export
|
|
10
|
+
export function getWrapper(pExtension, pTranspileOptions): ITranspilerWrapper;
|
|
11
11
|
|
|
12
12
|
export const scannableExtensions: string[];
|
|
13
13
|
|
|
@@ -19,4 +19,4 @@ export interface IAvailableTranspiler {
|
|
|
19
19
|
available: boolean;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
export
|
|
22
|
+
export function getAvailableTranspilers(): IAvailableTranspiler[];
|
package/src/meta.js
CHANGED
package/src/validate/index.d.ts
CHANGED
|
@@ -34,27 +34,27 @@ export interface IValidationResult {
|
|
|
34
34
|
* Validates the pModule module against the given
|
|
35
35
|
* ruleset pRuleSet
|
|
36
36
|
*/
|
|
37
|
-
export
|
|
37
|
+
export function module(
|
|
38
38
|
pRuleSet: IFlattenedRuleSet,
|
|
39
39
|
pModule: IModule
|
|
40
|
-
)
|
|
40
|
+
): IValidationResult;
|
|
41
41
|
|
|
42
42
|
/**
|
|
43
43
|
* Validates the pFrom and pTo dependency pair against the given
|
|
44
44
|
* ruleset pRuleSet
|
|
45
45
|
*/
|
|
46
|
-
export
|
|
46
|
+
export function dependency(
|
|
47
47
|
pRuleSet: IFlattenedRuleSet,
|
|
48
48
|
pFrom: IModule,
|
|
49
49
|
pTo: IDependency
|
|
50
|
-
)
|
|
50
|
+
): IValidationResult;
|
|
51
51
|
|
|
52
52
|
/**
|
|
53
53
|
* Validates the pFrom and pTo dependency pair against the given
|
|
54
54
|
* ruleset pRuleSet
|
|
55
55
|
*/
|
|
56
|
-
export
|
|
56
|
+
export function folder(
|
|
57
57
|
pRuleSet: IFlattenedRuleSet,
|
|
58
58
|
pFromFolder: IFolder,
|
|
59
59
|
pToFolder: IFolderDependency
|
|
60
|
-
)
|
|
60
|
+
): IValidationResult;
|
|
@@ -73,12 +73,12 @@ export interface IReporterOutput {
|
|
|
73
73
|
* before calling make sure to flatten them out if you want them
|
|
74
74
|
* used (e.g. with 'dependency-cruiser/config-utl/extract-ts-config')
|
|
75
75
|
*/
|
|
76
|
-
export
|
|
76
|
+
export function cruise(
|
|
77
77
|
pFileAndDirectoryArray: string[],
|
|
78
78
|
pCruiseOptions?: ICruiseOptions,
|
|
79
79
|
pResolveOptions?: IResolveOptions,
|
|
80
80
|
pTSConfig?: any
|
|
81
|
-
)
|
|
81
|
+
): IReporterOutput;
|
|
82
82
|
|
|
83
83
|
export interface ITranspileOptions {
|
|
84
84
|
/**
|
|
@@ -113,12 +113,12 @@ export interface ITranspileOptions {
|
|
|
113
113
|
* @param pTranspileOptions Object to hold options to pass to underlying transpilers
|
|
114
114
|
* like TypeScript or Babel
|
|
115
115
|
*/
|
|
116
|
-
export
|
|
116
|
+
export function futureCruise(
|
|
117
117
|
pFileAndDirectoryArray: string[],
|
|
118
118
|
pCruiseOptions?: ICruiseOptions,
|
|
119
119
|
pResolveOptions?: IResolveOptions,
|
|
120
120
|
pTranspileOptions?: ITranspileOptions
|
|
121
|
-
)
|
|
121
|
+
): IReporterOutput;
|
|
122
122
|
|
|
123
123
|
/**
|
|
124
124
|
* Given a cruise result, formats it with the given reporter (pOutputType)
|
|
@@ -127,10 +127,10 @@ export type futureCruise = (
|
|
|
127
127
|
* to the [dependency-cruiser results schema](https://github.com/sverweij/dependency-cruiser/blob/develop/src/schema/cruise-result.json)
|
|
128
128
|
* @param pOutputType Which reporter to use to format the cruise result with
|
|
129
129
|
*/
|
|
130
|
-
export
|
|
130
|
+
export function format(
|
|
131
131
|
pResult: ICruiseResult,
|
|
132
132
|
pFormatOptions: IFormatOptions
|
|
133
|
-
)
|
|
133
|
+
): IReporterOutput;
|
|
134
134
|
|
|
135
135
|
/**
|
|
136
136
|
* Returns an array of supported transpilers and for each of the transpilers
|
|
@@ -138,4 +138,4 @@ export type format = (
|
|
|
138
138
|
* - the supported version range (semver version range)
|
|
139
139
|
* - whether or not the transpiler is available in the current environment
|
|
140
140
|
*/
|
|
141
|
-
export
|
|
141
|
+
export function getAvailableTranspilers(): IAvailableTranspiler[];
|