@sentry/bundler-plugin-core 2.3.0 → 2.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
@@ -15,6 +15,7 @@ var glob = require('glob');
15
15
  var util = require('util');
16
16
  var utils = require('@sentry/utils');
17
17
  var node = require('@sentry/node');
18
+ var dotenv = require('dotenv');
18
19
 
19
20
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
20
21
 
@@ -47,6 +48,7 @@ var os__default = /*#__PURE__*/_interopDefaultLegacy(os);
47
48
  var crypto__default = /*#__PURE__*/_interopDefaultLegacy(crypto);
48
49
  var childProcess__default = /*#__PURE__*/_interopDefaultLegacy(childProcess);
49
50
  var util__namespace = /*#__PURE__*/_interopNamespace(util);
51
+ var dotenv__namespace = /*#__PURE__*/_interopNamespace(dotenv);
50
52
 
51
53
  function ownKeys(object, enumerableOnly) {
52
54
  var keys = Object.keys(object);
@@ -579,7 +581,7 @@ function stringToUUID(str) {
579
581
  function determineReleaseName() {
580
582
  var gitRevision;
581
583
  try {
582
- gitRevision = childProcess__default["default"].execSync("git rev-parse --short HEAD").toString().trim();
584
+ gitRevision = childProcess__default["default"].execSync("git rev-parse HEAD").toString().trim();
583
585
  } catch (e) {
584
586
  // noop
585
587
  }
@@ -617,6 +619,13 @@ function generateGlobalInjectorCode(_ref2) {
617
619
  }
618
620
  return code;
619
621
  }
622
+
623
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
624
+ function generateModuleMetadataInjectorCode(metadata) {
625
+ // The code below is mostly ternary operators because it saves bundle size.
626
+ // The checks are to support as many environments as possible. (Node.js, Browser, webworkers, etc.)
627
+ return "\n var _global2 =\n typeof window !== 'undefined' ?\n window :\n typeof global !== 'undefined' ?\n global :\n typeof self !== 'undefined' ?\n self :\n {};\n\n _global2._sentryModuleMetadata = _global2._sentryModuleMetadata || {};\n _global2._sentryModuleMetadata[new Error().stack] = ".concat(JSON.stringify(metadata), ";");
628
+ }
620
629
  function getBuildInformation$1() {
621
630
  var packageJson = getPackageJson();
622
631
  var _ref3 = packageJson ? getDependencies(packageJson) : {
@@ -1291,7 +1300,7 @@ function createSentryInstance(options, shouldSendTelemetry, bundler) {
1291
1300
  dsn: "https://4c2bae7d9fbc413e8f7385f55c515d51@o1.ingest.sentry.io/6690737",
1292
1301
  tracesSampleRate: 1,
1293
1302
  sampleRate: 1,
1294
- release: "2.3.0",
1303
+ release: "2.5.0",
1295
1304
  integrations: [],
1296
1305
  tracePropagationTargets: ["sentry.io/api"],
1297
1306
  stackParser: node.defaultStackParser,
@@ -1477,9 +1486,28 @@ function _allowedToSendTelemetry() {
1477
1486
  */
1478
1487
  function sentryUnpluginFactory(_ref) {
1479
1488
  var releaseInjectionPlugin = _ref.releaseInjectionPlugin,
1489
+ moduleMetadataInjectionPlugin = _ref.moduleMetadataInjectionPlugin,
1480
1490
  debugIdInjectionPlugin = _ref.debugIdInjectionPlugin,
1481
1491
  debugIdUploadPlugin = _ref.debugIdUploadPlugin;
1482
1492
  return unplugin.createUnplugin(function (userOptions, unpluginMetaContext) {
1493
+ var _userOptions$silent, _userOptions$debug;
1494
+ var logger = createLogger({
1495
+ prefix: "[sentry-".concat(unpluginMetaContext.framework, "-plugin]"),
1496
+ silent: (_userOptions$silent = userOptions.silent) !== null && _userOptions$silent !== void 0 ? _userOptions$silent : false,
1497
+ debug: (_userOptions$debug = userOptions.debug) !== null && _userOptions$debug !== void 0 ? _userOptions$debug : false
1498
+ });
1499
+ var dotenvResult = dotenv__namespace.config({
1500
+ path: path__namespace.join(process.cwd(), ".env.sentry-build-plugin")
1501
+ });
1502
+
1503
+ // Ignore "file not found" errors but throw all others
1504
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1505
+ // @ts-ignore Accessing `code` on error should be safe
1506
+ if (dotenvResult.error && dotenvResult.error.code !== "ENOENT") {
1507
+ throw dotenvResult.error;
1508
+ } else if (dotenvResult.parsed) {
1509
+ logger.info('Using environment variables configured in ".env.sentry-build-plugin".');
1510
+ }
1483
1511
  var options = normalizeUserOptions(userOptions);
1484
1512
  if (unpluginMetaContext.watchMode || options.disable) {
1485
1513
  return [{
@@ -1500,14 +1528,9 @@ function sentryUnpluginFactory(_ref) {
1500
1528
  sentEndSession = true;
1501
1529
  }
1502
1530
  });
1503
- var logger = createLogger({
1504
- prefix: "[sentry-".concat(unpluginMetaContext.framework, "-plugin]"),
1505
- silent: options.silent,
1506
- debug: options.debug
1507
- });
1508
1531
 
1509
1532
  // Set the User-Agent that Sentry CLI will use when interacting with Sentry
1510
- process.env["SENTRY_PIPELINE"] = "".concat(unpluginMetaContext.framework, "-plugin/", "2.3.0");
1533
+ process.env["SENTRY_PIPELINE"] = "".concat(unpluginMetaContext.framework, "-plugin/", "2.5.0");
1511
1534
  function handleRecoverableError(unknownError) {
1512
1535
  sentrySession.status = "abnormal";
1513
1536
  try {
@@ -1546,7 +1569,7 @@ function sentryUnpluginFactory(_ref) {
1546
1569
  if (!options.release.inject) {
1547
1570
  logger.debug("Release injection disabled via `release.inject` option. Will not inject release.");
1548
1571
  } else if (!options.release.name) {
1549
- logger.warn("No release name provided. Will not inject release. Please set the `release.name` option to identifiy your release.");
1572
+ logger.warn("No release name provided. Will not inject release. Please set the `release.name` option to identify your release.");
1550
1573
  } else {
1551
1574
  var _injectionCode = generateGlobalInjectorCode({
1552
1575
  release: options.release.name,
@@ -1554,8 +1577,27 @@ function sentryUnpluginFactory(_ref) {
1554
1577
  });
1555
1578
  plugins.push(releaseInjectionPlugin(_injectionCode));
1556
1579
  }
1580
+ if (moduleMetadataInjectionPlugin && options._experiments.moduleMetadata) {
1581
+ var metadata;
1582
+ if (typeof options._experiments.moduleMetadata === "function") {
1583
+ var args = {
1584
+ org: options.org,
1585
+ project: options.project,
1586
+ release: options.release.name
1587
+ };
1588
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
1589
+ metadata = options._experiments.moduleMetadata(args);
1590
+ } else {
1591
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
1592
+ metadata = options._experiments.moduleMetadata;
1593
+ }
1594
+ var _injectionCode2 = generateModuleMetadataInjectorCode(metadata);
1595
+ plugins.push(moduleMetadataInjectionPlugin(_injectionCode2));
1596
+ } else if (options._experiments.moduleMetadata) {
1597
+ logger.warn("'moduleMetadata' is currently only supported by '@sentry/webpack-plugin'");
1598
+ }
1557
1599
  if (!options.release.name) {
1558
- logger.warn("No release name provided. Will not create release. Please set the `release.name` option to identifiy your release.");
1600
+ logger.warn("No release name provided. Will not create release. Please set the `release.name` option to identify your release.");
1559
1601
  } else if (!options.authToken) {
1560
1602
  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/");
1561
1603
  } else if (!options.org) {