Skip to content
Fallow home
All docs pages

dependency-cruiser alternative: compare with fallow

Compare dependency-cruiser rules with fallow boundaries, cycles, and dependency checks for TypeScript and JavaScript. See which rules map and which have no fallow equivalent.

dependency-cruiser validates the dependencies of a project against your own rules, and it draws dependency graphs. Fallow checks import cycles, architecture boundaries, and the dependencies in package.json. It also reports unused code, duplication, and complexity in the same run. This page maps the dependency-cruiser rules to fallow, and lists what each tool does better.

fallow migrate does not read .dependency-cruiser.js or other dependency-cruiser configs. A dependency-cruiser rule is a set of regular expressions and conditions. Fallow boundaries use named zones with an allow list. The two models do not convert one to one, so write the fallow zones by hand. See Boundaries.

Rule mapping

These are the rules that npx dependency-cruiser --init writes, and the fallow rule that reports the same kind of problem:

dependency-cruiser ruleFallow
no-circularcircular-dependencies
no-orphansunused-files (fallow reports a file that no entry point reaches, see Orphans and unused files)
not-to-unresolvableunresolved-imports
no-non-package-jsonunlisted-dependencies
not-to-dev-depdev-dependencies-in-production
not-to-spec-- (no built-in rule. A boundary zone for test files can forbid the imports)
no-deprecated-core, not-to-deprecated-- (no check for deprecated Node.js core modules or deprecated npm packages)
no-duplicate-dep-types-- (no equivalent)
optional-deps-used, peer-deps-used-- (no equivalent)
Custom forbidden rules with from and to pathsboundaries zones and allow lists, reported as boundary-violation

Fallow also reports problems that dependency-cruiser does not: unused dependencies, unused exports and types, type-only and test-only production dependencies, and package cycles between workspace packages.

Write the boundaries

A dependency-cruiser forbidden rule says which dependencies are not allowed. A fallow boundary rule says which zones a zone can import from. All other imports between zones are violations. For example, this dependency-cruiser rule forbids an import from src/ui into src/db:

{
  "forbidden": [
    {
      "name": "ui-not-to-db",
      "severity": "error",
      "from": { "path": "^src/ui" },
      "to": { "path": "^src/db" }
    }
  ]
}

In fallow, give each directory a zone, and list the zones that ui can import from:

{
  "boundaries": {
    "zones": [
      { "name": "ui", "patterns": ["src/ui/**"] },
      { "name": "db", "patterns": ["src/db/**"] },
      { "name": "shared", "patterns": ["src/shared/**"] }
    ],
    "rules": [
      { "from": "ui", "allow": ["shared"] }
    ]
  }
}

Fallow patterns are globs, not regular expressions. A file that matches no zone has no restriction. For common layouts, start from a preset. To give each feature directory its own zone, like a dependency-cruiser rule with $1 group matching, see Auto-discovered feature zones.

Orphans and unused files

dependency-cruiser reports an orphan when a module has no incoming dependencies and no outgoing dependencies. Fallow reports an unused file when no entry point reaches it. Fallow finds entry points from package.json, from scripts, and from the built-in framework plugins. So the two checks find different files:

  • A file that nothing imports, but that imports other files, is not an orphan. Fallow reports it when it is not an entry point.
  • A file that nothing imports and that imports nothing is an orphan. Fallow does not report it when it is an entry point.
  • A group of files that only import each other has no orphans. Fallow reports the group when no entry point reaches it.

What dependency-cruiser does better

  • Rule conditions. A rule can match on dependency types (for example npm-dev or type-only), on dynamic imports, on licenses, on reachability, on the number of dependents, and on module stability. Fallow boundaries match on the zone of the source file and the zone of the target file. The one dependency-type condition is allowTypeOnly, which allows type-only imports from a zone that is not in allow.
  • Regular expressions with group matching. A rule can capture part of the from path and reuse it in the to path with $1. Fallow has auto-discovered feature zones for the common case, but no general group matching.
  • Required dependencies. A required rule says that a module must depend on another module. Fallow has no such rule.
  • Cycle filters. A circular rule can use via and viaOnly to match only some cycles. Fallow reports every import cycle, and you can ignore lazy imports or suppress one cycle with a comment.
  • Reporters. dependency-cruiser writes text, err, JSON, CSV, HTML, DOT, and Mermaid. Fallow draws the graph with fallow viz as HTML, DOT, or Mermaid, and writes findings as JSON, SARIF, CodeClimate, and other formats. Fallow has no CSV output.
  • More languages. dependency-cruiser also reads CoffeeScript and LiveScript.

What fallow adds

  • No rules to write for the basics. Fallow reports cycles, unresolved imports, and unlisted dependencies with no config.
  • Unused code. Fallow reports unused files, exports, types, dependencies, enum members, and class members, and fallow fix can remove some of them. See Auto-fix.
  • Framework entry points. Built-in plugins find the entry points of frameworks such as Next.js and Vite, so fallow knows which files are used.
  • Forbidden calls and rule packs. Fallow can also forbid calls and imports with rule packs.
  • More analyses in one run. Fallow also reports duplication and complexity hotspots.

Move a dependency-cruiser check to fallow

A typical CI step runs dependency-cruiser on the source directory and fails on an error rule. To check the same kinds of problems with fallow, run:

fallow architecture       # Import cycles and boundary violations
fallow dead-code          # Unused files, unresolved imports, and dependency findings

To adopt the checks on a codebase that already has findings, save a baseline first. See Baselines. Fallow does not report the dependency-cruiser config file as unused. When dependency-cruiser is a dependency, the built-in dependency-cruiser plugin marks .dependency-cruiser.js, .cjs, .mjs, and .json as used.

See also