(id: string, module: ModuleMetaData)
| 458 | const rootDir = this._options.rootDir; |
| 459 | |
| 460 | const setModule = (id: string, module: ModuleMetaData) => { |
| 461 | let moduleMap = map.get(id); |
| 462 | if (!moduleMap) { |
| 463 | moduleMap = Object.create(null) as ModuleMapItem; |
| 464 | map.set(id, moduleMap); |
| 465 | } |
| 466 | const platform = |
| 467 | getPlatformExtension(module[H.PATH], this._options.platforms) || |
| 468 | H.GENERIC_PLATFORM; |
| 469 | |
| 470 | const existingModule = moduleMap[platform]; |
| 471 | |
| 472 | if (existingModule && existingModule[H.PATH] !== module[H.PATH]) { |
| 473 | const method = this._options.throwOnModuleCollision ? 'error' : 'warn'; |
| 474 | |
| 475 | this._console[method]( |
| 476 | [ |
| 477 | `jest-haste-map: Haste module naming collision: ${id}`, |
| 478 | ' The following files share their name; please adjust your hasteImpl:', |
| 479 | ` * <rootDir>${path.sep}${existingModule[H.PATH]}`, |
| 480 | ` * <rootDir>${path.sep}${module[H.PATH]}`, |
| 481 | '', |
| 482 | ].join('\n'), |
| 483 | ); |
| 484 | |
| 485 | if (this._options.throwOnModuleCollision) { |
| 486 | throw new DuplicateError(existingModule[H.PATH], module[H.PATH]); |
| 487 | } |
| 488 | |
| 489 | // We do NOT want consumers to use a module that is ambiguous. |
| 490 | delete moduleMap[platform]; |
| 491 | |
| 492 | if (Object.keys(moduleMap).length === 1) { |
| 493 | map.delete(id); |
| 494 | } |
| 495 | |
| 496 | let dupsByPlatform = hasteMap.duplicates.get(id); |
| 497 | if (dupsByPlatform == null) { |
| 498 | dupsByPlatform = new Map(); |
| 499 | hasteMap.duplicates.set(id, dupsByPlatform); |
| 500 | } |
| 501 | |
| 502 | const dups = new Map([ |
| 503 | [module[H.PATH], module[H.TYPE]], |
| 504 | [existingModule[H.PATH], existingModule[H.TYPE]], |
| 505 | ]); |
| 506 | dupsByPlatform.set(platform, dups); |
| 507 | |
| 508 | return; |
| 509 | } |
| 510 | |
| 511 | const dupsByPlatform = hasteMap.duplicates.get(id); |
| 512 | if (dupsByPlatform != null) { |
| 513 | const dups = dupsByPlatform.get(platform); |
| 514 | if (dups != null) { |
| 515 | dups.set(module[H.PATH], module[H.TYPE]); |
| 516 | } |
| 517 | return; |
nothing calls this directly
no test coverage detected