diff --git a/CHANGELOG.md b/CHANGELOG.md index cea8853285a3..ac023720d4e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ### Features - `[pretty-format]` Option to not escape strings in diff messages ([#5661](https://github.com/facebook/jest/pull/5661)) +- `[jest-haste-map]` Add `getFileIterator` to `HasteFS` for faster file iteration ([#7010](https://github.com/facebook/jest/pull/7010)). ### Fixes diff --git a/packages/jest-haste-map/src/haste_fs.js b/packages/jest-haste-map/src/haste_fs.js index f62d84ab19c1..af38d68ea700 100644 --- a/packages/jest-haste-map/src/haste_fs.js +++ b/packages/jest-haste-map/src/haste_fs.js @@ -44,6 +44,10 @@ export default class HasteFS { return Array.from(this._files.keys()); } + getFileIterator(): Iterator { + return this._files.keys(); + } + matchFiles(pattern: RegExp | string): Array { if (!(pattern instanceof RegExp)) { pattern = new RegExp(pattern); diff --git a/packages/jest-resolve-dependencies/src/index.js b/packages/jest-resolve-dependencies/src/index.js index d36c59d69688..19c98f001a84 100644 --- a/packages/jest-resolve-dependencies/src/index.js +++ b/packages/jest-resolve-dependencies/src/index.js @@ -100,10 +100,13 @@ class DependencyResolver { } } } - const modules = this._hasteFS.getAllFiles().map(file => ({ - dependencies: this.resolve(file, options), - file, - })); + const modules = []; + for (const file of this._hasteFS.getFileIterator()) { + modules.push({ + dependencies: this.resolve(file, options), + file, + }); + } return Array.from(collectModules(relatedPaths, modules, changed)); } }