@sentry/bundler-plugin-core 4.7.0 → 4.9.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,10 +8093,55 @@ 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) {
8083
- 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;
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$_metaOpt3, _userOptions$_metaOpt4, _userOptions$_experim;
8084
8145
  var options = {
8085
8146
  org: (_userOptions$org = userOptions.org) !== null && _userOptions$org !== void 0 ? _userOptions$org : process.env["SENTRY_ORG"],
8086
8147
  project: (_userOptions$project = userOptions.project) !== null && _userOptions$project !== void 0 ? _userOptions$project : (_process$env$SENTRY_P = process.env["SENTRY_PROJECT"]) !== null && _process$env$SENTRY_P !== void 0 && _process$env$SENTRY_P.includes(",") ? process.env["SENTRY_PROJECT"].split(",").map(function (p) {
@@ -8107,7 +8168,8 @@ function normalizeUserOptions(userOptions) {
8107
8168
  reactComponentAnnotation: userOptions.reactComponentAnnotation,
8108
8169
  _metaOptions: {
8109
8170
  telemetry: {
8110
- metaFramework: (_userOptions$_metaOpt = userOptions._metaOptions) === null || _userOptions$_metaOpt === void 0 ? void 0 : (_userOptions$_metaOpt2 = _userOptions$_metaOpt.telemetry) === null || _userOptions$_metaOpt2 === void 0 ? void 0 : _userOptions$_metaOpt2.metaFramework
8171
+ metaFramework: (_userOptions$_metaOpt = userOptions._metaOptions) === null || _userOptions$_metaOpt === void 0 ? void 0 : (_userOptions$_metaOpt2 = _userOptions$_metaOpt.telemetry) === null || _userOptions$_metaOpt2 === void 0 ? void 0 : _userOptions$_metaOpt2.metaFramework,
8172
+ bundlerMajorVersion: (_userOptions$_metaOpt3 = userOptions._metaOptions) === null || _userOptions$_metaOpt3 === void 0 ? void 0 : (_userOptions$_metaOpt4 = _userOptions$_metaOpt3.telemetry) === null || _userOptions$_metaOpt4 === void 0 ? void 0 : _userOptions$_metaOpt4.bundlerMajorVersion
8111
8173
  }
8112
8174
  },
8113
8175
  applicationKey: userOptions.applicationKey,
@@ -8378,7 +8440,7 @@ function createSentryInstance(options, shouldSendTelemetry, buildTool) {
8378
8440
  dsn: "https://4c2bae7d9fbc413e8f7385f55c515d51@o1.ingest.sentry.io/6690737",
8379
8441
  tracesSampleRate: 1,
8380
8442
  sampleRate: 1,
8381
- release: "4.7.0",
8443
+ release: "4.9.0",
8382
8444
  integrations: [],
8383
8445
  tracePropagationTargets: ["sentry.io/api"],
8384
8446
  stackParser: stackParser,
@@ -8448,6 +8510,7 @@ function setTelemetryDataOnScope(options, scope, buildTool) {
8448
8510
  project: Array.isArray(project) ? project.join(", ") : project !== null && project !== void 0 ? project : "undefined",
8449
8511
  bundler: buildTool
8450
8512
  });
8513
+ scope.setTag("bundler-major-version", options._metaOptions.telemetry.bundlerMajorVersion);
8451
8514
  scope.setUser({
8452
8515
  id: org
8453
8516
  });
@@ -8987,7 +9050,7 @@ function createSentryBuildPluginManager(userOptions, bundlerPluginMetaContext) {
8987
9050
  });
8988
9051
 
8989
9052
  // 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");
9053
+ process.env["SENTRY_PIPELINE"] = "".concat(bundlerPluginMetaContext.buildTool, "-plugin/", "4.9.0");
8991
9054
 
8992
9055
  // Propagate debug flag to Sentry CLI via environment variable
8993
9056
  // Only set if not already defined to respect user's explicit configuration
@@ -9878,7 +9941,7 @@ function sentryUnpluginFactory(_ref) {
9878
9941
  if (Object.keys(bundleSizeOptimizationReplacementValues).length > 0) {
9879
9942
  plugins.push(bundleSizeOptimizationsPlugin(bundleSizeOptimizationReplacementValues));
9880
9943
  }
9881
- var injectionCode = "";
9944
+ var injectionCode = new CodeInjection();
9882
9945
  if (!options.release.inject) {
9883
9946
  logger.debug("Release injection disabled via `release.inject` option. Will not inject release.");
9884
9947
  } else if (!options.release.name) {
@@ -9889,20 +9952,20 @@ function sentryUnpluginFactory(_ref) {
9889
9952
  injectBuildInformation: options._experiments.injectBuildInformation || false
9890
9953
  });
9891
9954
  if (typeof injectionPlugin !== "function") {
9892
- plugins.push(injectionPlugin.releaseInjectionPlugin(_code));
9955
+ plugins.push(injectionPlugin.releaseInjectionPlugin(_code.code()));
9893
9956
  } else {
9894
- injectionCode += _code;
9957
+ injectionCode.append(_code);
9895
9958
  }
9896
9959
  }
9897
9960
  if (Object.keys(sentryBuildPluginManager.bundleMetadata).length > 0) {
9898
9961
  var _code2 = generateModuleMetadataInjectorCode(sentryBuildPluginManager.bundleMetadata);
9899
9962
  if (typeof injectionPlugin !== "function") {
9900
- plugins.push(injectionPlugin.moduleMetadataInjectionPlugin(_code2));
9963
+ plugins.push(injectionPlugin.moduleMetadataInjectionPlugin(_code2.code()));
9901
9964
  } else {
9902
- injectionCode += _code2;
9965
+ injectionCode.append(_code2);
9903
9966
  }
9904
9967
  }
9905
- if (typeof injectionPlugin === "function" && (injectionCode !== "" || ((_options$sourcemaps = options.sourcemaps) === null || _options$sourcemaps === void 0 ? void 0 : _options$sourcemaps.disable) !== true)) {
9968
+ if (typeof injectionPlugin === "function" && (!injectionCode.isEmpty() || ((_options$sourcemaps = options.sourcemaps) === null || _options$sourcemaps === void 0 ? void 0 : _options$sourcemaps.disable) !== true)) {
9906
9969
  var _options$sourcemaps2;
9907
9970
  plugins.push(injectionPlugin(injectionCode, ((_options$sourcemaps2 = options.sourcemaps) === null || _options$sourcemaps2 === void 0 ? void 0 : _options$sourcemaps2.disable) !== true, logger));
9908
9971
  }
@@ -9950,7 +10013,7 @@ function sentryUnpluginFactory(_ref) {
9950
10013
  } else if (options.reactComponentAnnotation.enabled && !componentNameAnnotatePlugin) {
9951
10014
  logger.warn("The component name annotate plugin is currently not supported by '@sentry/esbuild-plugin'");
9952
10015
  } else {
9953
- componentNameAnnotatePlugin && plugins.push(componentNameAnnotatePlugin(options.reactComponentAnnotation.ignoredComponents));
10016
+ componentNameAnnotatePlugin && plugins.push(componentNameAnnotatePlugin(options.reactComponentAnnotation.ignoredComponents || [], !!options.reactComponentAnnotation._experimentalInjectIntoHtml));
9954
10017
  }
9955
10018
  }
9956
10019
 
@@ -10043,8 +10106,8 @@ function createRollupBundleSizeOptimizationHooks(replacementValues) {
10043
10106
  }
10044
10107
  function createRollupInjectionHooks(injectionCode, debugIds) {
10045
10108
  return {
10046
- renderChunk: function renderChunk(code, chunk) {
10047
- var _code$match;
10109
+ renderChunk: function renderChunk(code, chunk, _, meta) {
10110
+ var _code$match, _ms$constructor;
10048
10111
  if (!isJsFile(chunk.fileName)) {
10049
10112
  return null; // returning null means not modifying the chunk at all
10050
10113
  }
@@ -10053,35 +10116,46 @@ function createRollupInjectionHooks(injectionCode, debugIds) {
10053
10116
  if (shouldSkipCodeInjection(code, chunk.facadeModuleId)) {
10054
10117
  return null;
10055
10118
  }
10056
- var codeToInject = injectionCode;
10119
+ var codeToInject = injectionCode.clone();
10057
10120
  if (debugIds) {
10058
10121
  // Check if a debug ID has already been injected to avoid duplicate injection (e.g. by another plugin or Sentry CLI)
10059
10122
  var chunkStartSnippet = code.slice(0, 6000);
10060
10123
  var chunkEndSnippet = code.slice(-500);
10061
10124
  if (!(chunkStartSnippet.includes("_sentryDebugIdIdentifier") || chunkEndSnippet.includes("//# debugId="))) {
10062
10125
  var debugId = stringToUUID(code); // generate a deterministic debug ID
10063
- codeToInject += getDebugIdSnippet(debugId);
10126
+ codeToInject.append(getDebugIdSnippet(debugId));
10064
10127
  }
10065
10128
  }
10066
- var ms = new MagicString__default["default"](code, {
10129
+ var ms = (meta === null || meta === void 0 ? void 0 : meta.magicString) || new MagicString__default["default"](code, {
10067
10130
  filename: chunk.fileName
10068
10131
  });
10069
10132
  var match = (_code$match = code.match(COMMENT_USE_STRICT_REGEX)) === null || _code$match === void 0 ? void 0 : _code$match[0];
10070
10133
  if (match) {
10071
10134
  // Add injected code after any comments or "use strict" at the beginning of the bundle.
10072
- ms.appendLeft(match.length, codeToInject);
10135
+ ms.appendLeft(match.length, codeToInject.code());
10073
10136
  } else {
10074
10137
  // ms.replace() doesn't work when there is an empty string match (which happens if
10075
10138
  // there is neither, a comment, nor a "use strict" at the top of the chunk) so we
10076
10139
  // need this special case here.
10077
- ms.prepend(codeToInject);
10140
+ ms.prepend(codeToInject.code());
10141
+ }
10142
+
10143
+ // Rolldown can pass a native MagicString instance in meta.magicString
10144
+ // https://rolldown.rs/in-depth/native-magic-string#usage-examples
10145
+ if ((ms === null || ms === void 0 ? void 0 : (_ms$constructor = ms.constructor) === null || _ms$constructor === void 0 ? void 0 : _ms$constructor.name) === "BindingMagicString") {
10146
+ // Rolldown docs say to return the magic string instance directly in this case
10147
+ return {
10148
+ code: ms
10149
+ };
10078
10150
  }
10079
10151
  return {
10080
10152
  code: ms.toString(),
10081
- map: ms.generateMap({
10082
- file: chunk.fileName,
10083
- hires: "boundary"
10084
- })
10153
+ get map() {
10154
+ return ms.generateMap({
10155
+ file: chunk.fileName,
10156
+ hires: "boundary"
10157
+ });
10158
+ }
10085
10159
  };
10086
10160
  }
10087
10161
  };
@@ -10147,11 +10221,11 @@ function createRollupDebugIdUploadHooks(upload, _logger, createDependencyOnBuild
10147
10221
  }
10148
10222
  };
10149
10223
  }
10150
- function createComponentNameAnnotateHooks(ignoredComponents) {
10224
+ function createComponentNameAnnotateHooks(ignoredComponents, injectIntoHtml) {
10151
10225
  return {
10152
10226
  transform: function transform(code, id) {
10153
10227
  return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
10154
- var idWithoutQueryAndHash, parserPlugins, _result$code, result;
10228
+ var idWithoutQueryAndHash, parserPlugins, plugin, _result$code, result;
10155
10229
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
10156
10230
  while (1) switch (_context4.prev = _context4.next) {
10157
10231
  case 0:
@@ -10177,10 +10251,11 @@ function createComponentNameAnnotateHooks(ignoredComponents) {
10177
10251
  } else if (idWithoutQueryAndHash.endsWith(".tsx")) {
10178
10252
  parserPlugins.push("jsx", "typescript");
10179
10253
  }
10180
- _context4.prev = 7;
10181
- _context4.next = 10;
10254
+ plugin = injectIntoHtml ? componentNameAnnotatePlugin.experimentalComponentNameAnnotatePlugin : componentNameAnnotatePlugin__default["default"];
10255
+ _context4.prev = 8;
10256
+ _context4.next = 11;
10182
10257
  return core.transformAsync(code, {
10183
- plugins: [[componentNameAnnotatePlugin__default["default"], {
10258
+ plugins: [[plugin, {
10184
10259
  ignoredComponents: ignoredComponents
10185
10260
  }]],
10186
10261
  filename: id,
@@ -10194,33 +10269,34 @@ function createComponentNameAnnotateHooks(ignoredComponents) {
10194
10269
  },
10195
10270
  sourceMaps: true
10196
10271
  });
10197
- case 10:
10272
+ case 11:
10198
10273
  result = _context4.sent;
10199
10274
  return _context4.abrupt("return", {
10200
10275
  code: (_result$code = result === null || result === void 0 ? void 0 : result.code) !== null && _result$code !== void 0 ? _result$code : code,
10201
10276
  map: result === null || result === void 0 ? void 0 : result.map
10202
10277
  });
10203
- case 14:
10204
- _context4.prev = 14;
10205
- _context4.t0 = _context4["catch"](7);
10278
+ case 15:
10279
+ _context4.prev = 15;
10280
+ _context4.t0 = _context4["catch"](8);
10206
10281
  logger.error("Failed to apply react annotate plugin", _context4.t0);
10207
- case 17:
10282
+ case 18:
10208
10283
  return _context4.abrupt("return", {
10209
10284
  code: code
10210
10285
  });
10211
- case 18:
10286
+ case 19:
10212
10287
  case "end":
10213
10288
  return _context4.stop();
10214
10289
  }
10215
- }, _callee4, null, [[7, 14]]);
10290
+ }, _callee4, null, [[8, 15]]);
10216
10291
  }))();
10217
10292
  }
10218
10293
  };
10219
10294
  }
10220
10295
  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){}};");
10296
+ 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
10297
  }
10223
10298
 
10299
+ exports.CodeInjection = CodeInjection;
10224
10300
  exports.createComponentNameAnnotateHooks = createComponentNameAnnotateHooks;
10225
10301
  exports.createRollupBundleSizeOptimizationHooks = createRollupBundleSizeOptimizationHooks;
10226
10302
  exports.createRollupDebugIdUploadHooks = createRollupDebugIdUploadHooks;