jest-haste-map
Advanced tools
Comparing version 29.0.2 to 29.0.3
@@ -10,9 +10,8 @@ /** | ||
import type {Config} from '@jest/types'; | ||
import {EventEmitter} from 'events'; | ||
import type {Stats} from 'graceful-fs'; | ||
export declare type ChangeEvent = { | ||
declare type ChangeEvent = { | ||
eventsQueue: EventsQueue; | ||
hasteFS: FS; | ||
moduleMap: ModuleMap; | ||
hasteFS: HasteFS; | ||
moduleMap: ModuleMap_2; | ||
}; | ||
@@ -60,3 +59,3 @@ | ||
export declare class FS { | ||
declare class HasteFS implements IHasteFS { | ||
private readonly _rootDir; | ||
@@ -78,155 +77,2 @@ private readonly _files; | ||
/** | ||
* 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<string>, // 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()`. | ||
* | ||
*/ | ||
declare class HasteMap extends EventEmitter { | ||
private _buildPromise; | ||
private _cachePath; | ||
private _changeInterval?; | ||
private _console; | ||
private _isWatchmanInstalledPromise; | ||
private _options; | ||
private _watchers; | ||
private _worker; | ||
static getStatic(config: Config.ProjectConfig): HasteMapStatic; | ||
static create(options: Options): Promise<HasteMap>; | ||
private constructor(); | ||
private setupCachePath; | ||
static getCacheFilePath( | ||
tmpdir: string, | ||
id: string, | ||
...extra: Array<string> | ||
): string; | ||
static getModuleMapFromJSON(json: SerializableModuleMap): ModuleMap; | ||
getCacheFilePath(): string; | ||
build(): Promise<HasteMapObject>; | ||
/** | ||
* 1. read data from the cache or create an empty structure. | ||
*/ | ||
read(): InternalHasteMap; | ||
readModuleMap(): ModuleMap; | ||
/** | ||
* 2. crawl the file system. | ||
*/ | ||
private _buildFileMap; | ||
/** | ||
* 3. parse and extract metadata from changed files. | ||
*/ | ||
private _processFile; | ||
private _buildHasteMap; | ||
private _cleanup; | ||
/** | ||
* 4. serialize the new `HasteMap` in a cache file. | ||
*/ | ||
private _persist; | ||
/** | ||
* Creates workers or parses files and extracts metadata in-process. | ||
*/ | ||
private _getWorker; | ||
private _crawl; | ||
/** | ||
* Watch mode | ||
*/ | ||
private _watch; | ||
/** | ||
* 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. | ||
*/ | ||
private _recoverDuplicates; | ||
end(): Promise<void>; | ||
/** | ||
* Helpers | ||
*/ | ||
private _ignore; | ||
private _shouldUseWatchman; | ||
private _createEmptyMap; | ||
static H: HType; | ||
} | ||
export default HasteMap; | ||
export declare type HasteMapObject = { | ||
hasteFS: FS; | ||
moduleMap: ModuleMap; | ||
__hasteMapForTest?: InternalHasteMap | null; | ||
}; | ||
declare type HasteMapStatic<S = SerializableModuleMap> = { | ||
@@ -261,2 +107,28 @@ getCacheFilePath( | ||
export declare interface IHasteFS { | ||
exists(path: string): boolean; | ||
getAbsoluteFileIterator(): Iterable<string>; | ||
getAllFiles(): Array<string>; | ||
getDependencies(file: string): Array<string> | null; | ||
getSize(path: string): number | null; | ||
matchFiles(pattern: RegExp | string): Array<string>; | ||
matchFilesWithGlob( | ||
globs: ReadonlyArray<string>, | ||
root: string | null, | ||
): Set<string>; | ||
} | ||
export declare interface IHasteMap { | ||
on(eventType: 'change', handler: (event: ChangeEvent) => void): void; | ||
build(): Promise<{ | ||
hasteFS: IHasteFS; | ||
moduleMap: IModuleMap; | ||
}>; | ||
} | ||
declare type IJestHasteMap = HasteMapStatic & { | ||
create(options: Options): Promise<IHasteMap>; | ||
getStatic(config: Config.ProjectConfig): HasteMapStatic; | ||
}; | ||
export declare interface IModuleMap<S = SerializableModuleMap> { | ||
@@ -279,13 +151,12 @@ getModule( | ||
declare type InternalHasteMap = { | ||
clocks: WatchmanClocks; | ||
duplicates: DuplicatesIndex; | ||
files: FileData; | ||
map: ModuleMapData; | ||
mocks: MockData; | ||
}; | ||
declare const JestHasteMap: IJestHasteMap; | ||
export default JestHasteMap; | ||
declare type MockData = Map<string, string>; | ||
export declare class ModuleMap implements IModuleMap<SerializableModuleMap> { | ||
export declare const ModuleMap: { | ||
create: (rootPath: string) => IModuleMap; | ||
}; | ||
declare class ModuleMap_2 implements IModuleMap { | ||
static DuplicateHasteCandidatesError: typeof DuplicateHasteCandidatesError; | ||
@@ -311,3 +182,3 @@ private readonly _raw; | ||
toJSON(): SerializableModuleMap; | ||
static fromJSON(serializableModuleMap: SerializableModuleMap): ModuleMap; | ||
static fromJSON(serializableModuleMap: SerializableModuleMap): ModuleMap_2; | ||
/** | ||
@@ -323,3 +194,3 @@ * When looking up a module's data, we walk through each eligible platform for | ||
private _assertNoDuplicates; | ||
static create(rootDir: string): ModuleMap; | ||
static create(rootDir: string): ModuleMap_2; | ||
} | ||
@@ -377,12 +248,2 @@ | ||
declare type WatchmanClocks = Map<string, WatchmanClockSpec>; | ||
declare type WatchmanClockSpec = | ||
| string | ||
| { | ||
scm: { | ||
'mergebase-with': string; | ||
}; | ||
}; | ||
export {}; |
@@ -6,10 +6,3 @@ 'use strict'; | ||
}); | ||
exports.DuplicateError = void 0; | ||
Object.defineProperty(exports, 'ModuleMap', { | ||
enumerable: true, | ||
get: function () { | ||
return _ModuleMap.default; | ||
} | ||
}); | ||
exports.default = void 0; | ||
exports.default = exports.ModuleMap = exports.DuplicateError = void 0; | ||
@@ -200,2 +193,4 @@ function _crypto() { | ||
const ModuleMap = _ModuleMap.default; | ||
exports.ModuleMap = ModuleMap; | ||
const CHANGE_INTERVAL = 30; | ||
@@ -1255,4 +1250,2 @@ const MAX_WAIT_TIME = 240000; | ||
exports.default = HasteMap; | ||
class DuplicateError extends Error { | ||
@@ -1277,2 +1270,6 @@ mockPath1; | ||
return new Map(input); | ||
} | ||
} // Export the smallest API surface required by Jest | ||
const JestHasteMap = HasteMap; | ||
var _default = JestHasteMap; | ||
exports.default = _default; |
{ | ||
"name": "jest-haste-map", | ||
"version": "29.0.2", | ||
"version": "29.0.3", | ||
"repository": { | ||
@@ -20,3 +20,3 @@ "type": "git", | ||
"dependencies": { | ||
"@jest/types": "^29.0.2", | ||
"@jest/types": "^29.0.3", | ||
"@types/graceful-fs": "^4.1.3", | ||
@@ -28,4 +28,4 @@ "@types/node": "*", | ||
"jest-regex-util": "^29.0.0", | ||
"jest-util": "^29.0.2", | ||
"jest-worker": "^29.0.2", | ||
"jest-util": "^29.0.3", | ||
"jest-worker": "^29.0.3", | ||
"micromatch": "^4.0.4", | ||
@@ -35,3 +35,3 @@ "walker": "^1.0.8" | ||
"devDependencies": { | ||
"@jest/test-utils": "^29.0.2", | ||
"@jest/test-utils": "^29.0.3", | ||
"@types/fb-watchman": "^2.0.0", | ||
@@ -50,3 +50,3 @@ "@types/micromatch": "^4.0.1", | ||
}, | ||
"gitHead": "616fcf56bb8481d29ba29cc34be32a92b1cf85e5" | ||
"gitHead": "77f865da39af5b3e1c114dc347e49257eb3dcfd1" | ||
} |
121754
3948
- Removedbraces@3.0.3(transitive)
- Removedfill-range@7.1.1(transitive)
- Removedis-number@7.0.0(transitive)
- Removedto-regex-range@5.0.1(transitive)
Updated@jest/types@^29.0.3
Updatedjest-util@^29.0.3
Updatedjest-worker@^29.0.3