diff --git a/src/presets/cloudflare.ts b/src/presets/cloudflare.ts index 202f58a..dba274a 100644 --- a/src/presets/cloudflare.ts +++ b/src/presets/cloudflare.ts @@ -19,6 +19,7 @@ const cloudflareNodeCompatModules = [ "stream/promises", "stream/web", "string_decoder", + "util/types", "zlib", ]; @@ -33,7 +34,6 @@ const hybridNodeCompatModules = [ "process", "timers", "util", - "util/types", ]; const cloudflarePreset: Preset = { diff --git a/src/runtime/node/util/$cloudflare.ts b/src/runtime/node/util/$cloudflare.ts index 6b48ce6..43b60dc 100644 --- a/src/runtime/node/util/$cloudflare.ts +++ b/src/runtime/node/util/$cloudflare.ts @@ -49,7 +49,6 @@ import { isUndefined, parseEnv, styleText, - types as unenvUtilTypes, } from "./index"; const workerdUtil = process.getBuiltinModule("node:util"); @@ -81,12 +80,7 @@ export const { transferableAbortSignal, } = workerdUtil; -// TODO(cloudflare): we should just implement this in workerd and drop this special case. -export const types = { - ...workerdUtil.types, - isExternal: unenvUtilTypes.isExternal, - isAnyArrayBuffer: workerdUtil.types.isAnyArrayBuffer, -} satisfies typeof nodeUtil.types; +export const types = workerdUtil.types; export default { /** diff --git a/src/runtime/node/util/internal/types.ts b/src/runtime/node/util/internal/types.ts index d357674..cdb71f8 100644 --- a/src/runtime/node/util/internal/types.ts +++ b/src/runtime/node/util/internal/types.ts @@ -1,9 +1,7 @@ import type utilTypes from "node:util/types"; import { notImplemented } from "../../../_internal/utils"; -export const isExternal = notImplemented( - "util.types.isExternal", -); +export const isExternal: typeof utilTypes.isExternal = (_obj) => false; export const isDate: typeof utilTypes.isDate = (val): val is Date => val instanceof Date; diff --git a/src/runtime/node/util/types/$cloudflare.ts b/src/runtime/node/util/types/$cloudflare.ts deleted file mode 100644 index a59d399..0000000 --- a/src/runtime/node/util/types/$cloudflare.ts +++ /dev/null @@ -1,106 +0,0 @@ -import type nodeUtilTypes from "node:util/types"; - -// TODO(cloudflare): we should just implement this in workerd and drop this whole file. -export { isExternal } from "./index"; - -import { isExternal } from "./index"; - -const workerdUtil = process.getBuiltinModule("node:util"); - -export const { - isAnyArrayBuffer, - isArgumentsObject, - isArrayBuffer, - isArrayBufferView, - isAsyncFunction, - isBigInt64Array, - // @ts-expect-error missing types? - isBigIntObject, - isBigUint64Array, - isBooleanObject, - isBoxedPrimitive, - isCryptoKey, - isDataView, - isDate, - isFloat32Array, - isFloat64Array, - isGeneratorFunction, - isGeneratorObject, - isInt16Array, - isInt32Array, - isInt8Array, - isKeyObject, - isMap, - isMapIterator, - isModuleNamespaceObject, - isNativeError, - isNumberObject, - isPromise, - isProxy, - isRegExp, - isSet, - isSetIterator, - isSharedArrayBuffer, - isStringObject, - isSymbolObject, - isTypedArray, - isUint16Array, - isUint32Array, - isUint8Array, - isUint8ClampedArray, - isWeakMap, - isWeakSet, -} = workerdUtil.types; - -export default { - /** - * manually unroll unenv-polyfilled-symbols to make it tree-shakeable - */ - isExternal, - - /** - * manually unroll workerd-polyfilled-symbols to make it tree-shakeable - */ - isAnyArrayBuffer, - isArgumentsObject, - isArrayBuffer, - isArrayBufferView, - isAsyncFunction, - isBigInt64Array, - // @ts-expect-error undocumented public API - isBigIntObject, - isBigUint64Array, - isBooleanObject, - isBoxedPrimitive, - isCryptoKey, - isDataView, - isDate, - isFloat32Array, - isFloat64Array, - isGeneratorFunction, - isGeneratorObject, - isInt16Array, - isInt32Array, - isInt8Array, - isKeyObject, - isMap, - isMapIterator, - isModuleNamespaceObject, - isNativeError, - isNumberObject, - isPromise, - isProxy, - isRegExp, - isSet, - isSetIterator, - isSharedArrayBuffer, - isStringObject, - isSymbolObject, - isTypedArray, - isUint16Array, - isUint32Array, - isUint8Array, - isUint8ClampedArray, - isWeakMap, - isWeakSet, -} satisfies typeof nodeUtilTypes; diff --git a/test/workerd/tests.mjs b/test/workerd/tests.mjs index aeda375..4eba227 100644 --- a/test/workerd/tests.mjs +++ b/test/workerd/tests.mjs @@ -62,3 +62,13 @@ export const buffer_implements = { assert.ok(new buffer.Blob([])); }, }; + +// --- node:util + +export const util_implements = { + async test() { + const { types } = await import("unenv/runtime/node/util"); + assert.strictEqual(types.isExternal("hello world"), false); + assert.strictEqual(types.isAnyArrayBuffer(new ArrayBuffer(0)), true); + }, +};