Skip to content

Commit

Permalink
Use builtin implementation for isArray and isDeepStrictEqual
Browse files Browse the repository at this point in the history
  • Loading branch information
vicb committed Feb 3, 2025
1 parent 59c7c8e commit 82c6dd8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/lazy-windows-provide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cloudflare/unenv-preset": patch
---

Use builtin implementation for isArray and isDeepStrictEqual
18 changes: 8 additions & 10 deletions packages/unenv-preset/src/runtime/node/util/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ import {
_exceptionWithHostPort,
getSystemErrorMap,
getSystemErrorName,
isArray,
isBoolean,
isBuffer,
isDate,
isDeepStrictEqual,
isError,
isFunction,
isNull,
Expand All @@ -30,11 +28,9 @@ export {
_exceptionWithHostPort,
getSystemErrorMap,
getSystemErrorName,
isArray,
isBoolean,
isBuffer,
isDate,
isDeepStrictEqual,
isError,
isFunction,
isNull,
Expand Down Expand Up @@ -71,6 +67,8 @@ export const {
getCallSite,
inherits,
inspect,
isArray,
isDeepStrictEqual,
log,
parseArgs,
promisify,
Expand All @@ -91,11 +89,9 @@ export default {
_exceptionWithHostPort,
getSystemErrorMap,
getSystemErrorName,
isArray,
isBoolean,
isBuffer,
isDate,
isDeepStrictEqual,
isError,
isFunction,
isNull,
Expand All @@ -113,10 +109,6 @@ export default {
/**
* manually unroll workerd-polyfilled-symbols to make it tree-shakeable
*/
MIMEParams,
MIMEType,
TextDecoder,
TextEncoder,
_extend,
aborted,
callbackify,
Expand All @@ -128,10 +120,16 @@ export default {
getCallSite,
inherits,
inspect,
isArray,
isDeepStrictEqual,
log,
MIMEParams,
MIMEType,
parseArgs,
promisify,
stripVTControlCharacters,
TextDecoder,
TextEncoder,
toUSVString,
transferableAbortController,
transferableAbortSignal,
Expand Down
5 changes: 4 additions & 1 deletion packages/unenv-preset/tests/worker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,12 @@ async function testNodeCompatModules() {
}

async function testUtilImplements() {
const { types } = await import("node:util");
const util = await import("node:util");
const { types } = util;
assert.strictEqual(types.isExternal("hello world"), false);
assert.strictEqual(types.isAnyArrayBuffer(new ArrayBuffer(0)), true);
assert.strictEqual(util.isArray([]), true);
assert.strictEqual(util.isDeepStrictEqual(0, 0), true);
}

async function testPath() {
Expand Down

0 comments on commit 82c6dd8

Please sign in to comment.