@hyperfrontend/project-scope/heuristics/dependencies

dependencies

Internal source-code dependency graph construction, circular-dependency detection, and package.json dependency categorization.

buildDependencyGraph walks source files extracting import, import(), require, and export-from specifiers via regex, resolving relative paths to graph nodes with dependencies/dependents edges and identifying roots (uncalled) and leaves (no outbound deps). findCircularDependencies performs DFS cycle detection and returns ordered cycle paths. getProjectDependencies categorizes package.json entries into runtime, development, peer, and optional buckets with totals.

API Reference

ƒ Functions

§function

buildDependencyGraph(projectPath: string, options?: BuildGraphOptions): DependencyGraph

Build dependency graph from source files.
Analyzes imports/exports in source files to build a graph of internal dependencies.

Parameters

NameTypeDescription
§projectPath
string
Absolute path to project root
§options?
BuildGraphOptions
Configuration for graph building

Returns

DependencyGraph
Dependency graph with nodes, roots, and leaves

Example

Building a dependency graph

import { buildDependencyGraph } from '@hyperfrontend/project-scope'

const graph = buildDependencyGraph('./my-lib')
console.log('Root files:', graph.roots)   // Files not imported by anything
console.log('Leaf files:', graph.leaves)  // Files that don't import anything
console.log('Total nodes:', graph.nodes.size)

// Examine a specific node's dependencies
const node = graph.nodes.get('src/utils/helper.ts')
console.log('Depends on:', node?.dependencies)
console.log('Used by:', node?.dependents)
§function

findCircularDependencies(graph: DependencyGraph): CircularDependency[]

Find circular dependencies in graph using DFS.

Parameters

NameTypeDescription
§graph
DependencyGraph
Dependency graph

Returns

CircularDependency[]
Array of circular dependencies found

Example

Finding circular dependencies

import { buildDependencyGraph, findCircularDependencies } from '@hyperfrontend/project-scope'

const graph = buildDependencyGraph('/workspace')
const cycles = findCircularDependencies(graph)
cycles.forEach(c => console.log(`Cycle: ${c.cycle.join(' -> ')}`))
§function

getProjectDependencies(projectPath: string): ProjectDependencies

Collect all dependencies from package.json grouped by category.

Parameters

NameTypeDescription
§projectPath
string
Project directory

Returns

ProjectDependencies
Dependencies grouped by runtime, dev, peer, and optional

Example

Getting project dependencies

import { getProjectDependencies } from '@hyperfrontend/project-scope'

const deps = getProjectDependencies('/path/to/project')
console.log('Runtime:', deps.runtime)     // ['express', 'lodash']
console.log('Dev:', deps.development)     // ['jest', 'typescript']
console.log('Total:', deps.total)         // 15

Interfaces

§interface

BuildGraphOptions

Options for dependency graph building.

Properties

§extensions?:string[]
File extensions to analyze
§includeExternal?:boolean
Include node_modules imports
§maxDepth?:number
Maximum depth to traverse
§interface

CircularDependency

Circular dependency information.

Properties

§cycle:string[]
Ordered list of files in cycle
§length:number
Cycle length
§interface

ProjectDependencies

Project dependencies categorized.

Properties

§development:string[]
Development dependencies
§optional:string[]
Optional dependencies
§peer:string[]
Peer dependencies
§runtime:string[]
Production dependencies
§total:number
Total count