Skip to content

fix(env-replace), when multiple versions of the same env is used for various components, replace them all #9174

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

Merged
merged 2 commits into from
Sep 4, 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
17 changes: 17 additions & 0 deletions e2e/harmony/custom-env.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,23 @@ describe('custom env', function () {
expect(bitMap.comp1.config[Extensions.envs].env).equal(envId);
});
});
describe('set up the same env with two different versions, then replace with another env', () => {
before(() => {
helper.scopeHelper.reInitLocalScope();
helper.scopeHelper.addRemoteScope();
helper.fixtures.populateComponents(2);
helper.command.setEnv('comp1', `${envId}@0.0.1`);
helper.command.setEnv('comp2', `${envId}@0.0.2`);
helper.command.replaceEnv(envId, `teambit.react/react`);
});
it('should replace the env for both components', () => {
const bitMap = helper.bitMap.read();
expect(bitMap.comp1.config).to.not.have.property(`${envId}@0.0.1`);
expect(bitMap.comp2.config).to.not.have.property(`${envId}@0.0.2`);
expect(bitMap.comp1.config).to.have.property('teambit.react/react');
expect(bitMap.comp2.config).to.have.property('teambit.react/react');
});
});
describe('tag and change the env version', () => {
before(() => {
helper.scopeHelper.reInitLocalScope({ addRemoteScopeAsDefaultScope: false });
Expand Down
6 changes: 3 additions & 3 deletions scopes/workspace/workspace/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1084,18 +1084,18 @@ it's possible that the version ${component.id.version} belong to ${idStr.split('
async getComponentsUsingEnv(env: string, ignoreVersion = true, throwIfNotFound = false): Promise<Component[]> {
const allComps = await this.list();
const allEnvs = await this.envs.createEnvironment(allComps);
const foundEnv = allEnvs.runtimeEnvs.find((runtimeEnv) => {
const foundEnvs = allEnvs.runtimeEnvs.filter((runtimeEnv) => {
if (runtimeEnv.id === env) return true;
if (!ignoreVersion) return false;
const envWithoutVersion = runtimeEnv.id.split('@')[0];
return env === envWithoutVersion;
});
if (!foundEnv && throwIfNotFound) {
if (!foundEnvs.length && throwIfNotFound) {
const availableEnvs = allEnvs.runtimeEnvs.map((runtimeEnv) => runtimeEnv.id);
throw new BitError(`unable to find components that using "${env}" env.
the following envs are used in this workspace: ${availableEnvs.join(', ')}`);
}
return foundEnv?.components || [];
return foundEnvs.map((runtimeEnv) => runtimeEnv.components).flat();
}

async getMany(ids: Array<ComponentID>, loadOpts?: ComponentLoadOptions, throwOnFailure = true): Promise<Component[]> {
Expand Down