Skip to content

Commit f31e427

Browse files
authored
add a new component-issue "RemovedEnv" (teambit#9009)
Helpful when a component's env has deleted. Instead of showing the RemovedDependencies issue, which is unhelpful in this scenario, it shows the newly introduced RemovedEnv issue, which suggests running `bit env set/replace` to fix.
1 parent 41b7f17 commit f31e427

File tree

4 files changed

+59
-8
lines changed

4 files changed

+59
-8
lines changed

components/component-issues/issues-list.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { RemovedDependencies } from './removed-dependencies';
2121
import { SelfReference } from './self-reference';
2222
import { ImportFromDirectory } from './import-from-directory';
2323
import { DeprecatedDependencies } from './deprecated-dependencies';
24+
import { RemovedEnv } from './removed-env';
2425

2526
export const IssuesClasses = {
2627
MissingPackagesDependenciesOnFs,
@@ -42,6 +43,7 @@ export const IssuesClasses = {
4243
NonLoadedEnv,
4344
ExternalEnvWithoutVersion,
4445
RemovedDependencies,
46+
RemovedEnv,
4547
DeprecatedDependencies,
4648
SelfReference,
4749
ImportFromDirectory,
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { ComponentIssue, ISSUE_FORMAT_SPACE } from './component-issue';
2+
3+
export class RemovedEnv extends ComponentIssue {
4+
description = 'the env of this component is deleted';
5+
solution =
6+
'use "bit env set/replace" to set a new env or a different version of this env. to undo the delete, run "bit recover"';
7+
data: string; // env id
8+
isTagBlocker = true;
9+
dataToString() {
10+
return ISSUE_FORMAT_SPACE + this.data;
11+
}
12+
}

e2e/harmony/custom-env.e2e.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,8 @@ describe('custom env', function () {
224224
});
225225

226226
(supportNpmCiRegistryTesting ? describe : describe.skip)('custom env installed as a package', () => {
227-
let envId;
228-
let envName;
227+
let envId: string;
228+
let envName: string;
229229
let npmCiRegistry: NpmCiRegistry;
230230
before(async () => {
231231
helper = new Helper({ scopesOptions: { remoteScopeWithDot: true } });
@@ -344,7 +344,27 @@ describe('custom env', function () {
344344
expect(isModified).to.be.true;
345345
});
346346
});
347+
describe('snapping the env on the lane and then deleting it', () => {
348+
before(() => {
349+
helper.scopeHelper.reInitLocalScope();
350+
helper.scopeHelper.addRemoteScope();
351+
helper.fixtures.populateComponents(1);
352+
helper.command.createLane();
353+
helper.command.importComponent(envName);
354+
helper.command.setEnv('comp1', envId);
355+
helper.command.snapAllComponentsWithoutBuild('--unmodified');
356+
helper.command.export();
347357

358+
helper.command.softRemoveOnLane(envId);
359+
});
360+
it('bit status should show the RemovedEnv issue', () => {
361+
helper.command.expectStatusToHaveIssue(IssuesClasses.RemovedEnv.name);
362+
});
363+
it('replacing the env should fix the issue', () => {
364+
helper.command.replaceEnv(envId, `${envId}@0.0.2`);
365+
helper.command.expectStatusToNotHaveIssue(IssuesClasses.RemovedEnv.name);
366+
});
367+
});
348368
describe('missing modules in the env capsule', () => {
349369
before(() => {
350370
helper.scopeHelper.reInitLocalScope();

scopes/component/remove/remove.main.runtime.ts

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,12 @@ ${mainComps.map((c) => c.id.toString()).join('\n')}`);
327327
return Boolean(isRemoved);
328328
}
329329

330+
async isEnvByIdWithoutLoadingComponent(componentId: ComponentID): Promise<boolean> {
331+
const versionObj = await this.workspace.scope.getBitObjectVersionById(componentId);
332+
const envData = versionObj?.extensions.findCoreExtension('teambit.envs/envs');
333+
return envData?.data.type === 'env';
334+
}
335+
330336
/**
331337
* get components that were soft-removed and tagged/snapped/merged but not exported yet.
332338
*/
@@ -342,16 +348,27 @@ ${mainComps.map((c) => c.id.toString()).join('\n')}`);
342348

343349
private async addRemovedDepIssue(component: Component) {
344350
const dependencies = this.depResolver.getComponentDependencies(component);
345-
const removedWithUndefined = await Promise.all(
351+
const removedDependencies: ComponentID[] = [];
352+
let removedEnv: ComponentID | undefined;
353+
await Promise.all(
346354
dependencies.map(async (dep) => {
347355
const isRemoved = await this.isRemovedByIdWithoutLoadingComponent(dep.componentId);
348-
if (isRemoved) return dep.componentId;
349-
return undefined;
356+
if (!isRemoved) return;
357+
const isEnv = await this.isEnvByIdWithoutLoadingComponent(dep.componentId);
358+
if (isEnv) {
359+
removedEnv = dep.componentId;
360+
} else {
361+
removedDependencies.push(dep.componentId);
362+
}
350363
})
351364
);
352-
const removed = compact(removedWithUndefined).map((id) => id.toString());
353-
if (removed.length) {
354-
component.state.issues.getOrCreate(IssuesClasses.RemovedDependencies).data = removed;
365+
if (removedDependencies.length) {
366+
component.state.issues.getOrCreate(IssuesClasses.RemovedDependencies).data = removedDependencies.map((r) =>
367+
r.toString()
368+
);
369+
}
370+
if (removedEnv) {
371+
component.state.issues.getOrCreate(IssuesClasses.RemovedEnv).data = removedEnv.toString();
355372
}
356373
}
357374

0 commit comments

Comments
 (0)