Skip to content

Change the way we detect Node.js in SignalR JS/TS client. #49066

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/SignalR/clients/ts/signalr/src/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,23 @@ export class Arg {
export class Platform {
// react-native has a window but no document so we should check both
public static get isBrowser(): boolean {
return typeof window === "object" && typeof window.document === "object";
return !Platform.isNode && typeof window === "object" && typeof window.document === "object";
}

// WebWorkers don't have a window object so the isBrowser check would fail
public static get isWebWorker(): boolean {
return typeof self === "object" && "importScripts" in self;
return !Platform.isNode && typeof self === "object" && "importScripts" in self;
}

// react-native has a window but no document
static get isReactNative(): boolean {
return typeof window === "object" && typeof window.document === "undefined";
return !Platform.isNode && typeof window === "object" && typeof window.document === "undefined";
}

// Node apps shouldn't have a window object, but WebWorkers don't either
// so we need to check for both WebWorker and window
public static get isNode(): boolean {
return !this.isBrowser && !this.isWebWorker && !this.isReactNative;
return typeof process !== "undefined" && process.release && process.release.name === "node";
}
}

Expand Down Expand Up @@ -295,4 +295,4 @@ export function getGlobalThis(): unknown {
return global;
}
throw new Error("could not find global");
}
}