Skip to content
Open
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
5 changes: 5 additions & 0 deletions .changeset/dts-plugin-remove-isomorphic-ws.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@module-federation/dts-plugin': patch
---

chore(dts-plugin): drop the `isomorphic-ws` dependency. Node-side server code now imports `ws` directly and browser-side code uses the global `WebSocket`, preserving Node 20 compatibility.
1 change: 0 additions & 1 deletion packages/dts-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
"@module-federation/sdk": "workspace:*",
"@module-federation/third-party-dts-extractor": "workspace:*",
"adm-zip": "0.6.0",
"isomorphic-ws": "5.0.0",
"undici": "7.28.0",
"ws": "8.21.0"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,20 @@ declare const FEDERATION_IPV4: string | undefined;
const PLUGIN_NAME = 'dynamic-remote-type-hints-plugin';

function dynamicRemoteTypeHintsPlugin(): ModuleFederationRuntimePlugin {
let ws = createWebsocket();
// `createWebsocket` relies on the global `WebSocket`, which only exists in
// browsers and Node >= 22. In a Node/SSR host on older Node it is undefined,
// so guard construction to degrade gracefully instead of throwing at init.
let ws = typeof WebSocket !== 'undefined' ? createWebsocket() : undefined;
let isConnected = false;
ws.onopen = () => {
isConnected = true;
};
if (ws) {
ws.onopen = () => {
isConnected = true;
};

ws.onerror = (err) => {
console.error(`[ ${PLUGIN_NAME} ] err: ${err}`);
};
ws.onerror = (err) => {
console.error(`[ ${PLUGIN_NAME} ] err: ${err}`);
};
}

return {
name: 'dynamic-remote-type-hints-plugin',
Expand All @@ -40,7 +45,7 @@ function dynamicRemoteTypeHintsPlugin(): ModuleFederationRuntimePlugin {
alias: remote.alias || remote.name,
};
if (remoteIp) {
ws.send(
ws?.send(
JSON.stringify(
new AddDynamicRemoteAction({
remoteIp,
Expand All @@ -52,7 +57,7 @@ function dynamicRemoteTypeHintsPlugin(): ModuleFederationRuntimePlugin {
);
}
// fetch types
ws.send(
ws?.send(
JSON.stringify(
new FetchTypesAction({
name: origin.name,
Expand Down
2 changes: 1 addition & 1 deletion packages/dts-plugin/src/server/DevServer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import WebSocket from 'isomorphic-ws';
import WebSocket from 'ws';
import { UpdateMode } from './constant';
import { Broker } from './broker/Broker';
import { fib, getIdentifier, getIPV4, fileLog } from './utils';
Expand Down
1 change: 0 additions & 1 deletion packages/dts-plugin/src/server/WebClient.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import WebSocket from 'isomorphic-ws';
import { DEFAULT_WEB_SOCKET_PORT } from './constant';
import { Message } from './message/Message';
import { AddWebClientAction } from './message/Action';
Expand Down
2 changes: 1 addition & 1 deletion packages/dts-plugin/src/server/broker/Broker.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IncomingMessage, createServer } from 'http';
import { UpdateMode } from '../constant';
import WebSocket from 'isomorphic-ws';
import WebSocket from 'ws';
import { parse } from 'url';
import { Publisher } from '../Publisher';
import { getIdentifier, fileLog, error } from '../utils';
Expand Down
3 changes: 2 additions & 1 deletion packages/dts-plugin/src/server/createWebsocket.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import WebSocket from 'isomorphic-ws';
import {
DEFAULT_WEB_SOCKET_PORT,
WEB_SOCKET_CONNECT_MAGIC_ID,
} from './constant';

// Browser-only module: uses the global `WebSocket` (always present in browsers),
// so no `isomorphic-ws`/`ws` dependency is required here.
export function createWebsocket() {
return new WebSocket(
`ws://127.0.0.1:${DEFAULT_WEB_SOCKET_PORT}?WEB_SOCKET_CONNECT_MAGIC_ID=${WEB_SOCKET_CONNECT_MAGIC_ID}`,
Expand Down
2 changes: 1 addition & 1 deletion packages/dts-plugin/src/server/types/broker.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import WebSocket from 'isomorphic-ws';
import type WebSocket from 'ws';
import { Subscriber } from './message';

type SubscriberIdentifier = string;
Expand Down
7 changes: 0 additions & 7 deletions pnpm-lock.yaml

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