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

Function addToPath

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

Source from the content-addressed store, hash-verified

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

Callers 1

buildTreeFunction · 0.85

Calls 1

isModuleTreeFunction · 0.85

Tested by

no test coverage detected