dependency-cruiser 12.1.0 → 12.2.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/README.md +1 -1
- package/configs/plugins/3d-reporter-plugin.js +3 -3
- package/configs/plugins/stats-reporter-plugin.js +3 -3
- package/package.json +26 -29
- package/src/cache/cache.js +4 -4
- package/src/cache/revision-data.js +13 -6
- package/src/cache/utl.js +1 -0
- package/src/cli/format.js +2 -2
- package/src/cli/index.js +9 -10
- package/src/cli/init-config/build-config.js +2 -2
- package/src/cli/init-config/environment-helpers.js +6 -3
- package/src/cli/init-config/get-user-input.js +2 -2
- package/src/cli/init-config/index.js +15 -8
- package/src/cli/init-config/{inquirer-validators.js → validators.js} +1 -9
- package/src/cli/init-config/write-config.js +1 -1
- package/src/cli/listeners/performance-log/format-helpers.js +75 -15
- package/src/cli/listeners/performance-log/handlers.js +32 -14
- package/src/cli/listeners/performance-log/index.js +6 -0
- package/src/config-utl/extract-depcruise-config/index.js +12 -9
- package/src/config-utl/extract-depcruise-config/read-config.js +1 -1
- package/src/config-utl/extract-webpack-resolve-config.js +1 -2
- package/src/config-utl/make-absolute.js +1 -1
- package/src/enrich/add-validations.js +1 -1
- package/src/enrich/derive/circular/get-cycle.js +3 -4
- package/src/enrich/derive/folders/index.js +3 -3
- package/src/enrich/derive/orphan/index.js +3 -2
- package/src/enrich/derive/orphan/is-orphan.js +1 -1
- package/src/enrich/derive/reachable/index.js +1 -1
- package/src/enrich/index.js +3 -3
- package/src/enrich/summarize/index.js +1 -1
- package/src/extract/ast-extractors/swc-dependency-visitor.js +1 -1
- package/src/extract/gather-initial-sources.js +1 -1
- package/src/extract/get-dependencies.js +14 -21
- package/src/extract/index.js +4 -4
- package/src/extract/resolve/determine-dependency-types.js +6 -6
- package/src/extract/resolve/index.js +2 -2
- package/src/graph-utl/add-focus.js +1 -1
- package/src/graph-utl/consolidate-module-dependencies.js +6 -4
- package/src/graph-utl/consolidate-modules.js +1 -1
- package/src/graph-utl/consolidate-to-folder.js +3 -2
- package/src/graph-utl/rule-set.js +3 -3
- package/src/main/index.js +4 -4
- package/src/main/options/normalize.js +6 -6
- package/src/main/options/validate.js +2 -2
- package/src/main/report-wrap.js +6 -6
- package/src/main/resolve-options/normalize.js +4 -4
- package/src/main/rule-set/normalize.js +1 -1
- package/src/meta.js +1 -1
- package/src/report/anon/index.js +1 -1
- package/src/report/baseline.js +12 -10
- package/src/report/csv.js +7 -5
- package/src/report/dot/index.js +12 -10
- package/src/report/dot/module-utl.js +2 -2
- package/src/report/dot/prepare-custom-level.js +6 -1
- package/src/report/dot/prepare-flat-level.js +1 -1
- package/src/report/dot/prepare-folder-level.js +6 -1
- package/src/report/error-html/index.js +7 -5
- package/src/report/error-html/utl.js +5 -5
- package/src/report/error.js +10 -8
- package/src/report/html/index.js +7 -5
- package/src/report/identity.js +7 -5
- package/src/report/json.js +7 -5
- package/src/report/markdown.js +9 -7
- package/src/report/mermaid.js +14 -11
- package/src/report/metrics.js +7 -8
- package/src/report/{plugins/index.js → plugins.js} +5 -2
- package/src/report/teamcity.js +5 -5
- package/src/report/text.js +7 -5
- package/src/report/utl/dependency-to-incidence-transformer.js +3 -2
- package/src/report/utl/index.js +4 -5
- package/src/validate/match-dependency-rule.js +2 -2
- package/types/README.md +1 -0
- package/types/init-config.d.ts +8 -11
package/README.md
CHANGED
|
@@ -154,7 +154,7 @@ You've come to the right place :-) :
|
|
|
154
154
|
|
|
155
155
|
## Build status
|
|
156
156
|
|
|
157
|
-
[](https://github.com/sverweij/dependency-cruiser/actions/workflows/ci.yml)
|
|
158
158
|
[](https://gitlab.com/sverweij/dependency-cruiser/builds)
|
|
159
159
|
[](https://codeclimate.com/github/sverweij/dependency-cruiser/maintainability)
|
|
160
160
|
[](https://codeclimate.com/github/sverweij/dependency-cruiser/test_coverage)
|
|
@@ -81,7 +81,7 @@ function formatDependency(pFrom, pTo) {
|
|
|
81
81
|
|
|
82
82
|
/**
|
|
83
83
|
*
|
|
84
|
-
* @param {import('
|
|
84
|
+
* @param {import('../..').ICruiseResult} pCruiseResult
|
|
85
85
|
*/
|
|
86
86
|
function render3DThing(pCruiseResult) {
|
|
87
87
|
const lNodes = pCruiseResult.modules.map((pModule) => {
|
|
@@ -114,10 +114,10 @@ function render3DThing(pCruiseResult) {
|
|
|
114
114
|
/**
|
|
115
115
|
* Sample plugin: 3d representation
|
|
116
116
|
*
|
|
117
|
-
* @param {import('
|
|
117
|
+
* @param {import('../..').ICruiseResult} pCruiseResult -
|
|
118
118
|
* the output of a dependency-cruise adhering to dependency-cruiser's
|
|
119
119
|
* cruise result schema
|
|
120
|
-
* @return {import('
|
|
120
|
+
* @return {import('../..').IReporterOutput} -
|
|
121
121
|
* output: a string
|
|
122
122
|
* exitCode: 0
|
|
123
123
|
*/
|
|
@@ -33,7 +33,7 @@ function doMagic(pCruiseResult) {
|
|
|
33
33
|
* returns an object with some stats from the ICruiseResult pCruiseResult it
|
|
34
34
|
* got passed
|
|
35
35
|
*
|
|
36
|
-
* @param {import('
|
|
36
|
+
* @param {import('../..').ICruiseResult} pCruiseResult - a result from a cruise.
|
|
37
37
|
* @return {string} an object with some stats
|
|
38
38
|
*/
|
|
39
39
|
function samplePluginReporter(pCruiseResult) {
|
|
@@ -65,10 +65,10 @@ function samplePluginReporter(pCruiseResult) {
|
|
|
65
65
|
/**
|
|
66
66
|
* Sample plugin
|
|
67
67
|
*
|
|
68
|
-
* @param {import('
|
|
68
|
+
* @param {import('../..').ICruiseResult} pCruiseResult -
|
|
69
69
|
* the output of a dependency-cruise adhering to dependency-cruiser's
|
|
70
70
|
* cruise result schema
|
|
71
|
-
* @return {import('
|
|
71
|
+
* @return {import('../..').IReporterOutput} -
|
|
72
72
|
* output: some stats on modules and dependencies in json format
|
|
73
73
|
* exitCode: 0
|
|
74
74
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dependency-cruiser",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.2.0",
|
|
4
4
|
"description": "Validate and visualize dependencies. With your rules. JavaScript, TypeScript, CoffeeScript. ES6, CommonJS, AMD.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"static analysis",
|
|
@@ -87,6 +87,8 @@
|
|
|
87
87
|
"depcruise:graph:doc:samples": "sh tools/generate-samples.sh",
|
|
88
88
|
"depcruise:graph:dot": "node ./bin/dependency-cruise.js bin src --config --output-type dot | dot -T svg > tmp_deps.svg",
|
|
89
89
|
"depcruise:graph:fdp": "node ./bin/dependency-cruise.js bin src --config --output-type dot | fdp -GK=0.1 -Gsplines=true -T svg > tmp_deps.svg",
|
|
90
|
+
"depcruise:graph:mermaid": "node ./bin/dependency-cruise.js bin src --include-only ^src/ --config --collapse 2 --output-type mermaid",
|
|
91
|
+
"depcruise:graph:mermaid:diff": "node ./bin/dependency-cruise.js bin src test types tools --config configs/.dependency-cruiser-unlimited.json --output-type mermaid --reaches \"$(watskeburt $SHA)\"",
|
|
90
92
|
"depcruise:graph:osage": "node ./bin/dependency-cruise.js bin src --config --output-type dot | osage -Gpack=32 -GpackMode=array2 -T svg > tmp_deps.svg",
|
|
91
93
|
"depcruise:graph:view": "node ./bin/dependency-cruise.js bin src --prefix vscode://file/$(pwd)/ --config configs/.dependency-cruiser-show-metrics-config.json --output-type dot --progress cli-feedback --highlight \"$(watskeburt develop)\" | dot -T svg | node ./bin/wrap-stream-in-html.js | browser",
|
|
92
94
|
"depcruise:graph:view:diff": "node ./bin/dependency-cruise.js bin src test --prefix vscode://file/$(pwd)/ --config configs/.dependency-cruiser-unlimited.json --output-type dot --progress cli-feedback --reaches \"$(watskeburt develop)\" | dot -T svg | node ./bin/wrap-stream-in-html.js | browser",
|
|
@@ -116,11 +118,11 @@
|
|
|
116
118
|
"scm:push:gitlab-mirror:commits": "git push gitlab-mirror",
|
|
117
119
|
"scm:push:gitlab-mirror:tags": "git push --tags gitlab-mirror",
|
|
118
120
|
"scm:stage": "git add .",
|
|
119
|
-
"test": "mocha",
|
|
120
|
-
"test:i": "mocha --grep \"^\\[[I]\\]\"",
|
|
121
|
-
"test:u": "mocha --grep \"^\\[[U]\\]\"",
|
|
122
|
-
"test:e": "mocha --grep \"^\\[[E]\\]\"",
|
|
123
|
-
"test:cover": "c8 --check-coverage --statements 99.9 --branches 99.7 --functions 100 --lines 99.9 --exclude \"{bin,configs/*.js,configs/rules,configs/plugins/3d-*.js,configs/plugins/stats-*.js,doc,docs,coverage,test,tools,webpack.conf.js,tmp*,src/**/*.template.js,src/cli/tools/svg-in-html-snippets/script.snippet.js,src/cli/init-config/get-user-input.js,src/cli/listeners/*/index.js}\" --reporter text-summary --reporter html --reporter json-summary mocha",
|
|
121
|
+
"test": "LANG=en_US.UTF-8 mocha",
|
|
122
|
+
"test:i": "LANG=en_US.UTF-8 mocha --grep \"^\\[[I]\\]\"",
|
|
123
|
+
"test:u": "LANG=en_US.UTF-8 mocha --grep \"^\\[[U]\\]\"",
|
|
124
|
+
"test:e": "LANG=en_US.UTF-8 mocha --grep \"^\\[[E]\\]\"",
|
|
125
|
+
"test:cover": "LANG=en_US.UTF-8 c8 --check-coverage --statements 99.9 --branches 99.7 --functions 100 --lines 99.9 --exclude \"{bin,configs/*.js,configs/rules,configs/plugins/3d-*.js,configs/plugins/stats-*.js,doc,docs,coverage,test,tools,webpack.conf.js,tmp*,src/**/*.template.js,src/cli/tools/svg-in-html-snippets/script.snippet.js,src/cli/init-config/get-user-input.js,src/cli/listeners/*/index.js}\" --reporter text-summary --reporter html --reporter json-summary mocha",
|
|
124
126
|
"test:glob": "set -f && test \"`bin/dependency-cruise.js test/extract/__mocks__/gather-globbing/packages/**/src/**/*.js | grep \"no dependency violations found\"`\" = \"✔ no dependency violations found (6 modules, 0 dependencies cruised)\"",
|
|
125
127
|
"test:yarn-pnp": "npm-run-all test:yarn-pnp:cleanup test:yarn-pnp:pack test:yarn-pnp:copy test:yarn-pnp:install test:yarn-pnp:version test:yarn-pnp:run test:yarn-pnp:test test:yarn-pnp:cleanup",
|
|
126
128
|
"test:yarn-pnp:pack": "npm pack",
|
|
@@ -154,9 +156,9 @@
|
|
|
154
156
|
"glob": "7.2.0",
|
|
155
157
|
"handlebars": "4.7.7",
|
|
156
158
|
"indent-string": "^4.0.0",
|
|
157
|
-
"interpret": "^
|
|
159
|
+
"interpret": "^3.1.0",
|
|
158
160
|
"is-installed-globally": "0.4.0",
|
|
159
|
-
"json5": "2.2.
|
|
161
|
+
"json5": "2.2.2",
|
|
160
162
|
"lodash": "4.17.21",
|
|
161
163
|
"prompts": "2.4.2",
|
|
162
164
|
"rechoir": "^0.8.0",
|
|
@@ -169,21 +171,21 @@
|
|
|
169
171
|
"wrap-ansi": "^7.0.0"
|
|
170
172
|
},
|
|
171
173
|
"devDependencies": {
|
|
172
|
-
"@babel/core": "7.20.
|
|
173
|
-
"@babel/plugin-transform-modules-commonjs": "7.
|
|
174
|
+
"@babel/core": "7.20.7",
|
|
175
|
+
"@babel/plugin-transform-modules-commonjs": "7.20.11",
|
|
174
176
|
"@babel/preset-typescript": "7.18.6",
|
|
175
|
-
"@swc/core": "1.3.
|
|
176
|
-
"@types/lodash": "4.14.
|
|
177
|
-
"@types/node": "18.11.
|
|
178
|
-
"@types/prompts": "2.4.
|
|
179
|
-
"@typescript-eslint/eslint-plugin": "5.
|
|
180
|
-
"@typescript-eslint/parser": "5.
|
|
177
|
+
"@swc/core": "1.3.24",
|
|
178
|
+
"@types/lodash": "4.14.191",
|
|
179
|
+
"@types/node": "18.11.17",
|
|
180
|
+
"@types/prompts": "2.4.2",
|
|
181
|
+
"@typescript-eslint/eslint-plugin": "5.47.0",
|
|
182
|
+
"@typescript-eslint/parser": "5.47.0",
|
|
181
183
|
"@vue/compiler-sfc": "3.2.45",
|
|
182
184
|
"c8": "7.12.0",
|
|
183
185
|
"chai": "4.3.7",
|
|
184
186
|
"chai-json-schema": "1.5.1",
|
|
185
187
|
"coffeescript": "2.7.0",
|
|
186
|
-
"eslint": "8.
|
|
188
|
+
"eslint": "8.30.0",
|
|
187
189
|
"eslint-config-moving-meadow": "4.0.2",
|
|
188
190
|
"eslint-config-prettier": "8.5.0",
|
|
189
191
|
"eslint-plugin-budapestian": "5.0.1",
|
|
@@ -195,16 +197,16 @@
|
|
|
195
197
|
"eslint-plugin-unicorn": "^45.0.0",
|
|
196
198
|
"husky": "8.0.2",
|
|
197
199
|
"intercept-stdout": "0.1.2",
|
|
198
|
-
"lint-staged": "
|
|
199
|
-
"mocha": "10.
|
|
200
|
+
"lint-staged": "13.1.0",
|
|
201
|
+
"mocha": "10.2.0",
|
|
200
202
|
"normalize-newline": "^3.0.0",
|
|
201
203
|
"npm-run-all": "4.1.5",
|
|
202
|
-
"prettier": "2.8.
|
|
204
|
+
"prettier": "2.8.1",
|
|
203
205
|
"proxyquire": "2.1.3",
|
|
204
206
|
"shx": "0.3.4",
|
|
205
|
-
"svelte": "3.
|
|
207
|
+
"svelte": "3.55.0",
|
|
206
208
|
"symlink-dir": "5.1.0",
|
|
207
|
-
"typescript": "4.9.
|
|
209
|
+
"typescript": "4.9.4",
|
|
208
210
|
"upem": "7.3.1",
|
|
209
211
|
"vue-template-compiler": "2.7.14",
|
|
210
212
|
"yarn": "1.22.19"
|
|
@@ -234,12 +236,7 @@
|
|
|
234
236
|
{
|
|
235
237
|
"package": "interpret",
|
|
236
238
|
"policy": "wanted",
|
|
237
|
-
"because": "we want to keep interpret ~similar to what webpack-cli uses (which is ^
|
|
238
|
-
},
|
|
239
|
-
{
|
|
240
|
-
"package": "lint-staged",
|
|
241
|
-
"policy": "pin",
|
|
242
|
-
"because": "12.3.5 fails with SyntaxError: Unexpected token o in JSON at position 1"
|
|
239
|
+
"because": "we want to keep interpret ~similar to what webpack-cli uses (which is ^3.1.0 since 2022-11-15)"
|
|
243
240
|
},
|
|
244
241
|
{
|
|
245
242
|
"package": "normalize-newline",
|
|
@@ -249,7 +246,7 @@
|
|
|
249
246
|
{
|
|
250
247
|
"package": "rechoir",
|
|
251
248
|
"policy": "wanted",
|
|
252
|
-
"because": "we want to keep rechoir ~similar to what webpack-cli uses (which is ^0.
|
|
249
|
+
"because": "we want to keep rechoir ~similar to what webpack-cli uses (which is ^0.8.0 since 2022-11-15))"
|
|
253
250
|
},
|
|
254
251
|
{
|
|
255
252
|
"package": "wrap-ansi",
|
package/src/cache/cache.js
CHANGED
|
@@ -21,7 +21,7 @@ function writeCache(pCacheFolder, pCruiseResult) {
|
|
|
21
21
|
/**
|
|
22
22
|
*
|
|
23
23
|
* @param {string} pCacheFolder
|
|
24
|
-
* @returns {import("
|
|
24
|
+
* @returns {import("../..").ICruiseResult}
|
|
25
25
|
*/
|
|
26
26
|
function readCache(pCacheFolder) {
|
|
27
27
|
try {
|
|
@@ -36,11 +36,11 @@ function readCache(pCacheFolder) {
|
|
|
36
36
|
/**
|
|
37
37
|
*
|
|
38
38
|
* @param {import("../../types/strict-options").IStrictCruiseOptions} pOptions
|
|
39
|
-
* @param {import("
|
|
40
|
-
* @returns
|
|
39
|
+
* @param {import("../..").IRevisionData} pRevisionData
|
|
40
|
+
* @returns {boolean}
|
|
41
41
|
*/
|
|
42
42
|
function canServeFromCache(pOptions, pRevisionData) {
|
|
43
|
-
/** @type {import("
|
|
43
|
+
/** @type {import("../..").ICruiseResult} */
|
|
44
44
|
const lCachedResults = readCache(pOptions.cache);
|
|
45
45
|
|
|
46
46
|
return (
|
|
@@ -36,10 +36,18 @@ function isInterestingChangeType(pInterestingChangeTypes) {
|
|
|
36
36
|
return (pChange) => pInterestingChangeTypes.has(pChange.changeType);
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
+
/**
|
|
40
|
+
* @param {string} pString
|
|
41
|
+
* @returns {string}
|
|
42
|
+
*/
|
|
39
43
|
function hash(pString) {
|
|
40
44
|
return createHash("sha1").update(pString).digest("base64");
|
|
41
45
|
}
|
|
42
46
|
|
|
47
|
+
/**
|
|
48
|
+
* @param {import("fs").PathOrFileDescriptor} pFileName
|
|
49
|
+
* @returns {string}
|
|
50
|
+
*/
|
|
43
51
|
function getFileHash(pFileName) {
|
|
44
52
|
try {
|
|
45
53
|
return hash(readFileSync(pFileName, "utf8"));
|
|
@@ -50,7 +58,7 @@ function getFileHash(pFileName) {
|
|
|
50
58
|
|
|
51
59
|
/**
|
|
52
60
|
* @param {import("watskeburt").IChange} pChange
|
|
53
|
-
* @param {import("
|
|
61
|
+
* @param {import("../..").IRevisionChange}
|
|
54
62
|
*/
|
|
55
63
|
function addChecksum(pChange) {
|
|
56
64
|
return {
|
|
@@ -66,8 +74,8 @@ function addChecksum(pChange) {
|
|
|
66
74
|
* @param {Object} pOptions
|
|
67
75
|
* @param {() => string} pOptions.shaRetrievalFn
|
|
68
76
|
* @param {(pString:string) => Array<import("watskeburt").IChange>} pOptions.diffListFn
|
|
69
|
-
* @param {(import("watskeburt").IChange) => import("
|
|
70
|
-
* @returns {import("
|
|
77
|
+
* @param {(import("watskeburt").IChange) => import("../..").IRevisionChange} pOptions.checkSumFn
|
|
78
|
+
* @returns {import("../..").IRevisionData}
|
|
71
79
|
*/
|
|
72
80
|
function getRevisionData(
|
|
73
81
|
pExtensions,
|
|
@@ -100,9 +108,8 @@ function getRevisionData(
|
|
|
100
108
|
}
|
|
101
109
|
|
|
102
110
|
/**
|
|
103
|
-
*
|
|
104
|
-
* @param {import("
|
|
105
|
-
* @param {import("../../types/cruise-result").IRevisionData} pNewRevisionData
|
|
111
|
+
* @param {import("../..").IRevisionData} pExistingRevisionData
|
|
112
|
+
* @param {import("../..").IRevisionData} pNewRevisionData
|
|
106
113
|
* @returns {boolean}
|
|
107
114
|
*/
|
|
108
115
|
function revisionDataEqual(pExistingRevisionData, pNewRevisionData) {
|
package/src/cache/utl.js
CHANGED
package/src/cli/format.js
CHANGED
|
@@ -7,10 +7,10 @@ const io = require("./utl/io");
|
|
|
7
7
|
/**
|
|
8
8
|
*
|
|
9
9
|
* @param {string} pResultFile the name of the file with cruise results
|
|
10
|
-
* @param {import("
|
|
10
|
+
* @param {import("../..").IFormatOptions} pOptions
|
|
11
11
|
* @returns {Number} an exitCode
|
|
12
12
|
*/
|
|
13
|
-
module.exports = async (pResultFile, pOptions)
|
|
13
|
+
module.exports = async function format(pResultFile, pOptions) {
|
|
14
14
|
const lOptions = normalizeOptions(pOptions);
|
|
15
15
|
|
|
16
16
|
if (pResultFile !== "-") {
|
package/src/cli/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const path = require("path");
|
|
2
2
|
const glob = require("glob");
|
|
3
|
-
const
|
|
3
|
+
const cloneDeep = require("lodash/cloneDeep");
|
|
4
4
|
const set = require("lodash/set");
|
|
5
5
|
const isInstalledGlobally = require("is-installed-globally");
|
|
6
6
|
const { red, yellow, bold } = require("chalk");
|
|
@@ -42,7 +42,7 @@ function addKnownViolations(pCruiseOptions) {
|
|
|
42
42
|
|
|
43
43
|
// Check against json schema is already done in src/main/options/validate
|
|
44
44
|
// so here we can just concentrate on the io
|
|
45
|
-
let lCruiseOptions =
|
|
45
|
+
let lCruiseOptions = cloneDeep(pCruiseOptions);
|
|
46
46
|
set(lCruiseOptions, "ruleSet.options.knownViolations", lKnownViolations);
|
|
47
47
|
return lCruiseOptions;
|
|
48
48
|
}
|
|
@@ -119,7 +119,6 @@ function runCruise(pFileDirectoryArray, pCruiseOptions) {
|
|
|
119
119
|
bus.emit("progress", "cli: writing results");
|
|
120
120
|
bus.emit("write-start");
|
|
121
121
|
io.write(lCruiseOptions.outputTo, lReportingResult.output);
|
|
122
|
-
bus.emit("end");
|
|
123
122
|
|
|
124
123
|
return lReportingResult.exitCode;
|
|
125
124
|
}
|
|
@@ -127,11 +126,11 @@ function runCruise(pFileDirectoryArray, pCruiseOptions) {
|
|
|
127
126
|
/**
|
|
128
127
|
*
|
|
129
128
|
* @param {string[]} pFileDirectoryArray
|
|
130
|
-
* @param {import("../../types/options").ICruiseOptions}
|
|
129
|
+
* @param {import("../../types/options").ICruiseOptions} lCruiseOptions
|
|
131
130
|
* @returns {number}
|
|
132
131
|
*/
|
|
133
132
|
module.exports = function executeCli(pFileDirectoryArray, pCruiseOptions) {
|
|
134
|
-
|
|
133
|
+
let lCruiseOptions = pCruiseOptions || {};
|
|
135
134
|
let lExitCode = 0;
|
|
136
135
|
|
|
137
136
|
try {
|
|
@@ -150,9 +149,9 @@ module.exports = function executeCli(pFileDirectoryArray, pCruiseOptions) {
|
|
|
150
149
|
);
|
|
151
150
|
}
|
|
152
151
|
/* c8 ignore stop */
|
|
153
|
-
if (
|
|
152
|
+
if (lCruiseOptions.info === true) {
|
|
154
153
|
process.stdout.write(formatMetaInfo());
|
|
155
|
-
} else if (
|
|
154
|
+
} else if (lCruiseOptions.init) {
|
|
156
155
|
// requiring init-config took ~100ms (most of it taken up by requiring
|
|
157
156
|
// inquirer, measured on a 2.6GHz quad core i7 with flash storage on
|
|
158
157
|
// macOS 10.15.7). Only requiring it when '--init' is necessary speeds up
|
|
@@ -161,15 +160,15 @@ module.exports = function executeCli(pFileDirectoryArray, pCruiseOptions) {
|
|
|
161
160
|
// holds.
|
|
162
161
|
// eslint-disable-next-line node/global-require
|
|
163
162
|
const initConfig = require("./init-config");
|
|
164
|
-
initConfig(
|
|
163
|
+
initConfig(lCruiseOptions.init);
|
|
165
164
|
} else {
|
|
166
|
-
lExitCode = runCruise(pFileDirectoryArray,
|
|
165
|
+
lExitCode = runCruise(pFileDirectoryArray, lCruiseOptions);
|
|
167
166
|
}
|
|
168
167
|
} catch (pError) {
|
|
169
168
|
process.stderr.write(`\n ${red("ERROR")}: ${pError.message}\n`);
|
|
170
169
|
bus.emit("end");
|
|
171
170
|
lExitCode = 1;
|
|
172
171
|
}
|
|
173
|
-
|
|
172
|
+
bus.emit("end");
|
|
174
173
|
return lExitCode;
|
|
175
174
|
};
|
|
@@ -9,9 +9,9 @@ require("./config.js.template");
|
|
|
9
9
|
* Creates a .dependency-cruiser config with a set of basic validations
|
|
10
10
|
* to the current directory.
|
|
11
11
|
*
|
|
12
|
-
* @
|
|
13
|
-
* @param {any} pNormalizedInitOptions Options that influence the shape of
|
|
12
|
+
* @param {import("../../../types/init-config").IInitConfig} pNormalizedInitOptions Options that influence the shape of
|
|
14
13
|
* the configuration
|
|
14
|
+
* @returns {string} the configuration as a string
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
module.exports = function buildConfig(pNormalizedInitOptions) {
|
|
@@ -24,9 +24,12 @@ function readManifest(pManifestFileName = "./package.json") {
|
|
|
24
24
|
return JSON.parse(readFileSync(pManifestFileName, "utf8"));
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
/**
|
|
28
|
+
* We could have used utl.fileExists - but that one is cached.
|
|
29
|
+
* Not typically what we want for this util.
|
|
30
|
+
*
|
|
31
|
+
* @param {import("fs").PathLike} pFile
|
|
32
|
+
* @returns {boolean}
|
|
30
33
|
*/
|
|
31
34
|
function fileExists(pFile) {
|
|
32
35
|
try {
|
|
@@ -15,7 +15,7 @@ const {
|
|
|
15
15
|
hasWebpackConfigCandidates,
|
|
16
16
|
getWebpackConfigCandidates,
|
|
17
17
|
} = require("./environment-helpers");
|
|
18
|
-
const { validateLocation } = require("./
|
|
18
|
+
const { validateLocation } = require("./validators");
|
|
19
19
|
|
|
20
20
|
function toPromptChoice(pString) {
|
|
21
21
|
return {
|
|
@@ -24,7 +24,7 @@ function toPromptChoice(pString) {
|
|
|
24
24
|
};
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
/** @type {import('
|
|
27
|
+
/** @type {import('prompts').PromptObject[]} */
|
|
28
28
|
const QUESTIONS = [
|
|
29
29
|
{
|
|
30
30
|
name: "isMonoRepo",
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @ts-check
|
|
1
2
|
const $defaults = require("../defaults");
|
|
2
3
|
const normalizeInitOptions = require("./normalize-init-options");
|
|
3
4
|
const buildConfig = require("./build-config");
|
|
@@ -29,8 +30,8 @@ const PACKAGE_MANIFEST = `./${$defaults.PACKAGE_MANIFEST}`;
|
|
|
29
30
|
* @param {import("../../../types/init-config").OneShotConfigIDType} pOneShotConfigId
|
|
30
31
|
* @return {import("../../../types/init-config").IPartialInitConfig} an initialization configuration
|
|
31
32
|
*/
|
|
32
|
-
function
|
|
33
|
-
/** @type {"../../../types/init-config").IPartialInitConfig} */
|
|
33
|
+
function getOneShotConfig(pOneShotConfigId) {
|
|
34
|
+
/** @type {import("../../../types/init-config").IPartialInitConfig} */
|
|
34
35
|
const lBaseConfig = {
|
|
35
36
|
isMonoRepo: isLikelyMonoRepo(),
|
|
36
37
|
combinedDependencies: false,
|
|
@@ -44,7 +45,8 @@ function getOneshotConfig(pOneShotConfigId) {
|
|
|
44
45
|
useBabelConfig: hasBabelConfigCandidates(),
|
|
45
46
|
babelConfig: getBabelConfigCandidates().shift(),
|
|
46
47
|
};
|
|
47
|
-
|
|
48
|
+
/** @type {Record<import("../../../types/init-config").OneShotConfigIDType, import("../../../types/init-config").IPartialInitConfig>} */
|
|
49
|
+
const lOneShotConfigs = {
|
|
48
50
|
preset: {
|
|
49
51
|
configType: "preset",
|
|
50
52
|
preset: "dependency-cruiser/configs/recommended-strict",
|
|
@@ -58,21 +60,24 @@ function getOneshotConfig(pOneShotConfigId) {
|
|
|
58
60
|
};
|
|
59
61
|
|
|
60
62
|
// eslint-disable-next-line security/detect-object-injection
|
|
61
|
-
return
|
|
63
|
+
return lOneShotConfigs[pOneShotConfigId] || lBaseConfig;
|
|
62
64
|
}
|
|
63
65
|
|
|
64
66
|
/**
|
|
65
67
|
*
|
|
66
68
|
* @param {import("../../../types/init-config").IInitConfig} pNormalizedInitConfig
|
|
67
69
|
*/
|
|
68
|
-
function
|
|
70
|
+
function manifestIsUpdatable(pNormalizedInitConfig) {
|
|
69
71
|
return (
|
|
70
72
|
pNormalizedInitConfig.updateManifest &&
|
|
71
73
|
pNormalizedInitConfig.sourceLocation.length > 0
|
|
72
74
|
);
|
|
73
75
|
}
|
|
74
76
|
|
|
75
|
-
|
|
77
|
+
/**
|
|
78
|
+
* @param {boolean|import("../../../types/init-config").OneShotConfigIDType} pInit
|
|
79
|
+
*/
|
|
80
|
+
module.exports = function initConfig(pInit) {
|
|
76
81
|
/* c8 ignore start */
|
|
77
82
|
if (pInit === true) {
|
|
78
83
|
getUserInput()
|
|
@@ -83,13 +88,15 @@ module.exports = (pInit) => {
|
|
|
83
88
|
process.stderr.write(`\n ERROR: ${pError.message}\n`);
|
|
84
89
|
});
|
|
85
90
|
/* c8 ignore stop */
|
|
91
|
+
} else if (pInit === false) {
|
|
92
|
+
// do nothing; deliberately left empty
|
|
86
93
|
} else {
|
|
87
|
-
const lNormalizedInitConfig = normalizeInitOptions(
|
|
94
|
+
const lNormalizedInitConfig = normalizeInitOptions(getOneShotConfig(pInit));
|
|
88
95
|
if (!fileExists(getDefaultConfigFileName())) {
|
|
89
96
|
writeConfig(buildConfig(lNormalizedInitConfig));
|
|
90
97
|
}
|
|
91
98
|
|
|
92
|
-
if (
|
|
99
|
+
if (manifestIsUpdatable(lNormalizedInitConfig)) {
|
|
93
100
|
writeRunScriptsToManifest(lNormalizedInitConfig);
|
|
94
101
|
}
|
|
95
102
|
}
|
|
@@ -1,12 +1,5 @@
|
|
|
1
1
|
const fs = require("fs");
|
|
2
|
-
const { toSourceLocationArray
|
|
3
|
-
|
|
4
|
-
function validateFileExistence(pInput) {
|
|
5
|
-
return (
|
|
6
|
-
fileExists(pInput) ||
|
|
7
|
-
`hmm, '${pInput}' doesn't seem to exist - could you try again?`
|
|
8
|
-
);
|
|
9
|
-
}
|
|
2
|
+
const { toSourceLocationArray } = require("./environment-helpers");
|
|
10
3
|
|
|
11
4
|
function validateLocation(pLocations) {
|
|
12
5
|
for (const lLocation of toSourceLocationArray(pLocations)) {
|
|
@@ -23,6 +16,5 @@ function validateLocation(pLocations) {
|
|
|
23
16
|
}
|
|
24
17
|
|
|
25
18
|
module.exports = {
|
|
26
|
-
validateFileExistence,
|
|
27
19
|
validateLocation,
|
|
28
20
|
};
|
|
@@ -11,7 +11,7 @@ const {
|
|
|
11
11
|
*
|
|
12
12
|
* @returns {void} Nothing
|
|
13
13
|
* @param {string} pConfig - dependency-cruiser configuration
|
|
14
|
-
* @param {
|
|
14
|
+
* @param {import("fs").PathOrFileDescriptor} pFileName - name of the file to write to
|
|
15
15
|
* @throws {Error} An error object with the root cause of the problem
|
|
16
16
|
* as a description:
|
|
17
17
|
* - file already exists
|
|
@@ -1,30 +1,90 @@
|
|
|
1
|
+
const chalk = require("chalk");
|
|
2
|
+
|
|
1
3
|
const MS_PER_SECOND = 1000;
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
+
const MS_PER_MICRO_SECOND = 0.001;
|
|
5
|
+
const MAX_LENGTH_EXPECTED = 12;
|
|
6
|
+
const NUMBER_OF_COLUMNS = 8;
|
|
4
7
|
const K = 1024;
|
|
8
|
+
/*
|
|
9
|
+
* using `undefined` as the first parameter to Intl.NumberFormat so
|
|
10
|
+
* it will fall back to the 'current' locale. Using a non-existent language
|
|
11
|
+
* (e.g. `zz`) also works, but `undefined` seems to be the lesser of the two
|
|
12
|
+
* evil as it is closer to the intent (skip the optional parameter).
|
|
13
|
+
*/
|
|
14
|
+
// eslint-disable-next-line no-undefined
|
|
15
|
+
const LOCALE = undefined;
|
|
16
|
+
|
|
17
|
+
const gTimeFormat = new Intl.NumberFormat(LOCALE, {
|
|
18
|
+
style: "unit",
|
|
19
|
+
unit: "millisecond",
|
|
20
|
+
unitDisplay: "narrow",
|
|
21
|
+
maximumFractionDigits: 0,
|
|
22
|
+
}).format;
|
|
23
|
+
const gSizeFormat = new Intl.NumberFormat(LOCALE, {
|
|
24
|
+
signDisplay: "exceptZero",
|
|
25
|
+
style: "unit",
|
|
26
|
+
unit: "kilobyte",
|
|
27
|
+
unitDisplay: "narrow",
|
|
28
|
+
maximumFractionDigits: 0,
|
|
29
|
+
}).format;
|
|
30
|
+
|
|
31
|
+
const pad = (pString) => pString.padStart(MAX_LENGTH_EXPECTED).concat(" ");
|
|
5
32
|
|
|
6
|
-
function
|
|
7
|
-
return
|
|
8
|
-
.
|
|
9
|
-
|
|
10
|
-
|
|
33
|
+
function formatHeader() {
|
|
34
|
+
return chalk
|
|
35
|
+
.bold(
|
|
36
|
+
`${
|
|
37
|
+
pad("elapsed real") +
|
|
38
|
+
pad("user") +
|
|
39
|
+
pad("system") +
|
|
40
|
+
pad("∆ rss") +
|
|
41
|
+
pad("∆ heapTotal") +
|
|
42
|
+
pad("∆ heapUsed") +
|
|
43
|
+
pad("∆ external")
|
|
44
|
+
}after step...\n`
|
|
45
|
+
)
|
|
46
|
+
.concat(
|
|
47
|
+
`${`${"-".repeat(MAX_LENGTH_EXPECTED)} `.repeat(NUMBER_OF_COLUMNS)}\n`
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function formatTime(pNumber, pConversionMultiplier = MS_PER_SECOND) {
|
|
52
|
+
return gTimeFormat(pConversionMultiplier * pNumber)
|
|
53
|
+
.padStart(MAX_LENGTH_EXPECTED)
|
|
54
|
+
.concat(" ");
|
|
11
55
|
}
|
|
12
56
|
|
|
13
57
|
function formatMemory(pBytes) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
.padStart(MAX_EXPECTED_LENGTH);
|
|
58
|
+
const lReturnValue = gSizeFormat(pBytes / K).padStart(MAX_LENGTH_EXPECTED);
|
|
59
|
+
|
|
60
|
+
return (pBytes < 0 ? chalk.blue(lReturnValue) : lReturnValue).concat(" ");
|
|
18
61
|
}
|
|
19
62
|
|
|
20
|
-
function formatPerfLine(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
63
|
+
function formatPerfLine({
|
|
64
|
+
elapsedTime,
|
|
65
|
+
elapsedUser,
|
|
66
|
+
elapsedSystem,
|
|
67
|
+
deltaRss,
|
|
68
|
+
deltaHeapUsed,
|
|
69
|
+
deltaHeapTotal,
|
|
70
|
+
deltaExternal,
|
|
71
|
+
message,
|
|
72
|
+
}) {
|
|
73
|
+
return `${
|
|
74
|
+
formatTime(elapsedTime) +
|
|
75
|
+
formatTime(elapsedUser, MS_PER_MICRO_SECOND) +
|
|
76
|
+
formatTime(elapsedSystem, MS_PER_MICRO_SECOND) +
|
|
77
|
+
formatMemory(deltaRss) +
|
|
78
|
+
formatMemory(deltaHeapTotal) +
|
|
79
|
+
formatMemory(deltaHeapUsed) +
|
|
80
|
+
formatMemory(deltaExternal) +
|
|
81
|
+
message
|
|
82
|
+
}\n`;
|
|
24
83
|
}
|
|
25
84
|
|
|
26
85
|
module.exports = {
|
|
27
86
|
formatTime,
|
|
28
87
|
formatMemory,
|
|
29
88
|
formatPerfLine,
|
|
89
|
+
formatHeader,
|
|
30
90
|
};
|