展示HN:Rev-dep – 20倍于knip.dev的Go语言构建替代方案
Show HN: Rev-dep – 20x faster knip.dev alternative build in Go

原始链接: https://github.com/jayu/rev-dep

## Rev-dep:JavaScript & TypeScript 快速依赖分析 Rev-dep 是一款高性能的静态分析工具,旨在维护大型 JavaScript 和 TypeScript 项目的代码质量和架构完整性。它使用 Go 语言构建,以实现卓越的性能,比其他工具更快地分析依赖图——审计 50 万+ 行代码的项目仅需约 500 毫秒。 它充当“依赖图的 lint 工具”,强制执行关于循环依赖、未使用代码(文件和模块)、模块边界和导入规范的规则。Rev-dep 提供基于**配置的治理**(用于自动化 CI 检查)和**探索性 CLI 工具集**,用于调试和理解依赖关系。 **主要特性:** * **Monorepo 支持:** 原生支持现代工作区(pnpm、yarn、npm)和 `package.json` exports/imports。 * **可配置规则:** 定义并强制执行架构规则、导入风格和卫生检查。 * **快速 CLI:** 快速识别入口点、解析依赖项和列出导入的文件。 * **CI 集成:** 作为一道关卡,防止架构漂移和代码膨胀。 Rev-dep 通过提供对项目依赖关系的清晰洞察,帮助开发者自信地重构、维护和扩展代码库。它是一个有价值的工具,可确保代码库精简、结构良好且易于维护。

Hacker News新 | 过去 | 评论 | 提问 | 展示 | 招聘 | 提交登录展示 HN:Rev-dep – 20 倍速 knip.dev 替代方案,用 Go 构建 (github.com/jayu)10 分,jayu_dev 发布 44 分钟前 | 隐藏 | 过去 | 收藏 | 2 条评论帮助 esafak 4 分钟前 | 下一个 [–] 快速浏览了一下,看起来不错;我很期待尝试。你有什么问题吗?回复e1g 11 分钟前 | 上一个 [–] +1 这个想法。在 AI 之间强制执行明确的边界,令人惊讶地有助于它们推理如何构建更改。我们最近推出了我们自己的静态分析,使用 oxc-parser 和 oxc-resolver,运行速度非常快(~100K LOC 小于 1 秒)。对我们来说,增加这一层防御“混乱”是值得的。回复 指南 | 常见问题 | 列表 | API | 安全 | 法律 | 申请 YC | 联系 搜索:
相关文章

原文

Rev-dep logo

Capabilities  •   Installation  •   Exploratory Toolkit  •   CLI Reference

Dependency analysis and optimization toolkit for modern JavaScript and TypeScript codebases.
Enforce dependency graph hygiene and remove unused code with a very fast CLI.

Rev-dep config execution CLI output


rev-dep version rev-dep license rev-dep PRs welcome

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.

Think of Rev-dep as a high-speed linter for your dependency graph.

Consolidate fragmented, sequential checks from multiple slow tools into a single, high-performance engine. Rev-dep executes a full suite of governance checks—including circularity, orphans, module boundaries and more, in one parallelized pass. Implemented in Go to bypass the performance bottlenecks of Node-based analysis, it can audit a 500k+ LoC project in approximately 500ms.

Automated Codebase Governance

Rev-dep moves beyond passive scanning to active enforcement, answering (and failing CI for) the hard questions:

  • Architecture Integrity: "Is my 'Domain A' illegally importing from 'Domain B'?".
  • Dead Code & Bloat: "Are these files unreachable, or are these node_modules unused?".
  • Refactoring Safety: "Which entry points actually use this utility, and are there circular chains?".
  • Workspace Hygiene: "Are my imports consistent and are all dependencies declared?".

Rev-dep serves as a high-speed gatekeeper for your CI, ensuring your dependency graph remains lean and your architecture stays intact as you iterate.

🏗️ First-class monorepo support

Designed for modern workspaces (pnpm, yarn, npm). Rev-dep natively resolves package.json exports/imports maps, TypeScript aliases and traces dependencies across package boundaries.

🛡️ Config-Based Codebase Governance

Move beyond passive scanning. Use the configuration engine to enforce Module Boundaries and Import Conventions. Execute a full suite of hygiene checks (circularity, orphans, unused modules and more) in a single, parallelized pass that serves as a high-speed gatekeeper for your CI.

CLI toolkit that helps debug issues with dependencies between files. Understand transitive relation between files and fix issues.

Built for Speed and CI Efficiency

Implemented in Go to eliminate the performance tax of Node-based analysis. By processing files in parallel, Rev-dep offers 10x-200x faster execution than alternatives, significantly reducing CI costs and developer wait-states.

Rev-dep can audit a 500k+ LoC project in around 500ms. See the performance comparison

Governance and maintenance (config-based) 🛡️

Use rev-dep config run to execute multiple checks in one pass for all packages.

Available checks:

  • moduleBoundaries - enforce architecture boundaries between modules.
  • importConventions - enforce import style conventions (offers autofix).
  • unusedExportsDetection - detect exports that are never used (offers autofix).
  • orphanFilesDetection - detect dead/orphan files (offers autofix).
  • unusedNodeModulesDetection - detect dependencies declared but not used.
  • missingNodeModulesDetection - detect imports missing from package json.
  • unresolvedImportsDetection - detect unresolved import requests.
  • circularImportsDetection - detect circular imports.
  • devDepsUsageOnProdDetection - detect dev dependencies used in production code.
  • restrictedImportsDetection - block importing denied files/modules from selected entry points.

Exploratory analysis (CLI-based) 🔍

Use CLI commands for ad-hoc dependency exploration:

  • entry-points - discover project entry points.
  • files - list dependency tree files for a given entry point.
  • resolve - trace dependency paths between files (who imports this file).
  • imported-by - list direct importers of a file.
  • circular - list circular dependency chains.
  • node-modules - inspect used, unused, missing, and installed node modules.
  • lines-of-code - count effective LOC.
  • list-cwd-files - list all source code files in CWD

Install locally to set up project check scripts

Create config file for a quick start:

Install globally to use as a CLI tool:

A few instant-use examples to get a feel for the tool:

# Detect unused node modules
rev-dep node-modules unused

# Detect circular imports/dependencies
rev-dep circular

# List all entry points in the project
rev-dep entry-points

# Check which files an entry point imports
rev-dep files --entry-point src/index.ts

# Find every entry point that depends on a file
rev-dep resolve --file src/utils/math.ts

# Resolve dependency path between files
rev-dep resolve --file src/utils/math.ts --entry-point src/index.ts

Config-Based Checks 🛡️

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.

Available checks are:

  • moduleBoundaries - enforce architecture boundaries between modules.
  • importConventions - enforce import style conventions (offers autofix).
  • unusedExportsDetection - detect exports that are never used (offers autofix).
  • orphanFilesDetection - detect dead/orphan files (offers autofix).
  • unusedNodeModulesDetection - detect dependencies declared but not used.
  • missingNodeModulesDetection - detect imports missing from package json.
  • unresolvedImportsDetection - detect unresolved import requests.
  • circularImportsDetection - detect circular imports.
  • devDepsUsageOnProdDetection - detect dev dependencies used in production code.
  • restrictedImportsDetection - block importing denied files/modules from selected entry points.

Checks are grouped in rules. You can have multiple rules, eg. for each monorepo package.

Initialize a configuration file in your project:

# Create a default configuration file
rev-dep config init

Behavior of rev-dep config init:

  • Monorepo root: Running rev-dep config init at the workspace root creates a root rule and a rule for each discovered workspace package.
  • 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.

Run all configured checks (dry run, not fixes applied yet):

# Execute all rules and checks defined in the config
rev-dep config run

List all detected issues:

# Lists all detected issues, by default lists first five issues for each check
rev-dep config run --list-all-issues

Fix all fixable checks:

# Fix checks configured with autofix
rev-dep config run --fix

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.

Quick Start Configuration

Comprehensive Config Example

Here's a comprehensive example showing all available properties:

{
  "configVersion": "1.5",
  "$schema": "https://github.com/jayu/rev-dep/blob/master/config-schema/1.5.schema.json?raw=true", // enables json autocompletion
  "conditionNames": ["import", "default"],
  "ignoreFiles": ["**/*.test.*"],
  "rules": [
    {
      "path": ".",
      "followMonorepoPackages": true,
      "moduleBoundaries": [
        {
          "name": "ui-components",
          "pattern": "src/components/**/*",
          "allow": ["src/utils/**/*", "src/types/**/*"],
          "deny": ["src/api/**/*"]
        },
        {
          "name": "api-layer",
          "pattern": "src/api/**/*",
          "allow": ["src/utils/**/*", "src/types/**/*"],
          "deny": ["src/components/**/*"]
        }
      ],
      "importConventions": [
        {
          "rule": "relative-internal-absolute-external",
          "autofix": true,
          "domains": [
            {
              "path": "src/features/auth",
              "alias": "@auth",
              "enabled": true
            },
            {
              "path": "src/shared/ui",
              "alias": "@ui-kit",
              "enabled": false // checks disabled for this domain, but alias is still used for absolute imports from other domains
            }
          ]
        }
      ],
      "circularImportsDetection": {
        "enabled": true,
        "ignoreTypeImports": true
      },
      "orphanFilesDetection": {
        "enabled": true,
        "validEntryPoints": ["src/index.ts", "src/app.ts"],
        "ignoreTypeImports": true,
        "graphExclude": ["**/*.test.*", "**/stories/**/*"],
        "autofix": true
      },
      "unusedNodeModulesDetection": {
        "enabled": true,
        "includeModules": ["@myorg/**"],
        "excludeModules": ["@types/**"],
        "pkgJsonFieldsWithBinaries": ["scripts", "bin"],
        "filesWithBinaries": ["scripts/check-something.sh"],
        "filesWithModules": [".storybook/main.ts"],
        "outputType": "groupByModule"
      },
      "missingNodeModulesDetection": {
        "enabled": true,
        "includeModules": ["lodash", "axios"],
        "excludeModules": ["@types/**"],
        "outputType": "groupByFile"
      },
      "unusedExportsDetection": {
        "enabled": true,
        "validEntryPoints": ["src/index.ts"],
        "ignoreTypeExports": true,
        "graphExclude": ["**/*.stories.tsx"],
        "autofix": true
      },
      "unresolvedImportsDetection": {
        "enabled": true,
        "ignore": {
          "src/index.ts": "legacy-unresolved-module"
        },
        "ignoreFiles": ["**/*.generated.ts"],
        "ignoreImports": ["@internal/dev-only"]
      },
      "devDepsUsageOnProdDetection": {
        "enabled": true,
        "prodEntryPoints": ["src/main.tsx", "src/pages/**/*.tsx", "src/server.ts"],
        "ignoreTypeImports": true
      },
      "restrictedImportsDetection": {
        "enabled": true,
        "entryPoints": ["src/server.ts", "src/server/**/*.ts"],
        "denyFiles": ["**/*.tsx"],
        "denyModules": ["react", "react-*"],
        "ignoreMatches": ["src/server/allowed-view.tsx", "react-awsome-lib"],
        "ignoreTypeImports": true
      }
    }
  ]
}
  • configVersion (required): Configuration version string
  • $schema (optional): JSON schema reference for validation
  • conditionNames (optional): Array of condition names for exports resolution
  • ignoreFiles (optional): Global file patterns to ignore across all rules. Git ignored files are skipped by default.
  • rules (required): Array of rule objects

Each rule can contain the following properties:

  • path (required): Target directory path for this rule (either . or path starting with sub directory name)
  • followMonorepoPackages (optional): Enable monorepo package resolution (default: true)
  • moduleBoundaries (optional): Array of module boundary rules
  • circularImportsDetection (optional): Circular import detection configuration
  • orphanFilesDetection (optional): Orphan files detection configuration
  • unusedNodeModulesDetection (optional): Unused node modules detection configuration
  • missingNodeModulesDetection (optional): Missing node modules detection configuration
  • unusedExportsDetection (optional): Unused exports detection configuration
  • unresolvedImportsDetection (optional): Unresolved imports detection configuration
  • devDepsUsageOnProdDetection (optional): Restricted dev dependencies usage detection configuration
  • restrictedImportsDetection (optional): Restrict importing denied files/modules from selected entry points
  • importConventions (optional): Array of import convention rules

Module Boundary Properties

  • name (required): Name of the boundary
  • pattern (required): Glob pattern for files in this boundary
  • allow (optional): Array of allowed import patterns
  • deny (optional): Array of denied import patterns (overrides allow)

Import Convention Properties

  • rule (required): Type of the rule, currently only relative-internal-absolute-external
  • autofix (optional): Whether to automatically fix import convention violations (default: false)
  • domains (required): Array of domain definitions. Can be a string (glob pattern) or an object with:
    • path (required): Directory with the domain files
    • alias (optional): Alias to be used for absolute imports of code from this domain
    • enabled (optional): Set to false to skip checks for this domain (default: true)

Detection Options Properties

CircularImportsDetection:

  • enabled (required): Enable/disable circular import detection
  • ignoreTypeImports (optional): Exclude type-only imports when building graph (default: false)

OrphanFilesDetection:

  • enabled (required): Enable/disable orphan files detection
  • validEntryPoints (optional): Array of valid entry point patterns (eg. ["src/index.ts", "src/main.ts"])
  • ignoreTypeImports (optional): Exclude type-only imports when building graph (default: false)
  • graphExclude (optional): File patterns to exclude from graph analysis
  • autofix (optional): Delete detected orphan files automatically when running rev-dep config run --fix (default: false)

UnusedNodeModulesDetection:

  • enabled (required): Enable/disable unused modules detection
  • includeModules (optional): Module patterns to include in analysis
  • excludeModules (optional): Module patterns to exclude from analysis
  • pkgJsonFieldsWithBinaries (optional): Package.json fields containing binary references (eg. lint-staged). Performs plain-text lookup
  • filesWithBinaries (optional): File patterns to search for binary usage. Performs plain-text lookup
  • filesWithModules (optional): Non JS/TS file patterns to search for module imports (eg. shell scripts). Performs plain-text lookup
  • outputType (optional): Output format - "list", "groupByModule", "groupByFile"

MissingNodeModulesDetection:

  • enabled (required): Enable/disable missing modules detection
  • includeModules (optional): Module patterns to include in analysis
  • excludeModules (optional): Module patterns to exclude from analysis
  • outputType (optional): Output format - "list", "groupByModule", "groupByFile", "groupByModuleFilesCount"

UnusedExportsDetection:

  • enabled (required): Enable/disable unused exports detection
  • validEntryPoints (optional): Glob patterns for files whose exports are never reported as unused (eg. ["index.ts", "src/public-api.ts"])
  • ignoreTypeExports (optional): Skip export type / export interface from analysis (default: false)
  • graphExclude (optional): File patterns to exclude from unused exports analysis

UnresolvedImportsDetection:

  • enabled (required): Enable/disable unresolved imports detection
  • ignore (optional): Map of file path (relative to rule path directory) to exact import request to suppress
  • ignoreFiles (optional): File path globs; all unresolved imports from matching files are suppressed
  • ignoreImports (optional): Import requests to suppress globally in unresolved results

DevDepsUsageOnProd:

  • enabled (required): Enable/disable restricted dev dependencies usage detection
  • prodEntryPoints (optional): Production entry point patterns to trace dependencies from (eg. ["src/pages/**/*.tsx", "src/main.tsx"])
  • ignoreTypeImports (optional): Exclude type-only imports from graph traversal and module matching (default: false)

RestrictedImportsDetection:

  • enabled (required): Enable/disable restricted imports detection
  • entryPoints (required when enabled): Entry point patterns used to build reachable dependency graph
  • denyFiles (optional): Denied file path patterns (eg. ["**/*.tsx"])
  • denyModules (optional): Denied module patterns (eg. ["react", "react-*"])
  • ignoreMatches (optional): File/module patterns to suppress from restricted import results
  • ignoreTypeImports (optional): Exclude type-only imports from traversal (default: false)

The configuration approach provides significant performance advantages:

  • Single Dependency Tree Build: Builds one comprehensive dependency tree for all rules
  • Parallel Rule Execution: Processes multiple rules simultaneously
  • Parallel Check Execution: Runs all enabled checks within each rule in parallel
  • Optimized File Discovery: Discovers files once and reuses across all checks

This makes config-based checks faster than running individual commands sequentially, especially for large codebases with multiple sub packages.

Practical examples show how to use rev-dep CLI commands to explore, debug or build code quality checks for your project.

How to identify where a file is used in the project

rev-dep resolve --file path/to/file.ts

You’ll see all entry points that implicitly require that file, along with resolution paths.

How to check if a file is used

rev-dep resolve --file path/to/file.ts --compact-summary

Shows how many entry points indirectly depend on the file.

How to identify dead files

Exclude framework entry points if needed using --result-exclude.

For example exclude Next.js valid entry points when using pages router, exclude scripts directory - scripts are valid entry-points and exclude all test files:

rev-dep entry-points --result-exclude "pages/**","scripts/**","**/*.test.*"

How to list all files imported by an entry point

rev-dep files --entry-point path/to/file.ts

Useful for identifying heavy components or unintended dependencies.

How to reduce unnecessary imports for an entry point

  1. List all files imported:

    rev-dep files --entry-point path/to/entry.ts
    
  2. Identify suspicious files.

  3. Trace why they are included:

    rev-dep resolve --file path/to/suspect --entry-points path/to/entry.ts --all
    

How to detect circular dependencies

How to find unused node modules

rev-dep node-modules unused

How to find missing node modules

rev-dep node-modules missing

How to check node_modules space usage

rev-dep node-modules dirs-size

Working with Monorepo 🏗️

Rev-dep provides first-class support for monorepo projects, enabling accurate dependency analysis across workspace packages.

followMonorepoPackages Flag

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.

# Enable monorepo package resolution
rev-dep circular --follow-monorepo-packages
rev-dep resolve --file src/utils.ts --follow-monorepo-packages
rev-dep entry-points --follow-monorepo-packages

When enabled, rev-dep will:

  • Detect workspace packages automatically by scanning for monorepo configuration
  • Resolve imports between packages within the workspace
  • Follow package.json exports for proper module resolution

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.

The exports map support includes:

  • Conditional exports using conditions like node, import, default, and custom conditions
  • Wildcard patterns for flexible subpath mapping
  • Sugar syntax for simple main export definitions
  • Nested conditions for complex resolution scenarios

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:

# Resolve exports for different environments
rev-dep circular --condition-names=node,import,default
rev-dep resolve --file src/utils.ts --condition-names=import,node
rev-dep entry-points --condition-names=default,node,import

The conditions are processed in the order specified, with the first matching condition being used. Common conditions include:

  • node - Node.js environment
  • import - ES modules
  • require - CommonJS
  • default - Fallback condition
  • Custom conditions specific to your project or build tools

Example package.json with exports:

{
  "name": "@myorg/utils",
  "exports": {
    ".": {
      "import": "./dist/index.mjs",
      "require": "./dist/index.js",
      "default": "./dist/index.js"
    },
    "./helpers": "./dist/helpers.js",
    "./types/*": "./dist/types/*.d.ts"
  }
}
  1. Monorepo Detection: When followMonorepoPackages is enabled, rev-dep scans for workspace configuration (pnpm-workspace.yaml, package.json workspaces, etc.)

  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

  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

  4. Path Resolution: All paths are resolved relative to their respective package roots, ensuring accurate dependency tracking across the entire monorepo

This makes rev-dep particularly effective for large-scale monorepo projects where understanding cross-package dependencies is crucial for maintaining code quality and architecture.

Performance comparison ⚡

Rev-dep can perform multiple checks on 500k+ LoC monorepo with several sub-packages in around 500ms.

It outperforms Madge, dpdm, dependency-cruiser, skott, knip, depcheck and other similar tools.

Here is a performance comparison of specific tasks between rev-dep and alternatives:

Task Execution Time [ms] Alternative Alternative Time [ms] Slower Than Rev-dep
Find circular dependencies 289 dpdm-fast 7061 24x
Find unused exports 303 knip 6606 22x
Find unused files 277 knip 6596 23x
Find unused node modules 287 knip 6572 22x
Find missing node modules 270 knip 6568 24x
List all files imported by an entry point 229 madge 4467 20x
Discover entry points 323 madge 67000 207x
Resolve dependency path between files 228 please suggest
Count lines of code 342 please suggest
Check node_modules disk usage 1619 please suggest
Analyze node_modules directory sizes 521 please suggest

Benchmark run on WSL Linux Debian Intel(R) Core(TM) i9-14900KF CPU @ 2.80GHz

Circular check performance comparison

Benchmark performed on TypeScript codebase with 6034 source code files and 518862 lines of code.

Benchmark performed on MacBook Pro with Apple M1 chip, 16GB of RAM and 256GB of Storage. Power save mode off.

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.

rev-dep circular check is 12 times faster than the fastest alternative❗

Tool Version Command to Run Circular Check Time
🥇 rev-dep 2.0.0 rev-dep circular 397 ms
🥈 dpdm-fast 1.0.14 dpdm --no-tree --no-progress --no-warning + list of directories with source code 4960 ms
🥉 dpdm 3.14.0 dpdm --no-warning + list of directories with source code 5030 ms
skott 0.35.6 node script using skott findCircularDependencies function 29575 ms
madge 8.0.0 madge --circular --extensions js,ts,jsx,tsx . 69328 ms
circular-dependency-scanner 2.3.0 ds - out of memory error n/a

How to detect dev dependencies used in production code

When devDepsUsageOnProdDetection is enabled in your config, rev-dep will:

  1. Trace dependency graphs from your specified production entry points
  2. Identify all files reachable from those entry points
  3. Check if any imported modules are listed in devDependencies in package.json
  4. Report violations showing which dev dependencies are used where

Example Output:

❌ Restricted Dev Dependencies Usage Issues (2):
  lodash (dev dependency)
     - src/components/Button.tsx (from entry point: src/pages/index.tsx)
     - src/utils/helpers.ts (from entry point: src/pages/index.tsx)
  eslint (dev dependency)
     - src/config/eslint-config.js (from entry point: src/server.ts)

Important Notes:

  • Type-only imports (e.g., import type { ReactNode } from 'react') are ignored when ignoreTypeImports is enabled
  • Only dependencies from devDependencies in package.json are flagged
  • Production dependencies from dependencies are allowed
  • Helps prevent runtime failures in production builds

Detect circular dependencies in your project

Analyzes the project to find circular dependencies between modules. Circular dependencies can cause hard-to-debug issues and should generally be avoided.

rev-dep circular --ignore-types-imports
      --condition-names strings                                     List of conditions for package.json imports resolution (e.g. node, imports, default)
  -c, --cwd string                                                  Working directory for the command (default "$PWD")
      --follow-monorepo-packages strings                            Enable resolution of imports from monorepo workspace packages. Pass without value to follow all, or pass package names
  -h, --help                                                        help for circular
  -t, --ignore-type-imports                                         Exclude type imports from the analysis
      --package-json string                                         Path to package.json (default: ./package.json)
      --tsconfig-json string                                        Path to tsconfig.json (default: ./tsconfig.json)
  -v, --verbose                                                     Show warnings and verbose output

Create and execute rev-dep configuration files

Commands for creating and executing rev-dep configuration files.

  -c, --cwd string   Working directory (default "$PWD")
  -h, --help         help for config

Execute all checks defined in (.)rev-dep.config.json(c)

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.

rev-dep config run [flags]
      --condition-names strings                                     List of conditions for package.json imports resolution (e.g. node, imports, default)
  -c, --cwd string                                                  Working directory (default "$PWD")
      --fix                                                         Automatically fix fixable issues
      --follow-monorepo-packages strings                            Enable resolution of imports from monorepo workspace packages. Pass without value to follow all, or pass package names
  -h, --help                                                        help for run
      --list-all-issues                                             List all issues instead of limiting output
      --package-json string                                         Path to package.json (default: ./package.json)
      --rules strings                                               Subset of rules to run (comma-separated list of rule paths)
      --tsconfig-json string                                        Path to tsconfig.json (default: ./tsconfig.json)
  -v, --verbose                                                     Show warnings and verbose output

Initialize a new rev-dep.config.json file

Create a new rev-dep.config.json configuration file in the current directory with default settings.

rev-dep config init [flags]
  -c, --cwd string   Working directory (default "$PWD")
  -h, --help         help for init

Discover and list all entry points in the project

Analyzes the project structure to identify all potential entry points. Useful for understanding your application's architecture and dependencies.

rev-dep entry-points [flags]
rev-dep entry-points --print-deps-count
      --condition-names strings                                     List of conditions for package.json imports resolution (e.g. node, imports, default)
  -n, --count                                                       Only display the number of entry points found
  -c, --cwd string                                                  Working directory for the command (default "$PWD")
      --follow-monorepo-packages strings                            Enable resolution of imports from monorepo workspace packages. Pass without value to follow all, or pass package names
      --graph-exclude strings                                       Exclude files matching these glob patterns from analysis
  -h, --help                                                        help for entry-points
  -t, --ignore-type-imports                                         Exclude type imports from the analysis
      --package-json string                                         Path to package.json (default: ./package.json)
      --print-deps-count                                            Show the number of dependencies for each entry point
      --result-exclude strings                                      Exclude files matching these glob patterns from results
      --result-include strings                                      Only include files matching these glob patterns in results
      --tsconfig-json string                                        Path to tsconfig.json (default: ./tsconfig.json)
  -v, --verbose                                                     Show warnings and verbose output

List all files in the dependency tree of an entry point

Recursively finds and lists all files that are required by the specified entry point.

rev-dep files --entry-point src/index.ts
      --condition-names strings                                     List of conditions for package.json imports resolution (e.g. node, imports, default)
  -n, --count                                                       Only display the count of files in the dependency tree
  -c, --cwd string                                                  Working directory for the command (default "$PWD")
  -p, --entry-point string                                          Entry point file to analyze (required)
      --follow-monorepo-packages strings                            Enable resolution of imports from monorepo workspace packages. Pass without value to follow all, or pass package names
  -h, --help                                                        help for files
  -t, --ignore-type-imports                                         Exclude type imports from the analysis
      --package-json string                                         Path to package.json (default: ./package.json)
      --tsconfig-json string                                        Path to tsconfig.json (default: ./tsconfig.json)
  -v, --verbose                                                     Show warnings and verbose output

List all files that directly import the specified file

Finds and lists all files in the project that directly import the specified file. This is useful for understanding the impact of changes to a particular file.

rev-dep imported-by [flags]
rev-dep imported-by --file src/utils/helpers.ts
      --condition-names strings                                     List of conditions for package.json imports resolution (e.g. node, imports, default)
  -n, --count                                                       Only display the count of importing files
  -c, --cwd string                                                  Working directory for the command (default "$PWD")
  -f, --file string                                                 Target file to find importers for (required)
      --follow-monorepo-packages strings                            Enable resolution of imports from monorepo workspace packages. Pass without value to follow all, or pass package names
  -h, --help                                                        help for imported-by
      --list-imports                                                List the import identifiers used by each file
      --package-json string                                         Path to package.json (default: ./package.json)
      --tsconfig-json string                                        Path to tsconfig.json (default: ./tsconfig.json)
  -v, --verbose                                                     Show warnings and verbose output

Count actual lines of code in the project excluding comments and blank lines

rev-dep lines-of-code [flags]
  -c, --cwd string   Directory to analyze (default "$PWD")
  -h, --help         help for lines-of-code

List all files in the current working directory

Recursively lists all files in the specified directory, with options to filter results.

rev-dep list-cwd-files [flags]
rev-dep list-cwd-files --include='*.ts' --exclude='*.test.ts'
      --count             Only display the count of matching files
      --cwd string        Directory to list files from (default "$PWD")
      --exclude strings   Exclude files matching these glob patterns
  -h, --help              help for list-cwd-files
      --include strings   Only include files matching these glob patterns

Analyze and manage Node.js dependencies

Tools for analyzing and managing Node.js module dependencies. Helps identify unused, missing, or duplicate dependencies in your project.

  rev-dep node-modules used -p src/index.ts
  rev-dep node-modules unused --exclude-modules=@types/*
  rev-dep node-modules missing --entry-points=src/main.ts
  -h, --help   help for node-modules

rev-dep node-modules dirs-size

Calculates cumulative files size in node_modules directories

Calculates and displays the size of node_modules folders 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)

rev-dep node-modules dirs-size [flags]
rev-dep node-modules dirs-size
  -c, --cwd string   Working directory for the command (default "$PWD")
  -h, --help         help for dirs-size

rev-dep node-modules installed-duplicates

Find and optimize duplicate package installations

Identifies packages that are installed multiple times in node_modules. Can optimize storage by creating symlinks between duplicate packages.

rev-dep node-modules installed-duplicates [flags]
rev-dep node-modules installed-duplicates --optimize --size-stats
  -c, --cwd string   Working directory for the command (default "$PWD")
  -h, --help         help for installed-duplicates
      --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
      --optimize     Automatically create symlinks to deduplicate packages
      --size-stats   Print node modules dirs size before and after optimization. Might take longer than optimization itself
      --verbose      Show detailed information about each optimization

rev-dep node-modules installed

List all installed npm packages in the project

Recursively scans node_modules directories to list all installed packages. Helpful for auditing dependencies across monorepos.

rev-dep node-modules installed [flags]
rev-dep node-modules installed --include-modules=@myorg/*
  -c, --cwd string                Working directory for the command (default "$PWD")
  -e, --exclude-modules strings   list of modules to exclude from the output
  -h, --help                      help for installed
  -i, --include-modules strings   list of modules to include in the output

rev-dep node-modules missing

Find imported packages not listed in package.json

Identifies packages that are imported in your code but not declared in your package.json dependencies.

rev-dep node-modules missing [flags]
rev-dep node-modules missing --entry-points=src/main.ts
      --condition-names strings                                     List of conditions for package.json imports resolution (e.g. node, imports, default)
  -n, --count                                                       Only display the count of modules
  -c, --cwd string                                                  Working directory for the command (default "$PWD")
  -p, --entry-points strings                                        Entry point file(s) to start analysis from (default: auto-detected)
  -e, --exclude-modules strings                                     list of modules to exclude from the output
  -b, --files-with-binaries strings                                 Additional files to search for binary usages. Use paths relative to cwd
  -m, --files-with-node-modules strings                             Additional files to search for module imports. Use paths relative to cwd
      --follow-monorepo-packages strings                            Enable resolution of imports from monorepo workspace packages. Pass without value to follow all, or pass package names
      --group-by-file                                               Organize output by project file path
      --group-by-module                                             Organize output by npm package name
      --group-by-module-files-count                                 Organize output by npm package name and show count of files using it
  -h, --help                                                        help for missing
  -t, --ignore-type-imports                                         Exclude type imports from the analysis
  -i, --include-modules strings                                     list of modules to include in the output
      --package-json string                                         Path to package.json (default: ./package.json)
      --pkg-fields-with-binaries strings                            Additional package.json fields to check for binary usages
      --tsconfig-json string                                        Path to tsconfig.json (default: ./tsconfig.json)
  -v, --verbose                                                     Show warnings and verbose output
      --zero-exit-code                                              Use this flag to always return zero exit code

rev-dep node-modules unused

Find installed packages that aren't imported in your code

Compares package.json dependencies with actual imports in your codebase to identify potentially unused packages.

rev-dep node-modules unused [flags]
rev-dep node-modules unused --exclude-modules=@types/*
      --condition-names strings                                     List of conditions for package.json imports resolution (e.g. node, imports, default)
  -n, --count                                                       Only display the count of modules
  -c, --cwd string                                                  Working directory for the command (default "$PWD")
  -p, --entry-points strings                                        Entry point file(s) to start analysis from (default: auto-detected)
  -e, --exclude-modules strings                                     list of modules to exclude from the output
  -b, --files-with-binaries strings                                 Additional files to search for binary usages. Use paths relative to cwd
  -m, --files-with-node-modules strings                             Additional files to search for module imports. Use paths relative to cwd
      --follow-monorepo-packages strings                            Enable resolution of imports from monorepo workspace packages. Pass without value to follow all, or pass package names
  -h, --help                                                        help for unused
  -t, --ignore-type-imports                                         Exclude type imports from the analysis
  -i, --include-modules strings                                     list of modules to include in the output
      --package-json string                                         Path to package.json (default: ./package.json)
      --pkg-fields-with-binaries strings                            Additional package.json fields to check for binary usages
      --tsconfig-json string                                        Path to tsconfig.json (default: ./tsconfig.json)
  -v, --verbose                                                     Show warnings and verbose output
      --zero-exit-code                                              Use this flag to always return zero exit code

rev-dep node-modules used

List all npm packages imported in your code

Analyzes your code to identify which npm packages are actually being used. Helps keep track of your project's runtime dependencies.

rev-dep node-modules used [flags]
rev-dep node-modules used -p src/index.ts --group-by-module
      --condition-names strings                                     List of conditions for package.json imports resolution (e.g. node, imports, default)
  -n, --count                                                       Only display the count of modules
  -c, --cwd string                                                  Working directory for the command (default "$PWD")
  -p, --entry-points strings                                        Entry point file(s) to start analysis from (default: auto-detected)
  -e, --exclude-modules strings                                     list of modules to exclude from the output
  -b, --files-with-binaries strings                                 Additional files to search for binary usages. Use paths relative to cwd
  -m, --files-with-node-modules strings                             Additional files to search for module imports. Use paths relative to cwd
      --follow-monorepo-packages strings                            Enable resolution of imports from monorepo workspace packages. Pass without value to follow all, or pass package names
      --group-by-entry-point                                        Organize output by entry point file path
      --group-by-entry-point-modules-count                          Organize output by entry point and show count of unique modules
      --group-by-file                                               Organize output by project file path
      --group-by-module                                             Organize output by npm package name
      --group-by-module-entry-points-count                          Organize output by npm package name and show count of entry points using it
      --group-by-module-files-count                                 Organize output by npm package name and show count of files using it
      --group-by-module-show-entry-points                           Organize output by npm package name and list entry points using it
  -h, --help                                                        help for used
  -t, --ignore-type-imports                                         Exclude type imports from the analysis
  -i, --include-modules strings                                     list of modules to include in the output
      --package-json string                                         Path to package.json (default: ./package.json)
      --pkg-fields-with-binaries strings                            Additional package.json fields to check for binary usages
      --tsconfig-json string                                        Path to tsconfig.json (default: ./tsconfig.json)
  -v, --verbose                                                     Show warnings and verbose output

Trace and display the dependency path between files in your project

Analyze and display the dependency chain between specified files. Helps understand how different parts of your codebase are connected.

rev-dep resolve -p src/index.ts -f src/utils/helpers.ts
  -a, --all                                                         Show all possible resolution paths, not just the first one
      --compact-summary                                             Display a compact summary of found paths
      --condition-names strings                                     List of conditions for package.json imports resolution (e.g. node, imports, default)
  -c, --cwd string                                                  Working directory for the command (default "$PWD")
  -p, --entry-points strings                                        Entry point file(s) or glob pattern(s) to start analysis from (default: auto-detected)
  -f, --file string                                                 Target file to check for dependencies
      --follow-monorepo-packages strings                            Enable resolution of imports from monorepo workspace packages. Pass without value to follow all, or pass package names
      --graph-exclude strings                                       Glob patterns to exclude files from dependency analysis
  -h, --help                                                        help for resolve
  -t, --ignore-type-imports                                         Exclude type imports from the analysis
      --module string                                               Target node module name to check for dependencies
      --package-json string                                         Path to package.json (default: ./package.json)
      --tsconfig-json string                                        Path to tsconfig.json (default: ./tsconfig.json)
  -v, --verbose                                                     Show warnings and verbose output

Some of the terms used in the problem space that rev-dep covers can be confusing. Here is a small glossary to help you navigate the concepts.

A dependency can be understood literally. In the context of a project’s dependency graph, it may refer to:

  • a node module / package (a package is a dependency of a project or file), or
  • a source code file (a file is a dependency of another file if it imports it).

An entry point is a source file that is not imported by any other file. It can represent:

  • the main entry of the application
  • an individual page or feature
  • configuration or test bootstrap files

— depending on the project structure.

A file is considered unused or dead when:

  • it is an entry point (nothing imports it), and
  • running it does not produce any meaningful output or side effect.

In practice, such files can often be removed safely.

A circular dependency occurs when a file directly or indirectly imports itself through a chain of imports.

This can lead to unpredictable runtime behavior, uninitialized values, or subtle bugs. However, circular dependencies between TypeScript type-only imports are usually harmless.

Reverse dependency (or "dependents")

Files that import a given file. Useful for answering: "What breaks if I change or delete this file?"

Import graph / Dependency graph

A visual representation of how files or modules import each other.

Missing dependency / unused node module

A module that your code imports but is not listed in package.json.

Unused dependency / unused node module

A dependency listed in package.json that is never imported in the source code.

Root directory / Project root

The top-level directory used as the starting point for dependency analysis.

Made in 🇵🇱 and 🇯🇵 with 🧠 by @jayu

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 ⭐!

联系我们 contact @ memedata.com