@teambit/workspace 0.0.918 → 0.0.919

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.
@@ -0,0 +1,45 @@
1
+ import { Graph } from '@teambit/graph.cleargraph';
2
+ import { ComponentID } from '@teambit/component';
3
+ import { ComponentDependency, DependencyResolverMain } from '@teambit/dependency-resolver';
4
+ import { DepEdgeType } from '@teambit/graph';
5
+ import { Logger } from '@teambit/logger';
6
+ import { Workspace } from './workspace';
7
+ export declare function lifecycleToDepType(compDep: ComponentDependency): DepEdgeType;
8
+ export declare class GraphIdsFromFsBuilder {
9
+ private workspace;
10
+ private logger;
11
+ private dependencyResolver;
12
+ private shouldThrowOnMissingDep;
13
+ private graph;
14
+ private completed;
15
+ private depth;
16
+ private consumer;
17
+ private loadedComponents;
18
+ private importedIds;
19
+ constructor(workspace: Workspace, logger: Logger, dependencyResolver: DependencyResolverMain, shouldThrowOnMissingDep?: boolean);
20
+ /**
21
+ * create a graph with all dependencies and flattened dependencies of the given components.
22
+ * the nodes are component-ids and the edges has a label of the dependency type.
23
+ * to get some info about this the graph build take a look into build-graph-from-fs.buildGraph() docs.
24
+ */
25
+ buildGraph(ids: ComponentID[]): Promise<Graph<ComponentID, DepEdgeType>>;
26
+ private processManyComponents;
27
+ /**
28
+ * only for components from the workspace that can be modified to add/remove dependencies, we need to make sure that
29
+ * all their dependencies are imported.
30
+ * once a component from scope is imported, we know that either we have its dependency graph or all flattened deps
31
+ */
32
+ private importObjects;
33
+ private processOneComponent;
34
+ /**
35
+ * this is tricky.
36
+ * the component is in the workspace so it can be modified. dependencies can be added/removed/updated/downgraded.
37
+ * we have the graph-dependencies from the last snap, so we prefer to use it whenever possible for performance reasons.
38
+ * if we can't use it, we have to recursively load dependencies components and get the data from there.
39
+ * to maximize the performance, we iterate the direct dependencies, if we find a dep with the same id in the graph,
40
+ * then ask the graph for all its successors. otherwise, if it's not there, fallback to load the deps components.
41
+ */
42
+ private processCompFromWorkspaceWithGraph;
43
+ private addDepEdge;
44
+ private loadManyComponents;
45
+ }
@@ -0,0 +1,222 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ require("core-js/modules/es.array.iterator.js");
5
+ require("core-js/modules/es.promise.js");
6
+ Object.defineProperty(exports, "__esModule", {
7
+ value: true
8
+ });
9
+ exports.GraphIdsFromFsBuilder = void 0;
10
+ exports.lifecycleToDepType = lifecycleToDepType;
11
+ function _defineProperty2() {
12
+ const data = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
13
+ _defineProperty2 = function () {
14
+ return data;
15
+ };
16
+ return data;
17
+ }
18
+ function _pMapSeries() {
19
+ const data = _interopRequireDefault(require("p-map-series"));
20
+ _pMapSeries = function () {
21
+ return data;
22
+ };
23
+ return data;
24
+ }
25
+ function _graph() {
26
+ const data = require("@teambit/graph.cleargraph");
27
+ _graph = function () {
28
+ return data;
29
+ };
30
+ return data;
31
+ }
32
+ function _lodash() {
33
+ const data = require("lodash");
34
+ _lodash = function () {
35
+ return data;
36
+ };
37
+ return data;
38
+ }
39
+ function _bitIds() {
40
+ const data = _interopRequireDefault(require("@teambit/legacy/dist/bit-id/bit-ids"));
41
+ _bitIds = function () {
42
+ return data;
43
+ };
44
+ return data;
45
+ }
46
+ function _exceptions() {
47
+ const data = require("@teambit/legacy/dist/scope/exceptions");
48
+ _exceptions = function () {
49
+ return data;
50
+ };
51
+ return data;
52
+ }
53
+ function _scope() {
54
+ const data = require("@teambit/scope");
55
+ _scope = function () {
56
+ return data;
57
+ };
58
+ return data;
59
+ }
60
+ function _lodash2() {
61
+ const data = _interopRequireDefault(require("lodash.compact"));
62
+ _lodash2 = function () {
63
+ return data;
64
+ };
65
+ return data;
66
+ }
67
+ function _bitError() {
68
+ const data = require("@teambit/bit-error");
69
+ _bitError = function () {
70
+ return data;
71
+ };
72
+ return data;
73
+ }
74
+ function lifecycleToDepType(compDep) {
75
+ if (compDep.isExtension) return 'ext';
76
+ switch (compDep.lifecycle) {
77
+ case 'dev':
78
+ return 'dev';
79
+ case 'runtime':
80
+ return 'prod';
81
+ default:
82
+ throw new Error(`lifecycle ${compDep.lifecycle} is not support`);
83
+ }
84
+ }
85
+ class GraphIdsFromFsBuilder {
86
+ constructor(workspace, logger, dependencyResolver, shouldThrowOnMissingDep = true) {
87
+ this.workspace = workspace;
88
+ this.logger = logger;
89
+ this.dependencyResolver = dependencyResolver;
90
+ this.shouldThrowOnMissingDep = shouldThrowOnMissingDep;
91
+ (0, _defineProperty2().default)(this, "graph", new (_graph().Graph)());
92
+ (0, _defineProperty2().default)(this, "completed", []);
93
+ (0, _defineProperty2().default)(this, "depth", 1);
94
+ (0, _defineProperty2().default)(this, "consumer", void 0);
95
+ (0, _defineProperty2().default)(this, "loadedComponents", {});
96
+ (0, _defineProperty2().default)(this, "importedIds", []);
97
+ this.consumer = this.workspace.consumer;
98
+ }
99
+
100
+ /**
101
+ * create a graph with all dependencies and flattened dependencies of the given components.
102
+ * the nodes are component-ids and the edges has a label of the dependency type.
103
+ * to get some info about this the graph build take a look into build-graph-from-fs.buildGraph() docs.
104
+ */
105
+ async buildGraph(ids) {
106
+ this.logger.debug(`GraphIdsFromFsBuilder, buildGraph with ${ids.length} seeders`);
107
+ const start = Date.now();
108
+ const components = await this.loadManyComponents(ids);
109
+ await this.processManyComponents(components);
110
+ this.logger.debug(`GraphIdsFromFsBuilder, buildGraph with ${ids.length} seeders completed (${(Date.now() - start) / 1000} sec)`);
111
+ return this.graph;
112
+ }
113
+ async processManyComponents(components) {
114
+ this.logger.debug(`GraphIdsFromFsBuilder.processManyComponents depth ${this.depth}, ${components.length} components`);
115
+ this.depth += 1;
116
+ await this.importObjects(components);
117
+ const allDependencies = await (0, _pMapSeries().default)(components, component => this.processOneComponent(component));
118
+ const allDependenciesFlattened = (0, _lodash().flatten)(allDependencies);
119
+ if (allDependenciesFlattened.length) await this.processManyComponents(allDependenciesFlattened);
120
+ }
121
+
122
+ /**
123
+ * only for components from the workspace that can be modified to add/remove dependencies, we need to make sure that
124
+ * all their dependencies are imported.
125
+ * once a component from scope is imported, we know that either we have its dependency graph or all flattened deps
126
+ */
127
+ async importObjects(components) {
128
+ const workspaceIds = await this.workspace.listIds();
129
+ const compOnWorkspaceOnly = components.filter(comp => workspaceIds.find(id => id.isEqual(comp.id)));
130
+ const notImported = compOnWorkspaceOnly.map(c => c.id).filter(id => !this.importedIds.includes(id.toString()));
131
+ const withScope = notImported.map(id => id._legacy).filter(dep => dep.hasScope());
132
+ const scopeComponentsImporter = this.consumer.scope.scopeImporter;
133
+ await scopeComponentsImporter.importMany({
134
+ ids: _bitIds().default.uniqFromArray(withScope),
135
+ throwForDependencyNotFound: this.shouldThrowOnMissingDep,
136
+ throwForSeederNotFound: this.shouldThrowOnMissingDep,
137
+ reFetchUnBuiltVersion: false,
138
+ preferDependencyGraph: true
139
+ });
140
+ notImported.map(id => this.importedIds.push(id.toString()));
141
+ }
142
+ async processOneComponent(component) {
143
+ const idStr = component.id.toString();
144
+ if (this.completed.includes(idStr)) return [];
145
+ const graphFromScope = await this.workspace.getSavedGraphOfComponentIfExist(component);
146
+ if (graphFromScope !== null && graphFromScope !== void 0 && graphFromScope.edges.length) {
147
+ const isOnWorkspace = await this.workspace.hasId(component.id);
148
+ if (isOnWorkspace) {
149
+ const allDependenciesComps = await this.processCompFromWorkspaceWithGraph(graphFromScope, component);
150
+ this.completed.push(idStr);
151
+ return allDependenciesComps;
152
+ }
153
+ this.graph.merge([graphFromScope]);
154
+ this.completed.push(idStr);
155
+ return [];
156
+ }
157
+ const deps = await this.dependencyResolver.getComponentDependencies(component);
158
+ const allDepsIds = deps.map(d => d.componentId);
159
+ const allDependenciesComps = await this.loadManyComponents(allDepsIds, idStr);
160
+ deps.forEach(dep => this.addDepEdge(idStr, dep));
161
+ this.completed.push(idStr);
162
+ return allDependenciesComps;
163
+ }
164
+
165
+ /**
166
+ * this is tricky.
167
+ * the component is in the workspace so it can be modified. dependencies can be added/removed/updated/downgraded.
168
+ * we have the graph-dependencies from the last snap, so we prefer to use it whenever possible for performance reasons.
169
+ * if we can't use it, we have to recursively load dependencies components and get the data from there.
170
+ * to maximize the performance, we iterate the direct dependencies, if we find a dep with the same id in the graph,
171
+ * then ask the graph for all its successors. otherwise, if it's not there, fallback to load the deps components.
172
+ */
173
+ async processCompFromWorkspaceWithGraph(graphFromScope, component) {
174
+ const deps = await this.dependencyResolver.getComponentDependencies(component);
175
+ const [depsInScopeGraph, depsNotInScopeGraph] = (0, _lodash().partition)(deps, dep => graphFromScope.hasNode(dep.componentId.toString()));
176
+ const subGraphs = depsInScopeGraph.map(dep => graphFromScope.successorsSubgraph([dep.componentId.toString()]));
177
+ this.graph.merge(subGraphs);
178
+ const allDepsIds = depsNotInScopeGraph.map(d => d.componentId);
179
+ const idStr = component.id.toString();
180
+ const allDependenciesComps = await this.loadManyComponents(allDepsIds, idStr);
181
+ deps.forEach(dep => this.addDepEdge(idStr, dep));
182
+ return allDependenciesComps;
183
+ }
184
+ addDepEdge(idStr, dep) {
185
+ const depId = dep.componentId;
186
+ if (!this.graph.hasNode(depId.toString())) {
187
+ if (this.shouldThrowOnMissingDep) {
188
+ throw new Error(`buildOneComponent: missing node of ${depId.toString()}`);
189
+ }
190
+ this.logger.warn(`ignoring missing ${depId.toString()}`);
191
+ return;
192
+ }
193
+ this.graph.setEdge(new (_graph().Edge)(idStr, depId.toString(), lifecycleToDepType(dep)));
194
+ }
195
+ async loadManyComponents(componentsIds, dependenciesOf) {
196
+ const components = await (0, _pMapSeries().default)(componentsIds, async comp => {
197
+ const idStr = comp.toString();
198
+ const fromCache = this.loadedComponents[idStr];
199
+ if (fromCache) return fromCache;
200
+ try {
201
+ const component = await this.workspace.get(comp);
202
+ this.loadedComponents[idStr] = component;
203
+ this.graph.setNode(new (_graph().Node)(idStr, component.id));
204
+ return component;
205
+ } catch (err) {
206
+ if (err instanceof _exceptions().ComponentNotFound || err instanceof _scope().ComponentNotFound || err instanceof _exceptions().ScopeNotFound) {
207
+ if (dependenciesOf && !this.shouldThrowOnMissingDep) {
208
+ this.logger.warn(`component ${idStr}, dependency of ${dependenciesOf} was not found. continuing without it`);
209
+ return null;
210
+ }
211
+ throw new (_bitError().BitError)(`error: component "${idStr}" was not found.\nthis component is a dependency of "${dependenciesOf || '<none>'}" and is needed as part of the graph generation`);
212
+ }
213
+ if (dependenciesOf) this.logger.error(`failed loading dependencies of ${dependenciesOf}`);
214
+ throw err;
215
+ }
216
+ });
217
+ return (0, _lodash2().default)(components);
218
+ }
219
+ }
220
+ exports.GraphIdsFromFsBuilder = GraphIdsFromFsBuilder;
221
+
222
+ //# sourceMappingURL=build-graph-ids-from-fs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["lifecycleToDepType","compDep","isExtension","lifecycle","Error","GraphIdsFromFsBuilder","constructor","workspace","logger","dependencyResolver","shouldThrowOnMissingDep","Graph","consumer","buildGraph","ids","debug","length","start","Date","now","components","loadManyComponents","processManyComponents","graph","depth","importObjects","allDependencies","mapSeries","component","processOneComponent","allDependenciesFlattened","flatten","workspaceIds","listIds","compOnWorkspaceOnly","filter","comp","find","id","isEqual","notImported","map","c","importedIds","includes","toString","withScope","_legacy","dep","hasScope","scopeComponentsImporter","scope","scopeImporter","importMany","BitIds","uniqFromArray","throwForDependencyNotFound","throwForSeederNotFound","reFetchUnBuiltVersion","preferDependencyGraph","push","idStr","completed","graphFromScope","getSavedGraphOfComponentIfExist","edges","isOnWorkspace","hasId","allDependenciesComps","processCompFromWorkspaceWithGraph","merge","deps","getComponentDependencies","allDepsIds","d","componentId","forEach","addDepEdge","depsInScopeGraph","depsNotInScopeGraph","partition","hasNode","subGraphs","successorsSubgraph","depId","warn","setEdge","Edge","componentsIds","dependenciesOf","fromCache","loadedComponents","get","setNode","Node","err","ComponentNotFound","ComponentNotFoundInScope","ScopeNotFound","BitError","error","compact"],"sources":["build-graph-ids-from-fs.ts"],"sourcesContent":["import mapSeries from 'p-map-series';\nimport { Graph, Node, Edge } from '@teambit/graph.cleargraph';\nimport { flatten, partition } from 'lodash';\nimport { Consumer } from '@teambit/legacy/dist/consumer';\nimport { Component, ComponentID } from '@teambit/component';\nimport BitIds from '@teambit/legacy/dist/bit-id/bit-ids';\nimport { ComponentDependency, DependencyResolverMain } from '@teambit/dependency-resolver';\nimport { CompIdGraph, DepEdgeType } from '@teambit/graph';\nimport { ComponentNotFound, ScopeNotFound } from '@teambit/legacy/dist/scope/exceptions';\nimport { ComponentNotFound as ComponentNotFoundInScope } from '@teambit/scope';\nimport compact from 'lodash.compact';\nimport { Logger } from '@teambit/logger';\nimport { BitError } from '@teambit/bit-error';\nimport { Workspace } from './workspace';\n\nexport function lifecycleToDepType(compDep: ComponentDependency): DepEdgeType {\n if (compDep.isExtension) return 'ext';\n switch (compDep.lifecycle) {\n case 'dev':\n return 'dev';\n case 'runtime':\n return 'prod';\n default:\n throw new Error(`lifecycle ${compDep.lifecycle} is not support`);\n }\n}\n\nexport class GraphIdsFromFsBuilder {\n private graph = new Graph<ComponentID, DepEdgeType>();\n private completed: string[] = [];\n private depth = 1;\n private consumer: Consumer;\n private loadedComponents: { [idStr: string]: Component } = {};\n private importedIds: string[] = [];\n constructor(\n private workspace: Workspace,\n private logger: Logger,\n private dependencyResolver: DependencyResolverMain,\n private shouldThrowOnMissingDep = true\n ) {\n this.consumer = this.workspace.consumer;\n }\n\n /**\n * create a graph with all dependencies and flattened dependencies of the given components.\n * the nodes are component-ids and the edges has a label of the dependency type.\n * to get some info about this the graph build take a look into build-graph-from-fs.buildGraph() docs.\n */\n async buildGraph(ids: ComponentID[]): Promise<Graph<ComponentID, DepEdgeType>> {\n this.logger.debug(`GraphIdsFromFsBuilder, buildGraph with ${ids.length} seeders`);\n const start = Date.now();\n const components = await this.loadManyComponents(ids);\n await this.processManyComponents(components);\n this.logger.debug(\n `GraphIdsFromFsBuilder, buildGraph with ${ids.length} seeders completed (${(Date.now() - start) / 1000} sec)`\n );\n return this.graph;\n }\n\n private async processManyComponents(components: Component[]) {\n this.logger.debug(\n `GraphIdsFromFsBuilder.processManyComponents depth ${this.depth}, ${components.length} components`\n );\n this.depth += 1;\n await this.importObjects(components);\n const allDependencies = await mapSeries(components, (component) => this.processOneComponent(component));\n const allDependenciesFlattened = flatten(allDependencies);\n if (allDependenciesFlattened.length) await this.processManyComponents(allDependenciesFlattened);\n }\n\n /**\n * only for components from the workspace that can be modified to add/remove dependencies, we need to make sure that\n * all their dependencies are imported.\n * once a component from scope is imported, we know that either we have its dependency graph or all flattened deps\n */\n private async importObjects(components: Component[]) {\n const workspaceIds = await this.workspace.listIds();\n const compOnWorkspaceOnly = components.filter((comp) => workspaceIds.find((id) => id.isEqual(comp.id)));\n const notImported = compOnWorkspaceOnly.map((c) => c.id).filter((id) => !this.importedIds.includes(id.toString()));\n const withScope = notImported.map((id) => id._legacy).filter((dep) => dep.hasScope());\n const scopeComponentsImporter = this.consumer.scope.scopeImporter;\n await scopeComponentsImporter.importMany({\n ids: BitIds.uniqFromArray(withScope),\n throwForDependencyNotFound: this.shouldThrowOnMissingDep,\n throwForSeederNotFound: this.shouldThrowOnMissingDep,\n reFetchUnBuiltVersion: false,\n preferDependencyGraph: true,\n });\n notImported.map((id) => this.importedIds.push(id.toString()));\n }\n\n private async processOneComponent(component: Component) {\n const idStr = component.id.toString();\n if (this.completed.includes(idStr)) return [];\n const graphFromScope = await this.workspace.getSavedGraphOfComponentIfExist(component);\n if (graphFromScope?.edges.length) {\n const isOnWorkspace = await this.workspace.hasId(component.id);\n if (isOnWorkspace) {\n const allDependenciesComps = await this.processCompFromWorkspaceWithGraph(graphFromScope, component);\n this.completed.push(idStr);\n return allDependenciesComps;\n }\n this.graph.merge([graphFromScope]);\n this.completed.push(idStr);\n return [];\n }\n\n const deps = await this.dependencyResolver.getComponentDependencies(component);\n const allDepsIds = deps.map((d) => d.componentId);\n const allDependenciesComps = await this.loadManyComponents(allDepsIds, idStr);\n\n deps.forEach((dep) => this.addDepEdge(idStr, dep));\n this.completed.push(idStr);\n\n return allDependenciesComps;\n }\n\n /**\n * this is tricky.\n * the component is in the workspace so it can be modified. dependencies can be added/removed/updated/downgraded.\n * we have the graph-dependencies from the last snap, so we prefer to use it whenever possible for performance reasons.\n * if we can't use it, we have to recursively load dependencies components and get the data from there.\n * to maximize the performance, we iterate the direct dependencies, if we find a dep with the same id in the graph,\n * then ask the graph for all its successors. otherwise, if it's not there, fallback to load the deps components.\n */\n private async processCompFromWorkspaceWithGraph(\n graphFromScope: CompIdGraph,\n component: Component\n ): Promise<Component[]> {\n const deps = await this.dependencyResolver.getComponentDependencies(component);\n const [depsInScopeGraph, depsNotInScopeGraph] = partition(deps, (dep) =>\n graphFromScope.hasNode(dep.componentId.toString())\n );\n const subGraphs = depsInScopeGraph.map((dep) => graphFromScope.successorsSubgraph([dep.componentId.toString()]));\n this.graph.merge(subGraphs);\n\n const allDepsIds = depsNotInScopeGraph.map((d) => d.componentId);\n const idStr = component.id.toString();\n const allDependenciesComps = await this.loadManyComponents(allDepsIds, idStr);\n deps.forEach((dep) => this.addDepEdge(idStr, dep));\n return allDependenciesComps;\n }\n\n private addDepEdge(idStr: string, dep: ComponentDependency) {\n const depId = dep.componentId;\n if (!this.graph.hasNode(depId.toString())) {\n if (this.shouldThrowOnMissingDep) {\n throw new Error(`buildOneComponent: missing node of ${depId.toString()}`);\n }\n this.logger.warn(`ignoring missing ${depId.toString()}`);\n return;\n }\n this.graph.setEdge(new Edge(idStr, depId.toString(), lifecycleToDepType(dep)));\n }\n\n private async loadManyComponents(componentsIds: ComponentID[], dependenciesOf?: string): Promise<Component[]> {\n const components = await mapSeries(componentsIds, async (comp) => {\n const idStr = comp.toString();\n const fromCache = this.loadedComponents[idStr];\n if (fromCache) return fromCache;\n try {\n const component = await this.workspace.get(comp);\n this.loadedComponents[idStr] = component;\n this.graph.setNode(new Node(idStr, component.id));\n return component;\n } catch (err: any) {\n if (\n err instanceof ComponentNotFound ||\n err instanceof ComponentNotFoundInScope ||\n err instanceof ScopeNotFound\n ) {\n if (dependenciesOf && !this.shouldThrowOnMissingDep) {\n this.logger.warn(\n `component ${idStr}, dependency of ${dependenciesOf} was not found. continuing without it`\n );\n return null;\n }\n throw new BitError(\n `error: component \"${idStr}\" was not found.\\nthis component is a dependency of \"${\n dependenciesOf || '<none>'\n }\" and is needed as part of the graph generation`\n );\n }\n if (dependenciesOf) this.logger.error(`failed loading dependencies of ${dependenciesOf}`);\n throw err;\n }\n });\n return compact(components);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAGA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAGA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAGO,SAASA,kBAAkB,CAACC,OAA4B,EAAe;EAC5E,IAAIA,OAAO,CAACC,WAAW,EAAE,OAAO,KAAK;EACrC,QAAQD,OAAO,CAACE,SAAS;IACvB,KAAK,KAAK;MACR,OAAO,KAAK;IACd,KAAK,SAAS;MACZ,OAAO,MAAM;IACf;MACE,MAAM,IAAIC,KAAK,CAAE,aAAYH,OAAO,CAACE,SAAU,iBAAgB,CAAC;EAAC;AAEvE;AAEO,MAAME,qBAAqB,CAAC;EAOjCC,WAAW,CACDC,SAAoB,EACpBC,MAAc,EACdC,kBAA0C,EAC1CC,uBAAuB,GAAG,IAAI,EACtC;IAAA,KAJQH,SAAoB,GAApBA,SAAoB;IAAA,KACpBC,MAAc,GAAdA,MAAc;IAAA,KACdC,kBAA0C,GAA1CA,kBAA0C;IAAA,KAC1CC,uBAAuB,GAAvBA,uBAAuB;IAAA,+CAVjB,KAAIC,cA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,EAAE,IAAI,CAACjF,MAAM,CAAC4F,KAAK,CAAE,kCAAiCX,cAAe,EAAC,CAAC;QACzF,MAAMM,GAAG;MACX;IACF,CAAC,CAAC;IACF,OAAO,IAAAM,kBAAO,EAACjF,UAAU,CAAC;EAC5B;AACF;AAAC"}
@@ -20,6 +20,7 @@ import type { AddActionResults, Warnings } from '@teambit/legacy/dist/consumer/c
20
20
  import ComponentsList from '@teambit/legacy/dist/consumer/component/components-list';
21
21
  import { ExtensionDataList } from '@teambit/legacy/dist/consumer/config/extension-data';
22
22
  import { PathOsBased, PathOsBasedRelative, PathOsBasedAbsolute } from '@teambit/legacy/dist/utils/path';
23
+ import { CompIdGraph, DepEdgeType } from '@teambit/graph';
23
24
  import ConsumerComponent from '@teambit/legacy/dist/consumer/component';
24
25
  import type { ComponentLog } from '@teambit/legacy/dist/scope/models/model-component';
25
26
  import { CompilationInitiator } from '@teambit/compiler';
@@ -228,6 +229,8 @@ export declare class Workspace implements ComponentFactory {
228
229
  newAndModified(): Promise<Component[]>;
229
230
  getLogs(id: ComponentID, shortHash?: boolean, startsFrom?: string): Promise<ComponentLog[]>;
230
231
  getGraph(ids?: ComponentID[], shouldThrowOnMissingDep?: boolean): Promise<Graph<Component, string>>;
232
+ getGraphIds(ids?: ComponentID[], shouldThrowOnMissingDep?: boolean): Promise<CompIdGraph>;
233
+ getSavedGraphOfComponentIfExist(component: Component): Promise<Graph<ComponentID, DepEdgeType> | null>;
231
234
  /**
232
235
  * given component ids, find their dependents in the workspace
233
236
  */
@@ -413,7 +416,6 @@ export declare class Workspace implements ComponentFactory {
413
416
  */
414
417
  loadAspects(ids?: string[], throwOnError?: boolean, neededFor?: string): Promise<string[]>;
415
418
  /**
416
- * Note - this gets called from Harmony only.
417
419
  * returns one graph that includes all dependencies types. each edge has a label of the dependency
418
420
  * type. the nodes content is the Component object.
419
421
  */
package/dist/workspace.js CHANGED
@@ -32,6 +32,13 @@ function _pMapSeries() {
32
32
  };
33
33
  return data;
34
34
  }
35
+ function _graph() {
36
+ const data = require("@teambit/graph.cleargraph");
37
+ _graph = function () {
38
+ return data;
39
+ };
40
+ return data;
41
+ }
35
42
  function _aspectLoader() {
36
43
  const data = require("@teambit/aspect-loader");
37
44
  _aspectLoader = function () {
@@ -298,6 +305,13 @@ function _workspace() {
298
305
  };
299
306
  return data;
300
307
  }
308
+ function _buildGraphIdsFromFs() {
309
+ const data = require("./build-graph-ids-from-fs");
310
+ _buildGraphIdsFromFs = function () {
311
+ return data;
312
+ };
313
+ return data;
314
+ }
301
315
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
302
316
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2().default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
303
317
  const AspectSpecificField = '__specific';
@@ -586,6 +600,44 @@ class Workspace {
586
600
  if (!ids || ids.length < 1) ids = await this.listIds();
587
601
  return this.buildOneGraphForComponents(ids, undefined, undefined, shouldThrowOnMissingDep);
588
602
  }
603
+ async getGraphIds(ids, shouldThrowOnMissingDep = true) {
604
+ if (!ids || ids.length < 1) ids = await this.listIds();
605
+ const graphIdsFromFsBuilder = new (_buildGraphIdsFromFs().GraphIdsFromFsBuilder)(this, this.logger, this.dependencyResolver, shouldThrowOnMissingDep);
606
+ return graphIdsFromFsBuilder.buildGraph(ids);
607
+ }
608
+ async getSavedGraphOfComponentIfExist(component) {
609
+ let versionObj;
610
+ try {
611
+ versionObj = await this.scope.legacyScope.getVersionInstance(component.id._legacy);
612
+ } catch (err) {
613
+ return null;
614
+ }
615
+ const flattenedEdges = versionObj.flattenedEdges;
616
+ if (!flattenedEdges.length && versionObj.flattenedDependencies.length) {
617
+ // there are flattenedDependencies, so must be edges, if they're empty, it's because the component was tagged
618
+ // with a version < ~0.0.901, so this flattenedEdges wasn't exist.
619
+ return null;
620
+ }
621
+ const flattenedBitIdCompIdMap = {};
622
+ flattenedBitIdCompIdMap[component.id._legacy.toString()] = component.id;
623
+ await Promise.all(versionObj.flattenedDependencies.map(async bitId => {
624
+ flattenedBitIdCompIdMap[bitId.toString()] = await this.resolveComponentId(bitId);
625
+ }));
626
+ const getCompIdByIdStr = idStr => {
627
+ const compId = flattenedBitIdCompIdMap[idStr];
628
+ if (!compId) throw new Error(`id ${idStr} exists in flattenedEdges but not in flattened`);
629
+ return compId;
630
+ };
631
+ const nodes = Object.values(flattenedBitIdCompIdMap);
632
+ const edges = flattenedEdges.map(edge => _objectSpread(_objectSpread({}, edge), {}, {
633
+ source: getCompIdByIdStr(edge.source.toString()),
634
+ target: getCompIdByIdStr(edge.target.toString())
635
+ }));
636
+ const graph = new (_graph().Graph)();
637
+ nodes.forEach(node => graph.setNode(new (_graph().Node)(node.toString(), node)));
638
+ edges.forEach(edge => graph.setEdge(new (_graph().Edge)(edge.source.toString(), edge.target.toString(), edge.type)));
639
+ return graph;
640
+ }
589
641
 
590
642
  /**
591
643
  * given component ids, find their dependents in the workspace
@@ -1614,7 +1666,6 @@ needed-for: ${neededFor || '<unknown>'}`);
1614
1666
  }
1615
1667
 
1616
1668
  /**
1617
- * Note - this gets called from Harmony only.
1618
1669
  * returns one graph that includes all dependencies types. each edge has a label of the dependency
1619
1670
  * type. the nodes content is the Component object.
1620
1671
  */