-
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.
Extract
DuplicateHasteCandidatesError
from ModuleMap
implementation
Summary: `DuplicateHasteCandidatesError` was previously defined within `ModuleMap.js` and exported as a static property of `ModuleMap`. Move it into its own file in preparation for making `ModuleMap` a private implementation of a public interface. Changelog: Internal Reviewed By: jacdebug Differential Revision: D41035344 fbshipit-source-id: af6b2e0ed53a0f5306fea10a939addfab3e00c26
- Loading branch information
1 parent
951c1d9
commit a4afc45
Showing
5 changed files
with
74 additions
and
61 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
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
65 changes: 65 additions & 0 deletions
65
packages/metro-file-map/src/lib/DuplicateHasteCandidatesError.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow strict-local | ||
* @format | ||
* @oncall react_native | ||
*/ | ||
|
||
import type {DuplicatesSet} from '../flow-types'; | ||
|
||
import H from '../constants'; | ||
|
||
export class DuplicateHasteCandidatesError extends Error { | ||
hasteName: string; | ||
platform: string | null; | ||
supportsNativePlatform: boolean; | ||
duplicatesSet: DuplicatesSet; | ||
|
||
constructor( | ||
name: string, | ||
platform: string, | ||
supportsNativePlatform: boolean, | ||
duplicatesSet: DuplicatesSet, | ||
) { | ||
const platformMessage = getPlatformMessage(platform); | ||
super( | ||
`The name \`${name}\` was looked up in the Haste module map. It ` + | ||
'cannot be resolved, because there exists several different ' + | ||
'files, or packages, that provide a module for ' + | ||
`that particular name and platform. ${platformMessage} You must ` + | ||
'delete or exclude files until there remains only one of these:\n\n' + | ||
Array.from(duplicatesSet) | ||
.map( | ||
([dupFilePath, dupFileType]) => | ||
` * \`${dupFilePath}\` (${getTypeMessage(dupFileType)})\n`, | ||
) | ||
.sort() | ||
.join(''), | ||
); | ||
this.hasteName = name; | ||
this.platform = platform; | ||
this.supportsNativePlatform = supportsNativePlatform; | ||
this.duplicatesSet = duplicatesSet; | ||
} | ||
} | ||
|
||
function getPlatformMessage(platform: string) { | ||
if (platform === H.GENERIC_PLATFORM) { | ||
return 'The platform is generic (no extension).'; | ||
} | ||
return `The platform extension is \`${platform}\`.`; | ||
} | ||
|
||
function getTypeMessage(type: number) { | ||
switch (type) { | ||
case H.MODULE: | ||
return 'module'; | ||
case H.PACKAGE: | ||
return 'package'; | ||
} | ||
return 'unknown'; | ||
} |
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