rev-dep 1.0.0-alpha.5 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  <h3 align="center">
2
- <code>revdep</code>
2
+ <code>revdep</code>
3
3
  </h3>
4
4
 
5
5
  <p align="center">
@@ -24,18 +24,18 @@ It's especially useful in JS world without TypeScript or tests coverage.
24
24
 
25
25
  It also helps to identify and eliminate dead files, understand the complexity of the file dependencies
26
26
 
27
- [Jump to CLI reference](#CLI-reference)
27
+ [Jump to CLI reference](#cli-reference)
28
28
 
29
- [`export * from` problem](#Export-from-problem)
29
+ [`export * from` problem](#export-from-problem)
30
30
 
31
31
  ### Use cases
32
32
 
33
- - You plan to refactor some file and you wonder which entry points are affected
34
- - You are wondering wether a given source file is used
35
- - You wonder if there are any dead files in your project
36
- - You want to identify all dead files at once
37
- - You want to verify if a given entry point imports only the required files
38
- - You want to optimize the amount of files imported by an entry point
33
+ - [You plan to refactor some file and you wonder which entry points are affected](#how-to-identify-where-a-file-is-used-in-the-project)
34
+
35
+ - [You are wondering wether a given source file is used](#how-to-check-if-a-file-is-used-in-the-project)
36
+ - [You wonder if there are any dead files in your project](#how-to-identify-dead-files-in-the-project)
37
+ - [You want to verify if a given entry point imports only the required files](#how-to-check-which-files-are-imported-by-a-given-file)
38
+ - [You want to optimize the amount of files imported by an entry point](#how-to-reduce-amount-of-files-imported-by-entry-point)
39
39
 
40
40
  ### How about dependency or bundle graphs?
41
41
 
@@ -67,48 +67,302 @@ or
67
67
 
68
68
  ### How to identify where a file is used in the project?
69
69
 
70
+ Just use `rev-dep resolve path/to/file.ts`
71
+
72
+ You will see all the entry points that implicitly require given file together with resolution path.
73
+
74
+ [`resolve` Command CLI reference](#command-resolve)
75
+
76
+ <details>
77
+ <summary>Example for the rev-dep repository</summary>
78
+
79
+ command:
80
+
81
+ `rev-dep resolve src/lib/utils.ts`
82
+
83
+ output:
84
+
85
+ ```s
86
+ src/babel/index.js :
87
+
88
+ ➞ src/babel/index.js
89
+ ➞ src/lib/utils.ts
90
+ _____________________
91
+
92
+ src/cli/index.ts :
93
+
94
+ ➞ src/cli/index.ts
95
+ ➞ src/cli/createCommands.ts
96
+ ➞ src/cli/resolve/index.ts
97
+ ➞ src/lib/find.ts
98
+ ➞ src/lib/getDepsTree.ts
99
+ ➞ src/lib/getDepsSetWebpack.ts
100
+ ➞ src/lib/utils.ts
101
+ _____________________
102
+
103
+ ```
104
+
105
+ </details>
106
+
107
+ #### Getting more details about file resolution in given entry point
108
+
109
+ To find out all paths combination use `rev-dep resolve` with `-a` flag
110
+
111
+ > You might be surprised how complex dependency tree can be!
112
+
113
+ <details>
114
+ <summary>Example for the rev-dep repository</summary>
115
+
116
+ command:
117
+
118
+ `rev-dep resolve src/lib/utils.ts src/cli/index.ts --all`
119
+
120
+ output:
121
+
122
+ ```s
123
+ src/cli/index.ts :
124
+
125
+ ➞ src/cli/index.ts
126
+ ➞ src/cli/createCommands.ts
127
+ ➞ src/cli/resolve/index.ts
128
+ ➞ src/lib/find.ts
129
+ ➞ src/lib/getDepsTree.ts
130
+ ➞ src/lib/getDepsSetWebpack.ts
131
+ ➞ src/lib/utils.ts
132
+
133
+ ➞ src/cli/index.ts
134
+ ➞ src/cli/createCommands.ts
135
+ ➞ src/cli/resolve/index.ts
136
+ ➞ src/lib/find.ts
137
+ ➞ src/lib/getEntryPoints.ts
138
+ ➞ src/lib/getDepsTree.ts
139
+ ➞ src/lib/getDepsSetWebpack.ts
140
+ ➞ src/lib/utils.ts
141
+
142
+ ➞ src/cli/index.ts
143
+ ➞ src/cli/createCommands.ts
144
+ ➞ src/cli/entryPoints/index.ts
145
+ ➞ src/lib/getEntryPoints.ts
146
+ ➞ src/lib/getDepsTree.ts
147
+ ➞ src/lib/getDepsSetWebpack.ts
148
+ ➞ src/lib/utils.ts
149
+
150
+ ➞ src/cli/index.ts
151
+ ➞ src/cli/createCommands.ts
152
+ ➞ src/cli/files/index.ts
153
+ ➞ src/lib/getDepsTree.ts
154
+ ➞ src/lib/getDepsSetWebpack.ts
155
+ ➞ src/lib/utils.ts
156
+
157
+ ➞ src/cli/index.ts
158
+ ➞ src/cli/createCommands.ts
159
+ ➞ src/cli/resolve/index.ts
160
+ ➞ src/lib/find.ts
161
+ ➞ src/lib/getEntryPoints.ts
162
+ ➞ src/lib/utils.ts
163
+
164
+ ➞ src/cli/index.ts
165
+ ➞ src/cli/createCommands.ts
166
+ ➞ src/cli/entryPoints/index.ts
167
+ ➞ src/lib/getEntryPoints.ts
168
+ ➞ src/lib/utils.ts
169
+
170
+ ➞ src/cli/index.ts
171
+ ➞ src/cli/createCommands.ts
172
+ ➞ src/cli/resolve/index.ts
173
+ ➞ src/lib/find.ts
174
+ ➞ src/lib/utils.ts
175
+
176
+ ➞ src/cli/index.ts
177
+ ➞ src/cli/createCommands.ts
178
+ ➞ src/cli/resolve/index.ts
179
+ ➞ src/lib/utils.ts
180
+
181
+ ➞ src/cli/index.ts
182
+ ➞ src/cli/createCommands.ts
183
+ ➞ src/cli/entryPoints/index.ts
184
+ ➞ src/lib/utils.ts
185
+
186
+ ➞ src/cli/index.ts
187
+ ➞ src/cli/createCommands.ts
188
+ ➞ src/cli/files/index.ts
189
+ ➞ src/lib/utils.ts
190
+
191
+ ```
192
+
193
+ </details>
194
+
70
195
  ### How to check if a file is used in the project?
71
196
 
197
+ Use `rev-dep resolve path/to/file.ts --compactSummary`
198
+
199
+ As a result you will see total amount of entry points requiring a given file.
200
+
201
+ > Note that among the entry points list there might be some dead files importing the searched file
202
+
203
+ [`resolve` Command CLI reference](#command-resolve)
204
+
205
+ <details>
206
+ <summary>Example for the rev-dep repository</summary>
207
+
208
+ command:
209
+
210
+ `rev-dep resolve src/lib/utils.ts --compactSummary`
211
+
212
+ output:
213
+
214
+ ```s
215
+ Results:
216
+
217
+ __tests__/find.test.js : 0
218
+ babel.js : 0
219
+ bin.js : 0
220
+ scripts/addDocsToReadme.js : 0
221
+ src/babel/index.js : 1
222
+ src/cli/index.ts : 1
223
+ src/lib/getMaxDepthInGraph.ts : 0
224
+ types.d.ts : 0
225
+
226
+ Total: 2
227
+ ```
228
+
229
+ </details>
230
+
72
231
  ### How to identify dead files in the project?
73
232
 
233
+ Use `rev-dep entry-points` to get list of all files that are not required by any other files in the project.
234
+
235
+ You might want to exclude some file paths that are meant to be actual entry point like `index.js` or `**/pages/**` in `next.js` projects using `--exclude` flag. The same for configuration files like `babel.config.js`
236
+
237
+ Review the list and look for suspicious files like `src/ui/components/SomeComponent/index.js`
238
+
239
+ [`entry-points` command CLI reference](#command-entry-points)
240
+
241
+ <details>
242
+ <summary>Example for the rev-dep repository</summary>
243
+
244
+ command:
245
+
246
+ `rev-dep entry-points --exclude '__tests__/**' 'types.d.ts'`
247
+
248
+ output:
249
+
250
+ ```s
251
+ babel.js
252
+ bin.js
253
+ scripts/addDocsToReadme.js
254
+ src/babel/index.js
255
+ src/cli/index.ts
256
+ src/lib/getMaxDepthInGraph.ts
257
+
258
+ ```
259
+
260
+ The last one `src/lib/getMaxDepthInGraph.ts` is the source file that is not used at the moment.
261
+
262
+ The rest of them looks legit!
263
+
264
+ </details>
265
+
74
266
  ### How to check which files are imported by a given file?
75
267
 
268
+ To get a full list of files imported by given entry point use `rev-dep files path/to/file.ts`.
269
+
270
+ You can use `--count` flag if you are interested in the amount.
271
+
272
+ This is a good indicator of how heavy a given entry point or component is
273
+
274
+ [`files` command CLI reference](#command-files)
275
+
276
+ <details>
277
+ <summary>Example for the rev-dep repository</summary>
278
+
279
+ command:
280
+
281
+ `rev-dep files files src/cli/index.ts`
282
+
283
+ output:
284
+
285
+ ```s
286
+ src/cli/index.ts
287
+ src/cli/createCommands.ts
288
+ package.json
289
+ src/cli/resolve/index.ts
290
+ src/cli/docs/index.ts
291
+ src/cli/entryPoints/index.ts
292
+ src/cli/files/index.ts
293
+ src/lib/find.ts
294
+ src/cli/resolve/types.ts
295
+ src/cli/resolve/formatResults.ts
296
+ src/lib/utils.ts
297
+ src/cli/commonOptions.ts
298
+ src/cli/docs/generate.ts
299
+ src/cli/entryPoints/types.ts
300
+ src/lib/getEntryPoints.ts
301
+ src/lib/buildDepsGraph.ts
302
+ src/cli/files/types.ts
303
+ src/lib/getDepsTree.ts
304
+ src/lib/types.ts
305
+ src/cli/docs/template.ts
306
+ src/lib/getDepsSetWebpack.ts
307
+ src/lib/cleanupDpdmDeps.ts
308
+
309
+ ```
310
+
311
+ As you can see cli even import `package.json`. This is to print version of the cli
312
+
313
+ </details>
314
+
76
315
  ### How to reduce amount of files imported by entry point?
77
316
 
317
+ There is no easy how to for this process, but you can do it iteratively using two of the `rev-dep` commands:
318
+
319
+ - `files`
320
+ - `resolve`
321
+
322
+ 1. Get the list of files imported by entry-point
323
+
324
+ - `rev-dep files path/to/entry-point`
325
+
326
+ 2. Identify some suspicious files on the list, components that should not be used on the given page or not related utility files
327
+ 3. Get all resolution paths for a suspicious file
328
+
329
+ - `rev-dep resolve path/to/suspicious-file path/to/entry-point --all`
330
+
331
+ 4. You would usually find out that there is some file, like directory `index` file that given entry point is using, which is mandatory, but as a side effect it imports a few files that are redundant for your entry point. In most cases you should be able to decouple the imports or reverse the dependency to cut off the resolution path for the unwanted file
332
+
78
333
  ## Usage
79
334
 
80
335
  Project can be used as a CLI tool or as a module
81
336
 
82
337
  ### CLI Tool
83
338
 
84
- For CLI usage see [CLI reference](#CLI-reference)
339
+ For CLI usage see [CLI reference](#cli-reference)
85
340
 
86
341
  ### Module
87
342
 
88
- #### `find` Function
343
+ #### `resolve` Function
89
344
 
90
345
  ```ts
91
- import { find } from "rev-dep";
346
+ import { resolve } from "rev-dep";
92
347
 
93
- const path = find({
348
+ const [paths] = await resolve({
94
349
  entryPoints: ["index.js"],
95
350
  filePath: "utils.js",
96
351
  });
97
352
 
98
- console.log(path);
353
+ console.log(paths);
99
354
  ```
100
355
 
101
- #### `find` Function
356
+ #### `getEntryPoints` Function
102
357
 
103
358
  ```ts
104
- import { find } from "rev-dep";
359
+ import { getEntryPoints } from "rev-dep";
105
360
 
106
- const path = find({
107
- entryPoints: ["index.js"],
108
- filePath: "utils.js",
361
+ const [entryPoints] = await getEntryPoints({
362
+ cwd: process.cwd(),
109
363
  });
110
364
 
111
- console.log(path);
365
+ console.log(entryPoints);
112
366
  ```
113
367
 
114
368
  ## CLI reference
@@ -203,9 +457,7 @@ rev-dep docs <outputPath> [options]
203
457
  ```js
204
458
  // babel.config.js
205
459
  module.exports = {
206
- plugins: [
207
- 'rev-dep/babel'
208
- ]
460
+ plugins: ["rev-dep/babel"],
209
461
  };
210
462
  ```
211
463
 
package/bin.js CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- require('./dist/cli');
2
+ require('./dist/cli')
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,23 @@
1
+ declare type OptionMeta2 = [string, string];
2
+ declare type OptionMeta3 = [string, string, string];
3
+ export declare const webpackConfigOption: OptionMeta2;
4
+ export declare type WebpackConfigOptionType = {
5
+ webpackConfig?: string;
6
+ };
7
+ export declare const cwdOption: OptionMeta3;
8
+ export declare type CwdOptionType = {
9
+ cwd: string;
10
+ };
11
+ export declare const reexportRewireOption: OptionMeta2;
12
+ export declare type ReexportRewireOptionType = {
13
+ reexportRewire?: boolean;
14
+ };
15
+ export declare const includeOption: OptionMeta2;
16
+ export declare type IncludeOptionType = {
17
+ include?: string[];
18
+ };
19
+ export declare const excludeOption: OptionMeta2;
20
+ export declare type ExcludeOptionType = {
21
+ exclude?: string[];
22
+ };
23
+ export {};
@@ -0,0 +1,2 @@
1
+ import commander from 'commander';
2
+ export declare function createCommands(program: commander.Command): void;
@@ -0,0 +1,20 @@
1
+ export declare type Command = {
2
+ name: string;
3
+ arguments: {
4
+ nameRaw: string;
5
+ name: string;
6
+ required: boolean;
7
+ description?: string;
8
+ }[];
9
+ description?: string;
10
+ options: {
11
+ shortName: string;
12
+ longName?: string;
13
+ argument?: string;
14
+ description?: string;
15
+ defaultValue?: string;
16
+ required: boolean;
17
+ }[];
18
+ };
19
+ declare function generate(output: string, initialHeaderLevel: number): void;
20
+ export default generate;
@@ -0,0 +1,3 @@
1
+ import commander from 'commander';
2
+ declare function create(program: commander.Command): void;
3
+ export default create;
@@ -0,0 +1,3 @@
1
+ import { Command } from './generate';
2
+ declare function template(commands: Command[], headerLevel: number): string;
3
+ export default template;
@@ -0,0 +1,2 @@
1
+ import commander from 'commander';
2
+ export default function createEntryPoints(program: commander.Command): void;
@@ -0,0 +1,4 @@
1
+ export declare type InputParams = {
2
+ printDependenciesCount?: boolean;
3
+ count?: boolean;
4
+ };
@@ -0,0 +1,2 @@
1
+ import commander from 'commander';
2
+ export default function createFiles(program: commander.Command): void;
@@ -0,0 +1,3 @@
1
+ export declare type InputParams = {
2
+ count?: boolean;
3
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,9 @@
1
+ import { InputParams } from './types';
2
+ declare type Results = Array<Array<Array<string>>>;
3
+ export declare function formatResults({ results, filePath, entryPoints, compactSummary }: {
4
+ results: Results;
5
+ compactSummary: InputParams['compactSummary'];
6
+ entryPoints: string[];
7
+ filePath: string;
8
+ }): string;
9
+ export {};
@@ -0,0 +1,2 @@
1
+ import commander from 'commander';
2
+ export default function createResolve(program: commander.Command): void;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const find_1 = require("../../lib/find");
3
+ const resolve_1 = require("../../lib/resolve");
4
4
  const formatResults_1 = require("./formatResults");
5
5
  const utils_1 = require("../../lib/utils");
6
6
  const commonOptions_1 = require("../commonOptions");
@@ -20,7 +20,7 @@ function createResolve(program) {
20
20
  .option('-a, --all', 'finds all paths combination of a given dependency. Might work very slow or crash for some projects due to heavy usage of RAM', false)
21
21
  .action(async (filePath, entryPoints, data) => {
22
22
  const { compactSummary, webpackConfig, all, cwd, exclude, include } = data;
23
- const [results, resolveEntryPoints] = await (0, find_1.resolve)({
23
+ const [results, resolveEntryPoints] = await (0, resolve_1.resolve)({
24
24
  entryPoints,
25
25
  filePath,
26
26
  webpackConfig,
@@ -0,0 +1,9 @@
1
+ export declare type InputParams = {
2
+ compactSummary?: boolean;
3
+ verbose?: boolean;
4
+ webpackConfig?: string;
5
+ typescriptConfig?: string;
6
+ printMaxDepth?: boolean;
7
+ printDependentCount?: boolean;
8
+ all: boolean;
9
+ };
@@ -0,0 +1,2 @@
1
+ import { Node, MinimalDependencyTree } from './types';
2
+ export declare const buildGraphDpdm: (deps: MinimalDependencyTree, filePath?: string | undefined) => (entryPoint: string) => [Node, Node | null, Map<string, Node>];
@@ -0,0 +1,3 @@
1
+ import { DependencyTree } from 'dpdm';
2
+ import { MinimalDependencyTree } from './types';
3
+ export declare const cleanupDpdmDeps: (deps: MinimalDependencyTree | DependencyTree) => MinimalDependencyTree;
@@ -0,0 +1,6 @@
1
+ export declare const getDepsSetWebpack: (entryPoints: string[], webpackConfigPath: string, cwd: string, skipRegex?: RegExp | undefined) => {
2
+ [key: string]: {
3
+ id: string;
4
+ request: string;
5
+ }[];
6
+ };
@@ -0,0 +1 @@
1
+ export declare function getDepsTree(cwd: string, entryPoints: string[], webpackConfigPath?: string): Promise<import("./types").MinimalDependencyTree>;
@@ -0,0 +1,9 @@
1
+ import { MinimalDependencyTree } from './types';
2
+ export declare const getDirectoriesForEntryPointsSearch: (dir: string) => Promise<string[]>;
3
+ export declare const findEntryPointsInDepsTree: (deps: MinimalDependencyTree, exclude?: string[], include?: string[] | undefined) => string[];
4
+ export declare const getEntryPoints: ({ cwd, exclude, include, webpackConfigPath }: {
5
+ cwd: string;
6
+ exclude?: string[] | undefined;
7
+ include?: string[] | undefined;
8
+ webpackConfigPath?: string | undefined;
9
+ }) => Promise<[string[], MinimalDependencyTree]>;
@@ -0,0 +1,4 @@
1
+ import { Node } from './types';
2
+ declare type MaxDepthMeta = [number, string[]];
3
+ export declare const getMaxDepth: (depth?: number, path?: string[], vertices?: Map<any, any>) => (tree: Node) => MaxDepthMeta;
4
+ export {};
@@ -0,0 +1,11 @@
1
+ declare type ResolveParams = {
2
+ entryPoints: string[];
3
+ filePath: string;
4
+ webpackConfig?: string;
5
+ cwd?: string;
6
+ all: boolean;
7
+ exclude?: string[];
8
+ include?: string[];
9
+ };
10
+ export declare const resolve: ({ entryPoints: _entryPoints, filePath, webpackConfig, cwd, all, include, exclude }: ResolveParams) => Promise<[string[][][], string[]]>;
11
+ export {};
File without changes
@@ -0,0 +1,10 @@
1
+ import { Dependency } from 'dpdm';
2
+ export declare type Node = {
3
+ path: string;
4
+ children: Node[];
5
+ parents: Node[];
6
+ };
7
+ export declare type MinimalDependency = Pick<Dependency, 'id' | 'request'>;
8
+ export declare type MinimalDependencyTree = {
9
+ [key: string]: readonly MinimalDependency[] | null;
10
+ };
@@ -0,0 +1,6 @@
1
+ export declare const removeInitialDot: (path: string) => string;
2
+ export declare const createResolveAbsolutePath: (cwd: string) => (p: string | undefined) => string | undefined;
3
+ export declare const asyncFilter: <T>(arr: T[], predicate: (el: T) => Promise<boolean>) => Promise<T[]>;
4
+ export declare const sanitizeUserEntryPoints: (entryPoints: string[]) => string[];
5
+ export declare const resolvePath: <P extends string | undefined>(p: P) => string | P;
6
+ export declare const findTsConfig: (cwd?: string) => string | undefined;
@@ -0,0 +1,2 @@
1
+ export { resolve } from './lib/resolve';
2
+ export { getEntryPoints } from './lib/getEntryPoints';
package/dist/module.js ADDED
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getEntryPoints = exports.resolve = void 0;
4
+ var resolve_1 = require("./lib/resolve");
5
+ Object.defineProperty(exports, "resolve", { enumerable: true, get: function () { return resolve_1.resolve; } });
6
+ var getEntryPoints_1 = require("./lib/getEntryPoints");
7
+ Object.defineProperty(exports, "getEntryPoints", { enumerable: true, get: function () { return getEntryPoints_1.getEntryPoints; } });
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "rev-dep",
3
- "version": "1.0.0-alpha.5",
4
- "description": "Reverse dependency resolution tool built with dependency-cruiser",
5
- "main": "lib/find.js",
3
+ "version": "1.0.1",
4
+ "description": "Dependency debugging tool for JavaScript and TypeScript projects",
5
+ "main": "dist/module.js",
6
6
  "bin": "bin.js",
7
7
  "files": [
8
8
  "dist/**",
@@ -21,13 +21,14 @@
21
21
  "node": ">=10"
22
22
  },
23
23
  "scripts": {
24
+ "checks": "yarn lint && yarn typecheck",
24
25
  "lint": "eslint --ext .js,.ts src",
25
26
  "lint:fix": "yarn lint --fix",
26
27
  "docs-gen": "node ./scripts/addDocsToReadme.js",
27
28
  "dev": "node bin",
28
29
  "test": "jest",
29
30
  "release": "release-it",
30
- "build": "tsc",
31
+ "build": "tsc --declaration",
31
32
  "build:watch": "tsc --watch",
32
33
  "typecheck": "tsc --noEmit"
33
34
  },
@@ -59,5 +60,18 @@
59
60
  "prettier": "^2.1.2",
60
61
  "release-it": "^14.2.1",
61
62
  "typescript": "^4.6.2"
62
- }
63
+ },
64
+ "keywords": [
65
+ "dependencies",
66
+ "deps",
67
+ "dependency graph",
68
+ "dependency debugging",
69
+ "entry points",
70
+ "dependency resolution",
71
+ "reverse dependency resolution",
72
+ "dependency tree",
73
+ "import path",
74
+ "resolution path",
75
+ "dependency optimization"
76
+ ]
63
77
  }