Skip to content

Commit

Permalink
feat: allow tree-shaking of unused transports
Browse files Browse the repository at this point in the history
  • Loading branch information
darrachequesne committed May 31, 2024
1 parent 579b243 commit 5185dc1
Show file tree
Hide file tree
Showing 23 changed files with 538 additions and 335 deletions.
9 changes: 0 additions & 9 deletions lib/globalThis.browser.ts

This file was deleted.

1 change: 0 additions & 1 deletion lib/globalThis.ts

This file was deleted.

6 changes: 3 additions & 3 deletions lib/transports/xmlhttprequest.ts → lib/globals.node.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as XMLHttpRequestModule from "xmlhttprequest-ssl";

export const XHR = XMLHttpRequestModule.default || XMLHttpRequestModule;
export const nextTick = process.nextTick;
export const globalThisShim = global;
export const defaultBinaryType = "nodebuffer";

export function createCookieJar() {
return new CookieJar();
Expand Down
16 changes: 12 additions & 4 deletions ...ansports/websocket-constructor.browser.ts → lib/globals.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { globalThisShim as globalThis } from "../globalThis.js";

export const nextTick = (() => {
const isPromiseAvailable =
typeof Promise === "function" && typeof Promise.resolve === "function";
Expand All @@ -10,6 +8,16 @@ export const nextTick = (() => {
}
})();

export const WebSocket = globalThis.WebSocket || globalThis.MozWebSocket;
export const usingBrowserWebSocket = true;
export const globalThisShim = (() => {
if (typeof self !== "undefined") {
return self;
} else if (typeof window !== "undefined") {
return window;
} else {
return Function("return this")();
}
})();

export const defaultBinaryType = "arraybuffer";

export function createCookieJar() {}
12 changes: 10 additions & 2 deletions lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
import { Socket } from "./socket.js";

export { Socket };
export { SocketOptions } from "./socket.js";
export {
SocketOptions,
SocketWithoutUpgrade,
SocketWithUpgrade,
} from "./socket.js";
export const protocol = Socket.protocol;
export { Transport, TransportError } from "./transport.js";
export { transports } from "./transports/index.js";
export { installTimerFunctions } from "./util.js";
export { parse } from "./contrib/parseuri.js";
export { nextTick } from "./transports/websocket-constructor.js";
export { nextTick } from "./globals.node.js";

export { Fetch } from "./transports/polling-fetch.js";
export { XHR as NodeXHR } from "./transports/polling-xhr.node.js";
export { XHR } from "./transports/polling-xhr.js";
export { WS as NodeWebSocket } from "./transports/websocket.node.js";
export { WS as WebSocket } from "./transports/websocket.js";
export { WT as WebTransport } from "./transports/webtransport.js";
Loading

0 comments on commit 5185dc1

Please sign in to comment.