@sentry/bundler-plugin-core 4.6.2 → 4.8.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.
package/dist/cjs/index.js CHANGED
@@ -419,6 +419,28 @@ function _asyncToGenerator(fn) {
419
419
  });
420
420
  };
421
421
  }
422
+ function _classCallCheck(instance, Constructor) {
423
+ if (!(instance instanceof Constructor)) {
424
+ throw new TypeError("Cannot call a class as a function");
425
+ }
426
+ }
427
+ function _defineProperties(target, props) {
428
+ for (var i = 0; i < props.length; i++) {
429
+ var descriptor = props[i];
430
+ descriptor.enumerable = descriptor.enumerable || false;
431
+ descriptor.configurable = true;
432
+ if ("value" in descriptor) descriptor.writable = true;
433
+ Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
434
+ }
435
+ }
436
+ function _createClass(Constructor, protoProps, staticProps) {
437
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
438
+ if (staticProps) _defineProperties(Constructor, staticProps);
439
+ Object.defineProperty(Constructor, "prototype", {
440
+ writable: false
441
+ });
442
+ return Constructor;
443
+ }
422
444
  function _defineProperty(obj, key, value) {
423
445
  key = _toPropertyKey(key);
424
446
  if (key in obj) {
@@ -7961,25 +7983,19 @@ function determineReleaseName() {
7961
7983
  function generateGlobalInjectorCode(_ref2) {
7962
7984
  var release = _ref2.release,
7963
7985
  injectBuildInformation = _ref2.injectBuildInformation;
7964
- // The code below is mostly ternary operators because it saves bundle size.
7965
- // The checks are to support as many environments as possible. (Node.js, Browser, webworkers, etc.)
7966
- var code = "!function(){try{var e=\"undefined\"!=typeof window?window:\"undefined\"!=typeof global?global:\"undefined\"!=typeof globalThis?globalThis:\"undefined\"!=typeof self?self:{};";
7967
- code += "e.SENTRY_RELEASE={id:".concat(JSON.stringify(release), "};");
7986
+ var code = "e.SENTRY_RELEASE={id:".concat(JSON.stringify(release), "};");
7968
7987
  if (injectBuildInformation) {
7969
7988
  var buildInfo = getBuildInformation();
7970
7989
  code += "e.SENTRY_BUILD_INFO=".concat(JSON.stringify(buildInfo), ";");
7971
7990
  }
7972
- code += "}catch(e){}}();";
7973
- return code;
7991
+ return new CodeInjection(code);
7974
7992
  }
7975
7993
 
7976
7994
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
7977
7995
  function generateModuleMetadataInjectorCode(metadata) {
7978
- // The code below is mostly ternary operators because it saves bundle size.
7979
- // The checks are to support as many environments as possible. (Node.js, Browser, webworkers, etc.)
7980
7996
  // We are merging the metadata objects in case modules are bundled twice with the plugin
7981
7997
  // Use try-catch to avoid issues when bundlers rename global variables like 'window' to 'k'
7982
- return "!function(){try{var e=\"undefined\"!=typeof window?window:\"undefined\"!=typeof global?global:\"undefined\"!=typeof globalThis?globalThis:\"undefined\"!=typeof self?self:{};e._sentryModuleMetadata=e._sentryModuleMetadata||{},e._sentryModuleMetadata[(new e.Error).stack]=function(e){for(var n=1;n<arguments.length;n++){var a=arguments[n];if(null!=a)for(var t in a)a.hasOwnProperty(t)&&(e[t]=a[t])}return e}({},e._sentryModuleMetadata[(new e.Error).stack],".concat(JSON.stringify(metadata), ")}catch(e){}}();");
7998
+ return new CodeInjection("e._sentryModuleMetadata=e._sentryModuleMetadata||{},e._sentryModuleMetadata[(new e.Error).stack]=function(e){for(var n=1;n<arguments.length;n++){var a=arguments[n];if(null!=a)for(var t in a)a.hasOwnProperty(t)&&(e[t]=a[t])}return e}({},e._sentryModuleMetadata[(new e.Error).stack],".concat(JSON.stringify(metadata), ");"));
7983
7999
  }
7984
8000
  function getBuildInformation() {
7985
8001
  var packageJson = getPackageJson();
@@ -8036,6 +8052,93 @@ function getProjects(project) {
8036
8052
  return undefined;
8037
8053
  }
8038
8054
 
8055
+ /**
8056
+ * Inlined functionality from @sentry/cli helper code to add `--ignore` options.
8057
+ *
8058
+ * Temporary workaround until we expose a function for injecting debug IDs. Currently, we directly call `execute` with CLI args to inject them.
8059
+ */
8060
+ function serializeIgnoreOptions(ignoreValue) {
8061
+ var DEFAULT_IGNORE = ["node_modules"];
8062
+ var ignoreOptions = Array.isArray(ignoreValue) ? ignoreValue : typeof ignoreValue === "string" ? [ignoreValue] : DEFAULT_IGNORE;
8063
+ return ignoreOptions.reduce(function (acc, value) {
8064
+ return acc.concat(["--ignore", String(value)]);
8065
+ }, []);
8066
+ }
8067
+
8068
+ /**
8069
+ * Checks if a chunk contains only import/export statements and no substantial code.
8070
+ *
8071
+ * In Vite MPA (multi-page application) mode, HTML entry points create "facade" chunks
8072
+ * that only contain import statements to load shared modules. These should not have
8073
+ * Sentry code injected. However, in SPA mode, the main bundle also has an HTML facade
8074
+ * but contains substantial application code that SHOULD have debug IDs injected.
8075
+ *
8076
+ * @ref https://github.com/getsentry/sentry-javascript-bundler-plugins/issues/829
8077
+ * @ref https://github.com/getsentry/sentry-javascript-bundler-plugins/issues/839
8078
+ */
8079
+ function containsOnlyImports(code) {
8080
+ var codeWithoutImports = code
8081
+ // Remove side effect imports: import '/path'; or import "./path";
8082
+ // Using explicit negated character classes to avoid polynomial backtracking
8083
+ .replace(/^\s*import\s+(?:'[^'\n]*'|"[^"\n]*"|`[^`\n]*`)[\s;]*$/gm, "")
8084
+ // Remove named/default imports: import x from '/path'; import { x } from '/path';
8085
+ .replace(/^\s*import\b[^'"`\n]*\bfrom\s+(?:'[^'\n]*'|"[^"\n]*"|`[^`\n]*`)[\s;]*$/gm, "")
8086
+ // Remove re-exports: export * from '/path'; export { x } from '/path';
8087
+ .replace(/^\s*export\b[^'"`\n]*\bfrom\s+(?:'[^'\n]*'|"[^"\n]*"|`[^`\n]*`)[\s;]*$/gm, "")
8088
+ // Remove block comments
8089
+ .replace(/\/\*[\s\S]*?\*\//g, "")
8090
+ // Remove line comments
8091
+ .replace(/\/\/.*$/gm, "")
8092
+ // Remove "use strict" directives
8093
+ .replace(/["']use strict["']\s*;?/g, "").trim();
8094
+ return codeWithoutImports.length === 0;
8095
+ }
8096
+ var CodeInjection = /*#__PURE__*/function () {
8097
+ function CodeInjection() {
8098
+ var body = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
8099
+ _classCallCheck(this, CodeInjection);
8100
+ // The code below is mostly ternary operators because it saves bundle size.
8101
+ // The checks are to support as many environments as possible. (Node.js, Browser, webworkers, etc.)
8102
+ _defineProperty(this, "header", "!function(){try{var e=\"undefined\"!=typeof window?window:\"undefined\"!=typeof global?global:\"undefined\"!=typeof globalThis?globalThis:\"undefined\"!=typeof self?self:{};");
8103
+ _defineProperty(this, "footer", "}catch(e){}}();");
8104
+ this.body = body;
8105
+ }
8106
+ _createClass(CodeInjection, [{
8107
+ key: "code",
8108
+ value: function code() {
8109
+ if (this.isEmpty()) {
8110
+ return "";
8111
+ }
8112
+ return this.header + this.body + this.footer;
8113
+ }
8114
+ }, {
8115
+ key: "isEmpty",
8116
+ value: function isEmpty() {
8117
+ return this.body.length === 0;
8118
+ }
8119
+ }, {
8120
+ key: "append",
8121
+ value: function append(code) {
8122
+ if (code instanceof CodeInjection) {
8123
+ this.body += code.body;
8124
+ } else {
8125
+ this.body += code;
8126
+ }
8127
+ }
8128
+ }, {
8129
+ key: "clear",
8130
+ value: function clear() {
8131
+ this.body = "";
8132
+ }
8133
+ }, {
8134
+ key: "clone",
8135
+ value: function clone() {
8136
+ return new CodeInjection(this.body);
8137
+ }
8138
+ }]);
8139
+ return CodeInjection;
8140
+ }();
8141
+
8039
8142
  var SENTRY_SAAS_URL = "https://sentry.io";
8040
8143
  function normalizeUserOptions(userOptions) {
8041
8144
  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;
@@ -8336,7 +8439,7 @@ function createSentryInstance(options, shouldSendTelemetry, buildTool) {
8336
8439
  dsn: "https://4c2bae7d9fbc413e8f7385f55c515d51@o1.ingest.sentry.io/6690737",
8337
8440
  tracesSampleRate: 1,
8338
8441
  sampleRate: 1,
8339
- release: "4.6.2",
8442
+ release: "4.8.0",
8340
8443
  integrations: [],
8341
8444
  tracePropagationTargets: ["sentry.io/api"],
8342
8445
  stackParser: stackParser,
@@ -8945,7 +9048,7 @@ function createSentryBuildPluginManager(userOptions, bundlerPluginMetaContext) {
8945
9048
  });
8946
9049
 
8947
9050
  // Set the User-Agent that Sentry CLI will use when interacting with Sentry
8948
- process.env["SENTRY_PIPELINE"] = "".concat(bundlerPluginMetaContext.buildTool, "-plugin/", "4.6.2");
9051
+ process.env["SENTRY_PIPELINE"] = "".concat(bundlerPluginMetaContext.buildTool, "-plugin/", "4.8.0");
8949
9052
 
8950
9053
  // Propagate debug flag to Sentry CLI via environment variable
8951
9054
  // Only set if not already defined to respect user's explicit configuration
@@ -9313,14 +9416,14 @@ function createSentryBuildPluginManager(userOptions, bundlerPluginMetaContext) {
9313
9416
  scope: sentryScope,
9314
9417
  forceTransaction: true
9315
9418
  }, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
9316
- var _options$debug, cliInstance;
9419
+ var _options$sourcemaps, cliInstance;
9317
9420
  return _regeneratorRuntime().wrap(function _callee8$(_context8) {
9318
9421
  while (1) switch (_context8.prev = _context8.next) {
9319
9422
  case 0:
9320
9423
  _context8.prev = 0;
9321
9424
  cliInstance = createCliInstance(options);
9322
9425
  _context8.next = 4;
9323
- return cliInstance.execute(["sourcemaps", "inject"].concat(_toConsumableArray(buildArtifactPaths)), (_options$debug = options.debug) !== null && _options$debug !== void 0 ? _options$debug : false);
9426
+ 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);
9324
9427
  case 4:
9325
9428
  _context8.next = 10;
9326
9429
  break;
@@ -9360,7 +9463,7 @@ function createSentryBuildPluginManager(userOptions, bundlerPluginMetaContext) {
9360
9463
  */
9361
9464
  uploadSourcemaps: function uploadSourcemaps(buildArtifactPaths, opts) {
9362
9465
  return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19() {
9363
- var _options$sourcemaps;
9466
+ var _options$sourcemaps2;
9364
9467
  var assets;
9365
9468
  return _regeneratorRuntime().wrap(function _callee19$(_context19) {
9366
9469
  while (1) switch (_context19.prev = _context19.next) {
@@ -9372,7 +9475,7 @@ function createSentryBuildPluginManager(userOptions, bundlerPluginMetaContext) {
9372
9475
  return _context19.abrupt("return");
9373
9476
  case 2:
9374
9477
  // Early exit if assets is explicitly set to an empty array
9375
- assets = (_options$sourcemaps = options.sourcemaps) === null || _options$sourcemaps === void 0 ? void 0 : _options$sourcemaps.assets;
9478
+ assets = (_options$sourcemaps2 = options.sourcemaps) === null || _options$sourcemaps2 === void 0 ? void 0 : _options$sourcemaps2.assets;
9376
9479
  if (!(Array.isArray(assets) && assets.length === 0)) {
9377
9480
  _context19.next = 6;
9378
9481
  break;
@@ -9389,7 +9492,7 @@ function createSentryBuildPluginManager(userOptions, bundlerPluginMetaContext) {
9389
9492
  forceTransaction: true
9390
9493
  }, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18() {
9391
9494
  var _opts$prepareArtifact;
9392
- var shouldPrepare, folderToCleanUp, freeUploadDependencyOnBuildArtifacts, _options$sourcemaps2, _options$sourcemaps3, _options$sourcemaps4, _options$sourcemaps5, pathsToUpload, ignorePaths, globAssets, globResult, debugIdChunkFilePaths, tmpUploadFolder, _process$env2;
9495
+ var shouldPrepare, folderToCleanUp, freeUploadDependencyOnBuildArtifacts, _options$sourcemaps3, _options$sourcemaps4, _options$sourcemaps5, _options$sourcemaps6, pathsToUpload, ignorePaths, globAssets, globResult, debugIdChunkFilePaths, tmpUploadFolder, _process$env2;
9393
9496
  return _regeneratorRuntime().wrap(function _callee18$(_context18) {
9394
9497
  while (1) switch (_context18.prev = _context18.next) {
9395
9498
  case 0:
@@ -9412,7 +9515,7 @@ function createSentryBuildPluginManager(userOptions, bundlerPluginMetaContext) {
9412
9515
  // Use original paths e.g. like ['.next/server'] directly –> preferred way when no globbing is done
9413
9516
  pathsToUpload = buildArtifactPaths;
9414
9517
  }
9415
- 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] : [];
9518
+ 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] : [];
9416
9519
  _context18.next = 8;
9417
9520
  return startSpan({
9418
9521
  name: "upload",
@@ -9459,7 +9562,7 @@ function createSentryBuildPluginManager(userOptions, bundlerPluginMetaContext) {
9459
9562
  name: "glob",
9460
9563
  scope: sentryScope
9461
9564
  }, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
9462
- var _options$sourcemaps6;
9565
+ var _options$sourcemaps7;
9463
9566
  return _regeneratorRuntime().wrap(function _callee11$(_context11) {
9464
9567
  while (1) switch (_context11.prev = _context11.next) {
9465
9568
  case 0:
@@ -9468,7 +9571,7 @@ function createSentryBuildPluginManager(userOptions, bundlerPluginMetaContext) {
9468
9571
  absolute: true,
9469
9572
  nodir: true,
9470
9573
  // We need individual files for preparation
9471
- ignore: (_options$sourcemaps6 = options.sourcemaps) === null || _options$sourcemaps6 === void 0 ? void 0 : _options$sourcemaps6.ignore
9574
+ ignore: (_options$sourcemaps7 = options.sourcemaps) === null || _options$sourcemaps7 === void 0 ? void 0 : _options$sourcemaps7.ignore
9472
9575
  });
9473
9576
  case 2:
9474
9577
  return _context11.abrupt("return", _context11.sent);
@@ -9538,12 +9641,12 @@ function createSentryBuildPluginManager(userOptions, bundlerPluginMetaContext) {
9538
9641
  // instead we do it with a maximum of 16 concurrent workers
9539
9642
  preparationTasks = debugIdChunkFilePaths.map(function (chunkFilePath, chunkIndex) {
9540
9643
  return /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
9541
- var _options$sourcemaps$r, _options$sourcemaps7, _options$sourcemaps8;
9644
+ var _options$sourcemaps$r, _options$sourcemaps8, _options$sourcemaps9;
9542
9645
  return _regeneratorRuntime().wrap(function _callee13$(_context13) {
9543
9646
  while (1) switch (_context13.prev = _context13.next) {
9544
9647
  case 0:
9545
9648
  _context13.next = 2;
9546
- 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);
9649
+ 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);
9547
9650
  case 2:
9548
9651
  case "end":
9549
9652
  return _context13.stop();
@@ -9706,13 +9809,13 @@ function createSentryBuildPluginManager(userOptions, bundlerPluginMetaContext) {
9706
9809
  */
9707
9810
  deleteArtifacts: function deleteArtifacts() {
9708
9811
  return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20() {
9709
- var _options$sourcemaps9, filesToDelete, filePathsToDelete;
9812
+ var _options$sourcemaps10, filesToDelete, filePathsToDelete;
9710
9813
  return _regeneratorRuntime().wrap(function _callee20$(_context20) {
9711
9814
  while (1) switch (_context20.prev = _context20.next) {
9712
9815
  case 0:
9713
9816
  _context20.prev = 0;
9714
9817
  _context20.next = 3;
9715
- return (_options$sourcemaps9 = options.sourcemaps) === null || _options$sourcemaps9 === void 0 ? void 0 : _options$sourcemaps9.filesToDeleteAfterUpload;
9818
+ return (_options$sourcemaps10 = options.sourcemaps) === null || _options$sourcemaps10 === void 0 ? void 0 : _options$sourcemaps10.filesToDeleteAfterUpload;
9716
9819
  case 3:
9717
9820
  filesToDelete = _context20.sent;
9718
9821
  if (!(filesToDelete !== undefined)) {
@@ -9766,8 +9869,8 @@ function createSentryBuildPluginManager(userOptions, bundlerPluginMetaContext) {
9766
9869
  };
9767
9870
  }
9768
9871
  function canUploadSourceMaps(options, logger, isDevMode) {
9769
- var _options$sourcemaps10, _getProjects3;
9770
- if ((_options$sourcemaps10 = options.sourcemaps) !== null && _options$sourcemaps10 !== void 0 && _options$sourcemaps10.disable) {
9872
+ var _options$sourcemaps11, _getProjects3;
9873
+ if ((_options$sourcemaps11 = options.sourcemaps) !== null && _options$sourcemaps11 !== void 0 && _options$sourcemaps11.disable) {
9771
9874
  logger.debug("Source map upload was disabled. Will not upload sourcemaps using debug ID process.");
9772
9875
  return false;
9773
9876
  }
@@ -9794,14 +9897,12 @@ function canUploadSourceMaps(options, logger, isDevMode) {
9794
9897
  * Creates an unplugin instance used to create Sentry plugins for Vite, Rollup, esbuild, and Webpack.
9795
9898
  */
9796
9899
  function sentryUnpluginFactory(_ref) {
9797
- var releaseInjectionPlugin = _ref.releaseInjectionPlugin,
9900
+ var injectionPlugin = _ref.injectionPlugin,
9798
9901
  componentNameAnnotatePlugin = _ref.componentNameAnnotatePlugin,
9799
- moduleMetadataInjectionPlugin = _ref.moduleMetadataInjectionPlugin,
9800
- debugIdInjectionPlugin = _ref.debugIdInjectionPlugin,
9801
9902
  debugIdUploadPlugin = _ref.debugIdUploadPlugin,
9802
9903
  bundleSizeOptimizationsPlugin = _ref.bundleSizeOptimizationsPlugin;
9803
9904
  return unplugin.createUnplugin(function () {
9804
- var _userOptions$_metaOpt, _userOptions$_metaOpt2, _options$sourcemaps;
9905
+ var _userOptions$_metaOpt, _userOptions$_metaOpt2, _options$sourcemaps, _options$sourcemaps3;
9805
9906
  var userOptions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
9806
9907
  var unpluginMetaContext = arguments.length > 1 ? arguments[1] : undefined;
9807
9908
  var sentryBuildPluginManager = createSentryBuildPluginManager(userOptions, {
@@ -9838,20 +9939,33 @@ function sentryUnpluginFactory(_ref) {
9838
9939
  if (Object.keys(bundleSizeOptimizationReplacementValues).length > 0) {
9839
9940
  plugins.push(bundleSizeOptimizationsPlugin(bundleSizeOptimizationReplacementValues));
9840
9941
  }
9942
+ var injectionCode = new CodeInjection();
9841
9943
  if (!options.release.inject) {
9842
9944
  logger.debug("Release injection disabled via `release.inject` option. Will not inject release.");
9843
9945
  } else if (!options.release.name) {
9844
9946
  logger.debug("No release name provided. Will not inject release. Please set the `release.name` option to identify your release.");
9845
9947
  } else {
9846
- var _injectionCode = generateGlobalInjectorCode({
9948
+ var _code = generateGlobalInjectorCode({
9847
9949
  release: options.release.name,
9848
9950
  injectBuildInformation: options._experiments.injectBuildInformation || false
9849
9951
  });
9850
- plugins.push(releaseInjectionPlugin(_injectionCode));
9952
+ if (typeof injectionPlugin !== "function") {
9953
+ plugins.push(injectionPlugin.releaseInjectionPlugin(_code.code()));
9954
+ } else {
9955
+ injectionCode.append(_code);
9956
+ }
9851
9957
  }
9852
9958
  if (Object.keys(sentryBuildPluginManager.bundleMetadata).length > 0) {
9853
- var _injectionCode2 = generateModuleMetadataInjectorCode(sentryBuildPluginManager.bundleMetadata);
9854
- plugins.push(moduleMetadataInjectionPlugin(_injectionCode2));
9959
+ var _code2 = generateModuleMetadataInjectorCode(sentryBuildPluginManager.bundleMetadata);
9960
+ if (typeof injectionPlugin !== "function") {
9961
+ plugins.push(injectionPlugin.moduleMetadataInjectionPlugin(_code2.code()));
9962
+ } else {
9963
+ injectionCode.append(_code2);
9964
+ }
9965
+ }
9966
+ if (typeof injectionPlugin === "function" && (!injectionCode.isEmpty() || ((_options$sourcemaps = options.sourcemaps) === null || _options$sourcemaps === void 0 ? void 0 : _options$sourcemaps.disable) !== true)) {
9967
+ var _options$sourcemaps2;
9968
+ plugins.push(injectionPlugin(injectionCode, ((_options$sourcemaps2 = options.sourcemaps) === null || _options$sourcemaps2 === void 0 ? void 0 : _options$sourcemaps2.disable) !== true, logger));
9855
9969
  }
9856
9970
 
9857
9971
  // Add plugin to create and finalize releases, and also take care of adding commits and legacy sourcemaps
@@ -9878,10 +9992,12 @@ function sentryUnpluginFactory(_ref) {
9878
9992
  }))();
9879
9993
  }
9880
9994
  });
9881
- if (((_options$sourcemaps = options.sourcemaps) === null || _options$sourcemaps === void 0 ? void 0 : _options$sourcemaps.disable) !== true) {
9882
- var _options$sourcemaps2;
9883
- plugins.push(debugIdInjectionPlugin(logger));
9884
- if (((_options$sourcemaps2 = options.sourcemaps) === null || _options$sourcemaps2 === void 0 ? void 0 : _options$sourcemaps2.disable) !== "disable-upload") {
9995
+ if (((_options$sourcemaps3 = options.sourcemaps) === null || _options$sourcemaps3 === void 0 ? void 0 : _options$sourcemaps3.disable) !== true) {
9996
+ var _options$sourcemaps4;
9997
+ if (typeof injectionPlugin !== "function") {
9998
+ plugins.push(injectionPlugin.debugIdInjectionPlugin(logger));
9999
+ }
10000
+ if (((_options$sourcemaps4 = options.sourcemaps) === null || _options$sourcemaps4 === void 0 ? void 0 : _options$sourcemaps4.disable) !== "disable-upload") {
9885
10001
  // This option is only strongly typed for the webpack plugin, where it is used. It has no effect on other plugins
9886
10002
  var _webpack_forceExitOnBuildComplete = typeof options._experiments["forceExitOnBuildCompletion"] === "boolean" ? options._experiments["forceExitOnBuildCompletion"] : undefined;
9887
10003
  plugins.push(debugIdUploadPlugin(createDebugIdUploadFunction({
@@ -9895,7 +10011,7 @@ function sentryUnpluginFactory(_ref) {
9895
10011
  } else if (options.reactComponentAnnotation.enabled && !componentNameAnnotatePlugin) {
9896
10012
  logger.warn("The component name annotate plugin is currently not supported by '@sentry/esbuild-plugin'");
9897
10013
  } else {
9898
- componentNameAnnotatePlugin && plugins.push(componentNameAnnotatePlugin(options.reactComponentAnnotation.ignoredComponents));
10014
+ componentNameAnnotatePlugin && plugins.push(componentNameAnnotatePlugin(options.reactComponentAnnotation.ignoredComponents || [], !!options.reactComponentAnnotation._experimentalInjectIntoHtml));
9899
10015
  }
9900
10016
  }
9901
10017
 
@@ -9960,6 +10076,9 @@ function isJsFile(fileName) {
9960
10076
  * HTML entry points create "facade" chunks that should not contain injected code.
9961
10077
  * See: https://github.com/getsentry/sentry-javascript-bundler-plugins/issues/829
9962
10078
  *
10079
+ * However, in SPA mode, the main bundle also has an HTML facade but contains
10080
+ * substantial application code. We should NOT skip injection for these bundles.
10081
+ *
9963
10082
  * @param code - The chunk's code content
9964
10083
  * @param facadeModuleId - The facade module ID (if any) - HTML files create facade chunks
9965
10084
  * @returns true if the chunk should be skipped
@@ -9970,48 +10089,12 @@ function shouldSkipCodeInjection(code, facadeModuleId) {
9970
10089
  return true;
9971
10090
  }
9972
10091
 
9973
- // Skip HTML facade chunks
9974
- // They only contain import statements and should not have Sentry code injected
10092
+ // For HTML facade chunks, only skip if they contain only import statements
9975
10093
  if (facadeModuleId && stripQueryAndHashFromPath(facadeModuleId).endsWith(".html")) {
9976
- return true;
10094
+ return containsOnlyImports(code);
9977
10095
  }
9978
10096
  return false;
9979
10097
  }
9980
- function createRollupReleaseInjectionHooks(injectionCode) {
9981
- return {
9982
- renderChunk: function renderChunk(code, chunk) {
9983
- var _code$match;
9984
- if (!isJsFile(chunk.fileName)) {
9985
- return null; // returning null means not modifying the chunk at all
9986
- }
9987
-
9988
- // Skip empty chunks and HTML facade chunks (Vite MPA)
9989
- if (shouldSkipCodeInjection(code, chunk.facadeModuleId)) {
9990
- return null;
9991
- }
9992
- var ms = new MagicString__default["default"](code, {
9993
- filename: chunk.fileName
9994
- });
9995
- var match = (_code$match = code.match(COMMENT_USE_STRICT_REGEX)) === null || _code$match === void 0 ? void 0 : _code$match[0];
9996
- if (match) {
9997
- // Add injected code after any comments or "use strict" at the beginning of the bundle.
9998
- ms.appendLeft(match.length, injectionCode);
9999
- } else {
10000
- // ms.replace() doesn't work when there is an empty string match (which happens if
10001
- // there is neither, a comment, nor a "use strict" at the top of the chunk) so we
10002
- // need this special case here.
10003
- ms.prepend(injectionCode);
10004
- }
10005
- return {
10006
- code: ms.toString(),
10007
- map: ms.generateMap({
10008
- file: chunk.fileName,
10009
- hires: "boundary"
10010
- })
10011
- };
10012
- }
10013
- };
10014
- }
10015
10098
  function createRollupBundleSizeOptimizationHooks(replacementValues) {
10016
10099
  return {
10017
10100
  transform: function transform(code) {
@@ -10019,10 +10102,10 @@ function createRollupBundleSizeOptimizationHooks(replacementValues) {
10019
10102
  }
10020
10103
  };
10021
10104
  }
10022
- function createRollupDebugIdInjectionHooks() {
10105
+ function createRollupInjectionHooks(injectionCode, debugIds) {
10023
10106
  return {
10024
- renderChunk: function renderChunk(code, chunk) {
10025
- var _code$match2;
10107
+ renderChunk: function renderChunk(code, chunk, _, meta) {
10108
+ var _code$match, _ms$constructor;
10026
10109
  if (!isJsFile(chunk.fileName)) {
10027
10110
  return null; // returning null means not modifying the chunk at all
10028
10111
  }
@@ -10031,70 +10114,46 @@ function createRollupDebugIdInjectionHooks() {
10031
10114
  if (shouldSkipCodeInjection(code, chunk.facadeModuleId)) {
10032
10115
  return null;
10033
10116
  }
10034
-
10035
- // Check if a debug ID has already been injected to avoid duplicate injection (e.g. by another plugin or Sentry CLI)
10036
- var chunkStartSnippet = code.slice(0, 6000);
10037
- var chunkEndSnippet = code.slice(-500);
10038
- if (chunkStartSnippet.includes("_sentryDebugIdIdentifier") || chunkEndSnippet.includes("//# debugId=")) {
10039
- return null; // Debug ID already present, skip injection
10117
+ var codeToInject = injectionCode.clone();
10118
+ if (debugIds) {
10119
+ // Check if a debug ID has already been injected to avoid duplicate injection (e.g. by another plugin or Sentry CLI)
10120
+ var chunkStartSnippet = code.slice(0, 6000);
10121
+ var chunkEndSnippet = code.slice(-500);
10122
+ if (!(chunkStartSnippet.includes("_sentryDebugIdIdentifier") || chunkEndSnippet.includes("//# debugId="))) {
10123
+ var debugId = stringToUUID(code); // generate a deterministic debug ID
10124
+ codeToInject.append(getDebugIdSnippet(debugId));
10125
+ }
10040
10126
  }
10041
-
10042
- var debugId = stringToUUID(code); // generate a deterministic debug ID
10043
- var codeToInject = getDebugIdSnippet(debugId);
10044
- var ms = new MagicString__default["default"](code, {
10127
+ var ms = (meta === null || meta === void 0 ? void 0 : meta.magicString) || new MagicString__default["default"](code, {
10045
10128
  filename: chunk.fileName
10046
10129
  });
10047
- var match = (_code$match2 = code.match(COMMENT_USE_STRICT_REGEX)) === null || _code$match2 === void 0 ? void 0 : _code$match2[0];
10130
+ var match = (_code$match = code.match(COMMENT_USE_STRICT_REGEX)) === null || _code$match === void 0 ? void 0 : _code$match[0];
10048
10131
  if (match) {
10049
10132
  // Add injected code after any comments or "use strict" at the beginning of the bundle.
10050
- ms.appendLeft(match.length, codeToInject);
10133
+ ms.appendLeft(match.length, codeToInject.code());
10051
10134
  } else {
10052
10135
  // ms.replace() doesn't work when there is an empty string match (which happens if
10053
10136
  // there is neither, a comment, nor a "use strict" at the top of the chunk) so we
10054
10137
  // need this special case here.
10055
- ms.prepend(codeToInject);
10056
- }
10057
- return {
10058
- code: ms.toString(),
10059
- map: ms.generateMap({
10060
- file: chunk.fileName,
10061
- hires: "boundary"
10062
- })
10063
- };
10064
- }
10065
- };
10066
- }
10067
- function createRollupModuleMetadataInjectionHooks(injectionCode) {
10068
- return {
10069
- renderChunk: function renderChunk(code, chunk) {
10070
- var _code$match3;
10071
- if (!isJsFile(chunk.fileName)) {
10072
- return null; // returning null means not modifying the chunk at all
10138
+ ms.prepend(codeToInject.code());
10073
10139
  }
10074
10140
 
10075
- // Skip empty chunks and HTML facade chunks (Vite MPA)
10076
- if (shouldSkipCodeInjection(code, chunk.facadeModuleId)) {
10077
- return null;
10078
- }
10079
- var ms = new MagicString__default["default"](code, {
10080
- filename: chunk.fileName
10081
- });
10082
- var match = (_code$match3 = code.match(COMMENT_USE_STRICT_REGEX)) === null || _code$match3 === void 0 ? void 0 : _code$match3[0];
10083
- if (match) {
10084
- // Add injected code after any comments or "use strict" at the beginning of the bundle.
10085
- ms.appendLeft(match.length, injectionCode);
10086
- } else {
10087
- // ms.replace() doesn't work when there is an empty string match (which happens if
10088
- // there is neither, a comment, nor a "use strict" at the top of the chunk) so we
10089
- // need this special case here.
10090
- ms.prepend(injectionCode);
10141
+ // Rolldown can pass a native MagicString instance in meta.magicString
10142
+ // https://rolldown.rs/in-depth/native-magic-string#usage-examples
10143
+ if ((ms === null || ms === void 0 ? void 0 : (_ms$constructor = ms.constructor) === null || _ms$constructor === void 0 ? void 0 : _ms$constructor.name) === "BindingMagicString") {
10144
+ // Rolldown docs say to return the magic string instance directly in this case
10145
+ return {
10146
+ code: ms
10147
+ };
10091
10148
  }
10092
10149
  return {
10093
10150
  code: ms.toString(),
10094
- map: ms.generateMap({
10095
- file: chunk.fileName,
10096
- hires: "boundary"
10097
- })
10151
+ get map() {
10152
+ return ms.generateMap({
10153
+ file: chunk.fileName,
10154
+ hires: "boundary"
10155
+ });
10156
+ }
10098
10157
  };
10099
10158
  }
10100
10159
  };
@@ -10160,11 +10219,11 @@ function createRollupDebugIdUploadHooks(upload, _logger, createDependencyOnBuild
10160
10219
  }
10161
10220
  };
10162
10221
  }
10163
- function createComponentNameAnnotateHooks(ignoredComponents) {
10222
+ function createComponentNameAnnotateHooks(ignoredComponents, injectIntoHtml) {
10164
10223
  return {
10165
10224
  transform: function transform(code, id) {
10166
10225
  return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
10167
- var idWithoutQueryAndHash, parserPlugins, _result$code, result;
10226
+ var idWithoutQueryAndHash, parserPlugins, plugin, _result$code, result;
10168
10227
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
10169
10228
  while (1) switch (_context4.prev = _context4.next) {
10170
10229
  case 0:
@@ -10190,10 +10249,11 @@ function createComponentNameAnnotateHooks(ignoredComponents) {
10190
10249
  } else if (idWithoutQueryAndHash.endsWith(".tsx")) {
10191
10250
  parserPlugins.push("jsx", "typescript");
10192
10251
  }
10193
- _context4.prev = 7;
10194
- _context4.next = 10;
10252
+ plugin = injectIntoHtml ? componentNameAnnotatePlugin.experimentalComponentNameAnnotatePlugin : componentNameAnnotatePlugin__default["default"];
10253
+ _context4.prev = 8;
10254
+ _context4.next = 11;
10195
10255
  return core.transformAsync(code, {
10196
- plugins: [[componentNameAnnotatePlugin__default["default"], {
10256
+ plugins: [[plugin, {
10197
10257
  ignoredComponents: ignoredComponents
10198
10258
  }]],
10199
10259
  filename: id,
@@ -10207,39 +10267,38 @@ function createComponentNameAnnotateHooks(ignoredComponents) {
10207
10267
  },
10208
10268
  sourceMaps: true
10209
10269
  });
10210
- case 10:
10270
+ case 11:
10211
10271
  result = _context4.sent;
10212
10272
  return _context4.abrupt("return", {
10213
10273
  code: (_result$code = result === null || result === void 0 ? void 0 : result.code) !== null && _result$code !== void 0 ? _result$code : code,
10214
10274
  map: result === null || result === void 0 ? void 0 : result.map
10215
10275
  });
10216
- case 14:
10217
- _context4.prev = 14;
10218
- _context4.t0 = _context4["catch"](7);
10276
+ case 15:
10277
+ _context4.prev = 15;
10278
+ _context4.t0 = _context4["catch"](8);
10219
10279
  logger.error("Failed to apply react annotate plugin", _context4.t0);
10220
- case 17:
10280
+ case 18:
10221
10281
  return _context4.abrupt("return", {
10222
10282
  code: code
10223
10283
  });
10224
- case 18:
10284
+ case 19:
10225
10285
  case "end":
10226
10286
  return _context4.stop();
10227
10287
  }
10228
- }, _callee4, null, [[7, 14]]);
10288
+ }, _callee4, null, [[8, 15]]);
10229
10289
  }))();
10230
10290
  }
10231
10291
  };
10232
10292
  }
10233
10293
  function getDebugIdSnippet(debugId) {
10234
- 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){}};");
10294
+ return new CodeInjection("var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]=\"".concat(debugId, "\",e._sentryDebugIdIdentifier=\"sentry-dbid-").concat(debugId, "\");"));
10235
10295
  }
10236
10296
 
10297
+ exports.CodeInjection = CodeInjection;
10237
10298
  exports.createComponentNameAnnotateHooks = createComponentNameAnnotateHooks;
10238
10299
  exports.createRollupBundleSizeOptimizationHooks = createRollupBundleSizeOptimizationHooks;
10239
- exports.createRollupDebugIdInjectionHooks = createRollupDebugIdInjectionHooks;
10240
10300
  exports.createRollupDebugIdUploadHooks = createRollupDebugIdUploadHooks;
10241
- exports.createRollupModuleMetadataInjectionHooks = createRollupModuleMetadataInjectionHooks;
10242
- exports.createRollupReleaseInjectionHooks = createRollupReleaseInjectionHooks;
10301
+ exports.createRollupInjectionHooks = createRollupInjectionHooks;
10243
10302
  exports.createSentryBuildPluginManager = createSentryBuildPluginManager;
10244
10303
  exports.getDebugIdSnippet = getDebugIdSnippet;
10245
10304
  exports.replaceBooleanFlagsInCode = replaceBooleanFlagsInCode;