@sentry/bundler-plugin-core 0.2.0 → 0.2.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/esm/index.js CHANGED
@@ -1,8 +1,9 @@
1
1
  import { createUnplugin } from 'unplugin';
2
2
  import MagicString from 'magic-string';
3
- import { NodeClient, Integrations, defaultStackParser, makeNodeTransport, Hub, makeMain } from '@sentry/node';
4
- import '@sentry/tracing';
5
3
  import SentryCli from '@sentry/cli';
4
+ import { NodeClient, defaultStackParser, makeNodeTransport, Hub, makeMain } from '@sentry/node';
5
+ import '@sentry/tracing';
6
+ import path from 'path';
6
7
 
7
8
  function _regeneratorRuntime() {
8
9
  /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
@@ -822,12 +823,7 @@ function normalizeUserOptions(userOptions) {
822
823
  dist: userOptions.dist,
823
824
  errorHandler: userOptions.errorHandler,
824
825
  configFile: userOptions.configFile
825
- }; // We only want to enable telemetry for SaaS users
826
- // This is not the final check (we need to call Sentry CLI at a later point)
827
- // but we can already at this point make a first decision.
828
- // @see `turnOffTelemetryForSelfHostedSentry` (telemetry.ts) for the second check.
829
-
830
- options.telemetry = options.telemetry && options.url === SENTRY_SAAS_URL;
826
+ };
831
827
  return options;
832
828
  }
833
829
  /**
@@ -940,30 +936,68 @@ function validateOptions(options, logger) {
940
936
  return true;
941
937
  }
942
938
 
943
- function makeSentryClient(dsn, telemetryEnabled) {
939
+ var SENTRY_SAAS_HOSTNAME = "sentry.io";
940
+ function makeSentryClient(dsn, allowedToSendTelemetryPromise) {
944
941
  var client = new NodeClient({
945
942
  dsn: dsn,
946
- enabled: telemetryEnabled,
947
- tracesSampleRate: telemetryEnabled ? 1.0 : 0.0,
948
- sampleRate: telemetryEnabled ? 1.0 : 0.0,
949
- release: "0.2.0",
950
- integrations: [new Integrations.Http({
951
- tracing: true
952
- })],
943
+ tracesSampleRate: 1,
944
+ sampleRate: 1,
945
+ release: "0.2.1",
946
+ integrations: [],
953
947
  tracePropagationTargets: ["sentry.io/api"],
954
948
  stackParser: defaultStackParser,
955
- transport: makeNodeTransport
956
- });
957
- var hub = new Hub(client); //TODO: This call is problematic because as soon as we set our hub as the current hub
958
- // we might interfere with other plugins that use Sentry. However, for now, we'll
959
- // leave it in because without it, we can't get distributed traces (which are pretty nice)
960
- // Let's keep it until someone complains about interference.
961
- // The ideal solution would be a code change in the JS SDK but it's not a straight-forward fix.
949
+ // We create a transport that stalls sending events until we know that we're allowed to (i.e. when Sentry CLI told
950
+ // us that the upload URL is the Sentry SaaS URL)
951
+ transport: function transport(nodeTransportOptions) {
952
+ var nodeTransport = makeNodeTransport(nodeTransportOptions);
953
+ return {
954
+ flush: function flush(timeout) {
955
+ return nodeTransport.flush(timeout);
956
+ },
957
+ send: function () {
958
+ var _send = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(request) {
959
+ var isAllowedToSend;
960
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
961
+ while (1) {
962
+ switch (_context.prev = _context.next) {
963
+ case 0:
964
+ _context.next = 2;
965
+ return allowedToSendTelemetryPromise;
966
+
967
+ case 2:
968
+ isAllowedToSend = _context.sent;
969
+
970
+ if (!isAllowedToSend) {
971
+ _context.next = 7;
972
+ break;
973
+ }
974
+
975
+ return _context.abrupt("return", nodeTransport.send(request));
976
+
977
+ case 7:
978
+ return _context.abrupt("return", undefined);
979
+
980
+ case 8:
981
+ case "end":
982
+ return _context.stop();
983
+ }
984
+ }
985
+ }, _callee);
986
+ }));
962
987
 
963
- makeMain(hub);
988
+ function send(_x) {
989
+ return _send.apply(this, arguments);
990
+ }
991
+
992
+ return send;
993
+ }()
994
+ };
995
+ }
996
+ });
997
+ var hub = new Hub(client);
964
998
  return {
965
- client: client,
966
- hub: hub
999
+ sentryClient: client,
1000
+ sentryHub: hub
967
1001
  };
968
1002
  }
969
1003
  /**
@@ -1005,8 +1039,10 @@ function captureMinimalError(error, hub) {
1005
1039
 
1006
1040
  hub.captureException(sentryError);
1007
1041
  }
1008
- function addPluginOptionTags(options, hub) {
1009
- var cleanArtifacts = options.cleanArtifacts,
1042
+ function addPluginOptionInformationToHub(options, hub, bundler) {
1043
+ var org = options.org,
1044
+ project = options.project,
1045
+ cleanArtifacts = options.cleanArtifacts,
1010
1046
  finalize = options.finalize,
1011
1047
  setCommits = options.setCommits,
1012
1048
  injectReleasesMap = options.injectReleasesMap,
@@ -1046,61 +1082,107 @@ function addPluginOptionTags(options, hub) {
1046
1082
  }
1047
1083
 
1048
1084
  hub.setTag("node", process.version);
1085
+ hub.setTags({
1086
+ organization: org,
1087
+ project: project,
1088
+ bundler: bundler
1089
+ });
1090
+ hub.setUser({
1091
+ id: org
1092
+ });
1049
1093
  }
1050
- /**
1051
- * Makes a call to SentryCLI to get the Sentry server URL the CLI uses.
1052
- *
1053
- * We need to check and decide to use telemetry based on the CLI's respone to this call
1054
- * because only at this time we checked a possibly existing .sentryclirc file. This file
1055
- * could point to another URL than the default URL.
1056
- */
1057
-
1058
- function turnOffTelemetryForSelfHostedSentry(_x, _x2) {
1059
- return _turnOffTelemetryForSelfHostedSentry.apply(this, arguments);
1094
+ function shouldSendTelemetry(_x2) {
1095
+ return _shouldSendTelemetry.apply(this, arguments);
1060
1096
  }
1061
1097
 
1062
- function _turnOffTelemetryForSelfHostedSentry() {
1063
- _turnOffTelemetryForSelfHostedSentry = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(cli, hub) {
1098
+ function _shouldSendTelemetry() {
1099
+ _shouldSendTelemetry = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(options) {
1064
1100
  var _cliInfo$split$, _cliInfo$split$$repla;
1065
1101
 
1066
- var cliInfo, url, client;
1067
- return _regeneratorRuntime().wrap(function _callee$(_context) {
1102
+ var silent, org, project, authToken, url, vcsRemote, customHeader, dist, telemetry, dryRun, cli, cliInfo, cliInfoUrl;
1103
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
1068
1104
  while (1) {
1069
- switch (_context.prev = _context.next) {
1105
+ switch (_context2.prev = _context2.next) {
1070
1106
  case 0:
1071
- _context.next = 2;
1072
- return cli.execute(["info"], false);
1107
+ silent = options.silent, org = options.org, project = options.project, authToken = options.authToken, url = options.url, vcsRemote = options.vcsRemote, customHeader = options.customHeader, dist = options.dist, telemetry = options.telemetry, dryRun = options.dryRun; // `options.telemetry` defaults to true
1073
1108
 
1074
- case 2:
1075
- cliInfo = _context.sent;
1076
- url = cliInfo === null || cliInfo === void 0 ? void 0 : (_cliInfo$split$ = cliInfo.split(/(\r\n|\n|\r)/)[0]) === null || _cliInfo$split$ === void 0 ? void 0 : (_cliInfo$split$$repla = _cliInfo$split$.replace(/^Sentry Server: /, "")) === null || _cliInfo$split$$repla === void 0 ? void 0 : _cliInfo$split$$repla.trim();
1109
+ if (!(telemetry === false)) {
1110
+ _context2.next = 3;
1111
+ break;
1112
+ }
1077
1113
 
1078
- if (url !== SENTRY_SAAS_URL) {
1079
- client = hub.getClient();
1114
+ return _context2.abrupt("return", false);
1080
1115
 
1081
- if (client) {
1082
- client.getOptions().enabled = false;
1083
- client.getOptions().tracesSampleRate = 0;
1084
- client.getOptions().sampleRate = 0;
1085
- }
1116
+ case 3:
1117
+ if (!dryRun) {
1118
+ _context2.next = 5;
1119
+ break;
1086
1120
  }
1087
1121
 
1122
+ return _context2.abrupt("return", false);
1123
+
1088
1124
  case 5:
1125
+ if (!(url === SENTRY_SAAS_URL)) {
1126
+ _context2.next = 7;
1127
+ break;
1128
+ }
1129
+
1130
+ return _context2.abrupt("return", true);
1131
+
1132
+ case 7:
1133
+ cli = new SentryCli(options.configFile, {
1134
+ url: url,
1135
+ authToken: authToken,
1136
+ org: org,
1137
+ project: project,
1138
+ vcsRemote: vcsRemote,
1139
+ dist: dist,
1140
+ silent: silent,
1141
+ customHeader: customHeader
1142
+ });
1143
+ _context2.prev = 8;
1144
+ _context2.next = 11;
1145
+ return cli.execute(["info"], false);
1146
+
1147
+ case 11:
1148
+ cliInfo = _context2.sent;
1149
+ _context2.next = 17;
1150
+ break;
1151
+
1152
+ case 14:
1153
+ _context2.prev = 14;
1154
+ _context2.t0 = _context2["catch"](8);
1155
+ throw new Error('Sentry CLI "info" command failed, make sure you have an auth token configured, and your `url` option is correct.');
1156
+
1157
+ case 17:
1158
+ cliInfoUrl = (_cliInfo$split$ = cliInfo.split(/(\r\n|\n|\r)/)[0]) === null || _cliInfo$split$ === void 0 ? void 0 : (_cliInfo$split$$repla = _cliInfo$split$.replace(/^Sentry Server: /, "")) === null || _cliInfo$split$$repla === void 0 ? void 0 : _cliInfo$split$$repla.trim();
1159
+
1160
+ if (!(cliInfoUrl === undefined)) {
1161
+ _context2.next = 20;
1162
+ break;
1163
+ }
1164
+
1165
+ return _context2.abrupt("return", false);
1166
+
1167
+ case 20:
1168
+ return _context2.abrupt("return", new URL(cliInfoUrl).hostname === SENTRY_SAAS_HOSTNAME);
1169
+
1170
+ case 21:
1089
1171
  case "end":
1090
- return _context.stop();
1172
+ return _context2.stop();
1091
1173
  }
1092
1174
  }
1093
- }, _callee);
1175
+ }, _callee2, null, [[8, 14]]);
1094
1176
  }));
1095
- return _turnOffTelemetryForSelfHostedSentry.apply(this, arguments);
1177
+ return _shouldSendTelemetry.apply(this, arguments);
1096
1178
  }
1097
1179
 
1098
- function createNewRelease(_x, _x2) {
1180
+ function createNewRelease(_x, _x2, _x3) {
1099
1181
  return _createNewRelease.apply(this, arguments);
1100
1182
  }
1101
1183
 
1102
1184
  function _createNewRelease() {
1103
- _createNewRelease = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(options, ctx) {
1185
+ _createNewRelease = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(options, ctx, releaseName) {
1104
1186
  var span;
1105
1187
  return _regeneratorRuntime().wrap(function _callee$(_context) {
1106
1188
  while (1) {
@@ -1108,7 +1190,7 @@ function _createNewRelease() {
1108
1190
  case 0:
1109
1191
  span = addSpanToTransaction(ctx, "function.plugin.create_release");
1110
1192
  _context.next = 3;
1111
- return ctx.cli.releases["new"](options.release);
1193
+ return ctx.cli.releases["new"](releaseName);
1112
1194
 
1113
1195
  case 3:
1114
1196
  ctx.logger.info("Successfully created release.");
@@ -1124,12 +1206,12 @@ function _createNewRelease() {
1124
1206
  return _createNewRelease.apply(this, arguments);
1125
1207
  }
1126
1208
 
1127
- function cleanArtifacts(_x3, _x4) {
1209
+ function cleanArtifacts(_x4, _x5, _x6) {
1128
1210
  return _cleanArtifacts.apply(this, arguments);
1129
1211
  }
1130
1212
 
1131
1213
  function _cleanArtifacts() {
1132
- _cleanArtifacts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(options, ctx) {
1214
+ _cleanArtifacts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(options, ctx, releaseName) {
1133
1215
  var span;
1134
1216
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
1135
1217
  while (1) {
@@ -1146,7 +1228,7 @@ function _cleanArtifacts() {
1146
1228
  case 3:
1147
1229
  span = addSpanToTransaction(ctx, "function.plugin.clean_artifacts");
1148
1230
  _context2.next = 6;
1149
- return ctx.cli.releases.execute(["releases", "files", options.release, "delete", "--all"], true);
1231
+ return ctx.cli.releases.execute(["releases", "files", releaseName, "delete", "--all"], true);
1150
1232
 
1151
1233
  case 6:
1152
1234
  ctx.logger.info("Successfully cleaned previous artifacts.");
@@ -1162,12 +1244,12 @@ function _cleanArtifacts() {
1162
1244
  return _cleanArtifacts.apply(this, arguments);
1163
1245
  }
1164
1246
 
1165
- function uploadSourceMaps(_x5, _x6) {
1247
+ function uploadSourceMaps(_x7, _x8, _x9) {
1166
1248
  return _uploadSourceMaps.apply(this, arguments);
1167
1249
  }
1168
1250
 
1169
1251
  function _uploadSourceMaps() {
1170
- _uploadSourceMaps = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(options, ctx) {
1252
+ _uploadSourceMaps = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(options, ctx, releaseName) {
1171
1253
  var span;
1172
1254
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
1173
1255
  while (1) {
@@ -1178,7 +1260,7 @@ function _uploadSourceMaps() {
1178
1260
  // we only need to pass the include option here.
1179
1261
 
1180
1262
  _context3.next = 4;
1181
- return ctx.cli.releases.uploadSourceMaps(options.release, {
1263
+ return ctx.cli.releases.uploadSourceMaps(releaseName, {
1182
1264
  include: options.include
1183
1265
  });
1184
1266
 
@@ -1196,12 +1278,12 @@ function _uploadSourceMaps() {
1196
1278
  return _uploadSourceMaps.apply(this, arguments);
1197
1279
  }
1198
1280
 
1199
- function setCommits(_x7, _x8) {
1281
+ function setCommits(_x10, _x11, _x12) {
1200
1282
  return _setCommits.apply(this, arguments);
1201
1283
  }
1202
1284
 
1203
1285
  function _setCommits() {
1204
- _setCommits = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(options, ctx) {
1286
+ _setCommits = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(options, ctx, releaseName) {
1205
1287
  var span, _options$setCommits, auto, repo, commit, previousCommit, ignoreMissing, ignoreEmpty;
1206
1288
 
1207
1289
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
@@ -1220,7 +1302,7 @@ function _setCommits() {
1220
1302
  span = addSpanToTransaction(ctx, "function.plugin.set_commits");
1221
1303
  _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;
1222
1304
  _context4.next = 7;
1223
- return ctx.cli.releases.setCommits(options.release, {
1305
+ return ctx.cli.releases.setCommits(releaseName, {
1224
1306
  commit: commit,
1225
1307
  previousCommit: previousCommit,
1226
1308
  repo: repo,
@@ -1243,12 +1325,12 @@ function _setCommits() {
1243
1325
  return _setCommits.apply(this, arguments);
1244
1326
  }
1245
1327
 
1246
- function finalizeRelease(_x9, _x10) {
1328
+ function finalizeRelease(_x13, _x14, _x15) {
1247
1329
  return _finalizeRelease.apply(this, arguments);
1248
1330
  }
1249
1331
 
1250
1332
  function _finalizeRelease() {
1251
- _finalizeRelease = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(options, ctx) {
1333
+ _finalizeRelease = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(options, ctx, releaseName) {
1252
1334
  var span;
1253
1335
  return _regeneratorRuntime().wrap(function _callee5$(_context5) {
1254
1336
  while (1) {
@@ -1265,7 +1347,7 @@ function _finalizeRelease() {
1265
1347
  case 3:
1266
1348
  span = addSpanToTransaction(ctx, "function.plugin.finalize_release");
1267
1349
  _context5.next = 6;
1268
- return ctx.cli.releases.finalize(options.release);
1350
+ return ctx.cli.releases.finalize(releaseName);
1269
1351
 
1270
1352
  case 6:
1271
1353
  ctx.logger.info("Successfully finalized release.");
@@ -1281,12 +1363,12 @@ function _finalizeRelease() {
1281
1363
  return _finalizeRelease.apply(this, arguments);
1282
1364
  }
1283
1365
 
1284
- function addDeploy(_x11, _x12) {
1366
+ function addDeploy(_x16, _x17, _x18) {
1285
1367
  return _addDeploy.apply(this, arguments);
1286
1368
  }
1287
1369
 
1288
1370
  function _addDeploy() {
1289
- _addDeploy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(options, ctx) {
1371
+ _addDeploy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(options, ctx, releaseName) {
1290
1372
  var span, _options$deploy, env, started, finished, time, name, url;
1291
1373
 
1292
1374
  return _regeneratorRuntime().wrap(function _callee6$(_context6) {
@@ -1305,7 +1387,7 @@ function _addDeploy() {
1305
1387
  span = addSpanToTransaction(ctx, "function.plugin.deploy");
1306
1388
  _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;
1307
1389
  _context6.next = 7;
1308
- return ctx.cli.releases.newDeploy(options.release, {
1390
+ return ctx.cli.releases.newDeploy(releaseName, {
1309
1391
  env: env,
1310
1392
  started: started,
1311
1393
  finished: finished,
@@ -1389,10 +1471,9 @@ function createLogger(options) {
1389
1471
  }
1390
1472
 
1391
1473
  // eslint-disable-next-line no-console
1392
- (_console4 = console).log.apply(_console4, ["".concat(options.prefix, " Debug: ").concat(message)].concat(params));
1393
- }
1474
+ (_console4 = console).log.apply(_console4, ["".concat(options.prefix, " Debug: ").concat(message)].concat(params)); // We're not creating breadcrumbs for debug logs because it is super spammy
1394
1475
 
1395
- addBreadcrumb("debug", message);
1476
+ }
1396
1477
  }
1397
1478
  };
1398
1479
  }
@@ -1472,9 +1553,9 @@ function getDryRunCLI(cli, logger) {
1472
1553
  };
1473
1554
  }
1474
1555
 
1475
- // We prefix the polyfill id with \0 to tell other plugins not to try to load or transform it.
1476
1556
  // This hack is taken straight from https://rollupjs.org/guide/en/#resolveid.
1477
1557
  // This probably doesn't work for all bundlers but for rollup it does.
1558
+
1478
1559
  var RELEASE_INJECTOR_ID = "\0sentry-release-injector";
1479
1560
  var ALLOWED_TRANSFORMATION_FILE_ENDINGS = [".js", ".ts", ".jsx", ".tsx", ".cjs", ".mjs"];
1480
1561
  /**
@@ -1507,11 +1588,19 @@ var ALLOWED_TRANSFORMATION_FILE_ENDINGS = [".js", ".ts", ".jsx", ".tsx", ".cjs",
1507
1588
 
1508
1589
  var unplugin = createUnplugin(function (options, unpluginMetaContext) {
1509
1590
  var internalOptions = normalizeUserOptions(options);
1591
+ var allowedToSendTelemetryPromise = shouldSendTelemetry(internalOptions);
1510
1592
 
1511
- var _makeSentryClient = makeSentryClient("https://4c2bae7d9fbc413e8f7385f55c515d51@o1.ingest.sentry.io/6690737", internalOptions.telemetry),
1512
- sentryHub = _makeSentryClient.hub;
1593
+ var _makeSentryClient = makeSentryClient("https://4c2bae7d9fbc413e8f7385f55c515d51@o1.ingest.sentry.io/6690737", allowedToSendTelemetryPromise),
1594
+ sentryHub = _makeSentryClient.sentryHub,
1595
+ sentryClient = _makeSentryClient.sentryClient;
1513
1596
 
1514
- addPluginOptionTags(internalOptions, sentryHub);
1597
+ addPluginOptionInformationToHub(internalOptions, sentryHub, unpluginMetaContext.framework); //TODO: This call is problematic because as soon as we set our hub as the current hub
1598
+ // we might interfere with other plugins that use Sentry. However, for now, we'll
1599
+ // leave it in because without it, we can't get distributed traces (which are pretty nice)
1600
+ // Let's keep it until someone complains about interference.
1601
+ // The ideal solution would be a code change in the JS SDK but it's not a straight-forward fix.
1602
+
1603
+ makeMain(sentryHub);
1515
1604
  var logger = createLogger({
1516
1605
  hub: sentryHub,
1517
1606
  prefix: "[sentry-".concat(unpluginMetaContext.framework, "-plugin]"),
@@ -1524,19 +1613,12 @@ var unplugin = createUnplugin(function (options, unpluginMetaContext) {
1524
1613
  }
1525
1614
 
1526
1615
  var cli = getSentryCli(internalOptions, logger);
1527
-
1528
- if (internalOptions.telemetry) {
1529
- logger.info("Sending error and performance telemetry data to Sentry.");
1530
- logger.info("To disable telemetry, set `options.telemetry` to `false`.");
1531
- }
1532
-
1533
- sentryHub.setTags({
1534
- organization: internalOptions.org,
1535
- project: internalOptions.project,
1536
- bundler: unpluginMetaContext.framework
1537
- });
1538
- sentryHub.setUser({
1539
- id: internalOptions.org
1616
+ var releaseNamePromise = new Promise(function (resolve) {
1617
+ if (options.release) {
1618
+ resolve(options.release);
1619
+ } else {
1620
+ resolve(cli.releases.proposeVersion());
1621
+ }
1540
1622
  });
1541
1623
  var transaction;
1542
1624
  var releaseInjectionSpan;
@@ -1550,28 +1632,31 @@ var unplugin = createUnplugin(function (options, unpluginMetaContext) {
1550
1632
  */
1551
1633
  buildStart: function buildStart() {
1552
1634
  return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
1635
+ var isAllowedToSendToSendTelemetry, releaseName;
1553
1636
  return _regeneratorRuntime().wrap(function _callee$(_context) {
1554
1637
  while (1) {
1555
1638
  switch (_context.prev = _context.next) {
1556
1639
  case 0:
1557
- _context.next = 2;
1558
- return turnOffTelemetryForSelfHostedSentry(cli, sentryHub);
1640
+ logger.debug("Called 'buildStart'");
1641
+ _context.next = 3;
1642
+ return allowedToSendTelemetryPromise;
1559
1643
 
1560
- case 2:
1561
- if (internalOptions.release) {
1562
- _context.next = 6;
1563
- break;
1644
+ case 3:
1645
+ isAllowedToSendToSendTelemetry = _context.sent;
1646
+
1647
+ if (isAllowedToSendToSendTelemetry) {
1648
+ logger.info("Sending error and performance telemetry data to Sentry.");
1649
+ logger.info("To disable telemetry, set `options.telemetry` to `false`.");
1564
1650
  }
1565
1651
 
1566
- _context.next = 5;
1567
- return cli.releases.proposeVersion();
1652
+ _context.next = 7;
1653
+ return releaseNamePromise;
1568
1654
 
1569
- case 5:
1570
- internalOptions.release = _context.sent;
1655
+ case 7:
1656
+ releaseName = _context.sent;
1571
1657
 
1572
- case 6:
1573
1658
  // At this point, we either have determined a release or we have to bail
1574
- if (!internalOptions.release) {
1659
+ if (!releaseName) {
1575
1660
  handleError(new Error("Unable to determine a release name. Make sure to set the `release` option or use an environment that supports auto-detection https://docs.sentry.io/cli/releases/#creating-releases`"), logger, internalOptions.errorHandler, sentryHub);
1576
1661
  }
1577
1662
 
@@ -1586,7 +1671,7 @@ var unplugin = createUnplugin(function (options, unpluginMetaContext) {
1586
1671
  cli: cli
1587
1672
  }, "function.plugin.inject_release", "Release injection");
1588
1673
 
1589
- case 9:
1674
+ case 11:
1590
1675
  case "end":
1591
1676
  return _context.stop();
1592
1677
  }
@@ -1608,10 +1693,10 @@ var unplugin = createUnplugin(function (options, unpluginMetaContext) {
1608
1693
  */
1609
1694
  resolveId: function resolveId(id, importer, _ref) {
1610
1695
  var isEntry = _ref.isEntry;
1611
- sentryHub.addBreadcrumb({
1612
- category: "resolveId",
1613
- message: "isEntry: ".concat(String(isEntry)),
1614
- level: "info"
1696
+ logger.debug('Called "resolveId":', {
1697
+ id: id,
1698
+ importer: importer,
1699
+ isEntry: isEntry
1615
1700
  });
1616
1701
 
1617
1702
  if (id === RELEASE_INJECTOR_ID) {
@@ -1621,9 +1706,9 @@ var unplugin = createUnplugin(function (options, unpluginMetaContext) {
1621
1706
  }
1622
1707
  },
1623
1708
  loadInclude: function loadInclude(id) {
1624
- logger.info("Called \"loadInclude\": ".concat(JSON.stringify({
1709
+ logger.debug('Called "loadInclude":', {
1625
1710
  id: id
1626
- })));
1711
+ });
1627
1712
  return id === RELEASE_INJECTOR_ID;
1628
1713
  },
1629
1714
 
@@ -1635,21 +1720,47 @@ var unplugin = createUnplugin(function (options, unpluginMetaContext) {
1635
1720
  * @returns The global injector code when we load the "sentry-release-injector" module. Otherwise returns `undefined`.
1636
1721
  */
1637
1722
  load: function load(id) {
1638
- sentryHub.addBreadcrumb({
1639
- category: "load",
1640
- level: "info"
1641
- });
1723
+ return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
1724
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
1725
+ while (1) {
1726
+ switch (_context2.prev = _context2.next) {
1727
+ case 0:
1728
+ logger.debug('Called "load":', {
1729
+ id: id
1730
+ });
1642
1731
 
1643
- if (id === RELEASE_INJECTOR_ID) {
1644
- return generateGlobalInjectorCode({
1645
- release: internalOptions.release,
1646
- injectReleasesMap: internalOptions.injectReleasesMap,
1647
- org: internalOptions.org,
1648
- project: internalOptions.project
1649
- });
1650
- } else {
1651
- return undefined;
1652
- }
1732
+ if (!(id === RELEASE_INJECTOR_ID)) {
1733
+ _context2.next = 13;
1734
+ break;
1735
+ }
1736
+
1737
+ _context2.t0 = generateGlobalInjectorCode;
1738
+ _context2.next = 5;
1739
+ return releaseNamePromise;
1740
+
1741
+ case 5:
1742
+ _context2.t1 = _context2.sent;
1743
+ _context2.t2 = internalOptions.injectReleasesMap;
1744
+ _context2.t3 = internalOptions.org;
1745
+ _context2.t4 = internalOptions.project;
1746
+ _context2.t5 = {
1747
+ release: _context2.t1,
1748
+ injectReleasesMap: _context2.t2,
1749
+ org: _context2.t3,
1750
+ project: _context2.t4
1751
+ };
1752
+ return _context2.abrupt("return", (0, _context2.t0)(_context2.t5));
1753
+
1754
+ case 13:
1755
+ return _context2.abrupt("return", undefined);
1756
+
1757
+ case 14:
1758
+ case "end":
1759
+ return _context2.stop();
1760
+ }
1761
+ }
1762
+ }, _callee2);
1763
+ }))();
1653
1764
  },
1654
1765
 
1655
1766
  /**
@@ -1661,32 +1772,35 @@ var unplugin = createUnplugin(function (options, unpluginMetaContext) {
1661
1772
  * want to transform the release injector file.
1662
1773
  */
1663
1774
  transformInclude: function transformInclude(id) {
1664
- sentryHub.addBreadcrumb({
1665
- category: "transformInclude",
1666
- level: "info"
1667
- }); // We don't want to transform our injected code.
1775
+ logger.debug('Called "transformInclude":', {
1776
+ id: id
1777
+ }); // We normalize the id because vite always passes `id` as a unix style path which causes problems when a user passes
1778
+ // a windows style path to `releaseInjectionTargets`
1668
1779
 
1669
- if (id === RELEASE_INJECTOR_ID) {
1780
+ var normalizedId = path.normalize(id); // We don't want to transform our injected code.
1781
+
1782
+ if (normalizedId === RELEASE_INJECTOR_ID) {
1670
1783
  return false;
1671
1784
  }
1672
1785
 
1673
1786
  if (internalOptions.releaseInjectionTargets) {
1674
1787
  // If there's an `releaseInjectionTargets` option transform (ie. inject the release varible) when the file path matches the option.
1675
1788
  if (typeof internalOptions.releaseInjectionTargets === "function") {
1676
- return internalOptions.releaseInjectionTargets(id);
1789
+ return internalOptions.releaseInjectionTargets(normalizedId);
1677
1790
  }
1678
1791
 
1679
1792
  return internalOptions.releaseInjectionTargets.some(function (entry) {
1680
1793
  if (entry instanceof RegExp) {
1681
- return entry.test(id);
1794
+ return entry.test(normalizedId);
1682
1795
  } else {
1683
- return id === entry;
1796
+ var normalizedEntry = path.normalize(entry);
1797
+ return normalizedId === normalizedEntry;
1684
1798
  }
1685
1799
  });
1686
1800
  } else {
1687
- var pathIsOrdinary = !id.includes("?") && !id.includes("#");
1801
+ var pathIsOrdinary = !normalizedId.includes("?") && !normalizedId.includes("#");
1688
1802
  var pathHasAllowedFileEnding = ALLOWED_TRANSFORMATION_FILE_ENDINGS.some(function (allowedFileEnding) {
1689
- return id.endsWith(allowedFileEnding);
1803
+ return normalizedId.endsWith(allowedFileEnding);
1690
1804
  });
1691
1805
  return pathIsOrdinary && pathHasAllowedFileEnding;
1692
1806
  }
@@ -1700,10 +1814,9 @@ var unplugin = createUnplugin(function (options, unpluginMetaContext) {
1700
1814
  * @param id Always the absolute (fully resolved) path to the module.
1701
1815
  * @returns transformed code + source map
1702
1816
  */
1703
- transform: function transform(code) {
1704
- sentryHub.addBreadcrumb({
1705
- category: "transform",
1706
- level: "info"
1817
+ transform: function transform(code, id) {
1818
+ logger.debug('Called "transform":', {
1819
+ id: id
1707
1820
  }); // The MagicString library allows us to generate sourcemaps for the changes we make to the user code.
1708
1821
 
1709
1822
  var ms = new MagicString(code); // Appending instead of prepending has less probability of mucking with user's source maps.
@@ -1729,69 +1842,119 @@ var unplugin = createUnplugin(function (options, unpluginMetaContext) {
1729
1842
  * Sentry.io, uploading sourcemaps, associating commits and deploys and finalizing the release)
1730
1843
  */
1731
1844
  writeBundle: function writeBundle() {
1732
- var _releaseInjectionSpan;
1733
-
1734
- (_releaseInjectionSpan = releaseInjectionSpan) === null || _releaseInjectionSpan === void 0 ? void 0 : _releaseInjectionSpan.finish();
1735
- var releasePipelineSpan = transaction && addSpanToTransaction({
1736
- hub: sentryHub,
1737
- parentSpan: transaction,
1738
- logger: logger,
1739
- cli: cli
1740
- }, "function.plugin.release", "Release pipeline");
1741
- sentryHub.addBreadcrumb({
1742
- category: "writeBundle:start",
1743
- level: "info"
1744
- });
1745
- var ctx = {
1746
- hub: sentryHub,
1747
- parentSpan: releasePipelineSpan,
1748
- logger: logger,
1749
- cli: cli
1750
- };
1751
- createNewRelease(internalOptions, ctx).then(function () {
1752
- return cleanArtifacts(internalOptions, ctx);
1753
- }).then(function () {
1754
- return uploadSourceMaps(internalOptions, ctx);
1755
- }).then(function () {
1756
- return setCommits(internalOptions, ctx);
1757
- }).then(function () {
1758
- return finalizeRelease(internalOptions, ctx);
1759
- }).then(function () {
1760
- return addDeploy(internalOptions, ctx);
1761
- }).then(function () {
1762
- var _transaction;
1763
-
1764
- return (_transaction = transaction) === null || _transaction === void 0 ? void 0 : _transaction.setStatus("ok");
1765
- })["catch"](function (e) {
1766
- var _transaction2;
1767
-
1768
- (_transaction2 = transaction) === null || _transaction2 === void 0 ? void 0 : _transaction2.setStatus("cancelled");
1769
- handleError(e, logger, internalOptions.errorHandler, sentryHub);
1770
- })["finally"](function () {
1771
- var _transaction3;
1772
-
1773
- sentryHub.addBreadcrumb({
1774
- category: "writeBundle:finish",
1775
- level: "info"
1776
- });
1777
- releasePipelineSpan === null || releasePipelineSpan === void 0 ? void 0 : releasePipelineSpan.finish();
1778
- (_transaction3 = transaction) === null || _transaction3 === void 0 ? void 0 : _transaction3.finish();
1779
- });
1845
+ return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
1846
+ var _releaseInjectionSpan;
1847
+
1848
+ var releasePipelineSpan, ctx, releaseName, _transaction, _transaction2, _transaction3;
1849
+
1850
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
1851
+ while (1) {
1852
+ switch (_context3.prev = _context3.next) {
1853
+ case 0:
1854
+ logger.debug('Called "writeBundle"');
1855
+ (_releaseInjectionSpan = releaseInjectionSpan) === null || _releaseInjectionSpan === void 0 ? void 0 : _releaseInjectionSpan.finish();
1856
+ releasePipelineSpan = transaction && addSpanToTransaction({
1857
+ hub: sentryHub,
1858
+ parentSpan: transaction,
1859
+ logger: logger,
1860
+ cli: cli
1861
+ }, "function.plugin.release", "Release pipeline");
1862
+ sentryHub.addBreadcrumb({
1863
+ category: "writeBundle:start",
1864
+ level: "info"
1865
+ });
1866
+ ctx = {
1867
+ hub: sentryHub,
1868
+ parentSpan: releasePipelineSpan,
1869
+ logger: logger,
1870
+ cli: cli
1871
+ };
1872
+ _context3.next = 7;
1873
+ return releaseNamePromise;
1874
+
1875
+ case 7:
1876
+ releaseName = _context3.sent;
1877
+ _context3.prev = 8;
1878
+ _context3.next = 11;
1879
+ return createNewRelease(internalOptions, ctx, releaseName);
1880
+
1881
+ case 11:
1882
+ _context3.next = 13;
1883
+ return cleanArtifacts(internalOptions, ctx, releaseName);
1884
+
1885
+ case 13:
1886
+ _context3.next = 15;
1887
+ return uploadSourceMaps(internalOptions, ctx, releaseName);
1888
+
1889
+ case 15:
1890
+ _context3.next = 17;
1891
+ return setCommits(internalOptions, ctx, releaseName);
1892
+
1893
+ case 17:
1894
+ _context3.next = 19;
1895
+ return finalizeRelease(internalOptions, ctx, releaseName);
1896
+
1897
+ case 19:
1898
+ _context3.next = 21;
1899
+ return addDeploy(internalOptions, ctx, releaseName);
1900
+
1901
+ case 21:
1902
+ (_transaction = transaction) === null || _transaction === void 0 ? void 0 : _transaction.setStatus("ok");
1903
+ _context3.next = 28;
1904
+ break;
1905
+
1906
+ case 24:
1907
+ _context3.prev = 24;
1908
+ _context3.t0 = _context3["catch"](8);
1909
+ (_transaction2 = transaction) === null || _transaction2 === void 0 ? void 0 : _transaction2.setStatus("cancelled");
1910
+ handleError(_context3.t0, logger, internalOptions.errorHandler, sentryHub);
1911
+
1912
+ case 28:
1913
+ _context3.prev = 28;
1914
+ sentryHub.addBreadcrumb({
1915
+ category: "writeBundle:finish",
1916
+ level: "info"
1917
+ });
1918
+ releasePipelineSpan === null || releasePipelineSpan === void 0 ? void 0 : releasePipelineSpan.finish();
1919
+ (_transaction3 = transaction) === null || _transaction3 === void 0 ? void 0 : _transaction3.finish();
1920
+ _context3.next = 34;
1921
+ return sentryClient.flush().then(null, function () {
1922
+ logger.warn("Sending of telemetry failed");
1923
+ });
1924
+
1925
+ case 34:
1926
+ return _context3.finish(28);
1927
+
1928
+ case 35:
1929
+ case "end":
1930
+ return _context3.stop();
1931
+ }
1932
+ }
1933
+ }, _callee3, null, [[8, 24, 28, 35]]);
1934
+ }))();
1780
1935
  }
1781
1936
  };
1782
1937
  });
1783
1938
 
1784
- function handleError(error, logger, errorHandler, sentryHub) {
1785
- logger.error(error.message);
1939
+ function handleError(unknownError, logger, errorHandler, sentryHub) {
1940
+ if (unknownError instanceof Error) {
1941
+ logger.error(unknownError.message);
1942
+ } else {
1943
+ logger.error(String(unknownError));
1944
+ }
1786
1945
 
1787
1946
  if (sentryHub) {
1788
- captureMinimalError(error, sentryHub);
1947
+ captureMinimalError(unknownError, sentryHub);
1789
1948
  }
1790
1949
 
1791
1950
  if (errorHandler) {
1792
- errorHandler(error);
1951
+ if (unknownError instanceof Error) {
1952
+ errorHandler(unknownError);
1953
+ } else {
1954
+ errorHandler(new Error("An unknown error occured"));
1955
+ }
1793
1956
  } else {
1794
- throw error;
1957
+ throw unknownError;
1795
1958
  }
1796
1959
  }
1797
1960
  /**