@sentry/bundler-plugin-core 4.6.1 → 4.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8299,7 +8299,7 @@ function createSentryInstance(options, shouldSendTelemetry, buildTool) {
8299
8299
  dsn: "https://4c2bae7d9fbc413e8f7385f55c515d51@o1.ingest.sentry.io/6690737",
8300
8300
  tracesSampleRate: 1,
8301
8301
  sampleRate: 1,
8302
- release: "4.6.1",
8302
+ release: "4.6.2",
8303
8303
  integrations: [],
8304
8304
  tracePropagationTargets: ["sentry.io/api"],
8305
8305
  stackParser: stackParser,
@@ -8908,7 +8908,7 @@ function createSentryBuildPluginManager(userOptions, bundlerPluginMetaContext) {
8908
8908
  });
8909
8909
 
8910
8910
  // Set the User-Agent that Sentry CLI will use when interacting with Sentry
8911
- process.env["SENTRY_PIPELINE"] = "".concat(bundlerPluginMetaContext.buildTool, "-plugin/", "4.6.1");
8911
+ process.env["SENTRY_PIPELINE"] = "".concat(bundlerPluginMetaContext.buildTool, "-plugin/", "4.6.2");
8912
8912
 
8913
8913
  // Propagate debug flag to Sentry CLI via environment variable
8914
8914
  // Only set if not already defined to respect user's explicit configuration
@@ -9905,42 +9905,76 @@ var COMMENT_USE_STRICT_REGEX =
9905
9905
  * about type mismatches
9906
9906
  */
9907
9907
 
9908
+ /**
9909
+ * Checks if a file is a JavaScript file based on its extension.
9910
+ * Handles query strings and hashes in the filename.
9911
+ */
9912
+ function isJsFile(fileName) {
9913
+ var cleanFileName = stripQueryAndHashFromPath(fileName);
9914
+ return [".js", ".mjs", ".cjs"].some(function (ext) {
9915
+ return cleanFileName.endsWith(ext);
9916
+ });
9917
+ }
9918
+
9919
+ /**
9920
+ * Checks if a chunk should be skipped for code injection
9921
+ *
9922
+ * This is necessary to handle Vite's MPA (multi-page application) mode where
9923
+ * HTML entry points create "facade" chunks that should not contain injected code.
9924
+ * See: https://github.com/getsentry/sentry-javascript-bundler-plugins/issues/829
9925
+ *
9926
+ * @param code - The chunk's code content
9927
+ * @param facadeModuleId - The facade module ID (if any) - HTML files create facade chunks
9928
+ * @returns true if the chunk should be skipped
9929
+ */
9930
+ function shouldSkipCodeInjection(code, facadeModuleId) {
9931
+ // Skip empty chunks - these are placeholder chunks that should be optimized away
9932
+ if (code.trim().length === 0) {
9933
+ return true;
9934
+ }
9935
+
9936
+ // Skip HTML facade chunks
9937
+ // They only contain import statements and should not have Sentry code injected
9938
+ if (facadeModuleId && stripQueryAndHashFromPath(facadeModuleId).endsWith(".html")) {
9939
+ return true;
9940
+ }
9941
+ return false;
9942
+ }
9908
9943
  function createRollupReleaseInjectionHooks(injectionCode) {
9909
9944
  return {
9910
9945
  renderChunk: function renderChunk(code, chunk) {
9911
- if (
9912
- // chunks could be any file (html, md, ...)
9913
- [".js", ".mjs", ".cjs"].some(function (ending) {
9914
- return stripQueryAndHashFromPath(chunk.fileName).endsWith(ending);
9915
- })) {
9916
- var _code$match;
9917
- var ms = new MagicString(code, {
9918
- filename: chunk.fileName
9919
- });
9920
- var match = (_code$match = code.match(COMMENT_USE_STRICT_REGEX)) === null || _code$match === void 0 ? void 0 : _code$match[0];
9921
- if (match) {
9922
- // Add injected code after any comments or "use strict" at the beginning of the bundle.
9923
- ms.appendLeft(match.length, injectionCode);
9924
- } else {
9925
- // ms.replace() doesn't work when there is an empty string match (which happens if
9926
- // there is neither, a comment, nor a "use strict" at the top of the chunk) so we
9927
- // need this special case here.
9928
- ms.prepend(injectionCode);
9929
- }
9930
- return {
9931
- code: ms.toString(),
9932
- map: ms.generateMap({
9933
- file: chunk.fileName,
9934
- hires: "boundary"
9935
- })
9936
- };
9937
- } else {
9946
+ var _code$match;
9947
+ if (!isJsFile(chunk.fileName)) {
9938
9948
  return null; // returning null means not modifying the chunk at all
9939
9949
  }
9950
+
9951
+ // Skip empty chunks and HTML facade chunks (Vite MPA)
9952
+ if (shouldSkipCodeInjection(code, chunk.facadeModuleId)) {
9953
+ return null;
9954
+ }
9955
+ var ms = new MagicString(code, {
9956
+ filename: chunk.fileName
9957
+ });
9958
+ var match = (_code$match = code.match(COMMENT_USE_STRICT_REGEX)) === null || _code$match === void 0 ? void 0 : _code$match[0];
9959
+ if (match) {
9960
+ // Add injected code after any comments or "use strict" at the beginning of the bundle.
9961
+ ms.appendLeft(match.length, injectionCode);
9962
+ } else {
9963
+ // ms.replace() doesn't work when there is an empty string match (which happens if
9964
+ // there is neither, a comment, nor a "use strict" at the top of the chunk) so we
9965
+ // need this special case here.
9966
+ ms.prepend(injectionCode);
9967
+ }
9968
+ return {
9969
+ code: ms.toString(),
9970
+ map: ms.generateMap({
9971
+ file: chunk.fileName,
9972
+ hires: "boundary"
9973
+ })
9974
+ };
9940
9975
  }
9941
9976
  };
9942
9977
  }
9943
-
9944
9978
  function createRollupBundleSizeOptimizationHooks(replacementValues) {
9945
9979
  return {
9946
9980
  transform: function transform(code) {
@@ -9951,77 +9985,83 @@ function createRollupBundleSizeOptimizationHooks(replacementValues) {
9951
9985
  function createRollupDebugIdInjectionHooks() {
9952
9986
  return {
9953
9987
  renderChunk: function renderChunk(code, chunk) {
9954
- if (
9955
- // chunks could be any file (html, md, ...)
9956
- [".js", ".mjs", ".cjs"].some(function (ending) {
9957
- return stripQueryAndHashFromPath(chunk.fileName).endsWith(ending);
9958
- })) {
9959
- var _code$match2;
9960
- var debugId = stringToUUID(code); // generate a deterministic debug ID
9961
- var codeToInject = getDebugIdSnippet(debugId);
9962
- var ms = new MagicString(code, {
9963
- filename: chunk.fileName
9964
- });
9965
- var match = (_code$match2 = code.match(COMMENT_USE_STRICT_REGEX)) === null || _code$match2 === void 0 ? void 0 : _code$match2[0];
9966
- if (match) {
9967
- // Add injected code after any comments or "use strict" at the beginning of the bundle.
9968
- ms.appendLeft(match.length, codeToInject);
9969
- } else {
9970
- // ms.replace() doesn't work when there is an empty string match (which happens if
9971
- // there is neither, a comment, nor a "use strict" at the top of the chunk) so we
9972
- // need this special case here.
9973
- ms.prepend(codeToInject);
9974
- }
9975
- return {
9976
- code: ms.toString(),
9977
- map: ms.generateMap({
9978
- file: chunk.fileName,
9979
- hires: "boundary"
9980
- })
9981
- };
9982
- } else {
9988
+ var _code$match2;
9989
+ if (!isJsFile(chunk.fileName)) {
9983
9990
  return null; // returning null means not modifying the chunk at all
9984
9991
  }
9992
+
9993
+ // Skip empty chunks and HTML facade chunks (Vite MPA)
9994
+ if (shouldSkipCodeInjection(code, chunk.facadeModuleId)) {
9995
+ return null;
9996
+ }
9997
+
9998
+ // Check if a debug ID has already been injected to avoid duplicate injection (e.g. by another plugin or Sentry CLI)
9999
+ var chunkStartSnippet = code.slice(0, 6000);
10000
+ var chunkEndSnippet = code.slice(-500);
10001
+ if (chunkStartSnippet.includes("_sentryDebugIdIdentifier") || chunkEndSnippet.includes("//# debugId=")) {
10002
+ return null; // Debug ID already present, skip injection
10003
+ }
10004
+
10005
+ var debugId = stringToUUID(code); // generate a deterministic debug ID
10006
+ var codeToInject = getDebugIdSnippet(debugId);
10007
+ var ms = new MagicString(code, {
10008
+ filename: chunk.fileName
10009
+ });
10010
+ var match = (_code$match2 = code.match(COMMENT_USE_STRICT_REGEX)) === null || _code$match2 === void 0 ? void 0 : _code$match2[0];
10011
+ if (match) {
10012
+ // Add injected code after any comments or "use strict" at the beginning of the bundle.
10013
+ ms.appendLeft(match.length, codeToInject);
10014
+ } else {
10015
+ // ms.replace() doesn't work when there is an empty string match (which happens if
10016
+ // there is neither, a comment, nor a "use strict" at the top of the chunk) so we
10017
+ // need this special case here.
10018
+ ms.prepend(codeToInject);
10019
+ }
10020
+ return {
10021
+ code: ms.toString(),
10022
+ map: ms.generateMap({
10023
+ file: chunk.fileName,
10024
+ hires: "boundary"
10025
+ })
10026
+ };
9985
10027
  }
9986
10028
  };
9987
10029
  }
9988
-
9989
10030
  function createRollupModuleMetadataInjectionHooks(injectionCode) {
9990
10031
  return {
9991
10032
  renderChunk: function renderChunk(code, chunk) {
9992
- if (
9993
- // chunks could be any file (html, md, ...)
9994
- [".js", ".mjs", ".cjs"].some(function (ending) {
9995
- return stripQueryAndHashFromPath(chunk.fileName).endsWith(ending);
9996
- })) {
9997
- var _code$match3;
9998
- var ms = new MagicString(code, {
9999
- filename: chunk.fileName
10000
- });
10001
- var match = (_code$match3 = code.match(COMMENT_USE_STRICT_REGEX)) === null || _code$match3 === void 0 ? void 0 : _code$match3[0];
10002
- if (match) {
10003
- // Add injected code after any comments or "use strict" at the beginning of the bundle.
10004
- ms.appendLeft(match.length, injectionCode);
10005
- } else {
10006
- // ms.replace() doesn't work when there is an empty string match (which happens if
10007
- // there is neither, a comment, nor a "use strict" at the top of the chunk) so we
10008
- // need this special case here.
10009
- ms.prepend(injectionCode);
10010
- }
10011
- return {
10012
- code: ms.toString(),
10013
- map: ms.generateMap({
10014
- file: chunk.fileName,
10015
- hires: "boundary"
10016
- })
10017
- };
10018
- } else {
10033
+ var _code$match3;
10034
+ if (!isJsFile(chunk.fileName)) {
10019
10035
  return null; // returning null means not modifying the chunk at all
10020
10036
  }
10037
+
10038
+ // Skip empty chunks and HTML facade chunks (Vite MPA)
10039
+ if (shouldSkipCodeInjection(code, chunk.facadeModuleId)) {
10040
+ return null;
10041
+ }
10042
+ var ms = new MagicString(code, {
10043
+ filename: chunk.fileName
10044
+ });
10045
+ var match = (_code$match3 = code.match(COMMENT_USE_STRICT_REGEX)) === null || _code$match3 === void 0 ? void 0 : _code$match3[0];
10046
+ if (match) {
10047
+ // Add injected code after any comments or "use strict" at the beginning of the bundle.
10048
+ ms.appendLeft(match.length, injectionCode);
10049
+ } else {
10050
+ // ms.replace() doesn't work when there is an empty string match (which happens if
10051
+ // there is neither, a comment, nor a "use strict" at the top of the chunk) so we
10052
+ // need this special case here.
10053
+ ms.prepend(injectionCode);
10054
+ }
10055
+ return {
10056
+ code: ms.toString(),
10057
+ map: ms.generateMap({
10058
+ file: chunk.fileName,
10059
+ hires: "boundary"
10060
+ })
10061
+ };
10021
10062
  }
10022
10063
  };
10023
10064
  }
10024
-
10025
10065
  function createRollupDebugIdUploadHooks(upload, _logger, createDependencyOnBuildArtifacts) {
10026
10066
  var freeGlobalDependencyOnDebugIdSourcemapArtifacts = createDependencyOnBuildArtifacts();
10027
10067
  return {