UNPKG

6.09 kBMarkdownView Raw
1# Dependency cruiser ![Dependency cruiser](https://raw.githubusercontent.com/sverweij/dependency-cruiser/master/doc/assets/ZKH-Dependency-recolored-160.png)
2
3_Validate and visualise dependencies. With your rules._ JavaScript. TypeScript. CoffeeScript. ES6, CommonJS, AMD.
4
5## What's this do?
6
7![Snazzy dot output to whet your appetite](https://raw.githubusercontent.com/sverweij/dependency-cruiser/master/doc/assets/sample-dot-output.png)
8
9This runs through the dependencies in any JavaScript, TypeScript, LiveScript or CoffeeScript project and ...
10
11- ... **validates** them against (your own) [rules](./doc/rules-reference.md)
12- ... **reports** violated rules
13 - in text (for your builds)
14 - in graphics (for your eyeballs)
15
16As a side effect it can generate [**cool dependency graphs**](./doc/real-world-samples.md)
17you can stick on the wall to impress your grandma.
18
19## How do I use it?
20
21### Install it
22
23- `npm install --save-dev dependency-cruiser` to use it as a validator in your project (recommended) or...
24- `npm install --global dependency-cruiser` if you just want to to inspect multiple projects.
25
26### Show stuff to your grandma
27
28To create a graph of the dependencies in your src folder, you'd run dependency
29cruiser with output type `dot` and run _GraphViz dot_ on the result. In
30a one liner:
31
32```shell
33depcruise --include-only "^src" --output-type dot src | dot -T svg > dependencygraph.svg
34```
35
36- You can read more about what you can do with `--include-only` and other command line
37 options in the
38 [command line interface](./doc/cli.md)
39 documentation.
40- _[Real world samples](./doc/real-world-samples.md)_
41 contains dependency cruises of some of the most used projects on npm.
42
43### Validate things
44
45#### Declare some rules
46
47The easy way to get you started:
48
49```shell
50depcruise --init
51```
52
53This will create a `.dependency-cruiser.json` with some rules that make sense
54in most projects (detecting **circular dependencies**, dependencies
55**missing** in package.json, **orphans**, production code relying on
56dev- or optionalDependencies, ...).
57
58Start adding your rules by tweaking that file.
59
60Sample rule:
61
62```json
63{
64 "forbidden": [
65 {
66 "name": "not-to-test",
67 "comment": "don't allow dependencies from outside the test folder to test",
68 "severity": "error",
69 "from": { "pathNot": "^test" },
70 "to": { "path": "^test" }
71 }
72 ]
73}
74```
75
76- To read more about writing rules check the
77 [writing rules](./doc/rules-tutorial.md) tutorial
78 or the [rules reference](./doc/rules-reference.md)
79- You can find the `--init-rules` set [here](./doc/rules.starter.json)
80
81#### Report them
82
83```sh
84depcruise --validate .dependency-cruiser.json src
85```
86
87This will validate against your rules and shows any violations in an eslint-like format:
88
89![sample err output](https://raw.githubusercontent.com/sverweij/dependency-cruiser/master/doc/assets/sample-err-output.png)
90
91There's more ways to report validations; in a graph (like the one on top of this
92readme) or in a table.
93
94- Read more about the err, dot, csv and html reporters in the
95 [command line interface](./doc/cli.md)
96 documentation.
97- dependency-cruiser uses itself to check on itself in its own build process;
98 see the `decpruise` script in the
99 [package.json](https://github.com/sverweij/dependency-cruiser/blob/master/package.json#L12)
100
101## I want to know more!
102
103You've come to the right place :-) :
104
105- Usage
106 - [Command line reference](./doc/cli.md)
107 - [Writing rules](./doc/rules-tutorial.md)
108 - [Rules reference](./doc/rules-reference.md)
109 - [FAQ](./doc/faq.md)
110- Hacking on dependency-cruiser
111 - [API](./doc/api.md)
112 - [Output format](./doc/output-format.md)
113 - [Adding other output formats](./doc/faq.md#q-how-do-i-add-a-new-output-format)
114 - [Adding support for other alt-js languages](./doc/faq.md#q-how-do-i-add-support-for-my-favorite-alt-js-language)
115- Other things
116 - [Road map](https://github.com/sverweij/dependency-cruiser/projects/1)
117 - [Contact](./doc/faq.md#contact)
118 - [Real world show cases](./doc/real-world-samples.md)
119 - [TypeScript, CoffeeScript and LiveScript support](./doc/faq.md#features)
120 - [Support for .jsx, .tsx, .csx/ .cjsx and .vue](./doc/faq.md#q-im-developing-in-react-and-use-jsx-tsx-csx-cjsx-how-do-i-get-that-to-work)
121 - [Webpack alias/ modules support](./doc/faq.md#q-does-this-work-with-webpack-configs-eg-alias-and-modules)
122
123## License
124
125[MIT](LICENSE)
126
127## Thanks
128
129- [Marijn Haverbeke](http://marijnhaverbeke.nl) and other people who
130 collaborated on [acorn](https://github.com/ternjs/acorn) -
131 the excellent JavaScript parser dependency-cruiser uses to infer
132 dependencies.
133- [Katerina Limpitsouni](https://twitter.com/ninaLimpi) of [unDraw](https://undraw.co/)
134 for the ollie in dependency-cruiser's
135 [social media image](https://repository-images.githubusercontent.com/74299372/239ed080-370b-11ea-8fe7-140cf7b90a33).
136- All members of the open source community who have been kind enough to raise issues,
137 ask questions and make pull requests to get dependency-cruiser to be a better
138 tool.
139
140## Build status
141
142[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/sverweij/dependency-cruiser/linting%20%26%20test%20coverage%20-%20linux?label=actions&logo=github)](https://github.com/sverweij/dependency-cruiser/actions)
143[![Build Status](https://travis-ci.org/sverweij/dependency-cruiser.svg?branch=master)](https://travis-ci.org/sverweij/dependency-cruiser)
144[![coverage](https://gitlab.com/sverweij/dependency-cruiser/badges/master/coverage.svg)](https://gitlab.com/sverweij/dependency-cruiser/builds)
145[![Maintainability](https://api.codeclimate.com/v1/badges/93035ef5fba33901d479/maintainability)](https://codeclimate.com/github/sverweij/dependency-cruiser/maintainability)
146[![Test Coverage](https://api.codeclimate.com/v1/badges/93035ef5fba33901d479/test_coverage)](https://codeclimate.com/github/sverweij/dependency-cruiser/test_coverage)
147[![total downloads on npm](https://img.shields.io/npm/dt/dependency-cruiser.svg?maxAge=2591999)](https://npmjs.com/package/dependency-cruiser)
148
149Made with :metal: in Holland.