MCPcopy
hub / github.com/npmx-dev/npmx.dev / flattenFileTree

Function flattenFileTree

server/utils/import-resolver.ts:10–25  ·  view source on GitHub ↗
(tree: PackageFileTree[])

Source from the content-addressed store, hash-verified

8 * Flatten a nested file tree into a set of file paths for quick lookups.
9 */
10export function flattenFileTree(tree: PackageFileTree[]): FileSet {
11 const files = new Set<string>()
12
13 function traverse(nodes: PackageFileTree[]) {
14 for (const node of nodes) {
15 if (node.type === 'file') {
16 files.add(node.path)
17 } else if (node.children) {
18 traverse(node.children)
19 }
20 }
21 }
22
23 traverse(tree)
24 return files
25}
26
27/**
28 * Normalize a path by resolving . and .. segments

Callers 3

[...pkg].get.tsFile · 0.85

Calls 1

traverseFunction · 0.70

Tested by

no test coverage detected