@teambit/scope 1.0.106 → 1.0.108

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 (47) hide show
  1. package/clear-cache-action.ts +11 -0
  2. package/dist/get-scope-options.d.ts +1 -1
  3. package/dist/{preview-1703505948637.js → preview-1703647408454.js} +2 -2
  4. package/dist/scope-aspects-loader.d.ts +4 -4
  5. package/dist/scope-aspects-loader.js +8 -9
  6. package/dist/scope-aspects-loader.js.map +1 -1
  7. package/dist/scope-cmd.d.ts +1 -1
  8. package/dist/scope-component-loader.js +2 -2
  9. package/dist/scope-component-loader.js.map +1 -1
  10. package/dist/scope.composition.d.ts +2 -2
  11. package/dist/scope.graphql.d.ts +4 -4
  12. package/dist/scope.main.runtime.d.ts +30 -22
  13. package/dist/scope.main.runtime.js +37 -15
  14. package/dist/scope.main.runtime.js.map +1 -1
  15. package/dist/scope.ui-root.d.ts +2 -2
  16. package/dist/scope.ui.drawer.d.ts +1 -1
  17. package/dist/scope.ui.drawer.js +6 -8
  18. package/dist/scope.ui.drawer.js.map +1 -1
  19. package/dist/scope.ui.runtime.d.ts +14 -14
  20. package/dist/scope.ui.runtime.js +8 -11
  21. package/dist/scope.ui.runtime.js.map +1 -1
  22. package/dist/staged-config.d.ts +3 -3
  23. package/dist/staged-config.js +2 -3
  24. package/dist/staged-config.js.map +1 -1
  25. package/dist/types.d.ts +3 -3
  26. package/dist/ui/menu/menu.d.ts +4 -4
  27. package/dist/ui/scope-overview/scope-overview.d.ts +5 -5
  28. package/dist/ui/scope-overview/scope-overview.js +2 -4
  29. package/dist/ui/scope-overview/scope-overview.js.map +1 -1
  30. package/dist/ui/scope.d.ts +3 -3
  31. package/dist/ui/scope.js +1 -1
  32. package/dist/ui/scope.js.map +1 -1
  33. package/get-scope-options.ts +16 -0
  34. package/index.ts +11 -0
  35. package/package.json +33 -40
  36. package/scope-aspects-loader.ts +493 -0
  37. package/scope-cmd.ts +17 -0
  38. package/scope-component-loader.ts +208 -0
  39. package/scope.aspect.ts +7 -0
  40. package/scope.graphql.ts +115 -0
  41. package/scope.main.runtime.ts +1263 -0
  42. package/scope.ui-root.ts +43 -0
  43. package/scope.ui.runtime.tsx +1 -0
  44. package/staged-config.ts +79 -0
  45. package/tsconfig.json +16 -21
  46. package/types/asset.d.ts +15 -3
  47. package/types.ts +12 -0
@@ -144,6 +144,13 @@ function _scopeLoader() {
144
144
  };
145
145
  return data;
146
146
  }
147
+ function _getDivergeData() {
148
+ const data = require("@teambit/legacy/dist/scope/component-ops/get-diverge-data");
149
+ _getDivergeData = function () {
150
+ return data;
151
+ };
152
+ return data;
153
+ }
147
154
  function _actions() {
148
155
  const data = require("@teambit/legacy/dist/scope/actions");
149
156
  _actions = function () {
@@ -526,8 +533,7 @@ class ScopeMain {
526
533
  }
527
534
  builderDataMapToLegacyOnTagResults(builderDataComponentMap) {
528
535
  const builderDataToLegacyExtension = (component, builderData) => {
529
- var _component$state$aspe;
530
- const existingBuilder = (_component$state$aspe = component.state.aspects.get(_builder().BuilderAspect.id)) === null || _component$state$aspe === void 0 ? void 0 : _component$state$aspe.legacy;
536
+ const existingBuilder = component.state.aspects.get(_builder().BuilderAspect.id)?.legacy;
531
537
  const builderExtension = existingBuilder || new (_config().ExtensionDataEntry)(undefined, undefined, _builder().BuilderAspect.id);
532
538
  builderExtension.data = builderData;
533
539
  return builderExtension;
@@ -592,7 +598,7 @@ class ScopeMain {
592
598
  force,
593
599
  lanes
594
600
  }, headers) {
595
- const authData = (0, _http().getAuthDataFromHeader)(headers === null || headers === void 0 ? void 0 : headers.authorization);
601
+ const authData = (0, _http().getAuthDataFromHeader)(headers?.authorization);
596
602
  const result = await (0, _scope2().remove)({
597
603
  path: this.path,
598
604
  ids,
@@ -801,7 +807,7 @@ class ScopeMain {
801
807
  * list all components in the scope.
802
808
  */
803
809
  async list(filter, includeCache = false, includeFromLanes = false, includeDeleted = false) {
804
- const patternsWithScope = (filter === null || filter === void 0 ? void 0 : filter.namespaces) && (filter === null || filter === void 0 ? void 0 : filter.namespaces.map(pattern => `**/${pattern || '**'}`)) || undefined;
810
+ const patternsWithScope = filter?.namespaces && filter?.namespaces.map(pattern => `**/${pattern || '**'}`) || undefined;
805
811
  const componentsIds = await this.listIds(includeCache, includeFromLanes, patternsWithScope);
806
812
  const comps = await this.getMany(filter && filter.limit ? (0, _lodash().slice)(componentsIds, filter.offset, filter.offset + filter.limit) : componentsIds);
807
813
  return includeDeleted ? comps : comps.filter(comp => !comp.isDeleted());
@@ -830,7 +836,7 @@ class ScopeMain {
830
836
  const modelComponentsToList = allModelComponents.filter(filterByCacheAndLanes);
831
837
  let ids = modelComponentsToList.map(component => _componentId().ComponentID.fromLegacy(component.toBitIdWithLatestVersion(), component.scope || this.name));
832
838
  if (patterns && patterns.length > 0) {
833
- ids = ids.filter(id => patterns === null || patterns === void 0 ? void 0 : patterns.some(pattern => (0, _workspaceModules().isMatchNamespacePatternItem)(id.toStringWithoutVersion(), pattern).match));
839
+ ids = ids.filter(id => patterns?.some(pattern => (0, _workspaceModules().isMatchNamespacePatternItem)(id.toStringWithoutVersion(), pattern).match));
834
840
  }
835
841
  this.logger.debug(`scope listIds: total ${ids.length} components after filter scope`);
836
842
  return ids;
@@ -1027,13 +1033,32 @@ class ScopeMain {
1027
1033
  await modelComp.setDivergeData(this.legacyScope.objects, throws);
1028
1034
  return modelComp.getDivergeData();
1029
1035
  }
1036
+ /**
1037
+ * get the distance for a component between two lanes. for example, lane-b forked from lane-a and lane-b added some new snaps
1038
+ * @param componentId
1039
+ * @param sourceHead head on the source lane. leave empty if the source is main
1040
+ * @param targetHead head on the target lane. leave empty if the target is main
1041
+ * @returns
1042
+ */
1043
+ async getSnapsDistanceBetweenTwoSnaps(componentId, sourceHead, targetHead, throws) {
1044
+ if (!sourceHead && !targetHead) {
1045
+ throw new Error(`getDivergeData got sourceHead and targetHead empty. at least one of them should be populated`);
1046
+ }
1047
+ const modelComponent = await this.legacyScope.getModelComponent(componentId);
1048
+ return (0, _getDivergeData().getDivergeData)({
1049
+ modelComponent,
1050
+ repo: this.legacyScope.objects,
1051
+ sourceHead: sourceHead ? _objects().Ref.from(sourceHead) : modelComponent.head || null,
1052
+ targetHead: targetHead ? _objects().Ref.from(targetHead) : modelComponent.head || null,
1053
+ throws
1054
+ });
1055
+ }
1030
1056
  async getExactVersionBySemverRange(id, range) {
1031
- var _semver$maxSatisfying;
1032
1057
  const modelComponent = await this.legacyScope.getModelComponent(id);
1033
1058
  const versions = modelComponent.listVersions();
1034
- return (_semver$maxSatisfying = _semver().default.maxSatisfying(versions, range, {
1059
+ return _semver().default.maxSatisfying(versions, range, {
1035
1060
  includePrerelease: true
1036
- })) === null || _semver$maxSatisfying === void 0 ? void 0 : _semver$maxSatisfying.toString();
1061
+ })?.toString();
1037
1062
  }
1038
1063
  async resumeExport(exportId, remotes) {
1039
1064
  return (0, _exportScopeComponents().resumeExport)(this.legacyScope, exportId, remotes);
@@ -1066,9 +1091,8 @@ class ScopeMain {
1066
1091
  try {
1067
1092
  return await this.legacyScope.getConsumerComponent(id);
1068
1093
  } catch (err) {
1069
- var _await$this$get;
1070
1094
  // in case the component is missing locally, this.get imports it.
1071
- return (_await$this$get = await this.get(id)) === null || _await$this$get === void 0 ? void 0 : _await$this$get.state._consumer;
1095
+ return (await this.get(id))?.state._consumer;
1072
1096
  }
1073
1097
  }
1074
1098
 
@@ -1107,16 +1131,14 @@ class ScopeMain {
1107
1131
  // important! previously, this was running for any aspect, not only apps. (the if statement was `this.aspectLoader.isAspectComponent(component)`)
1108
1132
  // Ran suggests changing it and if it breaks something, we'll document is and fix it.
1109
1133
  if (opts.loadApps) {
1110
- var _appData$data;
1111
1134
  const appData = component.state.aspects.get('teambit.harmony/application');
1112
- if (appData !== null && appData !== void 0 && (_appData$data = appData.data) !== null && _appData$data !== void 0 && _appData$data.appName) {
1135
+ if (appData?.data?.appName) {
1113
1136
  aspectIds.push(component.id.toString());
1114
1137
  }
1115
1138
  }
1116
1139
  if (opts.loadEnvs) {
1117
- var _envsData$data, _envsData$data2, _envsData$data3;
1118
1140
  const envsData = component.state.aspects.get(_envs().default.id);
1119
- if (envsData !== null && envsData !== void 0 && (_envsData$data = envsData.data) !== null && _envsData$data !== void 0 && _envsData$data.services || envsData !== null && envsData !== void 0 && (_envsData$data2 = envsData.data) !== null && _envsData$data2 !== void 0 && _envsData$data2.self || (envsData === null || envsData === void 0 || (_envsData$data3 = envsData.data) === null || _envsData$data3 === void 0 ? void 0 : _envsData$data3.type) === 'env') {
1141
+ if (envsData?.data?.services || envsData?.data?.self || envsData?.data?.type === 'env') {
1120
1142
  aspectIds.push(component.id.toString());
1121
1143
  }
1122
1144
  }
@@ -1157,7 +1179,7 @@ class ScopeMain {
1157
1179
 
1158
1180
  static async provider([componentExt, ui, graphql, cli, isolator, aspectLoader, express, loggerMain, envs, depsResolver, globalConfig], config, [postPutSlot, postDeleteSlot, postExportSlot, postObjectsPersistSlot, preFetchObjectsSlot, OnCompAspectReCalcSlot], harmony) {
1159
1181
  const bitConfig = harmony.config.get('teambit.harmony/bit');
1160
- const legacyScope = await (0, _scopeLoader().loadScopeIfExist)(bitConfig === null || bitConfig === void 0 ? void 0 : bitConfig.cwd);
1182
+ const legacyScope = await (0, _scopeLoader().loadScopeIfExist)(bitConfig?.cwd);
1161
1183
  if (!legacyScope) {
1162
1184
  return undefined;
1163
1185
  }