dependency-cruiser 11.15.0-beta-2 → 11.16.0-beta-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 +36 -20
- package/package.json +31 -37
- package/src/cache/cache.js +2 -2
- package/src/cache/revision-data.js +1 -1
- package/src/cli/index.js +22 -3
- package/src/cli/init-config/build-config.js +5 -6
- package/src/cli/init-config/environment-helpers.js +17 -24
- package/src/cli/utl/io.js +0 -1
- package/src/config-utl/extract-known-violations.js +1 -1
- package/src/config-utl/extract-webpack-resolve-config.js +1 -1
- package/src/extract/ast-extractors/extract-typescript-deps.js +1 -1
- package/src/main/index.js +1 -1
- package/src/main/options/validate.js +3 -3
- package/src/main/rule-set/validate.js +15 -1
- package/src/main/utl/normalize-re-properties.js +0 -1
- package/src/meta.js +1 -1
- package/src/report/dot/default-theme.js +0 -1
- package/src/report/error-html/index.js +0 -1
- package/src/report/error.js +0 -1
package/README.md
CHANGED
|
@@ -13,47 +13,64 @@ This runs through the dependencies in any JavaScript, TypeScript, LiveScript or
|
|
|
13
13
|
- in text (for your builds)
|
|
14
14
|
- in graphics (for your eyeballs)
|
|
15
15
|
|
|
16
|
-
As a side effect it can generate [**cool
|
|
16
|
+
As a side effect it can generate dependency graphs in various output formats including [**cool visualizations**](./doc/real-world-samples.md)
|
|
17
17
|
you can stick on the wall to impress your grandma.
|
|
18
18
|
|
|
19
19
|
## How do I use it?
|
|
20
20
|
|
|
21
21
|
### Install it
|
|
22
22
|
|
|
23
|
-
- `npm install --save-dev dependency-cruiser`
|
|
24
|
-
|
|
23
|
+
- `npm install --save-dev dependency-cruiser` (with `yarn` or `pnpm` use their
|
|
24
|
+
equivalent to install & save dependency-cruiser as a development dependency).
|
|
25
|
+
|
|
26
|
+
### Generate a config
|
|
27
|
+
|
|
28
|
+
```shell
|
|
29
|
+
npx depcruise --init
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
This will look around in your environment a bit, ask you some questions and create
|
|
33
|
+
a `.dependency-cruiser.js` configuration file attuned to your project[^1].
|
|
34
|
+
|
|
35
|
+
[^1]:
|
|
36
|
+
We're using `npx` in the example scripts for convenience. When you use the
|
|
37
|
+
commands in a script in `package.json` it's not necessary to prefix them with
|
|
38
|
+
`npx`.
|
|
25
39
|
|
|
26
40
|
### Show stuff to your grandma
|
|
27
41
|
|
|
28
42
|
To create a graph of the dependencies in your src folder, you'd run dependency
|
|
29
|
-
cruiser with output type `dot` and run _GraphViz dot_ on the result. In
|
|
43
|
+
cruiser with output type `dot` and run _GraphViz dot_[^2] on the result. In
|
|
30
44
|
a one liner:
|
|
31
45
|
|
|
32
46
|
```shell
|
|
33
|
-
depcruise --include-only "^src" --output-type dot
|
|
47
|
+
npx depcruise src --include-only "^src" --config --output-type dot | dot -T svg > dependency-graph.svg
|
|
34
48
|
```
|
|
35
49
|
|
|
36
50
|
- You can read more about what you can do with `--include-only` and other command line
|
|
37
51
|
options in the [command line interface](./doc/cli.md) documentation.
|
|
38
52
|
- _[Real world samples](./doc/real-world-samples.md)_
|
|
39
53
|
contains dependency cruises of some of the most used projects on npm.
|
|
54
|
+
- If our grandma is more into formats like `mermaid`, `json`, `csv`, `html` or plain text
|
|
55
|
+
we've [got her covered](./doc/cli.md#--output-type-specify-the-output-format)
|
|
56
|
+
as well.
|
|
57
|
+
|
|
58
|
+
[^2]:
|
|
59
|
+
This assumes the GraphViz `dot` command is available - on most linux and
|
|
60
|
+
comparable systems this will be. In case it's not, see
|
|
61
|
+
[GraphViz' download page](https://www.graphviz.org/download/) for instructions
|
|
62
|
+
on how to get it on your machine.
|
|
40
63
|
|
|
41
64
|
### Validate things
|
|
42
65
|
|
|
43
66
|
#### Declare some rules
|
|
44
67
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
This will ask you some questions and create a `.dependency-cruiser.js` with some
|
|
52
|
-
rules that make sense in most projects (detecting **circular dependencies**,
|
|
53
|
-
dependencies **missing** in package.json, **orphans**, production code relying on
|
|
54
|
-
dev- or optionalDependencies, ...).
|
|
68
|
+
When you ran the `depcruise --init command` above, the command also added some rules
|
|
69
|
+
to `.dependency-cruiser.js` that make sense in most projects, like detecting
|
|
70
|
+
**circular dependencies**, dependencies **missing** in package.json, **orphans**,
|
|
71
|
+
and production code relying on dev- or optionalDependencies.
|
|
55
72
|
|
|
56
|
-
Start adding your rules by tweaking that file.
|
|
73
|
+
Start adding your rules own by tweaking that file.
|
|
57
74
|
|
|
58
75
|
Sample rule:
|
|
59
76
|
|
|
@@ -74,12 +91,11 @@ Sample rule:
|
|
|
74
91
|
- To read more about writing rules check the
|
|
75
92
|
[writing rules](./doc/rules-tutorial.md) tutorial
|
|
76
93
|
or the [rules reference](./doc/rules-reference.md)
|
|
77
|
-
- You can find the `--init-rules` set [here](./doc/rules.starter.json)
|
|
78
94
|
|
|
79
95
|
#### Report them
|
|
80
96
|
|
|
81
97
|
```sh
|
|
82
|
-
depcruise --config .dependency-cruiser.js src
|
|
98
|
+
npx depcruise --config .dependency-cruiser.js src
|
|
83
99
|
```
|
|
84
100
|
|
|
85
101
|
This will validate against your rules and shows any violations in an eslint-like format:
|
|
@@ -87,14 +103,14 @@ This will validate against your rules and shows any violations in an eslint-like
|
|
|
87
103
|

|
|
88
104
|
|
|
89
105
|
There's more ways to report validations; in a graph (like the one on top of this
|
|
90
|
-
readme) or in
|
|
106
|
+
readme) or in an self-containing `html` file.
|
|
91
107
|
|
|
92
108
|
- Read more about the err, dot, csv and html reporters in the
|
|
93
109
|
[command line interface](./doc/cli.md)
|
|
94
110
|
documentation.
|
|
95
111
|
- dependency-cruiser uses itself to check on itself in its own build process;
|
|
96
112
|
see the `depcruise` script in the
|
|
97
|
-
[package.json](https://github.com/sverweij/dependency-cruiser/blob/master/package.json#
|
|
113
|
+
[package.json](https://github.com/sverweij/dependency-cruiser/blob/master/package.json#L76)
|
|
98
114
|
|
|
99
115
|
## I want to know more!
|
|
100
116
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dependency-cruiser",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.16.0-beta-1",
|
|
4
4
|
"description": "Validate and visualize dependencies. With your rules. JavaScript, TypeScript, CoffeeScript. ES6, CommonJS, AMD.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"static analysis",
|
|
@@ -89,13 +89,13 @@
|
|
|
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
90
|
"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
91
|
"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 | dot -T svg | node ./bin/wrap-stream-in-html.js | browser",
|
|
92
|
-
"depcruise:graph:view:diff": "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 --
|
|
92
|
+
"depcruise:graph:view:diff": "node ./bin/dependency-cruise.js bin src test --prefix vscode://file/$(pwd)/ --config configs/.dependency-cruiser-show-metrics-config.json --output-type dot --progress cli-feedback --reaches \"$(watskeburt develop)\" | dot -T svg | node ./bin/wrap-stream-in-html.js | browser",
|
|
93
93
|
"depcruise:report": "node ./bin/dependency-cruise.js src bin test configs types --output-type err-html --config configs/.dependency-cruiser-show-metrics-config.json --output-to dependency-violations.html",
|
|
94
94
|
"depcruise:report:view": "node ./bin/dependency-cruise.js src bin test configs types --output-type err-html --config configs/.dependency-cruiser-show-metrics-config.json --output-to - | browser",
|
|
95
95
|
"depcruise:focus": "node ./bin/dependency-cruise.js src bin test configs types tools --progress --config configs/.dependency-cruiser-show-metrics-config.json --output-type text --focus",
|
|
96
96
|
"depcruise:reaches": "node ./bin/dependency-cruise.js src bin test configs types tools --progress --config configs/.dependency-cruiser-show-metrics-config.json --output-type text --reaches",
|
|
97
97
|
"lint": "npm-run-all --parallel --aggregate-output lint:eslint lint:prettier lint:types",
|
|
98
|
-
"lint:eslint": "eslint bin/dependency-cruise.js src test configs tools/**/*.mjs --cache --cache-location node_modules/.cache/eslint/",
|
|
98
|
+
"lint:eslint": "eslint bin/dependency-cruise.js bin src test configs tools/**/*.mjs --cache --cache-location node_modules/.cache/eslint/",
|
|
99
99
|
"lint:eslint:fix": "eslint --fix bin src test configs tools/**/*.mjs --cache --cache-location node_modules/.cache/eslint/",
|
|
100
100
|
"lint:fix": "npm-run-all lint:eslint:fix lint:prettier:fix lint:types:fix",
|
|
101
101
|
"lint:prettier": "prettier --loglevel warn --check \"src/**/*.js\" \"configs/**/*.js\" \"tools/**/*.mjs\" \"bin/*\" \"types/*.d.ts\" \"test/**/*.spec.{cjs,js}\" \"test/**/*.{spec,utl}.mjs\"",
|
|
@@ -104,6 +104,7 @@
|
|
|
104
104
|
"lint:types:tsc": "tsc --project types/tsconfig.json",
|
|
105
105
|
"lint:types:lint": "eslint --no-ignore --config types/.eslintrc.json types/*.d.ts",
|
|
106
106
|
"lint:types:fix": "eslint --no-ignore --config types/.eslintrc.json --fix types/*.d.ts",
|
|
107
|
+
"prepare": "husky install",
|
|
107
108
|
"scm:push": "run-p --aggregate-output scm:push:*",
|
|
108
109
|
"scm:push:bitbucket-mirror": "run-p --aggregate-output scm:push:bitbucket-mirror:*",
|
|
109
110
|
"scm:push:bitbucket-mirror:commits": "git push bitbucket-mirror",
|
|
@@ -133,8 +134,9 @@
|
|
|
133
134
|
"test:load:short": "hyperfine --warmup 1 --runs 5 \"bin/dependency-cruise.js --ignore-known --validate -- src bin test configs types tools\"",
|
|
134
135
|
"test:watch": "mocha --watch --watch-extensions=json --reporter=min test/\\*\\*/\\*.spec.js",
|
|
135
136
|
"update-dependencies": "npm-run-all upem:update upem:install build:clean build lint:fix depcruise test:cover",
|
|
137
|
+
"upem-outdated": "npm outdated --json --long | upem --dry-run",
|
|
136
138
|
"upem:install": "npm install",
|
|
137
|
-
"upem:update": "npm outdated --json | upem",
|
|
139
|
+
"upem:update": "npm outdated --json --long | upem | pbcopy && pbpaste",
|
|
138
140
|
"version": "npm-run-all build depcruise:graph:doc scm:stage"
|
|
139
141
|
},
|
|
140
142
|
"dependencies": {
|
|
@@ -153,6 +155,7 @@
|
|
|
153
155
|
"handlebars": "4.7.7",
|
|
154
156
|
"indent-string": "^4.0.0",
|
|
155
157
|
"interpret": "^2.2.0",
|
|
158
|
+
"is-installed-globally": "0.4.0",
|
|
156
159
|
"json5": "2.2.1",
|
|
157
160
|
"lodash": "4.17.21",
|
|
158
161
|
"prompts": "2.4.2",
|
|
@@ -162,34 +165,35 @@
|
|
|
162
165
|
"semver-try-require": "^5.0.2",
|
|
163
166
|
"teamcity-service-messages": "0.1.14",
|
|
164
167
|
"tsconfig-paths-webpack-plugin": "4.0.0",
|
|
165
|
-
"watskeburt": "0.
|
|
168
|
+
"watskeburt": "0.7.0",
|
|
166
169
|
"wrap-ansi": "^7.0.0"
|
|
167
170
|
},
|
|
168
171
|
"devDependencies": {
|
|
169
|
-
"@babel/core": "7.18.
|
|
172
|
+
"@babel/core": "7.18.13",
|
|
170
173
|
"@babel/plugin-transform-modules-commonjs": "7.18.6",
|
|
171
174
|
"@babel/preset-typescript": "7.18.6",
|
|
172
|
-
"@swc/core": "1.2.
|
|
173
|
-
"@types/lodash": "4.14.
|
|
174
|
-
"@types/node": "18.
|
|
175
|
+
"@swc/core": "1.2.246",
|
|
176
|
+
"@types/lodash": "4.14.184",
|
|
177
|
+
"@types/node": "18.7.14",
|
|
175
178
|
"@types/prompts": "2.0.14",
|
|
176
|
-
"@typescript-eslint/eslint-plugin": "5.
|
|
177
|
-
"@typescript-eslint/parser": "5.
|
|
178
|
-
"@vue/compiler-sfc": "3.2.
|
|
179
|
+
"@typescript-eslint/eslint-plugin": "5.36.1",
|
|
180
|
+
"@typescript-eslint/parser": "5.36.1",
|
|
181
|
+
"@vue/compiler-sfc": "3.2.38",
|
|
179
182
|
"c8": "7.12.0",
|
|
180
183
|
"chai": "4.3.6",
|
|
181
184
|
"chai-json-schema": "1.5.1",
|
|
182
185
|
"coffeescript": "2.7.0",
|
|
183
|
-
"eslint": "
|
|
184
|
-
"eslint-config-moving-meadow": "
|
|
186
|
+
"eslint": "8.23.0",
|
|
187
|
+
"eslint-config-moving-meadow": "4.0.2",
|
|
185
188
|
"eslint-config-prettier": "8.5.0",
|
|
186
|
-
"eslint-plugin-budapestian": "
|
|
189
|
+
"eslint-plugin-budapestian": "5.0.0",
|
|
190
|
+
"eslint-plugin-eslint-comments": "3.2.0",
|
|
187
191
|
"eslint-plugin-import": "2.26.0",
|
|
188
192
|
"eslint-plugin-mocha": "10.1.0",
|
|
189
193
|
"eslint-plugin-node": "11.1.0",
|
|
190
194
|
"eslint-plugin-security": "1.5.0",
|
|
191
195
|
"eslint-plugin-unicorn": "^43.0.1",
|
|
192
|
-
"husky": "
|
|
196
|
+
"husky": "8.0.1",
|
|
193
197
|
"intercept-stdout": "0.1.2",
|
|
194
198
|
"lint-staged": "12.3.4",
|
|
195
199
|
"mocha": "10.0.0",
|
|
@@ -198,11 +202,11 @@
|
|
|
198
202
|
"prettier": "2.7.1",
|
|
199
203
|
"proxyquire": "2.1.3",
|
|
200
204
|
"shx": "0.3.4",
|
|
201
|
-
"svelte": "3.
|
|
205
|
+
"svelte": "3.50.0",
|
|
202
206
|
"symlink-dir": "5.0.1",
|
|
203
|
-
"typescript": "4.
|
|
204
|
-
"upem": "
|
|
205
|
-
"vue-template-compiler": "2.7.
|
|
207
|
+
"typescript": "4.8.2",
|
|
208
|
+
"upem": "7.3.0",
|
|
209
|
+
"vue-template-compiler": "2.7.10",
|
|
206
210
|
"yarn": "1.22.19"
|
|
207
211
|
},
|
|
208
212
|
"upem": {
|
|
@@ -210,32 +214,27 @@
|
|
|
210
214
|
{
|
|
211
215
|
"package": "chalk",
|
|
212
216
|
"policy": "wanted",
|
|
213
|
-
"because": "version 5 only exports
|
|
217
|
+
"because": "version 5 only exports esm - and we use cjs and don't transpile"
|
|
214
218
|
},
|
|
215
219
|
{
|
|
216
220
|
"package": "figures",
|
|
217
221
|
"policy": "wanted",
|
|
218
|
-
"because": "version 4 only exports
|
|
222
|
+
"because": "version 4 only exports esm - and we use cjs and don't transpile"
|
|
219
223
|
},
|
|
220
224
|
{
|
|
221
225
|
"package": "glob",
|
|
222
226
|
"policy": "pin",
|
|
223
227
|
"because": "from version 7.2.1 behavior on windows changes - in a potentially breaking fashion. Wait with upgrading until we're majoring or from when there's a vuln in 7.2.0"
|
|
224
228
|
},
|
|
225
|
-
{
|
|
226
|
-
"package": "husky",
|
|
227
|
-
"policy": "wanted",
|
|
228
|
-
"because": "https://github.com/typicode/husky/issues/822"
|
|
229
|
-
},
|
|
230
229
|
{
|
|
231
230
|
"package": "indent-string",
|
|
232
231
|
"policy": "wanted",
|
|
233
|
-
"because": "version 5 only exports
|
|
232
|
+
"because": "version 5 only exports esm - and we use cjs and don't transpile"
|
|
234
233
|
},
|
|
235
234
|
{
|
|
236
235
|
"package": "interpret",
|
|
237
236
|
"policy": "wanted",
|
|
238
|
-
"because": "we want to keep interpret ~similar to what webpack-cli
|
|
237
|
+
"because": "we want to keep interpret ~similar to what webpack-cli uses (which is ^2.2.0)"
|
|
239
238
|
},
|
|
240
239
|
{
|
|
241
240
|
"package": "lint-staged",
|
|
@@ -245,17 +244,17 @@
|
|
|
245
244
|
{
|
|
246
245
|
"package": "normalize-newline",
|
|
247
246
|
"policy": "wanted",
|
|
248
|
-
"because": "version 4 only exports
|
|
247
|
+
"because": "version 4 only exports esm - and we use cjs and don't transpile (this only used in unit tests - but one of'em is a cjs one ...)"
|
|
249
248
|
},
|
|
250
249
|
{
|
|
251
250
|
"package": "rechoir",
|
|
252
251
|
"policy": "wanted",
|
|
253
|
-
"because": "we want to keep rechoir ~similar to what webpack-cli
|
|
252
|
+
"because": "we want to keep rechoir ~similar to what webpack-cli uses (which is ^0.7.0, but ^0.8.0 is similar enough and more recent anyway)"
|
|
254
253
|
},
|
|
255
254
|
{
|
|
256
255
|
"package": "wrap-ansi",
|
|
257
256
|
"policy": "wanted",
|
|
258
|
-
"because": "version 8 only exports
|
|
257
|
+
"because": "version 8 only exports esm - and we use cjs and don't transpile"
|
|
259
258
|
}
|
|
260
259
|
]
|
|
261
260
|
},
|
|
@@ -290,11 +289,6 @@
|
|
|
290
289
|
"vue-template-compiler": ">=2.0.0 <3.0.0",
|
|
291
290
|
"@vue/compiler-sfc": ">=3.0.0 <4.0.0"
|
|
292
291
|
},
|
|
293
|
-
"husky": {
|
|
294
|
-
"hooks": {
|
|
295
|
-
"pre-commit": "lint-staged"
|
|
296
|
-
}
|
|
297
|
-
},
|
|
298
292
|
"lint-staged": {
|
|
299
293
|
"{src,config}/**/*.js": [
|
|
300
294
|
"eslint --fix"
|
package/src/cache/cache.js
CHANGED
|
@@ -14,7 +14,7 @@ function writeCache(pCacheFolder, pCruiseResult) {
|
|
|
14
14
|
writeFileSync(
|
|
15
15
|
join(pCacheFolder, CACHE_FILE_NAME),
|
|
16
16
|
JSON.stringify(pCruiseResult),
|
|
17
|
-
"
|
|
17
|
+
"utf8"
|
|
18
18
|
);
|
|
19
19
|
}
|
|
20
20
|
|
|
@@ -26,7 +26,7 @@ function writeCache(pCacheFolder, pCruiseResult) {
|
|
|
26
26
|
function readCache(pCacheFolder) {
|
|
27
27
|
try {
|
|
28
28
|
return JSON.parse(
|
|
29
|
-
readFileSync(join(pCacheFolder, CACHE_FILE_NAME), "
|
|
29
|
+
readFileSync(join(pCacheFolder, CACHE_FILE_NAME), "utf8")
|
|
30
30
|
);
|
|
31
31
|
} catch (pError) {
|
|
32
32
|
return { modules: [], summary: {} };
|
package/src/cli/index.js
CHANGED
|
@@ -2,6 +2,8 @@ const glob = require("glob");
|
|
|
2
2
|
const get = require("lodash/get");
|
|
3
3
|
const clone = require("lodash/clone");
|
|
4
4
|
const set = require("lodash/set");
|
|
5
|
+
const isInstalledGlobally = require("is-installed-globally");
|
|
6
|
+
const { red, yellow, bold } = require("chalk");
|
|
5
7
|
|
|
6
8
|
const main = require("../main");
|
|
7
9
|
const bus = require("../utl/bus");
|
|
@@ -138,13 +140,30 @@ module.exports = function executeCli(pFileDirectoryArray, pCruiseOptions) {
|
|
|
138
140
|
let lExitCode = 0;
|
|
139
141
|
|
|
140
142
|
try {
|
|
143
|
+
/* c8 ignore start */
|
|
144
|
+
if (isInstalledGlobally) {
|
|
145
|
+
process.stderr.write(
|
|
146
|
+
`\n ${yellow(
|
|
147
|
+
"WARNING"
|
|
148
|
+
)}: You're running a globally installed dependency-cruiser.\n\n` +
|
|
149
|
+
` We recommend to ${bold.italic.underline(
|
|
150
|
+
"install and run it as a local devDependency"
|
|
151
|
+
)} in\n` +
|
|
152
|
+
` your project instead. There it has your project's environment and\n` +
|
|
153
|
+
` transpilers at its disposal. That will ensure it can find e.g.\n` +
|
|
154
|
+
` TypeScript, Vue or Svelte modules and dependencies.\n\n`
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
/* c8 ignore stop */
|
|
141
158
|
if (pCruiseOptions.info === true) {
|
|
142
159
|
process.stdout.write(formatMetaInfo());
|
|
143
160
|
} else if (pCruiseOptions.init) {
|
|
144
|
-
// requiring init-config
|
|
161
|
+
// requiring init-config took ~100ms (most of it taken up by requiring
|
|
145
162
|
// inquirer, measured on a 2.6GHz quad core i7 with flash storage on
|
|
146
163
|
// macOS 10.15.7). Only requiring it when '--init' is necessary speeds up
|
|
147
|
-
// (the start-up) of cruises by that same amount.
|
|
164
|
+
// (the start-up) of cruises by that same amount. We've since replaced
|
|
165
|
+
// inquirer with 'prompts' (which is much smaller), but the same reasoning
|
|
166
|
+
// holds.
|
|
148
167
|
// eslint-disable-next-line node/global-require
|
|
149
168
|
const initConfig = require("./init-config");
|
|
150
169
|
initConfig(pCruiseOptions.init);
|
|
@@ -152,7 +171,7 @@ module.exports = function executeCli(pFileDirectoryArray, pCruiseOptions) {
|
|
|
152
171
|
lExitCode = runCruise(pFileDirectoryArray, pCruiseOptions);
|
|
153
172
|
}
|
|
154
173
|
} catch (pError) {
|
|
155
|
-
process.stderr.write(`\n ERROR: ${pError.message}\n`);
|
|
174
|
+
process.stderr.write(`\n ${red("ERROR")}: ${pError.message}\n`);
|
|
156
175
|
bus.emit("end");
|
|
157
176
|
lExitCode = 1;
|
|
158
177
|
}
|
|
@@ -17,11 +17,10 @@ require("./config.js.template");
|
|
|
17
17
|
module.exports = function buildConfig(pNormalizedInitOptions) {
|
|
18
18
|
return Handlebars.templates["config.js.template.hbs"]({
|
|
19
19
|
...pNormalizedInitOptions,
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
},
|
|
20
|
+
|
|
21
|
+
sourceLocationRE: folderNameArrayToRE(
|
|
22
|
+
pNormalizedInitOptions.sourceLocation
|
|
23
|
+
),
|
|
24
|
+
testLocationRE: folderNameArrayToRE(pNormalizedInitOptions.testLocation),
|
|
26
25
|
});
|
|
27
26
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const
|
|
2
|
-
const
|
|
1
|
+
const { readFileSync, readdirSync, accessSync, statSync, R_OK } = require("fs");
|
|
2
|
+
const { join } = require("path");
|
|
3
3
|
const has = require("lodash/has");
|
|
4
4
|
const get = require("lodash/get");
|
|
5
5
|
const { DEFAULT_CONFIG_FILE_NAME } = require("../defaults");
|
|
@@ -9,7 +9,7 @@ const LIKELY_TEST_FOLDERS = ["test", "spec", "tests", "specs", "bdd"];
|
|
|
9
9
|
const LIKELY_PACKAGES_FOLDERS = ["packages"];
|
|
10
10
|
const TSCONFIG_CANDIDATE_PATTERN = /.*tsconfig.*\.json$/gi;
|
|
11
11
|
const JSCONFIG_CANDIDATE_PATTERN = /.*jsconfig.*\.json$/gi;
|
|
12
|
-
const WEBPACK_CANDIDATE_PATTERN = /.*webpack.*\.c?js
|
|
12
|
+
const WEBPACK_CANDIDATE_PATTERN = /.*webpack.*\.(c?js|json5?|ts|ya?ml)$/gi;
|
|
13
13
|
const BABEL_CONFIG_CANDIDATE_PATTERN = /^\.babelrc$|.*babel.*\.json/gi;
|
|
14
14
|
|
|
15
15
|
/**
|
|
@@ -17,11 +17,11 @@ const BABEL_CONFIG_CANDIDATE_PATTERN = /^\.babelrc$|.*babel.*\.json/gi;
|
|
|
17
17
|
*
|
|
18
18
|
* @param {string} pManifestFileName - the file name where the package manifest (package.json) lives
|
|
19
19
|
* @returns {any} - the contents of said manifest as a javascript object
|
|
20
|
-
* @throws ENOENT when the manifest wasn't found
|
|
21
|
-
* @throws SyntaxError when the manifest's json is invalid
|
|
20
|
+
* @throws {ENOENT} when the manifest wasn't found
|
|
21
|
+
* @throws {SyntaxError} when the manifest's json is invalid
|
|
22
22
|
*/
|
|
23
23
|
function readManifest(pManifestFileName = "./package.json") {
|
|
24
|
-
return JSON.parse(
|
|
24
|
+
return JSON.parse(readFileSync(pManifestFileName, "utf8"));
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
/*
|
|
@@ -30,7 +30,7 @@ function readManifest(pManifestFileName = "./package.json") {
|
|
|
30
30
|
*/
|
|
31
31
|
function fileExists(pFile) {
|
|
32
32
|
try {
|
|
33
|
-
|
|
33
|
+
accessSync(pFile, R_OK);
|
|
34
34
|
} catch (pError) {
|
|
35
35
|
return false;
|
|
36
36
|
}
|
|
@@ -61,21 +61,17 @@ function isTypeModule() {
|
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
function getFolderNames(pFolderName) {
|
|
64
|
-
return
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
fs.statSync(path.join(pFolderName, pFileName)).isDirectory()
|
|
68
|
-
);
|
|
64
|
+
return readdirSync(pFolderName, "utf8").filter((pFileName) =>
|
|
65
|
+
statSync(join(pFolderName, pFileName)).isDirectory()
|
|
66
|
+
);
|
|
69
67
|
}
|
|
70
68
|
|
|
71
69
|
function getMatchingFileNames(pPattern, pFolderName = process.cwd()) {
|
|
72
|
-
return
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
(
|
|
76
|
-
|
|
77
|
-
pFileName.match(pPattern)
|
|
78
|
-
);
|
|
70
|
+
return readdirSync(pFolderName, "utf8").filter(
|
|
71
|
+
(pFileName) =>
|
|
72
|
+
statSync(join(pFolderName, pFileName)).isFile() &&
|
|
73
|
+
pFileName.match(pPattern)
|
|
74
|
+
);
|
|
79
75
|
}
|
|
80
76
|
|
|
81
77
|
function isLikelyMonoRepo(pFolderNames = getFolderNames(process.cwd())) {
|
|
@@ -83,11 +79,8 @@ function isLikelyMonoRepo(pFolderNames = getFolderNames(process.cwd())) {
|
|
|
83
79
|
}
|
|
84
80
|
|
|
85
81
|
function hasTestsWithinSource(pTestLocations, pSourceLocations) {
|
|
86
|
-
return (
|
|
87
|
-
|
|
88
|
-
pTestLocations.every((pTestLocation) =>
|
|
89
|
-
pSourceLocations.includes(pTestLocation)
|
|
90
|
-
)
|
|
82
|
+
return pTestLocations.every((pTestLocation) =>
|
|
83
|
+
pSourceLocations.includes(pTestLocation)
|
|
91
84
|
);
|
|
92
85
|
}
|
|
93
86
|
|
package/src/cli/utl/io.js
CHANGED
|
@@ -32,7 +32,6 @@ function writeToStdOut(pString, pBufferSize = PIPE_BUFFER_SIZE) {
|
|
|
32
32
|
|
|
33
33
|
/* eslint no-plusplus: 0 */
|
|
34
34
|
for (lIndex = 0; lIndex < lNumberOfChunks; lIndex++) {
|
|
35
|
-
// eslint-disable-next-line unicorn/prefer-string-slice
|
|
36
35
|
process.stdout.write(
|
|
37
36
|
pString.substr(lIndex * pBufferSize, pBufferSize),
|
|
38
37
|
"utf8"
|
|
@@ -5,7 +5,7 @@ const makeAbsolute = require("./make-absolute");
|
|
|
5
5
|
module.exports = function extractKnownViolations(pKnownViolationsFileName) {
|
|
6
6
|
try {
|
|
7
7
|
return json5.parse(
|
|
8
|
-
readFileSync(makeAbsolute(pKnownViolationsFileName), "
|
|
8
|
+
readFileSync(makeAbsolute(pKnownViolationsFileName), "utf8")
|
|
9
9
|
);
|
|
10
10
|
// TODO: apparently node12 native coverage doesn't see this is covered with UT
|
|
11
11
|
// (node 14 and 16 do), so c8 doesn't either. The ignore can be removed
|
|
@@ -82,7 +82,7 @@ function tryRegisterNonNative(pWebpackConfigFilename) {
|
|
|
82
82
|
* @throws {Error} when the webpack config isn't usable (e.g. because it
|
|
83
83
|
* doesn't exist, or because it's invalid)
|
|
84
84
|
*/
|
|
85
|
-
|
|
85
|
+
|
|
86
86
|
module.exports = function extractWebpackResolveConfig(
|
|
87
87
|
pWebpackConfigFilename,
|
|
88
88
|
pEnvironment,
|
package/src/main/index.js
CHANGED
|
@@ -81,10 +81,10 @@ function validateCruiseOptions(pOptions) {
|
|
|
81
81
|
let lReturnValue = {};
|
|
82
82
|
|
|
83
83
|
if (Boolean(pOptions)) {
|
|
84
|
-
//
|
|
84
|
+
// necessary because can slip through the cracks when passed as a cli parameter
|
|
85
85
|
validateSystems(pOptions.moduleSystems);
|
|
86
86
|
|
|
87
|
-
//
|
|
87
|
+
// necessary because this safety check can't be done in json schema (a.f.a.i.k.)
|
|
88
88
|
validatePathsSafety(pOptions.doNotFollow);
|
|
89
89
|
validatePathsSafety(pOptions.exclude);
|
|
90
90
|
validateRegExpSafety(pOptions.includeOnly);
|
|
@@ -95,7 +95,7 @@ function validateCruiseOptions(pOptions) {
|
|
|
95
95
|
// necessary because not in the config schema
|
|
96
96
|
validateOutputType(pOptions.outputType);
|
|
97
97
|
|
|
98
|
-
//
|
|
98
|
+
// necessary because not found a way to do this properly in JSON schema
|
|
99
99
|
validateMaxDepth(pOptions.maxDepth);
|
|
100
100
|
|
|
101
101
|
validateFocusDepth(pOptions.focusDepth);
|
|
@@ -5,6 +5,18 @@ const { validateCruiseOptions } = require("../options/validate");
|
|
|
5
5
|
const configurationSchema = require("../../schema/configuration.schema.js");
|
|
6
6
|
|
|
7
7
|
const ajv = new Ajv();
|
|
8
|
+
// the default for this is 25 - as noted in the safe-regex source code already,
|
|
9
|
+
// the repeat limit is not the best of heuristics for indicating exponential time
|
|
10
|
+
// regular expressions - and it leads to false positives. E.g. if you use rules
|
|
11
|
+
// 'generated' from rules it could be the generated 'from' or 'to' have a list
|
|
12
|
+
// of file patterns that's easily > 25 of length. It's currently not possible
|
|
13
|
+
// to disable this check in safe-regex (e.g. by setting it to an odd value like
|
|
14
|
+
// 0 or -1, or by passing a 'switch this thing off please' option), so the only
|
|
15
|
+
// option is to increase the repeat limit to something fairly high.
|
|
16
|
+
//
|
|
17
|
+
// This does _not_ influence the star height algorithm, which is the main value
|
|
18
|
+
// of the safe-regex package.
|
|
19
|
+
const MAX_SAFE_REGEX_STAR_REPEAT_LIMIT = 10000;
|
|
8
20
|
|
|
9
21
|
function validateAgainstSchema(pSchema, pConfiguration) {
|
|
10
22
|
if (!ajv.validate(pSchema, pConfiguration)) {
|
|
@@ -21,7 +33,9 @@ function hasPath(pObject, pSection, pCondition) {
|
|
|
21
33
|
function safeRule(pRule, pSection, pCondition) {
|
|
22
34
|
return (
|
|
23
35
|
!hasPath(pRule, pSection, pCondition) ||
|
|
24
|
-
safeRegex(pRule[pSection][pCondition]
|
|
36
|
+
safeRegex(pRule[pSection][pCondition], {
|
|
37
|
+
limit: MAX_SAFE_REGEX_STAR_REPEAT_LIMIT,
|
|
38
|
+
})
|
|
25
39
|
);
|
|
26
40
|
}
|
|
27
41
|
|
package/src/meta.js
CHANGED
package/src/report/error.js
CHANGED