From 7ff515254764b3372ac4ebe5a200246fc609f146 Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Fri, 3 Nov 2023 13:12:44 +0000 Subject: [PATCH] build: configure tslint to ban `performance.mark` usages (#52505) While `performance.mark` is available on all supported browsers and node.js version this API is not available in JSDOM which is used by Jest and Cloudflare worker. PR Close #52505 --- devtools/projects/ng-devtools-backend/src/lib/hooks/index.ts | 2 ++ packages/core/src/util/performance.ts | 2 +- tslint.json | 3 ++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/devtools/projects/ng-devtools-backend/src/lib/hooks/index.ts b/devtools/projects/ng-devtools-backend/src/lib/hooks/index.ts index c1506811799fa..629ee40b12fac 100644 --- a/devtools/projects/ng-devtools-backend/src/lib/hooks/index.ts +++ b/devtools/projects/ng-devtools-backend/src/lib/hooks/index.ts @@ -21,6 +21,7 @@ type Method = keyof LifecycleProfile|'changeDetection'|string; const recordMark = (s: string, method: Method) => { if (supportsPerformance) { + // tslint:disable-next-line:ban performance.mark(`${markName(s, method)}_start`); } }; @@ -31,6 +32,7 @@ const endMark = (nodeName: string, method: Method) => { const start = `${name}_start`; const end = `${name}_end`; if (performance.getEntriesByName(start).length > 0) { + // tslint:disable-next-line:ban performance.mark(end); performance.measure(name, start, end); } diff --git a/packages/core/src/util/performance.ts b/packages/core/src/util/performance.ts index 78bb7d65c4393..4c3dcf2c53389 100644 --- a/packages/core/src/util/performance.ts +++ b/packages/core/src/util/performance.ts @@ -6,7 +6,7 @@ * found in the LICENSE file at https://angular.io/license */ -// tslint:disable:no-performance +// tslint:disable:ban /** * A guarded `performance.mark`. * diff --git a/tslint.json b/tslint.json index a0f6be8a7f34a..494e9e8178845 100644 --- a/tslint.json +++ b/tslint.json @@ -76,7 +76,8 @@ { "name": ["*", "getMutableClone"], "message": "Use a ts.factory.update* or ts.factory.create* method instead." - } + }, + {"name": ["performance", "mark"], "message": "`performance` methods aren't not fully supported in all environments like JSDOM and Cloudflare workers. Use 'performanceMark' from '@angular/core' instead."} ] }, "jsRules": {