rev-dep 1.0.0-alpha.6 → 1.0.0-alpha.7

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
@@ -72,23 +72,24 @@ Just use `rev-dep resolve path/to/file.ts`
72
72
  You will see all the entry points that implicitly require given file together with resolution path.
73
73
 
74
74
  [`resolve` Command CLI reference](#command-resolve)
75
+
75
76
  <details>
76
77
  <summary>Example for the rev-dep repository</summary>
77
78
 
78
- command:
79
+ command:
79
80
 
80
81
  `rev-dep resolve src/lib/utils.ts`
81
82
 
82
83
  output:
83
84
 
84
85
  ```s
85
- src/babel/index.js :
86
+ src/babel/index.js :
86
87
 
87
88
  ➞ src/babel/index.js
88
- ➞ src/lib/utils.ts
89
+ ➞ src/lib/utils.ts
89
90
  _____________________
90
91
 
91
- src/cli/index.ts :
92
+ src/cli/index.ts :
92
93
 
93
94
  ➞ src/cli/index.ts
94
95
  ➞ src/cli/createCommands.ts
@@ -96,10 +97,11 @@ src/cli/index.ts :
96
97
  ➞ src/lib/find.ts
97
98
  ➞ src/lib/getDepsTree.ts
98
99
  ➞ src/lib/getDepsSetWebpack.ts
99
- ➞ src/lib/utils.ts
100
+ ➞ src/lib/utils.ts
100
101
  _____________________
101
102
 
102
103
  ```
104
+
103
105
  </details>
104
106
 
105
107
  #### Getting more details about file resolution in given entry point
@@ -111,14 +113,14 @@ To find out all paths combination use `rev-dep resolve` with `-a` flag
111
113
  <details>
112
114
  <summary>Example for the rev-dep repository</summary>
113
115
 
114
- command:
116
+ command:
115
117
 
116
118
  `rev-dep resolve src/lib/utils.ts src/cli/index.ts --all`
117
119
 
118
120
  output:
119
121
 
120
122
  ```s
121
- src/cli/index.ts :
123
+ src/cli/index.ts :
122
124
 
123
125
  ➞ src/cli/index.ts
124
126
  ➞ src/cli/createCommands.ts
@@ -126,7 +128,7 @@ src/cli/index.ts :
126
128
  ➞ src/lib/find.ts
127
129
  ➞ src/lib/getDepsTree.ts
128
130
  ➞ src/lib/getDepsSetWebpack.ts
129
- ➞ src/lib/utils.ts
131
+ ➞ src/lib/utils.ts
130
132
 
131
133
  ➞ src/cli/index.ts
132
134
  ➞ src/cli/createCommands.ts
@@ -135,7 +137,7 @@ src/cli/index.ts :
135
137
  ➞ src/lib/getEntryPoints.ts
136
138
  ➞ src/lib/getDepsTree.ts
137
139
  ➞ src/lib/getDepsSetWebpack.ts
138
- ➞ src/lib/utils.ts
140
+ ➞ src/lib/utils.ts
139
141
 
140
142
  ➞ src/cli/index.ts
141
143
  ➞ src/cli/createCommands.ts
@@ -143,55 +145,56 @@ src/cli/index.ts :
143
145
  ➞ src/lib/getEntryPoints.ts
144
146
  ➞ src/lib/getDepsTree.ts
145
147
  ➞ src/lib/getDepsSetWebpack.ts
146
- ➞ src/lib/utils.ts
148
+ ➞ src/lib/utils.ts
147
149
 
148
150
  ➞ src/cli/index.ts
149
151
  ➞ src/cli/createCommands.ts
150
152
  ➞ src/cli/files/index.ts
151
153
  ➞ src/lib/getDepsTree.ts
152
154
  ➞ src/lib/getDepsSetWebpack.ts
153
- ➞ src/lib/utils.ts
155
+ ➞ src/lib/utils.ts
154
156
 
155
157
  ➞ src/cli/index.ts
156
158
  ➞ src/cli/createCommands.ts
157
159
  ➞ src/cli/resolve/index.ts
158
160
  ➞ src/lib/find.ts
159
161
  ➞ src/lib/getEntryPoints.ts
160
- ➞ src/lib/utils.ts
162
+ ➞ src/lib/utils.ts
161
163
 
162
164
  ➞ src/cli/index.ts
163
165
  ➞ src/cli/createCommands.ts
164
166
  ➞ src/cli/entryPoints/index.ts
165
167
  ➞ src/lib/getEntryPoints.ts
166
- ➞ src/lib/utils.ts
168
+ ➞ src/lib/utils.ts
167
169
 
168
170
  ➞ src/cli/index.ts
169
171
  ➞ src/cli/createCommands.ts
170
172
  ➞ src/cli/resolve/index.ts
171
173
  ➞ src/lib/find.ts
172
- ➞ src/lib/utils.ts
174
+ ➞ src/lib/utils.ts
173
175
 
174
176
  ➞ src/cli/index.ts
175
177
  ➞ src/cli/createCommands.ts
176
178
  ➞ src/cli/resolve/index.ts
177
- ➞ src/lib/utils.ts
179
+ ➞ src/lib/utils.ts
178
180
 
179
181
  ➞ src/cli/index.ts
180
182
  ➞ src/cli/createCommands.ts
181
183
  ➞ src/cli/entryPoints/index.ts
182
- ➞ src/lib/utils.ts
184
+ ➞ src/lib/utils.ts
183
185
 
184
186
  ➞ src/cli/index.ts
185
187
  ➞ src/cli/createCommands.ts
186
188
  ➞ src/cli/files/index.ts
187
- ➞ src/lib/utils.ts
189
+ ➞ src/lib/utils.ts
188
190
 
189
191
  ```
192
+
190
193
  </details>
191
194
 
192
195
  ### How to check if a file is used in the project?
193
196
 
194
- Use `rev-dep resolve path/to/file.ts --compactSummary`
197
+ Use `rev-dep resolve path/to/file.ts --compactSummary`
195
198
 
196
199
  As a result you will see total amount of entry points requiring a given file.
197
200
 
@@ -202,7 +205,7 @@ As a result you will see total amount of entry points requiring a given file.
202
205
  <details>
203
206
  <summary>Example for the rev-dep repository</summary>
204
207
 
205
- command:
208
+ command:
206
209
 
207
210
  `rev-dep resolve src/lib/utils.ts --compactSummary`
208
211
 
@@ -222,6 +225,7 @@ types.d.ts : 0
222
225
 
223
226
  Total: 2
224
227
  ```
228
+
225
229
  </details>
226
230
 
227
231
  ### How to identify dead files in the project?
@@ -237,7 +241,7 @@ Review the list and look for suspicious files like `src/ui/components/SomeCompon
237
241
  <details>
238
242
  <summary>Example for the rev-dep repository</summary>
239
243
 
240
- command:
244
+ command:
241
245
 
242
246
  `rev-dep entry-points --exclude '__tests__/**' 'types.d.ts'`
243
247
 
@@ -253,14 +257,15 @@ src/lib/getMaxDepthInGraph.ts
253
257
 
254
258
  ```
255
259
 
256
- The last one `src/lib/getMaxDepthInGraph.ts` is the source file that is not used at the moment.
260
+ The last one `src/lib/getMaxDepthInGraph.ts` is the source file that is not used at the moment.
257
261
 
258
262
  The rest of them looks legit!
263
+
259
264
  </details>
260
265
 
261
266
  ### How to check which files are imported by a given file?
262
267
 
263
- To get a full list of files imported by given entry point use `rev-dep files path/to/file.ts`.
268
+ To get a full list of files imported by given entry point use `rev-dep files path/to/file.ts`.
264
269
 
265
270
  You can use `--count` flag if you are interested in the amount.
266
271
 
@@ -271,7 +276,7 @@ This is a good indicator of how heavy a given entry point or component is
271
276
  <details>
272
277
  <summary>Example for the rev-dep repository</summary>
273
278
 
274
- command:
279
+ command:
275
280
 
276
281
  `rev-dep files files src/cli/index.ts`
277
282
 
@@ -304,20 +309,25 @@ src/lib/cleanupDpdmDeps.ts
304
309
  ```
305
310
 
306
311
  As you can see cli even import `package.json`. This is to print version of the cli
307
- </details>
308
312
 
313
+ </details>
309
314
 
310
315
  ### How to reduce amount of files imported by entry point?
311
316
 
312
317
  There is no easy how to for this process, but you can do it iteratively using two of the `rev-dep` commands:
313
- - `files`
318
+
319
+ - `files`
314
320
  - `resolve`
315
321
 
316
- 1. Get the list of files imported by entry-point
317
- - `rev-dep files path/to/entry-point`
322
+ 1. Get the list of files imported by entry-point
323
+
324
+ - `rev-dep files path/to/entry-point`
325
+
318
326
  2. Identify some suspicious files on the list, components that should not be used on the given page or not related utility files
319
327
  3. Get all resolution paths for a suspicious file
320
- - `rev-dep resolve path/to/suspicious-file path/to/entry-point --all`
328
+
329
+ - `rev-dep resolve path/to/suspicious-file path/to/entry-point --all`
330
+
321
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
322
332
 
323
333
  ## Usage
@@ -335,7 +345,7 @@ For CLI usage see [CLI reference](#cli-reference)
335
345
  ```ts
336
346
  import { resolve } from "rev-dep";
337
347
 
338
- const paths = resolve({
348
+ const [paths] = await resolve({
339
349
  entryPoints: ["index.js"],
340
350
  filePath: "utils.js",
341
351
  });
@@ -348,7 +358,7 @@ console.log(paths);
348
358
  ```ts
349
359
  import { getEntryPoints } from "rev-dep";
350
360
 
351
- const entryPoints = getEntryPoints({
361
+ const [entryPoints] = await getEntryPoints({
352
362
  cwd: process.cwd(),
353
363
  });
354
364
 
@@ -447,9 +457,7 @@ rev-dep docs <outputPath> [options]
447
457
  ```js
448
458
  // babel.config.js
449
459
  module.exports = {
450
- plugins: [
451
- 'rev-dep/babel'
452
- ]
460
+ plugins: ["rev-dep/babel"],
453
461
  };
454
462
  ```
455
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;
@@ -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.0-alpha.7",
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;