@sentry/esbuild-plugin 4.9.1 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cjs/index.js CHANGED
@@ -1,791 +1,179 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var bundlerPluginCore = require('@sentry/bundler-plugin-core');
6
- var path = require('path');
7
- var uuid = require('uuid');
8
-
9
- function _interopNamespace(e) {
10
- if (e && e.__esModule) return e;
11
- var n = Object.create(null);
12
- if (e) {
13
- Object.keys(e).forEach(function (k) {
14
- if (k !== 'default') {
15
- var d = Object.getOwnPropertyDescriptor(e, k);
16
- Object.defineProperty(n, k, d.get ? d : {
17
- enumerable: true,
18
- get: function () { return e[k]; }
19
- });
20
- }
21
- });
22
- }
23
- n["default"] = e;
24
- return Object.freeze(n);
25
- }
26
-
27
- var path__namespace = /*#__PURE__*/_interopNamespace(path);
28
-
29
- function _iterableToArrayLimit(arr, i) {
30
- var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"];
31
- if (null != _i) {
32
- var _s,
33
- _e,
34
- _x,
35
- _r,
36
- _arr = [],
37
- _n = !0,
38
- _d = !1;
39
- try {
40
- if (_x = (_i = _i.call(arr)).next, 0 === i) {
41
- if (Object(_i) !== _i) return;
42
- _n = !1;
43
- } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0);
44
- } catch (err) {
45
- _d = !0, _e = err;
46
- } finally {
47
- try {
48
- if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return;
49
- } finally {
50
- if (_d) throw _e;
51
- }
52
- }
53
- return _arr;
54
- }
55
- }
56
- function ownKeys(object, enumerableOnly) {
57
- var keys = Object.keys(object);
58
- if (Object.getOwnPropertySymbols) {
59
- var symbols = Object.getOwnPropertySymbols(object);
60
- enumerableOnly && (symbols = symbols.filter(function (sym) {
61
- return Object.getOwnPropertyDescriptor(object, sym).enumerable;
62
- })), keys.push.apply(keys, symbols);
63
- }
64
- return keys;
65
- }
66
- function _objectSpread2(target) {
67
- for (var i = 1; i < arguments.length; i++) {
68
- var source = null != arguments[i] ? arguments[i] : {};
69
- i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
70
- _defineProperty(target, key, source[key]);
71
- }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
72
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
73
- });
74
- }
75
- return target;
76
- }
77
- function _regeneratorRuntime() {
78
- _regeneratorRuntime = function () {
79
- return exports;
80
- };
81
- var exports = {},
82
- Op = Object.prototype,
83
- hasOwn = Op.hasOwnProperty,
84
- defineProperty = Object.defineProperty || function (obj, key, desc) {
85
- obj[key] = desc.value;
86
- },
87
- $Symbol = "function" == typeof Symbol ? Symbol : {},
88
- iteratorSymbol = $Symbol.iterator || "@@iterator",
89
- asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator",
90
- toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
91
- function define(obj, key, value) {
92
- return Object.defineProperty(obj, key, {
93
- value: value,
94
- enumerable: !0,
95
- configurable: !0,
96
- writable: !0
97
- }), obj[key];
98
- }
99
- try {
100
- define({}, "");
101
- } catch (err) {
102
- define = function (obj, key, value) {
103
- return obj[key] = value;
104
- };
105
- }
106
- function wrap(innerFn, outerFn, self, tryLocsList) {
107
- var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator,
108
- generator = Object.create(protoGenerator.prototype),
109
- context = new Context(tryLocsList || []);
110
- return defineProperty(generator, "_invoke", {
111
- value: makeInvokeMethod(innerFn, self, context)
112
- }), generator;
113
- }
114
- function tryCatch(fn, obj, arg) {
115
- try {
116
- return {
117
- type: "normal",
118
- arg: fn.call(obj, arg)
119
- };
120
- } catch (err) {
121
- return {
122
- type: "throw",
123
- arg: err
124
- };
125
- }
126
- }
127
- exports.wrap = wrap;
128
- var ContinueSentinel = {};
129
- function Generator() {}
130
- function GeneratorFunction() {}
131
- function GeneratorFunctionPrototype() {}
132
- var IteratorPrototype = {};
133
- define(IteratorPrototype, iteratorSymbol, function () {
134
- return this;
135
- });
136
- var getProto = Object.getPrototypeOf,
137
- NativeIteratorPrototype = getProto && getProto(getProto(values([])));
138
- NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype);
139
- var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
140
- function defineIteratorMethods(prototype) {
141
- ["next", "throw", "return"].forEach(function (method) {
142
- define(prototype, method, function (arg) {
143
- return this._invoke(method, arg);
144
- });
145
- });
146
- }
147
- function AsyncIterator(generator, PromiseImpl) {
148
- function invoke(method, arg, resolve, reject) {
149
- var record = tryCatch(generator[method], generator, arg);
150
- if ("throw" !== record.type) {
151
- var result = record.arg,
152
- value = result.value;
153
- return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
154
- invoke("next", value, resolve, reject);
155
- }, function (err) {
156
- invoke("throw", err, resolve, reject);
157
- }) : PromiseImpl.resolve(value).then(function (unwrapped) {
158
- result.value = unwrapped, resolve(result);
159
- }, function (error) {
160
- return invoke("throw", error, resolve, reject);
161
- });
162
- }
163
- reject(record.arg);
164
- }
165
- var previousPromise;
166
- defineProperty(this, "_invoke", {
167
- value: function (method, arg) {
168
- function callInvokeWithMethodAndArg() {
169
- return new PromiseImpl(function (resolve, reject) {
170
- invoke(method, arg, resolve, reject);
171
- });
172
- }
173
- return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
174
- }
175
- });
176
- }
177
- function makeInvokeMethod(innerFn, self, context) {
178
- var state = "suspendedStart";
179
- return function (method, arg) {
180
- if ("executing" === state) throw new Error("Generator is already running");
181
- if ("completed" === state) {
182
- if ("throw" === method) throw arg;
183
- return doneResult();
184
- }
185
- for (context.method = method, context.arg = arg;;) {
186
- var delegate = context.delegate;
187
- if (delegate) {
188
- var delegateResult = maybeInvokeDelegate(delegate, context);
189
- if (delegateResult) {
190
- if (delegateResult === ContinueSentinel) continue;
191
- return delegateResult;
192
- }
193
- }
194
- if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) {
195
- if ("suspendedStart" === state) throw state = "completed", context.arg;
196
- context.dispatchException(context.arg);
197
- } else "return" === context.method && context.abrupt("return", context.arg);
198
- state = "executing";
199
- var record = tryCatch(innerFn, self, context);
200
- if ("normal" === record.type) {
201
- if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue;
202
- return {
203
- value: record.arg,
204
- done: context.done
205
- };
206
- }
207
- "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg);
208
- }
209
- };
210
- }
211
- function maybeInvokeDelegate(delegate, context) {
212
- var methodName = context.method,
213
- method = delegate.iterator[methodName];
214
- 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;
215
- var record = tryCatch(method, delegate.iterator, context.arg);
216
- if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel;
217
- var info = record.arg;
218
- 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);
219
- }
220
- function pushTryEntry(locs) {
221
- var entry = {
222
- tryLoc: locs[0]
223
- };
224
- 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry);
225
- }
226
- function resetTryEntry(entry) {
227
- var record = entry.completion || {};
228
- record.type = "normal", delete record.arg, entry.completion = record;
229
- }
230
- function Context(tryLocsList) {
231
- this.tryEntries = [{
232
- tryLoc: "root"
233
- }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0);
234
- }
235
- function values(iterable) {
236
- if (iterable) {
237
- var iteratorMethod = iterable[iteratorSymbol];
238
- if (iteratorMethod) return iteratorMethod.call(iterable);
239
- if ("function" == typeof iterable.next) return iterable;
240
- if (!isNaN(iterable.length)) {
241
- var i = -1,
242
- next = function next() {
243
- for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next;
244
- return next.value = undefined, next.done = !0, next;
245
- };
246
- return next.next = next;
247
- }
248
- }
249
- return {
250
- next: doneResult
251
- };
252
- }
253
- function doneResult() {
254
- return {
255
- value: undefined,
256
- done: !0
257
- };
258
- }
259
- return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", {
260
- value: GeneratorFunctionPrototype,
261
- configurable: !0
262
- }), defineProperty(GeneratorFunctionPrototype, "constructor", {
263
- value: GeneratorFunction,
264
- configurable: !0
265
- }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) {
266
- var ctor = "function" == typeof genFun && genFun.constructor;
267
- return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name));
268
- }, exports.mark = function (genFun) {
269
- return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun;
270
- }, exports.awrap = function (arg) {
271
- return {
272
- __await: arg
273
- };
274
- }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
275
- return this;
276
- }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
277
- void 0 === PromiseImpl && (PromiseImpl = Promise);
278
- var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
279
- return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) {
280
- return result.done ? result.value : iter.next();
281
- });
282
- }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () {
283
- return this;
284
- }), define(Gp, "toString", function () {
285
- return "[object Generator]";
286
- }), exports.keys = function (val) {
287
- var object = Object(val),
288
- keys = [];
289
- for (var key in object) keys.push(key);
290
- return keys.reverse(), function next() {
291
- for (; keys.length;) {
292
- var key = keys.pop();
293
- if (key in object) return next.value = key, next.done = !1, next;
294
- }
295
- return next.done = !0, next;
296
- };
297
- }, exports.values = values, Context.prototype = {
298
- constructor: Context,
299
- reset: function (skipTempReset) {
300
- if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined);
301
- },
302
- stop: function () {
303
- this.done = !0;
304
- var rootRecord = this.tryEntries[0].completion;
305
- if ("throw" === rootRecord.type) throw rootRecord.arg;
306
- return this.rval;
307
- },
308
- dispatchException: function (exception) {
309
- if (this.done) throw exception;
310
- var context = this;
311
- function handle(loc, caught) {
312
- return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught;
313
- }
314
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
315
- var entry = this.tryEntries[i],
316
- record = entry.completion;
317
- if ("root" === entry.tryLoc) return handle("end");
318
- if (entry.tryLoc <= this.prev) {
319
- var hasCatch = hasOwn.call(entry, "catchLoc"),
320
- hasFinally = hasOwn.call(entry, "finallyLoc");
321
- if (hasCatch && hasFinally) {
322
- if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
323
- if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
324
- } else if (hasCatch) {
325
- if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
326
- } else {
327
- if (!hasFinally) throw new Error("try statement without catch or finally");
328
- if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
329
- }
330
- }
331
- }
332
- },
333
- abrupt: function (type, arg) {
334
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
335
- var entry = this.tryEntries[i];
336
- if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
337
- var finallyEntry = entry;
338
- break;
339
- }
340
- }
341
- finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null);
342
- var record = finallyEntry ? finallyEntry.completion : {};
343
- return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record);
344
- },
345
- complete: function (record, afterLoc) {
346
- if ("throw" === record.type) throw record.arg;
347
- return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel;
348
- },
349
- finish: function (finallyLoc) {
350
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
351
- var entry = this.tryEntries[i];
352
- if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel;
353
- }
354
- },
355
- catch: function (tryLoc) {
356
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
357
- var entry = this.tryEntries[i];
358
- if (entry.tryLoc === tryLoc) {
359
- var record = entry.completion;
360
- if ("throw" === record.type) {
361
- var thrown = record.arg;
362
- resetTryEntry(entry);
363
- }
364
- return thrown;
365
- }
366
- }
367
- throw new Error("illegal catch attempt");
368
- },
369
- delegateYield: function (iterable, resultName, nextLoc) {
370
- return this.delegate = {
371
- iterator: values(iterable),
372
- resultName: resultName,
373
- nextLoc: nextLoc
374
- }, "next" === this.method && (this.arg = undefined), ContinueSentinel;
375
- }
376
- }, exports;
377
- }
378
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
379
- try {
380
- var info = gen[key](arg);
381
- var value = info.value;
382
- } catch (error) {
383
- reject(error);
384
- return;
385
- }
386
- if (info.done) {
387
- resolve(value);
388
- } else {
389
- Promise.resolve(value).then(_next, _throw);
390
- }
391
- }
392
- function _asyncToGenerator(fn) {
393
- return function () {
394
- var self = this,
395
- args = arguments;
396
- return new Promise(function (resolve, reject) {
397
- var gen = fn.apply(self, args);
398
- function _next(value) {
399
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
400
- }
401
- function _throw(err) {
402
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
403
- }
404
- _next(undefined);
405
- });
406
- };
407
- }
408
- function _defineProperty(obj, key, value) {
409
- key = _toPropertyKey(key);
410
- if (key in obj) {
411
- Object.defineProperty(obj, key, {
412
- value: value,
413
- enumerable: true,
414
- configurable: true,
415
- writable: true
416
- });
417
- } else {
418
- obj[key] = value;
419
- }
420
- return obj;
421
- }
422
- function _slicedToArray(arr, i) {
423
- return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
424
- }
425
- function _arrayWithHoles(arr) {
426
- if (Array.isArray(arr)) return arr;
427
- }
428
- function _unsupportedIterableToArray(o, minLen) {
429
- if (!o) return;
430
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
431
- var n = Object.prototype.toString.call(o).slice(8, -1);
432
- if (n === "Object" && o.constructor) n = o.constructor.name;
433
- if (n === "Map" || n === "Set") return Array.from(o);
434
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
435
- }
436
- function _arrayLikeToArray(arr, len) {
437
- if (len == null || len > arr.length) len = arr.length;
438
- for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
439
- return arr2;
440
- }
441
- function _nonIterableRest() {
442
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
443
- }
444
- function _toPrimitive(input, hint) {
445
- if (typeof input !== "object" || input === null) return input;
446
- var prim = input[Symbol.toPrimitive];
447
- if (prim !== undefined) {
448
- var res = prim.call(input, hint || "default");
449
- if (typeof res !== "object") return res;
450
- throw new TypeError("@@toPrimitive must return a primitive value.");
451
- }
452
- return (hint === "string" ? String : Number)(input);
453
- }
454
- function _toPropertyKey(arg) {
455
- var key = _toPrimitive(arg, "string");
456
- return typeof key === "symbol" ? key : String(key);
457
- }
458
-
459
- function esbuildReleaseInjectionPlugin(injectionCode) {
460
- var pluginName = "sentry-esbuild-release-injection-plugin";
461
- var virtualReleaseInjectionFilePath = path__namespace.resolve("_sentry-release-injection-stub"); // needs to be an absolute path for older eslint versions
462
-
463
- return {
464
- name: pluginName,
465
- esbuild: {
466
- setup: function setup(_ref) {
467
- var initialOptions = _ref.initialOptions,
468
- onLoad = _ref.onLoad,
469
- onResolve = _ref.onResolve;
470
- initialOptions.inject = initialOptions.inject || [];
471
- initialOptions.inject.push(virtualReleaseInjectionFilePath);
472
- onResolve({
473
- filter: /_sentry-release-injection-stub/
474
- }, function (args) {
475
- return {
476
- path: args.path,
477
- sideEffects: true,
478
- pluginName: pluginName
479
- };
480
- });
481
- onLoad({
482
- filter: /_sentry-release-injection-stub/
483
- }, function () {
484
- return {
485
- loader: "js",
486
- pluginName: pluginName,
487
- contents: injectionCode
488
- };
489
- });
490
- }
491
- }
492
- };
493
- }
494
-
495
- /**
496
- * Shared set to track entry points that have been wrapped by the metadata plugin
497
- * This allows the debug ID plugin to know when an import is coming from a metadata proxy
498
- */
499
- var metadataProxyEntryPoints = new Set();
500
-
501
- /**
502
- * Set to track which paths have already been wrapped with debug ID injection
503
- * This prevents the debug ID plugin from wrapping the same module multiple times
504
- */
505
- var debugIdWrappedPaths = new Set();
506
- function esbuildDebugIdInjectionPlugin(logger) {
507
- var pluginName = "sentry-esbuild-debug-id-injection-plugin";
508
- var stubNamespace = "sentry-debug-id-stub";
509
- return {
510
- name: pluginName,
511
- esbuild: {
512
- setup: function setup(_ref2) {
513
- var initialOptions = _ref2.initialOptions,
514
- onLoad = _ref2.onLoad,
515
- onResolve = _ref2.onResolve;
516
- // Clear state from previous builds (important for watch mode and test suites)
517
- debugIdWrappedPaths.clear();
518
- // Also clear metadataProxyEntryPoints here because if moduleMetadataInjectionPlugin
519
- // is not instantiated in this build (e.g., moduleMetadata was disabled), we don't
520
- // want stale entries from a previous build to affect the current one.
521
- metadataProxyEntryPoints.clear();
522
- if (!initialOptions.bundle) {
523
- logger.warn("The Sentry esbuild plugin only supports esbuild with `bundle: true` being set in the esbuild build options. Esbuild will probably crash now. Sorry about that. If you need to upload sourcemaps without `bundle: true`, it is recommended to use Sentry CLI instead: https://docs.sentry.io/platforms/javascript/sourcemaps/uploading/cli/");
524
- }
525
- onResolve({
526
- filter: /.*/
527
- }, function (args) {
528
- var _args$importer, _initialOptions$injec;
529
- // Inject debug IDs into entry points and into imports from metadata proxy modules
530
- var isEntryPoint = args.kind === "entry-point";
531
-
532
- // Check if this import is coming from a metadata proxy module
533
- // The metadata plugin registers entry points it wraps in the shared Set
534
- // We need to strip the query string suffix because esbuild includes the suffix
535
- // (e.g., ?sentryMetadataProxyModule=true) in args.importer
536
- var importerPath = (_args$importer = args.importer) === null || _args$importer === void 0 ? void 0 : _args$importer.split("?")[0];
537
- var isImportFromMetadataProxy = args.kind === "import-statement" && importerPath !== undefined && metadataProxyEntryPoints.has(importerPath);
538
- if (!isEntryPoint && !isImportFromMetadataProxy) {
539
- return;
540
- }
541
-
542
- // Skip injecting debug IDs into modules specified in the esbuild `inject` option
543
- // since they're already part of the entry points
544
- if ((_initialOptions$injec = initialOptions.inject) !== null && _initialOptions$injec !== void 0 && _initialOptions$injec.includes(args.path)) {
545
- return;
546
- }
547
- var resolvedPath = path__namespace.isAbsolute(args.path) ? args.path : path__namespace.join(args.resolveDir, args.path);
548
-
549
- // Skip injecting debug IDs into paths that have already been wrapped
550
- if (debugIdWrappedPaths.has(resolvedPath)) {
551
- return;
552
- }
553
- debugIdWrappedPaths.add(resolvedPath);
554
- return {
555
- pluginName: pluginName,
556
- // needs to be an abs path, otherwise esbuild will complain
557
- path: resolvedPath,
558
- pluginData: {
559
- isProxyResolver: true,
560
- originalPath: args.path,
561
- originalResolveDir: args.resolveDir
562
- },
563
- // We need to add a suffix here, otherwise esbuild will mark the entrypoint as resolved and won't traverse
564
- // the module tree any further down past the proxy module because we're essentially creating a dependency
565
- // loop back to the proxy module.
566
- // By setting a suffix we're telling esbuild that the entrypoint and proxy module are two different things,
567
- // making it re-resolve the entrypoint when it is imported from the proxy module.
568
- // Super confusing? Yes. Works? Apparently... Let's see.
569
- suffix: "?sentryProxyModule=true"
570
- };
571
- });
572
- onLoad({
573
- filter: /.*/
574
- }, function (args) {
575
- var _args$pluginData;
576
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
577
- if (!((_args$pluginData = args.pluginData) !== null && _args$pluginData !== void 0 && _args$pluginData.isProxyResolver)) {
578
- return null;
579
- }
580
-
581
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
582
- var originalPath = args.pluginData.originalPath;
583
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
584
- var originalResolveDir = args.pluginData.originalResolveDir;
585
- return {
586
- loader: "js",
587
- pluginName: pluginName,
588
- // We need to use JSON.stringify below so that any escape backslashes stay escape backslashes, in order not to break paths on windows
589
- contents: "\n import \"_sentry-debug-id-injection-stub\";\n import * as OriginalModule from ".concat(JSON.stringify(originalPath), ";\n export default OriginalModule.default;\n export * from ").concat(JSON.stringify(originalPath), ";"),
590
- resolveDir: originalResolveDir
591
- };
592
- });
593
- onResolve({
594
- filter: /_sentry-debug-id-injection-stub/
595
- }, function (args) {
596
- return {
597
- path: args.path,
598
- sideEffects: true,
599
- pluginName: pluginName,
600
- namespace: stubNamespace,
601
- suffix: "?sentry-module-id=" + uuid.v4() // create different module, each time this is resolved
602
- };
603
- });
604
-
605
- onLoad({
606
- filter: /_sentry-debug-id-injection-stub/,
607
- namespace: stubNamespace
608
- }, function () {
609
- return {
610
- loader: "js",
611
- pluginName: pluginName,
612
- contents: bundlerPluginCore.getDebugIdSnippet(uuid.v4()).code()
613
- };
614
- });
615
- }
616
- }
617
- };
618
- }
619
- function esbuildModuleMetadataInjectionPlugin(injectionCode) {
620
- var pluginName = "sentry-esbuild-module-metadata-injection-plugin";
621
- var stubNamespace = "sentry-module-metadata-stub";
622
- return {
623
- name: pluginName,
624
- esbuild: {
625
- setup: function setup(_ref3) {
626
- var initialOptions = _ref3.initialOptions,
627
- onLoad = _ref3.onLoad,
628
- onResolve = _ref3.onResolve;
629
- // Clear state from previous builds (important for watch mode and test suites)
630
- metadataProxyEntryPoints.clear();
631
- onResolve({
632
- filter: /.*/
633
- }, function (args) {
634
- if (args.kind !== "entry-point") {
635
- return;
636
- } else {
637
- var _initialOptions$injec2;
638
- // Injected modules via the esbuild `inject` option do also have `kind == "entry-point"`.
639
- // We do not want to inject debug IDs into those files because they are already bundled into the entrypoints
640
- if ((_initialOptions$injec2 = initialOptions.inject) !== null && _initialOptions$injec2 !== void 0 && _initialOptions$injec2.includes(args.path)) {
641
- return;
642
- }
643
- var resolvedPath = path__namespace.isAbsolute(args.path) ? args.path : path__namespace.join(args.resolveDir, args.path);
644
-
645
- // Register this entry point so the debug ID plugin knows to wrap imports from
646
- // this proxy module, this because the debug ID may run after the metadata plugin
647
- metadataProxyEntryPoints.add(resolvedPath);
648
- return {
649
- pluginName: pluginName,
650
- // needs to be an abs path, otherwise esbuild will complain
651
- path: resolvedPath,
652
- pluginData: {
653
- isMetadataProxyResolver: true,
654
- originalPath: args.path,
655
- originalResolveDir: args.resolveDir
656
- },
657
- // We need to add a suffix here, otherwise esbuild will mark the entrypoint as resolved and won't traverse
658
- // the module tree any further down past the proxy module because we're essentially creating a dependency
659
- // loop back to the proxy module.
660
- // By setting a suffix we're telling esbuild that the entrypoint and proxy module are two different things,
661
- // making it re-resolve the entrypoint when it is imported from the proxy module.
662
- // Super confusing? Yes. Works? Apparently... Let's see.
663
- suffix: "?sentryMetadataProxyModule=true"
664
- };
665
- }
666
- });
667
- onLoad({
668
- filter: /.*/
669
- }, function (args) {
670
- var _args$pluginData2;
671
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
672
- if (!((_args$pluginData2 = args.pluginData) !== null && _args$pluginData2 !== void 0 && _args$pluginData2.isMetadataProxyResolver)) {
673
- return null;
674
- }
675
-
676
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
677
- var originalPath = args.pluginData.originalPath;
678
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
679
- var originalResolveDir = args.pluginData.originalResolveDir;
680
- return {
681
- loader: "js",
682
- pluginName: pluginName,
683
- // We need to use JSON.stringify below so that any escape backslashes stay escape backslashes, in order not to break paths on windows
684
- contents: "\n import \"_sentry-module-metadata-injection-stub\";\n import * as OriginalModule from ".concat(JSON.stringify(originalPath), ";\n export default OriginalModule.default;\n export * from ").concat(JSON.stringify(originalPath), ";"),
685
- resolveDir: originalResolveDir
686
- };
687
- });
688
- onResolve({
689
- filter: /_sentry-module-metadata-injection-stub/
690
- }, function (args) {
691
- return {
692
- path: args.path,
693
- sideEffects: true,
694
- pluginName: pluginName,
695
- namespace: stubNamespace,
696
- suffix: "?sentry-module-id=" + uuid.v4() // create different module, each time this is resolved
697
- };
698
- });
699
-
700
- onLoad({
701
- filter: /_sentry-module-metadata-injection-stub/,
702
- namespace: stubNamespace
703
- }, function () {
704
- return {
705
- loader: "js",
706
- pluginName: pluginName,
707
- contents: injectionCode
708
- };
709
- });
710
- }
711
- }
712
- };
713
- }
714
- function esbuildDebugIdUploadPlugin(upload, _logger, createDependencyOnBuildArtifacts) {
715
- var freeGlobalDependencyOnDebugIdSourcemapArtifacts = createDependencyOnBuildArtifacts();
716
- return {
717
- name: "sentry-esbuild-debug-id-upload-plugin",
718
- esbuild: {
719
- setup: function setup(_ref4) {
720
- var initialOptions = _ref4.initialOptions,
721
- onEnd = _ref4.onEnd;
722
- initialOptions.metafile = true;
723
- onEnd( /*#__PURE__*/function () {
724
- var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(result) {
725
- var _buildArtifacts;
726
- return _regeneratorRuntime().wrap(function _callee$(_context) {
727
- while (1) switch (_context.prev = _context.next) {
728
- case 0:
729
- _context.prev = 0;
730
- _buildArtifacts = result.metafile ? Object.keys(result.metafile.outputs) : [];
731
- _context.next = 4;
732
- return upload(_buildArtifacts);
733
- case 4:
734
- _context.prev = 4;
735
- freeGlobalDependencyOnDebugIdSourcemapArtifacts();
736
- return _context.finish(4);
737
- case 7:
738
- case "end":
739
- return _context.stop();
740
- }
741
- }, _callee, null, [[0,, 4, 7]]);
742
- }));
743
- return function (_x) {
744
- return _ref5.apply(this, arguments);
745
- };
746
- }());
747
- }
748
- }
749
- };
750
- }
751
- function esbuildBundleSizeOptimizationsPlugin(replacementValues) {
752
- return {
753
- name: "sentry-esbuild-bundle-size-optimizations-plugin",
754
- esbuild: {
755
- setup: function setup(_ref6) {
756
- var initialOptions = _ref6.initialOptions;
757
- var replacementStringValues = {};
758
- Object.entries(replacementValues).forEach(function (_ref7) {
759
- var _ref8 = _slicedToArray(_ref7, 2),
760
- key = _ref8[0],
761
- value = _ref8[1];
762
- replacementStringValues[key] = JSON.stringify(value);
763
- });
764
- initialOptions.define = _objectSpread2(_objectSpread2({}, initialOptions.define), replacementStringValues);
765
- }
766
- }
767
- };
768
- }
769
- var sentryUnplugin = bundlerPluginCore.sentryUnpluginFactory({
770
- injectionPlugin: {
771
- releaseInjectionPlugin: esbuildReleaseInjectionPlugin,
772
- debugIdInjectionPlugin: esbuildDebugIdInjectionPlugin,
773
- moduleMetadataInjectionPlugin: esbuildModuleMetadataInjectionPlugin
774
- },
775
- debugIdUploadPlugin: esbuildDebugIdUploadPlugin,
776
- bundleSizeOptimizationsPlugin: esbuildBundleSizeOptimizationsPlugin
777
- });
778
-
779
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
780
- var sentryEsbuildPlugin = sentryUnplugin.esbuild;
781
-
782
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
783
- var index = sentryUnplugin.esbuild;
784
-
1
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
2
+ //#region \0rolldown/runtime.js
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
12
+ key = keys[i];
13
+ if (!__hasOwnProp.call(to, key) && key !== except) {
14
+ __defProp(to, key, {
15
+ get: ((k) => from[k]).bind(null, key),
16
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
+ });
18
+ }
19
+ }
20
+ }
21
+ return to;
22
+ };
23
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
24
+ value: mod,
25
+ enumerable: true
26
+ }) : target, mod));
27
+
28
+ //#endregion
29
+ let _sentry_bundler_plugin_core = require("@sentry/bundler-plugin-core");
30
+ let node_path = require("node:path");
31
+ node_path = __toESM(node_path);
32
+ let node_module = require("node:module");
33
+ let uuid = require("uuid");
34
+
35
+ //#region src/index.ts
36
+ function getEsbuildMajorVersion() {
37
+ try {
38
+ return (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href)("esbuild").version?.split(".")[1];
39
+ } catch (err) {}
40
+ }
41
+ const pluginName = "sentry-esbuild-plugin";
42
+ function sentryEsbuildPlugin(userOptions = {}) {
43
+ const sentryBuildPluginManager = (0, _sentry_bundler_plugin_core.createSentryBuildPluginManager)(userOptions, {
44
+ loggerPrefix: userOptions._metaOptions?.loggerPrefixOverride ?? `[${pluginName}]`,
45
+ buildTool: "esbuild",
46
+ buildToolMajorVersion: getEsbuildMajorVersion()
47
+ });
48
+ const { logger, normalizedOptions: options, bundleSizeOptimizationReplacementValues: replacementValues, bundleMetadata, createDependencyOnBuildArtifacts } = sentryBuildPluginManager;
49
+ if (options.disable) return {
50
+ name: "sentry-esbuild-noop-plugin",
51
+ setup() {}
52
+ };
53
+ if (process.cwd().match(/\\node_modules\\|\/node_modules\//)) logger.warn("Running Sentry plugin from within a `node_modules` folder. Some features may not work.");
54
+ const sourcemapsEnabled = options.sourcemaps?.disable !== true;
55
+ const staticInjectionCode = new _sentry_bundler_plugin_core.CodeInjection();
56
+ if (!options.release.inject) logger.debug("Release injection disabled via `release.inject` option. Will not inject release.");
57
+ else if (!options.release.name) logger.debug("No release name provided. Will not inject release. Please set the `release.name` option to identify your release.");
58
+ else staticInjectionCode.append((0, _sentry_bundler_plugin_core.generateReleaseInjectorCode)({
59
+ release: options.release.name,
60
+ injectBuildInformation: options._experiments.injectBuildInformation || false
61
+ }));
62
+ if (Object.keys(bundleMetadata).length > 0) staticInjectionCode.append((0, _sentry_bundler_plugin_core.generateModuleMetadataInjectorCode)(bundleMetadata));
63
+ if (options.reactComponentAnnotation?.enabled) logger.warn("Component name annotation is not supported in esbuild. Please use a separate transform step or consider using a different bundler.");
64
+ const transformReplace = Object.keys(replacementValues).length > 0;
65
+ const debugIdWrappedPaths = /* @__PURE__ */ new Set();
66
+ sentryBuildPluginManager.telemetry.emitBundlerPluginExecutionSignal().catch(() => {});
67
+ return {
68
+ name: pluginName,
69
+ setup({ initialOptions, onLoad, onResolve, onEnd }) {
70
+ if (!staticInjectionCode.isEmpty()) {
71
+ const virtualInjectionFilePath = node_path.resolve("_sentry-injection-stub");
72
+ initialOptions.inject = initialOptions.inject || [];
73
+ initialOptions.inject.push(virtualInjectionFilePath);
74
+ onResolve({ filter: /_sentry-injection-stub/ }, (args) => {
75
+ return {
76
+ path: args.path,
77
+ sideEffects: true,
78
+ pluginName
79
+ };
80
+ });
81
+ onLoad({ filter: /_sentry-injection-stub/ }, () => {
82
+ return {
83
+ loader: "js",
84
+ pluginName,
85
+ contents: staticInjectionCode.code()
86
+ };
87
+ });
88
+ }
89
+ if (transformReplace) {
90
+ const replacementStringValues = {};
91
+ Object.entries(replacementValues).forEach(([key, value]) => {
92
+ replacementStringValues[key] = JSON.stringify(value);
93
+ });
94
+ initialOptions.define = {
95
+ ...initialOptions.define,
96
+ ...replacementStringValues
97
+ };
98
+ }
99
+ if (sourcemapsEnabled) {
100
+ debugIdWrappedPaths.clear();
101
+ if (!initialOptions.bundle) logger.warn("The Sentry esbuild plugin only supports esbuild with `bundle: true` being set in the esbuild build options. Esbuild will probably crash now. Sorry about that. If you need to upload sourcemaps without `bundle: true`, it is recommended to use Sentry CLI instead: https://docs.sentry.io/platforms/javascript/sourcemaps/uploading/cli/");
102
+ onResolve({ filter: /.*/ }, (args) => {
103
+ if (args.kind !== "entry-point") return;
104
+ if (initialOptions.inject?.includes(args.path)) return;
105
+ const resolvedPath = node_path.isAbsolute(args.path) ? args.path : node_path.join(args.resolveDir, args.path);
106
+ if (debugIdWrappedPaths.has(resolvedPath)) return;
107
+ debugIdWrappedPaths.add(resolvedPath);
108
+ return {
109
+ pluginName,
110
+ path: resolvedPath,
111
+ pluginData: {
112
+ isDebugIdProxy: true,
113
+ originalPath: args.path,
114
+ originalResolveDir: args.resolveDir
115
+ },
116
+ suffix: "?sentryDebugIdProxy=true"
117
+ };
118
+ });
119
+ onLoad({ filter: /.*/ }, (args) => {
120
+ if (!args.pluginData?.isDebugIdProxy) return null;
121
+ const originalPath = args.pluginData.originalPath;
122
+ const originalResolveDir = args.pluginData.originalResolveDir;
123
+ return {
124
+ loader: "js",
125
+ pluginName,
126
+ contents: `
127
+ import "_sentry-debug-id-injection-stub";
128
+ import * as OriginalModule from ${JSON.stringify(originalPath)};
129
+ export default OriginalModule.default;
130
+ export * from ${JSON.stringify(originalPath)};`,
131
+ resolveDir: originalResolveDir
132
+ };
133
+ });
134
+ onResolve({ filter: /_sentry-debug-id-injection-stub/ }, (args) => {
135
+ return {
136
+ path: args.path,
137
+ sideEffects: true,
138
+ pluginName,
139
+ namespace: "sentry-debug-id-stub",
140
+ suffix: "?sentry-module-id=" + (0, uuid.v4)()
141
+ };
142
+ });
143
+ onLoad({
144
+ filter: /_sentry-debug-id-injection-stub/,
145
+ namespace: "sentry-debug-id-stub"
146
+ }, () => {
147
+ return {
148
+ loader: "js",
149
+ pluginName,
150
+ contents: (0, _sentry_bundler_plugin_core.getDebugIdSnippet)((0, uuid.v4)()).code()
151
+ };
152
+ });
153
+ }
154
+ const freeGlobalDependencyOnBuildArtifacts = createDependencyOnBuildArtifacts();
155
+ const upload = (0, _sentry_bundler_plugin_core.createDebugIdUploadFunction)({ sentryBuildPluginManager });
156
+ initialOptions.metafile = true;
157
+ onEnd(async (result) => {
158
+ try {
159
+ await sentryBuildPluginManager.createRelease();
160
+ if (sourcemapsEnabled && options.sourcemaps?.disable !== "disable-upload") await upload(result.metafile ? Object.keys(result.metafile.outputs) : []);
161
+ } finally {
162
+ freeGlobalDependencyOnBuildArtifacts();
163
+ await sentryBuildPluginManager.deleteArtifacts();
164
+ }
165
+ });
166
+ }
167
+ };
168
+ }
169
+
170
+ //#endregion
171
+ exports.default = sentryEsbuildPlugin;
172
+ exports.sentryEsbuildPlugin = sentryEsbuildPlugin;
785
173
  Object.defineProperty(exports, 'sentryCliBinaryExists', {
786
174
  enumerable: true,
787
- get: function () { return bundlerPluginCore.sentryCliBinaryExists; }
175
+ get: function () {
176
+ return _sentry_bundler_plugin_core.sentryCliBinaryExists;
177
+ }
788
178
  });
789
- exports["default"] = index;
790
- exports.sentryEsbuildPlugin = sentryEsbuildPlugin;
791
- //# sourceMappingURL=index.js.map
179
+ //# sourceMappingURL=index.js.map