Skip to content
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

refactor: replace isomorphic-ws with unws #390

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@
"@scure/bip39": "1.2.0",
"@wagmi/chains": "0.2.16",
"abitype": "0.7.1",
"isomorphic-ws": "5.0.0",
"unws": "0.2.1",
"ws": "8.12.0"
},
"devDependencies": {
Expand Down
23 changes: 12 additions & 11 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/clients/transports/webSocket.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { WebSocket } from 'isomorphic-ws'
import { WebSocket } from 'unws'
import { assertType, describe, expect, test } from 'vitest'

import { localWsUrl } from '../../_test/index.js'
Expand Down
2 changes: 1 addition & 1 deletion src/clients/transports/webSocket.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { WebSocket } from 'isomorphic-ws'
import type { WebSocket } from 'unws'

import { UrlRequiredError } from '../../errors/index.js'
import type { Hash } from '../../types/index.js'
Expand Down
2 changes: 1 addition & 1 deletion src/utils/rpc.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { IncomingHttpHeaders } from 'http'
import WebSocket from 'isomorphic-ws'
import { WebSocket } from 'unws'
import { describe, expect, test, vi } from 'vitest'

import { localHttpUrl } from '../_test/constants.js'
Expand Down
14 changes: 2 additions & 12 deletions src/utils/rpc.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { MessageEvent, WebSocket } from 'isomorphic-ws'
import type { MessageEvent, WebSocket } from 'unws'

import {
HttpRequestError,
Expand Down Expand Up @@ -145,17 +145,7 @@ export async function getSocket(url_: string) {
// If the socket already exists, return it.
if (socket) return socket

let WebSocket = await import('isomorphic-ws')
// Workaround for Vite.
// https://github.com/vitejs/vite/issues/9703
// TODO: Remove when issue is resolved.
if (
(WebSocket as unknown as { default?: typeof WebSocket }).default
?.constructor
)
WebSocket = (WebSocket as unknown as { default: typeof WebSocket }).default
else WebSocket = WebSocket.WebSocket

const { WebSocket } = await import('unws')
const webSocket = new WebSocket(url)

// Set up a cache for incoming "synchronous" requests.
Expand Down