MCPcopy Create free account
hub / github.com/btd/rollup-plugin-visualizer / addToPath

Function addToPath

plugin/data.ts:9–36  ·  view source on GitHub ↗
(
  moduleId: string,
  tree: ModuleTree,
  modulePath: string[],
  node: MappedNode,
)

Source from the content-addressed store, hash-verified

7}
8
9const addToPath = (
10 moduleId: string,
11 tree: ModuleTree,
12 modulePath: string[],
13 node: MappedNode,
14): void => {
15 if (modulePath.length === 0) {
16 throw new Error(`Error adding node to path ${moduleId}`);
17 }
18
19 const [head, ...rest] = modulePath;
20
21 if (rest.length === 0) {
22 tree.children.push({ ...node, name: head });
23 return;
24 } else {
25 let newTree = tree.children.find(
26 (folder): folder is ModuleTree => folder.name === head && isModuleTree(folder),
27 );
28
29 if (!newTree) {
30 newTree = { name: head, children: [] };
31 tree.children.push(newTree);
32 }
33 addToPath(moduleId, newTree, rest, node);
34 return;
35 }
36};
37
38// TODO try to make it without recursion, but still typesafe
39const mergeSingleChildTrees = (tree: ModuleTree): ModuleTree | ModuleTreeLeaf => {

Callers 1

buildTreeFunction · 0.85

Calls 1

isModuleTreeFunction · 0.85

Tested by

no test coverage detected