UNPKG

@sentry/nextjs

Version:
16 lines (13 loc) • 1.08 kB
import { getCodeInjectionPosition } from '@sentry/bundler-plugins/loader-utils'; function moduleMetadataInjectionLoader(userCode) { const { applicationKey } = "getOptions" in this ? this.getOptions() : this.query; this.cacheable(false); const metadata = JSON.stringify({ [`_sentryBundlerPluginAppKey:${applicationKey}`]: true }); const injectedCode = `;!function(){try{var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};e._sentryModuleMetadata=e._sentryModuleMetadata||{},e._sentryModuleMetadata[(new e.Error).stack]=Object.assign({},e._sentryModuleMetadata[(new e.Error).stack],${metadata});}catch(e){}}();`; const injectionIndex = getCodeInjectionPosition(userCode); const codeToInject = injectionIndex === userCode.length ? ` ${injectedCode}` : injectedCode; return `${userCode.slice(0, injectionIndex)}${codeToInject}${userCode.slice(injectionIndex)}`; } export { moduleMetadataInjectionLoader as default }; //# sourceMappingURL=moduleMetadataInjectionLoader.js.map