dependency_graph 0.1.0
dependency_graph: ^0.1.0 copied to clipboard
Who imports whom in a Dart package or pub workspace, and which pub libraries it pulls in: one interactive HTML page of graphs.
[Frame]
πΈοΈ Dependency Graph #
A Dart command-line tool that shows who imports whom in a Dart package or a pub workspace β and which pub libraries it pulls in β as one interactive HTML page.
[Packages]
π Features #
- π¦ Packages graph β one node per package, edges weighted by the number of directives
- π Package graph β its files boxed by folder, every neighbour package as one node
- ποΈ All files graph β every file, boxed by package and folder
- π External libraries β every library
pubspec.lockdownloaded, with its version and who imports it - π΄ Packages that depend on each other are marked red
- π§² Live physics, Obsidian-style β drag a node and its neighbours follow
- ποΈ Adjustable forces β center, repel, link force, link distance, damping
- π Light and dark theme, following the system
π Installation #
In a project (as dev dependency) #
dart pub add -d dependency_graph
Or manually in pubspec.yaml:
dev_dependencies:
dependency_graph: ^0.1.0
Globally #
dart pub global activate dependency_graph
Then run as:
dependency_graph [root] [out.html]
π Usage #
dart run dependency_graph [root] [out.html]
Arguments #
| Argument | Description | Default |
|---|---|---|
root |
The package or workspace root | . |
out.html |
Where to write the page | <root>/build/dependency_graph/index.html |
-h, --help |
Print usage information |
Run dart pub get first, so pubspec.lock lists the external libraries. The page loads Cytoscape.js and d3 from a CDN, so it needs a network connection to open.
π― Views #
Packages #
One node per package, sized by its file count. Packages are coloured by the folder they sit in (apps, packages), split by a name prefix several packages share (feature_*). Tick external libraries to add the pub packages the code imports.
What it shows:
- π How many directives go from one package to another
- π΄ Packages that import each other
- π Every downloaded library, and the ones the code actually imports
Package #
Double-click a package to open it: its files boxed by folder, and each package it touches as one node.
[Package]
What it shows:
- β‘οΈ What the package depends on, and how much
- β¬ οΈ Who uses it
- π Which external libraries it imports
Click any node to highlight its edges: outgoing in orange, incoming in blue. Dashed edges are export, dotted are part.
Forces #
Open the Forces panel to tune the physics. The settings are kept in the browser; Reset brings back the defaults.
[Forces]
| Slider | Effect |
|---|---|
| Center | Pull towards the middle |
| Repel | How hard nodes push each other away |
| Link force | Stiffness of the edges β lower is softer |
| Link distance | Length of the edges |
| Damping | How fast the motion settles |
Views above 600 nodes keep still; untick and tick physics to run it there anyway.
π‘ As a library #
import 'dart:io';
import 'package:dependency_graph/dependency_graph.dart';
void main() {
final graph = scan(Directory('.'));
File('graph.html').writeAsStringSync(render(graph));
}
scan returns plain data β packages, files, edges, external, uses β if you'd rather feed it to something else.