All files / dist chunk-64U3PNO3.mjs

39.68% Statements 25/63
45.45% Branches 15/33
66.66% Functions 4/6
40.35% Lines 23/57

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95    1x 1x 1x                         2x 2x 2x 2x 2x                     1x 1x 1x   1x             1x 1x 1x 1x 1x 1x       1x   1x 1x 1x     1x                                                                      
// src/utils/dependency-graph-utils.ts
function calculateImportDepthFromEdges(file, edges, visited = /* @__PURE__ */ new Set(), depth = 0) {
  Iif (visited.has(file)) return depth;
  const dependencies = edges.get(file);
  Eif (!dependencies || dependencies.size === 0) return depth;
  const nextVisited = new Set(visited);
  nextVisited.add(file);
  let maxDepth = depth;
  for (const dep of dependencies) {
    maxDepth = Math.max(
      maxDepth,
      calculateImportDepthFromEdges(dep, edges, nextVisited, depth + 1)
    );
  }
  return maxDepth;
}
function getTransitiveDependenciesFromEdges(file, edges, visited = /* @__PURE__ */ new Set()) {
  Iif (visited.has(file)) return [];
  const nextVisited = new Set(visited);
  nextVisited.add(file);
  const dependencies = edges.get(file);
  Eif (!dependencies || dependencies.size === 0) return [];
  const allDeps = [];
  for (const dep of dependencies) {
    allDeps.push(dep);
    allDeps.push(
      ...getTransitiveDependenciesFromEdges(dep, edges, nextVisited)
    );
  }
  return [...new Set(allDeps)];
}
function detectGraphCycles(edges) {
  const cycles = [];
  const visited = /* @__PURE__ */ new Set();
  const recursionStack = /* @__PURE__ */ new Set();
  function dfs(file, path) {
    Iif (recursionStack.has(file)) {
      const cycleStart = path.indexOf(file);
      if (cycleStart !== -1) {
        cycles.push([...path.slice(cycleStart), file]);
      }
      return;
    }
    Iif (visited.has(file)) return;
    visited.add(file);
    recursionStack.add(file);
    const dependencies = edges.get(file);
    Eif (dependencies) {
      for (const dep of dependencies) {
        dfs(dep, [...path, file]);
      }
    }
    recursionStack.delete(file);
  }
  for (const file of edges.keys()) {
    Eif (!visited.has(file)) {
      dfs(file, []);
    }
  }
  return cycles;
}
function detectGraphCyclesFromFile(file, edges) {
  const cycles = [];
  const visited = /* @__PURE__ */ new Set();
  const recursionStack = /* @__PURE__ */ new Set();
  function dfs(current, path) {
    if (recursionStack.has(current)) {
      const cycleStart = path.indexOf(current);
      if (cycleStart !== -1) {
        cycles.push([...path.slice(cycleStart), current]);
      }
      return;
    }
    if (visited.has(current)) return;
    visited.add(current);
    recursionStack.add(current);
    const dependencies = edges.get(current);
    if (dependencies) {
      for (const dep of dependencies) {
        dfs(dep, [...path, current]);
      }
    }
    recursionStack.delete(current);
  }
  dfs(file, []);
  return cycles;
}
 
export {
  calculateImportDepthFromEdges,
  getTransitiveDependenciesFromEdges,
  detectGraphCycles,
  detectGraphCyclesFromFile
};