dependency-cruiser

sverweijMIT活跃维护

校验并可视化 JavaScript、TypeScript 等项目的模块依赖,按自定义规则拦截循环依赖和违规引用,把架构约束变成可执行的检查。

Validate and visualize dependencies. Your rules. JavaScript, TypeScript, CoffeeScript. ES6, CommonJS, AMD.

v18.7.2发布于 2026-11-02 21:21 UTC7,399star +10 / 7 天310fork同步于 2026-11-10 17:33 UTC

怎么上手

由 README 提炼,执行前请确认
npm install --save-dev dependency-cruiser
npx dependency-cruiser --init
硬件要求按 README 说明

README 未说明

下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

用自定义规则校验并可视化 JS/TS 项目依赖,提前发现循环依赖和越界引用

校验并可视化 JavaScript、TypeScript 等项目的模块依赖,按自定义规则拦截循环依赖和违规引用,把架构约束变成可执行的检查。

核心能力

  • 按自定义规则校验依赖并报告违规项
  • 检测循环依赖、缺失依赖、孤儿模块等问题
  • 输出 dot、mermaid、json、csv、html 等多种格式
  • 支持 JS、TS、CoffeeScript、LiveScript 及 ES6/CommonJS/AMD
  • 内置 --init 交互式生成项目专属配置文件

容易踩的坑

生成 dot 图需额外安装 GraphViz 的 dot 命令;v12 及更早版本需手动传 --config 才能找到配置文件;pnpx 语义与 npx 差异较大,使用前需留意

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

5 个版本v18.7.2
  1. v18.7.2最新正式版2026-11-02 · 2026-11-02 21:21 UTC

    🐛 fixes

    • e65bb5b4 fix(extract/resolve): adds correctly handling 'bundledDependencies: true' (#1120) thanks to @sebdanielsson for finding and filing the issue that led to this fix.

    👷 maintenance

    • 4e2daa02 fix(manifest): updates contributor list with recent contributors
    • a37c1cf6 chore(test): bumps minimum branch coverage up to current HWM
    • 1ecdae89 build(npm): updates external dependencies
  2. v18.8.0-beta-2pre-release2026-11-01 · 2026-11-01 23:49 UTC
    查看更新说明

    ✨ features

    • 0b8b47d4 feat(extract): adds support for typescript >=7.1 (the native compiler) [AI] - thanks to @buko106 for the pull request

    This release updates the beta with fixes done in the main branch (npm: latest tag) in 18.7.1, which, for completeness sake are:

    🐛 fixes

    • 2a46eecf fix(main/resolve-options): resolves tsconfig paths without baseUrl from the tsconfig directory (#1116) Thanks to @thirtytwobits for raising the issue and @Johannes7549 for making the fixing pull request!
    • fd7889bf fix(extract/transpile): passes the file name to the typescript transpiler to prevent it choking on imports from './module' (#1118). Thanks to @sebdanielsson for reporting the issue, finding the root cause and baking the fixing PR!

    👷 maintenance

    • 00ca161c build(npm): updates external dependencies
    • 96a1dd35 doc(README): removes broken link
    • c5b97371 chore(npm): refreshes lock-file
    • dbe5e74e chore(Gort): makes agent instruction even more explicit
    • 5adda5b2 chore(gha): replaces last remnant of yarn with node --run
    • deea6a17 doc: corrects type references in jsdoc
  3. v18.7.12026-11-01 · 2026-11-01 23:37 UTC
    查看更新说明

    🐛 fixes

    • 2a46eecf fix(main/resolve-options): resolves tsconfig paths without baseUrl from the tsconfig directory (#1116) Thanks to @thirtytwobits for raising the issue and @Johannes7549 for making the fixing pull request!
    • fd7889bf fix(extract/transpile): passes the file name to the typescript transpiler to prevent it choking on imports from './module' (#1118). Thanks to @sebdanielsson for reporting the issue, finding the root cause and baking the fixing PR!

    👷 maintenance

    • 00ca161c build(npm): updates external dependencies
    • 96a1dd35 doc(README): removes broken link
    • c5b97371 chore(npm): refreshes lock-file
    • dbe5e74e chore(Gort): makes agent instruction even more explicit
    • 5adda5b2 chore(gha): replaces last remnant of yarn with node --run
    • deea6a17 doc: corrects type references in jsdoc

    Note for those eagerly awaiting typescript 7.1 support - thanks to @buko106 there's a dependency-cruiser (beta) version that works with typescript 7.1 beta . The fixes in this (18.7.1) release combined with 7.1 beta support will be published as 18.8.0-beta-2.

  4. v18.8.0-beta-1pre-release2026-10-23 · 2026-10-23 18:23 UTC
    查看更新说明

    ✨ features

    • 0b8b47d4 feat(extract): adds support for typescript >=7.1 (the native compiler) [AI] - thanks to @buko106 for the pull request
  5. v18.7.02026-10-19 · 2026-10-19 19:43 UTC
    查看更新说明

    ✨ features

    • 6ae13a39 feat(summarize): makes the missing compiler warnings more precise (#1111) This a.o. makes dependency-cruiser stop reporting a missing typescript compiler even when swc was installed (and swc was sufficient for the configured features). Thanks @duvillierA for raising the issue!

    🐛 fixes

    • da0efbb4 fix(extract/resolve): disregards peerDependenciesMeta and similar actual non-dependencies keys to prevent false positives (#1110). Thanks @arvidtorbjoernsen for reporting the issue that led to this fix!
    • c580daf6 fix(extract/swc): expands extensions swc can handle to all ts* variants (#1105) Thanks @duvillierA for raising the issue and for providing the fix that landed in the PR!
    • 9d53b95a fix(extract/swc): adds recognition of type-only-ness of exports (#1106). Thanks @duvillierA for raising the issue and for providing the fix that landed in the PR!

    📖 documentation

    • 8b4dbdee docs: fix typo in no-duplicate-dep-types comment (#1108) Thanks @Samathingamajig for the PR!

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    Dependency cruiser Dependency cruiser

    Validate and visualise dependencies. With your rules. JavaScript. TypeScript. CoffeeScript. ES6, CommonJS, AMD.

    What's this do?

    Snazzy dot output to whet your appetite

    This runs through the dependencies in any JavaScript, TypeScript, LiveScript or CoffeeScript project and ...

    • ... validates them against (your own) rules
    • ... reports violated rules
      • in text (for your builds)
      • in graphics (for your eyeballs)

    As a side effect it can generate dependency graphs in various output formats including cool visualizations you can stick on the wall to impress your grandma.

    How do I use it?

    Install it ...

    npm install --save-dev dependency-cruiser
    # or
    yarn add -D dependency-cruiser
    pnpm add -D dependency-cruiser
    

    ... and generate a config

    npx dependency-cruiser --init
    

    This will look around in your environment a bit, ask you some questions and create a .dependency-cruiser.js configuration file attuned to your project12.

    Show stuff to your grandma

    To create a graph of the dependencies in your src folder, you'd run dependency cruiser with output type dot and run GraphViz dot3 on the result. In a one liner:

    npx dependency-cruiser src --include-only "^src" --output-type dot | dot -T svg > dependency-graph.svg
    

    While not necessary from dependency-cruiser v13 and later, in v12 and older you'll have to pass the --config option to make it find the .dependency-cruiser.js configuration file:

    npx dependency-cruiser src --include-only "^src" --config --output-type dot | dot -T svg > dependency-graph.svg
    
    • You can read more about what you can do with --include-only and other command line options in the command line interface documentation.
    • Real world samples contains dependency cruises of some of the most used projects on npm.
    • If your grandma is more into formats like mermaid, json, csv, html or plain text we've got her covered as well.

    Validate things

    Declare some rules

    When you ran dependency-cruiser --init above, the command also added some rules to .dependency-cruiser.js that make sense in most projects, like detecting circular dependencies, dependencies missing in package.json, orphans, and production code relying on dev- or optionalDependencies.

    Start adding your own rules by tweaking that file.

    Sample rule:

    {
      "forbidden": [
        {
          "name": "not-to-test",
          "comment": "don't allow dependencies from outside the test folder to test",
          "severity": "error",
          "from": { "pathNot": "^test" },
          "to": { "path": "^test" }
        }
      ]
    }
    
    Report them
    npx dependency-cruiser src
    

    While not necessary from dependency-cruiser v13, in v12 and older you'll have to pass the --config option to make it find the .dependency-cruiser.js configuration file:

    npx dependency-cruiser --config .dependency-cruiser.js src
    

    This will validate against your rules and shows any violations in an eslint-like format:

    sample err output

    There's more ways to report validations; in a graph (like the one on top of this readme) or in an self-containing html file.

    • Read more about the err, dot, csv and html reporters in the command line interface documentation.
    • dependency-cruiser uses itself to check on itself in its own build process; see the depcruise script in the package.json

    I want to know more!

    You've come to the right place :-) :

    License

    MIT

    Thanks

    • Marijn Haverbeke and other people who collaborated on acorn - the excellent JavaScript parser dependency-cruiser uses to infer dependencies.
    • Katerina Limpitsouni of unDraw for the ollie in dependency-cruiser's social media image.
    • All members of the open source community who have been kind enough to raise issues, ask questions and make pull requests to get dependency-cruiser to be a better tool.

    Build status

    GitHub Workflow Status total downloads on npm

    Made with :metal: in Holland.

    Footnotes

    1. We're using npx in the example scripts for convenience. When you use the commands in a script in package.json it's not necessary to prefix them with npx. ↩

    2. If you don't want to use npx, but instead pnpx (from the pnpm package manager) or yarn - please refer to that tool's documentation. Particularly pnpx has semantics that differ from npx quite significantly and that you want to be aware of before using it. In the meantime: npx should work even when you installed the dependency with a package manager different from npm. ↩

    3. This assumes the GraphViz dot command is available - on most linux and comparable systems this will be. In case it's not, see GraphViz' download page for instructions on how to get it on your machine. ↩