@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.
@@ -7986,12 +7986,27 @@ function getTurborepoEnvPassthroughWarning(envVarName) {
7986
7986
  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") : "";
7987
7987
  }
7988
7988
 
7989
+ /**
7990
+ * Gets the projects from the project option. This might be a single project or an array of projects.
7991
+ */
7992
+ function getProjects(project) {
7993
+ if (Array.isArray(project)) {
7994
+ return project;
7995
+ }
7996
+ if (project) {
7997
+ return [project];
7998
+ }
7999
+ return undefined;
8000
+ }
8001
+
7989
8002
  var SENTRY_SAAS_URL = "https://sentry.io";
7990
8003
  function normalizeUserOptions(userOptions) {
7991
- 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;
8004
+ 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;
7992
8005
  var options = {
7993
8006
  org: (_userOptions$org = userOptions.org) !== null && _userOptions$org !== void 0 ? _userOptions$org : process.env["SENTRY_ORG"],
7994
- project: (_userOptions$project = userOptions.project) !== null && _userOptions$project !== void 0 ? _userOptions$project : process.env["SENTRY_PROJECT"],
8007
+ 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) {
8008
+ return p.trim();
8009
+ }) : process.env["SENTRY_PROJECT"],
7995
8010
  authToken: (_userOptions$authToke = userOptions.authToken) !== null && _userOptions$authToke !== void 0 ? _userOptions$authToke : process.env["SENTRY_AUTH_TOKEN"],
7996
8011
  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,
7997
8012
  headers: userOptions.headers,
@@ -8080,6 +8095,20 @@ function validateOptions(options, logger) {
8080
8095
  logger.error("The `deploy` option was specified but is missing the required `env` property.", "Please set the `env` property.");
8081
8096
  return false;
8082
8097
  }
8098
+ if (options.project && Array.isArray(options.project)) {
8099
+ if (options.project.length === 0) {
8100
+ logger.error("The `project` option was specified as an array but is empty.", "Please provide at least one project slug.");
8101
+ return false;
8102
+ }
8103
+ // Check each project is a non-empty string
8104
+ var invalidProjects = options.project.filter(function (p) {
8105
+ return typeof p !== "string" || p.trim() === "";
8106
+ });
8107
+ if (invalidProjects.length > 0) {
8108
+ logger.error("The `project` option contains invalid project slugs.", "All projects must be non-empty strings.");
8109
+ return false;
8110
+ }
8111
+ }
8083
8112
  return true;
8084
8113
  }
8085
8114
 
@@ -8270,7 +8299,7 @@ function createSentryInstance(options, shouldSendTelemetry, buildTool) {
8270
8299
  dsn: "https://4c2bae7d9fbc413e8f7385f55c515d51@o1.ingest.sentry.io/6690737",
8271
8300
  tracesSampleRate: 1,
8272
8301
  sampleRate: 1,
8273
- release: "4.3.0",
8302
+ release: "4.5.0",
8274
8303
  integrations: [],
8275
8304
  tracePropagationTargets: ["sentry.io/api"],
8276
8305
  stackParser: stackParser,
@@ -8337,7 +8366,7 @@ function setTelemetryDataOnScope(options, scope, buildTool) {
8337
8366
  scope.setTag("ci", !!process.env["CI"]);
8338
8367
  scope.setTags({
8339
8368
  organization: org,
8340
- project: project,
8369
+ project: Array.isArray(project) ? project.join(", ") : project !== null && project !== void 0 ? project : "undefined",
8341
8370
  bundler: buildTool
8342
8371
  });
8343
8372
  scope.setUser({
@@ -8353,7 +8382,7 @@ function allowedToSendTelemetry(_x) {
8353
8382
  */
8354
8383
  function _allowedToSendTelemetry() {
8355
8384
  _allowedToSendTelemetry = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(options) {
8356
- var _cliInfo$split$, _cliInfo$split$$repla;
8385
+ var _getProjects, _cliInfo$split$, _cliInfo$split$$repla;
8357
8386
  var silent, org, project, authToken, url, headers, telemetry, release, cli, cliInfo, cliInfoUrl;
8358
8387
  return _regeneratorRuntime().wrap(function _callee$(_context) {
8359
8388
  while (1) switch (_context.prev = _context.next) {
@@ -8375,7 +8404,7 @@ function _allowedToSendTelemetry() {
8375
8404
  url: url,
8376
8405
  authToken: authToken,
8377
8406
  org: org,
8378
- project: project,
8407
+ project: (_getProjects = getProjects(project)) === null || _getProjects === void 0 ? void 0 : _getProjects[0],
8379
8408
  vcsRemote: release.vcsRemote,
8380
8409
  silent: silent,
8381
8410
  headers: headers
@@ -8438,12 +8467,16 @@ function createDebugIdUploadFunction(_ref) {
8438
8467
  var sentryBuildPluginManager = _ref.sentryBuildPluginManager;
8439
8468
  return /*#__PURE__*/function () {
8440
8469
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(buildArtifactPaths) {
8470
+ var cleanedPaths;
8441
8471
  return _regeneratorRuntime().wrap(function _callee$(_context) {
8442
8472
  while (1) switch (_context.prev = _context.next) {
8443
8473
  case 0:
8444
- _context.next = 2;
8445
- return sentryBuildPluginManager.uploadSourcemaps(buildArtifactPaths);
8446
- case 2:
8474
+ // Webpack and perhaps other bundlers allow you to append query strings to
8475
+ // filenames for cache busting purposes. We should strip these before upload.
8476
+ cleanedPaths = buildArtifactPaths.map(stripQueryAndHashFromPath);
8477
+ _context.next = 3;
8478
+ return sentryBuildPluginManager.uploadSourcemaps(cleanedPaths);
8479
+ case 3:
8447
8480
  case "end":
8448
8481
  return _context.stop();
8449
8482
  }
@@ -8708,10 +8741,12 @@ function defaultRewriteSourcesHook(source) {
8708
8741
  }
8709
8742
 
8710
8743
  function createCliInstance(options) {
8744
+ var _getProjects;
8711
8745
  return new SentryCli(null, {
8712
8746
  authToken: options.authToken,
8713
8747
  org: options.org,
8714
- project: options.project,
8748
+ // Default to the first project if multiple projects are specified
8749
+ project: (_getProjects = getProjects(options.project)) === null || _getProjects === void 0 ? void 0 : _getProjects[0],
8715
8750
  silent: options.silent,
8716
8751
  url: options.url,
8717
8752
  vcsRemote: options.release.vcsRemote,
@@ -8873,7 +8908,13 @@ function createSentryBuildPluginManager(userOptions, bundlerPluginMetaContext) {
8873
8908
  });
8874
8909
 
8875
8910
  // Set the User-Agent that Sentry CLI will use when interacting with Sentry
8876
- process.env["SENTRY_PIPELINE"] = "".concat(bundlerPluginMetaContext.buildTool, "-plugin/", "4.3.0");
8911
+ process.env["SENTRY_PIPELINE"] = "".concat(bundlerPluginMetaContext.buildTool, "-plugin/", "4.5.0");
8912
+
8913
+ // Propagate debug flag to Sentry CLI via environment variable
8914
+ // Only set if not already defined to respect user's explicit configuration
8915
+ if (options.debug && !process.env["SENTRY_LOG_LEVEL"]) {
8916
+ process.env["SENTRY_LOG_LEVEL"] = "debug";
8917
+ }
8877
8918
 
8878
8919
  // Not a bulletproof check but should be good enough to at least sometimes determine
8879
8920
  // if the plugin is called in dev/watch mode or for a prod build. The important part
@@ -8995,9 +9036,11 @@ function createSentryBuildPluginManager(userOptions, bundlerPluginMetaContext) {
8995
9036
  bundleMetadata["_sentryBundlerPluginAppKey:".concat(options.applicationKey)] = true;
8996
9037
  }
8997
9038
  if (typeof options.moduleMetadata === "function") {
9039
+ var _getProjects2;
8998
9040
  var args = {
8999
9041
  org: options.org,
9000
- project: options.project,
9042
+ project: (_getProjects2 = getProjects(options.project)) === null || _getProjects2 === void 0 ? void 0 : _getProjects2[0],
9043
+ projects: getProjects(options.project),
9001
9044
  release: options.release.name
9002
9045
  };
9003
9046
  // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
@@ -9105,7 +9148,7 @@ function createSentryBuildPluginManager(userOptions, bundlerPluginMetaContext) {
9105
9148
  logger.warn("No organization slug provided. Will not create release. Please set the `org` option to your Sentry organization slug." + getTurborepoEnvPassthroughWarning("SENTRY_ORG"));
9106
9149
  return _context7.abrupt("return");
9107
9150
  case 20:
9108
- if (options.project) {
9151
+ if (!(!options.project || Array.isArray(options.project) && options.project.length === 0)) {
9109
9152
  _context7.next = 23;
9110
9153
  break;
9111
9154
  }
@@ -9146,6 +9189,9 @@ function createSentryBuildPluginManager(userOptions, bundlerPluginMetaContext) {
9146
9189
  return cliInstance.releases.uploadSourceMaps(options.release.name, {
9147
9190
  include: normalizedInclude,
9148
9191
  dist: options.release.dist,
9192
+ // @ts-expect-error - projects is not a valid option for uploadSourceMaps but is implemented in the CLI
9193
+ // Remove once https://github.com/getsentry/sentry-cli/pull/2856 is released
9194
+ projects: getProjects(options.project),
9149
9195
  // We want this promise to throw if the sourcemaps fail to upload so that we know about it.
9150
9196
  // see: https://github.com/getsentry/sentry-cli/pull/2605
9151
9197
  live: "rejectOnError"
@@ -9348,6 +9394,9 @@ function createSentryBuildPluginManager(userOptions, bundlerPluginMetaContext) {
9348
9394
  dist: options.release.dist
9349
9395
  }],
9350
9396
  ignore: ignorePaths,
9397
+ // @ts-expect-error - projects is not a valid option for uploadSourceMaps but is implemented in the CLI
9398
+ // Remove once https://github.com/getsentry/sentry-cli/pull/2856 is released
9399
+ projects: getProjects(options.project),
9351
9400
  live: "rejectOnError"
9352
9401
  });
9353
9402
  case 3:
@@ -9537,6 +9586,9 @@ function createSentryBuildPluginManager(userOptions, bundlerPluginMetaContext) {
9537
9586
  rewrite: false,
9538
9587
  dist: options.release.dist
9539
9588
  }],
9589
+ // @ts-expect-error - projects is not a valid option for uploadSourceMaps but is implemented in the CLI
9590
+ // Remove once https://github.com/getsentry/sentry-cli/pull/2856 is released
9591
+ projects: getProjects(options.project),
9540
9592
  live: "rejectOnError"
9541
9593
  });
9542
9594
  case 3:
@@ -9568,6 +9620,7 @@ function createSentryBuildPluginManager(userOptions, bundlerPluginMetaContext) {
9568
9620
  case 34:
9569
9621
  _context18.prev = 34;
9570
9622
  if (folderToCleanUp && !((_process$env2 = process.env) !== null && _process$env2 !== void 0 && _process$env2["SENTRY_TEST_OVERRIDE_TEMP_DIR"])) {
9623
+ logger.debug("Cleaning up temporary files...");
9571
9624
  void startSpan({
9572
9625
  name: "cleanup",
9573
9626
  scope: sentryScope
@@ -9576,7 +9629,7 @@ function createSentryBuildPluginManager(userOptions, bundlerPluginMetaContext) {
9576
9629
  while (1) switch (_context17.prev = _context17.next) {
9577
9630
  case 0:
9578
9631
  if (!folderToCleanUp) {
9579
- _context17.next = 3;
9632
+ _context17.next = 4;
9580
9633
  break;
9581
9634
  }
9582
9635
  _context17.next = 3;
@@ -9585,22 +9638,27 @@ function createSentryBuildPluginManager(userOptions, bundlerPluginMetaContext) {
9585
9638
  force: true
9586
9639
  });
9587
9640
  case 3:
9641
+ logger.debug("Temporary folder deleted: ".concat(folderToCleanUp));
9642
+ case 4:
9588
9643
  case "end":
9589
9644
  return _context17.stop();
9590
9645
  }
9591
9646
  }, _callee17);
9592
9647
  })));
9593
9648
  }
9649
+ logger.debug("Freeing upload dependencies...");
9594
9650
  freeUploadDependencyOnBuildArtifacts();
9595
- _context18.next = 39;
9651
+ logger.debug("Flushing telemetry data...");
9652
+ _context18.next = 41;
9596
9653
  return safeFlushTelemetry(sentryClient);
9597
- case 39:
9654
+ case 41:
9655
+ logger.debug("Telemetry flushed. Plugin upload process complete.");
9598
9656
  return _context18.finish(34);
9599
- case 40:
9657
+ case 43:
9600
9658
  case "end":
9601
9659
  return _context18.stop();
9602
9660
  }
9603
- }, _callee18, null, [[2, 30, 34, 40]]);
9661
+ }, _callee18, null, [[2, 30, 34, 43]]);
9604
9662
  })));
9605
9663
  case 8:
9606
9664
  case "end":
@@ -9674,7 +9732,7 @@ function createSentryBuildPluginManager(userOptions, bundlerPluginMetaContext) {
9674
9732
  };
9675
9733
  }
9676
9734
  function canUploadSourceMaps(options, logger, isDevMode) {
9677
- var _options$sourcemaps10;
9735
+ var _options$sourcemaps10, _getProjects3;
9678
9736
  if ((_options$sourcemaps10 = options.sourcemaps) !== null && _options$sourcemaps10 !== void 0 && _options$sourcemaps10.disable) {
9679
9737
  logger.debug("Source map upload was disabled. Will not upload sourcemaps using debug ID process.");
9680
9738
  return false;
@@ -9691,7 +9749,7 @@ function canUploadSourceMaps(options, logger, isDevMode) {
9691
9749
  logger.warn("No org provided. Will not upload source maps. Please set the `org` option to your Sentry organization slug." + getTurborepoEnvPassthroughWarning("SENTRY_ORG"));
9692
9750
  return false;
9693
9751
  }
9694
- if (!options.project) {
9752
+ if (!((_getProjects3 = getProjects(options.project)) !== null && _getProjects3 !== void 0 && _getProjects3[0])) {
9695
9753
  logger.warn("No project provided. Will not upload source maps. Please set the `project` option to your Sentry project slug." + getTurborepoEnvPassthroughWarning("SENTRY_PROJECT"));
9696
9754
  return false;
9697
9755
  }