|
1 | 1 | /* eslint-disable @typescript-eslint/no-explicit-any */ |
2 | 2 | import { Event, Integration, StackFrame, WrappedFunction } from '@sentry/types'; |
3 | 3 |
|
4 | | -import { dynamicRequire, isNodeEnv } from './node'; |
| 4 | +import { isNodeEnv } from './node'; |
5 | 5 | import { snipLine } from './string'; |
6 | 6 |
|
7 | 7 | /** Internal */ |
@@ -38,13 +38,6 @@ export function getGlobalObject<T>(): T & SentryGlobal { |
38 | 38 | : fallbackGlobalObject) as T & SentryGlobal; |
39 | 39 | } |
40 | 40 |
|
41 | | -/** |
42 | | - * Determines if running in react native |
43 | | - */ |
44 | | -export function isReactNative(): boolean { |
45 | | - return getGlobalObject<Window>().navigator?.product === 'ReactNative'; |
46 | | -} |
47 | | - |
48 | 41 | /** |
49 | 42 | * Extended Window interface that allows for Crypto API usage in IE browsers |
50 | 43 | */ |
@@ -241,94 +234,6 @@ export function getLocationHref(): string { |
241 | 234 | } |
242 | 235 | } |
243 | 236 |
|
244 | | -const INITIAL_TIME = Date.now(); |
245 | | -let prevNow = 0; |
246 | | - |
247 | | -/** |
248 | | - * Cross platform compatible partial performance implementation |
249 | | - */ |
250 | | -interface CrossPlatformPerformance { |
251 | | - timeOrigin: number; |
252 | | - /** |
253 | | - * Returns the current timestamp in ms |
254 | | - */ |
255 | | - now(): number; |
256 | | -} |
257 | | - |
258 | | -const performanceFallback: CrossPlatformPerformance = { |
259 | | - now(): number { |
260 | | - let now = Date.now() - INITIAL_TIME; |
261 | | - if (now < prevNow) { |
262 | | - now = prevNow; |
263 | | - } |
264 | | - prevNow = now; |
265 | | - return now; |
266 | | - }, |
267 | | - timeOrigin: INITIAL_TIME, |
268 | | -}; |
269 | | - |
270 | | -/** |
271 | | - * Performance wrapper for react native as performance.now() has been found to start off with an unusual offset. |
272 | | - */ |
273 | | -function getReactNativePerformanceWrapper(): CrossPlatformPerformance { |
274 | | - // Performance only available >= RN 0.63 |
275 | | - const { performance } = getGlobalObject<Window>(); |
276 | | - if (performance && typeof performance.now === 'function') { |
277 | | - const INITIAL_OFFSET = performance.now(); |
278 | | - |
279 | | - return { |
280 | | - now(): number { |
281 | | - return performance.now() - INITIAL_OFFSET; |
282 | | - }, |
283 | | - timeOrigin: INITIAL_TIME, |
284 | | - }; |
285 | | - } |
286 | | - return performanceFallback; |
287 | | -} |
288 | | - |
289 | | -export const crossPlatformPerformance: CrossPlatformPerformance = ((): CrossPlatformPerformance => { |
290 | | - // React Native's performance.now() starts with a gigantic offset, so we need to wrap it. |
291 | | - if (isReactNative()) { |
292 | | - return getReactNativePerformanceWrapper(); |
293 | | - } |
294 | | - |
295 | | - if (isNodeEnv()) { |
296 | | - try { |
297 | | - const perfHooks = dynamicRequire(module, 'perf_hooks') as { performance: CrossPlatformPerformance }; |
298 | | - return perfHooks.performance; |
299 | | - } catch (_) { |
300 | | - return performanceFallback; |
301 | | - } |
302 | | - } |
303 | | - |
304 | | - const { performance } = getGlobalObject<Window>(); |
305 | | - |
306 | | - if (!performance || !performance.now) { |
307 | | - return performanceFallback; |
308 | | - } |
309 | | - |
310 | | - // Polyfill for performance.timeOrigin. |
311 | | - // |
312 | | - // While performance.timing.navigationStart is deprecated in favor of performance.timeOrigin, performance.timeOrigin |
313 | | - // is not as widely supported. Namely, performance.timeOrigin is undefined in Safari as of writing. |
314 | | - if (performance.timeOrigin === undefined) { |
315 | | - // As of writing, performance.timing is not available in Web Workers in mainstream browsers, so it is not always a |
316 | | - // valid fallback. In the absence of a initial time provided by the browser, fallback to INITIAL_TIME. |
317 | | - // @ts-ignore ignored because timeOrigin is a readonly property but we want to override |
318 | | - // eslint-disable-next-line deprecation/deprecation |
319 | | - performance.timeOrigin = (performance.timing && performance.timing.navigationStart) || INITIAL_TIME; |
320 | | - } |
321 | | - |
322 | | - return performance; |
323 | | -})(); |
324 | | - |
325 | | -/** |
326 | | - * Returns a timestamp in seconds with milliseconds precision since the UNIX epoch calculated with the monotonic clock. |
327 | | - */ |
328 | | -export function timestampWithMs(): number { |
329 | | - return (crossPlatformPerformance.timeOrigin + crossPlatformPerformance.now()) / 1000; |
330 | | -} |
331 | | - |
332 | 237 | // https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string |
333 | 238 | const SEMVER_REGEXP = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/; |
334 | 239 |
|
|
0 commit comments