
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
generate-call-graph
Advanced tools
This tiny tool is to help generate a complete module relationship graph for Node.js/Electron project.
const generate = require('generate-call-graph');
const path = require('path');
const dot = generate(require.main, {
sep: path.sep,
title: 'Title of Graph',
ignore: ['path', 'generate-call-graph'],
});
require('fs').writeFileSync('output.dot', dot, 'utf8');
Please notice that API only provides string as result. You will need graphviz to generate the final SVG/PNG graph out of this dot file. For example, run the following script:
# generate PNG version
dot -Tpng -O output.dot
# generate SVG version
dot -Tsvg -O output.dot
This package also contains a tiny utility that helps you to determine the loading time cost of each module. To use this, first load the module as early as possible (for example, load it in preload
script in Electron):
require('generate-call-graph/enhancer');
Then, you could generate a graph with time cost labeled:
const generate = require('generate-call-graph');
const path = require('path');
const dot = generate(require.main, {
sep: path.sep,
title: 'Title of Graph',
ignore: ['path', 'generate-call-graph'].map(require.resolve),
labelTime: true,
threshold: {
warn: 50,
error: 100,
},
});
require('fs').writeFileSync('output.dot', dot, 'utf8');
In the example above, it will also mark the line as orange if it costs more than 50ms to load, and mark it as red if it costs more than 100ms. Easy to illustrate the potential issue when initializing the app.
Following are possible options to modify the behavior of API:
sep
: required / string
, simply pass require('path').sep
will be enough.
This API is design to be runnable in web environment, thus need to pass environment related info (such as path.sep
from outside);
title
: required / string
, title of the generate graph.
ignore
: optional / string[]
, list of IDs that should be ignored from generating the graph. In Node.js, each module as a unique ID, which is equal to the path of that file.
labelTime
: optional / boolean
, whether or not the graph should label cost time on each line.
Please notice that: 1) one module might be loaded multiple times, only the first time will be labeled by time cost, for the rest of usages, cache will be used instead of loading it again; 2) you will need to load generate-call-graph/enhancer
utility file as early as possible to get those info beforehand.
threshold
: optional / { warn?: number; error?: number }
, the threshold to warn the loading of modules based on time cost.
Default threshold
are 50ms
for warning (orange color) and 100ms
for error (red color). You can overwrite these two thresholds using this option.
FAQs
Generate Call Graph in Node/Electron project
The npm package generate-call-graph receives a total of 6 weekly downloads. As such, generate-call-graph popularity was classified as not popular.
We found that generate-call-graph demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.