Skip to content

Commit

Permalink
fix(out-of-sync): recreate a lane if local scope got deleted and is n…
Browse files Browse the repository at this point in the history
…ew (#7329)

Currently, in this case, the .bitmap still has the lane-id but the scope
doesn't have the lane object, so the user might be under impression that
the workspace is checked out to a lane. Snap command doesn't throw and
is snapped on main. Once the user is trying to export, an error is
thrown about missing lane object.
This PR re-create the lane in this case. since the .bitmap has the full
lane-id, the data to recreate the lane exists and it's possible to do.
  • Loading branch information
davidfirst authored May 3, 2023
1 parent f0ec708 commit fae8013
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 23 deletions.
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

0 comments on commit fae8013

Please sign in to comment.