chore: define __metadata for bundlers

This commit is contained in:
Nathan Walker
2025-07-05 22:21:04 -07:00
parent 4039e2c86e
commit 0fe60552a3

View File

@@ -381,6 +381,27 @@ function isTestingEnv() {
return typeof jest !== 'undefined' || global.__UNIT_TEST__;
}
if (typeof global.__metadata === 'undefined') {
/**
* TS decorator metadata helper.
* @param metadataKey the metadata key (e.g. "design:type")
* @param metadataValue the metadata value (e.g. the constructor function)
* @returns a decorator function, or undefined if Reflect.metadata isnt available
*/
global.__metadata = (metadataKey, metadataValue) => {
if (
typeof Reflect === 'object' &&
// @ts-expect-error
typeof Reflect.metadata === 'function'
) {
// Delegate to the reflect-metadata shim
// @ts-expect-error
return Reflect.metadata(metadataKey, metadataValue);
}
// no-op if no Reflect.metadata
};
}
if (!global.NativeScriptHasInitGlobal && !isTestingEnv()) {
initGlobal();
}