OverviewFilesCommitsIssuesDocsReleasesPeers

codetree / lib / traverse.js

25 lines · javascript ref:
import { scanStream } from './scan-stream.js'
import { TreeReducer } from './reducers/tree-reducer.js'

/**
 * walkGraph — build a graph of modules and files for a project root.
 *
 * This is now a thin wrapper around scan-stream + TreeReducer. The returned
 * shape is identical to the pre-refactor API so existing consumers (buildTree,
 * tests) keep working unchanged.
 *
 * Callers who want push-based incremental updates should use scanStream()
 * directly and attach their own reducer/listener.
 *
 * Returns: { modules, files, root, dirTree, projectType, languages, resolutionContext }
 */
export async function walkGraph (rootDir, opts = {}) {
  return new Promise((resolve, reject) => {
    const source = scanStream(rootDir, opts)
    const tree = new TreeReducer().attach(source)

    source.once('scan-end', () => resolve(tree.finalize()))
    source.once('error', reject)
  })
}