index.d.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /**
  2. * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. */
  7. import type { Config } from '@jest/types';
  8. import type { ModuleMap } from 'jest-haste-map';
  9. import type { ResolverConfig } from './types';
  10. import ModuleNotFoundError from './ModuleNotFoundError';
  11. import shouldLoadAsEsm from './shouldLoadAsEsm';
  12. declare type FindNodeModuleConfig = {
  13. basedir: Config.Path;
  14. browser?: boolean;
  15. extensions?: Array<string>;
  16. moduleDirectory?: Array<string>;
  17. paths?: Array<Config.Path>;
  18. resolver?: Config.Path | null;
  19. rootDir?: Config.Path;
  20. throwIfNotFound?: boolean;
  21. };
  22. declare type BooleanObject = Record<string, boolean>;
  23. declare namespace Resolver {
  24. type ResolveModuleConfig = {
  25. skipNodeResolution?: boolean;
  26. paths?: Array<Config.Path>;
  27. };
  28. type ResolverType = Resolver;
  29. }
  30. declare class Resolver {
  31. private readonly _options;
  32. private readonly _moduleMap;
  33. private readonly _moduleIDCache;
  34. private readonly _moduleNameCache;
  35. private readonly _modulePathCache;
  36. private readonly _supportsNativePlatform;
  37. constructor(moduleMap: ModuleMap, options: ResolverConfig);
  38. static ModuleNotFoundError: typeof ModuleNotFoundError;
  39. static tryCastModuleNotFoundError(error: unknown): ModuleNotFoundError | null;
  40. static clearDefaultResolverCache(): void;
  41. static findNodeModule(path: Config.Path, options: FindNodeModuleConfig): Config.Path | null;
  42. static unstable_shouldLoadAsEsm: typeof shouldLoadAsEsm;
  43. resolveModuleFromDirIfExists(dirname: Config.Path, moduleName: string, options?: Resolver.ResolveModuleConfig): Config.Path | null;
  44. resolveModule(from: Config.Path, moduleName: string, options?: Resolver.ResolveModuleConfig): Config.Path;
  45. private _isAliasModule;
  46. isCoreModule(moduleName: string): boolean;
  47. getModule(name: string): Config.Path | null;
  48. getModulePath(from: Config.Path, moduleName: string): Config.Path;
  49. getPackage(name: string): Config.Path | null;
  50. getMockModule(from: Config.Path, name: string): Config.Path | null;
  51. getModulePaths(from: Config.Path): Array<Config.Path>;
  52. getModuleID(virtualMocks: BooleanObject, from: Config.Path, _moduleName?: string): string;
  53. private _getModuleType;
  54. private _getAbsolutePath;
  55. private _getMockPath;
  56. private _getVirtualMockPath;
  57. private _isModuleResolved;
  58. resolveStubModuleName(from: Config.Path, moduleName: string): Config.Path | null;
  59. }
  60. export = Resolver;