Imports Analyzer¶
The imports analyzer extracts import and dependency information from source code using UAST parsing. It operates in both static mode (single-file analysis) and history mode (tracking import usage per developer over time).
Quick Start¶
Architecture (History Mode)¶
The imports history analyzer follows the TC/Aggregator pattern:
- Consume phase: For each commit,
Consume()extracts imports from changed files via parallel UAST parsing and returns them asTC{Data: []ImportEntry}. EachImportEntrycarries a language and import path. The analyzer retains no per-commit state; only the UAST parser is kept as working state. - Aggregation phase: An
imports.Aggregatorcollects TCs into a 4-levelMap(author -> language -> import -> tick -> count) usingSpillStore[Map]. TheAuthorIDandTickfrom each TC index the entries correctly. - Serialization phase:
SerializeTICKs()merges all tick data back into the fullMapwith metadata (author_index,tick_size), then delegates toSerialize()for JSON, YAML, binary, or HTML plot output.
This separation enables streaming output, budget-aware memory spilling, and decoupled aggregation.
What It Measures¶
Static Mode¶
- Import list: All imports/dependencies declared in each file
- Language detection: Automatically detects the language and normalizes import paths
- Dependency graph: Maps which files depend on which packages
History Mode¶
Tracks import usage across Git history, producing a per-developer, per-language, per-tick breakdown of which dependencies each developer introduces or modifies. This reveals:
- Dependency adoption timeline: When new libraries were introduced
- Developer expertise signals: Which developers work with which dependencies
- Technology spread: How quickly new dependencies propagate across the team
Configuration Options¶
Static Mode¶
No configuration options. Uses UAST directly.
History Mode¶
| Option | Type | Default | Description |
|---|---|---|---|
Imports.Goroutines | int | 4 | Number of parallel goroutines for import extraction |
Imports.MaxFileSize | int | 1048576 | Maximum file size in bytes; larger files are skipped |
Set options via the configuration file:
Example Output¶
Use Cases¶
- Dependency auditing: List all third-party dependencies used in a project.
- Developer profiling: Understand which developers work with which frameworks and libraries.
- Technology adoption tracking: Monitor when and how quickly new dependencies spread across the team.
- License compliance: Extract the full dependency list for license scanning pipelines.
- Architecture enforcement: Detect unauthorized imports from forbidden packages.
Limitations¶
- Language support: Only languages with UAST parser support are analyzed. Unsupported file types are silently skipped.
- Dynamic imports: Runtime or dynamic imports (e.g., Python's
importlib.import_module(), JavaScript'simport()) are not detected since they are not present in the static UAST. - Transitive dependencies: Only direct imports are reported. The analyzer does not resolve transitive dependency trees.
- File size threshold: Files exceeding
MaxFileSize(default 1 MB) are skipped to avoid excessive memory usage during parallel extraction. - History mode overhead: History mode creates a UAST parser per fork, which increases memory usage. Tune
Goroutinesbased on available memory.