@sentry/bundler-plugin-core 4.6.1 → 4.7.0

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.
@@ -7999,6 +7999,48 @@ function getProjects(project) {
7999
7999
  return undefined;
8000
8000
  }
8001
8001
 
8002
+ /**
8003
+ * Inlined functionality from @sentry/cli helper code to add `--ignore` options.
8004
+ *
8005
+ * Temporary workaround until we expose a function for injecting debug IDs. Currently, we directly call `execute` with CLI args to inject them.
8006
+ */
8007
+ function serializeIgnoreOptions(ignoreValue) {
8008
+ var DEFAULT_IGNORE = ["node_modules"];
8009
+ var ignoreOptions = Array.isArray(ignoreValue) ? ignoreValue : typeof ignoreValue === "string" ? [ignoreValue] : DEFAULT_IGNORE;
8010
+ return ignoreOptions.reduce(function (acc, value) {
8011
+ return acc.concat(["--ignore", String(value)]);
8012
+ }, []);
8013
+ }
8014
+
8015
+ /**
8016
+ * Checks if a chunk contains only import/export statements and no substantial code.
8017
+ *
8018
+ * In Vite MPA (multi-page application) mode, HTML entry points create "facade" chunks
8019
+ * that only contain import statements to load shared modules. These should not have
8020
+ * Sentry code injected. However, in SPA mode, the main bundle also has an HTML facade
8021
+ * but contains substantial application code that SHOULD have debug IDs injected.
8022
+ *
8023
+ * @ref https://github.com/getsentry/sentry-javascript-bundler-plugins/issues/829
8024
+ * @ref https://github.com/getsentry/sentry-javascript-bundler-plugins/issues/839
8025
+ */
8026
+ function containsOnlyImports(code) {
8027
+ var codeWithoutImports = code
8028
+ // Remove side effect imports: import '/path'; or import "./path";
8029
+ // Using explicit negated character classes to avoid polynomial backtracking
8030
+ .replace(/^\s*import\s+(?:'[^'\n]*'|"[^"\n]*"|`[^`\n]*`)[\s;]*$/gm, "")
8031
+ // Remove named/default imports: import x from '/path'; import { x } from '/path';
8032
+ .replace(/^\s*import\b[^'"`\n]*\bfrom\s+(?:'[^'\n]*'|"[^"\n]*"|`[^`\n]*`)[\s;]*$/gm, "")
8033
+ // Remove re-exports: export * from '/path'; export { x } from '/path';
8034
+ .replace(/^\s*export\b[^'"`\n]*\bfrom\s+(?:'[^'\n]*'|"[^"\n]*"|`[^`\n]*`)[\s;]*$/gm, "")
8035
+ // Remove block comments
8036
+ .replace(/\/\*[\s\S]*?\*\//g, "")
8037
+ // Remove line comments
8038
+ .replace(/\/\/.*$/gm, "")
8039
+ // Remove "use strict" directives
8040
+ .replace(/["']use strict["']\s*;?/g, "").trim();
8041
+ return codeWithoutImports.length === 0;
8042
+ }
8043
+
8002
8044
  var SENTRY_SAAS_URL = "https://sentry.io";
8003
8045
  function normalizeUserOptions(userOptions) {
8004
8046
  var _userOptions$org, _userOptions$project, _process$env$SENTRY_P, _userOptions$authToke, _ref, _userOptions$url, _userOptions$debug, _userOptions$silent, _userOptions$telemetr, _userOptions$disable, _ref2, _userOptions$release$, _userOptions$release, _userOptions$release$2, _userOptions$release2, _userOptions$release$3, _userOptions$release3, _userOptions$release$4, _userOptions$release4, _ref3, _userOptions$release$5, _userOptions$release5, _userOptions$release6, _userOptions$_metaOpt, _userOptions$_metaOpt2, _userOptions$_experim;
@@ -8299,7 +8341,7 @@ function createSentryInstance(options, shouldSendTelemetry, buildTool) {
8299
8341
  dsn: "https://4c2bae7d9fbc413e8f7385f55c515d51@o1.ingest.sentry.io/6690737",
8300
8342
  tracesSampleRate: 1,
8301
8343
  sampleRate: 1,
8302
- release: "4.6.1",
8344
+ release: "4.7.0",
8303
8345
  integrations: [],
8304
8346
  tracePropagationTargets: ["sentry.io/api"],
8305
8347
  stackParser: stackParser,
@@ -8908,7 +8950,7 @@ function createSentryBuildPluginManager(userOptions, bundlerPluginMetaContext) {
8908
8950
  });
8909
8951
 
8910
8952
  // 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");
8953
+ process.env["SENTRY_PIPELINE"] = "".concat(bundlerPluginMetaContext.buildTool, "-plugin/", "4.7.0");
8912
8954
 
8913
8955
  // Propagate debug flag to Sentry CLI via environment variable
8914
8956
  // Only set if not already defined to respect user's explicit configuration
@@ -9276,14 +9318,14 @@ function createSentryBuildPluginManager(userOptions, bundlerPluginMetaContext) {
9276
9318
  scope: sentryScope,
9277
9319
  forceTransaction: true
9278
9320
  }, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
9279
- var _options$debug, cliInstance;
9321
+ var _options$sourcemaps, cliInstance;
9280
9322
  return _regeneratorRuntime().wrap(function _callee8$(_context8) {
9281
9323
  while (1) switch (_context8.prev = _context8.next) {
9282
9324
  case 0:
9283
9325
  _context8.prev = 0;
9284
9326
  cliInstance = createCliInstance(options);
9285
9327
  _context8.next = 4;
9286
- return cliInstance.execute(["sourcemaps", "inject"].concat(_toConsumableArray(buildArtifactPaths)), (_options$debug = options.debug) !== null && _options$debug !== void 0 ? _options$debug : false);
9328
+ return cliInstance.execute(["sourcemaps", "inject"].concat(_toConsumableArray(serializeIgnoreOptions((_options$sourcemaps = options.sourcemaps) === null || _options$sourcemaps === void 0 ? void 0 : _options$sourcemaps.ignore)), _toConsumableArray(buildArtifactPaths)), options.debug ? "rejectOnError" : false);
9287
9329
  case 4:
9288
9330
  _context8.next = 10;
9289
9331
  break;
@@ -9323,7 +9365,7 @@ function createSentryBuildPluginManager(userOptions, bundlerPluginMetaContext) {
9323
9365
  */
9324
9366
  uploadSourcemaps: function uploadSourcemaps(buildArtifactPaths, opts) {
9325
9367
  return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19() {
9326
- var _options$sourcemaps;
9368
+ var _options$sourcemaps2;
9327
9369
  var assets;
9328
9370
  return _regeneratorRuntime().wrap(function _callee19$(_context19) {
9329
9371
  while (1) switch (_context19.prev = _context19.next) {
@@ -9335,7 +9377,7 @@ function createSentryBuildPluginManager(userOptions, bundlerPluginMetaContext) {
9335
9377
  return _context19.abrupt("return");
9336
9378
  case 2:
9337
9379
  // Early exit if assets is explicitly set to an empty array
9338
- assets = (_options$sourcemaps = options.sourcemaps) === null || _options$sourcemaps === void 0 ? void 0 : _options$sourcemaps.assets;
9380
+ assets = (_options$sourcemaps2 = options.sourcemaps) === null || _options$sourcemaps2 === void 0 ? void 0 : _options$sourcemaps2.assets;
9339
9381
  if (!(Array.isArray(assets) && assets.length === 0)) {
9340
9382
  _context19.next = 6;
9341
9383
  break;
@@ -9352,7 +9394,7 @@ function createSentryBuildPluginManager(userOptions, bundlerPluginMetaContext) {
9352
9394
  forceTransaction: true
9353
9395
  }, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18() {
9354
9396
  var _opts$prepareArtifact;
9355
- var shouldPrepare, folderToCleanUp, freeUploadDependencyOnBuildArtifacts, _options$sourcemaps2, _options$sourcemaps3, _options$sourcemaps4, _options$sourcemaps5, pathsToUpload, ignorePaths, globAssets, globResult, debugIdChunkFilePaths, tmpUploadFolder, _process$env2;
9397
+ var shouldPrepare, folderToCleanUp, freeUploadDependencyOnBuildArtifacts, _options$sourcemaps3, _options$sourcemaps4, _options$sourcemaps5, _options$sourcemaps6, pathsToUpload, ignorePaths, globAssets, globResult, debugIdChunkFilePaths, tmpUploadFolder, _process$env2;
9356
9398
  return _regeneratorRuntime().wrap(function _callee18$(_context18) {
9357
9399
  while (1) switch (_context18.prev = _context18.next) {
9358
9400
  case 0:
@@ -9375,7 +9417,7 @@ function createSentryBuildPluginManager(userOptions, bundlerPluginMetaContext) {
9375
9417
  // Use original paths e.g. like ['.next/server'] directly –> preferred way when no globbing is done
9376
9418
  pathsToUpload = buildArtifactPaths;
9377
9419
  }
9378
- ignorePaths = (_options$sourcemaps2 = options.sourcemaps) !== null && _options$sourcemaps2 !== void 0 && _options$sourcemaps2.ignore ? Array.isArray((_options$sourcemaps3 = options.sourcemaps) === null || _options$sourcemaps3 === void 0 ? void 0 : _options$sourcemaps3.ignore) ? (_options$sourcemaps4 = options.sourcemaps) === null || _options$sourcemaps4 === void 0 ? void 0 : _options$sourcemaps4.ignore : [(_options$sourcemaps5 = options.sourcemaps) === null || _options$sourcemaps5 === void 0 ? void 0 : _options$sourcemaps5.ignore] : [];
9420
+ ignorePaths = (_options$sourcemaps3 = options.sourcemaps) !== null && _options$sourcemaps3 !== void 0 && _options$sourcemaps3.ignore ? Array.isArray((_options$sourcemaps4 = options.sourcemaps) === null || _options$sourcemaps4 === void 0 ? void 0 : _options$sourcemaps4.ignore) ? (_options$sourcemaps5 = options.sourcemaps) === null || _options$sourcemaps5 === void 0 ? void 0 : _options$sourcemaps5.ignore : [(_options$sourcemaps6 = options.sourcemaps) === null || _options$sourcemaps6 === void 0 ? void 0 : _options$sourcemaps6.ignore] : [];
9379
9421
  _context18.next = 8;
9380
9422
  return startSpan({
9381
9423
  name: "upload",
@@ -9422,7 +9464,7 @@ function createSentryBuildPluginManager(userOptions, bundlerPluginMetaContext) {
9422
9464
  name: "glob",
9423
9465
  scope: sentryScope
9424
9466
  }, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
9425
- var _options$sourcemaps6;
9467
+ var _options$sourcemaps7;
9426
9468
  return _regeneratorRuntime().wrap(function _callee11$(_context11) {
9427
9469
  while (1) switch (_context11.prev = _context11.next) {
9428
9470
  case 0:
@@ -9431,7 +9473,7 @@ function createSentryBuildPluginManager(userOptions, bundlerPluginMetaContext) {
9431
9473
  absolute: true,
9432
9474
  nodir: true,
9433
9475
  // We need individual files for preparation
9434
- ignore: (_options$sourcemaps6 = options.sourcemaps) === null || _options$sourcemaps6 === void 0 ? void 0 : _options$sourcemaps6.ignore
9476
+ ignore: (_options$sourcemaps7 = options.sourcemaps) === null || _options$sourcemaps7 === void 0 ? void 0 : _options$sourcemaps7.ignore
9435
9477
  });
9436
9478
  case 2:
9437
9479
  return _context11.abrupt("return", _context11.sent);
@@ -9501,12 +9543,12 @@ function createSentryBuildPluginManager(userOptions, bundlerPluginMetaContext) {
9501
9543
  // instead we do it with a maximum of 16 concurrent workers
9502
9544
  preparationTasks = debugIdChunkFilePaths.map(function (chunkFilePath, chunkIndex) {
9503
9545
  return /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
9504
- var _options$sourcemaps$r, _options$sourcemaps7, _options$sourcemaps8;
9546
+ var _options$sourcemaps$r, _options$sourcemaps8, _options$sourcemaps9;
9505
9547
  return _regeneratorRuntime().wrap(function _callee13$(_context13) {
9506
9548
  while (1) switch (_context13.prev = _context13.next) {
9507
9549
  case 0:
9508
9550
  _context13.next = 2;
9509
- return prepareBundleForDebugIdUpload(chunkFilePath, tmpUploadFolder, chunkIndex, logger, (_options$sourcemaps$r = (_options$sourcemaps7 = options.sourcemaps) === null || _options$sourcemaps7 === void 0 ? void 0 : _options$sourcemaps7.rewriteSources) !== null && _options$sourcemaps$r !== void 0 ? _options$sourcemaps$r : defaultRewriteSourcesHook, (_options$sourcemaps8 = options.sourcemaps) === null || _options$sourcemaps8 === void 0 ? void 0 : _options$sourcemaps8.resolveSourceMap);
9551
+ return prepareBundleForDebugIdUpload(chunkFilePath, tmpUploadFolder, chunkIndex, logger, (_options$sourcemaps$r = (_options$sourcemaps8 = options.sourcemaps) === null || _options$sourcemaps8 === void 0 ? void 0 : _options$sourcemaps8.rewriteSources) !== null && _options$sourcemaps$r !== void 0 ? _options$sourcemaps$r : defaultRewriteSourcesHook, (_options$sourcemaps9 = options.sourcemaps) === null || _options$sourcemaps9 === void 0 ? void 0 : _options$sourcemaps9.resolveSourceMap);
9510
9552
  case 2:
9511
9553
  case "end":
9512
9554
  return _context13.stop();
@@ -9669,13 +9711,13 @@ function createSentryBuildPluginManager(userOptions, bundlerPluginMetaContext) {
9669
9711
  */
9670
9712
  deleteArtifacts: function deleteArtifacts() {
9671
9713
  return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20() {
9672
- var _options$sourcemaps9, filesToDelete, filePathsToDelete;
9714
+ var _options$sourcemaps10, filesToDelete, filePathsToDelete;
9673
9715
  return _regeneratorRuntime().wrap(function _callee20$(_context20) {
9674
9716
  while (1) switch (_context20.prev = _context20.next) {
9675
9717
  case 0:
9676
9718
  _context20.prev = 0;
9677
9719
  _context20.next = 3;
9678
- return (_options$sourcemaps9 = options.sourcemaps) === null || _options$sourcemaps9 === void 0 ? void 0 : _options$sourcemaps9.filesToDeleteAfterUpload;
9720
+ return (_options$sourcemaps10 = options.sourcemaps) === null || _options$sourcemaps10 === void 0 ? void 0 : _options$sourcemaps10.filesToDeleteAfterUpload;
9679
9721
  case 3:
9680
9722
  filesToDelete = _context20.sent;
9681
9723
  if (!(filesToDelete !== undefined)) {
@@ -9729,8 +9771,8 @@ function createSentryBuildPluginManager(userOptions, bundlerPluginMetaContext) {
9729
9771
  };
9730
9772
  }
9731
9773
  function canUploadSourceMaps(options, logger, isDevMode) {
9732
- var _options$sourcemaps10, _getProjects3;
9733
- if ((_options$sourcemaps10 = options.sourcemaps) !== null && _options$sourcemaps10 !== void 0 && _options$sourcemaps10.disable) {
9774
+ var _options$sourcemaps11, _getProjects3;
9775
+ if ((_options$sourcemaps11 = options.sourcemaps) !== null && _options$sourcemaps11 !== void 0 && _options$sourcemaps11.disable) {
9734
9776
  logger.debug("Source map upload was disabled. Will not upload sourcemaps using debug ID process.");
9735
9777
  return false;
9736
9778
  }
@@ -9757,14 +9799,12 @@ function canUploadSourceMaps(options, logger, isDevMode) {
9757
9799
  * Creates an unplugin instance used to create Sentry plugins for Vite, Rollup, esbuild, and Webpack.
9758
9800
  */
9759
9801
  function sentryUnpluginFactory(_ref) {
9760
- var releaseInjectionPlugin = _ref.releaseInjectionPlugin,
9802
+ var injectionPlugin = _ref.injectionPlugin,
9761
9803
  componentNameAnnotatePlugin = _ref.componentNameAnnotatePlugin,
9762
- moduleMetadataInjectionPlugin = _ref.moduleMetadataInjectionPlugin,
9763
- debugIdInjectionPlugin = _ref.debugIdInjectionPlugin,
9764
9804
  debugIdUploadPlugin = _ref.debugIdUploadPlugin,
9765
9805
  bundleSizeOptimizationsPlugin = _ref.bundleSizeOptimizationsPlugin;
9766
9806
  return createUnplugin(function () {
9767
- var _userOptions$_metaOpt, _userOptions$_metaOpt2, _options$sourcemaps;
9807
+ var _userOptions$_metaOpt, _userOptions$_metaOpt2, _options$sourcemaps, _options$sourcemaps3;
9768
9808
  var userOptions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
9769
9809
  var unpluginMetaContext = arguments.length > 1 ? arguments[1] : undefined;
9770
9810
  var sentryBuildPluginManager = createSentryBuildPluginManager(userOptions, {
@@ -9801,20 +9841,33 @@ function sentryUnpluginFactory(_ref) {
9801
9841
  if (Object.keys(bundleSizeOptimizationReplacementValues).length > 0) {
9802
9842
  plugins.push(bundleSizeOptimizationsPlugin(bundleSizeOptimizationReplacementValues));
9803
9843
  }
9844
+ var injectionCode = "";
9804
9845
  if (!options.release.inject) {
9805
9846
  logger.debug("Release injection disabled via `release.inject` option. Will not inject release.");
9806
9847
  } else if (!options.release.name) {
9807
9848
  logger.debug("No release name provided. Will not inject release. Please set the `release.name` option to identify your release.");
9808
9849
  } else {
9809
- var _injectionCode = generateGlobalInjectorCode({
9850
+ var _code = generateGlobalInjectorCode({
9810
9851
  release: options.release.name,
9811
9852
  injectBuildInformation: options._experiments.injectBuildInformation || false
9812
9853
  });
9813
- plugins.push(releaseInjectionPlugin(_injectionCode));
9854
+ if (typeof injectionPlugin !== "function") {
9855
+ plugins.push(injectionPlugin.releaseInjectionPlugin(_code));
9856
+ } else {
9857
+ injectionCode += _code;
9858
+ }
9814
9859
  }
9815
9860
  if (Object.keys(sentryBuildPluginManager.bundleMetadata).length > 0) {
9816
- var _injectionCode2 = generateModuleMetadataInjectorCode(sentryBuildPluginManager.bundleMetadata);
9817
- plugins.push(moduleMetadataInjectionPlugin(_injectionCode2));
9861
+ var _code2 = generateModuleMetadataInjectorCode(sentryBuildPluginManager.bundleMetadata);
9862
+ if (typeof injectionPlugin !== "function") {
9863
+ plugins.push(injectionPlugin.moduleMetadataInjectionPlugin(_code2));
9864
+ } else {
9865
+ injectionCode += _code2;
9866
+ }
9867
+ }
9868
+ if (typeof injectionPlugin === "function" && (injectionCode !== "" || ((_options$sourcemaps = options.sourcemaps) === null || _options$sourcemaps === void 0 ? void 0 : _options$sourcemaps.disable) !== true)) {
9869
+ var _options$sourcemaps2;
9870
+ plugins.push(injectionPlugin(injectionCode, ((_options$sourcemaps2 = options.sourcemaps) === null || _options$sourcemaps2 === void 0 ? void 0 : _options$sourcemaps2.disable) !== true, logger));
9818
9871
  }
9819
9872
 
9820
9873
  // Add plugin to create and finalize releases, and also take care of adding commits and legacy sourcemaps
@@ -9841,10 +9894,12 @@ function sentryUnpluginFactory(_ref) {
9841
9894
  }))();
9842
9895
  }
9843
9896
  });
9844
- if (((_options$sourcemaps = options.sourcemaps) === null || _options$sourcemaps === void 0 ? void 0 : _options$sourcemaps.disable) !== true) {
9845
- var _options$sourcemaps2;
9846
- plugins.push(debugIdInjectionPlugin(logger));
9847
- if (((_options$sourcemaps2 = options.sourcemaps) === null || _options$sourcemaps2 === void 0 ? void 0 : _options$sourcemaps2.disable) !== "disable-upload") {
9897
+ if (((_options$sourcemaps3 = options.sourcemaps) === null || _options$sourcemaps3 === void 0 ? void 0 : _options$sourcemaps3.disable) !== true) {
9898
+ var _options$sourcemaps4;
9899
+ if (typeof injectionPlugin !== "function") {
9900
+ plugins.push(injectionPlugin.debugIdInjectionPlugin(logger));
9901
+ }
9902
+ if (((_options$sourcemaps4 = options.sourcemaps) === null || _options$sourcemaps4 === void 0 ? void 0 : _options$sourcemaps4.disable) !== "disable-upload") {
9848
9903
  // This option is only strongly typed for the webpack plugin, where it is used. It has no effect on other plugins
9849
9904
  var _webpack_forceExitOnBuildComplete = typeof options._experiments["forceExitOnBuildCompletion"] === "boolean" ? options._experiments["forceExitOnBuildCompletion"] : undefined;
9850
9905
  plugins.push(debugIdUploadPlugin(createDebugIdUploadFunction({
@@ -9905,42 +9960,43 @@ var COMMENT_USE_STRICT_REGEX =
9905
9960
  * about type mismatches
9906
9961
  */
9907
9962
 
9908
- function createRollupReleaseInjectionHooks(injectionCode) {
9909
- return {
9910
- 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 {
9938
- return null; // returning null means not modifying the chunk at all
9939
- }
9940
- }
9941
- };
9963
+ /**
9964
+ * Checks if a file is a JavaScript file based on its extension.
9965
+ * Handles query strings and hashes in the filename.
9966
+ */
9967
+ function isJsFile(fileName) {
9968
+ var cleanFileName = stripQueryAndHashFromPath(fileName);
9969
+ return [".js", ".mjs", ".cjs"].some(function (ext) {
9970
+ return cleanFileName.endsWith(ext);
9971
+ });
9942
9972
  }
9943
9973
 
9974
+ /**
9975
+ * Checks if a chunk should be skipped for code injection
9976
+ *
9977
+ * This is necessary to handle Vite's MPA (multi-page application) mode where
9978
+ * HTML entry points create "facade" chunks that should not contain injected code.
9979
+ * See: https://github.com/getsentry/sentry-javascript-bundler-plugins/issues/829
9980
+ *
9981
+ * However, in SPA mode, the main bundle also has an HTML facade but contains
9982
+ * substantial application code. We should NOT skip injection for these bundles.
9983
+ *
9984
+ * @param code - The chunk's code content
9985
+ * @param facadeModuleId - The facade module ID (if any) - HTML files create facade chunks
9986
+ * @returns true if the chunk should be skipped
9987
+ */
9988
+ function shouldSkipCodeInjection(code, facadeModuleId) {
9989
+ // Skip empty chunks - these are placeholder chunks that should be optimized away
9990
+ if (code.trim().length === 0) {
9991
+ return true;
9992
+ }
9993
+
9994
+ // For HTML facade chunks, only skip if they contain only import statements
9995
+ if (facadeModuleId && stripQueryAndHashFromPath(facadeModuleId).endsWith(".html")) {
9996
+ return containsOnlyImports(code);
9997
+ }
9998
+ return false;
9999
+ }
9944
10000
  function createRollupBundleSizeOptimizationHooks(replacementValues) {
9945
10001
  return {
9946
10002
  transform: function transform(code) {
@@ -9948,80 +10004,51 @@ function createRollupBundleSizeOptimizationHooks(replacementValues) {
9948
10004
  }
9949
10005
  };
9950
10006
  }
9951
- function createRollupDebugIdInjectionHooks() {
10007
+ function createRollupInjectionHooks(injectionCode, debugIds) {
9952
10008
  return {
9953
10009
  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 {
10010
+ var _code$match;
10011
+ if (!isJsFile(chunk.fileName)) {
9983
10012
  return null; // returning null means not modifying the chunk at all
9984
10013
  }
9985
- }
9986
- };
9987
- }
9988
10014
 
9989
- function createRollupModuleMetadataInjectionHooks(injectionCode) {
9990
- return {
9991
- 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);
10015
+ // Skip empty chunks and HTML facade chunks (Vite MPA)
10016
+ if (shouldSkipCodeInjection(code, chunk.facadeModuleId)) {
10017
+ return null;
10018
+ }
10019
+ var codeToInject = injectionCode;
10020
+ if (debugIds) {
10021
+ // Check if a debug ID has already been injected to avoid duplicate injection (e.g. by another plugin or Sentry CLI)
10022
+ var chunkStartSnippet = code.slice(0, 6000);
10023
+ var chunkEndSnippet = code.slice(-500);
10024
+ if (!(chunkStartSnippet.includes("_sentryDebugIdIdentifier") || chunkEndSnippet.includes("//# debugId="))) {
10025
+ var debugId = stringToUUID(code); // generate a deterministic debug ID
10026
+ codeToInject += getDebugIdSnippet(debugId);
10010
10027
  }
10011
- return {
10012
- code: ms.toString(),
10013
- map: ms.generateMap({
10014
- file: chunk.fileName,
10015
- hires: "boundary"
10016
- })
10017
- };
10028
+ }
10029
+ var ms = new MagicString(code, {
10030
+ filename: chunk.fileName
10031
+ });
10032
+ var match = (_code$match = code.match(COMMENT_USE_STRICT_REGEX)) === null || _code$match === void 0 ? void 0 : _code$match[0];
10033
+ if (match) {
10034
+ // Add injected code after any comments or "use strict" at the beginning of the bundle.
10035
+ ms.appendLeft(match.length, codeToInject);
10018
10036
  } else {
10019
- return null; // returning null means not modifying the chunk at all
10037
+ // ms.replace() doesn't work when there is an empty string match (which happens if
10038
+ // there is neither, a comment, nor a "use strict" at the top of the chunk) so we
10039
+ // need this special case here.
10040
+ ms.prepend(codeToInject);
10020
10041
  }
10042
+ return {
10043
+ code: ms.toString(),
10044
+ map: ms.generateMap({
10045
+ file: chunk.fileName,
10046
+ hires: "boundary"
10047
+ })
10048
+ };
10021
10049
  }
10022
10050
  };
10023
10051
  }
10024
-
10025
10052
  function createRollupDebugIdUploadHooks(upload, _logger, createDependencyOnBuildArtifacts) {
10026
10053
  var freeGlobalDependencyOnDebugIdSourcemapArtifacts = createDependencyOnBuildArtifacts();
10027
10054
  return {
@@ -10157,5 +10184,5 @@ function getDebugIdSnippet(debugId) {
10157
10184
  return ";{try{(function(){var e=\"undefined\"!=typeof window?window:\"undefined\"!=typeof global?global:\"undefined\"!=typeof globalThis?globalThis:\"undefined\"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]=\"".concat(debugId, "\",e._sentryDebugIdIdentifier=\"sentry-dbid-").concat(debugId, "\");})();}catch(e){}};");
10158
10185
  }
10159
10186
 
10160
- export { createComponentNameAnnotateHooks, createRollupBundleSizeOptimizationHooks, createRollupDebugIdInjectionHooks, createRollupDebugIdUploadHooks, createRollupModuleMetadataInjectionHooks, createRollupReleaseInjectionHooks, createSentryBuildPluginManager, getDebugIdSnippet, replaceBooleanFlagsInCode, sentryCliBinaryExists, sentryUnpluginFactory, stringToUUID };
10187
+ export { createComponentNameAnnotateHooks, createRollupBundleSizeOptimizationHooks, createRollupDebugIdUploadHooks, createRollupInjectionHooks, createSentryBuildPluginManager, getDebugIdSnippet, replaceBooleanFlagsInCode, sentryCliBinaryExists, sentryUnpluginFactory, stringToUUID };
10161
10188
  //# sourceMappingURL=index.mjs.map