How to use the graphlib.alg.findCycles function in graphlib

To help you get started, we’ve selected a few graphlib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github serverless / components / src / core / declarative / utils / createGraph.js View on Github external
dag.setNode(ROOT_NODE_NAME)
  dag = reduce(
    (accum, instanceId) => {
      if (instanceId !== ROOT_NODE_NAME) {
        accum.setEdge(instanceId, ROOT_NODE_NAME)
      }
      return accum
    },
    dag,
    dag.sinks()
  )

  // checking for circular dependencies
  const isAcyclic = alg.isAcyclic(dag)
  if (!isAcyclic) {
    const cycles = alg.findCycles(dag)
    let msg = ['Your serverless.yml file has circular dependencies:']
    cycles.forEach((cycle, index) => {
      let fromAToB = cycle.join(' --> ')
      fromAToB = `${(index += 1)}. ${fromAToB}`
      const fromBToA = cycle.reverse().join(' <-- ')
      const padLength = fromAToB.length + 4
      msg.push(fromAToB.padStart(padLength))
      msg.push(fromBToA.padStart(padLength))
    }, cycles)
    msg = msg.join('\n')
    throw new Error(msg)
  }

  return dag
}
github webiny / webiny-js / packages / app-admin / src / components / Install / Install.js View on Github external
const validateGraph = graph => {
    const isAcyclic = alg.isAcyclic(graph);
    if (!isAcyclic) {
        const cycles = alg.findCycles(graph);
        let msg = ["Your installers have circular dependencies:"];
        cycles.forEach((cycle, index) => {
            let fromAToB = cycle.join(" --> ");
            fromAToB = `${(index += 1)}. ${fromAToB}`;
            const fromBToA = cycle.reverse().join(" <-- ");
            const padLength = fromAToB.length + 4;
            msg.push(fromAToB.padStart(padLength));
            msg.push(fromBToA.padStart(padLength));
        }, cycles);
        msg = msg.join("\n");
        throw new Error(msg);
    }
};
github unboundedsystems / adapt / core / src / deploy / execution_plan.ts View on Github external
check() {
        const cycleGroups = alg.findCycles(this.graph);
        if (cycleGroups.length > 0) {
            const cycles = cycleGroups.map(printCycleGroups).join("\n");
            if (debugExecute.enabled) {
                debugExecute(`Execution plan dependencies:\n${this.print()}`);
            }
            throw new UserError(`There are circular dependencies present in this deployment:\n${cycles}`);
        }
    }
github webiny / webiny-js / packages / cli / sls / template / utils.js View on Github external
const validateGraph = graph => {
    const isAcyclic = alg.isAcyclic(graph);
    if (!isAcyclic) {
        const cycles = alg.findCycles(graph);
        let msg = ["Your template has circular dependencies:"];
        cycles.forEach((cycle, index) => {
            let fromAToB = cycle.join(" --> ");
            fromAToB = `${(index += 1)}. ${fromAToB}`;
            const fromBToA = cycle.reverse().join(" <-- ");
            const padLength = fromAToB.length + 4;
            msg.push(fromAToB.padStart(padLength));
            msg.push(fromBToA.padStart(padLength));
        }, cycles);
        msg = msg.join("\n");
        throw new Error(msg);
    }
};
github webiny / webiny-js / packages / app-admin / src / components / Install / useInstaller.js View on Github external
const validateGraph = graph => {
        const isAcyclic = alg.isAcyclic(graph);
        if (!isAcyclic) {
            const cycles = alg.findCycles(graph);
            let msg = ["Your installers have circular dependencies:"];
            cycles.forEach((cycle, index) => {
                let fromAToB = cycle.join(" --> ");
                fromAToB = `${index + 1}. ${fromAToB}`;
                const fromBToA = cycle.reverse().join(" <-- ");
                const padLength = fromAToB.length + 4;
                msg.push(fromAToB.padStart(padLength));
                msg.push(fromBToA.padStart(padLength));
            }, cycles);
            msg = msg.join("\n");
            throw new Error(msg);
        }
    };