import type { Dependency as LegacyDependency } from '@teambit/legacy.consumer-component'; import type { SourceFile } from '@teambit/component.sources'; import type { CLIMain } from '@teambit/cli'; import type { Component, ComponentMain } from '@teambit/component'; import type { EnvPolicyConfigObject } from '@teambit/dependency-resolver'; import type { GraphqlMain } from '@teambit/graphql'; import type { IssuesMain } from '@teambit/issues'; import type { EnvJsoncPatterns } from '@teambit/dev-files'; import type { Harmony, SlotRegistry } from '@teambit/harmony'; import type { Logger, LoggerMain } from '@teambit/logger'; import type { ExtensionDataList, ExtensionDataEntry } from '@teambit/legacy.extension-data'; import type { WorkerMain } from '@teambit/worker'; import { ComponentID } from '@teambit/component-id'; import type { EnvService } from './services'; import type { Environment } from './environment'; import { Runtime } from './runtime'; import { EnvDefinition } from './env-definition'; import { EnvServiceList } from './env-service-list'; import { EnvPlugin } from './env.plugin'; import { EnvJsoncDetector } from './env-jsonc.detector'; export type EnvJsonc = { extends?: string; policy?: EnvPolicyConfigObject; patterns?: EnvJsoncPatterns; }; /** * The resolved env jsonc is the env jsonc after it was resolved from all the parent envs */ export type ResolvedEnvJsonc = Omit; export type EnvJsoncMergeCustomizer = (parentObj: EnvJsonc, childObj: EnvJsonc) => Partial; export type EnvJsoncResolver = (parentId: string, envExtendsDeps?: LegacyDependency[]) => Promise; export type EnvsRegistry = SlotRegistry; export type EnvJsoncMergeCustomizerRegistry = SlotRegistry; export type EnvJsoncResolverRegistry = SlotRegistry; export type EnvsConfig = { env: string; options: EnvOptions; }; type GetCalcEnvOptions = { skipWarnings?: boolean; }; export type EnvOptions = {}; export type EnvTransformer = (env: Environment) => Environment; export type ServicesRegistry = SlotRegistry>>; export type RegularCompDescriptor = { id: string; icon?: string; type?: string; name?: string; description?: string; }; export type EnvCompDescriptorProps = RegularCompDescriptor & { resolvedEnvJsonc?: ResolvedEnvJsonc; services?: { env: { id: string; icon: string; name?: string; description?: string; }; services: Array<{ id: string; name?: string; description?: string; data: any; }>; }; }; export type EnvCompDescriptor = EnvCompDescriptorProps & { self?: EnvCompDescriptorProps; }; export type Descriptor = RegularCompDescriptor | EnvCompDescriptor; export declare const DEFAULT_ENV = "teambit.harmony/node"; export declare class EnvsMain { /** * environments extension configuration. */ readonly config: EnvsConfig; /** * harmony context. */ private harmony; /** * slot for allowing extensions to register new environment. */ private envSlot; private logger; private servicesRegistry; private componentMain; private loggerMain; private workerMain; private envJsoncMergeCustomizerSlot; private envJsoncResolverSlot; /** * Envs that are failed to load */ private failedToLoadEnvs; /** * Extensions that are failed to load * We use this as sometime when we couldn't load an extension we don't know if it's an env or not * We should ideally take it from the aspect loader aspect, but right now the aspect loader is using envs */ private failedToLoadExt; /** * Ids of envs (not neccesrraly loaded successfully) */ envIds: Set; static runtime: import("@teambit/harmony").RuntimeDefinition; private alreadyShownWarning; private coreAspectIds; /** * icon of the extension. */ icon(): string; constructor( /** * environments extension configuration. */ config: EnvsConfig, /** * harmony context. */ harmony: Harmony, /** * slot for allowing extensions to register new environment. */ envSlot: EnvsRegistry, logger: Logger, servicesRegistry: ServicesRegistry, componentMain: ComponentMain, loggerMain: LoggerMain, workerMain: WorkerMain, envJsoncMergeCustomizerSlot: EnvJsoncMergeCustomizerRegistry, envJsoncResolverSlot: EnvJsoncResolverRegistry); /** * creates a new runtime environments for a set of components. */ createEnvironment(components: Component[]): Promise; setCoreAspectIds(ids: string[]): void; isCoreAspect(id: string): boolean; /** * * @param id */ /** * This function adds an extension ID to a set of failed to load extensions. * This mostly used by the aspect loader to add such issues * Then it is used to hide different errors that are caused by the same issue. * @param {string} id - string - represents the unique identifier of an extension that failed to load. */ addFailedToLoadEnvs(id: string): void; addFailedToLoadExt(id: string): void; resetFailedToLoadEnvs(): void; getFailedToLoadEnvs(): string[]; /** * get the configured default env. */ getDefaultEnv(): EnvDefinition; getCoreEnvsIds(): string[]; /** * compose a new environment from a list of environment transformers. */ compose(targetEnv: Environment, envTransformers: EnvTransformer[]): Environment; /** * create an env transformer which overrides specific env properties. */ override(propsToOverride: Environment): EnvTransformer; /** * compose two environments into one. */ merge(targetEnv: Environment, sourceEnv: Environment): T & S; /** * This function checks if an environment manifest file exists in a given component or set of legacy files. * @param {Component} [envComponent] - A component object that represents an environment. It contains information about * the files and directories that make up the environment. * @param {SourceFile[]} [legacyFiles] - An optional array of SourceFile objects representing the files in the legacy * file system. If this parameter is not provided, the function will attempt to retrieve the files from the envComponent * parameter. * @returns a boolean value indicating whether an `env.jsonc` or `env.json` file exists in the `files` array of either * the `envComponent` object or the `legacyFiles` array. If neither `envComponent` nor `legacyFiles` are provided, the * function returns `undefined`. */ hasEnvManifest(envComponent?: Component, legacyFiles?: SourceFile[]): boolean | undefined; getEnvManifest(envComponent: Component): ResolvedEnvJsonc | undefined; getOrCalculateEnvManifest(component: Component, legacyFiles?: SourceFile[], envExtendsDeps?: LegacyDependency[]): Promise; calculateEnvManifest(envComponent?: Component, legacyFiles?: SourceFile[], envExtendsDeps?: LegacyDependency[]): Promise; recursivelyMergeWithParentManifest(object: EnvJsonc, envExtendsDeps?: LegacyDependency[]): Promise; mergeEnvManifests(parent: EnvJsonc, child: EnvJsonc): EnvJsonc; hasEnvManifestById(envId: string, requesting: string): Promise; getEnvData(component: Component): Descriptor; /** * Return the id of the env as configured in the envs data (without version by default) * The reason it's not contain version by default is that we want to take the version from the aspect defined on the component itself * As this version is stay up to date during tagging the env along with the component * @param component * @param ignoreVersion */ private getEnvIdFromEnvsData; /** * get the env id of the given component. */ getEnvId(component: Component): string; isUsingCoreEnv(component: Component): boolean; isCoreEnv(envId: string): boolean; /** * get the env of the given component. * In case you are asking for the env during on load you should use calculateEnv instead */ getEnv(component: Component): EnvDefinition; /** * get the env component of the given component. */ getEnvComponent(component: Component): Promise; /** * get the env component by the env id. */ getEnvComponentByEnvId(envId: string, requesting?: string): Promise; /** * get the env of the given component. * This will try to use the regular getEnv but fallback to the calculate env (in case you are using it during on load) * This is safe to be used on onLoad as well */ getOrCalculateEnv(component: Component): EnvDefinition; getOrCalculateEnvId(component: Component): Promise; /** * get an environment Descriptor. */ getDescriptor(component: Component): Descriptor | undefined; calcDescriptor(component: Component, opts?: GetCalcEnvOptions): Promise; /** * Get env descriptor from the env itself if the component is an env * This will be empty for regular component, and will only contain data for env themself */ private getEnvSelfDescriptor; /** * Get env descriptor from the env that a given component is using */ private getComponentEnvDescriptor; private getEnvDescriptorFromEnvDef; resolveEnv(component: Component, id: string): ComponentID | undefined; /** * This used to calculate the actual env during the component load. * Do not use it to get the env (use getEnv instead) * This should be used only during on load */ calculateEnvId(component: Component): Promise; /** * This used to calculate the actual env during the component load. * Do not use it to get the env (use getEnv instead) * This should be used only during on load */ calculateEnv(component: Component, opts?: GetCalcEnvOptions): EnvDefinition; /** * an env can be configured on a component in two ways: * 1) explicitly inside "teambit.envs/envs". `{ "teambit.envs/envs": { "env": "my-env" } }` * 2) the env aspect is set on the variant as any other aspect, e.g. `{ "my-env": {} }` * * this method returns #1 if exists, otherwise, #2. */ getAllEnvsConfiguredOnComponent(component: Component): EnvDefinition[]; /** * whether a component has an env configured (either by variant or .bitmap). */ hasEnvConfigured(component: Component): boolean; getAllRegisteredEnvsIds(): string[]; getAllRegisteredEnvs(): Environment[]; getAllRegisteredEnvJsoncCustomizers(): EnvJsoncMergeCustomizer[]; getAllRegisteredEnvJsoncResolvers(): EnvJsoncResolver[]; getEnvPlugin(): EnvPlugin; /** * an env can be configured on a component in two ways: * 1) explicitly inside "teambit.envs/envs". `{ "teambit.envs/envs": { "env": "my-env" } }` * 2) the env aspect is set on the variant as any other aspect, e.g. `{ "my-env": {} }` * * this method returns only #1 */ getEnvFromEnvsConfig(component: Component): EnvDefinition | undefined; /** * an env can be configured on a component in two ways: * 1) explicitly inside "teambit.envs/envs". `{ "teambit.envs/envs": { "env": "my-env" } }` * 2) the env aspect is set on the variant as any other aspect, e.g. `{ "my-env": {} }` * * this method returns only #2 */ getEnvsNotFromEnvsConfig(component: Component): EnvDefinition[]; getEnvIdFromEnvsLegacyExtensions(extensions: ExtensionDataList): string | undefined; /** * @deprecated DO NOT USE THIS METHOD ANYMORE!!! (PLEASE USE .calculateEnvId() instead!) */ calculateEnvIdFromExtensions(extensions: ExtensionDataList): Promise; validateEnvId(ext: ExtensionDataEntry): { errorMsg: string; minBitVersion: string; } | undefined; /** * @deprecated DO NOT USE THIS METHOD ANYMORE!!! (PLEASE USE .calculateEnv() instead!) */ calculateEnvFromExtensions(extensions: ExtensionDataList): Promise; /** * This function finds the first environment ID from a list of IDs by checking if it is register as env (to the slot). * or contains env.jsonc file * @param {string[]} ids - `ids` is an array of string values representing environment IDs. The function `findFirstEnv` * takes this array as input and returns a Promise that resolves to a string value representing the first environment ID * that matches certain conditions. * @returns The `findFirstEnv` function returns a Promise that resolves to a string or undefined. The string represents * the ID of the first environment that matches the conditions specified in the function, or undefined if no environment * is found. */ private findFirstEnv; private getEnvDefinitionByLegacyExtension; getEnvIdFromEnvsConfig(component: Component): string | undefined; getEnvDefinition(id: ComponentID): EnvDefinition | undefined; getEnvDefinitionById(id: ComponentID): EnvDefinition | undefined; getEnvDefinitionByStringId(envId: string): EnvDefinition | undefined; getEnvFromComponent(envComponent: Component): EnvDefinition | undefined; /** * Return the env definition of teambit.envs/env */ getEnvsEnvDefinition(): EnvDefinition; private printWarningIfFirstTime; /** * determines whether an env is registered. */ isEnvRegistered(id: string): boolean; isUsingAspectEnv(component: Component): boolean; isUsingEnvEnv(component: Component): boolean; /** * Check if the given component is an env component. * @param component * @returns */ isEnv(component: Component): boolean; /** * register a new environment service. */ registerService(...envServices: EnvService[]): this; /** * get list of services enabled on an env. */ getServices(env: EnvDefinition): Promise; implements(env: EnvDefinition, service: EnvService): Promise; /** * register an environment. */ registerEnv(env: Environment): void; /** * register an env.jsonc merge customizer. */ registerEnvJsoncMergeCustomizer(customizer: EnvJsoncMergeCustomizer): void; registerEnvJsoncResolver(resolver: EnvJsoncResolver): void; getEnvJsoncDetector(): EnvJsoncDetector; addNonLoadedEnvAsComponentIssues(components: Component[]): Promise; private createRuntime; private aggregateByDefs; private getEnvAspectDef; private throwForDuplicateComponents; static slots: (((registerFn: () => string) => SlotRegistry) | ((registerFn: () => string) => SlotRegistry>) | ((registerFn: () => string) => SlotRegistry) | ((registerFn: () => string) => SlotRegistry))[]; static dependencies: import("@teambit/harmony").Aspect[]; static provider([graphql, loggerAspect, component, cli, worker, issues]: [ GraphqlMain, LoggerMain, ComponentMain, CLIMain, WorkerMain, IssuesMain ], config: EnvsConfig, [envSlot, servicesRegistry, envJsoncMergeCustomizerSlot, envJsoncResolverSlot]: [ EnvsRegistry, ServicesRegistry, EnvJsoncMergeCustomizerRegistry, EnvJsoncResolverRegistry ], context: Harmony): Promise; } export {};