File tree Expand file tree Collapse file tree 3 files changed +19
-4
lines changed Expand file tree Collapse file tree 3 files changed +19
-4
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,12 @@ for (const f of formats)
1616 external : Object . keys ( package . dependencies ) ,
1717 format : f . format ,
1818 outfile : 'build/index' + f . extension ,
19+ target : 'node16' ,
20+ define : {
21+ 'process.env.ES_TARGET' : '"' + f . format + '"' ,
22+ } ,
23+ } )
24+ . catch ( e => {
25+ console . log ( e )
1926 } )
20- . catch ( ( ) => process . exit ( 1 ) )
2127 . then ( ( ) => console . log ( 'Successfully bundled the package in the ' + f . format + ' format' ) )
Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ import { getObjectChanges } from '../utils/getObjectChanges'
2121export const DefaultHostname = 'ws.xapi.pro'
2222export const DefaultRateLimit = 850
2323
24- type AccountType = 'real' | 'demo'
24+ type AccountType = string
2525export interface XAPIConfig {
2626 accountId : string
2727 password : string
Original file line number Diff line number Diff line change 11import { Listener } from './Listener'
22import { Timer } from './Timer'
3-
3+ import type { WebSocket as WS } from 'ws'
44export const isNodeJS = ( ) => typeof window === 'undefined' && typeof module !== 'undefined' && module . exports
55
6+ function getWS ( ) : Promise < typeof WS > {
7+ if ( process . env . ES_TARGET == 'esm' ) {
8+ return import ( 'ws' )
9+ } else {
10+ // eslint-disable-next-line
11+ return new Promise ( resolve => resolve ( require ( 'ws' ) ) )
12+ }
13+ }
14+
615export class WebSocketWrapper extends Listener {
716 private ws : any = null
817 private _tryReconnect = false
@@ -38,7 +47,7 @@ export class WebSocketWrapper extends Listener {
3847 this . _connectionTimeout . clear ( )
3948 if ( isNodeJS ( ) ) {
4049 // NodeJS module
41- import ( 'ws' ) . then ( WebSocketClient => {
50+ getWS ( ) . then ( WebSocketClient => {
4251 this . ws = new WebSocketClient ( this . url )
4352 this . ws . on ( 'open' , ( ) => {
4453 this . _status = true
You can’t perform that action at this time.
0 commit comments