@teambit/workspace 0.0.529 → 0.0.530

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
@@ -409,7 +409,7 @@ class Workspace {
409
409
  /**
410
410
  * on component add slot.
411
411
  */
412
- onComponentAddSlot, onComponentRemoveSlot, graphql) {
412
+ onComponentAddSlot, onComponentRemoveSlot, onPreWatchSlot, graphql) {
413
413
  var _this$config;
414
414
 
415
415
  this.pubsub = pubsub;
@@ -429,6 +429,7 @@ class Workspace {
429
429
  this.envs = envs;
430
430
  this.onComponentAddSlot = onComponentAddSlot;
431
431
  this.onComponentRemoveSlot = onComponentRemoveSlot;
432
+ this.onPreWatchSlot = onPreWatchSlot;
432
433
  this.graphql = graphql;
433
434
  (0, _defineProperty2().default)(this, "priority", true);
434
435
  (0, _defineProperty2().default)(this, "owner", void 0);
@@ -488,6 +489,11 @@ class Workspace {
488
489
  this.onComponentRemoveSlot.register(onComponentRemoveFunc);
489
490
  return this;
490
491
  }
492
+
493
+ registerOnPreWatch(onPreWatchFunc) {
494
+ this.onPreWatchSlot.register(onPreWatchFunc);
495
+ return this;
496
+ }
491
497
  /**
492
498
  * name of the workspace as configured in either `workspace.json`.
493
499
  * defaults to workspace root directory name.
@@ -717,7 +723,7 @@ class Workspace {
717
723
  this.componentList = new (_componentsList().default)(this.consumer);
718
724
  }
719
725
 
720
- async triggerOnComponentChange(id, initiator) {
726
+ async triggerOnComponentChange(id, files, initiator) {
721
727
  const component = await this.get(id); // if a new file was added, upon component-load, its .bitmap entry is updated to include the
722
728
  // new file. write these changes to the .bitmap file so then other processes have access to
723
729
  // this new file. If the .bitmap wasn't change, it won't do anything.
@@ -727,7 +733,7 @@ class Workspace {
727
733
 
728
734
  const results = [];
729
735
  await (0, _pMapSeries().default)(onChangeEntries, async ([extension, onChangeFunc]) => {
730
- const onChangeResult = await onChangeFunc(component, initiator);
736
+ const onChangeResult = await onChangeFunc(component, files, initiator);
731
737
  results.push({
732
738
  extensionId: extension,
733
739
  results: onChangeResult
@@ -747,8 +753,9 @@ class Workspace {
747
753
  const onAddEntries = this.onComponentAddSlot.toArray(); // e.g. [ [ 'teambit.bit/compiler', [Function: bound onComponentChange] ] ]
748
754
 
749
755
  const results = [];
756
+ const files = component.state.filesystem.files.map(file => file.path);
750
757
  await (0, _pMapSeries().default)(onAddEntries, async ([extension, onAddFunc]) => {
751
- const onAddResult = await onAddFunc(component);
758
+ const onAddResult = await onAddFunc(component, files);
752
759
  results.push({
753
760
  extensionId: extension,
754
761
  results: onAddResult
@@ -947,6 +954,23 @@ class Workspace {
947
954
  }) {
948
955
  return this.componentDirFromLegacyId(componentId._legacy, bitMapOptions, options);
949
956
  }
957
+ /**
958
+ * component's files in the workspace are symlinked to the node_modules, and a package.json file is generated on that
959
+ * package directory to simulate a valid node package.
960
+ * @returns the package directory inside the node_module.
961
+ * by default the absolute path, unless `options.relative` was set
962
+ */
963
+
964
+
965
+ componentPackageDir(component, options = {
966
+ relative: false
967
+ }) {
968
+ const packageName = (0, _componentIdToPackageName().default)(component.state._consumer);
969
+
970
+ const packageDir = _path().default.join('node_modules', packageName);
971
+
972
+ return options.relative ? packageDir : this.consumer.toAbsolutePath(packageDir);
973
+ }
950
974
 
951
975
  componentDirFromLegacyId(bitId, bitMapOptions, options = {
952
976
  relative: false
@@ -1101,6 +1125,14 @@ class Workspace {
1101
1125
 
1102
1126
  return mergedExtensions;
1103
1127
  }
1128
+
1129
+ async triggerOnPreWatch(componentIds, watchOpts) {
1130
+ const components = await this.getMany(componentIds);
1131
+ const preWatchFunctions = this.onPreWatchSlot.values();
1132
+ await (0, _pMapSeries().default)(preWatchFunctions, async func => {
1133
+ await func(components, watchOpts);
1134
+ });
1135
+ }
1104
1136
  /**
1105
1137
  * This will mutate the entries with extensionId prop to have resolved legacy id
1106
1138
  * This should be worked on the extension data list not the new aspect list