rev-dep 2.0.0-alpha-8 → 2.1.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 (2) hide show
  1. package/Readme.md +853 -3
  2. package/package.json +25 -23
package/Readme.md CHANGED
@@ -1,5 +1,855 @@
1
- Alpha version of [rev-dep](https://www.npmjs.com/package/rev-dep) v2.
1
+ <p align="center">
2
+ <img src="https://github.com/jayu/rev-dep/raw/master/logo.png" width="400">
3
+ </p>
2
4
 
3
- Reimplemented from scratch in go to achieve 40x speedup.
5
+ <p align="center">
6
+ <a href="#key-features-">Key Features</a>&nbsp;&nbsp;•&nbsp;&nbsp;
7
+ <a href="#installation-">Installation</a>&nbsp;&nbsp;•&nbsp;&nbsp;
8
+ <a href="#quick-examples-">Quick Examples</a>&nbsp;&nbsp;•&nbsp;&nbsp;
9
+ <a href="#practical-examples-">Practical Examples</a>&nbsp;&nbsp;•&nbsp;&nbsp;
10
+ <a href="#cli-reference-">CLI Reference</a>
11
+ </p>
4
12
 
5
- Published from Opole 🇵🇱
13
+ <p align="center">
14
+ Dependency analysis and optimization toolkit for modern JavaScript and TypeScript projects.
15
+ <br>
16
+ Trace imports, find unused code, clean dependencies — all from a blazing-fast CLI.
17
+ </p>
18
+
19
+ ---
20
+
21
+ <img alt="rev-dep version" src="https://img.shields.io/npm/v/rev-dep">
22
+ <img alt="rev-dep license" src="https://img.shields.io/npm/l/rev-dep">
23
+ <img alt="rev-dep PRs welcome" src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square">
24
+
25
+ ---
26
+
27
+ # **About 📣**
28
+
29
+ Working in large JS/TS projects makes it difficult to answer simple but crucial questions:
30
+
31
+ * Which files depend on this file?
32
+ * Is this file even used?
33
+ * Which files does this entry point import?
34
+ * Do I have circular dependencies?
35
+ * Which packages in node_modules are unused?
36
+ * Which modules take the most disk space?
37
+
38
+ rev-dep helps you understand the real structure of your codebase so you can debug issues faster, refactor safely, and keep your dependencies clean.
39
+
40
+ It's particularly useful for JavaScript projects without TypeScript or test coverage — places where answering question "What will break if I change this" is not straightforward
41
+
42
+ ---
43
+
44
+ ## **Why rev-dep? 🤔**
45
+
46
+ rev-dep is designed for **fast iteration** and **minimal, actionable results** — no noise, just answers.
47
+
48
+ ### ✅ **Results in milliseconds**
49
+
50
+ Built in Go for speed. Even on large codebases, rev-dep responds almost instantly.
51
+
52
+ ### ✅ **Actionable, list-based output**
53
+
54
+ You get **exact file paths**, **import chains**, and **clear dependency relationships** — the kind of information you can fix or clean up right away.
55
+
56
+ ### ✅ **Designed for real-world JS/TS**
57
+
58
+ Works with mixed JS/TS projects, path aliases and thousands of files without configuration hassles.
59
+
60
+ ### ✅ **Deep analysis, one CLI**
61
+
62
+ Unused files, unused or missing dependencies, reverse-imports, entry point detection, node_modules insights, dependency paths — everything in one tool.
63
+
64
+ <!--
65
+ ### ✔ **Much faster than alternatives**
66
+
67
+ rev-dep outperforms Madge, dpdm, dependency-cruiser, skott, knip, depcheck and other similar tools.
68
+
69
+ For 500k+ lines of code and 6k+ source code files get checks as fast as:
70
+
71
+ | Task | Execution Time |
72
+ |------|----------------|
73
+ | Find circular dependencies | |
74
+ | Find unused files | |
75
+ | Find unused node modules | |
76
+ | Find missing node modules | |
77
+ | Trace reverse dependencies for a file | |
78
+ | Trace full dependency paths | |
79
+ | List all files imported by an entry point | |
80
+ | Discover entry points | |
81
+ | Count lines of code | |
82
+ | Check node_modules disk usage | |
83
+ | Analyze node_modules directory sizes | |
84
+ | List file-to-file dependency graph | |
85
+
86
+ >Benchmark run on WSL Linux Debian Intel(R) Core(TM) i9-14900KF CPU @ 2.80GHz
87
+
88
+ --->
89
+
90
+ If your project feels like a dependency maze, rev-dep gives you a map.
91
+
92
+ ---
93
+
94
+ # **Key Features 🚀**
95
+
96
+ * 🔍 **Reverse dependency lookup** — see all entry points that require a given file
97
+ * 🗂️ **Entry point discovery**
98
+ * 🧹 **Dead file detection**
99
+ * 📦 **Unused / missing / used node modules / dependencies analysis**
100
+ * 🔄 **Circular imports/dependencies detection**
101
+ * 🧭 **Trace all import paths between files**
102
+ * 📁 **List all files imported by any entry point**
103
+ * 📏 **Count actual lines of code (excluding comments, blanks and ai prompts)**
104
+ * 💽 **Node modules disk usage & size analysis**
105
+ * 💡 **Works with both JavaScript and TypeScript**
106
+ * ⚡ **Built for large codebases**
107
+
108
+ ---
109
+
110
+ # **Installation 📦**
111
+
112
+ Install globally to use as a CLI tool:
113
+
114
+ ```
115
+ yarn global add rev-dep
116
+ ```
117
+
118
+ ```
119
+ npm install -g rev-dep
120
+ ```
121
+
122
+ ```
123
+ pnpm global add rev-dep
124
+ ```
125
+
126
+ ---
127
+
128
+ # **Quick Examples ⚡**
129
+
130
+ A few instant-use examples to get a feel for the tool:
131
+
132
+ ```bash
133
+ # Find every entry point that depends on a file
134
+ rev-dep resolve --file src/utils/math.ts
135
+
136
+ # List all entry points in the project
137
+ rev-dep entry-points
138
+
139
+ # Detect unused node modules
140
+ rev-dep node-modules unused
141
+
142
+ # Check which files an entry point imports
143
+ rev-dep files --entry-point src/index.ts
144
+
145
+ # Detect circular imports/dependencies
146
+ rev-dep circular
147
+ ```
148
+
149
+ ---
150
+
151
+ # **Practical Examples 🔧**
152
+
153
+
154
+ ### **How to identify where a file is used in the project**
155
+
156
+ ```
157
+ rev-dep resolve --file path/to/file.ts
158
+ ```
159
+
160
+ You’ll see all entry points that implicitly require that file, along with resolution paths.
161
+
162
+ ---
163
+
164
+ ### **How to check if a file is used**
165
+
166
+ ```
167
+ rev-dep resolve --file path/to/file.ts --compact-summary
168
+ ```
169
+
170
+ Shows how many entry points indirectly depend on the file.
171
+
172
+ ---
173
+
174
+ ### **How to identify dead files**
175
+
176
+ ```
177
+ rev-dep entry-points
178
+ ```
179
+
180
+ Exclude framework entry points if needed using `--result-exclude`.
181
+
182
+ ---
183
+
184
+ ### **How to list all files imported by an entry point**
185
+
186
+ ```
187
+ rev-dep files --entry-point path/to/file.ts
188
+ ```
189
+
190
+ Useful for identifying heavy components or unintended dependencies.
191
+
192
+ ---
193
+
194
+ ### **How to reduce unnecessary imports for an entry point**
195
+
196
+ 1. List all files imported:
197
+
198
+ ```
199
+ rev-dep files --entry-point path/to/entry.ts
200
+ ```
201
+ 2. Identify suspicious files.
202
+ 3. Trace why they are included:
203
+
204
+ ```
205
+ rev-dep resolve --file path/to/suspect --entry-points path/to/entry.ts --all
206
+ ```
207
+
208
+ ---
209
+
210
+ ### **How to detect circular dependencies**
211
+
212
+ ```
213
+ rev-dep circular
214
+ ```
215
+
216
+ ---
217
+
218
+ ### **How to find unused node modules**
219
+
220
+ ```
221
+ rev-dep node-modules unused
222
+ ```
223
+
224
+ ---
225
+
226
+ ### **How to find missing node modules**
227
+
228
+ ```
229
+ rev-dep node-modules missing
230
+ ```
231
+
232
+ ---
233
+
234
+ ### **How to check node_modules space usage**
235
+
236
+ ```
237
+ rev-dep node-modules dirs-size
238
+ ```
239
+
240
+
241
+ ## Reimplemented to achieve 7x-37x speedup
242
+
243
+ Rev-dep@2.0.0 was reimplemented in Go from scratch to leverage it's concurrency features and better memory management of compiled languages.
244
+
245
+ As a result v2 is up to 37x faster than v1 and consumes up to 13x less memory.
246
+
247
+ ### Performance comparison
248
+
249
+ To compare performance rev-dep was benchmarked with hyperfine using 8 runs per test, taking mean time values as a result.
250
+ Benchmark was run on TypeScript codebase with 507658 lines of code and 5977 source code files.
251
+
252
+ Memory usage on Mac was measure using `/usr/bin/time` utility. Memory usage on Linux was not measured because I could't find reliable way to measure RAM usage on Linux. Subsequent runs had too much fluctuation.
253
+
254
+ ### MacBook Pro with Apple M1 chip, 16GB of RAM and 256GB of storage. Power save mode off
255
+
256
+ | Command | V1 Time | V2 Time | Time Change | V1 RAM | V2 RAM | RAM Change |
257
+ | ------------------------------------------------------------ | ------- | ------- | ----------- | ------ | ------ | ---------- |
258
+ | List entry-points `rev-dep entry-points` | 6500ms | 347ms | 19x | ~680MB | ~51MB | 13x |
259
+ | List entry-points with dependent files count `-pdc` | 8333ms | 782ms | 11x | ~885MB | ~110MB | 8x |
260
+ | List entry-point files `rev-dep files` | 2729ms | 400ms | 7x | ~330MB | ~36MB | 9x |
261
+ | Resolve dependency path `rev-dep resolve` | 2984ms | 359ms | 8x | ~330MB | ~35MB | 9x |
262
+
263
+ ### WSL Linux Debian Intel(R) Core(TM) i9-14900KF CPU @ 2.80GHz
264
+
265
+ | Command | V1 Time | V2 Time | Time Change |
266
+ | ----------------------------------------------------------------------- | ------- | ------- | ----------- |
267
+ | List entry-points `rev-dep entry-points` | 9904ms | 270ms | 37x |
268
+ | List entry-points with dependent files count `--print-deps-count` | 10562ms | 458ms | 23x |
269
+ | List entry-point files `rev-dep files` | 3097ms | 230ms | 13x |
270
+ | Resolve dependency path `rev-dep resolve` | 3146ms | 230ms | 14x |
271
+
272
+ ### New features
273
+
274
+ V2 comes with bunch of new commands
275
+
276
+ - `circular` - detects circular dependencies in the project
277
+ - `lines-of-code` - counts actual lines of code in the project excluding comments and blank lines
278
+ - `list-cwd-files` - lists all files in the current working directory
279
+ - `node-modules used` - lists all used node modules
280
+ - `node-modules unused` - lists all unused node modules
281
+ - `node-modules missing` - lists all missing node modules
282
+ - `node-modules installed` - lists all installed node modules
283
+ - `node-modules installed-duplicates` - lists all installed node modules that exist in file system with the same version multiple times
284
+ - `node-modules analyze-size` - analyzes size of specific node modules and helps to identify space-hogging dependencies
285
+ - `node-modules dirs-size` - calculates cumulative files size in node_modules directories
286
+
287
+ ### ⚠️ What's not supported
288
+
289
+ Comparing to previous versions, these tsconfig features are not supported
290
+
291
+ #### Config extends
292
+
293
+ If you tsconfig uses extends, and you have some paths defined in config being extended, paths from extended config won't be used during resolution
294
+
295
+ eg.
296
+
297
+ ```json
298
+ // tsconfig.json
299
+ {
300
+ "extends": "./tsconfig.base.json",
301
+ "paths": {
302
+ "@/components": ["src/components/*"]
303
+ }
304
+ }
305
+ ```
306
+
307
+ ```json
308
+ // tsconfig.base.json
309
+ {
310
+ "paths": {
311
+ "@/utils": ["src/utils/*"]
312
+ }
313
+ }
314
+ ```
315
+
316
+ In that scenario imports with `@/utils` won't be resolved.
317
+
318
+ Why it's not supported ? I consider this typescript capability as an usage edge-case. I forgot to to implement it at the begging and I don't feel like investing more time now, before this package get some reasonable adoption and people will be actually requesting this feature.
319
+
320
+ #### Multiple path aliases
321
+
322
+ Only first path will be used in resolution.
323
+
324
+ ```json
325
+ // tsconfig.json
326
+ {
327
+ "paths": {
328
+ "@/components": ["src/components/*", "src/components2/*"]
329
+ }
330
+ }
331
+ ```
332
+
333
+ Imports that should resolve to `src/components2/*` will be considered unresolved.
334
+
335
+ Why it's not supported? I consider this typescript capability as an anti-pattern. It introduces unnecessary ambiguity in module resolution.
336
+ Implementing this would make code more complex, less maintainable and slower.
337
+
338
+ #### Using rev-dep as node module
339
+
340
+ Importing rev-dep in JS/TS is no longer supported. Preferred way is to run rev-dep using child process.
341
+
342
+ #### Other discrepancies
343
+
344
+ Any other discrepancies between TypeScript module resolution and rev-dep should be considered as a bug.
345
+
346
+ ### Supported Platforms
347
+
348
+ - Linux x64
349
+ - MacOS Apple Silicon
350
+
351
+ There are the platforms I use and know. For these I build and tested binaries.
352
+ Go allows for cross-compiling, so I'm happy to build and distribute binaries for other platforms as well, but I haven't tested it.
353
+ Feel free to open an issue if you need support for another platform.
354
+
355
+ ## CLI reference 📖
356
+
357
+ <!-- cli-docs-start -->
358
+
359
+ ### rev-dep circular
360
+
361
+ Detect circular dependencies in your project
362
+
363
+ #### Synopsis
364
+
365
+ Analyzes the project to find circular dependencies between modules.
366
+ Circular dependencies can cause hard-to-debug issues and should generally be avoided.
367
+
368
+ ```
369
+ rev-dep circular [flags]
370
+ ```
371
+
372
+ #### Examples
373
+
374
+ ```
375
+ rev-dep circular --ignore-types-imports
376
+ ```
377
+
378
+ #### Options
379
+
380
+ ```
381
+ -c, --cwd string Working directory for the command (default "$PWD")
382
+ -h, --help help for circular
383
+ -t, --ignore-type-imports Exclude type imports from the analysis
384
+ --package-json string Path to package.json (default: ./package.json)
385
+ --tsconfig-json string Path to tsconfig.json (default: ./tsconfig.json)
386
+ ```
387
+
388
+
389
+ ### rev-dep entry-points
390
+
391
+ Discover and list all entry points in the project
392
+
393
+ #### Synopsis
394
+
395
+ Analyzes the project structure to identify all potential entry points.
396
+ Useful for understanding your application's architecture and dependencies.
397
+
398
+ ```
399
+ rev-dep entry-points [flags]
400
+ ```
401
+
402
+ #### Examples
403
+
404
+ ```
405
+ rev-dep entry-points --print-deps-count
406
+ ```
407
+
408
+ #### Options
409
+
410
+ ```
411
+ -n, --count Only display the number of entry points found
412
+ -c, --cwd string Working directory for the command (default "$PWD")
413
+ --graph-exclude strings Exclude files matching these glob patterns from analysis
414
+ -h, --help help for entry-points
415
+ -t, --ignore-type-imports Exclude type imports from the analysis
416
+ --package-json string Path to package.json (default: ./package.json)
417
+ --print-deps-count Show the number of dependencies for each entry point
418
+ --result-exclude strings Exclude files matching these glob patterns from results
419
+ --result-include strings Only include files matching these glob patterns in results
420
+ --tsconfig-json string Path to tsconfig.json (default: ./tsconfig.json)
421
+ ```
422
+
423
+
424
+ ### rev-dep files
425
+
426
+ List all files in the dependency tree of an entry point
427
+
428
+ #### Synopsis
429
+
430
+ Recursively finds and lists all files that are required
431
+ by the specified entry point.
432
+
433
+ ```
434
+ rev-dep files [flags]
435
+ ```
436
+
437
+ #### Examples
438
+
439
+ ```
440
+ rev-dep files --entry-point src/index.ts
441
+ ```
442
+
443
+ #### Options
444
+
445
+ ```
446
+ -n, --count Only display the count of files in the dependency tree
447
+ -c, --cwd string Working directory for the command (default "$PWD")
448
+ -p, --entry-point string Entry point file to analyze (required)
449
+ -h, --help help for files
450
+ -t, --ignore-type-imports Exclude type imports from the analysis
451
+ --package-json string Path to package.json (default: ./package.json)
452
+ --tsconfig-json string Path to tsconfig.json (default: ./tsconfig.json)
453
+ ```
454
+
455
+
456
+ ### rev-dep lines-of-code
457
+
458
+ Count actual lines of code in the project excluding comments and blank lines
459
+
460
+ ```
461
+ rev-dep lines-of-code [flags]
462
+ ```
463
+
464
+ #### Examples
465
+
466
+ ```
467
+ rev-dep lines-of-code
468
+ ```
469
+
470
+ #### Options
471
+
472
+ ```
473
+ -c, --cwd string Directory to analyze (default "$PWD")
474
+ -h, --help help for lines-of-code
475
+ ```
476
+
477
+
478
+ ### rev-dep list-cwd-files
479
+
480
+ List all files in the current working directory
481
+
482
+ #### Synopsis
483
+
484
+ Recursively lists all files in the specified directory,
485
+ with options to filter results.
486
+
487
+ ```
488
+ rev-dep list-cwd-files [flags]
489
+ ```
490
+
491
+ #### Examples
492
+
493
+ ```
494
+ rev-dep list-cwd-files --include='*.ts' --exclude='*.test.ts'
495
+ ```
496
+
497
+ #### Options
498
+
499
+ ```
500
+ --count Only display the count of matching files
501
+ --cwd string Directory to list files from (default "$PWD")
502
+ --exclude strings Exclude files matching these glob patterns
503
+ -h, --help help for list-cwd-files
504
+ --include strings Only include files matching these glob patterns
505
+ ```
506
+
507
+
508
+ ### rev-dep node-modules
509
+
510
+ Analyze and manage Node.js dependencies
511
+
512
+ #### Synopsis
513
+
514
+ Tools for analyzing and managing Node.js module dependencies.
515
+ Helps identify unused, missing, or duplicate dependencies in your project.
516
+
517
+ #### Examples
518
+
519
+ ```
520
+ rev-dep node-modules used -p src/index.ts
521
+ rev-dep node-modules unused --exclude-modules=@types/*
522
+ rev-dep node-modules missing --entry-points=src/main.ts
523
+ ```
524
+
525
+ #### Options
526
+
527
+ ```
528
+ -h, --help help for node-modules
529
+ ```
530
+
531
+
532
+ ### rev-dep node-modules dirs-size
533
+
534
+ Calculates cumulative files size in node_modules directories
535
+
536
+ #### Synopsis
537
+
538
+ Calculates and displays the size of node_modules folders
539
+ in the current directory and subdirectories. Sizes will be smaller than actual file size taken on disk. Tool is calculating actual file size rather than file size on disk (related to disk blocks usage)
540
+
541
+ ```
542
+ rev-dep node-modules dirs-size [flags]
543
+ ```
544
+
545
+ #### Examples
546
+
547
+ ```
548
+ rev-dep node-modules dirs-size
549
+ ```
550
+
551
+ #### Options
552
+
553
+ ```
554
+ -c, --cwd string Working directory for the command (default "$PWD")
555
+ -h, --help help for dirs-size
556
+ ```
557
+
558
+
559
+ ### rev-dep node-modules installed-duplicates
560
+
561
+ Find and optimize duplicate package installations
562
+
563
+ #### Synopsis
564
+
565
+ Identifies packages that are installed multiple times in node_modules.
566
+ Can optimize storage by creating symlinks between duplicate packages.
567
+
568
+ ```
569
+ rev-dep node-modules installed-duplicates [flags]
570
+ ```
571
+
572
+ #### Examples
573
+
574
+ ```
575
+ rev-dep node-modules installed-duplicates --optimize --size-stats
576
+ ```
577
+
578
+ #### Options
579
+
580
+ ```
581
+ -c, --cwd string Working directory for the command (default "$PWD")
582
+ -h, --help help for installed-duplicates
583
+ --isolate Create symlinks only within the same top-level node_module directories. By default optimize creates symlinks between top-level node_module directories (eg. when workspaces are used). Needs --optimize flag to take effect
584
+ --optimize Automatically create symlinks to deduplicate packages
585
+ --size-stats Print node modules dirs size before and after optimization. Might take longer than optimization itself
586
+ --verbose Show detailed information about each optimization
587
+ ```
588
+
589
+
590
+ ### rev-dep node-modules installed
591
+
592
+ List all installed npm packages in the project
593
+
594
+ #### Synopsis
595
+
596
+ Recursively scans node_modules directories to list all installed packages.
597
+ Helpful for auditing dependencies across monorepos.
598
+
599
+ ```
600
+ rev-dep node-modules installed [flags]
601
+ ```
602
+
603
+ #### Examples
604
+
605
+ ```
606
+ rev-dep node-modules installed --include-modules=@myorg/*
607
+ ```
608
+
609
+ #### Options
610
+
611
+ ```
612
+ -c, --cwd string Working directory for the command (default "$PWD")
613
+ -e, --exclude-modules strings list of modules to exclude from the output
614
+ -h, --help help for installed
615
+ -i, --include-modules strings list of modules to include in the output
616
+ ```
617
+
618
+
619
+ ### rev-dep node-modules missing
620
+
621
+ Find imported packages not listed in package.json
622
+
623
+ #### Synopsis
624
+
625
+ Identifies packages that are imported in your code but not declared
626
+ in your package.json dependencies.
627
+
628
+ ```
629
+ rev-dep node-modules missing [flags]
630
+ ```
631
+
632
+ #### Examples
633
+
634
+ ```
635
+ rev-dep node-modules missing --entry-points=src/main.ts
636
+ ```
637
+
638
+ #### Options
639
+
640
+ ```
641
+ -n, --count Only display the count of modules
642
+ -c, --cwd string Working directory for the command (default "$PWD")
643
+ -p, --entry-points strings Entry point file(s) to start analysis from (default: auto-detected)
644
+ -e, --exclude-modules strings list of modules to exclude from the output
645
+ -b, --files-with-binaries strings Additional files to search for binary usages. Use paths relative to cwd
646
+ -m, --files-with-node-modules strings Additional files to search for module imports. Use paths relative to cwd
647
+ --group-by-file Organize output by project file path
648
+ --group-by-module Organize output by npm package name
649
+ -h, --help help for missing
650
+ -t, --ignore-type-imports Exclude type imports from the analysis
651
+ -i, --include-modules strings list of modules to include in the output
652
+ --package-json string Path to package.json (default: ./package.json)
653
+ --pkg-fields-with-binaries strings Additional package.json fields to check for binary usages
654
+ --tsconfig-json string Path to tsconfig.json (default: ./tsconfig.json)
655
+ --zero-exit-code Use this flag to always return zero exit code
656
+ ```
657
+
658
+
659
+ ### rev-dep node-modules unused
660
+
661
+ Find installed packages that aren't imported in your code
662
+
663
+ #### Synopsis
664
+
665
+ Compares package.json dependencies with actual imports in your codebase
666
+ to identify potentially unused packages.
667
+
668
+ ```
669
+ rev-dep node-modules unused [flags]
670
+ ```
671
+
672
+ #### Examples
673
+
674
+ ```
675
+ rev-dep node-modules unused --exclude-modules=@types/*
676
+ ```
677
+
678
+ #### Options
679
+
680
+ ```
681
+ -n, --count Only display the count of modules
682
+ -c, --cwd string Working directory for the command (default "$PWD")
683
+ -p, --entry-points strings Entry point file(s) to start analysis from (default: auto-detected)
684
+ -e, --exclude-modules strings list of modules to exclude from the output
685
+ -b, --files-with-binaries strings Additional files to search for binary usages. Use paths relative to cwd
686
+ -m, --files-with-node-modules strings Additional files to search for module imports. Use paths relative to cwd
687
+ -h, --help help for unused
688
+ -t, --ignore-type-imports Exclude type imports from the analysis
689
+ -i, --include-modules strings list of modules to include in the output
690
+ --package-json string Path to package.json (default: ./package.json)
691
+ --pkg-fields-with-binaries strings Additional package.json fields to check for binary usages
692
+ --tsconfig-json string Path to tsconfig.json (default: ./tsconfig.json)
693
+ --zero-exit-code Use this flag to always return zero exit code
694
+ ```
695
+
696
+
697
+ ### rev-dep node-modules used
698
+
699
+ List all npm packages imported in your code
700
+
701
+ #### Synopsis
702
+
703
+ Analyzes your code to identify which npm packages are actually being used.
704
+ Helps keep track of your project's runtime dependencies.
705
+
706
+ ```
707
+ rev-dep node-modules used [flags]
708
+ ```
709
+
710
+ #### Examples
711
+
712
+ ```
713
+ rev-dep node-modules used -p src/index.ts --group-by-module
714
+ ```
715
+
716
+ #### Options
717
+
718
+ ```
719
+ -n, --count Only display the count of modules
720
+ -c, --cwd string Working directory for the command (default "$PWD")
721
+ -p, --entry-points strings Entry point file(s) to start analysis from (default: auto-detected)
722
+ -e, --exclude-modules strings list of modules to exclude from the output
723
+ -b, --files-with-binaries strings Additional files to search for binary usages. Use paths relative to cwd
724
+ -m, --files-with-node-modules strings Additional files to search for module imports. Use paths relative to cwd
725
+ --group-by-file Organize output by project file path
726
+ --group-by-module Organize output by npm package name
727
+ -h, --help help for used
728
+ -t, --ignore-type-imports Exclude type imports from the analysis
729
+ -i, --include-modules strings list of modules to include in the output
730
+ --package-json string Path to package.json (default: ./package.json)
731
+ --pkg-fields-with-binaries strings Additional package.json fields to check for binary usages
732
+ --tsconfig-json string Path to tsconfig.json (default: ./tsconfig.json)
733
+ ```
734
+
735
+
736
+ ### rev-dep resolve
737
+
738
+ Trace and display the dependency path between files in your project
739
+
740
+ #### Synopsis
741
+
742
+ Analyze and display the dependency chain between specified files.
743
+ Helps understand how different parts of your codebase are connected.
744
+
745
+ ```
746
+ rev-dep resolve [flags]
747
+ ```
748
+
749
+ #### Examples
750
+
751
+ ```
752
+ rev-dep resolve -p src/index.ts -f src/utils/helpers.ts
753
+ ```
754
+
755
+ #### Options
756
+
757
+ ```
758
+ -a, --all Show all possible resolution paths, not just the first one
759
+ --compact-summary Display a compact summary of found paths
760
+ -c, --cwd string Working directory for the command (default "$PWD")
761
+ -p, --entry-points strings Entry point file(s) to start analysis from (default: auto-detected)
762
+ -f, --file string Target file to check for dependencies
763
+ --graph-exclude strings Glob patterns to exclude files from dependency analysis
764
+ -h, --help help for resolve
765
+ -t, --ignore-type-imports Exclude type imports from the analysis
766
+ --package-json string Path to package.json (default: ./package.json)
767
+ --tsconfig-json string Path to tsconfig.json (default: ./tsconfig.json)
768
+ ```
769
+
770
+
771
+
772
+ <!-- cli-docs-end -->
773
+
774
+ ## Circular check performance comparison
775
+
776
+ Benchmark performed on TypeScript codebase with `6034` source code files and `518862` lines of code.
777
+
778
+ Benchmark performed on MacBook Pro with Apple M1 chip, 16GB of RAM and 256GB of Storage. Power save mode off.
779
+
780
+ Benchmark performed with `hyperfine` using 8 runs per test and 4 warm up runs, taking mean time values as a result. If single run was taking more than 10s, only 1 run was performed.
781
+
782
+ `rev-dep` circular check is **12 times** faster than the fastest alternative❗
783
+
784
+ | Tool | Version | Command to Run Circular Check | Time |
785
+ |------|---------|-------------------------------|------|
786
+ | 🥇 [rev-dep](https://github.com/jayu/rev-dep) | 2.0.0 | `rev-dep circular` | 397 ms |
787
+ | 🥈 [dpdm-fast](https://github.com/SunSince90/dpdm-fast) | 1.0.14 | `dpdm --no-tree --no-progress --no-warning` + list of directories with source code | 4960 ms |
788
+ | 🥉 [dpdm](https://github.com/acrazing/dpdm) | 3.14.0 | `dpdm --no-warning` + list of directories with source code | 5030 ms |
789
+ | [skott](https://github.com/antoine-coulon/skott) | 0.35.6 | node skoscript using `findCircularDependencies` function | 29575 ms |
790
+ | [madge](https://github.com/pahen/madge) | 8.0.0 | `madge --circular --extensions js,ts,jsx,tsx .` | 69328 ms |
791
+ | [circular-dependency-scanner](https://github.com/emosheeep/circular-dependency-scanner) | 2.3.0 | `ds` - out of memory error | n/a |
792
+
793
+ ## Glossary
794
+
795
+ Some of the terms used in the problem space that **rev-dep** covers can be confusing.
796
+ Here is a small glossary to help you navigate the concepts.
797
+
798
+ ### Dependency
799
+
800
+ A *dependency* can be understood literally. In the context of a project’s dependency graph, it may refer to:
801
+
802
+ * a **node module / package** (a package is a dependency of a project or file), or
803
+ * a **source code file** (a file is a dependency of another file if it imports it).
804
+
805
+ ### Entry point
806
+
807
+ An *entry point* is a source file that is **not imported by any other file**.
808
+ It can represent:
809
+
810
+ * the main entry of the application
811
+ * an individual page or feature
812
+ * configuration or test bootstrap files
813
+
814
+ — depending on the project structure.
815
+
816
+ ### Unused / Dead file
817
+
818
+ A file is considered *unused* or *dead* when:
819
+
820
+ * it is an **entry point** (nothing imports it), **and**
821
+ * running it does **not produce any meaningful output** or side effect.
822
+
823
+ In practice, such files can often be removed safely.
824
+
825
+ ### Circular dependency
826
+
827
+ A *circular dependency* occurs when a file **directly or indirectly imports itself** through a chain of imports.
828
+
829
+ This can lead to unpredictable runtime behavior, uninitialized values, or subtle bugs.
830
+ However, circular dependencies between **TypeScript type-only imports** are usually harmless.
831
+
832
+ ### Reverse dependency (or "dependents")
833
+
834
+ Files that *import* a given file.
835
+ Useful for answering: "What breaks if I change or delete this file?"
836
+
837
+ ### Import graph / Dependency graph
838
+
839
+ A visual representation of how files or modules import each other.
840
+
841
+ ### Missing dependency / unused node module
842
+
843
+ A module that your code imports but is **not listed in package.json**.
844
+
845
+ ### Unused dependency / unused node module
846
+
847
+ A dependency listed in **package.json** that is **never imported** in the source code.
848
+
849
+ ### Root directory / Project root
850
+
851
+ The top-level directory used as the starting point for dependency analysis.
852
+
853
+ ## Made in 🇵🇱 and 🇯🇵 with 🧠 by [@jayu](https://github.com/jayu)
854
+
855
+ 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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "rev-dep",
3
- "version": "2.0.0-alpha-8",
4
- "description": "Dependency debugging tool for JavaScript and TypeScript projects",
3
+ "version": "2.1.0",
4
+ "description": "Trace imports, detect unused code, clean dependencies — all with a super-fast CLI",
5
5
  "bin": "bin.js",
6
6
  "files": [
7
7
  "bin.js"
@@ -17,28 +17,30 @@
17
17
  "node": ">=18"
18
18
  },
19
19
  "optionalDependencies": {
20
- "@rev-dep/darwin-arm64": "2.0.0-alpha-8",
21
- "@rev-dep/linux-x64": "2.0.0-alpha-8"
20
+ "@rev-dep/darwin-arm64": "2.1.0",
21
+ "@rev-dep/linux-x64": "2.1.0"
22
22
  },
23
23
  "keywords": [
24
- "dependencies",
25
- "deps",
26
- "dependency graph",
27
- "dependency debugging",
28
- "entry points",
29
- "dependency resolution",
30
- "reverse dependency resolution",
31
- "import path",
32
- "resolution path",
33
- "dependency optimization",
34
- "dependency analysis",
35
- "bundle",
36
- "dependency tree",
37
- "imports",
38
- "dependencies checking",
39
- "imports debugging",
40
- "imports analysis",
41
- "imports search",
42
- "file dependencies"
24
+ "dependency-analysis",
25
+ "reverse-dependencies",
26
+ "dependency-resolution",
27
+ "file-dependencies",
28
+ "unused-files",
29
+ "dead-files",
30
+ "unused-dependencies",
31
+ "missing-dependencies",
32
+ "used-dependencies",
33
+ "module-analysis",
34
+ "import-analysis",
35
+ "entry-point-analysis",
36
+ "dependency-path",
37
+ "circular-dependency-detection",
38
+ "node-modules-analysis",
39
+ "module-size-analysis",
40
+ "lines-of-code",
41
+ "project-audit",
42
+ "typescript-analysis",
43
+ "javascript-analysis",
44
+ "monorepo-analysis"
43
45
  ]
44
46
  }