diff --git a/jest.setup.js b/jest.setup.js index 1f040bd1c6..07b499aa2e 100644 --- a/jest.setup.js +++ b/jest.setup.js @@ -1,8 +1,4 @@ const { JSDOM } = require('jsdom'); -// new TextDecoder('ascii') is not supported in node12 -// use TextDecoder and TextEncoder from `text-encoding` -const { TextDecoder, TextEncoder } = require('text-encoding'); - const jsdom = new JSDOM('
', { // https://github.com/jsdom/jsdom#basic-options // 禁用掉 resources: usable, 采用 jsdom 默认策略不加载 subresources diff --git a/package.json b/package.json index d678929388..d498547c7d 100644 --- a/package.json +++ b/package.json @@ -141,7 +141,6 @@ "simple-git": "^3.3.0", "strip-html-comments": "^1.0.0", "temp": "^0.9.4", - "text-encoding": "^0.7.0", "ts-jest": "^27.0.3", "uuid": "^8.3.2", "write-pkg": "^4.0.0", diff --git a/packages/connection/src/browser/connect.ts b/packages/connection/src/browser/connect.ts deleted file mode 100644 index d09f1ba40b..0000000000 --- a/packages/connection/src/browser/connect.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { - BrowserMessageReader, - BrowserMessageWriter, - createMessageConnection, -} from '@opensumi/vscode-jsonrpc/lib/browser/main'; - -export function createSocketConnection(socket: Worker) { - return createMessageConnection(new BrowserMessageReader(socket), new BrowserMessageWriter(socket)); -} diff --git a/packages/connection/src/browser/index.ts b/packages/connection/src/browser/index.ts index dc7fe4c061..6b1bce253c 100644 --- a/packages/connection/src/browser/index.ts +++ b/packages/connection/src/browser/index.ts @@ -1,2 +1 @@ export * from './ws-channel-handler'; -export * from './connect'; diff --git a/packages/connection/src/common/message.ts b/packages/connection/src/common/message.ts index d01ec2f1bb..a68c297b5e 100644 --- a/packages/connection/src/common/message.ts +++ b/packages/connection/src/common/message.ts @@ -6,6 +6,12 @@ import { import { Disposable } from '@opensumi/vscode-jsonrpc/lib/common/disposable'; import { MessageReader, DataCallback } from '@opensumi/vscode-jsonrpc/lib/common/messageReader'; import { MessageWriter } from '@opensumi/vscode-jsonrpc/lib/common/messageWriter'; +/** + * FIXME: 由于 `createMessageConnection` 方法隐式依赖了 `@opensumi/vscode-jsonrpc/lib/browser/main` 或 `@opensumi/vscode-jsonrpc/lib/node/main` + * 的 `RIL.install()` 初始化代码,而 `browser/main` 中仅支持浏览器使用, + * 故需要保证提前引入或执行一次 `@opensumi/vscode-jsonrpc/lib/node/main` 代码才能保证逻辑正常执行 + */ +import '@opensumi/vscode-jsonrpc/lib/node/main'; export class WebSocketMessageReader extends AbstractMessageReader implements MessageReader { protected state: 'initial' | 'listening' | 'closed' = 'initial'; diff --git a/packages/connection/src/common/proxy.ts b/packages/connection/src/common/proxy.ts index 6067e8fa10..a6dc87f62d 100644 --- a/packages/connection/src/common/proxy.ts +++ b/packages/connection/src/common/proxy.ts @@ -1,4 +1,4 @@ -import { MessageConnection } from '@opensumi/vscode-jsonrpc/lib/common/connection'; +import type { MessageConnection } from '@opensumi/vscode-jsonrpc/lib/common/connection'; export abstract class RPCService { rpcClient?: T[]; diff --git a/packages/core-browser/src/bootstrap/connection.ts b/packages/core-browser/src/bootstrap/connection.ts index c6bf6385c1..e1fb3629a5 100644 --- a/packages/core-browser/src/bootstrap/connection.ts +++ b/packages/core-browser/src/bootstrap/connection.ts @@ -1,6 +1,6 @@ import { Injector, Provider } from '@opensumi/di'; import { RPCServiceCenter, initRPCService, RPCMessageConnection } from '@opensumi/ide-connection'; -import { createSocketConnection, WSChannelHandler } from '@opensumi/ide-connection/lib/browser'; +import { WSChannelHandler } from '@opensumi/ide-connection/lib/browser'; import { createWebSocketConnection } from '@opensumi/ide-connection/lib/common/message'; import { getDebugLogger, @@ -63,13 +63,6 @@ export async function createClientConnection2( bindConnectionService(injector, modules, createWebSocketConnection(channel)); } -/** - * electron 环境下不要调用这个函数,该函数的 createSocketConnection 是 browser 环境下的 - */ -export async function createNetClientConnection(injector: Injector, modules: ModuleConstructor[], connection: any) { - bindConnectionService(injector, modules, createSocketConnection(connection)); -} - export async function bindConnectionService( injector: Injector, modules: ModuleConstructor[],