rev-dep 2.4.0-beta.2 → 2.5.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 (3) hide show
  1. package/LICENSE +21 -0
  2. package/Readme.md +365 -2
  3. package/package.json +4 -4
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Jakub Mazurek
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/Readme.md CHANGED
@@ -49,7 +49,7 @@ Built in Go for speed. Even on large codebases, rev-dep responds almost instantl
49
49
 
50
50
  You get **exact file paths**, **import chains**, and **clear dependency relationships** — the kind of information you can fix or clean up right away.
51
51
 
52
- ### ✅ **Designed for real-world JS/TS**
52
+ ### ✅ **Designed for real-world JS/TS with first class monorepo support**
53
53
 
54
54
  Works with mixed JS/TS projects, path aliases and thousands of files without configuration hassles.
55
55
 
@@ -91,7 +91,8 @@ For large project with 500k+ lines of code and 6k+ source code files get checks
91
91
  * 📏 **Count actual lines of code (excluding comments and blanks)**
92
92
  * 💽 **Node modules disk usage & size analysis**
93
93
  * 💡 **Works with both JavaScript and TypeScript**
94
- * ⚡ **Built for large codebases**
94
+ * ⚡ **Built for large codebases and monorepos**
95
+ * 🏗️ **Supports TypeScript path aliases and package.json imports and exports map**
95
96
 
96
97
  # **Installation 📦**
97
98
 
@@ -216,6 +217,271 @@ rev-dep node-modules missing
216
217
  rev-dep node-modules dirs-size
217
218
  ```
218
219
 
220
+ ## Working with Monorepo
221
+
222
+ Rev-dep provides first-class support for monorepo projects, enabling accurate dependency analysis across workspace packages.
223
+
224
+ ### followMonorepoPackages Flag
225
+
226
+ The `--follow-monorepo-packages` flag enables resolution of imports from monorepo workspace packages. By default, this flag is set to `false` to maintain compatibility with single-package projects.
227
+
228
+ ```bash
229
+ # Enable monorepo package resolution
230
+ rev-dep circular --follow-monorepo-packages
231
+ rev-dep resolve --file src/utils.ts --follow-monorepo-packages
232
+ rev-dep entry-points --follow-monorepo-packages
233
+ ```
234
+
235
+ When enabled, rev-dep will:
236
+
237
+ - **Detect workspace packages** automatically by scanning for monorepo configuration
238
+ - **Resolve imports between packages** within the workspace
239
+ - **Follow package.json exports** for proper module resolution
240
+
241
+ ### Exports Map Support
242
+
243
+ Rev-dep fully supports the `exports` field in package.json files, which is the standard way to define package entry points in modern Node.js projects.
244
+
245
+ The exports map support includes:
246
+
247
+ - **Conditional exports** using conditions like `node`, `import`, `default`, and custom conditions
248
+ - **Wildcard patterns** for flexible subpath mapping
249
+ - **Sugar syntax** for simple main export definitions
250
+ - **Nested conditions** for complex resolution scenarios
251
+
252
+ ### Condition Names Flag
253
+
254
+ To control which conditional exports are resolved, use the `--condition-names` flag. This allows you to specify the priority of conditions when resolving package exports:
255
+
256
+ ```bash
257
+ # Resolve exports for different environments
258
+ rev-dep circular --condition-names=node,import,default
259
+ rev-dep resolve --file src/utils.ts --condition-names=import,node
260
+ rev-dep entry-points --condition-names=default,node,import
261
+ ```
262
+
263
+ The conditions are processed in the order specified, with the first matching condition being used. Common conditions include:
264
+ - `node` - Node.js environment
265
+ - `import` - ES modules
266
+ - `require` - CommonJS
267
+ - `default` - Fallback condition
268
+ - Custom conditions specific to your project or build tools
269
+
270
+ Example package.json with exports:
271
+
272
+ ```json
273
+ {
274
+ "name": "@myorg/utils",
275
+ "exports": {
276
+ ".": {
277
+ "import": "./dist/index.mjs",
278
+ "require": "./dist/index.js",
279
+ "default": "./dist/index.js"
280
+ },
281
+ "./helpers": "./dist/helpers.js",
282
+ "./types/*": "./dist/types/*.d.ts"
283
+ }
284
+ }
285
+ ```
286
+
287
+ ### How It Works
288
+
289
+ 1. **Monorepo Detection**: When `followMonorepoPackages` is enabled, rev-dep scans for workspace configuration (pnpm-workspace.yaml, package.json workspaces, etc.)
290
+
291
+ 2. **Package Resolution**: Imports to workspace packages are resolved using the package's exports configuration, falling back to main/module fields when exports are not defined
292
+
293
+ 3. **Dependency Validation**: The tool validates that cross-package imports are only allowed when the target package is listed in the consumer's dependencies or devDependencies
294
+
295
+ 4. **Path Resolution**: All paths are resolved relative to their respective package roots, ensuring accurate dependency tracking across the entire monorepo
296
+
297
+ This makes rev-dep particularly effective for large-scale monorepo projects where understanding cross-package dependencies is crucial for maintaining code quality and architecture.
298
+
299
+ ## Config-Based Checks
300
+
301
+ Rev-dep provides a configuration system for orchestrating project checks. The config approach is **designed for speed** and is the **preferred way** of implementing project checks because it can execute all checks in a single pass, significantly faster than multiple running individual commands separately.
302
+
303
+ Available checks are:
304
+
305
+ - **module boundaries** - check if imports respect module boundaries
306
+ - **import conventions** - enforce syntactic consistency for imports
307
+ - **circular imports** - check if there are circular imports
308
+ - **orphan files** - check if there are orphan/dead files
309
+ - **unused node modules** - check against unused node modules
310
+ - **missing node modules** - check against missing node modules
311
+
312
+ Checks are grouped in rules. You can have multiple rules, eg. for each monorepo package.
313
+
314
+ ### Getting Started
315
+
316
+ Initialize a configuration file in your project:
317
+
318
+ ```bash
319
+ # Create a default configuration file
320
+ rev-dep config init
321
+ ```
322
+
323
+ Behavior of `rev-dep config init`:
324
+
325
+ - Monorepo root: Running `rev-dep config init` at the workspace root creates a root rule and a rule for each discovered workspace package.
326
+ - Monorepo workspace package or regular projects: Running `rev-dep config init` inside a directory creates config with a single rule with `path: "."` for this directory.
327
+
328
+ Run all configured checks:
329
+
330
+ ```bash
331
+ # Execute all rules and checks defined in the config
332
+ rev-dep config run
333
+ ```
334
+
335
+ ### Configuration Structure
336
+
337
+ The configuration file (`rev-dep.config.json(c)` or `.rev-dep.config.json(c)`) allows you to define multiple rules, each targeting different parts of your codebase with specific checks enabled.
338
+
339
+ Here's a comprehensive example showing all available properties:
340
+
341
+ ```jsonc
342
+ {
343
+ "configVersion": "1.1",
344
+ "$schema": "https://github.com/jayu/rev-dep/blob/master/config-schema/1.1.schema.json?raw=true", // enables json autocompletion
345
+ "conditionNames": ["import", "default"],
346
+ "ignoreFiles": ["**/*.test.*"],
347
+ "rules": [
348
+ {
349
+ "path": ".",
350
+ "followMonorepoPackages": true,
351
+ "moduleBoundaries": [
352
+ {
353
+ "name": "ui-components",
354
+ "pattern": "src/components/**/*",
355
+ "allow": ["src/utils/**/*", "src/types/**/*"],
356
+ "deny": ["src/api/**/*"]
357
+ },
358
+ {
359
+ "name": "api-layer",
360
+ "pattern": "src/api/**/*",
361
+ "allow": ["src/utils/**/*", "src/types/**/*"],
362
+ "deny": ["src/components/**/*"]
363
+ }
364
+ ],
365
+ "importConventions": [
366
+ {
367
+ "rule": "relative-internal-absolute-external",
368
+ "domains": [
369
+ {
370
+ "path": "src/features/auth",
371
+ "alias": "@auth",
372
+ "enabled": true
373
+ },
374
+ {
375
+ "path": "src/shared/ui",
376
+ "alias": "@ui-kit",
377
+ "enabled": false // checks disabled for this domain, but alias is still used for absolute imports from other domains
378
+ }
379
+ ]
380
+ }
381
+ ],
382
+ "circularImportsDetection": {
383
+ "enabled": true,
384
+ "ignoreTypeImports": true
385
+ },
386
+ "orphanFilesDetection": {
387
+ "enabled": true,
388
+ "validEntryPoints": ["src/index.ts", "src/app.ts"],
389
+ "ignoreTypeImports": true,
390
+ "graphExclude": ["**/*.test.*", "**/stories/**/*"]
391
+ },
392
+ "unusedNodeModulesDetection": {
393
+ "enabled": true,
394
+ "includeModules": ["@myorg/**"],
395
+ "excludeModules": ["@types/**"],
396
+ "pkgJsonFieldsWithBinaries": ["scripts", "bin"],
397
+ "filesWithBinaries": ["scripts/check-something.sh"],
398
+ "filesWithModules": [".storybook/main.ts"],
399
+ "outputType": "groupByModule"
400
+ },
401
+ "missingNodeModulesDetection": {
402
+ "enabled": true,
403
+ "includeModules": ["lodash", "axios"],
404
+ "excludeModules": ["@types/**"],
405
+ "outputType": "groupByFile"
406
+ }
407
+ }
408
+ ]
409
+ }
410
+ ```
411
+
412
+ ### Available Properties
413
+
414
+ #### Root Level Properties
415
+ - **`configVersion`** (required): Configuration version string
416
+ - **`$schema`** (optional): JSON schema reference for validation
417
+ - **`conditionNames`** (optional): Array of condition names for exports resolution
418
+ - **`ignoreFiles`** (optional): Global file patterns to ignore across all rules. Git ignored files are skipped by default.
419
+ - **`rules`** (required): Array of rule objects
420
+
421
+ #### Rule Properties
422
+ Each rule can contain the following properties:
423
+
424
+ - **`path`** (required): Target directory path for this rule (either `.` or path starting with sub directory name)
425
+ - **`followMonorepoPackages`** (optional): Enable monorepo package resolution (default: true)
426
+ - **`moduleBoundaries`** (optional): Array of module boundary rules
427
+ - **`circularImportsDetection`** (optional): Circular import detection configuration
428
+ - **`orphanFilesDetection`** (optional): Orphan files detection configuration
429
+ - **`unusedNodeModulesDetection`** (optional): Unused node modules detection configuration
430
+ - **`missingNodeModulesDetection`** (optional): Missing node modules detection configuration
431
+ - **`importConventions`** (optional): Array of import convention rules
432
+
433
+ #### Module Boundary Properties
434
+ - **`name`** (required): Name of the boundary
435
+ - **`pattern`** (required): Glob pattern for files in this boundary
436
+ - **`allow`** (optional): Array of allowed import patterns
437
+ - **`deny`** (optional): Array of denied import patterns (overrides allow)
438
+
439
+ #### Import Convention Properties
440
+ - **`rule`** (required): Type of the rule, currently only `relative-internal-absolute-external`
441
+ - **`domains`** (required): Array of domain definitions. Can be a string (glob pattern) or an object with:
442
+ - **`path`** (required): Directory with the domain files
443
+ - **`alias`** (optional): Alias to be used for absolute imports of code from this domain
444
+ - **`enabled`** (optional): Set to `false` to skip checks for this domain (default: true)
445
+
446
+ #### Detection Options Properties
447
+
448
+ **CircularImportsDetection:**
449
+ - **`enabled`** (required): Enable/disable circular import detection
450
+ - **`ignoreTypeImports`** (optional): Exclude type-only imports when building graph (default: false)
451
+
452
+ **OrphanFilesDetection:**
453
+ - **`enabled`** (required): Enable/disable orphan files detection
454
+ - **`validEntryPoints`** (optional): Array of valid entry point patterns (eg. ["src/index.ts", "src/main.ts"])
455
+ - **`ignoreTypeImports`** (optional): Exclude type-only imports when building graph (default: false)
456
+ - **`graphExclude`** (optional): File patterns to exclude from graph analysis
457
+
458
+ **UnusedNodeModulesDetection:**
459
+ - **`enabled`** (required): Enable/disable unused modules detection
460
+ - **`includeModules`** (optional): Module patterns to include in analysis
461
+ - **`excludeModules`** (optional): Module patterns to exclude from analysis
462
+ - **`pkgJsonFieldsWithBinaries`** (optional): Package.json fields containing binary references (eg. lint-staged). Performs plain-text lookup
463
+ - **`filesWithBinaries`** (optional): File patterns to search for binary usage. Performs plain-text lookup
464
+ - **`filesWithModules`** (optional): Non JS/TS file patterns to search for module imports (eg. shell scripts). Performs plain-text lookup
465
+ - **`outputType`** (optional): Output format - "list", "groupByModule", "groupByFile"
466
+
467
+ **MissingNodeModulesDetection:**
468
+ - **`enabled`** (required): Enable/disable missing modules detection
469
+ - **`includeModules`** (optional): Module patterns to include in analysis
470
+ - **`excludeModules`** (optional): Module patterns to exclude from analysis
471
+ - **`outputType`** (optional): Output format - "list", "groupByModule", "groupByFile"
472
+
473
+ ### Performance Benefits
474
+
475
+ The configuration approach provides significant performance advantages:
476
+
477
+ - **Single Dependency Tree Build**: Builds one comprehensive dependency tree for all rules
478
+ - **Parallel Rule Execution**: Processes multiple rules simultaneously
479
+ - **Parallel Check Execution**: Runs all enabled checks within each rule in parallel
480
+ - **Optimized File Discovery**: Discovers files once and reuses across all checks
481
+
482
+ This makes config-based checks faster than running individual commands sequentially, especially for large codebases with multiple sub packages.
483
+
484
+
219
485
 
220
486
  ## Reimplemented to achieve 7x-37x speedup
221
487
 
@@ -339,6 +605,68 @@ rev-dep circular --ignore-types-imports
339
605
  ```
340
606
 
341
607
 
608
+ ### rev-dep config
609
+
610
+ Create and execute rev-dep configuration files
611
+
612
+ #### Synopsis
613
+
614
+ Commands for creating and executing rev-dep configuration files.
615
+
616
+ #### Options
617
+
618
+ ```
619
+ -c, --cwd string Working directory (default "$PWD")
620
+ -h, --help help for config
621
+ ```
622
+
623
+
624
+ ### rev-dep config run
625
+
626
+ Execute all checks defined in (.)rev-dep.config.json(c)
627
+
628
+ #### Synopsis
629
+
630
+ Process (.)rev-dep.config.json(c) and execute all enabled checks (circular imports, orphan files, module boundaries, node modules) per rule.
631
+
632
+ ```
633
+ rev-dep config run [flags]
634
+ ```
635
+
636
+ #### Options
637
+
638
+ ```
639
+ --condition-names strings List of conditions for package.json imports resolution (e.g. node, imports, default)
640
+ -c, --cwd string Working directory (default "$PWD")
641
+ --follow-monorepo-packages Enable resolution of imports from monorepo workspace packages
642
+ -h, --help help for run
643
+ --list-all-issues List all issues instead of limiting output
644
+ --package-json string Path to package.json (default: ./package.json)
645
+ --tsconfig-json string Path to tsconfig.json (default: ./tsconfig.json)
646
+ -v, --verbose Show warnings and verbose output
647
+ ```
648
+
649
+
650
+ ### rev-dep config init
651
+
652
+ Initialize a new rev-dep.config.json file
653
+
654
+ #### Synopsis
655
+
656
+ Create a new rev-dep.config.json configuration file in the current directory with default settings.
657
+
658
+ ```
659
+ rev-dep config init [flags]
660
+ ```
661
+
662
+ #### Options
663
+
664
+ ```
665
+ -c, --cwd string Working directory (default "$PWD")
666
+ -h, --help help for init
667
+ ```
668
+
669
+
342
670
  ### rev-dep entry-points
343
671
 
344
672
  Discover and list all entry points in the project
@@ -412,6 +740,41 @@ rev-dep files --entry-point src/index.ts
412
740
  ```
413
741
 
414
742
 
743
+ ### rev-dep imported-by
744
+
745
+ List all files that directly import the specified file
746
+
747
+ #### Synopsis
748
+
749
+ Finds and lists all files in the project that directly import the specified file.
750
+ This is useful for understanding the impact of changes to a particular file.
751
+
752
+ ```
753
+ rev-dep imported-by [flags]
754
+ ```
755
+
756
+ #### Examples
757
+
758
+ ```
759
+ rev-dep imported-by --file src/utils/helpers.ts
760
+ ```
761
+
762
+ #### Options
763
+
764
+ ```
765
+ --condition-names strings List of conditions for package.json imports resolution (e.g. node, imports, default)
766
+ -n, --count Only display the count of importing files
767
+ -c, --cwd string Working directory for the command (default "$PWD")
768
+ -f, --file string Target file to find importers for (required)
769
+ --follow-monorepo-packages Enable resolution of imports from monorepo workspace packages
770
+ -h, --help help for imported-by
771
+ --list-imports List the import identifiers used by each file
772
+ --package-json string Path to package.json (default: ./package.json)
773
+ --tsconfig-json string Path to tsconfig.json (default: ./tsconfig.json)
774
+ -v, --verbose Show warnings and verbose output
775
+ ```
776
+
777
+
415
778
  ### rev-dep lines-of-code
416
779
 
417
780
  Count actual lines of code in the project excluding comments and blank lines
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rev-dep",
3
- "version": "2.4.0-beta.2",
3
+ "version": "2.5.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.4.0-beta.2",
21
- "@rev-dep/linux-x64": "2.4.0-beta.2",
22
- "@rev-dep/win32-x64": "2.4.0-beta.2"
20
+ "@rev-dep/darwin-arm64": "2.5.0",
21
+ "@rev-dep/linux-x64": "2.5.0",
22
+ "@rev-dep/win32-x64": "2.5.0"
23
23
  },
24
24
  "keywords": [
25
25
  "dependency-analysis",