|
1 | 1 | import { debug } from '@sentry/core'; |
| 2 | +import * as path from 'path'; |
2 | 3 | import type { VercelCronsConfig } from '../../common/types'; |
3 | 4 | import type { RouteManifest } from '../manifest/types'; |
4 | 5 | import type { NextConfigObject, SentryBuildOptions, TurbopackMatcherWithRule, TurbopackOptions } from '../types'; |
5 | | -import { supportsNativeDebugIds } from '../util'; |
| 6 | +import { supportsNativeDebugIds, supportsTurbopackRuleCondition } from '../util'; |
6 | 7 | import { generateValueInjectionRules } from './generateValueInjectionRules'; |
7 | 8 |
|
8 | 9 | /** |
@@ -56,6 +57,32 @@ export function constructTurbopackConfig({ |
56 | 57 | newConfig.rules = safelyAddTurbopackRule(newConfig.rules, { matcher, rule }); |
57 | 58 | } |
58 | 59 |
|
| 60 | + // Add module metadata injection loader for thirdPartyErrorFilterIntegration support. |
| 61 | + // This is only added when turbopackApplicationKey is set AND the Next.js version supports the |
| 62 | + // `condition` field in Turbopack rules (Next.js 16+). Without `condition: { not: 'foreign' }`, |
| 63 | + // the loader would tag node_modules as first-party, defeating the purpose. |
| 64 | + const applicationKey = userSentryOptions?._experimental?.turbopackApplicationKey; |
| 65 | + if ( |
| 66 | + applicationKey && |
| 67 | + nextJsVersion && |
| 68 | + supportsTurbopackRuleCondition(nextJsVersion) |
| 69 | + ) { |
| 70 | + newConfig.rules = safelyAddTurbopackRule(newConfig.rules, { |
| 71 | + matcher: '*.{ts,tsx,js,jsx,mjs,cjs}', |
| 72 | + rule: { |
| 73 | + condition: { not: 'foreign' }, |
| 74 | + loaders: [ |
| 75 | + { |
| 76 | + loader: path.resolve(__dirname, '..', 'loaders', 'moduleMetadataInjectionLoader.js'), |
| 77 | + options: { |
| 78 | + applicationKey, |
| 79 | + }, |
| 80 | + }, |
| 81 | + ], |
| 82 | + }, |
| 83 | + }); |
| 84 | + } |
| 85 | + |
59 | 86 | return newConfig; |
60 | 87 | } |
61 | 88 |
|
|
0 commit comments