Skip to content

Commit be90196

Browse files
authored
fix: correct ws import types (#4)
1 parent 6298ff4 commit be90196

7 files changed

Lines changed: 204 additions & 174 deletions

File tree

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"scripts": {
1515
"test": "vitest",
1616
"build": "tsup",
17+
"postbuild": "./patch-ws-d-ts.sh",
1718
"prepack": "pnpm test && pnpm build",
1819
"release": "release publish"
1920
},
@@ -57,6 +58,6 @@
5758
"tsup": "^8.2.4",
5859
"typescript": "^5.5.4",
5960
"undici": "^6.19.8",
60-
"vitest": "^2.0.5"
61+
"vitest": "^3.1.2"
6162
}
62-
}
63+
}

patch-ws-d-ts.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
# This is an ugly and terrible hack to allow proper interoperability of the `ws` module,
3+
# which is, sadly, a CommonJS module. The issue is that module publishes its types
4+
# nested under the `default` export, which breaks `esInterop` compatibility.
5+
6+
FILE="./lib/ws.d.ts"
7+
8+
if [ -f "$FILE" ]; then
9+
sed -i '' 's/import \* as ws from '\''ws'\'';/import ws from '\''ws'\'';/g' "$FILE"
10+
fi

pnpm-lock.yaml

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

src/ws.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { IncomingMessage } from 'node:http'
22
import type { Socket } from 'node:net'
3-
import type EventEmitter from 'node:events'
3+
import type { EventEmitter } from 'node:events'
44
import { randomUUID } from 'node:crypto'
55
import { WebSocketServer } from 'ws'
66
import { type ServerType } from '@hono/node-server'

tsconfig.base.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
"compilerOptions": {
33
"strict": true,
44
"skipLibCheck": true,
5-
"moduleDetection": "force",
65
"noUncheckedIndexedAccess": true,
7-
"verbatimModuleSyntax": true,
86
"module": "nodenext",
97
"moduleResolution": "nodenext",
8+
"esModuleInterop": true,
9+
"verbatimModuleSyntax": true,
1010
"types": ["node"]
1111
},
1212
"exclude": ["node_modules"]

tsconfig.build.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"compilerOptions": {
44
"outDir": "./lib",
55
"declaration": true,
6+
"emitDeclarationOnly": true,
67
"sourceMap": true
78
}
89
}

tsup.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { defineConfig } from 'tsup'
44
export default defineConfig({
55
entry: ['./src/http.ts', './src/ws.ts'],
66
outDir: './lib',
7-
format: ['esm'],
7+
format: 'esm',
88
dts: true,
99
tsconfig: fileURLToPath(new URL('./tsconfig.build.json', import.meta.url)),
1010
clean: true,

0 commit comments

Comments
 (0)