Skip to content

Commit 31ecfeb

Browse files
authored
Use the native node:constants module (#10514)
1 parent 4851955 commit 31ecfeb

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

.changeset/brave-wings-behave.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"@cloudflare/unenv-preset": patch
3+
---
4+
5+
Use the native `node:constants` module
6+
7+
The native `node:constants` module was implemented in [this PR](https://github.com/cloudflare/workerd/pull/4759)
8+
It was released as part of workerd [1.20250813.0](https://github.com/cloudflare/workerd/releases/tag/v1.20250813.0)

packages/unenv-preset/src/preset.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import type { Preset } from "unenv";
66
// https://developers.cloudflare.com/workers/runtime-apis/nodejs/
77
// https://github.com/cloudflare/workerd/tree/main/src/node
88
//
9-
// Last checked: 2025-01-24
10-
//
119
// NOTE: Please sync any changes to `testNodeCompatModules`.
1210
const nativeModules = [
1311
"_stream_duplex",
@@ -21,6 +19,7 @@ const nativeModules = [
2119
"assert/strict",
2220
"async_hooks",
2321
"buffer",
22+
"constants",
2423
"diagnostics_channel",
2524
"dns",
2625
"dns/promises",

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ export const WorkerdTests: Record<string, () => void> = {
107107
"assert/strict",
108108
"async_hooks",
109109
"buffer",
110+
"constants",
110111
"diagnostics_channel",
111112
"dns",
112113
"dns/promises",
@@ -435,4 +436,12 @@ export const WorkerdTests: Record<string, () => void> = {
435436
// @ts-expect-error TS2339 Invalid node/types.
436437
assert.strictEqual(typeof module._pathCache, "object");
437438
},
439+
440+
async testConstants() {
441+
const constants = await import("node:constants");
442+
443+
assert.deepStrictEqual(constants.O_RDONLY, 0);
444+
assert.deepStrictEqual(constants.O_WRONLY, 1);
445+
assert.deepStrictEqual(constants.O_RDWR, 2);
446+
},
438447
};

0 commit comments

Comments
 (0)