@teambit/merging 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +5 -0
- package/dist/index.js +44 -0
- package/dist/index.js.map +1 -0
- package/dist/merge-cmd.d.ts +25 -0
- package/dist/merge-cmd.js +185 -0
- package/dist/merge-cmd.js.map +1 -0
- package/dist/merging.aspect.d.ts +2 -0
- package/dist/merging.aspect.js +24 -0
- package/dist/merging.aspect.js.map +1 -0
- package/dist/merging.main.runtime.d.ts +67 -0
- package/dist/merging.main.runtime.js +776 -0
- package/dist/merging.main.runtime.js.map +1 -0
- package/package-tar/teambit-merging-0.0.1.tgz +0 -0
- package/package.json +88 -0
- package/preview-1648092203429.js +1 -0
- package/tsconfig.json +34 -0
- package/types/asset.d.ts +29 -0
- package/types/style.d.ts +42 -0
|
@@ -0,0 +1,776 @@
|
|
|
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.MergingMain = 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 _cli() {
|
|
25
|
+
const data = require("@teambit/cli");
|
|
26
|
+
|
|
27
|
+
_cli = function () {
|
|
28
|
+
return data;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
return data;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function _workspace() {
|
|
35
|
+
const data = _interopRequireDefault(require("@teambit/workspace"));
|
|
36
|
+
|
|
37
|
+
_workspace = function () {
|
|
38
|
+
return data;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
return data;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function _ramda() {
|
|
45
|
+
const data = _interopRequireDefault(require("ramda"));
|
|
46
|
+
|
|
47
|
+
_ramda = function () {
|
|
48
|
+
return data;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
return data;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function _componentsList() {
|
|
55
|
+
const data = _interopRequireDefault(require("@teambit/legacy/dist/consumer/component/components-list"));
|
|
56
|
+
|
|
57
|
+
_componentsList = function () {
|
|
58
|
+
return data;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
return data;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function _lanesIsDisabled() {
|
|
65
|
+
const data = require("@teambit/legacy/dist/consumer/lanes/exceptions/lanes-is-disabled");
|
|
66
|
+
|
|
67
|
+
_lanesIsDisabled = function () {
|
|
68
|
+
return data;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
return data;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function _mergeVersion() {
|
|
75
|
+
const data = require("@teambit/legacy/dist/consumer/versions-ops/merge-version");
|
|
76
|
+
|
|
77
|
+
_mergeVersion = function () {
|
|
78
|
+
return data;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
return data;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function _exceptions() {
|
|
85
|
+
const data = require("@teambit/legacy/dist/consumer/exceptions");
|
|
86
|
+
|
|
87
|
+
_exceptions = function () {
|
|
88
|
+
return data;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
return data;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function _snapping() {
|
|
95
|
+
const data = _interopRequireDefault(require("@teambit/snapping"));
|
|
96
|
+
|
|
97
|
+
_snapping = function () {
|
|
98
|
+
return data;
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
return data;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function _hasWildcard() {
|
|
105
|
+
const data = _interopRequireDefault(require("@teambit/legacy/dist/utils/string/has-wildcard"));
|
|
106
|
+
|
|
107
|
+
_hasWildcard = function () {
|
|
108
|
+
return data;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
return data;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function _fsExtra() {
|
|
115
|
+
const data = _interopRequireDefault(require("fs-extra"));
|
|
116
|
+
|
|
117
|
+
_fsExtra = function () {
|
|
118
|
+
return data;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
return data;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function _pMapSeries() {
|
|
125
|
+
const data = _interopRequireDefault(require("p-map-series"));
|
|
126
|
+
|
|
127
|
+
_pMapSeries = function () {
|
|
128
|
+
return data;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
return data;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function _path() {
|
|
135
|
+
const data = _interopRequireDefault(require("path"));
|
|
136
|
+
|
|
137
|
+
_path = function () {
|
|
138
|
+
return data;
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
return data;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function _bitId() {
|
|
145
|
+
const data = require("@teambit/legacy/dist/bit-id");
|
|
146
|
+
|
|
147
|
+
_bitId = function () {
|
|
148
|
+
return data;
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
return data;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function _constants() {
|
|
155
|
+
const data = require("@teambit/legacy/dist/constants");
|
|
156
|
+
|
|
157
|
+
_constants = function () {
|
|
158
|
+
return data;
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
return data;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function _generalError() {
|
|
165
|
+
const data = _interopRequireDefault(require("@teambit/legacy/dist/error/general-error"));
|
|
166
|
+
|
|
167
|
+
_generalError = function () {
|
|
168
|
+
return data;
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
return data;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function _laneId() {
|
|
175
|
+
const data = require("@teambit/legacy/dist/lane-id/lane-id");
|
|
176
|
+
|
|
177
|
+
_laneId = function () {
|
|
178
|
+
return data;
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
return data;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function _logger() {
|
|
185
|
+
const data = _interopRequireDefault(require("@teambit/legacy/dist/logger/logger"));
|
|
186
|
+
|
|
187
|
+
_logger = function () {
|
|
188
|
+
return data;
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
return data;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function _getDivergeData() {
|
|
195
|
+
const data = require("@teambit/legacy/dist/scope/component-ops/get-diverge-data");
|
|
196
|
+
|
|
197
|
+
_getDivergeData = function () {
|
|
198
|
+
return data;
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
return data;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function _objects() {
|
|
205
|
+
const data = require("@teambit/legacy/dist/scope/objects");
|
|
206
|
+
|
|
207
|
+
_objects = function () {
|
|
208
|
+
return data;
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
return data;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function _repositories() {
|
|
215
|
+
const data = require("@teambit/legacy/dist/scope/repositories");
|
|
216
|
+
|
|
217
|
+
_repositories = function () {
|
|
218
|
+
return data;
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
return data;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
function _utils() {
|
|
225
|
+
const data = require("@teambit/legacy/dist/utils");
|
|
226
|
+
|
|
227
|
+
_utils = function () {
|
|
228
|
+
return data;
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
return data;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function _manyComponentsWriter() {
|
|
235
|
+
const data = _interopRequireDefault(require("@teambit/legacy/dist/consumer/component-ops/many-components-writer"));
|
|
236
|
+
|
|
237
|
+
_manyComponentsWriter = function () {
|
|
238
|
+
return data;
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
return data;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
function _checkoutVersion() {
|
|
245
|
+
const data = _interopRequireWildcard(require("@teambit/legacy/dist/consumer/versions-ops/checkout-version"));
|
|
246
|
+
|
|
247
|
+
_checkoutVersion = function () {
|
|
248
|
+
return data;
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
return data;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
function _threeWayMerge() {
|
|
255
|
+
const data = _interopRequireDefault(require("@teambit/legacy/dist/consumer/versions-ops/merge-version/three-way-merge"));
|
|
256
|
+
|
|
257
|
+
_threeWayMerge = function () {
|
|
258
|
+
return data;
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
return data;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
function _mergeCmd() {
|
|
265
|
+
const data = require("./merge-cmd");
|
|
266
|
+
|
|
267
|
+
_mergeCmd = function () {
|
|
268
|
+
return data;
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
return data;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
function _merging() {
|
|
275
|
+
const data = require("./merging.aspect");
|
|
276
|
+
|
|
277
|
+
_merging = function () {
|
|
278
|
+
return data;
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
return data;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
285
|
+
|
|
286
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
287
|
+
|
|
288
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
289
|
+
|
|
290
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2().default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
291
|
+
|
|
292
|
+
class MergingMain {
|
|
293
|
+
constructor(workspace, snapping) {
|
|
294
|
+
var _this$workspace;
|
|
295
|
+
|
|
296
|
+
this.workspace = workspace;
|
|
297
|
+
this.snapping = snapping;
|
|
298
|
+
(0, _defineProperty2().default)(this, "consumer", void 0);
|
|
299
|
+
this.consumer = (_this$workspace = this.workspace) === null || _this$workspace === void 0 ? void 0 : _this$workspace.consumer;
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* merge components according to the "values" param.
|
|
303
|
+
* if the first param is a version, then merge the component ids to that version.
|
|
304
|
+
* otherwise, merge from the remote head to the local.
|
|
305
|
+
*/
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
async merge(values, mergeStrategy, abort, resolve, noSnap, message, build) {
|
|
309
|
+
if (!this.workspace) throw new (_exceptions().ConsumerNotFound)();
|
|
310
|
+
const consumer = this.workspace.consumer;
|
|
311
|
+
|
|
312
|
+
if (consumer.isLegacy && (noSnap || message || abort || resolve)) {
|
|
313
|
+
throw new (_lanesIsDisabled().LanesIsDisabled)();
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
let mergeResults;
|
|
317
|
+
|
|
318
|
+
const firstValue = _ramda().default.head(values);
|
|
319
|
+
|
|
320
|
+
if (resolve) {
|
|
321
|
+
mergeResults = await this.resolveMerge(consumer, values, message, build);
|
|
322
|
+
} else if (abort) {
|
|
323
|
+
mergeResults = await this.abortMerge(consumer, values);
|
|
324
|
+
} else if (!_bitId().BitId.isValidVersion(firstValue)) {
|
|
325
|
+
const bitIds = this.getComponentsToMerge(consumer, values); // @todo: version could be the lane only or remote/lane
|
|
326
|
+
|
|
327
|
+
mergeResults = await this.mergeComponentsFromRemote(consumer, bitIds, mergeStrategy, noSnap, message, build);
|
|
328
|
+
} else {
|
|
329
|
+
const version = firstValue;
|
|
330
|
+
|
|
331
|
+
const ids = _ramda().default.tail(values);
|
|
332
|
+
|
|
333
|
+
const bitIds = this.getComponentsToMerge(consumer, ids);
|
|
334
|
+
mergeResults = await (0, _mergeVersion().mergeVersion)(consumer, version, bitIds, mergeStrategy);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
await consumer.onDestroy();
|
|
338
|
+
return mergeResults;
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* when user is on main, it merges the remote main components into local.
|
|
342
|
+
* when user is on a lane, it merges the remote lane components into the local lane.
|
|
343
|
+
*/
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
async mergeComponentsFromRemote(consumer, bitIds, mergeStrategy, noSnap, snapMessage, build) {
|
|
347
|
+
const localLaneId = consumer.getCurrentLaneId();
|
|
348
|
+
const localLaneObject = await consumer.getCurrentLaneObject();
|
|
349
|
+
const remoteTrackedLane = consumer.scope.lanes.getRemoteTrackedDataByLocalLane(localLaneId.name);
|
|
350
|
+
|
|
351
|
+
if (!localLaneId.isDefault() && !remoteTrackedLane) {
|
|
352
|
+
throw new Error(`unable to find a remote tracked to the local lane "${localLaneId.name}"`);
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
const allComponentsStatus = await this.getAllComponentsStatus(bitIds, localLaneId, localLaneObject, remoteTrackedLane);
|
|
356
|
+
return this.mergeSnaps({
|
|
357
|
+
mergeStrategy,
|
|
358
|
+
allComponentsStatus,
|
|
359
|
+
remoteName: remoteTrackedLane ? remoteTrackedLane.remoteScope : null,
|
|
360
|
+
laneId: localLaneId,
|
|
361
|
+
localLane: localLaneObject,
|
|
362
|
+
noSnap,
|
|
363
|
+
snapMessage,
|
|
364
|
+
build
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* merge multiple components according to the "allComponentsStatus".
|
|
369
|
+
*/
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
async mergeSnaps({
|
|
373
|
+
mergeStrategy,
|
|
374
|
+
allComponentsStatus,
|
|
375
|
+
remoteName,
|
|
376
|
+
laneId,
|
|
377
|
+
localLane,
|
|
378
|
+
noSnap,
|
|
379
|
+
snapMessage,
|
|
380
|
+
build
|
|
381
|
+
}) {
|
|
382
|
+
const consumer = this.workspace.consumer;
|
|
383
|
+
const componentWithConflict = allComponentsStatus.find(component => component.mergeResults && component.mergeResults.hasConflicts);
|
|
384
|
+
|
|
385
|
+
if (componentWithConflict && !mergeStrategy) {
|
|
386
|
+
mergeStrategy = await (0, _mergeVersion().getMergeStrategyInteractive)();
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
const failedComponents = allComponentsStatus.filter(componentStatus => componentStatus.failureMessage).map(componentStatus => ({
|
|
390
|
+
id: componentStatus.id,
|
|
391
|
+
failureMessage: componentStatus.failureMessage
|
|
392
|
+
}));
|
|
393
|
+
const succeededComponents = allComponentsStatus.filter(componentStatus => !componentStatus.failureMessage); // do not use Promise.all for applyVersion. otherwise, it'll write all components in parallel,
|
|
394
|
+
// which can be an issue when some components are also dependencies of others
|
|
395
|
+
|
|
396
|
+
const componentsResults = await (0, _pMapSeries().default)(succeededComponents, ({
|
|
397
|
+
componentFromFS,
|
|
398
|
+
id,
|
|
399
|
+
mergeResults
|
|
400
|
+
}) => {
|
|
401
|
+
return this.applyVersion({
|
|
402
|
+
consumer,
|
|
403
|
+
componentFromFS,
|
|
404
|
+
id,
|
|
405
|
+
mergeResults,
|
|
406
|
+
mergeStrategy,
|
|
407
|
+
remoteHead: new (_objects().Ref)(id.version),
|
|
408
|
+
// @ts-ignore
|
|
409
|
+
remoteName: remoteName || componentFromFS.scope,
|
|
410
|
+
laneId,
|
|
411
|
+
localLane
|
|
412
|
+
});
|
|
413
|
+
});
|
|
414
|
+
if (localLane) consumer.scope.objects.add(localLane);
|
|
415
|
+
await consumer.scope.objects.persist(); // persist anyway, it localLane is null it should save all main heads
|
|
416
|
+
|
|
417
|
+
await consumer.scope.objects.unmergedComponents.write();
|
|
418
|
+
const mergeSnapResults = noSnap ? null : await this.snapResolvedComponents(consumer, snapMessage, build);
|
|
419
|
+
return {
|
|
420
|
+
components: componentsResults,
|
|
421
|
+
failedComponents,
|
|
422
|
+
mergeSnapResults
|
|
423
|
+
};
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
async getComponentMergeStatus(id, localLane, otherLaneName, existingOnWorkspaceOnly = false) {
|
|
427
|
+
var _modelComponent$laneH;
|
|
428
|
+
|
|
429
|
+
const consumer = this.workspace.consumer;
|
|
430
|
+
const componentStatus = {
|
|
431
|
+
id
|
|
432
|
+
};
|
|
433
|
+
|
|
434
|
+
const returnFailure = msg => {
|
|
435
|
+
componentStatus.failureMessage = msg;
|
|
436
|
+
return componentStatus;
|
|
437
|
+
};
|
|
438
|
+
|
|
439
|
+
const modelComponent = await consumer.scope.getModelComponentIfExist(id);
|
|
440
|
+
|
|
441
|
+
if (!modelComponent) {
|
|
442
|
+
throw new (_generalError().default)(`component ${id.toString()} is on the lane but its objects were not found, please re-import the lane`);
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
const unmerged = consumer.scope.objects.unmergedComponents.getEntry(id.name);
|
|
446
|
+
|
|
447
|
+
if (unmerged && unmerged.resolved === false) {
|
|
448
|
+
return returnFailure(`component ${id.toStringWithoutVersion()} has conflicts that need to be resolved first, please use bit merge --resolve/--abort`);
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
const version = id.version;
|
|
452
|
+
const existingBitMapId = consumer.bitMap.getBitIdIfExist(id, {
|
|
453
|
+
ignoreVersion: true
|
|
454
|
+
});
|
|
455
|
+
const componentOnLane = await modelComponent.loadVersion(version, consumer.scope.objects);
|
|
456
|
+
|
|
457
|
+
if (!existingBitMapId) {
|
|
458
|
+
if (existingOnWorkspaceOnly) {
|
|
459
|
+
return returnFailure(`component ${id.toStringWithoutVersion()} is not in the workspace`);
|
|
460
|
+
} // @ts-ignore
|
|
461
|
+
|
|
462
|
+
|
|
463
|
+
return {
|
|
464
|
+
componentFromFS: null,
|
|
465
|
+
componentFromModel: componentOnLane,
|
|
466
|
+
id,
|
|
467
|
+
mergeResults: null
|
|
468
|
+
};
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
const currentlyUsedVersion = existingBitMapId.version;
|
|
472
|
+
|
|
473
|
+
if (currentlyUsedVersion === version) {
|
|
474
|
+
// @todo: maybe this check is not needed as we check for diverge later on
|
|
475
|
+
if (localLane || modelComponent.hasHead()) {
|
|
476
|
+
return returnFailure(`component ${id.toStringWithoutVersion()} is already merged`);
|
|
477
|
+
}
|
|
478
|
+
} // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
|
|
479
|
+
|
|
480
|
+
|
|
481
|
+
const component = await consumer.loadComponent(existingBitMapId);
|
|
482
|
+
const componentModificationStatus = await consumer.getComponentStatusById(component.id);
|
|
483
|
+
|
|
484
|
+
if (componentModificationStatus.modified) {
|
|
485
|
+
throw new (_generalError().default)(`unable to merge ${id.toStringWithoutVersion()}, the component is modified, please snap/tag it first`);
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
const repo = consumer.scope.objects;
|
|
489
|
+
const laneHeadIsDifferentThanCheckedOut = localLane && currentlyUsedVersion && ((_modelComponent$laneH = modelComponent.laneHeadLocal) === null || _modelComponent$laneH === void 0 ? void 0 : _modelComponent$laneH.toString()) !== currentlyUsedVersion;
|
|
490
|
+
const localHead = laneHeadIsDifferentThanCheckedOut ? _objects().Ref.from(currentlyUsedVersion) : null;
|
|
491
|
+
const otherLaneHead = new (_objects().Ref)(version);
|
|
492
|
+
const divergeData = await (0, _getDivergeData().getDivergeData)(repo, modelComponent, otherLaneHead, localHead);
|
|
493
|
+
|
|
494
|
+
if (!divergeData.isDiverged()) {
|
|
495
|
+
if (divergeData.isLocalAhead()) {
|
|
496
|
+
// do nothing!
|
|
497
|
+
return returnFailure(`component ${component.id.toString()} is ahead, nothing to merge`);
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
if (divergeData.isRemoteAhead()) {
|
|
501
|
+
// just override with the model data
|
|
502
|
+
return {
|
|
503
|
+
componentFromFS: component,
|
|
504
|
+
componentFromModel: componentOnLane,
|
|
505
|
+
id,
|
|
506
|
+
mergeResults: null
|
|
507
|
+
};
|
|
508
|
+
} // we know that localHead and remoteHead are set, so if none of them is ahead they must be equal
|
|
509
|
+
|
|
510
|
+
|
|
511
|
+
return returnFailure(`component ${component.id.toString()} is already merged`);
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
const baseSnap = divergeData.commonSnapBeforeDiverge; // must be set when isTrueMerge
|
|
515
|
+
|
|
516
|
+
const baseComponent = await modelComponent.loadVersion(baseSnap.toString(), repo);
|
|
517
|
+
const otherComponent = await modelComponent.loadVersion(otherLaneHead.toString(), repo);
|
|
518
|
+
const mergeResults = await (0, _threeWayMerge().default)({
|
|
519
|
+
consumer,
|
|
520
|
+
otherComponent,
|
|
521
|
+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
|
|
522
|
+
otherLabel: `${otherLaneHead.toString()} (${otherLaneName})`,
|
|
523
|
+
currentComponent: component,
|
|
524
|
+
currentLabel: `${currentlyUsedVersion} (local)`,
|
|
525
|
+
baseComponent
|
|
526
|
+
});
|
|
527
|
+
return {
|
|
528
|
+
componentFromFS: component,
|
|
529
|
+
id,
|
|
530
|
+
mergeResults
|
|
531
|
+
};
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
async applyVersion({
|
|
535
|
+
consumer,
|
|
536
|
+
componentFromFS,
|
|
537
|
+
id,
|
|
538
|
+
mergeResults,
|
|
539
|
+
mergeStrategy,
|
|
540
|
+
remoteHead,
|
|
541
|
+
remoteName,
|
|
542
|
+
laneId,
|
|
543
|
+
localLane
|
|
544
|
+
}) {
|
|
545
|
+
let filesStatus = {};
|
|
546
|
+
const unmergedComponent = {
|
|
547
|
+
// @ts-ignore
|
|
548
|
+
id: {
|
|
549
|
+
name: id.name,
|
|
550
|
+
scope: id.scope
|
|
551
|
+
},
|
|
552
|
+
// @ts-ignore
|
|
553
|
+
head: remoteHead,
|
|
554
|
+
// @ts-ignore
|
|
555
|
+
remote: remoteName,
|
|
556
|
+
lane: laneId.name,
|
|
557
|
+
resolved: false // could be changed later
|
|
558
|
+
|
|
559
|
+
};
|
|
560
|
+
id = componentFromFS ? componentFromFS.id : id;
|
|
561
|
+
|
|
562
|
+
if (mergeResults && mergeResults.hasConflicts && mergeStrategy === _mergeVersion().MergeOptions.ours) {
|
|
563
|
+
if (!componentFromFS) throw new Error(`applyVersion expect to get componentFromFS for ${id.toString()}`);
|
|
564
|
+
componentFromFS.files.forEach(file => {
|
|
565
|
+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
|
|
566
|
+
filesStatus[(0, _utils().pathNormalizeToLinux)(file.relative)] = _mergeVersion().FileStatus.unchanged;
|
|
567
|
+
});
|
|
568
|
+
unmergedComponent.resolved = true;
|
|
569
|
+
consumer.scope.objects.unmergedComponents.addEntry(unmergedComponent);
|
|
570
|
+
return {
|
|
571
|
+
id,
|
|
572
|
+
filesStatus
|
|
573
|
+
};
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
const remoteId = id.changeVersion(remoteHead.toString());
|
|
577
|
+
const idToLoad = !mergeResults || mergeStrategy === _mergeVersion().MergeOptions.theirs ? remoteId : id;
|
|
578
|
+
const componentWithDependencies = await consumer.loadComponentWithDependenciesFromModel(idToLoad);
|
|
579
|
+
const componentMap = componentFromFS && componentFromFS.componentMap;
|
|
580
|
+
if (componentFromFS && !componentMap) throw new (_generalError().default)('applyVersion: componentMap was not found');
|
|
581
|
+
|
|
582
|
+
if (componentMap && componentMap.origin === _constants().COMPONENT_ORIGINS.AUTHORED && !id.scope) {
|
|
583
|
+
componentWithDependencies.dependencies = [];
|
|
584
|
+
componentWithDependencies.devDependencies = [];
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
const shouldWritePackageJson = async () => {
|
|
588
|
+
if (!componentMap) return true;
|
|
589
|
+
const rootDir = componentMap && componentMap.rootDir;
|
|
590
|
+
if (!rootDir) return false;
|
|
591
|
+
|
|
592
|
+
const packageJsonPath = _path().default.join(consumer.getPath(), rootDir, 'package.json');
|
|
593
|
+
|
|
594
|
+
return _fsExtra().default.pathExists(packageJsonPath);
|
|
595
|
+
};
|
|
596
|
+
|
|
597
|
+
const shouldInstallNpmPackages = () => {
|
|
598
|
+
if (componentMap && componentMap.origin === _constants().COMPONENT_ORIGINS.AUTHORED) return false;
|
|
599
|
+
return true;
|
|
600
|
+
};
|
|
601
|
+
|
|
602
|
+
const writePackageJson = await shouldWritePackageJson();
|
|
603
|
+
const files = componentWithDependencies.component.files;
|
|
604
|
+
files.forEach(file => {
|
|
605
|
+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
|
|
606
|
+
filesStatus[(0, _utils().pathNormalizeToLinux)(file.relative)] = _mergeVersion().FileStatus.updated;
|
|
607
|
+
});
|
|
608
|
+
|
|
609
|
+
if (mergeResults) {
|
|
610
|
+
// update files according to the merge results
|
|
611
|
+
const {
|
|
612
|
+
filesStatus: modifiedStatus,
|
|
613
|
+
modifiedFiles
|
|
614
|
+
} = (0, _checkoutVersion().applyModifiedVersion)(files, mergeResults, mergeStrategy, // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
|
|
615
|
+
componentWithDependencies.component.originallySharedDir);
|
|
616
|
+
componentWithDependencies.component.files = modifiedFiles;
|
|
617
|
+
filesStatus = _objectSpread(_objectSpread({}, filesStatus), modifiedStatus);
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
const shouldDependenciesSaveAsComponents = await consumer.shouldDependenciesSavedAsComponents([id]);
|
|
621
|
+
componentWithDependencies.component.dependenciesSavedAsComponents = shouldDependenciesSaveAsComponents[0].saveDependenciesAsComponents;
|
|
622
|
+
const manyComponentsWriter = new (_manyComponentsWriter().default)({
|
|
623
|
+
consumer,
|
|
624
|
+
componentsWithDependencies: [componentWithDependencies],
|
|
625
|
+
installNpmPackages: shouldInstallNpmPackages(),
|
|
626
|
+
override: true,
|
|
627
|
+
writeConfig: false,
|
|
628
|
+
// @todo: should write if config exists before, needs to figure out how to do it.
|
|
629
|
+
verbose: false,
|
|
630
|
+
// @todo: do we need a flag here?
|
|
631
|
+
writeDists: true,
|
|
632
|
+
// @todo: do we need a flag here?
|
|
633
|
+
writePackageJson
|
|
634
|
+
});
|
|
635
|
+
await manyComponentsWriter.writeAll(); // if mergeResults, the head snap is going to be updated on a later phase when snapping with two parents
|
|
636
|
+
// otherwise, update the head of the current lane or main
|
|
637
|
+
|
|
638
|
+
if (mergeResults) {
|
|
639
|
+
if (mergeResults.hasConflicts && mergeStrategy === _mergeVersion().MergeOptions.manual) {
|
|
640
|
+
unmergedComponent.resolved = false;
|
|
641
|
+
unmergedComponent.unmergedPaths = mergeResults.modifiedFiles.filter(f => f.conflict).map(f => f.filePath);
|
|
642
|
+
} else {
|
|
643
|
+
unmergedComponent.resolved = true;
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
consumer.scope.objects.unmergedComponents.addEntry(unmergedComponent);
|
|
647
|
+
} else if (localLane) {
|
|
648
|
+
localLane.addComponent({
|
|
649
|
+
id,
|
|
650
|
+
head: remoteHead
|
|
651
|
+
});
|
|
652
|
+
} else {
|
|
653
|
+
// this is main
|
|
654
|
+
const modelComponent = await consumer.scope.getModelComponent(id);
|
|
655
|
+
if (!consumer.isLegacy) modelComponent.setHead(remoteHead);
|
|
656
|
+
consumer.scope.objects.add(modelComponent);
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
return {
|
|
660
|
+
id,
|
|
661
|
+
filesStatus
|
|
662
|
+
};
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
async abortMerge(consumer, values) {
|
|
666
|
+
const ids = this.getIdsForUnresolved(consumer, values); // @ts-ignore not clear yet what to do with other flags
|
|
667
|
+
|
|
668
|
+
const results = await (0, _checkoutVersion().default)(consumer, {
|
|
669
|
+
ids,
|
|
670
|
+
reset: true
|
|
671
|
+
});
|
|
672
|
+
ids.forEach(id => consumer.scope.objects.unmergedComponents.removeComponent(id.name));
|
|
673
|
+
await consumer.scope.objects.unmergedComponents.write();
|
|
674
|
+
return {
|
|
675
|
+
abortedComponents: results.components
|
|
676
|
+
};
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
async resolveMerge(consumer, values, snapMessage, build) {
|
|
680
|
+
const ids = this.getIdsForUnresolved(consumer, values); // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
|
|
681
|
+
|
|
682
|
+
const {
|
|
683
|
+
snappedComponents
|
|
684
|
+
} = await this.snapping.snap({
|
|
685
|
+
legacyBitIds: _bitId().BitIds.fromArray(ids),
|
|
686
|
+
resolveUnmerged: true,
|
|
687
|
+
build,
|
|
688
|
+
message: snapMessage
|
|
689
|
+
});
|
|
690
|
+
return {
|
|
691
|
+
resolvedComponents: snappedComponents
|
|
692
|
+
};
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
async getAllComponentsStatus(bitIds, localLaneId, localLaneObject, remoteTrackedLane) {
|
|
696
|
+
const tmp = new (_repositories().Tmp)(this.consumer.scope);
|
|
697
|
+
|
|
698
|
+
try {
|
|
699
|
+
const componentsStatus = await Promise.all(bitIds.map(async bitId => {
|
|
700
|
+
const remoteLaneName = remoteTrackedLane ? remoteTrackedLane.remoteLane : localLaneId.name;
|
|
701
|
+
const remoteScopeName = remoteTrackedLane ? remoteTrackedLane.remoteScope : bitId.scope;
|
|
702
|
+
|
|
703
|
+
const remoteLaneId = _laneId().RemoteLaneId.from(remoteLaneName, remoteScopeName);
|
|
704
|
+
|
|
705
|
+
const remoteHead = await this.consumer.scope.objects.remoteLanes.getRef(remoteLaneId, bitId);
|
|
706
|
+
const remoteLaneIdStr = remoteLaneId.toString();
|
|
707
|
+
if (!remoteHead) throw new (_generalError().default)(`unable to find a remote head of "${bitId.toStringWithoutVersion()}" in "${remoteLaneIdStr}"`);
|
|
708
|
+
return this.getComponentMergeStatus(bitId.changeVersion(remoteHead.toString()), localLaneObject, remoteLaneIdStr);
|
|
709
|
+
}));
|
|
710
|
+
await tmp.clear();
|
|
711
|
+
return componentsStatus;
|
|
712
|
+
} catch (err) {
|
|
713
|
+
await tmp.clear();
|
|
714
|
+
throw err;
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
async snapResolvedComponents(consumer, snapMessage, build) {
|
|
719
|
+
const resolvedComponents = consumer.scope.objects.unmergedComponents.getResolvedComponents();
|
|
720
|
+
|
|
721
|
+
_logger().default.debug(`merge-snaps, snapResolvedComponents, total ${resolvedComponents.length.toString()} components`);
|
|
722
|
+
|
|
723
|
+
if (!resolvedComponents.length) return null;
|
|
724
|
+
|
|
725
|
+
const ids = _bitId().BitIds.fromArray(resolvedComponents.map(r => new (_bitId().BitId)(r.id)));
|
|
726
|
+
|
|
727
|
+
return this.snapping.snap({
|
|
728
|
+
legacyBitIds: ids,
|
|
729
|
+
build,
|
|
730
|
+
message: snapMessage
|
|
731
|
+
});
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
getIdsForUnresolved(consumer, idsStr) {
|
|
735
|
+
if (idsStr && idsStr.length) {
|
|
736
|
+
const bitIds = idsStr.map(id => consumer.getParsedId(id));
|
|
737
|
+
bitIds.forEach(id => {
|
|
738
|
+
const entry = consumer.scope.objects.unmergedComponents.getEntry(id.name);
|
|
739
|
+
|
|
740
|
+
if (!entry) {
|
|
741
|
+
throw new (_generalError().default)(`unable to merge-resolve ${id.toString()}, it is not marked as unresolved`);
|
|
742
|
+
}
|
|
743
|
+
});
|
|
744
|
+
return bitIds;
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
const unresolvedComponents = consumer.scope.objects.unmergedComponents.getComponents();
|
|
748
|
+
if (!unresolvedComponents.length) throw new (_generalError().default)(`all components are resolved already, nothing to do`);
|
|
749
|
+
return unresolvedComponents.map(u => new (_bitId().BitId)(u.id));
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
getComponentsToMerge(consumer, ids) {
|
|
753
|
+
if ((0, _hasWildcard().default)(ids)) {
|
|
754
|
+
const componentsList = new (_componentsList().default)(consumer);
|
|
755
|
+
return componentsList.listComponentsByIdsWithWildcard(ids);
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
return ids.map(id => consumer.getParsedId(id));
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
static async provider([cli, workspace, snapping]) {
|
|
762
|
+
const merging = new MergingMain(workspace, snapping);
|
|
763
|
+
cli.register(new (_mergeCmd().MergeCmd)(merging));
|
|
764
|
+
return merging;
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
exports.MergingMain = MergingMain;
|
|
770
|
+
(0, _defineProperty2().default)(MergingMain, "slots", []);
|
|
771
|
+
(0, _defineProperty2().default)(MergingMain, "dependencies", [_cli().CLIAspect, _workspace().default, _snapping().default]);
|
|
772
|
+
(0, _defineProperty2().default)(MergingMain, "runtime", _cli().MainRuntime);
|
|
773
|
+
|
|
774
|
+
_merging().MergingAspect.addRuntime(MergingMain);
|
|
775
|
+
|
|
776
|
+
//# sourceMappingURL=merging.main.runtime.js.map
|