import { Graph } from '@teambit/graph.cleargraph'; import type { DepEdgeType } from '@teambit/graph'; import type { ScopeMain } from '@teambit/scope'; import type { ConsumerComponent } from '@teambit/legacy.consumer-component'; import type { Lane } from '@teambit/objects'; import { ComponentID } from '@teambit/component-id'; import type { Logger } from '@teambit/logger'; /** * the goal of this class is to determine the graph dependencies of a given set of components with minimal effort. * it takes advantage of the fact that we save the dependency graph in the `Version` object and tries to reuse it. * * to optimize it as much as possible, we do it in 4 steps. each step we check whether the graph has missing ids, * and if so, continue to the next step. * * * * First step * * * * we have two groups in this graph. * 1. components that are now versioned (this.consumerComponents). they have the new version (which is not in the scope yet). * 2. component that are not part of the current snap/tag. * it's not possible that this group has new components that never been into the scope, otherwise the tag/snap is failing. * so we know we can always find the version-object of these components in the scope or import them. * * given the above. we can simply get the first level of dependencies of the first group. * start the graph by adding them all as nodes and edges. * * this dependencies array may contain components from the first group. we can filter them out. (we don't care about * them, they're part of the graph already) * we're left with the dependencies that are part of the second group. there are the `missingFromGraph`. * * * * Second step * * * * instead of import these components, we can more efficiently get their previous version from the scope. * it must be already in the scope because these are the components we load in the first place. * chances are that 99% of the dependencies of the current components objects are identical to the previous version. * by adding the flattenedEdges of the previous versions we can probably finish the graph without importing a single * component. It's ok that this graph of previous versions has ids that are not relevant to this graph. for example, if * we now tag bar@0.0.2, this graph will have bar@0.0.1 although it's not relevant. it's ok, because finally we don't * use this graph as a whole. we only pick a component and get its sub-graph, so all irrelevant ids are ignored. * * * * Third step * * * * in case the graph above wasn't enough. we can import the missing components and get their flattenedEdges. * all components that were snapped/tagged since around 0.0.8000 have the flattenedEdges saved in the version. * older components don't have them and that's why the last step is needed. * * * * Fourth step * * * * this is the worst scenario. we have some old dependencies without flattenedEdges, we have to import them with * all their flattened dependencies. * once we have all these objects we can iterate them and add them to the graph. */ export declare class FlattenedEdgesGetter { private scope; private consumerComponents; private logger; private lane?; private graph; private missingFromGraph; constructor(scope: ScopeMain, consumerComponents: ConsumerComponent[], logger: Logger, lane?: Lane | undefined); buildGraph(): Promise>; populateFlattenedAndEdgesForComp(component: ConsumerComponent): void; private importMissingAndAddToGraph; private addPreviousGraphs; private addComponentsWithMissingFlattenedEdges; private addFlattenedEdgesToGraph; private populateMissingFromGraph; private buildTheFirstLevel; private addEdges; }