@teambit/workspace 1.0.123 → 1.0.125

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/workspace.js CHANGED
@@ -319,6 +319,13 @@ function _filter() {
319
319
  };
320
320
  return data;
321
321
  }
322
+ function _componentStatusLoader() {
323
+ const data = require("./workspace-component/component-status-loader");
324
+ _componentStatusLoader = function () {
325
+ return data;
326
+ };
327
+ return data;
328
+ }
322
329
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
323
330
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
324
331
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
@@ -367,7 +374,7 @@ class Workspace {
367
374
  /**
368
375
  * on component add slot.
369
376
  */
370
- onComponentAddSlot, onComponentRemoveSlot, onAspectsResolveSlot, onRootAspectAddedSlot, graphql, onBitmapChangeSlot) {
377
+ onComponentAddSlot, onComponentRemoveSlot, onAspectsResolveSlot, onRootAspectAddedSlot, graphql, onBitmapChangeSlot, onWorkspaceConfigChangeSlot) {
371
378
  this.pubsub = pubsub;
372
379
  this.config = config;
373
380
  this.consumer = consumer;
@@ -389,12 +396,14 @@ class Workspace {
389
396
  this.onRootAspectAddedSlot = onRootAspectAddedSlot;
390
397
  this.graphql = graphql;
391
398
  this.onBitmapChangeSlot = onBitmapChangeSlot;
399
+ this.onWorkspaceConfigChangeSlot = onWorkspaceConfigChangeSlot;
392
400
  _defineProperty(this, "warnedAboutMisconfiguredEnvs", []);
393
401
  // cache env-ids that have been errored about not having "env" type
394
402
  _defineProperty(this, "priority", true);
395
403
  _defineProperty(this, "owner", void 0);
396
404
  _defineProperty(this, "componentsScopeDirsMap", void 0);
397
405
  _defineProperty(this, "componentLoader", void 0);
406
+ _defineProperty(this, "componentStatusLoader", void 0);
398
407
  _defineProperty(this, "bitMap", void 0);
399
408
  /**
400
409
  * Indicate that we are now running installation process
@@ -427,6 +436,7 @@ class Workspace {
427
436
  });
428
437
  this.aspectsMerger = new (_aspectsMerger().AspectsMerger)(this, this.harmony);
429
438
  this.filter = new (_filter().Filter)(this);
439
+ this.componentStatusLoader = new (_componentStatusLoader().ComponentStatusLoader)(this);
430
440
  }
431
441
  validateConfig() {
432
442
  if (this.consumer.isLegacy) return;
@@ -470,6 +480,9 @@ class Workspace {
470
480
  this.onBitmapChangeSlot.register(OnBitmapChangeFunc);
471
481
  return this;
472
482
  }
483
+ registerOnWorkspaceConfigChange(onWorkspaceConfigChangeFunc) {
484
+ this.onWorkspaceConfigChangeSlot.register(onWorkspaceConfigChangeFunc);
485
+ }
473
486
  registerOnAspectsResolve(onAspectsResolveFunc) {
474
487
  this.onAspectsResolveSlot.register(onAspectsResolveFunc);
475
488
  return this;
@@ -491,10 +504,18 @@ class Workspace {
491
504
  get icon() {
492
505
  return this.config.icon;
493
506
  }
494
- async hasModifiedDependencies(component) {
507
+ async listAutoTagPendingComponentIds() {
495
508
  const componentsList = new (_componentsList().default)(this.consumer);
496
- const listAutoTagPendingComponents = await componentsList.listAutoTagPendingComponents();
497
- const isAutoTag = listAutoTagPendingComponents.find(consumerComponent => consumerComponent.id.isEqualWithoutVersion(component.id));
509
+ const modifiedComponents = (await this.modified()).map(c => c.id);
510
+ const newComponents = await componentsList.listNewComponents();
511
+ if (!modifiedComponents || !modifiedComponents.length) return [];
512
+ const autoTagPending = await this.consumer.listComponentsForAutoTagging(_componentId().ComponentIdList.fromArray(modifiedComponents));
513
+ const comps = autoTagPending.filter(autoTagComp => !newComponents.has(autoTagComp.componentId));
514
+ return comps.map(c => c.id);
515
+ }
516
+ async hasModifiedDependencies(component) {
517
+ const listAutoTagPendingComponents = await this.listAutoTagPendingComponentIds();
518
+ const isAutoTag = listAutoTagPendingComponents.find(id => id.isEqualWithoutVersion(component.id));
498
519
  if (isAutoTag) return true;
499
520
  return false;
500
521
  }
@@ -510,7 +531,7 @@ class Workspace {
510
531
  * provides status of all components in the workspace.
511
532
  */
512
533
  async getComponentStatus(component) {
513
- const status = await this.consumer.getComponentStatusById(component.id);
534
+ const status = await this.getComponentStatusById(component.id);
514
535
  const hasModifiedDependencies = await this.hasModifiedDependencies(component);
515
536
  return _componentStatus().ComponentStatus.fromLegacy(status, hasModifiedDependencies, component.isOutdated());
516
537
  }
@@ -599,9 +620,11 @@ class Workspace {
599
620
  /**
600
621
  * list all modified components in the workspace.
601
622
  */
602
- async modified() {
603
- const allComps = await this.list();
604
- const modifiedIncludeNulls = await (0, _pMapSeries().default)(allComps, async component => {
623
+ async modified(loadOpts) {
624
+ const {
625
+ components
626
+ } = await this.listWithInvalid(loadOpts);
627
+ const modifiedIncludeNulls = await (0, _pMapSeries().default)(components, async component => {
605
628
  const modified = await this.isModified(component);
606
629
  return modified ? component : null;
607
630
  });
@@ -847,6 +870,7 @@ it's possible that the version ${component.id.version} belong to ${idStr.split('
847
870
  this.logger.debug('clearing the workspace and scope caches');
848
871
  delete this._cachedListIds;
849
872
  this.componentLoader.clearCache();
873
+ this.componentStatusLoader.clearCache();
850
874
  await this.scope.clearCache();
851
875
  this.componentList = new (_componentsList().default)(this.consumer);
852
876
  this.componentDefaultScopeFromComponentDirAndNameWithoutConfigFileMemoized.clear();
@@ -854,10 +878,12 @@ it's possible that the version ${component.id.version} belong to ${idStr.split('
854
878
  clearAllComponentsCache() {
855
879
  this.componentLoader.clearCache();
856
880
  this.consumer.componentLoader.clearComponentsCache();
881
+ this.componentStatusLoader.clearCache();
857
882
  this.componentList = new (_componentsList().default)(this.consumer);
858
883
  }
859
884
  clearComponentCache(id) {
860
885
  this.componentLoader.clearComponentCache(id);
886
+ this.componentStatusLoader.clearOneComponentCache(id);
861
887
  this.consumer.clearOneComponentCache(id);
862
888
  this.componentList = new (_componentsList().default)(this.consumer);
863
889
  }
@@ -937,8 +963,7 @@ it's possible that the version ${component.id.version} belong to ${idStr.split('
937
963
  }
938
964
 
939
965
  /**
940
- * if needed, add a slot to let other aspects react to this event.
941
- * currently, the purpose is to reload the workspace config when it changes, so entries like "defaultScope" are updated.
966
+ * the purpose is mostly to reload the workspace config when it changes, so entries like "defaultScope" are updated.
942
967
  * it also updates the DependencyResolver config. I couldn't find a good way to update all aspects in workspace.jsonc.
943
968
  */
944
969
  async triggerOnWorkspaceConfigChange() {
@@ -953,6 +978,10 @@ it's possible that the version ${component.id.version} belong to ${idStr.split('
953
978
  const configOfDepResolverAspect = workspaceConfig.extensions.findExtension(_dependencyResolver().DependencyResolverAspect.id);
954
979
  if (configOfDepResolverAspect) this.dependencyResolver.setConfig(configOfDepResolverAspect.config);
955
980
  this.dependencyResolver.clearCache();
981
+ const onWorkspaceConfigChangeEntries = this.onWorkspaceConfigChangeSlot.toArray(); // e.g. [ [ 'teambit.bit/compiler', [Function: bound onComponentChange] ] ]
982
+ await (0, _pMapSeries().default)(onWorkspaceConfigChangeEntries, async ([, onWorkspaceConfigFunc]) => {
983
+ await onWorkspaceConfigFunc();
984
+ });
956
985
  }
957
986
  getState(id, hash) {
958
987
  return this.scope.getState(id, hash);
@@ -1407,7 +1436,7 @@ the following envs are used in this workspace: ${availableEnvs.join(', ')}`);
1407
1436
  }
1408
1437
  const consumerComp = component.state._consumer;
1409
1438
  if (typeof consumerComp._isModified === 'boolean') return consumerComp._isModified;
1410
- const componentStatus = await this.consumer.getComponentStatusById(component.id);
1439
+ const componentStatus = await this.getComponentStatusById(component.id);
1411
1440
  return componentStatus.modified === true;
1412
1441
  }
1413
1442
  async isModifiedOrNew(component) {
@@ -1995,6 +2024,12 @@ the following envs are used in this workspace: ${availableEnvs.join(', ')}`);
1995
2024
  }
1996
2025
  return undefined;
1997
2026
  }
2027
+ async getManyComponentsStatuses(ids) {
2028
+ return this.componentStatusLoader.getManyComponentsStatuses(ids);
2029
+ }
2030
+ async getComponentStatusById(id) {
2031
+ return this.componentStatusLoader.getComponentStatusById(id);
2032
+ }
1998
2033
  }
1999
2034
 
2000
2035
  /**