Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Log package configuration warnings from package exports resolution
Summary: - Make "exports" package validation load-bearing by implementing [*Invalid Package Configuration* error](https://nodejs.org/docs/latest-v19.x/api/esm.html#esm_resolver_algorithm_specification). - Always catch error and output event to terminal/externally configured reporter using `context.unstable_logWarning`. Changelog: **[Internal]** Reviewed By: motiz88 Differential Revision: D43192757 fbshipit-source-id: 17e314d3a59589a49110a930ee612a76ffe7a2ed
- Loading branch information
1 parent
0f7268f
commit aa20356
Showing
4 changed files
with
109 additions
and
30 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
46 changes: 46 additions & 0 deletions
46
packages/metro-resolver/src/errors/InvalidPackageConfigurationError.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,46 @@ | ||
/** | ||
* 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 | ||
* @format | ||
* @oncall react_native | ||
*/ | ||
|
||
/** | ||
* Raised when a package contains an invalid `package.json` configuration. | ||
*/ | ||
export default class InvalidPackageConfigurationError extends Error { | ||
/** | ||
* The description of the error cause. | ||
*/ | ||
reason: string; | ||
|
||
/** | ||
* The module path or import specifier attempted. | ||
*/ | ||
modulePath: string; | ||
|
||
/** | ||
* Absolute path of the package being resolved. | ||
*/ | ||
packagePath: string; | ||
|
||
constructor( | ||
opts: $ReadOnly<{ | ||
reason: string, | ||
modulePath: string, | ||
packagePath: string, | ||
}>, | ||
) { | ||
super( | ||
`The package ${opts.packagePath} contains an invalid package.json ` + | ||
'configuration. Consider raising this issue with the package ' + | ||
'maintainer(s).\nReason: ' + | ||
opts.reason, | ||
); | ||
Object.assign(this, opts); | ||
} | ||
} |
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