rev-dep 2.7.2 → 2.9.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 +88 -14
  2. package/package.json +4 -4
package/Readme.md CHANGED
@@ -1,3 +1,5 @@
1
+ # Rev-dep
2
+
1
3
  <p align="center">
2
4
  <img src="https://github.com/jayu/rev-dep/raw/master/logo.png" width="400" alt="Rev-dep logo">
3
5
  </p>
@@ -12,11 +14,11 @@
12
14
  <p align="center">
13
15
  Dependency analysis and optimization toolkit for modern JavaScript and TypeScript codebases.
14
16
  <br>
15
- Enforce dependency graph hygiene and remove unused bits with a very fast CLI.
17
+ Enforce dependency graph hygiene and remove unused code with a very fast CLI.
16
18
  </p>
17
19
 
18
20
  <p align="center">
19
- <img src="https://github.com/jayu/rev-dep/raw/master/demo.png" alt="Rev-dep config execution CLI output"width="400">
21
+ <img src="https://github.com/jayu/rev-dep/raw/master/demo.png" alt="Rev-dep config execution CLI output" width="400">
20
22
  </p>
21
23
 
22
24
  ---
@@ -25,7 +27,7 @@
25
27
 
26
28
  ## **About 📣**
27
29
 
28
- As codebases scale, maintaining a mental map of dependencies becomes impossible. **Rev-dep** is a high-speed governance engine designed to enforce architecture integrity and dependency hygiene across large-scale JS/TS projects.
30
+ As codebases scale, maintaining a mental map of dependencies becomes impossible. **Rev-dep** is a high-speed static analysis tool designed to enforce architecture integrity and dependency hygiene across large-scale JS/TS projects.
29
31
 
30
32
  <p align="center"><b>Think of Rev-dep as a high-speed linter for your dependency graph.</b></p>
31
33
 
@@ -61,7 +63,7 @@ Implemented in **Go** to eliminate the performance tax of Node-based analysis. B
61
63
 
62
64
  ## Capabilities 🚀
63
65
 
64
- ## Governance and maintenance (config-based) 🛡️
66
+ ### Governance and maintenance (config-based) 🛡️
65
67
 
66
68
  Use `rev-dep config run` to execute multiple checks in one pass for all packages.
67
69
 
@@ -75,8 +77,10 @@ Available checks:
75
77
  - `missingNodeModulesDetection` - detect imports missing from package json.
76
78
  - `unresolvedImportsDetection` - detect unresolved import requests.
77
79
  - `circularImportsDetection` - detect circular imports.
80
+ - `devDepsUsageOnProdDetection` - detect dev dependencies used in production code.
81
+ - `restrictedImportsDetection` - block importing denied files/modules from selected entry points.
78
82
 
79
- ## Exploratory analysis (CLI-based) 🔍
83
+ ### Exploratory analysis (CLI-based) 🔍
80
84
 
81
85
  Use CLI commands for ad-hoc dependency exploration:
82
86
 
@@ -164,6 +168,8 @@ Available checks are:
164
168
  - `missingNodeModulesDetection` - detect imports missing from package json.
165
169
  - `unresolvedImportsDetection` - detect unresolved import requests.
166
170
  - `circularImportsDetection` - detect circular imports.
171
+ - `devDepsUsageOnProdDetection` - detect dev dependencies used in production code.
172
+ - `restrictedImportsDetection` - block importing denied files/modules from selected entry points.
167
173
 
168
174
  Checks are grouped in rules. You can have multiple rules, eg. for each monorepo package.
169
175
 
@@ -209,8 +215,8 @@ The configuration file (`rev-dep.config.json(c)` or `.rev-dep.config.json(c)`) a
209
215
 
210
216
  ```jsonc
211
217
  {
212
- "configVersion": "1.3",
213
- "$schema": "https://github.com/jayu/rev-dep/blob/master/config-schema/1.3.schema.json?raw=true",
218
+ "configVersion": "1.5",
219
+ "$schema": "https://github.com/jayu/rev-dep/blob/master/config-schema/1.5.schema.json?raw=true",
214
220
  "rules": [
215
221
  {
216
222
  "path": ".",
@@ -230,6 +236,11 @@ The configuration file (`rev-dep.config.json(c)` or `.rev-dep.config.json(c)`) a
230
236
  "circularImportsDetection": {
231
237
  "enabled": true
232
238
  },
239
+ "devDepsUsageOnProdDetection": {
240
+ "enabled": true,
241
+ "prodEntryPoints": ["src/main.tsx", "src/pages/**/*.tsx"],
242
+ "ignoreTypeImports": true
243
+ }
233
244
  }
234
245
  ]
235
246
  }
@@ -241,8 +252,8 @@ Here's a comprehensive example showing all available properties:
241
252
 
242
253
  ```jsonc
243
254
  {
244
- "configVersion": "1.3",
245
- "$schema": "https://github.com/jayu/rev-dep/blob/master/config-schema/1.3.schema.json?raw=true", // enables json autocompletion
255
+ "configVersion": "1.5",
256
+ "$schema": "https://github.com/jayu/rev-dep/blob/master/config-schema/1.5.schema.json?raw=true", // enables json autocompletion
246
257
  "conditionNames": ["import", "default"],
247
258
  "ignoreFiles": ["**/*.test.*"],
248
259
  "rules": [
@@ -321,6 +332,19 @@ Here's a comprehensive example showing all available properties:
321
332
  },
322
333
  "ignoreFiles": ["**/*.generated.ts"],
323
334
  "ignoreImports": ["@internal/dev-only"]
335
+ },
336
+ "devDepsUsageOnProdDetection": {
337
+ "enabled": true,
338
+ "prodEntryPoints": ["src/main.tsx", "src/pages/**/*.tsx", "src/server.ts"],
339
+ "ignoreTypeImports": true
340
+ },
341
+ "restrictedImportsDetection": {
342
+ "enabled": true,
343
+ "entryPoints": ["src/server.ts", "src/server/**/*.ts"],
344
+ "denyFiles": ["**/*.tsx"],
345
+ "denyModules": ["react", "react-*"],
346
+ "ignoreMatches": ["src/server/allowed-view.tsx", "react-awsome-lib"],
347
+ "ignoreTypeImports": true
324
348
  }
325
349
  }
326
350
  ]
@@ -348,6 +372,8 @@ Each rule can contain the following properties:
348
372
  - **`missingNodeModulesDetection`** (optional): Missing node modules detection configuration
349
373
  - **`unusedExportsDetection`** (optional): Unused exports detection configuration
350
374
  - **`unresolvedImportsDetection`** (optional): Unresolved imports detection configuration
375
+ - **`devDepsUsageOnProdDetection`** (optional): Restricted dev dependencies usage detection configuration
376
+ - **`restrictedImportsDetection`** (optional): Restrict importing denied files/modules from selected entry points
351
377
  - **`importConventions`** (optional): Array of import convention rules
352
378
 
353
379
  #### Module Boundary Properties
@@ -404,6 +430,19 @@ Each rule can contain the following properties:
404
430
  - **`ignoreFiles`** (optional): File path globs; all unresolved imports from matching files are suppressed
405
431
  - **`ignoreImports`** (optional): Import requests to suppress globally in unresolved results
406
432
 
433
+ **DevDepsUsageOnProd:**
434
+ - **`enabled`** (required): Enable/disable restricted dev dependencies usage detection
435
+ - **`prodEntryPoints`** (optional): Production entry point patterns to trace dependencies from (eg. ["src/pages/**/*.tsx", "src/main.tsx"])
436
+ - **`ignoreTypeImports`** (optional): Exclude type-only imports from graph traversal and module matching (default: false)
437
+
438
+ **RestrictedImportsDetection:**
439
+ - **`enabled`** (required): Enable/disable restricted imports detection
440
+ - **`entryPoints`** (required when enabled): Entry point patterns used to build reachable dependency graph
441
+ - **`denyFiles`** (optional): Denied file path patterns (eg. ["**/*.tsx"])
442
+ - **`denyModules`** (optional): Denied module patterns (eg. ["react", "react-*"])
443
+ - **`ignoreMatches`** (optional): File/module patterns to suppress from restricted import results
444
+ - **`ignoreTypeImports`** (optional): Exclude type-only imports from traversal (default: false)
445
+
407
446
  ### Performance Benefits
408
447
 
409
448
  The configuration approach provides significant performance advantages:
@@ -583,9 +622,10 @@ Here is a performance comparison of specific tasks between rev-dep and alternati
583
622
  | Task | Execution Time [ms] | Alternative | Alternative Time [ms] | Slower Than Rev-dep |
584
623
  |------|-------|--------------|------|----|
585
624
  | Find circular dependencies | 289 | dpdm-fast | 7061| 24x|
586
- | Find unused files | 588 | knip | 6346 | 11x |
587
- | Find unused node modules | 594 | knip | 6230 | 10x |
588
- | Find missing node modules | 553 | knip| 6226 | 11x |
625
+ | Find unused exports | 303 | knip| 6606 | 22x |
626
+ | Find unused files | 277 | knip | 6596 | 23x |
627
+ | Find unused node modules | 287 | knip | 6572 | 22x |
628
+ | Find missing node modules | 270 | knip| 6568 | 24x |
589
629
  | List all files imported by an entry point | 229 | madge | 4467 | 20x |
590
630
  | Discover entry points | 323 | madge | 67000 | 207x
591
631
  | Resolve dependency path between files | 228 | please suggest |
@@ -616,6 +656,35 @@ Benchmark performed with `hyperfine` using 8 runs per test and 4 warm up runs, t
616
656
 
617
657
 
618
658
 
659
+ ### **How to detect dev dependencies used in production code**
660
+
661
+ ```
662
+ rev-dep config run
663
+ ```
664
+
665
+ When `devDepsUsageOnProdDetection` is enabled in your config, rev-dep will:
666
+
667
+ 1. Trace dependency graphs from your specified production entry points
668
+ 2. Identify all files reachable from those entry points
669
+ 3. Check if any imported modules are listed in `devDependencies` in package.json
670
+ 4. Report violations showing which dev dependencies are used where
671
+
672
+ **Example Output:**
673
+ ```
674
+ ❌ Restricted Dev Dependencies Usage Issues (2):
675
+ lodash (dev dependency)
676
+ - src/components/Button.tsx (from entry point: src/pages/index.tsx)
677
+ - src/utils/helpers.ts (from entry point: src/pages/index.tsx)
678
+ eslint (dev dependency)
679
+ - src/config/eslint-config.js (from entry point: src/server.ts)
680
+ ```
681
+
682
+ **Important Notes:**
683
+ - Type-only imports (e.g., `import type { ReactNode } from 'react'`) are ignored when `ignoreTypeImports` is enabled
684
+ - Only dependencies from `devDependencies` in package.json are flagged
685
+ - Production dependencies from `dependencies` are allowed
686
+ - Helps prevent runtime failures in production builds
687
+
619
688
  ## CLI reference 📖
620
689
 
621
690
  <!-- cli-docs-start -->
@@ -675,7 +744,7 @@ Execute all checks defined in (.)rev-dep.config.json(c)
675
744
 
676
745
  #### Synopsis
677
746
 
678
- Process (.)rev-dep.config.json(c) and execute all enabled checks (circular imports, orphan files, module boundaries, node modules) per rule.
747
+ Process (.)rev-dep.config.json(c) and execute all enabled checks (circular imports, orphan files, module boundaries, import conventions, node modules, unused exports, unresolved imports, restricted imports and restricted dev deps usage) per rule.
679
748
 
680
749
  ```
681
750
  rev-dep config run [flags]
@@ -1103,9 +1172,13 @@ rev-dep node-modules used -p src/index.ts --group-by-module
1103
1172
  -b, --files-with-binaries strings Additional files to search for binary usages. Use paths relative to cwd
1104
1173
  -m, --files-with-node-modules strings Additional files to search for module imports. Use paths relative to cwd
1105
1174
  --follow-monorepo-packages strings Enable resolution of imports from monorepo workspace packages. Pass without value to follow all, or pass package names
1175
+ --group-by-entry-point Organize output by entry point file path
1176
+ --group-by-entry-point-modules-count Organize output by entry point and show count of unique modules
1106
1177
  --group-by-file Organize output by project file path
1107
1178
  --group-by-module Organize output by npm package name
1179
+ --group-by-module-entry-points-count Organize output by npm package name and show count of entry points using it
1108
1180
  --group-by-module-files-count Organize output by npm package name and show count of files using it
1181
+ --group-by-module-show-entry-points Organize output by npm package name and list entry points using it
1109
1182
  -h, --help help for used
1110
1183
  -t, --ignore-type-imports Exclude type imports from the analysis
1111
1184
  -i, --include-modules strings list of modules to include in the output
@@ -1142,12 +1215,13 @@ rev-dep resolve -p src/index.ts -f src/utils/helpers.ts
1142
1215
  --compact-summary Display a compact summary of found paths
1143
1216
  --condition-names strings List of conditions for package.json imports resolution (e.g. node, imports, default)
1144
1217
  -c, --cwd string Working directory for the command (default "$PWD")
1145
- -p, --entry-points strings Entry point file(s) to start analysis from (default: auto-detected)
1218
+ -p, --entry-points strings Entry point file(s) or glob pattern(s) to start analysis from (default: auto-detected)
1146
1219
  -f, --file string Target file to check for dependencies
1147
1220
  --follow-monorepo-packages strings Enable resolution of imports from monorepo workspace packages. Pass without value to follow all, or pass package names
1148
1221
  --graph-exclude strings Glob patterns to exclude files from dependency analysis
1149
1222
  -h, --help help for resolve
1150
1223
  -t, --ignore-type-imports Exclude type imports from the analysis
1224
+ --module string Target node module name to check for dependencies
1151
1225
  --package-json string Path to package.json (default: ./package.json)
1152
1226
  --tsconfig-json string Path to tsconfig.json (default: ./tsconfig.json)
1153
1227
  -v, --verbose Show warnings and verbose output
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rev-dep",
3
- "version": "2.7.2",
3
+ "version": "2.9.0",
4
4
  "description": "Trace imports, detect unused code, clean dependencies — all with a super-fast CLI",
5
5
  "bin": "bin.js",
6
6
  "files": [
@@ -17,9 +17,9 @@
17
17
  "node": ">=18"
18
18
  },
19
19
  "optionalDependencies": {
20
- "@rev-dep/darwin-arm64": "2.7.2",
21
- "@rev-dep/linux-x64": "2.7.2",
22
- "@rev-dep/win32-x64": "2.7.2"
20
+ "@rev-dep/darwin-arm64": "2.9.0",
21
+ "@rev-dep/linux-x64": "2.9.0",
22
+ "@rev-dep/win32-x64": "2.9.0"
23
23
  },
24
24
  "keywords": [
25
25
  "dependency-analysis",