Skip to Content
vitus·labs
Tools Atlas

API Reference

Complete API reference for @vitus-labs/tools-atlas.

Exports

import { generateAtlas } from '@vitus-labs/tools-atlas'

import type {
  AnalysisData,
  AtlasConfig,
  BundleSizeResult,
  ChangeFrequencyResult,
  CycleResult,
  DepEdge,
  DepGraph,
  DepNode,
  DepType,
  DepthResult,
  HealthScoreResult,
  ImpactResult,
  VersionDriftResult,
} from '@vitus-labs/tools-atlas'

The package also ships the vl_atlas binary — see CLI Options.

generateAtlas()

generateAtlas(config: AtlasConfig): Promise<RenderResult>

Scans the workspace (relative to process.cwd()), runs every analysis, writes the HTML page and the requested reports, optionally opens the HTML, and logs a short summary to the console.

interface RenderResult {
  htmlPath: string        // absolute path of the written HTML file
  reportPath?: string     // primary report (markdown when both formats are written)
  reportPaths?: string[]  // every report file written
}

RenderResult is not exported as a type. generateAtlas() throws if config.report is not true, false, 'markdown' or 'json'.

AtlasConfig

type DepType = 'dependencies' | 'devDependencies' | 'peerDependencies'

interface AtlasConfig {
  workspaces: string[]
  depTypes: DepType[]
  include: string[]
  exclude: string[]
  outputPath: string
  echartsCdn: string
  open: boolean
  title: string
  report: boolean | 'json' | 'markdown'
}

All fields are required when calling generateAtlas() directly. The defaults below are applied only by the vl_atlas CLI (merged with the atlas key of vl-tools.config.mjs).

FieldCLI defaultDescription
workspaces['packages/*']Workspace globs; !-prefixed patterns exclude
depTypes['dependencies', 'peerDependencies', 'devDependencies']Dependency fields that create edges
include[]Package-name patterns to keep (* wildcard, otherwise exact match)
exclude[]Package-name patterns to drop (* wildcard, otherwise exact match)
outputPath'./atlas.html'HTML output path
echartsCdn'https://cdn.jsdelivr.net/npm/echarts@5.6.1/dist/echarts.min.js'ECharts script URL; SRI integrity only for the default
opentrueOpen the HTML after writing
title'Atlas — Dependency Graph'Page title
report'markdown''markdown', 'json', true (both) or false (none)

Graph types

interface DepNode {
  name: string
  version: string    // '0.0.0' when package.json has no version
  path: string       // absolute package directory
  private: boolean
}

interface DepEdge {
  source: string     // dependent package name
  target: string     // dependency package name (always a workspace package)
  /** Strongest dep type for this edge (dependencies > peer > dev). */
  depType: DepType
  /** Every dep type this source -> target relation appears under. */
  depTypes?: DepType[]
}

interface DepGraph {
  nodes: DepNode[]
  edges: DepEdge[]
}

Packages without a name in package.json are skipped. Only dependencies on other scanned workspace packages become edges.

Analysis result types

interface CycleResult {
  cycles: string[][]   // each cycle normalized to start at its smallest name
  hasCycles: boolean
}

interface ImpactResult {
  impactMap: Record<string, string[]>  // package -> sorted transitive dependents
}

interface DepthResult {
  depthMap: Record<string, number>     // longest chain length (cycle edges ignored)
  criticalPath: string[]               // packages along the deepest chain
  maxDepth: number
}

interface BundleSizeResult {
  // bytes on disk of lib/; transitive = own + reachable workspace deps
  sizeMap: Record<string, { libSize: number; transitiveSize: number }>
}

interface VersionDriftResult {
  // external deps declared with more than one range: range -> packages
  drifts: { dependency: string; versions: Record<string, string[]> }[]
  hasDrifts: boolean
}

interface HealthScoreResult {
  scores: Record<string, { score: number; factors: string[] }>
}

interface ChangeFrequencyResult {
  // commits in the last 90 days; lastChanged is an ISO 8601 commit date
  frequencyMap: Record<string, { commits: number; lastChanged: string }>
  hotspots: string[]   // >= 3 dependents and >= 10 commits
}

interface AnalysisData {
  graph: DepGraph
  cycles: CycleResult
  impact: ImpactResult
  depth: DepthResult
  bundleSize: BundleSizeResult
  versionDrift: VersionDriftResult
  healthScore: HealthScoreResult
  changeFrequency: ChangeFrequencyResult | null  // null outside a git repo
}

Health score factors

Factor stringEffect
in N cycle(s)−20 per cycle, max −40
no dependents (orphan)−15 (only when there is more than one package)
deep chain (depth N)−10 when depth > 3
N version drift(s)−5 per drifted dependency, max −20
healthyNo penalties applied

Bonuses (not listed as factors): +5 per transitive dependent (max +20) and +5 if the package changed in the last 90 days. The final score is clamped to 0–100.

Report JSON

When report is 'json' or true, <output>-report.json has this shape (the type itself is internal):

interface ReportJson {
  summary: { packages: number; edges: number; cycles: number; maxDepth: number }
  cycles: { cycle: string[]; suggestion: string }[]
  highImpact: { name: string; directDeps: number; transitiveDependents: number }[]
  deepChains: { path: string[]; depth: number; suggestion: string }[]
  orphans: string[]
  depTypeDistribution: Record<DepType, number>
  versionDrift: {
    dependency: string
    versions: Record<string, string[]>
    suggestion: string
  }[]
  bundleSize: { name: string; ownSize: number; transitiveSize: number }[]
  healthScores: { name: string; score: number; factors: string[] }[]
  hotspots: { name: string; commits: number; dependents: number }[]
}
  • highImpact — packages with at least one transitive dependent, most impactful first
  • deepChains — packages with depth > 3, deepest first
  • bundleSize — sorted by transitive size, largest first
  • healthScores — sorted by score, lowest first
  • depTypeDistribution — counts every dep type of every edge
Edit on GitHub

Last updated on

On this page