rev-dep 1.0.0-alpha.4 → 1.0.0-alpha.5
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 +118 -61
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,16 +1,51 @@
|
|
|
1
1
|
<h3 align="center">
|
|
2
|
-
<code>rev
|
|
2
|
+
<code>rev⭠dep</code>
|
|
3
3
|
</h3>
|
|
4
4
|
|
|
5
5
|
<p align="center">
|
|
6
|
-
|
|
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
|
-
##
|
|
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
|
|
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
|
|
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,59 +63,31 @@ or
|
|
|
28
63
|
|
|
29
64
|
`npm install rev-dep`
|
|
30
65
|
|
|
31
|
-
##
|
|
66
|
+
## Recipes
|
|
32
67
|
|
|
33
|
-
|
|
68
|
+
### How to identify where a file is used in the project?
|
|
34
69
|
|
|
35
|
-
|
|
36
|
-
rev-dep resolve getDepsSet.js cli.js
|
|
37
|
-
```
|
|
70
|
+
### How to check if a file is used in the project?
|
|
38
71
|
|
|
39
|
-
|
|
72
|
+
### How to identify dead files in the project?
|
|
40
73
|
|
|
41
|
-
|
|
42
|
-
Results:
|
|
43
|
-
|
|
44
|
-
➞ cli.js
|
|
45
|
-
➞ find.js
|
|
46
|
-
➞ getDepsSet.js
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
Which says that `getDepsSet.js` file is used in `cli.js` entry point and is required through `find.js`
|
|
50
|
-
|
|
51
|
-
## About
|
|
52
|
-
|
|
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.
|
|
54
|
-
|
|
55
|
-
It's especially useful in JS world without TypeScript or tests coverage.
|
|
74
|
+
### How to check which files are imported by a given file?
|
|
56
75
|
|
|
57
|
-
|
|
76
|
+
### How to reduce amount of files imported by entry point?
|
|
58
77
|
|
|
59
78
|
## Usage
|
|
60
79
|
|
|
61
|
-
Project can be used as a CLI tool or as a
|
|
80
|
+
Project can be used as a CLI tool or as a module
|
|
62
81
|
|
|
63
82
|
### CLI Tool
|
|
64
83
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
#### `resolve`
|
|
68
|
-
|
|
69
|
-
```sh
|
|
70
|
-
rev-dep resolve <filePath> <entryPoints...>
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
Available options are
|
|
74
|
-
|
|
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
|
|
84
|
+
For CLI usage see [CLI reference](#CLI-reference)
|
|
78
85
|
|
|
79
86
|
### Module
|
|
80
87
|
|
|
81
88
|
#### `find` Function
|
|
82
89
|
|
|
83
|
-
```
|
|
90
|
+
```ts
|
|
84
91
|
import { find } from "rev-dep";
|
|
85
92
|
|
|
86
93
|
const path = find({
|
|
@@ -91,25 +98,18 @@ const path = find({
|
|
|
91
98
|
console.log(path);
|
|
92
99
|
```
|
|
93
100
|
|
|
94
|
-
#### `find`
|
|
95
|
-
|
|
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
|
|
102
|
-
|
|
103
|
-
### Additional setup may be required
|
|
104
|
-
|
|
105
|
-
#### Resolving implicit file extensions
|
|
101
|
+
#### `find` Function
|
|
106
102
|
|
|
107
|
-
|
|
108
|
-
|
|
103
|
+
```ts
|
|
104
|
+
import { find } from "rev-dep";
|
|
109
105
|
|
|
110
|
-
|
|
106
|
+
const path = find({
|
|
107
|
+
entryPoints: ["index.js"],
|
|
108
|
+
filePath: "utils.js",
|
|
109
|
+
});
|
|
111
110
|
|
|
112
|
-
|
|
111
|
+
console.log(path);
|
|
112
|
+
```
|
|
113
113
|
|
|
114
114
|
## CLI reference
|
|
115
115
|
|
|
@@ -196,6 +196,59 @@ rev-dep docs <outputPath> [options]
|
|
|
196
196
|
- `-hl, --headerLevel <value>` - Initial header level (_optional_)
|
|
197
197
|
<!-- cli-docs-end -->
|
|
198
198
|
|
|
199
|
+
## Export from problem
|
|
200
|
+
|
|
201
|
+
`rev-dep` attempts to also solve `export * from` by a babel plugin that can be used as follows
|
|
202
|
+
|
|
203
|
+
```js
|
|
204
|
+
// babel.config.js
|
|
205
|
+
module.exports = {
|
|
206
|
+
plugins: [
|
|
207
|
+
'rev-dep/babel'
|
|
208
|
+
]
|
|
209
|
+
};
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
The plugins is currently **experimental** and might not work for all codebases!
|
|
213
|
+
|
|
214
|
+
It helps by rewiring paths to re-exported modules
|
|
215
|
+
|
|
216
|
+
```ts
|
|
217
|
+
// file.ts
|
|
218
|
+
import { add } from "./utils";
|
|
219
|
+
|
|
220
|
+
// utils/index.ts
|
|
221
|
+
|
|
222
|
+
export * from "./math";
|
|
223
|
+
export * from "./otherModule";
|
|
224
|
+
export * from "./anotherModule";
|
|
225
|
+
|
|
226
|
+
// utils/math.ts
|
|
227
|
+
|
|
228
|
+
export const add = () => {};
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
And for `file.ts` it would rewire the import like this
|
|
232
|
+
|
|
233
|
+
```ts
|
|
234
|
+
// file.ts
|
|
235
|
+
import { add } from "./utils/math";
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
So as a result, we don't implicitly require `./otherModule` and `./anotherModule` which we will not use anyway
|
|
239
|
+
|
|
240
|
+
### Benefits
|
|
241
|
+
|
|
242
|
+
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.
|
|
243
|
+
|
|
244
|
+
But for sure it reduced bundle size, _slightly_, but still 😀
|
|
245
|
+
|
|
246
|
+
It all depends on the the project dependencies structure.
|
|
247
|
+
|
|
248
|
+
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.
|
|
249
|
+
|
|
250
|
+
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.
|
|
251
|
+
|
|
199
252
|
## Contributing
|
|
200
253
|
|
|
201
254
|
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 :)
|
|
@@ -204,16 +257,20 @@ Project is open to contributions, just rise an issue if you have some ideas abou
|
|
|
204
257
|
|
|
205
258
|
1. Clone repo
|
|
206
259
|
2. Install deps using `yarn`
|
|
207
|
-
3. Run
|
|
260
|
+
3. Run `yarn build:watch`
|
|
208
261
|
4. Code!
|
|
209
262
|
|
|
210
|
-
For testing purpose
|
|
263
|
+
For testing purpose use
|
|
264
|
+
|
|
265
|
+
`yarn dev [command] --cwd path/to/some/codebase`
|
|
266
|
+
|
|
267
|
+
or you can install CLI tool from the file system using
|
|
211
268
|
|
|
212
|
-
`yarn global add
|
|
269
|
+
`yarn global add $PWD`
|
|
213
270
|
|
|
214
|
-
|
|
271
|
+
and then just run
|
|
215
272
|
|
|
216
|
-
`
|
|
273
|
+
`rev-dep`
|
|
217
274
|
|
|
218
275
|
## Made with 🧠 by [@jayu](https://github.com/jayu)
|
|
219
276
|
|