UNPKG

@sentry/nextjs

Version:
109 lines (105 loc) 4.06 kB
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); const core = require('@sentry/core'); const path = require('path'); const webpack = require('@sentry/server-utils/orchestrion/webpack'); const util = require('../util.js'); const generateValueInjectionRules = require('./generateValueInjectionRules.js'); function constructTurbopackConfig({ userNextConfig, userSentryOptions, routeManifest, nextJsVersion, vercelCronsConfig }) { const shouldEnableNativeDebugIds = (util.supportsNativeDebugIds(nextJsVersion ?? "") && userNextConfig?.turbopack?.debugIds) ?? userSentryOptions?.sourcemaps?.disable !== true; const newConfig = { ...userNextConfig.turbopack, ...shouldEnableNativeDebugIds ? { debugIds: true } : {} }; const tunnelPath = userSentryOptions?.tunnelRoute !== void 0 && userNextConfig.output !== "export" && typeof userSentryOptions.tunnelRoute === "string" ? `${userNextConfig.basePath ?? ""}${userSentryOptions.tunnelRoute}` : void 0; const valueInjectionRules = generateValueInjectionRules.generateValueInjectionRules({ routeManifest, nextJsVersion, tunnelPath, vercelCronsConfig }); for (const { matcher, rule } of valueInjectionRules) { newConfig.rules = safelyAddTurbopackRule(newConfig.rules, { matcher, rule }); } const applicationKey = userSentryOptions?.applicationKey ?? userSentryOptions?._experimental?.turbopackApplicationKey; if (applicationKey && nextJsVersion && util.supportsTurbopackRuleCondition(nextJsVersion)) { newConfig.rules = safelyAddTurbopackRule(newConfig.rules, { matcher: "*.{ts,tsx,js,jsx,mjs,cjs}", rule: { condition: { not: { path: /next\/dist\/build\/polyfills/ } }, loaders: [ { loader: path.resolve(__dirname, "..", "loaders", "moduleMetadataInjectionLoader.js"), options: { applicationKey } } ] } }); } const turbopackReactComponentAnnotation = userSentryOptions?._experimental?.turbopackReactComponentAnnotation; if (turbopackReactComponentAnnotation?.enabled && nextJsVersion && util.supportsTurbopackRuleCondition(nextJsVersion)) { newConfig.rules = safelyAddTurbopackRule(newConfig.rules, { matcher: "*.{tsx,jsx}", rule: { condition: { not: "foreign" }, loaders: [ { loader: path.resolve(__dirname, "..", "loaders", "componentAnnotationLoader.js"), options: { ignoredComponents: turbopackReactComponentAnnotation.ignoredComponents ?? [] } } ] } }); } newConfig.rules = maybeAddOrchestrionRule(newConfig.rules, userSentryOptions, nextJsVersion); return newConfig; } function maybeAddOrchestrionRule(rules, userSentryOptions, nextJsVersion) { if (!userSentryOptions?._experimental?.useDiagnosticsChannelInjection || !nextJsVersion || !util.supportsTurbopackRuleCondition(nextJsVersion)) { return rules; } return safelyAddTurbopackRule(rules, { matcher: "*.{js,mjs,cjs}", rule: { condition: "node", loaders: [ { loader: webpack.getOrchestrionLoaderPath(), // Turbopack JSON-serializes loader options, so a RegExp `filePath` must be encoded first. options: { instrumentations: webpack.serializeInstrumentations(webpack.getSentryInstrumentations()) } } ] } }); } function safelyAddTurbopackRule(existingRules, { matcher, rule }) { if (!existingRules) { return { [matcher]: rule }; } if (existingRules[matcher]) { core.debug.log( `[@sentry/nextjs] - Turbopack rule already exists for ${matcher}. Please remove it from your Next.js config in order for Sentry to work properly.` ); return existingRules; } return { ...existingRules, [matcher]: rule }; } exports.constructTurbopackConfig = constructTurbopackConfig; exports.safelyAddTurbopackRule = safelyAddTurbopackRule; //# sourceMappingURL=constructTurbopackConfig.js.map