@honeybadger-io/js 6.4.2 → 6.4.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.
@@ -864,14 +864,14 @@ var NOT_BLANK = /\S/;
864
864
  var Client = /** @class */ (function () {
865
865
  function Client(opts, transport) {
866
866
  if (opts === void 0) { opts = {}; }
867
- this.__pluginsExecuted = false;
867
+ this.__pluginsLoaded = false;
868
868
  this.__store = null;
869
869
  this.__beforeNotifyHandlers = [];
870
870
  this.__afterNotifyHandlers = [];
871
871
  this.__notifier = {
872
872
  name: '@honeybadger-io/core',
873
873
  url: 'https://github.com/honeybadger-io/honeybadger-js/tree/master/packages/core',
874
- version: '6.4.2'
874
+ version: '6.4.3'
875
875
  };
876
876
  this.config = __assign({ apiKey: null, endpoint: 'https://api.honeybadger.io', environment: null, hostname: null, projectRoot: null, component: null, action: null, revision: null, reportData: null, breadcrumbsEnabled: true, maxBreadcrumbs: 40, maxObjectDepth: 8, logger: console, developmentEnvironments: ['dev', 'development', 'test'], debug: false, tags: null, enableUncaught: true, enableUnhandledRejection: true, afterUncaught: function () { return true; }, filters: ['creditcard', 'password'], __plugins: [] }, opts);
877
877
  this.__initStore();
@@ -895,17 +895,21 @@ var Client = /** @class */ (function () {
895
895
  this.__notifier = notifier;
896
896
  };
897
897
  Client.prototype.configure = function (opts) {
898
- var _this = this;
899
898
  if (opts === void 0) { opts = {}; }
900
899
  for (var k in opts) {
901
900
  this.config[k] = opts[k];
902
901
  }
903
- if (!this.__pluginsExecuted) {
904
- this.__pluginsExecuted = true;
905
- this.config.__plugins.forEach(function (plugin) { return plugin.load(_this); });
906
- }
902
+ this.loadPlugins();
907
903
  return this;
908
904
  };
905
+ Client.prototype.loadPlugins = function () {
906
+ var _this = this;
907
+ var pluginsToLoad = this.__pluginsLoaded
908
+ ? this.config.__plugins.filter(function (plugin) { return plugin.shouldReloadOnConfigure; })
909
+ : this.config.__plugins;
910
+ pluginsToLoad.forEach(function (plugin) { return plugin.load(_this); });
911
+ this.__pluginsLoaded = true;
912
+ };
909
913
  Client.prototype.__initStore = function () {
910
914
  this.__store = new store_1.GlobalStore({ context: {}, breadcrumbs: [] }, this.config.maxBreadcrumbs);
911
915
  };
@@ -1615,10 +1619,46 @@ var unhandled_rejection_monitor = {};
1615
1619
  Object.defineProperty(unhandled_rejection_monitor, "__esModule", { value: true });
1616
1620
  var util_1$1 = util;
1617
1621
  var UnhandledRejectionMonitor = /** @class */ (function () {
1618
- function UnhandledRejectionMonitor(client) {
1622
+ function UnhandledRejectionMonitor() {
1619
1623
  this.__isReporting = false;
1620
- this.__client = client;
1624
+ this.__listener = this.makeListener();
1621
1625
  }
1626
+ UnhandledRejectionMonitor.prototype.setClient = function (client) {
1627
+ this.__client = client;
1628
+ };
1629
+ UnhandledRejectionMonitor.prototype.makeListener = function () {
1630
+ var _this = this;
1631
+ var honeybadgerUnhandledRejectionListener = function (reason, _promise) {
1632
+ if (!_this.__client || !_this.__client.config.enableUnhandledRejection) {
1633
+ if (!_this.hasOtherUnhandledRejectionListeners() && !_this.__isReporting) {
1634
+ (0, util_1$1.fatallyLogAndExit)(reason);
1635
+ }
1636
+ return;
1637
+ }
1638
+ _this.__isReporting = true;
1639
+ _this.__client.notify(reason, { component: 'unhandledRejection' }, {
1640
+ afterNotify: function () {
1641
+ _this.__isReporting = false;
1642
+ if (!_this.hasOtherUnhandledRejectionListeners()) {
1643
+ (0, util_1$1.fatallyLogAndExit)(reason);
1644
+ }
1645
+ }
1646
+ });
1647
+ };
1648
+ return honeybadgerUnhandledRejectionListener;
1649
+ };
1650
+ UnhandledRejectionMonitor.prototype.maybeAddListener = function () {
1651
+ var listeners = process.listeners('unhandledRejection');
1652
+ if (!listeners.includes(this.__listener)) {
1653
+ process.on('unhandledRejection', this.__listener);
1654
+ }
1655
+ };
1656
+ UnhandledRejectionMonitor.prototype.maybeRemoveListener = function () {
1657
+ var listeners = process.listeners('unhandledRejection');
1658
+ if (listeners.includes(this.__listener)) {
1659
+ process.removeListener('unhandledRejection', this.__listener);
1660
+ }
1661
+ };
1622
1662
  /**
1623
1663
  * If there are no other unhandledRejection listeners,
1624
1664
  * we want to report the exception to Honeybadger and
@@ -1626,25 +1666,10 @@ var UnhandledRejectionMonitor = /** @class */ (function () {
1626
1666
  * which is to exit the process with code 1
1627
1667
  */
1628
1668
  UnhandledRejectionMonitor.prototype.hasOtherUnhandledRejectionListeners = function () {
1629
- return process.listeners('unhandledRejection').length > 1;
1630
- };
1631
- UnhandledRejectionMonitor.prototype.handleUnhandledRejection = function (reason, _promise) {
1632
1669
  var _this = this;
1633
- if (!this.__client.config.enableUnhandledRejection) {
1634
- if (!this.hasOtherUnhandledRejectionListeners() && !this.__isReporting) {
1635
- (0, util_1$1.fatallyLogAndExit)(reason);
1636
- }
1637
- return;
1638
- }
1639
- this.__isReporting = true;
1640
- this.__client.notify(reason, { component: 'unhandledRejection' }, {
1641
- afterNotify: function () {
1642
- _this.__isReporting = false;
1643
- if (!_this.hasOtherUnhandledRejectionListeners()) {
1644
- (0, util_1$1.fatallyLogAndExit)(reason);
1645
- }
1646
- }
1647
- });
1670
+ var otherListeners = process.listeners('unhandledRejection')
1671
+ .filter(function (listener) { return listener !== _this.__listener; });
1672
+ return otherListeners.length > 0;
1648
1673
  };
1649
1674
  return UnhandledRejectionMonitor;
1650
1675
  }());
@@ -1655,16 +1680,17 @@ var __importDefault$2 = (commonjsGlobal && commonjsGlobal.__importDefault) || fu
1655
1680
  };
1656
1681
  Object.defineProperty(unhandled_rejection_plugin, "__esModule", { value: true });
1657
1682
  var unhandled_rejection_monitor_1 = __importDefault$2(unhandled_rejection_monitor);
1683
+ var unhandledRejectionMonitor = new unhandled_rejection_monitor_1.default();
1658
1684
  function default_1() {
1659
1685
  return {
1660
1686
  load: function (client) {
1661
- if (!client.config.enableUnhandledRejection) {
1662
- return;
1687
+ unhandledRejectionMonitor.setClient(client);
1688
+ if (client.config.enableUnhandledRejection) {
1689
+ unhandledRejectionMonitor.maybeAddListener();
1690
+ }
1691
+ else {
1692
+ unhandledRejectionMonitor.maybeRemoveListener();
1663
1693
  }
1664
- var unhandledRejectionMonitor = new unhandled_rejection_monitor_1.default(client);
1665
- process.on('unhandledRejection', function honeybadgerUnhandledRejectionListener(reason, _promise) {
1666
- unhandledRejectionMonitor.handleUnhandledRejection(reason, _promise);
1667
- });
1668
1694
  }
1669
1695
  };
1670
1696
  }
@@ -2054,7 +2080,7 @@ stacked_store.StackedStore = StackedStore;
2054
2080
  var NOTIFIER = {
2055
2081
  name: '@honeybadger-io/js',
2056
2082
  url: 'https://github.com/honeybadger-io/honeybadger-js/tree/master/packages/js',
2057
- version: '6.4.2'
2083
+ version: '6.4.3'
2058
2084
  };
2059
2085
  singleton.setNotifier(NOTIFIER);
2060
2086
  var core_2 = src;