comparison .dependency-cruiser.js @ 126:9a57f8c556d2

add depgraph task
author drewp@bigasterisk.com
date Fri, 05 May 2023 21:22:35 -0700
parents
children
comparison
equal deleted inserted replaced
124:e26daf747e19 126:9a57f8c556d2
1 /** @type {import('dependency-cruiser').IConfiguration} */
2 module.exports = {
3 forbidden: [
4 /* rules from the 'recommended' preset: */
5 {
6 name: 'no-circular',
7 severity: 'warn',
8 comment:
9 'This dependency is part of a circular relationship. You might want to revise ' +
10 'your solution (i.e. use dependency inversion, make sure the modules have a single responsibility) ',
11 from: {},
12 to: {
13 circular: true
14 }
15 },
16 {
17 name: 'no-orphans',
18 comment:
19 "This is an orphan module - it's likely not used (anymore?). Either use it or " +
20 "remove it. If it's logical this module is an orphan (i.e. it's a config file), " +
21 "add an exception for it in your dependency-cruiser configuration. By default " +
22 "this rule does not scrutinize dot-files (e.g. .eslintrc.js), TypeScript declaration " +
23 "files (.d.ts), tsconfig.json and some of the babel and webpack configs.",
24 severity: 'warn',
25 from: {
26 orphan: true,
27 pathNot: [
28 '(^|/)\\.[^/]+\\.(js|cjs|mjs|ts|json)$', // dot files
29 '\\.d\\.ts$', // TypeScript declaration files
30 '(^|/)tsconfig\\.json$', // TypeScript config
31 '(^|/)(babel|webpack)\\.config\\.(js|cjs|mjs|ts|json)$' // other configs
32 ]
33 },
34 to: {},
35 },
36 {
37 name: 'no-deprecated-core',
38 comment:
39 'A module depends on a node core module that has been deprecated. Find an alternative - these are ' +
40 "bound to exist - node doesn't deprecate lightly.",
41 severity: 'warn',
42 from: {},
43 to: {
44 dependencyTypes: [
45 'core'
46 ],
47 path: [
48 '^(v8\/tools\/codemap)$',
49 '^(v8\/tools\/consarray)$',
50 '^(v8\/tools\/csvparser)$',
51 '^(v8\/tools\/logreader)$',
52 '^(v8\/tools\/profile_view)$',
53 '^(v8\/tools\/profile)$',
54 '^(v8\/tools\/SourceMap)$',
55 '^(v8\/tools\/splaytree)$',
56 '^(v8\/tools\/tickprocessor-driver)$',
57 '^(v8\/tools\/tickprocessor)$',
58 '^(node-inspect\/lib\/_inspect)$',
59 '^(node-inspect\/lib\/internal\/inspect_client)$',
60 '^(node-inspect\/lib\/internal\/inspect_repl)$',
61 '^(async_hooks)$',
62 '^(punycode)$',
63 '^(domain)$',
64 '^(constants)$',
65 '^(sys)$',
66 '^(_linklist)$',
67 '^(_stream_wrap)$'
68 ],
69 }
70 },
71 {
72 name: 'not-to-deprecated',
73 comment:
74 'This module uses a (version of an) npm module that has been deprecated. Either upgrade to a later ' +
75 'version of that module, or find an alternative. Deprecated modules are a security risk.',
76 severity: 'warn',
77 from: {},
78 to: {
79 dependencyTypes: [
80 'deprecated'
81 ]
82 }
83 },
84 {
85 name: 'no-non-package-json',
86 severity: 'error',
87 comment:
88 "This module depends on an npm package that isn't in the 'dependencies' section of your package.json. " +
89 "That's problematic as the package either (1) won't be available on live (2 - worse) will be " +
90 "available on live with an non-guaranteed version. Fix it by adding the package to the dependencies " +
91 "in your package.json.",
92 from: {},
93 to: {
94 dependencyTypes: [
95 'npm-no-pkg',
96 'npm-unknown'
97 ]
98 }
99 },
100 {
101 name: 'not-to-unresolvable',
102 comment:
103 "This module depends on a module that cannot be found ('resolved to disk'). If it's an npm " +
104 'module: add it to your package.json. In all other cases you likely already know what to do.',
105 severity: 'error',
106 from: {},
107 to: {
108 couldNotResolve: true
109 }
110 },
111 {
112 name: 'no-duplicate-dep-types',
113 comment:
114 "Likely this module depends on an external ('npm') package that occurs more than once " +
115 "in your package.json i.e. bot as a devDependencies and in dependencies. This will cause " +
116 "maintenance problems later on.",
117 severity: 'warn',
118 from: {},
119 to: {
120 moreThanOneDependencyType: true,
121 // as it's pretty common to have a type import be a type only import
122 // _and_ (e.g.) a devDependency - don't consider type-only dependency
123 // types for this rule
124 dependencyTypesNot: ["type-only"]
125 }
126 },
127
128 /* rules you might want to tweak for your specific situation: */
129 {
130 name: 'not-to-spec',
131 comment:
132 'This module depends on a spec (test) file. The sole responsibility of a spec file is to test code. ' +
133 "If there's something in a spec that's of use to other modules, it doesn't have that single " +
134 'responsibility anymore. Factor it out into (e.g.) a separate utility/ helper or a mock.',
135 severity: 'error',
136 from: {},
137 to: {
138 path: '\\.(spec|test)\\.(js|mjs|cjs|ts|ls|coffee|litcoffee|coffee\\.md)$'
139 }
140 },
141 {
142 name: 'not-to-dev-dep',
143 severity: 'error',
144 comment:
145 "This module depends on an npm package from the 'devDependencies' section of your " +
146 'package.json. It looks like something that ships to production, though. To prevent problems ' +
147 "with npm packages that aren't there on production declare it (only!) in the 'dependencies'" +
148 'section of your package.json. If this module is development only - add it to the ' +
149 'from.pathNot re of the not-to-dev-dep rule in the dependency-cruiser configuration',
150 from: {
151 path: '^(src)',
152 pathNot: '\\.(spec|test)\\.(js|mjs|cjs|ts|ls|coffee|litcoffee|coffee\\.md)$'
153 },
154 to: {
155 dependencyTypes: [
156 'npm-dev'
157 ]
158 }
159 },
160 {
161 name: 'optional-deps-used',
162 severity: 'info',
163 comment:
164 "This module depends on an npm package that is declared as an optional dependency " +
165 "in your package.json. As this makes sense in limited situations only, it's flagged here. " +
166 "If you're using an optional dependency here by design - add an exception to your" +
167 "dependency-cruiser configuration.",
168 from: {},
169 to: {
170 dependencyTypes: [
171 'npm-optional'
172 ]
173 }
174 },
175 {
176 name: 'peer-deps-used',
177 comment:
178 "This module depends on an npm package that is declared as a peer dependency " +
179 "in your package.json. This makes sense if your package is e.g. a plugin, but in " +
180 "other cases - maybe not so much. If the use of a peer dependency is intentional " +
181 "add an exception to your dependency-cruiser configuration.",
182 severity: 'warn',
183 from: {},
184 to: {
185 dependencyTypes: [
186 'npm-peer'
187 ]
188 }
189 }
190 ],
191 options: {
192
193 /* conditions specifying which files not to follow further when encountered:
194 - path: a regular expression to match
195 - dependencyTypes: see https://github.com/sverweij/dependency-cruiser/blob/master/doc/rules-reference.md#dependencytypes-and-dependencytypesnot
196 for a complete list
197 */
198 doNotFollow: {
199 path: 'node_modules'
200 },
201
202 /* conditions specifying which dependencies to exclude
203 - path: a regular expression to match
204 - dynamic: a boolean indicating whether to ignore dynamic (true) or static (false) dependencies.
205 leave out if you want to exclude neither (recommended!)
206 */
207 exclude : {
208 path: '.*\.test\.ts',
209 // dynamic: true
210 },
211
212 /* pattern specifying which files to include (regular expression)
213 dependency-cruiser will skip everything not matching this pattern
214 */
215 // includeOnly : '',
216
217 /* dependency-cruiser will include modules matching against the focus
218 regular expression in its output, as well as their neighbours (direct
219 dependencies and dependents)
220 */
221 // focus : '',
222
223 /* list of module systems to cruise */
224 // moduleSystems: ['amd', 'cjs', 'es6', 'tsd'],
225
226 /* prefix for links in html and svg output (e.g. 'https://github.com/you/yourrepo/blob/develop/'
227 to open it on your online repo or `vscode://file/${process.cwd()}/` to
228 open it in visual studio code),
229 */
230 // prefix: '',
231
232 /* false (the default): ignore dependencies that only exist before typescript-to-javascript compilation
233 true: also detect dependencies that only exist before typescript-to-javascript compilation
234 "specify": for each dependency identify whether it only exists before compilation or also after
235 */
236 tsPreCompilationDeps: true,
237
238 /*
239 list of extensions to scan that aren't javascript or compile-to-javascript.
240 Empty by default. Only put extensions in here that you want to take into
241 account that are _not_ parsable.
242 */
243 // extraExtensionsToScan: [".json", ".jpg", ".png", ".svg", ".webp"],
244
245 /* if true combines the package.jsons found from the module up to the base
246 folder the cruise is initiated from. Useful for how (some) mono-repos
247 manage dependencies & dependency definitions.
248 */
249 // combinedDependencies: false,
250
251 /* if true leave symlinks untouched, otherwise use the realpath */
252 // preserveSymlinks: false,
253
254 /* TypeScript project file ('tsconfig.json') to use for
255 (1) compilation and
256 (2) resolution (e.g. with the paths property)
257
258 The (optional) fileName attribute specifies which file to take (relative to
259 dependency-cruiser's current working directory). When not provided
260 defaults to './tsconfig.json'.
261 */
262 tsConfig: {
263 fileName: 'tsconfig.json'
264 },
265
266 /* Webpack configuration to use to get resolve options from.
267
268 The (optional) fileName attribute specifies which file to take (relative
269 to dependency-cruiser's current working directory. When not provided defaults
270 to './webpack.conf.js'.
271
272 The (optional) `env` and `arguments` attributes contain the parameters to be passed if
273 your webpack config is a function and takes them (see webpack documentation
274 for details)
275 */
276 // webpackConfig: {
277 // fileName: './webpack.config.js',
278 // env: {},
279 // arguments: {},
280 // },
281
282 /* Babel config ('.babelrc', '.babelrc.json', '.babelrc.json5', ...) to use
283 for compilation (and whatever other naughty things babel plugins do to
284 source code). This feature is well tested and usable, but might change
285 behavior a bit over time (e.g. more precise results for used module
286 systems) without dependency-cruiser getting a major version bump.
287 */
288 // babelConfig: {
289 // fileName: './.babelrc'
290 // },
291
292 /* List of strings you have in use in addition to cjs/ es6 requires
293 & imports to declare module dependencies. Use this e.g. if you've
294 re-declared require, use a require-wrapper or use window.require as
295 a hack.
296 */
297 // exoticRequireStrings: [],
298 /* options to pass on to enhanced-resolve, the package dependency-cruiser
299 uses to resolve module references to disk. You can set most of these
300 options in a webpack.conf.js - this section is here for those
301 projects that don't have a separate webpack config file.
302
303 Note: settings in webpack.conf.js override the ones specified here.
304 */
305 enhancedResolveOptions: {
306 /* List of strings to consider as 'exports' fields in package.json. Use
307 ['exports'] when you use packages that use such a field and your environment
308 supports it (e.g. node ^12.19 || >=14.7 or recent versions of webpack).
309
310 If you have an `exportsFields` attribute in your webpack config, that one
311 will have precedence over the one specified here.
312 */
313 exportsFields: ["exports"],
314 /* List of conditions to check for in the exports field. e.g. use ['imports']
315 if you're only interested in exposed es6 modules, ['require'] for commonjs,
316 or all conditions at once `(['import', 'require', 'node', 'default']`)
317 if anything goes for you. Only works when the 'exportsFields' array is
318 non-empty.
319
320 If you have a 'conditionNames' attribute in your webpack config, that one will
321 have precedence over the one specified here.
322 */
323 conditionNames: ["import", "require", "node", "default"],
324 /*
325 The extensions, by default are the same as the ones dependency-cruiser
326 can access (run `npx depcruise --info` to see which ones that are in
327 _your_ environment. If that list is larger than what you need (e.g.
328 it contains .js, .jsx, .ts, .tsx, .cts, .mts - but you don't use
329 TypeScript you can pass just the extensions you actually use (e.g.
330 [".js", ".jsx"]). This can speed up the most expensive step in
331 dependency cruising (module resolution) quite a bit.
332 */
333 // extensions: [".js", ".jsx", ".ts", ".tsx", ".d.ts"],
334 /*
335 If your TypeScript project makes use of types specified in 'types'
336 fields in package.jsons of external dependencies, specify "types"
337 in addition to "main" in here, so enhanced-resolve (the resolver
338 dependency-cruiser uses) knows to also look there. You can also do
339 this if you're not sure, but still use TypeScript. In a future version
340 of dependency-cruiser this will likely become the default.
341 */
342 mainFields: ["main", "types"],
343 },
344 reporterOptions: {
345 dot: {
346 /* pattern of modules that can be consolidated in the detailed
347 graphical dependency graph. The default pattern in this configuration
348 collapses everything in node_modules to one folder deep so you see
349 the external modules, but not the innards your app depends upon.
350 */
351 collapsePattern: 'node_modules/(@[^/]+/[^/]+|[^/]+)',
352
353 /* Options to tweak the appearance of your graph.See
354 https://github.com/sverweij/dependency-cruiser/blob/master/doc/options-reference.md#reporteroptions
355 for details and some examples. If you don't specify a theme
356 don't worry - dependency-cruiser will fall back to the default one.
357 */
358 // theme: {
359 // graph: {
360 // /* use splines: "ortho" for straight lines. Be aware though
361 // graphviz might take a long time calculating ortho(gonal)
362 // routings.
363 // */
364 // splines: "true"
365 // },
366 // modules: [
367 // {
368 // criteria: { matchesFocus: true },
369 // attributes: {
370 // fillcolor: "lime",
371 // penwidth: 2,
372 // },
373 // },
374 // {
375 // criteria: { matchesFocus: false },
376 // attributes: {
377 // fillcolor: "lightgrey",
378 // },
379 // },
380 // {
381 // criteria: { matchesReaches: true },
382 // attributes: {
383 // fillcolor: "lime",
384 // penwidth: 2,
385 // },
386 // },
387 // {
388 // criteria: { matchesReaches: false },
389 // attributes: {
390 // fillcolor: "lightgrey",
391 // },
392 // },
393 // {
394 // criteria: { source: "^src/model" },
395 // attributes: { fillcolor: "#ccccff" }
396 // },
397 // {
398 // criteria: { source: "^src/view" },
399 // attributes: { fillcolor: "#ccffcc" }
400 // },
401 // ],
402 // dependencies: [
403 // {
404 // criteria: { "rules[0].severity": "error" },
405 // attributes: { fontcolor: "red", color: "red" }
406 // },
407 // {
408 // criteria: { "rules[0].severity": "warn" },
409 // attributes: { fontcolor: "orange", color: "orange" }
410 // },
411 // {
412 // criteria: { "rules[0].severity": "info" },
413 // attributes: { fontcolor: "blue", color: "blue" }
414 // },
415 // {
416 // criteria: { resolved: "^src/model" },
417 // attributes: { color: "#0000ff77" }
418 // },
419 // {
420 // criteria: { resolved: "^src/view" },
421 // attributes: { color: "#00770077" }
422 // }
423 // ]
424 // }
425 },
426 archi: {
427 /* pattern of modules that can be consolidated in the high level
428 graphical dependency graph. If you use the high level graphical
429 dependency graph reporter (`archi`) you probably want to tweak
430 this collapsePattern to your situation.
431 */
432 collapsePattern: '^(packages|src|lib|app|bin|test(s?)|spec(s?))/[^/]+|node_modules/(@[^/]+/[^/]+|[^/]+)',
433
434 /* Options to tweak the appearance of your graph.See
435 https://github.com/sverweij/dependency-cruiser/blob/master/doc/options-reference.md#reporteroptions
436 for details and some examples. If you don't specify a theme
437 for 'archi' dependency-cruiser will use the one specified in the
438 dot section (see above), if any, and otherwise use the default one.
439 */
440 // theme: {
441 // },
442 },
443 "text": {
444 "highlightFocused": true
445 },
446 }
447 }
448 };
449 // generated: dependency-cruiser@12.12.0 on 2023-05-05T19:06:19.143Z