@teambit/graph 0.0.692 → 0.0.695
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/component-graph/component-graph.ts +9 -27
- package/dist/component-graph/component-graph.d.ts +5 -12
- package/dist/component-graph/component-graph.js +8 -24
- package/dist/component-graph/component-graph.js.map +1 -1
- package/dist/graph-builder.js +12 -2
- package/dist/graph-builder.js.map +1 -1
- package/dist/object-list-to-graph.d.ts +4 -11
- package/dist/object-list-to-graph.js +7 -17
- package/dist/object-list-to-graph.js.map +1 -1
- package/package-tar/teambit-graph-0.0.695.tgz +0 -0
- package/package.json +9 -9
- package/{preview-1648437892896.js → preview-1648696872583.js} +2 -2
- package/package-tar/teambit-graph-0.0.692.tgz +0 -0
@@ -1,23 +1,23 @@
|
|
1
1
|
import { Component, ComponentID } from '@teambit/component';
|
2
|
-
import { Graph } from 'cleargraph';
|
2
|
+
import { Graph, Node, Edge } from '@teambit/graph.cleargraph';
|
3
3
|
|
4
4
|
import { Dependency } from '../model/dependency';
|
5
5
|
import { DuplicateDependency, VersionSubgraph } from '../duplicate-dependency';
|
6
6
|
|
7
7
|
export const DEPENDENCIES_TYPES = ['dependencies', 'devDependencies'];
|
8
8
|
|
9
|
-
type
|
10
|
-
type
|
9
|
+
type ComponentNode = Node<Component>;
|
10
|
+
type DependencyEdge = Edge<Dependency>;
|
11
11
|
|
12
12
|
export class ComponentGraph extends Graph<Component, Dependency> {
|
13
13
|
versionMap: Map<string, { allVersionNodes: string[]; latestVersionNode: string }>;
|
14
14
|
seederIds: ComponentID[] = []; // component IDs that started the graph. (if from workspace, the .bitmap ids normally)
|
15
|
-
constructor(nodes:
|
15
|
+
constructor(nodes: ComponentNode[] = [], edges: DependencyEdge[] = []) {
|
16
16
|
super(nodes, edges);
|
17
17
|
this.versionMap = new Map();
|
18
18
|
}
|
19
19
|
|
20
|
-
protected create(nodes:
|
20
|
+
protected create(nodes: ComponentNode[] = [], edges: DependencyEdge[] = []): this {
|
21
21
|
return new ComponentGraph(nodes, edges) as this;
|
22
22
|
}
|
23
23
|
|
@@ -67,31 +67,13 @@ export class ComponentGraph extends Graph<Component, Dependency> {
|
|
67
67
|
}
|
68
68
|
|
69
69
|
buildFromCleargraph(graph: Graph<Component, Dependency>): ComponentGraph {
|
70
|
-
|
71
|
-
// this.create(graph.nodes, graph.edges)
|
72
|
-
|
73
|
-
const newGraph = new ComponentGraph();
|
74
|
-
const newGraphNodes: Node[] = graph.nodes.map((node) => {
|
75
|
-
return {
|
76
|
-
id: node.id,
|
77
|
-
node: node.attr,
|
78
|
-
};
|
79
|
-
});
|
80
|
-
const newGraphEdges: Edge[] = graph.edges.map((edge) => {
|
81
|
-
return {
|
82
|
-
sourceId: edge.sourceId,
|
83
|
-
targetId: edge.targetId,
|
84
|
-
edge: edge.attr,
|
85
|
-
};
|
86
|
-
});
|
87
|
-
newGraph.setNodes(newGraphNodes);
|
88
|
-
newGraph.setEdges(newGraphEdges);
|
89
|
-
|
90
|
-
return newGraph;
|
70
|
+
return this.create(graph.nodes, graph.edges);
|
91
71
|
}
|
92
72
|
|
93
73
|
runtimeOnly(componentIds: string[]) {
|
94
|
-
return this.successorsSubgraph(componentIds,
|
74
|
+
return this.successorsSubgraph(componentIds, {
|
75
|
+
edgeFilter: (edge: DependencyEdge) => edge.attr.type === 'runtime',
|
76
|
+
});
|
95
77
|
}
|
96
78
|
|
97
79
|
private shouldLimitToSeedersOnly() {
|
@@ -1,25 +1,18 @@
|
|
1
1
|
import { Component, ComponentID } from '@teambit/component';
|
2
|
-
import { Graph } from 'cleargraph';
|
2
|
+
import { Graph, Node, Edge } from '@teambit/graph.cleargraph';
|
3
3
|
import { Dependency } from '../model/dependency';
|
4
4
|
import { DuplicateDependency } from '../duplicate-dependency';
|
5
5
|
export declare const DEPENDENCIES_TYPES: string[];
|
6
|
-
declare type
|
7
|
-
|
8
|
-
node: Component;
|
9
|
-
};
|
10
|
-
declare type Edge = {
|
11
|
-
sourceId: string;
|
12
|
-
targetId: string;
|
13
|
-
edge: Dependency;
|
14
|
-
};
|
6
|
+
declare type ComponentNode = Node<Component>;
|
7
|
+
declare type DependencyEdge = Edge<Dependency>;
|
15
8
|
export declare class ComponentGraph extends Graph<Component, Dependency> {
|
16
9
|
versionMap: Map<string, {
|
17
10
|
allVersionNodes: string[];
|
18
11
|
latestVersionNode: string;
|
19
12
|
}>;
|
20
13
|
seederIds: ComponentID[];
|
21
|
-
constructor(nodes?:
|
22
|
-
protected create(nodes?:
|
14
|
+
constructor(nodes?: ComponentNode[], edges?: DependencyEdge[]);
|
15
|
+
protected create(nodes?: ComponentNode[], edges?: DependencyEdge[]): this;
|
23
16
|
/**
|
24
17
|
* overrides the super class to eliminate non-seeders components
|
25
18
|
*/
|
@@ -19,10 +19,10 @@ function _defineProperty2() {
|
|
19
19
|
return data;
|
20
20
|
}
|
21
21
|
|
22
|
-
function
|
23
|
-
const data = require("cleargraph");
|
22
|
+
function _graph() {
|
23
|
+
const data = require("@teambit/graph.cleargraph");
|
24
24
|
|
25
|
-
|
25
|
+
_graph = function () {
|
26
26
|
return data;
|
27
27
|
};
|
28
28
|
|
@@ -42,7 +42,7 @@ function _duplicateDependency() {
|
|
42
42
|
const DEPENDENCIES_TYPES = ['dependencies', 'devDependencies'];
|
43
43
|
exports.DEPENDENCIES_TYPES = DEPENDENCIES_TYPES;
|
44
44
|
|
45
|
-
class ComponentGraph extends
|
45
|
+
class ComponentGraph extends _graph().Graph {
|
46
46
|
// component IDs that started the graph. (if from workspace, the .bitmap ids normally)
|
47
47
|
constructor(nodes = [], edges = []) {
|
48
48
|
super(nodes, edges);
|
@@ -107,29 +107,13 @@ class ComponentGraph extends _cleargraph().Graph {
|
|
107
107
|
}
|
108
108
|
|
109
109
|
buildFromCleargraph(graph) {
|
110
|
-
|
111
|
-
// this.create(graph.nodes, graph.edges)
|
112
|
-
const newGraph = new ComponentGraph();
|
113
|
-
const newGraphNodes = graph.nodes.map(node => {
|
114
|
-
return {
|
115
|
-
id: node.id,
|
116
|
-
node: node.attr
|
117
|
-
};
|
118
|
-
});
|
119
|
-
const newGraphEdges = graph.edges.map(edge => {
|
120
|
-
return {
|
121
|
-
sourceId: edge.sourceId,
|
122
|
-
targetId: edge.targetId,
|
123
|
-
edge: edge.attr
|
124
|
-
};
|
125
|
-
});
|
126
|
-
newGraph.setNodes(newGraphNodes);
|
127
|
-
newGraph.setEdges(newGraphEdges);
|
128
|
-
return newGraph;
|
110
|
+
return this.create(graph.nodes, graph.edges);
|
129
111
|
}
|
130
112
|
|
131
113
|
runtimeOnly(componentIds) {
|
132
|
-
return this.successorsSubgraph(componentIds,
|
114
|
+
return this.successorsSubgraph(componentIds, {
|
115
|
+
edgeFilter: edge => edge.attr.type === 'runtime'
|
116
|
+
});
|
133
117
|
}
|
134
118
|
|
135
119
|
shouldLimitToSeedersOnly() {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["component-graph.ts"],"names":["DEPENDENCIES_TYPES","ComponentGraph","Graph","constructor","nodes","edges","versionMap","Map","create","findCycles","graph","cycles","shouldLimitToSeedersOnly","seederIdsStr","seederIds","map","id","toString","cyclesWithSeeders","filter","cycle","some","cycleIdStr","includes","findDuplicateDependencies","seederIdsNoVersions","toStringWithoutVersion","duplicateDependencies","compFullName","versions","allVersionNodes","length","versionSubgraphs","notLatestVersions","version","latestVersionNode","forEach","predecessors","predecessorsSubgraph","immediatePredecessors","predecessor","subGraph","buildFromCleargraph","versionSubgraph","versionId","immediateDependents","push","isSeeder","shouldDisplayDueToBeingSeeder","duplicateDep","DuplicateDependency","set","newGraph","newGraphNodes","node","attr","newGraphEdges","edge","sourceId","targetId","setNodes","setEdges","runtimeOnly","componentIds","successorsSubgraph","type","_calculateVersionMap","comp","compKey","_legacy","has","value","get","Object","prototype","hasOwnProperty","call","currentComp","latestComp","isLegacy","head","currentCompVersion","getVersion","latestCompVersion","isLaterThan","Date","timestamp"],"mappings":";;;;;;;;;;;;;;;;;;;;;AACA;A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,iBAA/B,CAAnD,EAAsG;AACpGZ,cAAAA,KAAK,CAACpC,iBAAN,GAA0BiC,OAA1B;AACD;AACF,WAND,MAMO,IAAI,IAAIiB,IAAJ,CAASR,WAAW,CAACG,IAAZ,CAAiBM,SAA1B,IAAuC,IAAID,IAAJ,CAASP,UAAU,CAACE,IAAX,CAAgBM,SAAzB,CAA3C,EAAgF;AACrFf,YAAAA,KAAK,CAACpC,iBAAN,GAA0BiC,OAA1B;AACD;AACF;AACF;AACF;;AACD,WAAO9D,UAAP;AACD;;AA3H8D","sourcesContent":["import { Component, ComponentID } from '@teambit/component';\nimport { Graph } from 'cleargraph';\n\nimport { Dependency } from '../model/dependency';\nimport { DuplicateDependency, VersionSubgraph } from '../duplicate-dependency';\n\nexport const DEPENDENCIES_TYPES = ['dependencies', 'devDependencies'];\n\ntype Node = { id: string; node: Component };\ntype Edge = { sourceId: string; targetId: string; edge: Dependency };\n\nexport class ComponentGraph extends Graph<Component, Dependency> {\n versionMap: Map<string, { allVersionNodes: string[]; latestVersionNode: string }>;\n seederIds: ComponentID[] = []; // component IDs that started the graph. (if from workspace, the .bitmap ids normally)\n constructor(nodes: Node[] = [], edges: Edge[] = []) {\n super(nodes, edges);\n this.versionMap = new Map();\n }\n\n protected create(nodes: Node[] = [], edges: Edge[] = []): this {\n return new ComponentGraph(nodes, edges) as this;\n }\n\n /**\n * overrides the super class to eliminate non-seeders components\n */\n findCycles(graph?: this): string[][] {\n const cycles = super.findCycles(graph);\n if (!this.shouldLimitToSeedersOnly()) {\n return cycles;\n }\n const seederIdsStr = this.seederIds.map((id) => id.toString());\n const cyclesWithSeeders = cycles.filter((cycle) => {\n return cycle.some((cycleIdStr) => seederIdsStr.includes(cycleIdStr));\n });\n return cyclesWithSeeders;\n }\n\n findDuplicateDependencies(): Map<string, DuplicateDependency> {\n const seederIdsNoVersions = this.seederIds.map((id) => id.toStringWithoutVersion());\n const duplicateDependencies: Map<string, DuplicateDependency> = new Map();\n for (const [compFullName, versions] of this.versionMap) {\n if (versions.allVersionNodes.length > 1) {\n const versionSubgraphs: VersionSubgraph[] = [];\n const notLatestVersions = versions.allVersionNodes.filter((version) => version !== versions.latestVersionNode);\n notLatestVersions.forEach((version) => {\n const predecessors = this.predecessorsSubgraph(version);\n const immediatePredecessors = this.predecessors(version).map((predecessor) => predecessor.id);\n const subGraph = this.buildFromCleargraph(predecessors);\n const versionSubgraph: VersionSubgraph = {\n versionId: version,\n subGraph,\n // TODO: validate that this is working correctly\n immediateDependents: immediatePredecessors,\n };\n versionSubgraphs.push(versionSubgraph);\n });\n const isSeeder = seederIdsNoVersions.includes(compFullName);\n const shouldDisplayDueToBeingSeeder = !this.shouldLimitToSeedersOnly() || isSeeder;\n if (shouldDisplayDueToBeingSeeder && versionSubgraphs.length > 0) {\n const duplicateDep = new DuplicateDependency(versions.latestVersionNode, versionSubgraphs);\n duplicateDependencies.set(compFullName, duplicateDep);\n }\n }\n }\n return duplicateDependencies;\n }\n\n buildFromCleargraph(graph: Graph<Component, Dependency>): ComponentGraph {\n // TODO: once cleargraph constructor and graph.nodes are consistent we should just use this line\n // this.create(graph.nodes, graph.edges)\n\n const newGraph = new ComponentGraph();\n const newGraphNodes: Node[] = graph.nodes.map((node) => {\n return {\n id: node.id,\n node: node.attr,\n };\n });\n const newGraphEdges: Edge[] = graph.edges.map((edge) => {\n return {\n sourceId: edge.sourceId,\n targetId: edge.targetId,\n edge: edge.attr,\n };\n });\n newGraph.setNodes(newGraphNodes);\n newGraph.setEdges(newGraphEdges);\n\n return newGraph;\n }\n\n runtimeOnly(componentIds: string[]) {\n return this.successorsSubgraph(componentIds, (edge) => edge.attr.type === 'runtime');\n }\n\n private shouldLimitToSeedersOnly() {\n return this.seederIds.length;\n }\n\n _calculateVersionMap() {\n const versionMap: Map<string, { allVersionNodes: string[]; latestVersionNode: string }> = new Map();\n for (const node of this.nodes) {\n const comp = node.attr;\n const compKey = node.id;\n const compFullName = comp.id._legacy.toStringWithoutVersion();\n if (!versionMap.has(compFullName)) {\n versionMap.set(compFullName, {\n allVersionNodes: [compKey],\n latestVersionNode: compKey,\n });\n } else {\n const value = versionMap.get(compFullName);\n if (value) {\n if (Object.prototype.hasOwnProperty.call(value, 'allVersionNodes')) {\n value.allVersionNodes.push(compKey);\n }\n const currentComp = this.node(compKey)?.attr;\n const latestComp = this.node(value.latestVersionNode)?.attr;\n const isLegacy = !currentComp?.head || !latestComp?.head;\n\n if (isLegacy) {\n const currentCompVersion = currentComp?.id._legacy.getVersion();\n const latestCompVersion = latestComp?.id._legacy.getVersion();\n if (!!currentCompVersion && !!latestCompVersion && currentCompVersion.isLaterThan(latestCompVersion)) {\n value.latestVersionNode = compKey;\n }\n } else if (new Date(currentComp.head.timestamp) > new Date(latestComp.head.timestamp)) {\n value.latestVersionNode = compKey;\n }\n }\n }\n }\n return versionMap;\n }\n}\n"]}
|
1
|
+
{"version":3,"sources":["component-graph.ts"],"names":["DEPENDENCIES_TYPES","ComponentGraph","Graph","constructor","nodes","edges","versionMap","Map","create","findCycles","graph","cycles","shouldLimitToSeedersOnly","seederIdsStr","seederIds","map","id","toString","cyclesWithSeeders","filter","cycle","some","cycleIdStr","includes","findDuplicateDependencies","seederIdsNoVersions","toStringWithoutVersion","duplicateDependencies","compFullName","versions","allVersionNodes","length","versionSubgraphs","notLatestVersions","version","latestVersionNode","forEach","predecessors","predecessorsSubgraph","immediatePredecessors","predecessor","subGraph","buildFromCleargraph","versionSubgraph","versionId","immediateDependents","push","isSeeder","shouldDisplayDueToBeingSeeder","duplicateDep","DuplicateDependency","set","runtimeOnly","componentIds","successorsSubgraph","edgeFilter","edge","attr","type","_calculateVersionMap","node","comp","compKey","_legacy","has","value","get","Object","prototype","hasOwnProperty","call","currentComp","latestComp","isLegacy","head","currentCompVersion","getVersion","latestCompVersion","isLaterThan","Date","timestamp"],"mappings":";;;;;;;;;;;;;;;;;;;;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;;AAAA;AAAA;AA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L,CAAUE,OAAV,CAAH,+CAAG,WAAoBL,IAAxC;AACA,gBAAMe,UAAU,kBAAG,KAAKZ,IAAL,CAAUK,KAAK,CAAC9B,iBAAhB,CAAH,gDAAG,YAAoCsB,IAAvD;AACA,gBAAMgB,QAAQ,GAAG,EAACF,WAAD,aAACA,WAAD,eAACA,WAAW,CAAEG,IAAd,KAAsB,EAACF,UAAD,aAACA,UAAD,eAACA,UAAU,CAAEE,IAAb,CAAvC;;AAEA,cAAID,QAAJ,EAAc;AACZ,kBAAME,kBAAkB,GAAGJ,WAAH,aAAGA,WAAH,uBAAGA,WAAW,CAAEvD,EAAb,CAAgB+C,OAAhB,CAAwBa,UAAxB,EAA3B;AACA,kBAAMC,iBAAiB,GAAGL,UAAH,aAAGA,UAAH,uBAAGA,UAAU,CAAExD,EAAZ,CAAe+C,OAAf,CAAuBa,UAAvB,EAA1B;;AACA,gBAAI,CAAC,CAACD,kBAAF,IAAwB,CAAC,CAACE,iBAA1B,IAA+CF,kBAAkB,CAACG,WAAnB,CAA+BD,iBAA/B,CAAnD,EAAsG;AACpGZ,cAAAA,KAAK,CAAC9B,iBAAN,GAA0B2B,OAA1B;AACD;AACF,WAND,MAMO,IAAI,IAAIiB,IAAJ,CAASR,WAAW,CAACG,IAAZ,CAAiBM,SAA1B,IAAuC,IAAID,IAAJ,CAASP,UAAU,CAACE,IAAX,CAAgBM,SAAzB,CAA3C,EAAgF;AACrFf,YAAAA,KAAK,CAAC9B,iBAAN,GAA0B2B,OAA1B;AACD;AACF;AACF;AACF;;AACD,WAAOxD,UAAP;AACD;;AAzG8D","sourcesContent":["import { Component, ComponentID } from '@teambit/component';\nimport { Graph, Node, Edge } from '@teambit/graph.cleargraph';\n\nimport { Dependency } from '../model/dependency';\nimport { DuplicateDependency, VersionSubgraph } from '../duplicate-dependency';\n\nexport const DEPENDENCIES_TYPES = ['dependencies', 'devDependencies'];\n\ntype ComponentNode = Node<Component>;\ntype DependencyEdge = Edge<Dependency>;\n\nexport class ComponentGraph extends Graph<Component, Dependency> {\n versionMap: Map<string, { allVersionNodes: string[]; latestVersionNode: string }>;\n seederIds: ComponentID[] = []; // component IDs that started the graph. (if from workspace, the .bitmap ids normally)\n constructor(nodes: ComponentNode[] = [], edges: DependencyEdge[] = []) {\n super(nodes, edges);\n this.versionMap = new Map();\n }\n\n protected create(nodes: ComponentNode[] = [], edges: DependencyEdge[] = []): this {\n return new ComponentGraph(nodes, edges) as this;\n }\n\n /**\n * overrides the super class to eliminate non-seeders components\n */\n findCycles(graph?: this): string[][] {\n const cycles = super.findCycles(graph);\n if (!this.shouldLimitToSeedersOnly()) {\n return cycles;\n }\n const seederIdsStr = this.seederIds.map((id) => id.toString());\n const cyclesWithSeeders = cycles.filter((cycle) => {\n return cycle.some((cycleIdStr) => seederIdsStr.includes(cycleIdStr));\n });\n return cyclesWithSeeders;\n }\n\n findDuplicateDependencies(): Map<string, DuplicateDependency> {\n const seederIdsNoVersions = this.seederIds.map((id) => id.toStringWithoutVersion());\n const duplicateDependencies: Map<string, DuplicateDependency> = new Map();\n for (const [compFullName, versions] of this.versionMap) {\n if (versions.allVersionNodes.length > 1) {\n const versionSubgraphs: VersionSubgraph[] = [];\n const notLatestVersions = versions.allVersionNodes.filter((version) => version !== versions.latestVersionNode);\n notLatestVersions.forEach((version) => {\n const predecessors = this.predecessorsSubgraph(version);\n const immediatePredecessors = this.predecessors(version).map((predecessor) => predecessor.id);\n const subGraph = this.buildFromCleargraph(predecessors);\n const versionSubgraph: VersionSubgraph = {\n versionId: version,\n subGraph,\n // TODO: validate that this is working correctly\n immediateDependents: immediatePredecessors,\n };\n versionSubgraphs.push(versionSubgraph);\n });\n const isSeeder = seederIdsNoVersions.includes(compFullName);\n const shouldDisplayDueToBeingSeeder = !this.shouldLimitToSeedersOnly() || isSeeder;\n if (shouldDisplayDueToBeingSeeder && versionSubgraphs.length > 0) {\n const duplicateDep = new DuplicateDependency(versions.latestVersionNode, versionSubgraphs);\n duplicateDependencies.set(compFullName, duplicateDep);\n }\n }\n }\n return duplicateDependencies;\n }\n\n buildFromCleargraph(graph: Graph<Component, Dependency>): ComponentGraph {\n return this.create(graph.nodes, graph.edges);\n }\n\n runtimeOnly(componentIds: string[]) {\n return this.successorsSubgraph(componentIds, {\n edgeFilter: (edge: DependencyEdge) => edge.attr.type === 'runtime',\n });\n }\n\n private shouldLimitToSeedersOnly() {\n return this.seederIds.length;\n }\n\n _calculateVersionMap() {\n const versionMap: Map<string, { allVersionNodes: string[]; latestVersionNode: string }> = new Map();\n for (const node of this.nodes) {\n const comp = node.attr;\n const compKey = node.id;\n const compFullName = comp.id._legacy.toStringWithoutVersion();\n if (!versionMap.has(compFullName)) {\n versionMap.set(compFullName, {\n allVersionNodes: [compKey],\n latestVersionNode: compKey,\n });\n } else {\n const value = versionMap.get(compFullName);\n if (value) {\n if (Object.prototype.hasOwnProperty.call(value, 'allVersionNodes')) {\n value.allVersionNodes.push(compKey);\n }\n const currentComp = this.node(compKey)?.attr;\n const latestComp = this.node(value.latestVersionNode)?.attr;\n const isLegacy = !currentComp?.head || !latestComp?.head;\n\n if (isLegacy) {\n const currentCompVersion = currentComp?.id._legacy.getVersion();\n const latestCompVersion = latestComp?.id._legacy.getVersion();\n if (!!currentCompVersion && !!latestCompVersion && currentCompVersion.isLaterThan(latestCompVersion)) {\n value.latestVersionNode = compKey;\n }\n } else if (new Date(currentComp.head.timestamp) > new Date(latestComp.head.timestamp)) {\n value.latestVersionNode = compKey;\n }\n }\n }\n }\n return versionMap;\n }\n}\n"]}
|
package/dist/graph-builder.js
CHANGED
@@ -21,6 +21,16 @@ function _defineProperty2() {
|
|
21
21
|
return data;
|
22
22
|
}
|
23
23
|
|
24
|
+
function _graph() {
|
25
|
+
const data = require("@teambit/graph.cleargraph");
|
26
|
+
|
27
|
+
_graph = function () {
|
28
|
+
return data;
|
29
|
+
};
|
30
|
+
|
31
|
+
return data;
|
32
|
+
}
|
33
|
+
|
24
34
|
function _componentGraph() {
|
25
35
|
const data = require("./component-graph");
|
26
36
|
|
@@ -73,7 +83,7 @@ class GraphBuilder {
|
|
73
83
|
const component = await componentHost.get(componentId);
|
74
84
|
|
75
85
|
if (component) {
|
76
|
-
newGraph.setNode(componentId.toString(), component);
|
86
|
+
newGraph.setNode(new (_graph().Node)(componentId.toString(), component));
|
77
87
|
}
|
78
88
|
});
|
79
89
|
await Promise.all(setNodeP);
|
@@ -81,7 +91,7 @@ class GraphBuilder {
|
|
81
91
|
const source = await componentHost.resolveComponentId(edgeId.v);
|
82
92
|
const target = await componentHost.resolveComponentId(edgeId.w);
|
83
93
|
const edgeObj = legacyGraph.edge(edgeId.v, edgeId.w) === 'dependencies' ? new (_dependency().Dependency)('runtime') : new (_dependency().Dependency)('dev');
|
84
|
-
newGraph.setEdge(source.toString(), target.toString(), edgeObj);
|
94
|
+
newGraph.setEdge(new (_graph().Edge)(source.toString(), target.toString(), edgeObj));
|
85
95
|
});
|
86
96
|
await Promise.all(setEdgePromise);
|
87
97
|
newGraph.versionMap = newGraph._calculateVersionMap();
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["graph-builder.ts"],"names":["GraphBuilder","constructor","componentAspect","getGraph","ids","opts","componentHost","host","getHost","legacyGraph","getLegacyGraph","graph","buildFromLegacy","_graph","_initialized","seederIds","listIds","newGraph","ComponentGraph","setNodeP","nodes","map","nodeId","componentId","resolveComponentId","component","get","setNode","toString","Promise","all","setEdgePromise","edges","edgeId","source","v","target","w","edgeObj","edge","Dependency","setEdge","versionMap","_calculateVersionMap"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAUA;AACA;AACA;AACA;AACA;AACO,MAAMA,YAAN,CAAmB;AAGxBC,EAAAA,WAAW,CAASC,eAAT,EAAyC;AAAA,SAAhCA,eAAgC,GAAhCA,eAAgC;AAAA;AAAA,0DADrC,KACqC;AAAE;;AAExC,QAARC,QAAQ,CAACC,GAAD,EAAsBC,IAAkB,GAAG,EAA3C,EAAwE;AACpF,UAAMC,aAAa,GAAGD,IAAI,CAACE,IAAL,IAAa,KAAKL,eAAL,CAAqBM,OAArB,EAAnC;AAEA,UAAMC,WAAW,GAAG,MAAMH,aAAa,CAACI,cAAd,CAA6BN,GAA7B,CAA1B;AACA,UAAMO,KAAK,GAAG,MAAM,KAAKC,eAAL,CAAqBH,WAArB,EAAkC;AAAEF,MAAAA,IAAI,EAAEF,IAAI,CAACE;AAAb,KAAlC,CAApB;AACA,SAAKM,MAAL,GAAcF,KAAd;AACA,SAAKG,YAAL,GAAoB,IAApB;AACAH,IAAAA,KAAK,CAACI,SAAN,GAAkBX,GAAG,KAAK,MAAME,aAAa,CAACU,OAAd,EAAX,CAArB;AACA,WAAO,KAAKH,MAAZ;AACD;;AAE4B,QAAfD,eAAe,CAC3BH,WAD2B,EAE3BJ,IAA8B,GAAG,EAFN,EAGF;AACzB,UAAMY,QAAQ,GAAG,KAAIC,gCAAJ,GAAjB;AACA,UAAMZ,aAAa,GAAGD,IAAI,CAACE,IAAL,IAAa,KAAKL,eAAL,CAAqBM,OAArB,EAAnC;AAEA,UAAMW,QAAQ,GAAGV,WAAW,CAACW,KAAZ,GAAoBC,GAApB,CAAwB,MAAOC,MAAP,IAAkB;AACzD,YAAMC,WAAW,GAAG,MAAMjB,aAAa,CAACkB,kBAAd,CAAiCF,MAAjC,CAA1B;AACA,YAAMG,SAAS,GAAG,MAAMnB,aAAa,CAACoB,GAAd,CAAkBH,WAAlB,CAAxB;;AACA,UAAIE,SAAJ,EAAe;AACbR,QAAAA,QAAQ,CAACU,OAAT,
|
1
|
+
{"version":3,"sources":["graph-builder.ts"],"names":["GraphBuilder","constructor","componentAspect","getGraph","ids","opts","componentHost","host","getHost","legacyGraph","getLegacyGraph","graph","buildFromLegacy","_graph","_initialized","seederIds","listIds","newGraph","ComponentGraph","setNodeP","nodes","map","nodeId","componentId","resolveComponentId","component","get","setNode","Node","toString","Promise","all","setEdgePromise","edges","edgeId","source","v","target","w","edgeObj","edge","Dependency","setEdge","Edge","versionMap","_calculateVersionMap"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAUA;AACA;AACA;AACA;AACA;AACO,MAAMA,YAAN,CAAmB;AAGxBC,EAAAA,WAAW,CAASC,eAAT,EAAyC;AAAA,SAAhCA,eAAgC,GAAhCA,eAAgC;AAAA;AAAA,0DADrC,KACqC;AAAE;;AAExC,QAARC,QAAQ,CAACC,GAAD,EAAsBC,IAAkB,GAAG,EAA3C,EAAwE;AACpF,UAAMC,aAAa,GAAGD,IAAI,CAACE,IAAL,IAAa,KAAKL,eAAL,CAAqBM,OAArB,EAAnC;AAEA,UAAMC,WAAW,GAAG,MAAMH,aAAa,CAACI,cAAd,CAA6BN,GAA7B,CAA1B;AACA,UAAMO,KAAK,GAAG,MAAM,KAAKC,eAAL,CAAqBH,WAArB,EAAkC;AAAEF,MAAAA,IAAI,EAAEF,IAAI,CAACE;AAAb,KAAlC,CAApB;AACA,SAAKM,MAAL,GAAcF,KAAd;AACA,SAAKG,YAAL,GAAoB,IAApB;AACAH,IAAAA,KAAK,CAACI,SAAN,GAAkBX,GAAG,KAAK,MAAME,aAAa,CAACU,OAAd,EAAX,CAArB;AACA,WAAO,KAAKH,MAAZ;AACD;;AAE4B,QAAfD,eAAe,CAC3BH,WAD2B,EAE3BJ,IAA8B,GAAG,EAFN,EAGF;AACzB,UAAMY,QAAQ,GAAG,KAAIC,gCAAJ,GAAjB;AACA,UAAMZ,aAAa,GAAGD,IAAI,CAACE,IAAL,IAAa,KAAKL,eAAL,CAAqBM,OAArB,EAAnC;AAEA,UAAMW,QAAQ,GAAGV,WAAW,CAACW,KAAZ,GAAoBC,GAApB,CAAwB,MA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edge } from '@teambit/graph.cleargraph';\nimport type LegacyGraph from '@teambit/legacy/dist/scope/graph/graph';\nimport { ComponentGraph } from './component-graph';\nimport { Dependency } from './model/dependency';\n\ntype GetGraphOpts = {\n host?: ComponentFactory;\n};\n\ntype BuildFromLegacyGraphOpts = {\n host?: ComponentFactory;\n};\n\n/**\n * @todo: potential issues with the current way the class is built.\n * it's possible to call `getGraph` multiple times and at the same time (Promise.all).\n * which makes the _graph prop and other props unpredictable.\n */\nexport class GraphBuilder {\n _graph?: ComponentGraph;\n _initialized = false;\n constructor(private componentAspect: ComponentMain) {}\n\n async getGraph(ids?: ComponentID[], opts: GetGraphOpts = {}): Promise<ComponentGraph> {\n const componentHost = opts.host || this.componentAspect.getHost();\n\n const legacyGraph = await componentHost.getLegacyGraph(ids);\n const graph = await this.buildFromLegacy(legacyGraph, { host: opts.host });\n this._graph = graph;\n this._initialized = true;\n graph.seederIds = ids || (await componentHost.listIds());\n return this._graph;\n }\n\n private async buildFromLegacy(\n legacyGraph: LegacyGraph,\n opts: BuildFromLegacyGraphOpts = {}\n ): Promise<ComponentGraph> {\n const newGraph = new ComponentGraph();\n const componentHost = opts.host || this.componentAspect.getHost();\n\n const setNodeP = legacyGraph.nodes().map(async (nodeId) => {\n const componentId = await componentHost.resolveComponentId(nodeId);\n const component = await componentHost.get(componentId);\n if (component) {\n newGraph.setNode(new Node(componentId.toString(), component));\n }\n });\n await Promise.all(setNodeP);\n\n const setEdgePromise = legacyGraph.edges().map(async (edgeId) => {\n const source = await componentHost.resolveComponentId(edgeId.v);\n const target = await componentHost.resolveComponentId(edgeId.w);\n const edgeObj =\n legacyGraph.edge(edgeId.v, edgeId.w) === 'dependencies' ? new Dependency('runtime') : new Dependency('dev');\n newGraph.setEdge(new Edge(source.toString(), target.toString(), edgeObj));\n });\n await Promise.all(setEdgePromise);\n\n newGraph.versionMap = newGraph._calculateVersionMap();\n return newGraph;\n }\n}\n"]}
|
@@ -1,18 +1,11 @@
|
|
1
|
-
import { Graph } from 'cleargraph';
|
1
|
+
import { Graph, Node, Edge } from '@teambit/graph.cleargraph';
|
2
2
|
import { BitId } from '@teambit/legacy-bit-id';
|
3
3
|
import { ObjectList } from '@teambit/legacy/dist/scope/objects/object-list';
|
4
4
|
import { Dependency } from './model/dependency';
|
5
|
-
declare type
|
6
|
-
|
7
|
-
node: BitId;
|
8
|
-
};
|
9
|
-
declare type Edge = {
|
10
|
-
sourceId: string;
|
11
|
-
targetId: string;
|
12
|
-
edge: Dependency;
|
13
|
-
};
|
5
|
+
declare type BitIdNode = Node<BitId>;
|
6
|
+
declare type DependencyEdge = Edge<Dependency>;
|
14
7
|
export declare class IdGraph extends Graph<BitId, Dependency> {
|
15
|
-
constructor(nodes?:
|
8
|
+
constructor(nodes?: BitIdNode[], edges?: DependencyEdge[]);
|
16
9
|
}
|
17
10
|
export declare function objectListToGraph(objectList: ObjectList): Promise<IdGraph>;
|
18
11
|
export {};
|
@@ -10,10 +10,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
10
10
|
exports.IdGraph = void 0;
|
11
11
|
exports.objectListToGraph = objectListToGraph;
|
12
12
|
|
13
|
-
function
|
14
|
-
const data = require("cleargraph");
|
13
|
+
function _graph() {
|
14
|
+
const data = require("@teambit/graph.cleargraph");
|
15
15
|
|
16
|
-
|
16
|
+
_graph = function () {
|
17
17
|
return data;
|
18
18
|
};
|
19
19
|
|
@@ -50,7 +50,7 @@ function _dependency() {
|
|
50
50
|
return data;
|
51
51
|
}
|
52
52
|
|
53
|
-
class IdGraph extends
|
53
|
+
class IdGraph extends _graph().Graph {
|
54
54
|
constructor(nodes = [], edges = []) {
|
55
55
|
super(nodes, edges);
|
56
56
|
}
|
@@ -74,10 +74,7 @@ async function objectListToGraph(objectList) {
|
|
74
74
|
versionsInfo.forEach(versionInfo => {
|
75
75
|
const id = component.toBitId().changeVersion(versionInfo.tag || versionInfo.ref.toString());
|
76
76
|
const idStr = id.toString();
|
77
|
-
nodes.push(
|
78
|
-
id: idStr,
|
79
|
-
node: id
|
80
|
-
});
|
77
|
+
nodes.push(new (_graph().Node)(idStr, id));
|
81
78
|
|
82
79
|
if (!versionInfo.version) {
|
83
80
|
return;
|
@@ -91,15 +88,8 @@ async function objectListToGraph(objectList) {
|
|
91
88
|
|
92
89
|
const addDep = (depId, edge) => {
|
93
90
|
const depIdStr = depId.toString();
|
94
|
-
nodes.push(
|
95
|
-
|
96
|
-
node: depId
|
97
|
-
});
|
98
|
-
edges.push({
|
99
|
-
sourceId: idStr,
|
100
|
-
targetId: depIdStr,
|
101
|
-
edge
|
102
|
-
});
|
91
|
+
nodes.push(new (_graph().Node)(depIdStr, depId));
|
92
|
+
edges.push(new (_graph().Edge)(idStr, depIdStr, edge));
|
103
93
|
};
|
104
94
|
|
105
95
|
const runTime = new (_dependency().Dependency)('runtime');
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["object-list-to-graph.ts"],"names":["IdGraph","Graph","constructor","nodes","edges","objectListToGraph","objectList","bitObjectsList","toBitObjects","components","getComponents","versions","getVersions","Promise","all","map","component","versionsInfo","modelComponent","versionObjects","throws","forEach","versionInfo","id","toBitId","changeVersion","tag","ref","toString","idStr","push","
|
1
|
+
{"version":3,"sources":["object-list-to-graph.ts"],"names":["IdGraph","Graph","constructor","nodes","edges","objectListToGraph","objectList","bitObjectsList","toBitObjects","components","getComponents","versions","getVersions","Promise","all","map","component","versionsInfo","modelComponent","versionObjects","throws","forEach","versionInfo","id","toBitId","changeVersion","tag","ref","toString","idStr","push","Node","version","dependencies","devDependencies","extensionDependencies","depsIdsGroupedByType","addDep","depId","edge","depIdStr","Edge","runTime","Dependency","dev","uniqNodes","idGraph"],"mappings":";;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;A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D,EAAeC,IAAf,KAAoC;AACjD,cAAMC,QAAQ,GAAGF,KAAK,CAACV,QAAN,EAAjB;AACAzB,QAAAA,KAAK,CAAC2B,IAAN,CAAW,KAAIC,aAAJ,EAASS,QAAT,EAAmBF,KAAnB,CAAX;AACAlC,QAAAA,KAAK,CAAC0B,IAAN,CAAW,KAAIW,aAAJ,EAASZ,KAAT,EAAgBW,QAAhB,EAA0BD,IAA1B,CAAX;AACD,OAJD;;AAKA,YAAMG,OAAO,GAAG,KAAIC,wBAAJ,EAAe,SAAf,CAAhB;AACA,YAAMC,GAAG,GAAG,KAAID,wBAAJ,EAAe,KAAf,CAAZ;AACAV,MAAAA,YAAY,CAACZ,OAAb,CAAsBiB,KAAD,IAAWD,MAAM,CAACC,KAAD,EAAQI,OAAR,CAAtC;AACA,OAAC,GAAGR,eAAJ,EAAqB,GAAGC,qBAAxB,EAA+Cd,OAA/C,CAAwDiB,KAAD,IAAWD,MAAM,CAACC,KAAD,EAAQM,GAAR,CAAxE;AACD,KAjBD;AAkBD,GAxBD,CADI,CAAN;AA2BA,QAAMC,SAAS,GAAG,sBAAO1C,KAAP,EAAc,IAAd,CAAlB;AACA,QAAM2C,OAAO,GAAG,IAAI9C,OAAJ,CAAY6C,SAAZ,EAAuBzC,KAAvB,CAAhB;AAEA,SAAO0C,OAAP;AACD","sourcesContent":["import { Graph, Node, Edge } from '@teambit/graph.cleargraph';\nimport { uniqBy } from 'lodash';\nimport { BitId } from '@teambit/legacy-bit-id';\nimport { ObjectList } from '@teambit/legacy/dist/scope/objects/object-list';\nimport { getAllVersionsInfo } from '@teambit/legacy/dist/scope/component-ops/traverse-versions';\nimport { Dependency } from './model/dependency';\n\ntype BitIdNode = Node<BitId>;\ntype DependencyEdge = Edge<Dependency>;\n\nexport class IdGraph extends Graph<BitId, Dependency> {\n constructor(nodes: BitIdNode[] = [], edges: DependencyEdge[] = []) {\n super(nodes, edges);\n }\n}\n\nexport async function objectListToGraph(objectList: ObjectList): Promise<IdGraph> {\n const bitObjectsList = await objectList.toBitObjects();\n const components = bitObjectsList.getComponents();\n const versions = bitObjectsList.getVersions();\n const nodes: BitIdNode[] = [];\n const edges: DependencyEdge[] = [];\n await Promise.all(\n components.map(async (component) => {\n const versionsInfo = await getAllVersionsInfo({\n modelComponent: component,\n versionObjects: versions,\n throws: false,\n });\n versionsInfo.forEach((versionInfo) => {\n const id = component.toBitId().changeVersion(versionInfo.tag || versionInfo.ref.toString());\n const idStr = id.toString();\n nodes.push(new Node(idStr, id));\n if (!versionInfo.version) {\n return;\n }\n const { dependencies, devDependencies, extensionDependencies } = versionInfo.version.depsIdsGroupedByType;\n const addDep = (depId: BitId, edge: Dependency) => {\n const depIdStr = depId.toString();\n nodes.push(new Node(depIdStr, depId));\n edges.push(new Edge(idStr, depIdStr, edge));\n };\n const runTime = new Dependency('runtime');\n const dev = new Dependency('dev');\n dependencies.forEach((depId) => addDep(depId, runTime));\n [...devDependencies, ...extensionDependencies].forEach((depId) => addDep(depId, dev));\n });\n })\n );\n const uniqNodes = uniqBy(nodes, 'id');\n const idGraph = new IdGraph(uniqNodes, edges);\n\n return idGraph;\n}\n"]}
|
Binary file
|
package/package.json
CHANGED
@@ -1,17 +1,16 @@
|
|
1
1
|
{
|
2
2
|
"name": "@teambit/graph",
|
3
|
-
"version": "0.0.
|
3
|
+
"version": "0.0.695",
|
4
4
|
"homepage": "https://bit.dev/teambit/component/graph",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"componentId": {
|
7
7
|
"scope": "teambit.component",
|
8
8
|
"name": "graph",
|
9
|
-
"version": "0.0.
|
9
|
+
"version": "0.0.695"
|
10
10
|
},
|
11
11
|
"dependencies": {
|
12
12
|
"@teambit/harmony": "0.2.11",
|
13
13
|
"graphql-tag": "2.12.1",
|
14
|
-
"cleargraph": "7.0.0",
|
15
14
|
"lodash": "4.17.21",
|
16
15
|
"classnames": "2.2.6",
|
17
16
|
"react-flow-renderer": "8.3.7",
|
@@ -19,14 +18,15 @@
|
|
19
18
|
"react-router-dom": "5.2.0",
|
20
19
|
"@babel/runtime": "7.12.18",
|
21
20
|
"core-js": "^3.0.0",
|
21
|
+
"@teambit/graph.cleargraph": "0.0.1",
|
22
22
|
"@teambit/base-ui.surfaces.card": "1.0.1",
|
23
23
|
"@teambit/base-ui.text.muted-text": "1.0.1",
|
24
24
|
"@teambit/evangelist.input.checkbox.label": "1.0.3",
|
25
25
|
"@teambit/documenter.ui.heading": "4.1.1",
|
26
|
-
"@teambit/component": "0.0.
|
27
|
-
"@teambit/graphql": "0.0.
|
28
|
-
"@teambit/cli": "0.0.
|
29
|
-
"@teambit/ui": "0.0.
|
26
|
+
"@teambit/component": "0.0.695",
|
27
|
+
"@teambit/graphql": "0.0.695",
|
28
|
+
"@teambit/cli": "0.0.464",
|
29
|
+
"@teambit/ui": "0.0.695",
|
30
30
|
"@teambit/legacy-bit-id": "0.0.399",
|
31
31
|
"@teambit/component.ui.deprecation-icon": "0.0.493",
|
32
32
|
"@teambit/design.ui.styles.ellipsis": "0.0.347",
|
@@ -50,7 +50,7 @@
|
|
50
50
|
},
|
51
51
|
"peerDependencies": {
|
52
52
|
"@apollo/client": "^3.0.0",
|
53
|
-
"@teambit/legacy": "1.0.
|
53
|
+
"@teambit/legacy": "1.0.242",
|
54
54
|
"react-dom": "^16.8.0 || ^17.0.0",
|
55
55
|
"react": "^16.8.0 || ^17.0.0"
|
56
56
|
},
|
@@ -78,7 +78,7 @@
|
|
78
78
|
"react": "-"
|
79
79
|
},
|
80
80
|
"peerDependencies": {
|
81
|
-
"@teambit/legacy": "1.0.
|
81
|
+
"@teambit/legacy": "1.0.242",
|
82
82
|
"react-dom": "^16.8.0 || ^17.0.0",
|
83
83
|
"react": "^16.8.0 || ^17.0.0"
|
84
84
|
}
|
@@ -1,2 +1,2 @@
|
|
1
|
-
export const compositions = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.component_graph@0.0.
|
2
|
-
export const overview = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.component_graph@0.0.
|
1
|
+
export const compositions = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.component_graph@0.0.695/dist/graph.composition.js')]
|
2
|
+
export const overview = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.component_graph@0.0.695/dist/graph.docs.md')]
|
Binary file
|