|
1 | 1 | import {
|
2 | 2 | isNodeLikeSystem,
|
3 |
| - Version, |
4 |
| - VersionRange, |
5 | 3 | } from "./_namespaces/ts";
|
6 | 4 |
|
7 | 5 | // The following definitions provide the minimum compatible support for the Web Performance User Timings API
|
@@ -52,7 +50,6 @@ export type PerformanceObserverConstructor = new (callback: (list: PerformanceOb
|
52 | 50 | export type PerformanceEntryList = PerformanceEntry[];
|
53 | 51 |
|
54 | 52 | // Browser globals for the Web Performance User Timings API
|
55 |
| -declare const process: any; |
56 | 53 | declare const performance: Performance | undefined;
|
57 | 54 | declare const PerformanceObserver: PerformanceObserverConstructor | undefined;
|
58 | 55 |
|
@@ -86,35 +83,8 @@ function tryGetWebPerformanceHooks(): PerformanceHooks | undefined {
|
86 | 83 | function tryGetNodePerformanceHooks(): PerformanceHooks | undefined {
|
87 | 84 | if (isNodeLikeSystem()) {
|
88 | 85 | try {
|
89 |
| - let performance: Performance; |
90 |
| - const { performance: nodePerformance, PerformanceObserver } = require("perf_hooks") as typeof import("perf_hooks"); |
91 |
| - if (hasRequiredAPI(nodePerformance as unknown as Performance, PerformanceObserver)) { |
92 |
| - performance = nodePerformance as unknown as Performance; |
93 |
| - // There is a bug in Node's performance.measure prior to 12.16.3/13.13.0 that does not |
94 |
| - // match the Web Performance API specification. Node's implementation did not allow |
95 |
| - // optional `start` and `end` arguments for `performance.measure`. |
96 |
| - // See https://github.com/nodejs/node/pull/32651 for more information. |
97 |
| - const version = new Version(process.versions.node); |
98 |
| - const range = new VersionRange("<12.16.3 || 13 <13.13"); |
99 |
| - if (range.test(version)) { |
100 |
| - performance = { |
101 |
| - get timeOrigin() { return nodePerformance.timeOrigin; }, |
102 |
| - now() { return nodePerformance.now(); }, |
103 |
| - mark(name) { return nodePerformance.mark(name); }, |
104 |
| - measure(name, start = "nodeStart", end?) { |
105 |
| - if (end === undefined) { |
106 |
| - end = "__performance.measure-fix__"; |
107 |
| - nodePerformance.mark(end); |
108 |
| - } |
109 |
| - nodePerformance.measure(name, start, end); |
110 |
| - if (end === "__performance.measure-fix__") { |
111 |
| - nodePerformance.clearMarks("__performance.measure-fix__"); |
112 |
| - } |
113 |
| - }, |
114 |
| - clearMarks(name) { return nodePerformance.clearMarks(name); }, |
115 |
| - clearMeasures(name) { return (nodePerformance as unknown as Performance).clearMeasures(name); }, |
116 |
| - }; |
117 |
| - } |
| 86 | + const { performance, PerformanceObserver } = require("perf_hooks") as typeof import("perf_hooks"); |
| 87 | + if (hasRequiredAPI(performance, PerformanceObserver)) { |
118 | 88 | return {
|
119 | 89 | // By default, only write native events when generating a cpu profile or using the v8 profiler.
|
120 | 90 | shouldWriteNativeEvents: false,
|
|
0 commit comments