@sentry/bundler-plugin-core 4.7.0 → 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();
@@ -8077,6 +8093,51 @@ function containsOnlyImports(code) {
8077
8093
  .replace(/["']use strict["']\s*;?/g, "").trim();
8078
8094
  return codeWithoutImports.length === 0;
8079
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
+ }();
8080
8141
 
8081
8142
  var SENTRY_SAAS_URL = "https://sentry.io";
8082
8143
  function normalizeUserOptions(userOptions) {
@@ -8378,7 +8439,7 @@ function createSentryInstance(options, shouldSendTelemetry, buildTool) {
8378
8439
  dsn: "https://4c2bae7d9fbc413e8f7385f55c515d51@o1.ingest.sentry.io/6690737",
8379
8440
  tracesSampleRate: 1,
8380
8441
  sampleRate: 1,
8381
- release: "4.7.0",
8442
+ release: "4.8.0",
8382
8443
  integrations: [],
8383
8444
  tracePropagationTargets: ["sentry.io/api"],
8384
8445
  stackParser: stackParser,
@@ -8987,7 +9048,7 @@ function createSentryBuildPluginManager(userOptions, bundlerPluginMetaContext) {
8987
9048
  });
8988
9049
 
8989
9050
  // Set the User-Agent that Sentry CLI will use when interacting with Sentry
8990
- process.env["SENTRY_PIPELINE"] = "".concat(bundlerPluginMetaContext.buildTool, "-plugin/", "4.7.0");
9051
+ process.env["SENTRY_PIPELINE"] = "".concat(bundlerPluginMetaContext.buildTool, "-plugin/", "4.8.0");
8991
9052
 
8992
9053
  // Propagate debug flag to Sentry CLI via environment variable
8993
9054
  // Only set if not already defined to respect user's explicit configuration
@@ -9878,7 +9939,7 @@ function sentryUnpluginFactory(_ref) {
9878
9939
  if (Object.keys(bundleSizeOptimizationReplacementValues).length > 0) {
9879
9940
  plugins.push(bundleSizeOptimizationsPlugin(bundleSizeOptimizationReplacementValues));
9880
9941
  }
9881
- var injectionCode = "";
9942
+ var injectionCode = new CodeInjection();
9882
9943
  if (!options.release.inject) {
9883
9944
  logger.debug("Release injection disabled via `release.inject` option. Will not inject release.");
9884
9945
  } else if (!options.release.name) {
@@ -9889,20 +9950,20 @@ function sentryUnpluginFactory(_ref) {
9889
9950
  injectBuildInformation: options._experiments.injectBuildInformation || false
9890
9951
  });
9891
9952
  if (typeof injectionPlugin !== "function") {
9892
- plugins.push(injectionPlugin.releaseInjectionPlugin(_code));
9953
+ plugins.push(injectionPlugin.releaseInjectionPlugin(_code.code()));
9893
9954
  } else {
9894
- injectionCode += _code;
9955
+ injectionCode.append(_code);
9895
9956
  }
9896
9957
  }
9897
9958
  if (Object.keys(sentryBuildPluginManager.bundleMetadata).length > 0) {
9898
9959
  var _code2 = generateModuleMetadataInjectorCode(sentryBuildPluginManager.bundleMetadata);
9899
9960
  if (typeof injectionPlugin !== "function") {
9900
- plugins.push(injectionPlugin.moduleMetadataInjectionPlugin(_code2));
9961
+ plugins.push(injectionPlugin.moduleMetadataInjectionPlugin(_code2.code()));
9901
9962
  } else {
9902
- injectionCode += _code2;
9963
+ injectionCode.append(_code2);
9903
9964
  }
9904
9965
  }
9905
- if (typeof injectionPlugin === "function" && (injectionCode !== "" || ((_options$sourcemaps = options.sourcemaps) === null || _options$sourcemaps === void 0 ? void 0 : _options$sourcemaps.disable) !== true)) {
9966
+ if (typeof injectionPlugin === "function" && (!injectionCode.isEmpty() || ((_options$sourcemaps = options.sourcemaps) === null || _options$sourcemaps === void 0 ? void 0 : _options$sourcemaps.disable) !== true)) {
9906
9967
  var _options$sourcemaps2;
9907
9968
  plugins.push(injectionPlugin(injectionCode, ((_options$sourcemaps2 = options.sourcemaps) === null || _options$sourcemaps2 === void 0 ? void 0 : _options$sourcemaps2.disable) !== true, logger));
9908
9969
  }
@@ -9950,7 +10011,7 @@ function sentryUnpluginFactory(_ref) {
9950
10011
  } else if (options.reactComponentAnnotation.enabled && !componentNameAnnotatePlugin) {
9951
10012
  logger.warn("The component name annotate plugin is currently not supported by '@sentry/esbuild-plugin'");
9952
10013
  } else {
9953
- componentNameAnnotatePlugin && plugins.push(componentNameAnnotatePlugin(options.reactComponentAnnotation.ignoredComponents));
10014
+ componentNameAnnotatePlugin && plugins.push(componentNameAnnotatePlugin(options.reactComponentAnnotation.ignoredComponents || [], !!options.reactComponentAnnotation._experimentalInjectIntoHtml));
9954
10015
  }
9955
10016
  }
9956
10017
 
@@ -10043,8 +10104,8 @@ function createRollupBundleSizeOptimizationHooks(replacementValues) {
10043
10104
  }
10044
10105
  function createRollupInjectionHooks(injectionCode, debugIds) {
10045
10106
  return {
10046
- renderChunk: function renderChunk(code, chunk) {
10047
- var _code$match;
10107
+ renderChunk: function renderChunk(code, chunk, _, meta) {
10108
+ var _code$match, _ms$constructor;
10048
10109
  if (!isJsFile(chunk.fileName)) {
10049
10110
  return null; // returning null means not modifying the chunk at all
10050
10111
  }
@@ -10053,35 +10114,46 @@ function createRollupInjectionHooks(injectionCode, debugIds) {
10053
10114
  if (shouldSkipCodeInjection(code, chunk.facadeModuleId)) {
10054
10115
  return null;
10055
10116
  }
10056
- var codeToInject = injectionCode;
10117
+ var codeToInject = injectionCode.clone();
10057
10118
  if (debugIds) {
10058
10119
  // Check if a debug ID has already been injected to avoid duplicate injection (e.g. by another plugin or Sentry CLI)
10059
10120
  var chunkStartSnippet = code.slice(0, 6000);
10060
10121
  var chunkEndSnippet = code.slice(-500);
10061
10122
  if (!(chunkStartSnippet.includes("_sentryDebugIdIdentifier") || chunkEndSnippet.includes("//# debugId="))) {
10062
10123
  var debugId = stringToUUID(code); // generate a deterministic debug ID
10063
- codeToInject += getDebugIdSnippet(debugId);
10124
+ codeToInject.append(getDebugIdSnippet(debugId));
10064
10125
  }
10065
10126
  }
10066
- var ms = new MagicString__default["default"](code, {
10127
+ var ms = (meta === null || meta === void 0 ? void 0 : meta.magicString) || new MagicString__default["default"](code, {
10067
10128
  filename: chunk.fileName
10068
10129
  });
10069
10130
  var match = (_code$match = code.match(COMMENT_USE_STRICT_REGEX)) === null || _code$match === void 0 ? void 0 : _code$match[0];
10070
10131
  if (match) {
10071
10132
  // Add injected code after any comments or "use strict" at the beginning of the bundle.
10072
- ms.appendLeft(match.length, codeToInject);
10133
+ ms.appendLeft(match.length, codeToInject.code());
10073
10134
  } else {
10074
10135
  // ms.replace() doesn't work when there is an empty string match (which happens if
10075
10136
  // there is neither, a comment, nor a "use strict" at the top of the chunk) so we
10076
10137
  // need this special case here.
10077
- ms.prepend(codeToInject);
10138
+ ms.prepend(codeToInject.code());
10139
+ }
10140
+
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
+ };
10078
10148
  }
10079
10149
  return {
10080
10150
  code: ms.toString(),
10081
- map: ms.generateMap({
10082
- file: chunk.fileName,
10083
- hires: "boundary"
10084
- })
10151
+ get map() {
10152
+ return ms.generateMap({
10153
+ file: chunk.fileName,
10154
+ hires: "boundary"
10155
+ });
10156
+ }
10085
10157
  };
10086
10158
  }
10087
10159
  };
@@ -10147,11 +10219,11 @@ function createRollupDebugIdUploadHooks(upload, _logger, createDependencyOnBuild
10147
10219
  }
10148
10220
  };
10149
10221
  }
10150
- function createComponentNameAnnotateHooks(ignoredComponents) {
10222
+ function createComponentNameAnnotateHooks(ignoredComponents, injectIntoHtml) {
10151
10223
  return {
10152
10224
  transform: function transform(code, id) {
10153
10225
  return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
10154
- var idWithoutQueryAndHash, parserPlugins, _result$code, result;
10226
+ var idWithoutQueryAndHash, parserPlugins, plugin, _result$code, result;
10155
10227
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
10156
10228
  while (1) switch (_context4.prev = _context4.next) {
10157
10229
  case 0:
@@ -10177,10 +10249,11 @@ function createComponentNameAnnotateHooks(ignoredComponents) {
10177
10249
  } else if (idWithoutQueryAndHash.endsWith(".tsx")) {
10178
10250
  parserPlugins.push("jsx", "typescript");
10179
10251
  }
10180
- _context4.prev = 7;
10181
- _context4.next = 10;
10252
+ plugin = injectIntoHtml ? componentNameAnnotatePlugin.experimentalComponentNameAnnotatePlugin : componentNameAnnotatePlugin__default["default"];
10253
+ _context4.prev = 8;
10254
+ _context4.next = 11;
10182
10255
  return core.transformAsync(code, {
10183
- plugins: [[componentNameAnnotatePlugin__default["default"], {
10256
+ plugins: [[plugin, {
10184
10257
  ignoredComponents: ignoredComponents
10185
10258
  }]],
10186
10259
  filename: id,
@@ -10194,33 +10267,34 @@ function createComponentNameAnnotateHooks(ignoredComponents) {
10194
10267
  },
10195
10268
  sourceMaps: true
10196
10269
  });
10197
- case 10:
10270
+ case 11:
10198
10271
  result = _context4.sent;
10199
10272
  return _context4.abrupt("return", {
10200
10273
  code: (_result$code = result === null || result === void 0 ? void 0 : result.code) !== null && _result$code !== void 0 ? _result$code : code,
10201
10274
  map: result === null || result === void 0 ? void 0 : result.map
10202
10275
  });
10203
- case 14:
10204
- _context4.prev = 14;
10205
- _context4.t0 = _context4["catch"](7);
10276
+ case 15:
10277
+ _context4.prev = 15;
10278
+ _context4.t0 = _context4["catch"](8);
10206
10279
  logger.error("Failed to apply react annotate plugin", _context4.t0);
10207
- case 17:
10280
+ case 18:
10208
10281
  return _context4.abrupt("return", {
10209
10282
  code: code
10210
10283
  });
10211
- case 18:
10284
+ case 19:
10212
10285
  case "end":
10213
10286
  return _context4.stop();
10214
10287
  }
10215
- }, _callee4, null, [[7, 14]]);
10288
+ }, _callee4, null, [[8, 15]]);
10216
10289
  }))();
10217
10290
  }
10218
10291
  };
10219
10292
  }
10220
10293
  function getDebugIdSnippet(debugId) {
10221
- 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, "\");"));
10222
10295
  }
10223
10296
 
10297
+ exports.CodeInjection = CodeInjection;
10224
10298
  exports.createComponentNameAnnotateHooks = createComponentNameAnnotateHooks;
10225
10299
  exports.createRollupBundleSizeOptimizationHooks = createRollupBundleSizeOptimizationHooks;
10226
10300
  exports.createRollupDebugIdUploadHooks = createRollupDebugIdUploadHooks;