UNPKG

@teambit/workspace

Version:
117 lines (116 loc) 4.8 kB
import type { Component, InvalidComponent } from '@teambit/component'; import type { ComponentID } from '@teambit/component-id'; import type { ComponentLoadOptions as LegacyComponentLoadOptions } from '@teambit/legacy.consumer-component'; import { ConsumerComponent } from '@teambit/legacy.consumer-component'; import type { DependencyResolverMain } from '@teambit/dependency-resolver'; import type { Logger } from '@teambit/logger'; import type { EnvsMain } from '@teambit/envs'; import type { AspectLoaderMain } from '@teambit/aspect-loader'; import type { Workspace } from '../workspace'; type GetManyRes = { components: Component[]; invalidComponents: InvalidComponent[]; }; export type ComponentLoadOptions = LegacyComponentLoadOptions & { loadExtensions?: boolean; executeLoadSlot?: boolean; idsToNotLoadAsAspects?: string[]; loadSeedersAsAspects?: boolean; resolveExtensionsVersions?: boolean; }; type ComponentGetOneOptions = { resolveIdVersion?: boolean; }; export type LoadCompAsAspectsOptions = { /** * In case the component we are loading is app, whether to load it as app (in a scope aspects capsule) */ loadApps?: boolean; /** * In case the component we are loading is env, whether to load it as env (in a scope aspects capsule) */ loadEnvs?: boolean; /** * In case the component we are loading is a regular aspect, whether to load it as aspect (in a scope aspects capsule) */ loadAspects?: boolean; idsToNotLoadAsAspects?: string[]; /** * Are this core aspects */ core?: boolean; /** * Are this aspects seeders of the load many operation */ seeders?: boolean; }; export declare class WorkspaceComponentLoader { private workspace; private logger; private dependencyResolver; private envs; private aspectLoader; private componentsCache; /** * Cache components that loaded from scope (especially for get many for perf improvements) */ private scopeComponentsCache; /** * Cache extension list for components. used by get many for perf improvements. * And to make sure we load extensions first. */ private componentsExtensionsCache; private componentLoadedSelfAsAspects; constructor(workspace: Workspace, logger: Logger, dependencyResolver: DependencyResolverMain, envs: EnvsMain, aspectLoader: AspectLoaderMain); getMany(ids: Array<ComponentID>, loadOpts?: ComponentLoadOptions, throwOnFailure?: boolean): Promise<GetManyRes>; private getAndLoadSlotOrdered; private buildLoadGroups; /** * This function will get a list of envs ids and will regroup them into two groups: * 1. envs that are envs of envs from the group * 2. other envs (envs which are just envs of regular components of the workspace) * For Example: * envsIds: [ReactEnv, NodeEnv, BitEnv] * The env of ReactEnv and NodeEnv is BitEnv * The result will be: * [ [BitEnv], [ReactEnv, NodeEnv] ] * * At the moment this function is not recursive, in the future we might want to make it recursive * @param envIds * @param envsIdsOfWsComps * @returns */ private regroupEnvsIdsFromTheList; private regroupExtIdsFromTheList; private getAndLoadSlot; loadCompsAsAspects(components: Component[], opts?: LoadCompAsAspectsOptions): Promise<void>; private populateScopeAndExtensionsCache; private warnAboutMisconfiguredEnvs; private groupAndUpdateIds; private isInWsIncludeDeleted; private getComponentsWithoutLoadExtensions; getInvalid(ids: Array<ComponentID>): Promise<InvalidComponent[]>; get(componentId: ComponentID, legacyComponent?: ConsumerComponent, useCache?: boolean, storeInCache?: boolean, loadOpts?: ComponentLoadOptions, getOpts?: ComponentGetOneOptions): Promise<Component>; getIfExist(componentId: ComponentID): Promise<Component | undefined>; private resolveVersion; private addMultipleEnvsIssueIfNeeded; clearCache(): void; clearComponentCache(id: ComponentID): void; private loadOne; private saveInCache; /** * make sure that not only the id-str match, but also the legacy-id. * this is needed because the ComponentID.toString() is the same whether or not the legacy-id has * scope-name, as it includes the defaultScope if the scope is empty. * as a result, when out-of-sync is happening and the id is changed to include scope-name in the * legacy-id, the component is the cache has the old id. */ private getFromCache; private getConsumerComponent; private isComponentNotExistsError; private executeLoadSlot; private newComponentFromState; private upsertExtensionData; private getDataEntry; } export {};