检测项目中的循环依赖 [英] Detect circular dependencies in project

查看:72
本文介绍了检测项目中的循环依赖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

上次我在我的项目中发现循环依赖问题.我解决了我的问题,但我希望将来避免这种情况.我想到了在我的所有项目中发现循环依赖并给我反馈的插件.

Last time i found in my project problem with circular dependencies. I resolve my problem but, i would like avoid this in future. I think about plugin which found circular dependencies in my all project and give me feedback.

示例:

文件 a.js:

var functionFromA= require("./b.js");
console.log("file a", functionFromA);
module.exports = {functionFromA: functionFromA};

文件 b.js:

var functionFromB = require("./c.js");
console.log("file b", functionFromB );
module.exports = {functionFromB : functionFromB };

文件 c.js:

var functionFromC = require("./a.js");
console.log("file c", functionFromC );
module.exports = {functionFromC : functionFromC }

当我运行文件 a.js 时,我在控制台看到:
文件 c {}
文件 b { functionFromC: {} }
文件 a { functionFromB: { functionFromC: {} } }

When i run file a.js i see in console:
file c {}
file b { functionFromC: {} }
file a { functionFromB: { functionFromC: {} } }

我在 npm 中找到了循环依赖插件",但我不知道如何使用它?可能有人遇到了类似的问题并找到了解决方案?

I found "Circular Dependency Plugin" in npm but i don't know how use it? May be someone has similar problem and found a solution?

推荐答案

您会发现这个其他工具很有用:https://www.npmjs.com/package/madge

You can find this other tool useful: https://www.npmjs.com/package/madge

非常易于使用:madge --circular [directory] 为您提供位于 [directory] 内的代码中循环依赖项的列表.它还可以生成图形图像.

is very easy to use: madge --circular [directory] give you a list of circular dependencies in your code located inside [directory]. It can also generate a graph image.

这篇关于检测项目中的循环依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆