From 0fe60552a3ebd47eb405521b38b9da2dc66e1af0 Mon Sep 17 00:00:00 2001 From: Nathan Walker Date: Sat, 5 Jul 2025 22:21:04 -0700 Subject: [PATCH] chore: define __metadata for bundlers --- packages/core/globals/index.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/packages/core/globals/index.ts b/packages/core/globals/index.ts index 5cc9397cf..51d7dd959 100644 --- a/packages/core/globals/index.ts +++ b/packages/core/globals/index.ts @@ -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 isn’t 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(); }