From f9cb983ab7050c0a1630cfc97eb30f2dd807186b Mon Sep 17 00:00:00 2001 From: Damien Arrachequesne Date: Thu, 11 Jul 2024 12:54:17 +0200 Subject: [PATCH] fix(engine.io-parser): do not expose the TransformStream type The previous commit [1] tried to work around the fact that the TransformStream object is not exposed in the global scope in the `@types/node` package, even though it is since Node.js `v18.0.0`. Unfortunately, it created two new issues: - using an older `@types/node` version (before v16) would fail with: > error TS2307: Cannot find module 'node:stream/web' or its corresponding type declarations. Related: https://github.com/socketio/socket.io/issues/5064#issuecomment-2217149344 - browser-only environments would somehow include the node types, leading to conflicts like the return value of the setTimeout() method Related: - https://github.com/socketio/socket.io/issues/5064#issuecomment-2217149374 - https://github.com/socketio/socket.io/issues/5065 [1]: https://github.com/socketio/engine.io-parser/commit/0305b4a7a597e0f070ce8ea17106121f9ab369bc --- packages/engine.io-parser/lib/index.ts | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/packages/engine.io-parser/lib/index.ts b/packages/engine.io-parser/lib/index.ts index 43c88fe894..e36b35b5ab 100644 --- a/packages/engine.io-parser/lib/index.ts +++ b/packages/engine.io-parser/lib/index.ts @@ -7,9 +7,6 @@ import { BinaryType, ERROR_PACKET, } from "./commons.js"; -// we can't import TransformStream as a value because it was added in Node.js v16.5.0, so it would break on older Node.js versions -// reference: https://nodejs.org/api/webstreams.html#class-transformstream -import type { TransformStream } from "node:stream/web"; const SEPARATOR = String.fromCharCode(30); // see https://en.wikipedia.org/wiki/Delimiter#ASCII_delimited_text @@ -49,8 +46,7 @@ const decodePayload = ( return packets; }; -export function createPacketEncoderStream() { - // @ts-expect-error +export function createPacketEncoderStream(): any { return new TransformStream({ transform(packet: Packet, controller) { encodePacketToBinary(packet, (encodedPacket) => { @@ -117,7 +113,7 @@ const enum State { export function createPacketDecoderStream( maxPayload: number, binaryType: BinaryType, -) { +): any { if (!TEXT_DECODER) { TEXT_DECODER = new TextDecoder(); } @@ -126,7 +122,6 @@ export function createPacketDecoderStream( let expectedLength = -1; let isBinary = false; - // @ts-expect-error return new TransformStream({ transform(chunk: Uint8Array, controller) { chunks.push(chunk);