@@ -8,7 +8,7 @@ import { promisify } from "util";
88import SentryCli from "@sentry/cli" ;
99import { dynamicSamplingContextToSentryBaggageHeader } from "@sentry/utils" ;
1010import { safeFlushTelemetry } from "./sentry/telemetry" ;
11- import { stripQueryAndHashFromPath } from "./utils" ;
11+ import { getDebugIdFromMagicComment , stripQueryAndHashFromPath } from "./utils" ;
1212import { setMeasurement , spanToTraceHeader , startSpan } from "@sentry/core" ;
1313import { getDynamicSamplingContextFromSpan , Scope } from "@sentry/core" ;
1414import { Client } from "@sentry/types" ;
@@ -223,7 +223,8 @@ export async function prepareBundleForDebugIdUpload(
223223 return ;
224224 }
225225
226- const debugId = determineDebugIdFromBundleSource ( bundleContent ) ;
226+ const debugIdFromMagicComment = getDebugIdFromMagicComment ( bundleContent ) ;
227+ const debugId = debugIdFromMagicComment || getDebugIdFromPolyfill ( bundleContent ) ;
227228 if ( debugId === undefined ) {
228229 logger . debug (
229230 `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(
233234
234235 const uniqueUploadName = `${ debugId } -${ chunkIndex } ` ;
235236
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+ ) ;
242245
243246 const writeSourceMapFilePromise = determineSourceMapPathFromBundle (
244247 bundleFilePath ,
@@ -266,7 +269,7 @@ export async function prepareBundleForDebugIdUpload(
266269 *
267270 * The string pattern is injected via the debug ID injection snipped.
268271 */
269- function determineDebugIdFromBundleSource ( code : string ) : string | undefined {
272+ function getDebugIdFromPolyfill ( code : string ) : string | undefined {
270273 const match = code . match (
271274 / 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 } ) /
272275 ) ;
0 commit comments