UNPKG

@botonic/plugin-contentful

Version:

## What Does This Plugin Do?

56 lines 1.99 kB
import { PerformanceMeasurer } from './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; } } } export class NodePerformanceMeasurer extends 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]; } } //# sourceMappingURL=node-performance-measurer.js.map