dependency_graph.ts

Dependency graph data structure and algorithms for multi-repo publishing.

Provides the DependencyGraph class, built from local repos, with topological sort (via @fuzdev/fuz_util/sort.ts), cycle detection by dependency type, and wildcard-range analysis. For the publishing order and the analysis workflow, see graph_validation.ts.

view source

Declarations
#

7 declarations

DEPENDENCY_TYPE
#

dependency_graph.ts view source

{ readonly PROD: "prod"; readonly PEER: "peer"; readonly DEV: "dev"; } import {DEPENDENCY_TYPE} from '@fuzdev/fuz_repos/dependency_graph.js';

DependencyAnalysis
#

dependency_graph.ts view source

DependencyAnalysis import type {DependencyAnalysis} from '@fuzdev/fuz_repos/dependency_graph.js';

Cycles and wildcard dependencies found by DependencyGraph.analyze.

production_cycles

type string[][]

dev_cycles

type string[][]

wildcard_deps

type { pkg: string; dep: string; version: string; }[]

DependencyGraph
#

dependency_graph.ts view source

import {DependencyGraph} from '@fuzdev/fuz_repos/dependency_graph.js';

nodes

type Map<string, DependencyNode>

edges

type Map<string, Set<string>>

constructor

Builds the graph from local repos.

Two passes: first creates nodes, then builds edges (dependents). Prioritizes prod/peer deps over dev deps when the same package appears in multiple dependency types (the stronger constraint wins).

type new (repos: LocalRepo[]): DependencyGraph

repos

type LocalRepo[]

get_node

type (name: string): DependencyNode | undefined

name

type string
returns DependencyNode | undefined

topological_sort

Computes topological sort order for dependency graph.

Delegates to @fuzdev/fuz_util/sort.ts for the sorting algorithm. Throws if cycles detected.

type (exclude_dev?: boolean): string[]

exclude_dev

if true, excludes dev dependencies to break cycles Publishing uses exclude_dev=true to handle circular dev deps.

type boolean
default false
returns string[]

array of package names in dependency order (dependencies before dependents)

throws

  • Error - if circular dependencies detected in included dependency types

detect_cycles_by_type

Detects circular dependencies, categorized by severity.

Production/peer cycles prevent publishing (impossible to order packages). Dev cycles are normal (test utils, shared configs) and safely ignored.

Uses DFS traversal with recursion stack to identify back edges. Deduplicates cycles using sorted cycle keys.

type (): { production_cycles: string[][]; dev_cycles: string[][]; }

returns { production_cycles: string[][]; dev_cycles: string[][]; }

object with production_cycles (errors) and dev_cycles (info)

analyze

Reports cycles by type and wildcard (*) dependency ranges. Tolerates cycles: it reports them rather than throwing.

type (): DependencyAnalysis

toJSON

type (): DependencyGraphJson

DependencyGraphJson
#

dependency_graph.ts view source

DependencyGraphJson import type {DependencyGraphJson} from '@fuzdev/fuz_repos/dependency_graph.js';

nodes

type { name: string; version: string; dependencies: { name: string; spec: DependencySpec; }[]; dependents: string[]; }[]

edges

type { from: string; to: string; }[]

DependencyNode
#

dependency_graph.ts view source

DependencyNode import type {DependencyNode} from '@fuzdev/fuz_repos/dependency_graph.js';

name

type string

version

type string

dependencies

type Map<string, DependencySpec>

dependents

type Set<string>

DependencySpec
#

DependencyType
#

dependency_graph.ts view source

DependencyType

type "prod" | "peer" | "dev"

import type {DependencyType} from '@fuzdev/fuz_repos/dependency_graph.js';

Depends on
#

Imported by
#