From e742b548eb273ada61e6c63d16c5c7055ab5b251 Mon Sep 17 00:00:00 2001 From: David First Date: Tue, 16 Jul 2024 09:22:00 -0400 Subject: [PATCH 1/2] fix(snap), save app data during snap/tag --- .../snapping/snapping.main.runtime.ts | 15 ++++++++++++--- .../application/application.main.runtime.ts | 19 ++++++++++++++----- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/scopes/component/snapping/snapping.main.runtime.ts b/scopes/component/snapping/snapping.main.runtime.ts index 8a62c72da3f4..9cae6cf5de20 100644 --- a/scopes/component/snapping/snapping.main.runtime.ts +++ b/scopes/component/snapping/snapping.main.runtime.ts @@ -59,6 +59,7 @@ import { getComponentsWithOptionToUntag, removeLocalVersionsForMultipleComponents, } from './reset-component'; +import { ApplicationAspect, ApplicationMain } from '@teambit/application'; export type TagDataPerComp = { componentId: ComponentID; @@ -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; } @@ -1018,10 +1020,13 @@ another option, in case this dependency is not in main yet is to remove all refe } private async loadComponentsForTagOrSnap(ids: ComponentIdList, shouldClearCacheFirst = true): Promise { + const appIds = await this.application.loadAllAppsAsAspects(ids); 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))); @@ -1244,6 +1249,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([ @@ -1259,6 +1265,7 @@ another option, in case this dependency is not in main yet is to remove all refe importer, globalConfig, deps, + application, ]: [ Workspace, CLIMain, @@ -1271,7 +1278,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( @@ -1284,7 +1292,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); diff --git a/scopes/harmony/application/application.main.runtime.ts b/scopes/harmony/application/application.main.runtime.ts index e273dc2de481..4cfe39f7d3a2 100644 --- a/scopes/harmony/application/application.main.runtime.ts +++ b/scopes/harmony/application/application.main.runtime.ts @@ -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 { + 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; } /** @@ -162,8 +165,14 @@ export class ApplicationMain { return this.listAppsComponents(); } - async listAppsComponents(): Promise { - 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 { + 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; From 07bf0a88bbae1ad18d0214f2d9ad11875781ba2c Mon Sep 17 00:00:00 2001 From: David First Date: Tue, 16 Jul 2024 13:13:30 -0400 Subject: [PATCH 2/2] fix tests --- scopes/component/snapping/snapping.main.runtime.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scopes/component/snapping/snapping.main.runtime.ts b/scopes/component/snapping/snapping.main.runtime.ts index 9cae6cf5de20..c4256e8a6a3a 100644 --- a/scopes/component/snapping/snapping.main.runtime.ts +++ b/scopes/component/snapping/snapping.main.runtime.ts @@ -1020,7 +1020,8 @@ another option, in case this dependency is not in main yet is to remove all refe } private async loadComponentsForTagOrSnap(ids: ComponentIdList, shouldClearCacheFirst = true): Promise { - const appIds = await this.application.loadAllAppsAsAspects(ids); + 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. @@ -1029,7 +1030,7 @@ another option, in case this dependency is not in main yet is to remove all refe 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[]) {