diff --git a/packages/shiki/src/global.d.ts b/packages/shiki/src/global.d.ts index 08c128f6c..b3e1fa56d 100644 --- a/packages/shiki/src/global.d.ts +++ b/packages/shiki/src/global.d.ts @@ -1 +1,20 @@ -declare var __BROWSER__: boolean +declare global { + var __BROWSER__: boolean + + // These will not be defined for Node which don't have "DOM" in their lib. + // So declare the minimal interface we need. + // They are defined here and not in `loader.ts` to avoid getting injected in the built code. + interface Window { + WorkerGlobalScope: any + } + + var self: Window & typeof globalThis + function fetch(url: string): Promise + interface Response { + json(): Promise + text(): Promise + } +} + +// This export is here so that all variables above would be added to the global scope +export {} diff --git a/packages/shiki/src/loader.ts b/packages/shiki/src/loader.ts index b0984ed8b..b3415ffa7 100644 --- a/packages/shiki/src/loader.ts +++ b/packages/shiki/src/loader.ts @@ -1,23 +1,11 @@ +/// + import { join, dirpathparts } from './utils' import type { IGrammar, IOnigLib, IRawTheme } from 'vscode-textmate' import { loadWASM, createOnigScanner, createOnigString } from 'vscode-oniguruma' import { parse, ParseError } from 'jsonc-parser' import type { IShikiTheme } from './types' -// These will not be defined for Node which don't have "DOM" in their lib. -// So declare the minimal interface we need. -declare global { - interface Window { - WorkerGlobalScope: any - } - var self: Window & typeof globalThis - function fetch(url: string): Promise - interface Response { - json(): Promise - text(): Promise - } -} - export const isWebWorker = typeof self !== 'undefined' && typeof self.WorkerGlobalScope !== 'undefined' export const isNode =