import type { Component, ComponentMap, ComponentMain, IComponent } from '@teambit/component'; import type { ConfigMain } from '@teambit/config'; import type { DependenciesEnv, EnvDefinition, EnvJsonc, EnvsMain } from '@teambit/envs'; import type { SlotRegistry, ExtensionManifest, Aspect } from '@teambit/harmony'; import type { RequireableComponent } from '@teambit/harmony.modules.requireable-component'; import type { LoggerMain, Logger } from '@teambit/logger'; import type { GraphqlMain } from '@teambit/graphql'; import { ExtensionDataList } from '@teambit/legacy.extension-data'; import type { ProxyConfig, NetworkConfig } from '@teambit/scope.network'; import type { Dependency as LegacyDependency } from '@teambit/legacy.consumer-component'; import { ConsumerComponent as LegacyComponent } from '@teambit/legacy.consumer-component'; import { ComponentID } from '@teambit/component-id'; import type { SourceFile } from '@teambit/component.sources'; import type { ProjectManifest, DependencyManifest } from '@pnpm/types'; import { SemVer } from 'semver'; import type { AspectLoaderMain } from '@teambit/aspect-loader'; import type { Registries } from '@teambit/pkg.entities.registry'; import type { UpdatedComponent } from './apply-updates'; import type { PreInstallSubscriberList, PostInstallSubscriberList, DepInstallerContext } from './dependency-installer'; import { DependencyInstaller } from './dependency-installer'; import { DependencyVersionResolver } from './dependency-version-resolver'; import type { DepLinkerContext, LinkingOptions } from './dependency-linker'; import { DependencyLinker } from './dependency-linker'; import type { ComponentRangePrefix, DependencyResolverWorkspaceConfig, NodeLinker } from './dependency-resolver-workspace-config'; import type { CurrentPkg, OutdatedPkg, CurrentPkgSource } from './get-all-policy-pkgs'; import type { CreateFromComponentsOptions, WorkspaceManifest, ManifestDependenciesObject } from './manifest'; import type { WorkspacePolicyConfigObject, VariantPolicyConfigObject, WorkspacePolicyAddEntryOptions, WorkspacePolicyEntry, SerializedVariantPolicy } from './policy'; import { WorkspacePolicy, VariantPolicy } from './policy'; import type { PackageManager, PackageManagerGetPeerDependencyIssuesOptions } from './package-manager'; import type { SerializedDependency, DependencyFactory, ComponentDependency } from './dependencies'; import { DependencyList } from './dependencies'; import type { DependencyDetector } from './detector-hook'; import { EnvPolicy } from './policy/env-policy'; import type { ConfigStoreMain } from '@teambit/config-store'; export declare const BIT_CLOUD_REGISTRY: string; export declare const NPM_REGISTRY = "https://registry.npmjs.org/"; export { ProxyConfig, NetworkConfig } from '@teambit/scope.network'; export interface DependencyResolverComponentData { packageName: string; policy: SerializedVariantPolicy; dependencies: SerializedDependency[]; componentRangePrefix?: ComponentRangePrefix; } export interface DependencyResolverVariantConfig { policy: VariantPolicyConfigObject; } export type RootPolicyRegistry = SlotRegistry; export type PoliciesRegistry = SlotRegistry; export type PackageManagerSlot = SlotRegistry; export type DependencyFactorySlot = SlotRegistry; export type PreInstallSlot = SlotRegistry; export type PostInstallSlot = SlotRegistry; type AddPackagesToLink = () => string[]; type AddPackagesToLinkSlot = SlotRegistry; export type MergeDependenciesFunc = (configuredExtensions: ExtensionDataList) => Promise; export type GetInstallerOptions = { rootDir?: string; packageManager?: string; cacheRootDirectory?: string; installingContext?: DepInstallerContext; nodeLinker?: NodeLinker; }; export type GetLinkerOptions = { rootDir?: string; linkingOptions?: LinkingOptions; linkingContext?: DepLinkerContext; }; export type GetDependenciesOptions = { includeHidden?: boolean; }; export type GetVersionResolverOptions = { cacheRootDirectory?: string; }; /** * see @teambit/dependencies.aspect-docs.dependency-resolver for more information about this aspect. * * The data of this aspect gets saved in workspace-component-loader.ts, `executeLoadSlot()`. * The type of the data is `DependencyResolverComponentData`. */ export declare class DependencyResolverMain { /** * Dependency resolver extension configuration. */ config: DependencyResolverWorkspaceConfig; /** * Registry for changes by other extensions. */ private rootPolicyRegistry; /** * Registry for changes by other extensions. */ private policiesRegistry; /** * envs extension. */ private envs; private logger; private configAspect; private aspectLoader; private configStore; /** * component aspect. */ readonly componentAspect: ComponentMain; private packageManagerSlot; private dependencyFactorySlot; private preInstallSlot; private postInstallSlot; private addPackagesToLinkSlot; /** * cache the workspace policy to improve performance. when workspace.jsonc is changed, this gets cleared. * @see workspace.triggerOnWorkspaceConfigChange */ private _workspacePolicy; private _additionalPackagesToLink?; constructor( /** * Dependency resolver extension configuration. */ config: DependencyResolverWorkspaceConfig, /** * Registry for changes by other extensions. */ rootPolicyRegistry: RootPolicyRegistry, /** * Registry for changes by other extensions. */ policiesRegistry: PoliciesRegistry, /** * envs extension. */ envs: EnvsMain, logger: Logger, configAspect: ConfigMain, aspectLoader: AspectLoaderMain, configStore: ConfigStoreMain, /** * component aspect. */ componentAspect: ComponentMain, packageManagerSlot: PackageManagerSlot, dependencyFactorySlot: DependencyFactorySlot, preInstallSlot: PreInstallSlot, postInstallSlot: PostInstallSlot, addPackagesToLinkSlot: AddPackagesToLinkSlot); /** * Save list of envs that doesn't contains env.jsonc file * this is used to show warning / instuctions to the user */ envsWithoutManifest: Set; /** * This function is a temporary workaround for installation in capsules with pnpm. * Currently pnpm breaks the root node_modules inside the capsule because it removes deps from it. * Install runs several times in the same capsule and pnpm removes deps from the previous runs. * * This workaround unfortunately also breaks pnpm on angular projects. Because dedupe doesn't work properly. * To fix this issue we'll either have to switch to root components or try to change pnpm code. * * Here is the PR where initially dedupe was turned off for pnpm: https://github.com/teambit/bit/pull/5410 */ supportsDedupingOnExistingRoot(): boolean; setConfig(config: DependencyResolverWorkspaceConfig): void; hasRootComponents(): boolean; isolatedCapsules(): boolean; harmonyVersionInRootPolicy(): string | undefined; nodeLinker(packageManagerName?: string): NodeLinker; linkCoreAspects(): boolean; /** * register a new package manager to the dependency resolver. */ registerPackageManager(packageManager: PackageManager): void; registerDependencyFactories(factories: DependencyFactory[]): void; registerPreInstallSubscribers(subscribers: PreInstallSubscriberList): void; registerPostInstallSubscribers(subscribers: PreInstallSubscriberList): void; registerAddPackagesToLink(fn: AddPackagesToLink): void; getSavePrefix(): string; getVersionWithSavePrefix({ version, overridePrefix, wantedRange, }: { version: string; overridePrefix?: string; wantedRange?: string; }): string; getPolicy(component: Component): Promise; /** * This function called on component load in order to calculate the dependencies based on the legacy (consumer) component * and write them to the dependencyResolver data. * Do not use this function for other purpose. * If you want to get the component dependencies call getDependencies (which will give you the dependencies from the data itself) * TODO: once we switch deps resolver <> workspace relation we should make it private * TODO: once we switch deps resolver <> workspace relation we should remove the resolveId func here * @param component */ extractDepsFromLegacy(component: Component, policy?: VariantPolicy): Promise; private getDependencyListFactory; /** * Main function to get the dependency list of a given component * @param component */ getDependencies(component: IComponent, { includeHidden }?: GetDependenciesOptions): DependencyList; getDependenciesFromLegacyComponent(component: LegacyComponent, { includeHidden }?: GetDependenciesOptions): DependencyList; /** * returns only the dependencies that are bit-components. */ getComponentDependencies(component: IComponent): ComponentDependency[]; getDependenciesFromSerializedDependencies(dependencies: SerializedDependency[]): DependencyList; /** * Getting the merged workspace policy (from dep resolver config and others like root package.json) */ getWorkspacePolicy(): WorkspacePolicy; getWorkspacePolicyManifest(): Partial>; clearCache(): void; /** * Getting the workspace policy as defined in the workspace.jsonc in the dependencyResolver aspect * This will not take into account packages that defined in the package.json of the root for example * in most cases you should use getWorkspacePolicy * @returns */ getWorkspacePolicyFromConfig(): WorkspacePolicy; getWorkspacePolicyFromConfigObject(obj: WorkspacePolicyConfigObject): WorkspacePolicy; getWorkspacePolicyFromPackageJson(packageJson: Record): WorkspacePolicy; mergeWorkspacePolices(polices: WorkspacePolicy[]): WorkspacePolicy; /** * Create a workspace manifest * The term workspace here is not the same as "bit workspace" but a workspace that represent a shared root * for installation of many components (sometime it might point to the workspace path) * in other case it can be for example the capsules root dir * * @param {string} [name=ROOT_NAME] * @param {SemVer} [version=new SemVer('1.0.0')] * @param {ManifestDependenciesObject} dependencies * @param {string} rootDir * @param {Component[]} components * @param {CreateFromComponentsOptions} [options={ * filterComponentsFromManifests: true, * createManifestForComponentsWithoutDependencies: true, * }] * @returns {WorkspaceManifest} * @memberof DependencyResolverMain */ getWorkspaceManifest(name: string | undefined, version: SemVer | undefined, rootPolicy: WorkspacePolicy, rootDir: string, components: Component[], options?: CreateFromComponentsOptions, context?: DepInstallerContext): Promise; /** * get the package name of a component. */ getPackageName(component: Component): string; createComponentIdByPkgNameMap(components: Component[]): Map; getDepResolverData(component: Component): DependencyResolverComponentData | undefined; calcPackageName(component: Component): string; getRuntimeModulePath(component: Component, options: { workspacePath: string; rootComponentsPath: string; isInWorkspace?: boolean; }): string; getComponentDirInBitRoots(component: Component, options: { workspacePath: string; rootComponentsPath: string; }): string; /** * returns the package path in the /node_modules/ folder * In case you call this in order to run the code from the path, please refer to the `getRuntimeModulePath` API */ getModulePath(component: Component): string; addDependenciesGraph(components: Array<{ component: Component; componentRelativeDir: string; }>, options: { rootDir: string; rootComponentsPath?: string; componentIdByPkgName: Map; }): Promise; /** * get a component dependency installer. */ getInstaller(options?: GetInstallerOptions): DependencyInstaller; private getPreInstallSubscribers; private getPostInstallSubscribers; private getAdditionalPackagesToLink; /** * get a component dependency linker. */ getLinker(options?: GetLinkerOptions): DependencyLinker; /** * This function returns the package manager if it exists, otherwise it returns undefined. * @returns The `getPackageManager()` function returns a `PackageManager` object or `undefined`. */ getPackageManager(): PackageManager | undefined; getVersionResolver(options?: GetVersionResolverOptions): Promise; /** * these ids should not be in the dependencyResolver policy normally. * one exception is bit itself, which needs teambit.harmony/harmony in the dependencies. * * returns component-ids string without a version. */ getCompIdsThatShouldNotBeInPolicy(): string[]; /** * return the system configured package manager. by default pnpm. */ getSystemPackageManager(): PackageManager; getProxyConfig(): Promise; private getProxyConfigFromDepResolverConfig; getNetworkConfig(): Promise; private getNetworkConfigFromGlobalConfig; private getNetworkConfigFromDepResolverConfig; private getNetworkConfigFromPackageManager; private getProxyConfigFromPackageManager; private getProxyConfigFromGlobalConfig; /** * Return the peer dependencies and their ranges that may be installed * without causing unmet peer dependency issues in some of the dependencies. */ getMissingPeerDependencies(rootDir: string, rootPolicy: WorkspacePolicy, componentDirectoryMap: ComponentMap, options: PackageManagerGetPeerDependencyIssuesOptions): Promise>; getRegistries(): Promise; /** * This will mutate any registry which point to BIT_DEV_REGISTRY to have the auth config from the @bit scoped registry or from the user.token in bit's config */ private addAuthToScopedBitRegistries; private getBitAuthConfig; get packageManagerName(): string; getAllowedScripts(): Record | undefined; updateAllowedScripts(newAllowedScripts: Record): void; addToRootPolicy(entries: WorkspacePolicyEntry[], options?: WorkspacePolicyAddEntryOptions): WorkspacePolicy; removeFromRootPolicy(dependencyIds: string[]): boolean; private updateConfigPolicy; persistConfig(reasonForChange?: string): Promise; /** * register new dependencies policies */ registerDependenciesPolicies(policy: VariantPolicyConfigObject): void; /** * register new dependencies policies */ registerRootPolicy(policy: WorkspacePolicy): void; getComponentEnvPolicyFromExtension(configuredExtensions: ExtensionDataList): Promise; getEnvPolicyFromEnvId(id: ComponentID, legacyFiles?: SourceFile[], envExtendsDeps?: LegacyDependency[]): Promise; /** * @deprecated use getEnvPolicyFromEnvId instead (it's the same) */ getEnvPolicyFromEnvLegacyId(id: ComponentID, legacyFiles?: SourceFile[]): Promise; getComponentEnvPolicy(component: Component): Promise; getEnvManifest(envComponent?: Component, legacyFiles?: SourceFile[], envExtendsDeps?: LegacyDependency[]): Promise; /** * Merge policy from parent and child env.jsonc files * The rule is that for each type of dependency (dev, runtime, peer) we check each item. * if a dep with a name exists on the child we will take the entire object from the child (including the version, * supported range, force etc') * if a dep exists with a version value "-" we will remove it from the policy */ mergeEnvManifestPolicy(parent: EnvJsonc, child: EnvJsonc): object; private getEnvPolicyFromFile; getComponentEnvPolicyFromEnv(env: DependenciesEnv, options: { envId: string; }): Promise; getComponentEnvPolicyFromEnvDefinition(envDef: EnvDefinition): Promise; /** * * dependencies that will bundled as part of the env template and will configured as externals for the component bundle * these dependencies will be available in the preview on the window. * these dependencies will have only one instance on the page. * for dev server these dependencies will be aliased. * TODO: this should probably moved to the preview aspect. the main issue is that is used for dev server which can't bring the preview aspect. * @param env */ getPreviewHostDependenciesFromEnv(env: DependenciesEnv): Promise; /** * Merge the dependencies provided by: * 1. envs configured in the component - via dependencies method * 2. extensions that registered to the registerDependencyPolicy slot (and configured for the component) * 3. props defined by the user (they are the strongest one) * @param configuredExtensions */ mergeVariantPolicies(configuredExtensions: ExtensionDataList, id: ComponentID, legacyFiles?: SourceFile[], envExtendsDeps?: LegacyDependency[]): Promise; /** * These are the policies that the env itself defines for itself. * So policies installed only locally for the env, not to any components that use the env. */ getPoliciesFromEnvForItself(id: ComponentID, legacyFiles?: SourceFile[], envExtendsDeps?: LegacyDependency[]): Promise; /** * Register a new dependency detector. Detectors allow to extend Bit's dependency detection * mechanism to support new file extensions and types. */ registerDetector(detector: DependencyDetector): this; /** * This function called on component load in order to calculate the custom * dependency detectors from an env, which is got by extension data list. * Do not use this function for other purposes. */ calcComponentEnvDepDetectors(extensions: ExtensionDataList): Promise; /** * This function registered to the onLoadRequireableExtensionSlot of the aspect-loader * Update the aspect / manifest deps versions in the runtimes (recursively) * This function mutate the manifest directly as otherwise it becomes very complicated * TODO: think if this funciton should be here as it about dependencies, or on the aspect loader * (as it's aware of the internal structure of aspects) * Maybe only register the dep resolution part to the aspect loader * at the moment it here for simplify the process * @param requireableExtension * @param manifest * @returns */ onLoadRequireableExtensionSubscriber(requireableExtension: RequireableComponent, manifest: ExtensionManifest | Aspect): Promise; /** * Update the aspect / manifest deps versions in the runtimes (recursively) * @param parentComponent * @param manifest */ private resolveRequireableExtensionManifestDepsVersionsRecursively; validateAspectData(data: DependencyResolverComponentData): { errorMsg: string; minBitVersion: string; } | undefined; /** * This function returns true for any of the following version specifiers: * - exact version * - version range * - dist-tag * - alias: npm:@ * - direct URL specifiers to the public npm registry. * E.g.: https://registry.npmjs.org/is-odd/-/is-odd-0.1.0.tgz) */ isValidVersionSpecifier(spec: string): boolean; /** * Return a list of outdated policy dependencies. */ getOutdatedPkgsFromPolicies({ rootDir, variantPoliciesByPatterns, componentPolicies, components, patterns, forceVersionBump, }: { rootDir: string; variantPoliciesByPatterns: Record; componentPolicies: Array<{ componentId: ComponentID; policy: any; }>; components: Component[]; patterns?: string[]; forceVersionBump?: 'major' | 'minor' | 'patch' | 'compatible'; }): Promise; getAllDependencies({ variantPoliciesByPatterns, componentPolicies, components, includeEnvJsoncDeps, }: { variantPoliciesByPatterns: Record; componentPolicies: Array<{ componentId: ComponentID; policy: any; }>; components: Component[]; includeEnvJsoncDeps?: boolean; }): CurrentPkg[]; getEnvJsoncPolicyPkgs(components: Component[]): CurrentPkg[]; getAllDedupedDirectDependencies(opts: { variantPoliciesByPatterns: Record; componentPolicies: Array<{ componentId: ComponentID; policy: any; }>; components: Component[]; }): CurrentPkg[]; private warnAboutOverwrite; /** * Fetching the package manifest from the full package document. * By default, we always request the abbreviated package document, * which is much smaller in size but doesn't include all the fields published in the package's package.json file. */ fetchFullPackageManifest(packageName: string): Promise; /** * Accepts a list of package dependency policies and returns a list of outdated policies extended with their "latestRange" */ getOutdatedPkgs({ rootDir, forceVersionBump, }: { rootDir: string; forceVersionBump?: 'major' | 'minor' | 'patch' | 'compatible'; }, pkgs: Array<{ name: string; currentRange: string; source: CurrentPkgSource; } & T>): Promise>; /** * Update the specified packages to their latest versions in all policies; * root polcies, variant pocilicies, and component configuration policies (component.json). */ applyUpdates(outdatedPkgs: Array>, options: { variantPoliciesByPatterns: Record; }): { updatedVariants: string[]; updatedComponents: UpdatedComponent[]; }; getWorkspaceComponentRangePrefix(): ComponentRangePrefix | undefined; calcComponentRangePrefixByConsumerComponent(component: LegacyComponent): ComponentRangePrefix | undefined; static runtime: import("@teambit/harmony").RuntimeDefinition; static dependencies: Aspect[]; static slots: (((registerFn: () => string) => SlotRegistry) | ((registerFn: () => string) => SlotRegistry>>) | ((registerFn: () => string) => SlotRegistry) | ((registerFn: () => string) => SlotRegistry) | ((registerFn: () => string) => SlotRegistry) | ((registerFn: () => string) => SlotRegistry) | ((registerFn: () => string) => SlotRegistry) | ((registerFn: () => string) => SlotRegistry))[]; static defaultConfig: DependencyResolverWorkspaceConfig & Required>; static provider([envs, loggerExt, configMain, aspectLoader, componentAspect, graphql, configStore]: [ EnvsMain, LoggerMain, ConfigMain, AspectLoaderMain, ComponentMain, GraphqlMain, ConfigStoreMain ], config: DependencyResolverWorkspaceConfig, [rootPolicyRegistry, policiesRegistry, packageManagerSlot, dependencyFactorySlot, preInstallSlot, postInstallSlot, addPackagesToLinkSlot,]: [ RootPolicyRegistry, PoliciesRegistry, PackageManagerSlot, DependencyFactorySlot, PreInstallSlot, PostInstallSlot, AddPackagesToLinkSlot ]): Promise; getEmptyDepsObject(): ManifestDependenciesObject; /** * Returns a list of target locations where that given component was hard linked to. * * @param rootDir - The root directory of the workspace * @param componentDir - Relative path to the component's directory * @param packageName - The injected component's packageName */ getInjectedDirs(rootDir: string, componentDir: string, packageName: string): Promise; getWorkspaceDepsOfBitRoots(manifests: ProjectManifest[]): Record; } export interface MergedOutdatedPkg extends OutdatedPkg { dependentComponents?: ComponentID[]; hasDifferentRanges?: boolean; }