3

I want to print a Javascript dependency graph using madge. It prints all dependencies of a given file successfully. Unfortunately, it skips the imported .ts files and subsequently does not show them in the graph.

Here is my config (.madgerc):

{
    "fileExtensions": ["js", "ts"],
    "tsConfig": "./tsconfig.json",
    "graphVizOptions": {
        "G": {
            "splines": "ortho"
        }
    }
}

Here is my tsconfig.json:

{
  "compilerOptions": {
    "esModuleInterop": true,
    "allowJs": true,
    "preserveConstEnums": true,
    "module": "commonjs",
    "target": "ES2018",
    "moduleResolution": "node",
    "noEmit": true,
    "rootDir": "../"
  }
}

I run madge like so:

madge src/main/path/to/file/view-model.js --warning --debug -i ~/Desktop/graph/view-model.png

It prints:

✔ Image created at /Users/patrick/Desktop/graph/view-model.png

✖ Skipped 1 file

./transform-sponsor

transform-sponsor is imported in my Javascript file like so:

const {transformSponsors} = require('./transform-sponsor');

So my question is, why does madge skip my typescript file. Even though I specifically added a tsconfig file as explained in the documentation?

Patrick
  • 1,728
  • 2
  • 17
  • 30

2 Answers2

2

Just add --extensions ts to the runned script

Jöcker
  • 5,281
  • 2
  • 38
  • 44
0

In my experience madge process JavaScript - Files much better then Typescript files. The solution for me was to use madge on the transpiled JavaScript - Files rather than on the original Typescript - src - Files.

I don't really know the answer to your question but I assume that madge is made originally for JavaScript - Files and TypeScript is just a superset of JavaScript thus not so important for the madge - developers (Please don't throw bananas at me when it's not true)

Matthias Gwiozda
  • 505
  • 5
  • 14