From fb8ae719e0a8e28ef0776545ae02350a0e5e17f5 Mon Sep 17 00:00:00 2001 From: Brendan Abbott Date: Mon, 28 Oct 2019 12:05:44 +1000 Subject: [PATCH] When populating ExportMap, only load file if it's not ignored --- CHANGELOG.md | 3 +++ src/ExportMap.js | 13 ++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ff5aeb3e0..0c893274e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel ### Fixed - `default`: make error message less confusing ([#1470], thanks [@golopot]) +- Improve performance of `ExportMap.for` by only loading paths when necessary. ([#1519], thanks [@brendo]) - Support export of a merged TypeScript namespace declaration ([#1495], thanks [@benmunro]) - [`import/order`]: fix autofix to not move imports across fn calls ([#1253], thanks [@tihonove]) - [`prefer-default-export`]: fix false positive with type export ([#1506], thanks [@golopot]) @@ -610,6 +611,7 @@ for info on changes for earlier releases. [`memo-parser`]: ./memo-parser/README.md +[#1519]: https://github.com/benmosher/eslint-plugin-import/pull/1519 [#1506]: https://github.com/benmosher/eslint-plugin-import/pull/1506 [#1495]: https://github.com/benmosher/eslint-plugin-import/pull/1495 [#1472]: https://github.com/benmosher/eslint-plugin-import/pull/1472 @@ -998,3 +1000,4 @@ for info on changes for earlier releases. [@TrevorBurnham]: https://github.com/TrevorBurnham [@benmunro]: https://github.com/benmunro [@tihonove]: https://github.com/tihonove +[@brendo]: https://github.com/brendo diff --git a/src/ExportMap.js b/src/ExportMap.js index c9544c9c8..8009f8b83 100644 --- a/src/ExportMap.js +++ b/src/ExportMap.js @@ -310,11 +310,18 @@ ExportMap.for = function (context) { return null } + // check for and cache ignore + if (isIgnored(path, context)) { + log('ignored path due to ignore settings:', path) + exportCache.set(cacheKey, null) + return null + } + const content = fs.readFileSync(path, { encoding: 'utf8' }) - // check for and cache ignore - if (isIgnored(path, context) || !unambiguous.test(content)) { - log('ignored path due to unambiguous regex or ignore settings:', path) + // check for and cache unambigious modules + if (!unambiguous.test(content)) { + log('ignored path due to unambiguous regex:', path) exportCache.set(cacheKey, null) return null }