Skip to content

Commit

Permalink
refactor, change workspace.listIds() to not be a promise (#8606)
Browse files Browse the repository at this point in the history
It's not really a promise. Fix it to remove the Promise from the return
type.
  • Loading branch information
davidfirst authored Mar 1, 2024
1 parent 0732531 commit c79e33d
Show file tree
Hide file tree
Showing 19 changed files with 27 additions and 30 deletions.
2 changes: 1 addition & 1 deletion scopes/component/component/component-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export interface ComponentFactory {
*/
listInvalid(): Promise<InvalidComponent[]>;

listIds(): Promise<ComponentID[]>;
listIds(): Promise<ComponentID[]> | ComponentID[];

/**
* get component-ids matching the given pattern. a pattern can have multiple patterns separated by a comma.
Expand Down
2 changes: 1 addition & 1 deletion scopes/component/forking/forking.main.runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ export class ForkingMain {
const idsFromOriginalScope = patternWithScopeName
? await this.workspace.scope.filterIdsFromPoolIdsByPattern(patternWithScopeName, allIdsFromOriginalScope)
: allIdsFromOriginalScope;
const workspaceIds = await this.workspace.listIds();
const workspaceIds = this.workspace.listIds();
const workspaceBitIds = ComponentIdList.fromArray(workspaceIds.map((id) => id));
idsFromOriginalScope.forEach((id) => {
const existInWorkspace = workspaceBitIds.searchWithoutVersion(id);
Expand Down
2 changes: 1 addition & 1 deletion scopes/component/merging/merge-status-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ other: ${otherLaneHead.toString()}`);
const otherLabel = `${otherLaneHead.toString()} (${
otherLaneName === currentLaneName ? 'incoming' : otherLaneName
})`;
const workspaceIds = (await this.workspace?.listIds()) || this.currentLane?.toComponentIds() || [];
const workspaceIds = this.workspace?.listIds() || this.currentLane?.toComponentIds() || [];
const configMerger = new ComponentConfigMerger(
id.toStringWithoutVersion(),
workspaceIds,
Expand Down
2 changes: 1 addition & 1 deletion scopes/component/remove/remove.main.runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ ${mainComps.map((c) => c.id.toString()).join('\n')}`);
const currentLane = await this.workspace.getCurrentLaneObject();
if (!currentLane) return [];
const laneIds = currentLane.toComponentIds();
const workspaceIds = await this.workspace.listIds();
const workspaceIds = this.workspace.listIds();
const laneCompIdsNotInWorkspace = laneIds.filter(
(id) => !workspaceIds.find((wId) => wId.isEqualWithoutVersion(id))
);
Expand Down
4 changes: 2 additions & 2 deletions scopes/component/renaming/renaming.main.runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ make sure this argument is the name only, without the scope-name. to change the
newScope: string,
options: { refactor?: boolean; deprecate?: boolean } = {}
): Promise<RenameResult> {
const allComponentsIds = await this.workspace.listIds();
const allComponentsIds = this.workspace.listIds();
const componentsUsingOldScope = allComponentsIds.filter((compId) => compId.scope === oldScope);
if (!componentsUsingOldScope.length && this.workspace.defaultScope !== oldScope) {
throw new OldScopeNotFound(oldScope);
Expand Down Expand Up @@ -222,7 +222,7 @@ make sure this argument is the name only, without the scope-name. to change the
): Promise<RenameResult> {
const isScopeUsesOldOwner = (scope: string) => scope.startsWith(`${oldOwner}.`);

const allComponentsIds = await this.workspace.listIds();
const allComponentsIds = this.workspace.listIds();
const componentsUsingOldScope = allComponentsIds.filter((compId) => isScopeUsesOldOwner(compId.scope));
if (!componentsUsingOldScope.length && !isScopeUsesOldOwner(this.workspace.defaultScope)) {
throw new OldScopeNotFound(oldOwner);
Expand Down
4 changes: 1 addition & 3 deletions scopes/component/stash/stash.main.runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ export class StashMain {
}

async save(options: { message?: string; pattern?: string }): Promise<ComponentID[]> {
const compIds = options?.pattern
? await this.workspace.idsByPattern(options?.pattern)
: await this.workspace.listIds();
const compIds = options?.pattern ? await this.workspace.idsByPattern(options?.pattern) : this.workspace.listIds();
const comps = await this.workspace.getMany(compIds);
const modifiedComps = compact(
await Promise.all(
Expand Down
2 changes: 1 addition & 1 deletion scopes/component/status/status.main.runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export class StatusMain {
}

async statusMini(componentPattern?: string, opts: MiniStatusOpts = {}): Promise<MiniStatusResults> {
const ids = componentPattern ? await this.workspace.idsByPattern(componentPattern) : await this.workspace.listIds();
const ids = componentPattern ? await this.workspace.idsByPattern(componentPattern) : this.workspace.listIds();
const compFiles = await pMapSeries(ids, (id) => this.workspace.getFilesModification(id));
const modified: ComponentID[] = [];
const newComps: ComponentID[] = [];
Expand Down
6 changes: 3 additions & 3 deletions scopes/harmony/api-server/api-for-ide.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export class APIForIDE {
}

async listIdsWithPaths() {
const ids = await this.workspace.listIds();
const ids = this.workspace.listIds();
return ids.reduce((acc, id) => {
acc[id.toStringWithoutVersion()] = this.workspace.componentDir(id);
return acc;
Expand Down Expand Up @@ -357,7 +357,7 @@ export class APIForIDE {
}

async getDataToInitSCM(): Promise<DataToInitSCM> {
const ids = await this.workspace.listIds();
const ids = this.workspace.listIds();
const results: DataToInitSCM = {};
await pMap(
ids,
Expand All @@ -384,7 +384,7 @@ export class APIForIDE {
}

async getCompFilesDirPathFromLastSnapForAllComps(): Promise<{ [relativePath: string]: string }> {
const ids = await this.workspace.listIds();
const ids = this.workspace.listIds();
let results = {};
await pMap(
ids,
Expand Down
2 changes: 1 addition & 1 deletion scopes/harmony/aspect/aspect.main.runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export class AspectMain {
);
}
}
const allCompIds = pattern ? await this.workspace.idsByPattern(pattern) : await this.workspace.listIds();
const allCompIds = pattern ? await this.workspace.idsByPattern(pattern) : this.workspace.listIds();
const allComps = await this.workspace.getMany(allCompIds);
const alreadyUpToDate: ComponentID[] = [];
const updatedComponentIds = await Promise.all(
Expand Down
6 changes: 3 additions & 3 deletions scopes/lanes/merge-lanes/merge-lanes.main.runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ export class MergeLanesMain {
});
}
if (existingOnWorkspaceOnly && this.workspace) {
const workspaceIds = await this.workspace.listIds();
const workspaceIds = this.workspace.listIds();
const compIdsFromPattern = workspaceIds.filter((id) =>
allComponentsStatus.find((c) => c.id.isEqualWithoutVersion(id))
);
Expand Down Expand Up @@ -291,7 +291,7 @@ export class MergeLanesMain {

let checkoutResults: ApplyVersionResults | undefined;
let checkoutError: Error | undefined;
checkoutProps.ids = await this.workspace.listIds();
checkoutProps.ids = this.workspace.listIds();
checkoutProps.restoreMissingComponents = true;
try {
checkoutResults = await this.checkout.checkout(checkoutProps);
Expand Down Expand Up @@ -322,7 +322,7 @@ export class MergeLanesMain {
if (!this.workspace) {
throw new BitError(`getMainIdsToMerge needs workspace`);
}
const workspaceIds = await this.workspace.listIds();
const workspaceIds = this.workspace.listIds();
const mainNotOnLane = workspaceIds.filter(
(id) => !laneIds.find((laneId) => laneId.isEqualWithoutVersion(id)) && this.scope.isExported(id)
);
Expand Down
2 changes: 1 addition & 1 deletion scopes/scope/export/export.main.runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ if the export fails with missing objects/versions/components, run "bit fetch --l
});
if (laneObject) await updateLanesAfterExport(consumer, laneObject);
const removedIds = await this.getRemovedStagedBitIds();
const workspaceIds = await this.workspace.listIds();
const workspaceIds = this.workspace.listIds();
const nonExistOnBitMap = exported.filter(
(id) => !workspaceIds.hasWithoutVersion(id) && !removedIds.hasWithoutVersion(id)
);
Expand Down
2 changes: 1 addition & 1 deletion scopes/scope/importer/dependents-getter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class DependentsGetter {
this.logger.setStatusLine('finding dependents');
const { silent } = this.options;
const graph = await this.graph.getGraphIds();
const sourceIds = await this.workspace.listIds();
const sourceIds = this.workspace.listIds();
const getIdsForThrough = () => {
if (!this.options.dependentsVia) return undefined;
return this.options.dependentsVia
Expand Down
2 changes: 1 addition & 1 deletion scopes/workspace/install/install.main.runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ export class InstallMain {
}

private async _getComponentsWithDependencyPolicies() {
const allComponentIds = await this.workspace.listIds();
const allComponentIds = this.workspace.listIds();
const componentPolicies = [] as Array<{ componentId: ComponentID; policy: any }>;
(
await Promise.all<ComponentConfigFile | undefined>(
Expand Down
2 changes: 1 addition & 1 deletion scopes/workspace/watcher/watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ export class Watcher {
if (!(await this.workspace.hasId(componentId))) {
// bitmap has changed meanwhile, which triggered `handleBitmapChanges`, which re-loaded consumer and updated versions
// so the original componentId might not be in the workspace now, and we need to find the updated one
const ids = await this.workspace.listIds();
const ids = this.workspace.listIds();
updatedComponentId = ids.find((id) => id.isEqual(componentId, { ignoreVersion: true }));
if (!updatedComponentId) {
logger.debug(`triggerCompChanges, the component ${componentId.toString()} was probably removed from .bitmap`);
Expand Down
2 changes: 1 addition & 1 deletion scopes/workspace/workspace/aspects-merger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ export class AspectsMerger {
if (envFromEnvsAspect && (origin === 'ModelNonSpecific' || origin === 'ModelSpecific')) {
// if env was found, search for this env in the workspace and if found, replace the env-id with the one from the workspace
const envAspectExt = extensionDataList.find((e) => e.extensionId?.toStringWithoutVersion() === envFromEnvsAspect);
const ids = await this.workspace.listIds();
const ids = this.workspace.listIds();
const envAspectId = envAspectExt?.extensionId;
const found = envAspectId && ids.find((id) => id.isEqualWithoutVersion(envAspectId));
if (found) {
Expand Down
2 changes: 1 addition & 1 deletion scopes/workspace/workspace/build-graph-from-fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export class GraphFromFsBuilder {
* that all its flattened dependencies are there. no need to call importMany again for them.
*/
private async importObjects(components: Component[]) {
const workspaceIds = await this.workspace.listIds();
const workspaceIds = this.workspace.listIds();
const compOnWorkspaceOnly = components.filter((comp) => workspaceIds.find((id) => id.isEqual(comp.id)));
const allDeps = (await Promise.all(compOnWorkspaceOnly.map((c) => this.getAllDepsUnfiltered(c)))).flat();
const allDepsNotImported = allDeps.filter((d) => !this.importedIds.includes(d.toString()));
Expand Down
4 changes: 2 additions & 2 deletions scopes/workspace/workspace/build-graph-ids-from-fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export class GraphIdsFromFsBuilder {
* once a component from scope is imported, we know that either we have its dependency graph or all flattened deps
*/
private async importObjects(components: Component[]) {
const workspaceIds = await this.workspace.listIds();
const workspaceIds = this.workspace.listIds();
const compOnWorkspaceOnly = components.filter((comp) => workspaceIds.find((id) => id.isEqual(comp.id)));
const notImported = compOnWorkspaceOnly.map((c) => c.id).filter((id) => !this.importedIds.includes(id.toString()));
const exportedDeps = notImported.filter((dep) => this.workspace.isExported(dep));
Expand Down Expand Up @@ -136,7 +136,7 @@ export class GraphIdsFromFsBuilder {
component: Component
): Promise<Component[]> {
const deps = await this.dependencyResolver.getComponentDependencies(component);
const workspaceIds = await this.workspace.listIds();
const workspaceIds = this.workspace.listIds();
const [depsInScopeGraph, depsNotInScopeGraph] = partition(
deps,
(dep) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ export class WorkspaceComponentLoader {
}

private async isInWsIncludeDeleted(componentId: ComponentID): Promise<boolean> {
const nonDeletedWsIds = await this.workspace.listIds();
const nonDeletedWsIds = this.workspace.listIds();
const deletedWsIds = await this.workspace.locallyDeletedIds();
const allWsIds = nonDeletedWsIds.concat(deletedWsIds);
const inWs = allWsIds.find((id) => id.isEqual(componentId, { ignoreVersion: !componentId.hasVersion() }));
Expand Down
7 changes: 3 additions & 4 deletions scopes/workspace/workspace/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -395,9 +395,8 @@ export class Workspace implements ComponentFactory {

/**
* get ids of all workspace components.
* @todo: remove the "async", it's not a promise anymore.
*/
async listIds(): Promise<ComponentIdList> {
listIds(): ComponentIdList {
if (this._cachedListIds && this.bitMap.hasChanged()) {
delete this._cachedListIds;
}
Expand Down Expand Up @@ -470,7 +469,7 @@ export class Workspace implements ComponentFactory {
}

async newComponentIds(): Promise<ComponentID[]> {
const allIds = await this.listIds();
const allIds = this.listIds();
return allIds.filter((id) => !id.hasVersion());
}

Expand All @@ -487,7 +486,7 @@ export class Workspace implements ComponentFactory {
* @deprecated use `listIds()` instead.
* get all workspace component-ids
*/
getAllComponentIds(): Promise<ComponentID[]> {
getAllComponentIds(): ComponentID[] {
return this.listIds();
}

Expand Down

0 comments on commit c79e33d

Please sign in to comment.