@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.
@@ -617,6 +617,24 @@ function stripQueryAndHashFromPath(path) {
617
617
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
618
618
  return path.split("?")[0].split("#")[0];
619
619
  }
620
+ function replaceBooleanFlagsInCode(code, replacementValues) {
621
+ var ms = new MagicString(code);
622
+ Object.keys(replacementValues).forEach(function (key) {
623
+ var value = replacementValues[key];
624
+ if (typeof value === "boolean") {
625
+ ms.replaceAll(key, JSON.stringify(value));
626
+ }
627
+ });
628
+ if (ms.hasChanged()) {
629
+ return {
630
+ code: ms.toString(),
631
+ map: ms.generateMap({
632
+ hires: true
633
+ })
634
+ };
635
+ }
636
+ return null;
637
+ }
620
638
 
621
639
  var SENTRY_SAAS_URL = "https://sentry.io";
622
640
  function normalizeUserOptions(userOptions) {
@@ -641,6 +659,7 @@ function normalizeUserOptions(userOptions) {
641
659
  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",
642
660
  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
643
661
  }),
662
+ bundleSizeOptimizations: userOptions.bundleSizeOptimizations,
644
663
  _experiments: (_userOptions$_experim = userOptions._experiments) !== null && _userOptions$_experim !== void 0 ? _userOptions$_experim : {}
645
664
  };
646
665
  return options;
@@ -1018,7 +1037,7 @@ function _determineSourceMapPathFromBundle() {
1018
1037
  // 1. try to find source map at `sourceMappingURL` location
1019
1038
  sourceMappingUrlMatch = bundleSource.match(/^\s*\/\/# sourceMappingURL=(.*)$/m);
1020
1039
  if (!sourceMappingUrlMatch) {
1021
- _context6.next = 21;
1040
+ _context6.next = 14;
1022
1041
  break;
1023
1042
  }
1024
1043
  sourceMappingUrl = path__default.normalize(sourceMappingUrlMatch[1]);
@@ -1030,53 +1049,44 @@ function _determineSourceMapPathFromBundle() {
1030
1049
  isUrl = false;
1031
1050
  isSupportedUrl = false;
1032
1051
  }
1033
- if (!isSupportedUrl) {
1034
- _context6.next = 8;
1035
- break;
1036
- }
1037
- absoluteSourceMapPath = sourceMappingUrl;
1038
- _context6.next = 13;
1039
- break;
1040
- case 8:
1041
- if (!isUrl) {
1042
- _context6.next = 12;
1043
- break;
1044
- }
1045
- return _context6.abrupt("return");
1046
- case 12:
1047
- if (path__default.isAbsolute(sourceMappingUrl)) {
1052
+ if (isSupportedUrl) {
1053
+ absoluteSourceMapPath = sourceMappingUrl;
1054
+ } else if (isUrl) ; else if (path__default.isAbsolute(sourceMappingUrl)) {
1048
1055
  absoluteSourceMapPath = sourceMappingUrl;
1049
1056
  } else {
1050
1057
  absoluteSourceMapPath = path__default.join(path__default.dirname(bundlePath), sourceMappingUrl);
1051
1058
  }
1052
- case 13:
1053
- _context6.prev = 13;
1054
- _context6.next = 16;
1059
+ if (!absoluteSourceMapPath) {
1060
+ _context6.next = 14;
1061
+ break;
1062
+ }
1063
+ _context6.prev = 6;
1064
+ _context6.next = 9;
1055
1065
  return util.promisify(fs__default.access)(absoluteSourceMapPath);
1056
- case 16:
1066
+ case 9:
1057
1067
  return _context6.abrupt("return", absoluteSourceMapPath);
1058
- case 19:
1059
- _context6.prev = 19;
1060
- _context6.t0 = _context6["catch"](13);
1061
- case 21:
1062
- _context6.prev = 21;
1068
+ case 12:
1069
+ _context6.prev = 12;
1070
+ _context6.t0 = _context6["catch"](6);
1071
+ case 14:
1072
+ _context6.prev = 14;
1063
1073
  adjacentSourceMapFilePath = bundlePath + ".map";
1064
- _context6.next = 25;
1074
+ _context6.next = 18;
1065
1075
  return util.promisify(fs__default.access)(adjacentSourceMapFilePath);
1066
- case 25:
1076
+ case 18:
1067
1077
  return _context6.abrupt("return", adjacentSourceMapFilePath);
1068
- case 28:
1069
- _context6.prev = 28;
1070
- _context6.t1 = _context6["catch"](21);
1071
- case 30:
1078
+ case 21:
1079
+ _context6.prev = 21;
1080
+ _context6.t1 = _context6["catch"](14);
1081
+ case 23:
1072
1082
  // This is just a debug message because it can be quite spammy for some frameworks
1073
1083
  logger.debug("Could not determine source map path for bundle: ".concat(bundlePath, " - Did you turn on source map generation in your bundler?"));
1074
1084
  return _context6.abrupt("return", undefined);
1075
- case 32:
1085
+ case 25:
1076
1086
  case "end":
1077
1087
  return _context6.stop();
1078
1088
  }
1079
- }, _callee6, null, [[13, 19], [21, 28]]);
1089
+ }, _callee6, null, [[6, 12], [14, 21]]);
1080
1090
  }));
1081
1091
  return _determineSourceMapPathFromBundle.apply(this, arguments);
1082
1092
  }
@@ -1340,7 +1350,7 @@ function createSentryInstance(options, shouldSendTelemetry, bundler) {
1340
1350
  dsn: "https://4c2bae7d9fbc413e8f7385f55c515d51@o1.ingest.sentry.io/6690737",
1341
1351
  tracesSampleRate: 1,
1342
1352
  sampleRate: 1,
1343
- release: "2.8.0",
1353
+ release: "2.9.0",
1344
1354
  integrations: [],
1345
1355
  tracePropagationTargets: ["sentry.io/api"],
1346
1356
  stackParser: defaultStackParser,
@@ -1530,7 +1540,8 @@ function sentryUnpluginFactory(_ref) {
1530
1540
  var releaseInjectionPlugin = _ref.releaseInjectionPlugin,
1531
1541
  moduleMetadataInjectionPlugin = _ref.moduleMetadataInjectionPlugin,
1532
1542
  debugIdInjectionPlugin = _ref.debugIdInjectionPlugin,
1533
- debugIdUploadPlugin = _ref.debugIdUploadPlugin;
1543
+ debugIdUploadPlugin = _ref.debugIdUploadPlugin,
1544
+ bundleSizeOptimizationsPlugin = _ref.bundleSizeOptimizationsPlugin;
1534
1545
  return createUnplugin(function (userOptions, unpluginMetaContext) {
1535
1546
  var _userOptions$silent, _userOptions$debug;
1536
1547
  var logger = createLogger({
@@ -1572,7 +1583,7 @@ function sentryUnpluginFactory(_ref) {
1572
1583
  });
1573
1584
 
1574
1585
  // Set the User-Agent that Sentry CLI will use when interacting with Sentry
1575
- process.env["SENTRY_PIPELINE"] = "".concat(unpluginMetaContext.framework, "-plugin/", "2.8.0");
1586
+ process.env["SENTRY_PIPELINE"] = "".concat(unpluginMetaContext.framework, "-plugin/", "2.9.0");
1576
1587
  function handleRecoverableError(unknownError) {
1577
1588
  sentrySession.status = "abnormal";
1578
1589
  try {
@@ -1608,6 +1619,28 @@ function sentryUnpluginFactory(_ref) {
1608
1619
  logger: logger,
1609
1620
  shouldSendTelemetry: shouldSendTelemetry
1610
1621
  }));
1622
+ if (options.bundleSizeOptimizations) {
1623
+ var bundleSizeOptimizations = options.bundleSizeOptimizations;
1624
+ var replacementValues = {};
1625
+ if (bundleSizeOptimizations.excludeDebugStatements) {
1626
+ replacementValues["__SENTRY_DEBUG__"] = false;
1627
+ }
1628
+ if (bundleSizeOptimizations.excludePerformanceMonitoring) {
1629
+ replacementValues["__SENTRY_TRACE__"] = false;
1630
+ }
1631
+ if (bundleSizeOptimizations.excludeReplayCanvas) {
1632
+ replacementValues["__RRWEB_EXCLUDE_CANVAS__"] = true;
1633
+ }
1634
+ if (bundleSizeOptimizations.excludeReplayIframe) {
1635
+ replacementValues["__RRWEB_EXCLUDE_IFRAME__"] = true;
1636
+ }
1637
+ if (bundleSizeOptimizations.excludeReplayShadowDom) {
1638
+ replacementValues["__RRWEB_EXCLUDE_SHADOW_DOM__"] = true;
1639
+ }
1640
+ if (Object.keys(replacementValues).length > 0) {
1641
+ plugins.push(bundleSizeOptimizationsPlugin(replacementValues));
1642
+ }
1643
+ }
1611
1644
  if (!options.release.inject) {
1612
1645
  logger.debug("Release injection disabled via `release.inject` option. Will not inject release.");
1613
1646
  } else if (!options.release.name) {
@@ -1778,6 +1811,13 @@ function createRollupReleaseInjectionHooks(injectionCode) {
1778
1811
  }
1779
1812
  };
1780
1813
  }
1814
+ function createRollupBundleSizeOptimizationHooks(replacementValues) {
1815
+ return {
1816
+ transform: function transform(code) {
1817
+ return replaceBooleanFlagsInCode(code, replacementValues);
1818
+ }
1819
+ };
1820
+ }
1781
1821
 
1782
1822
  // We need to be careful not to inject the snippet before any `"use strict";`s.
1783
1823
  // As an additional complication `"use strict";`s may come after any number of comments.
@@ -1870,7 +1910,7 @@ function createRollupDebugIdUploadHooks(upload) {
1870
1910
  }
1871
1911
  outputDir = outputOptions.dir;
1872
1912
  _context.next = 4;
1873
- return glob(["/**/*.js", "/**/*.js.map"], {
1913
+ return glob(["/**/*.js", "/**/*.js.map", "/**/*.mjs.map", "/**/*.cjs.map"], {
1874
1914
  root: outputDir,
1875
1915
  absolute: true,
1876
1916
  nodir: true
@@ -1911,5 +1951,5 @@ function getDebugIdSnippet(debugId) {
1911
1951
  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){}}();");
1912
1952
  }
1913
1953
 
1914
- export { createRollupDebugIdInjectionHooks, createRollupDebugIdUploadHooks, createRollupModuleMetadataInjectionHooks, createRollupReleaseInjectionHooks, getBuildInformation, getDebugIdSnippet, sentryCliBinaryExists, sentryUnpluginFactory, stringToUUID };
1954
+ export { createRollupBundleSizeOptimizationHooks, createRollupDebugIdInjectionHooks, createRollupDebugIdUploadHooks, createRollupModuleMetadataInjectionHooks, createRollupReleaseInjectionHooks, getBuildInformation, getDebugIdSnippet, replaceBooleanFlagsInCode, sentryCliBinaryExists, sentryUnpluginFactory, stringToUUID };
1915
1955
  //# sourceMappingURL=index.mjs.map