@teambit/graph 1.0.108 → 1.0.109
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/artifacts/preview/teambit_component_graph-preview.js +1 -0
- package/dist/{preview-1703647408454.js → preview-1703698405864.js} +2 -2
- package/package.json +14 -14
- package/component-id-graph.ts +0 -76
- package/duplicate-dependency.ts +0 -18
- package/edge-type.ts +0 -5
- package/graph-builder.ts +0 -47
- package/graph-cmd.ts +0 -111
- package/graph.aspect.ts +0 -9
- package/graph.graphql.ts +0 -94
- package/graph.main.runtime.ts +0 -49
- package/index.ts +0 -25
- package/object-list-to-graph.ts +0 -66
@@ -0,0 +1 @@
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["teambit.component/graph-preview"]=t():e["teambit.component/graph-preview"]=t()}(self,(()=>(()=>{"use strict";var e={96362:(e,t,o)=>{var r={id:"teambit.component/graph@1.0.109",homepage:"https://bit.cloud/teambit/component/graph",exported:!0};function n(){const e=i(o(87363));return n=function(){return e},e}function i(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(t,"__esModule",{value:!0}),t.Logo=void 0,n.__bit_component=r,i.__bit_component=r;const p=()=>n().default.createElement("div",{style:{height:"100%",display:"flex",justifyContent:"center"}},n().default.createElement("img",{style:{width:70},src:"https://static.bit.dev/extensions-icons/graph.svg"}));p.__bit_component=r,t.Logo=p},87363:e=>{e.exports=React}},t={};function o(r){var n=t[r];if(void 0!==n)return n.exports;var i=t[r]={exports:{}};return e[r](i,i.exports,o),i.exports}o.d=(e,t)=>{for(var r in t)o.o(t,r)&&!o.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},o.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),o.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var r={};return(()=>{o.r(r),o.d(r,{compositions:()=>u,compositions_metadata:()=>l,overview:()=>f});var e={};o.r(e),o.d(e,{default:()=>d});var t=o(96362);o(87363);const n=MdxJsReact,i=TeambitMdxUiMdxScopeContext;var p=["components"];function a(){return a=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var o=arguments[t];for(var r in o)Object.prototype.hasOwnProperty.call(o,r)&&(e[r]=o[r])}return e},a.apply(this,arguments)}var c={},s="wrapper";function d(e){var t=e.components,o=function(e,t){if(null==e)return{};var o,r,n=function(e,t){if(null==e)return{};var o,r,n={},i=Object.keys(e);for(r=0;r<i.length;r++)o=i[r],t.indexOf(o)>=0||(n[o]=e[o]);return n}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(r=0;r<i.length;r++)o=i[r],t.indexOf(o)>=0||Object.prototype.propertyIsEnumerable.call(e,o)&&(n[o]=e[o])}return n}(e,p);return(0,n.mdx)(s,a({},c,o,{components:t,mdxType:"MDXLayout"}),(0,n.mdx)(i.MDXScopeProvider,{components:{},mdxType:"MDXScopeProvider"}))}d.isMDXComponent=!0;const u=[t],f=[e],l={compositions:[{displayName:"Logo",identifier:"Logo"}]}})(),r})()));
|
@@ -1,5 +1,5 @@
|
|
1
|
-
import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.component_graph@1.0.
|
2
|
-
import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.component_graph@1.0.
|
1
|
+
import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.component_graph@1.0.109/dist/graph.composition.js';
|
2
|
+
import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.component_graph@1.0.109/dist/graph.docs.md';
|
3
3
|
|
4
4
|
export const compositions = [compositions_0];
|
5
5
|
export const overview = [overview_0];
|
package/package.json
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
{
|
2
2
|
"name": "@teambit/graph",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.109",
|
4
4
|
"homepage": "https://bit.cloud/teambit/component/graph",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"componentId": {
|
7
7
|
"scope": "teambit.component",
|
8
8
|
"name": "graph",
|
9
|
-
"version": "1.0.
|
9
|
+
"version": "1.0.109"
|
10
10
|
},
|
11
11
|
"dependencies": {
|
12
12
|
"lodash": "4.17.21",
|
@@ -15,8 +15,8 @@
|
|
15
15
|
"graphql-tag": "2.12.1",
|
16
16
|
"classnames": "2.2.6",
|
17
17
|
"react-flow-renderer": "8.3.7",
|
18
|
-
"semver": "7.5.2",
|
19
18
|
"dagre": "0.8.5",
|
19
|
+
"semver": "7.5.2",
|
20
20
|
"@teambit/graph.cleargraph": "0.0.1",
|
21
21
|
"@teambit/component-id": "1.2.0",
|
22
22
|
"@teambit/harmony": "0.4.6",
|
@@ -27,9 +27,6 @@
|
|
27
27
|
"@teambit/base-ui.text.muted-text": "1.0.1",
|
28
28
|
"@teambit/component.ui.deprecation-icon": "0.0.509",
|
29
29
|
"@teambit/design.ui.styles.ellipsis": "0.0.357",
|
30
|
-
"@teambit/component.ui.component-compare.context": "0.0.116",
|
31
|
-
"@teambit/design.ui.round-loader": "0.0.355",
|
32
|
-
"@teambit/component.ui.component-compare.status-resolver": "0.0.9",
|
33
30
|
"@teambit/evangelist.input.checkbox.label": "1.0.3",
|
34
31
|
"@teambit/design.ui.pages.not-found": "0.0.366",
|
35
32
|
"@teambit/design.ui.pages.server-error": "0.0.366",
|
@@ -37,12 +34,15 @@
|
|
37
34
|
"@teambit/ui-foundation.ui.full-loader": "0.0.500",
|
38
35
|
"@teambit/ui-foundation.ui.hooks.use-data-query": "0.0.505",
|
39
36
|
"@teambit/ui-foundation.ui.react-router.use-query": "0.0.501",
|
40
|
-
"@teambit/component": "
|
41
|
-
"@teambit/
|
42
|
-
"@teambit/
|
43
|
-
"@teambit/
|
44
|
-
"@teambit/
|
45
|
-
"@teambit/
|
37
|
+
"@teambit/component.ui.component-compare.context": "0.0.116",
|
38
|
+
"@teambit/design.ui.round-loader": "0.0.355",
|
39
|
+
"@teambit/component.ui.component-compare.status-resolver": "0.0.9",
|
40
|
+
"@teambit/component": "1.0.109",
|
41
|
+
"@teambit/cli": "0.0.841",
|
42
|
+
"@teambit/graphql": "1.0.109",
|
43
|
+
"@teambit/logger": "0.0.934",
|
44
|
+
"@teambit/component-compare": "1.0.109",
|
45
|
+
"@teambit/ui": "1.0.109",
|
46
46
|
"@teambit/component.modules.component-url": "0.0.165",
|
47
47
|
"@teambit/envs.ui.env-icon": "0.0.503"
|
48
48
|
},
|
@@ -50,12 +50,12 @@
|
|
50
50
|
"@types/lodash": "4.14.165",
|
51
51
|
"@types/graphlib": "2.1.7",
|
52
52
|
"@types/classnames": "2.2.11",
|
53
|
-
"@types/semver": "7.3.4",
|
54
53
|
"@types/dagre": "0.7.44",
|
54
|
+
"@types/semver": "7.3.4",
|
55
55
|
"@types/mocha": "9.1.0",
|
56
56
|
"@types/jest": "^29.2.2",
|
57
57
|
"@types/testing-library__jest-dom": "^5.9.5",
|
58
|
-
"@teambit/harmony.envs.core-aspect-env": "0.0.
|
58
|
+
"@teambit/harmony.envs.core-aspect-env": "0.0.14"
|
59
59
|
},
|
60
60
|
"peerDependencies": {
|
61
61
|
"@apollo/client": "^3.6.0",
|
package/component-id-graph.ts
DELETED
@@ -1,76 +0,0 @@
|
|
1
|
-
import { ComponentID } from '@teambit/component';
|
2
|
-
import { Graph, Node, Edge } from '@teambit/graph.cleargraph';
|
3
|
-
import { uniq } from 'lodash';
|
4
|
-
|
5
|
-
export type DepEdgeType = 'prod' | 'dev' | 'ext';
|
6
|
-
|
7
|
-
type ComponentIdNode = Node<ComponentID>;
|
8
|
-
type DependencyEdge = Edge<DepEdgeType>;
|
9
|
-
export type CompIdGraph = Graph<ComponentID, DepEdgeType>;
|
10
|
-
|
11
|
-
export class ComponentIdGraph extends Graph<ComponentID, DepEdgeType> {
|
12
|
-
seederIds: ComponentID[] = []; // component IDs that started the graph. (if from workspace, the .bitmap ids normally)
|
13
|
-
constructor(nodes: ComponentIdNode[] = [], edges: DependencyEdge[] = []) {
|
14
|
-
super(nodes, edges);
|
15
|
-
}
|
16
|
-
|
17
|
-
protected create(nodes: ComponentIdNode[] = [], edges: DependencyEdge[] = []): this {
|
18
|
-
return new ComponentIdGraph(nodes, edges) as this;
|
19
|
-
}
|
20
|
-
|
21
|
-
/**
|
22
|
-
* check all the routes from the sources to targets and return the components found during this traversal.
|
23
|
-
* e.g.
|
24
|
-
* A -> B -> C -> N.
|
25
|
-
* A -> E -> N.
|
26
|
-
* B -> F -> G.
|
27
|
-
* given source: A, targets: N. The results will be: B, C, E
|
28
|
-
*/
|
29
|
-
findIdsFromSourcesToTargets(sources: ComponentID[], targets: ComponentID[]): ComponentID[] {
|
30
|
-
const removeVerFromIdStr = (idStr: string) => idStr.split('@')[0];
|
31
|
-
const sourcesStr = sources.map((s) => s.toStringWithoutVersion());
|
32
|
-
const targetsStr = targets.map((t) => t.toStringWithoutVersion());
|
33
|
-
const allFlattened = sources.map((source) => this.successors(source.toString())).flat();
|
34
|
-
const allFlattenedIds = uniq(allFlattened.map((f) => f.id));
|
35
|
-
const results: string[] = [];
|
36
|
-
allFlattenedIds.forEach((id) => {
|
37
|
-
const idWithNoVer = removeVerFromIdStr(id);
|
38
|
-
if (sourcesStr.includes(idWithNoVer) || targetsStr.includes(idWithNoVer)) return;
|
39
|
-
const allSuccessors = this.successors(id);
|
40
|
-
const allSuccessorsWithNoVersion = allSuccessors.map((s) => removeVerFromIdStr(s.id));
|
41
|
-
if (allSuccessorsWithNoVersion.find((s) => targetsStr.includes(s))) results.push(id);
|
42
|
-
});
|
43
|
-
const componentIds = this.getNodes(results).map((n) => n.attr);
|
44
|
-
|
45
|
-
return componentIds;
|
46
|
-
}
|
47
|
-
|
48
|
-
/**
|
49
|
-
* overrides the super class to eliminate non-seeders components
|
50
|
-
*/
|
51
|
-
findCycles(graph?: this, includeDeps = false): string[][] {
|
52
|
-
const cycles = super.findCycles(graph);
|
53
|
-
if (!this.shouldLimitToSeedersOnly() || includeDeps) {
|
54
|
-
return cycles;
|
55
|
-
}
|
56
|
-
const seederIdsStr = this.seederIds.map((id) => id.toString());
|
57
|
-
const cyclesWithSeeders = cycles.filter((cycle) => {
|
58
|
-
return cycle.some((cycleIdStr) => seederIdsStr.includes(cycleIdStr));
|
59
|
-
});
|
60
|
-
return cyclesWithSeeders;
|
61
|
-
}
|
62
|
-
|
63
|
-
buildFromCleargraph(graph: Graph<ComponentID, DepEdgeType>): ComponentIdGraph {
|
64
|
-
return this.create(graph.nodes, graph.edges);
|
65
|
-
}
|
66
|
-
|
67
|
-
runtimeOnly(componentIds: string[]) {
|
68
|
-
return this.successorsSubgraph(componentIds, {
|
69
|
-
edgeFilter: (edge: DependencyEdge) => edge.attr === 'prod',
|
70
|
-
});
|
71
|
-
}
|
72
|
-
|
73
|
-
private shouldLimitToSeedersOnly() {
|
74
|
-
return this.seederIds.length;
|
75
|
-
}
|
76
|
-
}
|
package/duplicate-dependency.ts
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
// eslint-disable-next-line import/no-cycle
|
2
|
-
import type { ComponentGraph } from './component-graph';
|
3
|
-
|
4
|
-
export class DuplicateDependency {
|
5
|
-
latestVersionId: string;
|
6
|
-
priorVersions: VersionSubgraph[];
|
7
|
-
|
8
|
-
constructor(latestVersionId: string, priorVersions: VersionSubgraph[]) {
|
9
|
-
this.latestVersionId = latestVersionId;
|
10
|
-
this.priorVersions = priorVersions;
|
11
|
-
}
|
12
|
-
}
|
13
|
-
|
14
|
-
export type VersionSubgraph = {
|
15
|
-
versionId: string;
|
16
|
-
subGraph: ComponentGraph;
|
17
|
-
immediateDependents: string[];
|
18
|
-
};
|
package/edge-type.ts
DELETED
package/graph-builder.ts
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
import { Component, ComponentFactory, ComponentID, ComponentMain } from '@teambit/component';
|
2
|
-
import { Edge, Graph } from '@teambit/graph.cleargraph';
|
3
|
-
import { ComponentGraph } from './component-graph';
|
4
|
-
import { ComponentIdGraph } from './component-id-graph';
|
5
|
-
import { Dependency } from './model/dependency';
|
6
|
-
|
7
|
-
export type GetGraphOpts = {
|
8
|
-
host?: ComponentFactory;
|
9
|
-
};
|
10
|
-
|
11
|
-
export class GraphBuilder {
|
12
|
-
constructor(private componentAspect: ComponentMain) {}
|
13
|
-
|
14
|
-
/**
|
15
|
-
* important - prefer using `getGraphIds()` it's way better in terms of performance.
|
16
|
-
*/
|
17
|
-
async getGraph(ids?: ComponentID[], opts: GetGraphOpts = {}): Promise<ComponentGraph> {
|
18
|
-
const componentHost = opts.host || this.componentAspect.getHost();
|
19
|
-
|
20
|
-
const graph = await componentHost.getGraph(ids, false);
|
21
|
-
const componentGraph = await this.toComponentGraph(graph);
|
22
|
-
componentGraph.seederIds = ids || (await componentHost.listIds());
|
23
|
-
return componentGraph;
|
24
|
-
}
|
25
|
-
|
26
|
-
async getGraphIds(ids?: ComponentID[], opts: GetGraphOpts = {}): Promise<ComponentIdGraph> {
|
27
|
-
const componentHost = opts.host || this.componentAspect.getHost();
|
28
|
-
|
29
|
-
const graph = await componentHost.getGraphIds(ids, false);
|
30
|
-
const componentIdGraph = new ComponentIdGraph(graph.nodes, graph.edges);
|
31
|
-
componentIdGraph.seederIds = ids || (await componentHost.listIds());
|
32
|
-
return componentIdGraph;
|
33
|
-
}
|
34
|
-
|
35
|
-
private async toComponentGraph(graph: Graph<Component, string>): Promise<ComponentGraph> {
|
36
|
-
const newGraph = new ComponentGraph();
|
37
|
-
graph.nodes.forEach((node) => {
|
38
|
-
newGraph.setNode(node);
|
39
|
-
});
|
40
|
-
graph.edges.forEach((edge) => {
|
41
|
-
const edgeObj =
|
42
|
-
edge.attr === 'dependencies' || edge.attr === 'runtime' ? new Dependency('runtime') : new Dependency('dev');
|
43
|
-
newGraph.setEdge(new Edge(edge.sourceId, edge.targetId, edgeObj));
|
44
|
-
});
|
45
|
-
return newGraph;
|
46
|
-
}
|
47
|
-
}
|
package/graph-cmd.ts
DELETED
@@ -1,111 +0,0 @@
|
|
1
|
-
import chalk from 'chalk';
|
2
|
-
import os from 'os';
|
3
|
-
import * as path from 'path';
|
4
|
-
import GraphLib from 'graphlib';
|
5
|
-
import { Command, CommandOptions } from '@teambit/cli';
|
6
|
-
import { ComponentID } from '@teambit/component-id';
|
7
|
-
import { generateRandomStr } from '@teambit/legacy/dist/utils';
|
8
|
-
import VisualDependencyGraph from '@teambit/legacy/dist/scope/graph/vizgraph';
|
9
|
-
import { Consumer, loadConsumerIfExist } from '@teambit/legacy/dist/consumer';
|
10
|
-
import DependencyGraph from '@teambit/legacy/dist/scope/graph/scope-graph';
|
11
|
-
import { ConsumerNotFound } from '@teambit/legacy/dist/consumer/exceptions';
|
12
|
-
import getRemoteByName from '@teambit/legacy/dist/remotes/get-remote-by-name';
|
13
|
-
import { ComponentMain } from '@teambit/component';
|
14
|
-
|
15
|
-
type GraphOpt = {
|
16
|
-
image?: string;
|
17
|
-
remote?: string;
|
18
|
-
allVersions?: boolean;
|
19
|
-
layout?: string;
|
20
|
-
json?: boolean;
|
21
|
-
};
|
22
|
-
|
23
|
-
export class GraphCmd implements Command {
|
24
|
-
name = 'graph [id]';
|
25
|
-
description = "generate an image file with the workspace components' dependencies graph";
|
26
|
-
extendedDescription: 'black arrow is a runtime dependency. red arrow is either dev or peer';
|
27
|
-
group = 'discover';
|
28
|
-
alias = '';
|
29
|
-
options = [
|
30
|
-
['i', 'image <image>', 'image path and format. use one of the following extensions: [gif, png, svg, pdf]'],
|
31
|
-
['r', 'remote [remoteName]', 'remote name (name is optional, leave empty when id is specified)'],
|
32
|
-
['', 'all-versions', 'enter all components versions into the graph, not only latest'],
|
33
|
-
[
|
34
|
-
'',
|
35
|
-
'layout <name>',
|
36
|
-
'GraphVis layout. default to "dot". options are [circo, dot, fdp, neato, osage, patchwork, sfdp, twopi]',
|
37
|
-
],
|
38
|
-
['j', 'json', 'json format'],
|
39
|
-
] as CommandOptions;
|
40
|
-
remoteOp = true;
|
41
|
-
|
42
|
-
constructor(private componentAspect: ComponentMain) {}
|
43
|
-
|
44
|
-
async report([id]: [string], { remote, allVersions, layout, image }: GraphOpt): Promise<string> {
|
45
|
-
const consumer = await loadConsumerIfExist();
|
46
|
-
if (!consumer && !remote) throw new ConsumerNotFound();
|
47
|
-
|
48
|
-
const graph = await this.generateGraph(consumer, id, remote, allVersions);
|
49
|
-
|
50
|
-
const config = {};
|
51
|
-
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
|
52
|
-
if (layout) config.layout = layout;
|
53
|
-
const visualDependencyGraph = await VisualDependencyGraph.loadFromGraphlib(graph, config);
|
54
|
-
|
55
|
-
image = image || path.join(os.tmpdir(), `${generateRandomStr()}.png`);
|
56
|
-
const result = await visualDependencyGraph.image(image);
|
57
|
-
|
58
|
-
return chalk.green(`image created at ${result}`);
|
59
|
-
}
|
60
|
-
|
61
|
-
private async generateGraph(
|
62
|
-
consumer?: Consumer,
|
63
|
-
id?: string,
|
64
|
-
remote?: string,
|
65
|
-
allVersions?: boolean
|
66
|
-
): Promise<GraphLib.Graph> {
|
67
|
-
if (!consumer && !remote) throw new ConsumerNotFound();
|
68
|
-
const getBitId = (): ComponentID | undefined => {
|
69
|
-
if (!id) return undefined;
|
70
|
-
if (remote) return ComponentID.fromString(id); // user used --remote so we know it has a scope
|
71
|
-
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
|
72
|
-
return consumer.getParsedId(id);
|
73
|
-
};
|
74
|
-
const bitId = getBitId();
|
75
|
-
if (remote) {
|
76
|
-
if (id) {
|
77
|
-
// @ts-ignore scope must be set as it came from a remote
|
78
|
-
const scopeName: string = typeof remote === 'string' ? remote : bitId.scope;
|
79
|
-
const remoteScope = await getRemoteByName(scopeName, consumer);
|
80
|
-
const componentDepGraph = await remoteScope.graph(bitId);
|
81
|
-
return componentDepGraph.graph;
|
82
|
-
}
|
83
|
-
if (typeof remote !== 'string') {
|
84
|
-
throw new Error('please specify remote scope name or enter an id');
|
85
|
-
}
|
86
|
-
const remoteScope = await getRemoteByName(remote, consumer);
|
87
|
-
const componentDepGraph = await remoteScope.graph();
|
88
|
-
return componentDepGraph.graph;
|
89
|
-
}
|
90
|
-
|
91
|
-
const onlyLatest = !allVersions;
|
92
|
-
// @ts-ignore consumer must be set here
|
93
|
-
const workspaceGraph = await DependencyGraph.buildGraphFromWorkspace(consumer, onlyLatest);
|
94
|
-
const dependencyGraph = new DependencyGraph(workspaceGraph);
|
95
|
-
if (id) {
|
96
|
-
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
|
97
|
-
const componentGraph = dependencyGraph.getSubGraphOfConnectedComponents(bitId);
|
98
|
-
const componentDepGraph = new DependencyGraph(componentGraph);
|
99
|
-
return componentDepGraph.graph;
|
100
|
-
}
|
101
|
-
return dependencyGraph.graph;
|
102
|
-
}
|
103
|
-
|
104
|
-
async json([id]: [string], { remote, allVersions }: GraphOpt) {
|
105
|
-
const consumer = await loadConsumerIfExist();
|
106
|
-
if (!consumer && !remote) throw new ConsumerNotFound();
|
107
|
-
|
108
|
-
const graph = await this.generateGraph(consumer, id, remote, allVersions);
|
109
|
-
return GraphLib.json.write(graph);
|
110
|
-
}
|
111
|
-
}
|
package/graph.aspect.ts
DELETED
package/graph.graphql.ts
DELETED
@@ -1,94 +0,0 @@
|
|
1
|
-
import { ComponentMain } from '@teambit/component';
|
2
|
-
import { Schema } from '@teambit/graphql';
|
3
|
-
import gql from 'graphql-tag';
|
4
|
-
|
5
|
-
import { GraphBuilder } from './graph-builder';
|
6
|
-
import { ComponentGraph } from './component-graph';
|
7
|
-
import { GraphFilter } from './model/graph-filters';
|
8
|
-
import { DependencyType } from './model/dependency';
|
9
|
-
import { EdgeType } from './edge-type';
|
10
|
-
|
11
|
-
const textCmp = new Intl.Collator().compare;
|
12
|
-
|
13
|
-
export function graphSchema(graphBuilder: GraphBuilder, componentAspect: ComponentMain): Schema {
|
14
|
-
return {
|
15
|
-
typeDefs: gql`
|
16
|
-
type ComponentGraph {
|
17
|
-
nodes: [ComponentGraphNode]
|
18
|
-
edges: [ComponentGraphEdge]
|
19
|
-
}
|
20
|
-
|
21
|
-
type ComponentGraphNode {
|
22
|
-
id: String
|
23
|
-
component: Component
|
24
|
-
}
|
25
|
-
|
26
|
-
enum DependencyLifecycleType {
|
27
|
-
PEER
|
28
|
-
RUNTIME
|
29
|
-
DEV
|
30
|
-
}
|
31
|
-
|
32
|
-
type ComponentGraphEdge {
|
33
|
-
sourceId: String
|
34
|
-
targetId: String
|
35
|
-
dependencyLifecycleType: DependencyLifecycleType
|
36
|
-
}
|
37
|
-
|
38
|
-
extend type Query {
|
39
|
-
graph(ids: [String], filter: String): ComponentGraph
|
40
|
-
}
|
41
|
-
`,
|
42
|
-
resolvers: {
|
43
|
-
ComponentGraph: {
|
44
|
-
nodes: (graph: ComponentGraph) => {
|
45
|
-
return graph.nodes
|
46
|
-
.map((node) => {
|
47
|
-
return {
|
48
|
-
id: node.id,
|
49
|
-
component: node.attr,
|
50
|
-
};
|
51
|
-
})
|
52
|
-
.sort((a, b) => textCmp(a.id, b.id));
|
53
|
-
},
|
54
|
-
edges: (graph: ComponentGraph) => {
|
55
|
-
return graph.edges
|
56
|
-
.map(
|
57
|
-
(edge) =>
|
58
|
-
({
|
59
|
-
sourceId: edge.sourceId,
|
60
|
-
targetId: edge.targetId,
|
61
|
-
dependencyLifecycleType: getDependencyLifecycleType(edge.attr.type),
|
62
|
-
} as { sourceId: string; targetId: string; dependencyLifecycleType: EdgeType })
|
63
|
-
)
|
64
|
-
.sort((a, b) => textCmp(a.sourceId, b.sourceId))
|
65
|
-
.sort((a, b) => textCmp(a.targetId, b.targetId));
|
66
|
-
},
|
67
|
-
},
|
68
|
-
Query: {
|
69
|
-
graph: async (_parent, { ids, filter }: { ids?: string[]; filter?: GraphFilter }) => {
|
70
|
-
const componentsHost = componentAspect.getHost();
|
71
|
-
const resolvedIds = ids
|
72
|
-
? await componentsHost.resolveMultipleComponentIds(ids)
|
73
|
-
: (await componentsHost.list()).map((x) => x.id);
|
74
|
-
|
75
|
-
const graph = await graphBuilder.getGraph(resolvedIds);
|
76
|
-
if (!graph) return undefined;
|
77
|
-
|
78
|
-
if (filter === 'runtimeOnly') {
|
79
|
-
const runtimeGraph = graph.runtimeOnly(resolvedIds.map((x) => x.toString()));
|
80
|
-
return runtimeGraph;
|
81
|
-
}
|
82
|
-
|
83
|
-
return graph;
|
84
|
-
},
|
85
|
-
},
|
86
|
-
},
|
87
|
-
};
|
88
|
-
}
|
89
|
-
|
90
|
-
function getDependencyLifecycleType(edgeRawData: DependencyType): EdgeType {
|
91
|
-
if (edgeRawData === 'dev') return EdgeType.dev;
|
92
|
-
if (edgeRawData === 'runtime') return EdgeType.runtime;
|
93
|
-
return EdgeType.peer;
|
94
|
-
}
|
package/graph.main.runtime.ts
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
import { CLIAspect, CLIMain, MainRuntime } from '@teambit/cli';
|
2
|
-
import { ComponentMain, ComponentAspect, ComponentID } from '@teambit/component';
|
3
|
-
import { GraphqlAspect, GraphqlMain } from '@teambit/graphql';
|
4
|
-
import { Logger, LoggerAspect, LoggerMain } from '@teambit/logger';
|
5
|
-
import { GetGraphOpts, GraphBuilder } from './graph-builder';
|
6
|
-
import { graphSchema } from './graph.graphql';
|
7
|
-
import { GraphAspect } from './graph.aspect';
|
8
|
-
import { GraphCmd } from './graph-cmd';
|
9
|
-
import { ComponentGraph } from './component-graph';
|
10
|
-
import { ComponentIdGraph } from './component-id-graph';
|
11
|
-
|
12
|
-
export class GraphMain {
|
13
|
-
constructor(private componentAspect: ComponentMain, private logger: Logger) {}
|
14
|
-
|
15
|
-
/**
|
16
|
-
* important - prefer using `getGraphIds()` it's way better in terms of performance.
|
17
|
-
*/
|
18
|
-
async getGraph(ids?: ComponentID[], opts: GetGraphOpts = {}): Promise<ComponentGraph> {
|
19
|
-
const graphBuilder = new GraphBuilder(this.componentAspect);
|
20
|
-
return graphBuilder.getGraph(ids, opts);
|
21
|
-
}
|
22
|
-
|
23
|
-
async getGraphIds(ids?: ComponentID[], opts: GetGraphOpts = {}): Promise<ComponentIdGraph> {
|
24
|
-
const graphBuilder = new GraphBuilder(this.componentAspect);
|
25
|
-
return graphBuilder.getGraphIds(ids, opts);
|
26
|
-
}
|
27
|
-
|
28
|
-
static slots = [];
|
29
|
-
static dependencies = [GraphqlAspect, ComponentAspect, CLIAspect, LoggerAspect];
|
30
|
-
static runtime = MainRuntime;
|
31
|
-
static async provider([graphql, componentAspect, cli, loggerMain]: [
|
32
|
-
GraphqlMain,
|
33
|
-
ComponentMain,
|
34
|
-
CLIMain,
|
35
|
-
LoggerMain
|
36
|
-
]) {
|
37
|
-
const logger = loggerMain.createLogger(GraphAspect.id);
|
38
|
-
|
39
|
-
const graphBuilder = new GraphBuilder(componentAspect);
|
40
|
-
graphql.register(graphSchema(graphBuilder, componentAspect));
|
41
|
-
|
42
|
-
const graphMain = new GraphMain(componentAspect, logger);
|
43
|
-
cli.register(new GraphCmd(componentAspect));
|
44
|
-
|
45
|
-
return graphMain;
|
46
|
-
}
|
47
|
-
}
|
48
|
-
|
49
|
-
GraphAspect.addRuntime(GraphMain);
|
package/index.ts
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
export { DependenciesCompare } from './ui/dependencies-compare';
|
2
|
-
export { Dependency } from './model/dependency';
|
3
|
-
export { DuplicateDependency } from './duplicate-dependency';
|
4
|
-
export { GraphAspect as default, GraphAspect } from './graph.aspect';
|
5
|
-
export { IdGraph, objectListToGraph, bitObjectListToGraph } from './object-list-to-graph';
|
6
|
-
export {
|
7
|
-
calcElements,
|
8
|
-
calcLayout,
|
9
|
-
calcMinimapColors,
|
10
|
-
depTypeToClass,
|
11
|
-
depTypeToLabel,
|
12
|
-
styles as dependenciesGraphStyles,
|
13
|
-
} from './ui/dependencies-graph';
|
14
|
-
export { GraphFilters, styles as graphPageStyles } from './ui/graph-page';
|
15
|
-
export { EdgeModel, GraphModel, NodeModel, useGraph, useGraphQuery } from './ui/query';
|
16
|
-
export { styles as componentNodeStyles, root, defaultNode, external } from './ui/component-node';
|
17
|
-
export type { RawGraph } from './ui/query';
|
18
|
-
export type { CompIdGraph, DepEdgeType } from './component-id-graph';
|
19
|
-
export type { ComponentGraph } from './component-graph';
|
20
|
-
export type { ComponentWidget, ComponentWidgetProps, ComponentWidgetSlot, GraphUI } from './graph.ui.runtime';
|
21
|
-
export { EdgeType } from './edge-type';
|
22
|
-
export type { GraphBuilder } from './graph-builder';
|
23
|
-
export type { GraphFilter } from './model/graph-filters';
|
24
|
-
export type { GraphMain } from './graph.main.runtime';
|
25
|
-
export type { VersionSubgraph } from './duplicate-dependency';
|
package/object-list-to-graph.ts
DELETED
@@ -1,66 +0,0 @@
|
|
1
|
-
import { Graph, Node, Edge } from '@teambit/graph.cleargraph';
|
2
|
-
import { uniqBy } from 'lodash';
|
3
|
-
import { ComponentID } from '@teambit/component-id';
|
4
|
-
import type { ObjectList } from '@teambit/legacy/dist/scope/objects/object-list';
|
5
|
-
import { BitObjectList } from '@teambit/legacy/dist/scope/objects/bit-object-list';
|
6
|
-
import { getAllVersionsInfo } from '@teambit/legacy/dist/scope/component-ops/traverse-versions';
|
7
|
-
import { Dependency } from './model/dependency';
|
8
|
-
|
9
|
-
type BitIdNode = Node<ComponentID>;
|
10
|
-
type DependencyEdge = Edge<Dependency>;
|
11
|
-
|
12
|
-
export class IdGraph extends Graph<ComponentID, Dependency> {
|
13
|
-
constructor(nodes: BitIdNode[] = [], edges: DependencyEdge[] = []) {
|
14
|
-
super(nodes, edges);
|
15
|
-
}
|
16
|
-
}
|
17
|
-
|
18
|
-
export async function objectListToGraph(objectList: ObjectList): Promise<IdGraph> {
|
19
|
-
const bitObjectsList = await objectList.toBitObjects();
|
20
|
-
|
21
|
-
return bitObjectListToGraph(bitObjectsList);
|
22
|
-
}
|
23
|
-
|
24
|
-
export async function bitObjectListToGraph(bitObjectsList: BitObjectList): Promise<IdGraph> {
|
25
|
-
const exportMetadata = bitObjectsList.getExportMetadata();
|
26
|
-
const components = bitObjectsList.getComponents();
|
27
|
-
const versions = bitObjectsList.getVersions();
|
28
|
-
const nodes: BitIdNode[] = [];
|
29
|
-
const edges: DependencyEdge[] = [];
|
30
|
-
await Promise.all(
|
31
|
-
components.map(async (component) => {
|
32
|
-
const compFromMetadata = exportMetadata?.exportVersions.find((c) =>
|
33
|
-
c.id.isEqualWithoutVersion(component.toComponentId())
|
34
|
-
);
|
35
|
-
const startFrom = compFromMetadata?.head;
|
36
|
-
const versionsInfo = await getAllVersionsInfo({
|
37
|
-
modelComponent: component,
|
38
|
-
versionObjects: versions,
|
39
|
-
startFrom,
|
40
|
-
throws: false,
|
41
|
-
});
|
42
|
-
versionsInfo.forEach((versionInfo) => {
|
43
|
-
const id = component.toComponentId().changeVersion(versionInfo.tag || versionInfo.ref.toString());
|
44
|
-
const idStr = id.toString();
|
45
|
-
nodes.push(new Node(idStr, id));
|
46
|
-
if (!versionInfo.version) {
|
47
|
-
return;
|
48
|
-
}
|
49
|
-
const { dependencies, devDependencies, extensionDependencies } = versionInfo.version.depsIdsGroupedByType;
|
50
|
-
const addDep = (depId: ComponentID, edge: Dependency) => {
|
51
|
-
const depIdStr = depId.toString();
|
52
|
-
nodes.push(new Node(depIdStr, depId));
|
53
|
-
edges.push(new Edge(idStr, depIdStr, edge));
|
54
|
-
};
|
55
|
-
const runTime = new Dependency('runtime');
|
56
|
-
const dev = new Dependency('dev');
|
57
|
-
dependencies.forEach((depId) => addDep(depId, runTime));
|
58
|
-
[...devDependencies, ...extensionDependencies].forEach((depId) => addDep(depId, dev));
|
59
|
-
});
|
60
|
-
})
|
61
|
-
);
|
62
|
-
const uniqNodes = uniqBy(nodes, 'id');
|
63
|
-
const idGraph = new IdGraph(uniqNodes, edges);
|
64
|
-
|
65
|
-
return idGraph;
|
66
|
-
}
|