Skip to content

Commit

Permalink
fix: workaround undefined global this
Browse files Browse the repository at this point in the history
Default export of globalThis seems to have a problem
in the "browser" field when the library is loaded asynchronously
with webpack, so this is a quick workaround.
  • Loading branch information
yujiosaka committed Apr 22, 2022
1 parent 8437600 commit 6ee02ac
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 5 deletions.
5 changes: 4 additions & 1 deletion lib/transports/polling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ 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 * as globalThisModule from "../globalThis.js";
const globalThis =
globalThisModule.default ||
((globalThisModule as any) as typeof globalThisModule.default);

const debug = debugModule("engine.io-client:polling"); // debug()

Expand Down
5 changes: 4 additions & 1 deletion lib/transports/websocket-constructor.browser.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import globalThis from "../globalThis.js";
import * as globalThisModule from "../globalThis.js";
const globalThis =
globalThisModule.default ||
((globalThisModule as any) as typeof globalThisModule.default);

export const nextTick = (() => {
const isPromiseAvailable =
Expand Down
5 changes: 4 additions & 1 deletion lib/transports/xmlhttprequest.browser.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
// browser shim for xmlhttprequest module

import { hasCORS } from "../contrib/has-cors.js";
import globalThis from "../globalThis.js";
import * as globalThisModule from "../globalThis.js";
const globalThis =
globalThisModule.default ||
((globalThisModule as any) as typeof globalThisModule.default);

export default function(opts) {
const xdomain = opts.xdomain;
Expand Down
5 changes: 4 additions & 1 deletion lib/util.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import globalThis from "./globalThis.js";
import * as globalThisModule from "./globalThis.js";
const globalThis =
globalThisModule.default ||
((globalThisModule as any) as typeof globalThisModule.default);

export function pick(obj, ...attr) {
return attr.reduce((acc, k) => {
Expand Down
5 changes: 4 additions & 1 deletion lib/xmlhttprequest.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
// browser shim for xmlhttprequest module

import { hasCORS } from "./contrib/has-cors.js";
import globalThis from "./globalThis.js";
import * as globalThisModule from "./globalThis.js";
const globalThis =
globalThisModule.default ||
((globalThisModule as any) as typeof globalThisModule.default);

export default function(opts) {
const xdomain = opts.xdomain;
Expand Down

0 comments on commit 6ee02ac

Please sign in to comment.