@teambit/objects 0.0.0-00133c53667c619f31de3353b1a01a30e323f7bd

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.
Files changed (117) hide show
  1. package/dist/fixtures/version-model-extended.json +48 -0
  2. package/dist/fixtures/version-model-object.json +87 -0
  3. package/dist/index.d.ts +19 -0
  4. package/dist/index.js +371 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/models/dependencies-graph.d.ts +46 -0
  7. package/dist/models/dependencies-graph.js +105 -0
  8. package/dist/models/dependencies-graph.js.map +1 -0
  9. package/dist/models/detach-heads.d.ts +25 -0
  10. package/dist/models/detach-heads.js +84 -0
  11. package/dist/models/detach-heads.js.map +1 -0
  12. package/dist/models/export-metadata.d.ts +24 -0
  13. package/dist/models/export-metadata.js +74 -0
  14. package/dist/models/export-metadata.js.map +1 -0
  15. package/dist/models/index.d.ts +10 -0
  16. package/dist/models/index.js +125 -0
  17. package/dist/models/index.js.map +1 -0
  18. package/dist/models/lane-history.d.ts +40 -0
  19. package/dist/models/lane-history.js +117 -0
  20. package/dist/models/lane-history.js.map +1 -0
  21. package/dist/models/lane.d.ts +125 -0
  22. package/dist/models/lane.js +461 -0
  23. package/dist/models/lane.js.map +1 -0
  24. package/dist/models/model-component.d.ts +320 -0
  25. package/dist/models/model-component.js +1392 -0
  26. package/dist/models/model-component.js.map +1 -0
  27. package/dist/models/model-component.spec.d.ts +1 -0
  28. package/dist/models/model-component.spec.js +71 -0
  29. package/dist/models/model-component.spec.js.map +1 -0
  30. package/dist/models/scopeMeta.d.ts +20 -0
  31. package/dist/models/scopeMeta.js +68 -0
  32. package/dist/models/scopeMeta.js.map +1 -0
  33. package/dist/models/source.d.ts +10 -0
  34. package/dist/models/source.js +42 -0
  35. package/dist/models/source.js.map +1 -0
  36. package/dist/models/symlink.d.ts +30 -0
  37. package/dist/models/symlink.js +91 -0
  38. package/dist/models/symlink.js.map +1 -0
  39. package/dist/models/version-history.d.ts +59 -0
  40. package/dist/models/version-history.js +287 -0
  41. package/dist/models/version-history.js.map +1 -0
  42. package/dist/models/version.d.ts +286 -0
  43. package/dist/models/version.js +774 -0
  44. package/dist/models/version.js.map +1 -0
  45. package/dist/models/version.spec.d.ts +1 -0
  46. package/dist/models/version.spec.js +332 -0
  47. package/dist/models/version.spec.js.map +1 -0
  48. package/dist/objects/bit-object-list.d.ts +24 -0
  49. package/dist/objects/bit-object-list.js +65 -0
  50. package/dist/objects/bit-object-list.js.map +1 -0
  51. package/dist/objects/index.d.ts +5 -0
  52. package/dist/objects/index.js +60 -0
  53. package/dist/objects/index.js.map +1 -0
  54. package/dist/objects/object-list-to-graph.d.ts +13 -0
  55. package/dist/objects/object-list-to-graph.js +93 -0
  56. package/dist/objects/object-list-to-graph.js.map +1 -0
  57. package/dist/objects/object-list.d.ts +52 -0
  58. package/dist/objects/object-list.js +369 -0
  59. package/dist/objects/object-list.js.map +1 -0
  60. package/dist/objects/object.d.ts +35 -0
  61. package/dist/objects/object.js +189 -0
  62. package/dist/objects/object.js.map +1 -0
  63. package/dist/objects/objects-readable-generator.d.ts +31 -0
  64. package/dist/objects/objects-readable-generator.js +192 -0
  65. package/dist/objects/objects-readable-generator.js.map +1 -0
  66. package/dist/objects/raw-object.d.ts +23 -0
  67. package/dist/objects/raw-object.js +145 -0
  68. package/dist/objects/raw-object.js.map +1 -0
  69. package/dist/objects/ref.d.ts +14 -0
  70. package/dist/objects/ref.js +45 -0
  71. package/dist/objects/ref.js.map +1 -0
  72. package/dist/objects/repository.d.ts +165 -0
  73. package/dist/objects/repository.js +851 -0
  74. package/dist/objects/repository.js.map +1 -0
  75. package/dist/objects/scope-index.d.ts +74 -0
  76. package/dist/objects/scope-index.js +255 -0
  77. package/dist/objects/scope-index.js.map +1 -0
  78. package/dist/objects/scope-index.spec.d.ts +1 -0
  79. package/dist/objects/scope-index.spec.js +152 -0
  80. package/dist/objects/scope-index.spec.js.map +1 -0
  81. package/dist/objects.aspect.d.ts +2 -0
  82. package/dist/objects.aspect.js +18 -0
  83. package/dist/objects.aspect.js.map +1 -0
  84. package/dist/objects.main.runtime.d.ts +7 -0
  85. package/dist/objects.main.runtime.js +36 -0
  86. package/dist/objects.main.runtime.js.map +1 -0
  87. package/dist/preview-1763506442019.js +7 -0
  88. package/fixtures/version-model-extended.json +48 -0
  89. package/fixtures/version-model-object.json +87 -0
  90. package/models/dependencies-graph.ts +120 -0
  91. package/models/detach-heads.ts +79 -0
  92. package/models/export-metadata.ts +56 -0
  93. package/models/index.ts +11 -0
  94. package/models/lane-history.ts +106 -0
  95. package/models/lane.ts +368 -0
  96. package/models/model-component.spec.ts +55 -0
  97. package/models/model-component.ts +1407 -0
  98. package/models/scopeMeta.ts +58 -0
  99. package/models/source.ts +31 -0
  100. package/models/symlink.ts +66 -0
  101. package/models/version-history.ts +271 -0
  102. package/models/version.spec.ts +280 -0
  103. package/models/version.ts +815 -0
  104. package/objects/bit-object-list.ts +59 -0
  105. package/objects/index.ts +6 -0
  106. package/objects/object-list-to-graph.ts +69 -0
  107. package/objects/object-list.ts +313 -0
  108. package/objects/object.ts +152 -0
  109. package/objects/objects-readable-generator.ts +167 -0
  110. package/objects/raw-object.ts +132 -0
  111. package/objects/ref.ts +45 -0
  112. package/objects/repository.ts +771 -0
  113. package/objects/scope-index.spec.ts +95 -0
  114. package/objects/scope-index.ts +197 -0
  115. package/package.json +96 -0
  116. package/types/asset.d.ts +41 -0
  117. package/types/style.d.ts +42 -0
@@ -0,0 +1,1392 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = exports.VERSION_ZERO = void 0;
7
+ function _lodash() {
8
+ const data = require("lodash");
9
+ _lodash = function () {
10
+ return data;
11
+ };
12
+ return data;
13
+ }
14
+ function _asyncMutex() {
15
+ const data = require("async-mutex");
16
+ _asyncMutex = function () {
17
+ return data;
18
+ };
19
+ return data;
20
+ }
21
+ function semver() {
22
+ const data = _interopRequireWildcard(require("semver"));
23
+ semver = function () {
24
+ return data;
25
+ };
26
+ return data;
27
+ }
28
+ function _componentVersion() {
29
+ const data = require("@teambit/component-version");
30
+ _componentVersion = function () {
31
+ return data;
32
+ };
33
+ return data;
34
+ }
35
+ function _bitError() {
36
+ const data = require("@teambit/bit-error");
37
+ _bitError = function () {
38
+ return data;
39
+ };
40
+ return data;
41
+ }
42
+ function _laneId() {
43
+ const data = require("@teambit/lane-id");
44
+ _laneId = function () {
45
+ return data;
46
+ };
47
+ return data;
48
+ }
49
+ function _componentId() {
50
+ const data = require("@teambit/component-id");
51
+ _componentId = function () {
52
+ return data;
53
+ };
54
+ return data;
55
+ }
56
+ function _pMapSeries() {
57
+ const data = _interopRequireDefault(require("p-map-series"));
58
+ _pMapSeries = function () {
59
+ return data;
60
+ };
61
+ return data;
62
+ }
63
+ function _toolboxArray() {
64
+ const data = require("@teambit/toolbox.array.duplications-finder");
65
+ _toolboxArray = function () {
66
+ return data;
67
+ };
68
+ return data;
69
+ }
70
+ function _legacyBitId() {
71
+ const data = require("@teambit/legacy-bit-id");
72
+ _legacyBitId = function () {
73
+ return data;
74
+ };
75
+ return data;
76
+ }
77
+ function _legacy() {
78
+ const data = require("@teambit/legacy.constants");
79
+ _legacy = function () {
80
+ return data;
81
+ };
82
+ return data;
83
+ }
84
+ function _legacy2() {
85
+ const data = require("@teambit/legacy.consumer-component");
86
+ _legacy2 = function () {
87
+ return data;
88
+ };
89
+ return data;
90
+ }
91
+ function _component() {
92
+ const data = require("@teambit/component.sources");
93
+ _component = function () {
94
+ return data;
95
+ };
96
+ return data;
97
+ }
98
+ function _legacy3() {
99
+ const data = require("@teambit/legacy.consumer-config");
100
+ _legacy3 = function () {
101
+ return data;
102
+ };
103
+ return data;
104
+ }
105
+ function _legacyCli() {
106
+ const data = require("@teambit/legacy.cli.error");
107
+ _legacyCli = function () {
108
+ return data;
109
+ };
110
+ return data;
111
+ }
112
+ function _legacy4() {
113
+ const data = require("@teambit/legacy.logger");
114
+ _legacy4 = function () {
115
+ return data;
116
+ };
117
+ return data;
118
+ }
119
+ function _legacy5() {
120
+ const data = require("@teambit/legacy.utils");
121
+ _legacy5 = function () {
122
+ return data;
123
+ };
124
+ return data;
125
+ }
126
+ function _pkgModules() {
127
+ const data = require("@teambit/pkg.modules.semver-helper");
128
+ _pkgModules = function () {
129
+ return data;
130
+ };
131
+ return data;
132
+ }
133
+ function _component2() {
134
+ const data = require("@teambit/component.snap-distance");
135
+ _component2 = function () {
136
+ return data;
137
+ };
138
+ return data;
139
+ }
140
+ function _legacy6() {
141
+ const data = require("@teambit/legacy.scope");
142
+ _legacy6 = function () {
143
+ return data;
144
+ };
145
+ return data;
146
+ }
147
+ function _objects() {
148
+ const data = require("../objects");
149
+ _objects = function () {
150
+ return data;
151
+ };
152
+ return data;
153
+ }
154
+ function _scopeMeta() {
155
+ const data = _interopRequireDefault(require("./scopeMeta"));
156
+ _scopeMeta = function () {
157
+ return data;
158
+ };
159
+ return data;
160
+ }
161
+ function _versionHistory() {
162
+ const data = _interopRequireDefault(require("./version-history"));
163
+ _versionHistory = function () {
164
+ return data;
165
+ };
166
+ return data;
167
+ }
168
+ function _detachHeads() {
169
+ const data = require("./detach-heads");
170
+ _detachHeads = function () {
171
+ return data;
172
+ };
173
+ return data;
174
+ }
175
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
176
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
177
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
178
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
179
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
180
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
181
+ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
182
+ const VERSION_ZERO = exports.VERSION_ZERO = '0.0.0';
183
+
184
+ /**
185
+ * we can't rename the class as ModelComponent because old components are already saved in the model
186
+ * with 'Component' in their headers. see object-registrar.types()
187
+ */
188
+ // TODO: FIX me .parser
189
+ class Component extends _objects().BitObject {
190
+ constructor(props) {
191
+ super();
192
+ _defineProperty(this, "scope", void 0);
193
+ _defineProperty(this, "name", void 0);
194
+ _defineProperty(this, "versions", void 0);
195
+ _defineProperty(this, "orphanedVersions", void 0);
196
+ _defineProperty(this, "lang", void 0);
197
+ /**
198
+ * @deprecated moved to the Version object inside teambit/deprecation aspect
199
+ */
200
+ _defineProperty(this, "deprecated", void 0);
201
+ _defineProperty(this, "bindingPrefix", void 0);
202
+ /**
203
+ * @deprecated since 0.12.6 (long long ago :) probably can be removed)
204
+ */
205
+ _defineProperty(this, "local", void 0);
206
+ _defineProperty(this, "state", void 0);
207
+ _defineProperty(this, "scopesList", void 0);
208
+ _defineProperty(this, "head", void 0);
209
+ _defineProperty(this, "remoteHead", void 0);
210
+ // doesn't get saved in the scope, used to easier access the remote main head
211
+ /**
212
+ * doesn't get saved in the scope, used to easier access the local snap head data
213
+ * when checked out to a lane, this prop is either Ref or null. otherwise (when on main), this prop is undefined.
214
+ */
215
+ _defineProperty(this, "laneHeadLocal", void 0);
216
+ /**
217
+ * doesn't get saved in the scope, used to easier access the remote snap head data
218
+ * when checked out to a lane, this prop is either Ref or null. otherwise (when on main), this prop is undefined.
219
+ */
220
+ _defineProperty(this, "laneHeadRemote", void 0);
221
+ /**
222
+ * when checked out to a lane, calculate what should be the head on the remote.
223
+ * if the laneHeadRemote is null, for example, when the lane is new, then used the the lane it was forked from.
224
+ * it no head is found on the lane/forked, then use the component.head.
225
+ */
226
+ _defineProperty(this, "calculatedRemoteHeadWhenOnLane", void 0);
227
+ _defineProperty(this, "laneId", void 0);
228
+ // doesn't get saved in the scope.
229
+ _defineProperty(this, "laneDataIsPopulated", false);
230
+ // doesn't get saved in the scope, used to improve performance of loading the lane data
231
+ _defineProperty(this, "schema", void 0);
232
+ _defineProperty(this, "detachedHeads", void 0);
233
+ _defineProperty(this, "divergeData", void 0);
234
+ _defineProperty(this, "_populateVersionHistoryMutex", void 0);
235
+ if (!props.name) throw new TypeError('Model Component constructor expects to get a name parameter');
236
+ if (!props.scope) {
237
+ throw new (_legacy6().BitIdCompIdError)(props.name);
238
+ }
239
+ this.scope = props.scope;
240
+ this.name = props.name;
241
+ this.versions = props.versions || {};
242
+ this.orphanedVersions = props.orphanedVersions || {};
243
+ this.lang = props.lang || _legacy().DEFAULT_LANGUAGE;
244
+ this.deprecated = props.deprecated || false;
245
+ this.bindingPrefix = props.bindingPrefix || (0, _legacy3().getBindingPrefixByDefaultScope)(props.scope);
246
+ this.state = props.state || {};
247
+ this.scopesList = props.scopesList || [];
248
+ this.head = props.head;
249
+ this.schema = props.schema;
250
+ this.detachedHeads = props.detachedHeads || new (_detachHeads().DetachedHeads)();
251
+ }
252
+ get populateVersionHistoryMutex() {
253
+ if (!this._populateVersionHistoryMutex) {
254
+ this._populateVersionHistoryMutex = new (_asyncMutex().Mutex)();
255
+ }
256
+ return this._populateVersionHistoryMutex;
257
+ }
258
+ get versionArray() {
259
+ return Object.values(this.versions);
260
+ }
261
+ setVersion(tag, ref) {
262
+ this.versions[tag] = ref;
263
+ delete this.orphanedVersions[tag]; // just in case it's there.
264
+ }
265
+ setOrphanedVersion(tag, ref) {
266
+ if (this.versions[tag]) {
267
+ throw new Error(`unable to save orphanedVersion "${tag}" for "${this.id()}" because this tag is already part of the versions prop`);
268
+ }
269
+ this.orphanedVersions[tag] = ref;
270
+ }
271
+ getRef(version) {
272
+ if ((0, _componentVersion().isTag)(version)) {
273
+ return this.versionsIncludeOrphaned[version];
274
+ }
275
+ if ((0, _componentVersion().isHash)(version)) {
276
+ return new (_objects().Ref)(version);
277
+ }
278
+ return null;
279
+ }
280
+ getHeadStr() {
281
+ return this.head ? this.head.toString() : null;
282
+ }
283
+ getHead() {
284
+ return this.head;
285
+ }
286
+
287
+ /**
288
+ * returns the head hash. regardless of whether current lane is the default or not.
289
+ * if on a lane, it returns the head of the component on the lane.
290
+ */
291
+ getHeadRegardlessOfLane() {
292
+ return this.laneHeadLocal || this.getHead();
293
+ }
294
+ getHeadAsTagIfExist() {
295
+ if (!this.head) return undefined;
296
+ return this.getTagOfRefIfExists(this.head) || this.head.toString();
297
+ }
298
+ hasHead() {
299
+ return Boolean(this.head);
300
+ }
301
+ setHead(head) {
302
+ this.head = head;
303
+ }
304
+ listVersions(sort) {
305
+ const versions = Object.keys(this.versions);
306
+ if (!sort) return versions;
307
+ if (sort === 'ASC') {
308
+ return versions.sort(semver().compare);
309
+ }
310
+ return versions.sort(semver().compare).reverse();
311
+ }
312
+ listVersionsIncludeOrphaned(sort) {
313
+ const versions = Object.keys(this.versionsIncludeOrphaned);
314
+ if (!sort) return versions;
315
+ if (sort === 'ASC') {
316
+ return versions.sort(semver().compare);
317
+ }
318
+ return versions.sort(semver().compare).reverse();
319
+ }
320
+ async hasVersion(version, repo, includeOrphaned = true) {
321
+ if ((0, _componentVersion().isTag)(version)) {
322
+ return includeOrphaned ? this.hasTagIncludeOrphaned(version) : this.hasTag(version);
323
+ }
324
+ const head = this.getHeadRegardlessOfLane();
325
+ if (!head) {
326
+ return false;
327
+ }
328
+ const versionParents = await (0, _component2().getAllVersionParents)({
329
+ repo,
330
+ modelComponent: this,
331
+ heads: [head]
332
+ });
333
+ // we use "startsWith" because it can be a short hash
334
+ return versionParents.map(v => v.hash).some(hash => hash.toString().startsWith(version));
335
+ }
336
+ hasTag(version) {
337
+ return Boolean(this.versions[version]);
338
+ }
339
+ get versionsIncludeOrphaned() {
340
+ // for bit-bin with 266 components, it takes about 1,700ms. don't use lodash.merge, it's much faster
341
+ // but mutates `this.versions`.
342
+ return _objectSpread(_objectSpread({}, this.versions), this.orphanedVersions);
343
+ }
344
+ hasTagIncludeOrphaned(version) {
345
+ return Boolean(this.versions[version] || this.orphanedVersions[version]);
346
+ }
347
+
348
+ /**
349
+ * whether the head is a snap (not a tag)
350
+ */
351
+ isHeadSnap() {
352
+ const tagsHashes = this.versionArray.map(ref => ref.toString());
353
+ return this.head && !tagsHashes.includes(this.head.toString());
354
+ }
355
+
356
+ /**
357
+ * add a new remote if it is not there already
358
+ */
359
+ addScopeListItem(scopeListItem) {
360
+ if (!scopeListItem.name || !scopeListItem.url || !scopeListItem.date) {
361
+ throw new TypeError(`model-component.addRemote get an invalid remote. name: ${scopeListItem.name}, url: ${scopeListItem.url}, date: ${scopeListItem.date}`);
362
+ }
363
+ if (!this.scopesList.find(r => r.url === scopeListItem.url)) {
364
+ this.scopesList.push(scopeListItem);
365
+ }
366
+ }
367
+
368
+ /**
369
+ * on main - it checks local-head (or .bitmap version if given) vs remote-head.
370
+ * on lane - it checks local-head on lane vs remote-head on lane.
371
+ * however, to get an accurate `divergeData.snapsOnSourceOnly`, the above is not enough.
372
+ * for example, comp-a@snap-x from lane-a is merged into lane-b. we don't want this snap-x to be "local", because
373
+ * then, bit-status will show it as "staged" and bit-reset will remove it unexpectedly.
374
+ * if we only check by the local-head and remote-head on lane, it'll be local because the remote-head of lane-b is empty.
375
+ * to address this, we search all remote-refs files for this bit-id and during the local history traversal, if a hash
376
+ * is found there, it'll stop the traversal and not mark it as remote.
377
+ * in this example, during the merge, lane-a was fetched, and the remote-ref of this lane has snap-x as the head.
378
+ */
379
+ async setDivergeData(repo, throws = true, fromCache = true, workspaceId) {
380
+ if (!this.divergeData || !fromCache) {
381
+ const remoteHead = (this.laneId ? this.calculatedRemoteHeadWhenOnLane : this.remoteHead) || null;
382
+ // this is for detach-head scenario. it can happen on main only. we want to compare against the .bitmap
383
+ // version (which is the detached head) and not the actual head.
384
+ const workspaceVersion = !this.isOnLane() && workspaceId?.hasVersion() ? workspaceId.version : null;
385
+ this.divergeData = await (0, _component2().getDivergeData)({
386
+ repo,
387
+ modelComponent: this,
388
+ targetHead: remoteHead,
389
+ sourceHead: workspaceVersion ? this.getRef(workspaceVersion) : undefined,
390
+ throws
391
+ });
392
+ }
393
+ }
394
+ isOnLane() {
395
+ return Boolean(this.laneHeadLocal || this.laneHeadLocal === null);
396
+ }
397
+
398
+ /**
399
+ * this is used (among others) by `bit status` to check whether snaps are local (staged), for `bit reset` to remove them
400
+ * and for `bit export` to push them. for "merge pending" status, use `this.getDivergeDataForMergePending()`.
401
+ */
402
+ getDivergeData() {
403
+ if (!this.divergeData) throw new Error(`getDivergeData() expects divergeData to be populate, please use this.setDivergeData() for id: ${this.id()}`);
404
+ return this.divergeData;
405
+ }
406
+
407
+ /**
408
+ * don't use modelComponent.getDivergeData() because in some scenarios when on a lane, it compares the head
409
+ * on the lane against the head on the main, which could show the component as diverged incorrectly.
410
+ */
411
+ async getDivergeDataForMergePending(repo) {
412
+ return (0, _component2().getDivergeData)({
413
+ repo,
414
+ modelComponent: this,
415
+ targetHead: (this.laneId ? this.laneHeadRemote : this.remoteHead) || null,
416
+ throws: false
417
+ });
418
+ }
419
+ async populateLocalAndRemoteHeads(repo, lane) {
420
+ this.setLaneHeadLocal(lane);
421
+ if (lane) this.laneId = lane.toLaneId();
422
+ if (!this.scope) {
423
+ return; // no remote to update. it's local.
424
+ }
425
+ this.remoteHead = await repo.remoteLanes.getRef(_laneId().LaneId.from(_laneId().DEFAULT_LANE, this.scope), this.toComponentId());
426
+ if (!lane) {
427
+ return;
428
+ }
429
+ this.laneHeadRemote = lane.isNew ? null : await repo.remoteLanes.getRef(lane.toLaneId(), this.toComponentId());
430
+ const calculateRemote = async () => {
431
+ if (this.laneHeadRemote) return this.laneHeadRemote;
432
+ if (lane.isNew && lane.forkedFrom && lane.forkedFrom.scope === lane.scope) {
433
+ // the last check is to make sure that if this lane will be exported to a different scope than the original
434
+ // lane, all snaps of the original lane will be considered as local and will be exported later on.
435
+ const headFromFork = await repo.remoteLanes.getRef(lane.forkedFrom, this.toComponentId());
436
+ if (headFromFork) return headFromFork;
437
+ }
438
+ // if no remote-ref was found, because it's checked out to a lane, it's safe to assume that
439
+ // this.head should be on the original-remote. hence, FetchMissingHistory will retrieve it on lane-remote
440
+ return this.remoteHead || this.head;
441
+ };
442
+ this.calculatedRemoteHeadWhenOnLane = await calculateRemote();
443
+ }
444
+ setLaneHeadLocal(lane) {
445
+ if (lane) {
446
+ this.laneHeadLocal = lane.getComponentHead(this.toComponentId());
447
+ }
448
+ }
449
+
450
+ /**
451
+ * returns only the versions that exist in both components (regardless whether the hash are the same)
452
+ * e.g. this.component = [0.0.1, 0.0.2, 0.0.3], other component = [0.0.3, 0.0.4]. it returns only [0.0.3].
453
+ * also, in case it is coming from 'bit import', the version must be locally changed.
454
+ * otherwise, it doesn't matter whether the hashes are different.
455
+ */
456
+ _getComparableVersionsObjects(otherComponent,
457
+ // in case of merging, the otherComponent is the existing component, and "this" is the incoming component
458
+ local) {
459
+ const otherLocalVersion = otherComponent.getLocalVersions();
460
+ const otherComponentVersions = (0, _lodash().pickBy)(otherComponent.versions, (val, key) => Object.keys(this.versions).includes(key) && (!local || otherLocalVersion.includes(key)));
461
+ const thisComponentVersions = (0, _lodash().pickBy)(this.versions, (val, key) => Object.keys(otherComponentVersions).includes(key) && (!local || otherLocalVersion.includes(key)));
462
+ return {
463
+ thisComponentVersions,
464
+ otherComponentVersions
465
+ };
466
+ }
467
+ compatibleWith(component, local) {
468
+ const {
469
+ thisComponentVersions,
470
+ otherComponentVersions
471
+ } = this._getComparableVersionsObjects(component, local);
472
+ return (0, _lodash().isEqual)(thisComponentVersions, otherComponentVersions);
473
+ }
474
+ diffWith(component, local) {
475
+ const {
476
+ thisComponentVersions,
477
+ otherComponentVersions
478
+ } = this._getComparableVersionsObjects(component, local);
479
+ return Object.keys(thisComponentVersions).filter(version => thisComponentVersions[version].hash !== otherComponentVersions[version].hash);
480
+ }
481
+ isEmpty() {
482
+ return (0, _lodash().isEmpty)(this.versions) && !this.hasHead();
483
+ }
484
+
485
+ /**
486
+ * on main return main head, on lane, return lane head.
487
+ * if the head is also a tag, return the tag, otherwise, return the hash.
488
+ */
489
+ getHeadRegardlessOfLaneAsTagOrHash(returnVersionZeroForNoHead = false) {
490
+ const head = this.getHeadRegardlessOfLane();
491
+ if (!head) {
492
+ if (!(0, _lodash().isEmpty)(this.versions)) throw new Error(`error: ${this.id()} has tags but no head, it might be originated from legacy`);
493
+ if (returnVersionZeroForNoHead) return VERSION_ZERO;
494
+ throw new Error(`getHeadRegardlessOfLaneAsTagOrHash() failed finding a head for ${this.id()}`);
495
+ }
496
+ return this.getTagOfRefIfExists(head) || head.toString();
497
+ }
498
+
499
+ /**
500
+ * get the recent head. if locally is ahead, return the local head. otherwise, return the remote head.
501
+ *
502
+ * a user can be checked out to a lane, in which case, `this.laneHeadLocal` and `this.laneHeadRemote`
503
+ * may be populated.
504
+ * `this.head` may not be populated, e.g. when a component was created on
505
+ * this lane and never got snapped on main.
506
+ * it's impossible that `this.head.isEqual(this.laneHeadLocal)`, because when snapping it's either
507
+ * on main, which goes to this.head OR on a lane, which goes to this.laneHeadLocal.
508
+ */
509
+ async headIncludeRemote(repo) {
510
+ const latestLocally = this.getHeadRegardlessOfLaneAsTagOrHash(true);
511
+ const remoteHead = this.laneHeadRemote || this.remoteHead;
512
+ if (!remoteHead) return latestLocally;
513
+ if (!this.getHeadRegardlessOfLane()) {
514
+ return remoteHead.toString(); // in case a snap was created on another lane
515
+ }
516
+
517
+ // either a user is on main or a lane, check whether the remote is ahead of the local
518
+ if (this.laneId && !this.laneHeadRemote) {
519
+ // when on a lane, setDivergeData is using the `this.calculatedRemoteHeadWhenOnLane`,
520
+ // which takes into account main-head and forked-head. here, we don't want this. we care only about the
521
+ // remote-lane head.
522
+ return latestLocally;
523
+ }
524
+ await this.setDivergeData(repo, false);
525
+ const divergeData = this.getDivergeData();
526
+ if (divergeData.isTargetAhead()) {
527
+ return this.getTagOfRefIfExists(remoteHead) || remoteHead.toString();
528
+ }
529
+ return latestLocally;
530
+ }
531
+ async getRefOfAncestor(repo, generationsToGoBack) {
532
+ const head = this.getHeadRegardlessOfLane();
533
+ if (!head) throw new (_bitError().BitError)(`getRefOfAncestor failed to find the head of ${this.id()}`);
534
+ const versionHistory = await this.getAndPopulateVersionHistory(repo, head);
535
+ return versionHistory.getAncestor(generationsToGoBack, head);
536
+ }
537
+ latestVersion() {
538
+ if ((0, _lodash().isEmpty)(this.versions)) return VERSION_ZERO;
539
+ return (0, _pkgModules().getLatestVersion)(this.listVersions());
540
+ }
541
+ latestVersionIfExist() {
542
+ if ((0, _lodash().isEmpty)(this.versions)) return undefined;
543
+ return (0, _pkgModules().getLatestVersion)(this.listVersions());
544
+ }
545
+
546
+ // @todo: make it readable, it's a mess
547
+ isLatestGreaterThan(version) {
548
+ if (!version) throw TypeError('isLatestGreaterThan expect to get a Version');
549
+ const latest = this.getHeadRegardlessOfLaneAsTagOrHash(true);
550
+ if (this.isEmpty() && !this.calculatedRemoteHeadWhenOnLane) {
551
+ return false; // in case a snap was created on another lane
552
+ }
553
+ if ((0, _componentVersion().isTag)(latest) && (0, _componentVersion().isTag)(version)) {
554
+ return semver().gt(latest, version);
555
+ }
556
+ if (latest === version) return false;
557
+ const latestRef = this.getRef(latest);
558
+ if (!latestRef) throw new Error('isLatestGreaterThan, latestRef was not found');
559
+ const latestHash = latestRef.toString();
560
+ const versionRef = this.getRef(version);
561
+ if (!versionRef) return true; // probably a child
562
+ const versionHash = versionRef.toString();
563
+ if (latestHash === versionHash) return false;
564
+ return true;
565
+ }
566
+
567
+ /**
568
+ * Return the lateset version which actuall exists in the scope
569
+ * (exists means the object itself exists)
570
+ * This relevant for cases when the component version array has few versions
571
+ * but we don't have all the refs in the object
572
+ *
573
+ * @returns {number}
574
+ * @memberof Component
575
+ */
576
+ latestExisting(repository) {
577
+ if ((0, _lodash().isEmpty)(this.versions)) return VERSION_ZERO;
578
+ const versions = this.listVersions('ASC');
579
+ let version = null;
580
+ let versionStr = null;
581
+ while (!version && versions && versions.length) {
582
+ // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
583
+ versionStr = versions.pop();
584
+ // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
585
+ version = this.loadVersionSync(versionStr, repository, false);
586
+ }
587
+ return versionStr || VERSION_ZERO;
588
+ }
589
+
590
+ /**
591
+ * get component log and sort by the timestamp in ascending order (from the earliest to the latest)
592
+ */
593
+ async collectLogs(scope, shortHash = false, startFrom) {
594
+ const repo = scope.objects;
595
+ let versionsInfo = await (0, _component2().getAllVersionsInfo)({
596
+ modelComponent: this,
597
+ repo,
598
+ throws: false,
599
+ startFrom
600
+ });
601
+
602
+ // due to recent changes of getting version-history object rather than fetching the entire history, some version
603
+ // objects might be missing. import the component from the remote
604
+ if (versionsInfo.some(v => v.error && (0, _legacy6().errorIsTypeOfMissingObject)(v.error)) && this.scope !== repo.scopeJson.name) {
605
+ _legacy4().logger.info(`collectLogs is unable to find some objects for ${this.id()}. will try to import them`);
606
+ try {
607
+ const lane = await scope.getCurrentLaneObject();
608
+ await scope.scopeImporter.importWithoutDeps(_componentId().ComponentIdList.fromArray([this.toComponentId()]).toVersionLatest(), {
609
+ cache: false,
610
+ includeVersionHistory: true,
611
+ collectParents: true,
612
+ lane: lane || undefined,
613
+ reason: 'to collect logs (including parents)'
614
+ });
615
+ versionsInfo = await (0, _component2().getAllVersionsInfo)({
616
+ modelComponent: this,
617
+ repo,
618
+ throws: false,
619
+ startFrom
620
+ });
621
+ } catch (err) {
622
+ _legacy4().logger.error(`collectLogs failed to import ${this.id()} history`, err);
623
+ }
624
+ }
625
+ const head = this.getHeadRegardlessOfLane();
626
+ const headVersion = head ? await repo.load(head) : undefined;
627
+ const removeAspect = headVersion?.extensions.findCoreExtension(_legacy().Extensions.remove);
628
+ const removeRange = removeAspect?.config.range;
629
+ const removeSnaps = removeAspect?.config.snaps || [];
630
+ const deprecationAspect = headVersion?.extensions.findCoreExtension(_legacy().Extensions.deprecation);
631
+ const deprecationRange = deprecationAspect?.config.range;
632
+ const getRef = ref => shortHash ? ref.toShortString() : ref.toString();
633
+ const results = versionsInfo.map(versionInfo => {
634
+ const log = versionInfo.version ? versionInfo.version.log : {
635
+ message: '<no-data-available>'
636
+ };
637
+ return _objectSpread(_objectSpread({}, log), {}, {
638
+ // @ts-ignore
639
+ username: log?.username || 'unknown',
640
+ // @ts-ignore
641
+ email: log?.email || 'unknown',
642
+ tag: versionInfo.tag,
643
+ hash: getRef(versionInfo.ref),
644
+ parents: versionInfo.parents.map(parent => getRef(parent)),
645
+ onLane: versionInfo.onLane,
646
+ deleted: versionInfo.tag && removeRange && semver().satisfies(versionInfo.tag, removeRange) || !versionInfo.tag && removeSnaps.includes(versionInfo.ref.toString()),
647
+ deprecated: versionInfo.tag && deprecationRange && semver().satisfies(versionInfo.tag, deprecationRange),
648
+ hidden: versionInfo.version?.hidden
649
+ });
650
+ });
651
+ // sort from earliest to latest
652
+ const sorted = results.sort((a, b) => {
653
+ // @ts-ignore
654
+ if (a.date && b.date) return a.date - b.date;
655
+ return 0;
656
+ });
657
+ return sorted;
658
+ }
659
+ collectVersions(repo) {
660
+ return Promise.all(this.listVersions().map(versionNum => {
661
+ return this.toConsumerComponent(versionNum, this.scope, repo);
662
+ }));
663
+ }
664
+ getTagOfRefIfExists(ref, allTags = this.versionsIncludeOrphaned) {
665
+ return Object.keys(allTags).find(versionRef => allTags[versionRef].isEqual(ref));
666
+ }
667
+ getTag(version) {
668
+ if ((0, _componentVersion().isTag)(version)) return version;
669
+ const ref = _objects().Ref.from(version);
670
+ return this.getTagOfRefIfExists(ref);
671
+ }
672
+ switchHashesWithTagsIfExist(refs) {
673
+ // cache the this.versionsIncludeOrphaned results into "allTags", looks strange but it improved
674
+ // the performance on bit-bin with 188 components during source.merge in 4 seconds.
675
+ const allTags = this.versionsIncludeOrphaned;
676
+ return refs.map(ref => this.getTagOfRefIfExists(ref, allTags) || ref.toString());
677
+ }
678
+
679
+ /**
680
+ * if exactVersion is defined, add exact version instead of using the semver mechanism
681
+ */
682
+ getVersionToAdd(releaseType = _legacy().DEFAULT_BIT_RELEASE_TYPE, exactVersion, incrementBy, preReleaseId) {
683
+ if (exactVersion && this.versions[exactVersion]) {
684
+ throw new (_legacy6().VersionAlreadyExists)(exactVersion, this.id());
685
+ }
686
+ const version = exactVersion || this.version(releaseType, incrementBy, preReleaseId);
687
+ (0, _pkgModules().validateVersion)(version);
688
+ return version;
689
+ }
690
+ isEqual(component, considerOrphanedVersions = true) {
691
+ if (this.hasHead() && !component.hasHead() || !this.hasHead() && component.hasHead()) {
692
+ return false; // only one of them has head
693
+ }
694
+ if (this.head && component.head && !this.head.isEqual(component.head)) {
695
+ return false; // the head is not equal.
696
+ }
697
+ // the head is equal or they both don't have head. check the versions
698
+ if (this.versionArray.length !== component.versionArray.length) {
699
+ return false;
700
+ }
701
+ const hasSameVersions = Object.keys(this.versions).every(tag => component.versions[tag] && component.versions[tag].isEqual(this.versions[tag]));
702
+ if (considerOrphanedVersions) {
703
+ if (Object.keys(this.orphanedVersions).length !== Object.keys(component.orphanedVersions).length) {
704
+ return false;
705
+ }
706
+ const hasSameOrphanedVersions = Object.keys(this.orphanedVersions).every(tag => component.orphanedVersions[tag] && component.orphanedVersions[tag].isEqual(this.orphanedVersions[tag]));
707
+ if (!hasSameOrphanedVersions) {
708
+ return false;
709
+ }
710
+ }
711
+ return hasSameVersions;
712
+ }
713
+
714
+ // eslint-disable-next-line complexity
715
+ addVersion(version, versionToAdd, lane, previouslyUsedVersion, {
716
+ addToUpdateDependentsInLane,
717
+ setHeadAsParent,
718
+ detachHead,
719
+ overrideHead
720
+ } = {}) {
721
+ if (detachHead && overrideHead) {
722
+ throw new Error(`addVersion expects either detachHead or overrideHead to be true, not both`);
723
+ }
724
+ if (lane) {
725
+ if ((0, _componentVersion().isTag)(versionToAdd)) {
726
+ throw new (_bitError().BitError)('unable to tag when checked out to a lane, please switch to main, merge the lane and then tag again');
727
+ }
728
+ const currentBitId = this.toComponentId();
729
+ const versionToAddRef = _objects().Ref.from(versionToAdd);
730
+ const parent = previouslyUsedVersion ? this.getRef(previouslyUsedVersion) : null;
731
+ if (!parent) {
732
+ const existingComponentInLane = lane.getComponent(currentBitId);
733
+ const currentHead = existingComponentInLane && existingComponentInLane.head || this.getHead();
734
+ if (currentHead) {
735
+ throw new Error(`component ${currentBitId.toString()} has a head (${currentHead.toString()}) but previouslyUsedVersion is empty`);
736
+ }
737
+ }
738
+ if (parent && !parent.isEqual(versionToAddRef)) {
739
+ version.addAsOnlyParent(parent);
740
+ }
741
+ if (addToUpdateDependentsInLane) {
742
+ lane.addComponentToUpdateDependents(currentBitId.changeVersion(versionToAddRef.toString()));
743
+ lane.setOverrideUpdateDependents(true);
744
+ } else {
745
+ lane.addComponent({
746
+ id: currentBitId,
747
+ head: versionToAddRef,
748
+ isDeleted: version.isRemoved()
749
+ });
750
+ }
751
+ if (lane.readmeComponent && lane.readmeComponent.id.fullName === currentBitId.fullName) {
752
+ lane.setReadmeComponent(currentBitId);
753
+ }
754
+ this.laneHeadLocal = versionToAddRef;
755
+ return versionToAdd;
756
+ }
757
+ // user on main
758
+ const head = this.getHead();
759
+ const parent = previouslyUsedVersion ? this.getRef(previouslyUsedVersion) : null;
760
+ if (head && head.toString() !== versionToAdd && !this.hasTag(versionToAdd) // happens with auto-snap
761
+ ) {
762
+ // if this is a tag and this tag exists, the same version was added before with a different hash.
763
+ // adding the current head into the parent will result in a non-exist hash in the parent.
764
+ // if this is a hash and it's the same hash as the current head, adding it as a parent
765
+ // results in a parent and a version has the same hash.
766
+ // @todo: fix it in a more elegant way
767
+ const parentToSet = setHeadAsParent ? head : parent;
768
+ version.addAsOnlyParent(parentToSet || head);
769
+ }
770
+ if (parent && head && !parent.isEqual(head) && !overrideHead) {
771
+ if (detachHead) this.detachedHeads.setHead(version.hash());else throw new Error(`unable to add a new version for "${this.id()}" on main.
772
+ this version started from an older version (${previouslyUsedVersion}), and not from the head (${head}).
773
+ please run "bit checkout head" to be up to date, then snap/tag your changes.
774
+ if this is done intentionally, you can use --detach-head (or --override-head if available), but make sure you understand the implications as this is an experimental feature that may not be fully stable.`);
775
+ } else {
776
+ this.setHead(version.hash());
777
+ this.detachedHeads.clearCurrent();
778
+ }
779
+ if ((0, _componentVersion().isTag)(versionToAdd)) {
780
+ this.setVersion(versionToAdd, version.hash());
781
+ }
782
+ this.markVersionAsLocal(versionToAdd);
783
+ return versionToAdd;
784
+ }
785
+ version(releaseType = _legacy().DEFAULT_BIT_RELEASE_TYPE, incrementBy = 1, preReleaseId) {
786
+ const increment = ver => {
787
+ try {
788
+ // don't use "semver.inc" function, it'll swallow the error and return null.
789
+ const incResult = new (semver().SemVer)(ver).inc(releaseType, preReleaseId);
790
+ return incResult.version;
791
+ } catch (err) {
792
+ throw new Error(`unable to increment version "${ver}" with releaseType "${releaseType}" and preReleaseId "${preReleaseId}".
793
+ Error from "semver": ${err.message}`);
794
+ }
795
+ };
796
+ const latest = this.latestVersion();
797
+ if (!latest) {
798
+ const isPreReleaseLike = ['prerelease', 'premajor', 'preminor', 'prepatch'].includes(releaseType);
799
+ return isPreReleaseLike ? increment(_legacy().DEFAULT_BIT_VERSION) : _legacy().DEFAULT_BIT_VERSION;
800
+ }
801
+ let result = increment(latest);
802
+ if (incrementBy === 1) return result;
803
+ for (let i = 1; i < incrementBy; i += 1) {
804
+ result = increment(result);
805
+ }
806
+ return result;
807
+ }
808
+ id() {
809
+ return this.scope ? [this.scope, this.name].join('/') : this.name;
810
+ }
811
+
812
+ /**
813
+ * @deprecated use toComponentId() instead
814
+ */
815
+ toBitId() {
816
+ return new (_legacyBitId().BitId)({
817
+ scope: this.scope,
818
+ name: this.name
819
+ });
820
+ }
821
+ toComponentId() {
822
+ if (!this.scope) throw new Error(`ModelComponent: scope is missing from "${this.name}"`);
823
+ return new (_componentId().ComponentID)(this.toBitId());
824
+ }
825
+
826
+ /**
827
+ * @deprecated use toComponentIdWithLatestVersion() instead
828
+ */
829
+ toBitIdWithLatestVersion() {
830
+ return new (_legacyBitId().BitId)({
831
+ scope: this.scope,
832
+ name: this.name,
833
+ version: this.getHeadRegardlessOfLaneAsTagOrHash(true)
834
+ });
835
+ }
836
+ toComponentIdWithLatestVersion() {
837
+ return _componentId().ComponentID.fromObject({
838
+ scope: this.scope,
839
+ name: this.name,
840
+ version: this.getHeadRegardlessOfLaneAsTagOrHash(true)
841
+ });
842
+ }
843
+ toComponentIdWithHead() {
844
+ return _componentId().ComponentID.fromObject({
845
+ scope: this.scope,
846
+ name: this.name,
847
+ version: this.head?.toString()
848
+ });
849
+ }
850
+ toBitIdWithLatestVersionAllowNull() {
851
+ const id = this.toComponentIdWithLatestVersion();
852
+ return id.version === VERSION_ZERO ? id.changeVersion(undefined) : id;
853
+ }
854
+ toObject() {
855
+ function versions(vers) {
856
+ const obj = {};
857
+ (0, _lodash().forEach)(vers, (ref, version) => {
858
+ obj[version] = ref.toString();
859
+ });
860
+ return obj;
861
+ }
862
+ const componentObject = {
863
+ name: this.name,
864
+ scope: this.scope,
865
+ versions: versions(this.versions),
866
+ lang: this.lang,
867
+ deprecated: this.deprecated,
868
+ bindingPrefix: this.bindingPrefix,
869
+ remotes: this.scopesList,
870
+ schema: this.schema,
871
+ detachedHeads: this.detachedHeads.toObject()
872
+ };
873
+ // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
874
+ if (this.local) componentObject.local = this.local;
875
+ // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
876
+ if (!(0, _lodash().isEmpty)(this.state)) componentObject.state = this.state;
877
+ // @ts-ignore
878
+ if (!(0, _lodash().isEmpty)(this.orphanedVersions)) componentObject.orphanedVersions = versions(this.orphanedVersions);
879
+ const headStr = this.getHeadStr();
880
+ // @ts-ignore
881
+ if (headStr) componentObject.head = headStr;
882
+ return componentObject;
883
+ }
884
+ async loadVersion(versionStr, repository, throws = true) {
885
+ const versionRef = this.getRef(versionStr);
886
+ if (!versionRef) throw new (_legacy6().VersionNotFound)(versionStr, this.id());
887
+ const version = await repository.load(versionRef, false);
888
+ if (!version && throws) throw new (_legacy6().VersionNotFoundOnFS)(versionStr, this.id());
889
+ return version;
890
+ }
891
+ loadVersionSync(version, repository, throws = true) {
892
+ const versionRef = this.getRef(version);
893
+ if (!versionRef) throw new (_legacy6().VersionNotFound)(version, this.id());
894
+ // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
895
+ return versionRef.loadSync(repository, throws);
896
+ }
897
+ async collectVersionsObjects(repo, versions, throwForMissingLocalArtifacts = false, workspaceId) {
898
+ const refsWithoutArtifacts = [];
899
+ const artifactsRefs = [];
900
+ const artifactsRefsFromExportedVersions = [];
901
+ const locallyChangedVersions = await this.getLocalTagsOrHashes(repo, workspaceId);
902
+ const locallyChangedHashes = locallyChangedVersions.map(v => (0, _componentVersion().isTag)(v) ? this.versionsIncludeOrphaned[v].hash : v);
903
+ const versionsRefs = versions.map(version => this.getRef(version));
904
+ refsWithoutArtifacts.push(...versionsRefs);
905
+ const versionsObjects = await Promise.all(versionsRefs.map(versionRef => this.loadVersion(versionRef.toString(), repo)));
906
+ versionsObjects.forEach(versionObject => {
907
+ const refs = versionObject.refsWithOptions(false, false);
908
+ refsWithoutArtifacts.push(...refs);
909
+ const refsFromExtensions = (0, _component().getRefsFromExtensions)(versionObject.extensions);
910
+ locallyChangedHashes.includes(versionObject.hash().toString()) ? artifactsRefs.push(...refsFromExtensions) : artifactsRefsFromExportedVersions.push(...refsFromExtensions);
911
+ });
912
+ const loadedRefs = [];
913
+ try {
914
+ const loaded = await repo.loadManyRaw(refsWithoutArtifacts);
915
+ loadedRefs.push(...loaded);
916
+ } catch (err) {
917
+ if (err.code === 'ENOENT') {
918
+ throw new Error(`unable to find an object file "${err.path}"
919
+ for a component "${this.id()}", versions: ${versions.join(', ')}`);
920
+ }
921
+ throw err;
922
+ }
923
+ try {
924
+ const loaded = throwForMissingLocalArtifacts ? await repo.loadManyRaw(artifactsRefs) : await repo.loadManyRawIgnoreMissing(artifactsRefs);
925
+ loadedRefs.push(...loaded);
926
+ // ignore missing artifacts when exporting old versions that were exported in the past and are now exported to a
927
+ // different scope. this is happening for example when exporting a lane that has components from different
928
+ // remotes. it's ok to not have all artifacts from the other remotes to this remote.
929
+ const loadedExportedArtifacts = await repo.loadManyRawIgnoreMissing(artifactsRefsFromExportedVersions);
930
+ loadedRefs.push(...loadedExportedArtifacts);
931
+ } catch (err) {
932
+ if (err.code === 'ENOENT') {
933
+ throw new Error(`unable to find an artifact object file "${err.path}"
934
+ for a component "${this.id()}", versions: ${versions.join(', ')}
935
+ consider using --ignore-missing-artifacts flag if you're sure the artifacts are in the remote`);
936
+ }
937
+ throw err;
938
+ }
939
+ return loadedRefs;
940
+ }
941
+ async collectObjects(repo) {
942
+ try {
943
+ const [rawComponent, objects] = await Promise.all([this.asRaw(repo), this.collectRaw(repo)]);
944
+ return new (_legacy6().ComponentObjects)(rawComponent, objects.map(o => o.buffer));
945
+ } catch (err) {
946
+ if (err.code === 'ENOENT') {
947
+ throw new Error(`fatal: an object of "${this.id()}" was not found at ${err.path}\nplease try to re-import the component`);
948
+ }
949
+ throw err;
950
+ }
951
+ }
952
+
953
+ /**
954
+ * to delete a version from a component, don't call this method directly. Instead, use sources.removeVersion()
955
+ */
956
+ removeVersion(version) {
957
+ const objectRef = this.getRef(version);
958
+ if (!objectRef) throw new Error(`removeVersion failed finding version ${version}`);
959
+ delete this.versions[version];
960
+ if (this.state.versions && this.state.versions[version]) delete this.state.versions[version];
961
+ return objectRef;
962
+ }
963
+ toComponentVersion(versionStr) {
964
+ const versionParsed = (0, _componentVersion().versionParser)(versionStr);
965
+ const versionNum = versionParsed.latest ? this.getHeadRegardlessOfLaneAsTagOrHash(true) : versionParsed.versionNum;
966
+ if (versionNum === VERSION_ZERO) {
967
+ throw new (_legacy6().NoHeadNoVersion)(this.id());
968
+ }
969
+ if ((0, _componentVersion().isTag)(versionNum) && !this.hasTagIncludeOrphaned(versionNum)) {
970
+ throw new (_bitError().BitError)(`the version ${versionNum} of "${this.id()}" does not exist in ${this.listVersionsIncludeOrphaned().join('\n')}, versions array.`);
971
+ }
972
+ return new (_legacy6().ComponentVersion)(this, versionNum);
973
+ }
974
+
975
+ /**
976
+ * if no "specificVersion" is given, it returns according to the head
977
+ */
978
+ async isDeprecated(repo, specificVersion) {
979
+ // backward compatibility
980
+ if (this.deprecated) {
981
+ return true;
982
+ }
983
+ const head = this.getHeadRegardlessOfLane();
984
+ if (!head) {
985
+ // it's legacy, or new. If legacy, the "deprecated" prop should do. if it's new, the workspace should
986
+ // have the answer.
987
+ return false;
988
+ }
989
+ const headVersion = await repo.load(head);
990
+ if (!headVersion) {
991
+ // the head Version doesn't exist locally, there is no way to know whether it's deprecated
992
+ return null;
993
+ }
994
+ const deprecationAspect = headVersion.extensions.findCoreExtension(_legacy().Extensions.deprecation);
995
+ if (!deprecationAspect) {
996
+ return false;
997
+ }
998
+ if (deprecationAspect.config.deprecate) {
999
+ return true;
1000
+ }
1001
+ if (specificVersion && deprecationAspect.config.range) {
1002
+ const tag = this.getTag(specificVersion);
1003
+ if (!tag) return false; // it's a snap. "range" doesn't support deprecating snaps. only semver.
1004
+ return semver().satisfies(tag, deprecationAspect.config.range);
1005
+ }
1006
+ return false;
1007
+ }
1008
+ async isRemoved(repo, specificVersion) {
1009
+ const getHead = () => {
1010
+ if (!this.laneHeadLocal) return this.getHead();
1011
+ // you're checked out to a lane.
1012
+ if (!specificVersion) return this.laneHeadLocal;
1013
+ // it's possible that this specificVersion is from main.
1014
+ if (specificVersion === this.laneHeadLocal.toString()) return this.laneHeadLocal;
1015
+ return this.getHead();
1016
+ };
1017
+ const head = getHead();
1018
+ if (!head) {
1019
+ // it's new or only on lane
1020
+ return false;
1021
+ }
1022
+ const headVersion = await repo.load(head);
1023
+ if (!headVersion) {
1024
+ // the head Version doesn't exist locally, there is no way to know whether it's removed
1025
+ return null;
1026
+ }
1027
+ const removeAspect = headVersion.extensions.findCoreExtension(_legacy().Extensions.remove);
1028
+ if (!removeAspect) {
1029
+ return false;
1030
+ }
1031
+ if (removeAspect.config.removed) {
1032
+ return true;
1033
+ }
1034
+ if (specificVersion) {
1035
+ if (removeAspect.config.range) {
1036
+ const tag = this.getTag(specificVersion);
1037
+ if (tag) return semver().satisfies(tag, removeAspect.config.range);
1038
+ }
1039
+ if (removeAspect.config.snaps && Array.isArray(removeAspect.config.snaps)) {
1040
+ return removeAspect.config.snaps.includes(specificVersion);
1041
+ }
1042
+ }
1043
+ return false;
1044
+ }
1045
+ async isLaneReadmeOf(repo) {
1046
+ const head = this.getHeadRegardlessOfLane();
1047
+ if (!head) {
1048
+ // we dont support lanes in legacy
1049
+ return [];
1050
+ }
1051
+ const version = await repo.load(head);
1052
+ if (!version) {
1053
+ // the head Version doesn't exist locally, there is no way to know whether it is a lane readme component
1054
+ return [];
1055
+ }
1056
+ const lanesAspect = version.extensions.findCoreExtension(_legacy().Extensions.lanes);
1057
+ if (!lanesAspect || !lanesAspect.config.readme) {
1058
+ return [];
1059
+ }
1060
+ return Object.keys(lanesAspect.config.readme);
1061
+ }
1062
+ /**
1063
+ * convert a ModelComponent of a specific version to ConsumerComponent
1064
+ * @see sources.consumerComponentToVersion() for the opposite action.
1065
+ */
1066
+ async toConsumerComponent(versionStr, scopeName, repository) {
1067
+ _legacy4().logger.trace(`model-component, converting ${this.id()}, version: ${versionStr} to ConsumerComponent`);
1068
+ let componentVersion = this.toComponentVersion(versionStr);
1069
+ const version = await componentVersion.getVersion(repository);
1070
+ // in case the the version is a short-hash, it should be converted to a full hash.
1071
+ if (versionStr !== _componentVersion().LATEST_VERSION && !(0, _componentVersion().isTag)(versionStr) && !(0, _componentVersion().isSnap)(versionStr) && version.hash().toString() !== versionStr) {
1072
+ componentVersion = new (_legacy6().ComponentVersion)(this, version.hash().toString());
1073
+ }
1074
+ const loadFileInstance = ClassName => async file => {
1075
+ const loadP = file.file.load(repository);
1076
+ const content = await loadP;
1077
+ if (!content) throw new (_bitError().BitError)(`failed loading file ${file.relativePath} from the model of ${this.id()}@${versionStr}`);
1078
+ return new ClassName({
1079
+ base: '.',
1080
+ path: file.relativePath,
1081
+ contents: content.contents,
1082
+ test: file.test
1083
+ });
1084
+ };
1085
+ const filesP = version.files ? Promise.all(version.files.map(loadFileInstance(_component().SourceFile))) : null;
1086
+ // @todo: this is weird. why the scopeMeta would be taken from the current scope and not he component scope?
1087
+ const scopeMetaP = scopeName ? _scopeMeta().default.fromScopeName(scopeName).load(repository) : Promise.resolve();
1088
+ const log = version.log || null;
1089
+ const [files, scopeMeta] = await Promise.all([filesP, scopeMetaP]);
1090
+ const extensions = version.extensions.clone();
1091
+ // when generating a new ConsumerComponent out of Version, it is critical to make sure that
1092
+ // all objects are cloned and not copied by reference. Otherwise, every time the
1093
+ // ConsumerComponent instance is changed, the Version will be changed as well, and since
1094
+ // the Version instance is saved in the Repository._cache, the next time a Version instance
1095
+ // is retrieved, it'll be different than the first time.
1096
+ const consumerComponent = new (_legacy2().ConsumerComponent)({
1097
+ name: this.name,
1098
+ version: componentVersion.version,
1099
+ scope: this.toComponentId()._legacy.scope,
1100
+ defaultScope: this.scope,
1101
+ lang: this.lang,
1102
+ bindingPrefix: this.bindingPrefix,
1103
+ mainFile: version.mainFile,
1104
+ dependencies: this.addDepsInfoFromDepsResolver(version.dependencies, extensions),
1105
+ devDependencies: this.addDepsInfoFromDepsResolver(version.devDependencies, extensions),
1106
+ flattenedDependencies: version.flattenedDependencies.clone(),
1107
+ packageDependencies: (0, _lodash().clone)(version.packageDependencies),
1108
+ devPackageDependencies: (0, _lodash().clone)(version.devPackageDependencies),
1109
+ peerPackageDependencies: (0, _lodash().clone)(version.peerPackageDependencies),
1110
+ // @ts-ignore
1111
+ files,
1112
+ docs: version.docs,
1113
+ // @ts-ignore
1114
+ license: scopeMeta ? _component().License.deserialize(scopeMeta.license) : undefined,
1115
+ // todo: make sure we have license in case of local scope
1116
+ log,
1117
+ overrides: _legacy3().ComponentOverrides.loadFromScope(version.overrides),
1118
+ packageJsonChangedProps: (0, _lodash().clone)(version.packageJsonChangedProps),
1119
+ deprecated: this.deprecated,
1120
+ removed: version.isRemoved(),
1121
+ scopesList: (0, _lodash().clone)(this.scopesList),
1122
+ schema: version.schema,
1123
+ extensions,
1124
+ buildStatus: version.buildStatus
1125
+ });
1126
+ return consumerComponent;
1127
+ }
1128
+ addDepsInfoFromDepsResolver(dependencies, extensions) {
1129
+ const cloned = dependencies.getClone();
1130
+ const depsResolverData = extensions.find(ext => ext.name === 'teambit.dependencies/dependency-resolver');
1131
+ if (!depsResolverData) return cloned;
1132
+ cloned.forEach(dependency => {
1133
+ if (dependency.packageName) return;
1134
+ const matchedEntry = depsResolverData.data?.dependencies?.find(entry => {
1135
+ return dependency.id.toString() === entry.id;
1136
+ });
1137
+ if (matchedEntry) {
1138
+ dependency.packageName = matchedEntry.packageName;
1139
+ }
1140
+ });
1141
+ return cloned;
1142
+ }
1143
+
1144
+ // @todo: make sure it doesn't have the same ref twice, once as a version and once as a head
1145
+ refs() {
1146
+ const versions = Object.values(this.versionsIncludeOrphaned);
1147
+ if (this.head) versions.push(this.head);
1148
+ return versions;
1149
+ }
1150
+ validateBeforePersisting(componentStr) {
1151
+ _legacy4().logger.trace(`validating component object: ${this.hash().hash} ${this.id()}`);
1152
+ const component = Component.parse(componentStr);
1153
+ component.validate();
1154
+ }
1155
+ toBuffer(pretty) {
1156
+ const args = (0, _legacy5().getStringifyArgs)(pretty);
1157
+ const obj = this.toObject();
1158
+ const str = JSON.stringify(obj, ...args);
1159
+ if (this.validateBeforePersist) this.validateBeforePersisting(str);
1160
+ return Buffer.from(str);
1161
+ }
1162
+
1163
+ /**
1164
+ * Clear data that is relevant only for the local scope and should not be moved to the remote scope
1165
+ */
1166
+ clearStateData() {
1167
+ this.local = false; // backward compatibility for components created before 0.12.6
1168
+ this.state = {};
1169
+ }
1170
+ markVersionAsLocal(version) {
1171
+ if (!this.state.versions) this.state = {
1172
+ versions: {}
1173
+ };
1174
+ // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
1175
+ if (!this.state.versions[version]) this.state.versions[version] = {};
1176
+ // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
1177
+ this.state.versions[version].local = true;
1178
+ }
1179
+
1180
+ /**
1181
+ * local versions that are not exported on the main lane.
1182
+ * @see `this.getLocalTagsOrHashes()`, to get local snaps on the current lane
1183
+ */
1184
+ getLocalVersions() {
1185
+ if ((0, _lodash().isEmpty)(this.state) || (0, _lodash().isEmpty)(this.state.versions)) return [];
1186
+ // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
1187
+ return Object.keys(this.state.versions).filter(version => this.state.versions[version].local);
1188
+ }
1189
+ hasLocalTag(tag) {
1190
+ const localVersions = this.getLocalVersions();
1191
+ return localVersions.includes(tag);
1192
+ }
1193
+ async getLocalTagsOrHashes(repo, workspaceId) {
1194
+ const localHashes = await this.getLocalHashes(repo, workspaceId);
1195
+ if (!localHashes.length) return [];
1196
+ return this.switchHashesWithTagsIfExist(localHashes).reverse(); // reverse to get the older first
1197
+ }
1198
+ async getLocalHashes(repo, workspaceId) {
1199
+ await this.setDivergeData(repo, undefined, undefined, workspaceId);
1200
+ const divergeData = this.getDivergeData();
1201
+ const localHashes = divergeData.snapsOnSourceOnly;
1202
+
1203
+ // When there's a detached head, divergeData only includes the detached head lineage.
1204
+ // We also need to include unexported versions from the main head lineage.
1205
+ const hasDetachedHead = this.detachedHeads && this.detachedHeads.getAllHeads().length > 0;
1206
+ if (hasDetachedHead && this.head) {
1207
+ // Calculate divergence from the main head as well
1208
+ const mainHeadDivergeData = await (0, _component2().getDivergeData)({
1209
+ repo,
1210
+ modelComponent: this,
1211
+ targetHead: (this.laneId ? this.calculatedRemoteHeadWhenOnLane : this.remoteHead) || null,
1212
+ sourceHead: this.head,
1213
+ throws: false
1214
+ });
1215
+ // Add main head local versions that aren't already in localHashes
1216
+ for (const hash of mainHeadDivergeData.snapsOnSourceOnly) {
1217
+ if (!localHashes.find(h => h.isEqual(hash))) {
1218
+ localHashes.push(hash);
1219
+ }
1220
+ }
1221
+ }
1222
+ if (!localHashes.length) return [];
1223
+ return localHashes.reverse(); // reverse to get the older first
1224
+ }
1225
+
1226
+ /**
1227
+ * for most cases, use `isLocallyChanged`, which takes into account lanes.
1228
+ * this is for cases when we only care about the versions exist in the `state` prop.
1229
+ */
1230
+ isLocallyChangedRegardlessOfLanes() {
1231
+ return Boolean(this.getLocalVersions().length);
1232
+ }
1233
+
1234
+ /**
1235
+ * whether the component was locally changed, either by adding a new snap/tag or by merging
1236
+ * components from different lanes.
1237
+ */
1238
+ async isLocallyChanged(repo, lane, workspaceId) {
1239
+ if (lane) await this.populateLocalAndRemoteHeads(repo, lane);
1240
+ await this.setDivergeData(repo, undefined, undefined, workspaceId);
1241
+ const divergeData = this.getDivergeData();
1242
+ return divergeData.isSourceAhead();
1243
+ }
1244
+ async getVersionHistory(repo) {
1245
+ const emptyVersionHistory = _versionHistory().default.fromId(this.name, this.scope);
1246
+ const versionHistory = await repo.load(emptyVersionHistory.hash());
1247
+ return versionHistory || emptyVersionHistory;
1248
+ }
1249
+ async getAndPopulateVersionHistory(repo, head) {
1250
+ const versionHistory = await this.getVersionHistory(repo);
1251
+ const {
1252
+ err
1253
+ } = await this.populateVersionHistoryIfMissingGracefully(repo, versionHistory, head);
1254
+ if (err) {
1255
+ _legacy4().logger.error(`rethrowing an error ${err.message}, current stuck`, new Error(err.message));
1256
+ throw err;
1257
+ }
1258
+ return versionHistory;
1259
+ }
1260
+
1261
+ /**
1262
+ * careful! the `versions` passed here can belong to other components, not necessarily to this one.
1263
+ * that's why it checks whether the version-hash exists in the VersionHistory, and if it's not,
1264
+ * it won't update it.
1265
+ */
1266
+ async updateRebasedVersionHistory(repo, versions) {
1267
+ const versionHistory = await this.getVersionHistory(repo);
1268
+ const hasUpdated = versions.some(version => {
1269
+ const versionData = versionHistory.getVersionData(version.hash());
1270
+ if (!versionData) return false;
1271
+ versionHistory.addFromVersionsObjects([version]);
1272
+ return true;
1273
+ });
1274
+ return hasUpdated ? versionHistory : undefined;
1275
+ }
1276
+ async updateVersionHistory(repo, versions) {
1277
+ const versionHistory = await this.getVersionHistory(repo);
1278
+ versionHistory.addFromVersionsObjects(versions);
1279
+ _legacy4().logger.debug(`updating version history of ${this.id()} with ${versions.length} versions`);
1280
+ return versionHistory;
1281
+ }
1282
+ async populateVersionHistoryIfMissingGracefully(repo, versionHistory, head,
1283
+ /**
1284
+ * during traversal, if a hash is found in the VersionHistory it probably means that it has all history until this
1285
+ * point, so we can stop there for better performance. In some rare cases (e.g. the export was interrupted), we
1286
+ * need the ability of full traversal to repair the VersionHistory.
1287
+ */
1288
+ exitWhenFind = true) {
1289
+ const headExists = versionHistory.hasHash(head);
1290
+ if (exitWhenFind && headExists) return {};
1291
+ const getVersionObj = async ref => await ref.load(repo);
1292
+ const versionsToAdd = [];
1293
+ let err;
1294
+ const addParentsRecursively = async version => {
1295
+ await (0, _pMapSeries().default)(version.parents, async parent => {
1296
+ const foundParent = versionHistory.hasHash(parent) || versionsToAdd.find(v => v.hash().isEqual(parent));
1297
+ if (exitWhenFind && foundParent) {
1298
+ return;
1299
+ }
1300
+ const parentVersion = await getVersionObj(parent);
1301
+ if (!parentVersion) {
1302
+ const tag = this.getTagOfRefIfExists(parent);
1303
+ err = tag ? new (_legacy6().VersionNotFound)(tag, this.id()) : new (_legacy6().ParentNotFound)(this.id(), version.hash().toString(), parent.toString());
1304
+ return;
1305
+ }
1306
+ versionsToAdd.push(parentVersion);
1307
+ await addParentsRecursively(parentVersion);
1308
+ });
1309
+ };
1310
+ const headVer = await getVersionObj(head);
1311
+ if (!headVer) {
1312
+ return {
1313
+ err: new (_legacy6().HeadNotFound)(this.id(), head.toString())
1314
+ };
1315
+ }
1316
+ return this.populateVersionHistoryMutex.runExclusive(async () => {
1317
+ if (!headExists) versionsToAdd.push(headVer);
1318
+ await addParentsRecursively(headVer);
1319
+ const added = versionsToAdd.map(v => (0, _component2().getVersionParentsFromVersion)(v));
1320
+ if (err) {
1321
+ return {
1322
+ err,
1323
+ added
1324
+ };
1325
+ }
1326
+ versionHistory.addFromVersionsObjects(versionsToAdd);
1327
+ _legacy4().logger.debug(`populateVersionHistoryIfMissingGracefully, updating ${this.id()} with ${versionsToAdd.length} versions`);
1328
+ await repo.writeObjectsToTheFS([versionHistory]);
1329
+ return {
1330
+ added
1331
+ };
1332
+ });
1333
+ }
1334
+ static parse(contents) {
1335
+ const rawComponent = JSON.parse(contents);
1336
+ return Component.from({
1337
+ name: rawComponent.box ? `${rawComponent.box}/${rawComponent.name}` : rawComponent.name,
1338
+ scope: rawComponent.scope,
1339
+ versions: (0, _lodash().mapValues)(rawComponent.versions, val => _objects().Ref.from(val)),
1340
+ lang: rawComponent.lang,
1341
+ deprecated: rawComponent.deprecated,
1342
+ bindingPrefix: rawComponent.bindingPrefix,
1343
+ state: rawComponent.state,
1344
+ orphanedVersions: (0, _lodash().mapValues)(rawComponent.orphanedVersions || {}, val => _objects().Ref.from(val)),
1345
+ scopesList: rawComponent.remotes,
1346
+ head: rawComponent.head ? _objects().Ref.from(rawComponent.head) : undefined,
1347
+ schema: rawComponent.schema || (rawComponent.head ? _legacy2().SchemaName.Harmony : _legacy2().SchemaName.Legacy),
1348
+ detachedHeads: _detachHeads().DetachedHeads.fromObject(rawComponent.detachedHeads)
1349
+ });
1350
+ }
1351
+ static from(props) {
1352
+ return new Component(props);
1353
+ }
1354
+ static fromBitId(bitId) {
1355
+ // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
1356
+ return new Component({
1357
+ name: bitId.fullName,
1358
+ scope: bitId.scope
1359
+ });
1360
+ }
1361
+ get isLegacy() {
1362
+ return !this.schema || this.schema === _legacy2().SchemaName.Legacy;
1363
+ }
1364
+ validate() {
1365
+ const message = `unable to save Component object "${this.id()}"`;
1366
+ if (!this.name) throw new (_bitError().BitError)(`${message} the name is missing`);
1367
+ if (this.state && this.state.versions) {
1368
+ Object.keys(this.state.versions).forEach(version => {
1369
+ if ((0, _componentVersion().isTag)(version) && !this.hasTag(version)) {
1370
+ throw new (_legacyCli().ValidationError)(`${message}, the version ${version} is marked as staged but is not available`);
1371
+ }
1372
+ });
1373
+ }
1374
+ const hashDuplications = (0, _toolboxArray().findDuplications)(this.versionArray.map(v => v.toString()));
1375
+ if (hashDuplications.length) {
1376
+ throw new (_legacyCli().ValidationError)(`${message}, the following hash(es) are duplicated ${hashDuplications.join(', ')}`);
1377
+ }
1378
+ Object.keys(this.orphanedVersions).forEach(version => {
1379
+ if (this.versions[version]) {
1380
+ throw new (_legacyCli().ValidationError)(`${message}, the version "${version}" exists in orphanedVersions but it exits also in "versions" prop`);
1381
+ }
1382
+ });
1383
+ if (!this.isLegacy && !this.head && this.versionArray.length) {
1384
+ // legacy don't have head. also, when snapping on a lane the first time, there is no head.
1385
+ // tags are done on default lane only, so if there are versions (tag), it must have head
1386
+ throw new (_legacyCli().ValidationError)(`${message}, the "head" prop is missing`);
1387
+ }
1388
+ }
1389
+ }
1390
+ exports.default = Component;
1391
+
1392
+ //# sourceMappingURL=model-component.js.map