@sentry/bundler-plugin-core 3.2.2 → 3.2.3

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.
@@ -705,7 +705,7 @@ function replaceBooleanFlagsInCode(code, replacementValues) {
705
705
 
706
706
  var SENTRY_SAAS_URL = "https://sentry.io";
707
707
  function normalizeUserOptions(userOptions) {
708
- var _userOptions$org, _userOptions$project, _userOptions$authToke, _ref, _userOptions$url, _userOptions$debug, _userOptions$silent, _userOptions$telemetr, _userOptions$disable, _ref2, _userOptions$release$, _userOptions$release, _userOptions$release$2, _userOptions$release2, _userOptions$release$3, _userOptions$release3, _userOptions$release$4, _userOptions$release4, _ref3, _userOptions$release$5, _userOptions$release5, _userOptions$_metaOpt, _userOptions$_metaOpt2, _userOptions$_experim;
708
+ var _userOptions$org, _userOptions$project, _userOptions$authToke, _ref, _userOptions$url, _userOptions$debug, _userOptions$silent, _userOptions$telemetr, _userOptions$disable, _ref2, _userOptions$release$, _userOptions$release, _userOptions$release$2, _userOptions$release2, _userOptions$release$3, _userOptions$release3, _userOptions$release$4, _userOptions$release4, _ref3, _userOptions$release$5, _userOptions$release5, _userOptions$release6, _userOptions$_metaOpt, _userOptions$_metaOpt2, _userOptions$_experim;
709
709
  var options = {
710
710
  org: (_userOptions$org = userOptions.org) !== null && _userOptions$org !== void 0 ? _userOptions$org : process.env["SENTRY_ORG"],
711
711
  project: (_userOptions$project = userOptions.project) !== null && _userOptions$project !== void 0 ? _userOptions$project : process.env["SENTRY_PROJECT"],
@@ -723,7 +723,8 @@ function normalizeUserOptions(userOptions) {
723
723
  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,
724
724
  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,
725
725
  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,
726
- vcsRemote: (_ref3 = (_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 && _ref3 !== void 0 ? _ref3 : "origin"
726
+ vcsRemote: (_ref3 = (_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 && _ref3 !== void 0 ? _ref3 : "origin",
727
+ setCommits: (_userOptions$release6 = userOptions.release) === null || _userOptions$release6 === void 0 ? void 0 : _userOptions$release6.setCommits
727
728
  }),
728
729
  bundleSizeOptimizations: userOptions.bundleSizeOptimizations,
729
730
  reactComponentAnnotation: userOptions.reactComponentAnnotation,
@@ -736,6 +737,31 @@ function normalizeUserOptions(userOptions) {
736
737
  moduleMetadata: userOptions.moduleMetadata,
737
738
  _experiments: (_userOptions$_experim = userOptions._experiments) !== null && _userOptions$_experim !== void 0 ? _userOptions$_experim : {}
738
739
  };
740
+ if (options.release.setCommits === undefined) {
741
+ if (process.env["VERCEL"] && process.env["VERCEL_GIT_COMMIT_SHA"] && process.env["VERCEL_GIT_REPO_SLUG"] && process.env["VERCEL_GIT_REPO_OWNER"]) {
742
+ options.release.setCommits = {
743
+ shouldNotThrowOnFailure: true,
744
+ commit: process.env["VERCEL_GIT_COMMIT_SHA"],
745
+ previousCommit: process.env["VERCEL_GIT_PREVIOUS_SHA"],
746
+ repo: "".concat(process.env["VERCEL_GIT_REPO_OWNER"], "/").concat(process.env["VERCEL_GIT_REPO_SLUG"]),
747
+ ignoreEmpty: true,
748
+ ignoreMissing: true
749
+ };
750
+ } else {
751
+ options.release.setCommits = {
752
+ shouldNotThrowOnFailure: true,
753
+ auto: true,
754
+ ignoreEmpty: true,
755
+ ignoreMissing: true
756
+ };
757
+ }
758
+ }
759
+ if (options.release.deploy === undefined && process.env["VERCEL"] && process.env["VERCEL_TARGET_ENV"]) {
760
+ options.release.deploy = {
761
+ env: "vercel-".concat(process.env["VERCEL_TARGET_ENV"]),
762
+ url: process.env["VERCEL_URL"] ? "https://".concat(process.env["VERCEL_URL"]) : undefined
763
+ };
764
+ }
739
765
  return options;
740
766
  }
741
767
 
@@ -8075,7 +8101,7 @@ function createSentryInstance(options, shouldSendTelemetry, bundler) {
8075
8101
  dsn: "https://4c2bae7d9fbc413e8f7385f55c515d51@o1.ingest.sentry.io/6690737",
8076
8102
  tracesSampleRate: 1,
8077
8103
  sampleRate: 1,
8078
- release: "3.2.2",
8104
+ release: "3.2.3",
8079
8105
  integrations: [],
8080
8106
  tracePropagationTargets: ["sentry.io/api"],
8081
8107
  stackParser: stackParser,
@@ -8534,16 +8560,9 @@ function createDebugIdUploadFunction(_ref) {
8534
8560
  function prepareBundleForDebugIdUpload(_x4, _x5, _x6, _x7, _x8) {
8535
8561
  return _prepareBundleForDebugIdUpload.apply(this, arguments);
8536
8562
  }
8537
-
8538
- /**
8539
- * Looks for a particular string pattern (`sdbid-[debug ID]`) in the bundle
8540
- * source and extracts the bundle's debug ID from it.
8541
- *
8542
- * The string pattern is injected via the debug ID injection snipped.
8543
- */
8544
8563
  function _prepareBundleForDebugIdUpload() {
8545
8564
  _prepareBundleForDebugIdUpload = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(bundleFilePath, uploadFolder, chunkIndex, logger, rewriteSourcesHook) {
8546
- var bundleContent, debugId, uniqueUploadName, writeSourceFilePromise, writeSourceMapFilePromise;
8565
+ var bundleContent, debugId, uniqueSourceFileUploadPath, writeSourceFilePromise, writeSourceMapFilePromise;
8547
8566
  return _regeneratorRuntime().wrap(function _callee11$(_context11) {
8548
8567
  while (1) switch (_context11.prev = _context11.next) {
8549
8568
  case 0:
@@ -8568,9 +8587,13 @@ function _prepareBundleForDebugIdUpload() {
8568
8587
  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));
8569
8588
  return _context11.abrupt("return");
8570
8589
  case 14:
8571
- uniqueUploadName = "".concat(debugId, "-").concat(chunkIndex);
8590
+ uniqueSourceFileUploadPath = getUniqueUploadPath(uploadFolder, chunkIndex, bundleFilePath);
8572
8591
  bundleContent += "\n//# debugId=".concat(debugId);
8573
- writeSourceFilePromise = fs__default.promises.writeFile(path__default.join(uploadFolder, "".concat(uniqueUploadName, ".js")), bundleContent, "utf-8");
8592
+ writeSourceFilePromise = fs__default.promises.mkdir(path__default.dirname(uniqueSourceFileUploadPath), {
8593
+ recursive: true
8594
+ }).then(function () {
8595
+ return fs__default.promises.writeFile(uniqueSourceFileUploadPath, bundleContent, "utf-8");
8596
+ });
8574
8597
  writeSourceMapFilePromise = determineSourceMapPathFromBundle(bundleFilePath, bundleContent, logger).then( /*#__PURE__*/function () {
8575
8598
  var _ref12 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(sourceMapPath) {
8576
8599
  return _regeneratorRuntime().wrap(function _callee10$(_context10) {
@@ -8581,7 +8604,7 @@ function _prepareBundleForDebugIdUpload() {
8581
8604
  break;
8582
8605
  }
8583
8606
  _context10.next = 3;
8584
- return prepareSourceMapForDebugIdUpload(sourceMapPath, path__default.join(uploadFolder, "".concat(uniqueUploadName, ".js.map")), debugId, rewriteSourcesHook, logger);
8607
+ return prepareSourceMapForDebugIdUpload(sourceMapPath, getUniqueUploadPath(uploadFolder, chunkIndex, sourceMapPath), debugId, rewriteSourcesHook, logger);
8585
8608
  case 3:
8586
8609
  case "end":
8587
8610
  return _context10.stop();
@@ -8605,6 +8628,26 @@ function _prepareBundleForDebugIdUpload() {
8605
8628
  }));
8606
8629
  return _prepareBundleForDebugIdUpload.apply(this, arguments);
8607
8630
  }
8631
+ function getUniqueUploadPath(uploadFolder, chunkIndex, filePath) {
8632
+ return path__default.join(uploadFolder, // We add a "chunk index" segment to the path that is a simple incrementing number to avoid name collisions.
8633
+ // Name collisions can happen when files are located "outside" of the current working directory, at different levels but they share a subpath.
8634
+ // Example:
8635
+ // - CWD: /root/foo/cwd
8636
+ // - File 1: /root/foo/index.js -> ../foo/index.js -> foo/index.js
8637
+ // - File 2: /foo/index.js -> ../../foo/index.js -> foo/index.js
8638
+ "".concat(chunkIndex), path__default.normalize(path__default.relative(process.cwd(), filePath).split(path__default.sep)
8639
+ // We filter out these "navigation" segments because a) they look ugly b) they will cause us to break out of the upload folder.
8640
+ .filter(function (segment) {
8641
+ return segment !== ".." && segment !== ".";
8642
+ }).join(path__default.sep)));
8643
+ }
8644
+
8645
+ /**
8646
+ * Looks for a particular string pattern (`sdbid-[debug ID]`) in the bundle
8647
+ * source and extracts the bundle's debug ID from it.
8648
+ *
8649
+ * The string pattern is injected via the debug ID injection snipped.
8650
+ */
8608
8651
  function determineDebugIdFromBundleSource(code) {
8609
8652
  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})/);
8610
8653
  if (match) {
@@ -8731,22 +8774,27 @@ function _prepareSourceMapForDebugIdUpload() {
8731
8774
  }
8732
8775
  _context13.prev = 21;
8733
8776
  _context13.next = 24;
8734
- return util.promisify(fs__default.writeFile)(targetPath, JSON.stringify(map), {
8735
- encoding: "utf8"
8777
+ return fs__default.promises.mkdir(path__default.dirname(targetPath), {
8778
+ recursive: true
8736
8779
  });
8737
8780
  case 24:
8738
- _context13.next = 30;
8739
- break;
8781
+ _context13.next = 26;
8782
+ return fs__default.promises.writeFile(targetPath, JSON.stringify(map), {
8783
+ encoding: "utf8"
8784
+ });
8740
8785
  case 26:
8741
- _context13.prev = 26;
8786
+ _context13.next = 32;
8787
+ break;
8788
+ case 28:
8789
+ _context13.prev = 28;
8742
8790
  _context13.t2 = _context13["catch"](21);
8743
8791
  logger.error("Failed to prepare source map for debug ID upload: ".concat(sourceMapPath), _context13.t2);
8744
8792
  return _context13.abrupt("return");
8745
- case 30:
8793
+ case 32:
8746
8794
  case "end":
8747
8795
  return _context13.stop();
8748
8796
  }
8749
- }, _callee13, null, [[0, 6], [10, 16], [21, 26]]);
8797
+ }, _callee13, null, [[0, 6], [10, 16], [21, 28]]);
8750
8798
  }));
8751
8799
  return _prepareSourceMapForDebugIdUpload.apply(this, arguments);
8752
8800
  }
@@ -8765,7 +8813,8 @@ function defaultRewriteSourcesHook(source) {
8765
8813
  * Additionally, if legacy upload options are set, it uploads source maps in the legacy (non-debugId) way.
8766
8814
  */
8767
8815
  function releaseManagementPlugin(_ref) {
8768
- var releaseName = _ref.releaseName,
8816
+ var logger = _ref.logger,
8817
+ releaseName = _ref.releaseName,
8769
8818
  include = _ref.include,
8770
8819
  dist = _ref.dist,
8771
8820
  setCommitsOption = _ref.setCommitsOption,
@@ -8822,47 +8871,63 @@ function releaseManagementPlugin(_ref) {
8822
8871
  dist: dist
8823
8872
  });
8824
8873
  case 10:
8825
- if (!setCommitsOption) {
8826
- _context.next = 13;
8874
+ if (!(setCommitsOption !== false)) {
8875
+ _context.next = 23;
8827
8876
  break;
8828
8877
  }
8829
- _context.next = 13;
8878
+ _context.prev = 11;
8879
+ _context.next = 14;
8830
8880
  return cliInstance.releases.setCommits(releaseName, setCommitsOption);
8831
- case 13:
8881
+ case 14:
8882
+ _context.next = 23;
8883
+ break;
8884
+ case 16:
8885
+ _context.prev = 16;
8886
+ _context.t0 = _context["catch"](11);
8887
+ if (!("shouldNotThrowOnFailure" in setCommitsOption && setCommitsOption.shouldNotThrowOnFailure)) {
8888
+ _context.next = 22;
8889
+ break;
8890
+ }
8891
+ logger.debug("An error occurred setting commits on release (this message can be ignored unless you commits on release are desired):", _context.t0);
8892
+ _context.next = 23;
8893
+ break;
8894
+ case 22:
8895
+ throw _context.t0;
8896
+ case 23:
8832
8897
  if (!shouldFinalizeRelease) {
8833
- _context.next = 16;
8898
+ _context.next = 26;
8834
8899
  break;
8835
8900
  }
8836
- _context.next = 16;
8901
+ _context.next = 26;
8837
8902
  return cliInstance.releases.finalize(releaseName);
8838
- case 16:
8903
+ case 26:
8839
8904
  if (!deployOptions) {
8840
- _context.next = 19;
8905
+ _context.next = 29;
8841
8906
  break;
8842
8907
  }
8843
- _context.next = 19;
8908
+ _context.next = 29;
8844
8909
  return cliInstance.releases.newDeploy(releaseName, deployOptions);
8845
- case 19:
8846
- _context.next = 27;
8910
+ case 29:
8911
+ _context.next = 37;
8847
8912
  break;
8848
- case 21:
8849
- _context.prev = 21;
8850
- _context.t0 = _context["catch"](1);
8913
+ case 31:
8914
+ _context.prev = 31;
8915
+ _context.t1 = _context["catch"](1);
8851
8916
  sentryScope.captureException('Error in "releaseManagementPlugin" writeBundle hook');
8852
- _context.next = 26;
8917
+ _context.next = 36;
8853
8918
  return safeFlushTelemetry(sentryClient);
8854
- case 26:
8855
- handleRecoverableError(_context.t0, false);
8856
- case 27:
8857
- _context.prev = 27;
8919
+ case 36:
8920
+ handleRecoverableError(_context.t1, false);
8921
+ case 37:
8922
+ _context.prev = 37;
8858
8923
  freeGlobalDependencyOnSourcemapFiles();
8859
8924
  freeWriteBundleInvocationDependencyOnSourcemapFiles();
8860
- return _context.finish(27);
8861
- case 31:
8925
+ return _context.finish(37);
8926
+ case 41:
8862
8927
  case "end":
8863
8928
  return _context.stop();
8864
8929
  }
8865
- }, _callee, null, [[1, 21, 27, 31]]);
8930
+ }, _callee, null, [[1, 31, 37, 41], [11, 16]]);
8866
8931
  }))();
8867
8932
  }
8868
8933
  };
@@ -9122,7 +9187,7 @@ function sentryUnpluginFactory(_ref) {
9122
9187
  });
9123
9188
 
9124
9189
  // Set the User-Agent that Sentry CLI will use when interacting with Sentry
9125
- process.env["SENTRY_PIPELINE"] = "".concat(unpluginMetaContext.framework, "-plugin/", "3.2.2");
9190
+ process.env["SENTRY_PIPELINE"] = "".concat(unpluginMetaContext.framework, "-plugin/", "3.2.3");
9126
9191
 
9127
9192
  /**
9128
9193
  * Handles errors caught and emitted in various areas of the plugin.
@@ -9278,20 +9343,20 @@ function sentryUnpluginFactory(_ref) {
9278
9343
  plugins.push(moduleMetadataInjectionPlugin(_injectionCode2));
9279
9344
  }
9280
9345
  // https://turbo.build/repo/docs/reference/system-environment-variables#environment-variables-in-tasks
9281
- var isRunningInTurboRepo = Boolean(process.env["TURBO_HASH"]);
9282
- var getTruboRepoEnvPassthroughWarning = function getTruboRepoEnvPassthroughWarning(envVarName) {
9283
- return isRunningInTurboRepo ? "\nYou seem to be using Truborepo, did you forget to put ".concat(envVarName, " in `passThroughEnv`? https://turbo.build/repo/docs/reference/configuration#passthroughenv") : "";
9346
+ var isRunningInTurborepo = Boolean(process.env["TURBO_HASH"]);
9347
+ var getTurborepoEnvPassthroughWarning = function getTurborepoEnvPassthroughWarning(envVarName) {
9348
+ return isRunningInTurborepo ? "\nYou seem to be using Turborepo, did you forget to put ".concat(envVarName, " in `passThroughEnv`? https://turbo.build/repo/docs/reference/configuration#passthroughenv") : "";
9284
9349
  };
9285
9350
  if (!options.release.name) {
9286
9351
  logger.debug("No release name provided. Will not create release. Please set the `release.name` option to identify your release.");
9287
9352
  } else if (isDevMode) {
9288
9353
  logger.debug("Running in development mode. Will not create release.");
9289
9354
  } else if (!options.authToken) {
9290
- 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/" + getTruboRepoEnvPassthroughWarning("SENTRY_AUTH_TOKEN"));
9355
+ 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/" + getTurborepoEnvPassthroughWarning("SENTRY_AUTH_TOKEN"));
9291
9356
  } else if (!options.org && !options.authToken.startsWith("sntrys_")) {
9292
- logger.warn("No organization slug provided. Will not create release. Please set the `org` option to your Sentry organization slug." + getTruboRepoEnvPassthroughWarning("SENTRY_ORG"));
9357
+ logger.warn("No organization slug provided. Will not create release. Please set the `org` option to your Sentry organization slug." + getTurborepoEnvPassthroughWarning("SENTRY_ORG"));
9293
9358
  } else if (!options.project) {
9294
- logger.warn("No project provided. Will not create release. Please set the `project` option to your Sentry project slug." + getTruboRepoEnvPassthroughWarning("SENTRY_PROJECT"));
9359
+ logger.warn("No project provided. Will not create release. Please set the `project` option to your Sentry project slug." + getTurborepoEnvPassthroughWarning("SENTRY_PROJECT"));
9295
9360
  } else {
9296
9361
  plugins.push(releaseManagementPlugin({
9297
9362
  logger: logger,
@@ -9299,6 +9364,8 @@ function sentryUnpluginFactory(_ref) {
9299
9364
  shouldCreateRelease: options.release.create,
9300
9365
  shouldFinalizeRelease: options.release.finalize,
9301
9366
  include: options.release.uploadLegacySourcemaps,
9367
+ // setCommits has a default defined by the options mappings
9368
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
9302
9369
  setCommitsOption: options.release.setCommits,
9303
9370
  deployOptions: options.release.deploy,
9304
9371
  dist: options.release.dist,
@@ -9325,11 +9392,11 @@ function sentryUnpluginFactory(_ref) {
9325
9392
  } else if (isDevMode) {
9326
9393
  logger.debug("Running in development mode. Will not upload sourcemaps.");
9327
9394
  } else if (!options.authToken) {
9328
- 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/" + getTruboRepoEnvPassthroughWarning("SENTRY_AUTH_TOKEN"));
9395
+ 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/" + getTurborepoEnvPassthroughWarning("SENTRY_AUTH_TOKEN"));
9329
9396
  } else if (!options.org && !options.authToken.startsWith("sntrys_")) {
9330
- logger.warn("No org provided. Will not upload source maps. Please set the `org` option to your Sentry organization slug." + getTruboRepoEnvPassthroughWarning("SENTRY_ORG"));
9397
+ logger.warn("No org provided. Will not upload source maps. Please set the `org` option to your Sentry organization slug." + getTurborepoEnvPassthroughWarning("SENTRY_ORG"));
9331
9398
  } else if (!options.project) {
9332
- logger.warn("No project provided. Will not upload source maps. Please set the `project` option to your Sentry project slug." + getTruboRepoEnvPassthroughWarning("SENTRY_PROJECT"));
9399
+ logger.warn("No project provided. Will not upload source maps. Please set the `project` option to your Sentry project slug." + getTurborepoEnvPassthroughWarning("SENTRY_PROJECT"));
9333
9400
  } else {
9334
9401
  var _options$sourcemaps3, _options$sourcemaps4, _options$sourcemaps5;
9335
9402
  // This option is only strongly typed for the webpack plugin, where it is used. It has no effect on other plugins