fix(lib/modules/metro): fix bad exports check

This commit is contained in:
PalmDevs 2025-04-06 00:10:13 +07:00
parent 3c0405e64b
commit c5caa63cef
No known key found for this signature in database
GPG key ID: 6FAE8F8677ACA8BA

View file

@ -84,6 +84,8 @@ export function _isExportBad(exp: Metro.ModuleExports) {
// Nullish?
exp === undefined ||
exp === null ||
// Circular reference
exp === globalThis ||
// Is it a proxy?
isProxy(exp)
)
@ -97,9 +99,13 @@ export function _isExportBad(exp: Metro.ModuleExports) {
*/
export function _isExportsBad(exports: Metro.ModuleExports) {
return (
// Exports will always be an object, we are checking if the object is empty
!Reflect.ownKeys(exports).length ||
// Circular reference
exports === globalThis
// Nullish?
exports === undefined ||
exports === null ||
// Can't run isProxy() on this because this isn't your typical proxy:
// https://github.com/discord/react-native/blob/master/packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/TurboModuleBinding.cpp
(globalThis.nativeModuleProxy && exports === nativeModuleProxy) ||
// Checking if the object is empty
(exports.__proto__ === Object.prototype && !Reflect.ownKeys(exports).length)
)
}