From a05fdbc986e8d44eddcc6d30b9b0ed528da3248c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Norte?= Date: Thu, 20 Sep 2018 13:10:56 +0100 Subject: [PATCH 1/3] Added method to get an iterator for all files in HasteFS --- packages/jest-haste-map/src/haste_fs.js | 4 ++++ 1 file changed, 4 insertions(+) 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); From fa3c8b4d0050103fb705c25781132ecd974b7d80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Norte?= Date: Thu, 20 Sep 2018 14:13:24 +0100 Subject: [PATCH 2/3] Used hasteFS.getFileIterator() in jest-resolve-dependencies --- packages/jest-resolve-dependencies/src/index.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) 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)); } } From 5f857455796987c09d67711787bafa8196eae7b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Norte?= Date: Thu, 20 Sep 2018 14:32:06 +0100 Subject: [PATCH 3/3] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) 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