Skip to content

Commit 87c554b

Browse files
nicolello-devnaomi-lgbt
authored andcommitted
fix: fixed circular dependency giving errors under webpack
1 parent 711be7e commit 87c554b

6 files changed

Lines changed: 26 additions & 27 deletions

File tree

src/lib/constants.ts

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,8 @@
1-
import { convertProtocolToWs, isBrowser, isBun, isNode } from "./helpers";
1+
import { convertProtocolToWs } from "./helpers";
2+
import { isBrowser, isBun, isNode, NODE_VERSION, BUN_VERSION, BROWSER_AGENT } from "./runtime";
23
import { version } from "./version";
34
import type { DefaultNamespaceOptions, DefaultClientOptions } from "./types";
45

5-
export const NODE_VERSION =
6-
typeof process !== "undefined" && process.versions && process.versions.node
7-
? process.versions.node
8-
: "unknown";
9-
10-
export const BUN_VERSION =
11-
typeof process !== "undefined" && process.versions && process.versions.bun
12-
? process.versions.bun
13-
: "unknown";
14-
15-
export const BROWSER_AGENT =
16-
typeof window !== "undefined" && window.navigator && window.navigator.userAgent
17-
? window.navigator.userAgent
18-
: "unknown";
19-
206
const getAgent = () => {
217
if (isNode()) {
228
return `node/${NODE_VERSION}`;

src/lib/helpers.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,11 @@ import {
1111
import { Headers as CrossFetchHeaders } from "cross-fetch";
1212
import { Readable } from "stream";
1313
import merge from "deepmerge";
14-
import { BROWSER_AGENT, BUN_VERSION, NODE_VERSION } from "./constants";
1514

1615
export function stripTrailingSlash(url: string): string {
1716
return url.replace(/\/$/, "");
1817
}
1918

20-
export const isBrowser = () => BROWSER_AGENT !== "unknown";
21-
22-
export const isNode = () => NODE_VERSION !== "unknown";
23-
24-
export const isBun = () => BUN_VERSION !== "unknown";
25-
2619
export function applyDefaults<O, S>(options: Partial<O> = {}, subordinate: Partial<S> = {}): S {
2720
return merge(subordinate, options);
2821
}

src/lib/runtime.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
export const NODE_VERSION =
2+
typeof process !== "undefined" && process.versions && process.versions.node
3+
? process.versions.node
4+
: "unknown";
5+
6+
export const BUN_VERSION =
7+
typeof process !== "undefined" && process.versions && process.versions.bun
8+
? process.versions.bun
9+
: "unknown";
10+
11+
export const BROWSER_AGENT =
12+
typeof window !== "undefined" && window.navigator && window.navigator.userAgent
13+
? window.navigator.userAgent
14+
: "unknown";
15+
16+
export const isBrowser = () => BROWSER_AGENT !== "unknown";
17+
18+
export const isNode = () => NODE_VERSION !== "unknown";
19+
20+
export const isBun = () => BUN_VERSION !== "unknown";

src/packages/AbstractLiveClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { AbstractClient, noop } from "./AbstractClient";
22
import { CONNECTION_STATE, SOCKET_STATES } from "../lib/constants";
33
import type { DeepgramClientOptions, LiveSchema } from "../lib/types";
44
import type { WebSocket as WSWebSocket } from "ws";
5-
import { isBun } from "../lib/helpers";
5+
import { isBun } from "../lib/runtime";
66

77
/**
88
* Represents a constructor for a WebSocket-like object that can be used in the application.

src/packages/AbstractRestClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { fetchWithAuth, resolveResponse } from "../lib/fetch";
44
import type { Fetch, FetchOptions, RequestMethodType } from "../lib/types/Fetch";
55
import { AbstractClient } from "./AbstractClient";
66
import { DeepgramClientOptions } from "../lib/types";
7-
import { isBrowser } from "../lib/helpers";
7+
import { isBrowser } from "../lib/runtime";
88
import merge from "deepmerge";
99

1010
/**

test/constants.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import { applyDefaults, convertProtocolToWs, isBrowser } from "../src/lib/helpers";
1+
import { applyDefaults, convertProtocolToWs } from "../src/lib/helpers";
22
import {
33
CONNECTION_STATE,
44
DEFAULT_GLOBAL_OPTIONS,
55
DEFAULT_HEADERS,
66
DEFAULT_OPTIONS,
77
DEFAULT_URL,
8-
NODE_VERSION,
98
SOCKET_STATES,
109
} from "../src/lib/constants";
10+
import { isBrowser, NODE_VERSION } from "../src/lib/runtime";
1111
import { DeepgramClientOptions } from "../src/lib/types/DeepgramClientOptions";
1212
import { expect } from "chai";
1313
import { faker } from "@faker-js/faker";

0 commit comments

Comments
 (0)