From 0596b6fbffe50b71a7074f7c67a56bff6c208842 Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Mon, 17 Oct 2022 13:48:19 +0200 Subject: [PATCH] fix(utils): Rename `global.ts` -> `worldwide.ts` (#5969) Renames `global.ts` to `worldwide.ts` so we don't have issues with bundlers like as is described in https://docs.sentry.io/platforms/javascript/troubleshooting/#build-errors-with-vite. Luckily the rest of our references to global is removed since we did changes with the WinterCG work. It's not quite our responsibility to handle this, since Vite themselves recommends not use variables like global with the define setting, but we can unblock folks from not having build errors with our SDK, so I'm fine with this change. --- packages/utils/src/browser.ts | 2 +- packages/utils/src/index.ts | 2 +- packages/utils/src/logger.ts | 2 +- packages/utils/src/misc.ts | 2 +- packages/utils/src/{global.ts => worldwide.ts} | 7 +++++++ packages/utils/test/{global.test.ts => worldwide.test.ts} | 2 +- 6 files changed, 12 insertions(+), 5 deletions(-) rename packages/utils/src/{global.ts => worldwide.ts} (93%) rename packages/utils/test/{global.test.ts => worldwide.test.ts} (85%) diff --git a/packages/utils/src/browser.ts b/packages/utils/src/browser.ts index 30cd546c6ad8..25ccc443a03c 100644 --- a/packages/utils/src/browser.ts +++ b/packages/utils/src/browser.ts @@ -1,5 +1,5 @@ -import { GLOBAL_OBJ } from './global'; import { isString } from './is'; +import { GLOBAL_OBJ } from './worldwide'; /** * TODO: Move me to @sentry/browser when @sentry/utils no longer contains any browser code diff --git a/packages/utils/src/index.ts b/packages/utils/src/index.ts index b55e3b0303be..260360522685 100644 --- a/packages/utils/src/index.ts +++ b/packages/utils/src/index.ts @@ -1,7 +1,7 @@ export * from './browser'; export * from './dsn'; export * from './error'; -export * from './global'; +export * from './worldwide'; export * from './instrument'; export * from './is'; export * from './logger'; diff --git a/packages/utils/src/logger.ts b/packages/utils/src/logger.ts index 031c969a930d..efa8f49716b9 100644 --- a/packages/utils/src/logger.ts +++ b/packages/utils/src/logger.ts @@ -1,6 +1,6 @@ import { WrappedFunction } from '@sentry/types'; -import { getGlobalSingleton, GLOBAL_OBJ } from './global'; +import { getGlobalSingleton, GLOBAL_OBJ } from './worldwide'; /** Prefix for logging strings */ const PREFIX = 'Sentry Logger '; diff --git a/packages/utils/src/misc.ts b/packages/utils/src/misc.ts index 8c24439a47d4..aacb4de786e0 100644 --- a/packages/utils/src/misc.ts +++ b/packages/utils/src/misc.ts @@ -1,9 +1,9 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ import { Event, Exception, Mechanism, StackFrame } from '@sentry/types'; -import { GLOBAL_OBJ } from './global'; import { addNonEnumerableProperty } from './object'; import { snipLine } from './string'; +import { GLOBAL_OBJ } from './worldwide'; interface CryptoInternal { getRandomValues(array: Uint8Array): Uint8Array; diff --git a/packages/utils/src/global.ts b/packages/utils/src/worldwide.ts similarity index 93% rename from packages/utils/src/global.ts rename to packages/utils/src/worldwide.ts index 72163749214a..b882136689d0 100644 --- a/packages/utils/src/global.ts +++ b/packages/utils/src/worldwide.ts @@ -1,6 +1,13 @@ /** * NOTE: In order to avoid circular dependencies, if you add a function to this module and it needs to print something, * you must either a) use `console.log` rather than the logger, or b) put your function elsewhere. + * + * Note: This file was originally called `global.ts`, but was changed to unblock users which might be doing + * string replaces with bundlers like Vite for `global` (would break imports that rely on importing from utils/src/global). + * + * Why worldwide? + * + * Why not? */ /* eslint-disable @typescript-eslint/no-explicit-any */ diff --git a/packages/utils/test/global.test.ts b/packages/utils/test/worldwide.test.ts similarity index 85% rename from packages/utils/test/global.test.ts rename to packages/utils/test/worldwide.test.ts index 722abf678bb0..6137c95c093b 100644 --- a/packages/utils/test/global.test.ts +++ b/packages/utils/test/worldwide.test.ts @@ -1,4 +1,4 @@ -import { GLOBAL_OBJ } from '../src/global'; +import { GLOBAL_OBJ } from '../src/worldwide'; describe('GLOBAL_OBJ', () => { test('should return the same object', () => {