Skip to content

Commit d9c8eb8

Browse files
committed
drawing dependency refactor
1 parent b2f405b commit d9c8eb8

27 files changed

+533
-96
lines changed

.dependency-cruiser.js

+391
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,391 @@
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 dotfiles (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+
"Likeley 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+
"depdency-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: '',
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: false,
237+
238+
/* list of extensions (typically non-parseable) to scan. Empty by default. */
239+
// extraExtensionsToScan: [".json", ".jpg", ".png", ".svg", ".webp"],
240+
241+
/* if true combines the package.jsons found from the module up to the base
242+
folder the cruise is initiated from. Useful for how (some) mono-repos
243+
manage dependencies & dependency definitions.
244+
*/
245+
// combinedDependencies: false,
246+
247+
/* if true leave symlinks untouched, otherwise use the realpath */
248+
// preserveSymlinks: false,
249+
250+
/* TypeScript project file ('tsconfig.json') to use for
251+
(1) compilation and
252+
(2) resolution (e.g. with the paths property)
253+
The (optional) fileName attribute specifies which file to take (relative to
254+
dependency-cruiser's current working directory). When not provided
255+
defaults to './tsconfig.json'.
256+
*/
257+
tsConfig: {
258+
fileName: 'tsconfig.json'
259+
},
260+
261+
/* Webpack configuration to use to get resolve options from.
262+
The (optional) fileName attribute specifies which file to take (relative
263+
to dependency-cruiser's current working directory. When not provided defaults
264+
to './webpack.conf.js'.
265+
The (optional) `env` and `args` attributes contain the parameters to be passed if
266+
your webpack config is a function and takes them (see webpack documentation
267+
for details)
268+
*/
269+
webpackConfig: {
270+
fileName: 'webpack.config.js',
271+
env: {},
272+
arguments: {mode: "production"},
273+
},
274+
275+
/* Babel config ('.babelrc', '.babelrc.json', '.babelrc.json5', ...) to use
276+
for compilation (and whatever other naughty things babel plugins do to
277+
source code). This feature is well tested and usable, but might change
278+
behavior a bit over time (e.g. more precise results for used module
279+
systems) without dependency-cruiser getting a major version bump.
280+
*/
281+
// babelConfig: {
282+
// fileName: './.babelrc'
283+
// },
284+
285+
/* List of strings you have in use in addition to cjs/ es6 requires
286+
& imports to declare module dependencies. Use this e.g. if you've
287+
redeclared require, use a require-wrapper or use window.require as
288+
a hack.
289+
*/
290+
// exoticRequireStrings: [],
291+
/* options to pass on to enhanced-resolve, the package dependency-cruiser
292+
uses to resolve module references to disk. You can set most of these
293+
options in a webpack.conf.js - this section is here for those
294+
projects that don't have a separate webpack config file.
295+
Note: settings in webpack.conf.js override the ones specified here.
296+
*/
297+
enhancedResolveOptions: {
298+
/* List of strings to consider as 'exports' fields in package.json. Use
299+
['exports'] when you use packages that use such a field and your environment
300+
supports it (e.g. node ^12.19 || >=14.7 or recent versions of webpack).
301+
If you have an `exportsFields` attribute in your webpack config, that one
302+
will have precedence over the one specified here.
303+
*/
304+
exportsFields: ["exports"],
305+
/* List of conditions to check for in the exports field. e.g. use ['imports']
306+
if you're only interested in exposed es6 modules, ['require'] for commonjs,
307+
or all conditions at once `(['import', 'require', 'node', 'default']`)
308+
if anything goes for you. Only works when the 'exportsFields' array is
309+
non-empty.
310+
If you have a 'conditionNames' attribute in your webpack config, that one will
311+
have precedence over the one specified here.
312+
*/
313+
conditionNames: ["import", "require", "node", "default"]
314+
},
315+
reporterOptions: {
316+
dot: {
317+
/* pattern of modules that can be consolidated in the detailed
318+
graphical dependency graph. The default pattern in this configuration
319+
collapses everything in node_modules to one folder deep so you see
320+
the external modules, but not the innards your app depends upon.
321+
*/
322+
collapsePattern: 'node_modules/[^/]+',
323+
324+
/* Options to tweak the appearance of your graph.See
325+
https://github.com/sverweij/dependency-cruiser/blob/master/doc/options-reference.md#reporteroptions
326+
for details and some examples. If you don't specify a theme
327+
don't worry - dependency-cruiser will fall back to the default one.
328+
*/
329+
// theme: {
330+
// graph: {
331+
// /* use splines: "ortho" for straight lines. Be aware though
332+
// graphviz might take a long time calculating ortho(gonal)
333+
// routings.
334+
// */
335+
// splines: "true"
336+
// },
337+
// modules: [
338+
// {
339+
// criteria: { source: "^src/model" },
340+
// attributes: { fillcolor: "#ccccff" }
341+
// },
342+
// {
343+
// criteria: { source: "^src/view" },
344+
// attributes: { fillcolor: "#ccffcc" }
345+
// }
346+
// ],
347+
// dependencies: [
348+
// {
349+
// criteria: { "rules[0].severity": "error" },
350+
// attributes: { fontcolor: "red", color: "red" }
351+
// },
352+
// {
353+
// criteria: { "rules[0].severity": "warn" },
354+
// attributes: { fontcolor: "orange", color: "orange" }
355+
// },
356+
// {
357+
// criteria: { "rules[0].severity": "info" },
358+
// attributes: { fontcolor: "blue", color: "blue" }
359+
// },
360+
// {
361+
// criteria: { resolved: "^src/model" },
362+
// attributes: { color: "#0000ff77" }
363+
// },
364+
// {
365+
// criteria: { resolved: "^src/view" },
366+
// attributes: { color: "#00770077" }
367+
// }
368+
// ]
369+
// }
370+
},
371+
archi: {
372+
/* pattern of modules that can be consolidated in the high level
373+
graphical dependency graph. If you use the high level graphical
374+
dependency graph reporter (`archi`) you probably want to tweak
375+
this collapsePattern to your situation.
376+
*/
377+
collapsePattern: '^(packages|src|lib|app|bin|test(s?)|spec(s?))/[^/]+|node_modules/[^/]+',
378+
379+
/* Options to tweak the appearance of your graph.See
380+
https://github.com/sverweij/dependency-cruiser/blob/master/doc/options-reference.md#reporteroptions
381+
for details and some examples. If you don't specify a theme
382+
for 'archi' dependency-cruiser will use the one specified in the
383+
dot section (see above), if any, and otherwise use the default one.
384+
*/
385+
// theme: {
386+
// },
387+
}
388+
}
389+
}
390+
};
391+
// generated: [email protected] on 2022-06-06T03:32:00.982Z

0 commit comments

Comments
 (0)