Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(cloudflare): make node:util/types a nodejs_compat module #329

Merged
merged 1 commit into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
pi0 marked this conversation as resolved.
Show resolved Hide resolved
"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
4 changes: 1 addition & 3 deletions src/runtime/node/util/internal/types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import type utilTypes from "node:util/types";
import { notImplemented } from "../../../_internal/utils";

export const isExternal = notImplemented<typeof utilTypes.isExternal>(
"util.types.isExternal",
);
export const isExternal: typeof utilTypes.isExternal = (_obj) => false;

export const isDate: typeof utilTypes.isDate = (val): val is Date =>
val instanceof Date;
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);
pi0 marked this conversation as resolved.
Show resolved Hide resolved
assert.strictEqual(types.isAnyArrayBuffer(new ArrayBuffer(0)), true);
},
};