@teambit/workspace 0.0.537 → 0.0.545

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,160 @@
1
+ import mapSeries from 'p-map-series';
2
+ import { flatten } from 'lodash';
3
+ import { Consumer } from '@teambit/legacy/dist/consumer';
4
+ import BitIds from '@teambit/legacy/dist/bit-id/bit-ids';
5
+ import Component from '@teambit/legacy/dist/consumer/component/consumer-component';
6
+ import LegacyGraph from '@teambit/legacy/dist/scope/graph/graph';
7
+ import ScopeComponentsImporter from '@teambit/legacy/dist/scope/component-ops/scope-components-importer';
8
+ import compact from 'lodash.compact';
9
+ import { BitId } from '@teambit/legacy-bit-id';
10
+ import { Logger } from '@teambit/logger';
11
+ import { ComponentNotFound } from '@teambit/scope';
12
+ import { BitError } from '@teambit/bit-error';
13
+ import { Workspace } from './workspace';
14
+
15
+ export type ShouldIgnoreFunc = (bitId: BitId) => Promise<boolean>;
16
+
17
+ export class GraphFromFsBuilder {
18
+ private graph = new LegacyGraph();
19
+ private completed: string[] = [];
20
+ private depth = 1;
21
+ private shouldThrowOnMissingDep = true;
22
+ private consumer: Consumer;
23
+ constructor(
24
+ private workspace: Workspace,
25
+ private logger: Logger,
26
+ private ignoreIds = new BitIds(),
27
+ private shouldLoadItsDeps?: ShouldIgnoreFunc
28
+ ) {
29
+ this.consumer = this.workspace.consumer;
30
+ }
31
+
32
+ /**
33
+ * create a graph with all dependencies and flattened dependencies of the given components.
34
+ * the nodes are components and the edges has a label of the dependency type.
35
+ *
36
+ * the way how it is done is iterations by depths. each depth we gather all the dependencies of
37
+ * that depths, make sure all objects exist and then check their dependencies for the next depth.
38
+ * once there is no dependency left, we're on the last depth level and the graph is ready.
39
+ *
40
+ * for example, imagine the following graph:
41
+ * A1 -> A2 -> A3
42
+ * B1 -> B2 -> B3
43
+ * C1 -> C2 -> C3
44
+ *
45
+ * where the buildGraph is given [A1, B1, C1].
46
+ * first, it saves all these components as nodes in the graph. then, it finds the dependencies of
47
+ * the next level, in this case they're [A2, B2, C2]. it runs `importMany` in case some objects
48
+ * are missing. then, it loads them all (some from FS, some from the model) and sets the edges
49
+ * between the component and the dependencies.
50
+ * once done, it finds all their dependencies, which are [A3, B3, C3] and repeat the process
51
+ * above. since there are no more dependencies, the graph is completed.
52
+ * in this case, the total depth levels are 3.
53
+ *
54
+ * even with a huge project, there are not many depth levels. by iterating through depth levels
55
+ * we keep performance sane as the importMany doesn't run multiple time and therefore the round
56
+ * trips to the remotes are minimal.
57
+ *
58
+ * normally, one importMany of the seeders is enough as importMany knows to fetch all flattened.
59
+ * however, since this buildGraph is performed on the workspace, a dependency may be new or
60
+ * modified and as such, we don't know its flattened yet.
61
+ */
62
+ async buildGraph(ids: BitId[]): Promise<LegacyGraph> {
63
+ this.logger.debug(`GraphFromFsBuilder, buildGraph with ${ids.length} seeders`);
64
+ const start = Date.now();
65
+ const components = await this.loadManyComponents(ids, '<none>');
66
+ await this.processManyComponents(components);
67
+ this.logger.debug(
68
+ `GraphFromFsBuilder, buildGraph with ${ids.length} seeders completed (${(Date.now() - start) / 1000} sec)`
69
+ );
70
+ return this.graph;
71
+ }
72
+
73
+ private getAllDepsUnfiltered(component: Component) {
74
+ return component.getAllDependenciesIds().difference(this.ignoreIds);
75
+ }
76
+
77
+ private async getAllDepsFiltered(component: Component): Promise<BitIds> {
78
+ const depsWithoutIgnore = this.getAllDepsUnfiltered(component);
79
+ const shouldLoadFunc = this.shouldLoadItsDeps;
80
+ if (!shouldLoadFunc) return depsWithoutIgnore;
81
+ const deps = await mapSeries(depsWithoutIgnore, async (depId) => {
82
+ const shouldLoad = await shouldLoadFunc(depId);
83
+ if (!shouldLoad) this.ignoreIds.push(depId);
84
+ return shouldLoad ? depId : null;
85
+ });
86
+ return BitIds.fromArray(compact(deps));
87
+ }
88
+
89
+ private async processManyComponents(components: Component[]) {
90
+ this.logger.debug(`GraphFromFsBuilder.processManyComponents depth ${this.depth}, ${components.length} components`);
91
+ this.depth += 1;
92
+ await this.importObjects(components);
93
+ const allDependencies = await mapSeries(components, (component) => this.processOneComponent(component));
94
+ const allDependenciesFlattened = flatten(allDependencies);
95
+ if (allDependenciesFlattened.length) await this.processManyComponents(allDependenciesFlattened);
96
+ }
97
+
98
+ private async importObjects(components: Component[]) {
99
+ const allDeps = components.map((c) => this.getAllDepsUnfiltered(c)).flat();
100
+ const allDepsWithScope = allDeps.filter((dep) => dep.hasScope());
101
+ const scopeComponentsImporter = new ScopeComponentsImporter(this.consumer.scope);
102
+ await scopeComponentsImporter.importMany(
103
+ BitIds.uniqFromArray(allDepsWithScope),
104
+ undefined,
105
+ this.shouldThrowOnMissingDep
106
+ );
107
+ }
108
+
109
+ private async processOneComponent(component: Component) {
110
+ const idStr = component.id.toString();
111
+ if (this.completed.includes(idStr)) return [];
112
+ const allIds = await this.getAllDepsFiltered(component);
113
+
114
+ const allDependencies = await this.loadManyComponents(allIds, idStr);
115
+ Object.entries(component.depsIdsGroupedByType).forEach(([depType, depsIds]) => {
116
+ depsIds.forEach((depId) => {
117
+ if (this.ignoreIds.has(depId)) return;
118
+ if (!this.graph.hasNode(depId.toString())) {
119
+ throw new Error(`buildOneComponent: missing node of ${depId.toString()}`);
120
+ }
121
+ this.graph.setEdge(idStr, depId.toString(), depType);
122
+ });
123
+ });
124
+ this.completed.push(idStr);
125
+ return allDependencies;
126
+ }
127
+
128
+ private async loadManyComponents(componentsIds: BitId[], dependenciesOf: string): Promise<Component[]> {
129
+ const components = await mapSeries(componentsIds, async (comp: BitId) => {
130
+ const idStr = comp.toString();
131
+ const fromGraph = this.graph.node(idStr);
132
+ if (fromGraph) return fromGraph;
133
+ try {
134
+ const component = await this.loadComponent(comp);
135
+ this.graph.setNode(idStr, component);
136
+ return component;
137
+ } catch (err: any) {
138
+ if (err instanceof ComponentNotFound) {
139
+ throw new BitError(
140
+ `error: component "${idStr}" was not found.\nthis component is a dependency of "${dependenciesOf}" and is needed as part of the graph generation`
141
+ );
142
+ }
143
+ this.logger.error(`failed loading dependencies of ${dependenciesOf}`);
144
+ throw err;
145
+ }
146
+ });
147
+ return components;
148
+ }
149
+ private async loadComponent(componentId: BitId): Promise<Component> {
150
+ const componentMap = this.consumer.bitMap.getComponentIfExist(componentId);
151
+ const isOnWorkspace = Boolean(componentMap);
152
+ if (isOnWorkspace) {
153
+ return this.consumer.loadComponentForCapsule(componentId);
154
+ }
155
+ // a dependency might have been installed as a package in the workspace, and as such doesn't
156
+ // have a componentMap.
157
+ const componentFromModel = await this.consumer.loadComponentFromModel(componentId);
158
+ return componentFromModel.clone();
159
+ }
160
+ }
@@ -0,0 +1,26 @@
1
+ import BitIds from '@teambit/legacy/dist/bit-id/bit-ids';
2
+ import LegacyGraph from '@teambit/legacy/dist/scope/graph/graph';
3
+ import { BitId } from '@teambit/legacy-bit-id';
4
+ import { Logger } from '@teambit/logger';
5
+ import { Workspace } from './workspace';
6
+ export declare type ShouldIgnoreFunc = (bitId: BitId) => Promise<boolean>;
7
+ export declare class GraphFromFsBuilder {
8
+ private workspace;
9
+ private logger;
10
+ private ignoreIds;
11
+ private shouldLoadItsDeps?;
12
+ private graph;
13
+ private completed;
14
+ private depth;
15
+ private shouldThrowOnMissingDep;
16
+ private consumer;
17
+ constructor(workspace: Workspace, logger: Logger, ignoreIds?: BitIds, shouldLoadItsDeps?: ShouldIgnoreFunc | undefined);
18
+ buildGraph(ids: BitId[]): Promise<LegacyGraph>;
19
+ private getAllDepsUnfiltered;
20
+ private getAllDepsFiltered;
21
+ private processManyComponents;
22
+ private importObjects;
23
+ private processOneComponent;
24
+ private loadManyComponents;
25
+ private loadComponent;
26
+ }
@@ -0,0 +1,254 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ require("core-js/modules/es.array.flat.js");
6
+
7
+ require("core-js/modules/es.array.iterator.js");
8
+
9
+ require("core-js/modules/es.array.unscopables.flat.js");
10
+
11
+ require("core-js/modules/es.promise.js");
12
+
13
+ Object.defineProperty(exports, "__esModule", {
14
+ value: true
15
+ });
16
+ exports.GraphFromFsBuilder = void 0;
17
+
18
+ function _defineProperty2() {
19
+ const data = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
20
+
21
+ _defineProperty2 = function () {
22
+ return data;
23
+ };
24
+
25
+ return data;
26
+ }
27
+
28
+ function _pMapSeries() {
29
+ const data = _interopRequireDefault(require("p-map-series"));
30
+
31
+ _pMapSeries = function () {
32
+ return data;
33
+ };
34
+
35
+ return data;
36
+ }
37
+
38
+ function _lodash() {
39
+ const data = require("lodash");
40
+
41
+ _lodash = function () {
42
+ return data;
43
+ };
44
+
45
+ return data;
46
+ }
47
+
48
+ function _bitIds() {
49
+ const data = _interopRequireDefault(require("@teambit/legacy/dist/bit-id/bit-ids"));
50
+
51
+ _bitIds = function () {
52
+ return data;
53
+ };
54
+
55
+ return data;
56
+ }
57
+
58
+ function _graph() {
59
+ const data = _interopRequireDefault(require("@teambit/legacy/dist/scope/graph/graph"));
60
+
61
+ _graph = function () {
62
+ return data;
63
+ };
64
+
65
+ return data;
66
+ }
67
+
68
+ function _scopeComponentsImporter() {
69
+ const data = _interopRequireDefault(require("@teambit/legacy/dist/scope/component-ops/scope-components-importer"));
70
+
71
+ _scopeComponentsImporter = function () {
72
+ return data;
73
+ };
74
+
75
+ return data;
76
+ }
77
+
78
+ function _lodash2() {
79
+ const data = _interopRequireDefault(require("lodash.compact"));
80
+
81
+ _lodash2 = function () {
82
+ return data;
83
+ };
84
+
85
+ return data;
86
+ }
87
+
88
+ function _scope() {
89
+ const data = require("@teambit/scope");
90
+
91
+ _scope = function () {
92
+ return data;
93
+ };
94
+
95
+ return data;
96
+ }
97
+
98
+ function _bitError() {
99
+ const data = require("@teambit/bit-error");
100
+
101
+ _bitError = function () {
102
+ return data;
103
+ };
104
+
105
+ return data;
106
+ }
107
+
108
+ class GraphFromFsBuilder {
109
+ constructor(workspace, logger, ignoreIds = new (_bitIds().default)(), shouldLoadItsDeps) {
110
+ this.workspace = workspace;
111
+ this.logger = logger;
112
+ this.ignoreIds = ignoreIds;
113
+ this.shouldLoadItsDeps = shouldLoadItsDeps;
114
+ (0, _defineProperty2().default)(this, "graph", new (_graph().default)());
115
+ (0, _defineProperty2().default)(this, "completed", []);
116
+ (0, _defineProperty2().default)(this, "depth", 1);
117
+ (0, _defineProperty2().default)(this, "shouldThrowOnMissingDep", true);
118
+ (0, _defineProperty2().default)(this, "consumer", void 0);
119
+ this.consumer = this.workspace.consumer;
120
+ }
121
+ /**
122
+ * create a graph with all dependencies and flattened dependencies of the given components.
123
+ * the nodes are components and the edges has a label of the dependency type.
124
+ *
125
+ * the way how it is done is iterations by depths. each depth we gather all the dependencies of
126
+ * that depths, make sure all objects exist and then check their dependencies for the next depth.
127
+ * once there is no dependency left, we're on the last depth level and the graph is ready.
128
+ *
129
+ * for example, imagine the following graph:
130
+ * A1 -> A2 -> A3
131
+ * B1 -> B2 -> B3
132
+ * C1 -> C2 -> C3
133
+ *
134
+ * where the buildGraph is given [A1, B1, C1].
135
+ * first, it saves all these components as nodes in the graph. then, it finds the dependencies of
136
+ * the next level, in this case they're [A2, B2, C2]. it runs `importMany` in case some objects
137
+ * are missing. then, it loads them all (some from FS, some from the model) and sets the edges
138
+ * between the component and the dependencies.
139
+ * once done, it finds all their dependencies, which are [A3, B3, C3] and repeat the process
140
+ * above. since there are no more dependencies, the graph is completed.
141
+ * in this case, the total depth levels are 3.
142
+ *
143
+ * even with a huge project, there are not many depth levels. by iterating through depth levels
144
+ * we keep performance sane as the importMany doesn't run multiple time and therefore the round
145
+ * trips to the remotes are minimal.
146
+ *
147
+ * normally, one importMany of the seeders is enough as importMany knows to fetch all flattened.
148
+ * however, since this buildGraph is performed on the workspace, a dependency may be new or
149
+ * modified and as such, we don't know its flattened yet.
150
+ */
151
+
152
+
153
+ async buildGraph(ids) {
154
+ this.logger.debug(`GraphFromFsBuilder, buildGraph with ${ids.length} seeders`);
155
+ const start = Date.now();
156
+ const components = await this.loadManyComponents(ids, '<none>');
157
+ await this.processManyComponents(components);
158
+ this.logger.debug(`GraphFromFsBuilder, buildGraph with ${ids.length} seeders completed (${(Date.now() - start) / 1000} sec)`);
159
+ return this.graph;
160
+ }
161
+
162
+ getAllDepsUnfiltered(component) {
163
+ return component.getAllDependenciesIds().difference(this.ignoreIds);
164
+ }
165
+
166
+ async getAllDepsFiltered(component) {
167
+ const depsWithoutIgnore = this.getAllDepsUnfiltered(component);
168
+ const shouldLoadFunc = this.shouldLoadItsDeps;
169
+ if (!shouldLoadFunc) return depsWithoutIgnore;
170
+ const deps = await (0, _pMapSeries().default)(depsWithoutIgnore, async depId => {
171
+ const shouldLoad = await shouldLoadFunc(depId);
172
+ if (!shouldLoad) this.ignoreIds.push(depId);
173
+ return shouldLoad ? depId : null;
174
+ });
175
+ return _bitIds().default.fromArray((0, _lodash2().default)(deps));
176
+ }
177
+
178
+ async processManyComponents(components) {
179
+ this.logger.debug(`GraphFromFsBuilder.processManyComponents depth ${this.depth}, ${components.length} components`);
180
+ this.depth += 1;
181
+ await this.importObjects(components);
182
+ const allDependencies = await (0, _pMapSeries().default)(components, component => this.processOneComponent(component));
183
+ const allDependenciesFlattened = (0, _lodash().flatten)(allDependencies);
184
+ if (allDependenciesFlattened.length) await this.processManyComponents(allDependenciesFlattened);
185
+ }
186
+
187
+ async importObjects(components) {
188
+ const allDeps = components.map(c => this.getAllDepsUnfiltered(c)).flat();
189
+ const allDepsWithScope = allDeps.filter(dep => dep.hasScope());
190
+ const scopeComponentsImporter = new (_scopeComponentsImporter().default)(this.consumer.scope);
191
+ await scopeComponentsImporter.importMany(_bitIds().default.uniqFromArray(allDepsWithScope), undefined, this.shouldThrowOnMissingDep);
192
+ }
193
+
194
+ async processOneComponent(component) {
195
+ const idStr = component.id.toString();
196
+ if (this.completed.includes(idStr)) return [];
197
+ const allIds = await this.getAllDepsFiltered(component);
198
+ const allDependencies = await this.loadManyComponents(allIds, idStr);
199
+ Object.entries(component.depsIdsGroupedByType).forEach(([depType, depsIds]) => {
200
+ depsIds.forEach(depId => {
201
+ if (this.ignoreIds.has(depId)) return;
202
+
203
+ if (!this.graph.hasNode(depId.toString())) {
204
+ throw new Error(`buildOneComponent: missing node of ${depId.toString()}`);
205
+ }
206
+
207
+ this.graph.setEdge(idStr, depId.toString(), depType);
208
+ });
209
+ });
210
+ this.completed.push(idStr);
211
+ return allDependencies;
212
+ }
213
+
214
+ async loadManyComponents(componentsIds, dependenciesOf) {
215
+ const components = await (0, _pMapSeries().default)(componentsIds, async comp => {
216
+ const idStr = comp.toString();
217
+ const fromGraph = this.graph.node(idStr);
218
+ if (fromGraph) return fromGraph;
219
+
220
+ try {
221
+ const component = await this.loadComponent(comp);
222
+ this.graph.setNode(idStr, component);
223
+ return component;
224
+ } catch (err) {
225
+ if (err instanceof _scope().ComponentNotFound) {
226
+ throw new (_bitError().BitError)(`error: component "${idStr}" was not found.\nthis component is a dependency of "${dependenciesOf}" and is needed as part of the graph generation`);
227
+ }
228
+
229
+ this.logger.error(`failed loading dependencies of ${dependenciesOf}`);
230
+ throw err;
231
+ }
232
+ });
233
+ return components;
234
+ }
235
+
236
+ async loadComponent(componentId) {
237
+ const componentMap = this.consumer.bitMap.getComponentIfExist(componentId);
238
+ const isOnWorkspace = Boolean(componentMap);
239
+
240
+ if (isOnWorkspace) {
241
+ return this.consumer.loadComponentForCapsule(componentId);
242
+ } // a dependency might have been installed as a package in the workspace, and as such doesn't
243
+ // have a componentMap.
244
+
245
+
246
+ const componentFromModel = await this.consumer.loadComponentFromModel(componentId);
247
+ return componentFromModel.clone();
248
+ }
249
+
250
+ }
251
+
252
+ exports.GraphFromFsBuilder = GraphFromFsBuilder;
253
+
254
+ //# sourceMappingURL=build-graph-from-fs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["build-graph-from-fs.ts"],"names":["GraphFromFsBuilder","constructor","workspace","logger","ignoreIds","BitIds","shouldLoadItsDeps","LegacyGraph","consumer","buildGraph","ids","debug","length","start","Date","now","components","loadManyComponents","processManyComponents","graph","getAllDepsUnfiltered","component","getAllDependenciesIds","difference","getAllDepsFiltered","depsWithoutIgnore","shouldLoadFunc","deps","depId","shouldLoad","push","fromArray","depth","importObjects","allDependencies","processOneComponent","allDependenciesFlattened","allDeps","map","c","flat","allDepsWithScope","filter","dep","hasScope","scopeComponentsImporter","ScopeComponentsImporter","scope","importMany","uniqFromArray","undefined","shouldThrowOnMissingDep","idStr","id","toString","completed","includes","allIds","Object","entries","depsIdsGroupedByType","forEach","depType","depsIds","has","hasNode","Error","setEdge","componentsIds","dependenciesOf","comp","fromGraph","node","loadComponent","setNode","err","ComponentNotFound","BitError","error","componentId","componentMap","bitMap","getComponentIfExist","isOnWorkspace","Boolean","loadComponentForCapsule","componentFromModel","loadComponentFromModel","clone"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAKO,MAAMA,kBAAN,CAAyB;AAM9BC,EAAAA,WAAW,CACDC,SADC,EAEDC,MAFC,EAGDC,SAAS,GAAG,KAAIC,iBAAJ,GAHX,EAIDC,iBAJC,EAKT;AAAA,SAJQJ,SAIR,GAJQA,SAIR;AAAA,SAHQC,MAGR,GAHQA,MAGR;AAAA,SAFQC,SAER,GAFQA,SAER;AAAA,SADQE,iBACR,GADQA,iBACR;AAAA,mDAVc,KAAIC,gBAAJ,GAUd;AAAA,uDAT4B,EAS5B;AAAA,mDARc,CA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,aAAKnD,KAAL,CAAWuD,OAAX,CAAmBtB,KAAnB,EAA0B/B,SAA1B;AACA,eAAOA,SAAP;AACD,OAJD,CAIE,OAAOsD,GAAP,EAAiB;AACjB,YAAIA,GAAG,YAAYC,0BAAnB,EAAsC;AACpC,gBAAM,KAAIC,oBAAJ,EACH,qBAAoBzB,KAAM,wDAAuDiB,cAAe,iDAD7F,CAAN;AAGD;;AACD,aAAKlE,MAAL,CAAY2E,KAAZ,CAAmB,kCAAiCT,cAAe,EAAnE;AACA,cAAMM,GAAN;AACD;AACF,KAjBwB,CAAzB;AAkBA,WAAO3D,UAAP;AACD;;AAC0B,QAAbyD,aAAa,CAACM,WAAD,EAAyC;AAClE,UAAMC,YAAY,GAAG,KAAKxE,QAAL,CAAcyE,MAAd,CAAqBC,mBAArB,CAAyCH,WAAzC,CAArB;AACA,UAAMI,aAAa,GAAGC,OAAO,CAACJ,YAAD,CAA7B;;AACA,QAAIG,aAAJ,EAAmB;AACjB,aAAO,KAAK3E,QAAL,CAAc6E,uBAAd,CAAsCN,WAAtC,CAAP;AACD,KALiE,CAMlE;AACA;;;AACA,UAAMO,kBAAkB,GAAG,MAAM,KAAK9E,QAAL,CAAc+E,sBAAd,CAAqCR,WAArC,CAAjC;AACA,WAAOO,kBAAkB,CAACE,KAAnB,EAAP;AACD;;AA9I6B","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 compact from 'lodash.compact';\nimport { BitId } from '@teambit/legacy-bit-id';\nimport { Logger } from '@teambit/logger';\nimport { ComponentNotFound } from '@teambit/scope';\nimport { BitError } from '@teambit/bit-error';\nimport { Workspace } from './workspace';\n\nexport type ShouldIgnoreFunc = (bitId: BitId) => Promise<boolean>;\n\nexport class GraphFromFsBuilder {\n private graph = new LegacyGraph();\n private completed: string[] = [];\n private depth = 1;\n private shouldThrowOnMissingDep = true;\n private consumer: Consumer;\n constructor(\n private workspace: Workspace,\n private logger: Logger,\n private ignoreIds = new BitIds(),\n private shouldLoadItsDeps?: ShouldIgnoreFunc\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, '<none>');\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 BitIds.uniqFromArray(allDepsWithScope),\n undefined,\n this.shouldThrowOnMissingDep\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 throw new Error(`buildOneComponent: missing node of ${depId.toString()}`);\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 (err instanceof ComponentNotFound) {\n throw new BitError(\n `error: component \"${idStr}\" was not found.\\nthis component is a dependency of \"${dependenciesOf}\" and is needed as part of the graph generation`\n );\n }\n this.logger.error(`failed loading dependencies of ${dependenciesOf}`);\n throw err;\n }\n });\n return components;\n }\n private async loadComponent(componentId: BitId): Promise<Component> {\n const componentMap = this.consumer.bitMap.getComponentIfExist(componentId);\n const isOnWorkspace = Boolean(componentMap);\n if (isOnWorkspace) {\n return this.consumer.loadComponentForCapsule(componentId);\n }\n // a dependency might have been installed as a package in the workspace, and as such doesn't\n // have a componentMap.\n const componentFromModel = await this.consumer.loadComponentFromModel(componentId);\n return componentFromModel.clone();\n }\n}\n"]}
@@ -6,6 +6,7 @@ declare type LinkCommandOpts = {
6
6
  rewire: boolean;
7
7
  verbose: boolean;
8
8
  target: string;
9
+ skipFetchingObjects?: boolean;
9
10
  };
10
11
  export declare class LinkCommand implements Command {
11
12
  private workspace;
@@ -119,7 +119,7 @@ class LinkCommand {
119
119
  (0, _defineProperty2().default)(this, "shortDescription", 'link components and core aspects');
120
120
  (0, _defineProperty2().default)(this, "group", 'development');
121
121
  (0, _defineProperty2().default)(this, "private", false);
122
- (0, _defineProperty2().default)(this, "options", [['j', 'json', 'return the output as JSON'], ['', 'verbose', 'verbose output'], ['r', 'rewire', 'Replace relative paths with module paths in code (e.g. "../foo" => "@bit/foo")'], ['', 'target <dir>', 'EXPERIMENTAL. link to an external directory (similar to npm-link) so other projects could use these components']]);
122
+ (0, _defineProperty2().default)(this, "options", [['j', 'json', 'return the output as JSON'], ['', 'verbose', 'verbose output'], ['r', 'rewire', 'Replace relative paths with module paths in code (e.g. "../foo" => "@bit/foo")'], ['', 'target <dir>', 'EXPERIMENTAL. link to an external directory (similar to npm-link) so other projects could use these components'], ['', 'skip-fetching-objects', 'skip fetch missing objects from remotes before linking']]);
123
123
  }
124
124
 
125
125
  async report([ids], opts) {
@@ -166,7 +166,8 @@ class LinkCommand {
166
166
  rewire: opts.rewire,
167
167
  linkCoreAspects: true,
168
168
  linkTeambitBit: true,
169
- linkToDir: opts.target
169
+ linkToDir: opts.target,
170
+ fetchObject: !opts.skipFetchingObjects
170
171
  };
171
172
  const linkResults = await this.workspace.link(linkOpts);
172
173
  return linkResults;
@@ -1 +1 @@
1
- {"version":3,"sources":["link.cmd.ts"],"names":["LinkCommand","constructor","workspace","logger","BASE_DOCS_DOMAIN","report","ids","opts","startTime","Date","now","linkResults","json","endTime","numOfComponents","legacyLinkResults","length","timeDiff","coreAspectsLinksWithMainAspect","coreAspectsLinks","teambitBitLink","unshift","numOfCoreAspects","title","name","coreLinks","verbose","compsLinks","componentListLinks","rewireRow","legacyCodemodResults","legacyLinkCodemodResults","nestedLinks","nestedDepsInNmLinks","targetLinks","linkToDirResults","footer","console","chalk","cyan","linkOpts","legacyLink","rewire","linkCoreAspects","linkTeambitBit","linkToDir","target","link"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAOO,MAAMA,WAAN,CAAqC;AAkB1CC,EAAAA,WAAW;AACT;AACJ;AACA;AACYC,EAAAA,SAJC;AAMT;AACJ;AACA;AACYC,EAAAA,MATC,EAUT;AAAA,SANQD,SAMR,GANQA,SAMR;AAAA,SADQC,MACR,G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Results } from '@teambit/dependency-resolver';\nimport { Logger } from '@teambit/logger';\nimport { BASE_DOCS_DOMAIN } from '@teambit/legacy/dist/constants';\nimport { timeFormat } from '@teambit/toolbox.time.time-format';\nimport chalk from 'chalk';\nimport { Workspace, WorkspaceLinkOptions } from '../workspace';\nimport { ComponentListLinks } from './component-list-links';\nimport { CoreAspectsLinks } from './core-aspects-links';\nimport { NestedComponentLinksLinks } from './nested-deps-in-nm-links';\nimport { RewireRow } from './rewire-row';\nimport { linkToDir } from './link-to-dir';\n\ntype LinkCommandOpts = {\n rewire: boolean;\n verbose: boolean;\n target: string;\n};\nexport class LinkCommand implements Command {\n name = 'link [ids...]';\n alias = '';\n description = `generate symlinks to resolve module paths for imported components.\\n https://${BASE_DOCS_DOMAIN}/docs/dependencies#missing-links`;\n shortDescription = 'link components and core aspects';\n group = 'development';\n private = false;\n options = [\n ['j', 'json', 'return the output as JSON'],\n ['', 'verbose', 'verbose output'],\n ['r', 'rewire', 'Replace relative paths with module paths in code (e.g. \"../foo\" => \"@bit/foo\")'],\n [\n '',\n 'target <dir>',\n 'EXPERIMENTAL. link to an external directory (similar to npm-link) so other projects could use these components',\n ],\n ] as CommandOptions;\n\n constructor(\n /**\n * workspace extension.\n */\n private workspace: Workspace,\n\n /**\n * logger extension.\n */\n private logger: Logger\n ) {}\n\n async report([ids]: [string[]], opts: LinkCommandOpts) {\n const startTime = Date.now();\n const linkResults = await this.json([ids], opts);\n const endTime = Date.now();\n const numOfComponents = linkResults.legacyLinkResults?.length;\n const timeDiff = timeFormat(endTime - startTime);\n const coreAspectsLinksWithMainAspect = linkResults.coreAspectsLinks || [];\n if (linkResults.teambitBitLink) {\n coreAspectsLinksWithMainAspect.unshift(linkResults.teambitBitLink);\n }\n const numOfCoreAspects = coreAspectsLinksWithMainAspect.length;\n\n const title = `Linked ${numOfComponents} components and ${numOfCoreAspects} core aspects to node_modules for workspace: ${this.workspace.name}`;\n const coreLinks = CoreAspectsLinks({\n coreAspectsLinks: coreAspectsLinksWithMainAspect,\n verbose: opts.verbose,\n });\n const compsLinks = ComponentListLinks({ componentListLinks: linkResults.legacyLinkResults, verbose: opts.verbose });\n const rewireRow = RewireRow({ legacyCodemodResults: linkResults.legacyLinkCodemodResults });\n const nestedLinks = NestedComponentLinksLinks({\n nestedDepsInNmLinks: linkResults.nestedDepsInNmLinks,\n verbose: opts.verbose,\n });\n const targetLinks = linkToDir(linkResults.linkToDirResults);\n const footer = `Finished. ${timeDiff}`;\n return `${title}\\n${coreLinks}\\n${compsLinks}\\n${rewireRow}${nestedLinks}${targetLinks}${footer}`;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n async json([ids]: [string[]], opts: LinkCommandOpts): Promise<LinkResults> {\n this.logger.console(\n `Linking components and core aspects to node_modules for workspaces: '${chalk.cyan(this.workspace.name)}'`\n );\n\n const linkOpts: WorkspaceLinkOptions = {\n legacyLink: true,\n rewire: opts.rewire,\n linkCoreAspects: true,\n linkTeambitBit: true,\n linkToDir: opts.target,\n };\n const linkResults = await this.workspace.link(linkOpts);\n return linkResults;\n }\n}\n"]}
1
+ {"version":3,"sources":["link.cmd.ts"],"names":["LinkCommand","constructor","workspace","logger","BASE_DOCS_DOMAIN","report","ids","opts","startTime","Date","now","linkResults","json","endTime","numOfComponents","legacyLinkResults","length","timeDiff","coreAspectsLinksWithMainAspect","coreAspectsLinks","teambitBitLink","unshift","numOfCoreAspects","title","name","coreLinks","verbose","compsLinks","componentListLinks","rewireRow","legacyCodemodResults","legacyLinkCodemodResults","nestedLinks","nestedDepsInNmLinks","targetLinks","linkToDirResults","footer","console","chalk","cyan","linkOpts","legacyLink","rewire","linkCoreAspects","linkTeambitBit","linkToDir","target","fetchObject","skipFetchingObjects","link"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAA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iBAAMC,IAAN,CAAW,KAAKrC,SAAL,CAAesB,IAA1B,CAAgC,GAD1G;AAIA,UAAMgB,QAA8B,GAAG;AACrCC,MAAAA,UAAU,EAAE,IADyB;AAErCC,MAAAA,MAAM,EAAEnC,IAAI,CAACmC,MAFwB;AAGrCC,MAAAA,eAAe,EAAE,IAHoB;AAIrCC,MAAAA,cAAc,EAAE,IAJqB;AAKrCC,MAAAA,SAAS,EAAEtC,IAAI,CAACuC,MALqB;AAMrCC,MAAAA,WAAW,EAAE,CAACxC,IAAI,CAACyC;AANkB,KAAvC;AAQA,UAAMrC,WAAW,GAAG,MAAM,KAAKT,SAAL,CAAe+C,IAAf,CAAoBT,QAApB,CAA1B;AACA,WAAO7B,WAAP;AACD;;AA3EyC","sourcesContent":["import { Command, CommandOptions } from '@teambit/cli';\nimport { LinkResults } from '@teambit/dependency-resolver';\nimport { Logger } from '@teambit/logger';\nimport { BASE_DOCS_DOMAIN } from '@teambit/legacy/dist/constants';\nimport { timeFormat } from '@teambit/toolbox.time.time-format';\nimport chalk from 'chalk';\nimport { Workspace, WorkspaceLinkOptions } from '../workspace';\nimport { ComponentListLinks } from './component-list-links';\nimport { CoreAspectsLinks } from './core-aspects-links';\nimport { NestedComponentLinksLinks } from './nested-deps-in-nm-links';\nimport { RewireRow } from './rewire-row';\nimport { linkToDir } from './link-to-dir';\n\ntype LinkCommandOpts = {\n rewire: boolean;\n verbose: boolean;\n target: string;\n skipFetchingObjects?: boolean;\n};\nexport class LinkCommand implements Command {\n name = 'link [ids...]';\n alias = '';\n description = `generate symlinks to resolve module paths for imported components.\\n https://${BASE_DOCS_DOMAIN}/docs/dependencies#missing-links`;\n shortDescription = 'link components and core aspects';\n group = 'development';\n private = false;\n options = [\n ['j', 'json', 'return the output as JSON'],\n ['', 'verbose', 'verbose output'],\n ['r', 'rewire', 'Replace relative paths with module paths in code (e.g. \"../foo\" => \"@bit/foo\")'],\n [\n '',\n 'target <dir>',\n 'EXPERIMENTAL. link to an external directory (similar to npm-link) so other projects could use these components',\n ],\n ['', 'skip-fetching-objects', 'skip fetch missing objects from remotes before linking'],\n ] as CommandOptions;\n\n constructor(\n /**\n * workspace extension.\n */\n private workspace: Workspace,\n\n /**\n * logger extension.\n */\n private logger: Logger\n ) {}\n\n async report([ids]: [string[]], opts: LinkCommandOpts) {\n const startTime = Date.now();\n const linkResults = await this.json([ids], opts);\n const endTime = Date.now();\n const numOfComponents = linkResults.legacyLinkResults?.length;\n const timeDiff = timeFormat(endTime - startTime);\n const coreAspectsLinksWithMainAspect = linkResults.coreAspectsLinks || [];\n if (linkResults.teambitBitLink) {\n coreAspectsLinksWithMainAspect.unshift(linkResults.teambitBitLink);\n }\n const numOfCoreAspects = coreAspectsLinksWithMainAspect.length;\n\n const title = `Linked ${numOfComponents} components and ${numOfCoreAspects} core aspects to node_modules for workspace: ${this.workspace.name}`;\n const coreLinks = CoreAspectsLinks({\n coreAspectsLinks: coreAspectsLinksWithMainAspect,\n verbose: opts.verbose,\n });\n const compsLinks = ComponentListLinks({ componentListLinks: linkResults.legacyLinkResults, verbose: opts.verbose });\n const rewireRow = RewireRow({ legacyCodemodResults: linkResults.legacyLinkCodemodResults });\n const nestedLinks = NestedComponentLinksLinks({\n nestedDepsInNmLinks: linkResults.nestedDepsInNmLinks,\n verbose: opts.verbose,\n });\n const targetLinks = linkToDir(linkResults.linkToDirResults);\n const footer = `Finished. ${timeDiff}`;\n return `${title}\\n${coreLinks}\\n${compsLinks}\\n${rewireRow}${nestedLinks}${targetLinks}${footer}`;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n async json([ids]: [string[]], opts: LinkCommandOpts): Promise<LinkResults> {\n this.logger.console(\n `Linking components and core aspects to node_modules for workspaces: '${chalk.cyan(this.workspace.name)}'`\n );\n\n const linkOpts: WorkspaceLinkOptions = {\n legacyLink: true,\n rewire: opts.rewire,\n linkCoreAspects: true,\n linkTeambitBit: true,\n linkToDir: opts.target,\n fetchObject: !opts.skipFetchingObjects,\n };\n const linkResults = await this.workspace.link(linkOpts);\n return linkResults;\n }\n}\n"]}
@@ -14,8 +14,9 @@ import { RequireableComponent } from '@teambit/harmony.modules.requireable-compo
14
14
  import { ResolvedComponent } from '@teambit/harmony.modules.resolved-component';
15
15
  import type { VariantsMain } from '@teambit/variants';
16
16
  import LegacyGraph from '@teambit/legacy/dist/scope/graph/graph';
17
+ import { BitIds } from '@teambit/legacy/dist/bit-id';
17
18
  import { BitId } from '@teambit/legacy-bit-id';
18
- import { LocalLaneId } from '@teambit/legacy/dist/lane-id/lane-id';
19
+ import { LocalLaneId, RemoteLaneId } from '@teambit/legacy/dist/lane-id/lane-id';
19
20
  import { Consumer } from '@teambit/legacy/dist/consumer';
20
21
  import { GetBitMapComponentOptions } from '@teambit/legacy/dist/consumer/bit-map/bit-map';
21
22
  import type { AddActionResults, Warnings } from '@teambit/legacy/dist/consumer/component-ops/add-components/add-components';
@@ -31,6 +32,7 @@ import { Watcher, WatchOptions } from './watch/watcher';
31
32
  import { ComponentStatus } from './workspace-component/component-status';
32
33
  import { OnComponentAddSlot, OnComponentChangeSlot, OnComponentLoadSlot, OnComponentRemoveSlot, OnPreWatch, OnPreWatchSlot } from './workspace.provider';
33
34
  import { WorkspaceComponentLoader } from './workspace-component/workspace-component-loader';
35
+ import { ShouldIgnoreFunc } from './build-graph-from-fs';
34
36
  export declare type EjectConfResult = {
35
37
  configPath: string;
36
38
  };
@@ -130,6 +132,7 @@ export declare class Workspace implements ComponentFactory {
130
132
  getState(id: ComponentID, hash: string): Promise<import("@teambit/component").State>;
131
133
  getSnap(id: ComponentID, hash: string): Promise<import("@teambit/component").Snap>;
132
134
  getCurrentLaneId(): LocalLaneId;
135
+ getCurrentRemoteLaneId(): RemoteLaneId | null;
133
136
  getDefaultExtensions(): ExtensionDataList;
134
137
  ejectConfig(id: ComponentID, options: EjectConfOptions): Promise<EjectConfResult>;
135
138
  private resolveScopeAspectListIds;
@@ -159,8 +162,9 @@ export declare class Workspace implements ComponentFactory {
159
162
  private isVendorComponentByComponentDir;
160
163
  private componentConfigFile;
161
164
  private componentConfigFileFromComponentDirAndName;
162
- getGraphWithoutCore(components: Component[]): Promise<LegacyGraph>;
165
+ getAspectsGraphWithoutCore(components: Component[], isAspect?: ShouldIgnoreFunc): Promise<LegacyGraph>;
163
166
  loadAspects(ids?: string[], throwOnError?: boolean): Promise<void>;
167
+ buildOneGraphForComponents(ids: BitId[], ignoreIds?: BitIds, shouldIgnoreFunc?: ShouldIgnoreFunc): Promise<LegacyGraph>;
164
168
  resolveAspects(runtimeName?: string, componentIds?: ComponentID[]): Promise<AspectDefinition[]>;
165
169
  private groupIdsByWorkspaceAndScope;
166
170
  private groupComponentsByWorkspaceAndScope;