@sentry/bundler-plugin-core 4.3.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.3.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
@@ -8475,12 +8504,16 @@ function createDebugIdUploadFunction(_ref) {
8475
8504
  var sentryBuildPluginManager = _ref.sentryBuildPluginManager;
8476
8505
  return /*#__PURE__*/function () {
8477
8506
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(buildArtifactPaths) {
8507
+ var cleanedPaths;
8478
8508
  return _regeneratorRuntime().wrap(function _callee$(_context) {
8479
8509
  while (1) switch (_context.prev = _context.next) {
8480
8510
  case 0:
8481
- _context.next = 2;
8482
- return sentryBuildPluginManager.uploadSourcemaps(buildArtifactPaths);
8483
- case 2:
8511
+ // Webpack and perhaps other bundlers allow you to append query strings to
8512
+ // filenames for cache busting purposes. We should strip these before upload.
8513
+ cleanedPaths = buildArtifactPaths.map(stripQueryAndHashFromPath);
8514
+ _context.next = 3;
8515
+ return sentryBuildPluginManager.uploadSourcemaps(cleanedPaths);
8516
+ case 3:
8484
8517
  case "end":
8485
8518
  return _context.stop();
8486
8519
  }
@@ -8745,10 +8778,12 @@ function defaultRewriteSourcesHook(source) {
8745
8778
  }
8746
8779
 
8747
8780
  function createCliInstance(options) {
8781
+ var _getProjects;
8748
8782
  return new SentryCli__default["default"](null, {
8749
8783
  authToken: options.authToken,
8750
8784
  org: options.org,
8751
- 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],
8752
8787
  silent: options.silent,
8753
8788
  url: options.url,
8754
8789
  vcsRemote: options.release.vcsRemote,
@@ -8910,7 +8945,13 @@ function createSentryBuildPluginManager(userOptions, bundlerPluginMetaContext) {
8910
8945
  });
8911
8946
 
8912
8947
  // Set the User-Agent that Sentry CLI will use when interacting with Sentry
8913
- process.env["SENTRY_PIPELINE"] = "".concat(bundlerPluginMetaContext.buildTool, "-plugin/", "4.3.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
+ }
8914
8955
 
8915
8956
  // Not a bulletproof check but should be good enough to at least sometimes determine
8916
8957
  // if the plugin is called in dev/watch mode or for a prod build. The important part
@@ -9032,9 +9073,11 @@ function createSentryBuildPluginManager(userOptions, bundlerPluginMetaContext) {
9032
9073
  bundleMetadata["_sentryBundlerPluginAppKey:".concat(options.applicationKey)] = true;
9033
9074
  }
9034
9075
  if (typeof options.moduleMetadata === "function") {
9076
+ var _getProjects2;
9035
9077
  var args = {
9036
9078
  org: options.org,
9037
- project: options.project,
9079
+ project: (_getProjects2 = getProjects(options.project)) === null || _getProjects2 === void 0 ? void 0 : _getProjects2[0],
9080
+ projects: getProjects(options.project),
9038
9081
  release: options.release.name
9039
9082
  };
9040
9083
  // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
@@ -9142,7 +9185,7 @@ function createSentryBuildPluginManager(userOptions, bundlerPluginMetaContext) {
9142
9185
  logger.warn("No organization slug provided. Will not create release. Please set the `org` option to your Sentry organization slug." + getTurborepoEnvPassthroughWarning("SENTRY_ORG"));
9143
9186
  return _context7.abrupt("return");
9144
9187
  case 20:
9145
- if (options.project) {
9188
+ if (!(!options.project || Array.isArray(options.project) && options.project.length === 0)) {
9146
9189
  _context7.next = 23;
9147
9190
  break;
9148
9191
  }
@@ -9183,6 +9226,9 @@ function createSentryBuildPluginManager(userOptions, bundlerPluginMetaContext) {
9183
9226
  return cliInstance.releases.uploadSourceMaps(options.release.name, {
9184
9227
  include: normalizedInclude,
9185
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),
9186
9232
  // We want this promise to throw if the sourcemaps fail to upload so that we know about it.
9187
9233
  // see: https://github.com/getsentry/sentry-cli/pull/2605
9188
9234
  live: "rejectOnError"
@@ -9385,6 +9431,9 @@ function createSentryBuildPluginManager(userOptions, bundlerPluginMetaContext) {
9385
9431
  dist: options.release.dist
9386
9432
  }],
9387
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),
9388
9437
  live: "rejectOnError"
9389
9438
  });
9390
9439
  case 3:
@@ -9574,6 +9623,9 @@ function createSentryBuildPluginManager(userOptions, bundlerPluginMetaContext) {
9574
9623
  rewrite: false,
9575
9624
  dist: options.release.dist
9576
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),
9577
9629
  live: "rejectOnError"
9578
9630
  });
9579
9631
  case 3:
@@ -9605,6 +9657,7 @@ function createSentryBuildPluginManager(userOptions, bundlerPluginMetaContext) {
9605
9657
  case 34:
9606
9658
  _context18.prev = 34;
9607
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...");
9608
9661
  void startSpan({
9609
9662
  name: "cleanup",
9610
9663
  scope: sentryScope
@@ -9613,7 +9666,7 @@ function createSentryBuildPluginManager(userOptions, bundlerPluginMetaContext) {
9613
9666
  while (1) switch (_context17.prev = _context17.next) {
9614
9667
  case 0:
9615
9668
  if (!folderToCleanUp) {
9616
- _context17.next = 3;
9669
+ _context17.next = 4;
9617
9670
  break;
9618
9671
  }
9619
9672
  _context17.next = 3;
@@ -9622,22 +9675,27 @@ function createSentryBuildPluginManager(userOptions, bundlerPluginMetaContext) {
9622
9675
  force: true
9623
9676
  });
9624
9677
  case 3:
9678
+ logger.debug("Temporary folder deleted: ".concat(folderToCleanUp));
9679
+ case 4:
9625
9680
  case "end":
9626
9681
  return _context17.stop();
9627
9682
  }
9628
9683
  }, _callee17);
9629
9684
  })));
9630
9685
  }
9686
+ logger.debug("Freeing upload dependencies...");
9631
9687
  freeUploadDependencyOnBuildArtifacts();
9632
- _context18.next = 39;
9688
+ logger.debug("Flushing telemetry data...");
9689
+ _context18.next = 41;
9633
9690
  return safeFlushTelemetry(sentryClient);
9634
- case 39:
9691
+ case 41:
9692
+ logger.debug("Telemetry flushed. Plugin upload process complete.");
9635
9693
  return _context18.finish(34);
9636
- case 40:
9694
+ case 43:
9637
9695
  case "end":
9638
9696
  return _context18.stop();
9639
9697
  }
9640
- }, _callee18, null, [[2, 30, 34, 40]]);
9698
+ }, _callee18, null, [[2, 30, 34, 43]]);
9641
9699
  })));
9642
9700
  case 8:
9643
9701
  case "end":
@@ -9711,7 +9769,7 @@ function createSentryBuildPluginManager(userOptions, bundlerPluginMetaContext) {
9711
9769
  };
9712
9770
  }
9713
9771
  function canUploadSourceMaps(options, logger, isDevMode) {
9714
- var _options$sourcemaps10;
9772
+ var _options$sourcemaps10, _getProjects3;
9715
9773
  if ((_options$sourcemaps10 = options.sourcemaps) !== null && _options$sourcemaps10 !== void 0 && _options$sourcemaps10.disable) {
9716
9774
  logger.debug("Source map upload was disabled. Will not upload sourcemaps using debug ID process.");
9717
9775
  return false;
@@ -9728,7 +9786,7 @@ function canUploadSourceMaps(options, logger, isDevMode) {
9728
9786
  logger.warn("No org provided. Will not upload source maps. Please set the `org` option to your Sentry organization slug." + getTurborepoEnvPassthroughWarning("SENTRY_ORG"));
9729
9787
  return false;
9730
9788
  }
9731
- if (!options.project) {
9789
+ if (!((_getProjects3 = getProjects(options.project)) !== null && _getProjects3 !== void 0 && _getProjects3[0])) {
9732
9790
  logger.warn("No project provided. Will not upload source maps. Please set the `project` option to your Sentry project slug." + getTurborepoEnvPassthroughWarning("SENTRY_PROJECT"));
9733
9791
  return false;
9734
9792
  }