Create graphs from module dependencies.
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Full-featured CLI for dependency analysis from the command line. Includes options for output formatting, filtering, and visualization.
npm install -g madgemadge [options] <src...>The CLI accepts one or more source files or directories to analyze.
Usage Examples:
# Analyze single file
madge src/app.js
# Analyze multiple files
madge src/app.js src/utils.js
# Analyze directory
madge src/
# Analyze multiple directories
madge src/ lib/Options for controlling what dependencies to analyze and include.
-b, --basedir <path> # Base directory for resolving paths
-x, --exclude <regexp> # Exclude modules using RegExp
--extensions <list> # Comma separated string of valid file extensions
--include-npm # Include shallow NPM modules
--require-config <file> # Path to RequireJS config
--webpack-config <file> # Path to webpack config
--ts-config <file> # Path to typescript configUsage Examples:
# Set base directory
madge --basedir /project/root src/
# Exclude node_modules
madge --exclude '^node_modules' src/
# Include specific file extensions
madge --extensions js,jsx,ts,tsx src/
# Include NPM dependencies
madge --include-npm src/
# Use TypeScript config
madge --ts-config tsconfig.json src/Options for controlling how results are displayed.
-j, --json # Output as JSON
-s, --summary # Show dependency count summary
--no-color # Disable color in output and image
--no-spinner # Disable progress spinner
--warning # Show warnings about skipped files
--debug # Turn on debug outputUsage Examples:
# JSON output
madge --json src/
# Summary with counts
madge --summary src/
# Disable colors
madge --no-color src/
# Show warnings
madge --warning src/Options for specific types of dependency analysis.
-c, --circular # Show circular dependencies
-d, --depends <name> # Show module dependents
--orphans # Show modules that no one is depending on
--leaves # Show modules that have no dependencies
--no-count # Disable circular dependencies countingUsage Examples:
# Find circular dependencies
madge --circular src/
# Find what depends on a specific module
madge --depends utils.js src/
# Find orphaned modules
madge --orphans src/
# Find leaf modules (no dependencies)
madge --leaves src/Options for generating visual graphs and DOT output.
-i, --image <file> # Write graph to file as an image
--dot # Show graph using the DOT language
-l, --layout <name> # Layout engine to use for graph (dot/neato/fdp/sfdp/twopi/circo)
--rankdir <direction> # Set the direction of the graph layoutUsage Examples:
# Generate SVG image
madge --image graph.svg src/
# Generate PNG image
madge --image graph.png src/
# Generate DOT output
madge --dot src/ > graph.gv
# Use different layout engine
madge --layout neato --image graph.svg src/
# Change graph direction
madge --rankdir TB --image graph.svg src/
# Generate image with only circular dependencies
madge --circular --image circular.svg src/The CLI supports multiple input methods.
--stdin # Read predefined tree from STDINUsage Example:
# Pipe dependency tree via STDIN
echo '{"a.js": ["b.js"], "b.js": []}' | madge --stdin --jsonMadge supports configuration via .madgerc or package.json.
{
"fontSize": "10px",
"graphVizOptions": {
"G": {
"rankdir": "LR"
}
},
"excludeRegExp": ["test", "spec"],
"fileExtensions": ["js", "jsx", "ts", "tsx"]
}{
"name": "my-project",
"madge": {
"fontSize": "10px",
"backgroundColor": "#ffffff",
"nodeColor": "#000000"
}
}The CLI uses standard exit codes:
--circular option)┌────────────────────┐
│ Dependency graph │
└────────────────────┘
src/app.js
src/utils.js
src/api.js
src/api.js
src/config.js
src/utils.js
(no dependencies)
src/config.js
(no dependencies)
✔ Processed 4 files (12ms)madge --json src/{
"src/app.js": ["src/utils.js", "src/api.js"],
"src/api.js": ["src/config.js"],
"src/utils.js": [],
"src/config.js": []
}madge --circular src/✖ Found 2 circular dependencies!
1) src/a.js > src/b.js > src/a.js
2) src/x.js > src/y.js > src/z.js > src/x.jsmadge --summary src/┌─────────────────────────────────────┐
│ Dependency Summary │
├─────────────────────────────────────┤
│ Total files │ 12 │
│ Total dependencies │ 23 │
│ Circular dependencies │ 2 │
│ Orphaned files │ 1 │
└─────────────────────────────────────┘brew install graphvizapt-get install graphviz