@sentry/bundler-plugin-core 2.8.0 → 2.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
@@ -651,6 +651,24 @@ function stripQueryAndHashFromPath(path) {
651
651
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
652
652
  return path.split("?")[0].split("#")[0];
653
653
  }
654
+ function replaceBooleanFlagsInCode(code, replacementValues) {
655
+ var ms = new MagicString__default["default"](code);
656
+ Object.keys(replacementValues).forEach(function (key) {
657
+ var value = replacementValues[key];
658
+ if (typeof value === "boolean") {
659
+ ms.replaceAll(key, JSON.stringify(value));
660
+ }
661
+ });
662
+ if (ms.hasChanged()) {
663
+ return {
664
+ code: ms.toString(),
665
+ map: ms.generateMap({
666
+ hires: true
667
+ })
668
+ };
669
+ }
670
+ return null;
671
+ }
654
672
 
655
673
  var SENTRY_SAAS_URL = "https://sentry.io";
656
674
  function normalizeUserOptions(userOptions) {
@@ -675,6 +693,7 @@ function normalizeUserOptions(userOptions) {
675
693
  vcsRemote: (_ref3 = (_userOptions$release$5 = (_userOptions$release5 = userOptions.release) === null || _userOptions$release5 === void 0 ? void 0 : _userOptions$release5.vcsRemote) !== null && _userOptions$release$5 !== void 0 ? _userOptions$release$5 : process.env["SENTRY_VSC_REMOTE"]) !== null && _ref3 !== void 0 ? _ref3 : "origin",
676
694
  cleanArtifacts: (_userOptions$release$6 = (_userOptions$release6 = userOptions.release) === null || _userOptions$release6 === void 0 ? void 0 : _userOptions$release6.cleanArtifacts) !== null && _userOptions$release$6 !== void 0 ? _userOptions$release$6 : false
677
695
  }),
696
+ bundleSizeOptimizations: userOptions.bundleSizeOptimizations,
678
697
  _experiments: (_userOptions$_experim = userOptions._experiments) !== null && _userOptions$_experim !== void 0 ? _userOptions$_experim : {}
679
698
  };
680
699
  return options;
@@ -1052,7 +1071,7 @@ function _determineSourceMapPathFromBundle() {
1052
1071
  // 1. try to find source map at `sourceMappingURL` location
1053
1072
  sourceMappingUrlMatch = bundleSource.match(/^\s*\/\/# sourceMappingURL=(.*)$/m);
1054
1073
  if (!sourceMappingUrlMatch) {
1055
- _context6.next = 21;
1074
+ _context6.next = 14;
1056
1075
  break;
1057
1076
  }
1058
1077
  sourceMappingUrl = path__default["default"].normalize(sourceMappingUrlMatch[1]);
@@ -1064,53 +1083,44 @@ function _determineSourceMapPathFromBundle() {
1064
1083
  isUrl = false;
1065
1084
  isSupportedUrl = false;
1066
1085
  }
1067
- if (!isSupportedUrl) {
1068
- _context6.next = 8;
1069
- break;
1070
- }
1071
- absoluteSourceMapPath = sourceMappingUrl;
1072
- _context6.next = 13;
1073
- break;
1074
- case 8:
1075
- if (!isUrl) {
1076
- _context6.next = 12;
1077
- break;
1078
- }
1079
- return _context6.abrupt("return");
1080
- case 12:
1081
- if (path__default["default"].isAbsolute(sourceMappingUrl)) {
1086
+ if (isSupportedUrl) {
1087
+ absoluteSourceMapPath = sourceMappingUrl;
1088
+ } else if (isUrl) ; else if (path__default["default"].isAbsolute(sourceMappingUrl)) {
1082
1089
  absoluteSourceMapPath = sourceMappingUrl;
1083
1090
  } else {
1084
1091
  absoluteSourceMapPath = path__default["default"].join(path__default["default"].dirname(bundlePath), sourceMappingUrl);
1085
1092
  }
1086
- case 13:
1087
- _context6.prev = 13;
1088
- _context6.next = 16;
1093
+ if (!absoluteSourceMapPath) {
1094
+ _context6.next = 14;
1095
+ break;
1096
+ }
1097
+ _context6.prev = 6;
1098
+ _context6.next = 9;
1089
1099
  return util__namespace.promisify(fs__default["default"].access)(absoluteSourceMapPath);
1090
- case 16:
1100
+ case 9:
1091
1101
  return _context6.abrupt("return", absoluteSourceMapPath);
1092
- case 19:
1093
- _context6.prev = 19;
1094
- _context6.t0 = _context6["catch"](13);
1095
- case 21:
1096
- _context6.prev = 21;
1102
+ case 12:
1103
+ _context6.prev = 12;
1104
+ _context6.t0 = _context6["catch"](6);
1105
+ case 14:
1106
+ _context6.prev = 14;
1097
1107
  adjacentSourceMapFilePath = bundlePath + ".map";
1098
- _context6.next = 25;
1108
+ _context6.next = 18;
1099
1109
  return util__namespace.promisify(fs__default["default"].access)(adjacentSourceMapFilePath);
1100
- case 25:
1110
+ case 18:
1101
1111
  return _context6.abrupt("return", adjacentSourceMapFilePath);
1102
- case 28:
1103
- _context6.prev = 28;
1104
- _context6.t1 = _context6["catch"](21);
1105
- case 30:
1112
+ case 21:
1113
+ _context6.prev = 21;
1114
+ _context6.t1 = _context6["catch"](14);
1115
+ case 23:
1106
1116
  // This is just a debug message because it can be quite spammy for some frameworks
1107
1117
  logger.debug("Could not determine source map path for bundle: ".concat(bundlePath, " - Did you turn on source map generation in your bundler?"));
1108
1118
  return _context6.abrupt("return", undefined);
1109
- case 32:
1119
+ case 25:
1110
1120
  case "end":
1111
1121
  return _context6.stop();
1112
1122
  }
1113
- }, _callee6, null, [[13, 19], [21, 28]]);
1123
+ }, _callee6, null, [[6, 12], [14, 21]]);
1114
1124
  }));
1115
1125
  return _determineSourceMapPathFromBundle.apply(this, arguments);
1116
1126
  }
@@ -1374,7 +1384,7 @@ function createSentryInstance(options, shouldSendTelemetry, bundler) {
1374
1384
  dsn: "https://4c2bae7d9fbc413e8f7385f55c515d51@o1.ingest.sentry.io/6690737",
1375
1385
  tracesSampleRate: 1,
1376
1386
  sampleRate: 1,
1377
- release: "2.8.0",
1387
+ release: "2.9.0",
1378
1388
  integrations: [],
1379
1389
  tracePropagationTargets: ["sentry.io/api"],
1380
1390
  stackParser: node.defaultStackParser,
@@ -1564,7 +1574,8 @@ function sentryUnpluginFactory(_ref) {
1564
1574
  var releaseInjectionPlugin = _ref.releaseInjectionPlugin,
1565
1575
  moduleMetadataInjectionPlugin = _ref.moduleMetadataInjectionPlugin,
1566
1576
  debugIdInjectionPlugin = _ref.debugIdInjectionPlugin,
1567
- debugIdUploadPlugin = _ref.debugIdUploadPlugin;
1577
+ debugIdUploadPlugin = _ref.debugIdUploadPlugin,
1578
+ bundleSizeOptimizationsPlugin = _ref.bundleSizeOptimizationsPlugin;
1568
1579
  return unplugin.createUnplugin(function (userOptions, unpluginMetaContext) {
1569
1580
  var _userOptions$silent, _userOptions$debug;
1570
1581
  var logger = createLogger({
@@ -1606,7 +1617,7 @@ function sentryUnpluginFactory(_ref) {
1606
1617
  });
1607
1618
 
1608
1619
  // Set the User-Agent that Sentry CLI will use when interacting with Sentry
1609
- process.env["SENTRY_PIPELINE"] = "".concat(unpluginMetaContext.framework, "-plugin/", "2.8.0");
1620
+ process.env["SENTRY_PIPELINE"] = "".concat(unpluginMetaContext.framework, "-plugin/", "2.9.0");
1610
1621
  function handleRecoverableError(unknownError) {
1611
1622
  sentrySession.status = "abnormal";
1612
1623
  try {
@@ -1642,6 +1653,28 @@ function sentryUnpluginFactory(_ref) {
1642
1653
  logger: logger,
1643
1654
  shouldSendTelemetry: shouldSendTelemetry
1644
1655
  }));
1656
+ if (options.bundleSizeOptimizations) {
1657
+ var bundleSizeOptimizations = options.bundleSizeOptimizations;
1658
+ var replacementValues = {};
1659
+ if (bundleSizeOptimizations.excludeDebugStatements) {
1660
+ replacementValues["__SENTRY_DEBUG__"] = false;
1661
+ }
1662
+ if (bundleSizeOptimizations.excludePerformanceMonitoring) {
1663
+ replacementValues["__SENTRY_TRACE__"] = false;
1664
+ }
1665
+ if (bundleSizeOptimizations.excludeReplayCanvas) {
1666
+ replacementValues["__RRWEB_EXCLUDE_CANVAS__"] = true;
1667
+ }
1668
+ if (bundleSizeOptimizations.excludeReplayIframe) {
1669
+ replacementValues["__RRWEB_EXCLUDE_IFRAME__"] = true;
1670
+ }
1671
+ if (bundleSizeOptimizations.excludeReplayShadowDom) {
1672
+ replacementValues["__RRWEB_EXCLUDE_SHADOW_DOM__"] = true;
1673
+ }
1674
+ if (Object.keys(replacementValues).length > 0) {
1675
+ plugins.push(bundleSizeOptimizationsPlugin(replacementValues));
1676
+ }
1677
+ }
1645
1678
  if (!options.release.inject) {
1646
1679
  logger.debug("Release injection disabled via `release.inject` option. Will not inject release.");
1647
1680
  } else if (!options.release.name) {
@@ -1812,6 +1845,13 @@ function createRollupReleaseInjectionHooks(injectionCode) {
1812
1845
  }
1813
1846
  };
1814
1847
  }
1848
+ function createRollupBundleSizeOptimizationHooks(replacementValues) {
1849
+ return {
1850
+ transform: function transform(code) {
1851
+ return replaceBooleanFlagsInCode(code, replacementValues);
1852
+ }
1853
+ };
1854
+ }
1815
1855
 
1816
1856
  // We need to be careful not to inject the snippet before any `"use strict";`s.
1817
1857
  // As an additional complication `"use strict";`s may come after any number of comments.
@@ -1904,7 +1944,7 @@ function createRollupDebugIdUploadHooks(upload) {
1904
1944
  }
1905
1945
  outputDir = outputOptions.dir;
1906
1946
  _context.next = 4;
1907
- return glob.glob(["/**/*.js", "/**/*.js.map"], {
1947
+ return glob.glob(["/**/*.js", "/**/*.js.map", "/**/*.mjs.map", "/**/*.cjs.map"], {
1908
1948
  root: outputDir,
1909
1949
  absolute: true,
1910
1950
  nodir: true
@@ -1945,12 +1985,14 @@ function getDebugIdSnippet(debugId) {
1945
1985
  return ";!function(){try{var e=\"undefined\"!=typeof window?window:\"undefined\"!=typeof global?global:\"undefined\"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]=\"".concat(debugId, "\",e._sentryDebugIdIdentifier=\"sentry-dbid-").concat(debugId, "\")}catch(e){}}();");
1946
1986
  }
1947
1987
 
1988
+ exports.createRollupBundleSizeOptimizationHooks = createRollupBundleSizeOptimizationHooks;
1948
1989
  exports.createRollupDebugIdInjectionHooks = createRollupDebugIdInjectionHooks;
1949
1990
  exports.createRollupDebugIdUploadHooks = createRollupDebugIdUploadHooks;
1950
1991
  exports.createRollupModuleMetadataInjectionHooks = createRollupModuleMetadataInjectionHooks;
1951
1992
  exports.createRollupReleaseInjectionHooks = createRollupReleaseInjectionHooks;
1952
1993
  exports.getBuildInformation = getBuildInformation;
1953
1994
  exports.getDebugIdSnippet = getDebugIdSnippet;
1995
+ exports.replaceBooleanFlagsInCode = replaceBooleanFlagsInCode;
1954
1996
  exports.sentryCliBinaryExists = sentryCliBinaryExists;
1955
1997
  exports.sentryUnpluginFactory = sentryUnpluginFactory;
1956
1998
  exports.stringToUUID = stringToUUID;