@sentry/bundler-plugin-core 2.17.0 → 2.19.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
@@ -612,30 +612,77 @@ function gitRevision() {
612
612
  * Tries to guess a release name based on environmental data.
613
613
  */
614
614
  function determineReleaseName() {
615
- return (
616
- // GitHub Actions - https://help.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables#default-environment-variables
617
- process.env["GITHUB_SHA"] ||
618
- // Netlify - https://docs.netlify.com/configure-builds/environment-variables/#build-metadata
619
- process.env["COMMIT_REF"] ||
620
- // Cloudflare Pages - https://developers.cloudflare.com/pages/platform/build-configuration/#environment-variables
621
- process.env["CF_PAGES_COMMIT_SHA"] ||
622
- // AWS CodeBuild - https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-env-vars.html
623
- process.env["CODEBUILD_RESOLVED_SOURCE_VERSION"] ||
624
- // Bitbucket - https://support.atlassian.com/bitbucket-cloud/docs/variables-and-secrets/
625
- process.env["BITBUCKET_COMMIT"] ||
626
- // CircleCI - https://circleci.com/docs/2.0/env-vars/
627
- process.env["CIRCLE_SHA1"] ||
628
- // Vercel - https://vercel.com/docs/v2/build-step#system-environment-variables
629
- process.env["VERCEL_GIT_COMMIT_SHA"] || process.env["VERCEL_GITHUB_COMMIT_SHA"] || process.env["VERCEL_GITLAB_COMMIT_SHA"] || process.env["VERCEL_BITBUCKET_COMMIT_SHA"] ||
630
- // Zeit (now known as Vercel)
631
- process.env["ZEIT_GITHUB_COMMIT_SHA"] || process.env["ZEIT_GITLAB_COMMIT_SHA"] || process.env["ZEIT_BITBUCKET_COMMIT_SHA"] ||
632
- // Flightcontrol - https://www.flightcontrol.dev/docs/guides/flightcontrol/environment-variables#built-in-environment-variables
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()
638
- );
615
+ // This list is in approximate alpha order, separated into 3 categories:
616
+ // 1. Git providers
617
+ // 2. CI providers with specific environment variables (has the provider name in the variable name)
618
+ // 3. CI providers with generic environment variables (checked for last to prevent possible false positives)
619
+
620
+ var possibleReleaseNameOfGitProvider =
621
+ // GitHub Actions - https://help.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables#default-environment-variables
622
+ process.env["GITHUB_SHA"] ||
623
+ // GitLab CI - https://docs.gitlab.com/ee/ci/variables/predefined_variables.html
624
+ process.env["CI_MERGE_REQUEST_SOURCE_BRANCH_SHA"] || process.env["CI_BUILD_REF"] || process.env["CI_COMMIT_SHA"] ||
625
+ // Bitbucket - https://support.atlassian.com/bitbucket-cloud/docs/variables-and-secrets/
626
+ process.env["BITBUCKET_COMMIT"];
627
+ var possibleReleaseNameOfCiProvidersWithSpecificEnvVar =
628
+ // AppVeyor - https://www.appveyor.com/docs/environment-variables/
629
+ process.env["APPVEYOR_PULL_REQUEST_HEAD_COMMIT"] || process.env["APPVEYOR_REPO_COMMIT"] ||
630
+ // AWS CodeBuild - https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-env-vars.html
631
+ process.env["CODEBUILD_RESOLVED_SOURCE_VERSION"] ||
632
+ // AWS Amplify - https://docs.aws.amazon.com/amplify/latest/userguide/environment-variables.html
633
+ process.env["AWS_COMMIT_ID"] ||
634
+ // Azure Pipelines - https://docs.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&tabs=yaml
635
+ process.env["BUILD_SOURCEVERSION"] ||
636
+ // Bitrise - https://devcenter.bitrise.io/builds/available-environment-variables/
637
+ process.env["GIT_CLONE_COMMIT_HASH"] ||
638
+ // Buddy CI - https://buddy.works/docs/pipelines/environment-variables#default-environment-variables
639
+ process.env["BUDDY_EXECUTION_REVISION"] ||
640
+ // Builtkite - https://buildkite.com/docs/pipelines/environment-variables
641
+ process.env["BUILDKITE_COMMIT"] ||
642
+ // CircleCI - https://circleci.com/docs/variables/
643
+ process.env["CIRCLE_SHA1"] ||
644
+ // Cirrus CI - https://cirrus-ci.org/guide/writing-tasks/#environment-variables
645
+ process.env["CIRRUS_CHANGE_IN_REPO"] ||
646
+ // Codefresh - https://codefresh.io/docs/docs/codefresh-yaml/variables/
647
+ process.env["CF_REVISION"] ||
648
+ // Codemagic - https://docs.codemagic.io/yaml-basic-configuration/environment-variables/
649
+ process.env["CM_COMMIT"] ||
650
+ // Cloudflare Pages - https://developers.cloudflare.com/pages/platform/build-configuration/#environment-variables
651
+ process.env["CF_PAGES_COMMIT_SHA"] ||
652
+ // Drone - https://docs.drone.io/pipeline/environment/reference/
653
+ process.env["DRONE_COMMIT_SHA"] ||
654
+ // Flightcontrol - https://www.flightcontrol.dev/docs/guides/flightcontrol/environment-variables#built-in-environment-variables
655
+ process.env["FC_GIT_COMMIT_SHA"] ||
656
+ // Heroku #1 https://devcenter.heroku.com/articles/heroku-ci
657
+ process.env["HEROKU_TEST_RUN_COMMIT_VERSION"] ||
658
+ // Heroku #2 https://docs.sentry.io/product/integrations/deployment/heroku/#configure-releases
659
+ process.env["HEROKU_SLUG_COMMIT"] ||
660
+ // Render - https://render.com/docs/environment-variables
661
+ process.env["RENDER_GIT_COMMIT"] ||
662
+ // Semaphore CI - https://docs.semaphoreci.com/ci-cd-environment/environment-variables
663
+ process.env["SEMAPHORE_GIT_SHA"] ||
664
+ // TravisCI - https://docs.travis-ci.com/user/environment-variables/#default-environment-variables
665
+ process.env["TRAVIS_PULL_REQUEST_SHA"] ||
666
+ // Vercel - https://vercel.com/docs/v2/build-step#system-environment-variables
667
+ process.env["VERCEL_GIT_COMMIT_SHA"] || process.env["VERCEL_GITHUB_COMMIT_SHA"] || process.env["VERCEL_GITLAB_COMMIT_SHA"] || process.env["VERCEL_BITBUCKET_COMMIT_SHA"] ||
668
+ // Zeit (now known as Vercel)
669
+ process.env["ZEIT_GITHUB_COMMIT_SHA"] || process.env["ZEIT_GITLAB_COMMIT_SHA"] || process.env["ZEIT_BITBUCKET_COMMIT_SHA"];
670
+ var possibleReleaseNameOfCiProvidersWithGenericEnvVar =
671
+ // CloudBees CodeShip - https://docs.cloudbees.com/docs/cloudbees-codeship/latest/pro-builds-and-configuration/environment-variables
672
+ process.env["CI_COMMIT_ID"] ||
673
+ // Coolify - https://coolify.io/docs/knowledge-base/environment-variables
674
+ process.env["SOURCE_COMMIT"] ||
675
+ // Heroku #3 https://devcenter.heroku.com/changelog-items/630
676
+ process.env["SOURCE_VERSION"] ||
677
+ // Jenkins - https://plugins.jenkins.io/git/#environment-variables
678
+ process.env["GIT_COMMIT"] ||
679
+ // Netlify - https://docs.netlify.com/configure-builds/environment-variables/#build-metadata
680
+ process.env["COMMIT_REF"] ||
681
+ // TeamCity - https://www.jetbrains.com/help/teamcity/predefined-build-parameters.html
682
+ process.env["BUILD_VCS_NUMBER"] ||
683
+ // Woodpecker CI - https://woodpecker-ci.org/docs/usage/environment
684
+ process.env["CI_COMMIT_SHA"];
685
+ return possibleReleaseNameOfGitProvider || possibleReleaseNameOfCiProvidersWithSpecificEnvVar || possibleReleaseNameOfCiProvidersWithGenericEnvVar || gitRevision();
639
686
  }
640
687
 
641
688
  /**
@@ -659,7 +706,8 @@ function generateGlobalInjectorCode(_ref2) {
659
706
  function generateModuleMetadataInjectorCode(metadata) {
660
707
  // The code below is mostly ternary operators because it saves bundle size.
661
708
  // The checks are to support as many environments as possible. (Node.js, Browser, webworkers, etc.)
662
- 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), ";");
709
+ // We are merging the metadata objects in case modules are bundled twice with the plugin
710
+ 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}");
663
711
  }
664
712
  function getBuildInformation$1() {
665
713
  var packageJson = getPackageJson();
@@ -700,7 +748,7 @@ function replaceBooleanFlagsInCode(code, replacementValues) {
700
748
 
701
749
  var SENTRY_SAAS_URL = "https://sentry.io";
702
750
  function normalizeUserOptions(userOptions) {
703
- 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$_experim;
751
+ 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;
704
752
  var options = {
705
753
  org: (_userOptions$org = userOptions.org) !== null && _userOptions$org !== void 0 ? _userOptions$org : process.env["SENTRY_ORG"],
706
754
  project: (_userOptions$project = userOptions.project) !== null && _userOptions$project !== void 0 ? _userOptions$project : process.env["SENTRY_PROJECT"],
@@ -722,7 +770,14 @@ function normalizeUserOptions(userOptions) {
722
770
  }),
723
771
  bundleSizeOptimizations: userOptions.bundleSizeOptimizations,
724
772
  reactComponentAnnotation: userOptions.reactComponentAnnotation,
725
- _experiments: (_userOptions$_experim = userOptions._experiments) !== null && _userOptions$_experim !== void 0 ? _userOptions$_experim : {}
773
+ _metaOptions: {
774
+ telemetry: {
775
+ 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
776
+ }
777
+ },
778
+ applicationKey: userOptions.applicationKey,
779
+ moduleMetadata: userOptions.moduleMetadata || ((_userOptions$_experim = userOptions._experiments) === null || _userOptions$_experim === void 0 ? void 0 : _userOptions$_experim.moduleMetadata),
780
+ _experiments: (_userOptions$_experim2 = userOptions._experiments) !== null && _userOptions$_experim2 !== void 0 ? _userOptions$_experim2 : {}
726
781
  };
727
782
  return options;
728
783
  }
@@ -13604,7 +13659,7 @@ function createSentryInstance(options, shouldSendTelemetry, bundler) {
13604
13659
  dsn: "https://4c2bae7d9fbc413e8f7385f55c515d51@o1.ingest.sentry.io/6690737",
13605
13660
  tracesSampleRate: 1,
13606
13661
  sampleRate: 1,
13607
- release: "2.17.0",
13662
+ release: "2.19.0",
13608
13663
  integrations: [],
13609
13664
  tracePropagationTargets: ["sentry.io/api"],
13610
13665
  stackParser: defaultStackParser,
@@ -13665,6 +13720,7 @@ function createSentryInstance(options, shouldSendTelemetry, bundler) {
13665
13720
  };
13666
13721
  }
13667
13722
  function setTelemetryDataOnHub(options, hub, bundler) {
13723
+ var _options$_metaOptions;
13668
13724
  var org = options.org,
13669
13725
  project = options.project,
13670
13726
  release = options.release,
@@ -13675,7 +13731,7 @@ function setTelemetryDataOnHub(options, hub, bundler) {
13675
13731
  if (release.uploadLegacySourcemaps) {
13676
13732
  hub.setTag("uploadLegacySourcemapsEntries", Array.isArray(release.uploadLegacySourcemaps) ? release.uploadLegacySourcemaps.length : 1);
13677
13733
  }
13678
- hub.setTag("module-metadata", !!options._experiments.moduleMetadata);
13734
+ hub.setTag("module-metadata", !!options.moduleMetadata);
13679
13735
  hub.setTag("inject-build-information", !!options._experiments.injectBuildInformation);
13680
13736
 
13681
13737
  // Optional release pipeline steps
@@ -13694,6 +13750,7 @@ function setTelemetryDataOnHub(options, hub, bundler) {
13694
13750
  hub.setTag("react-annotate", !!(reactComponentAnnotation !== null && reactComponentAnnotation !== void 0 && reactComponentAnnotation.enabled));
13695
13751
  hub.setTag("node", process.version);
13696
13752
  hub.setTag("platform", process.platform);
13753
+ hub.setTag("meta-framework", (_options$_metaOptions = options._metaOptions.telemetry.metaFramework) !== null && _options$_metaOptions !== void 0 ? _options$_metaOptions : "none");
13697
13754
  hub.setTags({
13698
13755
  organization: org,
13699
13756
  project: project,
@@ -13804,10 +13861,10 @@ function createDebugIdUploadFunction(_ref) {
13804
13861
  sentryClient = _ref.sentryClient,
13805
13862
  sentryCliOptions = _ref.sentryCliOptions,
13806
13863
  rewriteSourcesHook = _ref.rewriteSourcesHook,
13807
- filesToDeleteAfterUpload = _ref.filesToDeleteAfterUpload;
13864
+ deleteFilesUpForDeletion = _ref.deleteFilesUpForDeletion;
13808
13865
  return /*#__PURE__*/function () {
13809
13866
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(buildArtifactPaths) {
13810
- var artifactBundleUploadTransaction, folderToCleanUp, mkdtempSpan, tmpUploadFolder, globAssets, globSpan, globResult, debugIdChunkFilePaths, prepareSpan, preparationTasks, workers, worker, workerIndex, files, stats, uploadSize, uploadSpan, cliInstance, deleteGlobSpan, filePathsToDelete, deleteSpan, cleanupSpan;
13867
+ var artifactBundleUploadTransaction, folderToCleanUp, mkdtempSpan, tmpUploadFolder, globAssets, globSpan, globResult, debugIdChunkFilePaths, prepareSpan, preparationTasks, workers, worker, workerIndex, files, stats, uploadSize, uploadSpan, cliInstance, cleanupSpan;
13811
13868
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
13812
13869
  while (1) switch (_context3.prev = _context3.next) {
13813
13870
  case 0:
@@ -13960,51 +14017,21 @@ function createDebugIdUploadFunction(_ref) {
13960
14017
  uploadSpan.finish();
13961
14018
  logger.info("Successfully uploaded source maps to Sentry");
13962
14019
  case 47:
13963
- if (!filesToDeleteAfterUpload) {
13964
- _context3.next = 58;
13965
- break;
13966
- }
13967
- deleteGlobSpan = artifactBundleUploadTransaction.startChild({
13968
- description: "delete-glob"
13969
- });
13970
- _context3.next = 51;
13971
- return glob.glob(filesToDeleteAfterUpload, {
13972
- absolute: true,
13973
- nodir: true
13974
- });
13975
- case 51:
13976
- filePathsToDelete = _context3.sent;
13977
- deleteGlobSpan.finish();
13978
- filePathsToDelete.forEach(function (filePathToDelete) {
13979
- logger.debug("Deleting asset after upload: ".concat(filePathToDelete));
13980
- });
13981
- deleteSpan = artifactBundleUploadTransaction.startChild({
13982
- description: "delete-files-after-upload"
13983
- });
13984
- _context3.next = 57;
13985
- return Promise.all(filePathsToDelete.map(function (filePathToDelete) {
13986
- return fs__default["default"].promises.rm(filePathToDelete, {
13987
- force: true
13988
- })["catch"](function (e) {
13989
- // This is allowed to fail - we just don't do anything
13990
- logger.debug("An error occured while attempting to delete asset: ".concat(filePathToDelete), e);
13991
- });
13992
- }));
13993
- case 57:
13994
- deleteSpan.finish();
13995
- case 58:
13996
- _context3.next = 64;
14020
+ _context3.next = 49;
14021
+ return deleteFilesUpForDeletion();
14022
+ case 49:
14023
+ _context3.next = 55;
13997
14024
  break;
13998
- case 60:
13999
- _context3.prev = 60;
14025
+ case 51:
14026
+ _context3.prev = 51;
14000
14027
  _context3.t0 = _context3["catch"](1);
14001
14028
  sentryHub.withScope(function (scope) {
14002
14029
  scope.setSpan(artifactBundleUploadTransaction);
14003
14030
  sentryHub.captureException('Error in "debugIdUploadPlugin" writeBundle hook');
14004
14031
  });
14005
14032
  handleRecoverableError(_context3.t0);
14006
- case 64:
14007
- _context3.prev = 64;
14033
+ case 55:
14034
+ _context3.prev = 55;
14008
14035
  if (folderToCleanUp) {
14009
14036
  cleanupSpan = artifactBundleUploadTransaction.startChild({
14010
14037
  description: "cleanup"
@@ -14016,15 +14043,15 @@ function createDebugIdUploadFunction(_ref) {
14016
14043
  cleanupSpan.finish();
14017
14044
  }
14018
14045
  artifactBundleUploadTransaction.finish();
14019
- _context3.next = 69;
14046
+ _context3.next = 60;
14020
14047
  return safeFlushTelemetry(sentryClient);
14021
- case 69:
14022
- return _context3.finish(64);
14023
- case 70:
14048
+ case 60:
14049
+ return _context3.finish(55);
14050
+ case 61:
14024
14051
  case "end":
14025
14052
  return _context3.stop();
14026
14053
  }
14027
- }, _callee3, null, [[1, 60, 64, 70]]);
14054
+ }, _callee3, null, [[1, 51, 55, 61]]);
14028
14055
  }));
14029
14056
  return function (_x) {
14030
14057
  return _ref2.apply(this, arguments);
@@ -14270,7 +14297,8 @@ function releaseManagementPlugin(_ref) {
14270
14297
  handleRecoverableError = _ref.handleRecoverableError,
14271
14298
  sentryHub = _ref.sentryHub,
14272
14299
  sentryClient = _ref.sentryClient,
14273
- sentryCliOptions = _ref.sentryCliOptions;
14300
+ sentryCliOptions = _ref.sentryCliOptions,
14301
+ deleteFilesUpForDeletion = _ref.deleteFilesUpForDeletion;
14274
14302
  return {
14275
14303
  name: "sentry-debug-id-upload-plugin",
14276
14304
  writeBundle: function writeBundle() {
@@ -14333,21 +14361,24 @@ function releaseManagementPlugin(_ref) {
14333
14361
  _context.next = 18;
14334
14362
  return cliInstance.releases.newDeploy(releaseName, deployOptions);
14335
14363
  case 18:
14336
- _context.next = 26;
14337
- break;
14364
+ _context.next = 20;
14365
+ return deleteFilesUpForDeletion();
14338
14366
  case 20:
14339
- _context.prev = 20;
14367
+ _context.next = 28;
14368
+ break;
14369
+ case 22:
14370
+ _context.prev = 22;
14340
14371
  _context.t0 = _context["catch"](0);
14341
14372
  sentryHub.captureException('Error in "releaseManagementPlugin" writeBundle hook');
14342
- _context.next = 25;
14373
+ _context.next = 27;
14343
14374
  return safeFlushTelemetry(sentryClient);
14344
- case 25:
14375
+ case 27:
14345
14376
  handleRecoverableError(_context.t0);
14346
- case 26:
14377
+ case 28:
14347
14378
  case "end":
14348
14379
  return _context.stop();
14349
14380
  }
14350
- }, _callee, null, [[0, 20]]);
14381
+ }, _callee, null, [[0, 22]]);
14351
14382
  }))();
14352
14383
  }
14353
14384
  };
@@ -14372,7 +14403,7 @@ function telemetryPlugin(_ref) {
14372
14403
  _context.next = 7;
14373
14404
  break;
14374
14405
  }
14375
- logger.info("Sending error and performance telemetry data to Sentry. To disable telemetry, set `options.telemetry` to `false`.");
14406
+ logger.info("Sending telemetry data on issues and performance to Sentry. To disable telemetry, set `options.telemetry` to `false`.");
14376
14407
  sentryHub.startTransaction({
14377
14408
  name: "Sentry Bundler Plugin execution"
14378
14409
  }).finish();
@@ -14433,6 +14464,42 @@ function createLogger(options) {
14433
14464
  };
14434
14465
  }
14435
14466
 
14467
+ function fileDeletionPlugin(_ref) {
14468
+ var handleRecoverableError = _ref.handleRecoverableError,
14469
+ sentryHub = _ref.sentryHub,
14470
+ sentryClient = _ref.sentryClient,
14471
+ deleteFilesUpForDeletion = _ref.deleteFilesUpForDeletion;
14472
+ return {
14473
+ name: "sentry-file-deletion-plugin",
14474
+ writeBundle: function writeBundle() {
14475
+ return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
14476
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
14477
+ while (1) switch (_context.prev = _context.next) {
14478
+ case 0:
14479
+ _context.prev = 0;
14480
+ _context.next = 3;
14481
+ return deleteFilesUpForDeletion();
14482
+ case 3:
14483
+ _context.next = 11;
14484
+ break;
14485
+ case 5:
14486
+ _context.prev = 5;
14487
+ _context.t0 = _context["catch"](0);
14488
+ sentryHub.captureException('Error in "sentry-file-deletion-plugin" buildEnd hook');
14489
+ _context.next = 10;
14490
+ return safeFlushTelemetry(sentryClient);
14491
+ case 10:
14492
+ handleRecoverableError(_context.t0);
14493
+ case 11:
14494
+ case "end":
14495
+ return _context.stop();
14496
+ }
14497
+ }, _callee, null, [[0, 5]]);
14498
+ }))();
14499
+ }
14500
+ };
14501
+ }
14502
+
14436
14503
  /**
14437
14504
  * The sentry bundler plugin concerns itself with two things:
14438
14505
  * - Release injection
@@ -14467,7 +14534,7 @@ function sentryUnpluginFactory(_ref) {
14467
14534
  debugIdUploadPlugin = _ref.debugIdUploadPlugin,
14468
14535
  bundleSizeOptimizationsPlugin = _ref.bundleSizeOptimizationsPlugin;
14469
14536
  return unplugin.createUnplugin(function () {
14470
- var _userOptions$_metaOpt, _userOptions$_metaOpt2, _userOptions$silent, _userOptions$debug;
14537
+ var _userOptions$_metaOpt, _userOptions$_metaOpt2, _userOptions$silent, _userOptions$debug, _userOptions$_experim;
14471
14538
  var userOptions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
14472
14539
  var unpluginMetaContext = arguments.length > 1 ? arguments[1] : undefined;
14473
14540
  var logger = createLogger({
@@ -14479,7 +14546,10 @@ function sentryUnpluginFactory(_ref) {
14479
14546
  var dotenvFile = fs__namespace.readFileSync(path__namespace.join(process.cwd(), ".env.sentry-build-plugin"), "utf-8");
14480
14547
  // NOTE: Do not use the dotenv.config API directly to read the dotenv file! For some ungodly reason, it falls back to reading `${process.cwd()}/.env` which is absolutely not what we want.
14481
14548
  var dotenvResult = dotenv__namespace.parse(dotenvFile);
14482
- process.env = _objectSpread2(_objectSpread2({}, process.env), dotenvResult);
14549
+
14550
+ // Vite has a bug/behaviour where spreading into process.env will cause it to crash
14551
+ // https://github.com/vitest-dev/vitest/issues/1870#issuecomment-1501140251
14552
+ Object.assign(process.env, dotenvResult);
14483
14553
  logger.info('Using environment variables configured in ".env.sentry-build-plugin".');
14484
14554
  } catch (e) {
14485
14555
  // Ignore "file not found" errors but throw all others
@@ -14488,6 +14558,11 @@ function sentryUnpluginFactory(_ref) {
14488
14558
  }
14489
14559
  }
14490
14560
  var options = normalizeUserOptions(userOptions);
14561
+
14562
+ // TODO(v3): Remove this warning
14563
+ if ((_userOptions$_experim = userOptions._experiments) !== null && _userOptions$_experim !== void 0 && _userOptions$_experim.moduleMetadata) {
14564
+ logger.warn("The `_experiments.moduleMetadata` option has been promoted to being stable. You can safely move the option out of the `_experiments` object scope.");
14565
+ }
14491
14566
  if (unpluginMetaContext.watchMode || options.disable) {
14492
14567
  return [{
14493
14568
  name: "sentry-noop-plugin"
@@ -14509,7 +14584,7 @@ function sentryUnpluginFactory(_ref) {
14509
14584
  });
14510
14585
 
14511
14586
  // Set the User-Agent that Sentry CLI will use when interacting with Sentry
14512
- process.env["SENTRY_PIPELINE"] = "".concat(unpluginMetaContext.framework, "-plugin/", "2.17.0");
14587
+ process.env["SENTRY_PIPELINE"] = "".concat(unpluginMetaContext.framework, "-plugin/", "2.19.0");
14513
14588
  function handleRecoverableError(unknownError) {
14514
14589
  sentrySession.status = "abnormal";
14515
14590
  try {
@@ -14545,6 +14620,48 @@ function sentryUnpluginFactory(_ref) {
14545
14620
  logger: logger,
14546
14621
  shouldSendTelemetry: shouldSendTelemetry
14547
14622
  }));
14623
+ function deleteFilesUpForDeletion() {
14624
+ return _deleteFilesUpForDeletion.apply(this, arguments);
14625
+ }
14626
+ function _deleteFilesUpForDeletion() {
14627
+ _deleteFilesUpForDeletion = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
14628
+ var _options$sourcemaps$f, _options$sourcemaps4, _options$sourcemaps5;
14629
+ var filesToDeleteAfterUpload, filePathsToDelete;
14630
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
14631
+ while (1) switch (_context.prev = _context.next) {
14632
+ case 0:
14633
+ filesToDeleteAfterUpload = (_options$sourcemaps$f = (_options$sourcemaps4 = options.sourcemaps) === null || _options$sourcemaps4 === void 0 ? void 0 : _options$sourcemaps4.filesToDeleteAfterUpload) !== null && _options$sourcemaps$f !== void 0 ? _options$sourcemaps$f : (_options$sourcemaps5 = options.sourcemaps) === null || _options$sourcemaps5 === void 0 ? void 0 : _options$sourcemaps5.deleteFilesAfterUpload;
14634
+ if (!filesToDeleteAfterUpload) {
14635
+ _context.next = 8;
14636
+ break;
14637
+ }
14638
+ _context.next = 4;
14639
+ return glob.glob(filesToDeleteAfterUpload, {
14640
+ absolute: true,
14641
+ nodir: true
14642
+ });
14643
+ case 4:
14644
+ filePathsToDelete = _context.sent;
14645
+ filePathsToDelete.forEach(function (filePathToDelete) {
14646
+ logger.debug("Deleting asset after upload: ".concat(filePathToDelete));
14647
+ });
14648
+ _context.next = 8;
14649
+ return Promise.all(filePathsToDelete.map(function (filePathToDelete) {
14650
+ return fs__namespace.promises.rm(filePathToDelete, {
14651
+ force: true
14652
+ })["catch"](function (e) {
14653
+ // This is allowed to fail - we just don't do anything
14654
+ logger.debug("An error occurred while attempting to delete asset: ".concat(filePathToDelete), e);
14655
+ });
14656
+ }));
14657
+ case 8:
14658
+ case "end":
14659
+ return _context.stop();
14660
+ }
14661
+ }, _callee);
14662
+ }));
14663
+ return _deleteFilesUpForDeletion.apply(this, arguments);
14664
+ }
14548
14665
  if (options.bundleSizeOptimizations) {
14549
14666
  var bundleSizeOptimizations = options.bundleSizeOptimizations;
14550
14667
  var replacementValues = {};
@@ -14581,24 +14698,31 @@ function sentryUnpluginFactory(_ref) {
14581
14698
  });
14582
14699
  plugins.push(releaseInjectionPlugin(_injectionCode));
14583
14700
  }
14584
- if (moduleMetadataInjectionPlugin && options._experiments.moduleMetadata) {
14585
- var metadata;
14586
- if (typeof options._experiments.moduleMetadata === "function") {
14701
+ if (options.moduleMetadata || options.applicationKey) {
14702
+ var metadata = {};
14703
+ if (options.applicationKey) {
14704
+ // We use different keys so that if user-code receives multiple bundling passes, we will store the application keys of all the passes.
14705
+ // It is a bit unfortunate that we have to inject the metadata snippet at the top, because after multiple
14706
+ // injections, the first injection will always "win" because it comes last in the code. We would generally be
14707
+ // fine with making the last bundling pass win. But because it cannot win, we have to use a workaround of storing
14708
+ // the app keys in different object keys.
14709
+ // We can simply use the `_sentryBundlerPluginAppKey:` to filter for app keys in the SDK.
14710
+ metadata["_sentryBundlerPluginAppKey:".concat(options.applicationKey)] = true;
14711
+ }
14712
+ if (typeof options.moduleMetadata === "function") {
14587
14713
  var args = {
14588
14714
  org: options.org,
14589
14715
  project: options.project,
14590
14716
  release: options.release.name
14591
14717
  };
14592
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
14593
- metadata = options._experiments.moduleMetadata(args);
14718
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
14719
+ metadata = _objectSpread2(_objectSpread2({}, metadata), options.moduleMetadata(args));
14594
14720
  } else {
14595
14721
  // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
14596
- metadata = options._experiments.moduleMetadata;
14722
+ metadata = _objectSpread2(_objectSpread2({}, metadata), options.moduleMetadata);
14597
14723
  }
14598
14724
  var _injectionCode2 = generateModuleMetadataInjectorCode(metadata);
14599
14725
  plugins.push(moduleMetadataInjectionPlugin(_injectionCode2));
14600
- } else if (options._experiments.moduleMetadata) {
14601
- logger.warn("'moduleMetadata' is currently only supported by '@sentry/webpack-plugin'");
14602
14726
  }
14603
14727
  if (!options.release.name) {
14604
14728
  logger.warn("No release name provided. Will not create release. Please set the `release.name` option to identify your release.");
@@ -14629,10 +14753,17 @@ function sentryUnpluginFactory(_ref) {
14629
14753
  url: options.url,
14630
14754
  vcsRemote: options.release.vcsRemote,
14631
14755
  headers: options.headers
14632
- }
14756
+ },
14757
+ deleteFilesUpForDeletion: deleteFilesUpForDeletion
14633
14758
  }));
14634
14759
  }
14635
14760
  plugins.push(debugIdInjectionPlugin(logger));
14761
+ plugins.push(fileDeletionPlugin({
14762
+ deleteFilesUpForDeletion: deleteFilesUpForDeletion,
14763
+ handleRecoverableError: handleRecoverableError,
14764
+ sentryHub: sentryHub,
14765
+ sentryClient: sentryClient
14766
+ }));
14636
14767
  if (!options.authToken) {
14637
14768
  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/");
14638
14769
  } else if (!options.org && !options.authToken.startsWith("sntrys_")) {
@@ -14640,16 +14771,16 @@ function sentryUnpluginFactory(_ref) {
14640
14771
  } else if (!options.project) {
14641
14772
  logger.warn("No project provided. Will not upload source maps. Please set the `project` option to your Sentry project slug.");
14642
14773
  } else {
14643
- var _options$sourcemaps, _options$sourcemaps2, _options$sourcemaps$f, _options$sourcemaps3, _options$sourcemaps4, _options$sourcemaps5;
14774
+ var _options$sourcemaps, _options$sourcemaps2, _options$sourcemaps3;
14644
14775
  plugins.push(debugIdUploadPlugin(createDebugIdUploadFunction({
14645
14776
  assets: (_options$sourcemaps = options.sourcemaps) === null || _options$sourcemaps === void 0 ? void 0 : _options$sourcemaps.assets,
14646
14777
  ignore: (_options$sourcemaps2 = options.sourcemaps) === null || _options$sourcemaps2 === void 0 ? void 0 : _options$sourcemaps2.ignore,
14647
- filesToDeleteAfterUpload: (_options$sourcemaps$f = (_options$sourcemaps3 = options.sourcemaps) === null || _options$sourcemaps3 === void 0 ? void 0 : _options$sourcemaps3.filesToDeleteAfterUpload) !== null && _options$sourcemaps$f !== void 0 ? _options$sourcemaps$f : (_options$sourcemaps4 = options.sourcemaps) === null || _options$sourcemaps4 === void 0 ? void 0 : _options$sourcemaps4.deleteFilesAfterUpload,
14778
+ deleteFilesUpForDeletion: deleteFilesUpForDeletion,
14648
14779
  dist: options.release.dist,
14649
14780
  releaseName: options.release.name,
14650
14781
  logger: logger,
14651
14782
  handleRecoverableError: handleRecoverableError,
14652
- rewriteSourcesHook: (_options$sourcemaps5 = options.sourcemaps) === null || _options$sourcemaps5 === void 0 ? void 0 : _options$sourcemaps5.rewriteSources,
14783
+ rewriteSourcesHook: (_options$sourcemaps3 = options.sourcemaps) === null || _options$sourcemaps3 === void 0 ? void 0 : _options$sourcemaps3.rewriteSources,
14653
14784
  sentryHub: sentryHub,
14654
14785
  sentryClient: sentryClient,
14655
14786
  sentryCliOptions: {
@@ -14836,50 +14967,50 @@ function createRollupModuleMetadataInjectionHooks(injectionCode) {
14836
14967
  function createRollupDebugIdUploadHooks(upload) {
14837
14968
  return {
14838
14969
  writeBundle: function writeBundle(outputOptions, bundle) {
14839
- return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
14970
+ return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
14840
14971
  var outputDir, _buildArtifacts, _buildArtifacts2;
14841
- return _regeneratorRuntime().wrap(function _callee$(_context) {
14842
- while (1) switch (_context.prev = _context.next) {
14972
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
14973
+ while (1) switch (_context2.prev = _context2.next) {
14843
14974
  case 0:
14844
14975
  if (!outputOptions.dir) {
14845
- _context.next = 9;
14976
+ _context2.next = 9;
14846
14977
  break;
14847
14978
  }
14848
14979
  outputDir = outputOptions.dir;
14849
- _context.next = 4;
14980
+ _context2.next = 4;
14850
14981
  return glob.glob(["/**/*.js", "/**/*.mjs", "/**/*.cjs", "/**/*.js.map", "/**/*.mjs.map", "/**/*.cjs.map"], {
14851
14982
  root: outputDir,
14852
14983
  absolute: true,
14853
14984
  nodir: true
14854
14985
  });
14855
14986
  case 4:
14856
- _buildArtifacts = _context.sent;
14857
- _context.next = 7;
14987
+ _buildArtifacts = _context2.sent;
14988
+ _context2.next = 7;
14858
14989
  return upload(_buildArtifacts);
14859
14990
  case 7:
14860
- _context.next = 17;
14991
+ _context2.next = 17;
14861
14992
  break;
14862
14993
  case 9:
14863
14994
  if (!outputOptions.file) {
14864
- _context.next = 14;
14995
+ _context2.next = 14;
14865
14996
  break;
14866
14997
  }
14867
- _context.next = 12;
14998
+ _context2.next = 12;
14868
14999
  return upload([outputOptions.file]);
14869
15000
  case 12:
14870
- _context.next = 17;
15001
+ _context2.next = 17;
14871
15002
  break;
14872
15003
  case 14:
14873
15004
  _buildArtifacts2 = Object.keys(bundle).map(function (asset) {
14874
15005
  return path__namespace.join(path__namespace.resolve(), asset);
14875
15006
  });
14876
- _context.next = 17;
15007
+ _context2.next = 17;
14877
15008
  return upload(_buildArtifacts2);
14878
15009
  case 17:
14879
15010
  case "end":
14880
- return _context.stop();
15011
+ return _context2.stop();
14881
15012
  }
14882
- }, _callee);
15013
+ }, _callee2);
14883
15014
  }))();
14884
15015
  }
14885
15016
  };
@@ -14887,26 +15018,26 @@ function createRollupDebugIdUploadHooks(upload) {
14887
15018
  function createComponentNameAnnotateHooks() {
14888
15019
  return {
14889
15020
  transform: function transform(code, id) {
14890
- return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
15021
+ return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
14891
15022
  var idWithoutQueryAndHash, parserPlugins, _result$code, result;
14892
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
14893
- while (1) switch (_context2.prev = _context2.next) {
15023
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
15024
+ while (1) switch (_context3.prev = _context3.next) {
14894
15025
  case 0:
14895
15026
  // id may contain query and hash which will trip up our file extension logic below
14896
15027
  idWithoutQueryAndHash = stripQueryAndHashFromPath(id);
14897
15028
  if (!idWithoutQueryAndHash.match(/\\node_modules\\|\/node_modules\//)) {
14898
- _context2.next = 3;
15029
+ _context3.next = 3;
14899
15030
  break;
14900
15031
  }
14901
- return _context2.abrupt("return", null);
15032
+ return _context3.abrupt("return", null);
14902
15033
  case 3:
14903
15034
  if ([".jsx", ".tsx"].some(function (ending) {
14904
15035
  return idWithoutQueryAndHash.endsWith(ending);
14905
15036
  })) {
14906
- _context2.next = 5;
15037
+ _context3.next = 5;
14907
15038
  break;
14908
15039
  }
14909
- return _context2.abrupt("return", null);
15040
+ return _context3.abrupt("return", null);
14910
15041
  case 5:
14911
15042
  parserPlugins = [];
14912
15043
  if (idWithoutQueryAndHash.endsWith(".jsx")) {
@@ -14914,8 +15045,8 @@ function createComponentNameAnnotateHooks() {
14914
15045
  } else if (idWithoutQueryAndHash.endsWith(".tsx")) {
14915
15046
  parserPlugins.push("jsx", "typescript");
14916
15047
  }
14917
- _context2.prev = 7;
14918
- _context2.next = 10;
15048
+ _context3.prev = 7;
15049
+ _context3.next = 10;
14919
15050
  return core.transformAsync(code, {
14920
15051
  plugins: [[componentNameAnnotatePlugin__default["default"]]],
14921
15052
  filename: id,
@@ -14930,24 +15061,24 @@ function createComponentNameAnnotateHooks() {
14930
15061
  sourceMaps: true
14931
15062
  });
14932
15063
  case 10:
14933
- result = _context2.sent;
14934
- return _context2.abrupt("return", {
15064
+ result = _context3.sent;
15065
+ return _context3.abrupt("return", {
14935
15066
  code: (_result$code = result === null || result === void 0 ? void 0 : result.code) !== null && _result$code !== void 0 ? _result$code : code,
14936
15067
  map: result === null || result === void 0 ? void 0 : result.map
14937
15068
  });
14938
15069
  case 14:
14939
- _context2.prev = 14;
14940
- _context2.t0 = _context2["catch"](7);
14941
- logger.error("Failed to apply react annotate plugin", _context2.t0);
15070
+ _context3.prev = 14;
15071
+ _context3.t0 = _context3["catch"](7);
15072
+ logger.error("Failed to apply react annotate plugin", _context3.t0);
14942
15073
  case 17:
14943
- return _context2.abrupt("return", {
15074
+ return _context3.abrupt("return", {
14944
15075
  code: code
14945
15076
  });
14946
15077
  case 18:
14947
15078
  case "end":
14948
- return _context2.stop();
15079
+ return _context3.stop();
14949
15080
  }
14950
- }, _callee2, null, [[7, 14]]);
15081
+ }, _callee3, null, [[7, 14]]);
14951
15082
  }))();
14952
15083
  }
14953
15084
  };