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

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,16 +1,51 @@
1
1
  <h3 align="center">
2
- <code>rev🠄dep</code>
2
+ <code>revdep</code>
3
3
  </h3>
4
4
 
5
5
  <p align="center">
6
- A small tool for JavaScript project discovery
6
+ Dependency debugging tool for JavaScript and TypeScript projects
7
7
  </p>
8
8
 
9
9
  ---
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
- ## Installation
13
+ ## About
14
+
15
+ The tool was created help with daily dev struggles by answering these questions:
16
+
17
+ - What entry points my codebase have
18
+ - Which entry points uses a given file
19
+ - Which dependencies a given file has
20
+
21
+ This helps to debug project dependencies, plan refactoring, optimize bundles or plan code splitting.
22
+
23
+ It's especially useful in JS world without TypeScript or tests coverage.
24
+
25
+ It also helps to identify and eliminate dead files, understand the complexity of the file dependencies
26
+
27
+ [Jump to CLI reference](#cli-reference)
28
+
29
+ [`export * from` problem](#export-from-problem)
30
+
31
+ ### Use cases
32
+
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
+
40
+ ### How about dependency or bundle graphs?
41
+
42
+ There are tool that can output nice, visual representation of project dependencies like [webpack-bundle-analyzer](https://www.npmjs.com/package/webpack-bundle-analyzer) or [dependency-cruiser](https://www.npmjs.com/package/dependency-cruiser) (_which btw rev-dep uses for non-TS codebases_)
43
+
44
+ While graphs can be useful to identify major problems like too big bundle size or to visualize mess in your deps, it's hard to take any action based on them (_at least it was hard for me_ 🤷‍♂️)
45
+
46
+ `rev-dep` visualize dependencies as lists, so it's really easy to see where to cut the line to solve the problem.
47
+
48
+ ## Getting Started
14
49
 
15
50
  ### Install globally to use as CLI tool
16
51
 
@@ -28,88 +63,297 @@ or
28
63
 
29
64
  `npm install rev-dep`
30
65
 
31
- ## Example
66
+ ## Recipes
32
67
 
33
- For this repo
68
+ ### How to identify where a file is used in the project?
34
69
 
35
- ```sh
36
- rev-dep resolve getDepsSet.js cli.js
37
- ```
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
+ <details>
76
+ <summary>Example for the rev-dep repository</summary>
77
+
78
+ command:
79
+
80
+ `rev-dep resolve src/lib/utils.ts`
81
+
82
+ output:
83
+
84
+ ```s
85
+ src/babel/index.js :
38
86
 
39
- will output
87
+ ➞ src/babel/index.js
88
+ ➞ src/lib/utils.ts
89
+ _____________________
90
+
91
+ src/cli/index.ts :
92
+
93
+ ➞ src/cli/index.ts
94
+ ➞ src/cli/createCommands.ts
95
+ ➞ src/cli/resolve/index.ts
96
+ ➞ src/lib/find.ts
97
+ ➞ src/lib/getDepsTree.ts
98
+ ➞ src/lib/getDepsSetWebpack.ts
99
+ ➞ src/lib/utils.ts
100
+ _____________________
101
+
102
+ ```
103
+ </details>
104
+
105
+ #### Getting more details about file resolution in given entry point
106
+
107
+ To find out all paths combination use `rev-dep resolve` with `-a` flag
108
+
109
+ > You might be surprised how complex dependency tree can be!
110
+
111
+ <details>
112
+ <summary>Example for the rev-dep repository</summary>
113
+
114
+ command:
115
+
116
+ `rev-dep resolve src/lib/utils.ts src/cli/index.ts --all`
117
+
118
+ output:
119
+
120
+ ```s
121
+ src/cli/index.ts :
122
+
123
+ ➞ src/cli/index.ts
124
+ ➞ src/cli/createCommands.ts
125
+ ➞ src/cli/resolve/index.ts
126
+ ➞ src/lib/find.ts
127
+ ➞ src/lib/getDepsTree.ts
128
+ ➞ src/lib/getDepsSetWebpack.ts
129
+ ➞ src/lib/utils.ts
130
+
131
+ ➞ src/cli/index.ts
132
+ ➞ src/cli/createCommands.ts
133
+ ➞ src/cli/resolve/index.ts
134
+ ➞ src/lib/find.ts
135
+ ➞ src/lib/getEntryPoints.ts
136
+ ➞ src/lib/getDepsTree.ts
137
+ ➞ src/lib/getDepsSetWebpack.ts
138
+ ➞ src/lib/utils.ts
139
+
140
+ ➞ src/cli/index.ts
141
+ ➞ src/cli/createCommands.ts
142
+ ➞ src/cli/entryPoints/index.ts
143
+ ➞ src/lib/getEntryPoints.ts
144
+ ➞ src/lib/getDepsTree.ts
145
+ ➞ src/lib/getDepsSetWebpack.ts
146
+ ➞ src/lib/utils.ts
147
+
148
+ ➞ src/cli/index.ts
149
+ ➞ src/cli/createCommands.ts
150
+ ➞ src/cli/files/index.ts
151
+ ➞ src/lib/getDepsTree.ts
152
+ ➞ src/lib/getDepsSetWebpack.ts
153
+ ➞ src/lib/utils.ts
154
+
155
+ ➞ src/cli/index.ts
156
+ ➞ src/cli/createCommands.ts
157
+ ➞ src/cli/resolve/index.ts
158
+ ➞ src/lib/find.ts
159
+ ➞ src/lib/getEntryPoints.ts
160
+ ➞ src/lib/utils.ts
161
+
162
+ ➞ src/cli/index.ts
163
+ ➞ src/cli/createCommands.ts
164
+ ➞ src/cli/entryPoints/index.ts
165
+ ➞ src/lib/getEntryPoints.ts
166
+ ➞ src/lib/utils.ts
167
+
168
+ ➞ src/cli/index.ts
169
+ ➞ src/cli/createCommands.ts
170
+ ➞ src/cli/resolve/index.ts
171
+ ➞ src/lib/find.ts
172
+ ➞ src/lib/utils.ts
173
+
174
+ ➞ src/cli/index.ts
175
+ ➞ src/cli/createCommands.ts
176
+ ➞ src/cli/resolve/index.ts
177
+ ➞ src/lib/utils.ts
178
+
179
+ ➞ src/cli/index.ts
180
+ ➞ src/cli/createCommands.ts
181
+ ➞ src/cli/entryPoints/index.ts
182
+ ➞ src/lib/utils.ts
183
+
184
+ ➞ src/cli/index.ts
185
+ ➞ src/cli/createCommands.ts
186
+ ➞ src/cli/files/index.ts
187
+ ➞ src/lib/utils.ts
40
188
 
41
189
  ```
190
+ </details>
191
+
192
+ ### How to check if a file is used in the project?
193
+
194
+ Use `rev-dep resolve path/to/file.ts --compactSummary`
195
+
196
+ As a result you will see total amount of entry points requiring a given file.
197
+
198
+ > Note that among the entry points list there might be some dead files importing the searched file
199
+
200
+ [`resolve` Command CLI reference](#command-resolve)
201
+
202
+ <details>
203
+ <summary>Example for the rev-dep repository</summary>
204
+
205
+ command:
206
+
207
+ `rev-dep resolve src/lib/utils.ts --compactSummary`
208
+
209
+ output:
210
+
211
+ ```s
42
212
  Results:
43
213
 
44
- ➞ cli.js
45
- ➞ find.js
46
- ➞ getDepsSet.js
214
+ __tests__/find.test.js : 0
215
+ babel.js : 0
216
+ bin.js : 0
217
+ scripts/addDocsToReadme.js : 0
218
+ src/babel/index.js : 1
219
+ src/cli/index.ts : 1
220
+ src/lib/getMaxDepthInGraph.ts : 0
221
+ types.d.ts : 0
222
+
223
+ Total: 2
47
224
  ```
225
+ </details>
48
226
 
49
- Which says that `getDepsSet.js` file is used in `cli.js` entry point and is required through `find.js`
227
+ ### How to identify dead files in the project?
50
228
 
51
- ## About
229
+ Use `rev-dep entry-points` to get list of all files that are not required by any other files in the project.
52
230
 
53
- The tool was created to determine places in the project where a particular file is used, to test wether the refactoring do not break functionalities.
231
+ 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`
54
232
 
55
- It's especially useful in JS world without TypeScript or tests coverage.
233
+ Review the list and look for suspicious files like `src/ui/components/SomeComponent/index.js`
56
234
 
57
- Except the reverse dependency resolution path, it can print statistics about how many times a particular module is required in the project, which might be helpful for code-splitting planning.
235
+ [`entry-points` command CLI reference](#command-entry-points)
58
236
 
59
- ## Usage
237
+ <details>
238
+ <summary>Example for the rev-dep repository</summary>
60
239
 
61
- Project can be used as a CLI tool or as a regular JS module
240
+ command:
62
241
 
63
- ### CLI Tool
242
+ `rev-dep entry-points --exclude '__tests__/**' 'types.d.ts'`
64
243
 
65
- Avaliable commands:
244
+ output:
66
245
 
67
- #### `resolve`
246
+ ```s
247
+ babel.js
248
+ bin.js
249
+ scripts/addDocsToReadme.js
250
+ src/babel/index.js
251
+ src/cli/index.ts
252
+ src/lib/getMaxDepthInGraph.ts
68
253
 
69
- ```sh
70
- rev-dep resolve <filePath> <entryPoints...>
71
254
  ```
72
255
 
73
- Available options are
256
+ The last one `src/lib/getMaxDepthInGraph.ts` is the source file that is not used at the moment.
257
+
258
+ The rest of them looks legit!
259
+ </details>
260
+
261
+ ### How to check which files are imported by a given file?
262
+
263
+ To get a full list of files imported by given entry point use `rev-dep files path/to/file.ts`.
264
+
265
+ You can use `--count` flag if you are interested in the amount.
266
+
267
+ This is a good indicator of how heavy a given entry point or component is
74
268
 
75
- - `-cs or --compactSummary` - instead of file paths print a compact summary of reverse resolution with a count of found paths
76
- - `--verbose` - log currently performed operation
77
- - `-wc, --webpackConfig <path>` - path to webpack config to enable webpack aliases support
269
+ [`files` command CLI reference](#command-files)
270
+
271
+ <details>
272
+ <summary>Example for the rev-dep repository</summary>
273
+
274
+ command:
275
+
276
+ `rev-dep files files src/cli/index.ts`
277
+
278
+ output:
279
+
280
+ ```s
281
+ src/cli/index.ts
282
+ src/cli/createCommands.ts
283
+ package.json
284
+ src/cli/resolve/index.ts
285
+ src/cli/docs/index.ts
286
+ src/cli/entryPoints/index.ts
287
+ src/cli/files/index.ts
288
+ src/lib/find.ts
289
+ src/cli/resolve/types.ts
290
+ src/cli/resolve/formatResults.ts
291
+ src/lib/utils.ts
292
+ src/cli/commonOptions.ts
293
+ src/cli/docs/generate.ts
294
+ src/cli/entryPoints/types.ts
295
+ src/lib/getEntryPoints.ts
296
+ src/lib/buildDepsGraph.ts
297
+ src/cli/files/types.ts
298
+ src/lib/getDepsTree.ts
299
+ src/lib/types.ts
300
+ src/cli/docs/template.ts
301
+ src/lib/getDepsSetWebpack.ts
302
+ src/lib/cleanupDpdmDeps.ts
303
+
304
+ ```
305
+
306
+ As you can see cli even import `package.json`. This is to print version of the cli
307
+ </details>
308
+
309
+
310
+ ### How to reduce amount of files imported by entry point?
311
+
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`
315
+
316
+ 1. Get the list of files imported by entry-point
317
+ - `rev-dep files path/to/entry-point`
318
+ 2. Identify some suspicious files on the list, components that should not be used on the given page or not related utility files
319
+ 3. Get all resolution paths for a suspicious file
320
+ - `rev-dep resolve path/to/suspicious-file path/to/entry-point --all`
321
+ 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
+
323
+ ## Usage
324
+
325
+ Project can be used as a CLI tool or as a module
326
+
327
+ ### CLI Tool
328
+
329
+ For CLI usage see [CLI reference](#cli-reference)
78
330
 
79
331
  ### Module
80
332
 
81
- #### `find` Function
333
+ #### `resolve` Function
82
334
 
83
- ```js
84
- import { find } from "rev-dep";
335
+ ```ts
336
+ import { resolve } from "rev-dep";
85
337
 
86
- const path = find({
338
+ const paths = resolve({
87
339
  entryPoints: ["index.js"],
88
340
  filePath: "utils.js",
89
341
  });
90
342
 
91
- console.log(path);
343
+ console.log(paths);
92
344
  ```
93
345
 
94
- #### `find` Options
346
+ #### `getEntryPoints` Function
95
347
 
96
- - `entryPoints (Array)` - Array of entry points to build a tree for search. Usually it will be one entry point, but project can have many of them, eg. next.js application. **Required**
97
- - `filePath (String)` - A file that we want to find path for. **Required**
98
- - `skipRegex (String | RegExp)` - If a file path matches the pattern, we stop to traverse it's dependencies and do not include that file in the search tree. _Optional_, default: `'(node_modules|/__tests__|/__test__|/__mockContent__|.scss)'`
99
- - `verbose (Boolean)` - when set to true, will print current operation performed by find function. _Optional_, default: `false`
100
- - `cwd` - root for resolved files, must be an absolute path. _Optional_, default: `process.cwd()`
101
- - `webpackConfig (String)` - path to webpack config to enable webpack aliases support
348
+ ```ts
349
+ import { getEntryPoints } from "rev-dep";
102
350
 
103
- ### Additional setup may be required
104
-
105
- #### Resolving implicit file extensions
106
-
107
- A vast amount of JS/TS projects are configured in a way that allows (or even forces) to skip file extensions in import statements. Rev-dep is strongly based on [dependency-cruiser](https://github.com/sverweij/dependency-cruiser) which by default support implicit file extensions for `*.js, *.cjs, *.mjs, *.jsx` files (check [source](https://github.com/sverweij/dependency-cruiser/blob/96e34d0cf158034f2b7c8cafe9cec72dd74d8c45/src/extract/transpile/meta.js)).
108
- In order to resolve implicit extensions for other JS based languages it look for available corresponding compiler in `package.json`. If compiler is available, then extension is supported.
109
-
110
- If you installed `rev-dep` **globally**, you will have appropriate compiler installed **globally** as well. If you use it as a module, your project has to have compiler in it's package.json.
351
+ const entryPoints = getEntryPoints({
352
+ cwd: process.cwd(),
353
+ });
111
354
 
112
- For example, to support `*.ts` and `*.tsx` implicit extensions in globally installed `rev-dep`, you have to also install globally `typescript` package (see [source](https://github.com/sverweij/dependency-cruiser/blob/96e34d0cf158034f2b7c8cafe9cec72dd74d8c45/src/extract/transpile/typescript-wrap.js))
355
+ console.log(entryPoints);
356
+ ```
113
357
 
114
358
  ## CLI reference
115
359
 
@@ -133,7 +377,6 @@ rev-dep resolve <filePath> [entryPoints...] [options]
133
377
 
134
378
  - `-wc, --webpackConfig <path>` - path to webpack config to enable webpack aliases support (_optional_)
135
379
  - `--cwd <path>` - path to a directory that should be used as a resolution root (_optional_)
136
- - `-rr --reexportRewire <value>` - resolve actual dependencies for "export \* from" statements (_optional_)
137
380
  - `-i --include <globs...>` - A list of globs to determine files included in entry points search (_optional_)
138
381
  - `-e --exclude <globs...>` - A list of globs to determine files excluded in entry points search (_optional_)
139
382
  - `-cs, --compactSummary` - print a compact summary of reverse resolution with a count of found paths (_optional_)
@@ -153,7 +396,6 @@ rev-dep entry-points [options]
153
396
 
154
397
  - `-wc, --webpackConfig <path>` - path to webpack config to enable webpack aliases support (_optional_)
155
398
  - `--cwd <path>` - path to a directory that should be used as a resolution root (_optional_)
156
- - `-rr --reexportRewire <value>` - resolve actual dependencies for "export \* from" statements (_optional_)
157
399
  - `-i --include <globs...>` - A list of globs to determine files included in entry points search (_optional_)
158
400
  - `-e --exclude <globs...>` - A list of globs to determine files excluded in entry points search (_optional_)
159
401
  - `-pdc, --printDependenciesCount` - print count of entry point dependencies (_optional_)
@@ -177,7 +419,6 @@ rev-dep files <entryPoint> [options]
177
419
 
178
420
  - `-wc, --webpackConfig <path>` - path to webpack config to enable webpack aliases support (_optional_)
179
421
  - `--cwd <path>` - path to a directory that should be used as a resolution root (_optional_)
180
- - `-rr --reexportRewire <value>` - resolve actual dependencies for "export \* from" statements (_optional_)
181
422
  - `-c, --count` - print only count of entry point dependencies (_optional_)
182
423
 
183
424
  ### Command `docs`
@@ -199,6 +440,59 @@ rev-dep docs <outputPath> [options]
199
440
  - `-hl, --headerLevel <value>` - Initial header level (_optional_)
200
441
  <!-- cli-docs-end -->
201
442
 
443
+ ## Export from problem
444
+
445
+ `rev-dep` attempts to also solve `export * from` by a babel plugin that can be used as follows
446
+
447
+ ```js
448
+ // babel.config.js
449
+ module.exports = {
450
+ plugins: [
451
+ 'rev-dep/babel'
452
+ ]
453
+ };
454
+ ```
455
+
456
+ The plugins is currently **experimental** and might not work for all codebases!
457
+
458
+ It helps by rewiring paths to re-exported modules
459
+
460
+ ```ts
461
+ // file.ts
462
+ import { add } from "./utils";
463
+
464
+ // utils/index.ts
465
+
466
+ export * from "./math";
467
+ export * from "./otherModule";
468
+ export * from "./anotherModule";
469
+
470
+ // utils/math.ts
471
+
472
+ export const add = () => {};
473
+ ```
474
+
475
+ And for `file.ts` it would rewire the import like this
476
+
477
+ ```ts
478
+ // file.ts
479
+ import { add } from "./utils/math";
480
+ ```
481
+
482
+ So as a result, we don't implicitly require `./otherModule` and `./anotherModule` which we will not use anyway
483
+
484
+ ### Benefits
485
+
486
+ I don't have solid evidence for this, but I think it reduced RAM usage of the dev server I worked with (_blitz.js_). It crashed less often due to reaching heap size limit.
487
+
488
+ But for sure it reduced bundle size, _slightly_, but still 😀
489
+
490
+ It all depends on the the project dependencies structure.
491
+
492
+ By using the babel plugin you will reduce a risk of problems like implicitly importing `front-end` modules on the `server` or similar while still being able to benefit from short import paths.
493
+
494
+ Once I got an incident that, after a rebase with main branch, my project stopped compiling due to the problem caused by `export * from`. I spend a few hours debugging that, very frustrating.
495
+
202
496
  ## Contributing
203
497
 
204
498
  Project is open to contributions, just rise an issue if you have some ideas about features or you noticed a bug. After discussion we can approach implementation :)
@@ -207,16 +501,20 @@ Project is open to contributions, just rise an issue if you have some ideas abou
207
501
 
208
502
  1. Clone repo
209
503
  2. Install deps using `yarn`
210
- 3. Run tests using `yarn test --watch`
504
+ 3. Run `yarn build:watch`
211
505
  4. Code!
212
506
 
213
- For testing purpose you can install CLI tool from the file system using
507
+ For testing purpose use
508
+
509
+ `yarn dev [command] --cwd path/to/some/codebase`
510
+
511
+ or you can install CLI tool from the file system using
214
512
 
215
- `yarn global add file:ABSOLUTE_PATH_TO_REPO`
513
+ `yarn global add $PWD`
216
514
 
217
- or just
515
+ and then just run
218
516
 
219
- `yarn global add file:$(echo $PWD)`
517
+ `rev-dep`
220
518
 
221
519
  ## Made with 🧠 by [@jayu](https://github.com/jayu)
222
520
 
@@ -10,7 +10,7 @@ function createEntryPoints(program) {
10
10
  .description('Print list of entry points in current directory')
11
11
  .option(...commonOptions_1.webpackConfigOption)
12
12
  .option(...commonOptions_1.cwdOption)
13
- .option(...commonOptions_1.reexportRewireOption)
13
+ // .option(...reexportRewireOption)
14
14
  .option(...commonOptions_1.includeOption)
15
15
  .option(...commonOptions_1.excludeOption)
16
16
  .option('-pdc, --printDependenciesCount', 'print count of entry point dependencies', false)
@@ -11,7 +11,7 @@ function createFiles(program) {
11
11
  })
12
12
  .option(...commonOptions_1.webpackConfigOption)
13
13
  .option(...commonOptions_1.cwdOption)
14
- .option(...commonOptions_1.reexportRewireOption)
14
+ // .option(...reexportRewireOption)
15
15
  .option('-c, --count', 'print only count of entry point dependencies', false)
16
16
  .action(async (entryPoint, data) => {
17
17
  const { webpackConfig: webpackConfigPath, cwd, count } = data;
@@ -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");
@@ -13,16 +13,15 @@ function createResolve(program) {
13
13
  })
14
14
  .option(...commonOptions_1.webpackConfigOption)
15
15
  .option(...commonOptions_1.cwdOption)
16
- .option(...commonOptions_1.reexportRewireOption)
16
+ // .option(...reexportRewireOption)
17
17
  .option(...commonOptions_1.includeOption)
18
18
  .option(...commonOptions_1.excludeOption)
19
19
  .option('-cs, --compactSummary', 'print a compact summary of reverse resolution with a count of found paths')
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 sanitizedEntryPoints = (0, utils_1.sanitizeUserEntryPoints)(entryPoints);
24
- const [results, resolveEntryPoints] = await (0, find_1.resolve)({
25
- entryPoints: sanitizedEntryPoints,
23
+ const [results, resolveEntryPoints] = await (0, resolve_1.resolve)({
24
+ entryPoints,
26
25
  filePath,
27
26
  webpackConfig,
28
27
  all,
package/dist/lib/find.js CHANGED
@@ -24,7 +24,8 @@ const resolve = async ({ entryPoints: _entryPoints, filePath, webpackConfig, cwd
24
24
  let deps, entryPoints;
25
25
  if (_entryPoints.length > 0) {
26
26
  entryPoints = _entryPoints;
27
- deps = await (0, getDepsTree_1.getDepsTree)(cwd, entryPoints, webpackConfig);
27
+ const sanitizedEntryPoints = (0, utils_1.sanitizeUserEntryPoints)(entryPoints);
28
+ deps = await (0, getDepsTree_1.getDepsTree)(cwd, sanitizedEntryPoints, webpackConfig);
28
29
  }
29
30
  else {
30
31
  ;
@@ -0,0 +1,46 @@
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;
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.3",
4
- "description": "Reverse dependency resolution tool built with dependency-cruiser",
5
- "main": "lib/find.js",
3
+ "version": "1.0.0-alpha.6",
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/**",
@@ -59,5 +59,18 @@
59
59
  "prettier": "^2.1.2",
60
60
  "release-it": "^14.2.1",
61
61
  "typescript": "^4.6.2"
62
- }
62
+ },
63
+ "keywords": [
64
+ "dependencies",
65
+ "deps",
66
+ "dependency graph",
67
+ "dependency debugging",
68
+ "entry points",
69
+ "dependency resolution",
70
+ "reverse dependency resolution",
71
+ "dependency tree",
72
+ "import path",
73
+ "resolution path",
74
+ "dependency optimization"
75
+ ]
63
76
  }