UNPKG

@botonic/plugin-contentful

Version:

## What Does This Plugin Do?

60 lines 2.19 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.NodePerformanceMeasurer = void 0; const performance_measurer_1 = require("./performance-measurer"); class PerformanceFactory { static getPerformance() { try { return performance; } catch (_a) { //TODO: investigate why a normal require breaks the bot when compiling with webpack //To solve the issue we're executing eval('require') instead of using a direct require (https://stackoverflow.com/a/67288823/3982733) return eval('require')('perf_hooks').performance; } } static getObserver() { try { return PerformanceObserver; } catch (_a) { //TODO: investigate why a normal require breaks the bot when compiling with webpack //To solve the issue we're executing eval('require') instead of using a direct require (https://stackoverflow.com/a/67288823/3982733) return eval('require')('perf_hooks').PerformanceObserver; } } } class NodePerformanceMeasurer extends performance_measurer_1.PerformanceMeasurer { constructor() { super(PerformanceFactory.getPerformance()); } enable() { if (this.enabled) { return; } super.enable(); const ObsClass = PerformanceFactory.getObserver(); this.performanceObserver = new ObsClass(list => { list.getEntries().forEach(measure => { if (!this.allProfiled[measure.name]) { this.allProfiled[measure.name] = [measure]; } else { this.allProfiled[measure.name].push(measure); } }); }); this.performanceObserver.observe({ entryTypes: ['measure'] }); } disable() { super.disable(); if (this.performanceObserver) { this.performanceObserver.disconnect(); } } getEntriesByName(name) { return this.allProfiled[name]; } } exports.NodePerformanceMeasurer = NodePerformanceMeasurer; //# sourceMappingURL=node-performance-measurer.js.map