@sentry/bundler-plugin-core 4.4.0 → 4.5.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
@@ -8023,12 +8023,27 @@ function getTurborepoEnvPassthroughWarning(envVarName) {
8023
8023
  return process.env["TURBO_HASH"] ? "\nYou seem to be using Turborepo, did you forget to put ".concat(envVarName, " in `passThroughEnv`? https://turbo.build/repo/docs/reference/configuration#passthroughenv") : "";
8024
8024
  }
8025
8025
 
8026
+ /**
8027
+ * Gets the projects from the project option. This might be a single project or an array of projects.
8028
+ */
8029
+ function getProjects(project) {
8030
+ if (Array.isArray(project)) {
8031
+ return project;
8032
+ }
8033
+ if (project) {
8034
+ return [project];
8035
+ }
8036
+ return undefined;
8037
+ }
8038
+
8026
8039
  var SENTRY_SAAS_URL = "https://sentry.io";
8027
8040
  function normalizeUserOptions(userOptions) {
8028
- 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;
8041
+ var _userOptions$org, _userOptions$project, _process$env$SENTRY_P, _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;
8029
8042
  var options = {
8030
8043
  org: (_userOptions$org = userOptions.org) !== null && _userOptions$org !== void 0 ? _userOptions$org : process.env["SENTRY_ORG"],
8031
- project: (_userOptions$project = userOptions.project) !== null && _userOptions$project !== void 0 ? _userOptions$project : process.env["SENTRY_PROJECT"],
8044
+ project: (_userOptions$project = userOptions.project) !== null && _userOptions$project !== void 0 ? _userOptions$project : (_process$env$SENTRY_P = process.env["SENTRY_PROJECT"]) !== null && _process$env$SENTRY_P !== void 0 && _process$env$SENTRY_P.includes(",") ? process.env["SENTRY_PROJECT"].split(",").map(function (p) {
8045
+ return p.trim();
8046
+ }) : process.env["SENTRY_PROJECT"],
8032
8047
  authToken: (_userOptions$authToke = userOptions.authToken) !== null && _userOptions$authToke !== void 0 ? _userOptions$authToke : process.env["SENTRY_AUTH_TOKEN"],
8033
8048
  url: (_ref = (_userOptions$url = userOptions.url) !== null && _userOptions$url !== void 0 ? _userOptions$url : process.env["SENTRY_URL"]) !== null && _ref !== void 0 ? _ref : SENTRY_SAAS_URL,
8034
8049
  headers: userOptions.headers,
@@ -8117,6 +8132,20 @@ function validateOptions(options, logger) {
8117
8132
  logger.error("The `deploy` option was specified but is missing the required `env` property.", "Please set the `env` property.");
8118
8133
  return false;
8119
8134
  }
8135
+ if (options.project && Array.isArray(options.project)) {
8136
+ if (options.project.length === 0) {
8137
+ logger.error("The `project` option was specified as an array but is empty.", "Please provide at least one project slug.");
8138
+ return false;
8139
+ }
8140
+ // Check each project is a non-empty string
8141
+ var invalidProjects = options.project.filter(function (p) {
8142
+ return typeof p !== "string" || p.trim() === "";
8143
+ });
8144
+ if (invalidProjects.length > 0) {
8145
+ logger.error("The `project` option contains invalid project slugs.", "All projects must be non-empty strings.");
8146
+ return false;
8147
+ }
8148
+ }
8120
8149
  return true;
8121
8150
  }
8122
8151
 
@@ -8307,7 +8336,7 @@ function createSentryInstance(options, shouldSendTelemetry, buildTool) {
8307
8336
  dsn: "https://4c2bae7d9fbc413e8f7385f55c515d51@o1.ingest.sentry.io/6690737",
8308
8337
  tracesSampleRate: 1,
8309
8338
  sampleRate: 1,
8310
- release: "4.4.0",
8339
+ release: "4.5.0",
8311
8340
  integrations: [],
8312
8341
  tracePropagationTargets: ["sentry.io/api"],
8313
8342
  stackParser: stackParser,
@@ -8374,7 +8403,7 @@ function setTelemetryDataOnScope(options, scope, buildTool) {
8374
8403
  scope.setTag("ci", !!process.env["CI"]);
8375
8404
  scope.setTags({
8376
8405
  organization: org,
8377
- project: project,
8406
+ project: Array.isArray(project) ? project.join(", ") : project !== null && project !== void 0 ? project : "undefined",
8378
8407
  bundler: buildTool
8379
8408
  });
8380
8409
  scope.setUser({
@@ -8390,7 +8419,7 @@ function allowedToSendTelemetry(_x) {
8390
8419
  */
8391
8420
  function _allowedToSendTelemetry() {
8392
8421
  _allowedToSendTelemetry = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(options) {
8393
- var _cliInfo$split$, _cliInfo$split$$repla;
8422
+ var _getProjects, _cliInfo$split$, _cliInfo$split$$repla;
8394
8423
  var silent, org, project, authToken, url, headers, telemetry, release, cli, cliInfo, cliInfoUrl;
8395
8424
  return _regeneratorRuntime().wrap(function _callee$(_context) {
8396
8425
  while (1) switch (_context.prev = _context.next) {
@@ -8412,7 +8441,7 @@ function _allowedToSendTelemetry() {
8412
8441
  url: url,
8413
8442
  authToken: authToken,
8414
8443
  org: org,
8415
- project: project,
8444
+ project: (_getProjects = getProjects(project)) === null || _getProjects === void 0 ? void 0 : _getProjects[0],
8416
8445
  vcsRemote: release.vcsRemote,
8417
8446
  silent: silent,
8418
8447
  headers: headers
@@ -8749,10 +8778,12 @@ function defaultRewriteSourcesHook(source) {
8749
8778
  }
8750
8779
 
8751
8780
  function createCliInstance(options) {
8781
+ var _getProjects;
8752
8782
  return new SentryCli__default["default"](null, {
8753
8783
  authToken: options.authToken,
8754
8784
  org: options.org,
8755
- project: options.project,
8785
+ // Default to the first project if multiple projects are specified
8786
+ project: (_getProjects = getProjects(options.project)) === null || _getProjects === void 0 ? void 0 : _getProjects[0],
8756
8787
  silent: options.silent,
8757
8788
  url: options.url,
8758
8789
  vcsRemote: options.release.vcsRemote,
@@ -8914,7 +8945,13 @@ function createSentryBuildPluginManager(userOptions, bundlerPluginMetaContext) {
8914
8945
  });
8915
8946
 
8916
8947
  // Set the User-Agent that Sentry CLI will use when interacting with Sentry
8917
- process.env["SENTRY_PIPELINE"] = "".concat(bundlerPluginMetaContext.buildTool, "-plugin/", "4.4.0");
8948
+ process.env["SENTRY_PIPELINE"] = "".concat(bundlerPluginMetaContext.buildTool, "-plugin/", "4.5.0");
8949
+
8950
+ // Propagate debug flag to Sentry CLI via environment variable
8951
+ // Only set if not already defined to respect user's explicit configuration
8952
+ if (options.debug && !process.env["SENTRY_LOG_LEVEL"]) {
8953
+ process.env["SENTRY_LOG_LEVEL"] = "debug";
8954
+ }
8918
8955
 
8919
8956
  // Not a bulletproof check but should be good enough to at least sometimes determine
8920
8957
  // if the plugin is called in dev/watch mode or for a prod build. The important part
@@ -9036,9 +9073,11 @@ function createSentryBuildPluginManager(userOptions, bundlerPluginMetaContext) {
9036
9073
  bundleMetadata["_sentryBundlerPluginAppKey:".concat(options.applicationKey)] = true;
9037
9074
  }
9038
9075
  if (typeof options.moduleMetadata === "function") {
9076
+ var _getProjects2;
9039
9077
  var args = {
9040
9078
  org: options.org,
9041
- project: options.project,
9079
+ project: (_getProjects2 = getProjects(options.project)) === null || _getProjects2 === void 0 ? void 0 : _getProjects2[0],
9080
+ projects: getProjects(options.project),
9042
9081
  release: options.release.name
9043
9082
  };
9044
9083
  // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
@@ -9146,7 +9185,7 @@ function createSentryBuildPluginManager(userOptions, bundlerPluginMetaContext) {
9146
9185
  logger.warn("No organization slug provided. Will not create release. Please set the `org` option to your Sentry organization slug." + getTurborepoEnvPassthroughWarning("SENTRY_ORG"));
9147
9186
  return _context7.abrupt("return");
9148
9187
  case 20:
9149
- if (options.project) {
9188
+ if (!(!options.project || Array.isArray(options.project) && options.project.length === 0)) {
9150
9189
  _context7.next = 23;
9151
9190
  break;
9152
9191
  }
@@ -9187,6 +9226,9 @@ function createSentryBuildPluginManager(userOptions, bundlerPluginMetaContext) {
9187
9226
  return cliInstance.releases.uploadSourceMaps(options.release.name, {
9188
9227
  include: normalizedInclude,
9189
9228
  dist: options.release.dist,
9229
+ // @ts-expect-error - projects is not a valid option for uploadSourceMaps but is implemented in the CLI
9230
+ // Remove once https://github.com/getsentry/sentry-cli/pull/2856 is released
9231
+ projects: getProjects(options.project),
9190
9232
  // We want this promise to throw if the sourcemaps fail to upload so that we know about it.
9191
9233
  // see: https://github.com/getsentry/sentry-cli/pull/2605
9192
9234
  live: "rejectOnError"
@@ -9389,6 +9431,9 @@ function createSentryBuildPluginManager(userOptions, bundlerPluginMetaContext) {
9389
9431
  dist: options.release.dist
9390
9432
  }],
9391
9433
  ignore: ignorePaths,
9434
+ // @ts-expect-error - projects is not a valid option for uploadSourceMaps but is implemented in the CLI
9435
+ // Remove once https://github.com/getsentry/sentry-cli/pull/2856 is released
9436
+ projects: getProjects(options.project),
9392
9437
  live: "rejectOnError"
9393
9438
  });
9394
9439
  case 3:
@@ -9578,6 +9623,9 @@ function createSentryBuildPluginManager(userOptions, bundlerPluginMetaContext) {
9578
9623
  rewrite: false,
9579
9624
  dist: options.release.dist
9580
9625
  }],
9626
+ // @ts-expect-error - projects is not a valid option for uploadSourceMaps but is implemented in the CLI
9627
+ // Remove once https://github.com/getsentry/sentry-cli/pull/2856 is released
9628
+ projects: getProjects(options.project),
9581
9629
  live: "rejectOnError"
9582
9630
  });
9583
9631
  case 3:
@@ -9609,6 +9657,7 @@ function createSentryBuildPluginManager(userOptions, bundlerPluginMetaContext) {
9609
9657
  case 34:
9610
9658
  _context18.prev = 34;
9611
9659
  if (folderToCleanUp && !((_process$env2 = process.env) !== null && _process$env2 !== void 0 && _process$env2["SENTRY_TEST_OVERRIDE_TEMP_DIR"])) {
9660
+ logger.debug("Cleaning up temporary files...");
9612
9661
  void startSpan({
9613
9662
  name: "cleanup",
9614
9663
  scope: sentryScope
@@ -9617,7 +9666,7 @@ function createSentryBuildPluginManager(userOptions, bundlerPluginMetaContext) {
9617
9666
  while (1) switch (_context17.prev = _context17.next) {
9618
9667
  case 0:
9619
9668
  if (!folderToCleanUp) {
9620
- _context17.next = 3;
9669
+ _context17.next = 4;
9621
9670
  break;
9622
9671
  }
9623
9672
  _context17.next = 3;
@@ -9626,22 +9675,27 @@ function createSentryBuildPluginManager(userOptions, bundlerPluginMetaContext) {
9626
9675
  force: true
9627
9676
  });
9628
9677
  case 3:
9678
+ logger.debug("Temporary folder deleted: ".concat(folderToCleanUp));
9679
+ case 4:
9629
9680
  case "end":
9630
9681
  return _context17.stop();
9631
9682
  }
9632
9683
  }, _callee17);
9633
9684
  })));
9634
9685
  }
9686
+ logger.debug("Freeing upload dependencies...");
9635
9687
  freeUploadDependencyOnBuildArtifacts();
9636
- _context18.next = 39;
9688
+ logger.debug("Flushing telemetry data...");
9689
+ _context18.next = 41;
9637
9690
  return safeFlushTelemetry(sentryClient);
9638
- case 39:
9691
+ case 41:
9692
+ logger.debug("Telemetry flushed. Plugin upload process complete.");
9639
9693
  return _context18.finish(34);
9640
- case 40:
9694
+ case 43:
9641
9695
  case "end":
9642
9696
  return _context18.stop();
9643
9697
  }
9644
- }, _callee18, null, [[2, 30, 34, 40]]);
9698
+ }, _callee18, null, [[2, 30, 34, 43]]);
9645
9699
  })));
9646
9700
  case 8:
9647
9701
  case "end":
@@ -9715,7 +9769,7 @@ function createSentryBuildPluginManager(userOptions, bundlerPluginMetaContext) {
9715
9769
  };
9716
9770
  }
9717
9771
  function canUploadSourceMaps(options, logger, isDevMode) {
9718
- var _options$sourcemaps10;
9772
+ var _options$sourcemaps10, _getProjects3;
9719
9773
  if ((_options$sourcemaps10 = options.sourcemaps) !== null && _options$sourcemaps10 !== void 0 && _options$sourcemaps10.disable) {
9720
9774
  logger.debug("Source map upload was disabled. Will not upload sourcemaps using debug ID process.");
9721
9775
  return false;
@@ -9732,7 +9786,7 @@ function canUploadSourceMaps(options, logger, isDevMode) {
9732
9786
  logger.warn("No org provided. Will not upload source maps. Please set the `org` option to your Sentry organization slug." + getTurborepoEnvPassthroughWarning("SENTRY_ORG"));
9733
9787
  return false;
9734
9788
  }
9735
- if (!options.project) {
9789
+ if (!((_getProjects3 = getProjects(options.project)) !== null && _getProjects3 !== void 0 && _getProjects3[0])) {
9736
9790
  logger.warn("No project provided. Will not upload source maps. Please set the `project` option to your Sentry project slug." + getTurborepoEnvPassthroughWarning("SENTRY_PROJECT"));
9737
9791
  return false;
9738
9792
  }