Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(snap/tag), remove duplicated extensions generated in old bit version #7992

Merged
merged 3 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions scopes/workspace/workspace/aspects-merger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { UnmergedComponent } from '@teambit/legacy/dist/scope/lanes/unmerged-com
import { BitId } from '@teambit/legacy-bit-id';
import { EnvsAspect } from '@teambit/envs';
import { DependencyResolverAspect } from '@teambit/dependency-resolver';
import { ExtensionDataList } from '@teambit/legacy/dist/consumer/config/extension-data';
import { partition, mergeWith, merge } from 'lodash';
import { ExtensionDataList, ignoreVersionPredicate } from '@teambit/legacy/dist/consumer/config/extension-data';
import { partition, mergeWith, merge, uniq, uniqWith } from 'lodash';
import { MergeConfigConflict } from './exceptions/merge-config-conflict';
import { AspectSpecificField, ExtensionsOrigin, Workspace } from './workspace';
import { MergeConflictFile } from './merge-conflict-file';
Expand Down Expand Up @@ -92,7 +92,7 @@ export class AspectsMerger {
: undefined;

this.removeAutoDepsFromConfig(componentId, configMergeExtensions);
const scopeExtensions = componentFromScope?.config?.extensions || new ExtensionDataList();
const scopeExtensions = this.getComponentFromScopeWithoutDuplications(componentFromScope);
// backward compatibility. previously, it was saved as an array into the model (when there was merge-config)
this.removeAutoDepsFromConfig(componentId, scopeExtensions, true);
const [specific, nonSpecific] = partition(scopeExtensions, (entry) => entry.config[AspectSpecificField] === true);
Expand Down Expand Up @@ -196,6 +196,23 @@ export class AspectsMerger {
};
}

/**
* before version 0.0.882 it was possible to save Version object with the same extension twice.
*/
private getComponentFromScopeWithoutDuplications(componentFromScope?: Component) {
if (!componentFromScope) return new ExtensionDataList();
const scopeExtensions = componentFromScope.config.extensions;
const scopeExtIds = scopeExtensions.ids;
const scopeExtHasDuplications = scopeExtIds.length !== uniq(scopeExtIds).length;
if (!scopeExtHasDuplications) {
return scopeExtensions;
}
// let's remove this duplicated extension blindly without trying to merge. (no need to merge coz it's old data from scope
// which will be overridden anyway by the workspace or other config strategies).
const arr = uniqWith(scopeExtensions, ignoreVersionPredicate);
return ExtensionDataList.fromArray(arr);
}

/**
* from the merge-config we get the dep-resolver policy as an array, because it needs to support "force" prop.
* however, when we save the config, we want to save it as an object, so we need split the data into two:
Expand Down
5 changes: 3 additions & 2 deletions src/consumer/config/extension-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import {
reStructureBuildArtifacts,
} from '../component/sources/artifact-files';

const mergeReducer = (accumulator, currentValue) => R.unionWith(ignoreVersionPredicate, accumulator, currentValue);
const mergeReducer = (accumulator: ExtensionDataList, currentValue: ExtensionDataList) =>
R.unionWith(ignoreVersionPredicate, accumulator, currentValue);
type ExtensionConfig = { [extName: string]: any } | RemoveExtensionSpecialSign;
type ConfigOnlyEntry = {
id: string;
Expand Down Expand Up @@ -264,7 +265,7 @@ export class ExtensionDataList extends Array<ExtensionDataEntry> {
}
}

function ignoreVersionPredicate(extensionEntry1: ExtensionDataEntry, extensionEntry2: ExtensionDataEntry) {
export function ignoreVersionPredicate(extensionEntry1: ExtensionDataEntry, extensionEntry2: ExtensionDataEntry) {
if (extensionEntry1.extensionId && extensionEntry2.extensionId) {
return extensionEntry1.extensionId.isEqualWithoutVersion(extensionEntry2.extensionId);
}
Expand Down