import type { ComponentID } from '@teambit/component-id'; import type { IssuesList } from '@teambit/component-issues'; import type { ConsumerComponent as Component } from '@teambit/legacy.consumer-component'; import type { Consumer } from '@teambit/legacy.consumer'; import type { PathOsBased } from '@teambit/legacy.utils'; import type { ComponentMap } from '@teambit/legacy.bit-map'; import type { DependencyResolverMain, DependencyDetector } from '@teambit/dependency-resolver'; import type { DependenciesTree } from '../files-dependency-builder/types/dependency-tree-type'; import type { DevFilesMain } from '@teambit/dev-files'; import type { Workspace } from '@teambit/workspace'; import type { AspectLoaderMain } from '@teambit/aspect-loader'; import { DependenciesData } from './dependencies-data'; import type { AllDependencies, AllPackagesDependencies } from './apply-overrides'; export type FileType = { isTestFile: boolean; }; export type DebugDependencies = { components: DebugComponentsDependency[]; unidentifiedPackages?: string[]; }; export type DebugComponentsDependency = { id: ComponentID; importSource?: string; dependencyPackageJsonPath?: string; dependentPackageJsonPath?: string; versionResolvedFrom?: 'DependencyPkgJson' | 'DependentPkgJson' | 'BitMap' | 'Model' | 'MergeConfig' | string; version?: string; componentIdResolvedFrom?: 'DependencyPkgJson' | 'DependencyPath'; packageName?: string; }; export declare class AutoDetectDeps { private component; private workspace; private devFiles; private depsResolver; private aspectLoader; componentId: ComponentID; componentMap: ComponentMap; componentFromModel: Component | undefined; consumerPath: PathOsBased; tree: DependenciesTree; allDependencies: AllDependencies; allPackagesDependencies: AllPackagesDependencies; issues: IssuesList; coreAspects: string[]; processedFiles: string[]; debugDependenciesData: DebugDependencies; autoDetectConfigMerge: Record; constructor(component: Component, workspace: Workspace, devFiles: DevFilesMain, depsResolver: DependencyResolverMain, aspectLoader: AspectLoaderMain); get consumer(): Consumer; private setTree; /** * Resolve components and packages dependencies for a component. * This method should NOT have any side-effect on the component. the DependenciesLoader class is * responsible for saving this data on the component object. * * The process is as follows: * 1) Use the language driver to parse the component files and find for each file its dependencies. * 2) The results we get from the driver per file tells us what are the files and packages that depend on our file. * and also whether there are missing packages and files. * 3) Using the information from the driver, we go over each one of the dependencies files and find its counterpart * component. The way how we find it, is by using the bit.map file which has a mapping between the component name and * the file paths. * 4) If we find a component to the file dependency, we add it to component.dependencies. Otherwise, it's added to * component.issues.untrackedDependencies * 5) Similarly, when we find the packages dependencies, they are added to component.packageDependencies. Otherwise, * they're added to component.issues.missingPackagesDependenciesOnFs * 6) In case the driver found a file dependency that is not on the file-system, we add that file to * component.issues.missingDependenciesOnFs */ getDependenciesData(cacheResolvedDependencies: Record, cacheProjectAst: Record | undefined): Promise<{ dependenciesData: DependenciesData; debugDependenciesData: DebugDependencies; }>; getEnvDetectors(): Promise; /** * Given the tree of file dependencies from the driver, find the components of these files. * Each dependency file has a path, use bit.map to search for the component name by that path. * If the component is found, add it to "this.allDependencies.dependencies". Otherwise, add it to "this.issues.untrackedDependencies". * * For the found components, add their sourceRelativePath and destinationRelativePath, they are being used for * generating links upon import: * sourceRelativePath - location of the link file. * destinationRelativePath - destination written inside the link file. * * When a dependency is found in a regular (implementation) file, it goes to `dependencies`. If * it found on a test file, it goes to `devDependencies`. * Similarly, when a package is found in a regular file, it goes to `packageDependencies`. When * if found in a test file, it goes to `devPackageDependencies`. * An exception for the above is when a package is required in a regular or test file but is also * mentioned in the `package.json` file as a peerDependency, in that case, the package is added * to `peerPackageDependencies` and removed from other places. Unless this package is overridden * and marked as ignored in the consumer or component config file. */ private populateDependencies; private throwForNonExistFile; private getComponentIdByResolvedPackageData; /** * this happens when using relative paths between components, which is allowed on Legacy only. * on Harmony, during the execution of this function, it recognizes the use of relative-paths, enter * it to the "issues", then, later, it shows a warning on bit-status and block tagging. */ private getComponentIdByDepFile; private processDepFiles; private processOneDepFile; /** * process require/import of Bit components where the require statement is not a relative path * but a module path, such as `require('@bit/bit.envs/compiler/babel');` */ private processComponents; private isPkgInWorkspacePolicies; private addImportNonMainIssueIfNeeded; private processPackages; private processMissing; private processErrors; /** * when a user uses core-extensions these core-extensions should not be dependencies. * here, we filter them out from all places they could entered as dependencies. * an exception is when running this method on bit-core-extensions themselves (dogfooding), in * which case we recognizes that the current originFile is a core-extension and avoid filtering. */ private processCoreAspects; /** * ** LEGACY ONLY ** * This is related to a legacy feature "custom-module-resolution". the code was removed, only the debug is still there, just in case. * * ** OLD COMMENT ** * currently the only unidentified packages being process are the ones coming from custom-modules-resolution. * assuming the author used custom-resolution, which enable using non-relative import syntax, * for example, requiring the file 'src/utils/is-string' from anywhere as require('utils/is-string'); * now, when the component is imported, the driver recognizes 'utils/is-string' as a package, * because it's not relative. * the goal here is to use the 'package' the driver found and match it with one of the * dependencies from the model. In the example above, we might find in the model, a dependency * is-string with importSource of 'utils/is-string'. * Once a match is found, copy the relativePaths from the model. * * keep in mind that this custom-modules-resolution supported on legacy components only. * as such, no need to find the packageName to pass to _pushToDependenciesIfNotExist method. */ private processUnidentifiedPackages; private _pushToDependenciesIfNotExist; private pushToDependenciesArray; private getExistingDependency; private getExistingDepRelativePaths; private getDiffSpecifiers; /** * when requiring packages in typescript, sometimes there are the types packages with the same * name, which the user probably wants as well. for example, requiring `foo` package, will also * add `@types/foo` to the devDependencies if it has been found in the user `package.json` file. * otherwise, it's taken from the merge config (during a merge, e.g. when the other side added it), and then from the * model. * * ideally this should be in bit-javascript. however, the decision where to put these `@types` * packages (dependencies/devDependencies) is done here according to the user `package.json` * and can't be done there because the `Tree` we get from bit-javascript doesn't have this * distinction. */ private _addTypesPackagesForTypeScript; private _pushToUntrackDependenciesIssues; private _pushToRelativeComponentsAuthoredIssues; private _pushToMissingDependenciesOnFs; private _pushToMissingPackagesDependenciesIssues; } /** * this is not necessarily a valid semver version. in case of a snap, it returns the hash only, not a valid semver. * this is for the ComponentID.version. */ export declare function getValidComponentVersion(version?: string): { version?: string; range?: string; };