@teambit/lanes 0.0.290 → 0.0.293

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.
@@ -0,0 +1,461 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ require("core-js/modules/es.array.iterator.js");
6
+
7
+ require("core-js/modules/es.promise.js");
8
+
9
+ Object.defineProperty(exports, "__esModule", {
10
+ value: true
11
+ });
12
+ exports.LaneSwitcher = void 0;
13
+
14
+ function _defineProperty2() {
15
+ const data = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
16
+
17
+ _defineProperty2 = function () {
18
+ return data;
19
+ };
20
+
21
+ return data;
22
+ }
23
+
24
+ function _pMapSeries() {
25
+ const data = _interopRequireDefault(require("p-map-series"));
26
+
27
+ _pMapSeries = function () {
28
+ return data;
29
+ };
30
+
31
+ return data;
32
+ }
33
+
34
+ function _constants() {
35
+ const data = require("@teambit/legacy/dist/constants");
36
+
37
+ _constants = function () {
38
+ return data;
39
+ };
40
+
41
+ return data;
42
+ }
43
+
44
+ function _generalError() {
45
+ const data = _interopRequireDefault(require("@teambit/legacy/dist/error/general-error"));
46
+
47
+ _generalError = function () {
48
+ return data;
49
+ };
50
+
51
+ return data;
52
+ }
53
+
54
+ function _laneId() {
55
+ const data = require("@teambit/legacy/dist/lane-id/lane-id");
56
+
57
+ _laneId = function () {
58
+ return data;
59
+ };
60
+
61
+ return data;
62
+ }
63
+
64
+ function _scopeComponentsImporter() {
65
+ const data = _interopRequireDefault(require("@teambit/legacy/dist/scope/component-ops/scope-components-importer"));
66
+
67
+ _scopeComponentsImporter = function () {
68
+ return data;
69
+ };
70
+
71
+ return data;
72
+ }
73
+
74
+ function _repositories() {
75
+ const data = require("@teambit/legacy/dist/scope/repositories");
76
+
77
+ _repositories = function () {
78
+ return data;
79
+ };
80
+
81
+ return data;
82
+ }
83
+
84
+ function _workspaceLane() {
85
+ const data = _interopRequireDefault(require("@teambit/legacy/dist/consumer/bit-map/workspace-lane"));
86
+
87
+ _workspaceLane = function () {
88
+ return data;
89
+ };
90
+
91
+ return data;
92
+ }
93
+
94
+ function _checkoutVersion() {
95
+ const data = require("@teambit/legacy/dist/consumer/versions-ops/checkout-version");
96
+
97
+ _checkoutVersion = function () {
98
+ return data;
99
+ };
100
+
101
+ return data;
102
+ }
103
+
104
+ function _manyComponentsWriter() {
105
+ const data = _interopRequireDefault(require("@teambit/legacy/dist/consumer/component-ops/many-components-writer"));
106
+
107
+ _manyComponentsWriter = function () {
108
+ return data;
109
+ };
110
+
111
+ return data;
112
+ }
113
+
114
+ function _mergeVersion() {
115
+ const data = require("@teambit/legacy/dist/consumer/versions-ops/merge-version");
116
+
117
+ _mergeVersion = function () {
118
+ return data;
119
+ };
120
+
121
+ return data;
122
+ }
123
+
124
+ function _createLane() {
125
+ const data = _interopRequireDefault(require("@teambit/legacy/dist/consumer/lanes/create-lane"));
126
+
127
+ _createLane = function () {
128
+ return data;
129
+ };
130
+
131
+ return data;
132
+ }
133
+
134
+ function _threeWayMerge() {
135
+ const data = _interopRequireDefault(require("@teambit/legacy/dist/consumer/versions-ops/merge-version/three-way-merge"));
136
+
137
+ _threeWayMerge = function () {
138
+ return data;
139
+ };
140
+
141
+ return data;
142
+ }
143
+
144
+ class LaneSwitcher {
145
+ constructor(workspace, logger, switchProps, checkoutProps) {
146
+ this.workspace = workspace;
147
+ this.logger = logger;
148
+ this.switchProps = switchProps;
149
+ this.checkoutProps = checkoutProps;
150
+ (0, _defineProperty2().default)(this, "consumer", void 0);
151
+ this.consumer = this.workspace.consumer;
152
+ }
153
+
154
+ async switch() {
155
+ this.logger.setStatusLine(`switching lanes`);
156
+ await this.populateSwitchProps();
157
+ const allComponentsStatus = await this.getAllComponentsStatus();
158
+ const componentWithConflict = allComponentsStatus.find(component => component.mergeResults && component.mergeResults.hasConflicts);
159
+
160
+ if (componentWithConflict) {
161
+ if (!this.checkoutProps.promptMergeOptions && !this.checkoutProps.mergeStrategy) {
162
+ throw new (_generalError().default)(`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`);
163
+ }
164
+
165
+ if (!this.checkoutProps.mergeStrategy) this.checkoutProps.mergeStrategy = await (0, _mergeVersion().getMergeStrategyInteractive)();
166
+ }
167
+
168
+ const failedComponents = allComponentsStatus.filter(componentStatus => componentStatus.failureMessage).map(componentStatus => ({
169
+ id: componentStatus.id,
170
+ failureMessage: componentStatus.failureMessage
171
+ }));
172
+ const succeededComponents = allComponentsStatus.filter(componentStatus => !componentStatus.failureMessage); // do not use Promise.all for applyVersion. otherwise, it'll write all components in parallel,
173
+ // which can be an issue when some components are also dependencies of others
174
+
175
+ const componentsResults = await (0, _pMapSeries().default)(succeededComponents, ({
176
+ id,
177
+ componentFromFS,
178
+ mergeResults
179
+ }) => {
180
+ return (0, _checkoutVersion().applyVersion)(this.consumer, id, componentFromFS, mergeResults, this.checkoutProps);
181
+ });
182
+ (0, _checkoutVersion().markFilesToBeRemovedIfNeeded)(succeededComponents, componentsResults);
183
+ await this.saveLanesData();
184
+ const componentsWithDependencies = componentsResults.map(c => c.component).filter(c => c);
185
+ const manyComponentsWriter = new (_manyComponentsWriter().default)({
186
+ consumer: this.consumer,
187
+ componentsWithDependencies,
188
+ installNpmPackages: !this.checkoutProps.skipNpmInstall,
189
+ override: true,
190
+ verbose: this.checkoutProps.verbose,
191
+ writeDists: !this.checkoutProps.ignoreDist,
192
+ writeConfig: this.checkoutProps.writeConfig,
193
+ writePackageJson: !this.checkoutProps.ignorePackageJson
194
+ });
195
+ await manyComponentsWriter.writeAll();
196
+ await (0, _checkoutVersion().deleteFilesIfNeeded)(componentsResults, this.consumer);
197
+ const appliedVersionComponents = componentsResults.map(c => c.applyVersionResult);
198
+ await this.consumer.onDestroy();
199
+ return {
200
+ components: appliedVersionComponents,
201
+ failedComponents
202
+ };
203
+ }
204
+
205
+ async populateSwitchProps() {
206
+ const lanes = await this.consumer.scope.listLanes();
207
+
208
+ const isDefaultLane = this.switchProps.laneName === _constants().DEFAULT_LANE;
209
+
210
+ const localLane = lanes.find(lane => lane.name === this.switchProps.laneName);
211
+
212
+ if (isDefaultLane || localLane) {
213
+ this.populatePropsAccordingToLocalLane(localLane);
214
+ } else {
215
+ await this.populatePropsAccordingToRemoteLane(lanes);
216
+ }
217
+ }
218
+
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
+ }
227
+
228
+ if (remoteLaneId.name === _constants().DEFAULT_LANE) {
229
+ throw new (_generalError().default)(`invalid remote lane id "${this.switchProps.laneName}". to switch to the main lane on remote,
230
+ run "bit switch main" and then "bit import".`);
231
+ } // fetch the remote to update all heads
232
+
233
+
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 (_generalError().default)(`already checked out to "${this.switchProps.localLaneName}"`);
240
+ }
241
+
242
+ const scopeComponentImporter = _scopeComponentsImporter().default.getInstance(this.consumer.scope);
243
+
244
+ const remoteLaneObjects = await scopeComponentImporter.importFromLanes([remoteLaneId]);
245
+
246
+ if (remoteLaneObjects.length === 0) {
247
+ throw new (_generalError().default)(`invalid lane id "${this.switchProps.laneName}", the lane ${this.switchProps.laneName} doesn't exist.`);
248
+ }
249
+
250
+ const remoteLaneComponents = remoteLaneObjects[0].components;
251
+ this.switchProps.remoteLaneName = remoteLaneId.name;
252
+ this.switchProps.laneName = remoteLaneId.name;
253
+ this.switchProps.remoteLaneScope = remoteLaneId.scope;
254
+ this.switchProps.remoteScope = remoteLaneId.scope;
255
+ this.switchProps.ids = remoteLaneComponents.map(l => l.id.changeVersion(l.head.toString()));
256
+ this.switchProps.remoteLaneComponents = remoteLaneComponents;
257
+ this.switchProps.localTrackedLane = localTrackedLane || undefined;
258
+ const laneExistsLocally = lanes.find(l => l.name === this.switchProps.localLaneName);
259
+
260
+ if (laneExistsLocally) {
261
+ throw new (_generalError().default)(`unable to checkout to a remote lane ${this.switchProps.remoteScope}/${this.switchProps.laneName}.
262
+ the local lane "${this.switchProps.localLaneName}" already exists, please switch to the local lane first by running "bit switch ${this.switchProps.localLaneName}"
263
+ then, to merge the remote lane into the local lane, run "bit lane merge ${this.switchProps.localLaneName} --remote ${this.switchProps.remoteScope}"`);
264
+ }
265
+
266
+ this.logger.debug(`populatePropsAccordingToRemoteLane, completed`);
267
+ }
268
+
269
+ populatePropsAccordingToLocalLane(localLane) {
270
+ this.switchProps.localLaneName = this.switchProps.laneName;
271
+
272
+ if (this.consumer.getCurrentLaneId().name === this.switchProps.laneName) {
273
+ throw new (_generalError().default)(`already checked out to "${this.switchProps.laneName}"`);
274
+ }
275
+
276
+ if (this.switchProps.laneName === _constants().DEFAULT_LANE) {
277
+ this.switchProps.ids = this.consumer.bitMap.getAuthoredAndImportedBitIdsOfDefaultLane();
278
+ return;
279
+ }
280
+
281
+ if (!localLane) {
282
+ throw new (_generalError().default)(`unable to find a local lane "${this.switchProps.laneName}", to create a new lane please run "bit lane create"`);
283
+ }
284
+
285
+ this.switchProps.ids = localLane.components.map(c => c.id.changeVersion(c.head.toString()));
286
+ }
287
+
288
+ async getAllComponentsStatus() {
289
+ const {
290
+ ids
291
+ } = this.switchProps;
292
+ const tmp = new (_repositories().Tmp)(this.consumer.scope);
293
+
294
+ try {
295
+ const componentsStatusP = ids.map(id => getComponentStatus(this.consumer, id, this.switchProps));
296
+ const componentsStatus = await Promise.all(componentsStatusP);
297
+ await tmp.clear(); // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
298
+
299
+ return componentsStatus;
300
+ } catch (err) {
301
+ await tmp.clear();
302
+ throw err;
303
+ }
304
+ }
305
+
306
+ async saveLanesData() {
307
+ await saveCheckedOutLaneInfo(this.consumer, {
308
+ remoteLaneScope: this.switchProps.remoteLaneScope,
309
+ remoteLaneName: this.switchProps.remoteLaneName,
310
+ localLaneName: this.switchProps.localLaneName,
311
+ addTrackingInfo: !this.switchProps.localTrackedLane,
312
+ laneComponents: this.switchProps.remoteLaneComponents
313
+ });
314
+ }
315
+
316
+ }
317
+
318
+ exports.LaneSwitcher = LaneSwitcher;
319
+
320
+ async function saveCheckedOutLaneInfo(consumer, opts) {
321
+ const saveRemoteLaneToBitmap = () => {
322
+ if (opts.remoteLaneScope) {
323
+ consumer.bitMap.setRemoteLane(_laneId().RemoteLaneId.from(opts.remoteLaneName, opts.remoteLaneScope)); // add versions to lane
324
+ }
325
+ };
326
+
327
+ const throwIfLaneExists = async () => {
328
+ const allLanes = await consumer.scope.listLanes();
329
+
330
+ if (allLanes.find(l => l.name === opts.localLaneName)) {
331
+ throw new (_generalError().default)(`unable to checkout to lane "${opts.localLaneName}".
332
+ the lane already exists. please switch to the lane and merge`);
333
+ }
334
+ };
335
+
336
+ if (opts.remoteLaneScope) {
337
+ await throwIfLaneExists();
338
+ await (0, _createLane().default)(consumer, opts.localLaneName, opts.laneComponents);
339
+
340
+ if (opts.addTrackingInfo) {
341
+ // otherwise, it is tracked already
342
+ consumer.scope.lanes.trackLane({
343
+ localLane: opts.localLaneName,
344
+ remoteLane: opts.remoteLaneName,
345
+ remoteScope: opts.remoteLaneScope
346
+ });
347
+ }
348
+ }
349
+
350
+ saveRemoteLaneToBitmap();
351
+ consumer.scope.lanes.setCurrentLane(opts.localLaneName);
352
+ const workspaceLane = opts.localLaneName === _constants().DEFAULT_LANE ? null : _workspaceLane().default.load(opts.localLaneName, consumer.scope.path);
353
+ consumer.bitMap.syncWithLanes(workspaceLane);
354
+ }
355
+
356
+ async function getComponentStatus(consumer, id, switchProps) {
357
+ const componentStatus = {
358
+ id
359
+ };
360
+
361
+ const returnFailure = msg => {
362
+ componentStatus.failureMessage = msg;
363
+ return componentStatus;
364
+ };
365
+
366
+ const modelComponent = await consumer.scope.getModelComponentIfExist(id);
367
+
368
+ if (!modelComponent) {
369
+ return returnFailure(`component ${id.toString()} had never imported`);
370
+ }
371
+
372
+ const unmerged = consumer.scope.objects.unmergedComponents.getEntry(id.name);
373
+
374
+ if (unmerged && unmerged.resolved === false) {
375
+ return returnFailure(`component ${id.toStringWithoutVersion()} has conflicts that need to be resolved first, please use bit merge --resolve/--abort`);
376
+ }
377
+
378
+ const version = id.version;
379
+
380
+ if (!version) {
381
+ return returnFailure(`component doesn't have any snaps on ${_constants().DEFAULT_LANE}`);
382
+ }
383
+
384
+ const existingBitMapId = consumer.bitMap.getBitIdIfExist(id, {
385
+ ignoreVersion: true
386
+ });
387
+ const componentOnLane = await modelComponent.loadVersion(version, consumer.scope.objects);
388
+
389
+ if (!existingBitMapId) {
390
+ if (switchProps.existingOnWorkspaceOnly) {
391
+ return returnFailure(`component ${id.toStringWithoutVersion()} is not in the workspace`);
392
+ }
393
+
394
+ return {
395
+ componentFromFS: undefined,
396
+ componentFromModel: componentOnLane,
397
+ id,
398
+ mergeResults: null
399
+ };
400
+ }
401
+
402
+ if (!existingBitMapId.hasVersion()) {
403
+ // happens when switching from main to a lane and a component was snapped on the lane.
404
+ // in the .bitmap file, the version is "latest" or empty. so we just need to write the component according to the
405
+ // model. we don't care about the componentFromFS
406
+ return {
407
+ componentFromFS: undefined,
408
+ componentFromModel: componentOnLane,
409
+ id,
410
+ mergeResults: null
411
+ };
412
+ }
413
+
414
+ const currentlyUsedVersion = existingBitMapId.version;
415
+
416
+ if (currentlyUsedVersion === version) {
417
+ return returnFailure(`component ${id.toStringWithoutVersion()} is already at version ${version}`);
418
+ } // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
419
+
420
+
421
+ const baseComponent = await modelComponent.loadVersion(currentlyUsedVersion, consumer.scope.objects);
422
+ const component = await consumer.loadComponent(existingBitMapId);
423
+ const isModified = await consumer.isComponentModified(baseComponent, component);
424
+ let mergeResults;
425
+
426
+ const isHeadSameAsMain = () => {
427
+ const head = modelComponent.getHead();
428
+ if (!head) return false;
429
+ if (!existingBitMapId.version) return false;
430
+ const tagVersion = modelComponent.getTagOfRefIfExists(head);
431
+ const headVersion = tagVersion || head.toString();
432
+ return existingBitMapId.version === headVersion;
433
+ };
434
+
435
+ if (isModified) {
436
+ if (!isHeadSameAsMain()) {
437
+ throw new (_generalError().default)(`unable to checkout ${id.toStringWithoutVersion()}, the component is modified and belongs to another lane`);
438
+ }
439
+
440
+ const otherComponent = await modelComponent.loadVersion(existingBitMapId.version, // we are here because the head is same as main. so, existingBitMapId.version must be set
441
+ consumer.scope.objects);
442
+ mergeResults = await (0, _threeWayMerge().default)({
443
+ consumer,
444
+ otherComponent,
445
+ otherLabel: version,
446
+ currentComponent: component,
447
+ currentLabel: `${currentlyUsedVersion} modified`,
448
+ baseComponent
449
+ });
450
+ } // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
451
+
452
+
453
+ return {
454
+ componentFromFS: component,
455
+ componentFromModel: componentOnLane,
456
+ id,
457
+ mergeResults
458
+ };
459
+ }
460
+
461
+ //# sourceMappingURL=switch-lanes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["switch-lanes.ts"],"names":["LaneSwitcher","constructor","workspace","logger","switchProps","checkoutProps","consumer","switch","setStatusLine","populateSwitchProps","allComponentsStatus","getAllComponentsStatus","componentWithConflict","find","component","mergeResults","hasConflicts","promptMergeOptions","mergeStrategy","GeneralError","id","toStringWithoutVersion","failedComponents","filter","componentStatus","failureMessage","map","succeededComponents","componentsResults","componentFromFS","saveLanesData","componentsWithDependencies","c","manyComponentsWriter","ManyComponentsWriter","installNpmPackages","skipNpmInstall","override","verbose","writeDists","ignoreDist","writeConfig","writePackageJson","ignorePackageJson","writeAll","appliedVersionComponents","applyVersionResult","onDestroy","components","lanes","scope","listLanes","isDefaultLane","laneName","DEFAULT_LANE","localLane","lane","name","populatePropsAccordingToLocalLane","populatePropsAccordingToRemoteLane","remoteLaneId","RemoteLaneId","parse","e","localTrackedLane","getLocalTrackedLaneByRemoteName","debug","toString","localLaneName","newLaneName","getCurrentLaneId","scopeComponentImporter","ScopeComponentsImporter","getInstance","remoteLaneObjects","importFromLanes","length","remoteLaneComponents","remoteLaneName","remoteLaneScope","remoteScope","ids","l","changeVersion","head","undefined","laneExistsLocally","bitMap","getAuthoredAndImportedBitIdsOfDefaultLane","tmp","Tmp","componentsStatusP","getComponentStatus","componentsStatus","Promise","all","clear","err","saveCheckedOutLaneInfo","addTrackingInfo","laneComponents","opts","saveRemoteLaneToBitmap","setRemoteLane","from","throwIfLaneExists","allLanes","trackLane","remoteLane","setCurrentLane","workspaceLane","WorkspaceLane","load","path","syncWithLanes","returnFailure","msg","modelComponent","getModelComponentIfExist","unmerged","objects","unmergedComponents","getEntry","resolved","version","existingBitMapId","getBitIdIfExist","ignoreVersion","componentOnLane","loadVersion","existingOnWorkspaceOnly","componentFromModel","hasVersion","currentlyUsedVersion","baseComponent","loadComponent","isModified","isComponentModified","isHeadSameAsMain","getHead","tagVersion","getTagOfRefIfExists","headVersion","otherComponent","otherLabel","currentComponent","currentLabel"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAKA;AAAA;;AAA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AMjCC,MAAAA;AANiC,KAAd,CAArB;AAQD,GAtEkH,CAuEnH;;;AACA,SAAO;AAAEzG,IAAAA,eAAe,EAAEf,SAAnB;AAA8BqH,IAAAA,kBAAkB,EAAEH,eAAlD;AAAmE5G,IAAAA,EAAnE;AAAuEL,IAAAA;AAAvE,GAAP;AACD","sourcesContent":["import mapSeries from 'p-map-series';\nimport { DEFAULT_LANE } from '@teambit/legacy/dist/constants';\nimport { Consumer } from '@teambit/legacy/dist/consumer';\nimport GeneralError from '@teambit/legacy/dist/error/general-error';\nimport { RemoteLaneId } from '@teambit/legacy/dist/lane-id/lane-id';\nimport ScopeComponentsImporter from '@teambit/legacy/dist/scope/component-ops/scope-components-importer';\nimport { BitId } from '@teambit/legacy-bit-id';\nimport { ComponentWithDependencies } from '@teambit/legacy/dist/scope';\nimport { Version, Lane } from '@teambit/legacy/dist/scope/models';\nimport { LaneComponent } from '@teambit/legacy/dist/scope/models/lane';\nimport { Tmp } from '@teambit/legacy/dist/scope/repositories';\nimport WorkspaceLane from '@teambit/legacy/dist/consumer/bit-map/workspace-lane';\nimport {\n applyVersion,\n ComponentStatus,\n CheckoutProps,\n deleteFilesIfNeeded,\n markFilesToBeRemovedIfNeeded,\n} from '@teambit/legacy/dist/consumer/versions-ops/checkout-version';\nimport ManyComponentsWriter from '@teambit/legacy/dist/consumer/component-ops/many-components-writer';\nimport {\n FailedComponents,\n getMergeStrategyInteractive,\n ApplyVersionResults,\n} from '@teambit/legacy/dist/consumer/versions-ops/merge-version';\nimport createNewLane from '@teambit/legacy/dist/consumer/lanes/create-lane';\nimport threeWayMerge, {\n MergeResultsThreeWay,\n} from '@teambit/legacy/dist/consumer/versions-ops/merge-version/three-way-merge';\nimport { Workspace } from '@teambit/workspace';\nimport { Logger } from '@teambit/logger';\n\nexport type SwitchProps = {\n laneName: string;\n remoteScope?: string;\n ids?: BitId[];\n existingOnWorkspaceOnly: boolean;\n localLaneName?: string;\n remoteLaneScope?: string;\n remoteLaneName?: string;\n remoteLaneComponents?: LaneComponent[];\n localTrackedLane?: string;\n newLaneName?: string;\n};\n\nexport class LaneSwitcher {\n private consumer: Consumer;\n constructor(\n private workspace: Workspace,\n private logger: Logger,\n private switchProps: SwitchProps,\n private checkoutProps: CheckoutProps\n ) {\n this.consumer = this.workspace.consumer;\n }\n\n async switch(): Promise<ApplyVersionResults> {\n this.logger.setStatusLine(`switching lanes`);\n await this.populateSwitchProps();\n const allComponentsStatus: ComponentStatus[] = await this.getAllComponentsStatus();\n const componentWithConflict = allComponentsStatus.find(\n (component) => component.mergeResults && component.mergeResults.hasConflicts\n );\n if (componentWithConflict) {\n if (!this.checkoutProps.promptMergeOptions && !this.checkoutProps.mergeStrategy) {\n throw new GeneralError(\n `automatic merge has failed for component ${componentWithConflict.id.toStringWithoutVersion()}.\\nplease use \"--manual\" to manually merge changes or use \"--theirs / --ours\" to choose one of the conflicted versions`\n );\n }\n if (!this.checkoutProps.mergeStrategy) this.checkoutProps.mergeStrategy = await getMergeStrategyInteractive();\n }\n const failedComponents: FailedComponents[] = allComponentsStatus\n .filter((componentStatus) => componentStatus.failureMessage)\n .map((componentStatus) => ({ id: componentStatus.id, failureMessage: componentStatus.failureMessage as string }));\n\n const succeededComponents = allComponentsStatus.filter((componentStatus) => !componentStatus.failureMessage);\n // do not use Promise.all for applyVersion. otherwise, it'll write all components in parallel,\n // which can be an issue when some components are also dependencies of others\n const componentsResults = await mapSeries(succeededComponents, ({ id, componentFromFS, mergeResults }) => {\n return applyVersion(this.consumer, id, componentFromFS, mergeResults, this.checkoutProps);\n });\n\n markFilesToBeRemovedIfNeeded(succeededComponents, componentsResults);\n\n await this.saveLanesData();\n\n const componentsWithDependencies = componentsResults\n .map((c) => c.component)\n .filter((c) => c) as ComponentWithDependencies[];\n\n const manyComponentsWriter = new ManyComponentsWriter({\n consumer: this.consumer,\n componentsWithDependencies,\n installNpmPackages: !this.checkoutProps.skipNpmInstall,\n override: true,\n verbose: this.checkoutProps.verbose,\n writeDists: !this.checkoutProps.ignoreDist,\n writeConfig: this.checkoutProps.writeConfig,\n writePackageJson: !this.checkoutProps.ignorePackageJson,\n });\n await manyComponentsWriter.writeAll();\n await deleteFilesIfNeeded(componentsResults, this.consumer);\n\n const appliedVersionComponents = componentsResults.map((c) => c.applyVersionResult);\n\n await this.consumer.onDestroy();\n\n return { components: appliedVersionComponents, failedComponents };\n }\n\n private async populateSwitchProps() {\n const lanes = await this.consumer.scope.listLanes();\n const isDefaultLane = this.switchProps.laneName === DEFAULT_LANE;\n\n const localLane = lanes.find((lane) => lane.name === this.switchProps.laneName);\n\n if (isDefaultLane || localLane) {\n this.populatePropsAccordingToLocalLane(localLane);\n } else {\n await this.populatePropsAccordingToRemoteLane(lanes);\n }\n }\n\n private async populatePropsAccordingToRemoteLane(lanes: Lane[]) {\n let remoteLaneId: RemoteLaneId;\n try {\n remoteLaneId = RemoteLaneId.parse(this.switchProps.laneName);\n } catch (e) {\n throw new GeneralError(\n `invalid lane id \"${this.switchProps.laneName}\", the lane ${this.switchProps.laneName} doesn't exist.`\n );\n }\n if (remoteLaneId.name === DEFAULT_LANE) {\n throw new GeneralError(`invalid remote lane id \"${this.switchProps.laneName}\". to switch to the main lane on remote,\n run \"bit switch main\" and then \"bit import\".`);\n }\n // fetch the remote to update all heads\n const localTrackedLane = this.consumer.scope.lanes.getLocalTrackedLaneByRemoteName(\n remoteLaneId.name,\n remoteLaneId.scope as string\n );\n this.logger.debug(`populatePropsAccordingToRemoteLane, remoteLaneId: ${remoteLaneId.toString()}`);\n this.switchProps.localLaneName = this.switchProps.newLaneName || localTrackedLane || remoteLaneId.name;\n if (this.consumer.getCurrentLaneId().name === this.switchProps.localLaneName) {\n throw new GeneralError(`already checked out to \"${this.switchProps.localLaneName}\"`);\n }\n const scopeComponentImporter = ScopeComponentsImporter.getInstance(this.consumer.scope);\n const remoteLaneObjects = await scopeComponentImporter.importFromLanes([remoteLaneId]);\n if (remoteLaneObjects.length === 0) {\n throw new GeneralError(\n `invalid lane id \"${this.switchProps.laneName}\", the lane ${this.switchProps.laneName} doesn't exist.`\n );\n }\n const remoteLaneComponents = remoteLaneObjects[0].components;\n this.switchProps.remoteLaneName = remoteLaneId.name;\n this.switchProps.laneName = remoteLaneId.name;\n this.switchProps.remoteLaneScope = remoteLaneId.scope;\n this.switchProps.remoteScope = remoteLaneId.scope;\n this.switchProps.ids = remoteLaneComponents.map((l) => l.id.changeVersion(l.head.toString()));\n this.switchProps.remoteLaneComponents = remoteLaneComponents;\n this.switchProps.localTrackedLane = localTrackedLane || undefined;\n const laneExistsLocally = lanes.find((l) => l.name === this.switchProps.localLaneName);\n if (laneExistsLocally) {\n throw new GeneralError(`unable to checkout to a remote lane ${this.switchProps.remoteScope}/${this.switchProps.laneName}.\nthe local lane \"${this.switchProps.localLaneName}\" already exists, please switch to the local lane first by running \"bit switch ${this.switchProps.localLaneName}\"\nthen, to merge the remote lane into the local lane, run \"bit lane merge ${this.switchProps.localLaneName} --remote ${this.switchProps.remoteScope}\"`);\n }\n this.logger.debug(`populatePropsAccordingToRemoteLane, completed`);\n }\n\n private populatePropsAccordingToLocalLane(localLane: Lane | undefined) {\n this.switchProps.localLaneName = this.switchProps.laneName;\n if (this.consumer.getCurrentLaneId().name === this.switchProps.laneName) {\n throw new GeneralError(`already checked out to \"${this.switchProps.laneName}\"`);\n }\n if (this.switchProps.laneName === DEFAULT_LANE) {\n this.switchProps.ids = this.consumer.bitMap.getAuthoredAndImportedBitIdsOfDefaultLane();\n return;\n }\n if (!localLane) {\n throw new GeneralError(\n `unable to find a local lane \"${this.switchProps.laneName}\", to create a new lane please run \"bit lane create\"`\n );\n }\n this.switchProps.ids = localLane.components.map((c) => c.id.changeVersion(c.head.toString()));\n }\n\n private async getAllComponentsStatus(): Promise<ComponentStatus[]> {\n const { ids } = this.switchProps;\n const tmp = new Tmp(this.consumer.scope);\n try {\n const componentsStatusP = (ids as BitId[]).map((id) => getComponentStatus(this.consumer, id, this.switchProps));\n const componentsStatus = await Promise.all(componentsStatusP);\n await tmp.clear();\n // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!\n return componentsStatus;\n } catch (err: any) {\n await tmp.clear();\n throw err;\n }\n }\n private async saveLanesData() {\n await saveCheckedOutLaneInfo(this.consumer, {\n remoteLaneScope: this.switchProps.remoteLaneScope,\n remoteLaneName: this.switchProps.remoteLaneName,\n localLaneName: this.switchProps.localLaneName,\n addTrackingInfo: !this.switchProps.localTrackedLane,\n laneComponents: this.switchProps.remoteLaneComponents,\n });\n }\n}\n\nasync function saveCheckedOutLaneInfo(\n consumer: Consumer,\n opts: {\n remoteLaneScope?: string;\n remoteLaneName?: string;\n localLaneName?: string;\n addTrackingInfo?: boolean;\n laneComponents?: LaneComponent[];\n }\n) {\n const saveRemoteLaneToBitmap = () => {\n if (opts.remoteLaneScope) {\n consumer.bitMap.setRemoteLane(RemoteLaneId.from(opts.remoteLaneName as string, opts.remoteLaneScope));\n // add versions to lane\n }\n };\n const throwIfLaneExists = async () => {\n const allLanes = await consumer.scope.listLanes();\n if (allLanes.find((l) => l.name === opts.localLaneName)) {\n throw new GeneralError(`unable to checkout to lane \"${opts.localLaneName}\".\nthe lane already exists. please switch to the lane and merge`);\n }\n };\n\n if (opts.remoteLaneScope) {\n await throwIfLaneExists();\n await createNewLane(consumer, opts.localLaneName as string, opts.laneComponents);\n if (opts.addTrackingInfo) {\n // otherwise, it is tracked already\n consumer.scope.lanes.trackLane({\n localLane: opts.localLaneName as string,\n remoteLane: opts.remoteLaneName as string,\n remoteScope: opts.remoteLaneScope as string,\n });\n }\n }\n\n saveRemoteLaneToBitmap();\n consumer.scope.lanes.setCurrentLane(opts.localLaneName as string);\n const workspaceLane =\n opts.localLaneName === DEFAULT_LANE ? null : WorkspaceLane.load(opts.localLaneName as string, consumer.scope.path);\n consumer.bitMap.syncWithLanes(workspaceLane);\n}\n\nasync function getComponentStatus(consumer: Consumer, id: BitId, switchProps: SwitchProps): Promise<ComponentStatus> {\n const componentStatus: ComponentStatus = { id };\n const returnFailure = (msg: string) => {\n componentStatus.failureMessage = msg;\n return componentStatus;\n };\n const modelComponent = await consumer.scope.getModelComponentIfExist(id);\n if (!modelComponent) {\n return returnFailure(`component ${id.toString()} had never imported`);\n }\n const unmerged = consumer.scope.objects.unmergedComponents.getEntry(id.name);\n if (unmerged && unmerged.resolved === false) {\n return returnFailure(\n `component ${id.toStringWithoutVersion()} has conflicts that need to be resolved first, please use bit merge --resolve/--abort`\n );\n }\n const version = id.version;\n if (!version) {\n return returnFailure(`component doesn't have any snaps on ${DEFAULT_LANE}`);\n }\n const existingBitMapId = consumer.bitMap.getBitIdIfExist(id, { ignoreVersion: true });\n const componentOnLane: Version = await modelComponent.loadVersion(version, consumer.scope.objects);\n if (!existingBitMapId) {\n if (switchProps.existingOnWorkspaceOnly) {\n return returnFailure(`component ${id.toStringWithoutVersion()} is not in the workspace`);\n }\n return { componentFromFS: undefined, componentFromModel: componentOnLane, id, mergeResults: null };\n }\n if (!existingBitMapId.hasVersion()) {\n // happens when switching from main to a lane and a component was snapped on the lane.\n // in the .bitmap file, the version is \"latest\" or empty. so we just need to write the component according to the\n // model. we don't care about the componentFromFS\n return { componentFromFS: undefined, componentFromModel: componentOnLane, id, mergeResults: null };\n }\n const currentlyUsedVersion = existingBitMapId.version;\n if (currentlyUsedVersion === version) {\n return returnFailure(`component ${id.toStringWithoutVersion()} is already at version ${version}`);\n }\n // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!\n const baseComponent: Version = await modelComponent.loadVersion(currentlyUsedVersion, consumer.scope.objects);\n const component = await consumer.loadComponent(existingBitMapId);\n const isModified = await consumer.isComponentModified(baseComponent, component);\n let mergeResults: MergeResultsThreeWay | null | undefined;\n const isHeadSameAsMain = () => {\n const head = modelComponent.getHead();\n if (!head) return false;\n if (!existingBitMapId.version) return false;\n const tagVersion = modelComponent.getTagOfRefIfExists(head);\n const headVersion = tagVersion || head.toString();\n return existingBitMapId.version === headVersion;\n };\n if (isModified) {\n if (!isHeadSameAsMain()) {\n throw new GeneralError(\n `unable to checkout ${id.toStringWithoutVersion()}, the component is modified and belongs to another lane`\n );\n }\n\n const otherComponent: Version = await modelComponent.loadVersion(\n existingBitMapId.version as string, // we are here because the head is same as main. so, existingBitMapId.version must be set\n consumer.scope.objects\n );\n mergeResults = await threeWayMerge({\n consumer,\n otherComponent,\n otherLabel: version,\n currentComponent: component,\n currentLabel: `${currentlyUsedVersion} modified`,\n baseComponent,\n });\n }\n // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!\n return { componentFromFS: component, componentFromModel: componentOnLane, id, mergeResults };\n}\n"]}
@@ -1,18 +1,20 @@
1
1
  import { Command, CommandOptions } from '@teambit/cli';
2
2
  import { MergeStrategy } from '@teambit/legacy/dist/consumer/versions-ops/merge-version';
3
+ import { LanesMain } from './lanes.main.runtime';
3
4
  export declare class SwitchCmd implements Command {
5
+ private lanes;
4
6
  name: string;
5
7
  description: string;
6
8
  private: boolean;
7
9
  alias: string;
8
10
  options: CommandOptions;
9
11
  loader: boolean;
10
- report([lane]: [string], { as, merge, getAll, skipDependencyInstallation, verbose, json, }: {
12
+ constructor(lanes: LanesMain);
13
+ report([lane]: [string], { as, merge, getAll, skipDependencyInstallation, json, }: {
11
14
  as?: string;
12
15
  merge?: MergeStrategy;
13
16
  getAll?: boolean;
14
17
  skipDependencyInstallation?: boolean;
15
- verbose?: boolean;
16
18
  override?: boolean;
17
19
  json?: boolean;
18
20
  }): Promise<string>;
@@ -31,26 +31,6 @@ function _chalk() {
31
31
  return data;
32
32
  }
33
33
 
34
- function _ramda() {
35
- const data = _interopRequireDefault(require("ramda"));
36
-
37
- _ramda = function () {
38
- return data;
39
- };
40
-
41
- return data;
42
- }
43
-
44
- function _consumer() {
45
- const data = require("@teambit/legacy/dist/api/consumer");
46
-
47
- _consumer = function () {
48
- return data;
49
- };
50
-
51
- return data;
52
- }
53
-
54
34
  function _mergeVersion() {
55
35
  const data = require("@teambit/legacy/dist/consumer/versions-ops/merge-version");
56
36
 
@@ -61,23 +41,14 @@ function _mergeVersion() {
61
41
  return data;
62
42
  }
63
43
 
64
- function _bitError() {
65
- const data = require("@teambit/bit-error");
66
-
67
- _bitError = function () {
68
- return data;
69
- };
70
-
71
- return data;
72
- }
73
-
74
44
  class SwitchCmd {
75
- constructor() {
45
+ constructor(lanes) {
46
+ this.lanes = lanes;
76
47
  (0, _defineProperty2().default)(this, "name", 'switch <lane>');
77
48
  (0, _defineProperty2().default)(this, "description", `switch to the specified lane`);
78
49
  (0, _defineProperty2().default)(this, "private", true);
79
50
  (0, _defineProperty2().default)(this, "alias", '');
80
- (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'], ['v', 'verbose', 'showing verbose output for inspection'], ['j', 'json', 'return the output as JSON']]);
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']]);
81
52
  (0, _defineProperty2().default)(this, "loader", true);
82
53
  }
83
54
 
@@ -86,45 +57,17 @@ class SwitchCmd {
86
57
  merge,
87
58
  getAll = false,
88
59
  skipDependencyInstallation = false,
89
- verbose = false,
90
60
  json = false
91
61
  }) {
92
- let mergeStrategy;
93
-
94
- if (merge && _ramda().default.is(String, merge)) {
95
- const options = Object.keys(_mergeVersion().MergeOptions);
96
-
97
- if (!options.includes(merge)) {
98
- throw new (_bitError().BitError)(`merge must be one of the following: ${options.join(', ')}`);
99
- }
100
-
101
- mergeStrategy = merge;
102
- }
103
-
104
- const switchProps = {
105
- laneName: lane,
106
- existingOnWorkspaceOnly: !getAll,
107
- newLaneName: as
108
- };
109
- const checkoutProps = {
110
- mergeStrategy,
111
- verbose,
112
- skipNpmInstall: skipDependencyInstallation,
113
- // not relevant in Harmony
114
- ignorePackageJson: true,
115
- // not relevant in Harmony
116
- ignoreDist: true,
117
- // not relevant in Harmony
118
- isLane: true,
119
- promptMergeOptions: false,
120
- writeConfig: false,
121
- reset: false,
122
- all: false
123
- };
124
62
  const {
125
63
  components,
126
64
  failedComponents
127
- } = await (0, _consumer().switchAction)(switchProps, checkoutProps);
65
+ } = await this.lanes.switchLanes(lane, {
66
+ newLaneName: as,
67
+ merge,
68
+ getAll,
69
+ skipDependencyInstallation
70
+ });
128
71
 
129
72
  if (json) {
130
73
  return JSON.stringify({