@teambit/lanes 0.0.296 → 0.0.299

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,20 +1,16 @@
1
1
  import { BitId } from '@teambit/legacy-bit-id';
2
- import { LaneComponent } from '@teambit/legacy/dist/scope/models/lane';
2
+ import { Lane } from '@teambit/legacy/dist/scope/models';
3
3
  import { CheckoutProps } from '@teambit/legacy/dist/consumer/versions-ops/checkout-version';
4
4
  import { ApplyVersionResults } from '@teambit/legacy/dist/consumer/versions-ops/merge-version';
5
5
  import { Workspace } from '@teambit/workspace';
6
6
  import { Logger } from '@teambit/logger';
7
7
  export declare type SwitchProps = {
8
8
  laneName: string;
9
- remoteScope?: string;
10
9
  ids?: BitId[];
11
10
  existingOnWorkspaceOnly: boolean;
12
- localLaneName?: string;
13
- remoteLaneScope?: string;
14
- remoteLaneName?: string;
15
- remoteLaneComponents?: LaneComponent[];
11
+ remoteLane?: Lane;
16
12
  localTrackedLane?: string;
17
- newLaneName?: string;
13
+ alias?: string;
18
14
  };
19
15
  export declare class LaneSwitcher {
20
16
  private workspace;
@@ -22,10 +18,12 @@ export declare class LaneSwitcher {
22
18
  private switchProps;
23
19
  private checkoutProps;
24
20
  private consumer;
21
+ private laneIdToSwitch;
25
22
  constructor(workspace: Workspace, logger: Logger, switchProps: SwitchProps, checkoutProps: CheckoutProps);
26
23
  switch(): Promise<ApplyVersionResults>;
27
24
  private populateSwitchProps;
28
25
  private populatePropsAccordingToRemoteLane;
26
+ private populatePropsAccordingToDefaultLane;
29
27
  private populatePropsAccordingToLocalLane;
30
28
  private getAllComponentsStatus;
31
29
  private saveLanesData;
@@ -111,20 +111,30 @@ function _mergeVersion() {
111
111
  return data;
112
112
  }
113
113
 
114
- function _createLane() {
115
- const data = _interopRequireDefault(require("@teambit/legacy/dist/consumer/lanes/create-lane"));
114
+ function _threeWayMerge() {
115
+ const data = _interopRequireDefault(require("@teambit/legacy/dist/consumer/versions-ops/merge-version/three-way-merge"));
116
116
 
117
- _createLane = function () {
117
+ _threeWayMerge = function () {
118
118
  return data;
119
119
  };
120
120
 
121
121
  return data;
122
122
  }
123
123
 
124
- function _threeWayMerge() {
125
- const data = _interopRequireDefault(require("@teambit/legacy/dist/consumer/versions-ops/merge-version/three-way-merge"));
124
+ function _bitError() {
125
+ const data = require("@teambit/bit-error");
126
126
 
127
- _threeWayMerge = function () {
127
+ _bitError = function () {
128
+ return data;
129
+ };
130
+
131
+ return data;
132
+ }
133
+
134
+ function _createLane() {
135
+ const data = require("./create-lane");
136
+
137
+ _createLane = function () {
128
138
  return data;
129
139
  };
130
140
 
@@ -132,12 +142,14 @@ function _threeWayMerge() {
132
142
  }
133
143
 
134
144
  class LaneSwitcher {
145
+ // populated by `this.populateSwitchProps()`
135
146
  constructor(workspace, logger, switchProps, checkoutProps) {
136
147
  this.workspace = workspace;
137
148
  this.logger = logger;
138
149
  this.switchProps = switchProps;
139
150
  this.checkoutProps = checkoutProps;
140
151
  (0, _defineProperty2().default)(this, "consumer", void 0);
152
+ (0, _defineProperty2().default)(this, "laneIdToSwitch", void 0);
141
153
  this.consumer = this.workspace.consumer;
142
154
  }
143
155
 
@@ -193,86 +205,64 @@ class LaneSwitcher {
193
205
  }
194
206
 
195
207
  async populateSwitchProps() {
196
- const lanes = await this.consumer.scope.listLanes();
208
+ const laneId = await this.consumer.scope.lanes.parseLaneIdFromString(this.switchProps.laneName);
209
+ const localLane = await this.consumer.scope.loadLane(laneId);
197
210
 
198
- const isDefaultLane = this.switchProps.laneName === _laneId().DEFAULT_LANE;
199
-
200
- const localLane = lanes.find(lane => lane.name === this.switchProps.laneName);
201
-
202
- if (isDefaultLane || localLane) {
211
+ if (laneId.isDefault()) {
212
+ this.populatePropsAccordingToDefaultLane();
213
+ } else if (localLane) {
203
214
  this.populatePropsAccordingToLocalLane(localLane);
204
215
  } else {
205
- await this.populatePropsAccordingToRemoteLane(lanes);
216
+ await this.populatePropsAccordingToRemoteLane(laneId);
206
217
  }
207
218
  }
208
219
 
209
- async populatePropsAccordingToRemoteLane(lanes) {
210
- let remoteLaneId;
211
-
212
- try {
213
- remoteLaneId = _laneId().RemoteLaneId.parse(this.switchProps.laneName);
214
- } catch (e) {
215
- throw new (_generalError().default)(`invalid lane id "${this.switchProps.laneName}", the lane ${this.switchProps.laneName} doesn't exist.`);
216
- }
220
+ async populatePropsAccordingToRemoteLane(remoteLaneId) {
221
+ this.laneIdToSwitch = remoteLaneId;
222
+ this.logger.debug(`populatePropsAccordingToRemoteLane, remoteLaneId: ${remoteLaneId.toString()}`);
217
223
 
218
- if (remoteLaneId.name === _laneId().DEFAULT_LANE) {
219
- throw new (_generalError().default)(`invalid remote lane id "${this.switchProps.laneName}". to switch to the main lane on remote,
220
- run "bit switch main" and then "bit import".`);
224
+ if (this.consumer.getCurrentLaneId().isEqual(remoteLaneId)) {
225
+ throw new (_bitError().BitError)(`already checked out to "${remoteLaneId.toString()}"`);
221
226
  } // fetch the remote to update all heads
222
227
 
223
228
 
224
- const localTrackedLane = this.consumer.scope.lanes.getLocalTrackedLaneByRemoteName(remoteLaneId.name, remoteLaneId.scope);
225
- this.logger.debug(`populatePropsAccordingToRemoteLane, remoteLaneId: ${remoteLaneId.toString()}`);
226
- this.switchProps.localLaneName = this.switchProps.newLaneName || localTrackedLane || remoteLaneId.name;
227
-
228
- if (this.consumer.getCurrentLaneId().name === this.switchProps.localLaneName) {
229
- throw new (_generalError().default)(`already checked out to "${this.switchProps.localLaneName}"`);
230
- }
231
-
232
229
  const scopeComponentImporter = _scopeComponentsImporter().default.getInstance(this.consumer.scope);
233
230
 
234
231
  const remoteLaneObjects = await scopeComponentImporter.importFromLanes([remoteLaneId]);
235
232
 
236
233
  if (remoteLaneObjects.length === 0) {
237
- throw new (_generalError().default)(`invalid lane id "${this.switchProps.laneName}", the lane ${this.switchProps.laneName} doesn't exist.`);
234
+ throw new (_bitError().BitError)(`error: the lane ${this.switchProps.laneName} doesn't exist.`);
238
235
  }
239
236
 
240
- const remoteLaneComponents = remoteLaneObjects[0].components;
241
- this.switchProps.remoteLaneName = remoteLaneId.name;
242
- this.switchProps.laneName = remoteLaneId.name;
243
- this.switchProps.remoteLaneScope = remoteLaneId.scope;
244
- this.switchProps.remoteScope = remoteLaneId.scope;
245
- this.switchProps.ids = remoteLaneComponents.map(l => l.id.changeVersion(l.head.toString()));
246
- this.switchProps.remoteLaneComponents = remoteLaneComponents;
247
- this.switchProps.localTrackedLane = localTrackedLane || undefined;
248
- const laneExistsLocally = lanes.find(l => l.name === this.switchProps.localLaneName);
249
-
250
- if (laneExistsLocally) {
251
- throw new (_generalError().default)(`unable to checkout to a remote lane ${this.switchProps.remoteScope}/${this.switchProps.laneName}.
252
- the local lane "${this.switchProps.localLaneName}" already exists, please switch to the local lane first by running "bit switch ${this.switchProps.localLaneName}"
253
- then, to merge the remote lane into the local lane, run "bit lane merge ${this.switchProps.localLaneName} --remote ${this.switchProps.remoteScope}"`);
237
+ if (remoteLaneObjects.length > 1) {
238
+ const allLanes = remoteLaneObjects.map(l => l.id()).join(', ');
239
+ throw new (_bitError().BitError)(`switching to multiple lanes is not supported. got: ${allLanes}`);
254
240
  }
255
241
 
242
+ const remoteLane = remoteLaneObjects[0];
243
+ this.switchProps.laneName = remoteLaneId.name;
244
+ this.switchProps.ids = remoteLane.components.map(l => l.id.changeVersion(l.head.toString()));
245
+ this.switchProps.localTrackedLane = this.consumer.scope.lanes.getAliasByLaneId(remoteLaneId) || undefined;
246
+ this.switchProps.remoteLane = remoteLane;
256
247
  this.logger.debug(`populatePropsAccordingToRemoteLane, completed`);
257
248
  }
258
249
 
259
- populatePropsAccordingToLocalLane(localLane) {
260
- this.switchProps.localLaneName = this.switchProps.laneName;
261
-
262
- if (this.consumer.getCurrentLaneId().name === this.switchProps.laneName) {
263
- throw new (_generalError().default)(`already checked out to "${this.switchProps.laneName}"`);
250
+ populatePropsAccordingToDefaultLane() {
251
+ if (!this.consumer.isOnLane()) {
252
+ throw new (_bitError().BitError)(`already checked out to "${this.switchProps.laneName}"`);
264
253
  }
265
254
 
266
- if (this.switchProps.laneName === _laneId().DEFAULT_LANE) {
267
- this.switchProps.ids = this.consumer.bitMap.getAuthoredAndImportedBitIdsOfDefaultLane();
268
- return;
269
- }
255
+ this.switchProps.ids = this.consumer.bitMap.getAuthoredAndImportedBitIdsOfDefaultLane();
256
+ this.laneIdToSwitch = _laneId().LaneId.from(_laneId().DEFAULT_LANE, this.consumer.scope.name);
257
+ }
270
258
 
271
- if (!localLane) {
272
- throw new (_generalError().default)(`unable to find a local lane "${this.switchProps.laneName}", to create a new lane please run "bit lane create"`);
259
+ populatePropsAccordingToLocalLane(localLane) {
260
+ if (this.consumer.getCurrentLaneId().name === this.switchProps.laneName) {
261
+ throw new (_bitError().BitError)(`already checked out to "${this.switchProps.laneName}"`);
273
262
  }
274
263
 
275
264
  this.switchProps.ids = localLane.components.map(c => c.id.changeVersion(c.head.toString()));
265
+ this.laneIdToSwitch = localLane.toLaneId();
276
266
  }
277
267
 
278
268
  async getAllComponentsStatus() {
@@ -294,55 +284,46 @@ then, to merge the remote lane into the local lane, run "bit lane merge ${this.s
294
284
  }
295
285
 
296
286
  async saveLanesData() {
297
- await saveCheckedOutLaneInfo(this.consumer, {
298
- remoteLaneScope: this.switchProps.remoteLaneScope,
299
- remoteLaneName: this.switchProps.remoteLaneName,
300
- localLaneName: this.switchProps.localLaneName,
301
- addTrackingInfo: !this.switchProps.localTrackedLane,
302
- laneComponents: this.switchProps.remoteLaneComponents
303
- });
304
- }
287
+ const saveRemoteLaneToBitmap = () => {
288
+ if (this.switchProps.remoteLane) {
289
+ this.consumer.bitMap.setRemoteLane(this.switchProps.remoteLane.toLaneId());
290
+ }
291
+ };
305
292
 
306
- }
293
+ const throwIfLaneExists = async () => {
294
+ const allLanes = await this.consumer.scope.listLanes();
307
295
 
308
- exports.LaneSwitcher = LaneSwitcher;
296
+ if (allLanes.find(l => l.toLaneId().isEqual(this.laneIdToSwitch))) {
297
+ throw new (_bitError().BitError)(`unable to checkout to lane "${this.laneIdToSwitch.toString()}".
298
+ the lane already exists. please switch to the lane and merge`);
299
+ }
300
+ };
309
301
 
310
- async function saveCheckedOutLaneInfo(consumer, opts) {
311
- const saveRemoteLaneToBitmap = () => {
312
- if (opts.remoteLaneScope) {
313
- consumer.bitMap.setRemoteLane(_laneId().RemoteLaneId.from(opts.remoteLaneName, opts.remoteLaneScope)); // add versions to lane
314
- }
315
- };
302
+ const localLaneName = this.switchProps.alias || this.laneIdToSwitch.name;
316
303
 
317
- const throwIfLaneExists = async () => {
318
- const allLanes = await consumer.scope.listLanes();
304
+ if (this.switchProps.remoteLane) {
305
+ await throwIfLaneExists();
306
+ await (0, _createLane().createLane)(this.consumer, this.laneIdToSwitch.name, this.laneIdToSwitch.scope, this.switchProps.remoteLane);
319
307
 
320
- if (allLanes.find(l => l.name === opts.localLaneName)) {
321
- throw new (_generalError().default)(`unable to checkout to lane "${opts.localLaneName}".
322
- the lane already exists. please switch to the lane and merge`);
308
+ if (!this.switchProps.localTrackedLane) {
309
+ this.consumer.scope.lanes.trackLane({
310
+ localLane: localLaneName,
311
+ remoteLane: this.laneIdToSwitch.name,
312
+ remoteScope: this.laneIdToSwitch.scope
313
+ });
314
+ }
323
315
  }
324
- };
325
316
 
326
- if (opts.remoteLaneScope) {
327
- await throwIfLaneExists();
328
- await (0, _createLane().default)(consumer, opts.localLaneName, opts.laneComponents);
329
-
330
- if (opts.addTrackingInfo) {
331
- // otherwise, it is tracked already
332
- consumer.scope.lanes.trackLane({
333
- localLane: opts.localLaneName,
334
- remoteLane: opts.remoteLaneName,
335
- remoteScope: opts.remoteLaneScope
336
- });
337
- }
317
+ saveRemoteLaneToBitmap();
318
+ this.consumer.scope.lanes.setCurrentLane(localLaneName);
319
+ const workspaceLane = localLaneName === _laneId().DEFAULT_LANE ? null : _workspaceLane().default.load(localLaneName, this.consumer.scope.path);
320
+ this.consumer.bitMap.syncWithLanes(workspaceLane);
338
321
  }
339
322
 
340
- saveRemoteLaneToBitmap();
341
- consumer.scope.lanes.setCurrentLane(opts.localLaneName);
342
- const workspaceLane = opts.localLaneName === _laneId().DEFAULT_LANE ? null : _workspaceLane().default.load(opts.localLaneName, consumer.scope.path);
343
- consumer.bitMap.syncWithLanes(workspaceLane);
344
323
  }
345
324
 
325
+ exports.LaneSwitcher = LaneSwitcher;
326
+
346
327
  async function getComponentStatus(consumer, id, switchProps) {
347
328
  const componentStatus = {
348
329
  id
@@ -409,8 +390,10 @@ async function getComponentStatus(consumer, id, switchProps) {
409
390
 
410
391
 
411
392
  const baseComponent = await modelComponent.loadVersion(currentlyUsedVersion, consumer.scope.objects);
412
- const component = await consumer.loadComponent(existingBitMapId);
413
- const isModified = await consumer.isComponentModified(baseComponent, component);
393
+ const component = await consumer.loadComponent(existingBitMapId); // don't use `consumer.isModified` here. otherwise, if there are dependency changes, the user can't discard them
394
+ // and won't be able to switch lanes.
395
+
396
+ const isModified = await consumer.isComponentSourceCodeModified(baseComponent, component);
414
397
  let mergeResults;
415
398
 
416
399
  const isHeadSameAsMain = () => {
@@ -1 +1 @@
1
- {"version":3,"sources":["switch-lanes.ts"],"names":["LaneSwitcher","constructor","workspace","logger","switchProps","checkoutProps","consumer","switch","setStatusLine","populateSwitchProps","allComponentsStatus","getAllComponentsStatus","componentWithConflict","find","component","mergeResults","hasConflicts","promptMergeOptions","mergeStrategy","GeneralError","id","toStringWithoutVersion","failedComponents","filter","componentStatus","failureMessage","map","succeededComponents","componentsResults","componentFromFS","saveLanesData","componentsWithDependencies","c","manyComponentsWriter","ManyComponentsWriter","installNpmPackages","skipNpmInstall","override","verbose","writeDists","ignoreDist","writeConfig","writePackageJson","ignorePackageJson","writeAll","appliedVersionComponents","applyVersionResult","onDestroy","components","lanes","scope","listLanes","isDefaultLane","laneName","DEFAULT_LANE","localLane","lane","name","populatePropsAccordingToLocalLane","populatePropsAccordingToRemoteLane","remoteLaneId","RemoteLaneId","parse","e","localTrackedLane","getLocalTrackedLaneByRemoteName","debug","toString","localLaneName","newLaneName","getCurrentLaneId","scopeComponentImporter","ScopeComponentsImporter","getInstance","remoteLaneObjects","importFromLanes","length","remoteLaneComponents","remoteLaneName","remoteLaneScope","remoteScope","ids","l","changeVersion","head","undefined","laneExistsLocally","bitMap","getAuthoredAndImportedBitIdsOfDefaultLane","tmp","Tmp","componentsStatusP","getComponentStatus","componentsStatus","Promise","all","clear","err","saveCheckedOutLaneInfo","addTrackingInfo","laneComponents","opts","saveRemoteLaneToBitmap","setRemoteLane","from","throwIfLaneExists","allLanes","trackLane","remoteLane","setCurrentLane","workspaceLane","WorkspaceLane","load","path","syncWithLanes","returnFailure","msg","modelComponent","getModelComponentIfExist","unmerged","objects","unmergedComponents","getEntry","resolved","version","existingBitMapId","getBitIdIfExist","ignoreVersion","componentOnLane","loadVersion","existingOnWorkspaceOnly","componentFromModel","hasVersion","currentlyUsedVersion","baseComponent","loadComponent","isModified","isComponentModified","isHeadSameAsMain","getHead","tagVersion","getTagOfRefIfExists","headVersion","otherComponent","otherLabel","currentComponent","currentLabel"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAKA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAOA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAKA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAmBO,MAAMA,YAAN,CAAmB;AAExBC,EAAAA,WA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GAAG,MAAM;AAC7B,UAAMtD,IAAI,GAAGiC,cAAc,CAACsB,OAAf,EAAb;AACA,QAAI,CAACvD,IAAL,EAAW,OAAO,KAAP;AACX,QAAI,CAACyC,gBAAgB,CAACD,OAAtB,EAA+B,OAAO,KAAP;AAC/B,UAAMgB,UAAU,GAAGvB,cAAc,CAACwB,mBAAf,CAAmCzD,IAAnC,CAAnB;AACA,UAAM0D,WAAW,GAAGF,UAAU,IAAIxD,IAAI,CAACjB,QAAL,EAAlC;AACA,WAAO0D,gBAAgB,CAACD,OAAjB,KAA6BkB,WAApC;AACD,GAPD;;AAQA,MAAIN,UAAJ,EAAgB;AACd,QAAI,CAACE,gBAAgB,EAArB,EAAyB;AACvB,YAAM,KAAIvH,uBAAJ,EACH,sBAAqBC,EAAE,CAACC,sBAAH,EAA4B,yDAD9C,CAAN;AAGD;;AAED,UAAM0H,cAAuB,GAAG,MAAM1B,cAAc,CAACY,WAAf,CACpCJ,gBAAgB,CAACD,OADmB,EACA;AACpCtH,IAAAA,QAAQ,CAAC4C,KAAT,CAAesE,OAFqB,CAAtC;AAIAzG,IAAAA,YAAY,GAAG,MAAM,8BAAc;AACjCT,MAAAA,QADiC;AAEjCyI,MAAAA,cAFiC;AAGjCC,MAAAA,UAAU,EAAEpB,OAHqB;AAIjCqB,MAAAA,gBAAgB,EAAEnI,SAJe;AAKjCoI,MAAAA,YAAY,EAAG,GAAEb,oBAAqB,WALL;AAMjCC,MAAAA;AANiC,KAAd,CAArB;AAQD,GAtEkH,CAuEnH;;;AACA,SAAO;AAAEzG,IAAAA,eAAe,EAAEf,SAAnB;AAA8BqH,IAAAA,kBAAkB,EAAEH,eAAlD;AAAmE5G,IAAAA,EAAnE;AAAuEL,IAAAA;AAAvE,GAAP;AACD","sourcesContent":["import mapSeries from 'p-map-series';\nimport { Consumer } from '@teambit/legacy/dist/consumer';\nimport GeneralError from '@teambit/legacy/dist/error/general-error';\nimport { RemoteLaneId, DEFAULT_LANE } from '@teambit/lane-id';\nimport ScopeComponentsImporter from '@teambit/legacy/dist/scope/component-ops/scope-components-importer';\nimport { BitId } from '@teambit/legacy-bit-id';\nimport { ComponentWithDependencies } from '@teambit/legacy/dist/scope';\nimport { Version, Lane } from '@teambit/legacy/dist/scope/models';\nimport { LaneComponent } from '@teambit/legacy/dist/scope/models/lane';\nimport { Tmp } from '@teambit/legacy/dist/scope/repositories';\nimport WorkspaceLane from '@teambit/legacy/dist/consumer/bit-map/workspace-lane';\nimport {\n applyVersion,\n ComponentStatus,\n CheckoutProps,\n deleteFilesIfNeeded,\n markFilesToBeRemovedIfNeeded,\n} from '@teambit/legacy/dist/consumer/versions-ops/checkout-version';\nimport ManyComponentsWriter from '@teambit/legacy/dist/consumer/component-ops/many-components-writer';\nimport {\n FailedComponents,\n getMergeStrategyInteractive,\n ApplyVersionResults,\n} from '@teambit/legacy/dist/consumer/versions-ops/merge-version';\nimport createNewLane from '@teambit/legacy/dist/consumer/lanes/create-lane';\nimport threeWayMerge, {\n MergeResultsThreeWay,\n} from '@teambit/legacy/dist/consumer/versions-ops/merge-version/three-way-merge';\nimport { Workspace } from '@teambit/workspace';\nimport { Logger } from '@teambit/logger';\n\nexport type SwitchProps = {\n laneName: string;\n remoteScope?: string;\n ids?: BitId[];\n existingOnWorkspaceOnly: boolean;\n localLaneName?: string;\n remoteLaneScope?: string;\n remoteLaneName?: string;\n remoteLaneComponents?: LaneComponent[];\n localTrackedLane?: string;\n newLaneName?: string;\n};\n\nexport class LaneSwitcher {\n private consumer: Consumer;\n constructor(\n private workspace: Workspace,\n private logger: Logger,\n private switchProps: SwitchProps,\n private checkoutProps: CheckoutProps\n ) {\n this.consumer = this.workspace.consumer;\n }\n\n async switch(): Promise<ApplyVersionResults> {\n this.logger.setStatusLine(`switching lanes`);\n await this.populateSwitchProps();\n const allComponentsStatus: ComponentStatus[] = await this.getAllComponentsStatus();\n const componentWithConflict = allComponentsStatus.find(\n (component) => component.mergeResults && component.mergeResults.hasConflicts\n );\n if (componentWithConflict) {\n if (!this.checkoutProps.promptMergeOptions && !this.checkoutProps.mergeStrategy) {\n throw new GeneralError(\n `automatic merge has failed for component ${componentWithConflict.id.toStringWithoutVersion()}.\\nplease use \"--manual\" to manually merge changes or use \"--theirs / --ours\" to choose one of the conflicted versions`\n );\n }\n if (!this.checkoutProps.mergeStrategy) this.checkoutProps.mergeStrategy = await getMergeStrategyInteractive();\n }\n const failedComponents: FailedComponents[] = allComponentsStatus\n .filter((componentStatus) => componentStatus.failureMessage)\n .map((componentStatus) => ({ id: componentStatus.id, failureMessage: componentStatus.failureMessage as string }));\n\n const succeededComponents = allComponentsStatus.filter((componentStatus) => !componentStatus.failureMessage);\n // do not use Promise.all for applyVersion. otherwise, it'll write all components in parallel,\n // which can be an issue when some components are also dependencies of others\n const componentsResults = await mapSeries(succeededComponents, ({ id, componentFromFS, mergeResults }) => {\n return applyVersion(this.consumer, id, componentFromFS, mergeResults, this.checkoutProps);\n });\n\n markFilesToBeRemovedIfNeeded(succeededComponents, componentsResults);\n\n await this.saveLanesData();\n\n const componentsWithDependencies = componentsResults\n .map((c) => c.component)\n .filter((c) => c) as ComponentWithDependencies[];\n\n const manyComponentsWriter = new ManyComponentsWriter({\n consumer: this.consumer,\n componentsWithDependencies,\n installNpmPackages: !this.checkoutProps.skipNpmInstall,\n override: true,\n verbose: this.checkoutProps.verbose,\n writeDists: !this.checkoutProps.ignoreDist,\n writeConfig: this.checkoutProps.writeConfig,\n writePackageJson: !this.checkoutProps.ignorePackageJson,\n });\n await manyComponentsWriter.writeAll();\n await deleteFilesIfNeeded(componentsResults, this.consumer);\n\n const appliedVersionComponents = componentsResults.map((c) => c.applyVersionResult);\n\n await this.consumer.onDestroy();\n\n return { components: appliedVersionComponents, failedComponents };\n }\n\n private async populateSwitchProps() {\n const lanes = await this.consumer.scope.listLanes();\n const isDefaultLane = this.switchProps.laneName === DEFAULT_LANE;\n\n const localLane = lanes.find((lane) => lane.name === this.switchProps.laneName);\n\n if (isDefaultLane || localLane) {\n this.populatePropsAccordingToLocalLane(localLane);\n } else {\n await this.populatePropsAccordingToRemoteLane(lanes);\n }\n }\n\n private async populatePropsAccordingToRemoteLane(lanes: Lane[]) {\n let remoteLaneId: RemoteLaneId;\n try {\n remoteLaneId = RemoteLaneId.parse(this.switchProps.laneName);\n } catch (e) {\n throw new GeneralError(\n `invalid lane id \"${this.switchProps.laneName}\", the lane ${this.switchProps.laneName} doesn't exist.`\n );\n }\n if (remoteLaneId.name === DEFAULT_LANE) {\n throw new GeneralError(`invalid remote lane id \"${this.switchProps.laneName}\". to switch to the main lane on remote,\n run \"bit switch main\" and then \"bit import\".`);\n }\n // fetch the remote to update all heads\n const localTrackedLane = this.consumer.scope.lanes.getLocalTrackedLaneByRemoteName(\n remoteLaneId.name,\n remoteLaneId.scope as string\n );\n this.logger.debug(`populatePropsAccordingToRemoteLane, remoteLaneId: ${remoteLaneId.toString()}`);\n this.switchProps.localLaneName = this.switchProps.newLaneName || localTrackedLane || remoteLaneId.name;\n if (this.consumer.getCurrentLaneId().name === this.switchProps.localLaneName) {\n throw new GeneralError(`already checked out to \"${this.switchProps.localLaneName}\"`);\n }\n const scopeComponentImporter = ScopeComponentsImporter.getInstance(this.consumer.scope);\n const remoteLaneObjects = await scopeComponentImporter.importFromLanes([remoteLaneId]);\n if (remoteLaneObjects.length === 0) {\n throw new GeneralError(\n `invalid lane id \"${this.switchProps.laneName}\", the lane ${this.switchProps.laneName} doesn't exist.`\n );\n }\n const remoteLaneComponents = remoteLaneObjects[0].components;\n this.switchProps.remoteLaneName = remoteLaneId.name;\n this.switchProps.laneName = remoteLaneId.name;\n this.switchProps.remoteLaneScope = remoteLaneId.scope;\n this.switchProps.remoteScope = remoteLaneId.scope;\n this.switchProps.ids = remoteLaneComponents.map((l) => l.id.changeVersion(l.head.toString()));\n this.switchProps.remoteLaneComponents = remoteLaneComponents;\n this.switchProps.localTrackedLane = localTrackedLane || undefined;\n const laneExistsLocally = lanes.find((l) => l.name === this.switchProps.localLaneName);\n if (laneExistsLocally) {\n throw new GeneralError(`unable to checkout to a remote lane ${this.switchProps.remoteScope}/${this.switchProps.laneName}.\nthe local lane \"${this.switchProps.localLaneName}\" already exists, please switch to the local lane first by running \"bit switch ${this.switchProps.localLaneName}\"\nthen, to merge the remote lane into the local lane, run \"bit lane merge ${this.switchProps.localLaneName} --remote ${this.switchProps.remoteScope}\"`);\n }\n this.logger.debug(`populatePropsAccordingToRemoteLane, completed`);\n }\n\n private populatePropsAccordingToLocalLane(localLane: Lane | undefined) {\n this.switchProps.localLaneName = this.switchProps.laneName;\n if (this.consumer.getCurrentLaneId().name === this.switchProps.laneName) {\n throw new GeneralError(`already checked out to \"${this.switchProps.laneName}\"`);\n }\n if (this.switchProps.laneName === DEFAULT_LANE) {\n this.switchProps.ids = this.consumer.bitMap.getAuthoredAndImportedBitIdsOfDefaultLane();\n return;\n }\n if (!localLane) {\n throw new GeneralError(\n `unable to find a local lane \"${this.switchProps.laneName}\", to create a new lane please run \"bit lane create\"`\n );\n }\n this.switchProps.ids = localLane.components.map((c) => c.id.changeVersion(c.head.toString()));\n }\n\n private async getAllComponentsStatus(): Promise<ComponentStatus[]> {\n const { ids } = this.switchProps;\n const tmp = new Tmp(this.consumer.scope);\n try {\n const componentsStatusP = (ids as BitId[]).map((id) => getComponentStatus(this.consumer, id, this.switchProps));\n const componentsStatus = await Promise.all(componentsStatusP);\n await tmp.clear();\n // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!\n return componentsStatus;\n } catch (err: any) {\n await tmp.clear();\n throw err;\n }\n }\n private async saveLanesData() {\n await saveCheckedOutLaneInfo(this.consumer, {\n remoteLaneScope: this.switchProps.remoteLaneScope,\n remoteLaneName: this.switchProps.remoteLaneName,\n localLaneName: this.switchProps.localLaneName,\n addTrackingInfo: !this.switchProps.localTrackedLane,\n laneComponents: this.switchProps.remoteLaneComponents,\n });\n }\n}\n\nasync function saveCheckedOutLaneInfo(\n consumer: Consumer,\n opts: {\n remoteLaneScope?: string;\n remoteLaneName?: string;\n localLaneName?: string;\n addTrackingInfo?: boolean;\n laneComponents?: LaneComponent[];\n }\n) {\n const saveRemoteLaneToBitmap = () => {\n if (opts.remoteLaneScope) {\n consumer.bitMap.setRemoteLane(RemoteLaneId.from(opts.remoteLaneName as string, opts.remoteLaneScope));\n // add versions to lane\n }\n };\n const throwIfLaneExists = async () => {\n const allLanes = await consumer.scope.listLanes();\n if (allLanes.find((l) => l.name === opts.localLaneName)) {\n throw new GeneralError(`unable to checkout to lane \"${opts.localLaneName}\".\nthe lane already exists. please switch to the lane and merge`);\n }\n };\n\n if (opts.remoteLaneScope) {\n await throwIfLaneExists();\n await createNewLane(consumer, opts.localLaneName as string, opts.laneComponents);\n if (opts.addTrackingInfo) {\n // otherwise, it is tracked already\n consumer.scope.lanes.trackLane({\n localLane: opts.localLaneName as string,\n remoteLane: opts.remoteLaneName as string,\n remoteScope: opts.remoteLaneScope as string,\n });\n }\n }\n\n saveRemoteLaneToBitmap();\n consumer.scope.lanes.setCurrentLane(opts.localLaneName as string);\n const workspaceLane =\n opts.localLaneName === DEFAULT_LANE ? null : WorkspaceLane.load(opts.localLaneName as string, consumer.scope.path);\n consumer.bitMap.syncWithLanes(workspaceLane);\n}\n\nasync function getComponentStatus(consumer: Consumer, id: BitId, switchProps: SwitchProps): Promise<ComponentStatus> {\n const componentStatus: ComponentStatus = { id };\n const returnFailure = (msg: string) => {\n componentStatus.failureMessage = msg;\n return componentStatus;\n };\n const modelComponent = await consumer.scope.getModelComponentIfExist(id);\n if (!modelComponent) {\n return returnFailure(`component ${id.toString()} had never imported`);\n }\n const unmerged = consumer.scope.objects.unmergedComponents.getEntry(id.name);\n if (unmerged && unmerged.resolved === false) {\n return returnFailure(\n `component ${id.toStringWithoutVersion()} has conflicts that need to be resolved first, please use bit merge --resolve/--abort`\n );\n }\n const version = id.version;\n if (!version) {\n return returnFailure(`component doesn't have any snaps on ${DEFAULT_LANE}`);\n }\n const existingBitMapId = consumer.bitMap.getBitIdIfExist(id, { ignoreVersion: true });\n const componentOnLane: Version = await modelComponent.loadVersion(version, consumer.scope.objects);\n if (!existingBitMapId) {\n if (switchProps.existingOnWorkspaceOnly) {\n return returnFailure(`component ${id.toStringWithoutVersion()} is not in the workspace`);\n }\n return { componentFromFS: undefined, componentFromModel: componentOnLane, id, mergeResults: null };\n }\n if (!existingBitMapId.hasVersion()) {\n // happens when switching from main to a lane and a component was snapped on the lane.\n // in the .bitmap file, the version is \"latest\" or empty. so we just need to write the component according to the\n // model. we don't care about the componentFromFS\n return { componentFromFS: undefined, componentFromModel: componentOnLane, id, mergeResults: null };\n }\n const currentlyUsedVersion = existingBitMapId.version;\n if (currentlyUsedVersion === version) {\n return returnFailure(`component ${id.toStringWithoutVersion()} is already at version ${version}`);\n }\n // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!\n const baseComponent: Version = await modelComponent.loadVersion(currentlyUsedVersion, consumer.scope.objects);\n const component = await consumer.loadComponent(existingBitMapId);\n const isModified = await consumer.isComponentModified(baseComponent, component);\n let mergeResults: MergeResultsThreeWay | null | undefined;\n const isHeadSameAsMain = () => {\n const head = modelComponent.getHead();\n if (!head) return false;\n if (!existingBitMapId.version) return false;\n const tagVersion = modelComponent.getTagOfRefIfExists(head);\n const headVersion = tagVersion || head.toString();\n return existingBitMapId.version === headVersion;\n };\n if (isModified) {\n if (!isHeadSameAsMain()) {\n throw new GeneralError(\n `unable to checkout ${id.toStringWithoutVersion()}, the component is modified and belongs to another lane`\n );\n }\n\n const otherComponent: Version = await modelComponent.loadVersion(\n existingBitMapId.version as string, // we are here because the head is same as main. so, existingBitMapId.version must be set\n consumer.scope.objects\n );\n mergeResults = await threeWayMerge({\n consumer,\n otherComponent,\n otherLabel: version,\n currentComponent: component,\n currentLabel: `${currentlyUsedVersion} modified`,\n baseComponent,\n });\n }\n // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!\n return { componentFromFS: component, componentFromModel: componentOnLane, id, mergeResults };\n}\n"]}
1
+ {"version":3,"sources":["switch-lanes.ts"],"names":["LaneSwitcher","constructor","workspace","logger","switchProps","checkoutProps","consumer","switch","setStatusLine","populateSwitchProps","allComponentsStatus","getAllComponentsStatus","componentWithConflict","find","component","mergeResults","hasConflicts","promptMergeOptions","mergeStrategy","GeneralError","id","toStringWithoutVersion","failedComponents","filter","componentStatus","failureMessage","map","succeededComponents","componentsResults","componentFromFS","saveLanesData","componentsWithDependencies","c","manyComponentsWriter","ManyComponentsWriter","installNpmPackages","skipNpmInstall","override","verbose","writeDists","ignoreDist","writeConfig","writePackageJson","ignorePackageJson","writeAll","appliedVersionComponents","applyVersionResult","onDestroy","components","laneId","scope","lanes","parseLaneIdFromString","laneName","localLane","loadLane","isDefault","populatePropsAccordingToDefaultLane","populatePropsAccordingToLocalLane","populatePropsAccordingToRemoteLane","remoteLaneId","laneIdToSwitch","debug","toString","getCurrentLaneId","isEqual","BitError","scopeComponentImporter","ScopeComponentsImporter","getInstance","remoteLaneObjects","importFromLanes","length","allLanes","l","join","remoteLane","name","ids","changeVersion","head","localTrackedLane","getAliasByLaneId","undefined","isOnLane","bitMap","getAuthoredAndImportedBitIdsOfDefaultLane","LaneId","from","DEFAULT_LANE","toLaneId","tmp","Tmp","componentsStatusP","getComponentStatus","componentsStatus","Promise","all","clear","err","saveRemoteLaneToBitmap","setRemoteLane","throwIfLaneExists","listLanes","localLaneName","alias","trackLane","remoteScope","setCurrentLane","workspaceLane","WorkspaceLane","load","path","syncWithLanes","returnFailure","msg","modelComponent","getModelComponentIfExist","unmerged","objects","unmergedComponents","getEntry","resolved","version","existingBitMapId","getBitIdIfExist","ignoreVersion","componentOnLane","loadVersion","existingOnWorkspaceOnly","componentFromModel","hasVersion","currentlyUsedVersion","baseComponent","loadComponent","isModified","isComponentSourceCodeModified","isHeadSameAsMain","getHead","tagVersion","getTagOfRefIfExists","headVersion","otherComponent","otherLabel","currentComponent","currentLabel"],"mappings":";;;;;;;;;;;;;;;;;;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CACpCJ,gBAAgB,CAACD,OADmB,EACA;AACpCrH,IAAAA,QAAQ,CAAC4C,KAAT,CAAeqE,OAFqB,CAAtC;AAIAxG,IAAAA,YAAY,GAAG,MAAM,8BAAc;AACjCT,MAAAA,QADiC;AAEjCwI,MAAAA,cAFiC;AAGjCC,MAAAA,UAAU,EAAEpB,OAHqB;AAIjCqB,MAAAA,gBAAgB,EAAElI,SAJe;AAKjCmI,MAAAA,YAAY,EAAG,GAAEb,oBAAqB,WALL;AAMjCC,MAAAA;AANiC,KAAd,CAArB;AAQD,GAxEkH,CAyEnH;;;AACA,SAAO;AAAExG,IAAAA,eAAe,EAAEf,SAAnB;AAA8BoH,IAAAA,kBAAkB,EAAEH,eAAlD;AAAmE3G,IAAAA,EAAnE;AAAuEL,IAAAA;AAAvE,GAAP;AACD","sourcesContent":["import mapSeries from 'p-map-series';\nimport { Consumer } from '@teambit/legacy/dist/consumer';\nimport GeneralError from '@teambit/legacy/dist/error/general-error';\nimport { LaneId, DEFAULT_LANE } from '@teambit/lane-id';\nimport ScopeComponentsImporter from '@teambit/legacy/dist/scope/component-ops/scope-components-importer';\nimport { BitId } from '@teambit/legacy-bit-id';\nimport { ComponentWithDependencies } from '@teambit/legacy/dist/scope';\nimport { Version, Lane } from '@teambit/legacy/dist/scope/models';\nimport { Tmp } from '@teambit/legacy/dist/scope/repositories';\nimport WorkspaceLane from '@teambit/legacy/dist/consumer/bit-map/workspace-lane';\nimport {\n applyVersion,\n ComponentStatus,\n CheckoutProps,\n deleteFilesIfNeeded,\n markFilesToBeRemovedIfNeeded,\n} from '@teambit/legacy/dist/consumer/versions-ops/checkout-version';\nimport ManyComponentsWriter from '@teambit/legacy/dist/consumer/component-ops/many-components-writer';\nimport {\n FailedComponents,\n getMergeStrategyInteractive,\n ApplyVersionResults,\n} from '@teambit/legacy/dist/consumer/versions-ops/merge-version';\nimport threeWayMerge, {\n MergeResultsThreeWay,\n} from '@teambit/legacy/dist/consumer/versions-ops/merge-version/three-way-merge';\nimport { Workspace } from '@teambit/workspace';\nimport { Logger } from '@teambit/logger';\nimport { BitError } from '@teambit/bit-error';\nimport { createLane } from './create-lane';\n\nexport type SwitchProps = {\n laneName: string;\n ids?: BitId[];\n existingOnWorkspaceOnly: boolean;\n remoteLane?: Lane;\n localTrackedLane?: string;\n alias?: string;\n};\n\nexport class LaneSwitcher {\n private consumer: Consumer;\n private laneIdToSwitch: LaneId; // populated by `this.populateSwitchProps()`\n constructor(\n private workspace: Workspace,\n private logger: Logger,\n private switchProps: SwitchProps,\n private checkoutProps: CheckoutProps\n ) {\n this.consumer = this.workspace.consumer;\n }\n\n async switch(): Promise<ApplyVersionResults> {\n this.logger.setStatusLine(`switching lanes`);\n await this.populateSwitchProps();\n const allComponentsStatus: ComponentStatus[] = await this.getAllComponentsStatus();\n const componentWithConflict = allComponentsStatus.find(\n (component) => component.mergeResults && component.mergeResults.hasConflicts\n );\n if (componentWithConflict) {\n if (!this.checkoutProps.promptMergeOptions && !this.checkoutProps.mergeStrategy) {\n throw new GeneralError(\n `automatic merge has failed for component ${componentWithConflict.id.toStringWithoutVersion()}.\\nplease use \"--manual\" to manually merge changes or use \"--theirs / --ours\" to choose one of the conflicted versions`\n );\n }\n if (!this.checkoutProps.mergeStrategy) this.checkoutProps.mergeStrategy = await getMergeStrategyInteractive();\n }\n const failedComponents: FailedComponents[] = allComponentsStatus\n .filter((componentStatus) => componentStatus.failureMessage)\n .map((componentStatus) => ({ id: componentStatus.id, failureMessage: componentStatus.failureMessage as string }));\n\n const succeededComponents = allComponentsStatus.filter((componentStatus) => !componentStatus.failureMessage);\n // do not use Promise.all for applyVersion. otherwise, it'll write all components in parallel,\n // which can be an issue when some components are also dependencies of others\n const componentsResults = await mapSeries(succeededComponents, ({ id, componentFromFS, mergeResults }) => {\n return applyVersion(this.consumer, id, componentFromFS, mergeResults, this.checkoutProps);\n });\n\n markFilesToBeRemovedIfNeeded(succeededComponents, componentsResults);\n\n await this.saveLanesData();\n\n const componentsWithDependencies = componentsResults\n .map((c) => c.component)\n .filter((c) => c) as ComponentWithDependencies[];\n\n const manyComponentsWriter = new ManyComponentsWriter({\n consumer: this.consumer,\n componentsWithDependencies,\n installNpmPackages: !this.checkoutProps.skipNpmInstall,\n override: true,\n verbose: this.checkoutProps.verbose,\n writeDists: !this.checkoutProps.ignoreDist,\n writeConfig: this.checkoutProps.writeConfig,\n writePackageJson: !this.checkoutProps.ignorePackageJson,\n });\n await manyComponentsWriter.writeAll();\n await deleteFilesIfNeeded(componentsResults, this.consumer);\n\n const appliedVersionComponents = componentsResults.map((c) => c.applyVersionResult);\n\n await this.consumer.onDestroy();\n\n return { components: appliedVersionComponents, failedComponents };\n }\n\n private async populateSwitchProps() {\n const laneId = await this.consumer.scope.lanes.parseLaneIdFromString(this.switchProps.laneName);\n\n const localLane = await this.consumer.scope.loadLane(laneId);\n if (laneId.isDefault()) {\n this.populatePropsAccordingToDefaultLane();\n } else if (localLane) {\n this.populatePropsAccordingToLocalLane(localLane);\n } else {\n await this.populatePropsAccordingToRemoteLane(laneId);\n }\n }\n\n private async populatePropsAccordingToRemoteLane(remoteLaneId: LaneId) {\n this.laneIdToSwitch = remoteLaneId;\n this.logger.debug(`populatePropsAccordingToRemoteLane, remoteLaneId: ${remoteLaneId.toString()}`);\n if (this.consumer.getCurrentLaneId().isEqual(remoteLaneId)) {\n throw new BitError(`already checked out to \"${remoteLaneId.toString()}\"`);\n }\n // fetch the remote to update all heads\n const scopeComponentImporter = ScopeComponentsImporter.getInstance(this.consumer.scope);\n const remoteLaneObjects = await scopeComponentImporter.importFromLanes([remoteLaneId]);\n if (remoteLaneObjects.length === 0) {\n throw new BitError(`error: the lane ${this.switchProps.laneName} doesn't exist.`);\n }\n if (remoteLaneObjects.length > 1) {\n const allLanes = remoteLaneObjects.map((l) => l.id()).join(', ');\n throw new BitError(`switching to multiple lanes is not supported. got: ${allLanes}`);\n }\n const remoteLane = remoteLaneObjects[0];\n this.switchProps.laneName = remoteLaneId.name;\n this.switchProps.ids = remoteLane.components.map((l) => l.id.changeVersion(l.head.toString()));\n this.switchProps.localTrackedLane = this.consumer.scope.lanes.getAliasByLaneId(remoteLaneId) || undefined;\n this.switchProps.remoteLane = remoteLane;\n this.logger.debug(`populatePropsAccordingToRemoteLane, completed`);\n }\n\n private populatePropsAccordingToDefaultLane() {\n if (!this.consumer.isOnLane()) {\n throw new BitError(`already checked out to \"${this.switchProps.laneName}\"`);\n }\n this.switchProps.ids = this.consumer.bitMap.getAuthoredAndImportedBitIdsOfDefaultLane();\n this.laneIdToSwitch = LaneId.from(DEFAULT_LANE, this.consumer.scope.name);\n }\n\n private populatePropsAccordingToLocalLane(localLane: Lane) {\n if (this.consumer.getCurrentLaneId().name === this.switchProps.laneName) {\n throw new BitError(`already checked out to \"${this.switchProps.laneName}\"`);\n }\n this.switchProps.ids = localLane.components.map((c) => c.id.changeVersion(c.head.toString()));\n this.laneIdToSwitch = localLane.toLaneId();\n }\n\n private async getAllComponentsStatus(): Promise<ComponentStatus[]> {\n const { ids } = this.switchProps;\n const tmp = new Tmp(this.consumer.scope);\n try {\n const componentsStatusP = (ids as BitId[]).map((id) => getComponentStatus(this.consumer, id, this.switchProps));\n const componentsStatus = await Promise.all(componentsStatusP);\n await tmp.clear();\n // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!\n return componentsStatus;\n } catch (err: any) {\n await tmp.clear();\n throw err;\n }\n }\n\n private async saveLanesData() {\n const saveRemoteLaneToBitmap = () => {\n if (this.switchProps.remoteLane) {\n this.consumer.bitMap.setRemoteLane(this.switchProps.remoteLane.toLaneId());\n }\n };\n const throwIfLaneExists = async () => {\n const allLanes = await this.consumer.scope.listLanes();\n if (allLanes.find((l) => l.toLaneId().isEqual(this.laneIdToSwitch))) {\n throw new BitError(`unable to checkout to lane \"${this.laneIdToSwitch.toString()}\".\n the lane already exists. please switch to the lane and merge`);\n }\n };\n\n const localLaneName = this.switchProps.alias || this.laneIdToSwitch.name;\n if (this.switchProps.remoteLane) {\n await throwIfLaneExists();\n await createLane(this.consumer, this.laneIdToSwitch.name, this.laneIdToSwitch.scope, this.switchProps.remoteLane);\n if (!this.switchProps.localTrackedLane) {\n this.consumer.scope.lanes.trackLane({\n localLane: localLaneName,\n remoteLane: this.laneIdToSwitch.name,\n remoteScope: this.laneIdToSwitch.scope,\n });\n }\n }\n\n saveRemoteLaneToBitmap();\n this.consumer.scope.lanes.setCurrentLane(localLaneName);\n const workspaceLane =\n localLaneName === DEFAULT_LANE ? null : WorkspaceLane.load(localLaneName, this.consumer.scope.path);\n this.consumer.bitMap.syncWithLanes(workspaceLane);\n }\n}\n\nasync function getComponentStatus(consumer: Consumer, id: BitId, switchProps: SwitchProps): Promise<ComponentStatus> {\n const componentStatus: ComponentStatus = { id };\n const returnFailure = (msg: string) => {\n componentStatus.failureMessage = msg;\n return componentStatus;\n };\n const modelComponent = await consumer.scope.getModelComponentIfExist(id);\n if (!modelComponent) {\n return returnFailure(`component ${id.toString()} had never imported`);\n }\n const unmerged = consumer.scope.objects.unmergedComponents.getEntry(id.name);\n if (unmerged && unmerged.resolved === false) {\n return returnFailure(\n `component ${id.toStringWithoutVersion()} has conflicts that need to be resolved first, please use bit merge --resolve/--abort`\n );\n }\n const version = id.version;\n if (!version) {\n return returnFailure(`component doesn't have any snaps on ${DEFAULT_LANE}`);\n }\n const existingBitMapId = consumer.bitMap.getBitIdIfExist(id, { ignoreVersion: true });\n const componentOnLane: Version = await modelComponent.loadVersion(version, consumer.scope.objects);\n if (!existingBitMapId) {\n if (switchProps.existingOnWorkspaceOnly) {\n return returnFailure(`component ${id.toStringWithoutVersion()} is not in the workspace`);\n }\n return { componentFromFS: undefined, componentFromModel: componentOnLane, id, mergeResults: null };\n }\n if (!existingBitMapId.hasVersion()) {\n // happens when switching from main to a lane and a component was snapped on the lane.\n // in the .bitmap file, the version is \"latest\" or empty. so we just need to write the component according to the\n // model. we don't care about the componentFromFS\n return { componentFromFS: undefined, componentFromModel: componentOnLane, id, mergeResults: null };\n }\n const currentlyUsedVersion = existingBitMapId.version;\n if (currentlyUsedVersion === version) {\n return returnFailure(`component ${id.toStringWithoutVersion()} is already at version ${version}`);\n }\n // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!\n const baseComponent: Version = await modelComponent.loadVersion(currentlyUsedVersion, consumer.scope.objects);\n const component = await consumer.loadComponent(existingBitMapId);\n // don't use `consumer.isModified` here. otherwise, if there are dependency changes, the user can't discard them\n // and won't be able to switch lanes.\n const isModified = await consumer.isComponentSourceCodeModified(baseComponent, component);\n let mergeResults: MergeResultsThreeWay | null | undefined;\n const isHeadSameAsMain = () => {\n const head = modelComponent.getHead();\n if (!head) return false;\n if (!existingBitMapId.version) return false;\n const tagVersion = modelComponent.getTagOfRefIfExists(head);\n const headVersion = tagVersion || head.toString();\n return existingBitMapId.version === headVersion;\n };\n if (isModified) {\n if (!isHeadSameAsMain()) {\n throw new GeneralError(\n `unable to checkout ${id.toStringWithoutVersion()}, the component is modified and belongs to another lane`\n );\n }\n\n const otherComponent: Version = await modelComponent.loadVersion(\n existingBitMapId.version as string, // we are here because the head is same as main. so, existingBitMapId.version must be set\n consumer.scope.objects\n );\n mergeResults = await threeWayMerge({\n consumer,\n otherComponent,\n otherLabel: version,\n currentComponent: component,\n currentLabel: `${currentlyUsedVersion} modified`,\n baseComponent,\n });\n }\n // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!\n return { componentFromFS: component, componentFromModel: componentOnLane, id, mergeResults };\n}\n"]}
@@ -10,8 +10,8 @@ export declare class SwitchCmd implements Command {
10
10
  options: CommandOptions;
11
11
  loader: boolean;
12
12
  constructor(lanes: LanesMain);
13
- report([lane]: [string], { as, merge, getAll, skipDependencyInstallation, json, }: {
14
- as?: string;
13
+ report([lane]: [string], { alias, merge, getAll, skipDependencyInstallation, json, }: {
14
+ alias?: string;
15
15
  merge?: MergeStrategy;
16
16
  getAll?: boolean;
17
17
  skipDependencyInstallation?: boolean;
@@ -48,12 +48,12 @@ class SwitchCmd {
48
48
  (0, _defineProperty2().default)(this, "description", `switch to the specified lane`);
49
49
  (0, _defineProperty2().default)(this, "private", true);
50
50
  (0, _defineProperty2().default)(this, "alias", '');
51
- (0, _defineProperty2().default)(this, "options", [['n', 'as <as>', 'relevant when the specified lane is a remote late. name a local lane differently than the remote lane'], ['m', 'merge [strategy]', 'merge local changes with the checked out version. strategy should be "theirs", "ours" or "manual"'], ['a', 'get-all', 'checkout all components in a lane include ones that do not exist in the workspace'], ['', 'skip-dependency-installation', 'do not install packages of the imported components'], ['j', 'json', 'return the output as JSON']]);
51
+ (0, _defineProperty2().default)(this, "options", [['n', 'alias <string>', 'relevant when the specified lane is a remote late. name a local lane differently than the remote lane'], ['m', 'merge [strategy]', 'merge local changes with the checked out version. strategy should be "theirs", "ours" or "manual"'], ['a', 'get-all', 'checkout all components in a lane include ones that do not exist in the workspace'], ['', 'skip-dependency-installation', 'do not install packages of the imported components'], ['j', 'json', 'return the output as JSON']]);
52
52
  (0, _defineProperty2().default)(this, "loader", true);
53
53
  }
54
54
 
55
55
  async report([lane], {
56
- as,
56
+ alias,
57
57
  merge,
58
58
  getAll = false,
59
59
  skipDependencyInstallation = false,
@@ -63,7 +63,7 @@ class SwitchCmd {
63
63
  components,
64
64
  failedComponents
65
65
  } = await this.lanes.switchLanes(lane, {
66
- newLaneName: as,
66
+ alias,
67
67
  merge,
68
68
  getAll,
69
69
  skipDependencyInstallation
@@ -1 +1 @@
1
- {"version":3,"sources":["switch.cmd.ts"],"names":["SwitchCmd","constructor","lanes","report","lane","as","merge","getAll","skipDependencyInstallation","json","components","failedComponents","switchLanes","newLaneName","JSON","stringify","getFailureOutput","length","title","body","map","failedComponent","chalk","bold","id","toString","red","failureMessage","join","getSuccessfulOutput","laneSwitched","green","component","componentName","toStringWithoutVersion","version","componentsStr","failedOutput","successOutput"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA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sB,aAAa,GAAGT,mBAAmB,EAAzC;AACA,WAAOQ,YAAY,GAAGC,aAAtB;AACD;;AA/EuC","sourcesContent":["import chalk from 'chalk';\nimport { Command, CommandOptions } from '@teambit/cli';\nimport { MergeStrategy, applyVersionReport } from '@teambit/legacy/dist/consumer/versions-ops/merge-version';\nimport { LanesMain } from './lanes.main.runtime';\n\nexport class SwitchCmd implements Command {\n name = 'switch <lane>';\n description = `switch to the specified lane`;\n private = true;\n alias = '';\n options = [\n [\n 'n',\n 'as <as>',\n 'relevant when the specified lane is a remote late. name a local lane differently than the remote lane',\n ],\n [\n 'm',\n 'merge [strategy]',\n 'merge local changes with the checked out version. strategy should be \"theirs\", \"ours\" or \"manual\"',\n ],\n ['a', 'get-all', 'checkout all components in a lane include ones that do not exist in the workspace'],\n ['', 'skip-dependency-installation', 'do not install packages of the imported components'],\n ['j', 'json', 'return the output as JSON'],\n ] as CommandOptions;\n loader = true;\n\n constructor(private lanes: LanesMain) {}\n\n async report(\n [lane]: [string],\n {\n as,\n merge,\n getAll = false,\n skipDependencyInstallation = false,\n json = false,\n }: {\n as?: string;\n merge?: MergeStrategy;\n getAll?: boolean;\n skipDependencyInstallation?: boolean;\n override?: boolean;\n json?: boolean;\n }\n ) {\n const { components, failedComponents } = await this.lanes.switchLanes(lane, {\n newLaneName: as,\n merge,\n getAll,\n skipDependencyInstallation,\n });\n if (json) {\n return JSON.stringify({ components, failedComponents }, null, 4);\n }\n const getFailureOutput = () => {\n if (!failedComponents || !failedComponents.length) return '';\n const title = 'the switch has been canceled on the following component(s)';\n const body = failedComponents\n .map(\n (failedComponent) =>\n `${chalk.bold(failedComponent.id.toString())} - ${chalk.red(failedComponent.failureMessage)}`\n )\n .join('\\n');\n return `${title}\\n${body}\\n\\n`;\n };\n const getSuccessfulOutput = () => {\n const laneSwitched = chalk.green(`\\nsuccessfully set \"${chalk.bold(lane)}\" as the active lane`);\n if (!components || !components.length) return `No component had been changed.${laneSwitched}`;\n if (components.length === 1) {\n const component = components[0];\n const componentName = component.id.toStringWithoutVersion();\n const title = `successfully switched ${chalk.bold(componentName)} to version ${chalk.bold(\n component.id.version as string\n )}\\n`;\n return `${title} ${applyVersionReport(components, false)}${laneSwitched}`;\n }\n const title = `successfully switched the following components to the version of ${lane}\\n\\n`;\n const componentsStr = applyVersionReport(components, true, false);\n return title + componentsStr + laneSwitched;\n };\n const failedOutput = getFailureOutput();\n const successOutput = getSuccessfulOutput();\n return failedOutput + successOutput;\n }\n}\n"]}
1
+ {"version":3,"sources":["switch.cmd.ts"],"names":["SwitchCmd","constructor","lanes","report","lane","alias","merge","getAll","skipDependencyInstallation","json","components","failedComponents","switchLanes","JSON","stringify","getFailureOutput","length","title","body","map","failedComponent","chalk","bold","id","toString","red","failureMessage","join","getSuccessfulOutput","laneSwitched","green","component","componentName","toStringWithoutVersion","version","componentsStr","failedOutput","successOutput"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGO,MAAMA,SAAN,CAAmC;AAsBxCC,EAAAA,WAAW,CAASC,KAAT,EAA2B;AAAA,SAAlBA,KAAkB,GAAlBA,KAAkB;AAAA,kDArB/B,eAqB+B;AAAA,yDApBvB,8BAoBuB;AAAA,qDAnB5B,IAmB4B;AAAA,mDAlB9B,EAkB8B;AAAA,qDAjB5B,CACR,CACE,GADF,EAEE,gBAFF,EAGE,uGAHF,CADQ,EAMR,CACE,GADF,EAEE,kBAFF,EAGE,mGAHF,CANQ,EAWR,CAAC,GAAD,EAAM,SAAN,EAAiB,mFAAjB,CAXQ,EAYR,CAAC,EAAD,EAAK,8BAAL,EAAqC,oDAArC,CAZQ,EAaR,CAAC,GAAD,EAAM,MAAN,EAAc,2BAAd,CAbQ,CAiB4B;AAAA,oDAF7B,IAE6B;AAAE;;AAE5B,QAANC,MAAM,CACV,CAACC,IAAD,CADU,EAEV;AACEC,IAAAA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EAA6B;AAC3B,cAAMe,SAAS,GAAGrB,UAAU,CAAC,CAAD,CAA5B;AACA,cAAMsB,aAAa,GAAGD,SAAS,CAACR,EAAV,CAAaU,sBAAb,EAAtB;AACA,cAAMhB,KAAK,GAAI,yBAAwBI,iBAAMC,IAAN,CAAWU,aAAX,CAA0B,eAAcX,iBAAMC,IAAN,CAC7ES,SAAS,CAACR,EAAV,CAAaW,OADgE,CAE7E,IAFF;AAGA,eAAQ,GAAEjB,KAAM,IAAG,wCAAmBP,UAAnB,EAA+B,KAA/B,CAAsC,GAAEmB,YAAa,EAAxE;AACD;;AACD,YAAMZ,KAAK,GAAI,oEAAmEb,IAAK,MAAvF;AACA,YAAM+B,aAAa,GAAG,wCAAmBzB,UAAnB,EAA+B,IAA/B,EAAqC,KAArC,CAAtB;AACA,aAAOO,KAAK,GAAGkB,aAAR,GAAwBN,YAA/B;AACD,KAdD;;AAeA,UAAMO,YAAY,GAAGrB,gBAAgB,EAArC;AACA,UAAMsB,aAAa,GAAGT,mBAAmB,EAAzC;AACA,WAAOQ,YAAY,GAAGC,aAAtB;AACD;;AA/EuC","sourcesContent":["import chalk from 'chalk';\nimport { Command, CommandOptions } from '@teambit/cli';\nimport { MergeStrategy, applyVersionReport } from '@teambit/legacy/dist/consumer/versions-ops/merge-version';\nimport { LanesMain } from './lanes.main.runtime';\n\nexport class SwitchCmd implements Command {\n name = 'switch <lane>';\n description = `switch to the specified lane`;\n private = true;\n alias = '';\n options = [\n [\n 'n',\n 'alias <string>',\n 'relevant when the specified lane is a remote late. name a local lane differently than the remote lane',\n ],\n [\n 'm',\n 'merge [strategy]',\n 'merge local changes with the checked out version. strategy should be \"theirs\", \"ours\" or \"manual\"',\n ],\n ['a', 'get-all', 'checkout all components in a lane include ones that do not exist in the workspace'],\n ['', 'skip-dependency-installation', 'do not install packages of the imported components'],\n ['j', 'json', 'return the output as JSON'],\n ] as CommandOptions;\n loader = true;\n\n constructor(private lanes: LanesMain) {}\n\n async report(\n [lane]: [string],\n {\n alias,\n merge,\n getAll = false,\n skipDependencyInstallation = false,\n json = false,\n }: {\n alias?: string;\n merge?: MergeStrategy;\n getAll?: boolean;\n skipDependencyInstallation?: boolean;\n override?: boolean;\n json?: boolean;\n }\n ) {\n const { components, failedComponents } = await this.lanes.switchLanes(lane, {\n alias,\n merge,\n getAll,\n skipDependencyInstallation,\n });\n if (json) {\n return JSON.stringify({ components, failedComponents }, null, 4);\n }\n const getFailureOutput = () => {\n if (!failedComponents || !failedComponents.length) return '';\n const title = 'the switch has been canceled on the following component(s)';\n const body = failedComponents\n .map(\n (failedComponent) =>\n `${chalk.bold(failedComponent.id.toString())} - ${chalk.red(failedComponent.failureMessage)}`\n )\n .join('\\n');\n return `${title}\\n${body}\\n\\n`;\n };\n const getSuccessfulOutput = () => {\n const laneSwitched = chalk.green(`\\nsuccessfully set \"${chalk.bold(lane)}\" as the active lane`);\n if (!components || !components.length) return `No component had been changed.${laneSwitched}`;\n if (components.length === 1) {\n const component = components[0];\n const componentName = component.id.toStringWithoutVersion();\n const title = `successfully switched ${chalk.bold(componentName)} to version ${chalk.bold(\n component.id.version as string\n )}\\n`;\n return `${title} ${applyVersionReport(components, false)}${laneSwitched}`;\n }\n const title = `successfully switched the following components to the version of ${lane}\\n\\n`;\n const componentsStr = applyVersionReport(components, true, false);\n return title + componentsStr + laneSwitched;\n };\n const failedOutput = getFailureOutput();\n const successOutput = getSuccessfulOutput();\n return failedOutput + successOutput;\n }\n}\n"]}
package/lanes.docs.mdx CHANGED
@@ -11,16 +11,16 @@ The following describes the final implementation, which differs from the specifi
11
11
 
12
12
  ```
13
13
  - create a snap: `bit snap` (synopsis similar to the `bit tag`)
14
- - create a new lane: `bit lane create <name> --test`
14
+ - create a new lane: `bit lane create <name>`
15
15
  - list lanes: `bit lane list`
16
16
  - switch between lanes: `bit switch <name>`
17
17
  - merge lanes: `bit lane merge`
18
18
  - show lane details: `bit lane show <name>`
19
19
  - diff between lanes: `bit lane diff <values>`
20
20
  - track local lane to a remote lane: `bit switch --as`
21
- - remove a lane `bit lane remove <name>`.
21
+ - remove a lane: `bit lane remove <name>`.
22
22
  - fetch lane objects (without the components): `bit fetch --lanes`
23
- - import a lane: `bit switch <name> --remote`
23
+ - import a lane: `bit lane import`
24
24
  - export current lane: `bit export`
25
25
  - (internal) cat lane object: `bit cat-lane <name>`
26
26
  ```
@@ -31,12 +31,17 @@ The following describes the final implementation, which differs from the specifi
31
31
  - [ ] Bit import with no args. When bitmap has a remote lane, should import the lane.
32
32
  - [ ] Tag dependencies to include them in a lane.
33
33
  - [ ] Test bit-fetch components
34
- - [ ] Rename lanes.
34
+ - [ ] Rename lanes: enable importing a lane after rename.
35
35
  - [ ] Fix performance issue. Now it fetches all parents every time. It doesn't make sense.
36
36
  - [ ] Fix performance issue. Now it traverses all parents to see if a hash in there.
37
37
 
38
38
  ## Important points
39
39
 
40
+ ### Lane ID
41
+
42
+ The Lane id consists of the lane name and the scope. If this is a new lane, the scope is the defaultScope.
43
+ The `LaneId` _always_ has these two props.
44
+
40
45
  ### Performance consideration
41
46
 
42
47
  Currently, if it imports with no-deps, it doesn't ask for parents, if it imports with deps it imports with all parents. It is originated from src/api/scope/lib/fetch.ts: `const collectParents = !noDependencies;`. We need to make a decision here.
@@ -51,6 +56,7 @@ Currently, if it imports with no-deps, it doesn't ask for parents, if it imports
51
56
  - Snap's hash is generated by a UUID and then converted into sha1. `sha1(v4())`.
52
57
  - Lane's hash is generated by a UUID and then converted into sha1. `sha1(v4())`.
53
58
  - Tag's hash stays the same. Generated by the `Version.id()`.
59
+ - Lane's hash doesn't get changed even if the lane has been renamed or its scope changed.
54
60
 
55
61
  ### Lane Data
56
62
 
@@ -85,3 +91,9 @@ Summary of when/what lanes data is saved per command:
85
91
  ### Useful APIs
86
92
 
87
93
  - bit-map `getAllIdsAvailableOnLane()` filters the currently checked out lane.
94
+
95
+ ### Remove component from a lane
96
+
97
+ Locally, to remove a component from a lane, use `bit remove` command. It will remove the component from the local lane-object.
98
+ This change won't affect the remote scope, even after exporting the lane. This is becuase on the remote, the merge-lane process doesn't remove anything, only adds/changes components to the lane object.
99
+ Remember that by default when importing a lane, only the components on the workspace are part of the lane, so the same lane-object, locally can have less components than the remote and obviously in this case we don't want to remove them from the remote on export.