@teambit/workspace 0.0.886 → 0.0.888
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/dist/build-graph-from-fs.d.ts +13 -7
- package/dist/build-graph-from-fs.js +49 -36
- package/dist/build-graph-from-fs.js.map +1 -1
- package/dist/ui/workspace/use-workspace.d.ts +1 -1
- package/dist/watch/watch.cmd.d.ts +2 -2
- package/dist/workspace.d.ts +4 -5
- package/dist/workspace.js +8 -15
- package/dist/workspace.js.map +1 -1
- package/dist/workspace.ui.runtime.d.ts +1 -1
- package/package-tar/teambit-workspace-0.0.888.tgz +0 -0
- package/package.json +57 -56
- package/{preview-1666842256282.js → preview-1667101073781.js} +2 -2
- package/package-tar/teambit-workspace-0.0.886.tgz +0 -0
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import { BitId } from '@teambit/legacy-bit-id';
|
|
1
|
+
import { Graph } from '@teambit/graph.cleargraph';
|
|
2
|
+
import { Component, ComponentID } from '@teambit/component';
|
|
4
3
|
import { Logger } from '@teambit/logger';
|
|
5
4
|
import { Workspace } from './workspace';
|
|
6
|
-
export declare type ShouldLoadFunc = (
|
|
5
|
+
export declare type ShouldLoadFunc = (id: ComponentID) => Promise<boolean>;
|
|
7
6
|
export declare class GraphFromFsBuilder {
|
|
8
7
|
private workspace;
|
|
9
8
|
private logger;
|
|
@@ -14,7 +13,9 @@ export declare class GraphFromFsBuilder {
|
|
|
14
13
|
private completed;
|
|
15
14
|
private depth;
|
|
16
15
|
private consumer;
|
|
17
|
-
|
|
16
|
+
private legacyIdStrToComponentId;
|
|
17
|
+
private importedIds;
|
|
18
|
+
constructor(workspace: Workspace, logger: Logger, ignoreIds?: string[], shouldLoadItsDeps?: ShouldLoadFunc | undefined, shouldThrowOnMissingDep?: boolean);
|
|
18
19
|
/**
|
|
19
20
|
* create a graph with all dependencies and flattened dependencies of the given components.
|
|
20
21
|
* the nodes are components and the edges has a label of the dependency type.
|
|
@@ -45,12 +46,17 @@ export declare class GraphFromFsBuilder {
|
|
|
45
46
|
* however, since this buildGraph is performed on the workspace, a dependency may be new or
|
|
46
47
|
* modified and as such, we don't know its flattened yet.
|
|
47
48
|
*/
|
|
48
|
-
buildGraph(ids:
|
|
49
|
+
buildGraph(ids: ComponentID[]): Promise<Graph<Component, string>>;
|
|
49
50
|
private getAllDepsUnfiltered;
|
|
50
51
|
private getAllDepsFiltered;
|
|
51
52
|
private processManyComponents;
|
|
53
|
+
/**
|
|
54
|
+
* only for components from the workspace that can be modified to add/remove dependencies, we need to make sure that
|
|
55
|
+
* all their dependencies are imported.
|
|
56
|
+
* remember that `importMany` fetches all flattened dependencies. once a component from scope is imported, we know
|
|
57
|
+
* that all its flattened dependencies are there. no need to call importMany again for them.
|
|
58
|
+
*/
|
|
52
59
|
private importObjects;
|
|
53
60
|
private processOneComponent;
|
|
54
61
|
private loadManyComponents;
|
|
55
|
-
private loadComponent;
|
|
56
62
|
}
|
|
@@ -23,6 +23,13 @@ function _pMapSeries() {
|
|
|
23
23
|
};
|
|
24
24
|
return data;
|
|
25
25
|
}
|
|
26
|
+
function _graph() {
|
|
27
|
+
const data = require("@teambit/graph.cleargraph");
|
|
28
|
+
_graph = function () {
|
|
29
|
+
return data;
|
|
30
|
+
};
|
|
31
|
+
return data;
|
|
32
|
+
}
|
|
26
33
|
function _lodash() {
|
|
27
34
|
const data = require("lodash");
|
|
28
35
|
_lodash = function () {
|
|
@@ -37,20 +44,6 @@ function _bitIds() {
|
|
|
37
44
|
};
|
|
38
45
|
return data;
|
|
39
46
|
}
|
|
40
|
-
function _graph() {
|
|
41
|
-
const data = _interopRequireDefault(require("@teambit/legacy/dist/scope/graph/graph"));
|
|
42
|
-
_graph = function () {
|
|
43
|
-
return data;
|
|
44
|
-
};
|
|
45
|
-
return data;
|
|
46
|
-
}
|
|
47
|
-
function _scopeComponentsImporter() {
|
|
48
|
-
const data = _interopRequireDefault(require("@teambit/legacy/dist/scope/component-ops/scope-components-importer"));
|
|
49
|
-
_scopeComponentsImporter = function () {
|
|
50
|
-
return data;
|
|
51
|
-
};
|
|
52
|
-
return data;
|
|
53
|
-
}
|
|
54
47
|
function _exceptions() {
|
|
55
48
|
const data = require("@teambit/legacy/dist/scope/exceptions");
|
|
56
49
|
_exceptions = function () {
|
|
@@ -80,16 +73,18 @@ function _bitError() {
|
|
|
80
73
|
return data;
|
|
81
74
|
}
|
|
82
75
|
class GraphFromFsBuilder {
|
|
83
|
-
constructor(workspace, logger, ignoreIds =
|
|
76
|
+
constructor(workspace, logger, ignoreIds = [], shouldLoadItsDeps, shouldThrowOnMissingDep = true) {
|
|
84
77
|
this.workspace = workspace;
|
|
85
78
|
this.logger = logger;
|
|
86
79
|
this.ignoreIds = ignoreIds;
|
|
87
80
|
this.shouldLoadItsDeps = shouldLoadItsDeps;
|
|
88
81
|
this.shouldThrowOnMissingDep = shouldThrowOnMissingDep;
|
|
89
|
-
(0, _defineProperty2().default)(this, "graph", new (_graph().
|
|
82
|
+
(0, _defineProperty2().default)(this, "graph", new (_graph().Graph)());
|
|
90
83
|
(0, _defineProperty2().default)(this, "completed", []);
|
|
91
84
|
(0, _defineProperty2().default)(this, "depth", 1);
|
|
92
85
|
(0, _defineProperty2().default)(this, "consumer", void 0);
|
|
86
|
+
(0, _defineProperty2().default)(this, "legacyIdStrToComponentId", {});
|
|
87
|
+
(0, _defineProperty2().default)(this, "importedIds", []);
|
|
93
88
|
this.consumer = this.workspace.consumer;
|
|
94
89
|
}
|
|
95
90
|
|
|
@@ -131,19 +126,27 @@ class GraphFromFsBuilder {
|
|
|
131
126
|
this.logger.debug(`GraphFromFsBuilder, buildGraph with ${ids.length} seeders completed (${(Date.now() - start) / 1000} sec)`);
|
|
132
127
|
return this.graph;
|
|
133
128
|
}
|
|
134
|
-
getAllDepsUnfiltered(component) {
|
|
135
|
-
|
|
129
|
+
async getAllDepsUnfiltered(component) {
|
|
130
|
+
const consumerComp = component.state._consumer;
|
|
131
|
+
const legacyDepsIds = consumerComp.getAllDependenciesIds();
|
|
132
|
+
const depsIds = await Promise.all(legacyDepsIds.map(async bitId => {
|
|
133
|
+
if (!this.legacyIdStrToComponentId[bitId.toString()]) {
|
|
134
|
+
this.legacyIdStrToComponentId[bitId.toString()] = await this.workspace.resolveComponentId(bitId);
|
|
135
|
+
}
|
|
136
|
+
return this.legacyIdStrToComponentId[bitId.toString()];
|
|
137
|
+
}));
|
|
138
|
+
return depsIds.filter(depId => !this.ignoreIds.includes(depId.toString()));
|
|
136
139
|
}
|
|
137
140
|
async getAllDepsFiltered(component) {
|
|
138
|
-
const depsWithoutIgnore = this.getAllDepsUnfiltered(component);
|
|
141
|
+
const depsWithoutIgnore = await this.getAllDepsUnfiltered(component);
|
|
139
142
|
const shouldLoadFunc = this.shouldLoadItsDeps;
|
|
140
143
|
if (!shouldLoadFunc) return depsWithoutIgnore;
|
|
141
144
|
const deps = await (0, _pMapSeries().default)(depsWithoutIgnore, async depId => {
|
|
142
145
|
const shouldLoad = await shouldLoadFunc(depId);
|
|
143
|
-
if (!shouldLoad) this.ignoreIds.push(depId);
|
|
146
|
+
if (!shouldLoad) this.ignoreIds.push(depId.toString());
|
|
144
147
|
return shouldLoad ? depId : null;
|
|
145
148
|
});
|
|
146
|
-
return
|
|
149
|
+
return (0, _lodash2().default)(deps);
|
|
147
150
|
}
|
|
148
151
|
async processManyComponents(components) {
|
|
149
152
|
this.logger.debug(`GraphFromFsBuilder.processManyComponents depth ${this.depth}, ${components.length} components`);
|
|
@@ -153,25 +156,39 @@ class GraphFromFsBuilder {
|
|
|
153
156
|
const allDependenciesFlattened = (0, _lodash().flatten)(allDependencies);
|
|
154
157
|
if (allDependenciesFlattened.length) await this.processManyComponents(allDependenciesFlattened);
|
|
155
158
|
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* only for components from the workspace that can be modified to add/remove dependencies, we need to make sure that
|
|
162
|
+
* all their dependencies are imported.
|
|
163
|
+
* remember that `importMany` fetches all flattened dependencies. once a component from scope is imported, we know
|
|
164
|
+
* that all its flattened dependencies are there. no need to call importMany again for them.
|
|
165
|
+
*/
|
|
156
166
|
async importObjects(components) {
|
|
157
|
-
const
|
|
158
|
-
const
|
|
159
|
-
const
|
|
167
|
+
const workspaceIds = await this.workspace.listIds();
|
|
168
|
+
const compOnWorkspaceOnly = components.filter(comp => workspaceIds.find(id => id.isEqual(comp.id)));
|
|
169
|
+
const allDeps = (await Promise.all(compOnWorkspaceOnly.map(c => this.getAllDepsUnfiltered(c)))).flat();
|
|
170
|
+
const allDepsNotImported = allDeps.filter(d => !this.importedIds.includes(d.toString()));
|
|
171
|
+
const allDepsWithScope = allDepsNotImported.map(id => id._legacy).filter(dep => dep.hasScope());
|
|
172
|
+
const scopeComponentsImporter = this.consumer.scope.scopeImporter;
|
|
160
173
|
await scopeComponentsImporter.importMany({
|
|
161
174
|
ids: _bitIds().default.uniqFromArray(allDepsWithScope),
|
|
162
175
|
throwForDependencyNotFound: this.shouldThrowOnMissingDep,
|
|
163
176
|
throwForSeederNotFound: this.shouldThrowOnMissingDep,
|
|
164
177
|
reFetchUnBuiltVersion: false
|
|
165
178
|
});
|
|
179
|
+
allDepsNotImported.map(id => this.importedIds.push(id.toString()));
|
|
166
180
|
}
|
|
167
181
|
async processOneComponent(component) {
|
|
168
182
|
const idStr = component.id.toString();
|
|
169
183
|
if (this.completed.includes(idStr)) return [];
|
|
170
184
|
const allIds = await this.getAllDepsFiltered(component);
|
|
171
185
|
const allDependencies = await this.loadManyComponents(allIds, idStr);
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
186
|
+
const consumerComponent = component.state._consumer;
|
|
187
|
+
Object.entries(consumerComponent.depsIdsGroupedByType).forEach(([depType, depsIds]) => {
|
|
188
|
+
depsIds.forEach(depBitId => {
|
|
189
|
+
const depId = this.legacyIdStrToComponentId[depBitId.toString()];
|
|
190
|
+
if (!depId) throw new Error(`unable to find ${depBitId.toString()} inside legacyIdStrToComponentId`);
|
|
191
|
+
if (this.ignoreIds.includes(depId.toString())) return;
|
|
175
192
|
if (!this.graph.hasNode(depId.toString())) {
|
|
176
193
|
if (this.shouldThrowOnMissingDep) {
|
|
177
194
|
throw new Error(`buildOneComponent: missing node of ${depId.toString()}`);
|
|
@@ -179,7 +196,7 @@ class GraphFromFsBuilder {
|
|
|
179
196
|
this.logger.warn(`ignoring missing ${depId.toString()}`);
|
|
180
197
|
return;
|
|
181
198
|
}
|
|
182
|
-
this.graph.setEdge(idStr, depId.toString(), depType);
|
|
199
|
+
this.graph.setEdge(new (_graph().Edge)(idStr, depId.toString(), depType));
|
|
183
200
|
});
|
|
184
201
|
});
|
|
185
202
|
this.completed.push(idStr);
|
|
@@ -187,12 +204,13 @@ class GraphFromFsBuilder {
|
|
|
187
204
|
}
|
|
188
205
|
async loadManyComponents(componentsIds, dependenciesOf) {
|
|
189
206
|
const components = await (0, _pMapSeries().default)(componentsIds, async comp => {
|
|
207
|
+
var _this$graph$node;
|
|
190
208
|
const idStr = comp.toString();
|
|
191
|
-
const fromGraph = this.graph.node(idStr);
|
|
209
|
+
const fromGraph = (_this$graph$node = this.graph.node(idStr)) === null || _this$graph$node === void 0 ? void 0 : _this$graph$node.attr;
|
|
192
210
|
if (fromGraph) return fromGraph;
|
|
193
211
|
try {
|
|
194
|
-
const component = await this.
|
|
195
|
-
this.graph.setNode(idStr, component);
|
|
212
|
+
const component = await this.workspace.get(comp);
|
|
213
|
+
this.graph.setNode(new (_graph().Node)(idStr, component));
|
|
196
214
|
return component;
|
|
197
215
|
} catch (err) {
|
|
198
216
|
if (err instanceof _exceptions().ComponentNotFound || err instanceof _scope().ComponentNotFound || err instanceof _exceptions().ScopeNotFound) {
|
|
@@ -208,11 +226,6 @@ class GraphFromFsBuilder {
|
|
|
208
226
|
});
|
|
209
227
|
return (0, _lodash2().default)(components);
|
|
210
228
|
}
|
|
211
|
-
async loadComponent(componentId) {
|
|
212
|
-
const compId = await this.workspace.resolveComponentId(componentId);
|
|
213
|
-
const comp = await this.workspace.get(compId);
|
|
214
|
-
return comp.state._consumer;
|
|
215
|
-
}
|
|
216
229
|
}
|
|
217
230
|
exports.GraphFromFsBuilder = GraphFromFsBuilder;
|
|
218
231
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["GraphFromFsBuilder","constructor","workspace","logger","ignoreIds","BitIds","shouldLoadItsDeps","shouldThrowOnMissingDep","LegacyGraph","consumer","buildGraph","ids","debug","length","start","Date","now","components","loadManyComponents","processManyComponents","graph","getAllDepsUnfiltered","component","getAllDependenciesIds","difference","getAllDepsFiltered","depsWithoutIgnore","shouldLoadFunc","deps","mapSeries","depId","shouldLoad","push","fromArray","compact","depth","importObjects","allDependencies","processOneComponent","allDependenciesFlattened","flatten","allDeps","map","c","flat","allDepsWithScope","filter","dep","hasScope","scopeComponentsImporter","ScopeComponentsImporter","scope","importMany","uniqFromArray","throwForDependencyNotFound","throwForSeederNotFound","reFetchUnBuiltVersion","idStr","id","toString","completed","includes","allIds","Object","entries","depsIdsGroupedByType","forEach","depType","depsIds","has","hasNode","Error","warn","setEdge","componentsIds","dependenciesOf","comp","fromGraph","node","loadComponent","setNode","err","ComponentNotFound","ComponentNotFoundInScope","ScopeNotFound","BitError","error","componentId","compId","resolveComponentId","get","state","_consumer"],"sources":["build-graph-from-fs.ts"],"sourcesContent":["import mapSeries from 'p-map-series';\nimport { flatten } from 'lodash';\nimport { Consumer } from '@teambit/legacy/dist/consumer';\nimport BitIds from '@teambit/legacy/dist/bit-id/bit-ids';\nimport Component from '@teambit/legacy/dist/consumer/component/consumer-component';\nimport LegacyGraph from '@teambit/legacy/dist/scope/graph/graph';\nimport ScopeComponentsImporter from '@teambit/legacy/dist/scope/component-ops/scope-components-importer';\nimport { ComponentNotFound, ScopeNotFound } from '@teambit/legacy/dist/scope/exceptions';\nimport { ComponentNotFound as ComponentNotFoundInScope } from '@teambit/scope';\nimport compact from 'lodash.compact';\nimport { BitId } from '@teambit/legacy-bit-id';\nimport { Logger } from '@teambit/logger';\nimport { BitError } from '@teambit/bit-error';\nimport { Workspace } from './workspace';\n\nexport type ShouldLoadFunc = (bitId: BitId) => Promise<boolean>;\n\nexport class GraphFromFsBuilder {\n private graph = new LegacyGraph();\n private completed: string[] = [];\n private depth = 1;\n private consumer: Consumer;\n constructor(\n private workspace: Workspace,\n private logger: Logger,\n private ignoreIds = new BitIds(),\n private shouldLoadItsDeps?: ShouldLoadFunc,\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 components and the edges has a label of the dependency type.\n *\n * the way how it is done is iterations by depths. each depth we gather all the dependencies of\n * that depths, make sure all objects exist and then check their dependencies for the next depth.\n * once there is no dependency left, we're on the last depth level and the graph is ready.\n *\n * for example, imagine the following graph:\n * A1 -> A2 -> A3\n * B1 -> B2 -> B3\n * C1 -> C2 -> C3\n *\n * where the buildGraph is given [A1, B1, C1].\n * first, it saves all these components as nodes in the graph. then, it finds the dependencies of\n * the next level, in this case they're [A2, B2, C2]. it runs `importMany` in case some objects\n * are missing. then, it loads them all (some from FS, some from the model) and sets the edges\n * between the component and the dependencies.\n * once done, it finds all their dependencies, which are [A3, B3, C3] and repeat the process\n * above. since there are no more dependencies, the graph is completed.\n * in this case, the total depth levels are 3.\n *\n * even with a huge project, there are not many depth levels. by iterating through depth levels\n * we keep performance sane as the importMany doesn't run multiple time and therefore the round\n * trips to the remotes are minimal.\n *\n * normally, one importMany of the seeders is enough as importMany knows to fetch all flattened.\n * however, since this buildGraph is performed on the workspace, a dependency may be new or\n * modified and as such, we don't know its flattened yet.\n */\n async buildGraph(ids: BitId[]): Promise<LegacyGraph> {\n this.logger.debug(`GraphFromFsBuilder, 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 `GraphFromFsBuilder, buildGraph with ${ids.length} seeders completed (${(Date.now() - start) / 1000} sec)`\n );\n return this.graph;\n }\n\n private getAllDepsUnfiltered(component: Component) {\n return component.getAllDependenciesIds().difference(this.ignoreIds);\n }\n\n private async getAllDepsFiltered(component: Component): Promise<BitIds> {\n const depsWithoutIgnore = this.getAllDepsUnfiltered(component);\n const shouldLoadFunc = this.shouldLoadItsDeps;\n if (!shouldLoadFunc) return depsWithoutIgnore;\n const deps = await mapSeries(depsWithoutIgnore, async (depId) => {\n const shouldLoad = await shouldLoadFunc(depId);\n if (!shouldLoad) this.ignoreIds.push(depId);\n return shouldLoad ? depId : null;\n });\n return BitIds.fromArray(compact(deps));\n }\n\n private async processManyComponents(components: Component[]) {\n this.logger.debug(`GraphFromFsBuilder.processManyComponents depth ${this.depth}, ${components.length} components`);\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 private async importObjects(components: Component[]) {\n const allDeps = components.map((c) => this.getAllDepsUnfiltered(c)).flat();\n const allDepsWithScope = allDeps.filter((dep) => dep.hasScope());\n const scopeComponentsImporter = new ScopeComponentsImporter(this.consumer.scope);\n await scopeComponentsImporter.importMany({\n ids: BitIds.uniqFromArray(allDepsWithScope),\n throwForDependencyNotFound: this.shouldThrowOnMissingDep,\n throwForSeederNotFound: this.shouldThrowOnMissingDep,\n reFetchUnBuiltVersion: false,\n });\n }\n\n private async processOneComponent(component: Component) {\n const idStr = component.id.toString();\n if (this.completed.includes(idStr)) return [];\n const allIds = await this.getAllDepsFiltered(component);\n\n const allDependencies = await this.loadManyComponents(allIds, idStr);\n Object.entries(component.depsIdsGroupedByType).forEach(([depType, depsIds]) => {\n depsIds.forEach((depId) => {\n if (this.ignoreIds.has(depId)) return;\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(idStr, depId.toString(), depType);\n });\n });\n this.completed.push(idStr);\n return allDependencies;\n }\n\n private async loadManyComponents(componentsIds: BitId[], dependenciesOf?: string): Promise<Component[]> {\n const components = await mapSeries(componentsIds, async (comp: BitId) => {\n const idStr = comp.toString();\n const fromGraph = this.graph.node(idStr);\n if (fromGraph) return fromGraph;\n try {\n const component = await this.loadComponent(comp);\n this.graph.setNode(idStr, component);\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 private async loadComponent(componentId: BitId): Promise<Component> {\n const compId = await this.workspace.resolveComponentId(componentId);\n const comp = await this.workspace.get(compId);\n return comp.state._consumer;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;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;AAKO,MAAMA,kBAAkB,CAAC;EAK9BC,WAAW,C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;QACA,IAAIA,cAAc,EAAE,IAAI,CAACxE,MAAM,CAACmF,KAAK,CAAE,kCAAiCX,cAAe,EAAC,CAAC;QACzF,MAAMM,GAAG;MACX;IACF,CAAC,CAAC;IACF,OAAO,IAAA/C,kBAAO,EAACjB,UAAU,CAAC;EAC5B;EACA,MAAc8D,aAAa,CAACQ,WAAkB,EAAsB;IAClE,MAAMC,MAAM,GAAG,MAAM,IAAI,CAACtF,SAAS,CAACuF,kBAAkB,CAACF,WAAW,CAAC;IACnE,MAAMX,IAAI,GAAG,MAAM,IAAI,CAAC1E,SAAS,CAACwF,GAAG,CAACF,MAAM,CAAC;IAC7C,OAAOZ,IAAI,CAACe,KAAK,CAACC,SAAS;EAC7B;AACF;AAAC"}
|
|
1
|
+
{"version":3,"names":["GraphFromFsBuilder","constructor","workspace","logger","ignoreIds","shouldLoadItsDeps","shouldThrowOnMissingDep","Graph","consumer","buildGraph","ids","debug","length","start","Date","now","components","loadManyComponents","processManyComponents","graph","getAllDepsUnfiltered","component","consumerComp","state","_consumer","legacyDepsIds","getAllDependenciesIds","depsIds","Promise","all","map","bitId","legacyIdStrToComponentId","toString","resolveComponentId","filter","depId","includes","getAllDepsFiltered","depsWithoutIgnore","shouldLoadFunc","deps","mapSeries","shouldLoad","push","compact","depth","importObjects","allDependencies","processOneComponent","allDependenciesFlattened","flatten","workspaceIds","listIds","compOnWorkspaceOnly","comp","find","id","isEqual","allDeps","c","flat","allDepsNotImported","d","importedIds","allDepsWithScope","_legacy","dep","hasScope","scopeComponentsImporter","scope","scopeImporter","importMany","BitIds","uniqFromArray","throwForDependencyNotFound","throwForSeederNotFound","reFetchUnBuiltVersion","idStr","completed","allIds","consumerComponent","Object","entries","depsIdsGroupedByType","forEach","depType","depBitId","Error","hasNode","warn","setEdge","Edge","componentsIds","dependenciesOf","fromGraph","node","attr","get","setNode","Node","err","ComponentNotFound","ComponentNotFoundInScope","ScopeNotFound","BitError","error"],"sources":["build-graph-from-fs.ts"],"sourcesContent":["import mapSeries from 'p-map-series';\nimport { Graph, Node, Edge } from '@teambit/graph.cleargraph';\nimport { flatten } 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 ConsumerComponent from '@teambit/legacy/dist/consumer/component/consumer-component';\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 type ShouldLoadFunc = (id: ComponentID) => Promise<boolean>;\n\nexport class GraphFromFsBuilder {\n private graph = new Graph<Component, string>();\n private completed: string[] = [];\n private depth = 1;\n private consumer: Consumer;\n private legacyIdStrToComponentId: { [bitIdStr: string]: ComponentID } = {};\n private importedIds: string[] = [];\n constructor(\n private workspace: Workspace,\n private logger: Logger,\n private ignoreIds: string[] = [],\n private shouldLoadItsDeps?: ShouldLoadFunc,\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 components and the edges has a label of the dependency type.\n *\n * the way how it is done is iterations by depths. each depth we gather all the dependencies of\n * that depths, make sure all objects exist and then check their dependencies for the next depth.\n * once there is no dependency left, we're on the last depth level and the graph is ready.\n *\n * for example, imagine the following graph:\n * A1 -> A2 -> A3\n * B1 -> B2 -> B3\n * C1 -> C2 -> C3\n *\n * where the buildGraph is given [A1, B1, C1].\n * first, it saves all these components as nodes in the graph. then, it finds the dependencies of\n * the next level, in this case they're [A2, B2, C2]. it runs `importMany` in case some objects\n * are missing. then, it loads them all (some from FS, some from the model) and sets the edges\n * between the component and the dependencies.\n * once done, it finds all their dependencies, which are [A3, B3, C3] and repeat the process\n * above. since there are no more dependencies, the graph is completed.\n * in this case, the total depth levels are 3.\n *\n * even with a huge project, there are not many depth levels. by iterating through depth levels\n * we keep performance sane as the importMany doesn't run multiple time and therefore the round\n * trips to the remotes are minimal.\n *\n * normally, one importMany of the seeders is enough as importMany knows to fetch all flattened.\n * however, since this buildGraph is performed on the workspace, a dependency may be new or\n * modified and as such, we don't know its flattened yet.\n */\n async buildGraph(ids: ComponentID[]): Promise<Graph<Component, string>> {\n this.logger.debug(`GraphFromFsBuilder, 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 `GraphFromFsBuilder, buildGraph with ${ids.length} seeders completed (${(Date.now() - start) / 1000} sec)`\n );\n return this.graph;\n }\n\n private async getAllDepsUnfiltered(component: Component): Promise<ComponentID[]> {\n const consumerComp = component.state._consumer as ConsumerComponent;\n const legacyDepsIds = consumerComp.getAllDependenciesIds();\n const depsIds = await Promise.all(\n legacyDepsIds.map(async (bitId) => {\n if (!this.legacyIdStrToComponentId[bitId.toString()]) {\n this.legacyIdStrToComponentId[bitId.toString()] = await this.workspace.resolveComponentId(bitId);\n }\n return this.legacyIdStrToComponentId[bitId.toString()];\n })\n );\n return depsIds.filter((depId) => !this.ignoreIds.includes(depId.toString()));\n }\n\n private async getAllDepsFiltered(component: Component): Promise<ComponentID[]> {\n const depsWithoutIgnore = await this.getAllDepsUnfiltered(component);\n const shouldLoadFunc = this.shouldLoadItsDeps;\n if (!shouldLoadFunc) return depsWithoutIgnore;\n const deps = await mapSeries(depsWithoutIgnore, async (depId) => {\n const shouldLoad = await shouldLoadFunc(depId);\n if (!shouldLoad) this.ignoreIds.push(depId.toString());\n return shouldLoad ? depId : null;\n });\n return compact(deps);\n }\n\n private async processManyComponents(components: Component[]) {\n this.logger.debug(`GraphFromFsBuilder.processManyComponents depth ${this.depth}, ${components.length} components`);\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 * remember that `importMany` fetches all flattened dependencies. once a component from scope is imported, we know\n * that all its flattened dependencies are there. no need to call importMany again for them.\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 allDeps = (await Promise.all(compOnWorkspaceOnly.map((c) => this.getAllDepsUnfiltered(c)))).flat();\n const allDepsNotImported = allDeps.filter((d) => !this.importedIds.includes(d.toString()));\n const allDepsWithScope = allDepsNotImported.map((id) => id._legacy).filter((dep) => dep.hasScope());\n const scopeComponentsImporter = this.consumer.scope.scopeImporter;\n await scopeComponentsImporter.importMany({\n ids: BitIds.uniqFromArray(allDepsWithScope),\n throwForDependencyNotFound: this.shouldThrowOnMissingDep,\n throwForSeederNotFound: this.shouldThrowOnMissingDep,\n reFetchUnBuiltVersion: false,\n });\n allDepsNotImported.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 allIds = await this.getAllDepsFiltered(component);\n\n const allDependencies = await this.loadManyComponents(allIds, idStr);\n const consumerComponent = component.state._consumer as ConsumerComponent;\n Object.entries(consumerComponent.depsIdsGroupedByType).forEach(([depType, depsIds]) => {\n depsIds.forEach((depBitId) => {\n const depId = this.legacyIdStrToComponentId[depBitId.toString()];\n if (!depId) throw new Error(`unable to find ${depBitId.toString()} inside legacyIdStrToComponentId`);\n if (this.ignoreIds.includes(depId.toString())) return;\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(), depType));\n });\n });\n this.completed.push(idStr);\n return allDependencies;\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 fromGraph = this.graph.node(idStr)?.attr;\n if (fromGraph) return fromGraph;\n try {\n const component = await this.workspace.get(comp);\n this.graph.setNode(new Node(idStr, component));\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;AAEA;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;AAKO,MAAMA,kBAAkB,CAAC;EAO9BC,WAAW,CACDC,SAAoB,EACpBC,MAAc,EACdC,SAAmB,GAAG,EAAE,EACxBC,iBAAkC,EAClCC,uBAAuB,GAAG,IAAI,EACtC;IAAA,KALQJ,SAAoB,GAApBA,SAAoB;IAAA,KACpBC,MAAc,GAAdA,MAAc;IAAA,KACdC,SAAmB,GAAnBA,SAAmB;IAAA,KACnBC,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uB,EAAE;YACnD,IAAI,CAACH,MAAM,CAACuF,IAAI,CACb,aAAYZ,KAAM,mBAAkBgB,cAAe,uCAAsC,CAC3F;YACD,OAAO,IAAI;UACb;UACA,MAAM,KAAIW,oBAAQ,EACf,qBAAoB3B,KAAM,wDACzBgB,cAAc,IAAI,QACnB,iDAAgD,CAClD;QACH;QACA,IAAIA,cAAc,EAAE,IAAI,CAAC3F,MAAM,CAACuG,KAAK,CAAE,kCAAiCZ,cAAe,EAAC,CAAC;QACzF,MAAMO,GAAG;MACX;IACF,CAAC,CAAC;IACF,OAAO,IAAAxD,kBAAO,EAAC7B,UAAU,CAAC;EAC5B;AACF;AAAC"}
|
|
@@ -14,12 +14,12 @@ export declare function useWorkspace(options?: UseWorkspaceOptions): {
|
|
|
14
14
|
loading: boolean;
|
|
15
15
|
networkStatus: import("@apollo/client").NetworkStatus;
|
|
16
16
|
called: boolean;
|
|
17
|
-
variables: import("@apollo/client").OperationVariables | undefined;
|
|
18
17
|
startPolling: (pollInterval: number) => void;
|
|
19
18
|
stopPolling: () => void;
|
|
20
19
|
updateQuery: <TVars = import("@apollo/client").OperationVariables>(mapFn: (previousQueryResult: any, options: Pick<import("@apollo/client").WatchQueryOptions<TVars, any>, "variables">) => any) => void;
|
|
21
20
|
refetch: (variables?: Partial<import("@apollo/client").OperationVariables> | undefined) => Promise<import("@apollo/client").ApolloQueryResult<any>>;
|
|
22
21
|
reobserve: (newOptions?: Partial<import("@apollo/client").WatchQueryOptions<import("@apollo/client").OperationVariables, any>> | undefined, newNetworkStatus?: import("@apollo/client").NetworkStatus | undefined) => Promise<import("@apollo/client").ApolloQueryResult<any>>;
|
|
22
|
+
variables: import("@apollo/client").OperationVariables | undefined;
|
|
23
23
|
fetchMore: <TFetchData = any, TFetchVars = import("@apollo/client").OperationVariables>(fetchMoreOptions: import("@apollo/client").FetchMoreQueryOptions<TFetchVars, TFetchData> & {
|
|
24
24
|
updateQuery?: ((previousQueryResult: any, options: {
|
|
25
25
|
fetchMoreResult: TFetchData;
|
|
@@ -25,8 +25,8 @@ export declare class WatchCommand implements Command {
|
|
|
25
25
|
onAll: (event: string, path: string) => void;
|
|
26
26
|
onStart: () => void;
|
|
27
27
|
onReady: (workspace: any, watchPathsSortByComponent: any, verbose: any) => void;
|
|
28
|
-
onChange: (filePaths: string[], buildResults: OnComponentEventResult[], verbose: boolean, duration: any, failureMsg?: string
|
|
29
|
-
onAdd: (filePaths: string[], buildResults: OnComponentEventResult[], verbose: boolean, duration: any, failureMsg?: string
|
|
28
|
+
onChange: (filePaths: string[], buildResults: OnComponentEventResult[], verbose: boolean, duration: any, failureMsg?: string) => void;
|
|
29
|
+
onAdd: (filePaths: string[], buildResults: OnComponentEventResult[], verbose: boolean, duration: any, failureMsg?: string) => void;
|
|
30
30
|
onUnlink: (p: any) => void;
|
|
31
31
|
onError: (err: any) => void;
|
|
32
32
|
};
|
package/dist/workspace.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Graph } from '@teambit/graph.cleargraph';
|
|
1
2
|
import type { PubsubMain } from '@teambit/pubsub';
|
|
2
3
|
import { IssuesList } from '@teambit/component-issues';
|
|
3
4
|
import type { AspectLoaderMain, AspectDefinition } from '@teambit/aspect-loader';
|
|
@@ -11,8 +12,6 @@ import { Logger } from '@teambit/logger';
|
|
|
11
12
|
import type { ScopeMain } from '@teambit/scope';
|
|
12
13
|
import { RequireableComponent } from '@teambit/harmony.modules.requireable-component';
|
|
13
14
|
import type { VariantsMain } from '@teambit/variants';
|
|
14
|
-
import LegacyGraph from '@teambit/legacy/dist/scope/graph/graph';
|
|
15
|
-
import { BitIds } from '@teambit/legacy/dist/bit-id';
|
|
16
15
|
import { BitId } from '@teambit/legacy-bit-id';
|
|
17
16
|
import { LaneId } from '@teambit/lane-id';
|
|
18
17
|
import { Consumer } from '@teambit/legacy/dist/consumer';
|
|
@@ -226,7 +225,7 @@ export declare class Workspace implements ComponentFactory {
|
|
|
226
225
|
getNewAndModifiedIds(): Promise<ComponentID[]>;
|
|
227
226
|
newAndModified(): Promise<Component[]>;
|
|
228
227
|
getLogs(id: ComponentID, shortHash?: boolean, startsFrom?: string): Promise<ComponentLog[]>;
|
|
229
|
-
|
|
228
|
+
getGraph(ids?: ComponentID[], shouldThrowOnMissingDep?: boolean): Promise<Graph<Component, string>>;
|
|
230
229
|
/**
|
|
231
230
|
* given component ids, find their dependents in the workspace
|
|
232
231
|
*/
|
|
@@ -398,7 +397,7 @@ export declare class Workspace implements ComponentFactory {
|
|
|
398
397
|
*/
|
|
399
398
|
getComponentIdByPath(componentPath: PathOsBased): Promise<ComponentID | undefined>;
|
|
400
399
|
private componentConfigFileFromComponentDirAndName;
|
|
401
|
-
getAspectsGraphWithoutCore(components: Component[], isAspect?: ShouldLoadFunc): Promise<
|
|
400
|
+
getAspectsGraphWithoutCore(components: Component[], isAspect?: ShouldLoadFunc): Promise<Graph<Component, string>>;
|
|
402
401
|
/**
|
|
403
402
|
* load aspects from the workspace and if not exists in the workspace, load from the scope.
|
|
404
403
|
* keep in mind that the graph may have circles.
|
|
@@ -409,7 +408,7 @@ export declare class Workspace implements ComponentFactory {
|
|
|
409
408
|
* returns one graph that includes all dependencies types. each edge has a label of the dependency
|
|
410
409
|
* type. the nodes content is the Component object.
|
|
411
410
|
*/
|
|
412
|
-
buildOneGraphForComponents(ids:
|
|
411
|
+
buildOneGraphForComponents(ids: ComponentID[], ignoreIds?: string[], shouldLoadFunc?: ShouldLoadFunc, shouldThrowOnMissingDep?: boolean): Promise<Graph<Component, string>>;
|
|
413
412
|
resolveAspects(runtimeName?: string, componentIds?: ComponentID[], opts?: ResolveAspectsOptions): Promise<AspectDefinition[]>;
|
|
414
413
|
private groupIdsByWorkspaceAndScope;
|
|
415
414
|
private groupComponentsByWorkspaceAndScope;
|
package/dist/workspace.js
CHANGED
|
@@ -584,11 +584,9 @@ class Workspace {
|
|
|
584
584
|
async getLogs(id, shortHash = false, startsFrom) {
|
|
585
585
|
return this.scope.getLogs(id, shortHash, startsFrom);
|
|
586
586
|
}
|
|
587
|
-
async
|
|
587
|
+
async getGraph(ids, shouldThrowOnMissingDep = true) {
|
|
588
588
|
if (!ids || ids.length < 1) ids = await this.listIds();
|
|
589
|
-
|
|
590
|
-
const legacyGraph = await this.buildOneGraphForComponents(legacyIds, undefined, undefined, shouldThrowOnMissingDep);
|
|
591
|
-
return legacyGraph;
|
|
589
|
+
return this.buildOneGraphForComponents(ids, undefined, undefined, shouldThrowOnMissingDep);
|
|
592
590
|
}
|
|
593
591
|
|
|
594
592
|
/**
|
|
@@ -1494,10 +1492,9 @@ the following envs are used in this workspace: ${availableEnvs.join(', ')}`);
|
|
|
1494
1492
|
return componentConfigFile;
|
|
1495
1493
|
}
|
|
1496
1494
|
async getAspectsGraphWithoutCore(components, isAspect) {
|
|
1497
|
-
const ids = components.map(component => component.id
|
|
1495
|
+
const ids = components.map(component => component.id);
|
|
1498
1496
|
const coreAspectsStringIds = this.aspectLoader.getCoreAspectIds();
|
|
1499
|
-
const coreAspectsComponentIds = coreAspectsStringIds.map(id =>
|
|
1500
|
-
const coreAspectsBitIds = _bitId().BitIds.fromArray(coreAspectsComponentIds.map(id => id.changeScope(null)));
|
|
1497
|
+
// const coreAspectsComponentIds = coreAspectsStringIds.map((id) => BitId.parse(id, true));
|
|
1501
1498
|
// const aspectsIds = components.reduce((acc, curr) => {
|
|
1502
1499
|
// const currIds = curr.state.aspects.ids;
|
|
1503
1500
|
// acc = acc.concat(currIds);
|
|
@@ -1515,8 +1512,7 @@ the following envs are used in this workspace: ${availableEnvs.join(', ')}`);
|
|
|
1515
1512
|
// We only want to load into the graph components which are aspects and not regular dependencies
|
|
1516
1513
|
// This come to solve a circular loop when an env aspect use an aspect (as regular dep) and the aspect use the env aspect as its env
|
|
1517
1514
|
// TODO: @gilad it causes many issues we need to find a better solution. removed for now.
|
|
1518
|
-
|
|
1519
|
-
return this.buildOneGraphForComponents(ids, _bitId().BitIds.fromArray(ignoredIds), isAspect);
|
|
1515
|
+
return this.buildOneGraphForComponents(ids, coreAspectsStringIds, isAspect);
|
|
1520
1516
|
}
|
|
1521
1517
|
|
|
1522
1518
|
/**
|
|
@@ -1536,8 +1532,7 @@ needed-for: ${neededFor || '<unknown>'}`);
|
|
|
1536
1532
|
const idsWithoutCore = (0, _lodash().difference)(notLoadedIds, coreAspectsStringIds);
|
|
1537
1533
|
const componentIds = await this.resolveMultipleComponentIds(idsWithoutCore);
|
|
1538
1534
|
const components = await this.importAndGetAspects(componentIds);
|
|
1539
|
-
const isAspect = async
|
|
1540
|
-
const id = await this.resolveComponentId(bitId);
|
|
1535
|
+
const isAspect = async id => {
|
|
1541
1536
|
const component = await this.get(id);
|
|
1542
1537
|
const data = this.envs.getEnvData(component);
|
|
1543
1538
|
const isUsingAspectEnv = this.envs.isUsingAspectEnv(component);
|
|
@@ -1557,10 +1552,8 @@ needed-for: ${neededFor || '<unknown>'}`);
|
|
|
1557
1552
|
return isValidAspect;
|
|
1558
1553
|
};
|
|
1559
1554
|
const graph = await this.getAspectsGraphWithoutCore(components, isAspect);
|
|
1560
|
-
const
|
|
1561
|
-
this.logger.debug(`${loggerPrefix} found ${
|
|
1562
|
-
const compIds = await this.resolveMultipleComponentIds(idsStr);
|
|
1563
|
-
const aspects = await this.getMany(compIds);
|
|
1555
|
+
const aspects = graph.nodes.map(node => node.attr);
|
|
1556
|
+
this.logger.debug(`${loggerPrefix} found ${aspects.length} aspects in the aspects-graph`);
|
|
1564
1557
|
const {
|
|
1565
1558
|
workspaceComps,
|
|
1566
1559
|
scopeComps
|