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