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

don't cache currentLaneId when a workspace is available #7944

Merged
merged 4 commits into from
Sep 21, 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
2 changes: 1 addition & 1 deletion scopes/pipelines/builder/builder.service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export class BuilderService implements EnvService<BuildServiceResults, string> {
previousTasksResults: [],
pipeName: this.displayPipeName,
dev: options.dev,
laneId: this.scope.legacyScope.currentLaneId,
laneId: this.scope.legacyScope.getCurrentLaneId(),
});
envsBuildContext[executionContext.id] = buildContext;
});
Expand Down
2 changes: 1 addition & 1 deletion scopes/scope/scope/scope.main.runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ export class ScopeMain implements ComponentFactory {
}

async getStagedConfig() {
const currentLaneId = this.legacyScope.currentLaneId;
const currentLaneId = this.legacyScope.getCurrentLaneId();
return StagedConfig.load(this.path, this.logger, currentLaneId);
}

Expand Down
9 changes: 6 additions & 3 deletions src/consumer/consumer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,12 @@ export default class Consumer {
return path.join(this.getPath(), BIT_WORKSPACE_TMP_DIRNAME);
}

getCurrentLaneIdIfExist() {
return this.bitMap.laneId;
}

getCurrentLaneId(): LaneId {
return this.bitMap.laneId || this.getDefaultLaneId();
return this.getCurrentLaneIdIfExist() || this.getDefaultLaneId();
}

getDefaultLaneId() {
Expand Down Expand Up @@ -167,7 +171,6 @@ export default class Consumer {

setCurrentLane(laneId: LaneId, exported = true) {
this.bitMap.setCurrentLane(laneId, exported);
this.scope.setCurrentLaneId(laneId);
}

async cleanTmpFolder() {
Expand Down Expand Up @@ -599,7 +602,7 @@ export default class Consumer {
scope,
});
await consumer.setBitMap();
scope.setCurrentLaneId(consumer.bitMap.laneId);
scope.currentLaneIdFunc = consumer.getCurrentLaneIdIfExist.bind(consumer);
logger.commandHistory.fileBasePath = scope.getPath();
return consumer;
}
Expand Down
19 changes: 16 additions & 3 deletions src/scope/scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,18 @@ export default class Scope {
_dependencyGraph: DependencyGraph; // cache DependencyGraph instance
lanes: Lanes;
/**
* important! never use this function directly, even inside this class. Only use getCurrentLaneId().
*
* normally, the data about the current-lane is saved in .bitmap. the reason for having this prop here is that we
* need this data when loading model-component, which gets called in multiple places where the consumer is not passed.
* another instance this is needed is for bit-sign, this way when loading aspects and fetching dists, it'll go to lane-scope.
*/
currentLaneId?: LaneId;
private currentLaneId?: LaneId;
/**
* when the consumer is available, this function is set with the consumer.getCurrentLaneIdIfExist, so then we guarantee
* that it's always in sync with the consumer.
*/
currentLaneIdFunc?: () => LaneId | undefined;
stagedSnaps: StagedSnaps;
constructor(scopeProps: ScopeProps) {
this.path = scopeProps.path;
Expand All @@ -138,6 +145,11 @@ export default class Scope {
await this.objects.reloadScopeIndexIfNeed(force);
}

getCurrentLaneId(): LaneId | undefined {
if (this.currentLaneIdFunc) return this.currentLaneIdFunc();
return this.currentLaneId;
}

async getDependencyGraph(): Promise<DependencyGraph> {
if (!this._dependencyGraph) {
this._dependencyGraph = await DependencyGraph.loadAllVersions(this);
Expand All @@ -163,7 +175,7 @@ export default class Scope {
setCurrentLaneId(laneId?: LaneId) {
if (!laneId) return;
if (laneId.isDefault()) this.currentLaneId = undefined;
this.currentLaneId = laneId;
else this.currentLaneId = laneId;
}

getPath() {
Expand Down Expand Up @@ -464,7 +476,8 @@ once done, to continue working, please run "bit cc"`
}

async getCurrentLaneObject(): Promise<Lane | null> {
return this.currentLaneId ? this.loadLane(this.currentLaneId) : null;
const currentLaneId = this.getCurrentLaneId();
return currentLaneId ? this.loadLane(currentLaneId) : null;
}

/**
Expand Down