UNPKG

10.1 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 * 'true' if the dependency between this dependency and its parent only
107 * exists before compilation takes place. 'false in all other cases.
108 * Dependency-cruiser will only specify this attribute for TypeScript and
109 * then only when the option 'tsPreCompilationDeps' has the value 'specify'.
110 */
111 preCompilationOnly?: boolean;
112 /**
113 * If following this dependency will ultimately return to the source (circular === true),
114 * this attribute will contain an (ordered) array of module names that shows (one of) the
115 * circular path(s)
116 */
117 cycle?: string[];
118 /**
119 * the type of inclusion - local, core, unknown (= we honestly don't know), undetermined (=
120 * we didn't bother determining it) or one of the npm dependencies defined in a package.jsom
121 * ('npm' for 'depenencies', 'npm-dev', 'npm-optional', 'npm-peer', 'npm-no-pkg' for
122 * development, optional, peer dependencies and dependencies in node_modules but not in
123 * package.json respectively)
124 */
125 dependencyTypes: DependencyType[];
126 /**
127 * true if this dependency is dynamic, false in all other cases
128 */
129 dynamic: boolean;
130 /**
131 * true if the dependency was defined by a require not named 'require'
132 * false in all other cases
133 */
134 exoticallyRequired: boolean;
135 /**
136 * If this dependency was defined by a require not named require (as defined in the
137 * exoticRequireStrings option): the string that was used
138 */
139 exoticRequire?: string;
140 /**
141 * Whether or not this is a dependency that can be followed any further. This will be
142 * 'false' for for core modules, json, modules that could not be resolved to a file and
143 * modules that weren't followed because it matches the doNotFollow expression.
144 */
145 followable: boolean;
146 /**
147 * the license, if known (usually known for modules pulled from npm, not for local ones)
148 */
149 license?: string;
150 /**
151 * 'true' if the file name of this module matches the doNotFollow regular expression
152 */
153 matchesDoNotFollow?: boolean;
154 /**
155 * The name of the module as it appeared in the source code, e.g. './main'
156 */
157 module: string;
158 moduleSystem: ModuleSystemType;
159 /**
160 * The (resolved) file name of the module, e.g. 'src/main//index.js'
161 */
162 resolved: string;
163 /**
164 * an array of rules violated by this dependency - left out if the dependency is valid
165 */
166 rules?: IRuleSummary[];
167 /**
168 * 'true' if this dependency violated a rule; 'false' in all other cases. The violated rule
169 * will be in the 'rule' object at the same level.
170 */
171 valid: boolean;
172}
173
174/**
175 * If there was a rule violation (valid === false), this object contains the name of the
176 * rule and severity of violating it.
177 */
178export interface IRuleSummary {
179 /**
180 * The (short, eslint style) name of the violated rule. Typically something like
181 * 'no-core-punycode' or 'no-outside-deps'.
182 */
183 name: string;
184 /**
185 * How severe a violation of a rule is. The 'error' severity will make some reporters return
186 * a non-zero exit code, so if you want e.g. a build to stop when there's a rule violated:
187 * use that. The absence of the 'ignore' severity here is by design; ignored rules don't
188 * show up in the output.
189 *
190 * Severity to use when a dependency is not in the 'allowed' set of rules. Defaults to 'warn'
191 */
192 severity: SeverityType;
193}
194
195export interface IReachable {
196 /**
197 * The name of the rule where the reachability was defined
198 */
199 asDefinedInRule: string;
200 /**
201 * 'true' if this module is reachable from any of the modules matched by the from part of a
202 * reachability-rule in 'asDefinedInRule', 'false' if not.
203 */
204 value: boolean;
205}
206
207export interface IReachesModule {
208 /**
209 * The (resolved) file name of the module, e.g. 'src/main/index.js'
210 */
211 source: string;
212 /**
213 * The path along wich the 'to' module is reachable from this one.
214 */
215 via: string[];
216}
217
218export interface IReaches {
219 /**
220 * The name of the rule where the reachability was defined
221 */
222 asDefinedInRule: string;
223 /**
224 * An array of modules that is (transitively) reachable from this module.
225 */
226 modules: IReachesModule[];
227}
228
229/**
230 * Data summarizing the found dependencies
231 */
232export interface ISummary {
233 /**
234 * the number of errors in the dependencies
235 */
236 error: number;
237 /**
238 * the number of informational level notices in the dependencies
239 */
240 info: number;
241 optionsUsed: IOptions;
242 /**
243 * rules used in the cruise
244 */
245 ruleSetUsed?: IFlattenedRuleSet;
246 /**
247 * the number of modules cruised
248 */
249 totalCruised: number;
250 /**
251 * the number of dependencies cruised
252 */
253 totalDependenciesCruised?: number;
254 /**
255 * A list of violations found in the dependencies. The dependencies themselves also contain
256 * this information, this summary is here for convenience.
257 */
258 violations: IViolation[];
259 /**
260 * the number of warnings in the dependencies
261 */
262 warn: number;
263}
264
265/**
266 * the (command line) options used to generate the dependency-tree
267 */
268export interface IOptions extends ICruiseOptions {
269 /**
270 * arguments passed on the command line
271 */
272 args?: string;
273 /**
274 * File the output was written to ('-' for stdout)
275 */
276 outputTo?: string;
277 /**
278 * The rules file used to validate the dependencies (if any)
279 */
280 rulesFile?: string;
281 /**
282 * The TypeScript configuration file used (if any)
283 */
284 tsConfig?: ITsConfig;
285 /**
286 * The webpack configuration options used for the cruise
287 */
288 webpackConfig?: IWebpackConfig;
289 /**
290 * The Babel configuration file used (if any)
291 */
292 babelConfig?: IBabelConfig;
293}
294
295export interface ITsConfig {
296 fileName?: string;
297}
298
299export interface IBabelConfig {
300 fileName?: string;
301}
302
303/**
304 * The webpack configuration options used for the cruise
305 */
306export interface IWebpackConfig {
307 /**
308 * The arguments used
309 */
310 arguments?: { [key: string]: any };
311 /**
312 * The 'env' parameters passed
313 */
314 env?: WebpackEnvType;
315 /**
316 * The name of the webpack configuration file used
317 */
318 fileName?: string;
319}
320
321/**
322 * The 'env' parameters passed
323 */
324export type WebpackEnvType = { [key: string]: any } | string;
325
326export interface IViolation {
327 /**
328 * The violated rule
329 */
330 rule: IRuleSummary;
331 /**
332 * The from part of the dependency this violation is about
333 */
334 from: string;
335 /**
336 * The to part of the dependency this violation is about
337 */
338 to: string;
339 /**
340 * The circular path if the violation is about circularity
341 */
342 cycle?: string[];
343 /**
344 * The path from the from to the to if the violation is transitive
345 */
346 via?: string[];
347}