Skip to content

Commit

Permalink
refactor(node/util/types): make util/types a nodejs_compat module
Browse files Browse the repository at this point in the history
  • Loading branch information
anonrig committed Oct 11, 2024
1 parent b1eed1a commit 4bc9c29
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 114 deletions.
2 changes: 1 addition & 1 deletion src/presets/cloudflare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const cloudflareNodeCompatModules = [
"stream/promises",
"stream/web",
"string_decoder",
"util/types",
"zlib",
];

Expand All @@ -33,7 +34,6 @@ const hybridNodeCompatModules = [
"process",
"timers",
"util",
"util/types",
];

const cloudflarePreset: Preset = {
Expand Down
8 changes: 1 addition & 7 deletions src/runtime/node/util/$cloudflare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ import {
isUndefined,
parseEnv,
styleText,
types as unenvUtilTypes,
} from "./index";

const workerdUtil = process.getBuiltinModule("node:util");
Expand Down Expand Up @@ -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 {
/**
Expand Down
106 changes: 0 additions & 106 deletions src/runtime/node/util/types/$cloudflare.ts

This file was deleted.

10 changes: 10 additions & 0 deletions test/workerd/tests.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,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);
},
};

0 comments on commit 4bc9c29

Please sign in to comment.