@hyperfrontend/project-scope/heuristics/dependenciesdependencies
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
Build dependency graph from source files.
Analyzes imports/exports in source files to build a graph of internal dependencies.
Analyzes imports/exports in source files to build a graph of internal dependencies.
Parameters
Returns
DependencyGraphDependency 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)Find circular dependencies in graph using DFS.
Parameters
| Name | Type | Description |
|---|---|---|
§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(' -> ')}`))Collect all dependencies from package.json grouped by category.
Parameters
| Name | Type | Description |
|---|---|---|
§projectPath | string | Project directory |
Returns
ProjectDependenciesDependencies 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
Options for dependency graph building.
Circular dependency information.