@sentry/bundler-plugin-core 2.0.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cjs/index.js CHANGED
@@ -4,15 +4,15 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var SentryCli = require('@sentry/cli');
6
6
  var fs = require('fs');
7
+ var path = require('path');
7
8
  var MagicString = require('magic-string');
8
9
  var unplugin = require('unplugin');
9
- var glob = require('glob');
10
- var os = require('os');
11
- var path = require('path');
12
- var util = require('util');
13
10
  var findUp = require('find-up');
11
+ var os = require('os');
14
12
  var crypto = require('crypto');
15
13
  var childProcess = require('child_process');
14
+ var glob = require('glob');
15
+ var util = require('util');
16
16
  var node = require('@sentry/node');
17
17
 
18
18
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
@@ -37,27 +37,26 @@ function _interopNamespace(e) {
37
37
 
38
38
  var SentryCli__default = /*#__PURE__*/_interopDefaultLegacy(SentryCli);
39
39
  var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
40
- var MagicString__default = /*#__PURE__*/_interopDefaultLegacy(MagicString);
41
- var os__default = /*#__PURE__*/_interopDefaultLegacy(os);
40
+ var fs__namespace = /*#__PURE__*/_interopNamespace(fs);
42
41
  var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
43
- var util__namespace = /*#__PURE__*/_interopNamespace(util);
42
+ var path__namespace = /*#__PURE__*/_interopNamespace(path);
43
+ var MagicString__default = /*#__PURE__*/_interopDefaultLegacy(MagicString);
44
44
  var findUp__default = /*#__PURE__*/_interopDefaultLegacy(findUp);
45
+ var os__default = /*#__PURE__*/_interopDefaultLegacy(os);
45
46
  var crypto__default = /*#__PURE__*/_interopDefaultLegacy(crypto);
46
47
  var childProcess__default = /*#__PURE__*/_interopDefaultLegacy(childProcess);
48
+ var util__namespace = /*#__PURE__*/_interopNamespace(util);
47
49
 
48
50
  function ownKeys(object, enumerableOnly) {
49
51
  var keys = Object.keys(object);
50
-
51
52
  if (Object.getOwnPropertySymbols) {
52
53
  var symbols = Object.getOwnPropertySymbols(object);
53
54
  enumerableOnly && (symbols = symbols.filter(function (sym) {
54
55
  return Object.getOwnPropertyDescriptor(object, sym).enumerable;
55
56
  })), keys.push.apply(keys, symbols);
56
57
  }
57
-
58
58
  return keys;
59
59
  }
60
-
61
60
  function _objectSpread2(target) {
62
61
  for (var i = 1; i < arguments.length; i++) {
63
62
  var source = null != arguments[i] ? arguments[i] : {};
@@ -67,25 +66,22 @@ function _objectSpread2(target) {
67
66
  Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
68
67
  });
69
68
  }
70
-
71
69
  return target;
72
70
  }
73
-
74
71
  function _regeneratorRuntime() {
75
- /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
76
-
77
72
  _regeneratorRuntime = function () {
78
73
  return exports;
79
74
  };
80
-
81
75
  var exports = {},
82
- Op = Object.prototype,
83
- hasOwn = Op.hasOwnProperty,
84
- $Symbol = "function" == typeof Symbol ? Symbol : {},
85
- iteratorSymbol = $Symbol.iterator || "@@iterator",
86
- asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator",
87
- toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
88
-
76
+ Op = Object.prototype,
77
+ hasOwn = Op.hasOwnProperty,
78
+ defineProperty = Object.defineProperty || function (obj, key, desc) {
79
+ obj[key] = desc.value;
80
+ },
81
+ $Symbol = "function" == typeof Symbol ? Symbol : {},
82
+ iteratorSymbol = $Symbol.iterator || "@@iterator",
83
+ asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator",
84
+ toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
89
85
  function define(obj, key, value) {
90
86
  return Object.defineProperty(obj, key, {
91
87
  value: value,
@@ -94,7 +90,6 @@ function _regeneratorRuntime() {
94
90
  writable: !0
95
91
  }), obj[key];
96
92
  }
97
-
98
93
  try {
99
94
  define({}, "");
100
95
  } catch (err) {
@@ -102,54 +97,14 @@ function _regeneratorRuntime() {
102
97
  return obj[key] = value;
103
98
  };
104
99
  }
105
-
106
100
  function wrap(innerFn, outerFn, self, tryLocsList) {
107
101
  var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator,
108
- generator = Object.create(protoGenerator.prototype),
109
- context = new Context(tryLocsList || []);
110
- return generator._invoke = function (innerFn, self, context) {
111
- var state = "suspendedStart";
112
- return function (method, arg) {
113
- if ("executing" === state) throw new Error("Generator is already running");
114
-
115
- if ("completed" === state) {
116
- if ("throw" === method) throw arg;
117
- return doneResult();
118
- }
119
-
120
- for (context.method = method, context.arg = arg;;) {
121
- var delegate = context.delegate;
122
-
123
- if (delegate) {
124
- var delegateResult = maybeInvokeDelegate(delegate, context);
125
-
126
- if (delegateResult) {
127
- if (delegateResult === ContinueSentinel) continue;
128
- return delegateResult;
129
- }
130
- }
131
-
132
- if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) {
133
- if ("suspendedStart" === state) throw state = "completed", context.arg;
134
- context.dispatchException(context.arg);
135
- } else "return" === context.method && context.abrupt("return", context.arg);
136
- state = "executing";
137
- var record = tryCatch(innerFn, self, context);
138
-
139
- if ("normal" === record.type) {
140
- if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue;
141
- return {
142
- value: record.arg,
143
- done: context.done
144
- };
145
- }
146
-
147
- "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg);
148
- }
149
- };
150
- }(innerFn, self, context), generator;
102
+ generator = Object.create(protoGenerator.prototype),
103
+ context = new Context(tryLocsList || []);
104
+ return defineProperty(generator, "_invoke", {
105
+ value: makeInvokeMethod(innerFn, self, context)
106
+ }), generator;
151
107
  }
152
-
153
108
  function tryCatch(fn, obj, arg) {
154
109
  try {
155
110
  return {
@@ -163,25 +118,19 @@ function _regeneratorRuntime() {
163
118
  };
164
119
  }
165
120
  }
166
-
167
121
  exports.wrap = wrap;
168
122
  var ContinueSentinel = {};
169
-
170
123
  function Generator() {}
171
-
172
124
  function GeneratorFunction() {}
173
-
174
125
  function GeneratorFunctionPrototype() {}
175
-
176
126
  var IteratorPrototype = {};
177
127
  define(IteratorPrototype, iteratorSymbol, function () {
178
128
  return this;
179
129
  });
180
130
  var getProto = Object.getPrototypeOf,
181
- NativeIteratorPrototype = getProto && getProto(getProto(values([])));
131
+ NativeIteratorPrototype = getProto && getProto(getProto(values([])));
182
132
  NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype);
183
133
  var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
184
-
185
134
  function defineIteratorMethods(prototype) {
186
135
  ["next", "throw", "return"].forEach(function (method) {
187
136
  define(prototype, method, function (arg) {
@@ -189,14 +138,12 @@ function _regeneratorRuntime() {
189
138
  });
190
139
  });
191
140
  }
192
-
193
141
  function AsyncIterator(generator, PromiseImpl) {
194
142
  function invoke(method, arg, resolve, reject) {
195
143
  var record = tryCatch(generator[method], generator, arg);
196
-
197
144
  if ("throw" !== record.type) {
198
145
  var result = record.arg,
199
- value = result.value;
146
+ value = result.value;
200
147
  return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
201
148
  invoke("next", value, resolve, reject);
202
149
  }, function (err) {
@@ -207,90 +154,109 @@ function _regeneratorRuntime() {
207
154
  return invoke("throw", error, resolve, reject);
208
155
  });
209
156
  }
210
-
211
157
  reject(record.arg);
212
158
  }
213
-
214
159
  var previousPromise;
215
-
216
- this._invoke = function (method, arg) {
217
- function callInvokeWithMethodAndArg() {
218
- return new PromiseImpl(function (resolve, reject) {
219
- invoke(method, arg, resolve, reject);
220
- });
160
+ defineProperty(this, "_invoke", {
161
+ value: function (method, arg) {
162
+ function callInvokeWithMethodAndArg() {
163
+ return new PromiseImpl(function (resolve, reject) {
164
+ invoke(method, arg, resolve, reject);
165
+ });
166
+ }
167
+ return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
168
+ }
169
+ });
170
+ }
171
+ function makeInvokeMethod(innerFn, self, context) {
172
+ var state = "suspendedStart";
173
+ return function (method, arg) {
174
+ if ("executing" === state) throw new Error("Generator is already running");
175
+ if ("completed" === state) {
176
+ if ("throw" === method) throw arg;
177
+ return doneResult();
178
+ }
179
+ for (context.method = method, context.arg = arg;;) {
180
+ var delegate = context.delegate;
181
+ if (delegate) {
182
+ var delegateResult = maybeInvokeDelegate(delegate, context);
183
+ if (delegateResult) {
184
+ if (delegateResult === ContinueSentinel) continue;
185
+ return delegateResult;
186
+ }
187
+ }
188
+ if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) {
189
+ if ("suspendedStart" === state) throw state = "completed", context.arg;
190
+ context.dispatchException(context.arg);
191
+ } else "return" === context.method && context.abrupt("return", context.arg);
192
+ state = "executing";
193
+ var record = tryCatch(innerFn, self, context);
194
+ if ("normal" === record.type) {
195
+ if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue;
196
+ return {
197
+ value: record.arg,
198
+ done: context.done
199
+ };
200
+ }
201
+ "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg);
221
202
  }
222
-
223
- return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
224
203
  };
225
204
  }
226
-
227
205
  function maybeInvokeDelegate(delegate, context) {
228
- var method = delegate.iterator[context.method];
229
-
230
- if (undefined === method) {
231
- if (context.delegate = null, "throw" === context.method) {
232
- if (delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method)) return ContinueSentinel;
233
- context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method");
234
- }
235
-
236
- return ContinueSentinel;
237
- }
238
-
206
+ var methodName = context.method,
207
+ method = delegate.iterator[methodName];
208
+ if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel;
239
209
  var record = tryCatch(method, delegate.iterator, context.arg);
240
210
  if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel;
241
211
  var info = record.arg;
242
212
  return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel);
243
213
  }
244
-
245
214
  function pushTryEntry(locs) {
246
215
  var entry = {
247
216
  tryLoc: locs[0]
248
217
  };
249
218
  1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry);
250
219
  }
251
-
252
220
  function resetTryEntry(entry) {
253
221
  var record = entry.completion || {};
254
222
  record.type = "normal", delete record.arg, entry.completion = record;
255
223
  }
256
-
257
224
  function Context(tryLocsList) {
258
225
  this.tryEntries = [{
259
226
  tryLoc: "root"
260
227
  }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0);
261
228
  }
262
-
263
229
  function values(iterable) {
264
230
  if (iterable) {
265
231
  var iteratorMethod = iterable[iteratorSymbol];
266
232
  if (iteratorMethod) return iteratorMethod.call(iterable);
267
233
  if ("function" == typeof iterable.next) return iterable;
268
-
269
234
  if (!isNaN(iterable.length)) {
270
235
  var i = -1,
271
- next = function next() {
272
- for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next;
273
-
274
- return next.value = undefined, next.done = !0, next;
275
- };
276
-
236
+ next = function next() {
237
+ for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next;
238
+ return next.value = undefined, next.done = !0, next;
239
+ };
277
240
  return next.next = next;
278
241
  }
279
242
  }
280
-
281
243
  return {
282
244
  next: doneResult
283
245
  };
284
246
  }
285
-
286
247
  function doneResult() {
287
248
  return {
288
249
  value: undefined,
289
250
  done: !0
290
251
  };
291
252
  }
292
-
293
- return GeneratorFunction.prototype = GeneratorFunctionPrototype, define(Gp, "constructor", GeneratorFunctionPrototype), define(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) {
253
+ return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", {
254
+ value: GeneratorFunctionPrototype,
255
+ configurable: !0
256
+ }), defineProperty(GeneratorFunctionPrototype, "constructor", {
257
+ value: GeneratorFunction,
258
+ configurable: !0
259
+ }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) {
294
260
  var ctor = "function" == typeof genFun && genFun.constructor;
295
261
  return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name));
296
262
  }, exports.mark = function (genFun) {
@@ -311,17 +277,15 @@ function _regeneratorRuntime() {
311
277
  return this;
312
278
  }), define(Gp, "toString", function () {
313
279
  return "[object Generator]";
314
- }), exports.keys = function (object) {
315
- var keys = [];
316
-
280
+ }), exports.keys = function (val) {
281
+ var object = Object(val),
282
+ keys = [];
317
283
  for (var key in object) keys.push(key);
318
-
319
284
  return keys.reverse(), function next() {
320
285
  for (; keys.length;) {
321
286
  var key = keys.pop();
322
287
  if (key in object) return next.value = key, next.done = !1, next;
323
288
  }
324
-
325
289
  return next.done = !0, next;
326
290
  };
327
291
  }, exports.values = values, Context.prototype = {
@@ -338,20 +302,16 @@ function _regeneratorRuntime() {
338
302
  dispatchException: function (exception) {
339
303
  if (this.done) throw exception;
340
304
  var context = this;
341
-
342
305
  function handle(loc, caught) {
343
306
  return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught;
344
307
  }
345
-
346
308
  for (var i = this.tryEntries.length - 1; i >= 0; --i) {
347
309
  var entry = this.tryEntries[i],
348
- record = entry.completion;
310
+ record = entry.completion;
349
311
  if ("root" === entry.tryLoc) return handle("end");
350
-
351
312
  if (entry.tryLoc <= this.prev) {
352
313
  var hasCatch = hasOwn.call(entry, "catchLoc"),
353
- hasFinally = hasOwn.call(entry, "finallyLoc");
354
-
314
+ hasFinally = hasOwn.call(entry, "finallyLoc");
355
315
  if (hasCatch && hasFinally) {
356
316
  if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
357
317
  if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
@@ -367,13 +327,11 @@ function _regeneratorRuntime() {
367
327
  abrupt: function (type, arg) {
368
328
  for (var i = this.tryEntries.length - 1; i >= 0; --i) {
369
329
  var entry = this.tryEntries[i];
370
-
371
330
  if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
372
331
  var finallyEntry = entry;
373
332
  break;
374
333
  }
375
334
  }
376
-
377
335
  finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null);
378
336
  var record = finallyEntry ? finallyEntry.completion : {};
379
337
  return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record);
@@ -391,19 +349,15 @@ function _regeneratorRuntime() {
391
349
  catch: function (tryLoc) {
392
350
  for (var i = this.tryEntries.length - 1; i >= 0; --i) {
393
351
  var entry = this.tryEntries[i];
394
-
395
352
  if (entry.tryLoc === tryLoc) {
396
353
  var record = entry.completion;
397
-
398
354
  if ("throw" === record.type) {
399
355
  var thrown = record.arg;
400
356
  resetTryEntry(entry);
401
357
  }
402
-
403
358
  return thrown;
404
359
  }
405
360
  }
406
-
407
361
  throw new Error("illegal catch attempt");
408
362
  },
409
363
  delegateYield: function (iterable, resultName, nextLoc) {
@@ -415,7 +369,6 @@ function _regeneratorRuntime() {
415
369
  }
416
370
  }, exports;
417
371
  }
418
-
419
372
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
420
373
  try {
421
374
  var info = gen[key](arg);
@@ -424,35 +377,30 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
424
377
  reject(error);
425
378
  return;
426
379
  }
427
-
428
380
  if (info.done) {
429
381
  resolve(value);
430
382
  } else {
431
383
  Promise.resolve(value).then(_next, _throw);
432
384
  }
433
385
  }
434
-
435
386
  function _asyncToGenerator(fn) {
436
387
  return function () {
437
388
  var self = this,
438
- args = arguments;
389
+ args = arguments;
439
390
  return new Promise(function (resolve, reject) {
440
391
  var gen = fn.apply(self, args);
441
-
442
392
  function _next(value) {
443
393
  asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
444
394
  }
445
-
446
395
  function _throw(err) {
447
396
  asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
448
397
  }
449
-
450
398
  _next(undefined);
451
399
  });
452
400
  };
453
401
  }
454
-
455
402
  function _defineProperty(obj, key, value) {
403
+ key = _toPropertyKey(key);
456
404
  if (key in obj) {
457
405
  Object.defineProperty(obj, key, {
458
406
  value: value,
@@ -463,787 +411,725 @@ function _defineProperty(obj, key, value) {
463
411
  } else {
464
412
  obj[key] = value;
465
413
  }
466
-
467
414
  return obj;
468
415
  }
469
-
470
- var SENTRY_SAAS_URL = "https://sentry.io";
471
- function normalizeUserOptions(userOptions) {
472
- var _userOptions$org, _userOptions$project, _userOptions$authToke, _ref, _userOptions$url, _userOptions$debug, _userOptions$silent, _userOptions$telemetr, _userOptions$disable, _userOptions$release$, _userOptions$release, _userOptions$release$2, _userOptions$release2, _userOptions$release$3, _userOptions$release3, _ref2, _userOptions$release$4, _userOptions$release4, _userOptions$release$5, _userOptions$release5, _userOptions$_experim;
473
-
474
- var options = {
475
- org: (_userOptions$org = userOptions.org) !== null && _userOptions$org !== void 0 ? _userOptions$org : process.env["SENTRY_ORG"],
476
- project: (_userOptions$project = userOptions.project) !== null && _userOptions$project !== void 0 ? _userOptions$project : process.env["SENTRY_PROJECT"],
477
- authToken: (_userOptions$authToke = userOptions.authToken) !== null && _userOptions$authToke !== void 0 ? _userOptions$authToke : process.env["SENTRY_AUTH_TOKEN"],
478
- url: (_ref = (_userOptions$url = userOptions.url) !== null && _userOptions$url !== void 0 ? _userOptions$url : process.env["SENTRY_URL"]) !== null && _ref !== void 0 ? _ref : SENTRY_SAAS_URL,
479
- headers: userOptions.headers,
480
- debug: (_userOptions$debug = userOptions.debug) !== null && _userOptions$debug !== void 0 ? _userOptions$debug : false,
481
- silent: (_userOptions$silent = userOptions.silent) !== null && _userOptions$silent !== void 0 ? _userOptions$silent : false,
482
- errorHandler: userOptions.errorHandler,
483
- telemetry: (_userOptions$telemetr = userOptions.telemetry) !== null && _userOptions$telemetr !== void 0 ? _userOptions$telemetr : true,
484
- disable: (_userOptions$disable = userOptions.disable) !== null && _userOptions$disable !== void 0 ? _userOptions$disable : false,
485
- sourcemaps: userOptions.sourcemaps,
486
- release: _objectSpread2(_objectSpread2({}, userOptions.release), {}, {
487
- inject: (_userOptions$release$ = (_userOptions$release = userOptions.release) === null || _userOptions$release === void 0 ? void 0 : _userOptions$release.inject) !== null && _userOptions$release$ !== void 0 ? _userOptions$release$ : true,
488
- create: (_userOptions$release$2 = (_userOptions$release2 = userOptions.release) === null || _userOptions$release2 === void 0 ? void 0 : _userOptions$release2.create) !== null && _userOptions$release$2 !== void 0 ? _userOptions$release$2 : true,
489
- finalize: (_userOptions$release$3 = (_userOptions$release3 = userOptions.release) === null || _userOptions$release3 === void 0 ? void 0 : _userOptions$release3.finalize) !== null && _userOptions$release$3 !== void 0 ? _userOptions$release$3 : true,
490
- vcsRemote: (_ref2 = (_userOptions$release$4 = (_userOptions$release4 = userOptions.release) === null || _userOptions$release4 === void 0 ? void 0 : _userOptions$release4.vcsRemote) !== null && _userOptions$release$4 !== void 0 ? _userOptions$release$4 : process.env["SENTRY_VSC_REMOTE"]) !== null && _ref2 !== void 0 ? _ref2 : "origin",
491
- cleanArtifacts: (_userOptions$release$5 = (_userOptions$release5 = userOptions.release) === null || _userOptions$release5 === void 0 ? void 0 : _userOptions$release5.cleanArtifacts) !== null && _userOptions$release$5 !== void 0 ? _userOptions$release$5 : false
492
- }),
493
- _experiments: (_userOptions$_experim = userOptions._experiments) !== null && _userOptions$_experim !== void 0 ? _userOptions$_experim : {}
494
- };
495
- return options;
416
+ function _toPrimitive(input, hint) {
417
+ if (typeof input !== "object" || input === null) return input;
418
+ var prim = input[Symbol.toPrimitive];
419
+ if (prim !== undefined) {
420
+ var res = prim.call(input, hint || "default");
421
+ if (typeof res !== "object") return res;
422
+ throw new TypeError("@@toPrimitive must return a primitive value.");
423
+ }
424
+ return (hint === "string" ? String : Number)(input);
496
425
  }
426
+ function _toPropertyKey(arg) {
427
+ var key = _toPrimitive(arg, "string");
428
+ return typeof key === "symbol" ? key : String(key);
429
+ }
430
+
497
431
  /**
498
- * Validates a few combinations of options that are not checked by Sentry CLI.
499
- *
500
- * For all other options, we can rely on Sentry CLI to validate them. In fact,
501
- * we can't validate them in the plugin because Sentry CLI might pick up options from
502
- * its config file.
503
- *
504
- * @param options the internal options
505
- * @param logger the logger
432
+ * Checks whether the given input is already an array, and if it isn't, wraps it in one.
506
433
  *
507
- * @returns `true` if the options are valid, `false` otherwise
434
+ * @param maybeArray Input to turn into an array, if necessary
435
+ * @returns The input, if already an array, or an array with the input as the only element, if not
436
+ */
437
+ function arrayify(maybeArray) {
438
+ return Array.isArray(maybeArray) ? maybeArray : [maybeArray];
439
+ }
440
+ /**
441
+ * Get the closes package.json from a given starting point upwards.
442
+ * This handles a few edge cases:
443
+ * * Check if a given file package.json appears to be an actual NPM package.json file
444
+ * * Stop at the home dir, to avoid looking too deeply
508
445
  */
446
+ function getPackageJson() {
447
+ var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
448
+ cwd = _ref.cwd,
449
+ stopAt = _ref.stopAt;
450
+ return lookupPackageJson(cwd !== null && cwd !== void 0 ? cwd : process.cwd(), path__default["default"].normalize(stopAt !== null && stopAt !== void 0 ? stopAt : os__default["default"].homedir()));
451
+ }
452
+ function parseMajorVersion(version) {
453
+ // if it has a `v` prefix, remove it
454
+ if (version.startsWith("v")) {
455
+ version = version.slice(1);
456
+ }
509
457
 
510
- function validateOptions(options, logger) {
511
- var _options$release, _options$release2, _options$release3;
458
+ // First, try simple lookup of exact, ~ and ^ versions
459
+ var regex = /^[\^~]?(\d+)(\.\d+)?(\.\d+)?(-.+)?/;
460
+ var match = version.match(regex);
461
+ if (match) {
462
+ return parseInt(match[1], 10);
463
+ }
512
464
 
513
- var setCommits = (_options$release = options.release) === null || _options$release === void 0 ? void 0 : _options$release.setCommits;
465
+ // Try to parse e.g. 1.x
466
+ var coerced = parseInt(version, 10);
467
+ if (!Number.isNaN(coerced)) {
468
+ return coerced;
469
+ }
514
470
 
515
- if (setCommits) {
516
- if (!setCommits.auto && !(setCommits.repo && setCommits.commit)) {
517
- logger.error("The `setCommits` option was specified but is missing required properties.", "Please set either `auto` or both, `repo` and `commit`.");
518
- return false;
519
- }
471
+ // Match <= and >= ranges.
472
+ var gteLteRegex = /^[<>]=\s*(\d+)(\.\d+)?(\.\d+)?(-.+)?/;
473
+ var gteLteMatch = version.match(gteLteRegex);
474
+ if (gteLteMatch) {
475
+ return parseInt(gteLteMatch[1], 10);
476
+ }
520
477
 
521
- if (setCommits.auto && setCommits.repo && setCommits) {
522
- logger.warn("The `setCommits` options includes `auto` but also `repo` and `commit`.", "Ignoring `repo` and `commit`.", "Please only set either `auto` or both, `repo` and `commit`.");
478
+ // match < ranges
479
+ var ltRegex = /^<\s*(\d+)(\.\d+)?(\.\d+)?(-.+)?/;
480
+ var ltMatch = version.match(ltRegex);
481
+ if (ltMatch) {
482
+ // Two scenarios:
483
+ // a) < 2.0.0 --> return 1
484
+ // b) < 2.1.0 --> return 2
485
+
486
+ var major = parseInt(ltMatch[1], 10);
487
+ if (
488
+ // minor version > 0
489
+ typeof ltMatch[2] === "string" && parseInt(ltMatch[2].slice(1), 10) > 0 ||
490
+ // patch version > 0
491
+ typeof ltMatch[3] === "string" && parseInt(ltMatch[3].slice(1), 10) > 0) {
492
+ return major;
523
493
  }
494
+ return major - 1;
524
495
  }
525
496
 
526
- if ((_options$release2 = options.release) !== null && _options$release2 !== void 0 && _options$release2.deploy && !((_options$release3 = options.release) !== null && _options$release3 !== void 0 && _options$release3.deploy.env)) {
527
- logger.error("The `deploy` option was specified but is missing the required `env` property.", "Please set the `env` property.");
528
- return false;
497
+ // match > ranges
498
+ var gtRegex = /^>\s*(\d+)(\.\d+)?(\.\d+)?(-.+)?/;
499
+ var gtMatch = version.match(gtRegex);
500
+ if (gtMatch) {
501
+ // We always return the version here, even though it _may_ be incorrect
502
+ // E.g. if given > 2.0.0, it should be 2 if there exists any 2.x.x version, else 3
503
+ // Since there is no way for us to know this, we're going to assume any kind of patch/feature release probably exists
504
+ return parseInt(gtMatch[1], 10);
529
505
  }
530
-
531
- return true;
506
+ return undefined;
532
507
  }
533
508
 
534
- function debugIdUploadPlugin(_ref) {
535
- var assets = _ref.assets,
536
- ignore = _ref.ignore,
537
- logger = _ref.logger,
538
- releaseName = _ref.releaseName,
539
- dist = _ref.dist,
540
- handleRecoverableError = _ref.handleRecoverableError,
541
- sentryHub = _ref.sentryHub,
542
- sentryClient = _ref.sentryClient,
543
- sentryCliOptions = _ref.sentryCliOptions,
544
- rewriteSourcesHook = _ref.rewriteSourcesHook,
545
- deleteFilesAfterUpload = _ref.deleteFilesAfterUpload;
509
+ // This is an explicit list of packages where we want to include the (major) version number.
510
+ var PACKAGES_TO_INCLUDE_VERSION = ["react", "@angular/core", "vue", "ember-source", "svelte", "@sveltejs/kit", "webpack", "vite", "gatsby", "next", "remix", "rollup", "esbuild"];
511
+ function getDependencies(packageJson) {
512
+ var _packageJson$devDepen, _packageJson$dependen;
513
+ 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 : {});
514
+ var deps = Object.keys(dependencies).sort();
515
+ var depsVersions = deps.reduce(function (depsVersions, depName) {
516
+ if (PACKAGES_TO_INCLUDE_VERSION.includes(depName)) {
517
+ var version = dependencies[depName];
518
+ var majorVersion = parseMajorVersion(version);
519
+ if (majorVersion) {
520
+ depsVersions[depName] = majorVersion;
521
+ }
522
+ }
523
+ return depsVersions;
524
+ }, {});
546
525
  return {
547
- name: "sentry-debug-id-upload-plugin",
548
- writeBundle: function writeBundle() {
549
- return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
550
- var folderToCleanUp, cliInstance, tmpUploadFolder, debugIdChunkFilePaths, filePathsToDelete;
551
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
552
- while (1) {
553
- switch (_context2.prev = _context2.next) {
554
- case 0:
555
- cliInstance = new SentryCli__default["default"](null, sentryCliOptions);
556
- _context2.prev = 1;
557
- _context2.next = 4;
558
- return fs__default["default"].promises.mkdtemp(path__default["default"].join(os__default["default"].tmpdir(), "sentry-bundler-plugin-upload-"));
559
-
560
- case 4:
561
- tmpUploadFolder = _context2.sent;
562
- folderToCleanUp = tmpUploadFolder;
563
- _context2.next = 8;
564
- return glob.glob(assets, {
565
- absolute: true,
566
- nodir: true,
567
- ignore: ignore
568
- });
569
-
570
- case 8:
571
- debugIdChunkFilePaths = _context2.sent.filter(function (debugIdChunkFilePath) {
572
- return debugIdChunkFilePath.endsWith(".js") || debugIdChunkFilePath.endsWith(".mjs") || debugIdChunkFilePath.endsWith(".cjs");
573
- });
574
- _context2.next = 11;
575
- return Promise.all(debugIdChunkFilePaths.map( /*#__PURE__*/function () {
576
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(chunkFilePath, chunkIndex) {
577
- return _regeneratorRuntime().wrap(function _callee$(_context) {
578
- while (1) {
579
- switch (_context.prev = _context.next) {
580
- case 0:
581
- _context.next = 2;
582
- return prepareBundleForDebugIdUpload(chunkFilePath, tmpUploadFolder, chunkIndex, logger, rewriteSourcesHook !== null && rewriteSourcesHook !== void 0 ? rewriteSourcesHook : defaultRewriteSourcesHook);
583
-
584
- case 2:
585
- case "end":
586
- return _context.stop();
587
- }
588
- }
589
- }, _callee);
590
- }));
591
-
592
- return function (_x, _x2) {
593
- return _ref2.apply(this, arguments);
594
- };
595
- }()));
526
+ deps: deps,
527
+ depsVersions: depsVersions
528
+ };
529
+ }
530
+ function lookupPackageJson(cwd, stopAt) {
531
+ var jsonPath = findUp__default["default"].sync(function (dirName) {
532
+ // Stop if we reach this dir
533
+ if (path__default["default"].normalize(dirName) === stopAt) {
534
+ return findUp__default["default"].stop;
535
+ }
536
+ return findUp__default["default"].sync.exists(dirName + "/package.json") ? "package.json" : undefined;
537
+ }, {
538
+ cwd: cwd
539
+ });
540
+ if (!jsonPath) {
541
+ return undefined;
542
+ }
543
+ try {
544
+ var jsonStr = fs__default["default"].readFileSync(jsonPath, "utf8");
545
+ var json = JSON.parse(jsonStr);
596
546
 
597
- case 11:
598
- _context2.next = 13;
599
- return cliInstance.releases.uploadSourceMaps(releaseName !== null && releaseName !== void 0 ? releaseName : "undefined", // unfortunetly this needs a value for now but it will not matter since debug IDs overpower releases anyhow
600
- {
601
- include: [{
602
- paths: [tmpUploadFolder],
603
- rewrite: false,
604
- dist: dist
605
- }],
606
- useArtifactBundle: true
607
- });
547
+ // Ensure it is an actual package.json
548
+ // This is very much not bulletproof, but should be good enough
549
+ if ("name" in json || "private" in json) {
550
+ return json;
551
+ }
552
+ } catch (error) {
553
+ // Ignore and walk up
554
+ }
608
555
 
609
- case 13:
610
- if (!deleteFilesAfterUpload) {
611
- _context2.next = 20;
612
- break;
613
- }
556
+ // Continue up the tree, if we find a fitting package.json
557
+ var newCwd = path__default["default"].dirname(path__default["default"].resolve(jsonPath + "/.."));
558
+ return lookupPackageJson(newCwd, stopAt);
559
+ }
614
560
 
615
- _context2.next = 16;
616
- return glob.glob(deleteFilesAfterUpload, {
617
- absolute: true,
618
- nodir: true
619
- });
620
-
621
- case 16:
622
- filePathsToDelete = _context2.sent;
623
- filePathsToDelete.forEach(function (filePathToDelete) {
624
- logger.debug("Deleting asset after upload: ".concat(filePathToDelete));
625
- });
626
- _context2.next = 20;
627
- return Promise.all(filePathsToDelete.map(function (filePathToDelete) {
628
- return fs__default["default"].promises.rm(filePathToDelete, {
629
- force: true
630
- });
631
- }));
632
-
633
- case 20:
634
- _context2.next = 28;
635
- break;
636
-
637
- case 22:
638
- _context2.prev = 22;
639
- _context2.t0 = _context2["catch"](1);
640
- sentryHub.captureException('Error in "debugIdUploadPlugin" writeBundle hook');
641
- _context2.next = 27;
642
- return sentryClient.flush();
561
+ /**
562
+ * Deterministically hashes a string and turns the hash into a uuid.
563
+ */
564
+ function stringToUUID(str) {
565
+ var md5sum = crypto__default["default"].createHash("md5");
566
+ md5sum.update(str);
567
+ var md5Hash = md5sum.digest("hex");
568
+ return (md5Hash.substring(0, 8) + "-" + md5Hash.substring(8, 12) + "-4" + md5Hash.substring(13, 16) + "-" + md5Hash.substring(16, 20) + "-" + md5Hash.substring(20)).toLowerCase();
569
+ }
643
570
 
644
- case 27:
645
- handleRecoverableError(_context2.t0);
571
+ /**
572
+ * Tries to guess a release name based on environmental data.
573
+ */
574
+ function determineReleaseName() {
575
+ var gitRevision;
576
+ try {
577
+ gitRevision = childProcess__default["default"].execSync("git rev-parse --short HEAD").toString().trim();
578
+ } catch (e) {
579
+ // noop
580
+ }
581
+ return (
582
+ // GitHub Actions - https://help.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables#default-environment-variables
583
+ process.env["GITHUB_SHA"] ||
584
+ // Netlify - https://docs.netlify.com/configure-builds/environment-variables/#build-metadata
585
+ process.env["COMMIT_REF"] ||
586
+ // Cloudflare Pages - https://developers.cloudflare.com/pages/platform/build-configuration/#environment-variables
587
+ process.env["CF_PAGES_COMMIT_SHA"] ||
588
+ // AWS CodeBuild - https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-env-vars.html
589
+ process.env["CODEBUILD_RESOLVED_SOURCE_VERSION"] ||
590
+ // CircleCI - https://circleci.com/docs/2.0/env-vars/
591
+ process.env["CIRCLE_SHA1"] ||
592
+ // Vercel - https://vercel.com/docs/v2/build-step#system-environment-variables
593
+ process.env["VERCEL_GIT_COMMIT_SHA"] || process.env["VERCEL_GITHUB_COMMIT_SHA"] || process.env["VERCEL_GITLAB_COMMIT_SHA"] || process.env["VERCEL_BITBUCKET_COMMIT_SHA"] ||
594
+ // Zeit (now known as Vercel)
595
+ process.env["ZEIT_GITHUB_COMMIT_SHA"] || process.env["ZEIT_GITLAB_COMMIT_SHA"] || process.env["ZEIT_BITBUCKET_COMMIT_SHA"] || gitRevision
596
+ );
597
+ }
646
598
 
647
- case 28:
648
- _context2.prev = 28;
599
+ /**
600
+ * Generates code for the global injector which is responsible for setting the global
601
+ * `SENTRY_RELEASE` & `SENTRY_BUILD_INFO` variables.
602
+ */
603
+ function generateGlobalInjectorCode(_ref2) {
604
+ var release = _ref2.release,
605
+ injectBuildInformation = _ref2.injectBuildInformation;
606
+ // The code below is mostly ternary operators because it saves bundle size.
607
+ // The checks are to support as many environments as possible. (Node.js, Browser, webworkers, etc.)
608
+ 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, "\"};");
609
+ if (injectBuildInformation) {
610
+ var buildInfo = getBuildInformation$1();
611
+ code += "\n _global.SENTRY_BUILD_INFO=".concat(JSON.stringify(buildInfo), ";");
612
+ }
613
+ return code;
614
+ }
615
+ function getBuildInformation$1() {
616
+ var packageJson = getPackageJson();
617
+ var _ref3 = packageJson ? getDependencies(packageJson) : {
618
+ deps: [],
619
+ depsVersions: {}
620
+ },
621
+ deps = _ref3.deps,
622
+ depsVersions = _ref3.depsVersions;
623
+ return {
624
+ deps: deps,
625
+ depsVersions: depsVersions,
626
+ nodeVersion: parseMajorVersion(process.version)
627
+ };
628
+ }
629
+ function stripQueryAndHashFromPath(path) {
630
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
631
+ return path.split("?")[0].split("#")[0];
632
+ }
649
633
 
650
- if (folderToCleanUp) {
651
- void fs__default["default"].promises.rm(folderToCleanUp, {
652
- recursive: true,
653
- force: true
654
- });
655
- }
634
+ var SENTRY_SAAS_URL = "https://sentry.io";
635
+ function normalizeUserOptions(userOptions) {
636
+ 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;
637
+ var options = {
638
+ org: (_userOptions$org = userOptions.org) !== null && _userOptions$org !== void 0 ? _userOptions$org : process.env["SENTRY_ORG"],
639
+ project: (_userOptions$project = userOptions.project) !== null && _userOptions$project !== void 0 ? _userOptions$project : process.env["SENTRY_PROJECT"],
640
+ authToken: (_userOptions$authToke = userOptions.authToken) !== null && _userOptions$authToke !== void 0 ? _userOptions$authToke : process.env["SENTRY_AUTH_TOKEN"],
641
+ url: (_ref = (_userOptions$url = userOptions.url) !== null && _userOptions$url !== void 0 ? _userOptions$url : process.env["SENTRY_URL"]) !== null && _ref !== void 0 ? _ref : SENTRY_SAAS_URL,
642
+ headers: userOptions.headers,
643
+ debug: (_userOptions$debug = userOptions.debug) !== null && _userOptions$debug !== void 0 ? _userOptions$debug : false,
644
+ silent: (_userOptions$silent = userOptions.silent) !== null && _userOptions$silent !== void 0 ? _userOptions$silent : false,
645
+ errorHandler: userOptions.errorHandler,
646
+ telemetry: (_userOptions$telemetr = userOptions.telemetry) !== null && _userOptions$telemetr !== void 0 ? _userOptions$telemetr : true,
647
+ disable: (_userOptions$disable = userOptions.disable) !== null && _userOptions$disable !== void 0 ? _userOptions$disable : false,
648
+ sourcemaps: userOptions.sourcemaps,
649
+ release: _objectSpread2(_objectSpread2({}, userOptions.release), {}, {
650
+ 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(),
651
+ 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,
652
+ 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,
653
+ 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,
654
+ 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",
655
+ 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
656
+ }),
657
+ _experiments: (_userOptions$_experim = userOptions._experiments) !== null && _userOptions$_experim !== void 0 ? _userOptions$_experim : {}
658
+ };
659
+ return options;
660
+ }
656
661
 
657
- return _context2.finish(28);
662
+ /**
663
+ * Validates a few combinations of options that are not checked by Sentry CLI.
664
+ *
665
+ * For all other options, we can rely on Sentry CLI to validate them. In fact,
666
+ * we can't validate them in the plugin because Sentry CLI might pick up options from
667
+ * its config file.
668
+ *
669
+ * @param options the internal options
670
+ * @param logger the logger
671
+ *
672
+ * @returns `true` if the options are valid, `false` otherwise
673
+ */
674
+ function validateOptions(options, logger) {
675
+ var _options$release, _options$release2, _options$release3;
676
+ var setCommits = (_options$release = options.release) === null || _options$release === void 0 ? void 0 : _options$release.setCommits;
677
+ if (setCommits) {
678
+ if (!setCommits.auto && !(setCommits.repo && setCommits.commit)) {
679
+ logger.error("The `setCommits` option was specified but is missing required properties.", "Please set either `auto` or both, `repo` and `commit`.");
680
+ return false;
681
+ }
682
+ if (setCommits.auto && setCommits.repo && setCommits) {
683
+ logger.warn("The `setCommits` options includes `auto` but also `repo` and `commit`.", "Ignoring `repo` and `commit`.", "Please only set either `auto` or both, `repo` and `commit`.");
684
+ }
685
+ }
686
+ if ((_options$release2 = options.release) !== null && _options$release2 !== void 0 && _options$release2.deploy && !((_options$release3 = options.release) !== null && _options$release3 !== void 0 && _options$release3.deploy.env)) {
687
+ logger.error("The `deploy` option was specified but is missing the required `env` property.", "Please set the `env` property.");
688
+ return false;
689
+ }
690
+ return true;
691
+ }
658
692
 
659
- case 31:
660
- case "end":
661
- return _context2.stop();
693
+ function createDebugIdUploadFunction(_ref) {
694
+ var assets = _ref.assets,
695
+ ignore = _ref.ignore,
696
+ logger = _ref.logger,
697
+ releaseName = _ref.releaseName,
698
+ dist = _ref.dist,
699
+ handleRecoverableError = _ref.handleRecoverableError,
700
+ sentryHub = _ref.sentryHub,
701
+ sentryClient = _ref.sentryClient,
702
+ sentryCliOptions = _ref.sentryCliOptions,
703
+ rewriteSourcesHook = _ref.rewriteSourcesHook,
704
+ deleteFilesAfterUpload = _ref.deleteFilesAfterUpload;
705
+ return /*#__PURE__*/function () {
706
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(buildArtifactPaths) {
707
+ var folderToCleanUp, cliInstance, tmpUploadFolder, globAssets, debugIdChunkFilePaths, filePathsToDelete;
708
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
709
+ while (1) switch (_context2.prev = _context2.next) {
710
+ case 0:
711
+ cliInstance = new SentryCli__default["default"](null, sentryCliOptions);
712
+ _context2.prev = 1;
713
+ _context2.next = 4;
714
+ return fs__default["default"].promises.mkdtemp(path__default["default"].join(os__default["default"].tmpdir(), "sentry-bundler-plugin-upload-"));
715
+ case 4:
716
+ tmpUploadFolder = _context2.sent;
717
+ folderToCleanUp = tmpUploadFolder;
718
+ if (assets) {
719
+ globAssets = assets;
720
+ } else {
721
+ logger.debug("No `sourcemaps.assets` option provided, falling back to uploading detected build artifacts.");
722
+ globAssets = buildArtifactPaths;
662
723
  }
663
- }
664
- }, _callee2, null, [[1, 22, 28, 31]]);
665
- }))();
666
- }
667
- };
724
+ _context2.next = 9;
725
+ return glob.glob(globAssets, {
726
+ absolute: true,
727
+ nodir: true,
728
+ ignore: ignore
729
+ });
730
+ case 9:
731
+ debugIdChunkFilePaths = _context2.sent.filter(function (debugIdChunkFilePath) {
732
+ return debugIdChunkFilePath.endsWith(".js") || debugIdChunkFilePath.endsWith(".mjs") || debugIdChunkFilePath.endsWith(".cjs");
733
+ });
734
+ if (!(Array.isArray(assets) && assets.length === 0)) {
735
+ _context2.next = 14;
736
+ break;
737
+ }
738
+ logger.debug("Empty `sourcemaps.assets` option provided. Will not upload sourcemaps with debug ID.");
739
+ _context2.next = 22;
740
+ break;
741
+ case 14:
742
+ if (!(debugIdChunkFilePaths.length === 0)) {
743
+ _context2.next = 18;
744
+ break;
745
+ }
746
+ logger.warn("Didn't find any matching sources for debug ID upload. Please check the `sourcemaps.assets` option.");
747
+ _context2.next = 22;
748
+ break;
749
+ case 18:
750
+ _context2.next = 20;
751
+ return Promise.all(debugIdChunkFilePaths.map( /*#__PURE__*/function () {
752
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(chunkFilePath, chunkIndex) {
753
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
754
+ while (1) switch (_context.prev = _context.next) {
755
+ case 0:
756
+ _context.next = 2;
757
+ return prepareBundleForDebugIdUpload(chunkFilePath, tmpUploadFolder, chunkIndex, logger, rewriteSourcesHook !== null && rewriteSourcesHook !== void 0 ? rewriteSourcesHook : defaultRewriteSourcesHook);
758
+ case 2:
759
+ case "end":
760
+ return _context.stop();
761
+ }
762
+ }, _callee);
763
+ }));
764
+ return function (_x2, _x3) {
765
+ return _ref3.apply(this, arguments);
766
+ };
767
+ }()));
768
+ case 20:
769
+ _context2.next = 22;
770
+ return cliInstance.releases.uploadSourceMaps(releaseName !== null && releaseName !== void 0 ? releaseName : "undefined",
771
+ // unfortunetly this needs a value for now but it will not matter since debug IDs overpower releases anyhow
772
+ {
773
+ include: [{
774
+ paths: [tmpUploadFolder],
775
+ rewrite: false,
776
+ dist: dist
777
+ }],
778
+ useArtifactBundle: true
779
+ });
780
+ case 22:
781
+ if (!deleteFilesAfterUpload) {
782
+ _context2.next = 29;
783
+ break;
784
+ }
785
+ _context2.next = 25;
786
+ return glob.glob(deleteFilesAfterUpload, {
787
+ absolute: true,
788
+ nodir: true
789
+ });
790
+ case 25:
791
+ filePathsToDelete = _context2.sent;
792
+ filePathsToDelete.forEach(function (filePathToDelete) {
793
+ logger.debug("Deleting asset after upload: ".concat(filePathToDelete));
794
+ });
795
+ _context2.next = 29;
796
+ return Promise.all(filePathsToDelete.map(function (filePathToDelete) {
797
+ return fs__default["default"].promises.rm(filePathToDelete, {
798
+ force: true
799
+ });
800
+ }));
801
+ case 29:
802
+ _context2.next = 37;
803
+ break;
804
+ case 31:
805
+ _context2.prev = 31;
806
+ _context2.t0 = _context2["catch"](1);
807
+ sentryHub.captureException('Error in "debugIdUploadPlugin" writeBundle hook');
808
+ _context2.next = 36;
809
+ return sentryClient.flush();
810
+ case 36:
811
+ handleRecoverableError(_context2.t0);
812
+ case 37:
813
+ _context2.prev = 37;
814
+ if (folderToCleanUp) {
815
+ void fs__default["default"].promises.rm(folderToCleanUp, {
816
+ recursive: true,
817
+ force: true
818
+ });
819
+ }
820
+ return _context2.finish(37);
821
+ case 40:
822
+ case "end":
823
+ return _context2.stop();
824
+ }
825
+ }, _callee2, null, [[1, 31, 37, 40]]);
826
+ }));
827
+ return function (_x) {
828
+ return _ref2.apply(this, arguments);
829
+ };
830
+ }();
668
831
  }
669
- function prepareBundleForDebugIdUpload(_x3, _x4, _x5, _x6, _x7) {
832
+ function prepareBundleForDebugIdUpload(_x4, _x5, _x6, _x7, _x8) {
670
833
  return _prepareBundleForDebugIdUpload.apply(this, arguments);
671
834
  }
835
+
672
836
  /**
673
837
  * Looks for a particular string pattern (`sdbid-[debug ID]`) in the bundle
674
838
  * source and extracts the bundle's debug ID from it.
675
839
  *
676
840
  * The string pattern is injected via the debug ID injection snipped.
677
841
  */
678
-
679
842
  function _prepareBundleForDebugIdUpload() {
680
843
  _prepareBundleForDebugIdUpload = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(bundleFilePath, uploadFolder, chunkIndex, logger, rewriteSourcesHook) {
681
844
  var bundleContent, debugId, uniqueUploadName, writeSourceFilePromise, writeSourceMapFilePromise;
682
845
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
683
- while (1) {
684
- switch (_context4.prev = _context4.next) {
685
- case 0:
686
- _context4.prev = 0;
687
- _context4.next = 3;
688
- return util.promisify(fs__default["default"].readFile)(bundleFilePath, "utf8");
689
-
690
- case 3:
691
- bundleContent = _context4.sent;
692
- _context4.next = 10;
846
+ while (1) switch (_context4.prev = _context4.next) {
847
+ case 0:
848
+ _context4.prev = 0;
849
+ _context4.next = 3;
850
+ return util.promisify(fs__default["default"].readFile)(bundleFilePath, "utf8");
851
+ case 3:
852
+ bundleContent = _context4.sent;
853
+ _context4.next = 10;
854
+ break;
855
+ case 6:
856
+ _context4.prev = 6;
857
+ _context4.t0 = _context4["catch"](0);
858
+ logger.error("Could not read bundle to determine debug ID and source map: ".concat(bundleFilePath), _context4.t0);
859
+ return _context4.abrupt("return");
860
+ case 10:
861
+ debugId = determineDebugIdFromBundleSource(bundleContent);
862
+ if (!(debugId === undefined)) {
863
+ _context4.next = 14;
693
864
  break;
694
-
695
- case 6:
696
- _context4.prev = 6;
697
- _context4.t0 = _context4["catch"](0);
698
- logger.error("Could not read bundle to determine debug ID and source map: ".concat(bundleFilePath), _context4.t0);
699
- return _context4.abrupt("return");
700
-
701
- case 10:
702
- debugId = determineDebugIdFromBundleSource(bundleContent);
703
-
704
- if (!(debugId === undefined)) {
705
- _context4.next = 14;
706
- break;
707
- }
708
-
709
- logger.debug("Could not determine debug ID from bundle. This can happen if you did not clean your output folder before installing the Sentry plugin. File will not be source mapped: ".concat(bundleFilePath));
710
- return _context4.abrupt("return");
711
-
712
- case 14:
713
- uniqueUploadName = "".concat(debugId, "-").concat(chunkIndex);
714
- bundleContent += "\n//# debugId=".concat(debugId);
715
- writeSourceFilePromise = fs__default["default"].promises.writeFile(path__default["default"].join(uploadFolder, "".concat(uniqueUploadName, ".js")), bundleContent, "utf-8");
716
- writeSourceMapFilePromise = determineSourceMapPathFromBundle(bundleFilePath, bundleContent, logger).then( /*#__PURE__*/function () {
717
- var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(sourceMapPath) {
718
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
719
- while (1) {
720
- switch (_context3.prev = _context3.next) {
721
- case 0:
722
- if (!sourceMapPath) {
723
- _context3.next = 4;
724
- break;
725
- }
726
-
727
- _context3.next = 3;
728
- return prepareSourceMapForDebugIdUpload(sourceMapPath, path__default["default"].join(uploadFolder, "".concat(uniqueUploadName, ".js.map")), debugId, rewriteSourcesHook, logger);
729
-
730
- case 3:
731
- return _context3.abrupt("return", _context3.sent);
732
-
733
- case 4:
734
- case "end":
735
- return _context3.stop();
865
+ }
866
+ logger.debug("Could not determine debug ID from bundle. This can happen if you did not clean your output folder before installing the Sentry plugin. File will not be source mapped: ".concat(bundleFilePath));
867
+ return _context4.abrupt("return");
868
+ case 14:
869
+ uniqueUploadName = "".concat(debugId, "-").concat(chunkIndex);
870
+ bundleContent += "\n//# debugId=".concat(debugId);
871
+ writeSourceFilePromise = fs__default["default"].promises.writeFile(path__default["default"].join(uploadFolder, "".concat(uniqueUploadName, ".js")), bundleContent, "utf-8");
872
+ writeSourceMapFilePromise = determineSourceMapPathFromBundle(bundleFilePath, bundleContent, logger).then( /*#__PURE__*/function () {
873
+ var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(sourceMapPath) {
874
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
875
+ while (1) switch (_context3.prev = _context3.next) {
876
+ case 0:
877
+ if (!sourceMapPath) {
878
+ _context3.next = 4;
879
+ break;
736
880
  }
737
- }
738
- }, _callee3);
739
- }));
740
-
741
- return function (_x16) {
742
- return _ref3.apply(this, arguments);
743
- };
744
- }());
745
- return _context4.abrupt("return", Promise.all([writeSourceFilePromise, writeSourceMapFilePromise]));
746
-
747
- case 19:
748
- case "end":
749
- return _context4.stop();
750
- }
881
+ _context3.next = 3;
882
+ return prepareSourceMapForDebugIdUpload(sourceMapPath, path__default["default"].join(uploadFolder, "".concat(uniqueUploadName, ".js.map")), debugId, rewriteSourcesHook, logger);
883
+ case 3:
884
+ return _context3.abrupt("return", _context3.sent);
885
+ case 4:
886
+ case "end":
887
+ return _context3.stop();
888
+ }
889
+ }, _callee3);
890
+ }));
891
+ return function (_x17) {
892
+ return _ref4.apply(this, arguments);
893
+ };
894
+ }());
895
+ return _context4.abrupt("return", Promise.all([writeSourceFilePromise, writeSourceMapFilePromise]));
896
+ case 19:
897
+ case "end":
898
+ return _context4.stop();
751
899
  }
752
900
  }, _callee4, null, [[0, 6]]);
753
901
  }));
754
902
  return _prepareBundleForDebugIdUpload.apply(this, arguments);
755
903
  }
756
-
757
904
  function determineDebugIdFromBundleSource(code) {
758
905
  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})/);
759
-
760
906
  if (match) {
761
907
  return match[1];
762
908
  } else {
763
909
  return undefined;
764
910
  }
765
911
  }
912
+
766
913
  /**
767
914
  * Applies a set of heuristics to find the source map for a particular bundle.
768
915
  *
769
916
  * @returns the path to the bundle's source map or `undefined` if none could be found.
770
917
  */
771
-
772
-
773
- function determineSourceMapPathFromBundle(_x8, _x9, _x10) {
918
+ function determineSourceMapPathFromBundle(_x9, _x10, _x11) {
774
919
  return _determineSourceMapPathFromBundle.apply(this, arguments);
775
920
  }
776
921
  /**
777
- * Reads a source map, injects debug ID fields, and writes the source map to the target path.
778
- */
779
-
780
-
781
- function _determineSourceMapPathFromBundle() {
782
- _determineSourceMapPathFromBundle = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(bundlePath, bundleSource, logger) {
783
- var sourceMappingUrlMatch, sourceMappingUrl, adjacentSourceMapFilePath;
784
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
785
- while (1) {
786
- switch (_context5.prev = _context5.next) {
787
- case 0:
788
- // 1. try to find source map at `sourceMappingURL` location
789
- sourceMappingUrlMatch = bundleSource.match(/^\/\/# sourceMappingURL=(.*)$/);
790
-
791
- if (!sourceMappingUrlMatch) {
792
- _context5.next = 8;
793
- break;
794
- }
795
-
796
- sourceMappingUrl = path__default["default"].normalize(sourceMappingUrlMatch[1]);
797
-
798
- if (!path__default["default"].isAbsolute(sourceMappingUrl)) {
799
- _context5.next = 7;
800
- break;
801
- }
802
-
803
- return _context5.abrupt("return", sourceMappingUrl);
804
-
805
- case 7:
806
- return _context5.abrupt("return", path__default["default"].join(path__default["default"].dirname(bundlePath), sourceMappingUrl));
807
-
808
- case 8:
809
- _context5.prev = 8;
810
- adjacentSourceMapFilePath = bundlePath + ".map";
811
- _context5.next = 12;
812
- return util__namespace.promisify(fs__default["default"].access)(adjacentSourceMapFilePath);
813
-
814
- case 12:
815
- return _context5.abrupt("return", adjacentSourceMapFilePath);
816
-
817
- case 15:
818
- _context5.prev = 15;
819
- _context5.t0 = _context5["catch"](8);
820
-
821
- case 17:
822
- // This is just a debug message because it can be quite spammy for some frameworks
823
- logger.debug("Could not determine source map path for bundle: ".concat(bundlePath));
824
- return _context5.abrupt("return", undefined);
825
-
826
- case 19:
827
- case "end":
828
- return _context5.stop();
829
- }
830
- }
831
- }, _callee5, null, [[8, 15]]);
832
- }));
833
- return _determineSourceMapPathFromBundle.apply(this, arguments);
834
- }
835
-
836
- function prepareSourceMapForDebugIdUpload(_x11, _x12, _x13, _x14, _x15) {
837
- return _prepareSourceMapForDebugIdUpload.apply(this, arguments);
838
- }
839
-
840
- function _prepareSourceMapForDebugIdUpload() {
841
- _prepareSourceMapForDebugIdUpload = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(sourceMapPath, targetPath, debugId, rewriteSourcesHook, logger) {
842
- var sourceMapFileContent, map;
843
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
844
- while (1) {
845
- switch (_context6.prev = _context6.next) {
846
- case 0:
847
- _context6.prev = 0;
848
- _context6.next = 3;
849
- return util__namespace.promisify(fs__default["default"].readFile)(sourceMapPath, {
850
- encoding: "utf8"
851
- });
852
-
853
- case 3:
854
- sourceMapFileContent = _context6.sent;
855
- _context6.next = 10;
856
- break;
857
-
858
- case 6:
859
- _context6.prev = 6;
860
- _context6.t0 = _context6["catch"](0);
861
- logger.error("Failed to read source map for debug ID upload: ".concat(sourceMapPath), _context6.t0);
862
- return _context6.abrupt("return");
863
-
864
- case 10:
865
- _context6.prev = 10;
866
- map = JSON.parse(sourceMapFileContent); // For now we write both fields until we know what will become the standard - if ever.
867
-
868
- map["debug_id"] = debugId;
869
- map["debugId"] = debugId;
870
- _context6.next = 20;
871
- break;
872
-
873
- case 16:
874
- _context6.prev = 16;
875
- _context6.t1 = _context6["catch"](10);
876
- logger.error("Failed to parse source map for debug ID upload: ".concat(sourceMapPath));
877
- return _context6.abrupt("return");
878
-
879
- case 20:
880
- if (map["sources"] && Array.isArray(map["sources"])) {
881
- map["sources"].map(function (source) {
882
- return rewriteSourcesHook(source, map);
883
- });
884
- }
885
-
886
- _context6.prev = 21;
887
- _context6.next = 24;
888
- return util__namespace.promisify(fs__default["default"].writeFile)(targetPath, JSON.stringify(map), {
889
- encoding: "utf8"
890
- });
891
-
892
- case 24:
893
- _context6.next = 30;
894
- break;
895
-
896
- case 26:
897
- _context6.prev = 26;
898
- _context6.t2 = _context6["catch"](21);
899
- logger.error("Failed to prepare source map for debug ID upload: ".concat(sourceMapPath), _context6.t2);
900
- return _context6.abrupt("return");
901
-
902
- case 30:
903
- case "end":
904
- return _context6.stop();
905
- }
906
- }
907
- }, _callee6, null, [[0, 6], [10, 16], [21, 26]]);
908
- }));
909
- return _prepareSourceMapForDebugIdUpload.apply(this, arguments);
910
- }
911
-
912
- var PROTOCOL_REGEX = /^[a-zA-Z][a-zA-Z0-9+\-.]*:\/\//;
913
-
914
- function defaultRewriteSourcesHook(source) {
915
- if (source.match(PROTOCOL_REGEX)) {
916
- return source.replace(PROTOCOL_REGEX, "");
917
- } else {
918
- return path__default["default"].relative(process.cwd(), path__default["default"].normalize(source));
919
- }
920
- }
921
-
922
- /**
923
- * Checks whether the given input is already an array, and if it isn't, wraps it in one.
924
- *
925
- * @param maybeArray Input to turn into an array, if necessary
926
- * @returns The input, if already an array, or an array with the input as the only element, if not
927
- */
928
-
929
- function arrayify(maybeArray) {
930
- return Array.isArray(maybeArray) ? maybeArray : [maybeArray];
931
- }
932
-
933
- /**
934
- * Get the closes package.json from a given starting point upwards.
935
- * This handles a few edge cases:
936
- * * Check if a given file package.json appears to be an actual NPM package.json file
937
- * * Stop at the home dir, to avoid looking too deeply
938
- */
939
- function getPackageJson() {
940
- var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
941
- cwd = _ref.cwd,
942
- stopAt = _ref.stopAt;
943
-
944
- return lookupPackageJson(cwd !== null && cwd !== void 0 ? cwd : process.cwd(), path__default["default"].normalize(stopAt !== null && stopAt !== void 0 ? stopAt : os__default["default"].homedir()));
945
- }
946
- function parseMajorVersion(version) {
947
- // if it has a `v` prefix, remove it
948
- if (version.startsWith("v")) {
949
- version = version.slice(1);
950
- } // First, try simple lookup of exact, ~ and ^ versions
951
-
952
-
953
- var regex = /^[\^~]?(\d+)(\.\d+)?(\.\d+)?(-.+)?/;
954
- var match = version.match(regex);
955
-
956
- if (match) {
957
- return parseInt(match[1], 10);
958
- } // Try to parse e.g. 1.x
959
-
960
-
961
- var coerced = parseInt(version, 10);
962
-
963
- if (!Number.isNaN(coerced)) {
964
- return coerced;
965
- } // Match <= and >= ranges.
966
-
967
-
968
- var gteLteRegex = /^[<>]=\s*(\d+)(\.\d+)?(\.\d+)?(-.+)?/;
969
- var gteLteMatch = version.match(gteLteRegex);
970
-
971
- if (gteLteMatch) {
972
- return parseInt(gteLteMatch[1], 10);
973
- } // match < ranges
974
-
975
-
976
- var ltRegex = /^<\s*(\d+)(\.\d+)?(\.\d+)?(-.+)?/;
977
- var ltMatch = version.match(ltRegex);
978
-
979
- if (ltMatch) {
980
- // Two scenarios:
981
- // a) < 2.0.0 --> return 1
982
- // b) < 2.1.0 --> return 2
983
- var major = parseInt(ltMatch[1], 10);
984
-
985
- if ( // minor version > 0
986
- typeof ltMatch[2] === "string" && parseInt(ltMatch[2].slice(1), 10) > 0 || // patch version > 0
987
- typeof ltMatch[3] === "string" && parseInt(ltMatch[3].slice(1), 10) > 0) {
988
- return major;
989
- }
990
-
991
- return major - 1;
992
- } // match > ranges
993
-
994
-
995
- var gtRegex = /^>\s*(\d+)(\.\d+)?(\.\d+)?(-.+)?/;
996
- var gtMatch = version.match(gtRegex);
997
-
998
- if (gtMatch) {
999
- // We always return the version here, even though it _may_ be incorrect
1000
- // E.g. if given > 2.0.0, it should be 2 if there exists any 2.x.x version, else 3
1001
- // Since there is no way for us to know this, we're going to assume any kind of patch/feature release probably exists
1002
- return parseInt(gtMatch[1], 10);
1003
- }
1004
-
1005
- return undefined;
1006
- } // This is an explicit list of packages where we want to include the (major) version number.
1007
-
1008
- var PACKAGES_TO_INCLUDE_VERSION = ["react", "@angular/core", "vue", "ember-source", "svelte", "@sveltejs/kit", "webpack", "vite", "gatsby", "next", "remix", "rollup", "esbuild"];
1009
- function getDependencies(packageJson) {
1010
- var _packageJson$devDepen, _packageJson$dependen;
1011
-
1012
- var dependencies = Object.assign({}, (_packageJson$devDepen = packageJson["devDependencies"]) !== null && _packageJson$devDepen !== void 0 ? _packageJson$devDepen : {}, (_packageJson$dependen = packageJson["dependencies"]) !== null && _packageJson$dependen !== void 0 ? _packageJson$dependen : {});
1013
- var deps = Object.keys(dependencies).sort();
1014
- var depsVersions = deps.reduce(function (depsVersions, depName) {
1015
- if (PACKAGES_TO_INCLUDE_VERSION.includes(depName)) {
1016
- var version = dependencies[depName];
1017
- var majorVersion = parseMajorVersion(version);
1018
-
1019
- if (majorVersion) {
1020
- depsVersions[depName] = majorVersion;
1021
- }
1022
- }
1023
-
1024
- return depsVersions;
1025
- }, {});
1026
- return {
1027
- deps: deps,
1028
- depsVersions: depsVersions
1029
- };
1030
- }
1031
-
1032
- function lookupPackageJson(cwd, stopAt) {
1033
- var jsonPath = findUp__default["default"].sync(function (dirName) {
1034
- // Stop if we reach this dir
1035
- if (path__default["default"].normalize(dirName) === stopAt) {
1036
- return findUp__default["default"].stop;
1037
- }
1038
-
1039
- return findUp__default["default"].sync.exists(dirName + "/package.json") ? "package.json" : undefined;
1040
- }, {
1041
- cwd: cwd
1042
- });
1043
-
1044
- if (!jsonPath) {
1045
- return undefined;
1046
- }
1047
-
1048
- try {
1049
- var jsonStr = fs__default["default"].readFileSync(jsonPath, "utf8");
1050
- var json = JSON.parse(jsonStr); // Ensure it is an actual package.json
1051
- // This is very much not bulletproof, but should be good enough
1052
-
1053
- if ("name" in json || "private" in json) {
1054
- return json;
1055
- }
1056
- } catch (error) {// Ignore and walk up
1057
- } // Continue up the tree, if we find a fitting package.json
1058
-
1059
-
1060
- var newCwd = path__default["default"].dirname(path__default["default"].resolve(jsonPath + "/.."));
1061
- return lookupPackageJson(newCwd, stopAt);
1062
- }
1063
- /**
1064
- * Deterministically hashes a string and turns the hash into a uuid.
1065
- */
1066
-
1067
-
1068
- function stringToUUID(str) {
1069
- var md5sum = crypto__default["default"].createHash("md5");
1070
- md5sum.update(str);
1071
- var md5Hash = md5sum.digest("hex");
1072
- return (md5Hash.substring(0, 8) + "-" + md5Hash.substring(8, 12) + "-4" + md5Hash.substring(13, 16) + "-" + md5Hash.substring(16, 20) + "-" + md5Hash.substring(20)).toLowerCase();
1073
- }
1074
- /**
1075
- * Tries to guess a release name based on environmental data.
1076
- */
1077
-
1078
- function determineReleaseName() {
1079
- var gitRevision;
1080
-
1081
- try {
1082
- gitRevision = childProcess__default["default"].execSync("git rev-parse --short HEAD").toString().trim();
1083
- } catch (e) {// noop
1084
- }
1085
-
1086
- return (// GitHub Actions - https://help.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables#default-environment-variables
1087
- process.env["GITHUB_SHA"] || // Netlify - https://docs.netlify.com/configure-builds/environment-variables/#build-metadata
1088
- process.env["COMMIT_REF"] || // Cloudflare Pages - https://developers.cloudflare.com/pages/platform/build-configuration/#environment-variables
1089
- process.env["CF_PAGES_COMMIT_SHA"] || // AWS CodeBuild - https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-env-vars.html
1090
- process.env["CODEBUILD_RESOLVED_SOURCE_VERSION"] || // CircleCI - https://circleci.com/docs/2.0/env-vars/
1091
- process.env["CIRCLE_SHA1"] || // Vercel - https://vercel.com/docs/v2/build-step#system-environment-variables
1092
- process.env["VERCEL_GIT_COMMIT_SHA"] || process.env["VERCEL_GITHUB_COMMIT_SHA"] || process.env["VERCEL_GITLAB_COMMIT_SHA"] || process.env["VERCEL_BITBUCKET_COMMIT_SHA"] || // Zeit (now known as Vercel)
1093
- process.env["ZEIT_GITHUB_COMMIT_SHA"] || process.env["ZEIT_GITLAB_COMMIT_SHA"] || process.env["ZEIT_BITBUCKET_COMMIT_SHA"] || gitRevision
1094
- );
1095
- }
1096
- /**
1097
- * Generates code for the global injector which is responsible for setting the global
1098
- * `SENTRY_RELEASE` & `SENTRY_BUILD_INFO` variables.
922
+ * Reads a source map, injects debug ID fields, and writes the source map to the target path.
1099
923
  */
1100
-
1101
- function generateGlobalInjectorCode(_ref2) {
1102
- var release = _ref2.release,
1103
- injectBuildInformation = _ref2.injectBuildInformation;
1104
- // The code below is mostly ternary operators because it saves bundle size.
1105
- // The checks are to support as many environments as possible. (Node.js, Browser, webworkers, etc.)
1106
- var code = "\n var _global =\n typeof window !== 'undefined' ?\n window :\n typeof global !== 'undefined' ?\n global :\n typeof self !== 'undefined' ?\n self :\n {};\n\n _global.SENTRY_RELEASE={id:\"".concat(release, "\"};");
1107
-
1108
- if (injectBuildInformation) {
1109
- var buildInfo = getBuildInformation$1();
1110
- code += "\n _global.SENTRY_BUILD_INFO=".concat(JSON.stringify(buildInfo), ";");
1111
- }
1112
-
1113
- return code;
924
+ function _determineSourceMapPathFromBundle() {
925
+ _determineSourceMapPathFromBundle = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(bundlePath, bundleSource, logger) {
926
+ var sourceMappingUrlMatch, sourceMappingUrl, adjacentSourceMapFilePath;
927
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
928
+ while (1) switch (_context5.prev = _context5.next) {
929
+ case 0:
930
+ // 1. try to find source map at `sourceMappingURL` location
931
+ sourceMappingUrlMatch = bundleSource.match(/^\/\/# sourceMappingURL=(.*)$/);
932
+ if (!sourceMappingUrlMatch) {
933
+ _context5.next = 8;
934
+ break;
935
+ }
936
+ sourceMappingUrl = path__default["default"].normalize(sourceMappingUrlMatch[1]);
937
+ if (!path__default["default"].isAbsolute(sourceMappingUrl)) {
938
+ _context5.next = 7;
939
+ break;
940
+ }
941
+ return _context5.abrupt("return", sourceMappingUrl);
942
+ case 7:
943
+ return _context5.abrupt("return", path__default["default"].join(path__default["default"].dirname(bundlePath), sourceMappingUrl));
944
+ case 8:
945
+ _context5.prev = 8;
946
+ adjacentSourceMapFilePath = bundlePath + ".map";
947
+ _context5.next = 12;
948
+ return util__namespace.promisify(fs__default["default"].access)(adjacentSourceMapFilePath);
949
+ case 12:
950
+ return _context5.abrupt("return", adjacentSourceMapFilePath);
951
+ case 15:
952
+ _context5.prev = 15;
953
+ _context5.t0 = _context5["catch"](8);
954
+ case 17:
955
+ // This is just a debug message because it can be quite spammy for some frameworks
956
+ logger.debug("Could not determine source map path for bundle: ".concat(bundlePath));
957
+ return _context5.abrupt("return", undefined);
958
+ case 19:
959
+ case "end":
960
+ return _context5.stop();
961
+ }
962
+ }, _callee5, null, [[8, 15]]);
963
+ }));
964
+ return _determineSourceMapPathFromBundle.apply(this, arguments);
1114
965
  }
1115
-
1116
- function getBuildInformation$1() {
1117
- var packageJson = getPackageJson();
1118
-
1119
- var _ref3 = packageJson ? getDependencies(packageJson) : {
1120
- deps: [],
1121
- depsVersions: {}
1122
- },
1123
- deps = _ref3.deps,
1124
- depsVersions = _ref3.depsVersions;
1125
-
1126
- return {
1127
- deps: deps,
1128
- depsVersions: depsVersions,
1129
- nodeVersion: parseMajorVersion(process.version)
1130
- };
966
+ function prepareSourceMapForDebugIdUpload(_x12, _x13, _x14, _x15, _x16) {
967
+ return _prepareSourceMapForDebugIdUpload.apply(this, arguments);
968
+ }
969
+ function _prepareSourceMapForDebugIdUpload() {
970
+ _prepareSourceMapForDebugIdUpload = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(sourceMapPath, targetPath, debugId, rewriteSourcesHook, logger) {
971
+ var sourceMapFileContent, map;
972
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
973
+ while (1) switch (_context6.prev = _context6.next) {
974
+ case 0:
975
+ _context6.prev = 0;
976
+ _context6.next = 3;
977
+ return util__namespace.promisify(fs__default["default"].readFile)(sourceMapPath, {
978
+ encoding: "utf8"
979
+ });
980
+ case 3:
981
+ sourceMapFileContent = _context6.sent;
982
+ _context6.next = 10;
983
+ break;
984
+ case 6:
985
+ _context6.prev = 6;
986
+ _context6.t0 = _context6["catch"](0);
987
+ logger.error("Failed to read source map for debug ID upload: ".concat(sourceMapPath), _context6.t0);
988
+ return _context6.abrupt("return");
989
+ case 10:
990
+ _context6.prev = 10;
991
+ map = JSON.parse(sourceMapFileContent);
992
+ // For now we write both fields until we know what will become the standard - if ever.
993
+ map["debug_id"] = debugId;
994
+ map["debugId"] = debugId;
995
+ _context6.next = 20;
996
+ break;
997
+ case 16:
998
+ _context6.prev = 16;
999
+ _context6.t1 = _context6["catch"](10);
1000
+ logger.error("Failed to parse source map for debug ID upload: ".concat(sourceMapPath));
1001
+ return _context6.abrupt("return");
1002
+ case 20:
1003
+ if (map["sources"] && Array.isArray(map["sources"])) {
1004
+ map["sources"].map(function (source) {
1005
+ return rewriteSourcesHook(source, map);
1006
+ });
1007
+ }
1008
+ _context6.prev = 21;
1009
+ _context6.next = 24;
1010
+ return util__namespace.promisify(fs__default["default"].writeFile)(targetPath, JSON.stringify(map), {
1011
+ encoding: "utf8"
1012
+ });
1013
+ case 24:
1014
+ _context6.next = 30;
1015
+ break;
1016
+ case 26:
1017
+ _context6.prev = 26;
1018
+ _context6.t2 = _context6["catch"](21);
1019
+ logger.error("Failed to prepare source map for debug ID upload: ".concat(sourceMapPath), _context6.t2);
1020
+ return _context6.abrupt("return");
1021
+ case 30:
1022
+ case "end":
1023
+ return _context6.stop();
1024
+ }
1025
+ }, _callee6, null, [[0, 6], [10, 16], [21, 26]]);
1026
+ }));
1027
+ return _prepareSourceMapForDebugIdUpload.apply(this, arguments);
1028
+ }
1029
+ var PROTOCOL_REGEX = /^[a-zA-Z][a-zA-Z0-9+\-.]*:\/\//;
1030
+ function defaultRewriteSourcesHook(source) {
1031
+ if (source.match(PROTOCOL_REGEX)) {
1032
+ return source.replace(PROTOCOL_REGEX, "");
1033
+ } else {
1034
+ return path__default["default"].relative(process.cwd(), path__default["default"].normalize(source));
1035
+ }
1131
1036
  }
1132
1037
 
1133
1038
  function releaseManagementPlugin(_ref) {
1134
1039
  var releaseName = _ref.releaseName,
1135
- include = _ref.include,
1136
- dist = _ref.dist,
1137
- setCommitsOption = _ref.setCommitsOption,
1138
- shouldCreateRelease = _ref.shouldCreateRelease,
1139
- shouldCleanArtifacts = _ref.shouldCleanArtifacts,
1140
- shouldFinalizeRelease = _ref.shouldFinalizeRelease,
1141
- deployOptions = _ref.deployOptions,
1142
- handleRecoverableError = _ref.handleRecoverableError,
1143
- sentryHub = _ref.sentryHub,
1144
- sentryClient = _ref.sentryClient,
1145
- sentryCliOptions = _ref.sentryCliOptions;
1040
+ include = _ref.include,
1041
+ dist = _ref.dist,
1042
+ setCommitsOption = _ref.setCommitsOption,
1043
+ shouldCreateRelease = _ref.shouldCreateRelease,
1044
+ shouldCleanArtifacts = _ref.shouldCleanArtifacts,
1045
+ shouldFinalizeRelease = _ref.shouldFinalizeRelease,
1046
+ deployOptions = _ref.deployOptions,
1047
+ handleRecoverableError = _ref.handleRecoverableError,
1048
+ sentryHub = _ref.sentryHub,
1049
+ sentryClient = _ref.sentryClient,
1050
+ sentryCliOptions = _ref.sentryCliOptions;
1146
1051
  return {
1147
1052
  name: "sentry-debug-id-upload-plugin",
1148
1053
  writeBundle: function writeBundle() {
1149
1054
  return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
1150
1055
  var cliInstance, normalizedInclude;
1151
1056
  return _regeneratorRuntime().wrap(function _callee$(_context) {
1152
- while (1) {
1153
- switch (_context.prev = _context.next) {
1154
- case 0:
1155
- _context.prev = 0;
1156
- cliInstance = new SentryCli__default["default"](null, sentryCliOptions);
1157
-
1158
- if (!shouldCreateRelease) {
1159
- _context.next = 5;
1160
- break;
1161
- }
1162
-
1057
+ while (1) switch (_context.prev = _context.next) {
1058
+ case 0:
1059
+ _context.prev = 0;
1060
+ cliInstance = new SentryCli__default["default"](null, sentryCliOptions);
1061
+ if (!shouldCreateRelease) {
1163
1062
  _context.next = 5;
1164
- return cliInstance.releases["new"](releaseName);
1165
-
1166
- case 5:
1167
- if (!shouldCleanArtifacts) {
1168
- _context.next = 8;
1169
- break;
1170
- }
1171
-
1063
+ break;
1064
+ }
1065
+ _context.next = 5;
1066
+ return cliInstance.releases["new"](releaseName);
1067
+ case 5:
1068
+ if (!shouldCleanArtifacts) {
1172
1069
  _context.next = 8;
1173
- return cliInstance.releases.execute(["releases", "files", releaseName, "delete", "--all"], true);
1174
-
1175
- case 8:
1176
- if (!include) {
1177
- _context.next = 12;
1178
- break;
1179
- }
1180
-
1181
- normalizedInclude = arrayify(include).map(function (includeItem) {
1182
- return typeof includeItem === "string" ? {
1183
- paths: [includeItem]
1184
- } : includeItem;
1185
- }).map(function (includeEntry) {
1186
- var _includeEntry$validat;
1187
-
1188
- return _objectSpread2(_objectSpread2({}, includeEntry), {}, {
1189
- validate: (_includeEntry$validat = includeEntry.validate) !== null && _includeEntry$validat !== void 0 ? _includeEntry$validat : false,
1190
- ext: includeEntry.ext ? includeEntry.ext.map(function (extension) {
1191
- return ".".concat(extension.replace(/^\./, ""));
1192
- }) : [".js", ".map", ".jsbundle", ".bundle"],
1193
- ignore: includeEntry.ignore ? arrayify(includeEntry.ignore) : undefined
1194
- });
1195
- });
1070
+ break;
1071
+ }
1072
+ _context.next = 8;
1073
+ return cliInstance.releases.execute(["releases", "files", releaseName, "delete", "--all"], true);
1074
+ case 8:
1075
+ if (!include) {
1196
1076
  _context.next = 12;
1197
- return cliInstance.releases.uploadSourceMaps(releaseName, {
1198
- include: normalizedInclude,
1199
- dist: dist
1077
+ break;
1078
+ }
1079
+ normalizedInclude = arrayify(include).map(function (includeItem) {
1080
+ return typeof includeItem === "string" ? {
1081
+ paths: [includeItem]
1082
+ } : includeItem;
1083
+ }).map(function (includeEntry) {
1084
+ var _includeEntry$validat;
1085
+ return _objectSpread2(_objectSpread2({}, includeEntry), {}, {
1086
+ validate: (_includeEntry$validat = includeEntry.validate) !== null && _includeEntry$validat !== void 0 ? _includeEntry$validat : false,
1087
+ ext: includeEntry.ext ? includeEntry.ext.map(function (extension) {
1088
+ return ".".concat(extension.replace(/^\./, ""));
1089
+ }) : [".js", ".map", ".jsbundle", ".bundle"],
1090
+ ignore: includeEntry.ignore ? arrayify(includeEntry.ignore) : undefined
1200
1091
  });
1201
-
1202
- case 12:
1203
- if (!setCommitsOption) {
1204
- _context.next = 15;
1205
- break;
1206
- }
1207
-
1092
+ });
1093
+ _context.next = 12;
1094
+ return cliInstance.releases.uploadSourceMaps(releaseName, {
1095
+ include: normalizedInclude,
1096
+ dist: dist
1097
+ });
1098
+ case 12:
1099
+ if (!setCommitsOption) {
1208
1100
  _context.next = 15;
1209
- return cliInstance.releases.setCommits(releaseName, setCommitsOption);
1210
-
1211
- case 15:
1212
- if (!shouldFinalizeRelease) {
1213
- _context.next = 18;
1214
- break;
1215
- }
1216
-
1101
+ break;
1102
+ }
1103
+ _context.next = 15;
1104
+ return cliInstance.releases.setCommits(releaseName, setCommitsOption);
1105
+ case 15:
1106
+ if (!shouldFinalizeRelease) {
1217
1107
  _context.next = 18;
1218
- return cliInstance.releases.finalize(releaseName);
1219
-
1220
- case 18:
1221
- if (!deployOptions) {
1222
- _context.next = 21;
1223
- break;
1224
- }
1225
-
1108
+ break;
1109
+ }
1110
+ _context.next = 18;
1111
+ return cliInstance.releases.finalize(releaseName);
1112
+ case 18:
1113
+ if (!deployOptions) {
1226
1114
  _context.next = 21;
1227
- return cliInstance.releases.newDeploy(releaseName, deployOptions);
1228
-
1229
- case 21:
1230
- _context.next = 29;
1231
1115
  break;
1232
-
1233
- case 23:
1234
- _context.prev = 23;
1235
- _context.t0 = _context["catch"](0);
1236
- sentryHub.captureException('Error in "releaseManagementPlugin" writeBundle hook');
1237
- _context.next = 28;
1238
- return sentryClient.flush();
1239
-
1240
- case 28:
1241
- handleRecoverableError(_context.t0);
1242
-
1243
- case 29:
1244
- case "end":
1245
- return _context.stop();
1246
- }
1116
+ }
1117
+ _context.next = 21;
1118
+ return cliInstance.releases.newDeploy(releaseName, deployOptions);
1119
+ case 21:
1120
+ _context.next = 29;
1121
+ break;
1122
+ case 23:
1123
+ _context.prev = 23;
1124
+ _context.t0 = _context["catch"](0);
1125
+ sentryHub.captureException('Error in "releaseManagementPlugin" writeBundle hook');
1126
+ _context.next = 28;
1127
+ return sentryClient.flush();
1128
+ case 28:
1129
+ handleRecoverableError(_context.t0);
1130
+ case 29:
1131
+ case "end":
1132
+ return _context.stop();
1247
1133
  }
1248
1134
  }, _callee, null, [[0, 23]]);
1249
1135
  }))();
@@ -1252,32 +1138,33 @@ function releaseManagementPlugin(_ref) {
1252
1138
  }
1253
1139
 
1254
1140
  function telemetryPlugin(_ref) {
1255
- var sentryClient = _ref.sentryClient,
1256
- pluginExecutionTransaction = _ref.pluginExecutionTransaction,
1257
- shouldSendTelemetry = _ref.shouldSendTelemetry,
1258
- logger = _ref.logger;
1141
+ var sentryHub = _ref.sentryHub,
1142
+ sentryClient = _ref.sentryClient,
1143
+ shouldSendTelemetry = _ref.shouldSendTelemetry,
1144
+ logger = _ref.logger;
1259
1145
  return {
1260
1146
  name: "sentry-telemetry-plugin",
1261
1147
  buildStart: function buildStart() {
1262
- void shouldSendTelemetry.then(function () {
1263
- logger.info("Sending error and performance telemetry data to Sentry. To disable telemetry, set `options.telemetry` to `false`.");
1264
- });
1265
- pluginExecutionTransaction.startTimestamp = Date.now() / 1000;
1266
- },
1267
- writeBundle: function writeBundle() {
1268
1148
  return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
1269
1149
  return _regeneratorRuntime().wrap(function _callee$(_context) {
1270
- while (1) {
1271
- switch (_context.prev = _context.next) {
1272
- case 0:
1273
- pluginExecutionTransaction.finish();
1274
- _context.next = 3;
1275
- return sentryClient.flush();
1276
-
1277
- case 3:
1278
- case "end":
1279
- return _context.stop();
1280
- }
1150
+ while (1) switch (_context.prev = _context.next) {
1151
+ case 0:
1152
+ _context.next = 2;
1153
+ return shouldSendTelemetry;
1154
+ case 2:
1155
+ if (!_context.sent) {
1156
+ _context.next = 7;
1157
+ break;
1158
+ }
1159
+ logger.info("Sending error and performance telemetry data to Sentry. To disable telemetry, set `options.telemetry` to `false`.");
1160
+ sentryHub.startTransaction({
1161
+ name: "Sentry Bundler Plugin execution"
1162
+ }).finish();
1163
+ _context.next = 7;
1164
+ return sentryClient.flush(3000);
1165
+ case 7:
1166
+ case "end":
1167
+ return _context.stop();
1281
1168
  }
1282
1169
  }, _callee);
1283
1170
  }))();
@@ -1290,11 +1177,9 @@ function createLogger(options) {
1290
1177
  info: function info(message) {
1291
1178
  if (!options.silent) {
1292
1179
  var _console;
1293
-
1294
1180
  for (var _len = arguments.length, params = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
1295
1181
  params[_key - 1] = arguments[_key];
1296
1182
  }
1297
-
1298
1183
  // eslint-disable-next-line no-console
1299
1184
  (_console = console).log.apply(_console, ["".concat(options.prefix, " Info: ").concat(message)].concat(params));
1300
1185
  }
@@ -1302,11 +1187,9 @@ function createLogger(options) {
1302
1187
  warn: function warn(message) {
1303
1188
  if (!options.silent) {
1304
1189
  var _console2;
1305
-
1306
1190
  for (var _len2 = arguments.length, params = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
1307
1191
  params[_key2 - 1] = arguments[_key2];
1308
1192
  }
1309
-
1310
1193
  // eslint-disable-next-line no-console
1311
1194
  (_console2 = console).log.apply(_console2, ["".concat(options.prefix, " Warning: ").concat(message)].concat(params));
1312
1195
  }
@@ -1314,11 +1197,9 @@ function createLogger(options) {
1314
1197
  error: function error(message) {
1315
1198
  if (!options.silent) {
1316
1199
  var _console3;
1317
-
1318
1200
  for (var _len3 = arguments.length, params = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
1319
1201
  params[_key3 - 1] = arguments[_key3];
1320
1202
  }
1321
-
1322
1203
  // eslint-disable-next-line no-console
1323
1204
  (_console3 = console).log.apply(_console3, ["".concat(options.prefix, " Error: ").concat(message)].concat(params));
1324
1205
  }
@@ -1326,11 +1207,9 @@ function createLogger(options) {
1326
1207
  debug: function debug(message) {
1327
1208
  if (!options.silent && options.debug) {
1328
1209
  var _console4;
1329
-
1330
1210
  for (var _len4 = arguments.length, params = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
1331
1211
  params[_key4 - 1] = arguments[_key4];
1332
1212
  }
1333
-
1334
1213
  // eslint-disable-next-line no-console
1335
1214
  (_console4 = console).log.apply(_console4, ["".concat(options.prefix, " Debug: ").concat(message)].concat(params));
1336
1215
  }
@@ -1344,23 +1223,20 @@ function createSentryInstance(options, shouldSendTelemetry, bundler) {
1344
1223
  dsn: "https://4c2bae7d9fbc413e8f7385f55c515d51@o1.ingest.sentry.io/6690737",
1345
1224
  tracesSampleRate: 1,
1346
1225
  sampleRate: 1,
1347
- release: "2.0.0",
1226
+ release: "2.2.0",
1348
1227
  integrations: [],
1349
1228
  tracePropagationTargets: ["sentry.io/api"],
1350
1229
  stackParser: node.defaultStackParser,
1351
1230
  beforeSend: function beforeSend(event) {
1352
1231
  var _event$exception, _event$exception$valu;
1353
-
1354
1232
  (_event$exception = event.exception) === null || _event$exception === void 0 ? void 0 : (_event$exception$valu = _event$exception.values) === null || _event$exception$valu === void 0 ? void 0 : _event$exception$valu.forEach(function (exception) {
1355
1233
  delete exception.stacktrace;
1356
1234
  });
1357
1235
  delete event.server_name; // Server name might contain PII
1358
-
1359
1236
  return event;
1360
1237
  },
1361
1238
  beforeSendTransaction: function beforeSendTransaction(event) {
1362
1239
  delete event.server_name; // Server name might contain PII
1363
-
1364
1240
  return event;
1365
1241
  },
1366
1242
  // We create a transport that stalls sending events until we know that we're allowed to (i.e. when Sentry CLI told
@@ -1374,35 +1250,27 @@ function createSentryInstance(options, shouldSendTelemetry, bundler) {
1374
1250
  send: function () {
1375
1251
  var _send = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(request) {
1376
1252
  return _regeneratorRuntime().wrap(function _callee$(_context) {
1377
- while (1) {
1378
- switch (_context.prev = _context.next) {
1379
- case 0:
1380
- _context.next = 2;
1381
- return shouldSendTelemetry;
1382
-
1383
- case 2:
1384
- if (!_context.sent) {
1385
- _context.next = 6;
1386
- break;
1387
- }
1388
-
1389
- return _context.abrupt("return", nodeTransport.send(request));
1390
-
1391
- case 6:
1392
- return _context.abrupt("return", undefined);
1393
-
1394
- case 7:
1395
- case "end":
1396
- return _context.stop();
1397
- }
1253
+ while (1) switch (_context.prev = _context.next) {
1254
+ case 0:
1255
+ _context.next = 2;
1256
+ return shouldSendTelemetry;
1257
+ case 2:
1258
+ if (!_context.sent) {
1259
+ _context.next = 6;
1260
+ break;
1261
+ }
1262
+ return _context.abrupt("return", nodeTransport.send(request));
1263
+ case 6:
1264
+ return _context.abrupt("return", undefined);
1265
+ case 7:
1266
+ case "end":
1267
+ return _context.stop();
1398
1268
  }
1399
1269
  }, _callee);
1400
1270
  }));
1401
-
1402
1271
  function send(_x) {
1403
1272
  return _send.apply(this, arguments);
1404
1273
  }
1405
-
1406
1274
  return send;
1407
1275
  }()
1408
1276
  };
@@ -1417,45 +1285,29 @@ function createSentryInstance(options, shouldSendTelemetry, bundler) {
1417
1285
  }
1418
1286
  function setTelemetryDataOnHub(options, hub, bundler) {
1419
1287
  var org = options.org,
1420
- project = options.project,
1421
- release = options.release,
1422
- errorHandler = options.errorHandler,
1423
- sourcemaps = options.sourcemaps;
1424
-
1288
+ project = options.project,
1289
+ release = options.release,
1290
+ errorHandler = options.errorHandler,
1291
+ sourcemaps = options.sourcemaps;
1292
+ hub.setTag("upload-legacy-sourcemaps", !!release.uploadLegacySourcemaps);
1425
1293
  if (release.uploadLegacySourcemaps) {
1426
1294
  hub.setTag("uploadLegacySourcemapsEntries", Array.isArray(release.uploadLegacySourcemaps) ? release.uploadLegacySourcemaps.length : 1);
1427
- } // Optional release pipeline steps
1428
-
1429
-
1430
- if (release.cleanArtifacts) {
1431
- hub.setTag("clean-artifacts", true);
1432
1295
  }
1433
1296
 
1297
+ // Optional release pipeline steps
1298
+ hub.setTag("clean-artifacts", release.cleanArtifacts);
1434
1299
  if (release.setCommits) {
1435
1300
  hub.setTag("set-commits", release.setCommits.auto === true ? "auto" : "manual");
1301
+ } else {
1302
+ hub.setTag("set-commits", "undefined");
1436
1303
  }
1304
+ hub.setTag("finalize-release", release.finalize);
1305
+ hub.setTag("deploy-options", !!release.deploy);
1437
1306
 
1438
- if (release.finalize) {
1439
- hub.setTag("finalize-release", true);
1440
- }
1441
-
1442
- if (release.deploy) {
1443
- hub.setTag("add-deploy", true);
1444
- } // Miscelaneous options
1445
-
1446
-
1447
- if (errorHandler) {
1448
- hub.setTag("error-handler", "custom");
1449
- }
1450
-
1451
- if (sourcemaps !== null && sourcemaps !== void 0 && sourcemaps.assets) {
1452
- hub.setTag("debug-id-upload", true);
1453
- }
1454
-
1455
- if (sourcemaps !== null && sourcemaps !== void 0 && sourcemaps.deleteFilesAfterUpload) {
1456
- hub.setTag("delete-after-upload", true);
1457
- }
1458
-
1307
+ // Miscelaneous options
1308
+ hub.setTag("custom-error-handler", !!errorHandler);
1309
+ hub.setTag("sourcemaps-assets", !!(sourcemaps !== null && sourcemaps !== void 0 && sourcemaps.assets));
1310
+ hub.setTag("delete-after-upload", !!(sourcemaps !== null && sourcemaps !== void 0 && sourcemaps.deleteFilesAfterUpload));
1459
1311
  hub.setTag("node", process.version);
1460
1312
  hub.setTags({
1461
1313
  organization: org,
@@ -1469,74 +1321,58 @@ function setTelemetryDataOnHub(options, hub, bundler) {
1469
1321
  function allowedToSendTelemetry(_x2) {
1470
1322
  return _allowedToSendTelemetry.apply(this, arguments);
1471
1323
  }
1472
-
1473
1324
  function _allowedToSendTelemetry() {
1474
1325
  _allowedToSendTelemetry = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(options) {
1475
1326
  var _cliInfo$split$, _cliInfo$split$$repla;
1476
-
1477
1327
  var silent, org, project, authToken, url, headers, telemetry, release, cli, cliInfo, cliInfoUrl;
1478
1328
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
1479
- while (1) {
1480
- switch (_context2.prev = _context2.next) {
1481
- case 0:
1482
- silent = options.silent, org = options.org, project = options.project, authToken = options.authToken, url = options.url, headers = options.headers, telemetry = options.telemetry, release = options.release; // `options.telemetry` defaults to true
1483
-
1484
- if (!(telemetry === false)) {
1485
- _context2.next = 3;
1486
- break;
1487
- }
1488
-
1489
- return _context2.abrupt("return", false);
1490
-
1491
- case 3:
1492
- if (!(url === SENTRY_SAAS_URL)) {
1493
- _context2.next = 5;
1494
- break;
1495
- }
1496
-
1497
- return _context2.abrupt("return", true);
1498
-
1499
- case 5:
1500
- cli = new SentryCli__default["default"](null, {
1501
- url: url,
1502
- authToken: authToken,
1503
- org: org,
1504
- project: project,
1505
- vcsRemote: release.vcsRemote,
1506
- silent: silent,
1507
- headers: headers
1508
- });
1509
- _context2.prev = 6;
1510
- _context2.next = 9;
1511
- return cli.execute(["info"], false);
1512
-
1513
- case 9:
1514
- cliInfo = _context2.sent;
1515
- _context2.next = 15;
1329
+ while (1) switch (_context2.prev = _context2.next) {
1330
+ case 0:
1331
+ silent = options.silent, org = options.org, project = options.project, authToken = options.authToken, url = options.url, headers = options.headers, telemetry = options.telemetry, release = options.release; // `options.telemetry` defaults to true
1332
+ if (!(telemetry === false)) {
1333
+ _context2.next = 3;
1516
1334
  break;
1517
-
1518
- case 12:
1519
- _context2.prev = 12;
1520
- _context2.t0 = _context2["catch"](6);
1521
- return _context2.abrupt("return", false);
1522
-
1523
- case 15:
1524
- 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();
1525
-
1526
- if (!(cliInfoUrl === undefined)) {
1527
- _context2.next = 18;
1528
- break;
1529
- }
1530
-
1531
- return _context2.abrupt("return", false);
1532
-
1533
- case 18:
1534
- return _context2.abrupt("return", new URL(cliInfoUrl).hostname === SENTRY_SAAS_HOSTNAME);
1535
-
1536
- case 19:
1537
- case "end":
1538
- return _context2.stop();
1539
- }
1335
+ }
1336
+ return _context2.abrupt("return", false);
1337
+ case 3:
1338
+ if (!(url === SENTRY_SAAS_URL)) {
1339
+ _context2.next = 5;
1340
+ break;
1341
+ }
1342
+ return _context2.abrupt("return", true);
1343
+ case 5:
1344
+ cli = new SentryCli__default["default"](null, {
1345
+ url: url,
1346
+ authToken: authToken,
1347
+ org: org,
1348
+ project: project,
1349
+ vcsRemote: release.vcsRemote,
1350
+ silent: silent,
1351
+ headers: headers
1352
+ });
1353
+ _context2.prev = 6;
1354
+ _context2.next = 9;
1355
+ return cli.execute(["info"], false);
1356
+ case 9:
1357
+ cliInfo = _context2.sent;
1358
+ _context2.next = 15;
1359
+ break;
1360
+ case 12:
1361
+ _context2.prev = 12;
1362
+ _context2.t0 = _context2["catch"](6);
1363
+ return _context2.abrupt("return", false);
1364
+ case 15:
1365
+ 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();
1366
+ if (!(cliInfoUrl === undefined)) {
1367
+ _context2.next = 18;
1368
+ break;
1369
+ }
1370
+ return _context2.abrupt("return", false);
1371
+ case 18:
1372
+ return _context2.abrupt("return", new URL(cliInfoUrl).hostname === SENTRY_SAAS_HOSTNAME);
1373
+ case 19:
1374
+ case "end":
1375
+ return _context2.stop();
1540
1376
  }
1541
1377
  }, _callee2, null, [[6, 12]]);
1542
1378
  }));
@@ -1572,64 +1408,69 @@ function _allowedToSendTelemetry() {
1572
1408
  */
1573
1409
  function sentryUnpluginFactory(_ref) {
1574
1410
  var releaseInjectionPlugin = _ref.releaseInjectionPlugin,
1575
- debugIdInjectionPlugin = _ref.debugIdInjectionPlugin;
1411
+ debugIdInjectionPlugin = _ref.debugIdInjectionPlugin,
1412
+ debugIdUploadPlugin = _ref.debugIdUploadPlugin;
1576
1413
  return unplugin.createUnplugin(function (userOptions, unpluginMetaContext) {
1577
- var _options$release$name;
1578
-
1579
1414
  var options = normalizeUserOptions(userOptions);
1580
-
1581
1415
  if (unpluginMetaContext.watchMode || options.disable) {
1582
1416
  return [{
1583
1417
  name: "sentry-noop-plugin"
1584
1418
  }];
1585
1419
  }
1586
-
1587
1420
  var shouldSendTelemetry = allowedToSendTelemetry(options);
1588
-
1589
1421
  var _createSentryInstance = createSentryInstance(options, shouldSendTelemetry, unpluginMetaContext.framework),
1590
- sentryHub = _createSentryInstance.sentryHub,
1591
- sentryClient = _createSentryInstance.sentryClient;
1592
-
1593
- var pluginExecutionTransaction = sentryHub.startTransaction({
1594
- name: "Sentry Bundler Plugin execution"
1422
+ sentryHub = _createSentryInstance.sentryHub,
1423
+ sentryClient = _createSentryInstance.sentryClient;
1424
+ var sentrySession = sentryHub.startSession();
1425
+ sentryHub.captureSession();
1426
+ var sentEndSession = false; // Just to prevent infinite loops with beforeExit, which is called whenever the event loop empties out
1427
+ // We also need to manually end sesisons on errors because beforeExit is not called on crashes
1428
+ process.on("beforeExit", function () {
1429
+ if (!sentEndSession) {
1430
+ sentryHub.endSession();
1431
+ sentEndSession = true;
1432
+ }
1595
1433
  });
1596
- sentryHub.getScope().setSpan(pluginExecutionTransaction);
1597
1434
  var logger = createLogger({
1598
1435
  prefix: "[sentry-".concat(unpluginMetaContext.framework, "-plugin]"),
1599
1436
  silent: options.silent,
1600
1437
  debug: options.debug
1601
1438
  });
1602
-
1603
1439
  function handleRecoverableError(unknownError) {
1604
- pluginExecutionTransaction.setStatus("internal_error");
1605
-
1606
- if (options.errorHandler) {
1607
- if (unknownError instanceof Error) {
1608
- options.errorHandler(unknownError);
1440
+ sentrySession.status = "abnormal";
1441
+ try {
1442
+ if (options.errorHandler) {
1443
+ try {
1444
+ if (unknownError instanceof Error) {
1445
+ options.errorHandler(unknownError);
1446
+ } else {
1447
+ options.errorHandler(new Error("An unknown error occured"));
1448
+ }
1449
+ } catch (e) {
1450
+ sentrySession.status = "crashed";
1451
+ throw e;
1452
+ }
1609
1453
  } else {
1610
- options.errorHandler(new Error("An unknown error occured"));
1454
+ sentrySession.status = "crashed";
1455
+ throw unknownError;
1611
1456
  }
1612
- } else {
1613
- throw unknownError;
1457
+ } finally {
1458
+ sentryHub.endSession();
1614
1459
  }
1615
1460
  }
1616
-
1617
1461
  if (!validateOptions(options, logger)) {
1618
1462
  handleRecoverableError(new Error("Options were not set correctly. See output above for more details."));
1619
1463
  }
1620
-
1621
1464
  if (process.cwd().match(/\\node_modules\\|\/node_modules\//)) {
1622
1465
  logger.warn("Running Sentry plugin from within a `node_modules` folder. Some features may not work.");
1623
1466
  }
1624
-
1625
1467
  var plugins = [];
1626
1468
  plugins.push(telemetryPlugin({
1627
- pluginExecutionTransaction: pluginExecutionTransaction,
1469
+ sentryClient: sentryClient,
1470
+ sentryHub: sentryHub,
1628
1471
  logger: logger,
1629
- shouldSendTelemetry: shouldSendTelemetry,
1630
- sentryClient: sentryClient
1472
+ shouldSendTelemetry: shouldSendTelemetry
1631
1473
  }));
1632
-
1633
1474
  if (!options.release.inject) {
1634
1475
  logger.debug("Release injection disabled via `release.inject` option. Will not inject release.");
1635
1476
  } else if (!options.release.name) {
@@ -1639,13 +1480,9 @@ function sentryUnpluginFactory(_ref) {
1639
1480
  release: options.release.name,
1640
1481
  injectBuildInformation: options._experiments.injectBuildInformation || false
1641
1482
  });
1642
-
1643
1483
  plugins.push(releaseInjectionPlugin(_injectionCode));
1644
1484
  }
1645
-
1646
- var releaseManagementPluginReleaseName = (_options$release$name = options.release.name) !== null && _options$release$name !== void 0 ? _options$release$name : determineReleaseName();
1647
-
1648
- if (!releaseManagementPluginReleaseName) {
1485
+ if (!options.release.name) {
1649
1486
  logger.warn("No release name provided. Will not create release. Please set the `release.name` option to identifiy your release.");
1650
1487
  } else if (!options.authToken) {
1651
1488
  logger.warn("No auth token provided. Will not create release. Please set the `authToken` option. You can find information on how to generate a Sentry auth token here: https://docs.sentry.io/api/auth/");
@@ -1656,7 +1493,7 @@ function sentryUnpluginFactory(_ref) {
1656
1493
  } else {
1657
1494
  plugins.push(releaseManagementPlugin({
1658
1495
  logger: logger,
1659
- releaseName: releaseManagementPluginReleaseName,
1496
+ releaseName: options.release.name,
1660
1497
  shouldCreateRelease: options.release.create,
1661
1498
  shouldCleanArtifacts: options.release.cleanArtifacts,
1662
1499
  shouldFinalizeRelease: options.release.finalize,
@@ -1678,69 +1515,62 @@ function sentryUnpluginFactory(_ref) {
1678
1515
  }
1679
1516
  }));
1680
1517
  }
1681
-
1682
- if (options.sourcemaps) {
1683
- if (!options.authToken) {
1684
- 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/");
1685
- } else if (!options.org) {
1686
- logger.warn("No org provided. Will not upload source maps. Please set the `org` option to your Sentry organization slug.");
1687
- } else if (!options.project) {
1688
- logger.warn("No project provided. Will not upload source maps. Please set the `project` option to your Sentry project slug.");
1689
- } else if (!options.sourcemaps.assets) {
1690
- logger.warn("No assets defined. Will not upload source maps. Please provide set the `assets` option to your build-output folder.");
1691
- } else {
1692
- plugins.push(debugIdInjectionPlugin());
1693
- plugins.push(debugIdUploadPlugin({
1694
- assets: options.sourcemaps.assets,
1695
- ignore: options.sourcemaps.ignore,
1696
- deleteFilesAfterUpload: options.sourcemaps.deleteFilesAfterUpload,
1697
- dist: options.release.dist,
1698
- releaseName: options.release.name,
1699
- logger: logger,
1700
- handleRecoverableError: handleRecoverableError,
1701
- rewriteSourcesHook: options.sourcemaps.rewriteSources,
1702
- sentryHub: sentryHub,
1703
- sentryClient: sentryClient,
1704
- sentryCliOptions: {
1705
- authToken: options.authToken,
1706
- org: options.org,
1707
- project: options.project,
1708
- silent: options.silent,
1709
- url: options.url,
1710
- vcsRemote: options.release.vcsRemote,
1711
- headers: options.headers
1712
- }
1713
- }));
1714
- }
1518
+ if (!options.authToken) {
1519
+ 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/");
1520
+ } else if (!options.org) {
1521
+ logger.warn("No org provided. Will not upload source maps. Please set the `org` option to your Sentry organization slug.");
1522
+ } else if (!options.project) {
1523
+ logger.warn("No project provided. Will not upload source maps. Please set the `project` option to your Sentry project slug.");
1524
+ } else {
1525
+ var _options$sourcemaps, _options$sourcemaps2, _options$sourcemaps3, _options$sourcemaps4;
1526
+ plugins.push(debugIdInjectionPlugin());
1527
+ plugins.push(debugIdUploadPlugin(createDebugIdUploadFunction({
1528
+ assets: (_options$sourcemaps = options.sourcemaps) === null || _options$sourcemaps === void 0 ? void 0 : _options$sourcemaps.assets,
1529
+ ignore: (_options$sourcemaps2 = options.sourcemaps) === null || _options$sourcemaps2 === void 0 ? void 0 : _options$sourcemaps2.ignore,
1530
+ deleteFilesAfterUpload: (_options$sourcemaps3 = options.sourcemaps) === null || _options$sourcemaps3 === void 0 ? void 0 : _options$sourcemaps3.deleteFilesAfterUpload,
1531
+ dist: options.release.dist,
1532
+ releaseName: options.release.name,
1533
+ logger: logger,
1534
+ handleRecoverableError: handleRecoverableError,
1535
+ rewriteSourcesHook: (_options$sourcemaps4 = options.sourcemaps) === null || _options$sourcemaps4 === void 0 ? void 0 : _options$sourcemaps4.rewriteSources,
1536
+ sentryHub: sentryHub,
1537
+ sentryClient: sentryClient,
1538
+ sentryCliOptions: {
1539
+ authToken: options.authToken,
1540
+ org: options.org,
1541
+ project: options.project,
1542
+ silent: options.silent,
1543
+ url: options.url,
1544
+ vcsRemote: options.release.vcsRemote,
1545
+ headers: options.headers
1546
+ }
1547
+ })));
1715
1548
  }
1716
-
1717
1549
  return plugins;
1718
1550
  });
1719
1551
  }
1720
1552
  function getBuildInformation() {
1721
1553
  var packageJson = getPackageJson();
1722
-
1723
1554
  var _ref2 = packageJson ? getDependencies(packageJson) : {
1724
- deps: [],
1725
- depsVersions: {}
1726
- },
1727
- deps = _ref2.deps,
1728
- depsVersions = _ref2.depsVersions;
1729
-
1555
+ deps: [],
1556
+ depsVersions: {}
1557
+ },
1558
+ deps = _ref2.deps,
1559
+ depsVersions = _ref2.depsVersions;
1730
1560
  return {
1731
1561
  deps: deps,
1732
1562
  depsVersions: depsVersions,
1733
1563
  nodeVersion: parseMajorVersion(process.version)
1734
1564
  };
1735
1565
  }
1566
+
1736
1567
  /**
1737
1568
  * Determines whether the Sentry CLI binary is in its expected location.
1738
1569
  * This function is useful since `@sentry/cli` installs the binary via a post-install
1739
1570
  * script and post-install scripts may not always run. E.g. with `npm i --ignore-scripts`.
1740
1571
  */
1741
-
1742
1572
  function sentryCliBinaryExists() {
1743
- return fs__default["default"].existsSync(SentryCli__default["default"].getPath());
1573
+ return fs__namespace.existsSync(SentryCli__default["default"].getPath());
1744
1574
  }
1745
1575
  function createRollupReleaseInjectionHooks(injectionCode) {
1746
1576
  var virtualReleaseInjectionFileId = "\0sentry-release-injection-file";
@@ -1768,19 +1598,20 @@ function createRollupReleaseInjectionHooks(injectionCode) {
1768
1598
  return null;
1769
1599
  }
1770
1600
 
1771
- if (id.match(/\\node_modules\\|\/node_modules\//)) {
1601
+ // id may contain query and hash which will trip up our file extension logic below
1602
+ var idWithoutQueryAndHash = stripQueryAndHashFromPath(id);
1603
+ if (idWithoutQueryAndHash.match(/\\node_modules\\|\/node_modules\//)) {
1772
1604
  return null;
1773
1605
  }
1774
-
1775
1606
  if (![".js", ".ts", ".jsx", ".tsx", ".mjs"].some(function (ending) {
1776
- return id.endsWith(ending);
1607
+ return idWithoutQueryAndHash.endsWith(ending);
1777
1608
  })) {
1778
1609
  return null;
1779
1610
  }
1611
+ var ms = new MagicString__default["default"](code);
1780
1612
 
1781
- var ms = new MagicString__default["default"](code); // Appending instead of prepending has less probability of mucking with user's source maps.
1613
+ // Appending instead of prepending has less probability of mucking with user's source maps.
1782
1614
  // Luckily import statements get hoisted to the top anyways.
1783
-
1784
1615
  ms.append("\n\n;import \"".concat(virtualReleaseInjectionFileId, "\";"));
1785
1616
  return {
1786
1617
  code: ms.toString(),
@@ -1797,18 +1628,17 @@ function createRollupDebugIdInjectionHooks() {
1797
1628
  }) // chunks could be any file (html, md, ...)
1798
1629
  ) {
1799
1630
  var _code$match;
1800
-
1801
1631
  var debugId = stringToUUID(code); // generate a deterministic debug ID
1802
-
1803
1632
  var codeToInject = getDebugIdSnippet(debugId);
1804
1633
  var ms = new MagicString__default["default"](code, {
1805
1634
  filename: chunk.fileName
1806
- }); // We need to be careful not to inject the snippet before any `"use strict";`s.
1807
- // As an additional complication `"use strict";`s may come after any number of comments.
1635
+ });
1808
1636
 
1809
- var commentUseStrictRegex = // Note: CodeQL complains that this regex potentially has n^2 runtime. This likely won't affect realistic files.
1637
+ // We need to be careful not to inject the snippet before any `"use strict";`s.
1638
+ // As an additional complication `"use strict";`s may come after any number of comments.
1639
+ var commentUseStrictRegex =
1640
+ // Note: CodeQL complains that this regex potentially has n^2 runtime. This likely won't affect realistic files.
1810
1641
  /^(?:\s*|\/\*(?:.|\r|\n)*\*\/|\/\/.*[\n\r])*(?:"[^"]*";|'[^']*';)?/;
1811
-
1812
1642
  if ((_code$match = code.match(commentUseStrictRegex)) !== null && _code$match !== void 0 && _code$match[0]) {
1813
1643
  // Add injected code after any comments or "use strict" at the beginning of the bundle.
1814
1644
  ms.replace(commentUseStrictRegex, function (match) {
@@ -1820,7 +1650,6 @@ function createRollupDebugIdInjectionHooks() {
1820
1650
  // need this special case here.
1821
1651
  ms.prepend(codeToInject);
1822
1652
  }
1823
-
1824
1653
  return {
1825
1654
  code: ms.toString(),
1826
1655
  map: ms.generateMap({
@@ -1833,11 +1662,59 @@ function createRollupDebugIdInjectionHooks() {
1833
1662
  }
1834
1663
  };
1835
1664
  }
1665
+
1666
+ function createRollupDebugIdUploadHooks(upload) {
1667
+ return {
1668
+ writeBundle: function writeBundle(outputOptions, bundle) {
1669
+ return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
1670
+ var outputDir, _buildArtifacts, _buildArtifacts2;
1671
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
1672
+ while (1) switch (_context.prev = _context.next) {
1673
+ case 0:
1674
+ if (!outputOptions.dir) {
1675
+ _context.next = 7;
1676
+ break;
1677
+ }
1678
+ outputDir = outputOptions.dir;
1679
+ _buildArtifacts = Object.keys(bundle).map(function (asset) {
1680
+ return path__namespace.join(outputDir, asset);
1681
+ });
1682
+ _context.next = 5;
1683
+ return upload(_buildArtifacts);
1684
+ case 5:
1685
+ _context.next = 15;
1686
+ break;
1687
+ case 7:
1688
+ if (!outputOptions.file) {
1689
+ _context.next = 12;
1690
+ break;
1691
+ }
1692
+ _context.next = 10;
1693
+ return upload([outputOptions.file]);
1694
+ case 10:
1695
+ _context.next = 15;
1696
+ break;
1697
+ case 12:
1698
+ _buildArtifacts2 = Object.keys(bundle).map(function (asset) {
1699
+ return path__namespace.join(path__namespace.resolve(), asset);
1700
+ });
1701
+ _context.next = 15;
1702
+ return upload(_buildArtifacts2);
1703
+ case 15:
1704
+ case "end":
1705
+ return _context.stop();
1706
+ }
1707
+ }, _callee);
1708
+ }))();
1709
+ }
1710
+ };
1711
+ }
1836
1712
  function getDebugIdSnippet(debugId) {
1837
1713
  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){}}();");
1838
1714
  }
1839
1715
 
1840
1716
  exports.createRollupDebugIdInjectionHooks = createRollupDebugIdInjectionHooks;
1717
+ exports.createRollupDebugIdUploadHooks = createRollupDebugIdUploadHooks;
1841
1718
  exports.createRollupReleaseInjectionHooks = createRollupReleaseInjectionHooks;
1842
1719
  exports.getBuildInformation = getBuildInformation;
1843
1720
  exports.getDebugIdSnippet = getDebugIdSnippet;