@sentry/bundler-plugin-core 2.0.0-alpha.6 → 2.0.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
@@ -6,13 +6,13 @@ var SentryCli = require('@sentry/cli');
6
6
  var fs = require('fs');
7
7
  var MagicString = require('magic-string');
8
8
  var unplugin = require('unplugin');
9
- var findUp = require('find-up');
10
- var path = require('path');
9
+ var glob = require('glob');
11
10
  var os = require('os');
11
+ var path = require('path');
12
+ var util = require('util');
13
+ var findUp = require('find-up');
12
14
  var crypto = require('crypto');
13
15
  var childProcess = require('child_process');
14
- var glob = require('glob');
15
- var util = require('util');
16
16
  var node = require('@sentry/node');
17
17
 
18
18
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
@@ -38,12 +38,12 @@ function _interopNamespace(e) {
38
38
  var SentryCli__default = /*#__PURE__*/_interopDefaultLegacy(SentryCli);
39
39
  var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
40
40
  var MagicString__default = /*#__PURE__*/_interopDefaultLegacy(MagicString);
41
- var findUp__default = /*#__PURE__*/_interopDefaultLegacy(findUp);
42
- var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
43
41
  var os__default = /*#__PURE__*/_interopDefaultLegacy(os);
42
+ var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
43
+ var util__namespace = /*#__PURE__*/_interopNamespace(util);
44
+ var findUp__default = /*#__PURE__*/_interopDefaultLegacy(findUp);
44
45
  var crypto__default = /*#__PURE__*/_interopDefaultLegacy(crypto);
45
46
  var childProcess__default = /*#__PURE__*/_interopDefaultLegacy(childProcess);
46
- var util__namespace = /*#__PURE__*/_interopNamespace(util);
47
47
 
48
48
  function ownKeys(object, enumerableOnly) {
49
49
  var keys = Object.keys(object);
@@ -467,220 +467,9 @@ function _defineProperty(obj, key, value) {
467
467
  return obj;
468
468
  }
469
469
 
470
- /**
471
- * Checks whether the given input is already an array, and if it isn't, wraps it in one.
472
- *
473
- * @param maybeArray Input to turn into an array, if necessary
474
- * @returns The input, if already an array, or an array with the input as the only element, if not
475
- */
476
-
477
- function arrayify(maybeArray) {
478
- return Array.isArray(maybeArray) ? maybeArray : [maybeArray];
479
- }
480
-
481
- /**
482
- * Get the closes package.json from a given starting point upwards.
483
- * This handles a few edge cases:
484
- * * Check if a given file package.json appears to be an actual NPM package.json file
485
- * * Stop at the home dir, to avoid looking too deeply
486
- */
487
- function getPackageJson() {
488
- var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
489
- cwd = _ref.cwd,
490
- stopAt = _ref.stopAt;
491
-
492
- return lookupPackageJson(cwd !== null && cwd !== void 0 ? cwd : process.cwd(), path__default["default"].normalize(stopAt !== null && stopAt !== void 0 ? stopAt : os__default["default"].homedir()));
493
- }
494
- function parseMajorVersion(version) {
495
- // if it has a `v` prefix, remove it
496
- if (version.startsWith("v")) {
497
- version = version.slice(1);
498
- } // First, try simple lookup of exact, ~ and ^ versions
499
-
500
-
501
- var regex = /^[\^~]?(\d+)(\.\d+)?(\.\d+)?(-.+)?/;
502
- var match = version.match(regex);
503
-
504
- if (match) {
505
- return parseInt(match[1], 10);
506
- } // Try to parse e.g. 1.x
507
-
508
-
509
- var coerced = parseInt(version, 10);
510
-
511
- if (!Number.isNaN(coerced)) {
512
- return coerced;
513
- } // Match <= and >= ranges.
514
-
515
-
516
- var gteLteRegex = /^[<>]=\s*(\d+)(\.\d+)?(\.\d+)?(-.+)?/;
517
- var gteLteMatch = version.match(gteLteRegex);
518
-
519
- if (gteLteMatch) {
520
- return parseInt(gteLteMatch[1], 10);
521
- } // match < ranges
522
-
523
-
524
- var ltRegex = /^<\s*(\d+)(\.\d+)?(\.\d+)?(-.+)?/;
525
- var ltMatch = version.match(ltRegex);
526
-
527
- if (ltMatch) {
528
- // Two scenarios:
529
- // a) < 2.0.0 --> return 1
530
- // b) < 2.1.0 --> return 2
531
- var major = parseInt(ltMatch[1], 10);
532
-
533
- if ( // minor version > 0
534
- typeof ltMatch[2] === "string" && parseInt(ltMatch[2].slice(1), 10) > 0 || // patch version > 0
535
- typeof ltMatch[3] === "string" && parseInt(ltMatch[3].slice(1), 10) > 0) {
536
- return major;
537
- }
538
-
539
- return major - 1;
540
- } // match > ranges
541
-
542
-
543
- var gtRegex = /^>\s*(\d+)(\.\d+)?(\.\d+)?(-.+)?/;
544
- var gtMatch = version.match(gtRegex);
545
-
546
- if (gtMatch) {
547
- // We always return the version here, even though it _may_ be incorrect
548
- // E.g. if given > 2.0.0, it should be 2 if there exists any 2.x.x version, else 3
549
- // Since there is no way for us to know this, we're going to assume any kind of patch/feature release probably exists
550
- return parseInt(gtMatch[1], 10);
551
- }
552
-
553
- return undefined;
554
- } // This is an explicit list of packages where we want to include the (major) version number.
555
-
556
- var PACKAGES_TO_INCLUDE_VERSION = ["react", "@angular/core", "vue", "ember-source", "svelte", "@sveltejs/kit", "webpack", "vite", "gatsby", "next", "remix", "rollup", "esbuild"];
557
- function getDependencies(packageJson) {
558
- var _packageJson$devDepen, _packageJson$dependen;
559
-
560
- var dependencies = Object.assign({}, (_packageJson$devDepen = packageJson["devDependencies"]) !== null && _packageJson$devDepen !== void 0 ? _packageJson$devDepen : {}, (_packageJson$dependen = packageJson["dependencies"]) !== null && _packageJson$dependen !== void 0 ? _packageJson$dependen : {});
561
- var deps = Object.keys(dependencies).sort();
562
- var depsVersions = deps.reduce(function (depsVersions, depName) {
563
- if (PACKAGES_TO_INCLUDE_VERSION.includes(depName)) {
564
- var version = dependencies[depName];
565
- var majorVersion = parseMajorVersion(version);
566
-
567
- if (majorVersion) {
568
- depsVersions[depName] = majorVersion;
569
- }
570
- }
571
-
572
- return depsVersions;
573
- }, {});
574
- return {
575
- deps: deps,
576
- depsVersions: depsVersions
577
- };
578
- }
579
-
580
- function lookupPackageJson(cwd, stopAt) {
581
- var jsonPath = findUp__default["default"].sync(function (dirName) {
582
- // Stop if we reach this dir
583
- if (path__default["default"].normalize(dirName) === stopAt) {
584
- return findUp__default["default"].stop;
585
- }
586
-
587
- return findUp__default["default"].sync.exists(dirName + "/package.json") ? "package.json" : undefined;
588
- }, {
589
- cwd: cwd
590
- });
591
-
592
- if (!jsonPath) {
593
- return undefined;
594
- }
595
-
596
- try {
597
- var jsonStr = fs__default["default"].readFileSync(jsonPath, "utf8");
598
- var json = JSON.parse(jsonStr); // Ensure it is an actual package.json
599
- // This is very much not bulletproof, but should be good enough
600
-
601
- if ("name" in json || "private" in json) {
602
- return json;
603
- }
604
- } catch (error) {// Ignore and walk up
605
- } // Continue up the tree, if we find a fitting package.json
606
-
607
-
608
- var newCwd = path__default["default"].dirname(path__default["default"].resolve(jsonPath + "/.."));
609
- return lookupPackageJson(newCwd, stopAt);
610
- }
611
- /**
612
- * Deterministically hashes a string and turns the hash into a uuid.
613
- */
614
-
615
-
616
- function stringToUUID(str) {
617
- var md5sum = crypto__default["default"].createHash("md5");
618
- md5sum.update(str);
619
- var md5Hash = md5sum.digest("hex");
620
- return (md5Hash.substring(0, 8) + "-" + md5Hash.substring(8, 12) + "-4" + md5Hash.substring(13, 16) + "-" + md5Hash.substring(16, 20) + "-" + md5Hash.substring(20)).toLowerCase();
621
- }
622
- /**
623
- * Tries to guess a release name based on environmental data.
624
- */
625
-
626
- function determineReleaseName() {
627
- var gitRevision;
628
-
629
- try {
630
- gitRevision = childProcess__default["default"].execSync("git rev-parse --short HEAD").toString().trim();
631
- } catch (e) {// noop
632
- }
633
-
634
- return (// GitHub Actions - https://help.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables#default-environment-variables
635
- process.env["GITHUB_SHA"] || // Netlify - https://docs.netlify.com/configure-builds/environment-variables/#build-metadata
636
- process.env["COMMIT_REF"] || // Cloudflare Pages - https://developers.cloudflare.com/pages/platform/build-configuration/#environment-variables
637
- process.env["CF_PAGES_COMMIT_SHA"] || // AWS CodeBuild - https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-env-vars.html
638
- process.env["CODEBUILD_RESOLVED_SOURCE_VERSION"] || // CircleCI - https://circleci.com/docs/2.0/env-vars/
639
- process.env["CIRCLE_SHA1"] || // Vercel - https://vercel.com/docs/v2/build-step#system-environment-variables
640
- process.env["VERCEL_GIT_COMMIT_SHA"] || process.env["VERCEL_GITHUB_COMMIT_SHA"] || process.env["VERCEL_GITLAB_COMMIT_SHA"] || process.env["VERCEL_BITBUCKET_COMMIT_SHA"] || // Zeit (now known as Vercel)
641
- process.env["ZEIT_GITHUB_COMMIT_SHA"] || process.env["ZEIT_GITLAB_COMMIT_SHA"] || process.env["ZEIT_BITBUCKET_COMMIT_SHA"] || gitRevision
642
- );
643
- }
644
- /**
645
- * Generates code for the global injector which is responsible for setting the global
646
- * `SENTRY_RELEASE` & `SENTRY_BUILD_INFO` variables.
647
- */
648
-
649
- function generateGlobalInjectorCode(_ref2) {
650
- var release = _ref2.release,
651
- injectBuildInformation = _ref2.injectBuildInformation;
652
- // The code below is mostly ternary operators because it saves bundle size.
653
- // The checks are to support as many environments as possible. (Node.js, Browser, webworkers, etc.)
654
- var code = "\n var _global =\n typeof window !== 'undefined' ?\n window :\n typeof global !== 'undefined' ?\n global :\n typeof self !== 'undefined' ?\n self :\n {};\n\n _global.SENTRY_RELEASE={id:\"".concat(release, "\"};");
655
-
656
- if (injectBuildInformation) {
657
- var buildInfo = getBuildInformation$1();
658
- code += "\n _global.SENTRY_BUILD_INFO=".concat(JSON.stringify(buildInfo), ";");
659
- }
660
-
661
- return code;
662
- }
663
-
664
- function getBuildInformation$1() {
665
- var packageJson = getPackageJson();
666
-
667
- var _ref3 = packageJson ? getDependencies(packageJson) : {
668
- deps: [],
669
- depsVersions: {}
670
- },
671
- deps = _ref3.deps,
672
- depsVersions = _ref3.depsVersions;
673
-
674
- return {
675
- deps: deps,
676
- depsVersions: depsVersions,
677
- nodeVersion: parseMajorVersion(process.version)
678
- };
679
- }
680
-
681
470
  var SENTRY_SAAS_URL = "https://sentry.io";
682
471
  function normalizeUserOptions(userOptions) {
683
- var _userOptions$org, _userOptions$project, _userOptions$authToke, _ref, _userOptions$url, _userOptions$debug, _userOptions$silent, _userOptions$telemetr, _userOptions$disable, _process$env$SENTRY_V, _userOptions$_experim;
472
+ var _userOptions$org, _userOptions$project, _userOptions$authToke, _ref, _userOptions$url, _userOptions$debug, _userOptions$silent, _userOptions$telemetr, _userOptions$disable, _userOptions$release$, _userOptions$release, _userOptions$release$2, _userOptions$release2, _userOptions$release$3, _userOptions$release3, _ref2, _userOptions$release$4, _userOptions$release4, _userOptions$release$5, _userOptions$release5, _userOptions$_experim;
684
473
 
685
474
  var options = {
686
475
  org: (_userOptions$org = userOptions.org) !== null && _userOptions$org !== void 0 ? _userOptions$org : process.env["SENTRY_ORG"],
@@ -694,14 +483,13 @@ function normalizeUserOptions(userOptions) {
694
483
  telemetry: (_userOptions$telemetr = userOptions.telemetry) !== null && _userOptions$telemetr !== void 0 ? _userOptions$telemetr : true,
695
484
  disable: (_userOptions$disable = userOptions.disable) !== null && _userOptions$disable !== void 0 ? _userOptions$disable : false,
696
485
  sourcemaps: userOptions.sourcemaps,
697
- release: _objectSpread2({
698
- name: determineReleaseName(),
699
- inject: true,
700
- create: true,
701
- finalize: true,
702
- vcsRemote: (_process$env$SENTRY_V = process.env["SENTRY_VSC_REMOTE"]) !== null && _process$env$SENTRY_V !== void 0 ? _process$env$SENTRY_V : "origin",
703
- cleanArtifacts: false
704
- }, userOptions.release),
486
+ release: _objectSpread2(_objectSpread2({}, userOptions.release), {}, {
487
+ inject: (_userOptions$release$ = (_userOptions$release = userOptions.release) === null || _userOptions$release === void 0 ? void 0 : _userOptions$release.inject) !== null && _userOptions$release$ !== void 0 ? _userOptions$release$ : true,
488
+ create: (_userOptions$release$2 = (_userOptions$release2 = userOptions.release) === null || _userOptions$release2 === void 0 ? void 0 : _userOptions$release2.create) !== null && _userOptions$release$2 !== void 0 ? _userOptions$release$2 : true,
489
+ finalize: (_userOptions$release$3 = (_userOptions$release3 = userOptions.release) === null || _userOptions$release3 === void 0 ? void 0 : _userOptions$release3.finalize) !== null && _userOptions$release$3 !== void 0 ? _userOptions$release$3 : true,
490
+ vcsRemote: (_ref2 = (_userOptions$release$4 = (_userOptions$release4 = userOptions.release) === null || _userOptions$release4 === void 0 ? void 0 : _userOptions$release4.vcsRemote) !== null && _userOptions$release$4 !== void 0 ? _userOptions$release$4 : process.env["SENTRY_VSC_REMOTE"]) !== null && _ref2 !== void 0 ? _ref2 : "origin",
491
+ cleanArtifacts: (_userOptions$release$5 = (_userOptions$release5 = userOptions.release) === null || _userOptions$release5 === void 0 ? void 0 : _userOptions$release5.cleanArtifacts) !== null && _userOptions$release$5 !== void 0 ? _userOptions$release$5 : false
492
+ }),
705
493
  _experiments: (_userOptions$_experim = userOptions._experiments) !== null && _userOptions$_experim !== void 0 ? _userOptions$_experim : {}
706
494
  };
707
495
  return options;
@@ -752,12 +540,14 @@ function debugIdUploadPlugin(_ref) {
752
540
  handleRecoverableError = _ref.handleRecoverableError,
753
541
  sentryHub = _ref.sentryHub,
754
542
  sentryClient = _ref.sentryClient,
755
- sentryCliOptions = _ref.sentryCliOptions;
543
+ sentryCliOptions = _ref.sentryCliOptions,
544
+ rewriteSourcesHook = _ref.rewriteSourcesHook,
545
+ deleteFilesAfterUpload = _ref.deleteFilesAfterUpload;
756
546
  return {
757
547
  name: "sentry-debug-id-upload-plugin",
758
548
  writeBundle: function writeBundle() {
759
549
  return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
760
- var folderToCleanUp, cliInstance, tmpUploadFolder, debugIdChunkFilePaths;
550
+ var folderToCleanUp, cliInstance, tmpUploadFolder, debugIdChunkFilePaths, filePathsToDelete;
761
551
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
762
552
  while (1) {
763
553
  switch (_context2.prev = _context2.next) {
@@ -789,7 +579,7 @@ function debugIdUploadPlugin(_ref) {
789
579
  switch (_context.prev = _context.next) {
790
580
  case 0:
791
581
  _context.next = 2;
792
- return prepareBundleForDebugIdUpload(chunkFilePath, tmpUploadFolder, String(chunkIndex), logger);
582
+ return prepareBundleForDebugIdUpload(chunkFilePath, tmpUploadFolder, chunkIndex, logger, rewriteSourcesHook !== null && rewriteSourcesHook !== void 0 ? rewriteSourcesHook : defaultRewriteSourcesHook);
793
583
 
794
584
  case 2:
795
585
  case "end":
@@ -806,7 +596,8 @@ function debugIdUploadPlugin(_ref) {
806
596
 
807
597
  case 11:
808
598
  _context2.next = 13;
809
- return cliInstance.releases.uploadSourceMaps(releaseName !== null && releaseName !== void 0 ? releaseName : "", {
599
+ return cliInstance.releases.uploadSourceMaps(releaseName !== null && releaseName !== void 0 ? releaseName : "undefined", // unfortunetly this needs a value for now but it will not matter since debug IDs overpower releases anyhow
600
+ {
810
601
  include: [{
811
602
  paths: [tmpUploadFolder],
812
603
  rewrite: false,
@@ -816,21 +607,45 @@ function debugIdUploadPlugin(_ref) {
816
607
  });
817
608
 
818
609
  case 13:
819
- _context2.next = 21;
610
+ if (!deleteFilesAfterUpload) {
611
+ _context2.next = 20;
612
+ break;
613
+ }
614
+
615
+ _context2.next = 16;
616
+ return glob.glob(deleteFilesAfterUpload, {
617
+ absolute: true,
618
+ nodir: true
619
+ });
620
+
621
+ case 16:
622
+ filePathsToDelete = _context2.sent;
623
+ filePathsToDelete.forEach(function (filePathToDelete) {
624
+ logger.debug("Deleting asset after upload: ".concat(filePathToDelete));
625
+ });
626
+ _context2.next = 20;
627
+ return Promise.all(filePathsToDelete.map(function (filePathToDelete) {
628
+ return fs__default["default"].promises.rm(filePathToDelete, {
629
+ force: true
630
+ });
631
+ }));
632
+
633
+ case 20:
634
+ _context2.next = 28;
820
635
  break;
821
636
 
822
- case 15:
823
- _context2.prev = 15;
637
+ case 22:
638
+ _context2.prev = 22;
824
639
  _context2.t0 = _context2["catch"](1);
825
640
  sentryHub.captureException('Error in "debugIdUploadPlugin" writeBundle hook');
826
- _context2.next = 20;
641
+ _context2.next = 27;
827
642
  return sentryClient.flush();
828
643
 
829
- case 20:
644
+ case 27:
830
645
  handleRecoverableError(_context2.t0);
831
646
 
832
- case 21:
833
- _context2.prev = 21;
647
+ case 28:
648
+ _context2.prev = 28;
834
649
 
835
650
  if (folderToCleanUp) {
836
651
  void fs__default["default"].promises.rm(folderToCleanUp, {
@@ -839,19 +654,19 @@ function debugIdUploadPlugin(_ref) {
839
654
  });
840
655
  }
841
656
 
842
- return _context2.finish(21);
657
+ return _context2.finish(28);
843
658
 
844
- case 24:
659
+ case 31:
845
660
  case "end":
846
661
  return _context2.stop();
847
662
  }
848
663
  }
849
- }, _callee2, null, [[1, 15, 21, 24]]);
664
+ }, _callee2, null, [[1, 22, 28, 31]]);
850
665
  }))();
851
666
  }
852
667
  };
853
668
  }
854
- function prepareBundleForDebugIdUpload(_x3, _x4, _x5, _x6) {
669
+ function prepareBundleForDebugIdUpload(_x3, _x4, _x5, _x6, _x7) {
855
670
  return _prepareBundleForDebugIdUpload.apply(this, arguments);
856
671
  }
857
672
  /**
@@ -862,8 +677,8 @@ function prepareBundleForDebugIdUpload(_x3, _x4, _x5, _x6) {
862
677
  */
863
678
 
864
679
  function _prepareBundleForDebugIdUpload() {
865
- _prepareBundleForDebugIdUpload = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(bundleFilePath, uploadFolder, uniqueUploadName, logger) {
866
- var bundleContent, debugId, writeSourceFilePromise, writeSourceMapFilePromise;
680
+ _prepareBundleForDebugIdUpload = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(bundleFilePath, uploadFolder, chunkIndex, logger, rewriteSourcesHook) {
681
+ var bundleContent, debugId, uniqueUploadName, writeSourceFilePromise, writeSourceMapFilePromise;
867
682
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
868
683
  while (1) {
869
684
  switch (_context4.prev = _context4.next) {
@@ -891,10 +706,11 @@ function _prepareBundleForDebugIdUpload() {
891
706
  break;
892
707
  }
893
708
 
894
- logger.warn("Could not determine debug ID from bundle. This can happen if you did not clean your output folder before installing the Sentry plugin. File will not be source mapped: ".concat(bundleFilePath));
709
+ logger.debug("Could not determine debug ID from bundle. This can happen if you did not clean your output folder before installing the Sentry plugin. File will not be source mapped: ".concat(bundleFilePath));
895
710
  return _context4.abrupt("return");
896
711
 
897
712
  case 14:
713
+ uniqueUploadName = "".concat(debugId, "-").concat(chunkIndex);
898
714
  bundleContent += "\n//# debugId=".concat(debugId);
899
715
  writeSourceFilePromise = fs__default["default"].promises.writeFile(path__default["default"].join(uploadFolder, "".concat(uniqueUploadName, ".js")), bundleContent, "utf-8");
900
716
  writeSourceMapFilePromise = determineSourceMapPathFromBundle(bundleFilePath, bundleContent, logger).then( /*#__PURE__*/function () {
@@ -909,7 +725,7 @@ function _prepareBundleForDebugIdUpload() {
909
725
  }
910
726
 
911
727
  _context3.next = 3;
912
- return prepareSourceMapForDebugIdUpload(sourceMapPath, path__default["default"].join(uploadFolder, "".concat(uniqueUploadName, ".js.map")), debugId, logger);
728
+ return prepareSourceMapForDebugIdUpload(sourceMapPath, path__default["default"].join(uploadFolder, "".concat(uniqueUploadName, ".js.map")), debugId, rewriteSourcesHook, logger);
913
729
 
914
730
  case 3:
915
731
  return _context3.abrupt("return", _context3.sent);
@@ -922,13 +738,13 @@ function _prepareBundleForDebugIdUpload() {
922
738
  }, _callee3);
923
739
  }));
924
740
 
925
- return function (_x14) {
741
+ return function (_x16) {
926
742
  return _ref3.apply(this, arguments);
927
743
  };
928
744
  }());
929
745
  return _context4.abrupt("return", Promise.all([writeSourceFilePromise, writeSourceMapFilePromise]));
930
746
 
931
- case 18:
747
+ case 19:
932
748
  case "end":
933
749
  return _context4.stop();
934
750
  }
@@ -954,7 +770,7 @@ function determineDebugIdFromBundleSource(code) {
954
770
  */
955
771
 
956
772
 
957
- function determineSourceMapPathFromBundle(_x7, _x8, _x9) {
773
+ function determineSourceMapPathFromBundle(_x8, _x9, _x10) {
958
774
  return _determineSourceMapPathFromBundle.apply(this, arguments);
959
775
  }
960
776
  /**
@@ -1003,7 +819,8 @@ function _determineSourceMapPathFromBundle() {
1003
819
  _context5.t0 = _context5["catch"](8);
1004
820
 
1005
821
  case 17:
1006
- logger.warn("Could not determine source map path for bundle: ".concat(bundlePath));
822
+ // This is just a debug message because it can be quite spammy for some frameworks
823
+ logger.debug("Could not determine source map path for bundle: ".concat(bundlePath));
1007
824
  return _context5.abrupt("return", undefined);
1008
825
 
1009
826
  case 19:
@@ -1016,12 +833,12 @@ function _determineSourceMapPathFromBundle() {
1016
833
  return _determineSourceMapPathFromBundle.apply(this, arguments);
1017
834
  }
1018
835
 
1019
- function prepareSourceMapForDebugIdUpload(_x10, _x11, _x12, _x13) {
836
+ function prepareSourceMapForDebugIdUpload(_x11, _x12, _x13, _x14, _x15) {
1020
837
  return _prepareSourceMapForDebugIdUpload.apply(this, arguments);
1021
838
  }
1022
839
 
1023
840
  function _prepareSourceMapForDebugIdUpload() {
1024
- _prepareSourceMapForDebugIdUpload = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(sourceMapPath, targetPath, debugId, logger) {
841
+ _prepareSourceMapForDebugIdUpload = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(sourceMapPath, targetPath, debugId, rewriteSourcesHook, logger) {
1025
842
  var sourceMapFileContent, map;
1026
843
  return _regeneratorRuntime().wrap(function _callee6$(_context6) {
1027
844
  while (1) {
@@ -1060,32 +877,259 @@ function _prepareSourceMapForDebugIdUpload() {
1060
877
  return _context6.abrupt("return");
1061
878
 
1062
879
  case 20:
1063
- _context6.prev = 20;
1064
- _context6.next = 23;
880
+ if (map["sources"] && Array.isArray(map["sources"])) {
881
+ map["sources"].map(function (source) {
882
+ return rewriteSourcesHook(source, map);
883
+ });
884
+ }
885
+
886
+ _context6.prev = 21;
887
+ _context6.next = 24;
1065
888
  return util__namespace.promisify(fs__default["default"].writeFile)(targetPath, JSON.stringify(map), {
1066
889
  encoding: "utf8"
1067
890
  });
1068
891
 
1069
- case 23:
1070
- _context6.next = 29;
892
+ case 24:
893
+ _context6.next = 30;
1071
894
  break;
1072
895
 
1073
- case 25:
1074
- _context6.prev = 25;
1075
- _context6.t2 = _context6["catch"](20);
896
+ case 26:
897
+ _context6.prev = 26;
898
+ _context6.t2 = _context6["catch"](21);
1076
899
  logger.error("Failed to prepare source map for debug ID upload: ".concat(sourceMapPath), _context6.t2);
1077
900
  return _context6.abrupt("return");
1078
901
 
1079
- case 29:
902
+ case 30:
1080
903
  case "end":
1081
904
  return _context6.stop();
1082
905
  }
1083
906
  }
1084
- }, _callee6, null, [[0, 6], [10, 16], [20, 25]]);
907
+ }, _callee6, null, [[0, 6], [10, 16], [21, 26]]);
1085
908
  }));
1086
909
  return _prepareSourceMapForDebugIdUpload.apply(this, arguments);
1087
910
  }
1088
911
 
912
+ var PROTOCOL_REGEX = /^[a-zA-Z][a-zA-Z0-9+\-.]*:\/\//;
913
+
914
+ function defaultRewriteSourcesHook(source) {
915
+ if (source.match(PROTOCOL_REGEX)) {
916
+ return source.replace(PROTOCOL_REGEX, "");
917
+ } else {
918
+ return path__default["default"].relative(process.cwd(), path__default["default"].normalize(source));
919
+ }
920
+ }
921
+
922
+ /**
923
+ * Checks whether the given input is already an array, and if it isn't, wraps it in one.
924
+ *
925
+ * @param maybeArray Input to turn into an array, if necessary
926
+ * @returns The input, if already an array, or an array with the input as the only element, if not
927
+ */
928
+
929
+ function arrayify(maybeArray) {
930
+ return Array.isArray(maybeArray) ? maybeArray : [maybeArray];
931
+ }
932
+
933
+ /**
934
+ * Get the closes package.json from a given starting point upwards.
935
+ * This handles a few edge cases:
936
+ * * Check if a given file package.json appears to be an actual NPM package.json file
937
+ * * Stop at the home dir, to avoid looking too deeply
938
+ */
939
+ function getPackageJson() {
940
+ var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
941
+ cwd = _ref.cwd,
942
+ stopAt = _ref.stopAt;
943
+
944
+ return lookupPackageJson(cwd !== null && cwd !== void 0 ? cwd : process.cwd(), path__default["default"].normalize(stopAt !== null && stopAt !== void 0 ? stopAt : os__default["default"].homedir()));
945
+ }
946
+ function parseMajorVersion(version) {
947
+ // if it has a `v` prefix, remove it
948
+ if (version.startsWith("v")) {
949
+ version = version.slice(1);
950
+ } // First, try simple lookup of exact, ~ and ^ versions
951
+
952
+
953
+ var regex = /^[\^~]?(\d+)(\.\d+)?(\.\d+)?(-.+)?/;
954
+ var match = version.match(regex);
955
+
956
+ if (match) {
957
+ return parseInt(match[1], 10);
958
+ } // Try to parse e.g. 1.x
959
+
960
+
961
+ var coerced = parseInt(version, 10);
962
+
963
+ if (!Number.isNaN(coerced)) {
964
+ return coerced;
965
+ } // Match <= and >= ranges.
966
+
967
+
968
+ var gteLteRegex = /^[<>]=\s*(\d+)(\.\d+)?(\.\d+)?(-.+)?/;
969
+ var gteLteMatch = version.match(gteLteRegex);
970
+
971
+ if (gteLteMatch) {
972
+ return parseInt(gteLteMatch[1], 10);
973
+ } // match < ranges
974
+
975
+
976
+ var ltRegex = /^<\s*(\d+)(\.\d+)?(\.\d+)?(-.+)?/;
977
+ var ltMatch = version.match(ltRegex);
978
+
979
+ if (ltMatch) {
980
+ // Two scenarios:
981
+ // a) < 2.0.0 --> return 1
982
+ // b) < 2.1.0 --> return 2
983
+ var major = parseInt(ltMatch[1], 10);
984
+
985
+ if ( // minor version > 0
986
+ typeof ltMatch[2] === "string" && parseInt(ltMatch[2].slice(1), 10) > 0 || // patch version > 0
987
+ typeof ltMatch[3] === "string" && parseInt(ltMatch[3].slice(1), 10) > 0) {
988
+ return major;
989
+ }
990
+
991
+ return major - 1;
992
+ } // match > ranges
993
+
994
+
995
+ var gtRegex = /^>\s*(\d+)(\.\d+)?(\.\d+)?(-.+)?/;
996
+ var gtMatch = version.match(gtRegex);
997
+
998
+ if (gtMatch) {
999
+ // We always return the version here, even though it _may_ be incorrect
1000
+ // E.g. if given > 2.0.0, it should be 2 if there exists any 2.x.x version, else 3
1001
+ // Since there is no way for us to know this, we're going to assume any kind of patch/feature release probably exists
1002
+ return parseInt(gtMatch[1], 10);
1003
+ }
1004
+
1005
+ return undefined;
1006
+ } // This is an explicit list of packages where we want to include the (major) version number.
1007
+
1008
+ var PACKAGES_TO_INCLUDE_VERSION = ["react", "@angular/core", "vue", "ember-source", "svelte", "@sveltejs/kit", "webpack", "vite", "gatsby", "next", "remix", "rollup", "esbuild"];
1009
+ function getDependencies(packageJson) {
1010
+ var _packageJson$devDepen, _packageJson$dependen;
1011
+
1012
+ var dependencies = Object.assign({}, (_packageJson$devDepen = packageJson["devDependencies"]) !== null && _packageJson$devDepen !== void 0 ? _packageJson$devDepen : {}, (_packageJson$dependen = packageJson["dependencies"]) !== null && _packageJson$dependen !== void 0 ? _packageJson$dependen : {});
1013
+ var deps = Object.keys(dependencies).sort();
1014
+ var depsVersions = deps.reduce(function (depsVersions, depName) {
1015
+ if (PACKAGES_TO_INCLUDE_VERSION.includes(depName)) {
1016
+ var version = dependencies[depName];
1017
+ var majorVersion = parseMajorVersion(version);
1018
+
1019
+ if (majorVersion) {
1020
+ depsVersions[depName] = majorVersion;
1021
+ }
1022
+ }
1023
+
1024
+ return depsVersions;
1025
+ }, {});
1026
+ return {
1027
+ deps: deps,
1028
+ depsVersions: depsVersions
1029
+ };
1030
+ }
1031
+
1032
+ function lookupPackageJson(cwd, stopAt) {
1033
+ var jsonPath = findUp__default["default"].sync(function (dirName) {
1034
+ // Stop if we reach this dir
1035
+ if (path__default["default"].normalize(dirName) === stopAt) {
1036
+ return findUp__default["default"].stop;
1037
+ }
1038
+
1039
+ return findUp__default["default"].sync.exists(dirName + "/package.json") ? "package.json" : undefined;
1040
+ }, {
1041
+ cwd: cwd
1042
+ });
1043
+
1044
+ if (!jsonPath) {
1045
+ return undefined;
1046
+ }
1047
+
1048
+ try {
1049
+ var jsonStr = fs__default["default"].readFileSync(jsonPath, "utf8");
1050
+ var json = JSON.parse(jsonStr); // Ensure it is an actual package.json
1051
+ // This is very much not bulletproof, but should be good enough
1052
+
1053
+ if ("name" in json || "private" in json) {
1054
+ return json;
1055
+ }
1056
+ } catch (error) {// Ignore and walk up
1057
+ } // Continue up the tree, if we find a fitting package.json
1058
+
1059
+
1060
+ var newCwd = path__default["default"].dirname(path__default["default"].resolve(jsonPath + "/.."));
1061
+ return lookupPackageJson(newCwd, stopAt);
1062
+ }
1063
+ /**
1064
+ * Deterministically hashes a string and turns the hash into a uuid.
1065
+ */
1066
+
1067
+
1068
+ function stringToUUID(str) {
1069
+ var md5sum = crypto__default["default"].createHash("md5");
1070
+ md5sum.update(str);
1071
+ var md5Hash = md5sum.digest("hex");
1072
+ return (md5Hash.substring(0, 8) + "-" + md5Hash.substring(8, 12) + "-4" + md5Hash.substring(13, 16) + "-" + md5Hash.substring(16, 20) + "-" + md5Hash.substring(20)).toLowerCase();
1073
+ }
1074
+ /**
1075
+ * Tries to guess a release name based on environmental data.
1076
+ */
1077
+
1078
+ function determineReleaseName() {
1079
+ var gitRevision;
1080
+
1081
+ try {
1082
+ gitRevision = childProcess__default["default"].execSync("git rev-parse --short HEAD").toString().trim();
1083
+ } catch (e) {// noop
1084
+ }
1085
+
1086
+ return (// GitHub Actions - https://help.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables#default-environment-variables
1087
+ process.env["GITHUB_SHA"] || // Netlify - https://docs.netlify.com/configure-builds/environment-variables/#build-metadata
1088
+ process.env["COMMIT_REF"] || // Cloudflare Pages - https://developers.cloudflare.com/pages/platform/build-configuration/#environment-variables
1089
+ process.env["CF_PAGES_COMMIT_SHA"] || // AWS CodeBuild - https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-env-vars.html
1090
+ process.env["CODEBUILD_RESOLVED_SOURCE_VERSION"] || // CircleCI - https://circleci.com/docs/2.0/env-vars/
1091
+ process.env["CIRCLE_SHA1"] || // Vercel - https://vercel.com/docs/v2/build-step#system-environment-variables
1092
+ process.env["VERCEL_GIT_COMMIT_SHA"] || process.env["VERCEL_GITHUB_COMMIT_SHA"] || process.env["VERCEL_GITLAB_COMMIT_SHA"] || process.env["VERCEL_BITBUCKET_COMMIT_SHA"] || // Zeit (now known as Vercel)
1093
+ process.env["ZEIT_GITHUB_COMMIT_SHA"] || process.env["ZEIT_GITLAB_COMMIT_SHA"] || process.env["ZEIT_BITBUCKET_COMMIT_SHA"] || gitRevision
1094
+ );
1095
+ }
1096
+ /**
1097
+ * Generates code for the global injector which is responsible for setting the global
1098
+ * `SENTRY_RELEASE` & `SENTRY_BUILD_INFO` variables.
1099
+ */
1100
+
1101
+ function generateGlobalInjectorCode(_ref2) {
1102
+ var release = _ref2.release,
1103
+ injectBuildInformation = _ref2.injectBuildInformation;
1104
+ // The code below is mostly ternary operators because it saves bundle size.
1105
+ // The checks are to support as many environments as possible. (Node.js, Browser, webworkers, etc.)
1106
+ var code = "\n var _global =\n typeof window !== 'undefined' ?\n window :\n typeof global !== 'undefined' ?\n global :\n typeof self !== 'undefined' ?\n self :\n {};\n\n _global.SENTRY_RELEASE={id:\"".concat(release, "\"};");
1107
+
1108
+ if (injectBuildInformation) {
1109
+ var buildInfo = getBuildInformation$1();
1110
+ code += "\n _global.SENTRY_BUILD_INFO=".concat(JSON.stringify(buildInfo), ";");
1111
+ }
1112
+
1113
+ return code;
1114
+ }
1115
+
1116
+ function getBuildInformation$1() {
1117
+ var packageJson = getPackageJson();
1118
+
1119
+ var _ref3 = packageJson ? getDependencies(packageJson) : {
1120
+ deps: [],
1121
+ depsVersions: {}
1122
+ },
1123
+ deps = _ref3.deps,
1124
+ depsVersions = _ref3.depsVersions;
1125
+
1126
+ return {
1127
+ deps: deps,
1128
+ depsVersions: depsVersions,
1129
+ nodeVersion: parseMajorVersion(process.version)
1130
+ };
1131
+ }
1132
+
1089
1133
  function releaseManagementPlugin(_ref) {
1090
1134
  var releaseName = _ref.releaseName,
1091
1135
  include = _ref.include,
@@ -1300,7 +1344,7 @@ function createSentryInstance(options, shouldSendTelemetry, bundler) {
1300
1344
  dsn: "https://4c2bae7d9fbc413e8f7385f55c515d51@o1.ingest.sentry.io/6690737",
1301
1345
  tracesSampleRate: 1,
1302
1346
  sampleRate: 1,
1303
- release: "2.0.0-alpha.6",
1347
+ release: "2.0.0",
1304
1348
  integrations: [],
1305
1349
  tracePropagationTargets: ["sentry.io/api"],
1306
1350
  stackParser: node.defaultStackParser,
@@ -1408,7 +1452,7 @@ function setTelemetryDataOnHub(options, hub, bundler) {
1408
1452
  hub.setTag("debug-id-upload", true);
1409
1453
  }
1410
1454
 
1411
- if (sourcemaps !== null && sourcemaps !== void 0 && sourcemaps.deleteAfterUpload) {
1455
+ if (sourcemaps !== null && sourcemaps !== void 0 && sourcemaps.deleteFilesAfterUpload) {
1412
1456
  hub.setTag("delete-after-upload", true);
1413
1457
  }
1414
1458
 
@@ -1530,6 +1574,8 @@ function sentryUnpluginFactory(_ref) {
1530
1574
  var releaseInjectionPlugin = _ref.releaseInjectionPlugin,
1531
1575
  debugIdInjectionPlugin = _ref.debugIdInjectionPlugin;
1532
1576
  return unplugin.createUnplugin(function (userOptions, unpluginMetaContext) {
1577
+ var _options$release$name;
1578
+
1533
1579
  var options = normalizeUserOptions(userOptions);
1534
1580
 
1535
1581
  if (unpluginMetaContext.watchMode || options.disable) {
@@ -1597,7 +1643,9 @@ function sentryUnpluginFactory(_ref) {
1597
1643
  plugins.push(releaseInjectionPlugin(_injectionCode));
1598
1644
  }
1599
1645
 
1600
- if (!options.release.name) {
1646
+ var releaseManagementPluginReleaseName = (_options$release$name = options.release.name) !== null && _options$release$name !== void 0 ? _options$release$name : determineReleaseName();
1647
+
1648
+ if (!releaseManagementPluginReleaseName) {
1601
1649
  logger.warn("No release name provided. Will not create release. Please set the `release.name` option to identifiy your release.");
1602
1650
  } else if (!options.authToken) {
1603
1651
  logger.warn("No auth token provided. Will not create release. Please set the `authToken` option. You can find information on how to generate a Sentry auth token here: https://docs.sentry.io/api/auth/");
@@ -1608,7 +1656,7 @@ function sentryUnpluginFactory(_ref) {
1608
1656
  } else {
1609
1657
  plugins.push(releaseManagementPlugin({
1610
1658
  logger: logger,
1611
- releaseName: options.release.name,
1659
+ releaseName: releaseManagementPluginReleaseName,
1612
1660
  shouldCreateRelease: options.release.create,
1613
1661
  shouldCleanArtifacts: options.release.cleanArtifacts,
1614
1662
  shouldFinalizeRelease: options.release.finalize,
@@ -1645,10 +1693,12 @@ function sentryUnpluginFactory(_ref) {
1645
1693
  plugins.push(debugIdUploadPlugin({
1646
1694
  assets: options.sourcemaps.assets,
1647
1695
  ignore: options.sourcemaps.ignore,
1696
+ deleteFilesAfterUpload: options.sourcemaps.deleteFilesAfterUpload,
1648
1697
  dist: options.release.dist,
1649
1698
  releaseName: options.release.name,
1650
1699
  logger: logger,
1651
1700
  handleRecoverableError: handleRecoverableError,
1701
+ rewriteSourcesHook: options.sourcemaps.rewriteSources,
1652
1702
  sentryHub: sentryHub,
1653
1703
  sentryClient: sentryClient,
1654
1704
  sentryCliOptions: {