Skip to content

Commit 40cd0de

Browse files
authored
Remove perf_hooks patch needed for old versions of Node (#53058)
1 parent 6b71882 commit 40cd0de

File tree

1 file changed

+2
-32
lines changed

1 file changed

+2
-32
lines changed

src/compiler/performanceCore.ts

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import {
22
isNodeLikeSystem,
3-
Version,
4-
VersionRange,
53
} from "./_namespaces/ts";
64

75
// 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
5250
export type PerformanceEntryList = PerformanceEntry[];
5351

5452
// Browser globals for the Web Performance User Timings API
55-
declare const process: any;
5653
declare const performance: Performance | undefined;
5754
declare const PerformanceObserver: PerformanceObserverConstructor | undefined;
5855

@@ -86,35 +83,8 @@ function tryGetWebPerformanceHooks(): PerformanceHooks | undefined {
8683
function tryGetNodePerformanceHooks(): PerformanceHooks | undefined {
8784
if (isNodeLikeSystem()) {
8885
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)) {
11888
return {
11989
// By default, only write native events when generating a cpu profile or using the v8 profiler.
12090
shouldWriteNativeEvents: false,

0 commit comments

Comments
 (0)