diff --git a/scopes/component/snapping/snapping.main.runtime.ts b/scopes/component/snapping/snapping.main.runtime.ts index 8a62c72da3f4..c4256e8a6a3a 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,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 { + 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[]) { @@ -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([ @@ -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, @@ -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( @@ -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); 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;