Skip to content

Commit 29cb306

Browse files
authoredMar 24, 2025··
add missing native APIs in node:tls (#8638)
1 parent d8c0495 commit 29cb306

File tree

5 files changed

+21
-68
lines changed

5 files changed

+21
-68
lines changed
 

‎.changeset/short-dryers-look.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@cloudflare/unenv-preset": patch
3+
---
4+
5+
Use native APIs in `node:tls`
6+
7+
Uses `checkServerIdentity`, `createSecureContext`, and `SecureContext` from workerd rather than the unenv polyfill.

‎fixtures/nodejs-hybrid-app/src/index.ts

+3
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,9 @@ async function testTls() {
207207

208208
assert.strictEqual(typeof tls.connect, "function");
209209
assert.strictEqual(typeof tls.TLSSocket, "function");
210+
assert.strictEqual(typeof tls.checkServerIdentity, "function");
211+
assert.strictEqual(typeof tls.createSecureContext, "function");
212+
assert.strictEqual(typeof tls.SecureContext, "function");
210213

211214
return new Response("OK");
212215
}

‎packages/unenv-preset/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
},
5555
"peerDependencies": {
5656
"unenv": "2.0.0-rc.15",
57-
"workerd": "^1.20250311.0"
57+
"workerd": "^1.20250320.0"
5858
},
5959
"peerDependenciesMeta": {
6060
"workerd": {

‎packages/unenv-preset/src/runtime/node/tls.ts

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import {
2-
checkServerIdentity,
32
CLIENT_RENEG_LIMIT,
43
CLIENT_RENEG_WINDOW,
54
convertALPNProtocols,
6-
createSecureContext,
75
createSecurePair,
86
createServer,
97
DEFAULT_CIPHERS,
@@ -12,17 +10,14 @@ import {
1210
DEFAULT_MIN_VERSION,
1311
getCiphers,
1412
rootCertificates,
15-
SecureContext,
1613
Server,
1714
} from "unenv/node/tls";
1815
import type nodeTls from "node:tls";
1916

2017
export {
21-
checkServerIdentity,
2218
CLIENT_RENEG_LIMIT,
2319
CLIENT_RENEG_WINDOW,
2420
convertALPNProtocols,
25-
createSecureContext,
2621
createSecurePair,
2722
createServer,
2823
DEFAULT_CIPHERS,
@@ -31,14 +26,20 @@ export {
3126
DEFAULT_MIN_VERSION,
3227
getCiphers,
3328
rootCertificates,
34-
SecureContext,
3529
Server,
3630
} from "unenv/node/tls";
3731

3832
const workerdTls = process.getBuiltinModule("node:tls");
3933

4034
// Natively implemented in workerd
41-
export const { connect, TLSSocket } = workerdTls;
35+
export const {
36+
checkServerIdentity,
37+
connect,
38+
createSecureContext,
39+
// @ts-expect-error Node typings wrongly declare `SecureContext` as an interface
40+
SecureContext,
41+
TLSSocket,
42+
} = workerdTls;
4243

4344
export default {
4445
CLIENT_RENEG_LIMIT,

‎pnpm-lock.yaml

+2-60
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
Please sign in to comment.