rev-dep 2.4.0-beta.1 → 2.4.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 +338 -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,245 @@ 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
+ - **circular imports** - check if there are circular imports
307
+ - **orphan files** - check if there are orphan/dead files
308
+ - **unused node modules** - check against unused node modules
309
+ - **missing node modules** - check against missing node modules
310
+
311
+ Checks are grouped in rules. You can have multiple rules, eg. for each monorepo package.
312
+
313
+ ### Getting Started
314
+
315
+ Initialize a configuration file in your project:
316
+
317
+ ```bash
318
+ # Create a default configuration file
319
+ rev-dep config init
320
+ ```
321
+
322
+ Behavior of `rev-dep config init`:
323
+
324
+ - Monorepo root: Running `rev-dep config init` at the workspace root creates a root rule and a rule for each discovered workspace package.
325
+ - 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.
326
+
327
+ Run all configured checks:
328
+
329
+ ```bash
330
+ # Execute all rules and checks defined in the config
331
+ rev-dep config run
332
+ ```
333
+
334
+ ### Configuration Structure
335
+
336
+ 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.
337
+
338
+ Here's a comprehensive example showing all available properties:
339
+
340
+ ```jsonc
341
+ {
342
+ "configVersion": "1.0",
343
+ "$schema": "https://github.com/jayu/rev-dep/blob/module-boundaries/config-schema/1.0.schema.json?raw=true", // enables json autocompletion
344
+ "conditionNames": ["import", "default"],
345
+ "ignoreFiles": ["**/*.test.*"],
346
+ "rules": [
347
+ {
348
+ "path": ".",
349
+ "followMonorepoPackages": true,
350
+ "moduleBoundaries": [
351
+ {
352
+ "name": "ui-components",
353
+ "pattern": "src/components/**/*",
354
+ "allow": ["src/utils/**/*", "src/types/**/*"],
355
+ "deny": ["src/api/**/*"]
356
+ },
357
+ {
358
+ "name": "api-layer",
359
+ "pattern": "src/api/**/*",
360
+ "allow": ["src/utils/**/*", "src/types/**/*"],
361
+ "deny": ["src/components/**/*"]
362
+ }
363
+ ],
364
+ "circularImportsDetection": {
365
+ "enabled": true,
366
+ "ignoreTypeImports": true
367
+ },
368
+ "orphanFilesDetection": {
369
+ "enabled": true,
370
+ "validEntryPoints": ["src/index.ts", "src/app.ts"],
371
+ "ignoreTypeImports": true,
372
+ "graphExclude": ["**/*.test.*", "**/stories/**/*"]
373
+ },
374
+ "unusedNodeModulesDetection": {
375
+ "enabled": true,
376
+ "includeModules": ["@myorg/**"],
377
+ "excludeModules": ["@types/**"],
378
+ "pkgJsonFieldsWithBinaries": ["scripts", "bin"],
379
+ "filesWithBinaries": ["scripts/check-something.sh"],
380
+ "filesWithModules": [".storybook/main.ts"],
381
+ "outputType": "groupByModule"
382
+ },
383
+ "missingNodeModulesDetection": {
384
+ "enabled": true,
385
+ "includeModules": ["lodash", "axios"],
386
+ "excludeModules": ["@types/**"],
387
+ "outputType": "groupByFile"
388
+ }
389
+ }
390
+ ]
391
+ }
392
+ ```
393
+
394
+ ### Available Properties
395
+
396
+ #### Root Level Properties
397
+ - **`configVersion`** (required): Configuration version string
398
+ - **`$schema`** (optional): JSON schema reference for validation
399
+ - **`conditionNames`** (optional): Array of condition names for exports resolution
400
+ - **`ignoreFiles`** (optional): Global file patterns to ignore across all rules. Git ignored files are skipped by default.
401
+ - **`rules`** (required): Array of rule objects
402
+
403
+ #### Rule Properties
404
+ Each rule can contain the following properties:
405
+
406
+ - **`path`** (required): Target directory path for this rule (either `.` or path starting with sub directory name)
407
+ - **`followMonorepoPackages`** (optional): Enable monorepo package resolution (default: true)
408
+ - **`moduleBoundaries`** (optional): Array of module boundary rules
409
+ - **`circularImportsDetection`** (optional): Circular import detection configuration
410
+ - **`orphanFilesDetection`** (optional): Orphan files detection configuration
411
+ - **`unusedNodeModulesDetection`** (optional): Unused node modules detection configuration
412
+ - **`missingNodeModulesDetection`** (optional): Missing node modules detection configuration
413
+
414
+ #### Module Boundary Properties
415
+ - **`name`** (required): Name of the boundary
416
+ - **`pattern`** (required): Glob pattern for files in this boundary
417
+ - **`allow`** (optional): Array of allowed import patterns
418
+ - **`deny`** (optional): Array of denied import patterns (overrides allow)
419
+
420
+ #### Detection Options Properties
421
+
422
+ **CircularImportsDetection:**
423
+ - **`enabled`** (required): Enable/disable circular import detection
424
+ - **`ignoreTypeImports`** (optional): Exclude type-only imports when building graph (default: false)
425
+
426
+ **OrphanFilesDetection:**
427
+ - **`enabled`** (required): Enable/disable orphan files detection
428
+ - **`validEntryPoints`** (optional): Array of valid entry point patterns (eg. ["src/index.ts", "src/main.ts"])
429
+ - **`ignoreTypeImports`** (optional): Exclude type-only imports when building graph (default: false)
430
+ - **`graphExclude`** (optional): File patterns to exclude from graph analysis
431
+
432
+ **UnusedNodeModulesDetection:**
433
+ - **`enabled`** (required): Enable/disable unused modules detection
434
+ - **`includeModules`** (optional): Module patterns to include in analysis
435
+ - **`excludeModules`** (optional): Module patterns to exclude from analysis
436
+ - **`pkgJsonFieldsWithBinaries`** (optional): Package.json fields containing binary references (eg. lint-staged). Performs plain-text lookup
437
+ - **`filesWithBinaries`** (optional): File patterns to search for binary usage. Performs plain-text lookup
438
+ - **`filesWithModules`** (optional): Non JS/TS file patterns to search for module imports (eg. shell scripts). Performs plain-text lookup
439
+ - **`outputType`** (optional): Output format - "list", "groupByModule", "groupByFile"
440
+
441
+ **MissingNodeModulesDetection:**
442
+ - **`enabled`** (required): Enable/disable missing modules detection
443
+ - **`includeModules`** (optional): Module patterns to include in analysis
444
+ - **`excludeModules`** (optional): Module patterns to exclude from analysis
445
+ - **`outputType`** (optional): Output format - "list", "groupByModule", "groupByFile"
446
+
447
+ ### Performance Benefits
448
+
449
+ The configuration approach provides significant performance advantages:
450
+
451
+ - **Single Dependency Tree Build**: Builds one comprehensive dependency tree for all rules
452
+ - **Parallel Rule Execution**: Processes multiple rules simultaneously
453
+ - **Parallel Check Execution**: Runs all enabled checks within each rule in parallel
454
+ - **Optimized File Discovery**: Discovers files once and reuses across all checks
455
+
456
+ This makes config-based checks faster than running individual commands sequentially, especially for large codebases with multiple sub packages.
457
+
458
+
219
459
 
220
460
  ## Reimplemented to achieve 7x-37x speedup
221
461
 
@@ -339,6 +579,67 @@ rev-dep circular --ignore-types-imports
339
579
  ```
340
580
 
341
581
 
582
+ ### rev-dep config
583
+
584
+ Create and execute rev-dep configuration files
585
+
586
+ #### Synopsis
587
+
588
+ Commands for creating and executing rev-dep configuration files.
589
+
590
+ #### Options
591
+
592
+ ```
593
+ -c, --cwd string Working directory (default "$PWD")
594
+ -h, --help help for config
595
+ ```
596
+
597
+
598
+ ### rev-dep config run
599
+
600
+ Execute all checks defined in (.)rev-dep.config.json(c)
601
+
602
+ #### Synopsis
603
+
604
+ Process (.)rev-dep.config.json(c) and execute all enabled checks (circular imports, orphan files, module boundaries, node modules) per rule.
605
+
606
+ ```
607
+ rev-dep config run [flags]
608
+ ```
609
+
610
+ #### Options
611
+
612
+ ```
613
+ --condition-names strings List of conditions for package.json imports resolution (e.g. node, imports, default)
614
+ -c, --cwd string Working directory (default "$PWD")
615
+ --follow-monorepo-packages Enable resolution of imports from monorepo workspace packages
616
+ -h, --help help for run
617
+ --package-json string Path to package.json (default: ./package.json)
618
+ --tsconfig-json string Path to tsconfig.json (default: ./tsconfig.json)
619
+ -v, --verbose Show warnings and verbose output
620
+ ```
621
+
622
+
623
+ ### rev-dep config init
624
+
625
+ Initialize a new rev-dep.config.json file
626
+
627
+ #### Synopsis
628
+
629
+ Create a new rev-dep.config.json configuration file in the current directory with default settings.
630
+
631
+ ```
632
+ rev-dep config init [flags]
633
+ ```
634
+
635
+ #### Options
636
+
637
+ ```
638
+ -c, --cwd string Working directory (default "$PWD")
639
+ -h, --help help for init
640
+ ```
641
+
642
+
342
643
  ### rev-dep entry-points
343
644
 
344
645
  Discover and list all entry points in the project
@@ -412,6 +713,41 @@ rev-dep files --entry-point src/index.ts
412
713
  ```
413
714
 
414
715
 
716
+ ### rev-dep imported-by
717
+
718
+ List all files that directly import the specified file
719
+
720
+ #### Synopsis
721
+
722
+ Finds and lists all files in the project that directly import the specified file.
723
+ This is useful for understanding the impact of changes to a particular file.
724
+
725
+ ```
726
+ rev-dep imported-by [flags]
727
+ ```
728
+
729
+ #### Examples
730
+
731
+ ```
732
+ rev-dep imported-by --file src/utils/helpers.ts
733
+ ```
734
+
735
+ #### Options
736
+
737
+ ```
738
+ --condition-names strings List of conditions for package.json imports resolution (e.g. node, imports, default)
739
+ -n, --count Only display the count of importing files
740
+ -c, --cwd string Working directory for the command (default "$PWD")
741
+ -f, --file string Target file to find importers for (required)
742
+ --follow-monorepo-packages Enable resolution of imports from monorepo workspace packages
743
+ -h, --help help for imported-by
744
+ --list-imports List the import identifiers used by each file
745
+ --package-json string Path to package.json (default: ./package.json)
746
+ --tsconfig-json string Path to tsconfig.json (default: ./tsconfig.json)
747
+ -v, --verbose Show warnings and verbose output
748
+ ```
749
+
750
+
415
751
  ### rev-dep lines-of-code
416
752
 
417
753
  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.1",
3
+ "version": "2.4.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.1",
21
- "@rev-dep/linux-x64": "2.4.0-beta.1",
22
- "@rev-dep/win32-x64": "2.4.0-beta.1"
20
+ "@rev-dep/darwin-arm64": "2.4.0",
21
+ "@rev-dep/linux-x64": "2.4.0",
22
+ "@rev-dep/win32-x64": "2.4.0"
23
23
  },
24
24
  "keywords": [
25
25
  "dependency-analysis",