@teambit/workspace 0.0.537 → 0.0.545

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.537",
3
+ "version": "0.0.545",
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.537"
9
+ "version": "0.0.545"
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,62 @@
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.463",
39
+ "@teambit/scope": "0.0.545",
35
40
  "@teambit/cli": "0.0.380",
36
- "@teambit/isolator": "0.0.537",
41
+ "@teambit/isolator": "0.0.545",
37
42
  "@teambit/component-tree": "0.0.366",
38
- "@teambit/component.ui.component-status-resolver": "0.0.457",
39
- "@teambit/harmony.modules.resolved-component": "0.0.451",
40
- "@teambit/dependency-resolver": "0.0.537",
41
- "@teambit/logger": "0.0.459",
42
- "@teambit/compiler": "0.0.537",
43
- "@teambit/component": "0.0.537",
44
- "@teambit/graphql": "0.0.537",
45
- "@teambit/aspect-loader": "0.0.537",
46
- "@teambit/bundler": "0.0.537",
47
- "@teambit/envs": "0.0.537",
48
- "@teambit/pubsub": "0.0.537",
49
- "@teambit/scope": "0.0.537",
50
- "@teambit/ui": "0.0.537",
51
- "@teambit/variants": "0.0.461",
52
- "@teambit/legacy-bit-id": "0.0.369",
53
- "@teambit/bit-error": "0.0.366",
43
+ "@teambit/component.ui.component-status-resolver": "0.0.461",
44
+ "@teambit/harmony.modules.resolved-component": "0.0.455",
45
+ "@teambit/dependency-resolver": "0.0.545",
46
+ "@teambit/compiler": "0.0.545",
47
+ "@teambit/component": "0.0.545",
48
+ "@teambit/graphql": "0.0.545",
49
+ "@teambit/aspect-loader": "0.0.545",
50
+ "@teambit/bundler": "0.0.545",
51
+ "@teambit/envs": "0.0.545",
52
+ "@teambit/pubsub": "0.0.545",
53
+ "@teambit/ui": "0.0.545",
54
+ "@teambit/variants": "0.0.465",
54
55
  "@teambit/component-issues": "0.0.15",
55
56
  "@teambit/config": "0.0.391",
56
- "@teambit/harmony.modules.requireable-component": "0.0.451",
57
- "@teambit/workspace.modules.match-pattern": "0.0.453",
58
- "@teambit/command-bar": "0.0.537",
57
+ "@teambit/harmony.modules.requireable-component": "0.0.455",
58
+ "@teambit/importer": "0.0.7",
59
+ "@teambit/workspace.modules.match-pattern": "0.0.457",
60
+ "@teambit/command-bar": "0.0.545",
59
61
  "@teambit/design.ui.surfaces.menu.link-item": "0.0.374",
60
- "@teambit/graph": "0.0.537",
61
- "@teambit/react-router": "0.0.537",
62
- "@teambit/sidebar": "0.0.537",
63
- "@teambit/ui-foundation.ui.main-dropdown": "0.0.453",
64
- "@teambit/ui-foundation.ui.menu": "0.0.453",
65
- "@teambit/ui-foundation.ui.react-router.slot-router": "0.0.455",
66
- "@teambit/toolbox.time.time-format": "0.0.450",
62
+ "@teambit/graph": "0.0.545",
63
+ "@teambit/react-router": "0.0.545",
64
+ "@teambit/sidebar": "0.0.545",
65
+ "@teambit/ui-foundation.ui.main-dropdown": "0.0.457",
66
+ "@teambit/ui-foundation.ui.menu": "0.0.457",
67
+ "@teambit/ui-foundation.ui.react-router.slot-router": "0.0.459",
68
+ "@teambit/toolbox.time.time-format": "0.0.454",
67
69
  "@teambit/component-id": "0.0.370",
68
- "@teambit/ui-foundation.ui.hooks.use-data-query": "0.0.454",
69
- "@teambit/deprecation": "0.0.537",
70
- "@teambit/ui-foundation.ui.constants.z-indexes": "0.0.453",
71
- "@teambit/ui-foundation.ui.buttons.collapser": "0.0.158",
72
- "@teambit/ui-foundation.ui.corner": "0.0.460",
73
- "@teambit/ui-foundation.ui.notifications.notification-context": "0.0.454",
74
- "@teambit/ui-foundation.ui.top-bar": "0.0.455",
70
+ "@teambit/ui-foundation.ui.hooks.use-data-query": "0.0.458",
71
+ "@teambit/deprecation": "0.0.545",
72
+ "@teambit/ui-foundation.ui.constants.z-indexes": "0.0.457",
73
+ "@teambit/ui-foundation.ui.buttons.collapser": "0.0.162",
74
+ "@teambit/ui-foundation.ui.corner": "0.0.464",
75
+ "@teambit/ui-foundation.ui.notifications.notification-context": "0.0.458",
76
+ "@teambit/ui-foundation.ui.top-bar": "0.0.459",
75
77
  "@teambit/design.ui.styles.ellipsis": "0.0.346",
76
78
  "@teambit/design.ui.styles.muted-italic": "0.0.35",
77
- "@teambit/ui-foundation.ui.full-loader": "0.0.453",
78
- "@teambit/ui-foundation.ui.side-bar": "0.0.457",
79
- "@teambit/ui-foundation.ui.tree.drawer": "0.0.453",
80
- "@teambit/explorer.ui.gallery.component-grid": "0.0.453",
81
- "@teambit/workspace.ui.empty-workspace": "0.0.455",
82
- "@teambit/workspace.ui.workspace-component-card": "0.0.456"
79
+ "@teambit/ui-foundation.ui.full-loader": "0.0.457",
80
+ "@teambit/ui-foundation.ui.side-bar": "0.0.461",
81
+ "@teambit/ui-foundation.ui.tree.drawer": "0.0.457",
82
+ "@teambit/explorer.ui.gallery.component-grid": "0.0.457",
83
+ "@teambit/workspace.ui.empty-workspace": "0.0.459",
84
+ "@teambit/workspace.ui.workspace-component-card": "0.0.460"
83
85
  },
84
86
  "devDependencies": {
87
+ "@types/lodash.compact": "3.0.6",
88
+ "@types/lodash": "4.14.165",
85
89
  "@types/react": "^17.0.8",
86
90
  "@types/semver": "7.3.4",
87
91
  "@types/fs-extra": "9.0.7",
88
- "@types/lodash": "4.14.165",
89
92
  "@types/react-router-dom": "5.1.7",
90
93
  "@types/pluralize": "0.0.29",
91
94
  "@types/classnames": "2.2.11",
package/workspace.ts CHANGED
@@ -16,6 +16,7 @@ import {
16
16
  AspectData,
17
17
  InvalidComponent,
18
18
  } from '@teambit/component';
19
+ import { Importer } from '@teambit/importer';
19
20
  import { ComponentScopeDirMap, Config } from '@teambit/config';
20
21
  import {
21
22
  DependencyLifecycleType,
@@ -37,13 +38,13 @@ import { isMatchNamespacePatternItem } from '@teambit/workspace.modules.match-pa
37
38
  import { RequireableComponent } from '@teambit/harmony.modules.requireable-component';
38
39
  import { ResolvedComponent } from '@teambit/harmony.modules.resolved-component';
39
40
  import type { VariantsMain } from '@teambit/variants';
40
- import { link, importAction } from '@teambit/legacy/dist/api/consumer';
41
+ import { link } from '@teambit/legacy/dist/api/consumer';
41
42
  import LegacyGraph from '@teambit/legacy/dist/scope/graph/graph';
42
43
  import { ImportOptions } from '@teambit/legacy/dist/consumer/component-ops/import-components';
43
44
  import { NothingToImport } from '@teambit/legacy/dist/consumer/exceptions';
44
45
  import { BitIds } from '@teambit/legacy/dist/bit-id';
45
46
  import { BitId, InvalidScopeName, isValidScopeName } from '@teambit/legacy-bit-id';
46
- import { LocalLaneId } from '@teambit/legacy/dist/lane-id/lane-id';
47
+ import { LocalLaneId, RemoteLaneId } from '@teambit/legacy/dist/lane-id/lane-id';
47
48
  import { Consumer, loadConsumer } from '@teambit/legacy/dist/consumer';
48
49
  import { GetBitMapComponentOptions } from '@teambit/legacy/dist/consumer/bit-map/bit-map';
49
50
  import AddComponents from '@teambit/legacy/dist/consumer/component-ops/add-components';
@@ -55,7 +56,6 @@ import { ComponentNotFound } from '@teambit/legacy/dist/scope/exceptions';
55
56
  import ComponentsList from '@teambit/legacy/dist/consumer/component/components-list';
56
57
  import { NoComponentDir } from '@teambit/legacy/dist/consumer/component/exceptions/no-component-dir';
57
58
  import { ExtensionDataList } from '@teambit/legacy/dist/consumer/config/extension-data';
58
- import { buildOneGraphForComponents } from '@teambit/legacy/dist/scope/graph/components-graph';
59
59
  import { pathIsInside } from '@teambit/legacy/dist/utils';
60
60
  import componentIdToPackageName from '@teambit/legacy/dist/utils/bit/component-id-to-package-name';
61
61
  import { PathOsBased, PathOsBasedRelative, PathOsBasedAbsolute } from '@teambit/legacy/dist/utils/path';
@@ -89,6 +89,7 @@ import {
89
89
  } from './workspace.provider';
90
90
  import { WorkspaceComponentLoader } from './workspace-component/workspace-component-loader';
91
91
  import { IncorrectEnvAspect } from './exceptions/incorrect-env-aspect';
92
+ import { GraphFromFsBuilder, ShouldIgnoreFunc } from './build-graph-from-fs';
92
93
 
93
94
  export type EjectConfResult = {
94
95
  configPath: string;
@@ -392,7 +393,7 @@ export class Workspace implements ComponentFactory {
392
393
 
393
394
  const legacyIds = ids.map((id) => id._legacy);
394
395
 
395
- const legacyGraph = await buildOneGraphForComponents(legacyIds, this.consumer);
396
+ const legacyGraph = await this.buildOneGraphForComponents(legacyIds);
396
397
  return legacyGraph;
397
398
  }
398
399
 
@@ -537,6 +538,22 @@ export class Workspace implements ComponentFactory {
537
538
  return this.consumer.getCurrentLaneId();
538
539
  }
539
540
 
541
+ /**
542
+ * if checked out to a lane, return the remote lane id (name+scope). otherwise, return null.
543
+ */
544
+ getCurrentRemoteLaneId(): RemoteLaneId | null {
545
+ const currentLane = this.getCurrentLaneId();
546
+ if (currentLane.isDefault()) {
547
+ return null;
548
+ }
549
+ const trackData = this.scope.legacyScope.lanes.getRemoteTrackedDataByLocalLane(currentLane.name);
550
+ const remoteLaneName = trackData?.remoteLane;
551
+ if (!remoteLaneName) {
552
+ return null;
553
+ }
554
+ return RemoteLaneId.from(remoteLaneName, trackData.remoteScope);
555
+ }
556
+
540
557
  getDefaultExtensions(): ExtensionDataList {
541
558
  if (!this.config.extensions) {
542
559
  return new ExtensionDataList();
@@ -608,7 +625,7 @@ export class Workspace implements ComponentFactory {
608
625
  * @param forCapsule
609
626
  */
610
627
  async importAndGetMany(ids: Array<ComponentID>, forCapsule = false): Promise<Component[]> {
611
- await this.scope.import(ids);
628
+ await this.scope.import(ids, { reFetchUnBuiltVersion: shouldReFetchUnBuiltVersion() });
612
629
  return this.componentLoader.getMany(ids, forCapsule);
613
630
  }
614
631
 
@@ -894,7 +911,7 @@ export class Workspace implements ComponentFactory {
894
911
  return componentConfigFile;
895
912
  }
896
913
 
897
- async getGraphWithoutCore(components: Component[]) {
914
+ async getAspectsGraphWithoutCore(components: Component[], isAspect?: ShouldIgnoreFunc) {
898
915
  const ids = components.map((component) => component.id._legacy);
899
916
  const coreAspectsStringIds = this.aspectLoader.getCoreAspectIds();
900
917
  const coreAspectsComponentIds = coreAspectsStringIds.map((id) => BitId.parse(id, true));
@@ -917,7 +934,7 @@ export class Workspace implements ComponentFactory {
917
934
  // 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
935
  // TODO: @gilad it causes many issues we need to find a better solution. removed for now.
919
936
  const ignoredIds = coreAspectsBitIds.concat([]);
920
- return buildOneGraphForComponents(ids, this.consumer, undefined, BitIds.fromArray(ignoredIds));
937
+ return this.buildOneGraphForComponents(ids, BitIds.fromArray(ignoredIds), isAspect);
921
938
  }
922
939
 
923
940
  /**
@@ -932,14 +949,10 @@ export class Workspace implements ComponentFactory {
932
949
  const idsWithoutCore: string[] = difference(notLoadedIds, coreAspectsStringIds);
933
950
  const componentIds = await this.resolveMultipleComponentIds(idsWithoutCore);
934
951
  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
952
 
942
- const aspects = allComponents.filter((component: Component) => {
953
+ const isAspect = async (bitId: BitId) => {
954
+ const id = await this.resolveComponentId(bitId);
955
+ const component = await this.get(id);
943
956
  let data = component.config.extensions.findExtension(EnvsAspect.id)?.data;
944
957
  if (!data) {
945
958
  // TODO: remove this once we re-export old components used to store the data here
@@ -959,11 +972,13 @@ export class Workspace implements ComponentFactory {
959
972
  }
960
973
  }
961
974
  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.
975
+ };
976
+
977
+ const graph = await this.getAspectsGraphWithoutCore(components, isAspect);
978
+ const idsStr = graph.nodes();
979
+ const compIds = await this.resolveMultipleComponentIds(idsStr);
980
+ const aspects = await this.getMany(compIds);
965
981
  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
982
  const scopeIds = scopeComps.map((aspect) => aspect.id.toString());
968
983
  const workspaceAspects = await this.requireComponents(workspaceComps);
969
984
  const workspaceManifests = await this.aspectLoader.getManifestsFromRequireableExtensions(
@@ -978,6 +993,20 @@ export class Workspace implements ComponentFactory {
978
993
  await this.aspectLoader.loadExtensionsByManifests(allManifests, throwOnError);
979
994
  }
980
995
 
996
+ /**
997
+ * Note - this gets called from Harmony only.
998
+ * returns one graph that includes all dependencies types. each edge has a label of the dependency
999
+ * type. the nodes content is the Component object.
1000
+ */
1001
+ async buildOneGraphForComponents(
1002
+ ids: BitId[],
1003
+ ignoreIds?: BitIds,
1004
+ shouldIgnoreFunc?: ShouldIgnoreFunc
1005
+ ): Promise<LegacyGraph> {
1006
+ const graphFromFsBuilder = new GraphFromFsBuilder(this, this.logger, ignoreIds, shouldIgnoreFunc);
1007
+ return graphFromFsBuilder.buildGraph(ids);
1008
+ }
1009
+
981
1010
  async resolveAspects(runtimeName?: string, componentIds?: ComponentID[]): Promise<AspectDefinition[]> {
982
1011
  let missingPaths = false;
983
1012
  const stringIds: string[] = [];
@@ -1227,6 +1256,9 @@ export class Workspace implements ComponentFactory {
1227
1256
  }
1228
1257
 
1229
1258
  async link(options?: WorkspaceLinkOptions): Promise<LinkResults> {
1259
+ if (options?.fetchObject) {
1260
+ await this.importObjects();
1261
+ }
1230
1262
  const compDirMap = await this.getComponentsDirectory([]);
1231
1263
  const mergedRootPolicy = this.dependencyResolver.getWorkspacePolicy();
1232
1264
  const linker = this.dependencyResolver.getLinker({
@@ -1294,8 +1326,9 @@ your workspace.jsonc has this component-id set. you might want to remove/change
1294
1326
  importDependenciesDirectly: false,
1295
1327
  importDependents: false,
1296
1328
  };
1329
+ const importer = new Importer(this, this.dependencyResolver);
1297
1330
  try {
1298
- const res = await importAction(importOptions, []);
1331
+ const res = await importer.import(importOptions, []);
1299
1332
  return res;
1300
1333
  } catch (err: any) {
1301
1334
  // TODO: this is a hack since the legacy throw an error, we should provide a way to not throw this error from the legacy
@@ -1468,4 +1501,17 @@ your workspace.jsonc has this component-id set. you might want to remove/change
1468
1501
  }
1469
1502
  }
1470
1503
 
1504
+ /**
1505
+ * this is a super hacky way to do it. problem is that loadAspect is running as onStart hook, where we don't
1506
+ * have the CLI fully loaded yet, so we can't get the command from the CLI aspect, we have to retrieve it from
1507
+ * process.argv.
1508
+ * in general, we don't want every command to try again and again fetching un-built versions. otherwise, every time
1509
+ * Bit loads (even bit --help), it'll fetch them and slow down everything.
1510
+ * instead, long-running commands and those that need the artifacts from the Version objects, should try to re-fetch.
1511
+ */
1512
+ function shouldReFetchUnBuiltVersion() {
1513
+ const commandsToReFetch = ['build', 'show', 'start', 'tag', 'install', 'link', 'import'];
1514
+ return commandsToReFetch.includes(process.argv[2]);
1515
+ }
1516
+
1471
1517
  export default Workspace;