Skip to content

Commit cb22f5f

Browse files
anonrigvicb
andauthored
remove node:util and node:sys polyfills (#10430)
Co-authored-by: Victor Berchet <[email protected]>
1 parent c0fad5f commit cb22f5f

File tree

4 files changed

+40
-148
lines changed

4 files changed

+40
-148
lines changed

.changeset/plain-views-occur.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+
Remove `node:util` and `node:sys` polyfills which are now fully implemented in workerd

packages/unenv-preset/src/preset.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,18 @@ const nativeModules = [
3636
"stream/promises",
3737
"stream/web",
3838
"string_decoder",
39+
"sys",
3940
"timers",
4041
"timers/promises",
4142
"tls",
4243
"url",
44+
"util",
4345
"util/types",
4446
"zlib",
4547
];
4648

4749
// Modules implemented via a mix of workerd APIs and polyfills.
48-
const hybridModules = ["console", "process", "util"];
50+
const hybridModules = ["console", "process"];
4951

5052
/**
5153
* Creates the Cloudflare preset for the given compatibility date and compatibility flags
@@ -102,10 +104,6 @@ export function getCloudflarePreset({
102104
])
103105
),
104106

105-
// The `node:sys` module is just a deprecated alias for `node:util` which we implemented using a hybrid polyfill
106-
sys: "@cloudflare/unenv-preset/node/util",
107-
"node:sys": "@cloudflare/unenv-preset/node/util",
108-
109107
// `hybridNodeCompatModules` are implemented by the cloudflare preset.
110108
...Object.fromEntries(
111109
dynamicHybridModules.flatMap((m) => [

packages/unenv-preset/src/runtime/node/util.ts

Lines changed: 0 additions & 143 deletions
This file was deleted.

packages/wrangler/e2e/unenv-preset/worker/index.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,11 @@ export const WorkerdTests: Record<string, () => void> = {
144144
"stream/promises",
145145
"stream/web",
146146
"string_decoder",
147+
"sys",
147148
"timers",
148149
"timers/promises",
149150
"url",
151+
"util",
150152
"util/types",
151153
"zlib",
152154
];
@@ -162,6 +164,36 @@ export const WorkerdTests: Record<string, () => void> = {
162164
assert.strictEqual(types.isAnyArrayBuffer(new ArrayBuffer(0)), true);
163165
assert.strictEqual(util.isArray([]), true);
164166
assert.strictEqual(util.isDeepStrictEqual(0, 0), true);
167+
168+
// @ts-expect-error `_errnoException` is not part of the public API
169+
assert.strictEqual(typeof util._errnoException, "function");
170+
// @ts-expect-error `_exceptionWithHostPort` is not part of the public API
171+
assert.strictEqual(typeof util._exceptionWithHostPort, "function");
172+
173+
const removeEolV23 = getRuntimeFlagValue("remove_nodejs_compat_eol_v23");
174+
175+
if (removeEolV23) {
176+
assert.strictEqual(util.isBoolean, undefined);
177+
assert.strictEqual(util.isBuffer, undefined);
178+
assert.strictEqual(util.isDate, undefined);
179+
assert.strictEqual(util.isError, undefined);
180+
} else {
181+
assert.strictEqual(util.isBoolean(true), true);
182+
assert.strictEqual(util.isBuffer(true), false);
183+
assert.strictEqual(util.isBuffer(Buffer.from("hello world")), true);
184+
assert.strictEqual(util.isDate(new Date()), true);
185+
assert.strictEqual(util.isError(new Error()), true);
186+
assert.strictEqual(util.isFunction(new Error()), false);
187+
assert.strictEqual(util.isNull(null), true);
188+
assert.strictEqual(util.isNullOrUndefined(null), true);
189+
assert.strictEqual(util.isNumber(1), true);
190+
assert.strictEqual(util.isObject({}), true);
191+
assert.strictEqual(util.isPrimitive(true), true);
192+
assert.strictEqual(util.isRegExp(true), false);
193+
assert.strictEqual(util.isString(true), false);
194+
assert.strictEqual(util.isSymbol(true), false);
195+
assert.strictEqual(util.isUndefined(undefined), true);
196+
}
165197
},
166198

167199
async testPath() {

0 commit comments

Comments
 (0)