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(lane-merge), avoid removing dependencies that were set explicitly before #8665

Merged
merged 4 commits into from
Mar 13, 2024
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
33 changes: 33 additions & 0 deletions e2e/harmony/merge-config.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -621,4 +621,37 @@ describe('merge config scenarios', function () {
});
}
);
describe('diverge with merge-able auto-detected dependencies config and pre-config explicitly set', () => {
let mainBeforeDiverge: string;
before(() => {
helper.scopeHelper.setNewLocalAndRemoteScopes();
helper.fixtures.populateComponents(1);
helper.fs.outputFile('comp1/index.js', `import R from 'ramda';`);
helper.npm.addFakeNpmPackage('ramda', '0.0.19');
helper.npm.addFakeNpmPackage('lodash', '4.2.4');
helper.command.dependenciesSet('comp1', '[email protected]');
helper.command.tagAllWithoutBuild();
helper.command.export();
mainBeforeDiverge = helper.scopeHelper.cloneLocalScope();

helper.command.createLane();
helper.command.snapAllComponentsWithoutBuild('--unmodified');
helper.command.export();

helper.scopeHelper.getClonedLocalScope(mainBeforeDiverge);
helper.npm.addFakeNpmPackage('ramda', '0.0.21');
helper.workspaceJsonc.addPolicyToDependencyResolver({ dependencies: { ramda: '0.0.21' } });
helper.command.snapAllComponentsWithoutBuild();
helper.command.export();

helper.scopeHelper.reInitLocalScope();
helper.scopeHelper.addRemoteScope();
helper.command.importLane('dev', '--skip-dependency-installation');
helper.command.mergeLane('main', '--no-snap --skip-dependency-installation --ignore-config-changes');
});
it('should not delete the previously deps set', () => {
const deps = helper.command.getCompDepsIdsFromData('comp1');
expect(deps).to.include('lodash');
});
});
});
27 changes: 27 additions & 0 deletions scopes/workspace/workspace/aspects-merger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ export class AspectsMerger {
const scopeExtensionsNonSpecific = new ExtensionDataList(...nonSpecific);
const scopeExtensionsSpecific = new ExtensionDataList(...specific);

this.addConfigDepsFromModelToConfigMerge(scopeExtensionsSpecific, mergeConfigCombined);

const componentConfigFile = await this.workspace.componentConfigFile(componentId);
if (componentConfigFile) {
configFileExtensions = componentConfigFile.aspects.toLegacy();
Expand Down Expand Up @@ -243,6 +245,31 @@ export class AspectsMerger {
}
}

/**
* this is needed because if the mergeConfig has a policy, it will be used, and any other policy along the line will be ignored.
* in case the model has some dependencies that were set explicitly they're gonna be ignored.
* this makes sure to add them to the policy of the mergeConfig.
* in a way, this is similar to what we do when a user is running `bit deps set` and the component had previous dependencies set,
* we copy those dependencies along with the current one to the .bitmap file, so they won't get lost.
*/
private addConfigDepsFromModelToConfigMerge(
scopeExtensionsSpecific: ExtensionDataList,
mergeConfig?: Record<string, any>
) {
const mergeConfigPolicy = mergeConfig?.[DependencyResolverAspect.id]?.policy;
if (!mergeConfigPolicy) return;
const scopePolicy = scopeExtensionsSpecific.findCoreExtension(DependencyResolverAspect.id)?.config.policy;
if (!scopePolicy) return;
Object.keys(scopePolicy).forEach((key) => {
if (!mergeConfigPolicy[key]) {
mergeConfigPolicy[key] = scopePolicy[key];
return;
}
// mergeConfigPolicy should take precedence over scopePolicy
mergeConfigPolicy[key] = { ...scopePolicy[key], ...mergeConfigPolicy[key] };
});
}

private getUnmergedData(componentId: ComponentID): UnmergedComponent | undefined {
return this.workspace.scope.legacyScope.objects.unmergedComponents.getEntry(componentId);
}
Expand Down
1 change: 1 addition & 0 deletions src/e2e-helper/e2e-command-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,7 @@ export default class CommandHelper {
return showConfig.data.dependencies;
}

/** returns the ids without the versions */
getCompDepsIdsFromData(compId: string): string[] {
const aspectConf = this.showAspectConfig(compId, Extensions.dependencyResolver);
return aspectConf.data.dependencies.map((dep) => dep.id);
Expand Down