* This function should be called when the file under `filePath` is removed * or changed. When that happens, we want to figure out if that file was * part of a group of files that had the same ID. If it was, we want to * remove it from the group. Furthermore, if there is only one file * r
(
hasteMap: InternalHasteMap,
relativeFilePath: string,
moduleName: string,
)
| 1028 | * correct resolution for its ID, and cleanup the duplicates index. |
| 1029 | */ |
| 1030 | private _recoverDuplicates( |
| 1031 | hasteMap: InternalHasteMap, |
| 1032 | relativeFilePath: string, |
| 1033 | moduleName: string, |
| 1034 | ) { |
| 1035 | let dupsByPlatform = hasteMap.duplicates.get(moduleName); |
| 1036 | if (dupsByPlatform == null) { |
| 1037 | return; |
| 1038 | } |
| 1039 | |
| 1040 | const platform = |
| 1041 | getPlatformExtension(relativeFilePath, this._options.platforms) || |
| 1042 | H.GENERIC_PLATFORM; |
| 1043 | let dups = dupsByPlatform.get(platform); |
| 1044 | if (dups == null) { |
| 1045 | return; |
| 1046 | } |
| 1047 | |
| 1048 | dupsByPlatform = copyMap(dupsByPlatform); |
| 1049 | hasteMap.duplicates.set(moduleName, dupsByPlatform); |
| 1050 | |
| 1051 | dups = copyMap(dups); |
| 1052 | dupsByPlatform.set(platform, dups); |
| 1053 | dups.delete(relativeFilePath); |
| 1054 | |
| 1055 | if (dups.size !== 1) { |
| 1056 | return; |
| 1057 | } |
| 1058 | |
| 1059 | const uniqueModule = dups.entries().next().value; |
| 1060 | |
| 1061 | if (!uniqueModule) { |
| 1062 | return; |
| 1063 | } |
| 1064 | |
| 1065 | let dedupMap = hasteMap.map.get(moduleName); |
| 1066 | |
| 1067 | if (!dedupMap) { |
| 1068 | dedupMap = Object.create(null) as ModuleMapItem; |
| 1069 | hasteMap.map.set(moduleName, dedupMap); |
| 1070 | } |
| 1071 | dedupMap[platform] = uniqueModule; |
| 1072 | dupsByPlatform.delete(platform); |
| 1073 | if (dupsByPlatform.size === 0) { |
| 1074 | hasteMap.duplicates.delete(moduleName); |
| 1075 | } |
| 1076 | } |
| 1077 | |
| 1078 | async end(): Promise<void> { |
| 1079 | if (this._changeInterval) { |