@teambit/importer 0.0.310 → 0.0.311
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/fetch-cmd.js +0 -22
- package/dist/fetch-cmd.js.map +1 -1
- package/dist/import-components.js +19 -191
- package/dist/import-components.js.map +1 -1
- package/dist/import.cmd.js +5 -59
- package/dist/import.cmd.js.map +1 -1
- package/dist/importer.aspect.js +0 -5
- package/dist/importer.aspect.js.map +1 -1
- package/dist/importer.composition.js +0 -6
- package/dist/importer.composition.js.map +1 -1
- package/dist/importer.main.runtime.js +1 -96
- package/dist/importer.main.runtime.js.map +1 -1
- package/dist/index.js +0 -5
- package/dist/index.js.map +1 -1
- package/package-tar/teambit-importer-0.0.311.tgz +0 -0
- package/package.json +5 -5
- package/{preview-1666409808293.js → preview-1666496165706.js} +2 -2
- package/package-tar/teambit-importer-0.0.310.tgz +0 -0
|
@@ -1,244 +1,170 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
require("core-js/modules/es.array.flat.js");
|
|
6
|
-
|
|
7
5
|
require("core-js/modules/es.array.flat-map.js");
|
|
8
|
-
|
|
9
6
|
require("core-js/modules/es.array.iterator.js");
|
|
10
|
-
|
|
11
7
|
require("core-js/modules/es.array.unscopables.flat.js");
|
|
12
|
-
|
|
13
8
|
require("core-js/modules/es.array.unscopables.flat-map.js");
|
|
14
|
-
|
|
15
9
|
require("core-js/modules/es.promise.js");
|
|
16
|
-
|
|
17
10
|
Object.defineProperty(exports, "__esModule", {
|
|
18
11
|
value: true
|
|
19
12
|
});
|
|
20
13
|
exports.default = void 0;
|
|
21
|
-
|
|
22
14
|
function _defineProperty2() {
|
|
23
15
|
const data = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
24
|
-
|
|
25
16
|
_defineProperty2 = function () {
|
|
26
17
|
return data;
|
|
27
18
|
};
|
|
28
|
-
|
|
29
19
|
return data;
|
|
30
20
|
}
|
|
31
|
-
|
|
32
21
|
function _chalk() {
|
|
33
22
|
const data = _interopRequireDefault(require("chalk"));
|
|
34
|
-
|
|
35
23
|
_chalk = function () {
|
|
36
24
|
return data;
|
|
37
25
|
};
|
|
38
|
-
|
|
39
26
|
return data;
|
|
40
27
|
}
|
|
41
|
-
|
|
42
28
|
function _ramda() {
|
|
43
29
|
const data = _interopRequireDefault(require("ramda"));
|
|
44
|
-
|
|
45
30
|
_ramda = function () {
|
|
46
31
|
return data;
|
|
47
32
|
};
|
|
48
|
-
|
|
49
33
|
return data;
|
|
50
34
|
}
|
|
51
|
-
|
|
52
35
|
function _bitError() {
|
|
53
36
|
const data = require("@teambit/bit-error");
|
|
54
|
-
|
|
55
37
|
_bitError = function () {
|
|
56
38
|
return data;
|
|
57
39
|
};
|
|
58
|
-
|
|
59
40
|
return data;
|
|
60
41
|
}
|
|
61
|
-
|
|
62
42
|
function _pMapSeries() {
|
|
63
43
|
const data = _interopRequireDefault(require("p-map-series"));
|
|
64
|
-
|
|
65
44
|
_pMapSeries = function () {
|
|
66
45
|
return data;
|
|
67
46
|
};
|
|
68
|
-
|
|
69
47
|
return data;
|
|
70
48
|
}
|
|
71
|
-
|
|
72
49
|
function _listScope() {
|
|
73
50
|
const data = require("@teambit/legacy/dist/api/consumer/lib/list-scope");
|
|
74
|
-
|
|
75
51
|
_listScope = function () {
|
|
76
52
|
return data;
|
|
77
53
|
};
|
|
78
|
-
|
|
79
54
|
return data;
|
|
80
55
|
}
|
|
81
|
-
|
|
82
56
|
function _bitId() {
|
|
83
57
|
const data = require("@teambit/legacy/dist/bit-id");
|
|
84
|
-
|
|
85
58
|
_bitId = function () {
|
|
86
59
|
return data;
|
|
87
60
|
};
|
|
88
|
-
|
|
89
61
|
return data;
|
|
90
62
|
}
|
|
91
|
-
|
|
92
63
|
function _loader() {
|
|
93
64
|
const data = _interopRequireDefault(require("@teambit/legacy/dist/cli/loader"));
|
|
94
|
-
|
|
95
65
|
_loader = function () {
|
|
96
66
|
return data;
|
|
97
67
|
};
|
|
98
|
-
|
|
99
68
|
return data;
|
|
100
69
|
}
|
|
101
|
-
|
|
102
70
|
function _loaderMessages() {
|
|
103
71
|
const data = require("@teambit/legacy/dist/cli/loader/loader-messages");
|
|
104
|
-
|
|
105
72
|
_loaderMessages = function () {
|
|
106
73
|
return data;
|
|
107
74
|
};
|
|
108
|
-
|
|
109
75
|
return data;
|
|
110
76
|
}
|
|
111
|
-
|
|
112
77
|
function _generalError() {
|
|
113
78
|
const data = _interopRequireDefault(require("@teambit/legacy/dist/error/general-error"));
|
|
114
|
-
|
|
115
79
|
_generalError = function () {
|
|
116
80
|
return data;
|
|
117
81
|
};
|
|
118
|
-
|
|
119
82
|
return data;
|
|
120
83
|
}
|
|
121
|
-
|
|
122
84
|
function _showDoctorError() {
|
|
123
85
|
const data = _interopRequireDefault(require("@teambit/legacy/dist/error/show-doctor-error"));
|
|
124
|
-
|
|
125
86
|
_showDoctorError = function () {
|
|
126
87
|
return data;
|
|
127
88
|
};
|
|
128
|
-
|
|
129
89
|
return data;
|
|
130
90
|
}
|
|
131
|
-
|
|
132
91
|
function _logger() {
|
|
133
92
|
const data = _interopRequireDefault(require("@teambit/legacy/dist/logger/logger"));
|
|
134
|
-
|
|
135
93
|
_logger = function () {
|
|
136
94
|
return data;
|
|
137
95
|
};
|
|
138
|
-
|
|
139
96
|
return data;
|
|
140
97
|
}
|
|
141
|
-
|
|
142
98
|
function _scopeRemotes() {
|
|
143
99
|
const data = require("@teambit/legacy/dist/scope/scope-remotes");
|
|
144
|
-
|
|
145
100
|
_scopeRemotes = function () {
|
|
146
101
|
return data;
|
|
147
102
|
};
|
|
148
|
-
|
|
149
103
|
return data;
|
|
150
104
|
}
|
|
151
|
-
|
|
152
105
|
function _utils() {
|
|
153
106
|
const data = require("@teambit/legacy/dist/utils");
|
|
154
|
-
|
|
155
107
|
_utils = function () {
|
|
156
108
|
return data;
|
|
157
109
|
};
|
|
158
|
-
|
|
159
110
|
return data;
|
|
160
111
|
}
|
|
161
|
-
|
|
162
112
|
function _hasWildcard() {
|
|
163
113
|
const data = _interopRequireDefault(require("@teambit/legacy/dist/utils/string/has-wildcard"));
|
|
164
|
-
|
|
165
114
|
_hasWildcard = function () {
|
|
166
115
|
return data;
|
|
167
116
|
};
|
|
168
|
-
|
|
169
117
|
return data;
|
|
170
118
|
}
|
|
171
|
-
|
|
172
119
|
function _exceptions() {
|
|
173
120
|
const data = require("@teambit/legacy/dist/consumer/exceptions");
|
|
174
|
-
|
|
175
121
|
_exceptions = function () {
|
|
176
122
|
return data;
|
|
177
123
|
};
|
|
178
|
-
|
|
179
124
|
return data;
|
|
180
125
|
}
|
|
181
|
-
|
|
182
126
|
function _checkoutVersion() {
|
|
183
127
|
const data = require("@teambit/legacy/dist/consumer/versions-ops/checkout-version");
|
|
184
|
-
|
|
185
128
|
_checkoutVersion = function () {
|
|
186
129
|
return data;
|
|
187
130
|
};
|
|
188
|
-
|
|
189
131
|
return data;
|
|
190
132
|
}
|
|
191
|
-
|
|
192
133
|
function _mergeVersion() {
|
|
193
134
|
const data = require("@teambit/legacy/dist/consumer/versions-ops/merge-version");
|
|
194
|
-
|
|
195
135
|
_mergeVersion = function () {
|
|
196
136
|
return data;
|
|
197
137
|
};
|
|
198
|
-
|
|
199
138
|
return data;
|
|
200
139
|
}
|
|
201
|
-
|
|
202
140
|
function _componentsPendingMerge() {
|
|
203
141
|
const data = _interopRequireDefault(require("@teambit/legacy/dist/consumer/component-ops/exceptions/components-pending-merge"));
|
|
204
|
-
|
|
205
142
|
_componentsPendingMerge = function () {
|
|
206
143
|
return data;
|
|
207
144
|
};
|
|
208
|
-
|
|
209
145
|
return data;
|
|
210
146
|
}
|
|
211
|
-
|
|
212
147
|
function _manyComponentsWriter() {
|
|
213
148
|
const data = _interopRequireDefault(require("@teambit/legacy/dist/consumer/component-ops/many-components-writer"));
|
|
214
|
-
|
|
215
149
|
_manyComponentsWriter = function () {
|
|
216
150
|
return data;
|
|
217
151
|
};
|
|
218
|
-
|
|
219
152
|
return data;
|
|
220
153
|
}
|
|
221
|
-
|
|
222
154
|
function _scopeComponentsImporter() {
|
|
223
155
|
const data = _interopRequireDefault(require("@teambit/legacy/dist/scope/component-ops/scope-components-importer"));
|
|
224
|
-
|
|
225
156
|
_scopeComponentsImporter = function () {
|
|
226
157
|
return data;
|
|
227
158
|
};
|
|
228
|
-
|
|
229
159
|
return data;
|
|
230
160
|
}
|
|
231
|
-
|
|
232
161
|
function _versionDependencies() {
|
|
233
162
|
const data = require("@teambit/legacy/dist/scope/version-dependencies");
|
|
234
|
-
|
|
235
163
|
_versionDependencies = function () {
|
|
236
164
|
return data;
|
|
237
165
|
};
|
|
238
|
-
|
|
239
166
|
return data;
|
|
240
167
|
}
|
|
241
|
-
|
|
242
168
|
class ImportComponents {
|
|
243
169
|
constructor(workspace, graph, options) {
|
|
244
170
|
this.workspace = workspace;
|
|
@@ -253,32 +179,24 @@ class ImportComponents {
|
|
|
253
179
|
this.scope = this.consumer.scope;
|
|
254
180
|
this.laneObjects = this.options.lanes ? this.options.lanes.lanes : [];
|
|
255
181
|
}
|
|
256
|
-
|
|
257
182
|
importComponents() {
|
|
258
183
|
_loader().default.start(_loaderMessages().BEFORE_IMPORT_ACTION);
|
|
259
|
-
|
|
260
184
|
this.options.saveDependenciesAsComponents = this.consumer.config._saveDependenciesAsComponents;
|
|
261
|
-
|
|
262
185
|
if (this.options.lanes && !this.options.ids.length) {
|
|
263
186
|
return this.importObjectsOnLane();
|
|
264
187
|
}
|
|
265
|
-
|
|
266
188
|
if (this.options.ids.length) {
|
|
267
189
|
return this.importSpecificComponents();
|
|
268
190
|
}
|
|
269
|
-
|
|
270
191
|
return this.importAccordingToBitMap();
|
|
271
192
|
}
|
|
272
|
-
|
|
273
193
|
async importObjectsOnLane() {
|
|
274
194
|
if (!this.options.objectsOnly) {
|
|
275
195
|
throw new Error(`importObjectsOnLane should have objectsOnly=true`);
|
|
276
196
|
}
|
|
277
|
-
|
|
278
197
|
if (this.laneObjects.length > 1) {
|
|
279
198
|
throw new Error(`importObjectsOnLane does not support more than one lane`);
|
|
280
199
|
}
|
|
281
|
-
|
|
282
200
|
const lane = this.laneObjects.length ? this.laneObjects[0] : undefined;
|
|
283
201
|
const bitIds = await this.getBitIds();
|
|
284
202
|
lane ? _logger().default.debug(`importObjectsOnLane, Lane: ${lane.id()}, Ids: ${bitIds.toString()}`) : _logger().default.debug(`importObjectsOnLane, the lane does not exist on the remote. importing only the main components`);
|
|
@@ -286,24 +204,24 @@ class ImportComponents {
|
|
|
286
204
|
const versionDependenciesArr = await this._importComponentsObjects(bitIds, {
|
|
287
205
|
allHistory: this.options.allHistory,
|
|
288
206
|
lane
|
|
289
|
-
});
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
// import lane components from their original scope, this way, it's possible to run diff/merge on them.
|
|
290
210
|
// don't use `scope.getDefaultLaneIdsFromLane()`. we need all components, because it's possible that a component
|
|
291
211
|
// does't have "head" locally although it exits in the origin-scope. it happens when the component was created on
|
|
292
212
|
// the origin-scope after a component with the same-name was created on the lane
|
|
293
|
-
|
|
294
213
|
if (lane) {
|
|
295
214
|
// @todo: optimize this maybe. currently, it imports twice.
|
|
296
215
|
// try to make the previous `importComponentsObjectsHarmony` import the same component once from the original
|
|
297
216
|
// scope and once from the lane-scope.
|
|
298
217
|
const mainIdsLatest = _bitId().BitIds.fromArray(lane.toBitIds().map(m => m.changeVersion(undefined)));
|
|
299
|
-
|
|
300
218
|
await this._importComponentsObjects(mainIdsLatest, {
|
|
301
219
|
allHistory: this.options.allHistory,
|
|
302
220
|
ignoreMissingHead: true
|
|
303
221
|
});
|
|
304
|
-
}
|
|
305
|
-
|
|
222
|
+
}
|
|
306
223
|
|
|
224
|
+
// merge the lane objects
|
|
307
225
|
const mergeAllLanesResults = await (0, _pMapSeries().default)(this.laneObjects, laneObject => this.scope.sources.mergeLane(laneObject, true));
|
|
308
226
|
const mergedLanes = mergeAllLanesResults.map(result => result.mergeLane);
|
|
309
227
|
await Promise.all(mergedLanes.map(mergedLane => this.scope.lanes.saveLane(mergedLane)));
|
|
@@ -314,39 +232,30 @@ class ImportComponents {
|
|
|
314
232
|
importDetails
|
|
315
233
|
};
|
|
316
234
|
}
|
|
317
|
-
|
|
318
235
|
async importSpecificComponents() {
|
|
319
236
|
var _this$laneObjects;
|
|
320
|
-
|
|
321
237
|
_logger().default.debug(`importSpecificComponents, Ids: ${this.options.ids.join(', ')}`);
|
|
322
|
-
|
|
323
238
|
const bitIds = await this.getBitIds();
|
|
324
239
|
const beforeImportVersions = await this._getCurrentVersions(bitIds);
|
|
325
240
|
await this._throwForPotentialIssues(bitIds);
|
|
326
241
|
const versionDependenciesArr = await this._importComponentsObjects(bitIds, {
|
|
327
242
|
lane: (_this$laneObjects = this.laneObjects) === null || _this$laneObjects === void 0 ? void 0 : _this$laneObjects[0]
|
|
328
243
|
});
|
|
329
|
-
|
|
330
244
|
if (this.laneObjects && this.options.objectsOnly) {
|
|
331
245
|
// merge the lane objects
|
|
332
246
|
const mergeAllLanesResults = await (0, _pMapSeries().default)(this.laneObjects, laneObject => this.scope.sources.mergeLane(laneObject, true));
|
|
333
247
|
const mergedLanes = mergeAllLanesResults.map(result => result.mergeLane);
|
|
334
248
|
await Promise.all(mergedLanes.map(mergedLane => this.scope.lanes.saveLane(mergedLane)));
|
|
335
249
|
}
|
|
336
|
-
|
|
337
250
|
let writtenComponents = [];
|
|
338
|
-
|
|
339
251
|
if (!this.options.objectsOnly) {
|
|
340
252
|
const componentsWithDependencies = await (0, _versionDependencies().multipleVersionDependenciesToConsumer)(versionDependenciesArr, this.scope.objects);
|
|
341
253
|
await this._fetchDivergeData(componentsWithDependencies);
|
|
342
|
-
|
|
343
254
|
this._throwForDivergedHistory();
|
|
344
|
-
|
|
345
255
|
await this._writeToFileSystem(componentsWithDependencies);
|
|
346
256
|
await this._saveLaneDataIfNeeded(componentsWithDependencies);
|
|
347
257
|
writtenComponents = componentsWithDependencies.map(c => c.component);
|
|
348
258
|
}
|
|
349
|
-
|
|
350
259
|
const importDetails = await this._getImportDetails(beforeImportVersions, versionDependenciesArr);
|
|
351
260
|
return {
|
|
352
261
|
importedIds: versionDependenciesArr.map(v => v.component.id).flat(),
|
|
@@ -355,14 +264,12 @@ class ImportComponents {
|
|
|
355
264
|
importDetails
|
|
356
265
|
};
|
|
357
266
|
}
|
|
358
|
-
|
|
359
267
|
async _fetchDivergeData(componentsWithDependencies) {
|
|
360
268
|
if (this.options.objectsOnly) {
|
|
361
269
|
// no need for it when importing objects only. if it's enabled, in case when on a lane and a non-lane
|
|
362
270
|
// component is in bitmap using an older version, it throws "getDivergeData: unable to find Version X of Y"
|
|
363
271
|
return;
|
|
364
272
|
}
|
|
365
|
-
|
|
366
273
|
await Promise.all(componentsWithDependencies.map(async ({
|
|
367
274
|
component
|
|
368
275
|
}) => {
|
|
@@ -371,11 +278,9 @@ class ImportComponents {
|
|
|
371
278
|
this.divergeData.push(modelComponent);
|
|
372
279
|
}));
|
|
373
280
|
}
|
|
374
|
-
|
|
375
281
|
_throwForDivergedHistory() {
|
|
376
282
|
if (this.options.merge || this.options.objectsOnly) return;
|
|
377
283
|
const divergedComponents = this.divergeData.filter(modelComponent => modelComponent.getDivergeData().isDiverged());
|
|
378
|
-
|
|
379
284
|
if (divergedComponents.length) {
|
|
380
285
|
const divergeData = divergedComponents.map(modelComponent => ({
|
|
381
286
|
id: modelComponent.id(),
|
|
@@ -385,7 +290,6 @@ class ImportComponents {
|
|
|
385
290
|
throw new (_componentsPendingMerge().default)(divergeData);
|
|
386
291
|
}
|
|
387
292
|
}
|
|
388
|
-
|
|
389
293
|
async _importComponentsObjects(ids, {
|
|
390
294
|
fromOriginalScope = false,
|
|
391
295
|
allHistory = false,
|
|
@@ -393,11 +297,8 @@ class ImportComponents {
|
|
|
393
297
|
ignoreMissingHead = false
|
|
394
298
|
}) {
|
|
395
299
|
const scopeComponentsImporter = _scopeComponentsImporter().default.getInstance(this.scope);
|
|
396
|
-
|
|
397
300
|
await scopeComponentsImporter.importManyDeltaWithoutDeps(ids, allHistory, lane, ignoreMissingHead);
|
|
398
|
-
|
|
399
301
|
_loader().default.start(`import ${ids.length} components with their dependencies (if missing)`);
|
|
400
|
-
|
|
401
302
|
const results = fromOriginalScope ? await scopeComponentsImporter.importManyFromOriginalScopes(ids) : await scopeComponentsImporter.importMany({
|
|
402
303
|
ids,
|
|
403
304
|
ignoreMissingHead,
|
|
@@ -405,6 +306,7 @@ class ImportComponents {
|
|
|
405
306
|
});
|
|
406
307
|
return results;
|
|
407
308
|
}
|
|
309
|
+
|
|
408
310
|
/**
|
|
409
311
|
* consider the following use cases:
|
|
410
312
|
* 1) no ids were provided. it should import all the lanes components objects AND main components objects
|
|
@@ -415,140 +317,108 @@ class ImportComponents {
|
|
|
415
317
|
* 3) ids are provided without wildcards. here, the user knows exactly what's needed and it's ok to get the ids from
|
|
416
318
|
* main if not found on the lane.
|
|
417
319
|
*/
|
|
418
|
-
|
|
419
|
-
|
|
420
320
|
async getBitIdsForLanes() {
|
|
421
321
|
if (!this.options.lanes) {
|
|
422
322
|
throw new Error(`getBitIdsForLanes: this.options.lanes must be set`);
|
|
423
323
|
}
|
|
424
|
-
|
|
425
324
|
const bitIdsFromLane = _bitId().BitIds.fromArray(this.laneObjects.flatMap(lane => lane.toBitIds()));
|
|
426
|
-
|
|
427
325
|
if (!this.options.ids.length) {
|
|
428
326
|
const mainIds = this.consumer.bitMap.getAuthoredAndImportedBitIdsOfDefaultLane();
|
|
429
327
|
const mainIdsToImport = mainIds.filter(id => id.hasScope() && !bitIdsFromLane.hasWithoutVersion(id));
|
|
430
328
|
bitIdsFromLane.push(...mainIdsToImport);
|
|
431
329
|
return bitIdsFromLane;
|
|
432
330
|
}
|
|
433
|
-
|
|
434
331
|
const idsWithWildcard = this.options.ids.filter(id => (0, _hasWildcard().default)(id));
|
|
435
332
|
const idsWithoutWildcard = this.options.ids.filter(id => !(0, _hasWildcard().default)(id));
|
|
436
333
|
const idsWithoutWildcardPreferFromLane = idsWithoutWildcard.map(idStr => {
|
|
437
334
|
const id = _bitId().BitId.parse(idStr, true);
|
|
438
|
-
|
|
439
335
|
const fromLane = bitIdsFromLane.searchWithoutVersion(id);
|
|
440
336
|
return fromLane || id;
|
|
441
337
|
});
|
|
442
338
|
const bitIds = [...idsWithoutWildcardPreferFromLane];
|
|
443
|
-
|
|
444
339
|
if (!idsWithWildcard) {
|
|
445
340
|
return bitIds;
|
|
446
341
|
}
|
|
447
|
-
|
|
448
342
|
await (0, _pMapSeries().default)(idsWithWildcard, async idStr => {
|
|
449
343
|
const idsFromRemote = await (0, _listScope().getRemoteBitIdsByWildcards)(idStr);
|
|
450
344
|
const existingOnLanes = idsFromRemote.filter(id => bitIdsFromLane.hasWithoutVersion(id));
|
|
451
|
-
|
|
452
345
|
if (!existingOnLanes.length) {
|
|
453
346
|
throw new (_bitError().BitError)(`the id with the the wildcard "${idStr}" has been parsed to multiple component ids.
|
|
454
347
|
however, none of them existing on the lane "${this.laneObjects.map(l => l.name).join(', ')}"
|
|
455
348
|
in case you intend to import these components from main, please run the following:
|
|
456
349
|
bit import ${idsFromRemote.map(id => id.toStringWithoutVersion()).join(' ')}`);
|
|
457
350
|
}
|
|
458
|
-
|
|
459
351
|
bitIds.push(...existingOnLanes);
|
|
460
352
|
});
|
|
461
353
|
return bitIds;
|
|
462
354
|
}
|
|
463
|
-
|
|
464
355
|
async getBitIdsForNonLanes() {
|
|
465
356
|
const bitIds = [];
|
|
466
357
|
await Promise.all(this.options.ids.map(async idStr => {
|
|
467
358
|
if ((0, _hasWildcard().default)(idStr)) {
|
|
468
359
|
const ids = await (0, _listScope().getRemoteBitIdsByWildcards)(idStr);
|
|
469
|
-
|
|
470
360
|
_loader().default.start(_loaderMessages().BEFORE_IMPORT_ACTION); // it stops the previous loader of BEFORE_REMOTE_LIST
|
|
471
|
-
|
|
472
|
-
|
|
473
361
|
bitIds.push(...ids);
|
|
474
362
|
} else {
|
|
475
363
|
bitIds.push(_bitId().BitId.parse(idStr, true)); // we don't support importing without a scope name
|
|
476
364
|
}
|
|
477
365
|
}));
|
|
366
|
+
|
|
478
367
|
return bitIds;
|
|
479
368
|
}
|
|
480
|
-
|
|
481
369
|
async getBitIds() {
|
|
482
370
|
const bitIds = this.options.lanes ? await this.getBitIdsForLanes() : await this.getBitIdsForNonLanes();
|
|
483
|
-
|
|
484
371
|
if (this.options.importDependenciesDirectly || this.options.importDependents) {
|
|
485
372
|
const graphs = await this._getComponentsGraphs(bitIds);
|
|
486
|
-
|
|
487
373
|
if (this.options.importDependenciesDirectly) {
|
|
488
374
|
const dependenciesIds = this._getDependenciesFromGraph(bitIds, graphs);
|
|
489
|
-
|
|
490
375
|
bitIds.push(...dependenciesIds);
|
|
491
376
|
}
|
|
492
|
-
|
|
493
377
|
if (this.options.importDependents) {
|
|
494
378
|
const graph = await this.graph.getGraph();
|
|
495
379
|
const targetCompIds = await this.workspace.resolveMultipleComponentIds(bitIds);
|
|
496
380
|
const sourceIds = await this.workspace.listIds();
|
|
497
381
|
const ids = graph.findIdsFromSourcesToTargets(sourceIds, targetCompIds);
|
|
498
|
-
|
|
499
382
|
_logger().default.debug(`found ${ids.length} component for --dependents flag`, ids.map(id => id.toString()));
|
|
500
|
-
|
|
501
383
|
bitIds.push(...ids.map(id => id._legacy));
|
|
502
384
|
}
|
|
503
385
|
}
|
|
504
|
-
|
|
505
386
|
return _bitId().BitIds.uniqFromArray(bitIds);
|
|
506
387
|
}
|
|
507
|
-
|
|
508
388
|
_getDependenciesFromGraph(bitIds, graphs) {
|
|
509
389
|
const dependencies = bitIds.map(bitId => {
|
|
510
390
|
const componentGraph = graphs.find(graph => graph.scopeName === bitId.scope);
|
|
511
|
-
|
|
512
391
|
if (!componentGraph) {
|
|
513
392
|
throw new Error(`unable to find a graph for ${bitId.toString()}`);
|
|
514
393
|
}
|
|
515
|
-
|
|
516
394
|
const dependenciesInfo = componentGraph.getDependenciesInfo(bitId);
|
|
517
395
|
return dependenciesInfo.map(d => d.id);
|
|
518
396
|
});
|
|
519
397
|
return _ramda().default.flatten(dependencies);
|
|
520
398
|
}
|
|
521
|
-
|
|
522
399
|
_getDependentsFromGraph(bitIds, graphs) {
|
|
523
400
|
const dependents = bitIds.map(bitId => {
|
|
524
401
|
const componentGraph = graphs.find(graph => graph.scopeName === bitId.scope);
|
|
525
|
-
|
|
526
402
|
if (!componentGraph) {
|
|
527
403
|
throw new Error(`unable to find a graph for ${bitId.toString()}`);
|
|
528
404
|
}
|
|
529
|
-
|
|
530
405
|
const dependentsInfo = componentGraph.getDependentsInfo(bitId);
|
|
531
406
|
return dependentsInfo.map(d => d.id);
|
|
532
407
|
});
|
|
533
408
|
return _ramda().default.flatten(dependents);
|
|
534
409
|
}
|
|
535
|
-
|
|
536
410
|
async _getComponentsGraphs(bitIds) {
|
|
537
411
|
const remotes = await (0, _scopeRemotes().getScopeRemotes)(this.consumer.scope);
|
|
538
412
|
return remotes.scopeGraphs(bitIds, this.consumer.scope);
|
|
539
413
|
}
|
|
540
|
-
|
|
541
414
|
async importAccordingToBitMap() {
|
|
542
415
|
this.options.objectsOnly = !this.options.merge && !this.options.override;
|
|
543
416
|
const componentsIdsToImport = this.getIdsToImportFromBitmap();
|
|
544
|
-
|
|
545
417
|
if (_ramda().default.isEmpty(componentsIdsToImport)) {
|
|
546
418
|
throw new (_exceptions().NothingToImport)();
|
|
547
419
|
}
|
|
548
|
-
|
|
549
420
|
await this._throwForModifiedOrNewComponents(componentsIdsToImport);
|
|
550
421
|
const beforeImportVersions = await this._getCurrentVersions(componentsIdsToImport);
|
|
551
|
-
|
|
552
422
|
if (!componentsIdsToImport.length) {
|
|
553
423
|
return {
|
|
554
424
|
importedIds: [],
|
|
@@ -556,23 +426,19 @@ bit import ${idsFromRemote.map(id => id.toStringWithoutVersion()).join(' ')}`);
|
|
|
556
426
|
importDetails: []
|
|
557
427
|
};
|
|
558
428
|
}
|
|
559
|
-
|
|
560
429
|
if (!this.options.objectsOnly) {
|
|
561
430
|
throw new Error(`bit import with no ids and --merge flag was not implemented yet`);
|
|
562
431
|
}
|
|
563
|
-
|
|
564
432
|
const versionDependenciesArr = await this._importComponentsObjects(componentsIdsToImport, {
|
|
565
433
|
fromOriginalScope: this.options.fromOriginalScope,
|
|
566
434
|
allHistory: this.options.allHistory
|
|
567
435
|
});
|
|
568
436
|
let writtenComponents = [];
|
|
569
|
-
|
|
570
437
|
if (!this.options.objectsOnly) {
|
|
571
438
|
const componentWithDependencies = await (0, _versionDependencies().multipleVersionDependenciesToConsumer)(versionDependenciesArr, this.scope.objects);
|
|
572
439
|
await this._writeToFileSystem(componentWithDependencies);
|
|
573
440
|
writtenComponents = componentWithDependencies.map(c => c.component);
|
|
574
441
|
}
|
|
575
|
-
|
|
576
442
|
const importDetails = await this._getImportDetails(beforeImportVersions, versionDependenciesArr);
|
|
577
443
|
return {
|
|
578
444
|
importedIds: versionDependenciesArr.map(v => v.component.id).flat(),
|
|
@@ -581,12 +447,10 @@ bit import ${idsFromRemote.map(id => id.toStringWithoutVersion()).join(' ')}`);
|
|
|
581
447
|
importDetails
|
|
582
448
|
};
|
|
583
449
|
}
|
|
584
|
-
|
|
585
450
|
getIdsToImportFromBitmap() {
|
|
586
451
|
const authoredExportedComponents = this.consumer.bitMap.getExportedComponents();
|
|
587
452
|
return _bitId().BitIds.fromArray(authoredExportedComponents);
|
|
588
453
|
}
|
|
589
|
-
|
|
590
454
|
async _getCurrentVersions(ids) {
|
|
591
455
|
const versionsP = ids.map(async id => {
|
|
592
456
|
const modelComponent = await this.consumer.scope.getModelComponentIfExist(id.changeVersion(undefined));
|
|
@@ -597,33 +461,27 @@ bit import ${idsFromRemote.map(id => id.toStringWithoutVersion()).join(' ')}`);
|
|
|
597
461
|
const versions = await Promise.all(versionsP);
|
|
598
462
|
return _ramda().default.fromPairs(versions);
|
|
599
463
|
}
|
|
464
|
+
|
|
600
465
|
/**
|
|
601
466
|
* get import details, includes the diff between the versions array before import and after import
|
|
602
467
|
*/
|
|
603
|
-
|
|
604
|
-
|
|
605
468
|
async _getImportDetails(currentVersions, components) {
|
|
606
469
|
const detailsP = components.map(async component => {
|
|
607
470
|
const id = component.component.id;
|
|
608
471
|
const idStr = id.toStringWithoutVersion();
|
|
609
472
|
const beforeImportVersions = currentVersions[idStr];
|
|
610
|
-
|
|
611
473
|
if (!beforeImportVersions) {
|
|
612
474
|
throw new Error(`_getImportDetails failed finding ${idStr} in currentVersions, which has ${Object.keys(currentVersions).join(', ')}`);
|
|
613
475
|
}
|
|
614
|
-
|
|
615
476
|
const modelComponent = await this.consumer.scope.getModelComponentIfExist(id);
|
|
616
477
|
if (!modelComponent) throw new (_showDoctorError().default)(`imported component ${idStr} was not found in the model`);
|
|
617
478
|
const afterImportVersions = modelComponent.listVersions();
|
|
618
|
-
|
|
619
479
|
const versionDifference = _ramda().default.difference(afterImportVersions, beforeImportVersions);
|
|
620
|
-
|
|
621
480
|
const getStatus = () => {
|
|
622
481
|
if (!versionDifference.length) return 'up to date';
|
|
623
482
|
if (!beforeImportVersions.length) return 'added';
|
|
624
483
|
return 'updated';
|
|
625
484
|
};
|
|
626
|
-
|
|
627
485
|
const filesStatus = this.mergeStatus && this.mergeStatus[idStr] ? this.mergeStatus[idStr] : null;
|
|
628
486
|
const deprecated = await modelComponent.isDeprecated(this.scope.objects);
|
|
629
487
|
const removed = await component.component.component.isRemoved(this.scope.objects);
|
|
@@ -641,13 +499,10 @@ bit import ${idsFromRemote.map(id => id.toStringWithoutVersion()).join(' ')}`);
|
|
|
641
499
|
});
|
|
642
500
|
return Promise.all(detailsP);
|
|
643
501
|
}
|
|
644
|
-
|
|
645
502
|
async _throwForPotentialIssues(ids) {
|
|
646
503
|
await this._throwForModifiedOrNewComponents(ids);
|
|
647
|
-
|
|
648
504
|
this._throwForDifferentComponentWithSameName(ids);
|
|
649
505
|
}
|
|
650
|
-
|
|
651
506
|
async _throwForModifiedOrNewComponents(ids) {
|
|
652
507
|
// the typical objectsOnly option is when a user cloned a project with components tagged to the source code, but
|
|
653
508
|
// doesn't have the model objects. in that case, calling getComponentStatusById() may return an error as it relies
|
|
@@ -657,22 +512,19 @@ bit import ${idsFromRemote.map(id => id.toStringWithoutVersion()).join(' ')}`);
|
|
|
657
512
|
const modifiedComponents = componentsStatuses.filter(({
|
|
658
513
|
status
|
|
659
514
|
}) => status.modified || status.newlyCreated).map(c => c.id);
|
|
660
|
-
|
|
661
515
|
if (modifiedComponents.length) {
|
|
662
516
|
throw new (_generalError().default)(_chalk().default.yellow(`unable to import the following components due to local changes, use --merge flag to merge your local changes or --override to override them\n${modifiedComponents.join('\n')} `));
|
|
663
517
|
}
|
|
664
518
|
}
|
|
519
|
+
|
|
665
520
|
/**
|
|
666
521
|
* Model Component id() calculation uses id.toString() for the hash.
|
|
667
522
|
* If an imported component has scopereadonly name equals to a local name, both will have the exact same
|
|
668
523
|
* hash and they'll override each other.
|
|
669
524
|
*/
|
|
670
|
-
|
|
671
|
-
|
|
672
525
|
_throwForDifferentComponentWithSameName(ids) {
|
|
673
526
|
ids.forEach(id => {
|
|
674
527
|
const existingId = this.consumer.getParsedIdIfExist(id.toStringWithoutVersion());
|
|
675
|
-
|
|
676
528
|
if (existingId && !existingId.hasScope()) {
|
|
677
529
|
throw new (_generalError().default)(`unable to import ${id.toString()}. the component name conflicted with your local component with the same name.
|
|
678
530
|
it's fine to have components with the same name as long as their scope names are different.
|
|
@@ -680,7 +532,6 @@ bit import ${idsFromRemote.map(id => id.toStringWithoutVersion()).join(' ')}`);
|
|
|
680
532
|
}
|
|
681
533
|
});
|
|
682
534
|
}
|
|
683
|
-
|
|
684
535
|
async _getMergeStatus(componentWithDependencies) {
|
|
685
536
|
const component = componentWithDependencies.component;
|
|
686
537
|
const componentStatus = await this.consumer.getComponentStatusById(component.id);
|
|
@@ -694,10 +545,11 @@ bit import ${idsFromRemote.map(id => id.toStringWithoutVersion()).join(' ')}`);
|
|
|
694
545
|
ignoreVersion: true
|
|
695
546
|
});
|
|
696
547
|
const fsComponent = await this.consumer.loadComponent(existingBitMapBitId);
|
|
697
|
-
const currentlyUsedVersion = existingBitMapBitId.version;
|
|
698
|
-
|
|
548
|
+
const currentlyUsedVersion = existingBitMapBitId.version;
|
|
549
|
+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
|
|
699
550
|
const baseComponent = await componentModel.loadVersion(currentlyUsedVersion, this.consumer.scope.objects);
|
|
700
|
-
const otherComponent = await componentModel.loadVersion(
|
|
551
|
+
const otherComponent = await componentModel.loadVersion(
|
|
552
|
+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
|
|
701
553
|
component.id.version, this.consumer.scope.objects);
|
|
702
554
|
const mergeResults = await (0, _mergeVersion().threeWayMerge)({
|
|
703
555
|
consumer: this.consumer,
|
|
@@ -710,6 +562,7 @@ bit import ${idsFromRemote.map(id => id.toStringWithoutVersion()).join(' ')}`);
|
|
|
710
562
|
mergeStatus.mergeResults = mergeResults;
|
|
711
563
|
return mergeStatus;
|
|
712
564
|
}
|
|
565
|
+
|
|
713
566
|
/**
|
|
714
567
|
* 1) when there are conflicts and the strategy is "ours", don't write the imported component to
|
|
715
568
|
* the filesystem, only update bitmap.
|
|
@@ -720,17 +573,14 @@ bit import ${idsFromRemote.map(id => id.toStringWithoutVersion()).join(' ')}`);
|
|
|
720
573
|
* 3) when there is no conflict or there are conflicts and the strategy is manual, write the files
|
|
721
574
|
* according to the merge result. (done by applyModifiedVersion())
|
|
722
575
|
*/
|
|
723
|
-
|
|
724
|
-
|
|
725
576
|
_updateComponentFilesPerMergeStrategy(componentMergeStatus) {
|
|
726
577
|
const mergeResults = componentMergeStatus.mergeResults;
|
|
727
578
|
if (!mergeResults) return null;
|
|
728
579
|
const component = componentMergeStatus.componentWithDependencies.component;
|
|
729
580
|
const files = component.files;
|
|
730
|
-
|
|
731
581
|
if (mergeResults.hasConflicts && this.options.mergeStrategy === _mergeVersion().MergeOptions.ours) {
|
|
732
|
-
const filesStatus = {};
|
|
733
|
-
|
|
582
|
+
const filesStatus = {};
|
|
583
|
+
// don't write the files to the filesystem, only bump the bitmap version.
|
|
734
584
|
files.forEach(file => {
|
|
735
585
|
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
|
|
736
586
|
filesStatus[(0, _utils().pathNormalizeToLinux)(file.relative)] = _mergeVersion().FileStatus.unchanged;
|
|
@@ -739,17 +589,15 @@ bit import ${idsFromRemote.map(id => id.toStringWithoutVersion()).join(' ')}`);
|
|
|
739
589
|
this.consumer.bitMap.hasChanged = true;
|
|
740
590
|
return filesStatus;
|
|
741
591
|
}
|
|
742
|
-
|
|
743
592
|
if (mergeResults.hasConflicts && this.options.mergeStrategy === _mergeVersion().MergeOptions.theirs) {
|
|
744
|
-
const filesStatus = {};
|
|
745
|
-
|
|
593
|
+
const filesStatus = {};
|
|
594
|
+
// the local changes will be overridden (as if the user entered --override flag for this component)
|
|
746
595
|
files.forEach(file => {
|
|
747
596
|
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
|
|
748
597
|
filesStatus[(0, _utils().pathNormalizeToLinux)(file.relative)] = _mergeVersion().FileStatus.updated;
|
|
749
598
|
});
|
|
750
599
|
return filesStatus;
|
|
751
600
|
}
|
|
752
|
-
|
|
753
601
|
const {
|
|
754
602
|
filesStatus,
|
|
755
603
|
modifiedFiles
|
|
@@ -757,12 +605,11 @@ bit import ${idsFromRemote.map(id => id.toStringWithoutVersion()).join(' ')}`);
|
|
|
757
605
|
component.files = modifiedFiles;
|
|
758
606
|
return filesStatus;
|
|
759
607
|
}
|
|
608
|
+
|
|
760
609
|
/**
|
|
761
610
|
* update the component files if they are modified and there is a merge strategy.
|
|
762
611
|
* returns only the components that need to be written to the filesystem
|
|
763
612
|
*/
|
|
764
|
-
|
|
765
|
-
|
|
766
613
|
async updateAllComponentsAccordingToMergeStrategy(componentsWithDependencies) {
|
|
767
614
|
if (!this.options.merge) return componentsWithDependencies;
|
|
768
615
|
const componentsStatusP = componentsWithDependencies.map(componentWithDependencies => {
|
|
@@ -770,63 +617,48 @@ bit import ${idsFromRemote.map(id => id.toStringWithoutVersion()).join(' ')}`);
|
|
|
770
617
|
});
|
|
771
618
|
const componentsStatus = await Promise.all(componentsStatusP);
|
|
772
619
|
const componentWithConflict = componentsStatus.find(component => component.mergeResults && component.mergeResults.hasConflicts);
|
|
773
|
-
|
|
774
620
|
if (componentWithConflict && !this.options.mergeStrategy) {
|
|
775
621
|
this.options.mergeStrategy = await (0, _mergeVersion().getMergeStrategyInteractive)();
|
|
776
622
|
}
|
|
777
|
-
|
|
778
623
|
this.mergeStatus = {};
|
|
779
624
|
const componentsToWrite = componentsStatus.map(componentStatus => {
|
|
780
625
|
const filesStatus = this._updateComponentFilesPerMergeStrategy(componentStatus);
|
|
781
|
-
|
|
782
626
|
const componentWithDependencies = componentStatus.componentWithDependencies;
|
|
783
627
|
if (!filesStatus) return componentWithDependencies;
|
|
784
628
|
this.mergeStatus[componentWithDependencies.component.id.toStringWithoutVersion()] = filesStatus;
|
|
785
629
|
const unchangedFiles = Object.keys(filesStatus).filter(file => filesStatus[file] === _mergeVersion().FileStatus.unchanged);
|
|
786
|
-
|
|
787
630
|
if (unchangedFiles.length === Object.keys(filesStatus).length) {
|
|
788
631
|
// all files are unchanged
|
|
789
632
|
return null;
|
|
790
633
|
}
|
|
791
|
-
|
|
792
634
|
return componentWithDependencies;
|
|
793
635
|
});
|
|
794
|
-
|
|
795
636
|
const removeNulls = _ramda().default.reject(_ramda().default.isNil);
|
|
796
|
-
|
|
797
637
|
return removeNulls(componentsToWrite);
|
|
798
638
|
}
|
|
799
|
-
|
|
800
639
|
_shouldSaveLaneData() {
|
|
801
640
|
if (this.options.objectsOnly) {
|
|
802
641
|
return false;
|
|
803
642
|
}
|
|
804
|
-
|
|
805
643
|
return this.consumer.isOnLane();
|
|
806
644
|
}
|
|
807
|
-
|
|
808
645
|
async _saveLaneDataIfNeeded(componentsWithDependencies) {
|
|
809
646
|
if (!this._shouldSaveLaneData()) {
|
|
810
647
|
return;
|
|
811
648
|
}
|
|
812
|
-
|
|
813
649
|
const currentLane = await this.consumer.getCurrentLaneObject();
|
|
814
|
-
|
|
815
650
|
if (!currentLane) {
|
|
816
651
|
return; // user on main
|
|
817
652
|
}
|
|
818
653
|
|
|
819
654
|
const idsFromRemoteLanes = _bitId().BitIds.fromArray(this.laneObjects.flatMap(lane => lane.toBitIds()));
|
|
820
|
-
|
|
821
655
|
const components = componentsWithDependencies.map(c => c.component);
|
|
822
656
|
await Promise.all(components.map(async comp => {
|
|
823
657
|
const existOnRemoteLane = idsFromRemoteLanes.has(comp.id);
|
|
824
|
-
|
|
825
658
|
if (!existOnRemoteLane && !this.options.saveInLane) {
|
|
826
659
|
this.consumer.bitMap.setComponentProp(comp.id, 'onLanesOnly', false);
|
|
827
660
|
return;
|
|
828
661
|
}
|
|
829
|
-
|
|
830
662
|
const modelComponent = await this.scope.getModelComponent(comp.id);
|
|
831
663
|
const ref = modelComponent.getRef(comp.id.version);
|
|
832
664
|
if (!ref) throw new Error(`_saveLaneDataIfNeeded unable to get ref for ${comp.id.toString()}`);
|
|
@@ -837,12 +669,10 @@ bit import ${idsFromRemote.map(id => id.toStringWithoutVersion()).join(' ')}`);
|
|
|
837
669
|
}));
|
|
838
670
|
await this.scope.lanes.saveLane(currentLane);
|
|
839
671
|
}
|
|
840
|
-
|
|
841
672
|
async _writeToFileSystem(componentsWithDependencies) {
|
|
842
673
|
if (this.options.objectsOnly) {
|
|
843
674
|
return;
|
|
844
675
|
}
|
|
845
|
-
|
|
846
676
|
const componentsToWrite = await this.updateAllComponentsAccordingToMergeStrategy(componentsWithDependencies);
|
|
847
677
|
const manyComponentsWriter = new (_manyComponentsWriter().default)({
|
|
848
678
|
consumer: this.consumer,
|
|
@@ -855,9 +685,7 @@ bit import ${idsFromRemote.map(id => id.toStringWithoutVersion()).join(' ')}`);
|
|
|
855
685
|
});
|
|
856
686
|
await manyComponentsWriter.writeAll();
|
|
857
687
|
}
|
|
858
|
-
|
|
859
688
|
}
|
|
860
|
-
|
|
861
689
|
exports.default = ImportComponents;
|
|
862
690
|
|
|
863
691
|
//# sourceMappingURL=import-components.js.map
|