@@ -8,7 +8,7 @@ import { promisify } from "util";
8
8
import SentryCli from "@sentry/cli" ;
9
9
import { dynamicSamplingContextToSentryBaggageHeader } from "@sentry/utils" ;
10
10
import { safeFlushTelemetry } from "./sentry/telemetry" ;
11
- import { stripQueryAndHashFromPath } from "./utils" ;
11
+ import { getDebugIdFromMagicComment , stripQueryAndHashFromPath } from "./utils" ;
12
12
import { setMeasurement , spanToTraceHeader , startSpan } from "@sentry/core" ;
13
13
import { getDynamicSamplingContextFromSpan , Scope } from "@sentry/core" ;
14
14
import { Client } from "@sentry/types" ;
@@ -223,7 +223,8 @@ export async function prepareBundleForDebugIdUpload(
223
223
return ;
224
224
}
225
225
226
- const debugId = determineDebugIdFromBundleSource ( bundleContent ) ;
226
+ const debugIdFromMagicComment = getDebugIdFromMagicComment ( bundleContent ) ;
227
+ const debugId = debugIdFromMagicComment || getDebugIdFromPolyfill ( bundleContent ) ;
227
228
if ( debugId === undefined ) {
228
229
logger . debug (
229
230
`Could not determine debug ID from bundle. This can happen if you did not clean your output folder before installing the Sentry plugin. File will not be source mapped: ${ bundleFilePath } `
@@ -233,12 +234,14 @@ export async function prepareBundleForDebugIdUpload(
233
234
234
235
const uniqueUploadName = `${ debugId } -${ chunkIndex } ` ;
235
236
236
- bundleContent += `\n//# debugId=${ debugId } ` ;
237
- const writeSourceFilePromise = fs . promises . writeFile (
238
- path . join ( uploadFolder , `${ uniqueUploadName } .js` ) ,
239
- bundleContent ,
240
- "utf-8"
241
- ) ;
237
+ // Only add the debug ID magic comment if source file does not already contain it
238
+ const writeSourceFilePromise = debugIdFromMagicComment
239
+ ? Promise . resolve ( )
240
+ : fs . promises . writeFile (
241
+ path . join ( uploadFolder , `${ uniqueUploadName } .js` ) ,
242
+ bundleContent + `\n//# debugId=${ debugId } ` ,
243
+ "utf-8"
244
+ ) ;
242
245
243
246
const writeSourceMapFilePromise = determineSourceMapPathFromBundle (
244
247
bundleFilePath ,
@@ -266,7 +269,7 @@ export async function prepareBundleForDebugIdUpload(
266
269
*
267
270
* The string pattern is injected via the debug ID injection snipped.
268
271
*/
269
- function determineDebugIdFromBundleSource ( code : string ) : string | undefined {
272
+ function getDebugIdFromPolyfill ( code : string ) : string | undefined {
270
273
const match = code . match (
271
274
/ s e n t r y - d b i d - ( [ 0 - 9 a - f A - F ] { 8 } \b - [ 0 - 9 a - f A - F ] { 4 } \b - [ 0 - 9 a - f A - F ] { 4 } \b - [ 0 - 9 a - f A - F ] { 4 } \b - [ 0 - 9 a - f A - F ] { 12 } ) /
272
275
) ;
0 commit comments