@teambit/scope 1.0.107 → 1.0.109

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 (40) hide show
  1. package/artifacts/preview/static/css/teambit.scope/scope-preview.49e9edaa.css +55 -0
  2. package/artifacts/preview/static/images/3a1072c009accd203fa8.png +0 -0
  3. package/artifacts/preview/static/images/aef2176d16de53259dad.png +0 -0
  4. package/artifacts/preview/static/images/ccf5ea377e3a1a72829d.png +0 -0
  5. package/artifacts/preview/teambit_scope_scope-preview.js +2 -0
  6. package/dist/get-scope-options.d.ts +1 -1
  7. package/dist/{preview-1703590665075.js → preview-1703698405864.js} +2 -2
  8. package/dist/scope-aspects-loader.d.ts +4 -4
  9. package/dist/scope-aspects-loader.js +8 -9
  10. package/dist/scope-aspects-loader.js.map +1 -1
  11. package/dist/scope-cmd.d.ts +1 -1
  12. package/dist/scope-component-loader.js +2 -2
  13. package/dist/scope-component-loader.js.map +1 -1
  14. package/dist/scope.composition.d.ts +2 -2
  15. package/dist/scope.graphql.d.ts +4 -4
  16. package/dist/scope.main.runtime.d.ts +30 -22
  17. package/dist/scope.main.runtime.js +37 -15
  18. package/dist/scope.main.runtime.js.map +1 -1
  19. package/dist/scope.ui-root.d.ts +2 -2
  20. package/dist/scope.ui.drawer.d.ts +1 -1
  21. package/dist/scope.ui.drawer.js +6 -8
  22. package/dist/scope.ui.drawer.js.map +1 -1
  23. package/dist/scope.ui.runtime.d.ts +14 -14
  24. package/dist/scope.ui.runtime.js +8 -11
  25. package/dist/scope.ui.runtime.js.map +1 -1
  26. package/dist/staged-config.d.ts +3 -3
  27. package/dist/staged-config.js +2 -3
  28. package/dist/staged-config.js.map +1 -1
  29. package/dist/types.d.ts +3 -3
  30. package/dist/ui/menu/menu.d.ts +4 -4
  31. package/dist/ui/scope-overview/scope-overview.d.ts +5 -5
  32. package/dist/ui/scope-overview/scope-overview.js +2 -4
  33. package/dist/ui/scope-overview/scope-overview.js.map +1 -1
  34. package/dist/ui/scope.d.ts +3 -3
  35. package/dist/ui/scope.js +1 -1
  36. package/dist/ui/scope.js.map +1 -1
  37. package/package.json +33 -40
  38. package/scope.ui.runtime.tsx +1 -0
  39. package/tsconfig.json +16 -21
  40. package/types/asset.d.ts +15 -3
@@ -4,9 +4,9 @@ export declare function scopeSchema(scopeMain: ScopeMain): {
4
4
  resolvers: {
5
5
  Scope: {
6
6
  name: (scope: ScopeMain) => string;
7
- description: (scope: ScopeMain) => string | undefined;
8
- icon: (scope: ScopeMain) => string | undefined;
9
- backgroundIconColor: (scope: ScopeMain) => string | undefined;
7
+ description: (scope: ScopeMain) => string;
8
+ icon: (scope: ScopeMain) => string;
9
+ backgroundIconColor: (scope: ScopeMain) => string;
10
10
  components: (scope: ScopeMain, props?: {
11
11
  offset: number;
12
12
  limit: number;
@@ -15,7 +15,7 @@ export declare function scopeSchema(scopeMain: ScopeMain): {
15
15
  }) => Promise<import("@teambit/component").Component[]>;
16
16
  get: (scope: ScopeMain, { id }: {
17
17
  id: string;
18
- }) => Promise<import("@teambit/component").Component | undefined>;
18
+ }) => Promise<import("@teambit/component").Component>;
19
19
  _getLegacy: (scope: ScopeMain, { id }: {
20
20
  id: string;
21
21
  }) => Promise<any>;
@@ -33,35 +33,35 @@ import { EnvsMain } from '@teambit/envs';
33
33
  import { ScopeComponentLoader } from './scope-component-loader';
34
34
  import { StagedConfig } from './staged-config';
35
35
  import { ScopeAspectsLoader, ScopeLoadAspectsOptions } from './scope-aspects-loader';
36
- declare type RemoteEventMetadata = {
36
+ type RemoteEventMetadata = {
37
37
  auth?: AuthData;
38
38
  headers?: {};
39
39
  };
40
- declare type RemoteEvent<Data> = (data: Data, metadata: RemoteEventMetadata, errors?: Array<string | Error>) => Promise<void>;
41
- declare type OnPostPutData = {
40
+ type RemoteEvent<Data> = (data: Data, metadata: RemoteEventMetadata, errors?: Array<string | Error>) => Promise<void>;
41
+ type OnPostPutData = {
42
42
  ids: ComponentID[];
43
43
  lanes: Lane[];
44
44
  };
45
- declare type OnPostDeleteData = {
45
+ type OnPostDeleteData = {
46
46
  ids: ComponentID[];
47
47
  };
48
- declare type OnPreFetchObjectData = {
48
+ type OnPreFetchObjectData = {
49
49
  ids: string[];
50
50
  fetchOptions: FETCH_OPTIONS;
51
51
  };
52
- declare type OnPostPut = RemoteEvent<OnPostPutData>;
53
- declare type OnPostExport = RemoteEvent<OnPostPutData>;
54
- declare type OnPostDelete = RemoteEvent<OnPostDeleteData>;
55
- declare type OnPostObjectsPersist = RemoteEvent<undefined>;
56
- declare type OnPreFetchObjects = RemoteEvent<OnPreFetchObjectData>;
57
- declare type OnCompAspectReCalc = (component: Component) => Promise<AspectData | undefined>;
58
- export declare type OnPostPutSlot = SlotRegistry<OnPostPut>;
59
- export declare type OnPostDeleteSlot = SlotRegistry<OnPostDelete>;
60
- export declare type OnPostExportSlot = SlotRegistry<OnPostExport>;
61
- export declare type OnPostObjectsPersistSlot = SlotRegistry<OnPostObjectsPersist>;
62
- export declare type OnPreFetchObjectsSlot = SlotRegistry<OnPreFetchObjects>;
63
- export declare type OnCompAspectReCalcSlot = SlotRegistry<OnCompAspectReCalc>;
64
- export declare type LoadOptions = {
52
+ type OnPostPut = RemoteEvent<OnPostPutData>;
53
+ type OnPostExport = RemoteEvent<OnPostPutData>;
54
+ type OnPostDelete = RemoteEvent<OnPostDeleteData>;
55
+ type OnPostObjectsPersist = RemoteEvent<undefined>;
56
+ type OnPreFetchObjects = RemoteEvent<OnPreFetchObjectData>;
57
+ type OnCompAspectReCalc = (component: Component) => Promise<AspectData | undefined>;
58
+ export type OnPostPutSlot = SlotRegistry<OnPostPut>;
59
+ export type OnPostDeleteSlot = SlotRegistry<OnPostDelete>;
60
+ export type OnPostExportSlot = SlotRegistry<OnPostExport>;
61
+ export type OnPostObjectsPersistSlot = SlotRegistry<OnPostObjectsPersist>;
62
+ export type OnPreFetchObjectsSlot = SlotRegistry<OnPreFetchObjects>;
63
+ export type OnCompAspectReCalcSlot = SlotRegistry<OnCompAspectReCalc>;
64
+ export type LoadOptions = {
65
65
  /**
66
66
  * In case the component we are loading is app, whether to load it as app (in a scope aspects capsule)
67
67
  */
@@ -71,7 +71,7 @@ export declare type LoadOptions = {
71
71
  */
72
72
  loadEnvs?: boolean;
73
73
  };
74
- export declare type ScopeConfig = {
74
+ export type ScopeConfig = {
75
75
  httpTimeOut: number;
76
76
  description?: string;
77
77
  icon?: string;
@@ -264,7 +264,7 @@ export declare class ScopeMain implements ComponentFactory {
264
264
  * in the future, this can return components that failed to load in the scope due to objects file
265
265
  * corruption or similar issues.
266
266
  */
267
- listInvalid(): Promise<never[]>;
267
+ listInvalid(): Promise<any[]>;
268
268
  /**
269
269
  * get ids of all scope components.
270
270
  * @param includeCache whether or not include components that their scope-name is different than the current scope-name
@@ -328,6 +328,14 @@ export declare class ScopeMain implements ComponentFactory {
328
328
  idsByPattern(pattern: string, throwForNoMatch?: boolean): Promise<ComponentID[]>;
329
329
  filterIdsFromPoolIdsByPattern(pattern: string, ids: ComponentID[], throwForNoMatch?: boolean, filterByStateFunc?: (state: any, poolIds: ComponentID[]) => Promise<ComponentID[]>): Promise<ComponentID[]>;
330
330
  getSnapDistance(id: ComponentID, throws?: boolean): Promise<SnapsDistance>;
331
+ /**
332
+ * get the distance for a component between two lanes. for example, lane-b forked from lane-a and lane-b added some new snaps
333
+ * @param componentId
334
+ * @param sourceHead head on the source lane. leave empty if the source is main
335
+ * @param targetHead head on the target lane. leave empty if the target is main
336
+ * @returns
337
+ */
338
+ getSnapsDistanceBetweenTwoSnaps(componentId: ComponentID, sourceHead?: string, targetHead?: string, throws?: boolean): Promise<SnapsDistance>;
331
339
  getExactVersionBySemverRange(id: ComponentID, range: string): Promise<string | undefined>;
332
340
  resumeExport(exportId: string, remotes: string[]): Promise<string[]>;
333
341
  /**
@@ -364,7 +372,7 @@ export declare class ScopeMain implements ComponentFactory {
364
372
  /**
365
373
  * declare the slots of scope extension.
366
374
  */
367
- static slots: (((registerFn: () => string) => SlotRegistry<OnPostPut>) | ((registerFn: () => string) => SlotRegistry<OnPostObjectsPersist>) | ((registerFn: () => string) => SlotRegistry<OnPreFetchObjects>) | ((registerFn: () => string) => SlotRegistry<OnCompAspectReCalc>))[];
375
+ static slots: (((registerFn: () => string) => SlotRegistry<OnPostPut>) | ((registerFn: () => string) => SlotRegistry<OnCompAspectReCalc>))[];
368
376
  static runtime: import("@teambit/harmony").RuntimeDefinition;
369
377
  static dependencies: import("@teambit/harmony").Aspect[];
370
378
  static defaultConfig: ScopeConfig;
@@ -387,6 +395,6 @@ export declare class ScopeMain implements ComponentFactory {
387
395
  OnPostObjectsPersistSlot,
388
396
  OnPreFetchObjectsSlot,
389
397
  OnCompAspectReCalcSlot
390
- ], harmony: Harmony): Promise<ScopeMain | undefined>;
398
+ ], harmony: Harmony): Promise<ScopeMain>;
391
399
  }
392
400
  export {};
@@ -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
  }