rev-dep 1.5.4 → 2.0.0-alpha-0

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.
Files changed (73) hide show
  1. package/Readme.md +5 -0
  2. package/bin.js +66 -1
  3. package/package.json +6 -49
  4. package/README.md +0 -558
  5. package/babel.js +0 -1
  6. package/dist/babel/babelParsingOptions.d.ts +0 -5
  7. package/dist/babel/babelParsingOptions.js +0 -15
  8. package/dist/babel/groupBy.d.ts +0 -1
  9. package/dist/babel/groupBy.js +0 -14
  10. package/dist/babel/index.d.ts +0 -1
  11. package/dist/babel/index.js +0 -449
  12. package/dist/babel/processCodeTextModificationsArray.d.ts +0 -30
  13. package/dist/babel/processCodeTextModificationsArray.js +0 -55
  14. package/dist/babel/template.d.ts +0 -1
  15. package/dist/babel/template.js +0 -13
  16. package/dist/babel/transform.d.ts +0 -6
  17. package/dist/babel/transform.js +0 -66
  18. package/dist/babel/transformCli.d.ts +0 -1
  19. package/dist/babel/transformCli.js +0 -18
  20. package/dist/cli/commonOptions.d.ts +0 -27
  21. package/dist/cli/commonOptions.js +0 -29
  22. package/dist/cli/createCommands.d.ts +0 -2
  23. package/dist/cli/createCommands.js +0 -19
  24. package/dist/cli/docs/generate.d.ts +0 -20
  25. package/dist/cli/docs/generate.js +0 -90
  26. package/dist/cli/docs/index.d.ts +0 -3
  27. package/dist/cli/docs/index.js +0 -18
  28. package/dist/cli/docs/template.d.ts +0 -3
  29. package/dist/cli/docs/template.js +0 -51
  30. package/dist/cli/entryPoints/index.d.ts +0 -2
  31. package/dist/cli/entryPoints/index.js +0 -52
  32. package/dist/cli/entryPoints/types.d.ts +0 -4
  33. package/dist/cli/entryPoints/types.js +0 -2
  34. package/dist/cli/files/index.d.ts +0 -2
  35. package/dist/cli/files/index.js +0 -36
  36. package/dist/cli/files/types.d.ts +0 -3
  37. package/dist/cli/files/types.js +0 -2
  38. package/dist/cli/index.d.ts +0 -1
  39. package/dist/cli/index.js +0 -10
  40. package/dist/cli/nodeModules/index.d.ts +0 -2
  41. package/dist/cli/nodeModules/index.js +0 -36
  42. package/dist/cli/nodeModules/types.d.ts +0 -3
  43. package/dist/cli/nodeModules/types.js +0 -2
  44. package/dist/cli/resolve/formatResults.d.ts +0 -9
  45. package/dist/cli/resolve/formatResults.js +0 -67
  46. package/dist/cli/resolve/index.d.ts +0 -2
  47. package/dist/cli/resolve/index.js +0 -47
  48. package/dist/cli/resolve/types.d.ts +0 -11
  49. package/dist/cli/resolve/types.js +0 -2
  50. package/dist/lib/buildDepsGraph.d.ts +0 -2
  51. package/dist/lib/buildDepsGraph.js +0 -49
  52. package/dist/lib/cleanupDpdmDeps.d.ts +0 -3
  53. package/dist/lib/cleanupDpdmDeps.js +0 -39
  54. package/dist/lib/getDepsSetWebpack.d.ts +0 -6
  55. package/dist/lib/getDepsSetWebpack.js +0 -44
  56. package/dist/lib/getDepsTree.d.ts +0 -1
  57. package/dist/lib/getDepsTree.js +0 -24
  58. package/dist/lib/getEntryPoints.d.ts +0 -18
  59. package/dist/lib/getEntryPoints.js +0 -83
  60. package/dist/lib/getFilesForEntryPoint.d.ts +0 -8
  61. package/dist/lib/getFilesForEntryPoint.js +0 -12
  62. package/dist/lib/getMaxDepthInGraph.d.ts +0 -4
  63. package/dist/lib/getMaxDepthInGraph.js +0 -21
  64. package/dist/lib/getNodeModulesForEntryPoint.d.ts +0 -8
  65. package/dist/lib/getNodeModulesForEntryPoint.js +0 -18
  66. package/dist/lib/resolve.d.ts +0 -15
  67. package/dist/lib/resolve.js +0 -60
  68. package/dist/lib/types.d.ts +0 -12
  69. package/dist/lib/types.js +0 -2
  70. package/dist/lib/utils.d.ts +0 -6
  71. package/dist/lib/utils.js +0 -44
  72. package/dist/module.d.ts +0 -5
  73. package/dist/module.js +0 -28
package/Readme.md ADDED
@@ -0,0 +1,5 @@
1
+ Alpha version of [rev-dep](https://www.npmjs.com/package/rev-dep) v2.
2
+
3
+ Reimplemented from scratch in go to achieve 40x speedup.
4
+
5
+ Published from Tokyo 🇯🇵
package/bin.js CHANGED
@@ -1,2 +1,67 @@
1
1
  #!/usr/bin/env node
2
- require('./dist/cli')
2
+ const fs = require('fs')
3
+ const path = require('path')
4
+ const cp = require('child_process')
5
+ const binaryArgs = process.argv.slice(2)
6
+
7
+ const binaryPackageName = `@rev-dep/${process.platform}-${process.arch}`
8
+ let packageDir = ''
9
+
10
+ const nestedNodeModulesPath = path.join(__dirname, 'node_modules', binaryPackageName)
11
+ const siblingNodeModulesPath = path.join(__dirname, '../', binaryPackageName)
12
+
13
+ const checkedPaths = []
14
+
15
+ if (fs.existsSync(nestedNodeModulesPath)) {
16
+ packageDir = nestedNodeModulesPath
17
+ }
18
+ else if (fs.existsSync(siblingNodeModulesPath)) {
19
+ packageDir = siblingNodeModulesPath
20
+ } else {
21
+ checkedPaths.push(nestedNodeModulesPath, siblingNodeModulesPath)
22
+ let lookupDir = path.join(__dirname, '../../../')
23
+ while (lookupDir != undefined && packageDir == '') {
24
+ const pathToCheck = path.join(lookupDir, 'node_modules', binaryPackageName)
25
+ if (fs.existsSync(pathToCheck)) {
26
+ packageDir = pathToCheck
27
+ }
28
+ else {
29
+ checkedPaths.push(pathToCheck)
30
+ if (lookupDir === '/') {
31
+ lookupDir = undefined
32
+ }
33
+ else {
34
+ lookupDir = path.join(lookupDir, '../')
35
+ }
36
+ }
37
+ }
38
+ }
39
+
40
+ if (packageDir === '') {
41
+ console.error("Could not locate rev-dep binary for your platform: ", binaryPackageName)
42
+ console.log('Checked paths', checkedPaths)
43
+ process.exit(1)
44
+ }
45
+
46
+ const binary = path.join(packageDir, 'bin', 'rev-dep')
47
+
48
+ if (!fs.existsSync(binary)) {
49
+ console.error("Could not locate binary in package directory.")
50
+ console.log(binary, 'does not exist')
51
+ process.exit(1)
52
+ }
53
+
54
+ try {
55
+ const result = cp.execSync(`${binary} ${binaryArgs.join(' ')}`, { stdio: 'pipe' })
56
+
57
+ if (Buffer.isBuffer(result)) {
58
+ process.stdout.write(result.toString())
59
+ }
60
+ else {
61
+ console.error("Unexpected binary result", result)
62
+ }
63
+ } catch (e) {
64
+ process.stderr.write(e.stderr)
65
+ process.exit(e.status)
66
+ }
67
+
package/package.json CHANGED
@@ -1,14 +1,10 @@
1
1
  {
2
2
  "name": "rev-dep",
3
- "version": "1.5.4",
3
+ "version": "2.0.0-alpha-0",
4
4
  "description": "Dependency debugging tool for JavaScript and TypeScript projects",
5
- "main": "dist/module.js",
6
5
  "bin": "bin.js",
7
6
  "files": [
8
- "dist/**",
9
- "lib/**",
10
- "bin.js",
11
- "babel.js"
7
+ "bin.js"
12
8
  ],
13
9
  "author": "Jakub Mazurek @jayu",
14
10
  "license": "MIT",
@@ -18,50 +14,11 @@
18
14
  },
19
15
  "homepage": "https://github.com/jayu/rev-dep#readme",
20
16
  "engines": {
21
- "node": ">=10"
17
+ "node": ">=18"
22
18
  },
23
- "scripts": {
24
- "checks": "yarn lint && yarn typecheck",
25
- "lint": "eslint --ext .js,.ts src",
26
- "lint:fix": "yarn lint --fix",
27
- "docs-gen": "node ./scripts/addDocsToReadme.js",
28
- "dev": "node bin",
29
- "test": "jest",
30
- "release": "release-it",
31
- "build": "tsc --declaration",
32
- "build:watch": "tsc --watch",
33
- "typecheck": "tsc --noEmit"
34
- },
35
- "dependencies": {
36
- "@babel/core": "^7.20.12",
37
- "@babel/parser": "^7.17.8",
38
- "@babel/template": "^7.16.7",
39
- "@codeque/core": "^0.4.0",
40
- "@types/dedent": "^0.7.0",
41
- "colorette": "^2.0.16",
42
- "commander": "^6.1.0",
43
- "dedent": "^0.7.0",
44
- "dependency-cruiser": "9.23.0",
45
- "dpdm": "^3.8.0",
46
- "glob-escape": "^0.0.2",
47
- "ignore": "^5.2.0",
48
- "is-builtin-module": "^3.1.0",
49
- "minimatch": "^5.0.1"
50
- },
51
- "devDependencies": {
52
- "@babel/types": "^7.17.0",
53
- "@typescript-eslint/eslint-plugin": "^5.16.0",
54
- "@typescript-eslint/parser": "^5.16.0",
55
- "eslint": "^7.11.0",
56
- "eslint-config-prettier": "^8.5.0",
57
- "eslint-plugin-jest": "^24.1.0",
58
- "eslint-plugin-node": "^11.1.0",
59
- "eslint-plugin-prettier": "^4.0.0",
60
- "jest": "^26.5.3",
61
- "mock-fs": "^4.13.0",
62
- "prettier": "^2.1.2",
63
- "release-it": "16.2.1",
64
- "typescript": "^4.6.2"
19
+ "optionalDependencies": {
20
+ "@rev-dep/darwin-arm64": "2.0.0-alpha-0",
21
+ "@rev-dep/linux-x64": "2.0.0-alpha-0"
65
22
  },
66
23
  "keywords": [
67
24
  "dependencies",
package/README.md DELETED
@@ -1,558 +0,0 @@
1
- <h3 align="center">
2
- <code>rev-dep</code>
3
- </h3>
4
-
5
- <p align="center">
6
- File dependency debugging tool for TypeScript projects
7
- </p>
8
-
9
- ---
10
-
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
-
13
- ## Pardon 🤫
14
-
15
- Since you landed here, you might be also interested in my other project - supercharged multiline code search and replace tool - [codeque.co](https://codeque.co) 🥳
16
-
17
- ## About 📣
18
-
19
- The tool was created help with daily dev struggles by answering these questions:
20
-
21
- 👉 What entry points my codebase have
22
-
23
- 👉 Which entry points uses a given file
24
-
25
- 👉 Which dependencies a given file has
26
-
27
- This helps to debug project dependencies, plan refactoring, optimize bundles or plan code splitting.
28
-
29
- It's especially useful in JS world without TypeScript or tests coverage.
30
-
31
- It also helps to identify and eliminate dead files, understand the complexity of the file dependencies
32
-
33
- [🦘 Jump to CLI reference](#cli-reference-)
34
-
35
- [🕸️ `export * from` problem](#export-from-problem)
36
-
37
- ### Use cases 🧑‍💻
38
-
39
- - [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)
40
- - [You are wondering wether a given source file is used](#how-to-check-if-a-file-is-used-in-the-project)
41
- - [You wonder if there are any dead files in your project](#how-to-identify-dead-files-in-the-project)
42
- - [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)
43
- - [You want to optimize the amount of files imported by an entry point](#how-to-reduce-amount-of-files-imported-by-entry-point)
44
-
45
- ### How about dependency or bundle graphs?
46
-
47
- 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_)
48
-
49
- 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_ 🤷‍♂️)
50
-
51
- `rev-dep` visualize dependencies as lists, so it's really easy to see where to cut the line to solve the problem.
52
-
53
- ## Getting Started 🎉
54
-
55
- ### Install globally to use as CLI tool
56
-
57
- `yarn global add rev-dep`
58
-
59
- or
60
-
61
- `npm -g install rev-dep`
62
-
63
- ### Install in project to use as a module
64
-
65
- `yarn add rev-dep`
66
-
67
- or
68
-
69
- `npm install rev-dep`
70
-
71
- ## Recipes 🌶️
72
-
73
- ### How to identify where a file is used in the project?
74
-
75
- Just use `rev-dep resolve path/to/file.ts`
76
-
77
- You will see all the entry points that implicitly require given file together with resolution path.
78
-
79
- [`resolve` Command CLI reference](#command-resolve)
80
-
81
- <details>
82
- <summary>Example for the rev-dep repository</summary>
83
-
84
- command:
85
-
86
- `rev-dep resolve src/lib/utils.ts`
87
-
88
- output:
89
-
90
- ```s
91
- src/babel/index.js :
92
-
93
- ➞ src/babel/index.js
94
- ➞ src/lib/utils.ts
95
- _____________________
96
-
97
- src/cli/index.ts :
98
-
99
- ➞ src/cli/index.ts
100
- ➞ src/cli/createCommands.ts
101
- ➞ src/cli/resolve/index.ts
102
- ➞ src/lib/find.ts
103
- ➞ src/lib/getDepsTree.ts
104
- ➞ src/lib/getDepsSetWebpack.ts
105
- ➞ src/lib/utils.ts
106
- _____________________
107
-
108
- ```
109
-
110
- </details>
111
-
112
- #### Getting more details about file resolution in given entry point
113
-
114
- To find out all paths combination use `rev-dep resolve` with `-a` flag
115
-
116
- > You might be surprised how complex dependency tree can be!
117
-
118
- <details>
119
- <summary>Example for the rev-dep repository</summary>
120
-
121
- command:
122
-
123
- `rev-dep resolve src/lib/utils.ts src/cli/index.ts --all`
124
-
125
- output:
126
-
127
- ```s
128
- src/cli/index.ts :
129
-
130
- ➞ src/cli/index.ts
131
- ➞ src/cli/createCommands.ts
132
- ➞ src/cli/resolve/index.ts
133
- ➞ src/lib/find.ts
134
- ➞ src/lib/getDepsTree.ts
135
- ➞ src/lib/getDepsSetWebpack.ts
136
- ➞ src/lib/utils.ts
137
-
138
- ➞ src/cli/index.ts
139
- ➞ src/cli/createCommands.ts
140
- ➞ src/cli/resolve/index.ts
141
- ➞ src/lib/find.ts
142
- ➞ src/lib/getEntryPoints.ts
143
- ➞ src/lib/getDepsTree.ts
144
- ➞ src/lib/getDepsSetWebpack.ts
145
- ➞ src/lib/utils.ts
146
-
147
- ➞ src/cli/index.ts
148
- ➞ src/cli/createCommands.ts
149
- ➞ src/cli/entryPoints/index.ts
150
- ➞ src/lib/getEntryPoints.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/files/index.ts
158
- ➞ src/lib/getDepsTree.ts
159
- ➞ src/lib/getDepsSetWebpack.ts
160
- ➞ src/lib/utils.ts
161
-
162
- ➞ src/cli/index.ts
163
- ➞ src/cli/createCommands.ts
164
- ➞ src/cli/resolve/index.ts
165
- ➞ src/lib/find.ts
166
- ➞ src/lib/getEntryPoints.ts
167
- ➞ src/lib/utils.ts
168
-
169
- ➞ src/cli/index.ts
170
- ➞ src/cli/createCommands.ts
171
- ➞ src/cli/entryPoints/index.ts
172
- ➞ src/lib/getEntryPoints.ts
173
- ➞ src/lib/utils.ts
174
-
175
- ➞ src/cli/index.ts
176
- ➞ src/cli/createCommands.ts
177
- ➞ src/cli/resolve/index.ts
178
- ➞ src/lib/find.ts
179
- ➞ src/lib/utils.ts
180
-
181
- ➞ src/cli/index.ts
182
- ➞ src/cli/createCommands.ts
183
- ➞ src/cli/resolve/index.ts
184
- ➞ src/lib/utils.ts
185
-
186
- ➞ src/cli/index.ts
187
- ➞ src/cli/createCommands.ts
188
- ➞ src/cli/entryPoints/index.ts
189
- ➞ src/lib/utils.ts
190
-
191
- ➞ src/cli/index.ts
192
- ➞ src/cli/createCommands.ts
193
- ➞ src/cli/files/index.ts
194
- ➞ src/lib/utils.ts
195
-
196
- ```
197
-
198
- </details>
199
-
200
- ### How to check if a file is used in the project?
201
-
202
- Use `rev-dep resolve path/to/file.ts --compactSummary`
203
-
204
- As a result you will see total amount of entry points requiring a given file.
205
-
206
- > Note that among the entry points list there might be some dead files importing the searched file
207
-
208
- [`resolve` Command CLI reference](#command-resolve)
209
-
210
- <details>
211
- <summary>Example for the rev-dep repository</summary>
212
-
213
- command:
214
-
215
- `rev-dep resolve src/lib/utils.ts --compactSummary`
216
-
217
- output:
218
-
219
- ```s
220
- Results:
221
-
222
- __tests__/find.test.js : 0
223
- babel.js : 0
224
- bin.js : 0
225
- scripts/addDocsToReadme.js : 0
226
- src/babel/index.js : 1
227
- src/cli/index.ts : 1
228
- src/lib/getMaxDepthInGraph.ts : 0
229
- types.d.ts : 0
230
-
231
- Total: 2
232
- ```
233
-
234
- </details>
235
-
236
- ### How to identify dead files in the project?
237
-
238
- Use `rev-dep entry-points` to get list of all files that are not required by any other files in the project.
239
-
240
- 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`
241
-
242
- Review the list and look for suspicious files like `src/ui/components/SomeComponent/index.js`
243
-
244
- [`entry-points` command CLI reference](#command-entry-points)
245
-
246
- <details>
247
- <summary>Example for the rev-dep repository</summary>
248
-
249
- command:
250
-
251
- `rev-dep entry-points --exclude '__tests__/**' 'types.d.ts'`
252
-
253
- output:
254
-
255
- ```s
256
- babel.js
257
- bin.js
258
- scripts/addDocsToReadme.js
259
- src/babel/index.js
260
- src/cli/index.ts
261
- src/lib/getMaxDepthInGraph.ts
262
-
263
- ```
264
-
265
- The last one `src/lib/getMaxDepthInGraph.ts` is the source file that is not used at the moment.
266
-
267
- The rest of them looks legit!
268
-
269
- </details>
270
-
271
- ### How to check which files are imported by a given file?
272
-
273
- To get a full list of files imported by given entry point use `rev-dep files path/to/file.ts`.
274
-
275
- You can use `--count` flag if you are interested in the amount.
276
-
277
- This is a good indicator of how heavy a given entry point or component is
278
-
279
- [`files` command CLI reference](#command-files)
280
-
281
- <details>
282
- <summary>Example for the rev-dep repository</summary>
283
-
284
- command:
285
-
286
- `rev-dep files files src/cli/index.ts`
287
-
288
- output:
289
-
290
- ```s
291
- src/cli/index.ts
292
- src/cli/createCommands.ts
293
- package.json
294
- src/cli/resolve/index.ts
295
- src/cli/docs/index.ts
296
- src/cli/entryPoints/index.ts
297
- src/cli/files/index.ts
298
- src/lib/find.ts
299
- src/cli/resolve/types.ts
300
- src/cli/resolve/formatResults.ts
301
- src/lib/utils.ts
302
- src/cli/commonOptions.ts
303
- src/cli/docs/generate.ts
304
- src/cli/entryPoints/types.ts
305
- src/lib/getEntryPoints.ts
306
- src/lib/buildDepsGraph.ts
307
- src/cli/files/types.ts
308
- src/lib/getDepsTree.ts
309
- src/lib/types.ts
310
- src/cli/docs/template.ts
311
- src/lib/getDepsSetWebpack.ts
312
- src/lib/cleanupDpdmDeps.ts
313
-
314
- ```
315
-
316
- As you can see cli even import `package.json`. This is to print version of the cli
317
-
318
- </details>
319
-
320
- ### How to reduce amount of files imported by entry point?
321
-
322
- There is no easy how to for this process, but you can do it iteratively using `rev-dep` commands `files` and `resolve`
323
-
324
- 1. Get the list of files imported by entry-point
325
-
326
- `rev-dep files path/to/entry-point`
327
-
328
- 2. Identify some suspicious files on the list, components that should not be used on the given page or not related utility files
329
- 3. Get all resolution paths for a suspicious file
330
-
331
- `rev-dep resolve path/to/suspicious-file path/to/entry-point --all`
332
-
333
- 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
334
-
335
- ## Usage 🎨
336
-
337
- Project can be used as a CLI tool or as a module
338
-
339
- ### CLI Tool
340
-
341
- For CLI usage see [CLI reference](#cli-reference-)
342
-
343
- ### Module
344
-
345
- #### `resolve` Function
346
-
347
- ```ts
348
- import { resolve } from "rev-dep";
349
-
350
- const [paths] = await resolve({
351
- entryPoints: ["index.js"],
352
- filePath: "utils.js",
353
- });
354
-
355
- console.log(paths);
356
- ```
357
-
358
- #### `getEntryPoints` Function
359
-
360
- ```ts
361
- import { getEntryPoints } from "rev-dep";
362
-
363
- const [entryPoints] = await getEntryPoints({
364
- cwd: process.cwd(),
365
- });
366
-
367
- console.log(entryPoints);
368
- ```
369
-
370
- ## CLI reference 📖
371
-
372
- <!-- cli-docs-start -->
373
-
374
- ### Command `resolve`
375
-
376
- Checks if a filePath is required from entryPoint(s) and prints the resolution path
377
-
378
- #### Usage
379
-
380
- ```sh
381
- rev-dep resolve <filePathOrNodeModuleName> [entryPoints...] [options]
382
- ```
383
-
384
- #### Arguments
385
-
386
- - `filePathOrNodeModuleName` - undefined (**required**)
387
- - `entryPoints...` - List of entry points to look for file (_optional_)
388
-
389
- #### Options
390
-
391
- - `-wc, --webpackConfig <path>` - path to webpack config to enable webpack aliases support (_optional_)
392
- - `--cwd <path>` - path to a directory that should be used as a resolution root (_optional_)
393
- - `-i --include <globs...>` - A list of globs to determine files included in entry points search (_optional_)
394
- - `-e --exclude <globs...>` - A list of globs to determine files excluded in entry points search (_optional_)
395
- - `-cs, --compactSummary` - print a compact summary of reverse resolution with a count of found paths (_optional_)
396
- - `-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 (_optional_)
397
- - `-ntp --notTraversePaths <paths...>` - Specify file paths relative to resolution root, that should not be traversed when finding dependency path (_optional_)
398
- - `-inm --includeNodeModules` - Whether to include node modules in dependency graph. Has to be provided to resolve node module. (_optional_)
399
- - `-iti --ignoreTypesImports` - Use this flag to not follow type imports when resolving modules (_optional_)
400
-
401
- ### Command `entry-points`
402
-
403
- Print list of entry points in current directory
404
-
405
- #### Usage
406
-
407
- ```sh
408
- rev-dep entry-points [options]
409
- ```
410
-
411
- #### Options
412
-
413
- - `-wc, --webpackConfig <path>` - path to webpack config to enable webpack aliases support (_optional_)
414
- - `--cwd <path>` - path to a directory that should be used as a resolution root (_optional_)
415
- - `-i --include <globs...>` - A list of globs to determine files included in entry points search (_optional_)
416
- - `-e --exclude <globs...>` - A list of globs to determine files excluded in entry points search (_optional_)
417
- - `-pdc, --printDependenciesCount` - print count of entry point dependencies (_optional_)
418
- - `-c, --count` - print just count of found entry points (_optional_)
419
- - `-iti --ignoreTypesImports` - Use this flag to not follow type imports when resolving modules (_optional_)
420
-
421
- ### Command `files`
422
-
423
- Get list of files required by entry point
424
-
425
- #### Usage
426
-
427
- ```sh
428
- rev-dep files <entryPoint> [options]
429
- ```
430
-
431
- #### Arguments
432
-
433
- - `entryPoint` - Path to entry point (**required**)
434
-
435
- #### Options
436
-
437
- - `-wc, --webpackConfig <path>` - path to webpack config to enable webpack aliases support (_optional_)
438
- - `--cwd <path>` - path to a directory that should be used as a resolution root (_optional_)
439
- - `-c, --count` - print only count of entry point dependencies (_optional_)
440
- - `-iti --ignoreTypesImports` - Use this flag to not follow type imports when resolving modules (_optional_)
441
-
442
- ### Command `node-modules`
443
-
444
- Get list of node modules required by entry point
445
-
446
- #### Usage
447
-
448
- ```sh
449
- rev-dep node-modules <entryPoint> [options]
450
- ```
451
-
452
- #### Arguments
453
-
454
- - `entryPoint` - Path to entry point (**required**)
455
-
456
- #### Options
457
-
458
- - `-wc, --webpackConfig <path>` - path to webpack config to enable webpack aliases support (_optional_)
459
- - `--cwd <path>` - path to a directory that should be used as a resolution root (_optional_)
460
- - `-c, --count` - print only count of entry point dependencies (_optional_)
461
- - `-iti --ignoreTypesImports` - Use this flag to not follow type imports when resolving modules (_optional_)
462
-
463
- ### Command `docs`
464
-
465
- Generate documentation of available commands into md file.
466
-
467
- #### Usage
468
-
469
- ```sh
470
- rev-dep docs <outputPath> [options]
471
- ```
472
-
473
- #### Arguments
474
-
475
- - `outputPath` - path to output \*.md file (**required**)
476
-
477
- #### Options
478
-
479
- - `-hl, --headerLevel <value>` - Initial header level (_optional_)
480
- <!-- cli-docs-end -->
481
-
482
- ## Export from problem
483
-
484
- `rev-dep` attempts to also solve `export * from` by a babel plugin that can be used as follows
485
-
486
- ```js
487
- // babel.config.js
488
- module.exports = {
489
- plugins: ["rev-dep/babel"],
490
- };
491
- ```
492
-
493
- The plugins is currently **experimental** and might not work for all codebases!
494
-
495
- It helps by rewiring paths to re-exported modules
496
-
497
- ```ts
498
- // file.ts
499
- import { add } from "./utils";
500
-
501
- // utils/index.ts
502
-
503
- export * from "./math";
504
- export * from "./otherModule";
505
- export * from "./anotherModule";
506
-
507
- // utils/math.ts
508
-
509
- export const add = () => {};
510
- ```
511
-
512
- And for `file.ts` it would rewire the import like this
513
-
514
- ```ts
515
- // file.ts
516
- import { add } from "./utils/math";
517
- ```
518
-
519
- So as a result, we don't implicitly require `./otherModule` and `./anotherModule` which we will not use anyway
520
-
521
- ### Benefits
522
-
523
- 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.
524
-
525
- But for sure it reduced bundle size, _slightly_, but still 😀
526
-
527
- It all depends on the the project dependencies structure.
528
-
529
- 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.
530
-
531
- 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.
532
-
533
- ## Contributing
534
-
535
- 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 :)
536
-
537
- ## Development
538
-
539
- 1. Clone repo
540
- 2. Install deps using `yarn`
541
- 3. Run `yarn build:watch`
542
- 4. Code!
543
-
544
- For testing purpose use
545
-
546
- `yarn dev [command] --cwd path/to/some/codebase`
547
-
548
- or you can install CLI tool from the file system using
549
-
550
- `yarn global add $PWD`
551
-
552
- and then just run
553
-
554
- `rev-dep`
555
-
556
- ## Made with 🧠 by [@jayu](https://github.com/jayu)
557
-
558
- I hope that this small piece of software will help you discover and understood complexity of your project hence make you more confident while refactoring. If this tool was useful, don't hesitate to give it a ⭐!
package/babel.js DELETED
@@ -1 +0,0 @@
1
- module.exports = require('./dist/babel/index.js')