@teambit/workspace 0.0.536 → 0.0.543

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/package.json CHANGED
@@ -1,22 +1,23 @@
1
1
  {
2
2
  "name": "@teambit/workspace",
3
- "version": "0.0.536",
3
+ "version": "0.0.543",
4
4
  "homepage": "https://bit.dev/teambit/workspace/workspace",
5
5
  "main": "dist/index.js",
6
6
  "componentId": {
7
7
  "scope": "teambit.workspace",
8
8
  "name": "workspace",
9
- "version": "0.0.536"
9
+ "version": "0.0.543"
10
10
  },
11
11
  "dependencies": {
12
+ "lodash.compact": "3.0.1",
13
+ "lodash": "4.17.21",
14
+ "p-map-series": "2.1.0",
12
15
  "chalk": "2.4.2",
13
16
  "ink": "3.0.8",
14
17
  "semver": "7.3.4",
15
18
  "@teambit/harmony": "0.2.11",
16
19
  "graphql-tag": "2.12.1",
17
20
  "fs-extra": "10.0.0",
18
- "lodash": "4.17.21",
19
- "p-map-series": "2.1.0",
20
21
  "react-router-dom": "5.2.0",
21
22
  "detect-indent": "5.0.0",
22
23
  "detect-newline": "3.1.0",
@@ -32,60 +33,61 @@
32
33
  "@teambit/base-ui.surfaces.split-pane.hover-splitter": "1.0.0",
33
34
  "@teambit/base-ui.surfaces.split-pane.split-pane": "1.0.0",
34
35
  "@teambit/base-ui.graph.tree.recursive-tree": "1.0.0",
36
+ "@teambit/bit-error": "0.0.366",
37
+ "@teambit/legacy-bit-id": "0.0.369",
38
+ "@teambit/logger": "0.0.461",
39
+ "@teambit/scope": "0.0.543",
35
40
  "@teambit/cli": "0.0.380",
36
- "@teambit/isolator": "0.0.536",
41
+ "@teambit/isolator": "0.0.543",
37
42
  "@teambit/component-tree": "0.0.366",
38
- "@teambit/component.ui.component-status-resolver": "0.0.455",
39
- "@teambit/harmony.modules.resolved-component": "0.0.449",
40
- "@teambit/dependency-resolver": "0.0.536",
41
- "@teambit/logger": "0.0.457",
42
- "@teambit/compiler": "0.0.536",
43
- "@teambit/component": "0.0.536",
44
- "@teambit/graphql": "0.0.536",
45
- "@teambit/aspect-loader": "0.0.536",
46
- "@teambit/bundler": "0.0.536",
47
- "@teambit/envs": "0.0.536",
48
- "@teambit/pubsub": "0.0.536",
49
- "@teambit/scope": "0.0.536",
50
- "@teambit/ui": "0.0.536",
51
- "@teambit/variants": "0.0.459",
52
- "@teambit/legacy-bit-id": "0.0.369",
53
- "@teambit/bit-error": "0.0.366",
43
+ "@teambit/component.ui.component-status-resolver": "0.0.459",
44
+ "@teambit/harmony.modules.resolved-component": "0.0.453",
45
+ "@teambit/dependency-resolver": "0.0.543",
46
+ "@teambit/compiler": "0.0.543",
47
+ "@teambit/component": "0.0.543",
48
+ "@teambit/graphql": "0.0.543",
49
+ "@teambit/aspect-loader": "0.0.543",
50
+ "@teambit/bundler": "0.0.543",
51
+ "@teambit/envs": "0.0.543",
52
+ "@teambit/pubsub": "0.0.543",
53
+ "@teambit/ui": "0.0.543",
54
+ "@teambit/variants": "0.0.463",
54
55
  "@teambit/component-issues": "0.0.15",
55
56
  "@teambit/config": "0.0.391",
56
- "@teambit/harmony.modules.requireable-component": "0.0.449",
57
- "@teambit/workspace.modules.match-pattern": "0.0.451",
58
- "@teambit/command-bar": "0.0.536",
57
+ "@teambit/harmony.modules.requireable-component": "0.0.453",
58
+ "@teambit/workspace.modules.match-pattern": "0.0.455",
59
+ "@teambit/command-bar": "0.0.543",
59
60
  "@teambit/design.ui.surfaces.menu.link-item": "0.0.374",
60
- "@teambit/graph": "0.0.536",
61
- "@teambit/react-router": "0.0.536",
62
- "@teambit/sidebar": "0.0.536",
63
- "@teambit/ui-foundation.ui.main-dropdown": "0.0.451",
64
- "@teambit/ui-foundation.ui.menu": "0.0.451",
65
- "@teambit/ui-foundation.ui.react-router.slot-router": "0.0.453",
66
- "@teambit/toolbox.time.time-format": "0.0.448",
61
+ "@teambit/graph": "0.0.543",
62
+ "@teambit/react-router": "0.0.543",
63
+ "@teambit/sidebar": "0.0.543",
64
+ "@teambit/ui-foundation.ui.main-dropdown": "0.0.455",
65
+ "@teambit/ui-foundation.ui.menu": "0.0.455",
66
+ "@teambit/ui-foundation.ui.react-router.slot-router": "0.0.457",
67
+ "@teambit/toolbox.time.time-format": "0.0.452",
67
68
  "@teambit/component-id": "0.0.370",
68
- "@teambit/ui-foundation.ui.hooks.use-data-query": "0.0.452",
69
- "@teambit/deprecation": "0.0.536",
70
- "@teambit/ui-foundation.ui.constants.z-indexes": "0.0.451",
71
- "@teambit/ui-foundation.ui.buttons.collapser": "0.0.156",
72
- "@teambit/ui-foundation.ui.corner": "0.0.458",
73
- "@teambit/ui-foundation.ui.notifications.notification-context": "0.0.452",
74
- "@teambit/ui-foundation.ui.top-bar": "0.0.453",
69
+ "@teambit/ui-foundation.ui.hooks.use-data-query": "0.0.456",
70
+ "@teambit/deprecation": "0.0.543",
71
+ "@teambit/ui-foundation.ui.constants.z-indexes": "0.0.455",
72
+ "@teambit/ui-foundation.ui.buttons.collapser": "0.0.160",
73
+ "@teambit/ui-foundation.ui.corner": "0.0.462",
74
+ "@teambit/ui-foundation.ui.notifications.notification-context": "0.0.456",
75
+ "@teambit/ui-foundation.ui.top-bar": "0.0.457",
75
76
  "@teambit/design.ui.styles.ellipsis": "0.0.346",
76
77
  "@teambit/design.ui.styles.muted-italic": "0.0.35",
77
- "@teambit/ui-foundation.ui.full-loader": "0.0.451",
78
- "@teambit/ui-foundation.ui.side-bar": "0.0.455",
79
- "@teambit/ui-foundation.ui.tree.drawer": "0.0.451",
80
- "@teambit/explorer.ui.gallery.component-grid": "0.0.451",
81
- "@teambit/workspace.ui.empty-workspace": "0.0.453",
82
- "@teambit/workspace.ui.workspace-component-card": "0.0.454"
78
+ "@teambit/ui-foundation.ui.full-loader": "0.0.455",
79
+ "@teambit/ui-foundation.ui.side-bar": "0.0.459",
80
+ "@teambit/ui-foundation.ui.tree.drawer": "0.0.455",
81
+ "@teambit/explorer.ui.gallery.component-grid": "0.0.455",
82
+ "@teambit/workspace.ui.empty-workspace": "0.0.457",
83
+ "@teambit/workspace.ui.workspace-component-card": "0.0.458"
83
84
  },
84
85
  "devDependencies": {
86
+ "@types/lodash.compact": "3.0.6",
87
+ "@types/lodash": "4.14.165",
85
88
  "@types/react": "^17.0.8",
86
89
  "@types/semver": "7.3.4",
87
90
  "@types/fs-extra": "9.0.7",
88
- "@types/lodash": "4.14.165",
89
91
  "@types/react-router-dom": "5.1.7",
90
92
  "@types/pluralize": "0.0.29",
91
93
  "@types/classnames": "2.2.11",
package/workspace.ts CHANGED
@@ -43,7 +43,7 @@ import { ImportOptions } from '@teambit/legacy/dist/consumer/component-ops/impor
43
43
  import { NothingToImport } from '@teambit/legacy/dist/consumer/exceptions';
44
44
  import { BitIds } from '@teambit/legacy/dist/bit-id';
45
45
  import { BitId, InvalidScopeName, isValidScopeName } from '@teambit/legacy-bit-id';
46
- import { LocalLaneId } from '@teambit/legacy/dist/lane-id/lane-id';
46
+ import { LocalLaneId, RemoteLaneId } from '@teambit/legacy/dist/lane-id/lane-id';
47
47
  import { Consumer, loadConsumer } from '@teambit/legacy/dist/consumer';
48
48
  import { GetBitMapComponentOptions } from '@teambit/legacy/dist/consumer/bit-map/bit-map';
49
49
  import AddComponents from '@teambit/legacy/dist/consumer/component-ops/add-components';
@@ -55,7 +55,6 @@ import { ComponentNotFound } from '@teambit/legacy/dist/scope/exceptions';
55
55
  import ComponentsList from '@teambit/legacy/dist/consumer/component/components-list';
56
56
  import { NoComponentDir } from '@teambit/legacy/dist/consumer/component/exceptions/no-component-dir';
57
57
  import { ExtensionDataList } from '@teambit/legacy/dist/consumer/config/extension-data';
58
- import { buildOneGraphForComponents } from '@teambit/legacy/dist/scope/graph/components-graph';
59
58
  import { pathIsInside } from '@teambit/legacy/dist/utils';
60
59
  import componentIdToPackageName from '@teambit/legacy/dist/utils/bit/component-id-to-package-name';
61
60
  import { PathOsBased, PathOsBasedRelative, PathOsBasedAbsolute } from '@teambit/legacy/dist/utils/path';
@@ -89,6 +88,7 @@ import {
89
88
  } from './workspace.provider';
90
89
  import { WorkspaceComponentLoader } from './workspace-component/workspace-component-loader';
91
90
  import { IncorrectEnvAspect } from './exceptions/incorrect-env-aspect';
91
+ import { GraphFromFsBuilder, ShouldIgnoreFunc } from './build-graph-from-fs';
92
92
 
93
93
  export type EjectConfResult = {
94
94
  configPath: string;
@@ -392,7 +392,7 @@ export class Workspace implements ComponentFactory {
392
392
 
393
393
  const legacyIds = ids.map((id) => id._legacy);
394
394
 
395
- const legacyGraph = await buildOneGraphForComponents(legacyIds, this.consumer);
395
+ const legacyGraph = await this.buildOneGraphForComponents(legacyIds);
396
396
  return legacyGraph;
397
397
  }
398
398
 
@@ -537,6 +537,22 @@ export class Workspace implements ComponentFactory {
537
537
  return this.consumer.getCurrentLaneId();
538
538
  }
539
539
 
540
+ /**
541
+ * if checked out to a lane, return the remote lane id (name+scope). otherwise, return null.
542
+ */
543
+ getCurrentRemoteLaneId(): RemoteLaneId | null {
544
+ const currentLane = this.getCurrentLaneId();
545
+ if (currentLane.isDefault()) {
546
+ return null;
547
+ }
548
+ const trackData = this.scope.legacyScope.lanes.getRemoteTrackedDataByLocalLane(currentLane.name);
549
+ const remoteLaneName = trackData?.remoteLane;
550
+ if (!remoteLaneName) {
551
+ return null;
552
+ }
553
+ return RemoteLaneId.from(remoteLaneName, trackData.remoteScope);
554
+ }
555
+
540
556
  getDefaultExtensions(): ExtensionDataList {
541
557
  if (!this.config.extensions) {
542
558
  return new ExtensionDataList();
@@ -608,7 +624,7 @@ export class Workspace implements ComponentFactory {
608
624
  * @param forCapsule
609
625
  */
610
626
  async importAndGetMany(ids: Array<ComponentID>, forCapsule = false): Promise<Component[]> {
611
- await this.scope.import(ids);
627
+ await this.scope.import(ids, { reFetchUnBuiltVersion: shouldReFetchUnBuiltVersion() });
612
628
  return this.componentLoader.getMany(ids, forCapsule);
613
629
  }
614
630
 
@@ -894,7 +910,7 @@ export class Workspace implements ComponentFactory {
894
910
  return componentConfigFile;
895
911
  }
896
912
 
897
- async getGraphWithoutCore(components: Component[]) {
913
+ async getAspectsGraphWithoutCore(components: Component[], isAspect?: ShouldIgnoreFunc) {
898
914
  const ids = components.map((component) => component.id._legacy);
899
915
  const coreAspectsStringIds = this.aspectLoader.getCoreAspectIds();
900
916
  const coreAspectsComponentIds = coreAspectsStringIds.map((id) => BitId.parse(id, true));
@@ -917,7 +933,7 @@ export class Workspace implements ComponentFactory {
917
933
  // This come to solve a circular loop when an env aspect use an aspect (as regular dep) and the aspect use the env aspect as its env
918
934
  // TODO: @gilad it causes many issues we need to find a better solution. removed for now.
919
935
  const ignoredIds = coreAspectsBitIds.concat([]);
920
- return buildOneGraphForComponents(ids, this.consumer, undefined, BitIds.fromArray(ignoredIds));
936
+ return this.buildOneGraphForComponents(ids, BitIds.fromArray(ignoredIds), isAspect);
921
937
  }
922
938
 
923
939
  /**
@@ -932,14 +948,10 @@ export class Workspace implements ComponentFactory {
932
948
  const idsWithoutCore: string[] = difference(notLoadedIds, coreAspectsStringIds);
933
949
  const componentIds = await this.resolveMultipleComponentIds(idsWithoutCore);
934
950
  const components = await this.importAndGetAspects(componentIds);
935
- const graph = await this.getGraphWithoutCore(components);
936
- const allIdsP = graph.nodes().map(async (id) => {
937
- return this.resolveComponentId(id);
938
- });
939
- const allIds = await Promise.all(allIdsP);
940
- const allComponents = await this.getMany(allIds as ComponentID[]);
941
951
 
942
- const aspects = allComponents.filter((component: Component) => {
952
+ const isAspect = async (bitId: BitId) => {
953
+ const id = await this.resolveComponentId(bitId);
954
+ const component = await this.get(id);
943
955
  let data = component.config.extensions.findExtension(EnvsAspect.id)?.data;
944
956
  if (!data) {
945
957
  // TODO: remove this once we re-export old components used to store the data here
@@ -959,11 +971,13 @@ export class Workspace implements ComponentFactory {
959
971
  }
960
972
  }
961
973
  return data.type === 'aspect';
962
- });
963
- // no need to filter core aspects as they are not included in the graph
964
- // here we are trying to load extensions from the workspace.
974
+ };
975
+
976
+ const graph = await this.getAspectsGraphWithoutCore(components, isAspect);
977
+ const idsStr = graph.nodes();
978
+ const compIds = await this.resolveMultipleComponentIds(idsStr);
979
+ const aspects = await this.getMany(compIds);
965
980
  const { workspaceComps, scopeComps } = await this.groupComponentsByWorkspaceAndScope(aspects);
966
- // load the scope first because we might need it for custom envs that extend external aspects
967
981
  const scopeIds = scopeComps.map((aspect) => aspect.id.toString());
968
982
  const workspaceAspects = await this.requireComponents(workspaceComps);
969
983
  const workspaceManifests = await this.aspectLoader.getManifestsFromRequireableExtensions(
@@ -978,6 +992,20 @@ export class Workspace implements ComponentFactory {
978
992
  await this.aspectLoader.loadExtensionsByManifests(allManifests, throwOnError);
979
993
  }
980
994
 
995
+ /**
996
+ * Note - this gets called from Harmony only.
997
+ * returns one graph that includes all dependencies types. each edge has a label of the dependency
998
+ * type. the nodes content is the Component object.
999
+ */
1000
+ async buildOneGraphForComponents(
1001
+ ids: BitId[],
1002
+ ignoreIds?: BitIds,
1003
+ shouldIgnoreFunc?: ShouldIgnoreFunc
1004
+ ): Promise<LegacyGraph> {
1005
+ const graphFromFsBuilder = new GraphFromFsBuilder(this, this.logger, ignoreIds, shouldIgnoreFunc);
1006
+ return graphFromFsBuilder.buildGraph(ids);
1007
+ }
1008
+
981
1009
  async resolveAspects(runtimeName?: string, componentIds?: ComponentID[]): Promise<AspectDefinition[]> {
982
1010
  let missingPaths = false;
983
1011
  const stringIds: string[] = [];
@@ -1468,4 +1496,17 @@ your workspace.jsonc has this component-id set. you might want to remove/change
1468
1496
  }
1469
1497
  }
1470
1498
 
1499
+ /**
1500
+ * this is a super hacky way to do it. problem is that loadAspect is running as onStart hook, where we don't
1501
+ * have the CLI fully loaded yet, so we can't get the command from the CLI aspect, we have to retrieve it from
1502
+ * process.argv.
1503
+ * in general, we don't want every command to try again and again fetching un-built versions. otherwise, every time
1504
+ * Bit loads (even bit --help), it'll fetch them and slow down everything.
1505
+ * instead, long-running commands and those that need the artifacts from the Version objects, should try to re-fetch.
1506
+ */
1507
+ function shouldReFetchUnBuiltVersion() {
1508
+ const commandsToReFetch = ['build', 'show', 'start', 'tag', 'install', 'link', 'import'];
1509
+ return commandsToReFetch.includes(process.argv[2]);
1510
+ }
1511
+
1471
1512
  export default Workspace;