@sentry/bundler-plugin-core 0.4.0 → 0.5.1

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,14 +6,46 @@ var unplugin$1 = require('unplugin');
6
6
  var MagicString = require('magic-string');
7
7
  var SentryCli = require('@sentry/cli');
8
8
  var node = require('@sentry/node');
9
- require('@sentry/tracing');
9
+ var findUp = require('find-up');
10
10
  var path = require('path');
11
+ var fs = require('fs');
12
+ var os = require('os');
13
+ var crypto = require('crypto');
14
+ require('@sentry/tracing');
15
+ var util = require('util');
16
+ var glob = require('glob');
11
17
 
12
18
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
13
19
 
20
+ function _interopNamespace(e) {
21
+ if (e && e.__esModule) return e;
22
+ var n = Object.create(null);
23
+ if (e) {
24
+ Object.keys(e).forEach(function (k) {
25
+ if (k !== 'default') {
26
+ var d = Object.getOwnPropertyDescriptor(e, k);
27
+ Object.defineProperty(n, k, d.get ? d : {
28
+ enumerable: true,
29
+ get: function () { return e[k]; }
30
+ });
31
+ }
32
+ });
33
+ }
34
+ n["default"] = e;
35
+ return Object.freeze(n);
36
+ }
37
+
14
38
  var MagicString__default = /*#__PURE__*/_interopDefaultLegacy(MagicString);
15
39
  var SentryCli__default = /*#__PURE__*/_interopDefaultLegacy(SentryCli);
40
+ var findUp__default = /*#__PURE__*/_interopDefaultLegacy(findUp);
16
41
  var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
42
+ var path__namespace = /*#__PURE__*/_interopNamespace(path);
43
+ var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
44
+ var fs__namespace = /*#__PURE__*/_interopNamespace(fs);
45
+ var os__default = /*#__PURE__*/_interopDefaultLegacy(os);
46
+ var crypto__default = /*#__PURE__*/_interopDefaultLegacy(crypto);
47
+ var util__namespace = /*#__PURE__*/_interopNamespace(util);
48
+ var util__default = /*#__PURE__*/_interopDefaultLegacy(util);
17
49
 
18
50
  function _regeneratorRuntime() {
19
51
  /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
@@ -769,13 +801,156 @@ timestampSource.nowSeconds.bind(timestampSource);
769
801
  * @param maybeArray Input to turn into an array, if necessary
770
802
  * @returns The input, if already an array, or an array with the input as the only element, if not
771
803
  */
804
+
772
805
  function arrayify(maybeArray) {
773
806
  return Array.isArray(maybeArray) ? maybeArray : [maybeArray];
774
807
  }
775
808
 
809
+ /**
810
+ * Get the closes package.json from a given starting point upwards.
811
+ * This handles a few edge cases:
812
+ * * Check if a given file package.json appears to be an actual NPM package.json file
813
+ * * Stop at the home dir, to avoid looking too deeply
814
+ */
815
+ function getPackageJson() {
816
+ var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
817
+ cwd = _ref.cwd,
818
+ stopAt = _ref.stopAt;
819
+
820
+ return lookupPackageJson(cwd !== null && cwd !== void 0 ? cwd : process.cwd(), path__default["default"].normalize(stopAt !== null && stopAt !== void 0 ? stopAt : os__default["default"].homedir()));
821
+ }
822
+ function parseMajorVersion(version) {
823
+ // if it has a `v` prefix, remove it
824
+ if (version.startsWith("v")) {
825
+ version = version.slice(1);
826
+ } // First, try simple lookup of exact, ~ and ^ versions
827
+
828
+
829
+ var regex = /^[\^~]?(\d+)(\.\d+)?(\.\d+)?(-.+)?/;
830
+ var match = version.match(regex);
831
+
832
+ if (match) {
833
+ return parseInt(match[1], 10);
834
+ } // Try to parse e.g. 1.x
835
+
836
+
837
+ var coerced = parseInt(version, 10);
838
+
839
+ if (!Number.isNaN(coerced)) {
840
+ return coerced;
841
+ } // Match <= and >= ranges.
842
+
843
+
844
+ var gteLteRegex = /^[<>]=\s*(\d+)(\.\d+)?(\.\d+)?(-.+)?/;
845
+ var gteLteMatch = version.match(gteLteRegex);
846
+
847
+ if (gteLteMatch) {
848
+ return parseInt(gteLteMatch[1], 10);
849
+ } // match < ranges
850
+
851
+
852
+ var ltRegex = /^<\s*(\d+)(\.\d+)?(\.\d+)?(-.+)?/;
853
+ var ltMatch = version.match(ltRegex);
854
+
855
+ if (ltMatch) {
856
+ // Two scenarios:
857
+ // a) < 2.0.0 --> return 1
858
+ // b) < 2.1.0 --> return 2
859
+ var major = parseInt(ltMatch[1], 10);
860
+
861
+ if ( // minor version > 0
862
+ typeof ltMatch[2] === "string" && parseInt(ltMatch[2].slice(1), 10) > 0 || // patch version > 0
863
+ typeof ltMatch[3] === "string" && parseInt(ltMatch[3].slice(1), 10) > 0) {
864
+ return major;
865
+ }
866
+
867
+ return major - 1;
868
+ } // match > ranges
869
+
870
+
871
+ var gtRegex = /^>\s*(\d+)(\.\d+)?(\.\d+)?(-.+)?/;
872
+ var gtMatch = version.match(gtRegex);
873
+
874
+ if (gtMatch) {
875
+ // We always return the version here, even though it _may_ be incorrect
876
+ // E.g. if given > 2.0.0, it should be 2 if there exists any 2.x.x version, else 3
877
+ // Since there is no way for us to know this, we're going to assume any kind of patch/feature release probably exists
878
+ return parseInt(gtMatch[1], 10);
879
+ }
880
+
881
+ return undefined;
882
+ } // This is an explicit list of packages where we want to include the (major) version number.
883
+
884
+ var PACKAGES_TO_INCLUDE_VERSION = ["react", "@angular/core", "vue", "ember-source", "svelte", "@sveltejs/kit", "webpack", "vite", "gatsby", "next", "remix", "rollup", "esbuild"];
885
+ function getDependencies(packageJson) {
886
+ var _packageJson$devDepen, _packageJson$dependen;
887
+
888
+ 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 : {});
889
+ var deps = Object.keys(dependencies).sort();
890
+ var depsVersions = deps.reduce(function (depsVersions, depName) {
891
+ if (PACKAGES_TO_INCLUDE_VERSION.includes(depName)) {
892
+ var version = dependencies[depName];
893
+ var majorVersion = parseMajorVersion(version);
894
+
895
+ if (majorVersion) {
896
+ depsVersions[depName] = majorVersion;
897
+ }
898
+ }
899
+
900
+ return depsVersions;
901
+ }, {});
902
+ return {
903
+ deps: deps,
904
+ depsVersions: depsVersions
905
+ };
906
+ }
907
+
908
+ function lookupPackageJson(cwd, stopAt) {
909
+ var jsonPath = findUp__default["default"].sync(function (dirName) {
910
+ // Stop if we reach this dir
911
+ if (path__default["default"].normalize(dirName) === stopAt) {
912
+ return findUp__default["default"].stop;
913
+ }
914
+
915
+ return findUp__default["default"].sync.exists(dirName + "/package.json") ? "package.json" : undefined;
916
+ }, {
917
+ cwd: cwd
918
+ });
919
+
920
+ if (!jsonPath) {
921
+ return undefined;
922
+ }
923
+
924
+ try {
925
+ var jsonStr = fs__default["default"].readFileSync(jsonPath, "utf8");
926
+ var json = JSON.parse(jsonStr); // Ensure it is an actual package.json
927
+ // This is very much not bulletproof, but should be good enough
928
+
929
+ if ("name" in json || "private" in json) {
930
+ return json;
931
+ }
932
+ } catch (error) {// Ignore and walk up
933
+ } // Continue up the tree, if we find a fitting package.json
934
+
935
+
936
+ var newCwd = path__default["default"].dirname(path__default["default"].resolve(jsonPath + "/.."));
937
+ return lookupPackageJson(newCwd, stopAt);
938
+ }
939
+ /**
940
+ * Deterministically hashes a string and turns the hash into a uuid.
941
+ */
942
+
943
+
944
+ function stringToUUID(str) {
945
+ var md5sum = crypto__default["default"].createHash("md5");
946
+ md5sum.update(str);
947
+ var md5Hash = md5sum.digest("hex");
948
+ return (md5Hash.substring(0, 8) + "-" + md5Hash.substring(8, 12) + "-4" + md5Hash.substring(13, 16) + "-" + md5Hash.substring(16, 20) + "-" + md5Hash.substring(20)).toLowerCase();
949
+ }
950
+
776
951
  var SENTRY_SAAS_URL = "https://sentry.io";
777
952
  function normalizeUserOptions(userOptions) {
778
- var _userOptions$org, _userOptions$project, _ref, _userOptions$release, _ref2, _userOptions$url, _userOptions$finalize, _userOptions$cleanArt, _userOptions$dryRun, _userOptions$debug, _userOptions$silent, _userOptions$telemetr, _userOptions$injectRe;
953
+ var _userOptions$org, _userOptions$project, _ref, _userOptions$release, _ref2, _userOptions$url, _userOptions$finalize, _userOptions$cleanArt, _userOptions$dryRun, _userOptions$debug, _userOptions$silent, _userOptions$telemetr, _userOptions$injectRe, _userOptions$injectRe2, _userOptions$uploadSo, _userOptions$_experim;
779
954
 
780
955
  var options = {
781
956
  // include is the only strictly required option
@@ -804,6 +979,9 @@ function normalizeUserOptions(userOptions) {
804
979
  silent: (_userOptions$silent = userOptions.silent) !== null && _userOptions$silent !== void 0 ? _userOptions$silent : false,
805
980
  telemetry: (_userOptions$telemetr = userOptions.telemetry) !== null && _userOptions$telemetr !== void 0 ? _userOptions$telemetr : true,
806
981
  injectReleasesMap: (_userOptions$injectRe = userOptions.injectReleasesMap) !== null && _userOptions$injectRe !== void 0 ? _userOptions$injectRe : false,
982
+ injectRelease: (_userOptions$injectRe2 = userOptions.injectRelease) !== null && _userOptions$injectRe2 !== void 0 ? _userOptions$injectRe2 : true,
983
+ uploadSourceMaps: (_userOptions$uploadSo = userOptions.uploadSourceMaps) !== null && _userOptions$uploadSo !== void 0 ? _userOptions$uploadSo : true,
984
+ _experiments: (_userOptions$_experim = userOptions._experiments) !== null && _userOptions$_experim !== void 0 ? _userOptions$_experim : {},
807
985
  // These options and can also be set via env variables or the config file.
808
986
  // If they're set in the options, we simply pass them to the CLI constructor.
809
987
  // Sentry CLI will internally query env variables and read its config file if
@@ -943,7 +1121,7 @@ function makeSentryClient(dsn, allowedToSendTelemetryPromise, userProject) {
943
1121
  // a dashboard.
944
1122
  // Yes, this is slightly abusing the purpose of this field.
945
1123
  dist: userProject,
946
- release: "0.4.0",
1124
+ release: "0.5.1",
947
1125
  integrations: [],
948
1126
  tracePropagationTargets: ["sentry.io/api"],
949
1127
  stackParser: node.defaultStackParser,
@@ -1045,7 +1223,8 @@ function addPluginOptionInformationToHub(options, hub, bundler) {
1045
1223
  dryRun = options.dryRun,
1046
1224
  errorHandler = options.errorHandler,
1047
1225
  deploy = options.deploy,
1048
- include = options.include;
1226
+ include = options.include,
1227
+ _experiments = options._experiments;
1049
1228
  hub.setTag("include", include.length > 1 ? "multiple-entries" : "single-entry"); // Optional release pipeline steps
1050
1229
 
1051
1230
  if (cleanArtifacts) {
@@ -1077,6 +1256,10 @@ function addPluginOptionInformationToHub(options, hub, bundler) {
1077
1256
  hub.setTag("error-handler", "custom");
1078
1257
  }
1079
1258
 
1259
+ if (_experiments.debugIdUpload) {
1260
+ hub.setTag("debug-id-upload", true);
1261
+ }
1262
+
1080
1263
  hub.setTag("node", process.version);
1081
1264
  hub.setTags({
1082
1265
  organization: org,
@@ -1288,74 +1471,141 @@ function _uploadSourceMaps() {
1288
1471
  while (1) {
1289
1472
  switch (_context3.prev = _context3.next) {
1290
1473
  case 0:
1474
+ if (options.uploadSourceMaps) {
1475
+ _context3.next = 3;
1476
+ break;
1477
+ }
1478
+
1479
+ logger.debug("Skipping source maps upload.");
1480
+ return _context3.abrupt("return");
1481
+
1482
+ case 3:
1291
1483
  span = addSpanToTransaction(ctx, "function.plugin.upload_sourcemaps");
1292
1484
  ctx.logger.info("Uploading Sourcemaps."); // Since our internal include entries contain all top-level sourcemaps options,
1293
1485
  // we only need to pass the include option here.
1294
1486
 
1295
- _context3.prev = 2;
1296
- _context3.next = 5;
1487
+ _context3.prev = 5;
1488
+ _context3.next = 8;
1297
1489
  return ctx.cli.releases.uploadSourceMaps(releaseName, {
1298
1490
  include: options.include,
1299
1491
  dist: options.dist
1300
1492
  });
1301
1493
 
1302
- case 5:
1303
- _context3.next = 11;
1494
+ case 8:
1495
+ _context3.next = 14;
1304
1496
  break;
1305
1497
 
1306
- case 7:
1307
- _context3.prev = 7;
1308
- _context3.t0 = _context3["catch"](2);
1498
+ case 10:
1499
+ _context3.prev = 10;
1500
+ _context3.t0 = _context3["catch"](5);
1309
1501
  ctx.hub.captureException(new Error("CLI Error: Uploading source maps failed"));
1310
1502
  throw _context3.t0;
1311
1503
 
1312
- case 11:
1313
- _context3.prev = 11;
1504
+ case 14:
1505
+ _context3.prev = 14;
1314
1506
  span === null || span === void 0 ? void 0 : span.finish();
1315
- return _context3.finish(11);
1507
+ return _context3.finish(14);
1316
1508
 
1317
- case 14:
1509
+ case 17:
1318
1510
  ctx.hub.addBreadcrumb({
1319
1511
  level: "info",
1320
1512
  message: "Successfully uploaded source maps."
1321
1513
  });
1322
1514
  ctx.logger.info("Successfully uploaded source maps.");
1323
1515
 
1324
- case 16:
1516
+ case 19:
1325
1517
  case "end":
1326
1518
  return _context3.stop();
1327
1519
  }
1328
1520
  }
1329
- }, _callee3, null, [[2, 7, 11, 14]]);
1521
+ }, _callee3, null, [[5, 10, 14, 17]]);
1330
1522
  }));
1331
1523
  return _uploadSourceMaps.apply(this, arguments);
1332
1524
  }
1333
1525
 
1334
- function setCommits(_x10, _x11, _x12) {
1526
+ function uploadDebugIdSourcemaps(_x10, _x11, _x12, _x13) {
1527
+ return _uploadDebugIdSourcemaps.apply(this, arguments);
1528
+ }
1529
+
1530
+ function _uploadDebugIdSourcemaps() {
1531
+ _uploadDebugIdSourcemaps = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(options, ctx, folderPathToUpload, releaseName) {
1532
+ var span;
1533
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
1534
+ while (1) {
1535
+ switch (_context4.prev = _context4.next) {
1536
+ case 0:
1537
+ span = addSpanToTransaction(ctx, "function.plugin.upload_debug_id_sourcemaps");
1538
+ ctx.logger.info("Uploading debug ID Sourcemaps."); // Since our internal include entries contain all top-level sourcemaps options,
1539
+ // we only need to pass the include option here.
1540
+
1541
+ _context4.prev = 2;
1542
+ _context4.next = 5;
1543
+ return ctx.cli.releases.uploadSourceMaps(releaseName, {
1544
+ include: [{
1545
+ paths: [folderPathToUpload],
1546
+ rewrite: false,
1547
+ dist: options.dist
1548
+ }],
1549
+ useArtifactBundle: true
1550
+ });
1551
+
1552
+ case 5:
1553
+ _context4.next = 11;
1554
+ break;
1555
+
1556
+ case 7:
1557
+ _context4.prev = 7;
1558
+ _context4.t0 = _context4["catch"](2);
1559
+ ctx.hub.captureException(new Error("CLI Error: Uploading debug ID source maps failed"));
1560
+ throw _context4.t0;
1561
+
1562
+ case 11:
1563
+ _context4.prev = 11;
1564
+ span === null || span === void 0 ? void 0 : span.finish();
1565
+ return _context4.finish(11);
1566
+
1567
+ case 14:
1568
+ ctx.hub.addBreadcrumb({
1569
+ level: "info",
1570
+ message: "Successfully uploaded debug ID source maps."
1571
+ });
1572
+ ctx.logger.info("Successfully uploaded debug ID source maps.");
1573
+
1574
+ case 16:
1575
+ case "end":
1576
+ return _context4.stop();
1577
+ }
1578
+ }
1579
+ }, _callee4, null, [[2, 7, 11, 14]]);
1580
+ }));
1581
+ return _uploadDebugIdSourcemaps.apply(this, arguments);
1582
+ }
1583
+
1584
+ function setCommits(_x14, _x15, _x16) {
1335
1585
  return _setCommits.apply(this, arguments);
1336
1586
  }
1337
1587
 
1338
1588
  function _setCommits() {
1339
- _setCommits = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(options, ctx, releaseName) {
1589
+ _setCommits = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(options, ctx, releaseName) {
1340
1590
  var span, _options$setCommits, auto, repo, commit, previousCommit, ignoreMissing, ignoreEmpty;
1341
1591
 
1342
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
1592
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
1343
1593
  while (1) {
1344
- switch (_context4.prev = _context4.next) {
1594
+ switch (_context5.prev = _context5.next) {
1345
1595
  case 0:
1346
1596
  if (options.setCommits) {
1347
- _context4.next = 3;
1597
+ _context5.next = 3;
1348
1598
  break;
1349
1599
  }
1350
1600
 
1351
1601
  logger.debug("Skipping setting commits to release.");
1352
- return _context4.abrupt("return");
1602
+ return _context5.abrupt("return");
1353
1603
 
1354
1604
  case 3:
1355
1605
  span = addSpanToTransaction(ctx, "function.plugin.set_commits");
1356
1606
  _options$setCommits = options.setCommits, auto = _options$setCommits.auto, repo = _options$setCommits.repo, commit = _options$setCommits.commit, previousCommit = _options$setCommits.previousCommit, ignoreMissing = _options$setCommits.ignoreMissing, ignoreEmpty = _options$setCommits.ignoreEmpty;
1357
- _context4.prev = 5;
1358
- _context4.next = 8;
1607
+ _context5.prev = 5;
1608
+ _context5.next = 8;
1359
1609
  return ctx.cli.releases.setCommits(releaseName, {
1360
1610
  commit: commit,
1361
1611
  previousCommit: previousCommit,
@@ -1366,46 +1616,46 @@ function _setCommits() {
1366
1616
  });
1367
1617
 
1368
1618
  case 8:
1369
- _context4.next = 14;
1619
+ _context5.next = 14;
1370
1620
  break;
1371
1621
 
1372
1622
  case 10:
1373
- _context4.prev = 10;
1374
- _context4.t0 = _context4["catch"](5);
1623
+ _context5.prev = 10;
1624
+ _context5.t0 = _context5["catch"](5);
1375
1625
  ctx.hub.captureException(new Error("CLI Error: Setting commits failed"));
1376
- throw _context4.t0;
1626
+ throw _context5.t0;
1377
1627
 
1378
1628
  case 14:
1379
- _context4.prev = 14;
1629
+ _context5.prev = 14;
1380
1630
  span === null || span === void 0 ? void 0 : span.finish();
1381
- return _context4.finish(14);
1631
+ return _context5.finish(14);
1382
1632
 
1383
1633
  case 17:
1384
1634
  ctx.logger.info("Successfully set commits.");
1385
1635
 
1386
1636
  case 18:
1387
1637
  case "end":
1388
- return _context4.stop();
1638
+ return _context5.stop();
1389
1639
  }
1390
1640
  }
1391
- }, _callee4, null, [[5, 10, 14, 17]]);
1641
+ }, _callee5, null, [[5, 10, 14, 17]]);
1392
1642
  }));
1393
1643
  return _setCommits.apply(this, arguments);
1394
1644
  }
1395
1645
 
1396
- function finalizeRelease(_x13, _x14, _x15) {
1646
+ function finalizeRelease(_x17, _x18, _x19) {
1397
1647
  return _finalizeRelease.apply(this, arguments);
1398
1648
  }
1399
1649
 
1400
1650
  function _finalizeRelease() {
1401
- _finalizeRelease = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(options, ctx, releaseName) {
1651
+ _finalizeRelease = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(options, ctx, releaseName) {
1402
1652
  var span;
1403
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
1653
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
1404
1654
  while (1) {
1405
- switch (_context5.prev = _context5.next) {
1655
+ switch (_context6.prev = _context6.next) {
1406
1656
  case 0:
1407
1657
  if (options.finalize) {
1408
- _context5.next = 4;
1658
+ _context6.next = 4;
1409
1659
  break;
1410
1660
  }
1411
1661
 
@@ -1414,28 +1664,28 @@ function _finalizeRelease() {
1414
1664
  message: "Skipping release finalization."
1415
1665
  });
1416
1666
  logger.debug("Skipping release finalization.");
1417
- return _context5.abrupt("return");
1667
+ return _context6.abrupt("return");
1418
1668
 
1419
1669
  case 4:
1420
1670
  span = addSpanToTransaction(ctx, "function.plugin.finalize_release");
1421
- _context5.prev = 5;
1422
- _context5.next = 8;
1671
+ _context6.prev = 5;
1672
+ _context6.next = 8;
1423
1673
  return ctx.cli.releases.finalize(releaseName);
1424
1674
 
1425
1675
  case 8:
1426
- _context5.next = 14;
1676
+ _context6.next = 14;
1427
1677
  break;
1428
1678
 
1429
1679
  case 10:
1430
- _context5.prev = 10;
1431
- _context5.t0 = _context5["catch"](5);
1680
+ _context6.prev = 10;
1681
+ _context6.t0 = _context6["catch"](5);
1432
1682
  ctx.hub.captureException(new Error("CLI Error: Finalizing release failed"));
1433
- throw _context5.t0;
1683
+ throw _context6.t0;
1434
1684
 
1435
1685
  case 14:
1436
- _context5.prev = 14;
1686
+ _context6.prev = 14;
1437
1687
  span === null || span === void 0 ? void 0 : span.finish();
1438
- return _context5.finish(14);
1688
+ return _context6.finish(14);
1439
1689
 
1440
1690
  case 17:
1441
1691
  ctx.hub.addBreadcrumb({
@@ -1446,28 +1696,28 @@ function _finalizeRelease() {
1446
1696
 
1447
1697
  case 19:
1448
1698
  case "end":
1449
- return _context5.stop();
1699
+ return _context6.stop();
1450
1700
  }
1451
1701
  }
1452
- }, _callee5, null, [[5, 10, 14, 17]]);
1702
+ }, _callee6, null, [[5, 10, 14, 17]]);
1453
1703
  }));
1454
1704
  return _finalizeRelease.apply(this, arguments);
1455
1705
  }
1456
1706
 
1457
- function addDeploy(_x16, _x17, _x18) {
1707
+ function addDeploy(_x20, _x21, _x22) {
1458
1708
  return _addDeploy.apply(this, arguments);
1459
1709
  }
1460
1710
 
1461
1711
  function _addDeploy() {
1462
- _addDeploy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(options, ctx, releaseName) {
1712
+ _addDeploy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(options, ctx, releaseName) {
1463
1713
  var span, _options$deploy, env, started, finished, time, name, url;
1464
1714
 
1465
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
1715
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
1466
1716
  while (1) {
1467
- switch (_context6.prev = _context6.next) {
1717
+ switch (_context7.prev = _context7.next) {
1468
1718
  case 0:
1469
1719
  if (options.deploy) {
1470
- _context6.next = 4;
1720
+ _context7.next = 4;
1471
1721
  break;
1472
1722
  }
1473
1723
 
@@ -1476,13 +1726,13 @@ function _addDeploy() {
1476
1726
  message: "Skipping adding deploy info to release."
1477
1727
  });
1478
1728
  logger.debug("Skipping adding deploy info to release.");
1479
- return _context6.abrupt("return");
1729
+ return _context7.abrupt("return");
1480
1730
 
1481
1731
  case 4:
1482
1732
  span = addSpanToTransaction(ctx, "function.plugin.deploy");
1483
1733
  _options$deploy = options.deploy, env = _options$deploy.env, started = _options$deploy.started, finished = _options$deploy.finished, time = _options$deploy.time, name = _options$deploy.name, url = _options$deploy.url;
1484
- _context6.prev = 6;
1485
- _context6.next = 9;
1734
+ _context7.prev = 6;
1735
+ _context7.next = 9;
1486
1736
  return ctx.cli.releases.newDeploy(releaseName, {
1487
1737
  env: env,
1488
1738
  started: started,
@@ -1493,19 +1743,19 @@ function _addDeploy() {
1493
1743
  });
1494
1744
 
1495
1745
  case 9:
1496
- _context6.next = 15;
1746
+ _context7.next = 15;
1497
1747
  break;
1498
1748
 
1499
1749
  case 11:
1500
- _context6.prev = 11;
1501
- _context6.t0 = _context6["catch"](6);
1750
+ _context7.prev = 11;
1751
+ _context7.t0 = _context7["catch"](6);
1502
1752
  ctx.hub.captureException(new Error("CLI Error: Adding deploy info failed"));
1503
- throw _context6.t0;
1753
+ throw _context7.t0;
1504
1754
 
1505
1755
  case 15:
1506
- _context6.prev = 15;
1756
+ _context7.prev = 15;
1507
1757
  span === null || span === void 0 ? void 0 : span.finish();
1508
- return _context6.finish(15);
1758
+ return _context7.finish(15);
1509
1759
 
1510
1760
  case 18:
1511
1761
  ctx.hub.addBreadcrumb({
@@ -1516,10 +1766,10 @@ function _addDeploy() {
1516
1766
 
1517
1767
  case 20:
1518
1768
  case "end":
1519
- return _context6.stop();
1769
+ return _context7.stop();
1520
1770
  }
1521
1771
  }
1522
- }, _callee6, null, [[6, 11, 15, 18]]);
1772
+ }, _callee7, null, [[6, 11, 15, 18]]);
1523
1773
  }));
1524
1774
  return _addDeploy.apply(this, arguments);
1525
1775
  }
@@ -1650,18 +1900,261 @@ function getDryRunCLI(cli, logger) {
1650
1900
  };
1651
1901
  }
1652
1902
 
1903
+ var DEBUG_ID_INJECTOR_SNIPPET = ';!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]="__SENTRY_DEBUG_ID__",e._sentryDebugIdIdentifier="sentry-dbid-__SENTRY_DEBUG_ID__")}catch(e){}}();';
1904
+ function injectDebugIdSnippetIntoChunk(code) {
1905
+ var _code$match;
1906
+
1907
+ var debugId = stringToUUID(code); // generate a deterministic debug ID
1908
+
1909
+ var ms = new MagicString__default["default"](code);
1910
+ var codeToInject = DEBUG_ID_INJECTOR_SNIPPET.replace(/__SENTRY_DEBUG_ID__/g, debugId); // We need to be careful not to inject the snippet before any `"use strict";`s.
1911
+ // As an additional complication `"use strict";`s may come after any number of comments.
1912
+
1913
+ var commentUseStrictRegex = /^(?:\s*|\/\*(.|\r|\n)*?\*\/|\/\/.*?[\n\r])*(?:"use strict";|'use strict';)?/;
1914
+
1915
+ if ((_code$match = code.match(commentUseStrictRegex)) !== null && _code$match !== void 0 && _code$match[0]) {
1916
+ // Add injected code after any comments or "use strict" at the beginning of the bundle.
1917
+ ms.replace(commentUseStrictRegex, function (match) {
1918
+ return "".concat(match).concat(codeToInject);
1919
+ });
1920
+ } else {
1921
+ // ms.replace() doesn't work when there is an empty string match (which happens if
1922
+ // there is neither, a comment, nor a "use strict" at the top of the chunk) so we
1923
+ // need this special case here.
1924
+ ms.prepend(codeToInject);
1925
+ }
1926
+
1927
+ return {
1928
+ code: ms.toString(),
1929
+ map: ms.generateMap()
1930
+ };
1931
+ }
1932
+ function prepareBundleForDebugIdUpload(_x, _x2, _x3, _x4) {
1933
+ return _prepareBundleForDebugIdUpload.apply(this, arguments);
1934
+ }
1935
+ /**
1936
+ * Looks for a particular string pattern (`sdbid-[debug ID]`) in the bundle
1937
+ * source and extracts the bundle's debug ID from it.
1938
+ *
1939
+ * The string pattern is injected via the debug ID injection snipped.
1940
+ */
1941
+
1942
+ function _prepareBundleForDebugIdUpload() {
1943
+ _prepareBundleForDebugIdUpload = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(bundleFilePath, uploadFolder, uniqueUploadName, logger) {
1944
+ var bundleContent, debugId, writeSourceFilePromise, writeSourceMapFilePromise;
1945
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
1946
+ while (1) {
1947
+ switch (_context2.prev = _context2.next) {
1948
+ case 0:
1949
+ _context2.prev = 0;
1950
+ _context2.next = 3;
1951
+ return util__namespace.promisify(fs__namespace.readFile)(bundleFilePath, "utf8");
1952
+
1953
+ case 3:
1954
+ bundleContent = _context2.sent;
1955
+ _context2.next = 10;
1956
+ break;
1957
+
1958
+ case 6:
1959
+ _context2.prev = 6;
1960
+ _context2.t0 = _context2["catch"](0);
1961
+ logger.warn("Could not read bundle to determine debug ID and source map: ".concat(bundleFilePath));
1962
+ return _context2.abrupt("return");
1963
+
1964
+ case 10:
1965
+ debugId = determineDebugIdFromBundleSource(bundleContent);
1966
+
1967
+ if (!(debugId === undefined)) {
1968
+ _context2.next = 14;
1969
+ break;
1970
+ }
1971
+
1972
+ logger.warn("Could not determine debug ID from bundle: ".concat(bundleFilePath));
1973
+ return _context2.abrupt("return");
1974
+
1975
+ case 14:
1976
+ bundleContent += "\n//# debugId=".concat(debugId);
1977
+ writeSourceFilePromise = util__namespace.promisify(fs__namespace.writeFile)(path__namespace.join(uploadFolder, "".concat(uniqueUploadName, ".js")), bundleContent, "utf-8");
1978
+ writeSourceMapFilePromise = determineSourceMapPathFromBundle(bundleFilePath, bundleContent, logger).then( /*#__PURE__*/function () {
1979
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(sourceMapPath) {
1980
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
1981
+ while (1) {
1982
+ switch (_context.prev = _context.next) {
1983
+ case 0:
1984
+ if (!sourceMapPath) {
1985
+ _context.next = 4;
1986
+ break;
1987
+ }
1988
+
1989
+ _context.next = 3;
1990
+ return prepareSourceMapForDebugIdUpload(sourceMapPath, path__namespace.join(uploadFolder, "".concat(uniqueUploadName, ".js.map")), debugId, logger);
1991
+
1992
+ case 3:
1993
+ return _context.abrupt("return", _context.sent);
1994
+
1995
+ case 4:
1996
+ case "end":
1997
+ return _context.stop();
1998
+ }
1999
+ }
2000
+ }, _callee);
2001
+ }));
2002
+
2003
+ return function (_x12) {
2004
+ return _ref.apply(this, arguments);
2005
+ };
2006
+ }());
2007
+ return _context2.abrupt("return", Promise.all([writeSourceFilePromise, writeSourceMapFilePromise]));
2008
+
2009
+ case 18:
2010
+ case "end":
2011
+ return _context2.stop();
2012
+ }
2013
+ }
2014
+ }, _callee2, null, [[0, 6]]);
2015
+ }));
2016
+ return _prepareBundleForDebugIdUpload.apply(this, arguments);
2017
+ }
2018
+
2019
+ function determineDebugIdFromBundleSource(code) {
2020
+ var match = code.match(/sentry-dbid-([0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12})/);
2021
+
2022
+ if (match) {
2023
+ return match[1];
2024
+ } else {
2025
+ return undefined;
2026
+ }
2027
+ }
2028
+ /**
2029
+ * Applies a set of heuristics to find the source map for a particular bundle.
2030
+ *
2031
+ * @returns the path to the bundle's source map or `undefined` if none could be found.
2032
+ */
2033
+
2034
+
2035
+ function determineSourceMapPathFromBundle(_x5, _x6, _x7) {
2036
+ return _determineSourceMapPathFromBundle.apply(this, arguments);
2037
+ }
2038
+ /**
2039
+ * Reads a source map, injects debug ID fields, and writes the source map to the target path.
2040
+ */
2041
+
2042
+
2043
+ function _determineSourceMapPathFromBundle() {
2044
+ _determineSourceMapPathFromBundle = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(bundlePath, bundleSource, logger) {
2045
+ var sourceMappingUrlMatch, sourceMappingUrl, adjacentSourceMapFilePath;
2046
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
2047
+ while (1) {
2048
+ switch (_context3.prev = _context3.next) {
2049
+ case 0:
2050
+ // 1. try to find source map at `sourceMappingURL` location
2051
+ sourceMappingUrlMatch = bundleSource.match(/^\/\/# sourceMappingURL=(.*)$/);
2052
+
2053
+ if (!sourceMappingUrlMatch) {
2054
+ _context3.next = 8;
2055
+ break;
2056
+ }
2057
+
2058
+ sourceMappingUrl = path__namespace.normalize(sourceMappingUrlMatch[1]);
2059
+
2060
+ if (!path__namespace.isAbsolute(sourceMappingUrl)) {
2061
+ _context3.next = 7;
2062
+ break;
2063
+ }
2064
+
2065
+ return _context3.abrupt("return", sourceMappingUrl);
2066
+
2067
+ case 7:
2068
+ return _context3.abrupt("return", path__namespace.join(path__namespace.dirname(bundlePath), sourceMappingUrl));
2069
+
2070
+ case 8:
2071
+ _context3.prev = 8;
2072
+ adjacentSourceMapFilePath = bundlePath + ".map";
2073
+ _context3.next = 12;
2074
+ return util__namespace.promisify(fs__namespace.access)(adjacentSourceMapFilePath);
2075
+
2076
+ case 12:
2077
+ return _context3.abrupt("return", adjacentSourceMapFilePath);
2078
+
2079
+ case 15:
2080
+ _context3.prev = 15;
2081
+ _context3.t0 = _context3["catch"](8);
2082
+
2083
+ case 17:
2084
+ logger.warn("Could not determine source map path for bundle: ".concat(bundlePath));
2085
+ return _context3.abrupt("return", undefined);
2086
+
2087
+ case 19:
2088
+ case "end":
2089
+ return _context3.stop();
2090
+ }
2091
+ }
2092
+ }, _callee3, null, [[8, 15]]);
2093
+ }));
2094
+ return _determineSourceMapPathFromBundle.apply(this, arguments);
2095
+ }
2096
+
2097
+ function prepareSourceMapForDebugIdUpload(_x8, _x9, _x10, _x11) {
2098
+ return _prepareSourceMapForDebugIdUpload.apply(this, arguments);
2099
+ }
2100
+
2101
+ function _prepareSourceMapForDebugIdUpload() {
2102
+ _prepareSourceMapForDebugIdUpload = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(sourceMapPath, targetPath, debugId, logger) {
2103
+ var sourceMapFileContent, map;
2104
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
2105
+ while (1) {
2106
+ switch (_context4.prev = _context4.next) {
2107
+ case 0:
2108
+ _context4.prev = 0;
2109
+ _context4.next = 3;
2110
+ return util__namespace.promisify(fs__namespace.readFile)(sourceMapPath, {
2111
+ encoding: "utf8"
2112
+ });
2113
+
2114
+ case 3:
2115
+ sourceMapFileContent = _context4.sent;
2116
+ map = JSON.parse(sourceMapFileContent); // For now we write both fields until we know what will become the standard - if ever.
2117
+
2118
+ map["debug_id"] = debugId;
2119
+ map["debugId"] = debugId;
2120
+ _context4.next = 9;
2121
+ return util__namespace.promisify(fs__namespace.writeFile)(targetPath, JSON.stringify(map), {
2122
+ encoding: "utf8"
2123
+ });
2124
+
2125
+ case 9:
2126
+ _context4.next = 14;
2127
+ break;
2128
+
2129
+ case 11:
2130
+ _context4.prev = 11;
2131
+ _context4.t0 = _context4["catch"](0);
2132
+ logger.warn("Failed to prepare source map for debug ID upload: ".concat(sourceMapPath));
2133
+
2134
+ case 14:
2135
+ case "end":
2136
+ return _context4.stop();
2137
+ }
2138
+ }
2139
+ }, _callee4, null, [[0, 11]]);
2140
+ }));
2141
+ return _prepareSourceMapForDebugIdUpload.apply(this, arguments);
2142
+ }
2143
+
1653
2144
  var ALLOWED_TRANSFORMATION_FILE_ENDINGS = [".js", ".ts", ".jsx", ".tsx", ".mjs"];
2145
+
2146
+ var releaseInjectionFilePath = require.resolve("@sentry/bundler-plugin-core/sentry-release-injection-file");
1654
2147
  /**
1655
2148
  * The sentry bundler plugin concerns itself with two things:
1656
2149
  * - Release injection
1657
2150
  * - Sourcemaps upload
1658
2151
  *
1659
2152
  * Release injection:
1660
- * Per default the sentry bundler plugin will inject a global `SENTRY_RELEASE` into
1661
- * each JavaScript/TypeScript entrypoint. On a technical level this is done by identifying
1662
- * entrypoints in the `resolveId` hook and prepending user code in the `transform` hook.
1663
- * If a user wants to inject the release into a particular set of modules instead,
1664
- * they can use the `releaseInjectionTargets` option.
2153
+ * Per default the sentry bundler plugin will inject a global `SENTRY_RELEASE` into each JavaScript/TypeScript module
2154
+ * that is part of the bundle. On a technical level this is done by appending an import (`import "sentry-release-injector;"`)
2155
+ * to all entrypoint files of the user code (see `transformInclude` and `transform` hooks). This import is then resolved
2156
+ * by the sentry plugin to a virtual module that sets the global variable (see `resolveId` and `load` hooks).
2157
+ * If a user wants to inject the release into a particular set of modules they can use the `releaseInjectionTargets` option.
1665
2158
  *
1666
2159
  * Source maps upload:
1667
2160
  *
@@ -1679,6 +2172,7 @@ var ALLOWED_TRANSFORMATION_FILE_ENDINGS = [".js", ".ts", ".jsx", ".tsx", ".mjs"]
1679
2172
  * This release creation pipeline relies on Sentry CLI to execute the different steps.
1680
2173
  */
1681
2174
 
2175
+
1682
2176
  var unplugin = unplugin$1.createUnplugin(function (options, unpluginMetaContext) {
1683
2177
  var internalOptions = normalizeUserOptions(options);
1684
2178
  var allowedToSendTelemetryPromise = shouldSendTelemetry(internalOptions);
@@ -1714,7 +2208,6 @@ var unplugin = unplugin$1.createUnplugin(function (options, unpluginMetaContext)
1714
2208
  });
1715
2209
  var transaction;
1716
2210
  var releaseInjectionSpan;
1717
- var absolueEntrypointPaths = new Set();
1718
2211
  return {
1719
2212
  name: "sentry-plugin",
1720
2213
  enforce: "pre",
@@ -1751,10 +2244,14 @@ var unplugin = unplugin$1.createUnplugin(function (options, unpluginMetaContext)
1751
2244
  });
1752
2245
  }
1753
2246
 
1754
- _context.next = 7;
2247
+ if (process.cwd().match(/\\node_modules\\|\/node_modules\//)) {
2248
+ logger.warn("Running Sentry plugin from within a `node_modules` folder. Some features may not work.");
2249
+ }
2250
+
2251
+ _context.next = 8;
1755
2252
  return releaseNamePromise;
1756
2253
 
1757
- case 7:
2254
+ case 8:
1758
2255
  releaseName = _context.sent;
1759
2256
 
1760
2257
  // At this point, we either have determined a release or we have to bail
@@ -1773,7 +2270,7 @@ var unplugin = unplugin$1.createUnplugin(function (options, unpluginMetaContext)
1773
2270
  cli: cli
1774
2271
  }, "function.plugin.inject_release", "Release injection");
1775
2272
 
1776
- case 11:
2273
+ case 12:
1777
2274
  case "end":
1778
2275
  return _context.stop();
1779
2276
  }
@@ -1800,11 +2297,6 @@ var unplugin = unplugin$1.createUnplugin(function (options, unpluginMetaContext)
1800
2297
  importer: importer,
1801
2298
  isEntry: isEntry
1802
2299
  });
1803
-
1804
- if (isEntry) {
1805
- absolueEntrypointPaths.add(path__default["default"].resolve(path__default["default"].normalize(id)));
1806
- }
1807
-
1808
2300
  return undefined;
1809
2301
  },
1810
2302
 
@@ -1819,11 +2311,20 @@ var unplugin = unplugin$1.createUnplugin(function (options, unpluginMetaContext)
1819
2311
  transformInclude: function transformInclude(id) {
1820
2312
  logger.debug('Called "transformInclude":', {
1821
2313
  id: id
1822
- }); // We normalize the id because vite always passes `id` as a unix style path which causes problems when a user passes
2314
+ });
2315
+
2316
+ if (id.match(/\\node_modules\\|\/node_modules\//)) {
2317
+ return false; // never transform 3rd party modules
2318
+ } // We normalize the id because vite always passes `id` as a unix style path which causes problems when a user passes
1823
2319
  // a windows style path to `releaseInjectionTargets`
1824
2320
 
2321
+
1825
2322
  var normalizedId = path__default["default"].normalize(id);
1826
2323
 
2324
+ if (id.includes("sentry-release-injection-file")) {
2325
+ return true;
2326
+ }
2327
+
1827
2328
  if (internalOptions.releaseInjectionTargets) {
1828
2329
  // If there's an `releaseInjectionTargets` option transform (ie. inject the release varible) when the file path matches the option.
1829
2330
  if (typeof internalOptions.releaseInjectionTargets === "function") {
@@ -1838,14 +2339,12 @@ var unplugin = unplugin$1.createUnplugin(function (options, unpluginMetaContext)
1838
2339
  return normalizedId === normalizedEntry;
1839
2340
  }
1840
2341
  });
1841
- } else if (absolueEntrypointPaths.has(normalizedId)) {
2342
+ } else {
1842
2343
  var pathIsOrdinary = !normalizedId.includes("?") && !normalizedId.includes("#");
1843
2344
  var pathHasAllowedFileEnding = ALLOWED_TRANSFORMATION_FILE_ENDINGS.some(function (allowedFileEnding) {
1844
2345
  return normalizedId.endsWith(allowedFileEnding);
1845
2346
  });
1846
2347
  return pathIsOrdinary && pathHasAllowedFileEnding;
1847
- } else {
1848
- return false;
1849
2348
  }
1850
2349
  },
1851
2350
 
@@ -1866,43 +2365,70 @@ var unplugin = unplugin$1.createUnplugin(function (options, unpluginMetaContext)
1866
2365
  case 0:
1867
2366
  logger.debug('Called "transform":', {
1868
2367
  id: id
1869
- }); // The MagicString library allows us to generate sourcemaps for the changes we make to the user code.
2368
+ });
2369
+
2370
+ if (internalOptions.injectRelease) {
2371
+ _context2.next = 3;
2372
+ break;
2373
+ }
1870
2374
 
2375
+ return _context2.abrupt("return");
2376
+
2377
+ case 3:
2378
+ // The MagicString library allows us to generate sourcemaps for the changes we make to the user code.
1871
2379
  ms = new MagicString__default["default"](code);
2380
+
2381
+ if (!code.includes("_sentry_release_injection_file")) {
2382
+ _context2.next = 19;
2383
+ break;
2384
+ }
2385
+
1872
2386
  _context2.t0 = ms;
1873
2387
  _context2.t1 = generateGlobalInjectorCode;
1874
- _context2.next = 6;
2388
+ _context2.next = 9;
1875
2389
  return releaseNamePromise;
1876
2390
 
1877
- case 6:
2391
+ case 9:
1878
2392
  _context2.t2 = _context2.sent;
1879
2393
  _context2.t3 = internalOptions.injectReleasesMap;
1880
- _context2.t4 = internalOptions.org;
1881
- _context2.t5 = internalOptions.project;
1882
- _context2.t6 = {
2394
+ _context2.t4 = internalOptions._experiments.injectBuildInformation || false;
2395
+ _context2.t5 = internalOptions.org;
2396
+ _context2.t6 = internalOptions.project;
2397
+ _context2.t7 = {
1883
2398
  release: _context2.t2,
1884
2399
  injectReleasesMap: _context2.t3,
1885
- org: _context2.t4,
1886
- project: _context2.t5
2400
+ injectBuildInformation: _context2.t4,
2401
+ org: _context2.t5,
2402
+ project: _context2.t6
1887
2403
  };
1888
- _context2.t7 = (0, _context2.t1)(_context2.t6);
2404
+ _context2.t8 = (0, _context2.t1)(_context2.t7);
2405
+
2406
+ _context2.t0.append.call(_context2.t0, _context2.t8);
1889
2407
 
1890
- _context2.t0.prepend.call(_context2.t0, _context2.t7);
2408
+ _context2.next = 20;
2409
+ break;
2410
+
2411
+ case 19:
2412
+ // Appending instead of prepending has less probability of mucking with user's source maps.
2413
+ // Luckily import statements get hoisted to the top anyways.
2414
+ // The import needs to be an absolute path because Rollup doesn't bundle stuff in `node_modules` by default when bundling CJS (unless the import path is absolute or the node-resolve-plugin is used).
2415
+ ms.append(";\nimport \"".concat(releaseInjectionFilePath.replace(/\\/g, "\\\\"), "\";"));
1891
2416
 
2417
+ case 20:
1892
2418
  if (!(unpluginMetaContext.framework === "esbuild")) {
1893
- _context2.next = 17;
2419
+ _context2.next = 24;
1894
2420
  break;
1895
2421
  }
1896
2422
 
1897
2423
  return _context2.abrupt("return", ms.toString());
1898
2424
 
1899
- case 17:
2425
+ case 24:
1900
2426
  return _context2.abrupt("return", {
1901
2427
  code: ms.toString(),
1902
2428
  map: ms.generateMap()
1903
2429
  });
1904
2430
 
1905
- case 18:
2431
+ case 25:
1906
2432
  case "end":
1907
2433
  return _context2.stop();
1908
2434
  }
@@ -1916,14 +2442,14 @@ var unplugin = unplugin$1.createUnplugin(function (options, unpluginMetaContext)
1916
2442
  * Sentry.io, uploading sourcemaps, associating commits and deploys and finalizing the release)
1917
2443
  */
1918
2444
  writeBundle: function writeBundle() {
1919
- return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
2445
+ return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
1920
2446
  var _releaseInjectionSpan;
1921
2447
 
1922
- var releasePipelineSpan, ctx, releaseName, _transaction, _transaction2, _transaction3;
2448
+ var releasePipelineSpan, ctx, releaseName, tmpUploadFolder, _transaction, debugIdChunkFilePaths, sourceFileUploadFolderPromise, _transaction2, _transaction3;
1923
2449
 
1924
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
2450
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
1925
2451
  while (1) {
1926
- switch (_context3.prev = _context3.next) {
2452
+ switch (_context4.prev = _context4.next) {
1927
2453
  case 0:
1928
2454
  logger.debug('Called "writeBundle"');
1929
2455
  (_releaseInjectionSpan = releaseInjectionSpan) === null || _releaseInjectionSpan === void 0 ? void 0 : _releaseInjectionSpan.finish();
@@ -1943,75 +2469,172 @@ var unplugin = unplugin$1.createUnplugin(function (options, unpluginMetaContext)
1943
2469
  logger: logger,
1944
2470
  cli: cli
1945
2471
  };
1946
- _context3.next = 7;
2472
+ _context4.next = 7;
1947
2473
  return releaseNamePromise;
1948
2474
 
1949
2475
  case 7:
1950
- releaseName = _context3.sent;
1951
- _context3.prev = 8;
1952
- _context3.next = 11;
2476
+ releaseName = _context4.sent;
2477
+ _context4.prev = 8;
2478
+
2479
+ if (!internalOptions._experiments.debugIdUpload) {
2480
+ _context4.next = 21;
2481
+ break;
2482
+ }
2483
+
2484
+ _context4.next = 12;
2485
+ return glob.glob(internalOptions._experiments.debugIdUpload.include, {
2486
+ absolute: true,
2487
+ nodir: true,
2488
+ ignore: internalOptions._experiments.debugIdUpload.ignore
2489
+ });
2490
+
2491
+ case 12:
2492
+ debugIdChunkFilePaths = _context4.sent.filter(function (p) {
2493
+ return p.endsWith(".js") || p.endsWith(".mjs");
2494
+ });
2495
+ sourceFileUploadFolderPromise = util__default["default"].promisify(fs__default["default"].mkdtemp)(path__default["default"].join(os__default["default"].tmpdir(), "sentry-bundler-plugin-upload-"));
2496
+ _context4.next = 16;
2497
+ return Promise.all(debugIdChunkFilePaths.map( /*#__PURE__*/function () {
2498
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(chunkFilePath, chunkIndex) {
2499
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
2500
+ while (1) {
2501
+ switch (_context3.prev = _context3.next) {
2502
+ case 0:
2503
+ _context3.t0 = prepareBundleForDebugIdUpload;
2504
+ _context3.t1 = chunkFilePath;
2505
+ _context3.next = 4;
2506
+ return sourceFileUploadFolderPromise;
2507
+
2508
+ case 4:
2509
+ _context3.t2 = _context3.sent;
2510
+ _context3.t3 = String(chunkIndex);
2511
+ _context3.t4 = logger;
2512
+ _context3.next = 9;
2513
+ return (0, _context3.t0)(_context3.t1, _context3.t2, _context3.t3, _context3.t4);
2514
+
2515
+ case 9:
2516
+ case "end":
2517
+ return _context3.stop();
2518
+ }
2519
+ }
2520
+ }, _callee3);
2521
+ }));
2522
+
2523
+ return function (_x, _x2) {
2524
+ return _ref2.apply(this, arguments);
2525
+ };
2526
+ }()));
2527
+
2528
+ case 16:
2529
+ _context4.next = 18;
2530
+ return sourceFileUploadFolderPromise;
2531
+
2532
+ case 18:
2533
+ tmpUploadFolder = _context4.sent;
2534
+ _context4.next = 21;
2535
+ return uploadDebugIdSourcemaps(internalOptions, ctx, tmpUploadFolder, releaseName);
2536
+
2537
+ case 21:
2538
+ _context4.next = 23;
1953
2539
  return createNewRelease(internalOptions, ctx, releaseName);
1954
2540
 
1955
- case 11:
1956
- _context3.next = 13;
2541
+ case 23:
2542
+ _context4.next = 25;
1957
2543
  return cleanArtifacts(internalOptions, ctx, releaseName);
1958
2544
 
1959
- case 13:
1960
- _context3.next = 15;
2545
+ case 25:
2546
+ _context4.next = 27;
1961
2547
  return uploadSourceMaps(internalOptions, ctx, releaseName);
1962
2548
 
1963
- case 15:
1964
- _context3.next = 17;
2549
+ case 27:
2550
+ _context4.next = 29;
1965
2551
  return setCommits(internalOptions, ctx, releaseName);
1966
2552
 
1967
- case 17:
1968
- _context3.next = 19;
2553
+ case 29:
2554
+ _context4.next = 31;
1969
2555
  return finalizeRelease(internalOptions, ctx, releaseName);
1970
2556
 
1971
- case 19:
1972
- _context3.next = 21;
2557
+ case 31:
2558
+ _context4.next = 33;
1973
2559
  return addDeploy(internalOptions, ctx, releaseName);
1974
2560
 
1975
- case 21:
2561
+ case 33:
1976
2562
  (_transaction = transaction) === null || _transaction === void 0 ? void 0 : _transaction.setStatus("ok");
1977
- _context3.next = 29;
2563
+ _context4.next = 41;
1978
2564
  break;
1979
2565
 
1980
- case 24:
1981
- _context3.prev = 24;
1982
- _context3.t0 = _context3["catch"](8);
2566
+ case 36:
2567
+ _context4.prev = 36;
2568
+ _context4.t0 = _context4["catch"](8);
1983
2569
  (_transaction2 = transaction) === null || _transaction2 === void 0 ? void 0 : _transaction2.setStatus("cancelled");
1984
2570
  sentryHub.addBreadcrumb({
1985
2571
  level: "error",
1986
2572
  message: "Error during writeBundle"
1987
2573
  });
1988
- handleError(_context3.t0, logger, internalOptions.errorHandler);
2574
+ handleError(_context4.t0, logger, internalOptions.errorHandler);
2575
+
2576
+ case 41:
2577
+ _context4.prev = 41;
2578
+
2579
+ if (tmpUploadFolder) {
2580
+ fs__default["default"].rm(tmpUploadFolder, {
2581
+ recursive: true,
2582
+ force: true
2583
+ }, function () {// We don't care if this errors
2584
+ });
2585
+ }
1989
2586
 
1990
- case 29:
1991
- _context3.prev = 29;
1992
2587
  releasePipelineSpan === null || releasePipelineSpan === void 0 ? void 0 : releasePipelineSpan.finish();
1993
2588
  (_transaction3 = transaction) === null || _transaction3 === void 0 ? void 0 : _transaction3.finish();
1994
- _context3.next = 34;
2589
+ _context4.next = 47;
1995
2590
  return sentryClient.flush().then(null, function () {
1996
2591
  logger.warn("Sending of telemetry failed");
1997
2592
  });
1998
2593
 
1999
- case 34:
2000
- return _context3.finish(29);
2594
+ case 47:
2595
+ return _context4.finish(41);
2001
2596
 
2002
- case 35:
2597
+ case 48:
2003
2598
  sentryHub.addBreadcrumb({
2004
2599
  category: "writeBundle:finish",
2005
2600
  level: "info"
2006
2601
  });
2007
2602
 
2008
- case 36:
2603
+ case 49:
2009
2604
  case "end":
2010
- return _context3.stop();
2605
+ return _context4.stop();
2011
2606
  }
2012
2607
  }
2013
- }, _callee3, null, [[8, 24, 29, 35]]);
2608
+ }, _callee4, null, [[8, 36, 41, 48]]);
2014
2609
  }))();
2610
+ },
2611
+ rollup: {
2612
+ renderChunk: function renderChunk(code, chunk) {
2613
+ var _options$_experiments;
2614
+
2615
+ if ((_options$_experiments = options._experiments) !== null && _options$_experiments !== void 0 && _options$_experiments.debugIdUpload && [".js", ".mjs"].some(function (ending) {
2616
+ return chunk.fileName.endsWith(ending);
2617
+ }) // chunks could be any file (html, md, ...)
2618
+ ) {
2619
+ return injectDebugIdSnippetIntoChunk(code);
2620
+ } else {
2621
+ return null; // returning null means not modifying the chunk at all
2622
+ }
2623
+ }
2624
+ },
2625
+ vite: {
2626
+ renderChunk: function renderChunk(code, chunk) {
2627
+ var _options$_experiments2;
2628
+
2629
+ if ((_options$_experiments2 = options._experiments) !== null && _options$_experiments2 !== void 0 && _options$_experiments2.debugIdUpload && [".js", ".mjs"].some(function (ending) {
2630
+ return chunk.fileName.endsWith(ending);
2631
+ }) // chunks could be any file (html, md, ...)
2632
+ ) {
2633
+ return injectDebugIdSnippetIntoChunk(code);
2634
+ } else {
2635
+ return null; // returning null means not modifying the chunk at all
2636
+ }
2637
+ }
2015
2638
  }
2016
2639
  };
2017
2640
  });
@@ -2034,16 +2657,17 @@ function handleError(unknownError, logger, errorHandler) {
2034
2657
  }
2035
2658
  }
2036
2659
  /**
2037
- * Generates code for the "sentry-release-injector" which is responsible for setting the global `SENTRY_RELEASE`
2038
- * variable.
2660
+ * Generates code for the global injector which is responsible for setting the global
2661
+ * `SENTRY_RELEASE` & `SENTRY_BUILD_INFO` variables.
2039
2662
  */
2040
2663
 
2041
2664
 
2042
- function generateGlobalInjectorCode(_ref2) {
2043
- var release = _ref2.release,
2044
- injectReleasesMap = _ref2.injectReleasesMap,
2045
- org = _ref2.org,
2046
- project = _ref2.project;
2665
+ function generateGlobalInjectorCode(_ref3) {
2666
+ var release = _ref3.release,
2667
+ injectReleasesMap = _ref3.injectReleasesMap,
2668
+ injectBuildInformation = _ref3.injectBuildInformation,
2669
+ org = _ref3.org,
2670
+ project = _ref3.project;
2047
2671
  // The code below is mostly ternary operators because it saves bundle size.
2048
2672
  // The checks are to support as many environments as possible. (Node.js, Browser, webworkers, etc.)
2049
2673
  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, "\"};");
@@ -2053,9 +2677,39 @@ function generateGlobalInjectorCode(_ref2) {
2053
2677
  code += "\n _global.SENTRY_RELEASES=_global.SENTRY_RELEASES || {};\n _global.SENTRY_RELEASES[\"".concat(key, "\"]={id:\"").concat(release, "\"};");
2054
2678
  }
2055
2679
 
2680
+ if (injectBuildInformation) {
2681
+ var buildInfo = getBuildInformation();
2682
+ code += "\n _global.SENTRY_BUILD_INFO=".concat(JSON.stringify(buildInfo), ";");
2683
+ }
2684
+
2056
2685
  return code;
2057
- } // eslint-disable-next-line @typescript-eslint/no-explicit-any
2686
+ }
2687
+
2688
+ function getBuildInformation() {
2689
+ var packageJson = getPackageJson();
2690
+
2691
+ var _ref4 = packageJson ? getDependencies(packageJson) : {
2692
+ deps: [],
2693
+ depsVersions: {}
2694
+ },
2695
+ deps = _ref4.deps,
2696
+ depsVersions = _ref4.depsVersions;
2697
+
2698
+ return {
2699
+ deps: deps,
2700
+ depsVersions: depsVersions,
2701
+ nodeVersion: parseMajorVersion(process.version)
2702
+ };
2703
+ }
2704
+ /**
2705
+ * Determines whether the Sentry CLI binary is in its expected location.
2706
+ * This function is useful since `@sentry/cli` installs the binary via a post-install
2707
+ * script and post-install scripts may not always run. E.g. with `npm i --ignore-scripts`.
2708
+ */
2058
2709
 
2710
+ function sentryCliBinaryExists() {
2711
+ return fs__default["default"].existsSync(SentryCli__default["default"].getPath());
2712
+ } // eslint-disable-next-line @typescript-eslint/no-explicit-any
2059
2713
 
2060
2714
  var sentryVitePlugin = unplugin.vite; // eslint-disable-next-line @typescript-eslint/no-explicit-any
2061
2715
 
@@ -2065,6 +2719,8 @@ var sentryWebpackPlugin = unplugin.webpack; // eslint-disable-next-line @typescr
2065
2719
 
2066
2720
  var sentryEsbuildPlugin = unplugin.esbuild;
2067
2721
 
2722
+ exports.getBuildInformation = getBuildInformation;
2723
+ exports.sentryCliBinaryExists = sentryCliBinaryExists;
2068
2724
  exports.sentryEsbuildPlugin = sentryEsbuildPlugin;
2069
2725
  exports.sentryRollupPlugin = sentryRollupPlugin;
2070
2726
  exports.sentryVitePlugin = sentryVitePlugin;