@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/dist/workspace.js CHANGED
@@ -75,6 +75,16 @@ function _component() {
75
75
  return data;
76
76
  }
77
77
 
78
+ function _importer() {
79
+ const data = require("@teambit/importer");
80
+
81
+ _importer = function () {
82
+ return data;
83
+ };
84
+
85
+ return data;
86
+ }
87
+
78
88
  function _dependencyResolver() {
79
89
  const data = require("@teambit/dependency-resolver");
80
90
 
@@ -165,6 +175,16 @@ function _legacyBitId() {
165
175
  return data;
166
176
  }
167
177
 
178
+ function _laneId() {
179
+ const data = require("@teambit/legacy/dist/lane-id/lane-id");
180
+
181
+ _laneId = function () {
182
+ return data;
183
+ };
184
+
185
+ return data;
186
+ }
187
+
168
188
  function _consumer2() {
169
189
  const data = require("@teambit/legacy/dist/consumer");
170
190
 
@@ -225,16 +245,6 @@ function _extensionData() {
225
245
  return data;
226
246
  }
227
247
 
228
- function _componentsGraph() {
229
- const data = require("@teambit/legacy/dist/scope/graph/components-graph");
230
-
231
- _componentsGraph = function () {
232
- return data;
233
- };
234
-
235
- return data;
236
- }
237
-
238
248
  function _utils() {
239
249
  const data = require("@teambit/legacy/dist/utils");
240
250
 
@@ -365,6 +375,16 @@ function _incorrectEnvAspect() {
365
375
  return data;
366
376
  }
367
377
 
378
+ function _buildGraphFromFs() {
379
+ const data = require("./build-graph-from-fs");
380
+
381
+ _buildGraphFromFs = function () {
382
+ return data;
383
+ };
384
+
385
+ return data;
386
+ }
387
+
368
388
  const ComponentAdded = 'componentAdded';
369
389
  exports.ComponentAdded = ComponentAdded;
370
390
  const ComponentChanged = 'componentChanged';
@@ -640,7 +660,7 @@ class Workspace {
640
660
  async getLegacyGraph(ids) {
641
661
  if (!ids || ids.length < 1) ids = await this.listIds();
642
662
  const legacyIds = ids.map(id => id._legacy);
643
- const legacyGraph = await (0, _componentsGraph().buildOneGraphForComponents)(legacyIds, this.consumer);
663
+ const legacyGraph = await this.buildOneGraphForComponents(legacyIds);
644
664
  return legacyGraph;
645
665
  }
646
666
 
@@ -799,6 +819,27 @@ class Workspace {
799
819
  getCurrentLaneId() {
800
820
  return this.consumer.getCurrentLaneId();
801
821
  }
822
+ /**
823
+ * if checked out to a lane, return the remote lane id (name+scope). otherwise, return null.
824
+ */
825
+
826
+
827
+ getCurrentRemoteLaneId() {
828
+ const currentLane = this.getCurrentLaneId();
829
+
830
+ if (currentLane.isDefault()) {
831
+ return null;
832
+ }
833
+
834
+ const trackData = this.scope.legacyScope.lanes.getRemoteTrackedDataByLocalLane(currentLane.name);
835
+ const remoteLaneName = trackData === null || trackData === void 0 ? void 0 : trackData.remoteLane;
836
+
837
+ if (!remoteLaneName) {
838
+ return null;
839
+ }
840
+
841
+ return _laneId().RemoteLaneId.from(remoteLaneName, trackData.remoteScope);
842
+ }
802
843
 
803
844
  getDefaultExtensions() {
804
845
  if (!this.config.extensions) {
@@ -875,7 +916,9 @@ class Workspace {
875
916
 
876
917
 
877
918
  async importAndGetMany(ids, forCapsule = false) {
878
- await this.scope.import(ids);
919
+ await this.scope.import(ids, {
920
+ reFetchUnBuiltVersion: shouldReFetchUnBuiltVersion()
921
+ });
879
922
  return this.componentLoader.getMany(ids, forCapsule);
880
923
  }
881
924
  /**
@@ -1192,7 +1235,7 @@ class Workspace {
1192
1235
  return componentConfigFile;
1193
1236
  }
1194
1237
 
1195
- async getGraphWithoutCore(components) {
1238
+ async getAspectsGraphWithoutCore(components, isAspect) {
1196
1239
  const ids = components.map(component => component.id._legacy);
1197
1240
  const coreAspectsStringIds = this.aspectLoader.getCoreAspectIds();
1198
1241
  const coreAspectsComponentIds = coreAspectsStringIds.map(id => _legacyBitId().BitId.parse(id, true));
@@ -1216,7 +1259,7 @@ class Workspace {
1216
1259
 
1217
1260
 
1218
1261
  const ignoredIds = coreAspectsBitIds.concat([]);
1219
- return (0, _componentsGraph().buildOneGraphForComponents)(ids, this.consumer, undefined, _bitId().BitIds.fromArray(ignoredIds));
1262
+ return this.buildOneGraphForComponents(ids, _bitId().BitIds.fromArray(ignoredIds), isAspect);
1220
1263
  }
1221
1264
  /**
1222
1265
  * load aspects from the workspace and if not exists in the workspace, load from the scope.
@@ -1232,15 +1275,12 @@ class Workspace {
1232
1275
  const idsWithoutCore = (0, _lodash().difference)(notLoadedIds, coreAspectsStringIds);
1233
1276
  const componentIds = await this.resolveMultipleComponentIds(idsWithoutCore);
1234
1277
  const components = await this.importAndGetAspects(componentIds);
1235
- const graph = await this.getGraphWithoutCore(components);
1236
- const allIdsP = graph.nodes().map(async id => {
1237
- return this.resolveComponentId(id);
1238
- });
1239
- const allIds = await Promise.all(allIdsP);
1240
- const allComponents = await this.getMany(allIds);
1241
- const aspects = allComponents.filter(component => {
1278
+
1279
+ const isAspect = async bitId => {
1242
1280
  var _component$config$ext;
1243
1281
 
1282
+ const id = await this.resolveComponentId(bitId);
1283
+ const component = await this.get(id);
1244
1284
  let data = (_component$config$ext = component.config.extensions.findExtension(_envs().EnvsAspect.id)) === null || _component$config$ext === void 0 ? void 0 : _component$config$ext.data;
1245
1285
 
1246
1286
  if (!data) {
@@ -1264,14 +1304,16 @@ class Workspace {
1264
1304
  }
1265
1305
 
1266
1306
  return data.type === 'aspect';
1267
- }); // no need to filter core aspects as they are not included in the graph
1268
- // here we are trying to load extensions from the workspace.
1307
+ };
1269
1308
 
1309
+ const graph = await this.getAspectsGraphWithoutCore(components, isAspect);
1310
+ const idsStr = graph.nodes();
1311
+ const compIds = await this.resolveMultipleComponentIds(idsStr);
1312
+ const aspects = await this.getMany(compIds);
1270
1313
  const {
1271
1314
  workspaceComps,
1272
1315
  scopeComps
1273
- } = await this.groupComponentsByWorkspaceAndScope(aspects); // load the scope first because we might need it for custom envs that extend external aspects
1274
-
1316
+ } = await this.groupComponentsByWorkspaceAndScope(aspects);
1275
1317
  const scopeIds = scopeComps.map(aspect => aspect.id.toString());
1276
1318
  const workspaceAspects = await this.requireComponents(workspaceComps);
1277
1319
  const workspaceManifests = await this.aspectLoader.getManifestsFromRequireableExtensions(workspaceAspects, throwOnError);
@@ -1280,6 +1322,17 @@ class Workspace {
1280
1322
  const allManifests = [...scopeManifests, ...workspaceManifests];
1281
1323
  await this.aspectLoader.loadExtensionsByManifests(allManifests, throwOnError);
1282
1324
  }
1325
+ /**
1326
+ * Note - this gets called from Harmony only.
1327
+ * returns one graph that includes all dependencies types. each edge has a label of the dependency
1328
+ * type. the nodes content is the Component object.
1329
+ */
1330
+
1331
+
1332
+ async buildOneGraphForComponents(ids, ignoreIds, shouldIgnoreFunc) {
1333
+ const graphFromFsBuilder = new (_buildGraphFromFs().GraphFromFsBuilder)(this, this.logger, ignoreIds, shouldIgnoreFunc);
1334
+ return graphFromFsBuilder.buildGraph(ids);
1335
+ }
1283
1336
 
1284
1337
  async resolveAspects(runtimeName, componentIds) {
1285
1338
  let missingPaths = false;
@@ -1541,6 +1594,10 @@ class Workspace {
1541
1594
  }
1542
1595
 
1543
1596
  async link(options) {
1597
+ if (options !== null && options !== void 0 && options.fetchObject) {
1598
+ await this.importObjects();
1599
+ }
1600
+
1544
1601
  const compDirMap = await this.getComponentsDirectory([]);
1545
1602
  const mergedRootPolicy = this.dependencyResolver.getWorkspacePolicy();
1546
1603
  const linker = this.dependencyResolver.getLinker({
@@ -1615,9 +1672,10 @@ your workspace.jsonc has this component-id set. you might want to remove/change
1615
1672
  importDependenciesDirectly: false,
1616
1673
  importDependents: false
1617
1674
  };
1675
+ const importer = new (_importer().Importer)(this, this.dependencyResolver);
1618
1676
 
1619
1677
  try {
1620
- const res = await (0, _consumer().importAction)(importOptions, []);
1678
+ const res = await importer.import(importOptions, []);
1621
1679
  return res;
1622
1680
  } catch (err) {
1623
1681
  // TODO: this is a hack since the legacy throw an error, we should provide a way to not throw this error from the legacy
@@ -1803,8 +1861,23 @@ your workspace.jsonc has this component-id set. you might want to remove/change
1803
1861
  }
1804
1862
 
1805
1863
  }
1864
+ /**
1865
+ * this is a super hacky way to do it. problem is that loadAspect is running as onStart hook, where we don't
1866
+ * have the CLI fully loaded yet, so we can't get the command from the CLI aspect, we have to retrieve it from
1867
+ * process.argv.
1868
+ * in general, we don't want every command to try again and again fetching un-built versions. otherwise, every time
1869
+ * Bit loads (even bit --help), it'll fetch them and slow down everything.
1870
+ * instead, long-running commands and those that need the artifacts from the Version objects, should try to re-fetch.
1871
+ */
1872
+
1806
1873
 
1807
1874
  exports.Workspace = Workspace;
1875
+
1876
+ function shouldReFetchUnBuiltVersion() {
1877
+ const commandsToReFetch = ['build', 'show', 'start', 'tag', 'install', 'link', 'import'];
1878
+ return commandsToReFetch.includes(process.argv[2]);
1879
+ }
1880
+
1808
1881
  var _default = Workspace;
1809
1882
  exports.default = _default;
1810
1883