@teambit/snapping 1.0.516 → 1.0.518
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +2 -2
- package/dist/index.js +11 -11
- package/dist/index.js.map +1 -1
- package/dist/snap-cmd.d.ts +1 -1
- package/dist/snap-cmd.js.map +1 -1
- package/dist/snap-from-scope.cmd.d.ts +1 -1
- package/dist/snap-from-scope.cmd.js.map +1 -1
- package/dist/snapping.main.runtime.d.ts +1 -1
- package/dist/snapping.main.runtime.js +29 -40
- package/dist/snapping.main.runtime.js.map +1 -1
- package/dist/tag-cmd.d.ts +1 -1
- package/dist/tag-cmd.js.map +1 -1
- package/dist/tag-model-component.d.ts +6 -35
- package/dist/tag-model-component.js +17 -625
- package/dist/tag-model-component.js.map +1 -1
- package/dist/version-maker.d.ts +96 -0
- package/dist/version-maker.js +685 -0
- package/dist/version-maker.js.map +1 -0
- package/package.json +21 -21
- package/artifacts/__bit_junit.xml +0 -20
- package/artifacts/preview/teambit_component_snapping-preview.js +0 -1
- package/artifacts/schema.json +0 -17716
- /package/dist/{preview-1736997622391.js → preview-1737170420676.js} +0 -0
|
@@ -0,0 +1,685 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.VersionMaker = void 0;
|
|
7
|
+
exports.updateVersions = updateVersions;
|
|
8
|
+
function _pMapSeries() {
|
|
9
|
+
const data = _interopRequireDefault(require("p-map-series"));
|
|
10
|
+
_pMapSeries = function () {
|
|
11
|
+
return data;
|
|
12
|
+
};
|
|
13
|
+
return data;
|
|
14
|
+
}
|
|
15
|
+
function _lodash() {
|
|
16
|
+
const data = require("lodash");
|
|
17
|
+
_lodash = function () {
|
|
18
|
+
return data;
|
|
19
|
+
};
|
|
20
|
+
return data;
|
|
21
|
+
}
|
|
22
|
+
function _uuid() {
|
|
23
|
+
const data = require("uuid");
|
|
24
|
+
_uuid = function () {
|
|
25
|
+
return data;
|
|
26
|
+
};
|
|
27
|
+
return data;
|
|
28
|
+
}
|
|
29
|
+
function _bitError() {
|
|
30
|
+
const data = require("@teambit/bit-error");
|
|
31
|
+
_bitError = function () {
|
|
32
|
+
return data;
|
|
33
|
+
};
|
|
34
|
+
return data;
|
|
35
|
+
}
|
|
36
|
+
function _componentId() {
|
|
37
|
+
const data = require("@teambit/component-id");
|
|
38
|
+
_componentId = function () {
|
|
39
|
+
return data;
|
|
40
|
+
};
|
|
41
|
+
return data;
|
|
42
|
+
}
|
|
43
|
+
function _legacy() {
|
|
44
|
+
const data = require("@teambit/legacy.constants");
|
|
45
|
+
_legacy = function () {
|
|
46
|
+
return data;
|
|
47
|
+
};
|
|
48
|
+
return data;
|
|
49
|
+
}
|
|
50
|
+
function _legacy2() {
|
|
51
|
+
const data = require("@teambit/legacy.consumer-component");
|
|
52
|
+
_legacy2 = function () {
|
|
53
|
+
return data;
|
|
54
|
+
};
|
|
55
|
+
return data;
|
|
56
|
+
}
|
|
57
|
+
function _workspaceModules() {
|
|
58
|
+
const data = require("@teambit/workspace.modules.node-modules-linker");
|
|
59
|
+
_workspaceModules = function () {
|
|
60
|
+
return data;
|
|
61
|
+
};
|
|
62
|
+
return data;
|
|
63
|
+
}
|
|
64
|
+
function _legacy3() {
|
|
65
|
+
const data = require("@teambit/legacy.consumer");
|
|
66
|
+
_legacy3 = function () {
|
|
67
|
+
return data;
|
|
68
|
+
};
|
|
69
|
+
return data;
|
|
70
|
+
}
|
|
71
|
+
function _remove() {
|
|
72
|
+
const data = require("@teambit/remove");
|
|
73
|
+
_remove = function () {
|
|
74
|
+
return data;
|
|
75
|
+
};
|
|
76
|
+
return data;
|
|
77
|
+
}
|
|
78
|
+
function _pkgModules() {
|
|
79
|
+
const data = require("@teambit/pkg.modules.semver-helper");
|
|
80
|
+
_pkgModules = function () {
|
|
81
|
+
return data;
|
|
82
|
+
};
|
|
83
|
+
return data;
|
|
84
|
+
}
|
|
85
|
+
function _harmonyModules() {
|
|
86
|
+
const data = require("@teambit/harmony.modules.get-basic-log");
|
|
87
|
+
_harmonyModules = function () {
|
|
88
|
+
return data;
|
|
89
|
+
};
|
|
90
|
+
return data;
|
|
91
|
+
}
|
|
92
|
+
function _toolboxCrypto() {
|
|
93
|
+
const data = require("@teambit/toolbox.crypto.sha1");
|
|
94
|
+
_toolboxCrypto = function () {
|
|
95
|
+
return data;
|
|
96
|
+
};
|
|
97
|
+
return data;
|
|
98
|
+
}
|
|
99
|
+
function _objects() {
|
|
100
|
+
const data = require("@teambit/objects");
|
|
101
|
+
_objects = function () {
|
|
102
|
+
return data;
|
|
103
|
+
};
|
|
104
|
+
return data;
|
|
105
|
+
}
|
|
106
|
+
function _messagePerComponent() {
|
|
107
|
+
const data = require("./message-per-component");
|
|
108
|
+
_messagePerComponent = function () {
|
|
109
|
+
return data;
|
|
110
|
+
};
|
|
111
|
+
return data;
|
|
112
|
+
}
|
|
113
|
+
function _toolboxPromise() {
|
|
114
|
+
const data = require("@teambit/toolbox.promise.map-pool");
|
|
115
|
+
_toolboxPromise = function () {
|
|
116
|
+
return data;
|
|
117
|
+
};
|
|
118
|
+
return data;
|
|
119
|
+
}
|
|
120
|
+
function _harmonyModules2() {
|
|
121
|
+
const data = require("@teambit/harmony.modules.feature-toggle");
|
|
122
|
+
_harmonyModules2 = function () {
|
|
123
|
+
return data;
|
|
124
|
+
};
|
|
125
|
+
return data;
|
|
126
|
+
}
|
|
127
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
128
|
+
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; }
|
|
129
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
130
|
+
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); }
|
|
131
|
+
/**
|
|
132
|
+
* create a tag or a snap of the given components and save them in the local scope.
|
|
133
|
+
*/
|
|
134
|
+
class VersionMaker {
|
|
135
|
+
constructor(snapping, components, consumerComponents, ids, params) {
|
|
136
|
+
this.snapping = snapping;
|
|
137
|
+
this.components = components;
|
|
138
|
+
this.consumerComponents = consumerComponents;
|
|
139
|
+
this.ids = ids;
|
|
140
|
+
this.params = params;
|
|
141
|
+
_defineProperty(this, "workspace", void 0);
|
|
142
|
+
_defineProperty(this, "consumer", void 0);
|
|
143
|
+
_defineProperty(this, "legacyScope", void 0);
|
|
144
|
+
_defineProperty(this, "scope", void 0);
|
|
145
|
+
_defineProperty(this, "builder", void 0);
|
|
146
|
+
_defineProperty(this, "dependencyResolver", void 0);
|
|
147
|
+
_defineProperty(this, "allComponentsToTag", []);
|
|
148
|
+
this.workspace = snapping.workspace;
|
|
149
|
+
this.scope = snapping.scope;
|
|
150
|
+
this.builder = snapping.builder;
|
|
151
|
+
this.dependencyResolver = snapping.dependencyResolver;
|
|
152
|
+
this.consumer = this.workspace?.consumer;
|
|
153
|
+
this.legacyScope = this.scope.legacyScope;
|
|
154
|
+
}
|
|
155
|
+
async makeVersion() {
|
|
156
|
+
const componentsToTag = this.getUniqCompsToTag();
|
|
157
|
+
const idsToTag = _componentId().ComponentIdList.fromArray(componentsToTag.map(c => c.id));
|
|
158
|
+
const autoTagData = await this.getAutoTagData(idsToTag);
|
|
159
|
+
const autoTagComponents = autoTagData.map(autoTagItem => autoTagItem.component);
|
|
160
|
+
const autoTagComponentsFiltered = autoTagComponents.filter(c => !idsToTag.has(c.id));
|
|
161
|
+
const autoTagIds = _componentId().ComponentIdList.fromArray(autoTagComponentsFiltered.map(autoTag => autoTag.id));
|
|
162
|
+
this.allComponentsToTag = [...componentsToTag, ...autoTagComponentsFiltered];
|
|
163
|
+
const messagePerId = await this.getMessagePerId(idsToTag, autoTagIds);
|
|
164
|
+
await this.checkForNewerVersions();
|
|
165
|
+
this.setCurrentSchema();
|
|
166
|
+
// go through all components and find the future versions for them
|
|
167
|
+
this.params.isSnap ? this.setHashes() : await this.setFutureVersions(autoTagIds);
|
|
168
|
+
// go through all dependencies and update their versions
|
|
169
|
+
this.updateDependenciesVersions();
|
|
170
|
+
await this.addLogToComponents(componentsToTag, autoTagComponents, messagePerId);
|
|
171
|
+
// don't move it down. otherwise, it'll be empty and we don't know which components were during merge.
|
|
172
|
+
// (it's being deleted in snapping.main.runtime - `_addCompToObjects` method)
|
|
173
|
+
const unmergedComps = (await this.workspace?.listComponentsDuringMerge()) || [];
|
|
174
|
+
const lane = await this.legacyScope.getCurrentLaneObject();
|
|
175
|
+
const stagedConfig = (await this.workspace?.scope.getStagedConfig()) || undefined;
|
|
176
|
+
if (this.params.soft) {
|
|
177
|
+
if (!this.consumer) throw new Error(`unable to soft-tag without consumer`);
|
|
178
|
+
this.consumer.updateNextVersionOnBitmap(this.allComponentsToTag, this.params.preReleaseId);
|
|
179
|
+
return {
|
|
180
|
+
taggedComponents: componentsToTag,
|
|
181
|
+
autoTaggedResults: autoTagData,
|
|
182
|
+
publishedPackages: [],
|
|
183
|
+
stagedConfig
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
const {
|
|
187
|
+
rebuildDepsGraph,
|
|
188
|
+
build,
|
|
189
|
+
updateDependentsOnLane,
|
|
190
|
+
setHeadAsParent,
|
|
191
|
+
detachHead,
|
|
192
|
+
overrideHead
|
|
193
|
+
} = this.params;
|
|
194
|
+
await this.snapping._addFlattenedDependenciesToComponents(this.allComponentsToTag, rebuildDepsGraph);
|
|
195
|
+
await this.snapping._addDependenciesGraphToComponents(this.components);
|
|
196
|
+
await this.snapping.throwForDepsFromAnotherLane(this.allComponentsToTag);
|
|
197
|
+
if (!build) this.emptyBuilderData();
|
|
198
|
+
this.addBuildStatus(this.allComponentsToTag, _legacy().BuildStatus.Pending);
|
|
199
|
+
const currentLane = this.consumer?.getCurrentLaneId();
|
|
200
|
+
await (0, _pMapSeries().default)(this.allComponentsToTag, async component => {
|
|
201
|
+
const results = await this.snapping._addCompToObjects({
|
|
202
|
+
source: component,
|
|
203
|
+
lane,
|
|
204
|
+
shouldValidateVersion: Boolean(build),
|
|
205
|
+
addVersionOpts: {
|
|
206
|
+
addToUpdateDependentsInLane: updateDependentsOnLane,
|
|
207
|
+
setHeadAsParent,
|
|
208
|
+
detachHead,
|
|
209
|
+
overrideHead: overrideHead
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
if (this.workspace) {
|
|
213
|
+
const modelComponent = component.modelComponent || (await this.legacyScope.getModelComponent(component.id));
|
|
214
|
+
await updateVersions(this.workspace, stagedConfig, currentLane, modelComponent, results.addedVersionStr, true);
|
|
215
|
+
} else {
|
|
216
|
+
const tagData = this.params.tagDataPerComp?.find(t => t.componentId.isEqualWithoutVersion(component.id));
|
|
217
|
+
if (tagData?.isNew) results.version.removeAllParents();
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
if (this.workspace) {
|
|
221
|
+
await this.workspace.scope.legacyScope.stagedSnaps.write();
|
|
222
|
+
}
|
|
223
|
+
const publishedPackages = [];
|
|
224
|
+
const harmonyCompsToTag = await (this.workspace || this.scope).getManyByLegacy(this.allComponentsToTag);
|
|
225
|
+
// this is not necessarily the same as the previous allComponentsToTag. although it should be, because
|
|
226
|
+
// harmonyCompsToTag is created from allComponentsToTag. however, for aspects, the getMany returns them from cache
|
|
227
|
+
// and therefore, their instance of ConsumerComponent can be different than the one in allComponentsToTag.
|
|
228
|
+
this.allComponentsToTag = harmonyCompsToTag.map(c => c.state._consumer);
|
|
229
|
+
await this.build(harmonyCompsToTag, publishedPackages);
|
|
230
|
+
const removedComponents = await removeDeletedComponentsFromBitmap(this.allComponentsToTag, this.workspace);
|
|
231
|
+
await this.addLaneObject(lane);
|
|
232
|
+
await this.legacyScope.objects.persist();
|
|
233
|
+
await removeMergeConfigFromComponents(unmergedComps, this.allComponentsToTag, this.workspace);
|
|
234
|
+
if (this.workspace) {
|
|
235
|
+
await (0, _workspaceModules().linkToNodeModulesByComponents)(harmonyCompsToTag, this.workspace);
|
|
236
|
+
}
|
|
237
|
+
// clear all objects. otherwise, ModelComponent has the wrong divergeData
|
|
238
|
+
this.legacyScope.objects.clearObjectsFromCache();
|
|
239
|
+
return {
|
|
240
|
+
taggedComponents: componentsToTag,
|
|
241
|
+
autoTaggedResults: autoTagData,
|
|
242
|
+
publishedPackages,
|
|
243
|
+
stagedConfig,
|
|
244
|
+
removedComponents
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
async addLaneObject(lane) {
|
|
248
|
+
if (lane) {
|
|
249
|
+
const {
|
|
250
|
+
message
|
|
251
|
+
} = this.params;
|
|
252
|
+
const msgStr = message ? ` (${message})` : '';
|
|
253
|
+
const laneHistory = await this.legacyScope.lanes.updateLaneHistory(lane, `snap${msgStr}`);
|
|
254
|
+
this.legacyScope.objects.add(laneHistory);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
async build(harmonyCompsToTag, publishedPackages) {
|
|
258
|
+
if (!this.params.build) {
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
const {
|
|
262
|
+
disableTagAndSnapPipelines,
|
|
263
|
+
ignoreBuildErrors,
|
|
264
|
+
isSnap,
|
|
265
|
+
populateArtifactsFrom,
|
|
266
|
+
skipTasks,
|
|
267
|
+
packageManagerConfigRootDir,
|
|
268
|
+
exitOnFirstFailedTask,
|
|
269
|
+
populateArtifactsIgnorePkgJson,
|
|
270
|
+
skipTests
|
|
271
|
+
} = this.params;
|
|
272
|
+
const onTagOpts = {
|
|
273
|
+
disableTagAndSnapPipelines,
|
|
274
|
+
throwOnError: true,
|
|
275
|
+
forceDeploy: ignoreBuildErrors,
|
|
276
|
+
isSnap,
|
|
277
|
+
populateArtifactsFrom
|
|
278
|
+
};
|
|
279
|
+
const skipTasksParsed = skipTasks ? skipTasks.split(',').map(t => t.trim()) : undefined;
|
|
280
|
+
const seedersOnly = !this.workspace; // if tag from scope, build only the given components
|
|
281
|
+
const isolateOptions = {
|
|
282
|
+
packageManagerConfigRootDir,
|
|
283
|
+
seedersOnly,
|
|
284
|
+
populateArtifactsIgnorePkgJson
|
|
285
|
+
};
|
|
286
|
+
const builderOptions = {
|
|
287
|
+
exitOnFirstFailedTask,
|
|
288
|
+
skipTests,
|
|
289
|
+
skipTasks: skipTasksParsed
|
|
290
|
+
};
|
|
291
|
+
const componentsToBuild = harmonyCompsToTag.filter(c => !c.isDeleted());
|
|
292
|
+
if (componentsToBuild.length) {
|
|
293
|
+
const componentsToBuildLegacy = componentsToBuild.map(c => c.state._consumer);
|
|
294
|
+
await this.scope.reloadAspectsWithNewVersion(componentsToBuildLegacy);
|
|
295
|
+
const {
|
|
296
|
+
builderDataMap
|
|
297
|
+
} = await this.builder.tagListener(componentsToBuild, onTagOpts, isolateOptions, builderOptions);
|
|
298
|
+
const buildResult = this.scope.builderDataMapToLegacyOnTagResults(builderDataMap);
|
|
299
|
+
this.snapping._updateComponentsByTagResult(componentsToBuildLegacy, buildResult);
|
|
300
|
+
const packageIntegritiesByPublishedPackages = this.snapping._getPublishedPackages(componentsToBuildLegacy);
|
|
301
|
+
publishedPackages.push(...Array.from(packageIntegritiesByPublishedPackages.keys()));
|
|
302
|
+
addIntegritiesToConsumerComponentsGraphs(packageIntegritiesByPublishedPackages, this.allComponentsToTag);
|
|
303
|
+
this.addBuildStatus(componentsToBuildLegacy, _legacy().BuildStatus.Succeed);
|
|
304
|
+
await (0, _pMapSeries().default)(componentsToBuild, comp => this.snapping.enrichComp(comp));
|
|
305
|
+
if (populateArtifactsFrom) await updateHiddenProp(this.scope, populateArtifactsFrom);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
async checkForNewerVersions() {
|
|
309
|
+
// check for each one of the components whether it is using an old version
|
|
310
|
+
// TODO: once --detach-head is supported by the remote, deprecate --ignore-newest-version. and change this
|
|
311
|
+
// throwForNewestVersion to suggest using --detach-head instead. also, it the error should not be limited
|
|
312
|
+
// to tags and can be thrown for snaps as well.
|
|
313
|
+
// once --ignore-newest-version is removed, no need for this condition. it's ok to not provide the override-head option.
|
|
314
|
+
const {
|
|
315
|
+
detachHead,
|
|
316
|
+
ignoreNewestVersion,
|
|
317
|
+
isSnap
|
|
318
|
+
} = this.params;
|
|
319
|
+
if (detachHead && !(0, _harmonyModules2().isFeatureEnabled)(_harmonyModules2().DETACH_HEAD)) {
|
|
320
|
+
throw new Error('unable to detach head, the feature is not enabled');
|
|
321
|
+
}
|
|
322
|
+
if (ignoreNewestVersion && !detachHead) this.params.overrideHead = true;
|
|
323
|
+
if (!ignoreNewestVersion && !isSnap) {
|
|
324
|
+
await throwForNewestVersion(this.allComponentsToTag, this.legacyScope);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
async getMessagePerId(idsToTag, autoTagIds) {
|
|
328
|
+
const messagesFromEditorFetcher = new (_messagePerComponent().MessagePerComponentFetcher)(idsToTag, autoTagIds);
|
|
329
|
+
const {
|
|
330
|
+
editor,
|
|
331
|
+
message,
|
|
332
|
+
tagDataPerComp
|
|
333
|
+
} = this.params;
|
|
334
|
+
if (editor) return messagesFromEditorFetcher.getMessagesFromEditor(this.legacyScope.tmp, editor);
|
|
335
|
+
if (tagDataPerComp) return tagDataPerComp.map(t => ({
|
|
336
|
+
id: t.componentId,
|
|
337
|
+
msg: t.message || message
|
|
338
|
+
}));
|
|
339
|
+
return [];
|
|
340
|
+
}
|
|
341
|
+
getUniqCompsToTag() {
|
|
342
|
+
const consumerComponentsIdsMap = {};
|
|
343
|
+
// Concat and unique all the dependencies from all the components so we will not import
|
|
344
|
+
// the same dependency more then once, it's mainly for performance purpose
|
|
345
|
+
this.consumerComponents.forEach(consumerComponent => {
|
|
346
|
+
const componentIdString = consumerComponent.id.toString();
|
|
347
|
+
// Store it in a map so we can take it easily from the sorted array which contain only the id
|
|
348
|
+
consumerComponentsIdsMap[componentIdString] = consumerComponent;
|
|
349
|
+
});
|
|
350
|
+
return Object.values(consumerComponentsIdsMap); // consumerComponents unique
|
|
351
|
+
}
|
|
352
|
+
async getAutoTagData(idsToTag) {
|
|
353
|
+
// ids without versions are new. it's impossible that tagged (and not-modified) components has
|
|
354
|
+
// them as dependencies.
|
|
355
|
+
const idsToTriggerAutoTag = idsToTag.filter(id => id.hasVersion());
|
|
356
|
+
const autoTagDataWithLocalOnly = this.params.skipAutoTag || !this.workspace ? [] : await this.workspace.getAutoTagInfo(_componentId().ComponentIdList.fromArray(idsToTriggerAutoTag));
|
|
357
|
+
const localOnly = this.workspace?.listLocalOnly();
|
|
358
|
+
return localOnly ? autoTagDataWithLocalOnly.filter(autoTagItem => !localOnly.hasWithoutVersion(autoTagItem.component.id)) : autoTagDataWithLocalOnly;
|
|
359
|
+
}
|
|
360
|
+
async setFutureVersions(autoTagIds) {
|
|
361
|
+
const {
|
|
362
|
+
releaseType,
|
|
363
|
+
tagDataPerComp,
|
|
364
|
+
incrementBy,
|
|
365
|
+
persist,
|
|
366
|
+
soft,
|
|
367
|
+
exactVersion,
|
|
368
|
+
preReleaseId
|
|
369
|
+
} = this.params;
|
|
370
|
+
const isPreReleaseLike = releaseType ? ['prerelease', 'premajor', 'preminor', 'prepatch'].includes(releaseType) : false;
|
|
371
|
+
await Promise.all(this.allComponentsToTag.map(async componentToTag => {
|
|
372
|
+
const isAutoTag = autoTagIds.hasWithoutVersion(componentToTag.id);
|
|
373
|
+
const modelComponent = await this.legacyScope.sources.findOrAddComponent(componentToTag);
|
|
374
|
+
const nextVersion = componentToTag.componentMap?.nextVersion?.version;
|
|
375
|
+
const getNewVersion = () => {
|
|
376
|
+
if (tagDataPerComp) {
|
|
377
|
+
const tagData = tagDataPerComp.find(t => t.componentId.isEqualWithoutVersion(componentToTag.id));
|
|
378
|
+
if (!tagData) throw new Error(`tag-data is missing for ${componentToTag.id.toStringWithoutVersion()}`);
|
|
379
|
+
if (!tagData.versionToTag) throw new Error(`tag-data.TagResults is missing for ${componentToTag.id.toStringWithoutVersion()}`);
|
|
380
|
+
const exactVersionOrReleaseType = (0, _pkgModules().getValidVersionOrReleaseType)(tagData.versionToTag);
|
|
381
|
+
return modelComponent.getVersionToAdd(exactVersionOrReleaseType.releaseType, exactVersionOrReleaseType.exactVersion, incrementBy, tagData.prereleaseId);
|
|
382
|
+
}
|
|
383
|
+
if (nextVersion && persist) {
|
|
384
|
+
const exactVersionOrReleaseType = (0, _pkgModules().getValidVersionOrReleaseType)(nextVersion);
|
|
385
|
+
return modelComponent.getVersionToAdd(exactVersionOrReleaseType.releaseType, exactVersionOrReleaseType.exactVersion, undefined, componentToTag.componentMap?.nextVersion?.preRelease);
|
|
386
|
+
}
|
|
387
|
+
if (isAutoTag) {
|
|
388
|
+
// auto-tag always bumped as patch unless it's pre-release
|
|
389
|
+
if (isPreReleaseLike) {
|
|
390
|
+
return soft ? releaseType : modelComponent.getVersionToAdd(releaseType, exactVersion, incrementBy, preReleaseId);
|
|
391
|
+
}
|
|
392
|
+
return soft ? 'patch' : modelComponent.getVersionToAdd('patch', undefined, incrementBy, preReleaseId);
|
|
393
|
+
}
|
|
394
|
+
const versionByEnteredId = this.getVersionByEnteredId(this.ids, componentToTag, modelComponent);
|
|
395
|
+
return soft ? versionByEnteredId || exactVersion || releaseType : versionByEnteredId || modelComponent.getVersionToAdd(releaseType, exactVersion, incrementBy, preReleaseId);
|
|
396
|
+
};
|
|
397
|
+
const newVersion = getNewVersion();
|
|
398
|
+
componentToTag.setNewVersion(newVersion);
|
|
399
|
+
}));
|
|
400
|
+
}
|
|
401
|
+
setCurrentSchema() {
|
|
402
|
+
this.allComponentsToTag.forEach(component => {
|
|
403
|
+
component.schema = _legacy2().CURRENT_SCHEMA;
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
setHashes() {
|
|
407
|
+
this.allComponentsToTag.forEach(componentToTag => {
|
|
408
|
+
componentToTag.setNewVersion((0, _toolboxCrypto().sha1)((0, _uuid().v4)()));
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
getVersionByEnteredId(enteredIds, component, modelComponent) {
|
|
412
|
+
const enteredId = enteredIds.searchWithoutVersion(component.id);
|
|
413
|
+
if (enteredId && enteredId.hasVersion()) {
|
|
414
|
+
const exactVersionOrReleaseType = (0, _pkgModules().getValidVersionOrReleaseType)(enteredId.version);
|
|
415
|
+
return modelComponent.getVersionToAdd(exactVersionOrReleaseType.releaseType, exactVersionOrReleaseType.exactVersion);
|
|
416
|
+
}
|
|
417
|
+
return undefined;
|
|
418
|
+
}
|
|
419
|
+
addBuildStatus(components, buildStatus) {
|
|
420
|
+
components.forEach(component => {
|
|
421
|
+
component.buildStatus = component.isRemoved() ? _legacy().BuildStatus.Skipped : buildStatus;
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
/**
|
|
426
|
+
* otherwise, tagging without build will have the old build data of the previous snap/tag.
|
|
427
|
+
* in case we currently build, it's ok to leave the data as is, because it'll be overridden anyway.
|
|
428
|
+
*/
|
|
429
|
+
emptyBuilderData() {
|
|
430
|
+
this.allComponentsToTag.forEach(component => {
|
|
431
|
+
component.extensions = component.extensions.clone();
|
|
432
|
+
const existingBuilder = component.extensions.findCoreExtension(_legacy().Extensions.builder);
|
|
433
|
+
if (existingBuilder) existingBuilder.data = {};
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
updateDependenciesVersions() {
|
|
437
|
+
// filter out removed components.
|
|
438
|
+
// if a component has a deleted-component as a dependency, it was probably running "bit install <dep>" with a version
|
|
439
|
+
// from main. we want to keep it as the user requested. Otherwise, this changes the dependency version to the newly
|
|
440
|
+
// snapped one unintentionally.
|
|
441
|
+
const componentsToTag = this.allComponentsToTag.filter(c => !c.isRemoved());
|
|
442
|
+
const getNewDependencyVersion = id => {
|
|
443
|
+
const foundDependency = componentsToTag.find(component => component.id.isEqualWithoutVersion(id));
|
|
444
|
+
return foundDependency ? id.changeVersion(foundDependency.version) : null;
|
|
445
|
+
};
|
|
446
|
+
const changeExtensionsVersion = component => {
|
|
447
|
+
component.extensions.forEach(ext => {
|
|
448
|
+
if (ext.extensionId) {
|
|
449
|
+
const newDepId = getNewDependencyVersion(ext.extensionId);
|
|
450
|
+
if (newDepId) ext.extensionId = newDepId;
|
|
451
|
+
}
|
|
452
|
+
});
|
|
453
|
+
};
|
|
454
|
+
componentsToTag.forEach(oneComponentToTag => {
|
|
455
|
+
oneComponentToTag.getAllDependencies().forEach(dependency => {
|
|
456
|
+
const newDepId = getNewDependencyVersion(dependency.id);
|
|
457
|
+
if (newDepId) dependency.id = newDepId;
|
|
458
|
+
});
|
|
459
|
+
changeExtensionsVersion(oneComponentToTag);
|
|
460
|
+
oneComponentToTag = this.dependencyResolver.updateDepsOnLegacyTag(oneComponentToTag, getNewDependencyVersion.bind(this));
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
async addLogToComponents(components, autoTagComps, messagePerComponent) {
|
|
464
|
+
let {
|
|
465
|
+
message
|
|
466
|
+
} = this.params;
|
|
467
|
+
const {
|
|
468
|
+
persist,
|
|
469
|
+
copyLogFromPreviousSnap
|
|
470
|
+
} = this.params;
|
|
471
|
+
// @ts-ignore this happens when running `bit tag -m ""`.
|
|
472
|
+
if (message === true) {
|
|
473
|
+
message = '';
|
|
474
|
+
}
|
|
475
|
+
const basicLog = await (0, _harmonyModules().getBasicLog)();
|
|
476
|
+
const getLog = component => {
|
|
477
|
+
const nextVersion = persist ? component.componentMap?.nextVersion : null;
|
|
478
|
+
const msgFromEditor = messagePerComponent.find(item => item.id.isEqualWithoutVersion(component.id))?.msg;
|
|
479
|
+
if (copyLogFromPreviousSnap) {
|
|
480
|
+
const currentLog = component.log;
|
|
481
|
+
if (!currentLog) {
|
|
482
|
+
throw new Error(`addLogToComponents is set copyLogFromPreviousSnap: true, but it is unable to find log in the previous snap`);
|
|
483
|
+
}
|
|
484
|
+
currentLog.message = msgFromEditor || message || currentLog.message;
|
|
485
|
+
currentLog.date = basicLog.date;
|
|
486
|
+
return currentLog;
|
|
487
|
+
}
|
|
488
|
+
return {
|
|
489
|
+
username: nextVersion?.username || basicLog.username,
|
|
490
|
+
email: nextVersion?.email || basicLog.email,
|
|
491
|
+
message: nextVersion?.message || msgFromEditor || message,
|
|
492
|
+
date: basicLog.date
|
|
493
|
+
};
|
|
494
|
+
};
|
|
495
|
+
components.forEach(component => {
|
|
496
|
+
component.log = getLog(component);
|
|
497
|
+
});
|
|
498
|
+
autoTagComps.forEach(autoTagComp => {
|
|
499
|
+
autoTagComp.log = getLog(autoTagComp);
|
|
500
|
+
const defaultMsg = 'bump dependencies versions';
|
|
501
|
+
if (message) {
|
|
502
|
+
autoTagComp.log.message += ` (${defaultMsg})`;
|
|
503
|
+
} else if (!autoTagComp.log.message) {
|
|
504
|
+
autoTagComp.log.message = defaultMsg;
|
|
505
|
+
}
|
|
506
|
+
});
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
exports.VersionMaker = VersionMaker;
|
|
510
|
+
async function throwForNewestVersion(allComponentsToTag, legacyScope) {
|
|
511
|
+
const newestVersionsP = allComponentsToTag.map(async component => {
|
|
512
|
+
if (component.componentFromModel) {
|
|
513
|
+
// otherwise it's a new component, so this check is irrelevant
|
|
514
|
+
const modelComponent = await legacyScope.getModelComponentIfExist(component.id);
|
|
515
|
+
if (!modelComponent) throw new (_bitError().BitError)(`component ${component.id} was not found in the model`);
|
|
516
|
+
if (!modelComponent.listVersions().length) return null; // no versions yet, no issues.
|
|
517
|
+
const latest = modelComponent.getHeadRegardlessOfLaneAsTagOrHash();
|
|
518
|
+
if (latest !== component.version) {
|
|
519
|
+
return {
|
|
520
|
+
componentId: component.id.toStringWithoutVersion(),
|
|
521
|
+
currentVersion: component.version,
|
|
522
|
+
latestVersion: latest
|
|
523
|
+
};
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
return null;
|
|
527
|
+
});
|
|
528
|
+
const newestVersions = await Promise.all(newestVersionsP);
|
|
529
|
+
const newestVersionsWithoutEmpty = (0, _lodash().compact)(newestVersions);
|
|
530
|
+
if (newestVersionsWithoutEmpty.length) {
|
|
531
|
+
throw new (_legacy3().NewerVersionFound)(newestVersionsWithoutEmpty);
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
function addIntegritiesToConsumerComponentsGraphs(packageIntegritiesByPublishedPackages, consumerComponents) {
|
|
535
|
+
const _addIntegritiesToDependenciesGraph = addIntegritiesToDependenciesGraph.bind(null, packageIntegritiesByPublishedPackages);
|
|
536
|
+
for (const consumerComponent of consumerComponents) {
|
|
537
|
+
if (consumerComponent.dependenciesGraph) {
|
|
538
|
+
consumerComponent.dependenciesGraph = _addIntegritiesToDependenciesGraph(consumerComponent.dependenciesGraph);
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
/**
|
|
544
|
+
* Updates the dependencies graph by replacing all "pending" version numbers of component dependencies
|
|
545
|
+
* with the actual version numbers of the recently published packages. It also attaches the integrity
|
|
546
|
+
* checksums of these components to ensure data integrity for each resolved dependency.
|
|
547
|
+
*
|
|
548
|
+
* @param packageIntegritiesByPublishedPackages - A map of package names and versions to their integrity checksums.
|
|
549
|
+
* @param dependenciesGraph - The current dependencies graph, containing nodes with potentially "pending" versions.
|
|
550
|
+
* @returns A new DependenciesGraph with updated versions and integrity checksums for all previously pending dependencies.
|
|
551
|
+
*/
|
|
552
|
+
function addIntegritiesToDependenciesGraph(packageIntegritiesByPublishedPackages, dependenciesGraph) {
|
|
553
|
+
const resolvedVersions = [];
|
|
554
|
+
for (const [selector, integrity] of packageIntegritiesByPublishedPackages.entries()) {
|
|
555
|
+
if (integrity == null) continue;
|
|
556
|
+
const index = selector.indexOf('@', 1);
|
|
557
|
+
const name = selector.substring(0, index);
|
|
558
|
+
const version = selector.substring(index + 1);
|
|
559
|
+
const pendingPkg = dependenciesGraph.packages.get(`${name}@pending:`);
|
|
560
|
+
if (pendingPkg) {
|
|
561
|
+
pendingPkg.resolution = {
|
|
562
|
+
integrity
|
|
563
|
+
};
|
|
564
|
+
resolvedVersions.push({
|
|
565
|
+
name,
|
|
566
|
+
version
|
|
567
|
+
});
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
return replacePendingVersions(dependenciesGraph, resolvedVersions);
|
|
571
|
+
}
|
|
572
|
+
async function removeDeletedComponentsFromBitmap(comps, workspace) {
|
|
573
|
+
if (!workspace) {
|
|
574
|
+
return undefined;
|
|
575
|
+
}
|
|
576
|
+
const removedComps = comps.filter(comp => comp.isRemoved());
|
|
577
|
+
if (!removedComps.length) return undefined;
|
|
578
|
+
const compBitIdsToRemove = _componentId().ComponentIdList.fromArray(removedComps.map(c => c.id));
|
|
579
|
+
await (0, _remove().deleteComponentsFiles)(workspace.consumer, compBitIdsToRemove);
|
|
580
|
+
await workspace.consumer.cleanFromBitMap(compBitIdsToRemove);
|
|
581
|
+
return compBitIdsToRemove;
|
|
582
|
+
}
|
|
583
|
+
async function removeMergeConfigFromComponents(unmergedComps, components, workspace) {
|
|
584
|
+
if (!workspace || !unmergedComps.length) {
|
|
585
|
+
return;
|
|
586
|
+
}
|
|
587
|
+
const configMergeFile = workspace.getConflictMergeFile();
|
|
588
|
+
unmergedComps.forEach(compId => {
|
|
589
|
+
const isNowSnapped = components.find(c => c.id.isEqualWithoutVersion(compId));
|
|
590
|
+
if (isNowSnapped) {
|
|
591
|
+
configMergeFile.removeConflict(compId.toStringWithoutVersion());
|
|
592
|
+
}
|
|
593
|
+
});
|
|
594
|
+
const currentlyUnmerged = workspace ? await workspace.listComponentsDuringMerge() : [];
|
|
595
|
+
if (configMergeFile.hasConflict() && currentlyUnmerged.length) {
|
|
596
|
+
// it's possible that "workspace" section is still there. but if all "unmerged" are now merged,
|
|
597
|
+
// then, it's safe to delete the file.
|
|
598
|
+
await configMergeFile.write();
|
|
599
|
+
} else {
|
|
600
|
+
await configMergeFile.delete();
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
function isAvailableOnMain(currentLane, modelComponent, id) {
|
|
604
|
+
if (currentLane.isDefault()) {
|
|
605
|
+
return true;
|
|
606
|
+
}
|
|
607
|
+
if (!id.hasVersion()) {
|
|
608
|
+
// component was unsnapped on the current lane and is back to a new component
|
|
609
|
+
return true;
|
|
610
|
+
}
|
|
611
|
+
return modelComponent.hasHead();
|
|
612
|
+
}
|
|
613
|
+
async function updateVersions(workspace, stagedConfig, currentLane, modelComponent, versionToSetInBitmap,
|
|
614
|
+
// helpful for detached head
|
|
615
|
+
isTag = true) {
|
|
616
|
+
const consumer = workspace.consumer;
|
|
617
|
+
const idLatest = modelComponent.toBitIdWithLatestVersionAllowNull();
|
|
618
|
+
const id = versionToSetInBitmap ? idLatest.changeVersion(versionToSetInBitmap) : idLatest;
|
|
619
|
+
const isOnBitmap = consumer.bitMap.getComponentIfExist(id, {
|
|
620
|
+
ignoreVersion: true
|
|
621
|
+
});
|
|
622
|
+
if (!isOnBitmap && !isTag) {
|
|
623
|
+
// handle the case when a component was deleted, snapped/tagged and is now reset.
|
|
624
|
+
const stagedData = stagedConfig.getPerId(id);
|
|
625
|
+
if (stagedData?.config && stagedData.config[_remove().RemoveAspect.id]) {
|
|
626
|
+
consumer.bitMap.addFromComponentJson(stagedData.id, stagedData.componentMapObject);
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
consumer.bitMap.updateComponentId(id, undefined, undefined, true);
|
|
630
|
+
const availableOnMain = isAvailableOnMain(currentLane, modelComponent, id);
|
|
631
|
+
if (!availableOnMain) {
|
|
632
|
+
consumer.bitMap.setOnLanesOnly(id, true);
|
|
633
|
+
}
|
|
634
|
+
const componentMap = consumer.bitMap.getComponent(id);
|
|
635
|
+
const compId = await workspace.resolveComponentId(id);
|
|
636
|
+
// it can be either a tag/snap or reset.
|
|
637
|
+
if (isTag) {
|
|
638
|
+
const compMapObj = componentMap.toPlainObject();
|
|
639
|
+
const config = componentMap.config;
|
|
640
|
+
stagedConfig.addComponentConfig(compId, config, compMapObj);
|
|
641
|
+
consumer.bitMap.removeConfig(id);
|
|
642
|
+
const hash = modelComponent.getRef(id.version);
|
|
643
|
+
if (!hash) throw new Error(`updateComponentsVersions: unable to find a hash for ${id.toString()}`);
|
|
644
|
+
workspace.scope.legacyScope.stagedSnaps.addSnap(hash?.toString());
|
|
645
|
+
} else if (!componentMap.config) {
|
|
646
|
+
componentMap.config = stagedConfig.getConfigPerId(compId);
|
|
647
|
+
}
|
|
648
|
+
componentMap.clearNextVersion();
|
|
649
|
+
}
|
|
650
|
+
function replacePendingVersions(graph, resolvedVersions) {
|
|
651
|
+
let s = graph.serialize();
|
|
652
|
+
for (const {
|
|
653
|
+
name,
|
|
654
|
+
version
|
|
655
|
+
} of resolvedVersions) {
|
|
656
|
+
s = s.replaceAll(`${name}@pending:`, `${name}@${version}`);
|
|
657
|
+
}
|
|
658
|
+
const updatedDependenciesGraph = _objects().DependenciesGraph.deserialize(s);
|
|
659
|
+
// This should never happen as we know at this point that the schema version is supported
|
|
660
|
+
if (updatedDependenciesGraph == null) {
|
|
661
|
+
throw new (_bitError().BitError)('Failed to deserialize dependencies graph in replacePendingVersions()');
|
|
662
|
+
}
|
|
663
|
+
return updatedDependenciesGraph;
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
/**
|
|
667
|
+
* relevant for "_tag" (tag-from-scope) command.
|
|
668
|
+
* the new tag uses the same files/config/build-artifacts as the previous snap.
|
|
669
|
+
* we want to mark the previous snap as hidden. so then "bit log" and "bit blame" won't show it.
|
|
670
|
+
*/
|
|
671
|
+
async function updateHiddenProp(scope, ids) {
|
|
672
|
+
const log = await (0, _harmonyModules().getBasicLog)();
|
|
673
|
+
log.message = 'marked as hidden';
|
|
674
|
+
await (0, _toolboxPromise().pMapPool)(ids, async id => {
|
|
675
|
+
const versionObj = await scope.getBitObjectVersionById(id);
|
|
676
|
+
if (!versionObj) return;
|
|
677
|
+
versionObj.hidden = true;
|
|
678
|
+
versionObj.addModifiedLog(log);
|
|
679
|
+
scope.legacyScope.objects.add(versionObj);
|
|
680
|
+
}, {
|
|
681
|
+
concurrency: 50
|
|
682
|
+
});
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
//# sourceMappingURL=version-maker.js.map
|