From 32878ea047c38e2b2f0444e828ac71f4d833971f Mon Sep 17 00:00:00 2001 From: yujiosaka Date: Fri, 22 Apr 2022 11:52:40 +0900 Subject: [PATCH] fix: use named export for globalThis shim (#688) Default export of globalThis seems to have a problem in the "browser" field when the library is loaded asynchronously with webpack. --- lib/globalThis.browser.ts | 2 +- lib/globalThis.ts | 2 +- lib/transports/polling.ts | 2 +- lib/transports/websocket-constructor.browser.ts | 2 +- lib/transports/xmlhttprequest.browser.ts | 2 +- lib/util.ts | 2 +- lib/xmlhttprequest.ts | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/globalThis.browser.ts b/lib/globalThis.browser.ts index ea8c4c431..0962057d1 100644 --- a/lib/globalThis.browser.ts +++ b/lib/globalThis.browser.ts @@ -1,4 +1,4 @@ -export default (() => { +export const globalThisShim = (() => { if (typeof self !== "undefined") { return self; } else if (typeof window !== "undefined") { diff --git a/lib/globalThis.ts b/lib/globalThis.ts index 1b8c4b29a..27a616bd4 100644 --- a/lib/globalThis.ts +++ b/lib/globalThis.ts @@ -1 +1 @@ -export default global; +export const globalThisShim = global; diff --git a/lib/transports/polling.ts b/lib/transports/polling.ts index 78f5e28ce..93e4ace4f 100644 --- a/lib/transports/polling.ts +++ b/lib/transports/polling.ts @@ -7,7 +7,7 @@ import XMLHttpRequest from "./xmlhttprequest.js"; import { Emitter } from "@socket.io/component-emitter"; import { SocketOptions } from "../socket.js"; import { installTimerFunctions, pick } from "../util.js"; -import globalThis from "../globalThis.js"; +import { globalThisShim as globalThis } from "../globalThis.js"; const debug = debugModule("engine.io-client:polling"); // debug() diff --git a/lib/transports/websocket-constructor.browser.ts b/lib/transports/websocket-constructor.browser.ts index 023d953d8..f103edf9b 100644 --- a/lib/transports/websocket-constructor.browser.ts +++ b/lib/transports/websocket-constructor.browser.ts @@ -1,4 +1,4 @@ -import globalThis from "../globalThis.js"; +import { globalThisShim as globalThis } from "../globalThis.js"; export const nextTick = (() => { const isPromiseAvailable = diff --git a/lib/transports/xmlhttprequest.browser.ts b/lib/transports/xmlhttprequest.browser.ts index ec71b40ad..db6846b2c 100644 --- a/lib/transports/xmlhttprequest.browser.ts +++ b/lib/transports/xmlhttprequest.browser.ts @@ -1,7 +1,7 @@ // browser shim for xmlhttprequest module import { hasCORS } from "../contrib/has-cors.js"; -import globalThis from "../globalThis.js"; +import { globalThisShim as globalThis } from "../globalThis.js"; export default function(opts) { const xdomain = opts.xdomain; diff --git a/lib/util.ts b/lib/util.ts index 4e40d4e36..48e927eeb 100644 --- a/lib/util.ts +++ b/lib/util.ts @@ -1,4 +1,4 @@ -import globalThis from "./globalThis.js"; +import { globalThisShim as globalThis } from "./globalThis.js"; export function pick(obj, ...attr) { return attr.reduce((acc, k) => { diff --git a/lib/xmlhttprequest.ts b/lib/xmlhttprequest.ts index 660d4135b..b1e803d41 100644 --- a/lib/xmlhttprequest.ts +++ b/lib/xmlhttprequest.ts @@ -1,7 +1,7 @@ // browser shim for xmlhttprequest module import { hasCORS } from "./contrib/has-cors.js"; -import globalThis from "./globalThis.js"; +import { globalThisShim as globalThis } from "./globalThis.js"; export default function(opts) { const xdomain = opts.xdomain;