Skip to content

Commit 590b148

Browse files
committed
add node:timers and node:util to unenv-preset
1 parent 6c2e943 commit 590b148

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

.changeset/popular-pigs-glow.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@cloudflare/unenv-preset": patch
3+
---
4+
5+
Removes node:net and node:timers from polyfills

packages/unenv-preset/src/preset.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { Preset } from "unenv";
44
// Built-in APIs provided by workerd.
55
// https://developers.cloudflare.com/workers/runtime-apis/nodejs/
66
// https://github.com/cloudflare/workerd/tree/main/src/node
7-
// Last checked: 2024-10-22
7+
// Last checked: 2025-01-24
88
const cloudflareNodeCompatModules = [
99
"_stream_duplex",
1010
"_stream_passthrough",
@@ -18,6 +18,8 @@ const cloudflareNodeCompatModules = [
1818
"dns",
1919
"dns/promises",
2020
"events",
21+
"net",
22+
"net/promises",
2123
"path",
2224
"path/posix",
2325
"path/win32",
@@ -27,6 +29,8 @@ const cloudflareNodeCompatModules = [
2729
"stream/promises",
2830
"stream/web",
2931
"string_decoder",
32+
"timers",
33+
"timers/promises",
3034
"url",
3135
"util/types",
3236
"zlib",
@@ -39,7 +43,6 @@ const hybridNodeCompatModules = [
3943
"crypto",
4044
"module",
4145
"process",
42-
"timers",
4346
"util",
4447
];
4548

packages/unenv-preset/tests/worker/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export const TESTS = {
1010
testPath,
1111
testDns,
1212
testTimers,
13+
testNet,
1314
};
1415

1516
export default {
@@ -86,6 +87,8 @@ async function testModules() {
8687
"dns",
8788
"dns/promises",
8889
"events",
90+
"net",
91+
"net/promises",
8992
"path",
9093
"path/posix",
9194
"path/win32",
@@ -95,6 +98,8 @@ async function testModules() {
9598
"stream/promises",
9699
"stream/web",
97100
"string_decoder",
101+
"timers",
102+
"timers/promises",
98103
"url",
99104
"util/types",
100105
"zlib",
@@ -150,3 +155,10 @@ async function testTimers() {
150155
(timers as any).active(timeout);
151156
timers.clearTimeout(timeout);
152157
}
158+
159+
export async function testNet() {
160+
const net = await import("node:net");
161+
assert.strictEqual(typeof net, "object");
162+
assert.strictEqual(typeof net.createConnection, "function");
163+
assert.throws(() => net.createServer(), /not implemented/);
164+
}

0 commit comments

Comments
 (0)