@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.
@@ -1,5 +1,5 @@
1
1
  import { transformAsync } from '@babel/core';
2
- import componentNameAnnotatePlugin from '@sentry/babel-plugin-component-annotate';
2
+ import componentNameAnnotatePlugin, { experimentalComponentNameAnnotatePlugin } from '@sentry/babel-plugin-component-annotate';
3
3
  import SentryCli from '@sentry/cli';
4
4
  import * as fs from 'fs';
5
5
  import fs__default from 'fs';
@@ -382,6 +382,28 @@ function _asyncToGenerator(fn) {
382
382
  });
383
383
  };
384
384
  }
385
+ function _classCallCheck(instance, Constructor) {
386
+ if (!(instance instanceof Constructor)) {
387
+ throw new TypeError("Cannot call a class as a function");
388
+ }
389
+ }
390
+ function _defineProperties(target, props) {
391
+ for (var i = 0; i < props.length; i++) {
392
+ var descriptor = props[i];
393
+ descriptor.enumerable = descriptor.enumerable || false;
394
+ descriptor.configurable = true;
395
+ if ("value" in descriptor) descriptor.writable = true;
396
+ Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
397
+ }
398
+ }
399
+ function _createClass(Constructor, protoProps, staticProps) {
400
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
401
+ if (staticProps) _defineProperties(Constructor, staticProps);
402
+ Object.defineProperty(Constructor, "prototype", {
403
+ writable: false
404
+ });
405
+ return Constructor;
406
+ }
385
407
  function _defineProperty(obj, key, value) {
386
408
  key = _toPropertyKey(key);
387
409
  if (key in obj) {
@@ -7924,25 +7946,19 @@ function determineReleaseName() {
7924
7946
  function generateGlobalInjectorCode(_ref2) {
7925
7947
  var release = _ref2.release,
7926
7948
  injectBuildInformation = _ref2.injectBuildInformation;
7927
- // The code below is mostly ternary operators because it saves bundle size.
7928
- // The checks are to support as many environments as possible. (Node.js, Browser, webworkers, etc.)
7929
- var code = "!function(){try{var e=\"undefined\"!=typeof window?window:\"undefined\"!=typeof global?global:\"undefined\"!=typeof globalThis?globalThis:\"undefined\"!=typeof self?self:{};";
7930
- code += "e.SENTRY_RELEASE={id:".concat(JSON.stringify(release), "};");
7949
+ var code = "e.SENTRY_RELEASE={id:".concat(JSON.stringify(release), "};");
7931
7950
  if (injectBuildInformation) {
7932
7951
  var buildInfo = getBuildInformation();
7933
7952
  code += "e.SENTRY_BUILD_INFO=".concat(JSON.stringify(buildInfo), ";");
7934
7953
  }
7935
- code += "}catch(e){}}();";
7936
- return code;
7954
+ return new CodeInjection(code);
7937
7955
  }
7938
7956
 
7939
7957
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
7940
7958
  function generateModuleMetadataInjectorCode(metadata) {
7941
- // The code below is mostly ternary operators because it saves bundle size.
7942
- // The checks are to support as many environments as possible. (Node.js, Browser, webworkers, etc.)
7943
7959
  // We are merging the metadata objects in case modules are bundled twice with the plugin
7944
7960
  // Use try-catch to avoid issues when bundlers rename global variables like 'window' to 'k'
7945
- 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){}}();");
7961
+ 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), ");"));
7946
7962
  }
7947
7963
  function getBuildInformation() {
7948
7964
  var packageJson = getPackageJson();
@@ -8040,10 +8056,55 @@ function containsOnlyImports(code) {
8040
8056
  .replace(/["']use strict["']\s*;?/g, "").trim();
8041
8057
  return codeWithoutImports.length === 0;
8042
8058
  }
8059
+ var CodeInjection = /*#__PURE__*/function () {
8060
+ function CodeInjection() {
8061
+ var body = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
8062
+ _classCallCheck(this, CodeInjection);
8063
+ // The code below is mostly ternary operators because it saves bundle size.
8064
+ // The checks are to support as many environments as possible. (Node.js, Browser, webworkers, etc.)
8065
+ _defineProperty(this, "header", "!function(){try{var e=\"undefined\"!=typeof window?window:\"undefined\"!=typeof global?global:\"undefined\"!=typeof globalThis?globalThis:\"undefined\"!=typeof self?self:{};");
8066
+ _defineProperty(this, "footer", "}catch(e){}}();");
8067
+ this.body = body;
8068
+ }
8069
+ _createClass(CodeInjection, [{
8070
+ key: "code",
8071
+ value: function code() {
8072
+ if (this.isEmpty()) {
8073
+ return "";
8074
+ }
8075
+ return this.header + this.body + this.footer;
8076
+ }
8077
+ }, {
8078
+ key: "isEmpty",
8079
+ value: function isEmpty() {
8080
+ return this.body.length === 0;
8081
+ }
8082
+ }, {
8083
+ key: "append",
8084
+ value: function append(code) {
8085
+ if (code instanceof CodeInjection) {
8086
+ this.body += code.body;
8087
+ } else {
8088
+ this.body += code;
8089
+ }
8090
+ }
8091
+ }, {
8092
+ key: "clear",
8093
+ value: function clear() {
8094
+ this.body = "";
8095
+ }
8096
+ }, {
8097
+ key: "clone",
8098
+ value: function clone() {
8099
+ return new CodeInjection(this.body);
8100
+ }
8101
+ }]);
8102
+ return CodeInjection;
8103
+ }();
8043
8104
 
8044
8105
  var SENTRY_SAAS_URL = "https://sentry.io";
8045
8106
  function normalizeUserOptions(userOptions) {
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;
8107
+ 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;
8047
8108
  var options = {
8048
8109
  org: (_userOptions$org = userOptions.org) !== null && _userOptions$org !== void 0 ? _userOptions$org : process.env["SENTRY_ORG"],
8049
8110
  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) {
@@ -8070,7 +8131,8 @@ function normalizeUserOptions(userOptions) {
8070
8131
  reactComponentAnnotation: userOptions.reactComponentAnnotation,
8071
8132
  _metaOptions: {
8072
8133
  telemetry: {
8073
- 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
8134
+ 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,
8135
+ 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
8074
8136
  }
8075
8137
  },
8076
8138
  applicationKey: userOptions.applicationKey,
@@ -8341,7 +8403,7 @@ function createSentryInstance(options, shouldSendTelemetry, buildTool) {
8341
8403
  dsn: "https://4c2bae7d9fbc413e8f7385f55c515d51@o1.ingest.sentry.io/6690737",
8342
8404
  tracesSampleRate: 1,
8343
8405
  sampleRate: 1,
8344
- release: "4.7.0",
8406
+ release: "4.9.0",
8345
8407
  integrations: [],
8346
8408
  tracePropagationTargets: ["sentry.io/api"],
8347
8409
  stackParser: stackParser,
@@ -8411,6 +8473,7 @@ function setTelemetryDataOnScope(options, scope, buildTool) {
8411
8473
  project: Array.isArray(project) ? project.join(", ") : project !== null && project !== void 0 ? project : "undefined",
8412
8474
  bundler: buildTool
8413
8475
  });
8476
+ scope.setTag("bundler-major-version", options._metaOptions.telemetry.bundlerMajorVersion);
8414
8477
  scope.setUser({
8415
8478
  id: org
8416
8479
  });
@@ -8950,7 +9013,7 @@ function createSentryBuildPluginManager(userOptions, bundlerPluginMetaContext) {
8950
9013
  });
8951
9014
 
8952
9015
  // Set the User-Agent that Sentry CLI will use when interacting with Sentry
8953
- process.env["SENTRY_PIPELINE"] = "".concat(bundlerPluginMetaContext.buildTool, "-plugin/", "4.7.0");
9016
+ process.env["SENTRY_PIPELINE"] = "".concat(bundlerPluginMetaContext.buildTool, "-plugin/", "4.9.0");
8954
9017
 
8955
9018
  // Propagate debug flag to Sentry CLI via environment variable
8956
9019
  // Only set if not already defined to respect user's explicit configuration
@@ -9841,7 +9904,7 @@ function sentryUnpluginFactory(_ref) {
9841
9904
  if (Object.keys(bundleSizeOptimizationReplacementValues).length > 0) {
9842
9905
  plugins.push(bundleSizeOptimizationsPlugin(bundleSizeOptimizationReplacementValues));
9843
9906
  }
9844
- var injectionCode = "";
9907
+ var injectionCode = new CodeInjection();
9845
9908
  if (!options.release.inject) {
9846
9909
  logger.debug("Release injection disabled via `release.inject` option. Will not inject release.");
9847
9910
  } else if (!options.release.name) {
@@ -9852,20 +9915,20 @@ function sentryUnpluginFactory(_ref) {
9852
9915
  injectBuildInformation: options._experiments.injectBuildInformation || false
9853
9916
  });
9854
9917
  if (typeof injectionPlugin !== "function") {
9855
- plugins.push(injectionPlugin.releaseInjectionPlugin(_code));
9918
+ plugins.push(injectionPlugin.releaseInjectionPlugin(_code.code()));
9856
9919
  } else {
9857
- injectionCode += _code;
9920
+ injectionCode.append(_code);
9858
9921
  }
9859
9922
  }
9860
9923
  if (Object.keys(sentryBuildPluginManager.bundleMetadata).length > 0) {
9861
9924
  var _code2 = generateModuleMetadataInjectorCode(sentryBuildPluginManager.bundleMetadata);
9862
9925
  if (typeof injectionPlugin !== "function") {
9863
- plugins.push(injectionPlugin.moduleMetadataInjectionPlugin(_code2));
9926
+ plugins.push(injectionPlugin.moduleMetadataInjectionPlugin(_code2.code()));
9864
9927
  } else {
9865
- injectionCode += _code2;
9928
+ injectionCode.append(_code2);
9866
9929
  }
9867
9930
  }
9868
- if (typeof injectionPlugin === "function" && (injectionCode !== "" || ((_options$sourcemaps = options.sourcemaps) === null || _options$sourcemaps === void 0 ? void 0 : _options$sourcemaps.disable) !== true)) {
9931
+ if (typeof injectionPlugin === "function" && (!injectionCode.isEmpty() || ((_options$sourcemaps = options.sourcemaps) === null || _options$sourcemaps === void 0 ? void 0 : _options$sourcemaps.disable) !== true)) {
9869
9932
  var _options$sourcemaps2;
9870
9933
  plugins.push(injectionPlugin(injectionCode, ((_options$sourcemaps2 = options.sourcemaps) === null || _options$sourcemaps2 === void 0 ? void 0 : _options$sourcemaps2.disable) !== true, logger));
9871
9934
  }
@@ -9913,7 +9976,7 @@ function sentryUnpluginFactory(_ref) {
9913
9976
  } else if (options.reactComponentAnnotation.enabled && !componentNameAnnotatePlugin) {
9914
9977
  logger.warn("The component name annotate plugin is currently not supported by '@sentry/esbuild-plugin'");
9915
9978
  } else {
9916
- componentNameAnnotatePlugin && plugins.push(componentNameAnnotatePlugin(options.reactComponentAnnotation.ignoredComponents));
9979
+ componentNameAnnotatePlugin && plugins.push(componentNameAnnotatePlugin(options.reactComponentAnnotation.ignoredComponents || [], !!options.reactComponentAnnotation._experimentalInjectIntoHtml));
9917
9980
  }
9918
9981
  }
9919
9982
 
@@ -10006,8 +10069,8 @@ function createRollupBundleSizeOptimizationHooks(replacementValues) {
10006
10069
  }
10007
10070
  function createRollupInjectionHooks(injectionCode, debugIds) {
10008
10071
  return {
10009
- renderChunk: function renderChunk(code, chunk) {
10010
- var _code$match;
10072
+ renderChunk: function renderChunk(code, chunk, _, meta) {
10073
+ var _code$match, _ms$constructor;
10011
10074
  if (!isJsFile(chunk.fileName)) {
10012
10075
  return null; // returning null means not modifying the chunk at all
10013
10076
  }
@@ -10016,35 +10079,46 @@ function createRollupInjectionHooks(injectionCode, debugIds) {
10016
10079
  if (shouldSkipCodeInjection(code, chunk.facadeModuleId)) {
10017
10080
  return null;
10018
10081
  }
10019
- var codeToInject = injectionCode;
10082
+ var codeToInject = injectionCode.clone();
10020
10083
  if (debugIds) {
10021
10084
  // Check if a debug ID has already been injected to avoid duplicate injection (e.g. by another plugin or Sentry CLI)
10022
10085
  var chunkStartSnippet = code.slice(0, 6000);
10023
10086
  var chunkEndSnippet = code.slice(-500);
10024
10087
  if (!(chunkStartSnippet.includes("_sentryDebugIdIdentifier") || chunkEndSnippet.includes("//# debugId="))) {
10025
10088
  var debugId = stringToUUID(code); // generate a deterministic debug ID
10026
- codeToInject += getDebugIdSnippet(debugId);
10089
+ codeToInject.append(getDebugIdSnippet(debugId));
10027
10090
  }
10028
10091
  }
10029
- var ms = new MagicString(code, {
10092
+ var ms = (meta === null || meta === void 0 ? void 0 : meta.magicString) || new MagicString(code, {
10030
10093
  filename: chunk.fileName
10031
10094
  });
10032
10095
  var match = (_code$match = code.match(COMMENT_USE_STRICT_REGEX)) === null || _code$match === void 0 ? void 0 : _code$match[0];
10033
10096
  if (match) {
10034
10097
  // Add injected code after any comments or "use strict" at the beginning of the bundle.
10035
- ms.appendLeft(match.length, codeToInject);
10098
+ ms.appendLeft(match.length, codeToInject.code());
10036
10099
  } else {
10037
10100
  // ms.replace() doesn't work when there is an empty string match (which happens if
10038
10101
  // there is neither, a comment, nor a "use strict" at the top of the chunk) so we
10039
10102
  // need this special case here.
10040
- ms.prepend(codeToInject);
10103
+ ms.prepend(codeToInject.code());
10104
+ }
10105
+
10106
+ // Rolldown can pass a native MagicString instance in meta.magicString
10107
+ // https://rolldown.rs/in-depth/native-magic-string#usage-examples
10108
+ if ((ms === null || ms === void 0 ? void 0 : (_ms$constructor = ms.constructor) === null || _ms$constructor === void 0 ? void 0 : _ms$constructor.name) === "BindingMagicString") {
10109
+ // Rolldown docs say to return the magic string instance directly in this case
10110
+ return {
10111
+ code: ms
10112
+ };
10041
10113
  }
10042
10114
  return {
10043
10115
  code: ms.toString(),
10044
- map: ms.generateMap({
10045
- file: chunk.fileName,
10046
- hires: "boundary"
10047
- })
10116
+ get map() {
10117
+ return ms.generateMap({
10118
+ file: chunk.fileName,
10119
+ hires: "boundary"
10120
+ });
10121
+ }
10048
10122
  };
10049
10123
  }
10050
10124
  };
@@ -10110,11 +10184,11 @@ function createRollupDebugIdUploadHooks(upload, _logger, createDependencyOnBuild
10110
10184
  }
10111
10185
  };
10112
10186
  }
10113
- function createComponentNameAnnotateHooks(ignoredComponents) {
10187
+ function createComponentNameAnnotateHooks(ignoredComponents, injectIntoHtml) {
10114
10188
  return {
10115
10189
  transform: function transform(code, id) {
10116
10190
  return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
10117
- var idWithoutQueryAndHash, parserPlugins, _result$code, result;
10191
+ var idWithoutQueryAndHash, parserPlugins, plugin, _result$code, result;
10118
10192
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
10119
10193
  while (1) switch (_context4.prev = _context4.next) {
10120
10194
  case 0:
@@ -10140,10 +10214,11 @@ function createComponentNameAnnotateHooks(ignoredComponents) {
10140
10214
  } else if (idWithoutQueryAndHash.endsWith(".tsx")) {
10141
10215
  parserPlugins.push("jsx", "typescript");
10142
10216
  }
10143
- _context4.prev = 7;
10144
- _context4.next = 10;
10217
+ plugin = injectIntoHtml ? experimentalComponentNameAnnotatePlugin : componentNameAnnotatePlugin;
10218
+ _context4.prev = 8;
10219
+ _context4.next = 11;
10145
10220
  return transformAsync(code, {
10146
- plugins: [[componentNameAnnotatePlugin, {
10221
+ plugins: [[plugin, {
10147
10222
  ignoredComponents: ignoredComponents
10148
10223
  }]],
10149
10224
  filename: id,
@@ -10157,32 +10232,32 @@ function createComponentNameAnnotateHooks(ignoredComponents) {
10157
10232
  },
10158
10233
  sourceMaps: true
10159
10234
  });
10160
- case 10:
10235
+ case 11:
10161
10236
  result = _context4.sent;
10162
10237
  return _context4.abrupt("return", {
10163
10238
  code: (_result$code = result === null || result === void 0 ? void 0 : result.code) !== null && _result$code !== void 0 ? _result$code : code,
10164
10239
  map: result === null || result === void 0 ? void 0 : result.map
10165
10240
  });
10166
- case 14:
10167
- _context4.prev = 14;
10168
- _context4.t0 = _context4["catch"](7);
10241
+ case 15:
10242
+ _context4.prev = 15;
10243
+ _context4.t0 = _context4["catch"](8);
10169
10244
  logger.error("Failed to apply react annotate plugin", _context4.t0);
10170
- case 17:
10245
+ case 18:
10171
10246
  return _context4.abrupt("return", {
10172
10247
  code: code
10173
10248
  });
10174
- case 18:
10249
+ case 19:
10175
10250
  case "end":
10176
10251
  return _context4.stop();
10177
10252
  }
10178
- }, _callee4, null, [[7, 14]]);
10253
+ }, _callee4, null, [[8, 15]]);
10179
10254
  }))();
10180
10255
  }
10181
10256
  };
10182
10257
  }
10183
10258
  function getDebugIdSnippet(debugId) {
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){}};");
10259
+ 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, "\");"));
10185
10260
  }
10186
10261
 
10187
- export { createComponentNameAnnotateHooks, createRollupBundleSizeOptimizationHooks, createRollupDebugIdUploadHooks, createRollupInjectionHooks, createSentryBuildPluginManager, getDebugIdSnippet, replaceBooleanFlagsInCode, sentryCliBinaryExists, sentryUnpluginFactory, stringToUUID };
10262
+ export { CodeInjection, createComponentNameAnnotateHooks, createRollupBundleSizeOptimizationHooks, createRollupDebugIdUploadHooks, createRollupInjectionHooks, createSentryBuildPluginManager, getDebugIdSnippet, replaceBooleanFlagsInCode, sentryCliBinaryExists, sentryUnpluginFactory, stringToUUID };
10188
10263
  //# sourceMappingURL=index.mjs.map