@teambit/snapping 1.0.346 → 1.0.347

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.
@@ -88,7 +88,7 @@ export declare class SnappingMain {
88
88
  * with a valid semver to that version.
89
89
  * tag can be done only on main, not on a lane.
90
90
  */
91
- tag({ ids, message, version, editor, snapped, unmerged, releaseType, preReleaseId, ignoreIssues, ignoreNewestVersion, skipTests, skipTasks, skipAutoTag, build, unmodified, soft, persist, ignoreBuildErrors, rebuildDepsGraph, incrementBy, disableTagAndSnapPipelines, failFast, }: {
91
+ tag({ ids, message, version, editor, snapped, unmerged, releaseType, preReleaseId, ignoreIssues, ignoreNewestVersion, skipTests, skipTasks, skipAutoTag, build, unmodified, soft, persist, ignoreBuildErrors, rebuildDepsGraph, incrementBy, disableTagAndSnapPipelines, failFast, includeLocalOnly, }: {
92
92
  ids?: string[];
93
93
  all?: boolean | string;
94
94
  snapped?: boolean;
@@ -119,7 +119,7 @@ export declare class SnappingMain {
119
119
  * once a component is snapped on a lane, it becomes part of it.
120
120
  */
121
121
  snap({ pattern, legacyBitIds, // @todo: change to ComponentID[]. pass only if have the ids already parsed.
122
- unmerged, editor, message, ignoreIssues, skipTests, skipTasks, skipAutoSnap, build, disableTagAndSnapPipelines, ignoreBuildErrors, rebuildDepsGraph, unmodified, exitOnFirstFailedTask, }: Partial<BasicTagSnapParams> & {
122
+ unmerged, editor, message, ignoreIssues, skipTests, skipTasks, skipAutoSnap, build, disableTagAndSnapPipelines, ignoreBuildErrors, rebuildDepsGraph, unmodified, exitOnFirstFailedTask, includeLocalOnly, }: Partial<BasicTagSnapParams> & {
123
123
  pattern?: string;
124
124
  legacyBitIds?: ComponentIdList;
125
125
  unmerged?: boolean;
@@ -180,6 +180,7 @@ export declare class SnappingMain {
180
180
  * 2. save all dependencies data from the legacy into DependencyResolver aspect.
181
181
  */
182
182
  UpdateDepsAspectsSaveIntoDepsResolver(component: Component, updatedIds: string[]): Promise<void>;
183
+ private getTagPendingComponentsIds;
183
184
  private getComponentsToTag;
184
185
  static slots: never[];
185
186
  static dependencies: import("@teambit/harmony").Aspect[];
@@ -371,7 +371,8 @@ class SnappingMain {
371
371
  rebuildDepsGraph,
372
372
  incrementBy = 1,
373
373
  disableTagAndSnapPipelines = false,
374
- failFast = false
374
+ failFast = false,
375
+ includeLocalOnly
375
376
  }) {
376
377
  if (soft) build = false;
377
378
  if (editor && persist) {
@@ -390,7 +391,7 @@ class SnappingMain {
390
391
  const {
391
392
  bitIds,
392
393
  warnings
393
- } = await this.getComponentsToTag(unmodified, exactVersion, persist, ids, snapped, unmerged);
394
+ } = await this.getComponentsToTag(unmodified, exactVersion, persist, ids, snapped, unmerged, includeLocalOnly);
394
395
  if (!bitIds.length) return null;
395
396
  const compIds = _componentId().ComponentIdList.fromArray(bitIds);
396
397
  this.logger.debug(`tagging the following components: ${compIds.toString()}`);
@@ -707,14 +708,17 @@ if you're willing to lose the history from the head to the specified version, us
707
708
  ignoreBuildErrors = false,
708
709
  rebuildDepsGraph,
709
710
  unmodified = false,
710
- exitOnFirstFailedTask = false
711
+ exitOnFirstFailedTask = false,
712
+ includeLocalOnly
711
713
  }) {
712
714
  if (!this.workspace) throw new (_workspace().OutsideWorkspaceError)();
713
715
  if (pattern && legacyBitIds) throw new Error(`please pass either pattern or legacyBitIds, not both`);
714
716
  const consumer = this.workspace.consumer;
715
717
  const componentsList = new (_legacy().ComponentsList)(consumer);
716
718
  const newComponents = await componentsList.listNewComponents();
717
- const ids = legacyBitIds || (await getIdsToSnap(this.workspace));
719
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
720
+ const self = this;
721
+ const ids = legacyBitIds || (await getIdsToSnap());
718
722
  if (!ids) return null;
719
723
  this.logger.debug(`snapping the following components: ${ids.toString()}`);
720
724
  const components = await this.loadComponentsForTagOrSnap(ids);
@@ -761,11 +765,11 @@ if you're willing to lose the history from the head to the specified version, us
761
765
  await stagedConfig?.write();
762
766
  // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
763
767
  return snapResults;
764
- async function getIdsToSnap(workspace) {
768
+ async function getIdsToSnap() {
765
769
  if (unmerged) {
766
770
  return componentsList.listDuringMergeStateComponents();
767
771
  }
768
- const tagPendingComponentsIds = unmodified ? await workspace.listPotentialTagIds() : await workspace.listTagPendingIds();
772
+ const tagPendingComponentsIds = await self.getTagPendingComponentsIds(unmodified, includeLocalOnly);
769
773
  if (!tagPendingComponentsIds.length) return null;
770
774
  // when unmodified, we ask for all components, throw if no matching. if not unmodified and no matching, see error
771
775
  // below, suggesting to use --unmodified flag.
@@ -773,14 +777,14 @@ if you're willing to lose the history from the head to the specified version, us
773
777
  const getCompIds = async () => {
774
778
  if (!pattern) return tagPendingComponentsIds;
775
779
  if (!pattern.includes('*') && !pattern.includes(',')) {
776
- const compId = await workspace.resolveComponentId(pattern);
780
+ const compId = await self.workspace.resolveComponentId(pattern);
777
781
  return [compId];
778
782
  }
779
- return workspace.filterIdsFromPoolIdsByPattern(pattern, tagPendingComponentsIds, shouldThrowForNoMatching);
783
+ return self.workspace.filterIdsFromPoolIdsByPattern(pattern, tagPendingComponentsIds, shouldThrowForNoMatching);
780
784
  };
781
785
  const componentIds = await getCompIds();
782
786
  if (!componentIds.length && pattern) {
783
- const allTagPending = await workspace.listPotentialTagIds();
787
+ const allTagPending = await self.workspace.listPotentialTagIds();
784
788
  if (allTagPending.length) {
785
789
  throw new (_bitError().BitError)(`unable to find matching for "${pattern}" pattern among modified/new components.
786
790
  there are matching among unmodified components though. consider using --unmodified flag if needed.
@@ -1269,7 +1273,19 @@ another option, in case this dependency is not in main yet is to remove all refe
1269
1273
  const extension = new (_config().ExtensionDataEntry)(undefined, undefined, extId, undefined, data);
1270
1274
  component.config.extensions.push(extension);
1271
1275
  }
1272
- async getComponentsToTag(includeUnmodified, exactVersion, persist, ids, snapped, unmerged) {
1276
+ async getTagPendingComponentsIds(includeUnmodified = false, includeLocalOnly = false) {
1277
+ const ids = includeUnmodified ? await this.workspace.listPotentialTagIds() : await this.workspace.listTagPendingIds();
1278
+ if (includeLocalOnly) {
1279
+ return ids;
1280
+ }
1281
+ const localOnlyIds = this.workspace.filter.byLocalOnly(ids);
1282
+ if (!localOnlyIds.length) {
1283
+ return ids;
1284
+ }
1285
+ const localOnlyListIds = _componentId().ComponentIdList.fromArray(localOnlyIds);
1286
+ return ids.filter(id => !localOnlyListIds.hasWithoutVersion(id));
1287
+ }
1288
+ async getComponentsToTag(includeUnmodified, exactVersion, persist, ids, snapped, unmerged, includeLocalOnly = false) {
1273
1289
  const warnings = [];
1274
1290
  const componentsList = new (_legacy().ComponentsList)(this.workspace.consumer);
1275
1291
  if (persist) {
@@ -1279,8 +1295,18 @@ another option, in case this dependency is not in main yet is to remove all refe
1279
1295
  warnings: []
1280
1296
  };
1281
1297
  }
1282
- const tagPendingComponentsIds = includeUnmodified ? await this.workspace.listPotentialTagIds() : await this.workspace.listTagPendingIds();
1298
+ const tagPendingComponentsIds = await this.getTagPendingComponentsIds(includeUnmodified, includeLocalOnly);
1283
1299
  const snappedComponentsIds = (await this.workspace.filter.bySnappedOnMain()).map(id => id.changeVersion(undefined));
1300
+ if (snappedComponentsIds.length && !includeLocalOnly) {
1301
+ const localOnlyIds = this.workspace.filter.byLocalOnly(snappedComponentsIds);
1302
+ const localOnlyListIds = _componentId().ComponentIdList.fromArray(localOnlyIds);
1303
+ snappedComponentsIds.forEach(id => {
1304
+ if (localOnlyListIds.hasWithoutVersion(id)) {
1305
+ const index = snappedComponentsIds.findIndex(c => c.isEqual(id));
1306
+ snappedComponentsIds.splice(index, 1);
1307
+ }
1308
+ });
1309
+ }
1284
1310
  if (ids.length) {
1285
1311
  const componentIds = await (0, _pMapSeries().default)(ids, async id => {
1286
1312
  const [idWithoutVer, version] = id.split('@');
@@ -1313,10 +1339,9 @@ another option, in case this dependency is not in main yet is to remove all refe
1313
1339
  warnings
1314
1340
  };
1315
1341
  }
1316
- const tagPendingBitIds = tagPendingComponentsIds.map(id => id);
1317
- const tagPendingBitIdsIncludeSnapped = [...tagPendingBitIds, ...snappedComponentsIds];
1342
+ const tagPendingBitIdsIncludeSnapped = [...tagPendingComponentsIds, ...snappedComponentsIds];
1318
1343
  if (includeUnmodified && exactVersion) {
1319
- const tagPendingComponentsLatest = await this.workspace.scope.legacyScope.latestVersions(tagPendingBitIds, false);
1344
+ const tagPendingComponentsLatest = await this.workspace.scope.legacyScope.latestVersions(tagPendingComponentsIds, false);
1320
1345
  tagPendingComponentsLatest.forEach(componentId => {
1321
1346
  if (componentId.version && _semver().default.valid(componentId.version) && _semver().default.gt(componentId.version, exactVersion)) {
1322
1347
  warnings.push(`warning: ${componentId.toString()} has a version greater than ${exactVersion}`);