Skip to content

Commit b4b06da

Browse files
committed
Fixed Node.js WebSockets
1 parent 0ea5fb0 commit b4b06da

File tree

4 files changed

+48
-5
lines changed

4 files changed

+48
-5
lines changed

node-transform.ps1

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ $DeleteList = "lib", "node_modules", "mod.js", "mod.d.ts"
1717
$Destination = "node"
1818
$NodePackageLocation = "$Destination/package.json"
1919
$ImportRegex = "(?<=(?<=\n|^)(im|ex)port(?:(?!(\.d)?\.ts).|\n)*)(\.d)?\.ts"
20+
$NodeOnlyRegex = "\/\/ build:node-only "
2021

2122
[string[]]$PresentFiles = @()
2223
$ItemList + $DeleteList | ForEach-Object {
@@ -32,8 +33,8 @@ If ($PresentFiles.Length -ne 0) {
3233
$decision = $Host.UI.PromptForChoice(
3334
"Item(s) in the specified destination location already exists. ($PresentFilesFormated)",
3435
"Do you want to delete these items and continue?",
35-
('&Yes', '&No'), 1)
36-
If (($decision -eq 0) -or ($null -ne $env:CI)) {
36+
('&No', '&Yes'), 1)
37+
If (($decision -eq 1) -or ($null -ne $env:CI)) {
3738
$PresentFiles | Remove-Item -Recurse -Force
3839
}
3940
Else {
@@ -60,7 +61,7 @@ If ($Version) {
6061
# Node Import Syntax Fix
6162
Get-ChildItem $Destination -Recurse -Filter *.ts | ForEach-Object {
6263
$Content = Get-Content $_.FullName -Raw
63-
$Content -replace "$ImportRegex", "" > $_.FullName
64+
$Content -replace "($ImportRegex|$NodeOnlyRegex)", "" > $_.FullName
6465
}
6566

6667
# Verification

node/package-lock.json

Lines changed: 32 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,9 @@
4646
"@types/node-fetch": "^2.6.2",
4747
"node-fetch": "^2.6.7",
4848
"typescript": "4.8.4"
49+
},
50+
"dependencies": {
51+
"@types/ws": "^8.5.3",
52+
"ws": "^8.11.0"
4953
}
5054
}

src/ws.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
* @module
1111
*/
1212

13+
// build:node-only import WebSocket, {
14+
// build:node-only type CloseEvent,
15+
// build:node-only type Event,
16+
// build:node-only type ErrorEvent,
17+
// build:node-only type MessageEvent,
18+
// build:node-only } from "ws";
1319
import { Tpy } from "./tpy.ts";
1420
import type { Unpacked } from "./types/util.d.ts";
1521
import type { PylonWebSocket } from "./types/pylon.d.ts";
@@ -171,8 +177,8 @@ export class TpyWs {
171177
this.eventEmitter.emit("close", event);
172178
}
173179

174-
private onMessage(event: MessageEvent<string>) {
175-
this.eventEmitter.emit("message", JSON.parse(event.data)[0]);
180+
private onMessage(event: MessageEvent) {
181+
this.eventEmitter.emit("message", JSON.parse(String(event.data))[0]);
176182
}
177183

178184
/**

0 commit comments

Comments
 (0)