@sentry/bundler-plugin-core 0.5.0 → 0.6.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
@@ -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.0",
1125
+ release: "0.6.0",
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
 
@@ -2244,10 +2247,14 @@ var unplugin = unplugin$1.createUnplugin(function (options, unpluginMetaContext)
2244
2247
  });
2245
2248
  }
2246
2249
 
2247
- _context.next = 7;
2250
+ if (process.cwd().match(/\\node_modules\\|\/node_modules\//)) {
2251
+ logger.warn("Running Sentry plugin from within a `node_modules` folder. Some features may not work.");
2252
+ }
2253
+
2254
+ _context.next = 8;
2248
2255
  return releaseNamePromise;
2249
2256
 
2250
- case 7:
2257
+ case 8:
2251
2258
  releaseName = _context.sent;
2252
2259
 
2253
2260
  // At this point, we either have determined a release or we have to bail
@@ -2266,7 +2273,7 @@ var unplugin = unplugin$1.createUnplugin(function (options, unpluginMetaContext)
2266
2273
  cli: cli
2267
2274
  }, "function.plugin.inject_release", "Release injection");
2268
2275
 
2269
- case 11:
2276
+ case 12:
2270
2277
  case "end":
2271
2278
  return _context.stop();
2272
2279
  }
@@ -2307,15 +2314,20 @@ var unplugin = unplugin$1.createUnplugin(function (options, unpluginMetaContext)
2307
2314
  transformInclude: function transformInclude(id) {
2308
2315
  logger.debug('Called "transformInclude":', {
2309
2316
  id: id
2310
- }); // We normalize the id because vite always passes `id` as a unix style path which causes problems when a user passes
2311
- // a windows style path to `releaseInjectionTargets`
2312
-
2313
- var normalizedId = path__default["default"].normalize(id);
2317
+ });
2314
2318
 
2315
2319
  if (id.includes("sentry-release-injection-file")) {
2316
2320
  return true;
2317
2321
  }
2318
2322
 
2323
+ if (id.match(/\\node_modules\\|\/node_modules\//)) {
2324
+ return false; // never transform 3rd party modules
2325
+ } // We normalize the id because vite always passes `id` as a unix style path which causes problems when a user passes
2326
+ // a windows style path to `releaseInjectionTargets`
2327
+
2328
+
2329
+ var normalizedId = path__default["default"].normalize(id);
2330
+
2319
2331
  if (internalOptions.releaseInjectionTargets) {
2320
2332
  // If there's an `releaseInjectionTargets` option transform (ie. inject the release varible) when the file path matches the option.
2321
2333
  if (typeof internalOptions.releaseInjectionTargets === "function") {
@@ -2467,24 +2479,29 @@ var unplugin = unplugin$1.createUnplugin(function (options, unpluginMetaContext)
2467
2479
  releaseName = _context4.sent;
2468
2480
  _context4.prev = 8;
2469
2481
 
2482
+ if (unpluginMetaContext.watchMode) {
2483
+ _context4.next = 34;
2484
+ break;
2485
+ }
2486
+
2470
2487
  if (!internalOptions._experiments.debugIdUpload) {
2471
- _context4.next = 21;
2488
+ _context4.next = 22;
2472
2489
  break;
2473
2490
  }
2474
2491
 
2475
- _context4.next = 12;
2492
+ _context4.next = 13;
2476
2493
  return glob.glob(internalOptions._experiments.debugIdUpload.include, {
2477
2494
  absolute: true,
2478
2495
  nodir: true,
2479
2496
  ignore: internalOptions._experiments.debugIdUpload.ignore
2480
2497
  });
2481
2498
 
2482
- case 12:
2499
+ case 13:
2483
2500
  debugIdChunkFilePaths = _context4.sent.filter(function (p) {
2484
2501
  return p.endsWith(".js") || p.endsWith(".mjs");
2485
2502
  });
2486
2503
  sourceFileUploadFolderPromise = util__default["default"].promisify(fs__default["default"].mkdtemp)(path__default["default"].join(os__default["default"].tmpdir(), "sentry-bundler-plugin-upload-"));
2487
- _context4.next = 16;
2504
+ _context4.next = 17;
2488
2505
  return Promise.all(debugIdChunkFilePaths.map( /*#__PURE__*/function () {
2489
2506
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(chunkFilePath, chunkIndex) {
2490
2507
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
@@ -2516,46 +2533,46 @@ var unplugin = unplugin$1.createUnplugin(function (options, unpluginMetaContext)
2516
2533
  };
2517
2534
  }()));
2518
2535
 
2519
- case 16:
2520
- _context4.next = 18;
2536
+ case 17:
2537
+ _context4.next = 19;
2521
2538
  return sourceFileUploadFolderPromise;
2522
2539
 
2523
- case 18:
2540
+ case 19:
2524
2541
  tmpUploadFolder = _context4.sent;
2525
- _context4.next = 21;
2542
+ _context4.next = 22;
2526
2543
  return uploadDebugIdSourcemaps(internalOptions, ctx, tmpUploadFolder, releaseName);
2527
2544
 
2528
- case 21:
2529
- _context4.next = 23;
2545
+ case 22:
2546
+ _context4.next = 24;
2530
2547
  return createNewRelease(internalOptions, ctx, releaseName);
2531
2548
 
2532
- case 23:
2533
- _context4.next = 25;
2549
+ case 24:
2550
+ _context4.next = 26;
2534
2551
  return cleanArtifacts(internalOptions, ctx, releaseName);
2535
2552
 
2536
- case 25:
2537
- _context4.next = 27;
2553
+ case 26:
2554
+ _context4.next = 28;
2538
2555
  return uploadSourceMaps(internalOptions, ctx, releaseName);
2539
2556
 
2540
- case 27:
2541
- _context4.next = 29;
2557
+ case 28:
2558
+ _context4.next = 30;
2542
2559
  return setCommits(internalOptions, ctx, releaseName);
2543
2560
 
2544
- case 29:
2545
- _context4.next = 31;
2561
+ case 30:
2562
+ _context4.next = 32;
2546
2563
  return finalizeRelease(internalOptions, ctx, releaseName);
2547
2564
 
2548
- case 31:
2549
- _context4.next = 33;
2565
+ case 32:
2566
+ _context4.next = 34;
2550
2567
  return addDeploy(internalOptions, ctx, releaseName);
2551
2568
 
2552
- case 33:
2569
+ case 34:
2553
2570
  (_transaction = transaction) === null || _transaction === void 0 ? void 0 : _transaction.setStatus("ok");
2554
- _context4.next = 41;
2571
+ _context4.next = 42;
2555
2572
  break;
2556
2573
 
2557
- case 36:
2558
- _context4.prev = 36;
2574
+ case 37:
2575
+ _context4.prev = 37;
2559
2576
  _context4.t0 = _context4["catch"](8);
2560
2577
  (_transaction2 = transaction) === null || _transaction2 === void 0 ? void 0 : _transaction2.setStatus("cancelled");
2561
2578
  sentryHub.addBreadcrumb({
@@ -2564,8 +2581,8 @@ var unplugin = unplugin$1.createUnplugin(function (options, unpluginMetaContext)
2564
2581
  });
2565
2582
  handleError(_context4.t0, logger, internalOptions.errorHandler);
2566
2583
 
2567
- case 41:
2568
- _context4.prev = 41;
2584
+ case 42:
2585
+ _context4.prev = 42;
2569
2586
 
2570
2587
  if (tmpUploadFolder) {
2571
2588
  fs__default["default"].rm(tmpUploadFolder, {
@@ -2577,26 +2594,26 @@ var unplugin = unplugin$1.createUnplugin(function (options, unpluginMetaContext)
2577
2594
 
2578
2595
  releasePipelineSpan === null || releasePipelineSpan === void 0 ? void 0 : releasePipelineSpan.finish();
2579
2596
  (_transaction3 = transaction) === null || _transaction3 === void 0 ? void 0 : _transaction3.finish();
2580
- _context4.next = 47;
2597
+ _context4.next = 48;
2581
2598
  return sentryClient.flush().then(null, function () {
2582
2599
  logger.warn("Sending of telemetry failed");
2583
2600
  });
2584
2601
 
2585
- case 47:
2586
- return _context4.finish(41);
2587
-
2588
2602
  case 48:
2603
+ return _context4.finish(42);
2604
+
2605
+ case 49:
2589
2606
  sentryHub.addBreadcrumb({
2590
2607
  category: "writeBundle:finish",
2591
2608
  level: "info"
2592
2609
  });
2593
2610
 
2594
- case 49:
2611
+ case 50:
2595
2612
  case "end":
2596
2613
  return _context4.stop();
2597
2614
  }
2598
2615
  }
2599
- }, _callee4, null, [[8, 36, 41, 48]]);
2616
+ }, _callee4, null, [[8, 37, 42, 49]]);
2600
2617
  }))();
2601
2618
  },
2602
2619
  rollup: {
@@ -2626,6 +2643,55 @@ var unplugin = unplugin$1.createUnplugin(function (options, unpluginMetaContext)
2626
2643
  return null; // returning null means not modifying the chunk at all
2627
2644
  }
2628
2645
  }
2646
+ },
2647
+ webpack: function webpack(compiler) {
2648
+ var _options$_experiments3;
2649
+
2650
+ if ((_options$_experiments3 = options._experiments) !== null && _options$_experiments3 !== void 0 && _options$_experiments3.debugIdUpload) {
2651
+ // Cache inspired by https://github.com/webpack/webpack/pull/15454
2652
+ var cache = new WeakMap();
2653
+ compiler.hooks.compilation.tap("sentry-plugin", function (compilation) {
2654
+ compilation.hooks.optimizeChunkAssets.tap("sentry-plugin", function (chunks) {
2655
+ chunks.forEach(function (chunk) {
2656
+ var fileNames = chunk.files;
2657
+ fileNames.forEach(function (fileName) {
2658
+ var source = compilation.assets[fileName];
2659
+
2660
+ if (!source) {
2661
+ 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.");
2662
+ return;
2663
+ }
2664
+
2665
+ compilation.updateAsset(fileName, function (oldSource) {
2666
+ var cached = cache.get(oldSource);
2667
+
2668
+ if (cached) {
2669
+ return cached;
2670
+ }
2671
+
2672
+ var originalCode = source.source().toString(); // The source map type is very annoying :(
2673
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-explicit-any
2674
+
2675
+ var originalSourceMap = source.map();
2676
+
2677
+ var _injectDebugIdSnippet = injectDebugIdSnippetIntoChunk(originalCode, fileName),
2678
+ newCode = _injectDebugIdSnippet.code,
2679
+ newSourceMap = _injectDebugIdSnippet.map; // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
2680
+
2681
+
2682
+ newSourceMap.sources = originalSourceMap.sources; // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
2683
+
2684
+ newSourceMap.sourcesContent = originalSourceMap.sourcesContent;
2685
+ var newSource = new webpackSources.SourceMapSource(newCode, fileName, // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
2686
+ originalSourceMap, originalCode, newSourceMap, false);
2687
+ cache.set(oldSource, newSource);
2688
+ return newSource;
2689
+ });
2690
+ });
2691
+ });
2692
+ });
2693
+ });
2694
+ }
2629
2695
  }
2630
2696
  };
2631
2697
  });