@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
stringAbsolute path to project root
§options?
BuildGraphOptionsConfiguration 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
DependencyGraphDependency 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
stringProject 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
§maxDepth?:numberMaximum depth to traverse
§includeExternal?:booleanInclude node_modules imports
§extensions?:string[]File extensions to analyze
§interface

CircularDependency

Circular dependency information.
Properties
§cycle:string[]Ordered list of files in cycle
§length:numberCycle length
§interface

ProjectDependencies

Project dependencies categorized.
Properties
§runtime:string[]Production dependencies
§development:string[]Development dependencies
§peer:string[]Peer dependencies
§optional:string[]Optional dependencies
§total:numberTotal count