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

add a new component-issue "RemovedEnv" #9009

Merged
merged 2 commits into from
Jul 8, 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
2 changes: 2 additions & 0 deletions components/component-issues/issues-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { RemovedDependencies } from './removed-dependencies';
import { SelfReference } from './self-reference';
import { ImportFromDirectory } from './import-from-directory';
import { DeprecatedDependencies } from './deprecated-dependencies';
import { RemovedEnv } from './removed-env';

export const IssuesClasses = {
MissingPackagesDependenciesOnFs,
Expand All @@ -42,6 +43,7 @@ export const IssuesClasses = {
NonLoadedEnv,
ExternalEnvWithoutVersion,
RemovedDependencies,
RemovedEnv,
DeprecatedDependencies,
SelfReference,
ImportFromDirectory,
Expand Down
12 changes: 12 additions & 0 deletions components/component-issues/removed-env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { ComponentIssue, ISSUE_FORMAT_SPACE } from './component-issue';

export class RemovedEnv extends ComponentIssue {
description = 'the env of this component is deleted';
solution =
'use "bit env set/replace" to set a new env or a different version of this env. to undo the delete, run "bit recover"';
data: string; // env id
isTagBlocker = true;
dataToString() {
return ISSUE_FORMAT_SPACE + this.data;
}
}
24 changes: 22 additions & 2 deletions e2e/harmony/custom-env.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,8 @@ describe('custom env', function () {
});

(supportNpmCiRegistryTesting ? describe : describe.skip)('custom env installed as a package', () => {
let envId;
let envName;
let envId: string;
let envName: string;
let npmCiRegistry: NpmCiRegistry;
before(async () => {
helper = new Helper({ scopesOptions: { remoteScopeWithDot: true } });
Expand Down Expand Up @@ -344,7 +344,27 @@ describe('custom env', function () {
expect(isModified).to.be.true;
});
});
describe('snapping the env on the lane and then deleting it', () => {
before(() => {
helper.scopeHelper.reInitLocalScope();
helper.scopeHelper.addRemoteScope();
helper.fixtures.populateComponents(1);
helper.command.createLane();
helper.command.importComponent(envName);
helper.command.setEnv('comp1', envId);
helper.command.snapAllComponentsWithoutBuild('--unmodified');
helper.command.export();

helper.command.softRemoveOnLane(envId);
});
it('bit status should show the RemovedEnv issue', () => {
helper.command.expectStatusToHaveIssue(IssuesClasses.RemovedEnv.name);
});
it('replacing the env should fix the issue', () => {
helper.command.replaceEnv(envId, `${envId}@0.0.2`);
helper.command.expectStatusToNotHaveIssue(IssuesClasses.RemovedEnv.name);
});
});
describe('missing modules in the env capsule', () => {
before(() => {
helper.scopeHelper.reInitLocalScope();
Expand Down
29 changes: 23 additions & 6 deletions scopes/component/remove/remove.main.runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,12 @@ ${mainComps.map((c) => c.id.toString()).join('\n')}`);
return Boolean(isRemoved);
}

async isEnvByIdWithoutLoadingComponent(componentId: ComponentID): Promise<boolean> {
const versionObj = await this.workspace.scope.getBitObjectVersionById(componentId);
const envData = versionObj?.extensions.findCoreExtension('teambit.envs/envs');
return envData?.data.type === 'env';
}

/**
* get components that were soft-removed and tagged/snapped/merged but not exported yet.
*/
Expand All @@ -342,16 +348,27 @@ ${mainComps.map((c) => c.id.toString()).join('\n')}`);

private async addRemovedDepIssue(component: Component) {
const dependencies = this.depResolver.getComponentDependencies(component);
const removedWithUndefined = await Promise.all(
const removedDependencies: ComponentID[] = [];
let removedEnv: ComponentID | undefined;
await Promise.all(
dependencies.map(async (dep) => {
const isRemoved = await this.isRemovedByIdWithoutLoadingComponent(dep.componentId);
if (isRemoved) return dep.componentId;
return undefined;
if (!isRemoved) return;
const isEnv = await this.isEnvByIdWithoutLoadingComponent(dep.componentId);
if (isEnv) {
removedEnv = dep.componentId;
} else {
removedDependencies.push(dep.componentId);
}
})
);
const removed = compact(removedWithUndefined).map((id) => id.toString());
if (removed.length) {
component.state.issues.getOrCreate(IssuesClasses.RemovedDependencies).data = removed;
if (removedDependencies.length) {
component.state.issues.getOrCreate(IssuesClasses.RemovedDependencies).data = removedDependencies.map((r) =>
r.toString()
);
}
if (removedEnv) {
component.state.issues.getOrCreate(IssuesClasses.RemovedEnv).data = removedEnv.toString();
}
}

Expand Down