From aeb8de64ed623bd556b9ef5161cdb981435c2ffa Mon Sep 17 00:00:00 2001 From: Lo Date: Wed, 6 Mar 2024 13:14:45 +0800 Subject: [PATCH] feat: change to use globalThis --- src/client/app/index.ts | 4 +--- src/shared/shared.ts | 17 ----------------- 2 files changed, 1 insertion(+), 20 deletions(-) diff --git a/src/client/app/index.ts b/src/client/app/index.ts index 5bc8087c..911760a1 100644 --- a/src/client/app/index.ts +++ b/src/client/app/index.ts @@ -17,7 +17,6 @@ import { usePrefetch } from './composables/preFetch' import { dataSymbol, initData, siteDataRef, useData } from './data' import { RouterSymbol, createRouter, scrollTo, type Router } from './router' import { inBrowser, pathToFile } from './utils' -import { getGlobalThis } from '../shared' function resolveThemeExtends(theme: typeof RawTheme): typeof RawTheme { if (theme.extends) { @@ -65,8 +64,7 @@ const VitePressApp = defineComponent({ }) export async function createApp() { - const target = getGlobalThis() - target.__VITEPRESS__ = true + ;(globalThis as any).__VITEPRESS__ = true const router = newRouter() diff --git a/src/shared/shared.ts b/src/shared/shared.ts index d24b98b3..1308840e 100644 --- a/src/shared/shared.ts +++ b/src/shared/shared.ts @@ -211,20 +211,3 @@ export function treatAsHtml(filename: string): boolean { export function escapeRegExp(str: string) { return str.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&').replace(/-/g, '\\x2d') } - -let _globalThis: any -export const getGlobalThis = (): any => { - return ( - _globalThis || - (_globalThis = - typeof globalThis !== 'undefined' - ? globalThis - : typeof self !== 'undefined' - ? self - : typeof window !== 'undefined' - ? window - : typeof global !== 'undefined' - ? global - : {}) - ) -}