rev-dep 1.0.0-alpha.6 β†’ 1.0.2

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>rev←dep</code>
2
+ <code>rev-dep</code>
3
3
  </h3>
4
4
 
5
5
  <p align="center">
@@ -10,13 +10,15 @@
10
10
 
11
11
  <img alt="rev-dep version" src="https://img.shields.io/npm/v/rev-dep"> <img alt="rev-dep license" src="https://img.shields.io/npm/l/rev-dep"> <img alt="rev-dep PRs welcome" src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square">
12
12
 
13
- ## About
13
+ ## About πŸ“£
14
14
 
15
15
  The tool was created help with daily dev struggles by answering these questions:
16
16
 
17
- - What entry points my codebase have
18
- - Which entry points uses a given file
19
- - Which dependencies a given file has
17
+ πŸ‘‰ What entry points my codebase have
18
+
19
+ πŸ‘‰ Which entry points uses a given file
20
+
21
+ πŸ‘‰ Which dependencies a given file has
20
22
 
21
23
  This helps to debug project dependencies, plan refactoring, optimize bundles or plan code splitting.
22
24
 
@@ -24,14 +26,13 @@ It's especially useful in JS world without TypeScript or tests coverage.
24
26
 
25
27
  It also helps to identify and eliminate dead files, understand the complexity of the file dependencies
26
28
 
27
- [Jump to CLI reference](#cli-reference)
29
+ [🦘 Jump to CLI reference](#cli-reference)
28
30
 
29
- [`export * from` problem](#export-from-problem)
31
+ [πŸ•ΈοΈ `export * from` problem](#export-from-problem)
30
32
 
31
- ### Use cases
33
+ ### Use cases πŸ§‘β€πŸ’»
32
34
 
33
35
  - [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
36
  - [You are wondering wether a given source file is used](#how-to-check-if-a-file-is-used-in-the-project)
36
37
  - [You wonder if there are any dead files in your project](#how-to-identify-dead-files-in-the-project)
37
38
  - [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)
@@ -45,7 +46,7 @@ While graphs can be useful to identify major problems like too big bundle size o
45
46
 
46
47
  `rev-dep` visualize dependencies as lists, so it's really easy to see where to cut the line to solve the problem.
47
48
 
48
- ## Getting Started
49
+ ## Getting Started πŸŽ‰
49
50
 
50
51
  ### Install globally to use as CLI tool
51
52
 
@@ -63,7 +64,7 @@ or
63
64
 
64
65
  `npm install rev-dep`
65
66
 
66
- ## Recipes
67
+ ## Recipes 🌢️
67
68
 
68
69
  ### How to identify where a file is used in the project?
69
70
 
@@ -72,23 +73,24 @@ Just use `rev-dep resolve path/to/file.ts`
72
73
  You will see all the entry points that implicitly require given file together with resolution path.
73
74
 
74
75
  [`resolve` Command CLI reference](#command-resolve)
76
+
75
77
  <details>
76
78
  <summary>Example for the rev-dep repository</summary>
77
79
 
78
- command:
80
+ command:
79
81
 
80
82
  `rev-dep resolve src/lib/utils.ts`
81
83
 
82
84
  output:
83
85
 
84
86
  ```s
85
- src/babel/index.js :
87
+ src/babel/index.js :
86
88
 
87
89
  ➞ src/babel/index.js
88
- ➞ src/lib/utils.ts
90
+ ➞ src/lib/utils.ts
89
91
  _____________________
90
92
 
91
- src/cli/index.ts :
93
+ src/cli/index.ts :
92
94
 
93
95
  ➞ src/cli/index.ts
94
96
  ➞ src/cli/createCommands.ts
@@ -96,10 +98,11 @@ src/cli/index.ts :
96
98
  ➞ src/lib/find.ts
97
99
  ➞ src/lib/getDepsTree.ts
98
100
  ➞ src/lib/getDepsSetWebpack.ts
99
- ➞ src/lib/utils.ts
101
+ ➞ src/lib/utils.ts
100
102
  _____________________
101
103
 
102
104
  ```
105
+
103
106
  </details>
104
107
 
105
108
  #### Getting more details about file resolution in given entry point
@@ -111,14 +114,14 @@ To find out all paths combination use `rev-dep resolve` with `-a` flag
111
114
  <details>
112
115
  <summary>Example for the rev-dep repository</summary>
113
116
 
114
- command:
117
+ command:
115
118
 
116
119
  `rev-dep resolve src/lib/utils.ts src/cli/index.ts --all`
117
120
 
118
121
  output:
119
122
 
120
123
  ```s
121
- src/cli/index.ts :
124
+ src/cli/index.ts :
122
125
 
123
126
  ➞ src/cli/index.ts
124
127
  ➞ src/cli/createCommands.ts
@@ -126,7 +129,7 @@ src/cli/index.ts :
126
129
  ➞ src/lib/find.ts
127
130
  ➞ src/lib/getDepsTree.ts
128
131
  ➞ src/lib/getDepsSetWebpack.ts
129
- ➞ src/lib/utils.ts
132
+ ➞ src/lib/utils.ts
130
133
 
131
134
  ➞ src/cli/index.ts
132
135
  ➞ src/cli/createCommands.ts
@@ -135,7 +138,7 @@ src/cli/index.ts :
135
138
  ➞ src/lib/getEntryPoints.ts
136
139
  ➞ src/lib/getDepsTree.ts
137
140
  ➞ src/lib/getDepsSetWebpack.ts
138
- ➞ src/lib/utils.ts
141
+ ➞ src/lib/utils.ts
139
142
 
140
143
  ➞ src/cli/index.ts
141
144
  ➞ src/cli/createCommands.ts
@@ -143,55 +146,56 @@ src/cli/index.ts :
143
146
  ➞ src/lib/getEntryPoints.ts
144
147
  ➞ src/lib/getDepsTree.ts
145
148
  ➞ src/lib/getDepsSetWebpack.ts
146
- ➞ src/lib/utils.ts
149
+ ➞ src/lib/utils.ts
147
150
 
148
151
  ➞ src/cli/index.ts
149
152
  ➞ src/cli/createCommands.ts
150
153
  ➞ src/cli/files/index.ts
151
154
  ➞ src/lib/getDepsTree.ts
152
155
  ➞ src/lib/getDepsSetWebpack.ts
153
- ➞ src/lib/utils.ts
156
+ ➞ src/lib/utils.ts
154
157
 
155
158
  ➞ src/cli/index.ts
156
159
  ➞ src/cli/createCommands.ts
157
160
  ➞ src/cli/resolve/index.ts
158
161
  ➞ src/lib/find.ts
159
162
  ➞ src/lib/getEntryPoints.ts
160
- ➞ src/lib/utils.ts
163
+ ➞ src/lib/utils.ts
161
164
 
162
165
  ➞ src/cli/index.ts
163
166
  ➞ src/cli/createCommands.ts
164
167
  ➞ src/cli/entryPoints/index.ts
165
168
  ➞ src/lib/getEntryPoints.ts
166
- ➞ src/lib/utils.ts
169
+ ➞ src/lib/utils.ts
167
170
 
168
171
  ➞ src/cli/index.ts
169
172
  ➞ src/cli/createCommands.ts
170
173
  ➞ src/cli/resolve/index.ts
171
174
  ➞ src/lib/find.ts
172
- ➞ src/lib/utils.ts
175
+ ➞ src/lib/utils.ts
173
176
 
174
177
  ➞ src/cli/index.ts
175
178
  ➞ src/cli/createCommands.ts
176
179
  ➞ src/cli/resolve/index.ts
177
- ➞ src/lib/utils.ts
180
+ ➞ src/lib/utils.ts
178
181
 
179
182
  ➞ src/cli/index.ts
180
183
  ➞ src/cli/createCommands.ts
181
184
  ➞ src/cli/entryPoints/index.ts
182
- ➞ src/lib/utils.ts
185
+ ➞ src/lib/utils.ts
183
186
 
184
187
  ➞ src/cli/index.ts
185
188
  ➞ src/cli/createCommands.ts
186
189
  ➞ src/cli/files/index.ts
187
- ➞ src/lib/utils.ts
190
+ ➞ src/lib/utils.ts
188
191
 
189
192
  ```
193
+
190
194
  </details>
191
195
 
192
196
  ### How to check if a file is used in the project?
193
197
 
194
- Use `rev-dep resolve path/to/file.ts --compactSummary`
198
+ Use `rev-dep resolve path/to/file.ts --compactSummary`
195
199
 
196
200
  As a result you will see total amount of entry points requiring a given file.
197
201
 
@@ -202,7 +206,7 @@ As a result you will see total amount of entry points requiring a given file.
202
206
  <details>
203
207
  <summary>Example for the rev-dep repository</summary>
204
208
 
205
- command:
209
+ command:
206
210
 
207
211
  `rev-dep resolve src/lib/utils.ts --compactSummary`
208
212
 
@@ -222,6 +226,7 @@ types.d.ts : 0
222
226
 
223
227
  Total: 2
224
228
  ```
229
+
225
230
  </details>
226
231
 
227
232
  ### How to identify dead files in the project?
@@ -237,7 +242,7 @@ Review the list and look for suspicious files like `src/ui/components/SomeCompon
237
242
  <details>
238
243
  <summary>Example for the rev-dep repository</summary>
239
244
 
240
- command:
245
+ command:
241
246
 
242
247
  `rev-dep entry-points --exclude '__tests__/**' 'types.d.ts'`
243
248
 
@@ -253,14 +258,15 @@ src/lib/getMaxDepthInGraph.ts
253
258
 
254
259
  ```
255
260
 
256
- The last one `src/lib/getMaxDepthInGraph.ts` is the source file that is not used at the moment.
261
+ The last one `src/lib/getMaxDepthInGraph.ts` is the source file that is not used at the moment.
257
262
 
258
263
  The rest of them looks legit!
264
+
259
265
  </details>
260
266
 
261
267
  ### How to check which files are imported by a given file?
262
268
 
263
- To get a full list of files imported by given entry point use `rev-dep files path/to/file.ts`.
269
+ To get a full list of files imported by given entry point use `rev-dep files path/to/file.ts`.
264
270
 
265
271
  You can use `--count` flag if you are interested in the amount.
266
272
 
@@ -271,7 +277,7 @@ This is a good indicator of how heavy a given entry point or component is
271
277
  <details>
272
278
  <summary>Example for the rev-dep repository</summary>
273
279
 
274
- command:
280
+ command:
275
281
 
276
282
  `rev-dep files files src/cli/index.ts`
277
283
 
@@ -304,23 +310,25 @@ src/lib/cleanupDpdmDeps.ts
304
310
  ```
305
311
 
306
312
  As you can see cli even import `package.json`. This is to print version of the cli
307
- </details>
308
313
 
314
+ </details>
309
315
 
310
316
  ### How to reduce amount of files imported by entry point?
311
317
 
312
- There is no easy how to for this process, but you can do it iteratively using two of the `rev-dep` commands:
313
- - `files`
314
- - `resolve`
318
+ There is no easy how to for this process, but you can do it iteratively using `rev-dep` commands `files` and `resolve`
319
+
320
+ 1. Get the list of files imported by entry-point
321
+
322
+ `rev-dep files path/to/entry-point`
315
323
 
316
- 1. Get the list of files imported by entry-point
317
- - `rev-dep files path/to/entry-point`
318
324
  2. Identify some suspicious files on the list, components that should not be used on the given page or not related utility files
319
325
  3. Get all resolution paths for a suspicious file
320
- - `rev-dep resolve path/to/suspicious-file path/to/entry-point --all`
326
+
327
+ `rev-dep resolve path/to/suspicious-file path/to/entry-point --all`
328
+
321
329
  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
322
330
 
323
- ## Usage
331
+ ## Usage 🎨
324
332
 
325
333
  Project can be used as a CLI tool or as a module
326
334
 
@@ -335,7 +343,7 @@ For CLI usage see [CLI reference](#cli-reference)
335
343
  ```ts
336
344
  import { resolve } from "rev-dep";
337
345
 
338
- const paths = resolve({
346
+ const [paths] = await resolve({
339
347
  entryPoints: ["index.js"],
340
348
  filePath: "utils.js",
341
349
  });
@@ -348,14 +356,14 @@ console.log(paths);
348
356
  ```ts
349
357
  import { getEntryPoints } from "rev-dep";
350
358
 
351
- const entryPoints = getEntryPoints({
359
+ const [entryPoints] = await getEntryPoints({
352
360
  cwd: process.cwd(),
353
361
  });
354
362
 
355
363
  console.log(entryPoints);
356
364
  ```
357
365
 
358
- ## CLI reference
366
+ ## CLI reference πŸ“–
359
367
 
360
368
  <!-- cli-docs-start -->
361
369
 
@@ -447,9 +455,7 @@ rev-dep docs <outputPath> [options]
447
455
  ```js
448
456
  // babel.config.js
449
457
  module.exports = {
450
- plugins: [
451
- 'rev-dep/babel'
452
- ]
458
+ plugins: ["rev-dep/babel"],
453
459
  };
454
460
  ```
455
461
 
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;
@@ -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 {};
@@ -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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rev-dep",
3
- "version": "1.0.0-alpha.6",
3
+ "version": "1.0.2",
4
4
  "description": "Dependency debugging tool for JavaScript and TypeScript projects",
5
5
  "main": "dist/module.js",
6
6
  "bin": "bin.js",
@@ -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
  },
package/dist/lib/find.js DELETED
@@ -1,46 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.resolve = void 0;
4
- const buildDepsGraph_1 = require("./buildDepsGraph");
5
- const getDepsTree_1 = require("./getDepsTree");
6
- const getEntryPoints_1 = require("./getEntryPoints");
7
- const utils_1 = require("./utils");
8
- const resolvePathsToRoot = (node, all = false, resolvedPaths = [[]]) => {
9
- const newPaths = resolvedPaths.map((resolvedPath) => [
10
- node.path,
11
- ...resolvedPath
12
- ]);
13
- if (node.parents.length === 0) {
14
- return newPaths;
15
- }
16
- if (all) {
17
- return node.parents
18
- .map((parentPath) => resolvePathsToRoot(parentPath, all, newPaths))
19
- .flat(1);
20
- }
21
- return resolvePathsToRoot(node.parents[0], false, newPaths);
22
- };
23
- const resolve = async ({ entryPoints: _entryPoints, filePath, webpackConfig, cwd = process.cwd(), all, include, exclude }) => {
24
- let deps, entryPoints;
25
- if (_entryPoints.length > 0) {
26
- entryPoints = _entryPoints;
27
- const sanitizedEntryPoints = (0, utils_1.sanitizeUserEntryPoints)(entryPoints);
28
- deps = await (0, getDepsTree_1.getDepsTree)(cwd, sanitizedEntryPoints, webpackConfig);
29
- }
30
- else {
31
- ;
32
- [entryPoints, deps] = await (0, getEntryPoints_1.getEntryPoints)({ cwd, exclude, include });
33
- }
34
- const cleanedEntryPoints = entryPoints.map(utils_1.removeInitialDot);
35
- const cleanedFilePath = (0, utils_1.removeInitialDot)(filePath);
36
- const forest = cleanedEntryPoints.map((0, buildDepsGraph_1.buildGraphDpdm)(deps, cleanedFilePath));
37
- const resolvedPaths = forest.reduce((allPaths, [_, fileNode]) => {
38
- if (!fileNode) {
39
- return [...allPaths, []];
40
- }
41
- const pathsForTree = resolvePathsToRoot(fileNode, all);
42
- return [...allPaths, pathsForTree];
43
- }, []);
44
- return [resolvedPaths, entryPoints];
45
- };
46
- exports.resolve = resolve;