UNPKG

9.77 kBTypeScriptView Raw
1import { ICruiseOptions } from "./options";
2import { IFlattenedRuleSet } from "./rule-set";
3import { DependencyType, ModuleSystemType, SeverityType } from "./shared-types";
4
5export interface ICruiseResult {
6 /**
7 * A list of modules, with for each module the modules it depends upon
8 */
9 modules: IModule[];
10 /**
11 * Data summarizing the found dependencies
12 */
13 summary: ISummary;
14}
15
16export interface IModule {
17 /**
18 * The (resolved) file name of the module, e.g. 'src/main/index.js'
19 */
20 source: string;
21 /**
22 * 'true' if this module violated a rule; 'false' in all other cases. The violated rule will
23 * be in the 'rule' object at the same level.
24 */
25 valid: boolean;
26 dependencies: IDependency[];
27 /**
28 * Whether or not this is a node.js core module
29 */
30 coreModule?: boolean;
31 /**
32 * 'true' if dependency-cruiser could not resolve the module name in the source code to a
33 * file name or core module. 'false' in all other cases.
34 */
35 couldNotResolve?: boolean;
36 /**
37 * the type of inclusion - local, core, unknown (= we honestly don't know), undetermined (=
38 * we didn't bother determining it) or one of the npm dependencies defined in a package.jsom
39 * ('npm' for 'depenencies', 'npm-dev', 'npm-optional', 'npm-peer', 'npm-no-pkg' for
40 * development, optional, peer dependencies and dependencies in node_modules but not in
41 * package.json respectively)
42 */
43 dependencyTypes?: DependencyType[];
44 /**
45 * Whether or not this is a dependency that can be followed any further. This will be
46 * 'false' for for core modules, json, modules that could not be resolved to a file and
47 * modules that weren't followed because it matches the doNotFollow expression.
48 */
49 followable?: boolean;
50 /**
51 * the license, if known (usually known for modules pulled from npm, not for local ones)
52 */
53 license?: string;
54 /**
55 * 'true' if the file name of this module matches the doNotFollow regular expression
56 */
57 matchesDoNotFollow?: boolean;
58 /**
59 * 'true' if the file name of this module matches the focus regular expression
60 */
61 matchesFocus?: boolean;
62 /**
63 * 'true' if this module does not have dependencies, and no module has it as a dependency
64 */
65 orphan?: boolean;
66 /**
67 * An array of objects that tell whether this module is 'reachable', and according to rule
68 * in which this reachability was defined
69 */
70 reachable?: IReachable[];
71 /**
72 * An array of objects that tell which other modules it reaches,
73 * and that falls within the definition of the passed rule.
74 */
75 reaches?: IReaches[];
76 /**
77 * an array of rules violated by this module - left out if the module is valid
78 */
79 rules?: IRuleSummary[];
80 /**
81 * true if the module was 'consolidated'. Consolidating implies the
82 * entity a Module represents might be several modules at the same time.
83 * This attribute is set by tools that consolidate modules for reporting
84 * purposes - it will not be present after a regular cruise.
85 */
86 consolidated?: boolean;
87}
88
89export interface IDependency {
90 /**
91 * 'true' if following this dependency will ultimately return to the source, false in all
92 * other cases
93 */
94 circular: boolean;
95 /**
96 * Whether or not this is a node.js core module - deprecated in favor of dependencyType ===
97 * core
98 */
99 coreModule: boolean;
100 /**
101 * 'true' if dependency-cruiser could not resulve the module name in the source code to a
102 * file name or core module. 'false' in all other cases.
103 */
104 couldNotResolve: boolean;
105 /**
106 * If following this dependency will ultimately return to the source (circular === true),
107 * this attribute will contain an (ordered) array of module names that shows (one of) the
108 * circular path(s)
109 */
110 cycle?: string[];
111 /**
112 * the type of inclusion - local, core, unknown (= we honestly don't know), undetermined (=
113 * we didn't bother determining it) or one of the npm dependencies defined in a package.jsom
114 * ('npm' for 'depenencies', 'npm-dev', 'npm-optional', 'npm-peer', 'npm-no-pkg' for
115 * development, optional, peer dependencies and dependencies in node_modules but not in
116 * package.json respectively)
117 */
118 dependencyTypes: DependencyType[];
119 /**
120 * true if this dependency is dynamic, false in all other cases
121 */
122 dynamic: boolean;
123 /**
124 * true if the dependency was defined by a require not named 'require'
125 * false in all other cases
126 */
127 exoticallyRequired: boolean;
128 /**
129 * If this dependency was defined by a require not named require (as defined in the
130 * exoticRequireStrings option): the string that was used
131 */
132 exoticRequire?: string;
133 /**
134 * Whether or not this is a dependency that can be followed any further. This will be
135 * 'false' for for core modules, json, modules that could not be resolved to a file and
136 * modules that weren't followed because it matches the doNotFollow expression.
137 */
138 followable: boolean;
139 /**
140 * the license, if known (usually known for modules pulled from npm, not for local ones)
141 */
142 license?: string;
143 /**
144 * 'true' if the file name of this module matches the doNotFollow regular expression
145 */
146 matchesDoNotFollow?: boolean;
147 /**
148 * The name of the module as it appeared in the source code, e.g. './main'
149 */
150 module: string;
151 moduleSystem: ModuleSystemType;
152 /**
153 * The (resolved) file name of the module, e.g. 'src/main//index.js'
154 */
155 resolved: string;
156 /**
157 * an array of rules violated by this dependency - left out if the dependency is valid
158 */
159 rules?: IRuleSummary[];
160 /**
161 * 'true' if this dependency violated a rule; 'false' in all other cases. The violated rule
162 * will be in the 'rule' object at the same level.
163 */
164 valid: boolean;
165}
166
167/**
168 * If there was a rule violation (valid === false), this object contains the name of the
169 * rule and severity of violating it.
170 */
171export interface IRuleSummary {
172 /**
173 * The (short, eslint style) name of the violated rule. Typically something like
174 * 'no-core-punycode' or 'no-outside-deps'.
175 */
176 name: string;
177 /**
178 * How severe a violation of a rule is. The 'error' severity will make some reporters return
179 * a non-zero exit code, so if you want e.g. a build to stop when there's a rule violated:
180 * use that. The absence of the 'ignore' severity here is by design; ignored rules don't
181 * show up in the output.
182 *
183 * Severity to use when a dependency is not in the 'allowed' set of rules. Defaults to 'warn'
184 */
185 severity: SeverityType;
186}
187
188export interface IReachable {
189 /**
190 * The name of the rule where the reachability was defined
191 */
192 asDefinedInRule: string;
193 /**
194 * 'true' if this module is reachable from any of the modules matched by the from part of a
195 * reachability-rule in 'asDefinedInRule', 'false' if not.
196 */
197 value: boolean;
198}
199
200export interface IReachesModule {
201 /**
202 * The (resolved) file name of the module, e.g. 'src/main/index.js'
203 */
204 source: string;
205 /**
206 * The path along wich the 'to' module is reachable from this one.
207 */
208 via: string[];
209}
210
211export interface IReaches {
212 /**
213 * The name of the rule where the reachability was defined
214 */
215 asDefinedInRule: string;
216 /**
217 * An array of modules that is (transitively) reachable from this module.
218 */
219 modules: IReachesModule[];
220}
221
222/**
223 * Data summarizing the found dependencies
224 */
225export interface ISummary {
226 /**
227 * the number of errors in the dependencies
228 */
229 error: number;
230 /**
231 * the number of informational level notices in the dependencies
232 */
233 info: number;
234 optionsUsed: IOptions;
235 /**
236 * rules used in the cruise
237 */
238 ruleSetUsed?: IFlattenedRuleSet;
239 /**
240 * the number of modules cruised
241 */
242 totalCruised: number;
243 /**
244 * the number of dependencies cruised
245 */
246 totalDependenciesCruised?: number;
247 /**
248 * A list of violations found in the dependencies. The dependencies themselves also contain
249 * this information, this summary is here for convenience.
250 */
251 violations: IViolation[];
252 /**
253 * the number of warnings in the dependencies
254 */
255 warn: number;
256}
257
258/**
259 * the (command line) options used to generate the dependency-tree
260 */
261export interface IOptions extends ICruiseOptions {
262 /**
263 * arguments passed on the command line
264 */
265 args?: string;
266 /**
267 * File the output was written to ('-' for stdout)
268 */
269 outputTo?: string;
270 /**
271 * The rules file used to validate the dependencies (if any)
272 */
273 rulesFile?: string;
274 /**
275 * The TypeScript configuration file used (if any)
276 */
277 tsConfig?: ITsConfig;
278 /**
279 * The webpack configuration options used for the cruise
280 */
281 webpackConfig?: IWebpackConfig;
282 /**
283 * The Babel configuration file used (if any)
284 */
285 babelConfig?: IBabelConfig;
286}
287
288export interface ITsConfig {
289 fileName?: string;
290}
291
292export interface IBabelConfig {
293 fileName?: string;
294}
295
296/**
297 * The webpack configuration options used for the cruise
298 */
299export interface IWebpackConfig {
300 /**
301 * The arguments used
302 */
303 arguments?: { [key: string]: any };
304 /**
305 * The 'env' parameters passed
306 */
307 env?: WebpackEnvType;
308 /**
309 * The name of the webpack configuration file used
310 */
311 fileName?: string;
312}
313
314/**
315 * The 'env' parameters passed
316 */
317export type WebpackEnvType = { [key: string]: any } | string;
318
319export interface IViolation {
320 /**
321 * The violated rule
322 */
323 rule: IRuleSummary;
324 /**
325 * The from part of the dependency this violation is about
326 */
327 from: string;
328 /**
329 * The to part of the dependency this violation is about
330 */
331 to: string;
332 /**
333 * The circular path if the violation is about circularity
334 */
335 cycle?: string[];
336 /**
337 * The path from the from to the to if the violation is transitive
338 */
339 via?: string[];
340}