Skip to content

Commit 4926340

Browse files
committed
add depdency graph
1 parent ceb53be commit 4926340

File tree

3 files changed

+569
-1
lines changed

3 files changed

+569
-1
lines changed

.dependency-cruiser.js

Lines changed: 377 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,377 @@
1+
module.exports = {
2+
forbidden: [
3+
/* rules from the 'recommended' preset: */
4+
{
5+
name: 'no-circular',
6+
severity: 'warn',
7+
comment:
8+
'This dependency is part of a circular relationship. You might want to revise ' +
9+
'your solution (i.e. use dependency inversion, make sure the modules have a single responsibility) ',
10+
from: {},
11+
to: {
12+
circular: true
13+
}
14+
},
15+
{
16+
name: 'no-orphans',
17+
comment:
18+
"This is an orphan module - it's likely not used (anymore?). Either use it or " +
19+
"remove it. If it's logical this module is an orphan (i.e. it's a config file), " +
20+
"add an exception for it in your dependency-cruiser configuration. By default " +
21+
"this rule does not scrutinize dotfiles (e.g. .eslintrc.js), TypeScript declaration " +
22+
"files (.d.ts), tsconfig.json and some of the babel and webpack configs.",
23+
severity: 'warn',
24+
from: {
25+
orphan: true,
26+
pathNot: [
27+
'(^|/)\\.[^/]+\\.(js|cjs|mjs|ts|json)$', // dot files
28+
'\\.d\\.ts$', // TypeScript declaration files
29+
'(^|/)tsconfig\\.json$', // TypeScript config
30+
'(^|/)(babel|webpack)\\.config\\.(js|cjs|mjs|ts|json)$' // other configs
31+
]
32+
},
33+
to: {},
34+
},
35+
{
36+
name: 'no-deprecated-core',
37+
comment:
38+
'A module depends on a node core module that has been deprecated. Find an alternative - these are ' +
39+
"bound to exist - node doesn't deprecate lightly.",
40+
severity: 'warn',
41+
from: {},
42+
to: {
43+
dependencyTypes: [
44+
'core'
45+
],
46+
path: '^(punycode|domain|constants|sys|_linklist|_stream_wrap)$'
47+
}
48+
},
49+
{
50+
name: 'not-to-deprecated',
51+
comment:
52+
'This module uses a (version of an) npm module that has been deprecated. Either upgrade to a later ' +
53+
'version of that module, or find an alternative. Deprecated modules are a security risk.',
54+
severity: 'warn',
55+
from: {},
56+
to: {
57+
dependencyTypes: [
58+
'deprecated'
59+
]
60+
}
61+
},
62+
{
63+
name: 'no-non-package-json',
64+
severity: 'error',
65+
comment:
66+
"This module depends on an npm package that isn't in the 'dependencies' section of your package.json. " +
67+
"That's problematic as the package either (1) won't be available on live (2 - worse) will be " +
68+
"available on live with an non-guaranteed version. Fix it by adding the package to the dependencies " +
69+
"in your package.json.",
70+
from: {},
71+
to: {
72+
dependencyTypes: [
73+
'npm-no-pkg',
74+
'npm-unknown'
75+
]
76+
}
77+
},
78+
{
79+
name: 'not-to-unresolvable',
80+
comment:
81+
"This module depends on a module that cannot be found ('resolved to disk'). If it's an npm " +
82+
'module: add it to your package.json. In all other cases you likely already know what to do.',
83+
severity: 'error',
84+
from: {},
85+
to: {
86+
couldNotResolve: true
87+
}
88+
},
89+
{
90+
name: 'no-duplicate-dep-types',
91+
comment:
92+
"Likeley this module depends on an external ('npm') package that occurs more than once " +
93+
"in your package.json i.e. bot as a devDependencies and in dependencies. This will cause " +
94+
"maintenance problems later on.",
95+
severity: 'warn',
96+
from: {},
97+
to: {
98+
moreThanOneDependencyType: true
99+
}
100+
},
101+
102+
/* rules you might want to tweak for your specific situation: */
103+
{
104+
name: 'not-to-test',
105+
comment:
106+
"This module depends on code within a folder that should only contain tests. As tests don't " +
107+
"implement functionality this is odd. Either you're writing a test outside the test folder " +
108+
"or there's something in the test folder that isn't a test.",
109+
severity: 'error',
110+
from: {
111+
pathNot: '^(test)'
112+
},
113+
to: {
114+
path: '^(test)'
115+
}
116+
},
117+
{
118+
name: 'not-to-spec',
119+
comment:
120+
'This module depends on a spec (test) file. The sole responsibility of a spec file is to test code. ' +
121+
"If there's something in a spec that's of use to other modules, it doesn't have that single " +
122+
'responsibility anymore. Factor it out into (e.g.) a separate utility/ helper or a mock.',
123+
severity: 'error',
124+
from: {},
125+
to: {
126+
path: '\\.spec\\.(js|mjs|cjs|ts|ls|coffee|litcoffee|coffee\\.md)$'
127+
}
128+
},
129+
// {
130+
// name: 'not-to-dev-dep',
131+
// severity: 'error',
132+
// comment:
133+
// "This module depends on an npm package from the 'devDependencies' section of your " +
134+
// 'package.json. It looks like something that ships to production, though. To prevent problems ' +
135+
// "with npm packages that aren't there on production declare it (only!) in the 'dependencies'" +
136+
// 'section of your package.json. If this module is development only - add it to the ' +
137+
// 'from.pathNot re of the not-to-dev-dep rule in the dependency-cruiser configuration',
138+
// from: {
139+
// path: '^()',
140+
// pathNot: '\\.spec\\.(js|mjs|cjs|ts|ls|coffee|litcoffee|coffee\\.md)$'
141+
// },
142+
// to: {
143+
// dependencyTypes: [
144+
// 'npm-dev'
145+
// ]
146+
// }
147+
// },
148+
{
149+
name: 'optional-deps-used',
150+
severity: 'info',
151+
comment:
152+
"This module depends on an npm package that is declared as an optional dependency " +
153+
"in your package.json. As this makes sense in limited situations only, it's flagged here. " +
154+
"If you're using an optional dependency here by design - add an exception to your" +
155+
"depdency-cruiser configuration.",
156+
from: {},
157+
to: {
158+
dependencyTypes: [
159+
'npm-optional'
160+
]
161+
}
162+
},
163+
{
164+
name: 'peer-deps-used',
165+
comment:
166+
"This module depends on an npm package that is declared as a peer dependency " +
167+
"in your package.json. This makes sense if your package is e.g. a plugin, but in " +
168+
"other cases - maybe not so much. If the use of a peer dependency is intentional " +
169+
"add an exception to your dependency-cruiser configuration.",
170+
severity: 'warn',
171+
from: {},
172+
to: {
173+
dependencyTypes: [
174+
'npm-peer'
175+
]
176+
}
177+
}
178+
],
179+
options: {
180+
181+
/* conditions specifying which files not to follow further when encountered:
182+
- path: a regular expression to match
183+
- dependencyTypes: see https://github.com/sverweij/dependency-cruiser/blob/master/doc/rules-reference.md#dependencytypes
184+
for a complete list
185+
*/
186+
doNotFollow: {
187+
path: '(node_modules|coverage)',
188+
dependencyTypes: [
189+
'npm',
190+
'npm-dev',
191+
'npm-optional',
192+
'npm-peer',
193+
'npm-bundled',
194+
'npm-no-pkg'
195+
]
196+
},
197+
198+
/* conditions specifying which dependencies to exclude
199+
- path: a regular expression to match
200+
- dynamic: a boolean indicating whether to ignore dynamic (true) or static (false) dependencies.
201+
leave out if you want to exclude neither (recommended!)
202+
*/
203+
// exclude : {
204+
// path: '',
205+
// dynamic: true
206+
// },
207+
208+
/* pattern specifying which files to include (regular expression)
209+
dependency-cruiser will skip everything not matching this pattern
210+
*/
211+
// includeOnly : '',
212+
213+
/* dependency-cruiser will include modules matching against the focus
214+
regular expression in its output, as well as their neighbours (direct
215+
dependencies and dependents)
216+
*/
217+
// focus : '',
218+
219+
/* list of module systems to cruise */
220+
// moduleSystems: ['amd', 'cjs', 'es6', 'tsd'],
221+
222+
/* prefix for links in html and svg output (e.g. https://github.com/you/yourrepo/blob/develop/) */
223+
// prefix: '',
224+
225+
/* false (the default): ignore dependencies that only exist before typescript-to-javascript compilation
226+
true: also detect dependencies that only exist before typescript-to-javascript compilation
227+
"specify": for each dependency identify whether it only exists before compilation or also after
228+
*/
229+
// tsPreCompilationDeps: false,
230+
231+
/* if true combines the package.jsons found from the module up to the base
232+
folder the cruise is initiated from. Useful for how (some) mono-repos
233+
manage dependencies & dependency definitions.
234+
*/
235+
// combinedDependencies: false,
236+
237+
/* if true leave symlinks untouched, otherwise use the realpath */
238+
// preserveSymlinks: false,
239+
240+
/* TypeScript project file ('tsconfig.json') to use for
241+
(1) compilation and
242+
(2) resolution (e.g. with the paths property)
243+
244+
The (optional) fileName attribute specifies which file to take (relative to
245+
dependency-cruiser's current working directory). When not provided
246+
defaults to './tsconfig.json'.
247+
*/
248+
// tsConfig: {
249+
// fileName: './tsconfig.json'
250+
// },
251+
252+
/* Webpack configuration to use to get resolve options from.
253+
254+
The (optional) fileName attribute specifies which file to take (relative
255+
to dependency-cruiser's current working directory. When not provided defaults
256+
to './webpack.conf.js'.
257+
258+
The (optional) `env` and `args` attributes contain the parameters to be passed if
259+
your webpack config is a function and takes them (see webpack documentation
260+
for details)
261+
*/
262+
// webpackConfig: {
263+
// fileName: './webpack.config.js',
264+
// env: {},
265+
// args: {},
266+
// },
267+
268+
/* Babel config ('.babelrc', '.babelrc.json', '.babelrc.json5', ...) to use
269+
for compilation (and whatever other naughty things babel plugins do to
270+
source code). This feature is well tested and usable, but might change
271+
behavior a bit over time (e.g. more precise results for used module
272+
systems) without dependency-cruiser getting a major version bump.
273+
*/
274+
// babelConfig: {
275+
// fileName: './.babelrc'
276+
// },
277+
278+
279+
/* How to resolve external modules - use "yarn-pnp" if you're using yarn's Plug'n'Play.
280+
otherwise leave it out (or set to the default, which is 'node_modules')
281+
*/
282+
// externalModuleResolutionStrategy: 'node_modules',
283+
/* List of strings you have in use in addition to cjs/ es6 requires
284+
& imports to declare module dependencies. Use this e.g. if you've
285+
redeclared require, use a require-wrapper or use window.require as
286+
a hack.
287+
*/
288+
// exoticRequireStrings: [],
289+
reporterOptions: {
290+
dot: {
291+
/* pattern of modules that can be consolidated in the detailed
292+
graphical dependency graph. The default pattern in this configuration
293+
collapses everything in node_modules to one folder deep so you see
294+
the external modules, but not the innards your app depends upon.
295+
*/
296+
collapsePattern: 'node_modules/[^/]+',
297+
298+
/* Options to tweak the appearance of your graph.See
299+
https://github.com/sverweij/dependency-cruiser/blob/master/doc/rules-reference.md#dot
300+
for details and some examples. If you don't specify a theme
301+
don't worry - dependency-cruiser will fall back to the default one.
302+
*/
303+
theme: {
304+
graph: {
305+
splines: true,
306+
},
307+
modules: [
308+
{
309+
criteria: { source: "\\.json$" },
310+
attributes: {
311+
shape: "cylinder",
312+
fillcolor: "#ffffff33:#ffffff88",
313+
},
314+
},
315+
{
316+
criteria: { coreModule: true },
317+
attributes: {
318+
color: "white",
319+
fillcolor: "#ffffff33",
320+
fontcolor: "white",
321+
},
322+
},
323+
324+
{
325+
criteria: { source: "^src/model" },
326+
attributes: { fillcolor: "#ccccff" }
327+
},
328+
{
329+
criteria: { source: "^src/view" },
330+
attributes: { fillcolor: "#ccffcc" }
331+
}
332+
],
333+
dependencies: [
334+
{
335+
criteria: { "rules[0].severity": "error" },
336+
attributes: { fontcolor: "red", color: "red" }
337+
},
338+
{
339+
criteria: { "rules[0].severity": "warn" },
340+
attributes: { fontcolor: "orange", color: "orange" }
341+
},
342+
{
343+
criteria: { "rules[0].severity": "info" },
344+
attributes: { fontcolor: "blue", color: "blue" }
345+
},
346+
{
347+
criteria: { resolved: "^src/model" },
348+
attributes: { color: "#0000ff77" }
349+
},
350+
{
351+
criteria: { resolved: "^src/view" },
352+
attributes: { color: "#00770077" }
353+
}
354+
]
355+
}
356+
},
357+
// archi: {
358+
// /* pattern of modules that can be consolidated in the high level
359+
// graphical dependency graph. If you use the high level graphical
360+
// dependency graph reporter (`archi`) you probably want to tweak
361+
// this collapsePattern to your situation.
362+
// */
363+
// collapsePattern: '^(node_modules|packages|src|lib|app|bin|test(s?)|spec(s?))/[^/]+',
364+
365+
// /* Options to tweak the appearance of your graph.See
366+
// https://github.com/sverweij/dependency-cruiser/blob/master/doc/rules-reference.md#dot
367+
// for details and some examples. If you don't specify a theme
368+
// for 'archi' dependency-cruiser will use the one specified in the
369+
// dot section (see above), if any, and otherwise use the default one.
370+
// */
371+
// // theme: {
372+
// // },
373+
// }
374+
}
375+
}
376+
};
377+
// generated: [email protected] on 2020-06-16T06:49:38.964Z

0 commit comments

Comments
 (0)