@teambit/lanes 0.0.297 → 0.0.300

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.
@@ -142,12 +142,14 @@ function _createLane() {
142
142
  }
143
143
 
144
144
  class LaneSwitcher {
145
+ // populated by `this.populateSwitchProps()`
145
146
  constructor(workspace, logger, switchProps, checkoutProps) {
146
147
  this.workspace = workspace;
147
148
  this.logger = logger;
148
149
  this.switchProps = switchProps;
149
150
  this.checkoutProps = checkoutProps;
150
151
  (0, _defineProperty2().default)(this, "consumer", void 0);
152
+ (0, _defineProperty2().default)(this, "laneIdToSwitch", void 0);
151
153
  this.consumer = this.workspace.consumer;
152
154
  }
153
155
 
@@ -203,48 +205,33 @@ class LaneSwitcher {
203
205
  }
204
206
 
205
207
  async populateSwitchProps() {
206
- 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);
207
210
 
208
- const isDefaultLane = this.switchProps.laneName === _laneId().DEFAULT_LANE;
209
-
210
- const localLane = lanes.find(lane => lane.name === this.switchProps.laneName);
211
-
212
- if (isDefaultLane || localLane) {
211
+ if (laneId.isDefault()) {
212
+ this.populatePropsAccordingToDefaultLane();
213
+ } else if (localLane) {
213
214
  this.populatePropsAccordingToLocalLane(localLane);
214
215
  } else {
215
- await this.populatePropsAccordingToRemoteLane(lanes);
216
+ await this.populatePropsAccordingToRemoteLane(laneId);
216
217
  }
217
218
  }
218
219
 
219
- async populatePropsAccordingToRemoteLane(lanes) {
220
- let remoteLaneId;
221
-
222
- try {
223
- remoteLaneId = _laneId().RemoteLaneId.parse(this.switchProps.laneName);
224
- } catch (e) {
225
- throw new (_generalError().default)(`invalid lane id "${this.switchProps.laneName}", the lane ${this.switchProps.laneName} doesn't exist.`);
226
- }
220
+ async populatePropsAccordingToRemoteLane(remoteLaneId) {
221
+ this.laneIdToSwitch = remoteLaneId;
222
+ this.logger.debug(`populatePropsAccordingToRemoteLane, remoteLaneId: ${remoteLaneId.toString()}`);
227
223
 
228
- if (remoteLaneId.name === _laneId().DEFAULT_LANE) {
229
- throw new (_bitError().BitError)(`invalid remote lane id "${this.switchProps.laneName}". to switch to the main lane on remote,
230
- 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()}"`);
231
226
  } // fetch the remote to update all heads
232
227
 
233
228
 
234
- const localTrackedLane = this.consumer.scope.lanes.getLocalTrackedLaneByRemoteName(remoteLaneId.name, remoteLaneId.scope);
235
- this.logger.debug(`populatePropsAccordingToRemoteLane, remoteLaneId: ${remoteLaneId.toString()}`);
236
- this.switchProps.localLaneName = this.switchProps.newLaneName || localTrackedLane || remoteLaneId.name;
237
-
238
- if (this.consumer.getCurrentLaneId().name === this.switchProps.localLaneName) {
239
- throw new (_bitError().BitError)(`already checked out to "${this.switchProps.localLaneName}"`);
240
- }
241
-
242
229
  const scopeComponentImporter = _scopeComponentsImporter().default.getInstance(this.consumer.scope);
243
230
 
244
231
  const remoteLaneObjects = await scopeComponentImporter.importFromLanes([remoteLaneId]);
245
232
 
246
233
  if (remoteLaneObjects.length === 0) {
247
- throw new (_bitError().BitError)(`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.`);
248
235
  }
249
236
 
250
237
  if (remoteLaneObjects.length > 1) {
@@ -253,41 +240,29 @@ class LaneSwitcher {
253
240
  }
254
241
 
255
242
  const remoteLane = remoteLaneObjects[0];
256
- this.switchProps.remoteLaneName = remoteLaneId.name;
257
243
  this.switchProps.laneName = remoteLaneId.name;
258
- this.switchProps.remoteLaneScope = remoteLaneId.scope;
259
- this.switchProps.remoteScope = remoteLaneId.scope;
260
244
  this.switchProps.ids = remoteLane.components.map(l => l.id.changeVersion(l.head.toString()));
261
- this.switchProps.localTrackedLane = localTrackedLane || undefined;
245
+ this.switchProps.localTrackedLane = this.consumer.scope.lanes.getAliasByLaneId(remoteLaneId) || undefined;
262
246
  this.switchProps.remoteLane = remoteLane;
263
- const laneExistsLocally = lanes.find(l => l.name === this.switchProps.localLaneName);
247
+ this.logger.debug(`populatePropsAccordingToRemoteLane, completed`);
248
+ }
264
249
 
265
- if (laneExistsLocally) {
266
- throw new (_bitError().BitError)(`unable to checkout to a remote lane ${this.switchProps.remoteScope}/${this.switchProps.laneName}.
267
- the local lane "${this.switchProps.localLaneName}" already exists, please switch to the local lane first by running "bit switch ${this.switchProps.localLaneName}"
268
- then, to merge the remote lane into the local lane, run "bit lane merge ${this.switchProps.localLaneName} --remote ${this.switchProps.remoteScope}"`);
250
+ populatePropsAccordingToDefaultLane() {
251
+ if (!this.consumer.isOnLane()) {
252
+ throw new (_bitError().BitError)(`already checked out to "${this.switchProps.laneName}"`);
269
253
  }
270
254
 
271
- this.logger.debug(`populatePropsAccordingToRemoteLane, completed`);
255
+ this.switchProps.ids = this.consumer.bitMap.getAuthoredAndImportedBitIdsOfDefaultLane();
256
+ this.laneIdToSwitch = _laneId().LaneId.from(_laneId().DEFAULT_LANE, this.consumer.scope.name);
272
257
  }
273
258
 
274
259
  populatePropsAccordingToLocalLane(localLane) {
275
- this.switchProps.localLaneName = this.switchProps.laneName;
276
-
277
260
  if (this.consumer.getCurrentLaneId().name === this.switchProps.laneName) {
278
- throw new (_generalError().default)(`already checked out to "${this.switchProps.laneName}"`);
279
- }
280
-
281
- if (this.switchProps.laneName === _laneId().DEFAULT_LANE) {
282
- this.switchProps.ids = this.consumer.bitMap.getAuthoredAndImportedBitIdsOfDefaultLane();
283
- return;
284
- }
285
-
286
- if (!localLane) {
287
- throw new (_generalError().default)(`unable to find a local lane "${this.switchProps.laneName}", to create a new lane please run "bit lane create"`);
261
+ throw new (_bitError().BitError)(`already checked out to "${this.switchProps.laneName}"`);
288
262
  }
289
263
 
290
264
  this.switchProps.ids = localLane.components.map(c => c.id.changeVersion(c.head.toString()));
265
+ this.laneIdToSwitch = localLane.toLaneId();
291
266
  }
292
267
 
293
268
  async getAllComponentsStatus() {
@@ -310,36 +285,38 @@ then, to merge the remote lane into the local lane, run "bit lane merge ${this.s
310
285
 
311
286
  async saveLanesData() {
312
287
  const saveRemoteLaneToBitmap = () => {
313
- if (this.switchProps.remoteLaneScope) {
314
- this.consumer.bitMap.setRemoteLane(_laneId().RemoteLaneId.from(this.switchProps.remoteLaneName, this.switchProps.remoteLaneScope)); // add versions to lane
288
+ if (this.switchProps.remoteLane) {
289
+ this.consumer.bitMap.setRemoteLane(this.switchProps.remoteLane.toLaneId());
315
290
  }
316
291
  };
317
292
 
318
293
  const throwIfLaneExists = async () => {
319
294
  const allLanes = await this.consumer.scope.listLanes();
320
295
 
321
- if (allLanes.find(l => l.name === this.switchProps.localLaneName)) {
322
- throw new (_generalError().default)(`unable to checkout to lane "${this.switchProps.localLaneName}".
296
+ if (allLanes.find(l => l.toLaneId().isEqual(this.laneIdToSwitch))) {
297
+ throw new (_bitError().BitError)(`unable to checkout to lane "${this.laneIdToSwitch.toString()}".
323
298
  the lane already exists. please switch to the lane and merge`);
324
299
  }
325
300
  };
326
301
 
302
+ const localLaneName = this.switchProps.alias || this.laneIdToSwitch.name;
303
+
327
304
  if (this.switchProps.remoteLane) {
328
305
  await throwIfLaneExists();
329
- await (0, _createLane().createLane)(this.consumer, this.switchProps.localLaneName, this.switchProps.remoteLane);
306
+ await (0, _createLane().createLane)(this.consumer, this.laneIdToSwitch.name, this.laneIdToSwitch.scope, this.switchProps.remoteLane);
330
307
 
331
308
  if (!this.switchProps.localTrackedLane) {
332
309
  this.consumer.scope.lanes.trackLane({
333
- localLane: this.switchProps.localLaneName,
334
- remoteLane: this.switchProps.remoteLaneName,
335
- remoteScope: this.switchProps.remoteLaneScope
310
+ localLane: localLaneName,
311
+ remoteLane: this.laneIdToSwitch.name,
312
+ remoteScope: this.laneIdToSwitch.scope
336
313
  });
337
314
  }
338
315
  }
339
316
 
340
317
  saveRemoteLaneToBitmap();
341
- this.consumer.scope.lanes.setCurrentLane(this.switchProps.localLaneName);
342
- const workspaceLane = this.switchProps.localLaneName === _laneId().DEFAULT_LANE ? null : _workspaceLane().default.load(this.switchProps.localLaneName, this.consumer.scope.path);
318
+ this.consumer.scope.lanes.setCurrentLane(localLaneName);
319
+ const workspaceLane = localLaneName === _laneId().DEFAULT_LANE ? null : _workspaceLane().default.load(localLaneName, this.consumer.scope.path);
343
320
  this.consumer.bitMap.syncWithLanes(workspaceLane);
344
321
  }
345
322
 
@@ -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","BitError","localTrackedLane","getLocalTrackedLaneByRemoteName","debug","toString","localLaneName","newLaneName","getCurrentLaneId","scopeComponentImporter","ScopeComponentsImporter","getInstance","remoteLaneObjects","importFromLanes","length","allLanes","l","join","remoteLane","remoteLaneName","remoteLaneScope","remoteScope","ids","changeVersion","head","undefined","laneExistsLocally","bitMap","getAuthoredAndImportedBitIdsOfDefaultLane","tmp","Tmp","componentsStatusP","getComponentStatus","componentsStatus","Promise","all","clear","err","saveRemoteLaneToBitmap","setRemoteLane","from","throwIfLaneExists","trackLane","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":";;;;;;;;;;;;;;;;;;;;;;;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;;AAIA;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;;AAKA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAeO,MAAMA,YAAN,CAAmB;AAExBC,EAAAA,WAAW,CACDC,SADC,EAEDC,MAFC,EAGDC,WAHC,EAIDC,aAJC,EAKT;AAAA,SAJQH,SAIR,GAJQA,SAIR;AAAA,SAHQC,MAGR,GAHQA,MAGR;AAAA,SAFQC,WAER,GAFQA,WAER;AAAA,SADQC,aACR,GADQA,aACR;AAAA;AACA,SAAKC,QAAL,GAAgB,KAAKJ,SAAL,CAAeI,QAA/B;AACD;;AAEW,QAANC,MAAM,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,GAAGF,UAAU,IAAIlD,IAAI,CAACnB,QAAL,EAAlC;AACA,WAAOsD,gBAAgB,CAACD,OAAjB,KAA6BkB,WAApC;AACD,GAPD;;AAQA,MAAIN,UAAJ,EAAgB;AACd,QAAI,CAACE,gBAAgB,EAArB,EAAyB;AACvB,YAAM,KAAIpH,uBAAJ,EACH,sBAAqBC,EAAE,CAACC,sBAAH,EAA4B,yDAD9C,CAAN;AAGD;;AAED,UAAMuH,cAAuB,GAAG,MAAM1B,cAAc,CAACY,WAAf,CACpCJ,gBAAgB,CAACD,OADmB,EACA;AACpCnH,IAAAA,QAAQ,CAAC4C,KAAT,CAAemE,OAFqB,CAAtC;AAIAtG,IAAAA,YAAY,GAAG,MAAM,8BAAc;AACjCT,MAAAA,QADiC;AAEjCsI,MAAAA,cAFiC;AAGjCC,MAAAA,UAAU,EAAEpB,OAHqB;AAIjCqB,MAAAA,gBAAgB,EAAEhI,SAJe;AAKjCiI,MAAAA,YAAY,EAAG,GAAEb,oBAAqB,WALL;AAMjCC,MAAAA;AANiC,KAAd,CAArB;AAQD,GAxEkH,CAyEnH;;;AACA,SAAO;AAAEtG,IAAAA,eAAe,EAAEf,SAAnB;AAA8BkH,IAAAA,kBAAkB,EAAEH,eAAlD;AAAmEzG,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 { 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 remoteScope?: string;\n ids?: BitId[];\n existingOnWorkspaceOnly: boolean;\n localLaneName?: string;\n remoteLaneScope?: string;\n remoteLaneName?: string;\n remoteLane?: Lane;\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 BitError(`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 BitError(`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 BitError(\n `invalid lane id \"${this.switchProps.laneName}\", the lane ${this.switchProps.laneName} doesn't exist.`\n );\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.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 = remoteLane.components.map((l) => l.id.changeVersion(l.head.toString()));\n this.switchProps.localTrackedLane = localTrackedLane || undefined;\n this.switchProps.remoteLane = remoteLane;\n const laneExistsLocally = lanes.find((l) => l.name === this.switchProps.localLaneName);\n if (laneExistsLocally) {\n throw new BitError(`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\n private async saveLanesData() {\n const saveRemoteLaneToBitmap = () => {\n if (this.switchProps.remoteLaneScope) {\n this.consumer.bitMap.setRemoteLane(\n RemoteLaneId.from(this.switchProps.remoteLaneName as string, this.switchProps.remoteLaneScope)\n );\n // add versions to lane\n }\n };\n const throwIfLaneExists = async () => {\n const allLanes = await this.consumer.scope.listLanes();\n if (allLanes.find((l) => l.name === this.switchProps.localLaneName)) {\n throw new GeneralError(`unable to checkout to lane \"${this.switchProps.localLaneName}\".\n the lane already exists. please switch to the lane and merge`);\n }\n };\n\n if (this.switchProps.remoteLane) {\n await throwIfLaneExists();\n await createLane(this.consumer, this.switchProps.localLaneName as string, this.switchProps.remoteLane);\n if (!this.switchProps.localTrackedLane) {\n this.consumer.scope.lanes.trackLane({\n localLane: this.switchProps.localLaneName as string,\n remoteLane: this.switchProps.remoteLaneName as string,\n remoteScope: this.switchProps.remoteLaneScope as string,\n });\n }\n }\n\n saveRemoteLaneToBitmap();\n this.consumer.scope.lanes.setCurrentLane(this.switchProps.localLaneName as string);\n const workspaceLane =\n this.switchProps.localLaneName === DEFAULT_LANE\n ? null\n : WorkspaceLane.load(this.switchProps.localLaneName as string, 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"]}
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":";;;;;;;;;;;;;;;;;;;;;;;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;;AAIA;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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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;;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,SAFF,EAGE,uGAHF,CADQ,EAMR,CACE,GADF,EAEE,kBAFF,EAGE,mGAHF,CANQ,EAWR,CAAC,GAAD,EAAM,SAAN,EAAiB,mFAAjB,CAXQ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,KAAN,CAAa,uBAAsBT,iBAAMC,IAAN,CAAWnB,IAAX,CAAiB,sBAApD,CAArB;;AACA,UAAI,CAACM,UAAD,IAAe,CAACA,UAAU,CAACO,MAA/B,EAAuC,OAAQ,iCAAgCa,YAAa,EAArD;;AACvC,UAAIpB,UAAU,CAACO,MAAX,KAAsB,CAA1B,EAA6B;AAC3B,cAAMe,SAAS,GAAGtB,UAAU,CAAC,CAAD,CAA5B;AACA,cAAMuB,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,wCAAmBR,UAAnB,EAA+B,KAA/B,CAAsC,GAAEoB,YAAa,EAAxE;AACD;;AACD,YAAMZ,KAAK,GAAI,oEAAmEd,IAAK,MAAvF;AACA,YAAMgC,aAAa,GAAG,wCAAmB1B,UAAnB,EAA+B,IAA/B,EAAqC,KAArC,CAAtB;AACA,aAAOQ,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 '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,KADF;AAEEC,IAAAA,KAFF;AAGEC,IAAAA,MAAM,GAAG,KAHX;AAIEC,IAAAA,0BAA0B,GAAG,KAJ/B;AAKEC,IAAAA,IAAI,GAAG;AALT,GAFU,EAgBV;AACA,UAAM;AAAEC,MAAAA,UAAF;AAAcC,MAAAA;AAAd,QAAmC,MAAM,KAAKT,KAAL,CAAWU,WAAX,CAAuBR,IAAvB,EAA6B;AAC1EC,MAAAA,KAD0E;AAE1EC,MAAAA,KAF0E;AAG1EC,MAAAA,MAH0E;AAI1EC,MAAAA;AAJ0E,KAA7B,CAA/C;;AAMA,QAAIC,IAAJ,EAAU;AACR,aAAOI,IAAI,C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AK,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.
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@teambit/lanes",
3
- "version": "0.0.297",
3
+ "version": "0.0.300",
4
4
  "homepage": "https://bit.dev/teambit/lanes/lanes",
5
5
  "main": "dist/index.js",
6
6
  "componentId": {
7
7
  "scope": "teambit.lanes",
8
8
  "name": "lanes",
9
- "version": "0.0.297"
9
+ "version": "0.0.300"
10
10
  },
11
11
  "dependencies": {
12
12
  "chalk": "4.1.2",
@@ -19,22 +19,22 @@
19
19
  "core-js": "^3.0.0",
20
20
  "@teambit/harmony": "0.3.3",
21
21
  "@teambit/bit-error": "0.0.394",
22
- "@teambit/cli": "0.0.484",
23
- "@teambit/merging": "0.0.40",
24
- "@teambit/scope": "0.0.725",
25
- "@teambit/workspace": "0.0.725",
26
- "@teambit/graphql": "0.0.725",
27
- "@teambit/community": "0.0.32",
28
- "@teambit/component": "0.0.725",
29
- "@teambit/lane-id": "0.0.3",
30
- "@teambit/lanes.modules.diff": "0.0.111",
22
+ "@teambit/cli": "0.0.486",
23
+ "@teambit/merging": "0.0.43",
24
+ "@teambit/scope": "0.0.728",
25
+ "@teambit/workspace": "0.0.728",
26
+ "@teambit/graphql": "0.0.728",
27
+ "@teambit/community": "0.0.34",
28
+ "@teambit/component": "0.0.728",
29
+ "@teambit/lane-id": "0.0.5",
30
+ "@teambit/lanes.modules.diff": "0.0.113",
31
31
  "@teambit/legacy-bit-id": "0.0.399",
32
- "@teambit/logger": "0.0.576",
33
- "@teambit/lanes.ui.lanes": "0.0.50",
34
- "@teambit/sidebar": "0.0.725",
32
+ "@teambit/logger": "0.0.578",
33
+ "@teambit/lanes.ui.lanes": "0.0.52",
34
+ "@teambit/sidebar": "0.0.728",
35
35
  "@teambit/ui-foundation.ui.menu": "0.0.487",
36
36
  "@teambit/ui-foundation.ui.react-router.slot-router": "0.0.489",
37
- "@teambit/ui": "0.0.725"
37
+ "@teambit/ui": "0.0.728"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@types/react": "^17.0.8",
@@ -50,7 +50,7 @@
50
50
  "@teambit/workspace.testing.mock-workspace": "0.0.5"
51
51
  },
52
52
  "peerDependencies": {
53
- "@teambit/legacy": "1.0.263",
53
+ "@teambit/legacy": "1.0.265",
54
54
  "react-dom": "^16.8.0 || ^17.0.0",
55
55
  "react": "^16.8.0 || ^17.0.0"
56
56
  },
@@ -78,7 +78,7 @@
78
78
  "react": "-"
79
79
  },
80
80
  "peerDependencies": {
81
- "@teambit/legacy": "1.0.263",
81
+ "@teambit/legacy": "1.0.265",
82
82
  "react-dom": "^16.8.0 || ^17.0.0",
83
83
  "react": "^16.8.0 || ^17.0.0"
84
84
  }
@@ -1,2 +1,2 @@
1
- export const compositions = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.lanes_lanes@0.0.297/dist/lanes.composition.js')]
2
- export const overview = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.lanes_lanes@0.0.297/dist/lanes.docs.mdx')]
1
+ export const compositions = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.lanes_lanes@0.0.300/dist/lanes.composition.js')]
2
+ export const overview = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.lanes_lanes@0.0.300/dist/lanes.docs.mdx')]