jest-haste-map

  • Version 27.2.5
  • Published
  • 135 kB
  • 13 dependencies
  • MIT license

Install

npm i jest-haste-map
yarn add jest-haste-map
pnpm add jest-haste-map

Overview

Overview not available.

Index

Classes

class DuplicateError

class DuplicateError extends Error {}

    constructor

    constructor(mockPath1: string, mockPath2: string);

      property mockPath1

      mockPath1: string;

        property mockPath2

        mockPath2: string;

          class FS

          class HasteFS {}

            constructor

            constructor({ rootDir, files }: { rootDir: any; files: FileData });

              method exists

              exists: (file: any) => boolean;

                method getAbsoluteFileIterator

                getAbsoluteFileIterator: () => Iterable<Config.Path>;

                  method getAllFiles

                  getAllFiles: () => Array<Config.Path>;

                    method getDependencies

                    getDependencies: (file: any) => Array<string> | null;

                      method getFileIterator

                      getFileIterator: () => Iterable<Config.Path>;

                        method getModuleName

                        getModuleName: (file: any) => string | null;

                          method getSha1

                          getSha1: (file: any) => string | null;

                            method getSize

                            getSize: (file: any) => number | null;

                              method matchFiles

                              matchFiles: (pattern: RegExp | string) => Array<Config.Path>;

                                method matchFilesWithGlob

                                matchFilesWithGlob: (
                                globs: Array<Config.Glob>,
                                root: Config.Path | null
                                ) => Set<Config.Path>;

                                  class HasteMap

                                  class HasteMap extends EventEmitter {}
                                  • HasteMap is a JavaScript implementation of Facebook's haste module system.

                                    This implementation is inspired by https://github.com/facebook/node-haste and was built with for high-performance in large code repositories with hundreds of thousands of files. This implementation is scalable and provides predictable performance.

                                    Because the haste map creation and synchronization is critical to startup performance and most tasks are blocked by I/O this class makes heavy use of synchronous operations. It uses worker processes for parallelizing file access and metadata extraction.

                                    The data structures created by jest-haste-map can be used directly from the cache without further processing. The metadata objects in the files and map objects contain cross-references: a metadata object from one can look up the corresponding metadata object in the other map. Note that in most projects, the number of files will be greater than the number of haste modules one module can refer to many files based on platform extensions.

                                    type HasteMap = { clocks: WatchmanClocks, files: {[filepath: string]: FileMetaData}, map: {[id: string]: ModuleMapItem}, mocks: {[id: string]: string}, }

                                    // Watchman clocks are used for query synchronization and file system deltas. type WatchmanClocks = {[filepath: string]: string};

                                    type FileMetaData = { id: ?string, // used to look up module metadata objects in map. mtime: number, // check for outdated files. size: number, // size of the file in bytes. visited: boolean, // whether the file has been parsed or not. dependencies: Array, // all relative dependencies of this file. sha1: ?string, // SHA-1 of the file, if requested via options. };

                                    // Modules can be targeted to a specific platform based on the file name. // Example: platform.ios.js and Platform.android.js will both map to the same // Platform module. The platform should be specified during resolution. type ModuleMapItem = {[platform: string]: ModuleMetaData};

                                    // type ModuleMetaData = { path: string, // the path to look up the file object in files. type: string, // the module type (either package or module). };

                                    Note that the data structures described above are conceptual only. The actual implementation uses arrays and constant keys for metadata storage. Instead of {id: 'flatMap', mtime: 3421, size: 42, visited: true, dependencies: []} the real representation is similar to ['flatMap', 3421, 42, 1, []] to save storage space and reduce parse and write time of a big JSON blob.

                                    The HasteMap is created as follows: 1. read data from the cache or create an empty structure.

                                    2. crawl the file system. * empty cache: crawl the entire file system. * cache available: * if watchman is available: get file system delta changes. * if watchman is unavailable: crawl the entire file system. * build metadata objects for every file. This builds the files part of the HasteMap.

                                    3. parse and extract metadata from changed files. * this is done in parallel over worker processes to improve performance. * the worst case is to parse all files. * the best case is no file system access and retrieving all data from the cache. * the average case is a small number of changed files.

                                    4. serialize the new HasteMap in a cache file. Worker processes can directly access the cache through HasteMap.read().

                                  property H

                                  static H: HType;

                                    method build

                                    build: () => Promise<InternalHasteMapObject>;

                                      method create

                                      static create: (options: Options) => HasteMap;

                                        method end

                                        end: () => Promise<void>;

                                          method getCacheFilePath

                                          static getCacheFilePath: (
                                          tmpdir: any,
                                          name: string,
                                          ...extra: Array<string>
                                          ) => string;

                                            method getModuleMapFromJSON

                                            static getModuleMapFromJSON: (json: SerializableModuleMap) => HasteModuleMap;

                                              method getStatic

                                              static getStatic: (config: any) => HasteMapStatic;

                                                method read

                                                read: () => InternalHasteMap;
                                                • 1. read data from the cache or create an empty structure.

                                                method readModuleMap

                                                readModuleMap: () => HasteModuleMap;

                                                  class ModuleMap

                                                  class ModuleMap implements IModuleMap<SerializableModuleMap> {}

                                                    constructor

                                                    constructor(raw: RawModuleMap);

                                                      property DuplicateHasteCandidatesError

                                                      static DuplicateHasteCandidatesError: typeof DuplicateHasteCandidatesError;

                                                        method create

                                                        static create: (rootDir: any) => ModuleMap;

                                                          method fromJSON

                                                          static fromJSON: (serializableModuleMap: SerializableModuleMap) => ModuleMap;

                                                            method getMockModule

                                                            getMockModule: (name: string) => Config.Path | undefined;

                                                              method getModule

                                                              getModule: (
                                                              name: string,
                                                              platform?: string | null,
                                                              supportsNativePlatform?: boolean | null,
                                                              type?: HTypeValue | null
                                                              ) => Config.Path | null;

                                                                method getPackage

                                                                getPackage: (
                                                                name: string,
                                                                platform: string | null | undefined,
                                                                _supportsNativePlatform: boolean | null
                                                                ) => Config.Path | null;

                                                                  method getRawModuleMap

                                                                  getRawModuleMap: () => RawModuleMap;

                                                                    method toJSON

                                                                    toJSON: () => SerializableModuleMap;

                                                                      Interfaces

                                                                      interface IModuleMap

                                                                      interface IModuleMap<S = SerializableModuleMap> {}

                                                                        method getMockModule

                                                                        getMockModule: (name: string) => Config.Path | undefined;

                                                                          method getModule

                                                                          getModule: (
                                                                          name: string,
                                                                          platform?: string | null,
                                                                          supportsNativePlatform?: boolean | null,
                                                                          type?: HTypeValue | null
                                                                          ) => Config.Path | null;

                                                                            method getPackage

                                                                            getPackage: (
                                                                            name: string,
                                                                            platform: string | null | undefined,
                                                                            _supportsNativePlatform: boolean | null
                                                                            ) => Config.Path | null;

                                                                              method getRawModuleMap

                                                                              getRawModuleMap: () => RawModuleMap;

                                                                                method toJSON

                                                                                toJSON: () => S;

                                                                                  Type Aliases

                                                                                  type ChangeEvent

                                                                                  type ChangeEvent = {
                                                                                  eventsQueue: EventsQueue;
                                                                                  hasteFS: HasteFS;
                                                                                  moduleMap: ModuleMap;
                                                                                  };

                                                                                    type HasteMapObject

                                                                                    type HasteMap = {
                                                                                    hasteFS: HasteFS;
                                                                                    moduleMap: ModuleMap;
                                                                                    __hasteMapForTest?: InternalHasteMap | null;
                                                                                    };

                                                                                      type SerializableModuleMap

                                                                                      type SerializableModuleMap = {
                                                                                      duplicates: ReadonlyArray<[string, [string, [string, [string, number]]]]>;
                                                                                      map: ReadonlyArray<[string, ValueType<ModuleMapData>]>;
                                                                                      mocks: ReadonlyArray<[string, ValueType<MockData>]>;
                                                                                      rootDir: Config.Path;
                                                                                      };

                                                                                        Package Files (4)

                                                                                        Dependencies (13)

                                                                                        Dev Dependencies (5)

                                                                                        Peer Dependencies (0)

                                                                                        No peer dependencies.

                                                                                        Badge

                                                                                        To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                                                                        You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/jest-haste-map.

                                                                                        • Markdown
                                                                                          [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/jest-haste-map)
                                                                                        • HTML
                                                                                          <a href="https://www.jsdocs.io/package/jest-haste-map"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>