From 86796487f30436cd26291834ae7445fc40ce6139 Mon Sep 17 00:00:00 2001 From: Curran Kelleher <68416+curran@users.noreply.github.com> Date: Wed, 31 Jan 2024 12:19:52 -0500 Subject: [PATCH] feat: support Web Workers by using the global `btoa` (#269) Co-authored-by: Anthony Fu --- .eslintrc | 3 ++- src/SourceMap.js | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.eslintrc b/.eslintrc index e6dd07c..3ad659f 100644 --- a/.eslintrc +++ b/.eslintrc @@ -27,7 +27,8 @@ "globals": { "DEBUG": true, "process": true, - "Buffer": true + "Buffer": true, + "globalThis": true, }, "extends": "eslint:recommended", "parserOptions": { diff --git a/src/SourceMap.js b/src/SourceMap.js index e909671..a91b319 100644 --- a/src/SourceMap.js +++ b/src/SourceMap.js @@ -1,8 +1,8 @@ import { encode } from '@jridgewell/sourcemap-codec'; function getBtoa() { - if (typeof window !== 'undefined' && typeof window.btoa === 'function') { - return (str) => window.btoa(unescape(encodeURIComponent(str))); + if (typeof globalThis !== 'undefined' && typeof globalThis.btoa === 'function') { + return (str) => globalThis.btoa(unescape(encodeURIComponent(str))); } else if (typeof Buffer === 'function') { return (str) => Buffer.from(str, 'utf-8').toString('base64'); } else {