@sentry/bundler-plugin-core 2.2.2 → 2.4.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.
@@ -14,6 +14,7 @@ import * as util from 'util';
14
14
  import { promisify } from 'util';
15
15
  import { dynamicSamplingContextToSentryBaggageHeader } from '@sentry/utils';
16
16
  import { NodeClient, defaultStackParser, makeNodeTransport, Hub } from '@sentry/node';
17
+ import * as dotenv from 'dotenv';
17
18
 
18
19
  function ownKeys(object, enumerableOnly) {
19
20
  var keys = Object.keys(object);
@@ -533,7 +534,11 @@ function stringToUUID(str) {
533
534
  var md5sum = crypto.createHash("md5");
534
535
  md5sum.update(str);
535
536
  var md5Hash = md5sum.digest("hex");
536
- return (md5Hash.substring(0, 8) + "-" + md5Hash.substring(8, 12) + "-4" + md5Hash.substring(13, 16) + "-" + md5Hash.substring(16, 20) + "-" + md5Hash.substring(20)).toLowerCase();
537
+
538
+ // Position 16 is fixed to either 8, 9, a, or b in the uuid v4 spec (10xx in binary)
539
+ // RFC 4122 section 4.4
540
+ var v4variant = ["8", "9", "a", "b"][md5Hash.substring(16, 17).charCodeAt(0) % 4];
541
+ return (md5Hash.substring(0, 8) + "-" + md5Hash.substring(8, 12) + "-4" + md5Hash.substring(13, 16) + "-" + v4variant + md5Hash.substring(17, 20) + "-" + md5Hash.substring(20)).toLowerCase();
537
542
  }
538
543
 
539
544
  /**
@@ -542,7 +547,7 @@ function stringToUUID(str) {
542
547
  function determineReleaseName() {
543
548
  var gitRevision;
544
549
  try {
545
- gitRevision = childProcess.execSync("git rev-parse --short HEAD").toString().trim();
550
+ gitRevision = childProcess.execSync("git rev-parse HEAD").toString().trim();
546
551
  } catch (e) {
547
552
  // noop
548
553
  }
@@ -601,7 +606,7 @@ function stripQueryAndHashFromPath(path) {
601
606
 
602
607
  var SENTRY_SAAS_URL = "https://sentry.io";
603
608
  function normalizeUserOptions(userOptions) {
604
- 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, _userOptions$release$4, _userOptions$release4, _ref2, _userOptions$release$5, _userOptions$release5, _userOptions$release$6, _userOptions$release6, _userOptions$_experim;
609
+ 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;
605
610
  var options = {
606
611
  org: (_userOptions$org = userOptions.org) !== null && _userOptions$org !== void 0 ? _userOptions$org : process.env["SENTRY_ORG"],
607
612
  project: (_userOptions$project = userOptions.project) !== null && _userOptions$project !== void 0 ? _userOptions$project : process.env["SENTRY_PROJECT"],
@@ -615,11 +620,11 @@ function normalizeUserOptions(userOptions) {
615
620
  disable: (_userOptions$disable = userOptions.disable) !== null && _userOptions$disable !== void 0 ? _userOptions$disable : false,
616
621
  sourcemaps: userOptions.sourcemaps,
617
622
  release: _objectSpread2(_objectSpread2({}, userOptions.release), {}, {
618
- name: (_userOptions$release$ = (_userOptions$release = userOptions.release) === null || _userOptions$release === void 0 ? void 0 : _userOptions$release.name) !== null && _userOptions$release$ !== void 0 ? _userOptions$release$ : determineReleaseName(),
623
+ name: (_ref2 = (_userOptions$release$ = (_userOptions$release = userOptions.release) === null || _userOptions$release === void 0 ? void 0 : _userOptions$release.name) !== null && _userOptions$release$ !== void 0 ? _userOptions$release$ : process.env["SENTRY_RELEASE"]) !== null && _ref2 !== void 0 ? _ref2 : determineReleaseName(),
619
624
  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,
620
625
  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,
621
626
  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,
622
- vcsRemote: (_ref2 = (_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 && _ref2 !== void 0 ? _ref2 : "origin",
627
+ 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",
623
628
  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
624
629
  }),
625
630
  _experiments: (_userOptions$_experim = userOptions._experiments) !== null && _userOptions$_experim !== void 0 ? _userOptions$_experim : {}
@@ -669,7 +674,7 @@ function createDebugIdUploadFunction(_ref) {
669
674
  sentryClient = _ref.sentryClient,
670
675
  sentryCliOptions = _ref.sentryCliOptions,
671
676
  rewriteSourcesHook = _ref.rewriteSourcesHook,
672
- deleteFilesAfterUpload = _ref.deleteFilesAfterUpload;
677
+ filesToDeleteAfterUpload = _ref.filesToDeleteAfterUpload;
673
678
  return /*#__PURE__*/function () {
674
679
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(buildArtifactPaths) {
675
680
  var artifactBundleUploadTransaction, folderToCleanUp, mkdtempSpan, tmpUploadFolder, globAssets, globSpan, globResult, debugIdChunkFilePaths, prepareSpan, files, stats, uploadSize, uploadSpan, cliInstance, deleteGlobSpan, filePathsToDelete, deleteSpan, cleanupSpan;
@@ -709,27 +714,29 @@ function createDebugIdUploadFunction(_ref) {
709
714
  globSpan.finish();
710
715
  debugIdChunkFilePaths = globResult.filter(function (debugIdChunkFilePath) {
711
716
  return debugIdChunkFilePath.endsWith(".js") || debugIdChunkFilePath.endsWith(".mjs") || debugIdChunkFilePath.endsWith(".cjs");
712
- });
717
+ }); // The order of the files output by glob() is not deterministic
718
+ // Ensure order within the files so that {debug-id}-{chunkIndex} coupling is consistent
719
+ debugIdChunkFilePaths.sort();
713
720
  if (!(Array.isArray(assets) && assets.length === 0)) {
714
- _context2.next = 19;
721
+ _context2.next = 20;
715
722
  break;
716
723
  }
717
724
  logger.debug("Empty `sourcemaps.assets` option provided. Will not upload sourcemaps with debug ID.");
718
- _context2.next = 41;
725
+ _context2.next = 43;
719
726
  break;
720
- case 19:
727
+ case 20:
721
728
  if (!(debugIdChunkFilePaths.length === 0)) {
722
- _context2.next = 23;
729
+ _context2.next = 24;
723
730
  break;
724
731
  }
725
732
  logger.warn("Didn't find any matching sources for debug ID upload. Please check the `sourcemaps.assets` option.");
726
- _context2.next = 41;
733
+ _context2.next = 43;
727
734
  break;
728
- case 23:
735
+ case 24:
729
736
  prepareSpan = artifactBundleUploadTransaction.startChild({
730
737
  description: "prepare-bundles"
731
738
  });
732
- _context2.next = 26;
739
+ _context2.next = 27;
733
740
  return Promise.all(debugIdChunkFilePaths.map( /*#__PURE__*/function () {
734
741
  var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(chunkFilePath, chunkIndex) {
735
742
  return _regeneratorRuntime().wrap(function _callee$(_context) {
@@ -747,18 +754,18 @@ function createDebugIdUploadFunction(_ref) {
747
754
  return _ref3.apply(this, arguments);
748
755
  };
749
756
  }()));
750
- case 26:
757
+ case 27:
751
758
  prepareSpan.finish();
752
- _context2.next = 29;
759
+ _context2.next = 30;
753
760
  return fs__default.promises.readdir(tmpUploadFolder);
754
- case 29:
761
+ case 30:
755
762
  files = _context2.sent;
756
763
  stats = files.map(function (file) {
757
764
  return fs__default.promises.stat(path__default.join(tmpUploadFolder, file));
758
765
  });
759
- _context2.next = 33;
766
+ _context2.next = 34;
760
767
  return Promise.all(stats);
761
- case 33:
768
+ case 34:
762
769
  uploadSize = _context2.sent.reduce(function (accumulator, _ref4) {
763
770
  var size = _ref4.size;
764
771
  return accumulator + size;
@@ -775,7 +782,7 @@ function createDebugIdUploadFunction(_ref) {
775
782
  baggage: dynamicSamplingContextToSentryBaggageHeader(artifactBundleUploadTransaction.getDynamicSamplingContext())
776
783
  }, sentryCliOptions.headers)
777
784
  }));
778
- _context2.next = 40;
785
+ _context2.next = 41;
779
786
  return cliInstance.releases.uploadSourceMaps(releaseName !== null && releaseName !== void 0 ? releaseName : "undefined",
780
787
  // unfortunetly this needs a value for now but it will not matter since debug IDs overpower releases anyhow
781
788
  {
@@ -786,22 +793,23 @@ function createDebugIdUploadFunction(_ref) {
786
793
  }],
787
794
  useArtifactBundle: true
788
795
  });
789
- case 40:
790
- uploadSpan.finish();
791
796
  case 41:
792
- if (!deleteFilesAfterUpload) {
793
- _context2.next = 52;
797
+ uploadSpan.finish();
798
+ logger.info("Successfully uploaded source maps to Sentry");
799
+ case 43:
800
+ if (!filesToDeleteAfterUpload) {
801
+ _context2.next = 54;
794
802
  break;
795
803
  }
796
804
  deleteGlobSpan = artifactBundleUploadTransaction.startChild({
797
805
  description: "delete-glob"
798
806
  });
799
- _context2.next = 45;
800
- return glob(deleteFilesAfterUpload, {
807
+ _context2.next = 47;
808
+ return glob(filesToDeleteAfterUpload, {
801
809
  absolute: true,
802
810
  nodir: true
803
811
  });
804
- case 45:
812
+ case 47:
805
813
  filePathsToDelete = _context2.sent;
806
814
  deleteGlobSpan.finish();
807
815
  filePathsToDelete.forEach(function (filePathToDelete) {
@@ -810,27 +818,27 @@ function createDebugIdUploadFunction(_ref) {
810
818
  deleteSpan = artifactBundleUploadTransaction.startChild({
811
819
  description: "delete-files-after-upload"
812
820
  });
813
- _context2.next = 51;
821
+ _context2.next = 53;
814
822
  return Promise.all(filePathsToDelete.map(function (filePathToDelete) {
815
823
  return fs__default.promises.rm(filePathToDelete, {
816
824
  force: true
817
825
  });
818
826
  }));
819
- case 51:
827
+ case 53:
820
828
  deleteSpan.finish();
821
- case 52:
822
- _context2.next = 58;
823
- break;
824
829
  case 54:
825
- _context2.prev = 54;
830
+ _context2.next = 60;
831
+ break;
832
+ case 56:
833
+ _context2.prev = 56;
826
834
  _context2.t0 = _context2["catch"](1);
827
835
  sentryHub.withScope(function (scope) {
828
836
  scope.setSpan(artifactBundleUploadTransaction);
829
837
  sentryHub.captureException('Error in "debugIdUploadPlugin" writeBundle hook');
830
838
  });
831
839
  handleRecoverableError(_context2.t0);
832
- case 58:
833
- _context2.prev = 58;
840
+ case 60:
841
+ _context2.prev = 60;
834
842
  if (folderToCleanUp) {
835
843
  cleanupSpan = artifactBundleUploadTransaction.startChild({
836
844
  description: "cleanup"
@@ -842,15 +850,15 @@ function createDebugIdUploadFunction(_ref) {
842
850
  cleanupSpan.finish();
843
851
  }
844
852
  artifactBundleUploadTransaction.finish();
845
- _context2.next = 63;
853
+ _context2.next = 65;
846
854
  return sentryClient.flush();
847
- case 63:
848
- return _context2.finish(58);
849
- case 64:
855
+ case 65:
856
+ return _context2.finish(60);
857
+ case 66:
850
858
  case "end":
851
859
  return _context2.stop();
852
860
  }
853
- }, _callee2, null, [[1, 54, 58, 64]]);
861
+ }, _callee2, null, [[1, 56, 60, 66]]);
854
862
  }));
855
863
  return function (_x) {
856
864
  return _ref2.apply(this, arguments);
@@ -1251,7 +1259,7 @@ function createSentryInstance(options, shouldSendTelemetry, bundler) {
1251
1259
  dsn: "https://4c2bae7d9fbc413e8f7385f55c515d51@o1.ingest.sentry.io/6690737",
1252
1260
  tracesSampleRate: 1,
1253
1261
  sampleRate: 1,
1254
- release: "2.2.2",
1262
+ release: "2.4.0",
1255
1263
  integrations: [],
1256
1264
  tracePropagationTargets: ["sentry.io/api"],
1257
1265
  stackParser: defaultStackParser,
@@ -1335,7 +1343,7 @@ function setTelemetryDataOnHub(options, hub, bundler) {
1335
1343
  // Miscelaneous options
1336
1344
  hub.setTag("custom-error-handler", !!errorHandler);
1337
1345
  hub.setTag("sourcemaps-assets", !!(sourcemaps !== null && sourcemaps !== void 0 && sourcemaps.assets));
1338
- hub.setTag("delete-after-upload", !!(sourcemaps !== null && sourcemaps !== void 0 && sourcemaps.deleteFilesAfterUpload));
1346
+ hub.setTag("delete-after-upload", !!(sourcemaps !== null && sourcemaps !== void 0 && sourcemaps.deleteFilesAfterUpload) || !!(sourcemaps !== null && sourcemaps !== void 0 && sourcemaps.filesToDeleteAfterUpload));
1339
1347
  hub.setTag("node", process.version);
1340
1348
  hub.setTag("platform", process.platform);
1341
1349
  hub.setTags({
@@ -1440,6 +1448,24 @@ function sentryUnpluginFactory(_ref) {
1440
1448
  debugIdInjectionPlugin = _ref.debugIdInjectionPlugin,
1441
1449
  debugIdUploadPlugin = _ref.debugIdUploadPlugin;
1442
1450
  return createUnplugin(function (userOptions, unpluginMetaContext) {
1451
+ var _userOptions$silent, _userOptions$debug;
1452
+ var logger = createLogger({
1453
+ prefix: "[sentry-".concat(unpluginMetaContext.framework, "-plugin]"),
1454
+ silent: (_userOptions$silent = userOptions.silent) !== null && _userOptions$silent !== void 0 ? _userOptions$silent : false,
1455
+ debug: (_userOptions$debug = userOptions.debug) !== null && _userOptions$debug !== void 0 ? _userOptions$debug : false
1456
+ });
1457
+ var dotenvResult = dotenv.config({
1458
+ path: path.join(process.cwd(), ".env.sentry-build-plugin")
1459
+ });
1460
+
1461
+ // Ignore "file not found" errors but throw all others
1462
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1463
+ // @ts-ignore Accessing `code` on error should be safe
1464
+ if (dotenvResult.error && dotenvResult.error.code !== "ENOENT") {
1465
+ throw dotenvResult.error;
1466
+ } else if (dotenvResult.parsed) {
1467
+ logger.info('Using environment variables configured in ".env.sentry-build-plugin".');
1468
+ }
1443
1469
  var options = normalizeUserOptions(userOptions);
1444
1470
  if (unpluginMetaContext.watchMode || options.disable) {
1445
1471
  return [{
@@ -1460,14 +1486,9 @@ function sentryUnpluginFactory(_ref) {
1460
1486
  sentEndSession = true;
1461
1487
  }
1462
1488
  });
1463
- var logger = createLogger({
1464
- prefix: "[sentry-".concat(unpluginMetaContext.framework, "-plugin]"),
1465
- silent: options.silent,
1466
- debug: options.debug
1467
- });
1468
1489
 
1469
1490
  // Set the User-Agent that Sentry CLI will use when interacting with Sentry
1470
- process.env["SENTRY_PIPELINE"] = "".concat(unpluginMetaContext.framework, "-plugin/", "2.2.2");
1491
+ process.env["SENTRY_PIPELINE"] = "".concat(unpluginMetaContext.framework, "-plugin/", "2.4.0");
1471
1492
  function handleRecoverableError(unknownError) {
1472
1493
  sentrySession.status = "abnormal";
1473
1494
  try {
@@ -1547,6 +1568,7 @@ function sentryUnpluginFactory(_ref) {
1547
1568
  }
1548
1569
  }));
1549
1570
  }
1571
+ plugins.push(debugIdInjectionPlugin());
1550
1572
  if (!options.authToken) {
1551
1573
  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/");
1552
1574
  } else if (!options.org) {
@@ -1554,17 +1576,16 @@ function sentryUnpluginFactory(_ref) {
1554
1576
  } else if (!options.project) {
1555
1577
  logger.warn("No project provided. Will not upload source maps. Please set the `project` option to your Sentry project slug.");
1556
1578
  } else {
1557
- var _options$sourcemaps, _options$sourcemaps2, _options$sourcemaps3, _options$sourcemaps4;
1558
- plugins.push(debugIdInjectionPlugin());
1579
+ var _options$sourcemaps, _options$sourcemaps2, _options$sourcemaps$f, _options$sourcemaps3, _options$sourcemaps4, _options$sourcemaps5;
1559
1580
  plugins.push(debugIdUploadPlugin(createDebugIdUploadFunction({
1560
1581
  assets: (_options$sourcemaps = options.sourcemaps) === null || _options$sourcemaps === void 0 ? void 0 : _options$sourcemaps.assets,
1561
1582
  ignore: (_options$sourcemaps2 = options.sourcemaps) === null || _options$sourcemaps2 === void 0 ? void 0 : _options$sourcemaps2.ignore,
1562
- deleteFilesAfterUpload: (_options$sourcemaps3 = options.sourcemaps) === null || _options$sourcemaps3 === void 0 ? void 0 : _options$sourcemaps3.deleteFilesAfterUpload,
1583
+ 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,
1563
1584
  dist: options.release.dist,
1564
1585
  releaseName: options.release.name,
1565
1586
  logger: logger,
1566
1587
  handleRecoverableError: handleRecoverableError,
1567
- rewriteSourcesHook: (_options$sourcemaps4 = options.sourcemaps) === null || _options$sourcemaps4 === void 0 ? void 0 : _options$sourcemaps4.rewriteSources,
1588
+ rewriteSourcesHook: (_options$sourcemaps5 = options.sourcemaps) === null || _options$sourcemaps5 === void 0 ? void 0 : _options$sourcemaps5.rewriteSources,
1568
1589
  sentryHub: sentryHub,
1569
1590
  sentryClient: sentryClient,
1570
1591
  sentryCliOptions: {
@@ -1744,5 +1765,5 @@ function getDebugIdSnippet(debugId) {
1744
1765
  return ";!function(){try{var e=\"undefined\"!=typeof window?window:\"undefined\"!=typeof global?global:\"undefined\"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]=\"".concat(debugId, "\",e._sentryDebugIdIdentifier=\"sentry-dbid-").concat(debugId, "\")}catch(e){}}();");
1745
1766
  }
1746
1767
 
1747
- export { createRollupDebugIdInjectionHooks, createRollupDebugIdUploadHooks, createRollupReleaseInjectionHooks, getBuildInformation, getDebugIdSnippet, sentryCliBinaryExists, sentryUnpluginFactory };
1768
+ export { createRollupDebugIdInjectionHooks, createRollupDebugIdUploadHooks, createRollupReleaseInjectionHooks, getBuildInformation, getDebugIdSnippet, sentryCliBinaryExists, sentryUnpluginFactory, stringToUUID };
1748
1769
  //# sourceMappingURL=index.mjs.map