@teambit/snapping 0.0.196 → 0.0.198

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.
@@ -1,197 +1,139 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  require("core-js/modules/es.array.iterator.js");
6
-
7
5
  require("core-js/modules/es.promise.js");
8
-
9
6
  Object.defineProperty(exports, "__esModule", {
10
7
  value: true
11
8
  });
12
9
  exports.tagModelComponent = tagModelComponent;
13
10
  exports.updateComponentsVersions = updateComponentsVersions;
14
-
15
11
  function _pMapSeries() {
16
12
  const data = _interopRequireDefault(require("p-map-series"));
17
-
18
13
  _pMapSeries = function () {
19
14
  return data;
20
15
  };
21
-
22
16
  return data;
23
17
  }
24
-
25
18
  function _nodeFetch() {
26
19
  const data = _interopRequireDefault(require("node-fetch"));
27
-
28
20
  _nodeFetch = function () {
29
21
  return data;
30
22
  };
31
-
32
23
  return data;
33
24
  }
34
-
35
25
  function _ramda() {
36
26
  const data = _interopRequireDefault(require("ramda"));
37
-
38
27
  _ramda = function () {
39
28
  return data;
40
29
  };
41
-
42
30
  return data;
43
31
  }
44
-
45
32
  function _lodash() {
46
33
  const data = require("lodash");
47
-
48
34
  _lodash = function () {
49
35
  return data;
50
36
  };
51
-
52
37
  return data;
53
38
  }
54
-
55
39
  function _uuid() {
56
40
  const data = require("uuid");
57
-
58
41
  _uuid = function () {
59
42
  return data;
60
43
  };
61
-
62
44
  return data;
63
45
  }
64
-
65
46
  function globalConfig() {
66
47
  const data = _interopRequireWildcard(require("@teambit/legacy/dist/api/consumer/lib/global-config"));
67
-
68
48
  globalConfig = function () {
69
49
  return data;
70
50
  };
71
-
72
51
  return data;
73
52
  }
74
-
75
53
  function _bitId() {
76
54
  const data = require("@teambit/legacy/dist/bit-id");
77
-
78
55
  _bitId = function () {
79
56
  return data;
80
57
  };
81
-
82
58
  return data;
83
59
  }
84
-
85
60
  function _constants() {
86
61
  const data = require("@teambit/legacy/dist/constants");
87
-
88
62
  _constants = function () {
89
63
  return data;
90
64
  };
91
-
92
65
  return data;
93
66
  }
94
-
95
67
  function _componentSchema() {
96
68
  const data = require("@teambit/legacy/dist/consumer/component/component-schema");
97
-
98
69
  _componentSchema = function () {
99
70
  return data;
100
71
  };
101
-
102
72
  return data;
103
73
  }
104
-
105
74
  function _exceptions() {
106
75
  const data = require("@teambit/legacy/dist/consumer/exceptions");
107
-
108
76
  _exceptions = function () {
109
77
  return data;
110
78
  };
111
-
112
79
  return data;
113
80
  }
114
-
115
81
  function _showDoctorError() {
116
82
  const data = _interopRequireDefault(require("@teambit/legacy/dist/error/show-doctor-error"));
117
-
118
83
  _showDoctorError = function () {
119
84
  return data;
120
85
  };
121
-
122
86
  return data;
123
87
  }
124
-
125
88
  function _logger() {
126
89
  const data = _interopRequireDefault(require("@teambit/legacy/dist/logger/logger"));
127
-
128
90
  _logger = function () {
129
91
  return data;
130
92
  };
131
-
132
93
  return data;
133
94
  }
134
-
135
95
  function _utils() {
136
96
  const data = require("@teambit/legacy/dist/utils");
137
-
138
97
  _utils = function () {
139
98
  return data;
140
99
  };
141
-
142
100
  return data;
143
101
  }
144
-
145
102
  function _autoTag() {
146
103
  const data = require("@teambit/legacy/dist/scope/component-ops/auto-tag");
147
-
148
104
  _autoTag = function () {
149
105
  return data;
150
106
  };
151
-
152
107
  return data;
153
108
  }
154
-
155
109
  function _semverHelper() {
156
110
  const data = require("@teambit/legacy/dist/utils/semver-helper");
157
-
158
111
  _semverHelper = function () {
159
112
  return data;
160
113
  };
161
-
162
114
  return data;
163
115
  }
164
-
165
116
  function _messagePerComponent() {
166
117
  const data = require("@teambit/legacy/dist/scope/component-ops/message-per-component");
167
-
168
118
  _messagePerComponent = function () {
169
119
  return data;
170
120
  };
171
-
172
121
  return data;
173
122
  }
174
-
175
123
  function _models() {
176
124
  const data = require("@teambit/legacy/dist/scope/models");
177
-
178
125
  _models = function () {
179
126
  return data;
180
127
  };
181
-
182
128
  return data;
183
129
  }
184
-
185
130
  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); }
186
-
187
131
  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; }
188
-
189
132
  function updateDependenciesVersions(componentsToTag, dependencyResolver) {
190
133
  const getNewDependencyVersion = id => {
191
134
  const foundDependency = componentsToTag.find(component => component.id.isEqualWithoutVersion(id));
192
135
  return foundDependency ? id.changeVersion(foundDependency.version) : null;
193
136
  };
194
-
195
137
  const changeExtensionsVersion = component => {
196
138
  component.extensions.forEach(ext => {
197
139
  if (ext.extensionId) {
@@ -200,36 +142,30 @@ function updateDependenciesVersions(componentsToTag, dependencyResolver) {
200
142
  }
201
143
  });
202
144
  };
203
-
204
145
  componentsToTag.forEach(oneComponentToTag => {
205
146
  oneComponentToTag.getAllDependencies().forEach(dependency => {
206
147
  const newDepId = getNewDependencyVersion(dependency.id);
207
148
  if (newDepId) dependency.id = newDepId;
208
149
  });
209
- changeExtensionsVersion(oneComponentToTag); // @ts-ignore
210
-
150
+ changeExtensionsVersion(oneComponentToTag);
151
+ // @ts-ignore
211
152
  oneComponentToTag = dependencyResolver.updateDepsOnLegacyTag(oneComponentToTag, getNewDependencyVersion.bind(this));
212
153
  });
213
154
  }
214
-
215
155
  function setHashes(componentsToTag) {
216
156
  componentsToTag.forEach(componentToTag => {
217
157
  componentToTag.version = (0, _utils().sha1)((0, _uuid().v4)());
218
158
  });
219
159
  }
220
-
221
160
  async function setFutureVersions(componentsToTag, scope, releaseType, exactVersion, persist, autoTagIds, ids, incrementBy, preRelease, soft) {
222
161
  await Promise.all(componentsToTag.map(async componentToTag => {
223
162
  var _componentToTag$compo, _componentToTag$compo2;
224
-
225
163
  const isAutoTag = autoTagIds.hasWithoutVersion(componentToTag.id);
226
164
  const modelComponent = await scope.sources.findOrAddComponent(componentToTag);
227
165
  const nextVersion = (_componentToTag$compo = componentToTag.componentMap) === null || _componentToTag$compo === void 0 ? void 0 : (_componentToTag$compo2 = _componentToTag$compo.nextVersion) === null || _componentToTag$compo2 === void 0 ? void 0 : _componentToTag$compo2.version;
228
166
  componentToTag.previouslyUsedVersion = componentToTag.version;
229
-
230
167
  if (nextVersion && persist) {
231
168
  var _componentToTag$compo3, _componentToTag$compo4;
232
-
233
169
  const exactVersionOrReleaseType = (0, _semverHelper().getValidVersionOrReleaseType)(nextVersion);
234
170
  componentToTag.version = modelComponent.getVersionToAdd(exactVersionOrReleaseType.releaseType, exactVersionOrReleaseType.exactVersion, undefined, (_componentToTag$compo3 = componentToTag.componentMap) === null || _componentToTag$compo3 === void 0 ? void 0 : (_componentToTag$compo4 = _componentToTag$compo3.nextVersion) === null || _componentToTag$compo4 === void 0 ? void 0 : _componentToTag$compo4.preRelease);
235
171
  } else if (isAutoTag) {
@@ -241,18 +177,14 @@ async function setFutureVersions(componentsToTag, scope, releaseType, exactVersi
241
177
  }
242
178
  }));
243
179
  }
244
-
245
180
  function getVersionByEnteredId(enteredIds, component, modelComponent) {
246
181
  const enteredId = enteredIds.searchWithoutVersion(component.id);
247
-
248
182
  if (enteredId && enteredId.hasVersion()) {
249
183
  const exactVersionOrReleaseType = (0, _semverHelper().getValidVersionOrReleaseType)(enteredId.version);
250
184
  return modelComponent.getVersionToAdd(exactVersionOrReleaseType.releaseType, exactVersionOrReleaseType.exactVersion);
251
185
  }
252
-
253
186
  return undefined;
254
187
  }
255
-
256
188
  async function tagModelComponent({
257
189
  workspace,
258
190
  scope,
@@ -280,33 +212,28 @@ async function tagModelComponent({
280
212
  }) {
281
213
  const consumer = workspace === null || workspace === void 0 ? void 0 : workspace.consumer;
282
214
  const legacyScope = scope.legacyScope;
283
- const consumerComponentsIdsMap = {}; // Concat and unique all the dependencies from all the components so we will not import
215
+ const consumerComponentsIdsMap = {};
216
+ // Concat and unique all the dependencies from all the components so we will not import
284
217
  // the same dependency more then once, it's mainly for performance purpose
285
-
286
218
  consumerComponents.forEach(consumerComponent => {
287
- const componentIdString = consumerComponent.id.toString(); // Store it in a map so we can take it easily from the sorted array which contain only the id
288
-
219
+ const componentIdString = consumerComponent.id.toString();
220
+ // Store it in a map so we can take it easily from the sorted array which contain only the id
289
221
  consumerComponentsIdsMap[componentIdString] = consumerComponent;
290
222
  });
291
-
292
223
  const componentsToTag = _ramda().default.values(consumerComponentsIdsMap); // consumerComponents unique
293
-
294
-
295
- const idsToTag = _bitId().BitIds.fromArray(componentsToTag.map(c => c.id)); // ids without versions are new. it's impossible that tagged (and not-modified) components has
224
+ const idsToTag = _bitId().BitIds.fromArray(componentsToTag.map(c => c.id));
225
+ // ids without versions are new. it's impossible that tagged (and not-modified) components has
296
226
  // them as dependencies.
297
-
298
-
299
227
  const idsToTriggerAutoTag = idsToTag.filter(id => id.hasVersion());
300
228
  const autoTagData = skipAutoTag || !consumer ? [] : await (0, _autoTag().getAutoTagInfo)(consumer, _bitId().BitIds.fromArray(idsToTriggerAutoTag));
301
229
  const autoTagComponents = autoTagData.map(autoTagItem => autoTagItem.component);
302
230
  const autoTagComponentsFiltered = autoTagComponents.filter(c => !idsToTag.has(c.id));
303
-
304
231
  const autoTagIds = _bitId().BitIds.fromArray(autoTagComponentsFiltered.map(autoTag => autoTag.id));
305
-
306
232
  const allComponentsToTag = [...componentsToTag, ...autoTagComponentsFiltered];
307
233
  const messagesFromEditorFetcher = new (_messagePerComponent().MessagePerComponentFetcher)(idsToTag, autoTagIds);
308
- const messagePerId = editor ? await messagesFromEditorFetcher.getMessagesFromEditor(legacyScope.tmp, editor) : []; // check for each one of the components whether it is using an old version
234
+ const messagePerId = editor ? await messagesFromEditorFetcher.getMessagesFromEditor(legacyScope.tmp, editor) : [];
309
235
 
236
+ // check for each one of the components whether it is using an old version
310
237
  if (!ignoreNewestVersion && !isSnap) {
311
238
  const newestVersionsP = allComponentsToTag.map(async component => {
312
239
  if (component.componentFromModel) {
@@ -314,9 +241,7 @@ async function tagModelComponent({
314
241
  const modelComponent = await legacyScope.getModelComponentIfExist(component.id);
315
242
  if (!modelComponent) throw new (_showDoctorError().default)(`component ${component.id} was not found in the model`);
316
243
  if (!modelComponent.listVersions().length) return null; // no versions yet, no issues.
317
-
318
244
  const latest = modelComponent.latest();
319
-
320
245
  if (latest !== component.version) {
321
246
  return {
322
247
  componentId: component.id.toStringWithoutVersion(),
@@ -325,27 +250,22 @@ async function tagModelComponent({
325
250
  };
326
251
  }
327
252
  }
328
-
329
253
  return null;
330
254
  });
331
255
  const newestVersions = await Promise.all(newestVersionsP);
332
256
  const newestVersionsWithoutEmpty = newestVersions.filter(newest => newest);
333
-
334
257
  if (!(0, _lodash().isEmpty)(newestVersionsWithoutEmpty)) {
335
258
  // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
336
259
  throw new (_exceptions().NewerVersionFound)(newestVersionsWithoutEmpty);
337
260
  }
338
261
  }
339
-
340
- _logger().default.debugAndAddBreadCrumb('tag-model-components', 'sequentially persist all components'); // go through all components and find the future versions for them
341
-
342
-
262
+ _logger().default.debugAndAddBreadCrumb('tag-model-components', 'sequentially persist all components');
263
+ // go through all components and find the future versions for them
343
264
  isSnap ? setHashes(allComponentsToTag) : await setFutureVersions(allComponentsToTag, legacyScope, releaseType, exactVersion, persist, autoTagIds, ids, incrementBy, preReleaseId, soft);
344
- setCurrentSchema(allComponentsToTag); // go through all dependencies and update their versions
345
-
265
+ setCurrentSchema(allComponentsToTag);
266
+ // go through all dependencies and update their versions
346
267
  updateDependenciesVersions(allComponentsToTag, dependencyResolver);
347
268
  await addLogToComponents(componentsToTag, autoTagComponents, persist, message, messagePerId);
348
-
349
269
  if (soft) {
350
270
  if (!consumer) throw new Error(`unable to soft-tag without consumer`);
351
271
  consumer.updateNextVersionOnBitmap(allComponentsToTag, preReleaseId);
@@ -356,9 +276,7 @@ async function tagModelComponent({
356
276
  await addComponentsToScope(legacyScope, snapping, allComponentsToTag, Boolean(build), consumer);
357
277
  if (workspace) await updateComponentsVersions(workspace, allComponentsToTag);
358
278
  }
359
-
360
279
  const publishedPackages = [];
361
-
362
280
  if (build) {
363
281
  const onTagOpts = {
364
282
  disableTagAndSnapPipelines,
@@ -368,7 +286,6 @@ async function tagModelComponent({
368
286
  isSnap
369
287
  };
370
288
  const seedersOnly = !workspace; // if tag from scope, build only the given components
371
-
372
289
  const isolateOptions = {
373
290
  packageManagerConfigRootDir,
374
291
  seedersOnly
@@ -379,31 +296,25 @@ async function tagModelComponent({
379
296
  builderDataMap
380
297
  } = await builder.tagListener(harmonyComps, onTagOpts, isolateOptions);
381
298
  const buildResult = scope.builderDataMapToLegacyOnTagResults(builderDataMap);
382
-
383
299
  snapping._updateComponentsByTagResult(allComponentsToTag, buildResult);
384
-
385
300
  publishedPackages.push(...snapping._getPublishedPackages(allComponentsToTag));
386
301
  addBuildStatus(allComponentsToTag, _constants().BuildStatus.Succeed);
387
302
  await (0, _pMapSeries().default)(allComponentsToTag, consumerComponent => snapping._enrichComp(consumerComponent));
388
303
  }
389
-
390
304
  if (!soft) {
391
305
  await removeDeletedComponentsFromBitmap(allComponentsToTag, workspace);
392
306
  await legacyScope.objects.persist();
393
307
  }
394
-
395
308
  return {
396
309
  taggedComponents: componentsToTag,
397
310
  autoTaggedResults: autoTagData,
398
311
  publishedPackages
399
312
  };
400
313
  }
401
-
402
314
  async function removeDeletedComponentsFromBitmap(comps, workspace) {
403
315
  if (!workspace) {
404
316
  return;
405
317
  }
406
-
407
318
  await Promise.all(comps.map(async comp => {
408
319
  if (comp.removed) {
409
320
  const compId = await workspace.resolveComponentId(comp.id);
@@ -411,10 +322,8 @@ async function removeDeletedComponentsFromBitmap(comps, workspace) {
411
322
  }
412
323
  }));
413
324
  }
414
-
415
325
  async function addComponentsToScope(scope, snapping, components, shouldValidateVersion, consumer) {
416
326
  const lane = await scope.getCurrentLaneObject();
417
-
418
327
  if (consumer) {
419
328
  await (0, _pMapSeries().default)(components, async component => {
420
329
  await snapping._addCompToObjects({
@@ -430,22 +339,18 @@ async function addComponentsToScope(scope, snapping, components, shouldValidateV
430
339
  });
431
340
  }
432
341
  }
433
-
434
342
  function emptyBuilderData(components) {
435
343
  components.forEach(component => {
436
344
  const existingBuilder = component.extensions.findCoreExtension(_constants().Extensions.builder);
437
345
  if (existingBuilder) existingBuilder.data = {};
438
346
  });
439
347
  }
440
-
441
348
  async function addLogToComponents(components, autoTagComps, persist, message, messagePerComponent) {
442
349
  const username = await globalConfig().get(_constants().CFG_USER_NAME_KEY);
443
350
  const bitCloudUsername = await getBitCloudUsername();
444
351
  const email = await globalConfig().get(_constants().CFG_USER_EMAIL_KEY);
445
-
446
352
  const getLog = component => {
447
353
  var _component$componentM, _messagePerComponent$;
448
-
449
354
  const nextVersion = persist ? (_component$componentM = component.componentMap) === null || _component$componentM === void 0 ? void 0 : _component$componentM.nextVersion : null;
450
355
  const msgFromEditor = (_messagePerComponent$ = messagePerComponent.find(item => item.id.isEqualWithoutVersion(component.id))) === null || _messagePerComponent$ === void 0 ? void 0 : _messagePerComponent$.msg;
451
356
  return {
@@ -455,14 +360,12 @@ async function addLogToComponents(components, autoTagComps, persist, message, me
455
360
  date: Date.now().toString()
456
361
  };
457
362
  };
458
-
459
363
  components.forEach(component => {
460
364
  component.log = getLog(component);
461
365
  });
462
366
  autoTagComps.forEach(autoTagComp => {
463
367
  autoTagComp.log = getLog(autoTagComp);
464
368
  const defaultMsg = 'bump dependencies versions';
465
-
466
369
  if (message) {
467
370
  autoTagComp.log.message += ` (${defaultMsg})`;
468
371
  } else if (!autoTagComp.log.message) {
@@ -470,11 +373,9 @@ async function addLogToComponents(components, autoTagComps, persist, message, me
470
373
  }
471
374
  });
472
375
  }
473
-
474
376
  async function getBitCloudUsername() {
475
377
  const token = await globalConfig().get(_constants().CFG_USER_TOKEN_KEY);
476
378
  if (!token) return '';
477
-
478
379
  try {
479
380
  const res = await (0, _nodeFetch().default)(`https://api.${_constants().BASE_CLOUD_DOMAIN}/user`, {
480
381
  headers: {
@@ -490,50 +391,41 @@ async function getBitCloudUsername() {
490
391
  return undefined;
491
392
  }
492
393
  }
493
-
494
394
  function setCurrentSchema(components) {
495
395
  components.forEach(component => {
496
396
  component.schema = _componentSchema().CURRENT_SCHEMA;
497
397
  });
498
398
  }
499
-
500
399
  function addBuildStatus(components, buildStatus) {
501
400
  components.forEach(component => {
502
401
  component.buildStatus = buildStatus;
503
402
  });
504
403
  }
505
-
506
404
  async function updateComponentsVersions(workspace, components, isTag = true) {
507
405
  const consumer = workspace.consumer;
508
406
  const currentLane = consumer.getCurrentLaneId();
509
407
  const stagedConfig = await workspace.scope.getStagedConfig();
510
-
511
408
  const isAvailableOnMain = async (component, id) => {
512
409
  if (currentLane.isDefault()) {
513
410
  return true;
514
411
  }
515
-
516
412
  if (!id.hasVersion()) {
517
413
  // component was unsnapped on the current lane and is back to a new component
518
414
  return true;
519
415
  }
520
-
521
416
  const modelComponent = component instanceof _models().ModelComponent ? component : await consumer.scope.getModelComponent(component.id);
522
417
  return modelComponent.hasHead();
523
418
  };
524
-
525
419
  const updateVersions = async unknownComponent => {
526
420
  const id = unknownComponent instanceof _models().ModelComponent ? unknownComponent.toBitIdWithLatestVersionAllowNull() : unknownComponent.id;
527
421
  consumer.bitMap.updateComponentId(id);
528
422
  const availableOnMain = await isAvailableOnMain(unknownComponent, id);
529
-
530
423
  if (!availableOnMain) {
531
424
  consumer.bitMap.setComponentProp(id, 'onLanesOnly', true);
532
425
  }
533
-
534
426
  const componentMap = consumer.bitMap.getComponent(id);
535
- const compId = await workspace.resolveComponentId(id); // it can be either a tag/snap or reset.
536
-
427
+ const compId = await workspace.resolveComponentId(id);
428
+ // it can be either a tag/snap or reset.
537
429
  if (isTag) {
538
430
  const config = componentMap.config;
539
431
  stagedConfig.addComponentConfig(compId, config);
@@ -541,13 +433,11 @@ async function updateComponentsVersions(workspace, components, isTag = true) {
541
433
  } else if (!componentMap.config) {
542
434
  componentMap.config = stagedConfig.getConfigPerId(compId);
543
435
  }
544
-
545
436
  componentMap.clearNextVersion();
546
- }; // important! DO NOT use Promise.all here! otherwise, you're gonna enter into a whole world of pain.
437
+ };
438
+ // important! DO NOT use Promise.all here! otherwise, you're gonna enter into a whole world of pain.
547
439
  // imagine tagging comp1 with auto-tagged comp2, comp1 package.json is written while comp2 is
548
440
  // trying to get the dependencies of comp1 using its package.json.
549
-
550
-
551
441
  await (0, _pMapSeries().default)(components, updateVersions);
552
442
  await stagedConfig.write();
553
443
  }