From e250856f1228264141ece9595185eb125d601056 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Wed, 1 Mar 2023 19:06:07 -0800 Subject: [PATCH] Remove perf_hooks patch needed for old versions of Node --- src/compiler/performanceCore.ts | 34 ++------------------------------- 1 file changed, 2 insertions(+), 32 deletions(-) diff --git a/src/compiler/performanceCore.ts b/src/compiler/performanceCore.ts index 9e20bddb69480..3f8a459bb0d75 100644 --- a/src/compiler/performanceCore.ts +++ b/src/compiler/performanceCore.ts @@ -1,7 +1,5 @@ import { isNodeLikeSystem, - Version, - VersionRange, } from "./_namespaces/ts"; // 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 export type PerformanceEntryList = PerformanceEntry[]; // Browser globals for the Web Performance User Timings API -declare const process: any; declare const performance: Performance | undefined; declare const PerformanceObserver: PerformanceObserverConstructor | undefined; @@ -86,35 +83,8 @@ function tryGetWebPerformanceHooks(): PerformanceHooks | undefined { function tryGetNodePerformanceHooks(): PerformanceHooks | undefined { if (isNodeLikeSystem()) { try { - let performance: Performance; - const { performance: nodePerformance, PerformanceObserver } = require("perf_hooks") as typeof import("perf_hooks"); - if (hasRequiredAPI(nodePerformance as unknown as Performance, PerformanceObserver)) { - performance = nodePerformance as unknown as Performance; - // There is a bug in Node's performance.measure prior to 12.16.3/13.13.0 that does not - // match the Web Performance API specification. Node's implementation did not allow - // optional `start` and `end` arguments for `performance.measure`. - // See https://github.com/nodejs/node/pull/32651 for more information. - const version = new Version(process.versions.node); - const range = new VersionRange("<12.16.3 || 13 <13.13"); - if (range.test(version)) { - performance = { - get timeOrigin() { return nodePerformance.timeOrigin; }, - now() { return nodePerformance.now(); }, - mark(name) { return nodePerformance.mark(name); }, - measure(name, start = "nodeStart", end?) { - if (end === undefined) { - end = "__performance.measure-fix__"; - nodePerformance.mark(end); - } - nodePerformance.measure(name, start, end); - if (end === "__performance.measure-fix__") { - nodePerformance.clearMarks("__performance.measure-fix__"); - } - }, - clearMarks(name) { return nodePerformance.clearMarks(name); }, - clearMeasures(name) { return (nodePerformance as unknown as Performance).clearMeasures(name); }, - }; - } + const { performance, PerformanceObserver } = require("perf_hooks") as typeof import("perf_hooks"); + if (hasRequiredAPI(performance, PerformanceObserver)) { return { // By default, only write native events when generating a cpu profile or using the v8 profiler. shouldWriteNativeEvents: false,