# jest-haste-map

> `jest-haste-map` is a module used by Jest, a popular JavaScript testing framework, to create a fast lookup of files in a project. It helps Jest efficiently locate and track changes in files during testing, making it particularly useful for large projects

Latest version **30.5.1** (published 2026-09-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install jest-haste-map
pnpm add jest-haste-map
yarn add jest-haste-map
bun add jest-haste-map
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; recently updated; high maintenance score; popular repo.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 30.5.1 |
| Published | 2026-09-01 |
| First published | 2016-04-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | ^18.14.0 \|\| ^20.0.0 \|\| ^22.0.0 \|\| >=24.0.0 |
| Dependencies | 11 |
| Unpacked size | 155.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 45465 |
| Maintainers | aaronabramov, simenb, rickhanlonii, openjs-operations, cpojer |

## Links

- npm: https://www.npmjs.com/package/jest-haste-map
- Repository: https://github.com/jestjs/jest
- Homepage: https://github.com/jestjs/jest#readme
- Issues: https://github.com/jestjs/jest/issues
- npm.io page: https://npm.io/package/jest-haste-map

## Dependencies (11)

- [fdir](https://npm.io/package/fdir.md) ^6.5.0
- [anymatch](https://npm.io/package/anymatch.md) ^3.1.3
- [jest-util](https://npm.io/package/jest-util.md) 30.5.1
- [picomatch](https://npm.io/package/picomatch.md) ^4.0.3
- [@jest/types](https://npm.io/package/@jest/types.md) 30.5.1
- [@types/node](https://npm.io/package/@types/node.md) *
- [fb-watchman](https://npm.io/package/fb-watchman.md) ^2.0.2
- [graceful-fs](https://npm.io/package/graceful-fs.md) ^4.2.11
- [jest-worker](https://npm.io/package/jest-worker.md) 30.5.1
- [@parcel/watcher](https://npm.io/package/@parcel/watcher.md) ^2.6.0
- [jest-regex-util](https://npm.io/package/jest-regex-util.md) 30.5.0

## Recent versions

- 30.5.1 (latest) — 2026-09-01
- 30.0.0-rc.1 (next) — 2025-06-09
- 20.0.5 (alpha) — 2017-07-17
- 30.5.0 — 2026-08-28
- 30.4.1 — 2026-05-08
- 30.4.0 — 2026-05-07
- 30.3.0 — 2026-03-10
- 30.2.0 — 2025-09-28
- 30.1.0 — 2025-08-27
- 30.0.5 — 2025-07-22
- 30.0.2 — 2025-06-19
- 30.0.1 — 2025-06-18
- 30.0.0 — 2025-06-10
- 30.0.0-beta.8 — 2025-06-04
- 30.0.0-beta.7 — 2025-06-04
- … 278 more at https://npm.io/package/jest-haste-map/versions

## README

# jest-haste-map

`jest-haste-map` is a module used by Jest, a popular JavaScript testing framework, to create a fast lookup of files in a project. It helps Jest efficiently locate and track changes in files during testing, making it particularly useful for large projects with many files.

## why jest-haste-map ?

- **Parallel crawling and analysis:** jest-haste-map crawls the entire project, extracts dependencies, and analyzes files in parallel across worker processes.This can significantly improve the performance of the map building process.
- **Cached file system:** jest-haste-map keeps a cache of the file system in memory and on disk. This allows for fast file related operations, such as resolving module imports and checking for changes.
- **Minimal work**: jest-haste-map only does the minimal amount of work necessary when files change. When using [watchman](https://facebook.github.io/watchman/) (recommended for large projects), Jest asks watchman for changed files instead of crawling the file system. Without watchman, [@parcel/watcher](https://github.com/parcel-bundler/watcher) is used — it picks the best native backend for the platform (`fs-events` on macOS, `inotify` on Linux, `windows` on Windows).
- **File system watching:** jest-haste-map can watch the file system for changes. This is useful for building interactive tools, such as watch mode.

## Installation

with npm :

```bash
npm install jest-haste-map --save-dev
```

with yarn :

```bash
yarn add jest-haste-map --dev
```

## usage

`jest-haste-map` is compatible with both `ES modules` and `CommonJS`

### simple usage

```javascript
const map = new HasteMap.default({
  // options
});
```

### Example usage (get all files with .js extension in the project)

```javascript
import HasteMap from 'jest-haste-map';
import os from 'os';
import {dirname} from 'path';
import {fileURLToPath} from 'url';

const root = dirname(fileURLToPath(import.meta.url));

const map = new HasteMap.default({
  id: 'myproject', //Used for caching.
  extensions: ['js'], // Tells jest-haste-map to only crawl .js files.
  maxWorkers: os.availableParallelism(), //Parallelizes across all available CPUs.
  platforms: [], // This is only used for React Native, you can leave it empty.
  roots: [root], // Can be used to only search a subset of files within `rootDir`
  retainAllFiles: true,
  rootDir: root, //The project root.
});

const {hasteFS} = await map.build();

const files = hasteFS.getAllFiles();

console.log(files);
```

### options

| Option                 | Type                | Required | Default Value |
| ---------------------- | ------------------- | -------- | ------------- |
| cacheDirectory         | string              | No       | `os.tmpdir()` |
| computeDependencies    | boolean             | No       | `true`        |
| computeSha1            | boolean             | No       | `false`       |
| console                | Console             | No       | -             |
| dependencyExtractor    | string \| null      | No       | `null`        |
| enableSymlinks         | boolean             | No       | `false`       |
| extensions             | Array&lt;string&gt; | Yes      | -             |
| forceNodeFilesystemAPI | boolean             | No       | `false`       |
| hasteImplModulePath    | string              | No       | -             |
| hasteMapModulePath     | string              | No       | -             |
| id                     | string              | Yes      | -             |
| ignorePattern          | HasteRegExp         | No       | -             |
| maxWorkers             | number              | Yes      | -             |
| mocksPattern           | string              | No       | -             |
| platforms              | Array&lt;string&gt; | Yes      | -             |
| resetCache             | boolean             | No       | -             |
| retainAllFiles         | boolean             | Yes      | -             |
| rootDir                | string              | Yes      | -             |
| roots                  | Array&lt;string&gt; | Yes      | -             |
| skipPackageJson        | boolean             | No       | `false`       |
| throwOnModuleCollision | boolean             | No       | `false`       |
| useWatchman            | boolean             | No       | `true`        |

For more, you can check [github](https://github.com/jestjs/jest/tree/main/packages/jest-haste-map)

---
_Source: https://npm.io/package/jest-haste-map · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
