Skip to main content
Rev-dep provides first-class support for monorepo projects, enabling accurate dependency analysis across workspace packages. It natively resolves package.json exports/imports maps, TypeScript aliases, and traces dependencies across package boundaries.

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.
rev-dep circular --follow-monorepo-packages
rev-dep resolve --file src/utils.ts --follow-monorepo-packages
rev-dep entry-points --follow-monorepo-packages

What It Does

When enabled, rev-dep will:
Rev-dep scans for monorepo configuration files including:
  • pnpm-workspace.yaml
  • package.json workspaces field (npm/yarn)
  • Lerna configuration
Cross-package imports are resolved using the package’s exports configuration, falling back to main/module fields when exports are not defined.
Full support for the modern exports field including conditional exports, wildcards, and nested conditions.

Configuration File Usage

In your rev-dep.config.json, use the followMonorepoPackages property at the rule level:
{
  "configVersion": "1.6",
  "rules": [
    {
      "path": ".",
      "followMonorepoPackages": true,
      "prodEntryPoints": ["src/main.tsx"],
      "circularImportsDetection": {
        "enabled": true
      }
    }
  ]
}
Set followMonorepoPackages to true to follow all workspace packages, false to disable it, or an array to follow only selected package names.

Exports Map Support

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.

Supported Features

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

Example Package Configuration

package.json
{
  "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"
  }
}
With this configuration:
  • import '@myorg/utils' resolves to ./dist/index.mjs (when using import condition)
  • import '@myorg/utils/helpers' resolves to ./dist/helpers.js
  • import '@myorg/utils/types/config' resolves to ./dist/types/config.d.ts

Condition Names

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

ConditionDescription
nodeNode.js environment
importES modules
requireCommonJS
defaultFallback condition
CustomProject or build tool specific conditions

Configuration File Usage

Set condition names globally in your config:
rev-dep.config.json
{
  "configVersion": "1.6",
  "conditionNames": ["import", "default"],
  "rules": [
    {
      "path": ".",
      "followMonorepoPackages": true,
      "prodEntryPoints": ["src/main.tsx"]
    }
  ]
}

How It Works

Rev-dep’s monorepo resolution follows this workflow:
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.

Best Practices

Enable for monorepos

Always set followMonorepoPackages: true in your config when working with monorepos

Use exports field

Define clear package boundaries using the exports field in package.json

Set condition names

Configure appropriate condition names for your build environment

Validate dependencies

Let rev-dep ensure cross-package imports are properly declared

Build docs developers (and LLMs) love