Given: a large project, organized as amd modules, which are loaded via requirejs. Some pieces are requested on-demand from inside modules by calling require.

Question: Is there a ready-made tool, or some simple (I’m ready to spend a couple of hours, but not a couple of days to write my own tool) a way to build a dependency graph of this project?

That is, I say the project’s folder or entry point, and it shows me in some kind of person-oriented manner that depends on what, taking into account possible require calls from inside define modules.

UPD: Screwed madge . The tool is working, but it requires numerous dances with a tambourine (however, this is most often associated with the graphviz library used, and with the drawbacks of the madge itself). I would be grateful for the advice of other tools.

  • one
    I have not heard about the tools, but perhaps, as a starting point, you will be helped by requirejs.s.contexts , in particular, defined - Mr. Brightside
  • @Mr.Brightside, I thought about tearing the tree straight from requirejs, but in the project, decent asynchronous require calls (routing through them), but requirejs.s.context doesn't know anything until they are executed. That is, we need exactly static analysis of some kind - Duck Learns to Take Cover
  • @ru_volt, and if you take and build AST by JS code and carefully bypass it by pulling out the necessary calls? I understand that the proposal is delusional and requires a lot of work, but suddenly it will be useful - Dmitriy Simushev
  • @DmitriySimushev, well, I guess that tulza should do it. That's why I wrote that I am not ready to spend a couple of days) Because, as the nuances pop up, as a result, you will get a couple of days. Someone, well, exactly this problem was solved before me. But I almost already ruined madge - Duck Learns to Hide

1 answer 1

One alternative to madge is dependo . (see also grunt-dependo ). It allows you to generate an HTML report of the type that uses d3js for rendering.

  • and you tried it yourself? - Duck Learns to Take Cover
  • What am I asking - I watched him having played enough with the madge, so I threw on the first "something went wrong" - Duck Learns to Hide
  • @ru_volt: I have never had any practical problems with AMD dependencies, but if necessary, React modules (.jsx), which is a slightly different task. In this case, babelify, for example, resolves all dependencies by itself and combines everything into one module at the time of assembly. If you are interested, I found another node-dependency-tree , but did not work with it myself. - Oleg
  • Right now I will explain the "grocery" problem that caused it. There is an old great legacy SPA. There was a self-made modular system, the dependencies through the modules were practically almost not described. At one point, the system was decided to rationally refactor this project. I cut the self-written modules, replaced the modules with and require with amd. And I want to see the dependencies between the modules in order to choose a target for further refactoring. - Duck Learns to Take Cover
  • Well, in general, I somehow screwed madge and at the same time I found in which open-source project I want to donate. - Duck Learns to Take Cover