@sentry/bundler-plugin-core 0.5.1 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cjs/index.js CHANGED
@@ -14,6 +14,7 @@ var crypto = require('crypto');
14
14
  require('@sentry/tracing');
15
15
  var util = require('util');
16
16
  var glob = require('glob');
17
+ var webpackSources = require('webpack-sources');
17
18
 
18
19
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
19
20
 
@@ -1121,7 +1122,7 @@ function makeSentryClient(dsn, allowedToSendTelemetryPromise, userProject) {
1121
1122
  // a dashboard.
1122
1123
  // Yes, this is slightly abusing the purpose of this field.
1123
1124
  dist: userProject,
1124
- release: "0.5.1",
1125
+ release: "0.6.1",
1125
1126
  integrations: [],
1126
1127
  tracePropagationTargets: ["sentry.io/api"],
1127
1128
  stackParser: node.defaultStackParser,
@@ -1901,12 +1902,14 @@ function getDryRunCLI(cli, logger) {
1901
1902
  }
1902
1903
 
1903
1904
  var DEBUG_ID_INJECTOR_SNIPPET = ';!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="__SENTRY_DEBUG_ID__",e._sentryDebugIdIdentifier="sentry-dbid-__SENTRY_DEBUG_ID__")}catch(e){}}();';
1904
- function injectDebugIdSnippetIntoChunk(code) {
1905
+ function injectDebugIdSnippetIntoChunk(code, filename) {
1905
1906
  var _code$match;
1906
1907
 
1907
1908
  var debugId = stringToUUID(code); // generate a deterministic debug ID
1908
1909
 
1909
- var ms = new MagicString__default["default"](code);
1910
+ var ms = new MagicString__default["default"](code, {
1911
+ filename: filename
1912
+ });
1910
1913
  var codeToInject = DEBUG_ID_INJECTOR_SNIPPET.replace(/__SENTRY_DEBUG_ID__/g, debugId); // We need to be careful not to inject the snippet before any `"use strict";`s.
1911
1914
  // As an additional complication `"use strict";`s may come after any number of comments.
1912
1915
 
@@ -1982,7 +1985,7 @@ function _prepareBundleForDebugIdUpload() {
1982
1985
  switch (_context.prev = _context.next) {
1983
1986
  case 0:
1984
1987
  if (!sourceMapPath) {
1985
- _context.next = 4;
1988
+ _context.next = 3;
1986
1989
  break;
1987
1990
  }
1988
1991
 
@@ -1990,9 +1993,6 @@ function _prepareBundleForDebugIdUpload() {
1990
1993
  return prepareSourceMapForDebugIdUpload(sourceMapPath, path__namespace.join(uploadFolder, "".concat(uniqueUploadName, ".js.map")), debugId, logger);
1991
1994
 
1992
1995
  case 3:
1993
- return _context.abrupt("return", _context.sent);
1994
-
1995
- case 4:
1996
1996
  case "end":
1997
1997
  return _context.stop();
1998
1998
  }
@@ -2004,9 +2004,14 @@ function _prepareBundleForDebugIdUpload() {
2004
2004
  return _ref.apply(this, arguments);
2005
2005
  };
2006
2006
  }());
2007
- return _context2.abrupt("return", Promise.all([writeSourceFilePromise, writeSourceMapFilePromise]));
2007
+ _context2.next = 19;
2008
+ return writeSourceFilePromise;
2008
2009
 
2009
- case 18:
2010
+ case 19:
2011
+ _context2.next = 21;
2012
+ return writeSourceMapFilePromise;
2013
+
2014
+ case 21:
2010
2015
  case "end":
2011
2016
  return _context2.stop();
2012
2017
  }
@@ -2313,6 +2318,10 @@ var unplugin = unplugin$1.createUnplugin(function (options, unpluginMetaContext)
2313
2318
  id: id
2314
2319
  });
2315
2320
 
2321
+ if (id.includes("sentry-release-injection-file")) {
2322
+ return true;
2323
+ }
2324
+
2316
2325
  if (id.match(/\\node_modules\\|\/node_modules\//)) {
2317
2326
  return false; // never transform 3rd party modules
2318
2327
  } // We normalize the id because vite always passes `id` as a unix style path which causes problems when a user passes
@@ -2321,10 +2330,6 @@ var unplugin = unplugin$1.createUnplugin(function (options, unpluginMetaContext)
2321
2330
 
2322
2331
  var normalizedId = path__default["default"].normalize(id);
2323
2332
 
2324
- if (id.includes("sentry-release-injection-file")) {
2325
- return true;
2326
- }
2327
-
2328
2333
  if (internalOptions.releaseInjectionTargets) {
2329
2334
  // If there's an `releaseInjectionTargets` option transform (ie. inject the release varible) when the file path matches the option.
2330
2335
  if (typeof internalOptions.releaseInjectionTargets === "function") {
@@ -2442,14 +2447,14 @@ var unplugin = unplugin$1.createUnplugin(function (options, unpluginMetaContext)
2442
2447
  * Sentry.io, uploading sourcemaps, associating commits and deploys and finalizing the release)
2443
2448
  */
2444
2449
  writeBundle: function writeBundle() {
2445
- return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
2450
+ return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
2446
2451
  var _releaseInjectionSpan;
2447
2452
 
2448
- var releasePipelineSpan, ctx, releaseName, tmpUploadFolder, _transaction, debugIdChunkFilePaths, sourceFileUploadFolderPromise, _transaction2, _transaction3;
2453
+ var releasePipelineSpan, ctx, releaseName, tmpUploadFolder, _transaction, debugIdChunkFilePaths, sourceFileUploadFolderPromise, preparationTasks, workers, worker, workerIndex, _transaction2, _transaction3;
2449
2454
 
2450
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
2455
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
2451
2456
  while (1) {
2452
- switch (_context4.prev = _context4.next) {
2457
+ switch (_context5.prev = _context5.next) {
2453
2458
  case 0:
2454
2459
  logger.debug('Called "writeBundle"');
2455
2460
  (_releaseInjectionSpan = releaseInjectionSpan) === null || _releaseInjectionSpan === void 0 ? void 0 : _releaseInjectionSpan.finish();
@@ -2469,33 +2474,39 @@ var unplugin = unplugin$1.createUnplugin(function (options, unpluginMetaContext)
2469
2474
  logger: logger,
2470
2475
  cli: cli
2471
2476
  };
2472
- _context4.next = 7;
2477
+ _context5.next = 7;
2473
2478
  return releaseNamePromise;
2474
2479
 
2475
2480
  case 7:
2476
- releaseName = _context4.sent;
2477
- _context4.prev = 8;
2481
+ releaseName = _context5.sent;
2482
+ _context5.prev = 8;
2483
+
2484
+ if (unpluginMetaContext.watchMode) {
2485
+ _context5.next = 38;
2486
+ break;
2487
+ }
2478
2488
 
2479
2489
  if (!internalOptions._experiments.debugIdUpload) {
2480
- _context4.next = 21;
2490
+ _context5.next = 26;
2481
2491
  break;
2482
2492
  }
2483
2493
 
2484
- _context4.next = 12;
2494
+ _context5.next = 13;
2485
2495
  return glob.glob(internalOptions._experiments.debugIdUpload.include, {
2486
2496
  absolute: true,
2487
2497
  nodir: true,
2488
2498
  ignore: internalOptions._experiments.debugIdUpload.ignore
2489
2499
  });
2490
2500
 
2491
- case 12:
2492
- debugIdChunkFilePaths = _context4.sent.filter(function (p) {
2501
+ case 13:
2502
+ debugIdChunkFilePaths = _context5.sent.filter(function (p) {
2493
2503
  return p.endsWith(".js") || p.endsWith(".mjs");
2494
2504
  });
2495
- sourceFileUploadFolderPromise = util__default["default"].promisify(fs__default["default"].mkdtemp)(path__default["default"].join(os__default["default"].tmpdir(), "sentry-bundler-plugin-upload-"));
2496
- _context4.next = 16;
2497
- return Promise.all(debugIdChunkFilePaths.map( /*#__PURE__*/function () {
2498
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(chunkFilePath, chunkIndex) {
2505
+ sourceFileUploadFolderPromise = util__default["default"].promisify(fs__default["default"].mkdtemp)(path__default["default"].join(os__default["default"].tmpdir(), "sentry-bundler-plugin-upload-")); // Preparing the bundles can be a lot of work and doing it all at once has the potential of nuking the heap so
2506
+ // instead we do it with a maximum of 16 concurrent workers
2507
+
2508
+ preparationTasks = debugIdChunkFilePaths.map(function (chunkFilePath, chunkIndex) {
2509
+ return /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
2499
2510
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
2500
2511
  while (1) {
2501
2512
  switch (_context3.prev = _context3.next) {
@@ -2519,62 +2530,105 @@ var unplugin = unplugin$1.createUnplugin(function (options, unpluginMetaContext)
2519
2530
  }
2520
2531
  }, _callee3);
2521
2532
  }));
2533
+ });
2534
+ workers = [];
2535
+
2536
+ worker = /*#__PURE__*/function () {
2537
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
2538
+ var task;
2539
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
2540
+ while (1) {
2541
+ switch (_context4.prev = _context4.next) {
2542
+ case 0:
2543
+ if (!(preparationTasks.length > 0)) {
2544
+ _context4.next = 7;
2545
+ break;
2546
+ }
2547
+
2548
+ task = preparationTasks.shift();
2549
+
2550
+ if (!task) {
2551
+ _context4.next = 5;
2552
+ break;
2553
+ }
2554
+
2555
+ _context4.next = 5;
2556
+ return task();
2557
+
2558
+ case 5:
2559
+ _context4.next = 0;
2560
+ break;
2561
+
2562
+ case 7:
2563
+ case "end":
2564
+ return _context4.stop();
2565
+ }
2566
+ }
2567
+ }, _callee4);
2568
+ }));
2522
2569
 
2523
- return function (_x, _x2) {
2524
- return _ref2.apply(this, arguments);
2570
+ return function worker() {
2571
+ return _ref3.apply(this, arguments);
2525
2572
  };
2526
- }()));
2573
+ }();
2574
+
2575
+ for (workerIndex = 0; workerIndex < 16; workerIndex++) {
2576
+ workers.push(worker());
2577
+ }
2527
2578
 
2528
- case 16:
2529
- _context4.next = 18;
2579
+ _context5.next = 21;
2580
+ return Promise.all(workers);
2581
+
2582
+ case 21:
2583
+ _context5.next = 23;
2530
2584
  return sourceFileUploadFolderPromise;
2531
2585
 
2532
- case 18:
2533
- tmpUploadFolder = _context4.sent;
2534
- _context4.next = 21;
2586
+ case 23:
2587
+ tmpUploadFolder = _context5.sent;
2588
+ _context5.next = 26;
2535
2589
  return uploadDebugIdSourcemaps(internalOptions, ctx, tmpUploadFolder, releaseName);
2536
2590
 
2537
- case 21:
2538
- _context4.next = 23;
2591
+ case 26:
2592
+ _context5.next = 28;
2539
2593
  return createNewRelease(internalOptions, ctx, releaseName);
2540
2594
 
2541
- case 23:
2542
- _context4.next = 25;
2595
+ case 28:
2596
+ _context5.next = 30;
2543
2597
  return cleanArtifacts(internalOptions, ctx, releaseName);
2544
2598
 
2545
- case 25:
2546
- _context4.next = 27;
2599
+ case 30:
2600
+ _context5.next = 32;
2547
2601
  return uploadSourceMaps(internalOptions, ctx, releaseName);
2548
2602
 
2549
- case 27:
2550
- _context4.next = 29;
2603
+ case 32:
2604
+ _context5.next = 34;
2551
2605
  return setCommits(internalOptions, ctx, releaseName);
2552
2606
 
2553
- case 29:
2554
- _context4.next = 31;
2607
+ case 34:
2608
+ _context5.next = 36;
2555
2609
  return finalizeRelease(internalOptions, ctx, releaseName);
2556
2610
 
2557
- case 31:
2558
- _context4.next = 33;
2611
+ case 36:
2612
+ _context5.next = 38;
2559
2613
  return addDeploy(internalOptions, ctx, releaseName);
2560
2614
 
2561
- case 33:
2615
+ case 38:
2562
2616
  (_transaction = transaction) === null || _transaction === void 0 ? void 0 : _transaction.setStatus("ok");
2563
- _context4.next = 41;
2617
+ _context5.next = 46;
2564
2618
  break;
2565
2619
 
2566
- case 36:
2567
- _context4.prev = 36;
2568
- _context4.t0 = _context4["catch"](8);
2620
+ case 41:
2621
+ _context5.prev = 41;
2622
+ _context5.t0 = _context5["catch"](8);
2569
2623
  (_transaction2 = transaction) === null || _transaction2 === void 0 ? void 0 : _transaction2.setStatus("cancelled");
2570
2624
  sentryHub.addBreadcrumb({
2571
2625
  level: "error",
2572
2626
  message: "Error during writeBundle"
2573
2627
  });
2574
- handleError(_context4.t0, logger, internalOptions.errorHandler);
2628
+ handleError(_context5.t0, logger, internalOptions.errorHandler);
2575
2629
 
2576
- case 41:
2577
- _context4.prev = 41;
2630
+ case 46:
2631
+ _context5.prev = 46;
2578
2632
 
2579
2633
  if (tmpUploadFolder) {
2580
2634
  fs__default["default"].rm(tmpUploadFolder, {
@@ -2586,26 +2640,26 @@ var unplugin = unplugin$1.createUnplugin(function (options, unpluginMetaContext)
2586
2640
 
2587
2641
  releasePipelineSpan === null || releasePipelineSpan === void 0 ? void 0 : releasePipelineSpan.finish();
2588
2642
  (_transaction3 = transaction) === null || _transaction3 === void 0 ? void 0 : _transaction3.finish();
2589
- _context4.next = 47;
2643
+ _context5.next = 52;
2590
2644
  return sentryClient.flush().then(null, function () {
2591
2645
  logger.warn("Sending of telemetry failed");
2592
2646
  });
2593
2647
 
2594
- case 47:
2595
- return _context4.finish(41);
2648
+ case 52:
2649
+ return _context5.finish(46);
2596
2650
 
2597
- case 48:
2651
+ case 53:
2598
2652
  sentryHub.addBreadcrumb({
2599
2653
  category: "writeBundle:finish",
2600
2654
  level: "info"
2601
2655
  });
2602
2656
 
2603
- case 49:
2657
+ case 54:
2604
2658
  case "end":
2605
- return _context4.stop();
2659
+ return _context5.stop();
2606
2660
  }
2607
2661
  }
2608
- }, _callee4, null, [[8, 36, 41, 48]]);
2662
+ }, _callee5, null, [[8, 41, 46, 53]]);
2609
2663
  }))();
2610
2664
  },
2611
2665
  rollup: {
@@ -2635,6 +2689,55 @@ var unplugin = unplugin$1.createUnplugin(function (options, unpluginMetaContext)
2635
2689
  return null; // returning null means not modifying the chunk at all
2636
2690
  }
2637
2691
  }
2692
+ },
2693
+ webpack: function webpack(compiler) {
2694
+ var _options$_experiments3;
2695
+
2696
+ if ((_options$_experiments3 = options._experiments) !== null && _options$_experiments3 !== void 0 && _options$_experiments3.debugIdUpload) {
2697
+ // Cache inspired by https://github.com/webpack/webpack/pull/15454
2698
+ var cache = new WeakMap();
2699
+ compiler.hooks.compilation.tap("sentry-plugin", function (compilation) {
2700
+ compilation.hooks.optimizeChunkAssets.tap("sentry-plugin", function (chunks) {
2701
+ chunks.forEach(function (chunk) {
2702
+ var fileNames = chunk.files;
2703
+ fileNames.forEach(function (fileName) {
2704
+ var source = compilation.assets[fileName];
2705
+
2706
+ if (!source) {
2707
+ logger.warn("Unable to access compilation assets. If you see this warning, it is likely a bug in the Sentry webpack plugin. Feel free to open an issue at https://github.com/getsentry/sentry-javascript-bundler-plugins with reproduction steps.");
2708
+ return;
2709
+ }
2710
+
2711
+ compilation.updateAsset(fileName, function (oldSource) {
2712
+ var cached = cache.get(oldSource);
2713
+
2714
+ if (cached) {
2715
+ return cached;
2716
+ }
2717
+
2718
+ var originalCode = source.source().toString(); // The source map type is very annoying :(
2719
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-explicit-any
2720
+
2721
+ var originalSourceMap = source.map();
2722
+
2723
+ var _injectDebugIdSnippet = injectDebugIdSnippetIntoChunk(originalCode, fileName),
2724
+ newCode = _injectDebugIdSnippet.code,
2725
+ newSourceMap = _injectDebugIdSnippet.map; // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
2726
+
2727
+
2728
+ newSourceMap.sources = originalSourceMap.sources; // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
2729
+
2730
+ newSourceMap.sourcesContent = originalSourceMap.sourcesContent;
2731
+ var newSource = new webpackSources.SourceMapSource(newCode, fileName, // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
2732
+ originalSourceMap, originalCode, newSourceMap, false);
2733
+ cache.set(oldSource, newSource);
2734
+ return newSource;
2735
+ });
2736
+ });
2737
+ });
2738
+ });
2739
+ });
2740
+ }
2638
2741
  }
2639
2742
  };
2640
2743
  });
@@ -2662,12 +2765,12 @@ function handleError(unknownError, logger, errorHandler) {
2662
2765
  */
2663
2766
 
2664
2767
 
2665
- function generateGlobalInjectorCode(_ref3) {
2666
- var release = _ref3.release,
2667
- injectReleasesMap = _ref3.injectReleasesMap,
2668
- injectBuildInformation = _ref3.injectBuildInformation,
2669
- org = _ref3.org,
2670
- project = _ref3.project;
2768
+ function generateGlobalInjectorCode(_ref4) {
2769
+ var release = _ref4.release,
2770
+ injectReleasesMap = _ref4.injectReleasesMap,
2771
+ injectBuildInformation = _ref4.injectBuildInformation,
2772
+ org = _ref4.org,
2773
+ project = _ref4.project;
2671
2774
  // The code below is mostly ternary operators because it saves bundle size.
2672
2775
  // The checks are to support as many environments as possible. (Node.js, Browser, webworkers, etc.)
2673
2776
  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, "\"};");
@@ -2688,12 +2791,12 @@ function generateGlobalInjectorCode(_ref3) {
2688
2791
  function getBuildInformation() {
2689
2792
  var packageJson = getPackageJson();
2690
2793
 
2691
- var _ref4 = packageJson ? getDependencies(packageJson) : {
2794
+ var _ref5 = packageJson ? getDependencies(packageJson) : {
2692
2795
  deps: [],
2693
2796
  depsVersions: {}
2694
2797
  },
2695
- deps = _ref4.deps,
2696
- depsVersions = _ref4.depsVersions;
2798
+ deps = _ref5.deps,
2799
+ depsVersions = _ref5.depsVersions;
2697
2800
 
2698
2801
  return {
2699
2802
  deps: deps,