@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.
package/dist/cjs/index.js CHANGED
@@ -741,7 +741,7 @@ function replaceBooleanFlagsInCode(code, replacementValues) {
741
741
 
742
742
  var SENTRY_SAAS_URL = "https://sentry.io";
743
743
  function normalizeUserOptions(userOptions) {
744
- 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;
744
+ 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;
745
745
  var options = {
746
746
  org: (_userOptions$org = userOptions.org) !== null && _userOptions$org !== void 0 ? _userOptions$org : process.env["SENTRY_ORG"],
747
747
  project: (_userOptions$project = userOptions.project) !== null && _userOptions$project !== void 0 ? _userOptions$project : process.env["SENTRY_PROJECT"],
@@ -759,7 +759,8 @@ function normalizeUserOptions(userOptions) {
759
759
  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,
760
760
  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,
761
761
  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,
762
- 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"
762
+ 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",
763
+ setCommits: (_userOptions$release6 = userOptions.release) === null || _userOptions$release6 === void 0 ? void 0 : _userOptions$release6.setCommits
763
764
  }),
764
765
  bundleSizeOptimizations: userOptions.bundleSizeOptimizations,
765
766
  reactComponentAnnotation: userOptions.reactComponentAnnotation,
@@ -772,6 +773,31 @@ function normalizeUserOptions(userOptions) {
772
773
  moduleMetadata: userOptions.moduleMetadata,
773
774
  _experiments: (_userOptions$_experim = userOptions._experiments) !== null && _userOptions$_experim !== void 0 ? _userOptions$_experim : {}
774
775
  };
776
+ if (options.release.setCommits === undefined) {
777
+ if (process.env["VERCEL"] && process.env["VERCEL_GIT_COMMIT_SHA"] && process.env["VERCEL_GIT_REPO_SLUG"] && process.env["VERCEL_GIT_REPO_OWNER"]) {
778
+ options.release.setCommits = {
779
+ shouldNotThrowOnFailure: true,
780
+ commit: process.env["VERCEL_GIT_COMMIT_SHA"],
781
+ previousCommit: process.env["VERCEL_GIT_PREVIOUS_SHA"],
782
+ repo: "".concat(process.env["VERCEL_GIT_REPO_OWNER"], "/").concat(process.env["VERCEL_GIT_REPO_SLUG"]),
783
+ ignoreEmpty: true,
784
+ ignoreMissing: true
785
+ };
786
+ } else {
787
+ options.release.setCommits = {
788
+ shouldNotThrowOnFailure: true,
789
+ auto: true,
790
+ ignoreEmpty: true,
791
+ ignoreMissing: true
792
+ };
793
+ }
794
+ }
795
+ if (options.release.deploy === undefined && process.env["VERCEL"] && process.env["VERCEL_TARGET_ENV"]) {
796
+ options.release.deploy = {
797
+ env: "vercel-".concat(process.env["VERCEL_TARGET_ENV"]),
798
+ url: process.env["VERCEL_URL"] ? "https://".concat(process.env["VERCEL_URL"]) : undefined
799
+ };
800
+ }
775
801
  return options;
776
802
  }
777
803
 
@@ -8111,7 +8137,7 @@ function createSentryInstance(options, shouldSendTelemetry, bundler) {
8111
8137
  dsn: "https://4c2bae7d9fbc413e8f7385f55c515d51@o1.ingest.sentry.io/6690737",
8112
8138
  tracesSampleRate: 1,
8113
8139
  sampleRate: 1,
8114
- release: "3.2.2",
8140
+ release: "3.2.3",
8115
8141
  integrations: [],
8116
8142
  tracePropagationTargets: ["sentry.io/api"],
8117
8143
  stackParser: stackParser,
@@ -8570,16 +8596,9 @@ function createDebugIdUploadFunction(_ref) {
8570
8596
  function prepareBundleForDebugIdUpload(_x4, _x5, _x6, _x7, _x8) {
8571
8597
  return _prepareBundleForDebugIdUpload.apply(this, arguments);
8572
8598
  }
8573
-
8574
- /**
8575
- * Looks for a particular string pattern (`sdbid-[debug ID]`) in the bundle
8576
- * source and extracts the bundle's debug ID from it.
8577
- *
8578
- * The string pattern is injected via the debug ID injection snipped.
8579
- */
8580
8599
  function _prepareBundleForDebugIdUpload() {
8581
8600
  _prepareBundleForDebugIdUpload = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(bundleFilePath, uploadFolder, chunkIndex, logger, rewriteSourcesHook) {
8582
- var bundleContent, debugId, uniqueUploadName, writeSourceFilePromise, writeSourceMapFilePromise;
8601
+ var bundleContent, debugId, uniqueSourceFileUploadPath, writeSourceFilePromise, writeSourceMapFilePromise;
8583
8602
  return _regeneratorRuntime().wrap(function _callee11$(_context11) {
8584
8603
  while (1) switch (_context11.prev = _context11.next) {
8585
8604
  case 0:
@@ -8604,9 +8623,13 @@ function _prepareBundleForDebugIdUpload() {
8604
8623
  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));
8605
8624
  return _context11.abrupt("return");
8606
8625
  case 14:
8607
- uniqueUploadName = "".concat(debugId, "-").concat(chunkIndex);
8626
+ uniqueSourceFileUploadPath = getUniqueUploadPath(uploadFolder, chunkIndex, bundleFilePath);
8608
8627
  bundleContent += "\n//# debugId=".concat(debugId);
8609
- writeSourceFilePromise = fs__default["default"].promises.writeFile(path__default["default"].join(uploadFolder, "".concat(uniqueUploadName, ".js")), bundleContent, "utf-8");
8628
+ writeSourceFilePromise = fs__default["default"].promises.mkdir(path__default["default"].dirname(uniqueSourceFileUploadPath), {
8629
+ recursive: true
8630
+ }).then(function () {
8631
+ return fs__default["default"].promises.writeFile(uniqueSourceFileUploadPath, bundleContent, "utf-8");
8632
+ });
8610
8633
  writeSourceMapFilePromise = determineSourceMapPathFromBundle(bundleFilePath, bundleContent, logger).then( /*#__PURE__*/function () {
8611
8634
  var _ref12 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(sourceMapPath) {
8612
8635
  return _regeneratorRuntime().wrap(function _callee10$(_context10) {
@@ -8617,7 +8640,7 @@ function _prepareBundleForDebugIdUpload() {
8617
8640
  break;
8618
8641
  }
8619
8642
  _context10.next = 3;
8620
- return prepareSourceMapForDebugIdUpload(sourceMapPath, path__default["default"].join(uploadFolder, "".concat(uniqueUploadName, ".js.map")), debugId, rewriteSourcesHook, logger);
8643
+ return prepareSourceMapForDebugIdUpload(sourceMapPath, getUniqueUploadPath(uploadFolder, chunkIndex, sourceMapPath), debugId, rewriteSourcesHook, logger);
8621
8644
  case 3:
8622
8645
  case "end":
8623
8646
  return _context10.stop();
@@ -8641,6 +8664,26 @@ function _prepareBundleForDebugIdUpload() {
8641
8664
  }));
8642
8665
  return _prepareBundleForDebugIdUpload.apply(this, arguments);
8643
8666
  }
8667
+ function getUniqueUploadPath(uploadFolder, chunkIndex, filePath) {
8668
+ return path__default["default"].join(uploadFolder, // We add a "chunk index" segment to the path that is a simple incrementing number to avoid name collisions.
8669
+ // Name collisions can happen when files are located "outside" of the current working directory, at different levels but they share a subpath.
8670
+ // Example:
8671
+ // - CWD: /root/foo/cwd
8672
+ // - File 1: /root/foo/index.js -> ../foo/index.js -> foo/index.js
8673
+ // - File 2: /foo/index.js -> ../../foo/index.js -> foo/index.js
8674
+ "".concat(chunkIndex), path__default["default"].normalize(path__default["default"].relative(process.cwd(), filePath).split(path__default["default"].sep)
8675
+ // We filter out these "navigation" segments because a) they look ugly b) they will cause us to break out of the upload folder.
8676
+ .filter(function (segment) {
8677
+ return segment !== ".." && segment !== ".";
8678
+ }).join(path__default["default"].sep)));
8679
+ }
8680
+
8681
+ /**
8682
+ * Looks for a particular string pattern (`sdbid-[debug ID]`) in the bundle
8683
+ * source and extracts the bundle's debug ID from it.
8684
+ *
8685
+ * The string pattern is injected via the debug ID injection snipped.
8686
+ */
8644
8687
  function determineDebugIdFromBundleSource(code) {
8645
8688
  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})/);
8646
8689
  if (match) {
@@ -8767,22 +8810,27 @@ function _prepareSourceMapForDebugIdUpload() {
8767
8810
  }
8768
8811
  _context13.prev = 21;
8769
8812
  _context13.next = 24;
8770
- return util__namespace.promisify(fs__default["default"].writeFile)(targetPath, JSON.stringify(map), {
8771
- encoding: "utf8"
8813
+ return fs__default["default"].promises.mkdir(path__default["default"].dirname(targetPath), {
8814
+ recursive: true
8772
8815
  });
8773
8816
  case 24:
8774
- _context13.next = 30;
8775
- break;
8817
+ _context13.next = 26;
8818
+ return fs__default["default"].promises.writeFile(targetPath, JSON.stringify(map), {
8819
+ encoding: "utf8"
8820
+ });
8776
8821
  case 26:
8777
- _context13.prev = 26;
8822
+ _context13.next = 32;
8823
+ break;
8824
+ case 28:
8825
+ _context13.prev = 28;
8778
8826
  _context13.t2 = _context13["catch"](21);
8779
8827
  logger.error("Failed to prepare source map for debug ID upload: ".concat(sourceMapPath), _context13.t2);
8780
8828
  return _context13.abrupt("return");
8781
- case 30:
8829
+ case 32:
8782
8830
  case "end":
8783
8831
  return _context13.stop();
8784
8832
  }
8785
- }, _callee13, null, [[0, 6], [10, 16], [21, 26]]);
8833
+ }, _callee13, null, [[0, 6], [10, 16], [21, 28]]);
8786
8834
  }));
8787
8835
  return _prepareSourceMapForDebugIdUpload.apply(this, arguments);
8788
8836
  }
@@ -8801,7 +8849,8 @@ function defaultRewriteSourcesHook(source) {
8801
8849
  * Additionally, if legacy upload options are set, it uploads source maps in the legacy (non-debugId) way.
8802
8850
  */
8803
8851
  function releaseManagementPlugin(_ref) {
8804
- var releaseName = _ref.releaseName,
8852
+ var logger = _ref.logger,
8853
+ releaseName = _ref.releaseName,
8805
8854
  include = _ref.include,
8806
8855
  dist = _ref.dist,
8807
8856
  setCommitsOption = _ref.setCommitsOption,
@@ -8858,47 +8907,63 @@ function releaseManagementPlugin(_ref) {
8858
8907
  dist: dist
8859
8908
  });
8860
8909
  case 10:
8861
- if (!setCommitsOption) {
8862
- _context.next = 13;
8910
+ if (!(setCommitsOption !== false)) {
8911
+ _context.next = 23;
8863
8912
  break;
8864
8913
  }
8865
- _context.next = 13;
8914
+ _context.prev = 11;
8915
+ _context.next = 14;
8866
8916
  return cliInstance.releases.setCommits(releaseName, setCommitsOption);
8867
- case 13:
8917
+ case 14:
8918
+ _context.next = 23;
8919
+ break;
8920
+ case 16:
8921
+ _context.prev = 16;
8922
+ _context.t0 = _context["catch"](11);
8923
+ if (!("shouldNotThrowOnFailure" in setCommitsOption && setCommitsOption.shouldNotThrowOnFailure)) {
8924
+ _context.next = 22;
8925
+ break;
8926
+ }
8927
+ logger.debug("An error occurred setting commits on release (this message can be ignored unless you commits on release are desired):", _context.t0);
8928
+ _context.next = 23;
8929
+ break;
8930
+ case 22:
8931
+ throw _context.t0;
8932
+ case 23:
8868
8933
  if (!shouldFinalizeRelease) {
8869
- _context.next = 16;
8934
+ _context.next = 26;
8870
8935
  break;
8871
8936
  }
8872
- _context.next = 16;
8937
+ _context.next = 26;
8873
8938
  return cliInstance.releases.finalize(releaseName);
8874
- case 16:
8939
+ case 26:
8875
8940
  if (!deployOptions) {
8876
- _context.next = 19;
8941
+ _context.next = 29;
8877
8942
  break;
8878
8943
  }
8879
- _context.next = 19;
8944
+ _context.next = 29;
8880
8945
  return cliInstance.releases.newDeploy(releaseName, deployOptions);
8881
- case 19:
8882
- _context.next = 27;
8946
+ case 29:
8947
+ _context.next = 37;
8883
8948
  break;
8884
- case 21:
8885
- _context.prev = 21;
8886
- _context.t0 = _context["catch"](1);
8949
+ case 31:
8950
+ _context.prev = 31;
8951
+ _context.t1 = _context["catch"](1);
8887
8952
  sentryScope.captureException('Error in "releaseManagementPlugin" writeBundle hook');
8888
- _context.next = 26;
8953
+ _context.next = 36;
8889
8954
  return safeFlushTelemetry(sentryClient);
8890
- case 26:
8891
- handleRecoverableError(_context.t0, false);
8892
- case 27:
8893
- _context.prev = 27;
8955
+ case 36:
8956
+ handleRecoverableError(_context.t1, false);
8957
+ case 37:
8958
+ _context.prev = 37;
8894
8959
  freeGlobalDependencyOnSourcemapFiles();
8895
8960
  freeWriteBundleInvocationDependencyOnSourcemapFiles();
8896
- return _context.finish(27);
8897
- case 31:
8961
+ return _context.finish(37);
8962
+ case 41:
8898
8963
  case "end":
8899
8964
  return _context.stop();
8900
8965
  }
8901
- }, _callee, null, [[1, 21, 27, 31]]);
8966
+ }, _callee, null, [[1, 31, 37, 41], [11, 16]]);
8902
8967
  }))();
8903
8968
  }
8904
8969
  };
@@ -9158,7 +9223,7 @@ function sentryUnpluginFactory(_ref) {
9158
9223
  });
9159
9224
 
9160
9225
  // Set the User-Agent that Sentry CLI will use when interacting with Sentry
9161
- process.env["SENTRY_PIPELINE"] = "".concat(unpluginMetaContext.framework, "-plugin/", "3.2.2");
9226
+ process.env["SENTRY_PIPELINE"] = "".concat(unpluginMetaContext.framework, "-plugin/", "3.2.3");
9162
9227
 
9163
9228
  /**
9164
9229
  * Handles errors caught and emitted in various areas of the plugin.
@@ -9314,20 +9379,20 @@ function sentryUnpluginFactory(_ref) {
9314
9379
  plugins.push(moduleMetadataInjectionPlugin(_injectionCode2));
9315
9380
  }
9316
9381
  // https://turbo.build/repo/docs/reference/system-environment-variables#environment-variables-in-tasks
9317
- var isRunningInTurboRepo = Boolean(process.env["TURBO_HASH"]);
9318
- var getTruboRepoEnvPassthroughWarning = function getTruboRepoEnvPassthroughWarning(envVarName) {
9319
- 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") : "";
9382
+ var isRunningInTurborepo = Boolean(process.env["TURBO_HASH"]);
9383
+ var getTurborepoEnvPassthroughWarning = function getTurborepoEnvPassthroughWarning(envVarName) {
9384
+ 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") : "";
9320
9385
  };
9321
9386
  if (!options.release.name) {
9322
9387
  logger.debug("No release name provided. Will not create release. Please set the `release.name` option to identify your release.");
9323
9388
  } else if (isDevMode) {
9324
9389
  logger.debug("Running in development mode. Will not create release.");
9325
9390
  } else if (!options.authToken) {
9326
- 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"));
9391
+ 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"));
9327
9392
  } else if (!options.org && !options.authToken.startsWith("sntrys_")) {
9328
- logger.warn("No organization slug provided. Will not create release. Please set the `org` option to your Sentry organization slug." + getTruboRepoEnvPassthroughWarning("SENTRY_ORG"));
9393
+ logger.warn("No organization slug provided. Will not create release. Please set the `org` option to your Sentry organization slug." + getTurborepoEnvPassthroughWarning("SENTRY_ORG"));
9329
9394
  } else if (!options.project) {
9330
- logger.warn("No project provided. Will not create release. Please set the `project` option to your Sentry project slug." + getTruboRepoEnvPassthroughWarning("SENTRY_PROJECT"));
9395
+ logger.warn("No project provided. Will not create release. Please set the `project` option to your Sentry project slug." + getTurborepoEnvPassthroughWarning("SENTRY_PROJECT"));
9331
9396
  } else {
9332
9397
  plugins.push(releaseManagementPlugin({
9333
9398
  logger: logger,
@@ -9335,6 +9400,8 @@ function sentryUnpluginFactory(_ref) {
9335
9400
  shouldCreateRelease: options.release.create,
9336
9401
  shouldFinalizeRelease: options.release.finalize,
9337
9402
  include: options.release.uploadLegacySourcemaps,
9403
+ // setCommits has a default defined by the options mappings
9404
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
9338
9405
  setCommitsOption: options.release.setCommits,
9339
9406
  deployOptions: options.release.deploy,
9340
9407
  dist: options.release.dist,
@@ -9361,11 +9428,11 @@ function sentryUnpluginFactory(_ref) {
9361
9428
  } else if (isDevMode) {
9362
9429
  logger.debug("Running in development mode. Will not upload sourcemaps.");
9363
9430
  } else if (!options.authToken) {
9364
- 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"));
9431
+ 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"));
9365
9432
  } else if (!options.org && !options.authToken.startsWith("sntrys_")) {
9366
- logger.warn("No org provided. Will not upload source maps. Please set the `org` option to your Sentry organization slug." + getTruboRepoEnvPassthroughWarning("SENTRY_ORG"));
9433
+ logger.warn("No org provided. Will not upload source maps. Please set the `org` option to your Sentry organization slug." + getTurborepoEnvPassthroughWarning("SENTRY_ORG"));
9367
9434
  } else if (!options.project) {
9368
- logger.warn("No project provided. Will not upload source maps. Please set the `project` option to your Sentry project slug." + getTruboRepoEnvPassthroughWarning("SENTRY_PROJECT"));
9435
+ logger.warn("No project provided. Will not upload source maps. Please set the `project` option to your Sentry project slug." + getTurborepoEnvPassthroughWarning("SENTRY_PROJECT"));
9369
9436
  } else {
9370
9437
  var _options$sourcemaps3, _options$sourcemaps4, _options$sourcemaps5;
9371
9438
  // This option is only strongly typed for the webpack plugin, where it is used. It has no effect on other plugins