From 94bc58381c72dce6e4709d799a073339c128d210 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E6=99=BA=E5=AD=90=20Kevin=20Deng?= Date: Wed, 19 Apr 2023 18:56:53 +0800 Subject: [PATCH] refactor: replace isomorphic-ws with unws --- package.json | 2 +- pnpm-lock.yaml | 23 ++++++++++++----------- src/clients/transports/webSocket.test.ts | 2 +- src/clients/transports/webSocket.ts | 2 +- src/utils/rpc.test.ts | 3 +-- src/utils/rpc.ts | 10 ++-------- 6 files changed, 18 insertions(+), 24 deletions(-) diff --git a/package.json b/package.json index f24b0edf63..8fc74c0dc7 100644 --- a/package.json +++ b/package.json @@ -153,7 +153,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": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index fb256e9dd2..bd315d51d8 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -33,9 +33,9 @@ importers: abitype: specifier: 0.7.1 version: 0.7.1(typescript@5.0.3) - isomorphic-ws: - specifier: 5.0.0 - version: 5.0.0(ws@8.12.0) + unws: + specifier: 0.2.1 + version: 0.2.1(ws@8.12.0) ws: specifier: 8.12.0 version: 8.12.0 @@ -4791,14 +4791,6 @@ packages: resolution: {integrity: sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==} dev: true - /isomorphic-ws@5.0.0(ws@8.12.0): - resolution: {integrity: sha512-muId7Zzn9ywDsyXgTIafTry2sV3nySZeUDe6YedVd1Hvuuep5AsIlqK+XefWpYTyJG5e503F2xIuT2lcU6rCSw==} - peerDependencies: - ws: '*' - dependencies: - ws: 8.12.0 - dev: false - /istanbul-lib-coverage@3.2.0: resolution: {integrity: sha512-eOeJ5BHCmHYvQK7xt9GkdHuzuCGS1Y6g9Gvnx3Ym33fz/HpLRYxiS0wHNr+m/MBC8B647Xt608vCDEvhl9c6Mw==} engines: {node: '>=8'} @@ -6455,6 +6447,15 @@ packages: engines: {node: '>= 10.0.0'} dev: true + /unws@0.2.1(ws@8.12.0): + resolution: {integrity: sha512-6IORJnvNsWru00zb4waE5t1IJLx7RCmA89NOP0rIS8xkAKaIvg4YOiy4GvAWzO3VQbSOq7obNwIymaSSKSoZxw==} + engines: {node: '>=16.14.0'} + peerDependencies: + ws: '*' + dependencies: + ws: 8.12.0 + dev: false + /update-browserslist-db@1.0.10(browserslist@4.21.4): resolution: {integrity: sha512-OztqDenkfFkbSG+tRxBeAnCVPckDBcvibKd35yDONx6OU8N7sqgwc7rCbkJ/WcYtVRZ4ba68d6byhC21GFh7sQ==} hasBin: true diff --git a/src/clients/transports/webSocket.test.ts b/src/clients/transports/webSocket.test.ts index d8724ccda6..cf595738e2 100644 --- a/src/clients/transports/webSocket.test.ts +++ b/src/clients/transports/webSocket.test.ts @@ -1,5 +1,5 @@ import { assertType, describe, expect, test } from 'vitest' -import { WebSocket } from 'isomorphic-ws' +import { WebSocket } from 'unws' import { localWsUrl } from '../../_test/index.js' import { localhost } from '../../chains.js' diff --git a/src/clients/transports/webSocket.ts b/src/clients/transports/webSocket.ts index 92e5b7ec1d..76cada9de9 100644 --- a/src/clients/transports/webSocket.ts +++ b/src/clients/transports/webSocket.ts @@ -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' import type { RpcResponse } from '../../utils/rpc.js' diff --git a/src/utils/rpc.test.ts b/src/utils/rpc.test.ts index 4726f9c9f8..0bc6cba5ec 100644 --- a/src/utils/rpc.test.ts +++ b/src/utils/rpc.test.ts @@ -1,6 +1,5 @@ import { describe, expect, test, vi } from 'vitest' - -import WebSocket from 'isomorphic-ws' +import { WebSocket } from 'unws' import { createHttpServer, diff --git a/src/utils/rpc.ts b/src/utils/rpc.ts index 803f500ec8..7bfbc45242 100644 --- a/src/utils/rpc.ts +++ b/src/utils/rpc.ts @@ -1,4 +1,4 @@ -import type { WebSocket, MessageEvent } from 'isomorphic-ws' +import type { WebSocket, MessageEvent } from 'unws' import { HttpRequestError, RpcRequestError, @@ -144,13 +144,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.constructor) - WebSocket = (WebSocket as unknown as { default: typeof WebSocket }).default - + const { WebSocket } = await import('unws') const webSocket = new WebSocket(url) // Set up a cache for incoming "synchronous" requests.