@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.
@@ -13,6 +13,7 @@ import '@sentry/tracing';
13
13
  import * as util from 'util';
14
14
  import util__default from 'util';
15
15
  import { glob } from 'glob';
16
+ import { SourceMapSource } from 'webpack-sources';
16
17
 
17
18
  function _regeneratorRuntime() {
18
19
  /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
@@ -1088,7 +1089,7 @@ function makeSentryClient(dsn, allowedToSendTelemetryPromise, userProject) {
1088
1089
  // a dashboard.
1089
1090
  // Yes, this is slightly abusing the purpose of this field.
1090
1091
  dist: userProject,
1091
- release: "0.5.0",
1092
+ release: "0.6.0",
1092
1093
  integrations: [],
1093
1094
  tracePropagationTargets: ["sentry.io/api"],
1094
1095
  stackParser: defaultStackParser,
@@ -1868,12 +1869,14 @@ function getDryRunCLI(cli, logger) {
1868
1869
  }
1869
1870
 
1870
1871
  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){}}();';
1871
- function injectDebugIdSnippetIntoChunk(code) {
1872
+ function injectDebugIdSnippetIntoChunk(code, filename) {
1872
1873
  var _code$match;
1873
1874
 
1874
1875
  var debugId = stringToUUID(code); // generate a deterministic debug ID
1875
1876
 
1876
- var ms = new MagicString(code);
1877
+ var ms = new MagicString(code, {
1878
+ filename: filename
1879
+ });
1877
1880
  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.
1878
1881
  // As an additional complication `"use strict";`s may come after any number of comments.
1879
1882
 
@@ -2211,10 +2214,14 @@ var unplugin = createUnplugin(function (options, unpluginMetaContext) {
2211
2214
  });
2212
2215
  }
2213
2216
 
2214
- _context.next = 7;
2217
+ if (process.cwd().match(/\\node_modules\\|\/node_modules\//)) {
2218
+ logger.warn("Running Sentry plugin from within a `node_modules` folder. Some features may not work.");
2219
+ }
2220
+
2221
+ _context.next = 8;
2215
2222
  return releaseNamePromise;
2216
2223
 
2217
- case 7:
2224
+ case 8:
2218
2225
  releaseName = _context.sent;
2219
2226
 
2220
2227
  // At this point, we either have determined a release or we have to bail
@@ -2233,7 +2240,7 @@ var unplugin = createUnplugin(function (options, unpluginMetaContext) {
2233
2240
  cli: cli
2234
2241
  }, "function.plugin.inject_release", "Release injection");
2235
2242
 
2236
- case 11:
2243
+ case 12:
2237
2244
  case "end":
2238
2245
  return _context.stop();
2239
2246
  }
@@ -2274,15 +2281,20 @@ var unplugin = createUnplugin(function (options, unpluginMetaContext) {
2274
2281
  transformInclude: function transformInclude(id) {
2275
2282
  logger.debug('Called "transformInclude":', {
2276
2283
  id: id
2277
- }); // We normalize the id because vite always passes `id` as a unix style path which causes problems when a user passes
2278
- // a windows style path to `releaseInjectionTargets`
2279
-
2280
- var normalizedId = path__default.normalize(id);
2284
+ });
2281
2285
 
2282
2286
  if (id.includes("sentry-release-injection-file")) {
2283
2287
  return true;
2284
2288
  }
2285
2289
 
2290
+ if (id.match(/\\node_modules\\|\/node_modules\//)) {
2291
+ return false; // never transform 3rd party modules
2292
+ } // We normalize the id because vite always passes `id` as a unix style path which causes problems when a user passes
2293
+ // a windows style path to `releaseInjectionTargets`
2294
+
2295
+
2296
+ var normalizedId = path__default.normalize(id);
2297
+
2286
2298
  if (internalOptions.releaseInjectionTargets) {
2287
2299
  // If there's an `releaseInjectionTargets` option transform (ie. inject the release varible) when the file path matches the option.
2288
2300
  if (typeof internalOptions.releaseInjectionTargets === "function") {
@@ -2434,24 +2446,29 @@ var unplugin = createUnplugin(function (options, unpluginMetaContext) {
2434
2446
  releaseName = _context4.sent;
2435
2447
  _context4.prev = 8;
2436
2448
 
2449
+ if (unpluginMetaContext.watchMode) {
2450
+ _context4.next = 34;
2451
+ break;
2452
+ }
2453
+
2437
2454
  if (!internalOptions._experiments.debugIdUpload) {
2438
- _context4.next = 21;
2455
+ _context4.next = 22;
2439
2456
  break;
2440
2457
  }
2441
2458
 
2442
- _context4.next = 12;
2459
+ _context4.next = 13;
2443
2460
  return glob(internalOptions._experiments.debugIdUpload.include, {
2444
2461
  absolute: true,
2445
2462
  nodir: true,
2446
2463
  ignore: internalOptions._experiments.debugIdUpload.ignore
2447
2464
  });
2448
2465
 
2449
- case 12:
2466
+ case 13:
2450
2467
  debugIdChunkFilePaths = _context4.sent.filter(function (p) {
2451
2468
  return p.endsWith(".js") || p.endsWith(".mjs");
2452
2469
  });
2453
2470
  sourceFileUploadFolderPromise = util__default.promisify(fs__default.mkdtemp)(path__default.join(os.tmpdir(), "sentry-bundler-plugin-upload-"));
2454
- _context4.next = 16;
2471
+ _context4.next = 17;
2455
2472
  return Promise.all(debugIdChunkFilePaths.map( /*#__PURE__*/function () {
2456
2473
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(chunkFilePath, chunkIndex) {
2457
2474
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
@@ -2483,46 +2500,46 @@ var unplugin = createUnplugin(function (options, unpluginMetaContext) {
2483
2500
  };
2484
2501
  }()));
2485
2502
 
2486
- case 16:
2487
- _context4.next = 18;
2503
+ case 17:
2504
+ _context4.next = 19;
2488
2505
  return sourceFileUploadFolderPromise;
2489
2506
 
2490
- case 18:
2507
+ case 19:
2491
2508
  tmpUploadFolder = _context4.sent;
2492
- _context4.next = 21;
2509
+ _context4.next = 22;
2493
2510
  return uploadDebugIdSourcemaps(internalOptions, ctx, tmpUploadFolder, releaseName);
2494
2511
 
2495
- case 21:
2496
- _context4.next = 23;
2512
+ case 22:
2513
+ _context4.next = 24;
2497
2514
  return createNewRelease(internalOptions, ctx, releaseName);
2498
2515
 
2499
- case 23:
2500
- _context4.next = 25;
2516
+ case 24:
2517
+ _context4.next = 26;
2501
2518
  return cleanArtifacts(internalOptions, ctx, releaseName);
2502
2519
 
2503
- case 25:
2504
- _context4.next = 27;
2520
+ case 26:
2521
+ _context4.next = 28;
2505
2522
  return uploadSourceMaps(internalOptions, ctx, releaseName);
2506
2523
 
2507
- case 27:
2508
- _context4.next = 29;
2524
+ case 28:
2525
+ _context4.next = 30;
2509
2526
  return setCommits(internalOptions, ctx, releaseName);
2510
2527
 
2511
- case 29:
2512
- _context4.next = 31;
2528
+ case 30:
2529
+ _context4.next = 32;
2513
2530
  return finalizeRelease(internalOptions, ctx, releaseName);
2514
2531
 
2515
- case 31:
2516
- _context4.next = 33;
2532
+ case 32:
2533
+ _context4.next = 34;
2517
2534
  return addDeploy(internalOptions, ctx, releaseName);
2518
2535
 
2519
- case 33:
2536
+ case 34:
2520
2537
  (_transaction = transaction) === null || _transaction === void 0 ? void 0 : _transaction.setStatus("ok");
2521
- _context4.next = 41;
2538
+ _context4.next = 42;
2522
2539
  break;
2523
2540
 
2524
- case 36:
2525
- _context4.prev = 36;
2541
+ case 37:
2542
+ _context4.prev = 37;
2526
2543
  _context4.t0 = _context4["catch"](8);
2527
2544
  (_transaction2 = transaction) === null || _transaction2 === void 0 ? void 0 : _transaction2.setStatus("cancelled");
2528
2545
  sentryHub.addBreadcrumb({
@@ -2531,8 +2548,8 @@ var unplugin = createUnplugin(function (options, unpluginMetaContext) {
2531
2548
  });
2532
2549
  handleError(_context4.t0, logger, internalOptions.errorHandler);
2533
2550
 
2534
- case 41:
2535
- _context4.prev = 41;
2551
+ case 42:
2552
+ _context4.prev = 42;
2536
2553
 
2537
2554
  if (tmpUploadFolder) {
2538
2555
  fs__default.rm(tmpUploadFolder, {
@@ -2544,26 +2561,26 @@ var unplugin = createUnplugin(function (options, unpluginMetaContext) {
2544
2561
 
2545
2562
  releasePipelineSpan === null || releasePipelineSpan === void 0 ? void 0 : releasePipelineSpan.finish();
2546
2563
  (_transaction3 = transaction) === null || _transaction3 === void 0 ? void 0 : _transaction3.finish();
2547
- _context4.next = 47;
2564
+ _context4.next = 48;
2548
2565
  return sentryClient.flush().then(null, function () {
2549
2566
  logger.warn("Sending of telemetry failed");
2550
2567
  });
2551
2568
 
2552
- case 47:
2553
- return _context4.finish(41);
2554
-
2555
2569
  case 48:
2570
+ return _context4.finish(42);
2571
+
2572
+ case 49:
2556
2573
  sentryHub.addBreadcrumb({
2557
2574
  category: "writeBundle:finish",
2558
2575
  level: "info"
2559
2576
  });
2560
2577
 
2561
- case 49:
2578
+ case 50:
2562
2579
  case "end":
2563
2580
  return _context4.stop();
2564
2581
  }
2565
2582
  }
2566
- }, _callee4, null, [[8, 36, 41, 48]]);
2583
+ }, _callee4, null, [[8, 37, 42, 49]]);
2567
2584
  }))();
2568
2585
  },
2569
2586
  rollup: {
@@ -2593,6 +2610,55 @@ var unplugin = createUnplugin(function (options, unpluginMetaContext) {
2593
2610
  return null; // returning null means not modifying the chunk at all
2594
2611
  }
2595
2612
  }
2613
+ },
2614
+ webpack: function webpack(compiler) {
2615
+ var _options$_experiments3;
2616
+
2617
+ if ((_options$_experiments3 = options._experiments) !== null && _options$_experiments3 !== void 0 && _options$_experiments3.debugIdUpload) {
2618
+ // Cache inspired by https://github.com/webpack/webpack/pull/15454
2619
+ var cache = new WeakMap();
2620
+ compiler.hooks.compilation.tap("sentry-plugin", function (compilation) {
2621
+ compilation.hooks.optimizeChunkAssets.tap("sentry-plugin", function (chunks) {
2622
+ chunks.forEach(function (chunk) {
2623
+ var fileNames = chunk.files;
2624
+ fileNames.forEach(function (fileName) {
2625
+ var source = compilation.assets[fileName];
2626
+
2627
+ if (!source) {
2628
+ 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.");
2629
+ return;
2630
+ }
2631
+
2632
+ compilation.updateAsset(fileName, function (oldSource) {
2633
+ var cached = cache.get(oldSource);
2634
+
2635
+ if (cached) {
2636
+ return cached;
2637
+ }
2638
+
2639
+ var originalCode = source.source().toString(); // The source map type is very annoying :(
2640
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-explicit-any
2641
+
2642
+ var originalSourceMap = source.map();
2643
+
2644
+ var _injectDebugIdSnippet = injectDebugIdSnippetIntoChunk(originalCode, fileName),
2645
+ newCode = _injectDebugIdSnippet.code,
2646
+ newSourceMap = _injectDebugIdSnippet.map; // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
2647
+
2648
+
2649
+ newSourceMap.sources = originalSourceMap.sources; // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
2650
+
2651
+ newSourceMap.sourcesContent = originalSourceMap.sourcesContent;
2652
+ var newSource = new SourceMapSource(newCode, fileName, // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
2653
+ originalSourceMap, originalCode, newSourceMap, false);
2654
+ cache.set(oldSource, newSource);
2655
+ return newSource;
2656
+ });
2657
+ });
2658
+ });
2659
+ });
2660
+ });
2661
+ }
2596
2662
  }
2597
2663
  };
2598
2664
  });