Creates workers or parses files and extracts metadata in-process.
Helpers
HasteMap
in a cache file.This function should be called when the file under filePath
is removed
or changed. When that happens, we want to figure out if that file was
part of a group of files that had the same ID. If it was, we want to
remove it from the group. Furthermore, if there is only one file
remaining in the group, then we want to restore that single file as the
correct resolution for its ID, and cleanup the duplicates index.
Watch mode
Generated using TypeDoc
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 thefiles
andmap
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, // all relative dependencies of this file.
sha1: ?string, // SHA-1 of the file, if requested via options.
};
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// 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 (eitherpackage
ormodule
). };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:
read data from the cache or create an empty structure.
crawl the file system.
files
part of theHasteMap
.parse and extract metadata from changed files.
serialize the new
HasteMap
in a cache file. Worker processes can directly access the cache throughHasteMap.read()
.