@sentry/bundler-plugin-core 2.16.1 → 2.18.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
@@ -630,7 +630,11 @@ function determineReleaseName() {
630
630
  // Zeit (now known as Vercel)
631
631
  process.env["ZEIT_GITHUB_COMMIT_SHA"] || process.env["ZEIT_GITLAB_COMMIT_SHA"] || process.env["ZEIT_BITBUCKET_COMMIT_SHA"] ||
632
632
  // Flightcontrol - https://www.flightcontrol.dev/docs/guides/flightcontrol/environment-variables#built-in-environment-variables
633
- process.env["FC_GIT_COMMIT_SHA"] || gitRevision()
633
+ process.env["FC_GIT_COMMIT_SHA"] ||
634
+ // Heroku #1 https://devcenter.heroku.com/changelog-items/630
635
+ process.env["SOURCE_VERSION"] ||
636
+ // Heroku #2 https://docs.sentry.io/product/integrations/deployment/heroku/#configure-releases
637
+ process.env["HEROKU_SLUG_COMMIT"] || gitRevision()
634
638
  );
635
639
  }
636
640
 
@@ -655,7 +659,8 @@ function generateGlobalInjectorCode(_ref2) {
655
659
  function generateModuleMetadataInjectorCode(metadata) {
656
660
  // The code below is mostly ternary operators because it saves bundle size.
657
661
  // The checks are to support as many environments as possible. (Node.js, Browser, webworkers, etc.)
658
- return "\n var _global2 =\n typeof window !== 'undefined' ?\n window :\n typeof global !== 'undefined' ?\n global :\n typeof self !== 'undefined' ?\n self :\n {};\n\n _global2._sentryModuleMetadata = _global2._sentryModuleMetadata || {};\n _global2._sentryModuleMetadata[new Error().stack] = ".concat(JSON.stringify(metadata), ";");
662
+ // We are merging the metadata objects in case modules are bundled twice with the plugin
663
+ return "{\n var _sentryModuleMetadataGlobal =\n typeof window !== \"undefined\"\n ? window\n : typeof global !== \"undefined\"\n ? global\n : typeof self !== \"undefined\"\n ? self\n : {};\n\n _sentryModuleMetadataGlobal._sentryModuleMetadata =\n _sentryModuleMetadataGlobal._sentryModuleMetadata || {};\n\n _sentryModuleMetadataGlobal._sentryModuleMetadata[new Error().stack] =\n Object.assign(\n {},\n _sentryModuleMetadataGlobal._sentryModuleMetadata[new Error().stack],\n ".concat(JSON.stringify(metadata), "\n );\n}");
659
664
  }
660
665
  function getBuildInformation$1() {
661
666
  var packageJson = getPackageJson();
@@ -696,7 +701,7 @@ function replaceBooleanFlagsInCode(code, replacementValues) {
696
701
 
697
702
  var SENTRY_SAAS_URL = "https://sentry.io";
698
703
  function normalizeUserOptions(userOptions) {
699
- var _userOptions$org, _userOptions$project, _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$release$6, _userOptions$release6, _userOptions$_experim;
704
+ var _userOptions$org, _userOptions$project, _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$_metaOpt, _userOptions$_metaOpt2, _userOptions$_experim, _userOptions$_experim2;
700
705
  var options = {
701
706
  org: (_userOptions$org = userOptions.org) !== null && _userOptions$org !== void 0 ? _userOptions$org : process.env["SENTRY_ORG"],
702
707
  project: (_userOptions$project = userOptions.project) !== null && _userOptions$project !== void 0 ? _userOptions$project : process.env["SENTRY_PROJECT"],
@@ -714,12 +719,18 @@ function normalizeUserOptions(userOptions) {
714
719
  inject: (_userOptions$release$2 = (_userOptions$release2 = userOptions.release) === null || _userOptions$release2 === void 0 ? void 0 : _userOptions$release2.inject) !== null && _userOptions$release$2 !== void 0 ? _userOptions$release$2 : true,
715
720
  create: (_userOptions$release$3 = (_userOptions$release3 = userOptions.release) === null || _userOptions$release3 === void 0 ? void 0 : _userOptions$release3.create) !== null && _userOptions$release$3 !== void 0 ? _userOptions$release$3 : true,
716
721
  finalize: (_userOptions$release$4 = (_userOptions$release4 = userOptions.release) === null || _userOptions$release4 === void 0 ? void 0 : _userOptions$release4.finalize) !== null && _userOptions$release$4 !== void 0 ? _userOptions$release$4 : true,
717
- 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",
718
- 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
722
+ 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"
719
723
  }),
720
724
  bundleSizeOptimizations: userOptions.bundleSizeOptimizations,
721
725
  reactComponentAnnotation: userOptions.reactComponentAnnotation,
722
- _experiments: (_userOptions$_experim = userOptions._experiments) !== null && _userOptions$_experim !== void 0 ? _userOptions$_experim : {}
726
+ _metaOptions: {
727
+ telemetry: {
728
+ 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
729
+ }
730
+ },
731
+ applicationKey: userOptions.applicationKey,
732
+ moduleMetadata: userOptions.moduleMetadata || ((_userOptions$_experim = userOptions._experiments) === null || _userOptions$_experim === void 0 ? void 0 : _userOptions$_experim.moduleMetadata),
733
+ _experiments: (_userOptions$_experim2 = userOptions._experiments) !== null && _userOptions$_experim2 !== void 0 ? _userOptions$_experim2 : {}
723
734
  };
724
735
  return options;
725
736
  }
@@ -13601,7 +13612,7 @@ function createSentryInstance(options, shouldSendTelemetry, bundler) {
13601
13612
  dsn: "https://4c2bae7d9fbc413e8f7385f55c515d51@o1.ingest.sentry.io/6690737",
13602
13613
  tracesSampleRate: 1,
13603
13614
  sampleRate: 1,
13604
- release: "2.16.1",
13615
+ release: "2.18.0",
13605
13616
  integrations: [],
13606
13617
  tracePropagationTargets: ["sentry.io/api"],
13607
13618
  stackParser: defaultStackParser,
@@ -13662,6 +13673,7 @@ function createSentryInstance(options, shouldSendTelemetry, bundler) {
13662
13673
  };
13663
13674
  }
13664
13675
  function setTelemetryDataOnHub(options, hub, bundler) {
13676
+ var _options$_metaOptions;
13665
13677
  var org = options.org,
13666
13678
  project = options.project,
13667
13679
  release = options.release,
@@ -13672,11 +13684,10 @@ function setTelemetryDataOnHub(options, hub, bundler) {
13672
13684
  if (release.uploadLegacySourcemaps) {
13673
13685
  hub.setTag("uploadLegacySourcemapsEntries", Array.isArray(release.uploadLegacySourcemaps) ? release.uploadLegacySourcemaps.length : 1);
13674
13686
  }
13675
- hub.setTag("module-metadata", !!options._experiments.moduleMetadata);
13687
+ hub.setTag("module-metadata", !!options.moduleMetadata);
13676
13688
  hub.setTag("inject-build-information", !!options._experiments.injectBuildInformation);
13677
13689
 
13678
13690
  // Optional release pipeline steps
13679
- hub.setTag("clean-artifacts", release.cleanArtifacts);
13680
13691
  if (release.setCommits) {
13681
13692
  hub.setTag("set-commits", release.setCommits.auto === true ? "auto" : "manual");
13682
13693
  } else {
@@ -13692,6 +13703,7 @@ function setTelemetryDataOnHub(options, hub, bundler) {
13692
13703
  hub.setTag("react-annotate", !!(reactComponentAnnotation !== null && reactComponentAnnotation !== void 0 && reactComponentAnnotation.enabled));
13693
13704
  hub.setTag("node", process.version);
13694
13705
  hub.setTag("platform", process.platform);
13706
+ hub.setTag("meta-framework", (_options$_metaOptions = options._metaOptions.telemetry.metaFramework) !== null && _options$_metaOptions !== void 0 ? _options$_metaOptions : "none");
13695
13707
  hub.setTags({
13696
13708
  organization: org,
13697
13709
  project: project,
@@ -14263,7 +14275,6 @@ function releaseManagementPlugin(_ref) {
14263
14275
  dist = _ref.dist,
14264
14276
  setCommitsOption = _ref.setCommitsOption,
14265
14277
  shouldCreateRelease = _ref.shouldCreateRelease,
14266
- shouldCleanArtifacts = _ref.shouldCleanArtifacts,
14267
14278
  shouldFinalizeRelease = _ref.shouldFinalizeRelease,
14268
14279
  deployOptions = _ref.deployOptions,
14269
14280
  handleRecoverableError = _ref.handleRecoverableError,
@@ -14287,15 +14298,8 @@ function releaseManagementPlugin(_ref) {
14287
14298
  _context.next = 5;
14288
14299
  return cliInstance.releases["new"](releaseName);
14289
14300
  case 5:
14290
- if (!shouldCleanArtifacts) {
14291
- _context.next = 8;
14292
- break;
14293
- }
14294
- _context.next = 8;
14295
- return cliInstance.releases.execute(["releases", "files", releaseName, "delete", "--all"], true);
14296
- case 8:
14297
14301
  if (!include) {
14298
- _context.next = 12;
14302
+ _context.next = 9;
14299
14303
  break;
14300
14304
  }
14301
14305
  normalizedInclude = arrayify$1(include).map(function (includeItem) {
@@ -14312,48 +14316,48 @@ function releaseManagementPlugin(_ref) {
14312
14316
  ignore: includeEntry.ignore ? arrayify$1(includeEntry.ignore) : undefined
14313
14317
  });
14314
14318
  });
14315
- _context.next = 12;
14319
+ _context.next = 9;
14316
14320
  return cliInstance.releases.uploadSourceMaps(releaseName, {
14317
14321
  include: normalizedInclude,
14318
14322
  dist: dist
14319
14323
  });
14320
- case 12:
14324
+ case 9:
14321
14325
  if (!setCommitsOption) {
14322
- _context.next = 15;
14326
+ _context.next = 12;
14323
14327
  break;
14324
14328
  }
14325
- _context.next = 15;
14329
+ _context.next = 12;
14326
14330
  return cliInstance.releases.setCommits(releaseName, setCommitsOption);
14327
- case 15:
14331
+ case 12:
14328
14332
  if (!shouldFinalizeRelease) {
14329
- _context.next = 18;
14333
+ _context.next = 15;
14330
14334
  break;
14331
14335
  }
14332
- _context.next = 18;
14336
+ _context.next = 15;
14333
14337
  return cliInstance.releases.finalize(releaseName);
14334
- case 18:
14338
+ case 15:
14335
14339
  if (!deployOptions) {
14336
- _context.next = 21;
14340
+ _context.next = 18;
14337
14341
  break;
14338
14342
  }
14339
- _context.next = 21;
14343
+ _context.next = 18;
14340
14344
  return cliInstance.releases.newDeploy(releaseName, deployOptions);
14341
- case 21:
14342
- _context.next = 29;
14345
+ case 18:
14346
+ _context.next = 26;
14343
14347
  break;
14344
- case 23:
14345
- _context.prev = 23;
14348
+ case 20:
14349
+ _context.prev = 20;
14346
14350
  _context.t0 = _context["catch"](0);
14347
14351
  sentryHub.captureException('Error in "releaseManagementPlugin" writeBundle hook');
14348
- _context.next = 28;
14352
+ _context.next = 25;
14349
14353
  return safeFlushTelemetry(sentryClient);
14350
- case 28:
14354
+ case 25:
14351
14355
  handleRecoverableError(_context.t0);
14352
- case 29:
14356
+ case 26:
14353
14357
  case "end":
14354
14358
  return _context.stop();
14355
14359
  }
14356
- }, _callee, null, [[0, 23]]);
14360
+ }, _callee, null, [[0, 20]]);
14357
14361
  }))();
14358
14362
  }
14359
14363
  };
@@ -14458,11 +14462,10 @@ function createLogger(options) {
14458
14462
  * release creation pipeline:
14459
14463
  *
14460
14464
  * 1. Create a new release
14461
- * 2. Delete already uploaded artifacts for this release (if `cleanArtifacts` is enabled)
14462
- * 3. Upload sourcemaps based on `include` and source-map-specific options
14463
- * 4. Associate a range of commits with the release (if `setCommits` is specified)
14464
- * 5. Finalize the release (unless `finalize` is disabled)
14465
- * 6. Add deploy information to the release (if `deploy` is specified)
14465
+ * 2. Upload sourcemaps based on `include` and source-map-specific options
14466
+ * 3. Associate a range of commits with the release (if `setCommits` is specified)
14467
+ * 4. Finalize the release (unless `finalize` is disabled)
14468
+ * 5. Add deploy information to the release (if `deploy` is specified)
14466
14469
  *
14467
14470
  * This release creation pipeline relies on Sentry CLI to execute the different steps.
14468
14471
  */
@@ -14474,7 +14477,7 @@ function sentryUnpluginFactory(_ref) {
14474
14477
  debugIdUploadPlugin = _ref.debugIdUploadPlugin,
14475
14478
  bundleSizeOptimizationsPlugin = _ref.bundleSizeOptimizationsPlugin;
14476
14479
  return unplugin.createUnplugin(function () {
14477
- var _userOptions$_metaOpt, _userOptions$_metaOpt2, _userOptions$silent, _userOptions$debug;
14480
+ var _userOptions$_metaOpt, _userOptions$_metaOpt2, _userOptions$silent, _userOptions$debug, _userOptions$_experim;
14478
14481
  var userOptions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
14479
14482
  var unpluginMetaContext = arguments.length > 1 ? arguments[1] : undefined;
14480
14483
  var logger = createLogger({
@@ -14495,6 +14498,11 @@ function sentryUnpluginFactory(_ref) {
14495
14498
  }
14496
14499
  }
14497
14500
  var options = normalizeUserOptions(userOptions);
14501
+
14502
+ // TODO(v3): Remove this warning
14503
+ if ((_userOptions$_experim = userOptions._experiments) !== null && _userOptions$_experim !== void 0 && _userOptions$_experim.moduleMetadata) {
14504
+ logger.warn("The `_experiments.moduleMetadata` option has been promoted to being stable. You can safely move the option out of the `_experiments` object scope.");
14505
+ }
14498
14506
  if (unpluginMetaContext.watchMode || options.disable) {
14499
14507
  return [{
14500
14508
  name: "sentry-noop-plugin"
@@ -14516,7 +14524,7 @@ function sentryUnpluginFactory(_ref) {
14516
14524
  });
14517
14525
 
14518
14526
  // Set the User-Agent that Sentry CLI will use when interacting with Sentry
14519
- process.env["SENTRY_PIPELINE"] = "".concat(unpluginMetaContext.framework, "-plugin/", "2.16.1");
14527
+ process.env["SENTRY_PIPELINE"] = "".concat(unpluginMetaContext.framework, "-plugin/", "2.18.0");
14520
14528
  function handleRecoverableError(unknownError) {
14521
14529
  sentrySession.status = "abnormal";
14522
14530
  try {
@@ -14588,24 +14596,31 @@ function sentryUnpluginFactory(_ref) {
14588
14596
  });
14589
14597
  plugins.push(releaseInjectionPlugin(_injectionCode));
14590
14598
  }
14591
- if (moduleMetadataInjectionPlugin && options._experiments.moduleMetadata) {
14592
- var metadata;
14593
- if (typeof options._experiments.moduleMetadata === "function") {
14599
+ if (options.moduleMetadata || options.applicationKey) {
14600
+ var metadata = {};
14601
+ if (options.applicationKey) {
14602
+ // We use different keys so that if user-code receives multiple bundling passes, we will store the application keys of all the passes.
14603
+ // It is a bit unfortunate that we have to inject the metadata snippet at the top, because after multiple
14604
+ // injections, the first injection will always "win" because it comes last in the code. We would generally be
14605
+ // fine with making the last bundling pass win. But because it cannot win, we have to use a workaround of storing
14606
+ // the app keys in different object keys.
14607
+ // We can simply use the `_sentryBundlerPluginAppKey:` to filter for app keys in the SDK.
14608
+ metadata["_sentryBundlerPluginAppKey:".concat(options.applicationKey)] = true;
14609
+ }
14610
+ if (typeof options.moduleMetadata === "function") {
14594
14611
  var args = {
14595
14612
  org: options.org,
14596
14613
  project: options.project,
14597
14614
  release: options.release.name
14598
14615
  };
14599
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
14600
- metadata = options._experiments.moduleMetadata(args);
14616
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
14617
+ metadata = _objectSpread2(_objectSpread2({}, metadata), options.moduleMetadata(args));
14601
14618
  } else {
14602
14619
  // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
14603
- metadata = options._experiments.moduleMetadata;
14620
+ metadata = _objectSpread2(_objectSpread2({}, metadata), options.moduleMetadata);
14604
14621
  }
14605
14622
  var _injectionCode2 = generateModuleMetadataInjectorCode(metadata);
14606
14623
  plugins.push(moduleMetadataInjectionPlugin(_injectionCode2));
14607
- } else if (options._experiments.moduleMetadata) {
14608
- logger.warn("'moduleMetadata' is currently only supported by '@sentry/webpack-plugin'");
14609
14624
  }
14610
14625
  if (!options.release.name) {
14611
14626
  logger.warn("No release name provided. Will not create release. Please set the `release.name` option to identify your release.");
@@ -14620,7 +14635,6 @@ function sentryUnpluginFactory(_ref) {
14620
14635
  logger: logger,
14621
14636
  releaseName: options.release.name,
14622
14637
  shouldCreateRelease: options.release.create,
14623
- shouldCleanArtifacts: options.release.cleanArtifacts,
14624
14638
  shouldFinalizeRelease: options.release.finalize,
14625
14639
  include: options.release.uploadLegacySourcemaps,
14626
14640
  setCommitsOption: options.release.setCommits,
@@ -14640,7 +14654,7 @@ function sentryUnpluginFactory(_ref) {
14640
14654
  }
14641
14655
  }));
14642
14656
  }
14643
- plugins.push(debugIdInjectionPlugin());
14657
+ plugins.push(debugIdInjectionPlugin(logger));
14644
14658
  if (!options.authToken) {
14645
14659
  logger.warn("No auth token provided. Will not upload source maps. Please set the `authToken` option. You can find information on how to generate a Sentry auth token here: https://docs.sentry.io/api/auth/");
14646
14660
  } else if (!options.org && !options.authToken.startsWith("sntrys_")) {