Skip to content

Commit dfd30b9

Browse files
committed
fix(core): remove dynamic imports
1 parent a15148c commit dfd30b9

File tree

3 files changed

+12
-32
lines changed

3 files changed

+12
-32
lines changed
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import * as encoding from 'text-encoding-polyfill';
2+
13
const scope =
2-
typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : this;
4+
typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : {};
35

46
if (typeof scope.crypto !== 'object') {
57
scope.crypto = {
@@ -8,8 +10,6 @@ if (typeof scope.crypto !== 'object') {
810
}
911

1012
if (typeof scope.TextEncoder !== 'object' || typeof scope.TextDecoder !== 'object') {
11-
import('text-encoding-polyfill/lib/encoding.js').then((encoding) => {
12-
scope.TextEncoder = encoding.TextEncoder;
13-
scope.TextDecoder = encoding.TextDecoder;
14-
});
13+
scope.TextEncoder = encoding.TextEncoder;
14+
scope.TextDecoder = encoding.TextDecoder;
1515
}

libraries/core/src/sockjs-client.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
declare module "sockjs-client/dist/sockjs" {
2+
export default (await import("sockjs-client")).default
3+
}

libraries/core/src/stompx.ts

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,11 @@ import { Subscription } from 'rxjs';
55
import { take } from 'rxjs/operators';
66
import { v4 as uuidv4 } from 'uuid';
77

8-
import { version } from './environment';
9-
10-
let TransportFallback: { new (url: string): unknown };
11-
12-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
13-
// @ts-ignore
14-
const transportFallbackPromise = import('sockjs-client/dist/sockjs.js')
15-
.then((sockjs) => {
16-
TransportFallback = sockjs.default;
17-
})
18-
.catch((error) => {
19-
ErrorMessageTransportFallback.errorMessage = error.message;
20-
21-
TransportFallback = ErrorMessageTransportFallback;
22-
});
8+
import sockjs from 'sockjs-client/dist/sockjs';
239

24-
class ErrorMessageTransportFallback {
25-
static errorMessage: string;
10+
import { version } from './environment';
2611

27-
constructor() {
28-
throw new Error(
29-
'Encountered error when attempting to use transport fallback: ' +
30-
ErrorMessageTransportFallback.errorMessage,
31-
);
32-
}
33-
}
12+
const TransportFallback = sockjs;
3413

3514
export default class StompX {
3615
private readonly host: string;
@@ -244,9 +223,7 @@ export default class StompX {
244223
});
245224
});
246225

247-
transportFallbackPromise.then(() => {
248-
this.rxStomp.activate();
249-
});
226+
this.rxStomp.activate();
250227
}
251228

252229
public relayResource<R>(request: StompXRelayResourceRequest<R>) {

0 commit comments

Comments
 (0)