-
Notifications
You must be signed in to change notification settings - Fork 637
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Haste map cleanup with Haste module duplicates
Summary: One issue led to another here - 1. I inadvertently broke [this condition](https://github.com/facebook/metro/blame/eeb211fdcfdcb9e7f8a51721bd0f48bc7d0d211f/packages/metro-file-map/src/index.js#L527) when refactoring the data structures in D42303308 (ef9af83) - to preserve the previous behaviour, `moduleMap` should've been changed to `moduleMapItem` on that line. The condition has since been a no-op, because `moduleMap` ([`RawModuleMap`](https://github.com/facebook/metro/blob/eeb211fdcfdcb9e7f8a51721bd0f48bc7d0d211f/packages/metro-file-map/src/flow-types.js#L232-L237)) always has 4 keys. 2. Thinking about fixing this led me to question what it does - in particular, why "`Object.keys(moduleMapItem).length === 1`" and not "`=== 0`" before deleting the entry from the `moduleMap`. It was introduced in jestjs/jest#3647 but there's no discussion of that line. I'm 99% certain it's meant to remove an empty entry from the module map, but obviously it actually removes an entry if and only if it has exactly 1 remaining platform. For example, this would've meant that if three `Banana` Haste modules exist, with a duplicate for `ios`: `Banana.js` `Banana.ios.js` `another/Banana.ios.js` `jest-haste-map` would detect a duplicate `Banana.ios`, correctly delete `moduleMap.get('Banana')[ios]`, and then *also* delete the whole entry (along with the generic platform) *without* adding `Banana.js` to duplicates. Then, if `another/Banana.ios.js` is deleted from disk to theoretically recover a good state, the Haste map would end up in a bad state, with no generic platform entry `Banana.js`. So in fact, D42303308 (ef9af83) accidentally fixed this bug by breaking the over-zealous deletion, but left some nonsense code. This diff restores the presumed original intent of the code, removing an empty object from the module map. Changelog: [Internal] Reviewed By: jacdebug Differential Revision: D43664985 fbshipit-source-id: 61ae91f820bc6e2cf4985ae22c295d98df3da8a1
- Loading branch information
1 parent
cd25c2b
commit 3cbd9ae
Showing
2 changed files
with
68 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters