@teambit/workspace 0.0.881 → 0.0.883

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.
Files changed (108) hide show
  1. package/dist/bit-map.js +10 -51
  2. package/dist/bit-map.js.map +1 -1
  3. package/dist/build-graph-from-fs.js +1 -53
  4. package/dist/build-graph-from-fs.js.map +1 -1
  5. package/dist/capsule.cmd.js +2 -34
  6. package/dist/capsule.cmd.js.map +1 -1
  7. package/dist/component-config-file/component-config-file.js +2 -60
  8. package/dist/component-config-file/component-config-file.js.map +1 -1
  9. package/dist/component-config-file/exceptions/already-exists.js +0 -6
  10. package/dist/component-config-file/exceptions/already-exists.js.map +1 -1
  11. package/dist/component-config-file/exceptions/index.js +0 -3
  12. package/dist/component-config-file/exceptions/index.js.map +1 -1
  13. package/dist/component-config-file/index.js +0 -6
  14. package/dist/component-config-file/index.js.map +1 -1
  15. package/dist/component-tree.widget.js +0 -18
  16. package/dist/component-tree.widget.js.map +1 -1
  17. package/dist/constants.js.map +1 -1
  18. package/dist/eject-conf.cmd.js +0 -23
  19. package/dist/eject-conf.cmd.js.map +1 -1
  20. package/dist/envs-subcommands/envs-replace.cmd.js +0 -13
  21. package/dist/envs-subcommands/envs-replace.cmd.js.map +1 -1
  22. package/dist/envs-subcommands/envs-set.cmd.js +0 -16
  23. package/dist/envs-subcommands/envs-set.cmd.js.map +1 -1
  24. package/dist/envs-subcommands/envs-unset.cmd.js +0 -18
  25. package/dist/envs-subcommands/envs-unset.cmd.js.map +1 -1
  26. package/dist/events/index.js +0 -6
  27. package/dist/events/index.js.map +1 -1
  28. package/dist/events/on-component-add-event.js +1 -12
  29. package/dist/events/on-component-add-event.js.map +1 -1
  30. package/dist/events/on-component-change-event.js +1 -12
  31. package/dist/events/on-component-change-event.js.map +1 -1
  32. package/dist/events/on-component-removed-event.js +1 -12
  33. package/dist/events/on-component-removed-event.js.map +1 -1
  34. package/dist/exceptions/incorrect-env-aspect.js +0 -6
  35. package/dist/exceptions/incorrect-env-aspect.js.map +1 -1
  36. package/dist/index.js +0 -19
  37. package/dist/index.js.map +1 -1
  38. package/dist/list.cmd.js +2 -15
  39. package/dist/list.cmd.js.map +1 -1
  40. package/dist/pattern.cmd.js +0 -16
  41. package/dist/pattern.cmd.js.map +1 -1
  42. package/dist/scope-subcommands/scope-set.cmd.js +0 -17
  43. package/dist/scope-subcommands/scope-set.cmd.js.map +1 -1
  44. package/dist/ui/index.js +0 -3
  45. package/dist/ui/index.js.map +1 -1
  46. package/dist/ui/workspace/default-component.js.map +1 -1
  47. package/dist/ui/workspace/index.js +0 -2
  48. package/dist/ui/workspace/index.js.map +1 -1
  49. package/dist/ui/workspace/use-workspace.js +14 -49
  50. package/dist/ui/workspace/use-workspace.js.map +1 -1
  51. package/dist/ui/workspace/workspace-context.js +0 -7
  52. package/dist/ui/workspace/workspace-context.js.map +1 -1
  53. package/dist/ui/workspace/workspace-model.js +2 -14
  54. package/dist/ui/workspace/workspace-model.js.map +1 -1
  55. package/dist/ui/workspace/workspace-overview/index.js +0 -3
  56. package/dist/ui/workspace/workspace-overview/index.js.map +1 -1
  57. package/dist/ui/workspace/workspace-overview/workspace-overview.js +0 -23
  58. package/dist/ui/workspace/workspace-overview/workspace-overview.js.map +1 -1
  59. package/dist/ui/workspace/workspace-provider.js +0 -8
  60. package/dist/ui/workspace/workspace-provider.js.map +1 -1
  61. package/dist/ui/workspace/workspace.js +2 -52
  62. package/dist/ui/workspace/workspace.js.map +1 -1
  63. package/dist/use.cmd.js +0 -13
  64. package/dist/use.cmd.js.map +1 -1
  65. package/dist/watch/check-types.js +0 -1
  66. package/dist/watch/check-types.js.map +1 -1
  67. package/dist/watch/output-formatter.js +1 -12
  68. package/dist/watch/output-formatter.js.map +1 -1
  69. package/dist/watch/watch-queue.js +0 -13
  70. package/dist/watch/watch-queue.js.map +1 -1
  71. package/dist/watch/watch.cmd.js +6 -41
  72. package/dist/watch/watch.cmd.js.map +1 -1
  73. package/dist/watch/watcher.js +13 -133
  74. package/dist/watch/watcher.js.map +1 -1
  75. package/dist/workspace-component/component-status.js +0 -4
  76. package/dist/workspace-component/component-status.js.map +1 -1
  77. package/dist/workspace-component/index.js +0 -6
  78. package/dist/workspace-component/index.js.map +1 -1
  79. package/dist/workspace-component/workspace-component-loader.js +31 -116
  80. package/dist/workspace-component/workspace-component-loader.js.map +1 -1
  81. package/dist/workspace-component/workspace-component.js +1 -11
  82. package/dist/workspace-component/workspace-component.js.map +1 -1
  83. package/dist/workspace-section.js +2 -0
  84. package/dist/workspace-section.js.map +1 -1
  85. package/dist/workspace.aspect.js +0 -5
  86. package/dist/workspace.aspect.js.map +1 -1
  87. package/dist/workspace.composition.js +0 -6
  88. package/dist/workspace.composition.js.map +1 -1
  89. package/dist/workspace.d.ts +1 -0
  90. package/dist/workspace.graphql.js +0 -12
  91. package/dist/workspace.graphql.js.map +1 -1
  92. package/dist/workspace.js +141 -545
  93. package/dist/workspace.js.map +1 -1
  94. package/dist/workspace.main.runtime.js +0 -55
  95. package/dist/workspace.main.runtime.js.map +1 -1
  96. package/dist/workspace.provider.js +8 -77
  97. package/dist/workspace.provider.js.map +1 -1
  98. package/dist/workspace.ui-root.js +3 -17
  99. package/dist/workspace.ui-root.js.map +1 -1
  100. package/dist/workspace.ui.drawer.js +2 -24
  101. package/dist/workspace.ui.drawer.js.map +1 -1
  102. package/dist/workspace.ui.runtime.js +0 -75
  103. package/dist/workspace.ui.runtime.js.map +1 -1
  104. package/package-tar/teambit-workspace-0.0.883.tgz +0 -0
  105. package/package.json +18 -18
  106. package/{preview-1666409808293.js → preview-1666582798766.js} +2 -2
  107. package/workspace-component/workspace-component-loader.ts +13 -3
  108. package/package-tar/teambit-workspace-0.0.881.tgz +0 -0
package/dist/workspace.js CHANGED
@@ -1,448 +1,312 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  require("core-js/modules/es.symbol.description.js");
6
-
7
5
  require("core-js/modules/es.array.flat.js");
8
-
9
6
  require("core-js/modules/es.array.iterator.js");
10
-
11
7
  require("core-js/modules/es.array.unscopables.flat.js");
12
-
13
8
  require("core-js/modules/es.promise.js");
14
-
15
9
  require("core-js/modules/es.regexp.exec.js");
16
-
17
10
  Object.defineProperty(exports, "__esModule", {
18
11
  value: true
19
12
  });
20
13
  exports.default = exports.Workspace = exports.ComponentRemoved = exports.ComponentChanged = exports.ComponentAdded = exports.AspectSpecificField = void 0;
21
-
22
14
  function _defineProperty2() {
23
15
  const data = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
24
-
25
16
  _defineProperty2 = function () {
26
17
  return data;
27
18
  };
28
-
29
19
  return data;
30
20
  }
31
-
32
21
  function _memoizee() {
33
22
  const data = _interopRequireDefault(require("memoizee"));
34
-
35
23
  _memoizee = function () {
36
24
  return data;
37
25
  };
38
-
39
26
  return data;
40
27
  }
41
-
42
28
  function _pMapSeries() {
43
29
  const data = _interopRequireDefault(require("p-map-series"));
44
-
45
30
  _pMapSeries = function () {
46
31
  return data;
47
32
  };
48
-
49
33
  return data;
50
34
  }
51
-
52
35
  function _aspectLoader() {
53
36
  const data = require("@teambit/aspect-loader");
54
-
55
37
  _aspectLoader = function () {
56
38
  return data;
57
39
  };
58
-
59
40
  return data;
60
41
  }
61
-
62
42
  function _cli() {
63
43
  const data = require("@teambit/cli");
64
-
65
44
  _cli = function () {
66
45
  return data;
67
46
  };
68
-
69
47
  return data;
70
48
  }
71
-
72
49
  function _scopeGraph() {
73
50
  const data = _interopRequireDefault(require("@teambit/legacy/dist/scope/graph/scope-graph"));
74
-
75
51
  _scopeGraph = function () {
76
52
  return data;
77
53
  };
78
-
79
54
  return data;
80
55
  }
81
-
82
56
  function _component() {
83
57
  const data = require("@teambit/component");
84
-
85
58
  _component = function () {
86
59
  return data;
87
60
  };
88
-
89
61
  return data;
90
62
  }
91
-
92
63
  function _bitError() {
93
64
  const data = require("@teambit/bit-error");
94
-
95
65
  _bitError = function () {
96
66
  return data;
97
67
  };
98
-
99
68
  return data;
100
69
  }
101
-
102
70
  function _config() {
103
71
  const data = require("@teambit/legacy/dist/consumer/config");
104
-
105
72
  _config = function () {
106
73
  return data;
107
74
  };
108
-
109
75
  return data;
110
76
  }
111
-
112
77
  function _envs() {
113
78
  const data = require("@teambit/envs");
114
-
115
79
  _envs = function () {
116
80
  return data;
117
81
  };
118
-
119
82
  return data;
120
83
  }
121
-
122
84
  function _workspaceModules() {
123
85
  const data = require("@teambit/workspace.modules.match-pattern");
124
-
125
86
  _workspaceModules = function () {
126
87
  return data;
127
88
  };
128
-
129
89
  return data;
130
90
  }
131
-
132
91
  function _harmonyModules() {
133
92
  const data = require("@teambit/harmony.modules.requireable-component");
134
-
135
93
  _harmonyModules = function () {
136
94
  return data;
137
95
  };
138
-
139
96
  return data;
140
97
  }
141
-
142
98
  function _consumer() {
143
99
  const data = require("@teambit/legacy/dist/api/consumer");
144
-
145
100
  _consumer = function () {
146
101
  return data;
147
102
  };
148
-
149
103
  return data;
150
104
  }
151
-
152
105
  function _bitId() {
153
106
  const data = require("@teambit/legacy/dist/bit-id");
154
-
155
107
  _bitId = function () {
156
108
  return data;
157
109
  };
158
-
159
110
  return data;
160
111
  }
161
-
162
112
  function _legacyBitId() {
163
113
  const data = require("@teambit/legacy-bit-id");
164
-
165
114
  _legacyBitId = function () {
166
115
  return data;
167
116
  };
168
-
169
117
  return data;
170
118
  }
171
-
172
119
  function _consumer2() {
173
120
  const data = require("@teambit/legacy/dist/consumer");
174
-
175
121
  _consumer2 = function () {
176
122
  return data;
177
123
  };
178
-
179
124
  return data;
180
125
  }
181
-
182
126
  function _addComponents() {
183
127
  const data = _interopRequireDefault(require("@teambit/legacy/dist/consumer/component-ops/add-components"));
184
-
185
128
  _addComponents = function () {
186
129
  return data;
187
130
  };
188
-
189
131
  return data;
190
132
  }
191
-
192
133
  function _inMemoryCache() {
193
134
  const data = require("@teambit/legacy/dist/cache/in-memory-cache");
194
-
195
135
  _inMemoryCache = function () {
196
136
  return data;
197
137
  };
198
-
199
138
  return data;
200
139
  }
201
-
202
140
  function _cacheFactory() {
203
141
  const data = require("@teambit/legacy/dist/cache/cache-factory");
204
-
205
142
  _cacheFactory = function () {
206
143
  return data;
207
144
  };
208
-
209
145
  return data;
210
146
  }
211
-
212
147
  function _exceptions() {
213
148
  const data = require("@teambit/legacy/dist/scope/exceptions");
214
-
215
149
  _exceptions = function () {
216
150
  return data;
217
151
  };
218
-
219
152
  return data;
220
153
  }
221
-
222
154
  function _componentsList() {
223
155
  const data = _interopRequireDefault(require("@teambit/legacy/dist/consumer/component/components-list"));
224
-
225
156
  _componentsList = function () {
226
157
  return data;
227
158
  };
228
-
229
159
  return data;
230
160
  }
231
-
232
161
  function _noComponentDir() {
233
162
  const data = require("@teambit/legacy/dist/consumer/component/exceptions/no-component-dir");
234
-
235
163
  _noComponentDir = function () {
236
164
  return data;
237
165
  };
238
-
239
166
  return data;
240
167
  }
241
-
242
168
  function _extensionData() {
243
169
  const data = require("@teambit/legacy/dist/consumer/config/extension-data");
244
-
245
170
  _extensionData = function () {
246
171
  return data;
247
172
  };
248
-
249
173
  return data;
250
174
  }
251
-
252
175
  function _utils() {
253
176
  const data = require("@teambit/legacy/dist/utils");
254
-
255
177
  _utils = function () {
256
178
  return data;
257
179
  };
258
-
259
180
  return data;
260
181
  }
261
-
262
182
  function _componentIdToPackageName() {
263
183
  const data = _interopRequireDefault(require("@teambit/legacy/dist/utils/bit/component-id-to-package-name"));
264
-
265
184
  _componentIdToPackageName = function () {
266
185
  return data;
267
186
  };
268
-
269
187
  return data;
270
188
  }
271
-
272
189
  function _path() {
273
190
  const data = require("@teambit/legacy/dist/utils/path");
274
-
275
191
  _path = function () {
276
192
  return data;
277
193
  };
278
-
279
194
  return data;
280
195
  }
281
-
282
196
  function _fsExtra() {
283
197
  const data = _interopRequireDefault(require("fs-extra"));
284
-
285
198
  _fsExtra = function () {
286
199
  return data;
287
200
  };
288
-
289
201
  return data;
290
202
  }
291
-
292
203
  function _lodash() {
293
204
  const data = require("lodash");
294
-
295
205
  _lodash = function () {
296
206
  return data;
297
207
  };
298
-
299
208
  return data;
300
209
  }
301
-
302
210
  function _path2() {
303
211
  const data = _interopRequireDefault(require("path"));
304
-
305
212
  _path2 = function () {
306
213
  return data;
307
214
  };
308
-
309
215
  return data;
310
216
  }
311
-
312
217
  function _scopeComponentsImporter() {
313
218
  const data = _interopRequireDefault(require("@teambit/legacy/dist/scope/component-ops/scope-components-importer"));
314
-
315
219
  _scopeComponentsImporter = function () {
316
220
  return data;
317
221
  };
318
-
319
222
  return data;
320
223
  }
321
-
322
224
  function _exceptions2() {
323
225
  const data = require("@teambit/legacy/dist/consumer/bit-map/exceptions");
324
-
325
226
  _exceptions2 = function () {
326
227
  return data;
327
228
  };
328
-
329
229
  return data;
330
230
  }
331
-
332
231
  function _loader() {
333
232
  const data = _interopRequireDefault(require("@teambit/legacy/dist/cli/loader"));
334
-
335
233
  _loader = function () {
336
234
  return data;
337
235
  };
338
-
339
236
  return data;
340
237
  }
341
-
342
238
  function _laneNotFound() {
343
239
  const data = require("@teambit/legacy/dist/api/scope/lib/exceptions/lane-not-found");
344
-
345
240
  _laneNotFound = function () {
346
241
  return data;
347
242
  };
348
-
349
243
  return data;
350
244
  }
351
-
352
245
  function _scopeNotFoundOrDenied() {
353
246
  const data = require("@teambit/legacy/dist/remotes/exceptions/scope-not-found-or-denied");
354
-
355
247
  _scopeNotFoundOrDenied = function () {
356
248
  return data;
357
249
  };
358
-
359
250
  return data;
360
251
  }
361
-
362
252
  function _componentConfigFile() {
363
253
  const data = require("./component-config-file");
364
-
365
254
  _componentConfigFile = function () {
366
255
  return data;
367
256
  };
368
-
369
257
  return data;
370
258
  }
371
-
372
259
  function _watcher() {
373
260
  const data = require("./watch/watcher");
374
-
375
261
  _watcher = function () {
376
262
  return data;
377
263
  };
378
-
379
264
  return data;
380
265
  }
381
-
382
266
  function _componentStatus() {
383
267
  const data = require("./workspace-component/component-status");
384
-
385
268
  _componentStatus = function () {
386
269
  return data;
387
270
  };
388
-
389
271
  return data;
390
272
  }
391
-
392
273
  function _workspaceComponentLoader() {
393
274
  const data = require("./workspace-component/workspace-component-loader");
394
-
395
275
  _workspaceComponentLoader = function () {
396
276
  return data;
397
277
  };
398
-
399
278
  return data;
400
279
  }
401
-
402
280
  function _incorrectEnvAspect() {
403
281
  const data = require("./exceptions/incorrect-env-aspect");
404
-
405
282
  _incorrectEnvAspect = function () {
406
283
  return data;
407
284
  };
408
-
409
285
  return data;
410
286
  }
411
-
412
287
  function _buildGraphFromFs() {
413
288
  const data = require("./build-graph-from-fs");
414
-
415
289
  _buildGraphFromFs = function () {
416
290
  return data;
417
291
  };
418
-
419
292
  return data;
420
293
  }
421
-
422
294
  function _bitMap() {
423
295
  const data = require("./bit-map");
424
-
425
296
  _bitMap = function () {
426
297
  return data;
427
298
  };
428
-
429
299
  return data;
430
300
  }
431
-
432
301
  function _workspace() {
433
302
  const data = require("./workspace.aspect");
434
-
435
303
  _workspace = function () {
436
304
  return data;
437
305
  };
438
-
439
306
  return data;
440
307
  }
441
-
442
308
  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; }
443
-
444
309
  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; }
445
-
446
310
  const AspectSpecificField = '__specific';
447
311
  exports.AspectSpecificField = AspectSpecificField;
448
312
  const ComponentAdded = 'componentAdded';
@@ -452,10 +316,10 @@ exports.ComponentChanged = ComponentChanged;
452
316
  const ComponentRemoved = 'componentRemoved';
453
317
  exports.ComponentRemoved = ComponentRemoved;
454
318
  const DEFAULT_VENDOR_DIR = 'vendor';
319
+
455
320
  /**
456
321
  * API of the Bit Workspace
457
322
  */
458
-
459
323
  class Workspace {
460
324
  // cache loaded components
461
325
  // cache env-ids that have been errored about not having "env" type
@@ -493,7 +357,6 @@ class Workspace {
493
357
  */
494
358
  onComponentAddSlot, onComponentRemoveSlot, onPreWatchSlot, graphql) {
495
359
  var _this$config;
496
-
497
360
  this.pubsub = pubsub;
498
361
  this.config = config;
499
362
  this.consumer = consumer;
@@ -523,18 +386,18 @@ class Workspace {
523
386
  (0, _defineProperty2().default)(this, "watcher", new (_watcher().Watcher)(this, this.pubsub));
524
387
  this.componentLoadedSelfAsAspects = (0, _cacheFactory().createInMemoryCache)({
525
388
  maxSize: (0, _inMemoryCache().getMaxSizeForComponents)()
526
- }); // TODO: refactor - prefer to avoid code inside the constructor.
389
+ });
527
390
 
391
+ // TODO: refactor - prefer to avoid code inside the constructor.
528
392
  this.owner = (_this$config = this.config) === null || _this$config === void 0 ? void 0 : _this$config.defaultOwner;
529
393
  this.componentLoader = new (_workspaceComponentLoader().WorkspaceComponentLoader)(this, logger, dependencyResolver, envs);
530
394
  this.validateConfig();
531
- this.bitMap = new (_bitMap().BitMap)(this.consumer.bitMap, this.consumer); // memoize this method to improve performance.
532
-
395
+ this.bitMap = new (_bitMap().BitMap)(this.consumer.bitMap, this.consumer);
396
+ // memoize this method to improve performance.
533
397
  this.componentDefaultScopeFromComponentDirAndNameWithoutConfigFile = (0, _memoizee().default)(this.componentDefaultScopeFromComponentDirAndNameWithoutConfigFile.bind(this), {
534
398
  primitive: true,
535
399
  promise: true,
536
400
  maxAge: 60 * 1000 // 1 min
537
-
538
401
  });
539
402
  }
540
403
 
@@ -545,68 +408,58 @@ class Workspace {
545
408
  if (!defaultScope) throw new (_bitError().BitError)('defaultScope is missing');
546
409
  if (!(0, _legacyBitId().isValidScopeName)(defaultScope)) throw new (_legacyBitId().InvalidScopeName)(defaultScope);
547
410
  }
411
+
548
412
  /**
549
413
  * watcher api.
550
414
  */
551
415
 
552
-
553
416
  /**
554
417
  * root path of the Workspace.
555
418
  */
556
419
  get path() {
557
420
  return this.consumer.getPath();
558
421
  }
559
- /** get the `node_modules` folder of this workspace */
560
-
561
422
 
423
+ /** get the `node_modules` folder of this workspace */
562
424
  get modulesPath() {
563
425
  return _path2().default.join(this.path, 'node_modules');
564
426
  }
565
-
566
427
  get isLegacy() {
567
428
  return this.consumer.isLegacy;
568
429
  }
569
-
570
430
  onComponentLoad(loadFn) {
571
431
  this.onComponentLoadSlot.register(loadFn);
572
432
  return this;
573
433
  }
574
-
575
434
  registerOnComponentChange(onComponentChangeFunc) {
576
435
  this.onComponentChangeSlot.register(onComponentChangeFunc);
577
436
  return this;
578
437
  }
579
-
580
438
  registerOnComponentAdd(onComponentAddFunc) {
581
439
  this.onComponentAddSlot.register(onComponentAddFunc);
582
440
  return this;
583
441
  }
584
-
585
442
  registerOnComponentRemove(onComponentRemoveFunc) {
586
443
  this.onComponentRemoveSlot.register(onComponentRemoveFunc);
587
444
  return this;
588
445
  }
589
-
590
446
  registerOnPreWatch(onPreWatchFunc) {
591
447
  this.onPreWatchSlot.register(onPreWatchFunc);
592
448
  return this;
593
449
  }
450
+
594
451
  /**
595
452
  * name of the workspace as configured in either `workspace.json`.
596
453
  * defaults to workspace root directory name.
597
454
  */
598
-
599
-
600
455
  get name() {
601
456
  if (this.config.name) return this.config.name;
602
457
  const tokenizedPath = this.path.split('/');
603
458
  return tokenizedPath[tokenizedPath.length - 1];
604
459
  }
605
-
606
460
  get icon() {
607
461
  return this.config.icon;
608
462
  }
609
-
610
463
  async hasModifiedDependencies(component) {
611
464
  const componentsList = new (_componentsList().default)(this.consumer);
612
465
  const listAutoTagPendingComponents = await componentsList.listAutoTagPendingComponents();
@@ -614,68 +467,60 @@ class Workspace {
614
467
  if (isAutoTag) return true;
615
468
  return false;
616
469
  }
470
+
617
471
  /**
618
472
  * get Component issues
619
473
  */
620
-
621
-
622
474
  getComponentIssues(component) {
623
475
  return component.state._consumer.issues || null;
624
476
  }
477
+
625
478
  /**
626
479
  * provides status of all components in the workspace.
627
480
  */
628
-
629
-
630
481
  async getComponentStatus(component) {
631
482
  const status = await this.consumer.getComponentStatusById(component.id._legacy);
632
483
  const hasModifiedDependencies = await this.hasModifiedDependencies(component);
633
484
  return _componentStatus().ComponentStatus.fromLegacy(status, hasModifiedDependencies, component.isOutdated());
634
485
  }
486
+
635
487
  /**
636
488
  * list all workspace components.
637
489
  */
638
-
639
-
640
490
  async list(filter, loadOpts) {
641
491
  const legacyIds = this.consumer.bitMap.getAllIdsAvailableOnLane();
642
492
  const ids = await this.resolveMultipleComponentIds(legacyIds);
643
493
  const idsToGet = filter && filter.limit ? (0, _lodash().slice)(ids, filter.offset, filter.offset + filter.limit) : ids;
644
494
  return this.getMany(idsToGet, loadOpts);
645
495
  }
496
+
646
497
  /**
647
498
  * list all invalid components.
648
499
  * (see the invalid criteria in ConsumerComponent.isComponentInvalidByErrorType())
649
500
  */
650
-
651
-
652
501
  async listInvalid() {
653
502
  const legacyIds = this.consumer.bitMap.getAllIdsAvailableOnLane();
654
503
  const ids = await this.resolveMultipleComponentIds(legacyIds);
655
504
  return this.componentLoader.getInvalid(ids);
656
505
  }
506
+
657
507
  /**
658
508
  * get ids of all workspace components.
659
509
  */
660
-
661
-
662
510
  async listIds() {
663
511
  if (this._cachedListIds && this.bitMap.hasChanged()) {
664
512
  delete this._cachedListIds;
665
513
  }
666
-
667
514
  if (!this._cachedListIds) {
668
515
  this._cachedListIds = await this.resolveMultipleComponentIds(this.consumer.bitmapIdsFromCurrentLane);
669
516
  }
670
-
671
517
  return this._cachedListIds;
672
518
  }
519
+
673
520
  /**
674
521
  * Check if a specific id exist in the workspace
675
522
  * @param componentId
676
523
  */
677
-
678
-
679
524
  async hasId(componentId) {
680
525
  const ids = await this.listIds();
681
526
  const found = ids.find(id => {
@@ -683,125 +528,113 @@ class Workspace {
683
528
  });
684
529
  return !!found;
685
530
  }
531
+
686
532
  /**
687
533
  * whether or not a workspace has a component with the given name
688
534
  */
689
-
690
-
691
535
  async hasName(name) {
692
536
  const ids = await this.listIds();
693
537
  return Boolean(ids.find(id => id.fullName === name));
694
538
  }
539
+
695
540
  /**
696
541
  * Check if a specific id exist in the workspace or in the scope
697
542
  * @param componentId
698
543
  */
699
-
700
-
701
544
  async hasIdNested(componentId, includeCache = true) {
702
545
  const found = await this.hasId(componentId);
703
546
  if (found) return found;
704
547
  return this.scope.hasIdNested(componentId, includeCache);
705
548
  }
549
+
706
550
  /**
707
551
  * list all modified components in the workspace.
708
552
  */
709
-
710
-
711
553
  async modified() {
712
554
  const ids = await this.componentList.listModifiedComponents(false);
713
555
  const componentIds = ids.map(_component().ComponentID.fromLegacy);
714
556
  return this.getMany(componentIds);
715
557
  }
558
+
716
559
  /**
717
560
  * list all new components in the workspace.
718
561
  */
719
-
720
-
721
562
  async newComponents() {
722
563
  const ids = await this.componentList.listNewComponents(false);
723
564
  const componentIds = ids.map(_component().ComponentID.fromLegacy);
724
565
  return this.getMany(componentIds);
725
566
  }
567
+
726
568
  /**
727
569
  * get all workspace component-ids, include vendor components.
728
570
  * (exclude nested dependencies in case dependencies are saved as components and not packages)
729
571
  */
730
-
731
-
732
572
  getAllComponentIds() {
733
573
  const bitIds = this.consumer.bitMap.getAllBitIds();
734
574
  return this.resolveMultipleComponentIds(bitIds);
735
575
  }
736
-
737
576
  async getNewAndModifiedIds() {
738
577
  const ids = await this.componentList.listTagPendingComponents();
739
578
  return this.resolveMultipleComponentIds(ids);
740
579
  }
741
-
742
580
  async newAndModified() {
743
581
  const ids = await this.getNewAndModifiedIds();
744
582
  return this.getMany(ids);
745
583
  }
746
-
747
584
  async getLogs(id, shortHash = false, startsFrom) {
748
585
  return this.scope.getLogs(id, shortHash, startsFrom);
749
586
  }
750
-
751
587
  async getLegacyGraph(ids, shouldThrowOnMissingDep = true) {
752
588
  if (!ids || ids.length < 1) ids = await this.listIds();
753
589
  const legacyIds = ids.map(id => id._legacy);
754
590
  const legacyGraph = await this.buildOneGraphForComponents(legacyIds, undefined, undefined, shouldThrowOnMissingDep);
755
591
  return legacyGraph;
756
592
  }
593
+
757
594
  /**
758
595
  * given component ids, find their dependents in the workspace
759
596
  */
760
-
761
-
762
597
  async getDependentsIds(ids) {
763
598
  const workspaceGraph = await _scopeGraph().default.buildGraphFromWorkspace(this.consumer, true);
764
599
  const workspaceDependencyGraph = new (_scopeGraph().default)(workspaceGraph);
765
600
  const workspaceDependents = ids.map(id => workspaceDependencyGraph.getDependentsInfo(id._legacy));
766
601
  const dependentsLegacyIds = workspaceDependents.flat().map(_ => _.id);
767
-
768
602
  const dependentsLegacyNoDup = _bitId().BitIds.uniqFromArray(dependentsLegacyIds);
769
-
770
603
  const dependentsIds = await this.resolveMultipleComponentIds(dependentsLegacyNoDup);
771
604
  return dependentsIds;
772
605
  }
773
-
774
606
  async createAspectList(extensionDataList) {
775
607
  const entiresP = extensionDataList.map(entry => this.extensionDataEntryToAspectEntry(entry));
776
608
  const entries = await Promise.all(entiresP);
777
609
  return this.componentAspect.createAspectListFromEntries(entries);
778
610
  }
779
-
780
611
  async extensionDataEntryToAspectEntry(dataEntry) {
781
612
  return new (_component().AspectEntry)(await this.resolveComponentId(dataEntry.id), dataEntry);
782
613
  }
614
+
783
615
  /**
784
616
  * get a component from workspace
785
617
  * @param id component ID
786
618
  */
787
-
788
-
789
619
  async get(componentId, legacyComponent, useCache = true, storeInCache = true, loadOpts) {
790
620
  this.logger.debug(`get ${componentId.toString()}`);
791
- const component = await this.componentLoader.get(componentId, legacyComponent, useCache, storeInCache, loadOpts); // When loading a component if it's an env make sure to load it as aspect as well
621
+ const component = await this.componentLoader.get(componentId, legacyComponent, useCache, storeInCache, loadOpts);
622
+ // When loading a component if it's an env make sure to load it as aspect as well
792
623
  // We only want to try load it as aspect if it's the first time we load the component
624
+ const tryLoadAsAspect = this.componentLoadedSelfAsAspects.get(component.id.toString()) === undefined;
625
+ // const config = this.harmony.get<ConfigMain>('teambit.harmony/config');
793
626
 
794
- const tryLoadAsAspect = this.componentLoadedSelfAsAspects.get(component.id.toString()) === undefined; // const config = this.harmony.get<ConfigMain>('teambit.harmony/config');
795
627
  // We are loading the component as aspect if it's an env, in order to be able to run the env-preview-template task which run only on envs.
796
628
  // Without this loading we will have a problem in case the env is the only component in the workspace. in that case we will load it as component
797
629
  // then we don't run it's provider so it doesn't register to the env slot, so we don't know it's an env.
798
-
799
- if (tryLoadAsAspect && this.envs.isUsingEnvEnv(component) && !this.aspectLoader.isCoreAspect(component.id.toStringWithoutVersion()) && !this.aspectLoader.isAspectLoaded(component.id.toString()) && (await this.hasId(component.id)) // !config.extension(component.id.toStringWithoutVersion(), true)
630
+ if (tryLoadAsAspect && this.envs.isUsingEnvEnv(component) && !this.aspectLoader.isCoreAspect(component.id.toStringWithoutVersion()) && !this.aspectLoader.isAspectLoaded(component.id.toString()) && (await this.hasId(component.id))
631
+ // !config.extension(component.id.toStringWithoutVersion(), true)
800
632
  ) {
801
633
  try {
802
634
  this.componentLoadedSelfAsAspects.set(component.id.toString(), true);
803
635
  this.logger.debug(`trying to load self as aspect with id ${component.id.toString()}`);
804
- await this.loadAspects([component.id.toString()], undefined, component.id.toString()); // In most cases if the load self as aspect failed we don't care about it.
636
+ await this.loadAspects([component.id.toString()], undefined, component.id.toString());
637
+ // In most cases if the load self as aspect failed we don't care about it.
805
638
  // we only need it in specific cases to work, but this workspace.get runs on different
806
639
  // cases where it might fail (like when importing aspect, after the import objects
807
640
  // when we write the package.json we run the applyTransformers which get to pkg which call
@@ -812,20 +645,17 @@ class Workspace {
812
645
  return component;
813
646
  }
814
647
  }
815
-
816
648
  this.componentLoadedSelfAsAspects.set(component.id.toString(), false);
817
649
  return component;
818
- } // TODO: @gilad we should refactor this asap into to the envs aspect.
819
-
650
+ }
820
651
 
652
+ // TODO: @gilad we should refactor this asap into to the envs aspect.
821
653
  async getEnvSystemDescriptor(component) {
822
654
  const env = this.envs.calculateEnv(component);
823
-
824
655
  if (env.env.__getDescriptor && typeof env.env.__getDescriptor === 'function') {
825
656
  var _services;
826
-
827
- const systemDescriptor = await env.env.__getDescriptor(); // !important persist services only on the env itself.
828
-
657
+ const systemDescriptor = await env.env.__getDescriptor();
658
+ // !important persist services only on the env itself.
829
659
  let services;
830
660
  if (this.envs.isEnvRegistered(component.id.toString())) services = this.envs.getServices(env);
831
661
  const icon = this.aspectLoader.getDescriptor(env.id).icon || env.env.icon;
@@ -840,10 +670,8 @@ class Workspace {
840
670
  services: (_services = services) === null || _services === void 0 ? void 0 : _services.toObject()
841
671
  };
842
672
  }
843
-
844
673
  return {};
845
674
  }
846
-
847
675
  clearCache() {
848
676
  this.aspectLoader.resetFailedLoadAspects();
849
677
  this.logger.debug('clearing the workspace and scope caches');
@@ -852,21 +680,18 @@ class Workspace {
852
680
  this.scope.clearCache();
853
681
  this.componentList = new (_componentsList().default)(this.consumer);
854
682
  }
855
-
856
683
  clearComponentCache(id) {
857
684
  this.componentLoader.clearComponentCache(id);
858
685
  this.consumer.componentLoader.clearOneComponentCache(id._legacy);
859
686
  this.componentList = new (_componentsList().default)(this.consumer);
860
687
  }
861
-
862
688
  async triggerOnComponentChange(id, files, initiator) {
863
- const component = await this.get(id); // if a new file was added, upon component-load, its .bitmap entry is updated to include the
689
+ const component = await this.get(id);
690
+ // if a new file was added, upon component-load, its .bitmap entry is updated to include the
864
691
  // new file. write these changes to the .bitmap file so then other processes have access to
865
692
  // this new file. If the .bitmap wasn't change, it won't do anything.
866
-
867
693
  await this.bitMap.write();
868
694
  const onChangeEntries = this.onComponentChangeSlot.toArray(); // e.g. [ [ 'teambit.bit/compiler', [Function: bound onComponentChange] ] ]
869
-
870
695
  const results = [];
871
696
  await (0, _pMapSeries().default)(onChangeEntries, async ([extension, onChangeFunc]) => {
872
697
  const onChangeResult = await onChangeFunc(component, files, initiator);
@@ -874,8 +699,9 @@ class Workspace {
874
699
  extensionId: extension,
875
700
  results: onChangeResult
876
701
  });
877
- }); // TODO: find way to standardize event names.
702
+ });
878
703
 
704
+ // TODO: find way to standardize event names.
879
705
  await this.graphql.pubsub.publish(ComponentChanged, {
880
706
  componentChanged: {
881
707
  component
@@ -883,11 +709,9 @@ class Workspace {
883
709
  });
884
710
  return results;
885
711
  }
886
-
887
712
  async triggerOnComponentAdd(id) {
888
713
  const component = await this.get(id);
889
714
  const onAddEntries = this.onComponentAddSlot.toArray(); // e.g. [ [ 'teambit.bit/compiler', [Function: bound onComponentChange] ] ]
890
-
891
715
  const results = [];
892
716
  const files = component.state.filesystem.files.map(file => file.path);
893
717
  await (0, _pMapSeries().default)(onAddEntries, async ([extension, onAddFunc]) => {
@@ -904,10 +728,8 @@ class Workspace {
904
728
  });
905
729
  return results;
906
730
  }
907
-
908
731
  async triggerOnComponentRemove(id) {
909
732
  const onRemoveEntries = this.onComponentRemoveSlot.toArray(); // e.g. [ [ 'teambit.bit/compiler', [Function: bound onComponentChange] ] ]
910
-
911
733
  const results = [];
912
734
  await (0, _pMapSeries().default)(onRemoveEntries, async ([extension, onRemoveFunc]) => {
913
735
  const onRemoveResult = await onRemoveFunc(id);
@@ -923,67 +745,52 @@ class Workspace {
923
745
  });
924
746
  return results;
925
747
  }
926
-
927
748
  getState(id, hash) {
928
749
  return this.scope.getState(id, hash);
929
750
  }
930
-
931
751
  getSnap(id, hash) {
932
752
  return this.scope.getSnap(id, hash);
933
753
  }
934
-
935
754
  getCurrentLaneId() {
936
755
  return this.consumer.getCurrentLaneId();
937
756
  }
757
+
938
758
  /**
939
759
  * if checked out to a lane and the lane exists in the remote,
940
760
  * return the remote lane id (name+scope). otherwise, return null.
941
761
  */
942
-
943
-
944
762
  async getCurrentRemoteLane() {
945
763
  const currentLaneId = this.getCurrentLaneId();
946
-
947
764
  if (currentLaneId.isDefault()) {
948
765
  return null;
949
766
  }
950
-
951
767
  const scopeComponentImporter = _scopeComponentsImporter().default.getInstance(this.consumer.scope);
952
-
953
768
  try {
954
769
  const lanes = await scopeComponentImporter.importLanes([currentLaneId]);
955
770
  return lanes[0];
956
771
  } catch (err) {
957
772
  if (err instanceof _legacyBitId().InvalidScopeName || err instanceof _scopeNotFoundOrDenied().ScopeNotFoundOrDenied || err instanceof _laneNotFound().LaneNotFound || err instanceof _legacyBitId().InvalidScopeNameFromRemote) {
958
773
  const bitMapLaneId = this.bitMap.getExportedLaneId();
959
-
960
774
  if (bitMapLaneId !== null && bitMapLaneId !== void 0 && bitMapLaneId.isEqual(currentLaneId)) {
961
775
  throw err; // we know the lane is not new, so the error is legit
962
- } // the lane could be a local lane so no need to throw an error in such case
963
-
964
-
776
+ }
777
+ // the lane could be a local lane so no need to throw an error in such case
965
778
  _loader().default.stop();
966
-
967
779
  this.logger.warn(`unable to get lane's data from a remote due to an error:\n${err.message}`);
968
780
  return null;
969
781
  }
970
-
971
782
  throw err;
972
783
  }
973
784
  }
974
-
975
785
  getDefaultExtensions() {
976
786
  if (!this.config.extensions) {
977
787
  return new (_extensionData().ExtensionDataList)();
978
788
  }
979
-
980
789
  return _extensionData().ExtensionDataList.fromConfigObject(this.config.extensions);
981
790
  }
982
-
983
791
  async ejectMultipleConfigs(ids, options) {
984
792
  return Promise.all(ids.map(id => this.ejectConfig(id, options)));
985
793
  }
986
-
987
794
  async ejectConfig(id, options) {
988
795
  const componentId = await this.resolveComponentId(id);
989
796
  const component = await this.get(componentId);
@@ -998,31 +805,30 @@ class Workspace {
998
805
  const componentConfigFile = new (_componentConfigFile().ComponentConfigFile)(componentId, aspects, componentDir, options.propagate);
999
806
  await componentConfigFile.write({
1000
807
  override: options.override
1001
- }); // remove config from the .bitmap as it's not needed anymore. it is replaced by the component.json
1002
-
808
+ });
809
+ // remove config from the .bitmap as it's not needed anymore. it is replaced by the component.json
1003
810
  this.bitMap.removeEntireConfig(id);
1004
811
  await this.bitMap.write();
1005
812
  return {
1006
813
  configPath: _componentConfigFile().ComponentConfigFile.composePath(componentDir)
1007
814
  };
1008
815
  }
816
+
1009
817
  /**
1010
818
  * see component-aspect, createAspectListFromLegacy() method for a context why this is needed.
1011
819
  */
1012
-
1013
-
1014
820
  async resolveScopeAspectListIds(aspectListFromScope) {
1015
821
  const resolvedList = await aspectListFromScope.pmap(async entry => {
1016
822
  if (entry.id.scope !== this.scope.name) {
1017
823
  return entry;
1018
824
  }
1019
-
1020
825
  const newId = await this.resolveComponentId(entry.id.fullName);
1021
826
  const newEntry = new (_component().AspectEntry)(newId, entry.legacy);
1022
827
  return newEntry;
1023
828
  });
1024
829
  return resolvedList;
1025
830
  }
831
+
1026
832
  /**
1027
833
  * @deprecated use `this.idsByPattern` instead for consistency. also, it supports negation and list of patterns.
1028
834
  *
@@ -1030,8 +836,6 @@ class Workspace {
1030
836
  * @param pattern variants.
1031
837
  * @param scope scope name.
1032
838
  */
1033
-
1034
-
1035
839
  async byPattern(pattern, scope = '**') {
1036
840
  const ids = await this.listIds();
1037
841
  const finalPattern = `${scope}/${pattern || '**'}`;
@@ -1042,12 +846,11 @@ class Workspace {
1042
846
  const components = await this.getMany(targetIds);
1043
847
  return components;
1044
848
  }
849
+
1045
850
  /**
1046
851
  * get component-ids matching the given pattern. a pattern can have multiple patterns separated by a comma.
1047
852
  * it supports negate (!) character to exclude ids.
1048
853
  */
1049
-
1050
-
1051
854
  async idsByPattern(pattern, throwForNoMatch = true) {
1052
855
  if (!pattern.includes('*') && !pattern.includes(',')) {
1053
856
  // if it's not a pattern but just id, resolve it without multimatch to support specifying id without scope-name
@@ -1056,30 +859,25 @@ class Workspace {
1056
859
  if (throwForNoMatch) throw new (_exceptions2().MissingBitMapComponent)(pattern);
1057
860
  return [];
1058
861
  }
1059
-
1060
862
  const ids = await this.listIds();
1061
863
  return this.scope.filterIdsFromPoolIdsByPattern(pattern, ids, throwForNoMatch);
1062
864
  }
865
+
1063
866
  /**
1064
867
  * useful for workspace commands, such as `bit build`, `bit compile`.
1065
868
  * by default, it should be running on new and modified components.
1066
869
  * a user can specify `--all` to run on all components or specify a pattern to limit to specific components.
1067
870
  * some commands such as build/test needs to run also on the dependents.
1068
871
  */
1069
-
1070
-
1071
872
  async getComponentsByUserInput(all, pattern, includeDependents = false) {
1072
873
  if (all) {
1073
874
  return this.list();
1074
875
  }
1075
-
1076
876
  if (pattern) {
1077
877
  const ids = await this.idsByPattern(pattern);
1078
878
  return this.getMany(ids);
1079
879
  }
1080
-
1081
880
  const newAndModified = await this.newAndModified();
1082
-
1083
881
  if (includeDependents) {
1084
882
  const newAndModifiedIds = newAndModified.map(comp => comp.id);
1085
883
  const dependentsIds = await this.getDependentsIds(newAndModifiedIds);
@@ -1087,10 +885,8 @@ class Workspace {
1087
885
  const dependents = await this.getMany(dependentsIdsFiltered);
1088
886
  newAndModified.push(...dependents);
1089
887
  }
1090
-
1091
888
  return newAndModified;
1092
889
  }
1093
-
1094
890
  async getComponentsUsingEnv(env, ignoreVersion = true, throwIfNotFound = false) {
1095
891
  const allComps = await this.list();
1096
892
  const allEnvs = await this.envs.createEnvironment(allComps);
@@ -1100,42 +896,37 @@ class Workspace {
1100
896
  const envWithoutVersion = runtimeEnv.id.split('@')[0];
1101
897
  return env === envWithoutVersion;
1102
898
  });
1103
-
1104
899
  if (!foundEnv && throwIfNotFound) {
1105
900
  const availableEnvs = allEnvs.runtimeEnvs.map(runtimeEnv => runtimeEnv.id);
1106
901
  throw new (_bitError().BitError)(`unable to find components that using "${env}" env.
1107
902
  the following envs are used in this workspace: ${availableEnvs.join(', ')}`);
1108
903
  }
1109
-
1110
904
  return (foundEnv === null || foundEnv === void 0 ? void 0 : foundEnv.components) || [];
1111
905
  }
1112
-
1113
906
  async getMany(ids, loadOpts) {
1114
907
  return this.componentLoader.getMany(ids, loadOpts);
1115
908
  }
1116
-
1117
909
  getManyByLegacy(components, loadOpts) {
1118
910
  return (0, _pMapSeries().default)(components, async component => {
1119
911
  const id = await this.resolveComponentId(component.id);
1120
912
  return this.get(id, component, true, true, loadOpts);
1121
913
  });
1122
914
  }
915
+
1123
916
  /**
1124
917
  * don't throw an error if the component was not found, simply return undefined.
1125
918
  */
1126
-
1127
-
1128
919
  async getIfExist(componentId) {
1129
920
  return this.componentLoader.getIfExist(componentId);
1130
921
  }
922
+
1131
923
  /**
1132
924
  * whether a component exists in the workspace
1133
925
  */
1134
-
1135
-
1136
926
  exists(componentId) {
1137
927
  return Boolean(this.consumer.bitmapIdsFromCurrentLane.find(_ => _.isEqualWithoutVersion(componentId._legacy)));
1138
928
  }
929
+
1139
930
  /**
1140
931
  * This will make sure to fetch the objects prior to load them
1141
932
  * do not use it if you are not sure you need it.
@@ -1143,8 +934,6 @@ the following envs are used in this workspace: ${availableEnvs.join(', ')}`);
1143
934
  * currently it used only for get many of aspects
1144
935
  * @param ids
1145
936
  */
1146
-
1147
-
1148
937
  async importAndGetMany(ids) {
1149
938
  await this.importCurrentLaneIfMissing();
1150
939
  await this.scope.import(ids, {
@@ -1152,34 +941,27 @@ the following envs are used in this workspace: ${availableEnvs.join(', ')}`);
1152
941
  });
1153
942
  return this.componentLoader.getMany(ids);
1154
943
  }
1155
-
1156
944
  async importCurrentLaneIfMissing() {
1157
945
  const laneId = this.getCurrentLaneId();
1158
946
  const laneObj = await this.scope.legacyScope.getCurrentLaneObject();
1159
-
1160
947
  if (laneId.isDefault() || laneObj) {
1161
948
  return;
1162
949
  }
1163
-
1164
950
  const lane = await this.getCurrentRemoteLane();
1165
-
1166
951
  if (!lane) {
1167
952
  return;
1168
953
  }
1169
-
1170
954
  this.logger.info(`current lane ${laneId.toString()} is missing, importing it`);
1171
955
  await this.scope.legacyScope.objects.writeObjectsToTheFS([lane]);
1172
-
1173
956
  const scopeComponentsImporter = _scopeComponentsImporter().default.getInstance(this.scope.legacyScope);
1174
-
1175
957
  const ids = _bitId().BitIds.fromArray(lane.toBitIds().filter(id => id.hasScope()));
1176
-
1177
958
  await scopeComponentsImporter.importManyDeltaWithoutDeps(ids, true, lane);
1178
959
  await scopeComponentsImporter.importMany({
1179
960
  ids,
1180
961
  lanes: [lane]
1181
962
  });
1182
963
  }
964
+
1183
965
  /**
1184
966
  * @deprecated use this.track() instead
1185
967
  * track a new component. (practically, add it to .bitmap).
@@ -1189,8 +971,6 @@ the following envs are used in this workspace: ${availableEnvs.join(', ')}`);
1189
971
  * @param main if not set, will try to guess according to some strategies and throws if failed
1190
972
  * @param override whether add details to an existing component or re-define it
1191
973
  */
1192
-
1193
-
1194
974
  async add(componentPaths, id, main, override = false) {
1195
975
  const addComponent = new (_addComponents().default)({
1196
976
  consumer: this.consumer
@@ -1200,28 +980,23 @@ the following envs are used in this workspace: ${availableEnvs.join(', ')}`);
1200
980
  main,
1201
981
  override
1202
982
  });
1203
- const addResults = await addComponent.add(); // @todo: the legacy commands have `consumer.onDestroy()` on command completion, it writes the
983
+ const addResults = await addComponent.add();
984
+ // @todo: the legacy commands have `consumer.onDestroy()` on command completion, it writes the
1204
985
  // .bitmap file. workspace needs a similar mechanism. once done, remove the next line.
1205
-
1206
986
  await this.bitMap.write();
1207
987
  return addResults;
1208
988
  }
1209
-
1210
989
  async use(aspectIdStr) {
1211
990
  const aspectId = await this.resolveComponentId(aspectIdStr);
1212
991
  let aspectIdToAdd = aspectId.toStringWithoutVersion();
1213
-
1214
992
  if (!(await this.hasId(aspectId))) {
1215
993
  const loadedIds = await this.scope.loadAspects([aspectIdStr], true, 'bit use command');
1216
994
  if (loadedIds[0]) aspectIdToAdd = loadedIds[0];
1217
995
  }
1218
-
1219
996
  const config = this.harmony.get('teambit.harmony/config').workspaceConfig;
1220
-
1221
997
  if (!config) {
1222
998
  throw new Error(`use() unable to get the workspace config`);
1223
999
  }
1224
-
1225
1000
  config.setExtension(aspectIdToAdd, {}, {
1226
1001
  overrideExisting: false,
1227
1002
  ignoreVersion: false
@@ -1229,13 +1004,12 @@ the following envs are used in this workspace: ${availableEnvs.join(', ')}`);
1229
1004
  await config.write();
1230
1005
  return aspectIdToAdd;
1231
1006
  }
1007
+
1232
1008
  /**
1233
1009
  * add a new component to the .bitmap file.
1234
1010
  * this method only adds the records in memory but doesn't persist to the filesystem.
1235
1011
  * to write the .bitmap file once completed, run "await this.bitMap.write();"
1236
1012
  */
1237
-
1238
-
1239
1013
  async track(trackData) {
1240
1014
  const defaultScope = trackData.defaultScope ? await this.addOwnerToScopeName(trackData.defaultScope) : undefined;
1241
1015
  const addComponent = new (_addComponents().default)({
@@ -1258,6 +1032,7 @@ the following envs are used in this workspace: ${availableEnvs.join(', ')}`);
1258
1032
  warnings: result.warnings
1259
1033
  };
1260
1034
  }
1035
+
1261
1036
  /**
1262
1037
  * scopes in bit.dev are "owner.collection".
1263
1038
  * we might have the scope-name only without the owner and we need to retrieve it from the defaultScope in the
@@ -1266,80 +1041,64 @@ the following envs are used in this workspace: ${availableEnvs.join(', ')}`);
1266
1041
  * @param scopeName scopeName that might not have the owner part.
1267
1042
  * @returns full scope name
1268
1043
  */
1269
-
1270
-
1271
1044
  async addOwnerToScopeName(scopeName) {
1272
1045
  if (scopeName.includes('.')) return scopeName; // it has owner.
1273
-
1274
1046
  const isSelfHosted = !(await this.isHostedByBit(scopeName));
1275
1047
  if (isSelfHosted) return scopeName;
1276
1048
  const wsDefaultScope = this.defaultScope;
1277
-
1278
1049
  if (!wsDefaultScope.includes('.')) {
1279
1050
  throw new Error(`the entered scope has no owner nor the defaultScope in workspace.jsonc`);
1280
1051
  }
1281
-
1282
1052
  const [owner] = wsDefaultScope.split('.');
1283
1053
  return `${owner}.${scopeName}`;
1284
1054
  }
1285
-
1286
1055
  async write(component, rootPath) {
1287
1056
  await Promise.all(component.filesystem.files.map(async file => {
1288
1057
  const pathToWrite = rootPath ? _path2().default.join(this.path, rootPath, file.relative) : file.path;
1289
1058
  await _fsExtra().default.outputFile(pathToWrite, file.contents);
1290
1059
  }));
1291
1060
  }
1061
+
1292
1062
  /**
1293
1063
  * Get the component root dir in the file system (relative to workspace or full) in Linux format
1294
1064
  * @param componentId
1295
1065
  * @param relative return the path relative to the workspace or full path
1296
1066
  */
1297
-
1298
-
1299
1067
  componentDir(componentId, bitMapOptions, options = {
1300
1068
  relative: false
1301
1069
  }) {
1302
1070
  return this.componentDirFromLegacyId(componentId._legacy, bitMapOptions, options);
1303
1071
  }
1072
+
1304
1073
  /**
1305
1074
  * component's files in the workspace are symlinked to the node_modules, and a package.json file is generated on that
1306
1075
  * package directory to simulate a valid node package.
1307
1076
  * @returns the package directory inside the node_module.
1308
1077
  * by default the absolute path, unless `options.relative` was set
1309
1078
  */
1310
-
1311
-
1312
1079
  componentPackageDir(component, options = {
1313
1080
  relative: false
1314
1081
  }) {
1315
1082
  const packageName = (0, _componentIdToPackageName().default)(component.state._consumer);
1316
-
1317
1083
  const packageDir = _path2().default.join('node_modules', packageName);
1318
-
1319
1084
  return options.relative ? packageDir : this.consumer.toAbsolutePath(packageDir);
1320
1085
  }
1321
-
1322
1086
  componentDirFromLegacyId(bitId, bitMapOptions, options = {
1323
1087
  relative: false
1324
1088
  }) {
1325
1089
  const componentMap = this.consumer.bitMap.getComponent(bitId, bitMapOptions);
1326
1090
  const relativeComponentDir = componentMap.getComponentDir();
1327
-
1328
1091
  if (!relativeComponentDir) {
1329
1092
  throw new (_noComponentDir().NoComponentDir)(bitId.toString());
1330
1093
  }
1331
-
1332
1094
  if (options.relative) {
1333
1095
  return relativeComponentDir;
1334
1096
  }
1335
-
1336
1097
  return _path2().default.join(this.path, relativeComponentDir);
1337
1098
  }
1338
-
1339
1099
  componentDirToAbsolute(relativeComponentDir) {
1340
1100
  return _path2().default.join(this.path, relativeComponentDir);
1341
1101
  }
1342
-
1343
1102
  async componentDefaultScope(componentId) {
1344
1103
  const relativeComponentDir = this.componentDir(componentId, {
1345
1104
  ignoreVersion: true
@@ -1348,43 +1107,33 @@ the following envs are used in this workspace: ${availableEnvs.join(', ')}`);
1348
1107
  });
1349
1108
  return this.componentDefaultScopeFromComponentDirAndName(relativeComponentDir, componentId.fullName);
1350
1109
  }
1351
-
1352
1110
  async componentDefaultScopeFromComponentDirAndName(relativeComponentDir, name) {
1353
1111
  const componentConfigFile = await this.componentConfigFileFromComponentDirAndName(relativeComponentDir, name);
1354
-
1355
1112
  if (componentConfigFile && componentConfigFile.defaultScope) {
1356
1113
  return componentConfigFile.defaultScope;
1357
1114
  }
1358
-
1359
1115
  const bitMapId = this.consumer.bitMap.getExistingBitId(name);
1360
1116
  const bitMapEntry = bitMapId ? this.consumer.bitMap.getComponent(bitMapId) : undefined;
1361
-
1362
1117
  if (bitMapEntry && bitMapEntry.defaultScope) {
1363
1118
  return bitMapEntry.defaultScope;
1364
1119
  }
1365
-
1366
1120
  return this.componentDefaultScopeFromComponentDirAndNameWithoutConfigFile(relativeComponentDir, name);
1367
1121
  }
1368
-
1369
1122
  get defaultScope() {
1370
1123
  return this.config.defaultScope;
1371
1124
  }
1372
-
1373
1125
  async componentDefaultScopeFromComponentDirAndNameWithoutConfigFile(relativeComponentDir, name) {
1374
1126
  const variantConfig = this.variants.byRootDirAndName(relativeComponentDir, name);
1375
-
1376
1127
  if (variantConfig && variantConfig.defaultScope) {
1377
1128
  return variantConfig.defaultScope;
1378
1129
  }
1379
-
1380
1130
  const isVendor = this.isVendorComponentByComponentDir(relativeComponentDir);
1381
-
1382
1131
  if (!isVendor) {
1383
1132
  return this.config.defaultScope;
1384
1133
  }
1385
-
1386
1134
  return undefined;
1387
1135
  }
1136
+
1388
1137
  /**
1389
1138
  * Calculate the component config based on:
1390
1139
  * the config property in the .bitmap file
@@ -1394,11 +1143,8 @@ the following envs are used in this workspace: ${availableEnvs.join(', ')}`);
1394
1143
  * extensions from the model.
1395
1144
  */
1396
1145
  // eslint-disable-next-line complexity
1397
-
1398
-
1399
1146
  async componentExtensions(componentId, componentFromScope, excludeOrigins = []) {
1400
1147
  var _componentFromScope$c, _componentConfigFile$, _variantConfig$propag, _wsDefaultExtensions;
1401
-
1402
1148
  // TODO: consider caching this result
1403
1149
  let configFileExtensions;
1404
1150
  let variantsExtensions;
@@ -1410,7 +1156,6 @@ the following envs are used in this workspace: ${availableEnvs.join(', ')}`);
1410
1156
  let unmergedExtensions;
1411
1157
  let unmergedExtensionsSpecific;
1412
1158
  let unmergedExtensionsNonSpecific;
1413
-
1414
1159
  if (unmergedHead) {
1415
1160
  const versionInstance = await this.scope.legacyScope.getVersionInstance(componentId._legacy.changeVersion(unmergedHead.toString()));
1416
1161
  unmergedExtensions = versionInstance.extensions;
@@ -1418,58 +1163,48 @@ the following envs are used in this workspace: ${availableEnvs.join(', ')}`);
1418
1163
  unmergedExtensionsSpecific = new (_extensionData().ExtensionDataList)(...specific);
1419
1164
  unmergedExtensionsNonSpecific = new (_extensionData().ExtensionDataList)(...nonSpecific);
1420
1165
  }
1421
-
1422
1166
  const scopeExtensions = (componentFromScope === null || componentFromScope === void 0 ? void 0 : (_componentFromScope$c = componentFromScope.config) === null || _componentFromScope$c === void 0 ? void 0 : _componentFromScope$c.extensions) || new (_extensionData().ExtensionDataList)();
1423
1167
  const [specific, nonSpecific] = (0, _lodash().partition)(scopeExtensions, entry => entry.config[AspectSpecificField] === true);
1424
1168
  const scopeExtensionsNonSpecific = new (_extensionData().ExtensionDataList)(...nonSpecific);
1425
1169
  const scopeExtensionsSpecific = new (_extensionData().ExtensionDataList)(...specific);
1426
1170
  const componentConfigFile = await this.componentConfigFile(componentId);
1427
-
1428
1171
  if (componentConfigFile) {
1429
1172
  configFileExtensions = componentConfigFile.aspects.toLegacy();
1430
1173
  }
1431
-
1432
1174
  const relativeComponentDir = this.componentDir(componentId, {
1433
1175
  ignoreVersion: true
1434
1176
  }, {
1435
1177
  relative: true
1436
1178
  });
1437
1179
  const variantConfig = this.variants.byRootDirAndName(relativeComponentDir, componentId.fullName);
1438
-
1439
1180
  if (variantConfig) {
1440
- variantsExtensions = variantConfig.extensions.clone(); // Do not merge from scope when there is specific variant (which is not *) that match the component
1181
+ variantsExtensions = variantConfig.extensions.clone();
1182
+ // Do not merge from scope when there is specific variant (which is not *) that match the component
1441
1183
  // if (variantConfig.maxSpecificity > 0) {
1442
1184
  // mergeFromScope = false;
1443
1185
  // }
1444
1186
  }
1445
1187
 
1446
1188
  const isVendor = this.isVendorComponentByComponentDir(relativeComponentDir);
1447
-
1448
1189
  if (!isVendor) {
1449
1190
  wsDefaultExtensions = this.getDefaultExtensions();
1450
- } // We don't stop on each step because we want to merge the default scope even if propagate=false but the default scope is not defined
1191
+ }
1192
+ // We don't stop on each step because we want to merge the default scope even if propagate=false but the default scope is not defined
1451
1193
  // in the case the same extension pushed twice, the former takes precedence (opposite of Object.assign)
1452
-
1453
-
1454
1194
  const extensionsToMerge = [];
1455
1195
  let envWasFoundPreviously = false;
1456
1196
  const loadedExtensionIds = [];
1457
1197
  const removedExtensionIds = [];
1458
-
1459
1198
  const addAndLoadExtensions = async (extensions, origin, extraData) => {
1460
1199
  if (!extensions.length) {
1461
1200
  return;
1462
1201
  }
1463
-
1464
1202
  removedExtensionIds.push(...extensions.filter(extData => extData.isRemoved).map(extData => extData.stringId));
1465
1203
  const extsWithoutRemoved = extensions.filterRemovedExtensions();
1466
-
1467
1204
  const extsWithoutLoaded = _extensionData().ExtensionDataList.fromArray(extsWithoutRemoved.filter(ext => {
1468
1205
  var _ext$extensionId;
1469
-
1470
1206
  return !loadedExtensionIds.includes(((_ext$extensionId = ext.extensionId) === null || _ext$extensionId === void 0 ? void 0 : _ext$extensionId.toStringWithoutVersion()) || '');
1471
1207
  }));
1472
-
1473
1208
  const selfInMergedExtensions = extsWithoutLoaded.findExtension(componentId._legacy.toStringWithoutScopeAndVersion(), true, true);
1474
1209
  const extsWithoutSelf = selfInMergedExtensions !== null && selfInMergedExtensions !== void 0 && selfInMergedExtensions.extensionId ? extsWithoutLoaded.remove(selfInMergedExtensions.extensionId) : extsWithoutLoaded;
1475
1210
  await this.loadExtensions(extsWithoutSelf, componentId);
@@ -1477,12 +1212,10 @@ the following envs are used in this workspace: ${availableEnvs.join(', ')}`);
1477
1212
  extensionDataListFiltered,
1478
1213
  envIsCurrentlySet
1479
1214
  } = this.filterEnvsFromExtensionsIfNeeded(extsWithoutSelf, envWasFoundPreviously);
1480
-
1481
1215
  if (envIsCurrentlySet) {
1482
1216
  await this.warnAboutMisconfiguredEnv(componentId, extensions);
1483
1217
  envWasFoundPreviously = true;
1484
1218
  }
1485
-
1486
1219
  extensionsToMerge.push({
1487
1220
  origin,
1488
1221
  extensions: extensionDataListFiltered,
@@ -1490,37 +1223,28 @@ the following envs are used in this workspace: ${availableEnvs.join(', ')}`);
1490
1223
  });
1491
1224
  loadedExtensionIds.push(...(0, _lodash().compact)(extensionDataListFiltered.map(e => {
1492
1225
  var _e$extensionId;
1493
-
1494
1226
  return (_e$extensionId = e.extensionId) === null || _e$extensionId === void 0 ? void 0 : _e$extensionId.toStringWithoutVersion();
1495
1227
  })));
1496
1228
  };
1497
-
1498
1229
  const setDataListAsSpecific = extensions => {
1499
1230
  extensions.forEach(dataEntry => dataEntry.config[AspectSpecificField] = true);
1500
1231
  };
1501
-
1502
1232
  if (bitMapExtensions && !excludeOrigins.includes('BitmapFile')) {
1503
1233
  const extensionDataList = _extensionData().ExtensionDataList.fromConfigObject(bitMapExtensions);
1504
-
1505
1234
  setDataListAsSpecific(extensionDataList);
1506
1235
  await addAndLoadExtensions(extensionDataList, 'BitmapFile');
1507
1236
  }
1508
-
1509
1237
  if (configFileExtensions && !excludeOrigins.includes('ComponentJsonFile')) {
1510
1238
  setDataListAsSpecific(configFileExtensions);
1511
1239
  await addAndLoadExtensions(configFileExtensions, 'ComponentJsonFile');
1512
1240
  }
1513
-
1514
1241
  if (unmergedExtensionsSpecific && !excludeOrigins.includes('UnmergedSpecific')) {
1515
1242
  await addAndLoadExtensions(_extensionData().ExtensionDataList.fromArray(unmergedExtensionsSpecific), 'UnmergedSpecific');
1516
1243
  }
1517
-
1518
1244
  if (!excludeOrigins.includes('ModelSpecific')) {
1519
1245
  await addAndLoadExtensions(_extensionData().ExtensionDataList.fromArray(scopeExtensionsSpecific), 'ModelSpecific');
1520
1246
  }
1521
-
1522
1247
  let continuePropagating = (_componentConfigFile$ = componentConfigFile === null || componentConfigFile === void 0 ? void 0 : componentConfigFile.propagate) !== null && _componentConfigFile$ !== void 0 ? _componentConfigFile$ : true;
1523
-
1524
1248
  if (variantsExtensions && continuePropagating && !excludeOrigins.includes('WorkspaceVariants')) {
1525
1249
  const appliedRules = variantConfig === null || variantConfig === void 0 ? void 0 : variantConfig.sortedMatches.map(({
1526
1250
  pattern,
@@ -1533,57 +1257,52 @@ the following envs are used in this workspace: ${availableEnvs.join(', ')}`);
1533
1257
  appliedRules
1534
1258
  });
1535
1259
  }
1536
-
1537
- continuePropagating = continuePropagating && ((_variantConfig$propag = variantConfig === null || variantConfig === void 0 ? void 0 : variantConfig.propagate) !== null && _variantConfig$propag !== void 0 ? _variantConfig$propag : true); // Do not apply default extensions on the default extensions (it will create infinite loop when loading them)
1538
-
1260
+ continuePropagating = continuePropagating && ((_variantConfig$propag = variantConfig === null || variantConfig === void 0 ? void 0 : variantConfig.propagate) !== null && _variantConfig$propag !== void 0 ? _variantConfig$propag : true);
1261
+ // Do not apply default extensions on the default extensions (it will create infinite loop when loading them)
1539
1262
  const isDefaultExtension = (_wsDefaultExtensions = wsDefaultExtensions) === null || _wsDefaultExtensions === void 0 ? void 0 : _wsDefaultExtensions.findExtension(componentId.toString(), true, true);
1540
-
1541
1263
  if (wsDefaultExtensions && continuePropagating && !isDefaultExtension && !excludeOrigins.includes('WorkspaceDefault')) {
1542
1264
  await addAndLoadExtensions(wsDefaultExtensions, 'WorkspaceDefault');
1543
1265
  }
1544
-
1545
1266
  if (unmergedExtensionsNonSpecific && mergeFromScope && continuePropagating && !excludeOrigins.includes('UnmergedNonSpecific')) {
1546
1267
  await addAndLoadExtensions(unmergedExtensionsNonSpecific, 'UnmergedNonSpecific');
1547
1268
  }
1548
-
1549
1269
  if (mergeFromScope && continuePropagating && !excludeOrigins.includes('ModelNonSpecific')) {
1550
1270
  await addAndLoadExtensions(scopeExtensionsNonSpecific, 'ModelNonSpecific');
1551
- } // It's important to do this resolution before the merge, otherwise we have issues with extensions
1552
- // coming from scope with local scope name, as opposed to the same extension comes from the workspace with default scope name
1553
-
1271
+ }
1554
1272
 
1273
+ // It's important to do this resolution before the merge, otherwise we have issues with extensions
1274
+ // coming from scope with local scope name, as opposed to the same extension comes from the workspace with default scope name
1555
1275
  await Promise.all(extensionsToMerge.map(list => this.resolveExtensionListIds(list.extensions)));
1556
-
1557
1276
  const afterMerge = _extensionData().ExtensionDataList.mergeConfigs(extensionsToMerge.map(ext => ext.extensions));
1558
-
1559
1277
  const withoutRemoved = afterMerge.filter(extData => !removedExtensionIds.includes(extData.stringId));
1560
-
1561
1278
  const extensions = _extensionData().ExtensionDataList.fromArray(withoutRemoved);
1562
-
1563
1279
  return {
1564
1280
  extensions,
1565
1281
  beforeMerge: extensionsToMerge
1566
1282
  };
1567
1283
  }
1568
-
1569
1284
  getUnmergedHead(componentId) {
1570
1285
  const unmerged = this.scope.legacyScope.objects.unmergedComponents.getEntry(componentId._legacy.name);
1571
1286
  return unmerged === null || unmerged === void 0 ? void 0 : unmerged.head;
1572
1287
  }
1573
-
1288
+ async getUnmergedComponent(componentId) {
1289
+ const unmerged = this.scope.legacyScope.objects.unmergedComponents.getEntry(componentId._legacy.name);
1290
+ if (unmerged !== null && unmerged !== void 0 && unmerged.head) {
1291
+ return this.scope.get(componentId.changeVersion(unmerged === null || unmerged === void 0 ? void 0 : unmerged.head.toString()));
1292
+ }
1293
+ return undefined;
1294
+ }
1574
1295
  async warnAboutMisconfiguredEnv(componentId, extensionDataList) {
1575
1296
  if (!(await this.hasId(componentId))) {
1576
1297
  // if this is a dependency and not belong to the workspace, don't show the warning
1577
1298
  return;
1578
1299
  }
1579
-
1580
1300
  const envAspect = extensionDataList.findExtension(_envs().EnvsAspect.id);
1581
1301
  const envFromEnvsAspect = envAspect === null || envAspect === void 0 ? void 0 : envAspect.config.env;
1582
1302
  if (!envFromEnvsAspect) return;
1583
1303
  if (this.envs.getCoreEnvsIds().includes(envFromEnvsAspect)) return;
1584
1304
  if (this.warnedAboutMisconfiguredEnvs.includes(envFromEnvsAspect)) return;
1585
1305
  let env;
1586
-
1587
1306
  try {
1588
1307
  const envId = await this.resolveComponentId(envFromEnvsAspect);
1589
1308
  env = await this.get(envId);
@@ -1596,10 +1315,8 @@ the following envs are used in this workspace: ${availableEnvs.join(', ')}`);
1596
1315
  this.logger.consoleWarning(`env "${envFromEnvsAspect}" is not of type env. (correct the env's type, or component config with "bit env set ${envFromEnvsAspect} teambit.envs/env")`);
1597
1316
  }
1598
1317
  }
1599
-
1600
1318
  async isModified(component) {
1601
1319
  const head = component.head;
1602
-
1603
1320
  if (!head) {
1604
1321
  return true; // it's a new component
1605
1322
  }
@@ -1609,7 +1326,6 @@ the following envs are used in this workspace: ${availableEnvs.join(', ')}`);
1609
1326
  const componentStatus = await this.consumer.getComponentStatusById(component.id._legacy);
1610
1327
  return componentStatus.modified === true;
1611
1328
  }
1612
-
1613
1329
  filterEnvsFromExtensionsIfNeeded(extensionDataList, envWasFoundPreviously) {
1614
1330
  const envAspect = extensionDataList.findExtension(_envs().EnvsAspect.id);
1615
1331
  const envFromEnvsAspect = envAspect === null || envAspect === void 0 ? void 0 : envAspect.config.env;
@@ -1617,7 +1333,6 @@ the following envs are used in this workspace: ${availableEnvs.join(', ')}`);
1617
1333
  const extensionDataListFiltered = new (_extensionData().ExtensionDataList)(...nonEnvs);
1618
1334
  const envIsCurrentlySet = envFromEnvsAspect || envsNotFromEnvsAspect.length;
1619
1335
  const shouldIgnoreCurrentEnv = envIsCurrentlySet && envWasFoundPreviously;
1620
-
1621
1336
  if (shouldIgnoreCurrentEnv) {
1622
1337
  // still, aspect env may have other data other then config.env.
1623
1338
  if (envAspect) {
@@ -1629,13 +1344,11 @@ the following envs are used in this workspace: ${availableEnvs.join(', ')}`);
1629
1344
  if (envAspect) extensionDataListFiltered.push(envAspect);
1630
1345
  extensionDataListFiltered.push(...envsNotFromEnvsAspect);
1631
1346
  }
1632
-
1633
1347
  return {
1634
1348
  extensionDataListFiltered,
1635
1349
  envIsCurrentlySet
1636
1350
  };
1637
1351
  }
1638
-
1639
1352
  async triggerOnPreWatch(componentIds, watchOpts) {
1640
1353
  const components = await this.getMany(componentIds);
1641
1354
  const preWatchFunctions = this.onPreWatchSlot.values();
@@ -1643,36 +1356,29 @@ the following envs are used in this workspace: ${availableEnvs.join(', ')}`);
1643
1356
  await func(components, watchOpts);
1644
1357
  });
1645
1358
  }
1359
+
1646
1360
  /**
1647
1361
  * filter the given component-ids and set default-scope only to the new ones.
1648
1362
  * returns the affected components.
1649
1363
  */
1650
-
1651
-
1652
1364
  async setDefaultScopeToComponents(componentIds, scopeName) {
1653
1365
  if (!(0, _legacyBitId().isValidScopeName)(scopeName)) {
1654
1366
  throw new (_legacyBitId().InvalidScopeName)(scopeName);
1655
1367
  }
1656
-
1657
1368
  const newComponentIds = componentIds.filter(id => !id.hasVersion());
1658
-
1659
1369
  if (!newComponentIds.length) {
1660
1370
  const compIdsStr = componentIds.map(compId => compId.toString()).join(', ');
1661
1371
  throw new (_bitError().BitError)(`unable to set default-scope for the following components, as they are not new:\n${compIdsStr}`);
1662
1372
  }
1663
-
1664
1373
  newComponentIds.map(comp => this.bitMap.setDefaultScope(comp, scopeName));
1665
1374
  await this.bitMap.write();
1666
1375
  return newComponentIds;
1667
1376
  }
1668
-
1669
1377
  async setDefaultScope(scopeName) {
1670
1378
  var _config$workspaceConf, _config$workspaceConf2;
1671
-
1672
1379
  if (this.defaultScope === scopeName) {
1673
1380
  throw new Error(`the default-scope is already set as "${scopeName}", nothing to change`);
1674
1381
  }
1675
-
1676
1382
  const config = this.harmony.get('teambit.harmony/config');
1677
1383
  (_config$workspaceConf = config.workspaceConfig) === null || _config$workspaceConf === void 0 ? void 0 : _config$workspaceConf.setExtension(_workspace().WorkspaceAspect.id, {
1678
1384
  defaultScope: scopeName
@@ -1684,10 +1390,8 @@ the following envs are used in this workspace: ${availableEnvs.join(', ')}`);
1684
1390
  dir: _path2().default.dirname(config.workspaceConfig.path)
1685
1391
  }));
1686
1392
  }
1687
-
1688
1393
  async addSpecificComponentConfig(id, aspectId, config = {}, shouldMergeWithExisting = false) {
1689
1394
  const componentConfigFile = await this.componentConfigFile(id);
1690
-
1691
1395
  if (componentConfigFile) {
1692
1396
  await componentConfigFile.addAspect(aspectId, config, this.resolveComponentId.bind(this), shouldMergeWithExisting);
1693
1397
  await componentConfigFile.write({
@@ -1697,10 +1401,8 @@ the following envs are used in this workspace: ${availableEnvs.join(', ')}`);
1697
1401
  this.bitMap.addComponentConfig(id, aspectId, config, shouldMergeWithExisting);
1698
1402
  }
1699
1403
  }
1700
-
1701
1404
  async removeSpecificComponentConfig(id, aspectId, markWithMinusIfNotExist) {
1702
1405
  const componentConfigFile = await this.componentConfigFile(id);
1703
-
1704
1406
  if (componentConfigFile) {
1705
1407
  await componentConfigFile.removeAspect(aspectId, markWithMinusIfNotExist, this.resolveComponentId.bind(this));
1706
1408
  await componentConfigFile.write({
@@ -1710,72 +1412,57 @@ the following envs are used in this workspace: ${availableEnvs.join(', ')}`);
1710
1412
  this.bitMap.removeComponentConfig(id, aspectId, markWithMinusIfNotExist);
1711
1413
  }
1712
1414
  }
1713
-
1714
1415
  async getAspectIdFromConfig(componentId, aspectIdStr, ignoreAspectVersion = false) {
1715
1416
  const aspectId = await this.resolveComponentId(aspectIdStr);
1716
1417
  const componentConfigFile = await this.componentConfigFile(componentId);
1717
-
1718
1418
  if (componentConfigFile) {
1719
1419
  const aspectEntry = componentConfigFile.aspects.find(aspectId, ignoreAspectVersion);
1720
1420
  return aspectEntry === null || aspectEntry === void 0 ? void 0 : aspectEntry.id.toString();
1721
1421
  }
1722
-
1723
1422
  return this.bitMap.getAspectIdFromConfig(componentId, aspectId, ignoreAspectVersion);
1724
1423
  }
1725
-
1726
1424
  async getSpecificComponentConfig(id, aspectId) {
1727
1425
  var _this$bitMap$getBitma;
1728
-
1729
1426
  const componentConfigFile = await this.componentConfigFile(id);
1730
-
1731
1427
  if (componentConfigFile) {
1732
1428
  var _componentConfigFile$2;
1733
-
1734
1429
  return (_componentConfigFile$2 = componentConfigFile.aspects.get(aspectId)) === null || _componentConfigFile$2 === void 0 ? void 0 : _componentConfigFile$2.config;
1735
1430
  }
1736
-
1737
1431
  return (_this$bitMap$getBitma = this.bitMap.getBitmapEntry(id, {
1738
1432
  ignoreVersion: true
1739
1433
  }).config) === null || _this$bitMap$getBitma === void 0 ? void 0 : _this$bitMap$getBitma[aspectId];
1740
1434
  }
1435
+
1741
1436
  /**
1742
1437
  * This will mutate the entries with extensionId prop to have resolved legacy id
1743
1438
  * This should be worked on the extension data list not the new aspect list
1744
1439
  * @param extensionList
1745
1440
  */
1746
-
1747
-
1748
1441
  async resolveExtensionListIds(extensionList) {
1749
1442
  const promises = extensionList.map(async entry => {
1750
1443
  if (entry.extensionId) {
1751
1444
  const id = await this.resolveComponentId(entry.extensionId);
1752
1445
  entry.extensionId = id._legacy;
1753
1446
  }
1754
-
1755
1447
  return entry;
1756
1448
  });
1757
1449
  await Promise.all(promises);
1758
1450
  return extensionList;
1759
1451
  }
1760
-
1761
1452
  isVendorComponentByComponentDir(relativeComponentDir) {
1762
1453
  var _this$config$vendor;
1763
-
1764
1454
  const vendorDir = ((_this$config$vendor = this.config.vendor) === null || _this$config$vendor === void 0 ? void 0 : _this$config$vendor.directory) || DEFAULT_VENDOR_DIR;
1765
-
1766
1455
  if ((0, _utils().pathIsInside)(relativeComponentDir, vendorDir)) {
1767
1456
  return true;
1768
- } // TODO: implement
1769
-
1770
-
1457
+ }
1458
+ // TODO: implement
1771
1459
  return false;
1772
1460
  }
1461
+
1773
1462
  /**
1774
1463
  * return the component config from its folder (component.json)
1775
1464
  * @param componentId
1776
1465
  */
1777
-
1778
-
1779
1466
  async componentConfigFile(id) {
1780
1467
  const relativeComponentDir = this.componentDir(id, {
1781
1468
  ignoreVersion: true
@@ -1784,41 +1471,34 @@ the following envs are used in this workspace: ${availableEnvs.join(', ')}`);
1784
1471
  });
1785
1472
  return this.componentConfigFileFromComponentDirAndName(relativeComponentDir, id.fullName);
1786
1473
  }
1474
+
1787
1475
  /**
1788
1476
  * @param componentPath can be relative or absolute. supports Linux and Windows
1789
1477
  */
1790
-
1791
-
1792
1478
  async getComponentIdByPath(componentPath) {
1793
1479
  const relativePath = _path2().default.isAbsolute(componentPath) ? _path2().default.relative(this.path, componentPath) : componentPath;
1794
1480
  const linuxPath = (0, _path().pathNormalizeToLinux)(relativePath);
1795
1481
  const bitId = this.consumer.bitMap.getComponentIdByPath(linuxPath);
1796
-
1797
1482
  if (bitId) {
1798
1483
  return this.resolveComponentId(bitId);
1799
1484
  }
1800
-
1801
1485
  return undefined;
1802
1486
  }
1803
-
1804
1487
  async componentConfigFileFromComponentDirAndName(relativeComponentDir, name) {
1805
1488
  let componentConfigFile;
1806
-
1807
1489
  if (relativeComponentDir) {
1808
1490
  const absComponentDir = this.componentDirToAbsolute(relativeComponentDir);
1809
1491
  const defaultScopeFromVariantsOrWs = await this.componentDefaultScopeFromComponentDirAndNameWithoutConfigFile(relativeComponentDir, name);
1810
1492
  componentConfigFile = await _componentConfigFile().ComponentConfigFile.load(absComponentDir, this.createAspectList.bind(this), defaultScopeFromVariantsOrWs);
1811
1493
  }
1812
-
1813
1494
  return componentConfigFile;
1814
1495
  }
1815
-
1816
1496
  async getAspectsGraphWithoutCore(components, isAspect) {
1817
1497
  const ids = components.map(component => component.id._legacy);
1818
1498
  const coreAspectsStringIds = this.aspectLoader.getCoreAspectIds();
1819
1499
  const coreAspectsComponentIds = coreAspectsStringIds.map(id => _legacyBitId().BitId.parse(id, true));
1820
-
1821
- const coreAspectsBitIds = _bitId().BitIds.fromArray(coreAspectsComponentIds.map(id => id.changeScope(null))); // const aspectsIds = components.reduce((acc, curr) => {
1500
+ const coreAspectsBitIds = _bitId().BitIds.fromArray(coreAspectsComponentIds.map(id => id.changeScope(null)));
1501
+ // const aspectsIds = components.reduce((acc, curr) => {
1822
1502
  // const currIds = curr.state.aspects.ids;
1823
1503
  // acc = acc.concat(currIds);
1824
1504
  // return acc;
@@ -1829,22 +1509,20 @@ the following envs are used in this workspace: ${availableEnvs.join(', ')}`);
1829
1509
  // Object.assign(acc, currMap);
1830
1510
  // return acc;
1831
1511
  // }, {});
1512
+
1832
1513
  // const depsWhichAreNotAspects = difference(Object.keys(otherDependenciesMap), aspectsIds);
1833
1514
  // const depsWhichAreNotAspectsBitIds = depsWhichAreNotAspects.map((strId) => otherDependenciesMap[strId]);
1834
1515
  // We only want to load into the graph components which are aspects and not regular dependencies
1835
1516
  // 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
1836
1517
  // TODO: @gilad it causes many issues we need to find a better solution. removed for now.
1837
-
1838
-
1839
1518
  const ignoredIds = coreAspectsBitIds.concat([]);
1840
1519
  return this.buildOneGraphForComponents(ids, _bitId().BitIds.fromArray(ignoredIds), isAspect);
1841
1520
  }
1521
+
1842
1522
  /**
1843
1523
  * load aspects from the workspace and if not exists in the workspace, load from the scope.
1844
1524
  * keep in mind that the graph may have circles.
1845
1525
  */
1846
-
1847
-
1848
1526
  async loadAspects(ids = [], throwOnError = false, neededFor) {
1849
1527
  // generate a random callId to be able to identify the call from the logs
1850
1528
  const callId = Math.floor(Math.random() * 1000);
@@ -1858,7 +1536,6 @@ needed-for: ${neededFor || '<unknown>'}`);
1858
1536
  const idsWithoutCore = (0, _lodash().difference)(notLoadedIds, coreAspectsStringIds);
1859
1537
  const componentIds = await this.resolveMultipleComponentIds(idsWithoutCore);
1860
1538
  const components = await this.importAndGetAspects(componentIds);
1861
-
1862
1539
  const isAspect = async bitId => {
1863
1540
  const id = await this.resolveComponentId(bitId);
1864
1541
  const component = await this.get(id);
@@ -1866,10 +1543,8 @@ needed-for: ${neededFor || '<unknown>'}`);
1866
1543
  const isUsingAspectEnv = this.envs.isUsingAspectEnv(component);
1867
1544
  const isUsingEnvEnv = this.envs.isUsingEnvEnv(component);
1868
1545
  const isValidAspect = isUsingAspectEnv || isUsingEnvEnv;
1869
-
1870
1546
  if (!isValidAspect && idsWithoutCore.includes(component.id.toString())) {
1871
1547
  const err = new (_incorrectEnvAspect().IncorrectEnvAspect)(component.id.toString(), data.type, data.id);
1872
-
1873
1548
  if (data.id === _envs().DEFAULT_ENV) {
1874
1549
  // when cloning a project, or when the node-modules dir is deleted, nothing works and all
1875
1550
  // components are default to the DEFAULT_ENV, which is node-env. we must allow "bit
@@ -1879,10 +1554,8 @@ needed-for: ${neededFor || '<unknown>'}`);
1879
1554
  throw err;
1880
1555
  }
1881
1556
  }
1882
-
1883
1557
  return isValidAspect;
1884
1558
  };
1885
-
1886
1559
  const graph = await this.getAspectsGraphWithoutCore(components, isAspect);
1887
1560
  const idsStr = graph.nodes();
1888
1561
  this.logger.debug(`${loggerPrefix} found ${idsStr.length} aspects in the aspects-graph`);
@@ -1901,10 +1574,10 @@ needed-for: ${neededFor || '<unknown>'}`);
1901
1574
  if (this.aspectLoader.isValidAspect(manifest)) return undefined;
1902
1575
  return index;
1903
1576
  }));
1904
- const workspaceManifestsIds = (0, _lodash().compact)(workspaceManifests.map(m => m.id)); // We are grouping the scope aspects by whether they are envs of something of the list or not
1577
+ const workspaceManifestsIds = (0, _lodash().compact)(workspaceManifests.map(m => m.id));
1578
+ // We are grouping the scope aspects by whether they are envs of something of the list or not
1905
1579
  // if yes, we want to load them first
1906
1580
  // the rest we will load together with the workspace aspects
1907
-
1908
1581
  const scopeIdsGrouped = await this.scope.groupAspectIdsByEnvOfTheList(scopeIds);
1909
1582
  const scopeEnvsManifestsIds = scopeIdsGrouped.envs && scopeIdsGrouped.envs.length ? await this.scope.loadAspects(scopeIdsGrouped.envs, throwOnError, 'workspace.loadAspects loading scope aspects') : [];
1910
1583
  const {
@@ -1915,39 +1588,35 @@ needed-for: ${neededFor || '<unknown>'}`);
1915
1588
  manifests: []
1916
1589
  };
1917
1590
  const scopeOtherManifestsIds = (0, _lodash().compact)(scopeOtherManifests.map(m => m.id));
1918
- await this.aspectLoader.loadExtensionsByManifests([...scopeOtherManifests, ...workspaceManifests], throwOnError); // Try require components for potential plugins
1919
-
1591
+ await this.aspectLoader.loadExtensionsByManifests([...scopeOtherManifests, ...workspaceManifests], throwOnError);
1592
+ // Try require components for potential plugins
1920
1593
  const pluginsWorkspaceComps = potentialPluginsIndexes.map(index => {
1921
1594
  return workspaceComps[index];
1922
- }); // Do the require again now that the plugins defs already registered
1923
-
1595
+ });
1596
+ // Do the require again now that the plugins defs already registered
1924
1597
  const pluginsWorkspaceAspects = await this.requireComponents(pluginsWorkspaceComps);
1925
1598
  const pluginsWorkspaceManifests = await this.aspectLoader.getManifestsFromRequireableExtensions(pluginsWorkspaceAspects, throwOnError);
1926
1599
  await this.aspectLoader.loadExtensionsByManifests(pluginsWorkspaceManifests, throwOnError);
1927
1600
  this.logger.debug(`${loggerPrefix} finish loading aspects`);
1928
1601
  return (0, _lodash().compact)(scopeEnvsManifestsIds.concat(scopeOtherManifestsIds).concat(workspaceManifestsIds));
1929
1602
  }
1603
+
1930
1604
  /**
1931
1605
  * Note - this gets called from Harmony only.
1932
1606
  * returns one graph that includes all dependencies types. each edge has a label of the dependency
1933
1607
  * type. the nodes content is the Component object.
1934
1608
  */
1935
-
1936
-
1937
1609
  async buildOneGraphForComponents(ids, ignoreIds, shouldLoadFunc, shouldThrowOnMissingDep = true) {
1938
1610
  const graphFromFsBuilder = new (_buildGraphFromFs().GraphFromFsBuilder)(this, this.logger, ignoreIds, shouldLoadFunc, shouldThrowOnMissingDep);
1939
1611
  return graphFromFsBuilder.buildGraph(ids);
1940
1612
  }
1941
-
1942
1613
  async resolveAspects(runtimeName, componentIds, opts) {
1943
1614
  this.logger.debug(`workspace resolveAspects, runtimeName: ${runtimeName}, componentIds: ${componentIds}`);
1944
1615
  const defaultOpts = {
1945
1616
  excludeCore: false,
1946
1617
  requestedOnly: false
1947
1618
  };
1948
-
1949
1619
  const mergedOpts = _objectSpread(_objectSpread({}, defaultOpts), opts);
1950
-
1951
1620
  let missingPaths = false;
1952
1621
  const stringIds = [];
1953
1622
  const idsToResolve = componentIds ? componentIds.map(id => id.toString()) : this.harmony.extensionsIds;
@@ -1961,15 +1630,12 @@ needed-for: ${neededFor || '<unknown>'}`);
1961
1630
  const wsComponents = await this.getMany(workspaceIds);
1962
1631
  const aspectDefs = await this.aspectLoader.resolveAspects(wsComponents, async component => {
1963
1632
  const compStringId = component.id._legacy.toString();
1964
-
1965
1633
  stringIds.push(compStringId);
1966
1634
  const localPath = this.getComponentPackagePath(component);
1967
1635
  const isExist = await _fsExtra().default.pathExists(localPath);
1968
-
1969
1636
  if (!isExist) {
1970
1637
  missingPaths = true;
1971
1638
  }
1972
-
1973
1639
  const runtimePath = runtimeName ? await this.aspectLoader.getRuntimePath(component, localPath, runtimeName) : null;
1974
1640
  this.logger.debug(`workspace resolveAspects, resolving id: ${compStringId}, localPath: ${localPath}, runtimePath: ${runtimePath}`);
1975
1641
  return {
@@ -1978,56 +1644,46 @@ needed-for: ${neededFor || '<unknown>'}`);
1978
1644
  };
1979
1645
  });
1980
1646
  let scopeAspectDefs = [];
1981
-
1982
1647
  if (scopeIds.length) {
1983
1648
  scopeAspectDefs = await this.scope.resolveAspects(runtimeName, scopeIds, mergedOpts);
1984
1649
  }
1985
-
1986
1650
  let coreAspectDefs = await Promise.all(coreAspectsIds.map(async coreId => {
1987
1651
  const rawDef = await (0, _aspectLoader().getAspectDef)(coreId, runtimeName);
1988
1652
  return this.aspectLoader.loadDefinition(rawDef);
1989
- })); // due to lack of workspace and scope runtimes. TODO: fix after adding them.
1653
+ }));
1990
1654
 
1655
+ // due to lack of workspace and scope runtimes. TODO: fix after adding them.
1991
1656
  if (runtimeName) {
1992
1657
  coreAspectDefs = coreAspectDefs.filter(coreAspect => {
1993
1658
  return coreAspect.runtimePath;
1994
1659
  });
1995
1660
  }
1996
-
1997
1661
  if (missingPaths) {
1998
1662
  await (0, _consumer().link)(stringIds, false);
1999
1663
  }
2000
-
2001
1664
  const allDefs = aspectDefs.concat(coreAspectDefs).concat(scopeAspectDefs);
2002
1665
  const ids = idsToResolve.map(idStr => _component().ComponentID.fromString(idStr).toStringWithoutVersion());
2003
1666
  const afterExclusion = mergedOpts.excludeCore ? allDefs.filter(def => {
2004
1667
  const isCore = coreAspectDefs.find(coreId => def.getId === coreId.getId);
2005
-
2006
1668
  const id = _component().ComponentID.fromString(def.getId || '');
2007
-
2008
1669
  const isTarget = ids.includes(id.toStringWithoutVersion());
2009
1670
  if (isTarget) return true;
2010
1671
  return !isCore;
2011
1672
  }) : allDefs;
2012
1673
  const uniqDefs = (0, _lodash().uniqBy)(afterExclusion, def => `${def.aspectPath}-${def.runtimePath}`);
2013
1674
  let defs = uniqDefs;
2014
-
2015
1675
  if (runtimeName) {
2016
1676
  defs = defs.filter(def => def.runtimePath);
2017
1677
  }
2018
-
2019
1678
  if (componentIds && componentIds.length && mergedOpts.requestedOnly) {
2020
1679
  const componentIdsString = componentIds.map(id => id.toString());
2021
1680
  defs = defs.filter(def => {
2022
1681
  var _def$component;
2023
-
2024
1682
  return def.id && componentIdsString.includes(def.id) || def.component && componentIdsString.includes((_def$component = def.component) === null || _def$component === void 0 ? void 0 : _def$component.id.toString());
2025
1683
  });
2026
1684
  }
2027
-
2028
1685
  return defs;
2029
1686
  }
2030
-
2031
1687
  async groupIdsByWorkspaceAndScope(ids) {
2032
1688
  const workspaceIds = [];
2033
1689
  const scopeIds = [];
@@ -2040,7 +1696,6 @@ needed-for: ${neededFor || '<unknown>'}`);
2040
1696
  scopeIds
2041
1697
  };
2042
1698
  }
2043
-
2044
1699
  async groupComponentsByWorkspaceAndScope(components) {
2045
1700
  const workspaceComps = [];
2046
1701
  const scopeComps = [];
@@ -2053,21 +1708,19 @@ needed-for: ${neededFor || '<unknown>'}`);
2053
1708
  scopeComps
2054
1709
  };
2055
1710
  }
1711
+
2056
1712
  /**
2057
1713
  * Load all unloaded extensions from a list
2058
1714
  * @param extensions list of extensions with config to load
2059
1715
  */
2060
-
2061
-
2062
1716
  async loadExtensions(extensions, originatedFrom, throwOnError = false) {
2063
1717
  const extensionsIdsP = extensions.map(async extensionEntry => {
2064
1718
  // Core extension
2065
1719
  if (!extensionEntry.extensionId) {
2066
1720
  return extensionEntry.stringId;
2067
1721
  }
2068
-
2069
- const id = await this.resolveComponentId(extensionEntry.extensionId); // return this.resolveComponentId(extensionEntry.extensionId);
2070
-
1722
+ const id = await this.resolveComponentId(extensionEntry.extensionId);
1723
+ // return this.resolveComponentId(extensionEntry.extensionId);
2071
1724
  return id.toString();
2072
1725
  });
2073
1726
  const extensionsIds = await Promise.all(extensionsIdsP);
@@ -2076,31 +1729,27 @@ needed-for: ${neededFor || '<unknown>'}`);
2076
1729
  if (!extensionsToLoad.length) return;
2077
1730
  await this.loadAspects(extensionsToLoad, throwOnError, originatedFrom === null || originatedFrom === void 0 ? void 0 : originatedFrom.toString());
2078
1731
  }
1732
+
2079
1733
  /**
2080
1734
  * Provides a cache folder, unique per key.
2081
1735
  * Return value may be undefined, if workspace folder is unconventional (bare-scope, no node_modules, etc)
2082
1736
  */
2083
-
2084
-
2085
1737
  getTempDir(
2086
1738
  /*
2087
1739
  * unique key, i.e. aspect or component id
2088
1740
  */
2089
1741
  id) {
2090
1742
  const PREFIX = 'bit';
1743
+ const cacheDir = _path2().default.join(this.modulesPath, '.cache', PREFIX, id);
2091
1744
 
2092
- const cacheDir = _path2().default.join(this.modulesPath, '.cache', PREFIX, id); // maybe should also check it's a folder and has write permissions
2093
-
2094
-
1745
+ // maybe should also check it's a folder and has write permissions
2095
1746
  if (!_fsExtra().default.existsSync(cacheDir)) {
2096
1747
  _fsExtra().default.mkdirSync(cacheDir, {
2097
1748
  recursive: true
2098
1749
  });
2099
1750
  }
2100
-
2101
1751
  return cacheDir;
2102
1752
  }
2103
-
2104
1753
  async requireComponents(components) {
2105
1754
  let missingPaths = false;
2106
1755
  const stringIds = [];
@@ -2108,101 +1757,87 @@ needed-for: ${neededFor || '<unknown>'}`);
2108
1757
  stringIds.push(component.id._legacy.toString());
2109
1758
  const localPath = this.getComponentPackagePath(component);
2110
1759
  const isExist = await _fsExtra().default.pathExists(localPath);
2111
-
2112
1760
  if (!isExist) {
2113
1761
  missingPaths = true;
2114
1762
  }
2115
-
2116
1763
  const requireFunc = async () => {
2117
1764
  const plugins = this.aspectLoader.getPlugins(component, localPath);
2118
-
2119
1765
  if (plugins.has()) {
2120
1766
  return plugins.load(_cli().MainRuntime.name);
2121
- } // eslint-disable-next-line global-require, import/no-dynamic-require
2122
-
2123
-
2124
- const aspect = require(localPath); // require aspect runtimes
2125
-
2126
-
2127
- const runtimePath = await this.aspectLoader.getRuntimePath(component, localPath, _cli().MainRuntime.name); // eslint-disable-next-line global-require, import/no-dynamic-require
1767
+ }
2128
1768
 
1769
+ // eslint-disable-next-line global-require, import/no-dynamic-require
1770
+ const aspect = require(localPath);
1771
+ // require aspect runtimes
1772
+ const runtimePath = await this.aspectLoader.getRuntimePath(component, localPath, _cli().MainRuntime.name);
1773
+ // eslint-disable-next-line global-require, import/no-dynamic-require
2129
1774
  if (runtimePath) require(runtimePath);
2130
1775
  return aspect;
2131
1776
  };
2132
-
2133
1777
  return new (_harmonyModules().RequireableComponent)(component, requireFunc);
2134
1778
  });
2135
- const resolved = await Promise.all(resolveP); // Make sure to link missing components
2136
-
1779
+ const resolved = await Promise.all(resolveP);
1780
+ // Make sure to link missing components
2137
1781
  if (missingPaths) {
2138
1782
  await (0, _consumer().link)(stringIds, false);
2139
1783
  }
2140
-
2141
1784
  return resolved;
2142
1785
  }
1786
+
2143
1787
  /**
2144
1788
  * whether a scope is hosted by Bit cloud.
2145
1789
  * otherwise, it is self-hosted
2146
1790
  */
2147
-
2148
-
2149
1791
  async isHostedByBit(scopeName) {
2150
1792
  // TODO: once scope create a new API for this, replace it with the new one
2151
1793
  const remotes = await this.scope._legacyRemotes();
2152
1794
  return remotes.isHub(scopeName);
2153
1795
  }
1796
+
2154
1797
  /**
2155
1798
  * same as `this.importAndGetMany()` with a specific error handling of ComponentNotFound
2156
1799
  */
2157
-
2158
-
2159
1800
  async importAndGetAspects(componentIds) {
2160
1801
  try {
2161
1802
  return await this.importAndGetMany(componentIds);
2162
1803
  } catch (err) {
2163
1804
  if (err instanceof _exceptions().ComponentNotFound) {
2164
1805
  var _config$workspaceConf3;
2165
-
2166
1806
  const config = this.harmony.get('teambit.harmony/config');
2167
1807
  const configStr = JSON.stringify(((_config$workspaceConf3 = config.workspaceConfig) === null || _config$workspaceConf3 === void 0 ? void 0 : _config$workspaceConf3.raw) || {});
2168
-
2169
1808
  if (configStr.includes(err.id)) {
2170
1809
  throw new (_bitError().BitError)(`error: a component "${err.id}" was not found
2171
1810
  your workspace.jsonc has this component-id set. you might want to remove/change it.`);
2172
1811
  }
2173
1812
  }
2174
-
2175
1813
  throw err;
2176
1814
  }
2177
1815
  }
1816
+
2178
1817
  /**
2179
1818
  * this should be rarely in-use.
2180
1819
  * it's currently used by watch extension as a quick workaround to load .bitmap and the components
2181
1820
  */
2182
-
2183
-
2184
1821
  async _reloadConsumer() {
2185
1822
  this.consumer = await (0, _consumer2().loadConsumer)(this.path, true);
2186
1823
  this.clearCache();
2187
1824
  }
2188
-
2189
1825
  getComponentPackagePath(component) {
2190
1826
  const relativePath = this.dependencyResolver.getRuntimeModulePath(component);
2191
1827
  return _path2().default.join(this.path, relativePath);
2192
- } // TODO: should we return here the dir as it defined (aka components) or with /{name} prefix (as it used in legacy)
2193
-
1828
+ }
2194
1829
 
1830
+ // TODO: should we return here the dir as it defined (aka components) or with /{name} prefix (as it used in legacy)
2195
1831
  get defaultDirectory() {
2196
1832
  return this.config.defaultDirectory;
2197
1833
  }
2198
-
2199
1834
  get legacyDefaultDirectory() {
2200
1835
  if (this.defaultDirectory && !this.defaultDirectory.includes('{name}')) {
2201
1836
  return `${this.defaultDirectory}/{name}`;
2202
1837
  }
2203
-
2204
1838
  return this.defaultDirectory;
2205
1839
  }
1840
+
2206
1841
  /**
2207
1842
  * Transform the id to ComponentId and get the exact id as appear in bitmap
2208
1843
  *
@@ -2210,51 +1845,44 @@ your workspace.jsonc has this component-id set. you might want to remove/change
2210
1845
  * @returns {Promise<ComponentID>}
2211
1846
  * @memberof Workspace
2212
1847
  */
2213
-
2214
-
2215
1848
  async resolveComponentId(id) {
2216
1849
  const getDefaultScope = async (bitId, bitMapOptions) => {
2217
1850
  if (bitId.scope) {
2218
1851
  return bitId.scope;
2219
1852
  }
2220
-
2221
1853
  const relativeComponentDir = this.componentDirFromLegacyId(bitId, bitMapOptions, {
2222
1854
  relative: true
2223
1855
  });
2224
1856
  const defaultScope = await this.componentDefaultScopeFromComponentDirAndName(relativeComponentDir, bitId.toStringWithoutScopeAndVersion());
2225
1857
  return defaultScope;
2226
- }; // This is required in case where you have in your workspace a component with the same name as a core aspect
1858
+ };
1859
+
1860
+ // This is required in case where you have in your workspace a component with the same name as a core aspect
2227
1861
  // let's say you have component called react-native (which is eventually my-org.my-scope/react-native)
2228
1862
  // and you set teambit.react/react-native as your env
2229
1863
  // bit will get here with the string teambit.react/react-native and will try to resolve it from the workspace
2230
1864
  // during this it will find the my-org.my-scope/react-native which is incorrect as the core one doesn't exist in the
2231
1865
  // workspace
2232
-
2233
-
2234
1866
  if (this.aspectLoader.isCoreAspect(id.toString())) {
2235
1867
  return _component().ComponentID.fromString(id.toString());
2236
1868
  }
2237
-
2238
1869
  let legacyId = this.consumer.getParsedIdIfExist(id.toString(), true, true);
2239
-
2240
1870
  if (legacyId) {
2241
- const defaultScope = await getDefaultScope(legacyId); // only reason to strip the scopeName from the given id is when this id has the defaultScope, because .bitmap
1871
+ const defaultScope = await getDefaultScope(legacyId);
1872
+ // only reason to strip the scopeName from the given id is when this id has the defaultScope, because .bitmap
2242
1873
  // doesn't have the defaultScope. if the given id doesn't have scope or has scope different than the default,
2243
1874
  // then don't ignore it. search with the scope-name.
2244
-
2245
1875
  const shouldSearchWithoutScopeInProvidedId = id.toString().startsWith(`${defaultScope}/`);
2246
1876
  legacyId = this.consumer.getParsedIdIfExist(id.toString(), true, shouldSearchWithoutScopeInProvidedId);
2247
-
2248
1877
  if (legacyId) {
2249
1878
  return _component().ComponentID.fromLegacy(legacyId, defaultScope);
2250
1879
  }
2251
1880
  }
2252
-
2253
1881
  try {
2254
1882
  const idWithVersion = id.toString();
2255
1883
  const [idWithoutVersion, version] = id.toString().split('@');
2256
-
2257
- const _bitMapId = this.consumer.getParsedIdIfExist(idWithoutVersion, false, true); // This logic is very specific, and very sensitive for changes please do not touch this without consulting with @ran or @gilad
1884
+ const _bitMapId = this.consumer.getParsedIdIfExist(idWithoutVersion, false, true);
1885
+ // This logic is very specific, and very sensitive for changes please do not touch this without consulting with @ran or @gilad
2258
1886
  // example (partial list) cases which should be handled are:
2259
1887
  // use case 1 - ws component provided with the local scope name:
2260
1888
  // source id : my-scope1/my-name1
@@ -2280,55 +1908,43 @@ your workspace.jsonc has this component-id set. you might want to remove/change
2280
1908
  // local scope name : my-scope1
2281
1909
  // scope content : my-scope2/my-name1
2282
1910
  // expected result : my-scope2/my-name1 (get the name from the bitmap)
2283
- // No entry in bitmap at all, search for the original input id
2284
-
2285
1911
 
1912
+ // No entry in bitmap at all, search for the original input id
2286
1913
  if (!_bitMapId) {
2287
1914
  return await this.scope.resolveComponentId(id.toString());
2288
1915
  }
2289
-
2290
1916
  const _bitMapIdWithoutVersion = _bitMapId.toStringWithoutVersion();
2291
-
2292
- const _bitMapIdWithVersion = _bitMapId.changeVersion(version).toString(); // The id in the bitmap has prefix which is not in the source id - the bitmap entry has scope name
1917
+ const _bitMapIdWithVersion = _bitMapId.changeVersion(version).toString();
1918
+ // The id in the bitmap has prefix which is not in the source id - the bitmap entry has scope name
2293
1919
  // Handle use case 4
2294
-
2295
-
2296
1920
  if (_bitMapIdWithoutVersion.endsWith(idWithoutVersion) && _bitMapIdWithoutVersion !== idWithoutVersion) {
2297
1921
  return await this.scope.resolveComponentId(_bitMapIdWithVersion);
2298
- } // Handle case when I tagged the component locally with a default scope which is not the local scope
1922
+ }
1923
+ // Handle case when I tagged the component locally with a default scope which is not the local scope
2299
1924
  // but not exported it yet
2300
1925
  // now i'm trying to load it with source id contain the default scope prefix
2301
1926
  // we want to get it from the local first before assuming it's something coming from outside
2302
-
2303
-
2304
1927
  if (!_bitMapId.scope) {
2305
1928
  const defaultScopeForBitmapId = await getDefaultScope(_bitMapId, {
2306
1929
  ignoreVersion: true
2307
1930
  });
2308
-
2309
1931
  const getFromBitmapAddDefaultScope = () => {
2310
1932
  let _bitmapIdWithVersionForSource = _bitMapId;
2311
-
2312
1933
  if (version) {
2313
1934
  _bitmapIdWithVersionForSource = _bitMapId.changeVersion(version);
2314
1935
  }
2315
-
2316
1936
  return _component().ComponentID.fromLegacy(_bitmapIdWithVersionForSource, defaultScopeForBitmapId);
2317
- }; // a case when the given id contains the default scope
2318
-
2319
-
1937
+ };
1938
+ // a case when the given id contains the default scope
2320
1939
  if (idWithVersion.startsWith(`${defaultScopeForBitmapId}/${_bitMapIdWithoutVersion}`)) {
2321
1940
  return getFromBitmapAddDefaultScope();
2322
- } // a case when the given id does not contain the default scope
2323
-
2324
-
1941
+ }
1942
+ // a case when the given id does not contain the default scope
2325
1943
  const fromScope = await this.scope.resolveComponentId(idWithVersion);
2326
-
2327
1944
  if (!fromScope._legacy.hasScope()) {
2328
1945
  return getFromBitmapAddDefaultScope();
2329
1946
  }
2330
1947
  }
2331
-
2332
1948
  if (idWithoutVersion.endsWith(_bitMapIdWithoutVersion) && _bitMapIdWithoutVersion !== idWithoutVersion) {
2333
1949
  // The id in the bitmap doesn't have scope, the source id has scope
2334
1950
  // Handle use case 2 and use case 1
@@ -2336,24 +1952,22 @@ your workspace.jsonc has this component-id set. you might want to remove/change
2336
1952
  // Handle use case 1 - the provided id has scope name same as the local scope name
2337
1953
  // we want to send it as it appear in the bitmap
2338
1954
  return await this.scope.resolveComponentId(_bitMapIdWithVersion);
2339
- } // Handle use case 2 - the provided id has scope which is not the local scope
1955
+ }
1956
+ // Handle use case 2 - the provided id has scope which is not the local scope
2340
1957
  // we want to search by the source id
2341
-
2342
-
2343
1958
  return await this.scope.resolveComponentId(idWithVersion);
2344
- } // Handle use case 3
2345
-
2346
-
1959
+ }
1960
+ // Handle use case 3
2347
1961
  return await this.scope.resolveComponentId(idWithVersion);
2348
1962
  } catch (error) {
2349
1963
  legacyId = _legacyBitId().BitId.parse(id.toString(), true);
2350
1964
  return _component().ComponentID.fromLegacy(legacyId);
2351
1965
  }
2352
1966
  }
2353
-
2354
1967
  async resolveMultipleComponentIds(ids) {
2355
1968
  return Promise.all(ids.map(async id => this.resolveComponentId(id)));
2356
1969
  }
1970
+
2357
1971
  /**
2358
1972
  * This will mutate the original extensions list and resolve it's ids
2359
1973
  *
@@ -2361,14 +1975,13 @@ your workspace.jsonc has this component-id set. you might want to remove/change
2361
1975
  * @returns {Promise<void[]>}
2362
1976
  * @memberof Workspace
2363
1977
  */
2364
-
2365
-
2366
1978
  resolveExtensionsList(extensions) {
2367
1979
  const resolveMergedExtensionsP = extensions.map(async extensionEntry => {
2368
1980
  if (extensionEntry.extensionId) {
2369
1981
  // const hasVersion = extensionEntry.extensionId.hasVersion();
2370
1982
  // const useBitmapVersion = !hasVersion;
2371
1983
  // const resolvedId = await this.resolveComponentId(extensionEntry.extensionId, true, useBitmapVersion);
1984
+
2372
1985
  // Assuming extensionId always has scope - do not allow extension id without scope
2373
1986
  const resolvedId = await this.resolveComponentId(extensionEntry.extensionId);
2374
1987
  extensionEntry.extensionId = resolvedId._legacy;
@@ -2376,6 +1989,7 @@ your workspace.jsonc has this component-id set. you might want to remove/change
2376
1989
  });
2377
1990
  return Promise.all(resolveMergedExtensionsP);
2378
1991
  }
1992
+
2379
1993
  /**
2380
1994
  * This will mutate the original extensions list and make sure all extensions has the ids with the scope / default scope
2381
1995
  *
@@ -2383,25 +1997,21 @@ your workspace.jsonc has this component-id set. you might want to remove/change
2383
1997
  * @returns {Promise<void[]>}
2384
1998
  * @memberof Workspace
2385
1999
  */
2386
-
2387
-
2388
2000
  addDefaultScopeToExtensionsList(extensions) {
2389
2001
  const resolveMergedExtensionsP = extensions.map(async extensionEntry => {
2390
2002
  if (extensionEntry.extensionId && !extensionEntry.extensionId.hasScope()) {
2391
2003
  const componentId = _component().ComponentID.fromLegacy(extensionEntry.extensionId);
2392
-
2393
2004
  const defaultScope = await this.componentDefaultScope(componentId);
2394
2005
  extensionEntry.extensionId = extensionEntry.extensionId.changeScope(defaultScope);
2395
2006
  }
2396
2007
  });
2397
2008
  return Promise.all(resolveMergedExtensionsP);
2398
2009
  }
2010
+
2399
2011
  /**
2400
2012
  * configure an environment to the given components in the .bitmap file, this configuration overrides other, such as
2401
2013
  * overrides in workspace.jsonc.
2402
2014
  */
2403
-
2404
-
2405
2015
  async setEnvToComponents(envId, componentIds) {
2406
2016
  const envStrWithPossiblyVersion = await this.resolveEnvIdWithPotentialVersionForConfig(envId);
2407
2017
  const envIdStrNoVersion = envId.toStringWithoutVersion();
@@ -2414,56 +2024,46 @@ your workspace.jsonc has this component-id set. you might want to remove/change
2414
2024
  }));
2415
2025
  await this.bitMap.write();
2416
2026
  }
2027
+
2417
2028
  /**
2418
2029
  * helpful when a user provides an env-string to be set and this env has no version.
2419
2030
  * in the workspace config, a custom-env needs to be set with a version unless it's part of the workspace.
2420
2031
  * (inside envs/envs it's set without a version).
2421
2032
  */
2422
-
2423
-
2424
2033
  async resolveEnvIdWithPotentialVersionForConfig(envId) {
2425
2034
  var _found$extensionId;
2426
-
2427
2035
  const isCore = this.aspectLoader.isCoreAspect(envId.toStringWithoutVersion());
2428
2036
  const existsOnWorkspace = await this.hasId(envId);
2429
-
2430
2037
  if (isCore || existsOnWorkspace) {
2431
2038
  // the env needs to be without version
2432
2039
  return envId.toStringWithoutVersion();
2433
- } // the env must include a version
2434
-
2435
-
2040
+ }
2041
+ // the env must include a version
2436
2042
  if (envId.hasVersion()) {
2437
2043
  return envId.toString();
2438
2044
  }
2439
-
2440
2045
  const extensions = this.harmony.get('teambit.harmony/config').extensions;
2441
2046
  const found = extensions === null || extensions === void 0 ? void 0 : extensions.findExtension(envId.toString(), true);
2442
-
2443
2047
  if (found && (_found$extensionId = found.extensionId) !== null && _found$extensionId !== void 0 && _found$extensionId.version) {
2444
2048
  return found.extensionId.toString();
2445
2049
  }
2446
-
2447
2050
  const comps = await this.importAndGetMany([envId]);
2448
2051
  return comps[0].id.toString();
2449
2052
  }
2053
+
2450
2054
  /**
2451
2055
  * remove env configuration from the .bitmap file, so then other configuration, such as "variants" will take place
2452
2056
  */
2453
-
2454
-
2455
2057
  async unsetEnvFromComponents(ids) {
2456
2058
  const changed = [];
2457
2059
  const unchanged = [];
2458
2060
  await Promise.all(ids.map(async id => {
2459
2061
  const envsAspect = await this.getSpecificComponentConfig(id, _envs().EnvsAspect.id);
2460
2062
  const currentEnv = envsAspect && envsAspect !== _config().REMOVE_EXTENSION_SPECIAL_SIGN ? envsAspect.env : null;
2461
-
2462
2063
  if (!currentEnv) {
2463
2064
  unchanged.push(id);
2464
2065
  return;
2465
2066
  }
2466
-
2467
2067
  const currentEnvWithPotentialVersion = await this.getAspectIdFromConfig(id, currentEnv, true);
2468
2068
  await this.removeSpecificComponentConfig(id, currentEnvWithPotentialVersion || currentEnv, false);
2469
2069
  await this.removeSpecificComponentConfig(id, _envs().EnvsAspect.id, false);
@@ -2475,8 +2075,8 @@ your workspace.jsonc has this component-id set. you might want to remove/change
2475
2075
  unchanged
2476
2076
  };
2477
2077
  }
2478
-
2479
2078
  }
2079
+
2480
2080
  /**
2481
2081
  * this is a super hacky way to do it. problem is that loadAspect is running as onStart hook, where we don't
2482
2082
  * have the CLI fully loaded yet, so we can't get the command from the CLI aspect, we have to retrieve it from
@@ -2485,15 +2085,11 @@ your workspace.jsonc has this component-id set. you might want to remove/change
2485
2085
  * Bit loads (even bit --help), it'll fetch them and slow down everything.
2486
2086
  * instead, long-running commands and those that need the artifacts from the Version objects, should try to re-fetch.
2487
2087
  */
2488
-
2489
-
2490
2088
  exports.Workspace = Workspace;
2491
-
2492
2089
  function shouldReFetchUnBuiltVersion() {
2493
2090
  const commandsToReFetch = ['import'];
2494
2091
  return commandsToReFetch.includes(process.argv[2]);
2495
2092
  }
2496
-
2497
2093
  var _default = Workspace;
2498
2094
  exports.default = _default;
2499
2095