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(snap), save app data during snap/tag #9037

Merged
merged 5 commits into from
Jul 16, 2024
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
18 changes: 14 additions & 4 deletions scopes/component/snapping/snapping.main.runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import {
getComponentsWithOptionToUntag,
removeLocalVersionsForMultipleComponents,
} from './reset-component';
import { ApplicationAspect, ApplicationMain } from '@teambit/application';

export type TagDataPerComp = {
componentId: ComponentID;
Expand Down Expand Up @@ -122,7 +123,8 @@ export class SnappingMain {
private exporter: ExportMain,
private builder: BuilderMain,
private importer: ImporterMain,
private deps: DependenciesMain
private deps: DependenciesMain,
private application: ApplicationMain
) {
this.objectsRepo = this.scope?.legacyScope?.objects;
}
Expand Down Expand Up @@ -1018,13 +1020,17 @@ another option, in case this dependency is not in main yet is to remove all refe
}

private async loadComponentsForTagOrSnap(ids: ComponentIdList, shouldClearCacheFirst = true): Promise<Component[]> {
const idsWithoutVersions = ids.map((id) => id.changeVersion(undefined));
const appIds = await this.application.loadAllAppsAsAspects(idsWithoutVersions);
if (shouldClearCacheFirst) {
await this.workspace.consumer.componentFsCache.deleteAllDependenciesDataCache();
// don't clear only the cache of these ids. we need also the auto-tag. so it's safer to just clear all.
this.workspace.clearAllComponentsCache();
} else {
appIds.forEach((id) => this.workspace.clearComponentCache(id));
}

return this.workspace.getMany(ids.map((id) => id.changeVersion(undefined)));
return this.workspace.getMany(idsWithoutVersions);
}

private throwForPendingImport(components: ConsumerComponent[]) {
Expand Down Expand Up @@ -1244,6 +1250,7 @@ another option, in case this dependency is not in main yet is to remove all refe
ImporterAspect,
GlobalConfigAspect,
DependenciesAspect,
ApplicationAspect,
];
static runtime = MainRuntime;
static async provider([
Expand All @@ -1259,6 +1266,7 @@ another option, in case this dependency is not in main yet is to remove all refe
importer,
globalConfig,
deps,
application,
]: [
Workspace,
CLIMain,
Expand All @@ -1271,7 +1279,8 @@ another option, in case this dependency is not in main yet is to remove all refe
BuilderMain,
ImporterMain,
GlobalConfigMain,
DependenciesMain
DependenciesMain,
ApplicationMain
]) {
const logger = loggerMain.createLogger(SnappingAspect.id);
const snapping = new SnappingMain(
Expand All @@ -1284,7 +1293,8 @@ another option, in case this dependency is not in main yet is to remove all refe
exporter,
builder,
importer,
deps
deps,
application
);
const snapCmd = new SnapCmd(snapping, logger, globalConfig);
const tagCmd = new TagCmd(snapping, logger, globalConfig);
Expand Down
19 changes: 14 additions & 5 deletions scopes/harmony/application/application.main.runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,13 @@ export class ApplicationMain {
/**
* instead of adding apps to workspace.jsonc, this method gets all apps components and load them as aspects so then
* they could register to the apps slots and be available to list/run etc.
* if poolIds is provided, it will load only the apps that are part of the pool.
*/
async loadAllAppsAsAspects() {
const apps = await this.listAppsComponents();
await this.componentAspect.getHost().loadAspects(apps.map((a) => a.id.toString()));
async loadAllAppsAsAspects(poolIds?: ComponentID[]): Promise<ComponentID[]> {
const apps = await this.listAppsComponents(poolIds);
const appIds = apps.map((app) => app.id);
await this.componentAspect.getHost().loadAspects(appIds.map((id) => id.toString()));
return appIds;
}

/**
Expand Down Expand Up @@ -162,8 +165,14 @@ export class ApplicationMain {
return this.listAppsComponents();
}

async listAppsComponents(): Promise<Component[]> {
const components = await this.componentAspect.getHost().list();
/**
* list all components that are apps.
* if poolIds is provided, it will load only the apps that are part of the pool.
*/
async listAppsComponents(poolIds?: ComponentID[]): Promise<Component[]> {
const components = poolIds
? await this.componentAspect.getHost().getMany(poolIds)
: await this.componentAspect.getHost().list();
const appTypesPatterns = this.getAppPatterns();
const appsComponents = components.filter((component) => this.hasAppTypePattern(component, appTypesPatterns));
return appsComponents;
Expand Down