@teambit/lanes 1.0.107 → 1.0.108

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.
@@ -131,7 +131,6 @@ to be up to date with the remote lane, please run "bit checkout head""`);
131
131
  }
132
132
  }
133
133
  async saveLanesData() {
134
- var _this$laneToSwitchTo;
135
134
  const localLaneName = this.switchProps.alias || this.laneIdToSwitchTo.name;
136
135
  if (this.switchProps.remoteLane) {
137
136
  if (!this.switchProps.localTrackedLane) {
@@ -142,7 +141,7 @@ to be up to date with the remote lane, please run "bit checkout head""`);
142
141
  });
143
142
  }
144
143
  }
145
- this.consumer.setCurrentLane(this.laneIdToSwitchTo, !((_this$laneToSwitchTo = this.laneToSwitchTo) !== null && _this$laneToSwitchTo !== void 0 && _this$laneToSwitchTo.isNew));
144
+ this.consumer.setCurrentLane(this.laneIdToSwitchTo, !this.laneToSwitchTo?.isNew);
146
145
  this.consumer.bitMap.syncWithIds(_componentId().ComponentIdList.fromArray(this.switchProps.ids || []), _componentId().ComponentIdList.fromArray(this.switchProps.laneBitIds || []));
147
146
  }
148
147
  }
@@ -1 +1 @@
1
- {"version":3,"names":["_laneId","data","require","_componentId","_bitError","_createLane","ownKeys","e","r","t","Object","keys","getOwnPropertySymbols","o","filter","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","arguments","length","forEach","_defineProperty","getOwnPropertyDescriptors","defineProperties","defineProperty","obj","key","value","_toPropertyKey","configurable","writable","i","_toPrimitive","String","Symbol","toPrimitive","call","TypeError","Number","LaneSwitcher","constructor","workspace","logger","switchProps","checkoutProps","Lanes","consumer","switch","setStatusLine","isOnMain","throwForStagedComponents","populateSwitchProps","bitMapIds","bitmapIdsFromCurrentLaneIncludeRemoved","idsToSwitch","ids","idsWithVersion","map","id","bitMapId","searchWithoutVersion","resolveMultipleComponentIds","allowAddingComponentsFromScope","versionPerId","lane","laneToSwitchTo","results","checkout","saveLanesData","onDestroy","laneId","scope","lanes","parseLaneIdFromString","laneName","localLane","loadLane","mainIds","getIdsOfDefaultLane","isDefault","populatePropsAccordingToDefaultLane","laneIds","populatePropsAccordingToLocalLane","populatePropsAccordingToRemoteLane","idsOnLaneOnly","find","isEqualWithoutVersion","idsOnMainOnly","laneBitIds","pattern","bitMap","getAllBitIdsFromAllLanes","BitError","allIds","patternIds","filterIdsFromPoolIdsByPattern","remoteLaneId","laneIdToSwitchTo","debug","toString","throwForSwitchingToCurrentLane","remoteLane","fetchLaneWithItsComponents","name","localTrackedLane","getAliasByLaneId","undefined","components","l","changeVersion","head","LaneId","from","DEFAULT_LANE","toLaneId","c","getCurrentLaneId","isEqual","laneIdStr","_this$laneToSwitchTo","localLaneName","alias","trackLane","remoteScope","setCurrentLane","isNew","syncWithIds","ComponentIdList","fromArray","exports"],"sources":["switch-lanes.ts"],"sourcesContent":["import { Consumer } from '@teambit/legacy/dist/consumer';\nimport { LaneId, DEFAULT_LANE } from '@teambit/lane-id';\nimport { ComponentID, ComponentIdList } from '@teambit/component-id';\nimport { ApplyVersionResults } from '@teambit/merging';\nimport { Lane } from '@teambit/legacy/dist/scope/models';\nimport { CheckoutPropsLegacy, CheckoutProps } from '@teambit/checkout';\nimport { Workspace } from '@teambit/workspace';\nimport { Logger } from '@teambit/logger';\nimport { BitError } from '@teambit/bit-error';\nimport { LanesMain } from './lanes.main.runtime';\nimport { throwForStagedComponents } from './create-lane';\n\nexport type SwitchProps = {\n laneName: string;\n ids?: ComponentID[];\n laneBitIds?: ComponentID[]; // only needed for the deprecated onLanesOnly prop. once this prop is removed, this prop can be removed as well.\n pattern?: string;\n existingOnWorkspaceOnly: boolean;\n remoteLane?: Lane;\n localTrackedLane?: string;\n alias?: string;\n};\n\nexport class LaneSwitcher {\n private consumer: Consumer;\n private laneIdToSwitchTo: LaneId; // populated by `this.populateSwitchProps()`\n private laneToSwitchTo: Lane | undefined; // populated by `this.populateSwitchProps()`, if default-lane, it's undefined\n constructor(\n private workspace: Workspace,\n private logger: Logger,\n private switchProps: SwitchProps,\n private checkoutProps: CheckoutPropsLegacy,\n private Lanes: LanesMain\n ) {\n this.consumer = this.workspace.consumer;\n }\n\n async switch(): Promise<ApplyVersionResults> {\n this.logger.setStatusLine(`switching lanes`);\n if (this.workspace.isOnMain()) {\n await throwForStagedComponents(this.consumer);\n }\n await this.populateSwitchProps();\n const bitMapIds = this.workspace.consumer.bitmapIdsFromCurrentLaneIncludeRemoved;\n const idsToSwitch = this.switchProps.ids || [];\n const idsWithVersion = idsToSwitch.map((id) => {\n const bitMapId = bitMapIds.searchWithoutVersion(id);\n return bitMapId || id;\n });\n const ids = await this.workspace.resolveMultipleComponentIds(idsWithVersion);\n\n const checkoutProps: CheckoutProps = {\n ...this.checkoutProps,\n ids,\n allowAddingComponentsFromScope: true,\n versionPerId: await this.workspace.resolveMultipleComponentIds(idsToSwitch),\n lane: this.laneToSwitchTo,\n };\n\n const results = await this.Lanes.checkout.checkout(checkoutProps);\n\n await this.saveLanesData();\n await this.consumer.onDestroy('lane-switch');\n\n return results;\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 const mainIds = await this.consumer.getIdsOfDefaultLane();\n if (laneId.isDefault()) {\n await this.populatePropsAccordingToDefaultLane();\n this.switchProps.ids = mainIds;\n } else {\n const laneIds = localLane\n ? this.populatePropsAccordingToLocalLane(localLane)\n : await this.populatePropsAccordingToRemoteLane(laneId);\n const idsOnLaneOnly = laneIds.filter((id) => !mainIds.find((i) => i.isEqualWithoutVersion(id)));\n const idsOnMainOnly = mainIds.filter((id) => !laneIds.find((i) => i.isEqualWithoutVersion(id)));\n this.switchProps.ids = [...idsOnMainOnly, ...laneIds];\n this.switchProps.laneBitIds = idsOnLaneOnly;\n }\n\n if (this.switchProps.pattern) {\n if (this.consumer.bitMap.getAllBitIdsFromAllLanes().length) {\n // if the workspace is not empty, it's possible that it has components from lane-x, and is now switching\n // partially to lane-y, while lane-y has the same components as lane-x. in which case, the user ends up with\n // an invalid state of components from lane-x and lane-y together.\n throw new BitError('error: use --pattern only when the workspace is empty');\n }\n const allIds = await this.workspace.resolveMultipleComponentIds(this.switchProps.ids || []);\n const patternIds = await this.workspace.filterIdsFromPoolIdsByPattern(this.switchProps.pattern, allIds);\n this.switchProps.ids = patternIds.map((id) => id);\n }\n }\n\n private async populatePropsAccordingToRemoteLane(remoteLaneId: LaneId): Promise<ComponentID[]> {\n this.laneIdToSwitchTo = remoteLaneId;\n this.logger.debug(`populatePropsAccordingToRemoteLane, remoteLaneId: ${remoteLaneId.toString()}`);\n this.throwForSwitchingToCurrentLane();\n const remoteLane = await this.Lanes.fetchLaneWithItsComponents(remoteLaneId);\n this.switchProps.laneName = remoteLaneId.name;\n this.switchProps.localTrackedLane = this.consumer.scope.lanes.getAliasByLaneId(remoteLaneId) || undefined;\n this.switchProps.remoteLane = remoteLane;\n this.laneToSwitchTo = remoteLane;\n this.logger.debug(`populatePropsAccordingToRemoteLane, completed`);\n return remoteLane.components.map((l) => l.id.changeVersion(l.head.toString()));\n }\n\n private async populatePropsAccordingToDefaultLane() {\n this.laneIdToSwitchTo = LaneId.from(DEFAULT_LANE, this.consumer.scope.name);\n this.throwForSwitchingToCurrentLane();\n }\n\n private populatePropsAccordingToLocalLane(localLane: Lane): ComponentID[] {\n this.laneIdToSwitchTo = localLane.toLaneId();\n this.laneToSwitchTo = localLane;\n this.throwForSwitchingToCurrentLane();\n return localLane.components.map((c) => c.id.changeVersion(c.head.toString()));\n }\n\n private throwForSwitchingToCurrentLane() {\n if (this.consumer.getCurrentLaneId().isEqual(this.laneIdToSwitchTo)) {\n const laneIdStr = this.laneIdToSwitchTo.isDefault()\n ? this.laneIdToSwitchTo.name\n : this.laneIdToSwitchTo.toString();\n throw new BitError(`already checked out to \"${laneIdStr}\".\nto be up to date with the remote lane, please run \"bit checkout head\"\"`);\n }\n }\n\n private async saveLanesData() {\n const localLaneName = this.switchProps.alias || this.laneIdToSwitchTo.name;\n if (this.switchProps.remoteLane) {\n if (!this.switchProps.localTrackedLane) {\n this.consumer.scope.lanes.trackLane({\n localLane: localLaneName,\n remoteLane: this.laneIdToSwitchTo.name,\n remoteScope: this.laneIdToSwitchTo.scope,\n });\n }\n }\n\n this.consumer.setCurrentLane(this.laneIdToSwitchTo, !this.laneToSwitchTo?.isNew);\n this.consumer.bitMap.syncWithIds(\n ComponentIdList.fromArray(this.switchProps.ids || []),\n ComponentIdList.fromArray(this.switchProps.laneBitIds || [])\n );\n }\n}\n"],"mappings":";;;;;;AACA,SAAAA,QAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,OAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAE,aAAA;EAAA,MAAAF,IAAA,GAAAC,OAAA;EAAAC,YAAA,YAAAA,CAAA;IAAA,OAAAF,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAMA,SAAAG,UAAA;EAAA,MAAAH,IAAA,GAAAC,OAAA;EAAAE,SAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAI,YAAA;EAAA,MAAAJ,IAAA,GAAAC,OAAA;EAAAG,WAAA,YAAAA,CAAA;IAAA,OAAAJ,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAAyD,SAAAK,QAAAC,CAAA,EAAAC,CAAA,QAAAC,CAAA,GAAAC,MAAA,CAAAC,IAAA,CAAAJ,CAAA,OAAAG,MAAA,CAAAE,qBAAA,QAAAC,CAAA,GAAAH,MAAA,CAAAE,qBAAA,CAAAL,CAAA,GAAAC,CAAA,KAAAK,CAAA,GAAAA,CAAA,CAAAC,MAAA,WAAAN,CAAA,WAAAE,MAAA,CAAAK,wBAAA,CAAAR,CAAA,EAAAC,CAAA,EAAAQ,UAAA,OAAAP,CAAA,CAAAQ,IAAA,CAAAC,KAAA,CAAAT,CA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AA,GAAAA,YAAA"}
1
+ {"version":3,"names":["_laneId","data","require","_componentId","_bitError","_createLane","ownKeys","e","r","t","Object","keys","getOwnPropertySymbols","o","filter","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","arguments","length","forEach","_defineProperty","getOwnPropertyDescriptors","defineProperties","defineProperty","obj","key","value","_toPropertyKey","configurable","writable","i","_toPrimitive","String","Symbol","toPrimitive","call","TypeError","Number","LaneSwitcher","constructor","workspace","logger","switchProps","checkoutProps","Lanes","consumer","switch","setStatusLine","isOnMain","throwForStagedComponents","populateSwitchProps","bitMapIds","bitmapIdsFromCurrentLaneIncludeRemoved","idsToSwitch","ids","idsWithVersion","map","id","bitMapId","searchWithoutVersion","resolveMultipleComponentIds","allowAddingComponentsFromScope","versionPerId","lane","laneToSwitchTo","results","checkout","saveLanesData","onDestroy","laneId","scope","lanes","parseLaneIdFromString","laneName","localLane","loadLane","mainIds","getIdsOfDefaultLane","isDefault","populatePropsAccordingToDefaultLane","laneIds","populatePropsAccordingToLocalLane","populatePropsAccordingToRemoteLane","idsOnLaneOnly","find","isEqualWithoutVersion","idsOnMainOnly","laneBitIds","pattern","bitMap","getAllBitIdsFromAllLanes","BitError","allIds","patternIds","filterIdsFromPoolIdsByPattern","remoteLaneId","laneIdToSwitchTo","debug","toString","throwForSwitchingToCurrentLane","remoteLane","fetchLaneWithItsComponents","name","localTrackedLane","getAliasByLaneId","undefined","components","l","changeVersion","head","LaneId","from","DEFAULT_LANE","toLaneId","c","getCurrentLaneId","isEqual","laneIdStr","localLaneName","alias","trackLane","remoteScope","setCurrentLane","isNew","syncWithIds","ComponentIdList","fromArray","exports"],"sources":["switch-lanes.ts"],"sourcesContent":["import { Consumer } from '@teambit/legacy/dist/consumer';\nimport { LaneId, DEFAULT_LANE } from '@teambit/lane-id';\nimport { ComponentID, ComponentIdList } from '@teambit/component-id';\nimport { ApplyVersionResults } from '@teambit/merging';\nimport { Lane } from '@teambit/legacy/dist/scope/models';\nimport { CheckoutPropsLegacy, CheckoutProps } from '@teambit/checkout';\nimport { Workspace } from '@teambit/workspace';\nimport { Logger } from '@teambit/logger';\nimport { BitError } from '@teambit/bit-error';\nimport { LanesMain } from './lanes.main.runtime';\nimport { throwForStagedComponents } from './create-lane';\n\nexport type SwitchProps = {\n laneName: string;\n ids?: ComponentID[];\n laneBitIds?: ComponentID[]; // only needed for the deprecated onLanesOnly prop. once this prop is removed, this prop can be removed as well.\n pattern?: string;\n existingOnWorkspaceOnly: boolean;\n remoteLane?: Lane;\n localTrackedLane?: string;\n alias?: string;\n};\n\nexport class LaneSwitcher {\n private consumer: Consumer;\n private laneIdToSwitchTo: LaneId; // populated by `this.populateSwitchProps()`\n private laneToSwitchTo: Lane | undefined; // populated by `this.populateSwitchProps()`, if default-lane, it's undefined\n constructor(\n private workspace: Workspace,\n private logger: Logger,\n private switchProps: SwitchProps,\n private checkoutProps: CheckoutPropsLegacy,\n private Lanes: LanesMain\n ) {\n this.consumer = this.workspace.consumer;\n }\n\n async switch(): Promise<ApplyVersionResults> {\n this.logger.setStatusLine(`switching lanes`);\n if (this.workspace.isOnMain()) {\n await throwForStagedComponents(this.consumer);\n }\n await this.populateSwitchProps();\n const bitMapIds = this.workspace.consumer.bitmapIdsFromCurrentLaneIncludeRemoved;\n const idsToSwitch = this.switchProps.ids || [];\n const idsWithVersion = idsToSwitch.map((id) => {\n const bitMapId = bitMapIds.searchWithoutVersion(id);\n return bitMapId || id;\n });\n const ids = await this.workspace.resolveMultipleComponentIds(idsWithVersion);\n\n const checkoutProps: CheckoutProps = {\n ...this.checkoutProps,\n ids,\n allowAddingComponentsFromScope: true,\n versionPerId: await this.workspace.resolveMultipleComponentIds(idsToSwitch),\n lane: this.laneToSwitchTo,\n };\n\n const results = await this.Lanes.checkout.checkout(checkoutProps);\n\n await this.saveLanesData();\n await this.consumer.onDestroy('lane-switch');\n\n return results;\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 const mainIds = await this.consumer.getIdsOfDefaultLane();\n if (laneId.isDefault()) {\n await this.populatePropsAccordingToDefaultLane();\n this.switchProps.ids = mainIds;\n } else {\n const laneIds = localLane\n ? this.populatePropsAccordingToLocalLane(localLane)\n : await this.populatePropsAccordingToRemoteLane(laneId);\n const idsOnLaneOnly = laneIds.filter((id) => !mainIds.find((i) => i.isEqualWithoutVersion(id)));\n const idsOnMainOnly = mainIds.filter((id) => !laneIds.find((i) => i.isEqualWithoutVersion(id)));\n this.switchProps.ids = [...idsOnMainOnly, ...laneIds];\n this.switchProps.laneBitIds = idsOnLaneOnly;\n }\n\n if (this.switchProps.pattern) {\n if (this.consumer.bitMap.getAllBitIdsFromAllLanes().length) {\n // if the workspace is not empty, it's possible that it has components from lane-x, and is now switching\n // partially to lane-y, while lane-y has the same components as lane-x. in which case, the user ends up with\n // an invalid state of components from lane-x and lane-y together.\n throw new BitError('error: use --pattern only when the workspace is empty');\n }\n const allIds = await this.workspace.resolveMultipleComponentIds(this.switchProps.ids || []);\n const patternIds = await this.workspace.filterIdsFromPoolIdsByPattern(this.switchProps.pattern, allIds);\n this.switchProps.ids = patternIds.map((id) => id);\n }\n }\n\n private async populatePropsAccordingToRemoteLane(remoteLaneId: LaneId): Promise<ComponentID[]> {\n this.laneIdToSwitchTo = remoteLaneId;\n this.logger.debug(`populatePropsAccordingToRemoteLane, remoteLaneId: ${remoteLaneId.toString()}`);\n this.throwForSwitchingToCurrentLane();\n const remoteLane = await this.Lanes.fetchLaneWithItsComponents(remoteLaneId);\n this.switchProps.laneName = remoteLaneId.name;\n this.switchProps.localTrackedLane = this.consumer.scope.lanes.getAliasByLaneId(remoteLaneId) || undefined;\n this.switchProps.remoteLane = remoteLane;\n this.laneToSwitchTo = remoteLane;\n this.logger.debug(`populatePropsAccordingToRemoteLane, completed`);\n return remoteLane.components.map((l) => l.id.changeVersion(l.head.toString()));\n }\n\n private async populatePropsAccordingToDefaultLane() {\n this.laneIdToSwitchTo = LaneId.from(DEFAULT_LANE, this.consumer.scope.name);\n this.throwForSwitchingToCurrentLane();\n }\n\n private populatePropsAccordingToLocalLane(localLane: Lane): ComponentID[] {\n this.laneIdToSwitchTo = localLane.toLaneId();\n this.laneToSwitchTo = localLane;\n this.throwForSwitchingToCurrentLane();\n return localLane.components.map((c) => c.id.changeVersion(c.head.toString()));\n }\n\n private throwForSwitchingToCurrentLane() {\n if (this.consumer.getCurrentLaneId().isEqual(this.laneIdToSwitchTo)) {\n const laneIdStr = this.laneIdToSwitchTo.isDefault()\n ? this.laneIdToSwitchTo.name\n : this.laneIdToSwitchTo.toString();\n throw new BitError(`already checked out to \"${laneIdStr}\".\nto be up to date with the remote lane, please run \"bit checkout head\"\"`);\n }\n }\n\n private async saveLanesData() {\n const localLaneName = this.switchProps.alias || this.laneIdToSwitchTo.name;\n if (this.switchProps.remoteLane) {\n if (!this.switchProps.localTrackedLane) {\n this.consumer.scope.lanes.trackLane({\n localLane: localLaneName,\n remoteLane: this.laneIdToSwitchTo.name,\n remoteScope: this.laneIdToSwitchTo.scope,\n });\n }\n }\n\n this.consumer.setCurrentLane(this.laneIdToSwitchTo, !this.laneToSwitchTo?.isNew);\n this.consumer.bitMap.syncWithIds(\n ComponentIdList.fromArray(this.switchProps.ids || []),\n ComponentIdList.fromArray(this.switchProps.laneBitIds || [])\n );\n }\n}\n"],"mappings":";;;;;;AACA,SAAAA,QAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,OAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAE,aAAA;EAAA,MAAAF,IAAA,GAAAC,OAAA;EAAAC,YAAA,YAAAA,CAAA;IAAA,OAAAF,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAMA,SAAAG,UAAA;EAAA,MAAAH,IAAA,GAAAC,OAAA;EAAAE,SAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;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AAW,EAAE,IAAI,CAACzB,gBAAgB,CAAC1B;QACrC,CAAC,CAAC;MACJ;IACF;IAEA,IAAI,CAACzB,QAAQ,CAAC6E,cAAc,CAAC,IAAI,CAAC1B,gBAAgB,EAAE,CAAC,IAAI,CAAChC,cAAc,EAAE2D,KAAK,CAAC;IAChF,IAAI,CAAC9E,QAAQ,CAAC4C,MAAM,CAACmC,WAAW,CAC9BC,8BAAe,CAACC,SAAS,CAAC,IAAI,CAACpF,WAAW,CAACY,GAAG,IAAI,EAAE,CAAC,EACrDuE,8BAAe,CAACC,SAAS,CAAC,IAAI,CAACpF,WAAW,CAAC6C,UAAU,IAAI,EAAE,CAC7D,CAAC;EACH;AACF;AAACwC,OAAA,CAAAzF,YAAA,GAAAA,YAAA"}
package/index.ts ADDED
@@ -0,0 +1,8 @@
1
+ import { LanesAspect } from './lanes.aspect';
2
+
3
+ export type { LanesMain, Lane } from './lanes.main.runtime';
4
+ export type { LanesQuery } from '@teambit/lanes.ui.models.lanes-model';
5
+ export { LanesModel } from '@teambit/lanes.ui.models.lanes-model';
6
+ export type { LanesUI, LaneCompareProps, LaneProviderIgnoreSlot } from './lanes.ui.runtime';
7
+ export default LanesAspect;
8
+ export { LanesAspect };
package/lane.cmd.ts ADDED
@@ -0,0 +1,499 @@
1
+ // eslint-disable-next-line max-classes-per-file
2
+ import chalk from 'chalk';
3
+ import yn from 'yn';
4
+ import { ScopeMain } from '@teambit/scope';
5
+ import { DEFAULT_LANE, LaneId } from '@teambit/lane-id';
6
+ import { Workspace } from '@teambit/workspace';
7
+ import { Command, CommandOptions } from '@teambit/cli';
8
+ import { LaneData, serializeLaneData } from '@teambit/legacy/dist/scope/lanes/lanes';
9
+ import { BitError } from '@teambit/bit-error';
10
+ import { approveOperation } from '@teambit/legacy/dist/prompts';
11
+ import { COMPONENT_PATTERN_HELP } from '@teambit/legacy/dist/constants';
12
+ import { CreateLaneOptions, LanesMain } from './lanes.main.runtime';
13
+ import { SwitchCmd } from './switch.cmd';
14
+
15
+ type LaneOptions = {
16
+ details?: boolean;
17
+ remote?: string;
18
+ merged?: boolean;
19
+ notMerged?: boolean;
20
+ json?: boolean;
21
+ };
22
+
23
+ export class LaneListCmd implements Command {
24
+ name = 'list';
25
+ description = `list local lanes`;
26
+ alias = '';
27
+ options = [
28
+ ['d', 'details', 'show more details on the state of each component in each lane'],
29
+ ['j', 'json', "show lanes' details in a json format"],
30
+ ['r', 'remote <remote-scope-name>', 'show all remote lanes from the specified scope'],
31
+ ['', 'merged', 'list only merged lanes'],
32
+ ['', 'not-merged', "list only lanes that haven't been merged"],
33
+ ] as CommandOptions;
34
+ loader = true;
35
+ migration = true;
36
+ remoteOp = true;
37
+ skipWorkspace = true;
38
+
39
+ constructor(private lanes: LanesMain, private workspace: Workspace, private scope: ScopeMain) {}
40
+
41
+ async report(args, laneOptions: LaneOptions): Promise<string> {
42
+ const { details, remote, merged, notMerged } = laneOptions;
43
+ const laneIdStr = (laneId: LaneId, alias?: string | null) => {
44
+ if (laneId.isDefault()) return laneId.name;
45
+ if (alias) return `${laneId.toString()} (${alias})`;
46
+ return laneId.toString();
47
+ };
48
+ const lanes = await this.lanes.getLanes({
49
+ remote,
50
+ merged,
51
+ notMerged,
52
+ showDefaultLane: true,
53
+ });
54
+ if (merged) {
55
+ const mergedLanes = lanes.filter((l) => l.isMerged);
56
+ if (!mergedLanes.length) return chalk.green('None of the lanes is merged');
57
+ return chalk.green(mergedLanes.map((m) => m.name).join('\n'));
58
+ }
59
+ if (notMerged) {
60
+ const unmergedLanes = lanes.filter((l) => !l.isMerged);
61
+ if (!unmergedLanes.length) return chalk.green('All lanes are merged');
62
+ return chalk.green(unmergedLanes.map((m) => m.name).join('\n'));
63
+ }
64
+ const currentLane = this.lanes.getCurrentLaneId() || this.lanes.getDefaultLaneId();
65
+ const laneDataOfCurrentLane = currentLane ? lanes.find((l) => currentLane.isEqual(l.id)) : undefined;
66
+ const currentAlias = laneDataOfCurrentLane ? laneDataOfCurrentLane.alias : undefined;
67
+ const currentLaneReadmeComponentStr = outputReadmeComponent(laneDataOfCurrentLane?.readmeComponent);
68
+ let currentLaneStr = `current lane - ${chalk.green.green(laneIdStr(currentLane, currentAlias))}`;
69
+ currentLaneStr += currentLaneReadmeComponentStr;
70
+
71
+ if (details) {
72
+ const currentLaneComponents = laneDataOfCurrentLane ? outputComponents(laneDataOfCurrentLane.components) : '';
73
+ if (currentLaneStr) {
74
+ currentLaneStr += `\n${currentLaneComponents}`;
75
+ }
76
+ }
77
+
78
+ const availableLanes = lanes
79
+ .filter((l) => !currentLane.isEqual(l.id))
80
+ .map((laneData) => {
81
+ const readmeComponentStr = outputReadmeComponent(laneData.readmeComponent);
82
+ if (details) {
83
+ const laneTitle = `> ${chalk.bold(laneIdStr(laneData.id, laneData.alias))}\n`;
84
+ const components = outputComponents(laneData.components);
85
+ return laneTitle + readmeComponentStr.concat('\n') + components;
86
+ }
87
+ return ` > ${chalk.green(laneIdStr(laneData.id, laneData.alias))} (${
88
+ laneData.components.length
89
+ } components)${readmeComponentStr}`;
90
+ })
91
+ .join('\n');
92
+
93
+ const outputFooter = () => {
94
+ let footer = '\n';
95
+ if (details) {
96
+ footer += 'You can use --merged and --not-merged to see which of the lanes is fully merged.';
97
+ } else {
98
+ footer +=
99
+ "to get more info on all lanes in local scope use 'bit lane list --details', or 'bit lane show <lane-name>' for a specific lane.";
100
+ }
101
+ if (!remote && this.workspace)
102
+ footer += `\nswitch lanes using 'bit switch <name>'. create lanes using 'bit lane create <name>'.`;
103
+
104
+ return footer;
105
+ };
106
+
107
+ return outputCurrentLane() + outputAvailableLanes() + outputFooter();
108
+
109
+ function outputCurrentLane() {
110
+ return currentLaneStr ? `${currentLaneStr}\n` : '';
111
+ }
112
+
113
+ function outputAvailableLanes() {
114
+ if (!availableLanes) return '';
115
+ return remote ? `${availableLanes}\n` : `\nAvailable lanes:\n${availableLanes}\n`;
116
+ }
117
+ }
118
+ async json(args, laneOptions: LaneOptions) {
119
+ const { remote, merged = false, notMerged = false } = laneOptions;
120
+
121
+ const lanesData = await this.lanes.getLanes({
122
+ remote,
123
+ showDefaultLane: true,
124
+ merged,
125
+ notMerged,
126
+ });
127
+ const lanes = lanesData.map(serializeLaneData);
128
+ const currentLane = this.lanes.getCurrentLaneNameOrAlias();
129
+ return { lanes, currentLane };
130
+ }
131
+ }
132
+
133
+ export class LaneShowCmd implements Command {
134
+ name = 'show [lane-name]';
135
+ description = `show lane details. if no lane specified, show the current lane`;
136
+ alias = '';
137
+ options = [
138
+ ['j', 'json', 'show the lane details in json format'],
139
+ ['r', 'remote', 'show details of the remote head of the provided lane'],
140
+ ] as CommandOptions;
141
+ loader = true;
142
+ migration = true;
143
+ remoteOp = true;
144
+ skipWorkspace = true;
145
+
146
+ constructor(private lanes: LanesMain, private workspace: Workspace, private scope: ScopeMain) {}
147
+
148
+ async report([name]: [string], laneOptions: LaneOptions): Promise<string> {
149
+ const { remote } = laneOptions;
150
+
151
+ if (!name && remote) {
152
+ throw new Error('remote flag is not supported without lane name');
153
+ }
154
+ if (!name) {
155
+ name = this.lanes.getCurrentLaneName() || DEFAULT_LANE;
156
+ }
157
+
158
+ const laneId = await this.lanes.parseLaneId(name);
159
+
160
+ const lanes = await this.lanes.getLanes({
161
+ name: laneId.name,
162
+ remote: remote ? laneId.scope : undefined,
163
+ });
164
+
165
+ const onlyLane = lanes[0];
166
+ const title = `showing information for ${chalk.bold(onlyLane.id.toString())}\n`;
167
+ const author = `author: ${onlyLane.log?.username || 'N/A'} <${onlyLane.log?.email || 'N/A'}>\n`;
168
+ const date = onlyLane.log?.date
169
+ ? `created: ${new Date(parseInt(onlyLane.log.date)).toLocaleString()}\n`
170
+ : undefined;
171
+ return title + author + date + outputComponents(onlyLane.components);
172
+ }
173
+
174
+ async json([name]: [string], laneOptions: LaneOptions) {
175
+ const { remote } = laneOptions;
176
+
177
+ const lanes = await this.lanes.getLanes({
178
+ name,
179
+ remote,
180
+ });
181
+
182
+ return serializeLaneData(lanes[0]);
183
+ }
184
+ }
185
+
186
+ export class LaneCreateCmd implements Command {
187
+ name = 'create <lane-name>';
188
+ arguments = [
189
+ {
190
+ name: 'lane-name',
191
+ description: 'the name for the new lane',
192
+ },
193
+ ];
194
+ description = `creates a new lane and switches to it`;
195
+ extendedDescription = `a lane created from main (default-lane) is empty until components are snapped.
196
+ a lane created from another lane contains all the components of the original lane.`;
197
+ alias = '';
198
+ options = [
199
+ [
200
+ 's',
201
+ 'scope <scope-name>',
202
+ 'remote scope to which this lane will be exported, default to the workspace.json\'s defaultScope (can be changed up to first export of the lane with "bit lane change-scope")',
203
+ ],
204
+ ['', 'remote-scope <scope-name>', 'DEPRECATED. use --scope'],
205
+ [
206
+ '',
207
+ 'alias <name>',
208
+ 'a local alias to refer to this lane, defaults to the `<lane-name>` (can be added later with "bit lane alias")',
209
+ ],
210
+ [
211
+ '',
212
+ 'fork-lane-new-scope',
213
+ 'create the new lane in a different scope than its parent lane (if created from another lane)',
214
+ ],
215
+ ] as CommandOptions;
216
+ loader = true;
217
+ migration = true;
218
+
219
+ constructor(private lanes: LanesMain) {}
220
+
221
+ async report([name]: [string], createLaneOptions: CreateLaneOptions & { remoteScope?: string }): Promise<string> {
222
+ const currentLane = await this.lanes.getCurrentLane();
223
+ if (createLaneOptions.remoteScope) createLaneOptions.scope = createLaneOptions.remoteScope;
224
+ const result = await this.lanes.createLane(name, createLaneOptions);
225
+ const remoteScopeOrDefaultScope = createLaneOptions.scope
226
+ ? `the remote scope ${chalk.bold(createLaneOptions.scope)}`
227
+ : `the default-scope ${chalk.bold(
228
+ result.laneId.scope
229
+ )}. you can change the lane's scope, before it is exported, with the "bit lane change-scope" command`;
230
+ const title = chalk.green(
231
+ `successfully added and checked out to the new lane ${chalk.bold(result.alias || result.laneId.name)}
232
+ ${currentLane !== null ? chalk.yellow(`\nnote - your new lane will be based on lane ${currentLane.name}`) : ''}
233
+ `
234
+ );
235
+ const remoteScopeOutput = `this lane will be exported to ${remoteScopeOrDefaultScope}`;
236
+ return `${title}\n${remoteScopeOutput}`;
237
+ }
238
+ }
239
+
240
+ export class LaneAliasCmd implements Command {
241
+ name = 'alias <lane-name> <alias>';
242
+ description = 'adds an alias to a lane';
243
+ extendedDescription = `an alias is a name that can be used locally to refer to a lane. it is saved locally and never reaches the remote.
244
+ it is useful e.g. when having multiple lanes with the same name, but with different remote scopes.`;
245
+ alias = '';
246
+ options = [] as CommandOptions;
247
+ loader = true;
248
+ migration = true;
249
+
250
+ constructor(private lanes: LanesMain) {}
251
+
252
+ async report([laneName, alias]: [string, string, string]): Promise<string> {
253
+ const { laneId } = await this.lanes.aliasLane(laneName, alias);
254
+ return `successfully added the alias ${chalk.bold(alias)} for lane ${chalk.bold(laneId.toString())}`;
255
+ }
256
+ }
257
+
258
+ export class LaneChangeScopeCmd implements Command {
259
+ name = 'change-scope <remote-scope-name>';
260
+ description = `changes the remote scope of a lane`;
261
+ extendedDescription = 'NOTE: available only before the lane is exported to the remote';
262
+ alias = '';
263
+ options = [
264
+ [
265
+ 'l',
266
+ 'lane-name <lane-name>',
267
+ 'the name of the lane to change its remote scope. if not specified, the current lane is used',
268
+ ],
269
+ ] as CommandOptions;
270
+ loader = true;
271
+ migration = true;
272
+
273
+ constructor(private lanes: LanesMain) {}
274
+
275
+ async report([remoteScope]: [string], { laneName }: { laneName?: string }): Promise<string> {
276
+ const { remoteScopeBefore, localName } = await this.lanes.changeScope(remoteScope, laneName);
277
+ return `the remote-scope of ${chalk.bold(localName)} has been changed from ${chalk.bold(
278
+ remoteScopeBefore
279
+ )} to ${chalk.bold(remoteScope)}`;
280
+ }
281
+ }
282
+
283
+ export class LaneRenameCmd implements Command {
284
+ name = 'rename <new-name>';
285
+ description = `EXPERIMENTAL. change the lane-name locally`;
286
+ extendedDescription = 'the remote will be updated after the next "bit export" command';
287
+ alias = '';
288
+ options = [
289
+ ['l', 'lane-name <lane-name>', 'the name of the lane to rename. if not specified, the current lane is used'],
290
+ ] as CommandOptions;
291
+ loader = true;
292
+ migration = true;
293
+ constructor(private lanes: LanesMain) {}
294
+
295
+ async report([newName]: [string], { laneName }: { laneName?: string }): Promise<string> {
296
+ const { currentName } = await this.lanes.rename(newName, laneName);
297
+ return `the lane ${chalk.bold(currentName)}'s name has been changed to ${chalk.bold(newName)}.`;
298
+ }
299
+ }
300
+
301
+ export class LaneRemoveCmd implements Command {
302
+ name = 'remove <lanes...>';
303
+ arguments = [{ name: 'lanes...', description: 'A list of lane names, separated by spaces' }];
304
+ description = `remove or delete lanes`;
305
+ group = 'collaborate';
306
+ alias = '';
307
+ options = [
308
+ [
309
+ 'r',
310
+ 'remote',
311
+ 'delete a remote lane. use remote/lane-id syntax e.g. bit lane remove owner.org/my-lane --remote. Delete is immediate, no export required',
312
+ ],
313
+ ['f', 'force', 'removes/deletes the lane even when the lane is not yet merged to main'],
314
+ ['s', 'silent', 'skip confirmation'],
315
+ ] as CommandOptions;
316
+ loader = true;
317
+ migration = true;
318
+
319
+ constructor(private lanes: LanesMain) {}
320
+
321
+ async report(
322
+ [names]: [string[]],
323
+ {
324
+ remote = false,
325
+ force = false,
326
+ silent = false,
327
+ }: {
328
+ remote: boolean;
329
+ force: boolean;
330
+ silent: boolean;
331
+ }
332
+ ): Promise<string> {
333
+ if (!silent) {
334
+ const removePromptResult = await approveOperation();
335
+ // @ts-ignore
336
+ if (!yn(removePromptResult.shouldProceed)) {
337
+ throw new BitError('the operation has been cancelled');
338
+ }
339
+ }
340
+ const laneResults = await this.lanes.removeLanes(names, { remote, force });
341
+ return chalk.green(`successfully removed the following lane(s): ${chalk.bold(laneResults.join(', '))}`);
342
+ }
343
+ }
344
+
345
+ export type RemoveCompsOpts = { workspaceOnly?: boolean; updateMain?: boolean };
346
+
347
+ export class LaneRemoveCompCmd implements Command {
348
+ name = 'remove-comp <component-pattern>';
349
+ arguments = [
350
+ {
351
+ name: 'component-pattern',
352
+ description: COMPONENT_PATTERN_HELP,
353
+ },
354
+ ];
355
+ description = `DEPRECATED. remove components when on a lane`;
356
+ group = 'collaborate';
357
+ alias = 'rc';
358
+ options = [
359
+ [
360
+ '',
361
+ 'workspace-only',
362
+ 'do not mark the components as removed from the lane. instead, remove them from the workspace only',
363
+ ],
364
+ [
365
+ '',
366
+ 'update-main',
367
+ 'EXPERIMENTAL. remove, i.e. delete, component/s on the main lane after merging this lane into main',
368
+ ],
369
+ ] as CommandOptions;
370
+ loader = true;
371
+ migration = true;
372
+
373
+ constructor(private workspace: Workspace, private lanes: LanesMain) {}
374
+
375
+ async report(): Promise<string> {
376
+ throw new BitError(`bit lane remove-comp has been removed. please use "bit remove" or "bit delete" instead`);
377
+ }
378
+ }
379
+
380
+ export class LaneImportCmd implements Command {
381
+ name = 'import <lane>';
382
+ description = `import a remote lane to your workspace and switch to that lane`;
383
+ arguments = [{ name: 'lane', description: 'the remote lane name' }];
384
+ alias = '';
385
+ options = [
386
+ ['x', 'skip-dependency-installation', 'do not install dependencies of the imported components'],
387
+ [
388
+ 'p',
389
+ 'pattern <component-pattern>',
390
+ 'import only components from the lane that fit the specified component-pattern to the workspace. works only when the workspace is empty',
391
+ ],
392
+ ] as CommandOptions;
393
+ loader = true;
394
+ migration = true;
395
+
396
+ constructor(private switchCmd: SwitchCmd) {}
397
+
398
+ async report(
399
+ [lane]: [string],
400
+ { skipDependencyInstallation = false, pattern }: { skipDependencyInstallation: boolean; pattern?: string }
401
+ ): Promise<string> {
402
+ return this.switchCmd.report([lane], { getAll: true, skipDependencyInstallation, pattern });
403
+ }
404
+ }
405
+
406
+ export class LaneCmd implements Command {
407
+ name = 'lane [sub-command]';
408
+ description = 'manage lanes - if no sub-command is used, runs "bit lane list"';
409
+ alias = 'l';
410
+ options = [
411
+ ['d', 'details', 'show more details on the state of each component in each lane'],
412
+ ['j', 'json', 'show lanes details in json format'],
413
+ ['r', 'remote <remote-scope-name>', 'show all remote lanes from the specified scope'],
414
+ ['', 'merged', 'list only merged lanes'],
415
+ ['', 'not-merged', "list only lanes that haven't been merged"],
416
+ ] as CommandOptions;
417
+ loader = true;
418
+ migration = true;
419
+ group = 'collaborate';
420
+ remoteOp = true;
421
+ skipWorkspace = true;
422
+ helpUrl = 'reference/components/lanes';
423
+ commands: Command[] = [];
424
+
425
+ constructor(private lanes: LanesMain, private workspace: Workspace, private scope: ScopeMain) {}
426
+
427
+ async report([name]: [string], laneOptions: LaneOptions): Promise<string> {
428
+ return new LaneListCmd(this.lanes, this.workspace, this.scope).report([name], laneOptions);
429
+ }
430
+ }
431
+
432
+ export class LaneRemoveReadmeCmd implements Command {
433
+ name = 'remove-readme [laneName]';
434
+ description = 'EXPERIMENTAL. remove lane readme component';
435
+ options = [] as CommandOptions;
436
+ loader = true;
437
+ skipWorkspace = false;
438
+
439
+ constructor(private lanes: LanesMain) {}
440
+
441
+ async report([laneName]: [string]): Promise<string> {
442
+ const { result, message } = await this.lanes.removeLaneReadme(laneName);
443
+
444
+ if (result) {
445
+ return chalk.green(
446
+ `the readme component has been successfully removed from the lane ${
447
+ laneName || this.lanes.getCurrentLaneName()
448
+ }`
449
+ );
450
+ }
451
+
452
+ return chalk.red(`${message}\n`);
453
+ }
454
+ }
455
+
456
+ export class LaneAddReadmeCmd implements Command {
457
+ name = 'add-readme <component-name> [lane-name]';
458
+ description = 'EXPERIMENTAL. sets an existing component as the readme of a lane';
459
+ arguments = [
460
+ { name: 'component-id', description: "the component name or id of the component to use as the lane's readme" },
461
+ { name: 'lane-name', description: 'the lane to attach the readme to (defaults to the current lane)' },
462
+ ];
463
+ options = [] as CommandOptions;
464
+ loader = true;
465
+ skipWorkspace = false;
466
+
467
+ constructor(private lanes: LanesMain) {}
468
+
469
+ async report([componentId, laneName]: [string, string]): Promise<string> {
470
+ const { result, message } = await this.lanes.addLaneReadme(componentId, laneName);
471
+
472
+ if (result)
473
+ return chalk.green(
474
+ `the component ${componentId} has been successfully added as the readme component for the lane ${
475
+ laneName || this.lanes.getCurrentLaneName()
476
+ }`
477
+ );
478
+
479
+ return chalk.red(
480
+ `${message || ''}\nthe component ${componentId} could not be added as a readme component for the lane ${
481
+ laneName || this.lanes.getCurrentLaneName()
482
+ }`
483
+ );
484
+ }
485
+ }
486
+
487
+ function outputComponents(components: LaneData['components']): string {
488
+ const componentsTitle = `\t${chalk.bold(`components (${components.length})`)}\n`;
489
+ const componentsStr = components.map((c) => `\t ${c.id.toString()} - ${c.head}`).join('\n');
490
+ return componentsTitle + componentsStr;
491
+ }
492
+
493
+ function outputReadmeComponent(component: LaneData['readmeComponent']): string {
494
+ if (!component) return '';
495
+ return `\n\t${`${chalk.yellow('readme component')}\n\t ${component.id} - ${
496
+ component.head ||
497
+ `(unsnapped)\n\t("use bit snap ${component.id.fullName}" to snap the readme component on the lane before exporting)`
498
+ }`}\n`;
499
+ }
@@ -0,0 +1,7 @@
1
+ import { Aspect } from '@teambit/harmony';
2
+
3
+ export const LanesAspect = Aspect.create({
4
+ id: 'teambit.lanes/lanes',
5
+ });
6
+
7
+ export default LanesAspect;
@@ -0,0 +1,28 @@
1
+ import { Route, Verb, Request, Response } from '@teambit/express';
2
+ import { Logger } from '@teambit/logger';
3
+ import { LanesMain } from './lanes.main.runtime';
4
+
5
+ export class LanesCreateRoute implements Route {
6
+ constructor(private lanes: LanesMain, private logger: Logger) {}
7
+
8
+ method = 'post';
9
+ route = this.lanes.createRoutePath;
10
+ verb = Verb.WRITE;
11
+
12
+ middlewares = [
13
+ async (req: Request, res: Response) => {
14
+ const { body } = req;
15
+ const laneName = body.name;
16
+ if (!laneName) {
17
+ return res.status(400).send('Missing laneName in body');
18
+ }
19
+ try {
20
+ const result = await this.lanes.createLane(laneName);
21
+ return res.json(result);
22
+ } catch (e: any) {
23
+ this.logger.error(e.toString());
24
+ return res.status(500).send(e.toString());
25
+ }
26
+ },
27
+ ];
28
+ }
@@ -0,0 +1,31 @@
1
+ import { Route, Verb, Request, Response } from '@teambit/express';
2
+ import { Logger } from '@teambit/logger';
3
+ import { LanesMain } from './lanes.main.runtime';
4
+
5
+ export class LanesDeleteRoute implements Route {
6
+ constructor(private lanes: LanesMain, private logger: Logger) {}
7
+
8
+ method = 'post';
9
+ route = this.lanes.deleteRoutePath;
10
+ verb = Verb.WRITE;
11
+
12
+ middlewares = [
13
+ async (req: Request, res: Response) => {
14
+ const { body } = req;
15
+ const laneNames = body.names;
16
+ if (!laneNames) {
17
+ return res.status(400).send('Missing laneNames in body');
18
+ }
19
+ if (laneNames.length === 0) {
20
+ return res.status(204).send('No laneNames provided to delete');
21
+ }
22
+ try {
23
+ const result = await this.lanes.removeLanes(laneNames);
24
+ return res.json(result);
25
+ } catch (e: any) {
26
+ this.logger.error(e.toString());
27
+ return res.status(500).send(e.toString());
28
+ }
29
+ },
30
+ ];
31
+ }