JanUnld / tsplot

Analyzes the dependencies within a typescript project and generates stats and diagrams
https://www.npmjs.com/package/tsplot
7 stars 0 forks source link

Fail the process if the mermaid max size is exceeded. #2

Closed Sebastian-G closed 2 months ago

Sebastian-G commented 2 months ago

I tried the tool to create the graph for my current project, but the mermaid could not render the results.

Example:

filename: ./tsplot.mmd
errorMessage: "Maximum text size in diagram exceeded"
lines: 4522

Is there any way to verify the size upfront and let the process fail before it creates an unusable file?

Background info:

Stats: npx tsplot stats . returns:

{
  "files": 1897,
  "members": 6228,
  "edges": 15326,
  "classes": 13,
  "interfaces": 635,
  "enums": 22,
  "types": 208,
  "functions": 673,
  "variables": 4677
}
Sebastian-G commented 2 months ago

This issue is not directly related to tsplot but can increase the developer's experience while using it.

JanUnld commented 2 months ago

Interesting 🤔. I'll take a look at it and let you know, if there's anything we can do about it.

Thanks for the feedback!

JanUnld commented 2 months ago

So I've thought a bit about possible solutions from tsplot side. There's a Mermaid directive called init or initialize which lets you configure the Mermaid rendering process from the generated Mermaid output string content.

Example

%%{init: { theme: 'neutral' }}%%
classDiagram
    Foo --> Bar

Unfortunately this won't work for most cases in which Mermaid diagrams are embedded. Due to the unsafe nature almost any platform disables it (e.g. Github or IDE Plugins).

So all we can really do here is displaying a warning message during the rendering process of tsplot which refers to the documentation of the Mermaid configuration describing how to override the default maxTextSize or maxEdges limits.

Example

WARN The generated output exceeds the default maximum text size or amount of edges. Make sure to configure
 Mermaid properly to allow rendering of larger diagrams (see https://mermaid.js.org/config/schema-docs/config.html)
 or consider refining the filter options to reduce the output diagram size (see --help)

@Sebastian-G, do you think that's a feasible enhancement to the CLI experience? Any thoughts on it are highly appreciated.

Edit: I've also added the stats output to the tsplot diagram command execution when using --debug.