Skip to content

Commit

Permalink
Drop detect-node dependency by coalescing eventsource inclusion (#…
Browse files Browse the repository at this point in the history
…831)

* Coalesce eventsource inclusion, drop Node detection
* Refresh yarn.lock after new deps
  • Loading branch information
Shaptic committed Jun 13, 2023
1 parent 15327d6 commit 52947e8
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 200 deletions.
11 changes: 5 additions & 6 deletions config/.prettierignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/package.json
/node_modules
/lib
/dist
/docs
gulpfile.js
../package.json
../node_modules
../lib
../dist
../docs
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@
"dependencies": {
"axios": "^1.4.0",
"bignumber.js": "^9.1.1",
"detect-node": "^2.0.4",
"eventsource": "^2.0.2",
"randombytes": "^2.1.0",
"stellar-base": "v9.0.0-beta.2",
Expand Down
22 changes: 5 additions & 17 deletions src/call_builder.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import isNode from "detect-node";
import URI from "urijs";
import URITemplate from "urijs/src/URITemplate";

Expand All @@ -14,29 +13,18 @@ const version = require("../package.json").version;
// query-param.
const JOINABLE = ["transaction"];

type Constructable<T> = new (e: string) => T;

export interface EventSourceOptions<T> {
onmessage?: (value: T) => void;
onerror?: (event: MessageEvent) => void;
reconnectTimeout?: number;
}

let EventSource: Constructable<EventSource>;
const anyGlobal = global as any;

if (anyGlobal.EventSource) {
EventSource = anyGlobal.EventSource;
} else if (isNode) {
/* tslint:disable-next-line:no-var-requires */
EventSource = require("eventsource");
} else if (anyGlobal.window.EventSource) {
EventSource = anyGlobal.window.EventSource;
} else {
// require("eventsource") for React Native environment
/* tslint:disable-next-line:no-var-requires */
EventSource = require("eventsource");
}
type Constructable<T> = new (e: string) => T;
// require("eventsource") for Node and React Native environment
let EventSource: Constructable<EventSource> = anyGlobal.EventSource ??
anyGlobal.window?.EventSource ??
require("eventsource");

/**
* Creates a new {@link CallBuilder} pointed to server defined by serverUrl.
Expand Down
Loading

0 comments on commit 52947e8

Please sign in to comment.