@teambit/workspace 1.0.660 → 1.0.662

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.
@@ -1,5 +1,5 @@
1
- import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad/teambit.workspace_workspace@1.0.660/dist/workspace.composition.js';
2
- import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad/teambit.workspace_workspace@1.0.660/dist/workspace.docs.mdx';
1
+ import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad/teambit.workspace_workspace@1.0.662/dist/workspace.composition.js';
2
+ import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad/teambit.workspace_workspace@1.0.662/dist/workspace.docs.mdx';
3
3
 
4
4
  export const compositions = [compositions_0];
5
5
  export const overview = [overview_0];
@@ -8,21 +8,20 @@ type UseWorkspaceOptions = {
8
8
  };
9
9
  export declare function useWorkspace(options?: UseWorkspaceOptions): {
10
10
  error?: import("@apollo/client").ApolloError | undefined;
11
- errors?: ReadonlyArray<import("graphql").GraphQLFormattedError> | undefined;
12
11
  loading: boolean;
13
- client: import("@apollo/client").ApolloClient<any>;
14
12
  variables: import("@apollo/client").OperationVariables | undefined;
15
- observable: import("@apollo/client").ObservableQuery<any, import("@apollo/client").OperationVariables>;
16
- networkStatus: import("@apollo/client").NetworkStatus;
17
- called: boolean;
18
13
  startPolling: (pollInterval: number) => void;
19
14
  stopPolling: () => void;
20
- updateQuery: (mapFn: import("@apollo/client").UpdateQueryMapFn<any, import("@apollo/client").OperationVariables>) => void;
15
+ updateQuery: <TVars = import("@apollo/client").OperationVariables>(mapFn: (previousQueryResult: any, options: Pick<import("@apollo/client").WatchQueryOptions<TVars, any>, "variables">) => any) => void;
21
16
  reobserve: (newOptions?: Partial<import("@apollo/client").WatchQueryOptions<import("@apollo/client").OperationVariables, any>> | undefined, newNetworkStatus?: import("@apollo/client").NetworkStatus) => Promise<import("@apollo/client").ApolloQueryResult<any>>;
17
+ client: import("@apollo/client").ApolloClient<any>;
18
+ observable: import("@apollo/client").ObservableQuery<any, import("@apollo/client").OperationVariables>;
19
+ networkStatus: import("@apollo/client").NetworkStatus;
20
+ called: boolean;
22
21
  previousData?: any;
23
22
  fetchMore: (options: import("@apollo/client").FetchMoreQueryOptions<import("@apollo/client").OperationVariables, any>) => Promise<import("@apollo/client").ApolloQueryResult<any>>;
24
23
  refetch: (variables?: Partial<import("@apollo/client").OperationVariables> | undefined) => Promise<import("@apollo/client").ApolloQueryResult<any>>;
25
24
  workspace: Workspace | undefined;
26
- subscribeToMore: import("@apollo/client").SubscribeToMoreFunction<any, import("@apollo/client").OperationVariables>;
25
+ subscribeToMore: <TSubscriptionData = any, TSubscriptionVariables = import("@apollo/client").OperationVariables>(options: import("@apollo/client").SubscribeToMoreOptions<any, TSubscriptionVariables, TSubscriptionData>) => () => void;
27
26
  };
28
27
  export {};
@@ -396,6 +396,35 @@ export declare class Workspace implements ComponentFactory {
396
396
  * @param ids
397
397
  */
398
398
  importAndGetMany(ids: Array<ComponentID>, reason?: string, loadOpts?: ComponentLoadOptions, throwOnError?: boolean): Promise<Component[]>;
399
+ /**
400
+ * This is happening when the user is running "git pull", which updates ".bitmap" file, but the local scope objects
401
+ * are not updated yet ("bit import" is not run yet).
402
+ * Although it might happen on a lane. This is rare. Because using git with bit normally means that locally you don't have
403
+ * any lane. The CI is the one that creates the lanes.
404
+ * The following conditions are checked:
405
+ * 1. we're on main.
406
+ * 2. git is enabled.
407
+ * 3. components on .bitmap has tags that are not in the local scope.
408
+ *
409
+ * It is designed to be performant. On mac M1 with 337 components, it takes around 100ms.
410
+ *
411
+ * @returns array of component IDs that have tags in .bitmap but not in local scope, or empty array if not outdated
412
+ */
413
+ private getOutdatedIdsAgainstGit;
414
+ /**
415
+ * This is relevant when the user is running "git pull", which updates ".bitmap" file, but the local scope objects
416
+ * are not updated yet ("bit import" is not run yet). In case it found outdated components, it imports them.
417
+ *
418
+ * Important: this is only for main (not lanes) and only when using git and only for tags, not snaps.
419
+ * see `getOutdatedIdsAgainstGit` for more info.
420
+ */
421
+ importObjectsIfOutdatedAgainstBitmap(): Promise<void>;
422
+ /**
423
+ * This is pretty much the same as `importer.importCurrentObjects`.
424
+ * The reason for the duplication is that many aspects can't depend on the `importer` aspect, due to circular dependencies.
425
+ * The importer aspect is reacher in a way that it shows the results of what was imported by comparing the before and after.
426
+ */
427
+ importCurrentObjects(compIds?: ComponentID[]): Promise<void>;
399
428
  importCurrentLaneIfMissing(): Promise<Lane | undefined>;
400
429
  use(aspectIdStr: string): Promise<string>;
401
430
  unuse(aspectIdStr: string): Promise<boolean>;
package/dist/workspace.js CHANGED
@@ -18,6 +18,13 @@ function _pMapSeries() {
18
18
  };
19
19
  return data;
20
20
  }
21
+ function _pMap() {
22
+ const data = _interopRequireDefault(require("p-map"));
23
+ _pMap = function () {
24
+ return data;
25
+ };
26
+ return data;
27
+ }
21
28
  function _graph() {
22
29
  const data = require("@teambit/graph.cleargraph");
23
30
  _graph = function () {
@@ -1279,6 +1286,90 @@ the following envs are used in this workspace: ${(0, _lodash().uniq)(availableEn
1279
1286
  });
1280
1287
  return this.getMany(ids, loadOpts, throwOnError);
1281
1288
  }
1289
+
1290
+ /**
1291
+ * This is happening when the user is running "git pull", which updates ".bitmap" file, but the local scope objects
1292
+ * are not updated yet ("bit import" is not run yet).
1293
+ * Although it might happen on a lane. This is rare. Because using git with bit normally means that locally you don't have
1294
+ * any lane. The CI is the one that creates the lanes.
1295
+ * The following conditions are checked:
1296
+ * 1. we're on main.
1297
+ * 2. git is enabled.
1298
+ * 3. components on .bitmap has tags that are not in the local scope.
1299
+ *
1300
+ * It is designed to be performant. On mac M1 with 337 components, it takes around 100ms.
1301
+ *
1302
+ * @returns array of component IDs that have tags in .bitmap but not in local scope, or empty array if not outdated
1303
+ */
1304
+ async getOutdatedIdsAgainstGit() {
1305
+ if (!this.consumer.isOnMain()) {
1306
+ return [];
1307
+ }
1308
+ if (!(await _fsExtra().default.pathExists(_path().default.join(this.path, '.git')))) {
1309
+ return [];
1310
+ }
1311
+
1312
+ // Collect bitmap components that have tags not in local scope
1313
+ const bitmapIds = this.consumer.bitMap.getAllIdsAvailableOnLane();
1314
+ const outdatedIds = await (0, _pMap().default)(bitmapIds, async bitmapId => {
1315
+ if (!bitmapId.version) return;
1316
+ const modelComponent = await this.scope.legacyScope.getModelComponentIfExist(bitmapId.changeVersion(undefined));
1317
+ if (!modelComponent || !modelComponent.hasTag(bitmapId.version)) {
1318
+ // Component doesn't exist in scope or exists but this tag version is missing
1319
+ return bitmapId;
1320
+ }
1321
+ return null;
1322
+ }, {
1323
+ concurrency: 30
1324
+ });
1325
+ return (0, _lodash().compact)(outdatedIds);
1326
+ }
1327
+
1328
+ /**
1329
+ * This is relevant when the user is running "git pull", which updates ".bitmap" file, but the local scope objects
1330
+ * are not updated yet ("bit import" is not run yet). In case it found outdated components, it imports them.
1331
+ *
1332
+ * Important: this is only for main (not lanes) and only when using git and only for tags, not snaps.
1333
+ * see `getOutdatedIdsAgainstGit` for more info.
1334
+ */
1335
+ async importObjectsIfOutdatedAgainstBitmap() {
1336
+ const outdatedIds = await this.getOutdatedIdsAgainstGit();
1337
+ if (outdatedIds.length) {
1338
+ await this.importCurrentObjects(outdatedIds);
1339
+ this.logger.setStatusLine(`imported ${outdatedIds.length} components that were outdated against bitmap`);
1340
+ }
1341
+ }
1342
+
1343
+ /**
1344
+ * This is pretty much the same as `importer.importCurrentObjects`.
1345
+ * The reason for the duplication is that many aspects can't depend on the `importer` aspect, due to circular dependencies.
1346
+ * The importer aspect is reacher in a way that it shows the results of what was imported by comparing the before and after.
1347
+ */
1348
+ async importCurrentObjects(compIds) {
1349
+ const lane = await this.importCurrentLaneIfMissing();
1350
+ if (lane) {
1351
+ return; // it was all imported in the function above.
1352
+ }
1353
+ const scopeComponentsImporter = _legacy7().ScopeComponentsImporter.getInstance(this.scope.legacyScope);
1354
+ const allIds = compIds || this.consumer.bitMap.getAllBitIdsFromAllLanes();
1355
+ const ids = _componentId().ComponentIdList.fromArray(allIds.filter(id => id.hasScope()));
1356
+ await scopeComponentsImporter.importWithoutDeps(ids.toVersionLatest(), {
1357
+ cache: false,
1358
+ includeVersionHistory: true,
1359
+ fetchHeadIfLocalIsBehind: true,
1360
+ ignoreMissingHead: true,
1361
+ reason: `of their latest on main`
1362
+ });
1363
+ this.logger.setStatusLine(`import ${ids.length} components with their dependencies (if missing)`);
1364
+ await scopeComponentsImporter.importMany({
1365
+ ids,
1366
+ ignoreMissingHead: true,
1367
+ preferDependencyGraph: true,
1368
+ reFetchUnBuiltVersion: true,
1369
+ throwForSeederNotFound: false,
1370
+ reason: 'for getting all dependencies'
1371
+ });
1372
+ }
1282
1373
  async importCurrentLaneIfMissing() {
1283
1374
  const laneId = this.getCurrentLaneId();
1284
1375
  const laneObj = await this.scope.legacyScope.getCurrentLaneObject();