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(out-of-sync): recreate a lane if local scope got deleted and is new #7329

Merged
merged 4 commits into from
May 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
13 changes: 13 additions & 0 deletions e2e/harmony/out-of-sync-components-harmony.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,17 @@ describe('components that are not synced between the scope and the consumer', fu
expect(bitmap.comp1.version).to.equal('0.0.1');
});
});
describe('new lane got deleted', () => {
before(() => {
helper.scopeHelper.setNewLocalAndRemoteScopes();
helper.fixtures.populateComponents(1, false);
helper.command.createLane();
helper.command.snapAllComponentsWithoutBuild();
helper.fs.deletePath('.bit');
helper.scopeHelper.addRemoteScope();
});
it('should recrate the lane', () => {
expect(() => helper.command.showOneLane('dev')).to.not.throw();
});
});
});
16 changes: 16 additions & 0 deletions scopes/lanes/lanes/lanes.main.runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,19 @@ please create a new lane instead, which will include all components of this lane
};
}

private async recreateNewLaneIfDeleted() {
if (!this.workspace) return;
const laneId = this.getCurrentLaneId();
if (!laneId || laneId.isDefault() || this.workspace.consumer.bitMap.isLaneExported) {
return;
}
const laneObj = await this.scope.legacyScope.getCurrentLaneObject();
if (laneObj) {
return;
}
await this.createLane(laneId.name, { scope: laneId.scope });
}

async addLaneReadme(readmeComponentIdStr: string, laneName?: string): Promise<{ result: boolean; message?: string }> {
if (!this.workspace) {
throw new BitError(`unable to track a lane readme component outside of Bit workspace`);
Expand Down Expand Up @@ -951,6 +964,9 @@ please create a new lane instead, which will include all components of this lane
new LaneImportCmd(switchCmd),
];
cli.register(laneCmd, switchCmd);
cli.registerOnStart(async () => {
await lanesMain.recreateNewLaneIfDeleted();
});
graphql.register(lanesSchema(lanesMain));
express.register([
new LanesCreateRoute(lanesMain, logger),
Expand Down
12 changes: 2 additions & 10 deletions src/consumer/bit-map/bit-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,8 @@ export default class BitMap {
let isLaneExported = false;
let laneId: LaneId | undefined;
if (componentsJson[LANE_KEY]) {
if (componentsJson[LANE_KEY].name) {
// backward compatibility
throw new Error(
`enable to migrate to the new Lane format of .bitmap. change to the previous Bit version, switch to main, then upgrade again`
);
} else {
laneId = new LaneId(componentsJson[LANE_KEY].id);
isLaneExported = componentsJson[LANE_KEY].exported;
}
laneId = new LaneId(componentsJson[LANE_KEY].id);
isLaneExported = componentsJson[LANE_KEY].exported;
}
BitMap.removeNonComponentFields(componentsJson);

Expand Down Expand Up @@ -232,7 +225,6 @@ export default class BitMap {
};
if (resetHard) {
deleteBitMapFile();
// @todo: delete workspace lanes as well? maybe they're already taken care of within scope.reset
return;
}
try {
Expand Down
13 changes: 0 additions & 13 deletions src/consumer/consumer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,19 +335,6 @@ export default class Consumer {
return this.componentLoader.loadMany(ids, throwOnFailure, loadOpts);
}

async shouldDependenciesSavedAsComponents(bitIds: BitId[], saveDependenciesAsComponents?: boolean) {
if (saveDependenciesAsComponents === undefined) {
saveDependenciesAsComponents = this.config._saveDependenciesAsComponents;
}
const shouldDependenciesSavedAsComponents = bitIds.map((bitId: BitId) => {
return {
id: bitId, // if it doesn't go to the hub, it can't import dependencies as packages
saveDependenciesAsComponents: false,
};
});
return shouldDependenciesSavedAsComponents;
}

async listComponentsForAutoTagging(modifiedComponents: BitIds): Promise<Component[]> {
return getAutoTagPending(this, modifiedComponents);
}
Expand Down