Skip to content
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
9 changes: 9 additions & 0 deletions .changeset/cold-parents-guess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@cloudflare/unenv-preset": patch
"wrangler": patch
---

Use more workerd native modules

Node modules `punycode`, `trace_events`, `cluster`, `wasi`, and `domains` will be used when enabled
via a compatibility flag or by default when the compatibility date is greater or equal to 2025-12-04.
2 changes: 1 addition & 1 deletion packages/unenv-preset/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
},
"peerDependencies": {
"unenv": "2.0.0-rc.24",
"workerd": "^1.20251106.1"
"workerd": "^1.20251125.0"
},
"peerDependenciesMeta": {
"workerd": {
Expand Down
70 changes: 35 additions & 35 deletions packages/unenv-preset/src/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,12 +325,11 @@ function getFsOverrides({
* Returns the overrides for `node:punycode` (unenv or workerd)
*
* The native punycode implementation:
* - is experimental
* - is enabled starting from 2025-12-04
* - can be enabled with the "enable_nodejs_punycode_module" flag
* - can be disabled with the "disable_nodejs_punycode_module" flag
*/
function getPunycodeOverrides({
// eslint-disable-next-line unused-imports/no-unused-vars
compatibilityDate,
compatibilityFlags,
}: {
Expand All @@ -341,12 +340,13 @@ function getPunycodeOverrides({
"disable_nodejs_punycode_module"
);

// TODO: add `enabledByDate` when a date is defined in workerd
const enabledByFlag =
compatibilityFlags.includes("enable_nodejs_punycode_module") &&
compatibilityFlags.includes("experimental");
const enabledByFlag = compatibilityFlags.includes(
"enable_nodejs_punycode_module"
);

const enabled = enabledByFlag && !disabledByFlag;
const enabledByDate = compatibilityDate >= "2025-12-04";

const enabled = (enabledByFlag || enabledByDate) && !disabledByFlag;

return enabled
? {
Expand All @@ -363,12 +363,11 @@ function getPunycodeOverrides({
* Returns the overrides for `node:cluster` (unenv or workerd)
*
* The native cluster implementation:
* - is experimental
* - is enabled starting from 2025-12-04
* - can be enabled with the "enable_nodejs_cluster_module" flag
* - can be disabled with the "disable_nodejs_cluster_module" flag
*/
function getClusterOverrides({
// eslint-disable-next-line unused-imports/no-unused-vars
compatibilityDate,
compatibilityFlags,
}: {
Expand All @@ -379,12 +378,13 @@ function getClusterOverrides({
"disable_nodejs_cluster_module"
);

// TODO: add `enabledByDate` when a date is defined in workerd
const enabledByFlag =
compatibilityFlags.includes("enable_nodejs_cluster_module") &&
compatibilityFlags.includes("experimental");
const enabledByFlag = compatibilityFlags.includes(
"enable_nodejs_cluster_module"
);

const enabledByDate = compatibilityDate >= "2025-12-04";

const enabled = enabledByFlag && !disabledByFlag;
const enabled = (enabledByFlag || enabledByDate) && !disabledByFlag;

return enabled
? {
Expand All @@ -401,12 +401,11 @@ function getClusterOverrides({
* Returns the overrides for `node:trace_events` (unenv or workerd)
*
* The native trace_events implementation:
* - is experimental
* - is enabled starting from 2025-12-04
* - can be enabled with the "enable_nodejs_trace_events_module" flag
* - can be disabled with the "disable_nodejs_trace_events_module" flag
*/
function getTraceEventsOverrides({
// eslint-disable-next-line unused-imports/no-unused-vars
compatibilityDate,
compatibilityFlags,
}: {
Expand All @@ -417,12 +416,13 @@ function getTraceEventsOverrides({
"disable_nodejs_trace_events_module"
);

// TODO: add `enabledByDate` when a date is defined in workerd
const enabledByFlag =
compatibilityFlags.includes("enable_nodejs_trace_events_module") &&
compatibilityFlags.includes("experimental");
const enabledByFlag = compatibilityFlags.includes(
"enable_nodejs_trace_events_module"
);

const enabledByDate = compatibilityDate >= "2025-12-04";

const enabled = enabledByFlag && !disabledByFlag;
const enabled = (enabledByFlag || enabledByDate) && !disabledByFlag;

return enabled
? {
Expand All @@ -439,12 +439,11 @@ function getTraceEventsOverrides({
* Returns the overrides for `node:domain` (unenv or workerd)
*
* The native domain implementation:
* - is experimental
* - is enabled starting from 2025-12-04
* - can be enabled with the "enable_nodejs_domain_module" flag
* - can be disabled with the "disable_nodejs_domain_module" flag
*/
function getDomainOverrides({
// eslint-disable-next-line unused-imports/no-unused-vars
compatibilityDate,
compatibilityFlags,
}: {
Expand All @@ -455,12 +454,13 @@ function getDomainOverrides({
"disable_nodejs_domain_module"
);

// TODO: add `enabledByDate` when a date is defined in workerd
const enabledByFlag =
compatibilityFlags.includes("enable_nodejs_domain_module") &&
compatibilityFlags.includes("experimental");
const enabledByFlag = compatibilityFlags.includes(
"enable_nodejs_domain_module"
);

const enabledByDate = compatibilityDate >= "2025-12-04";

const enabled = enabledByFlag && !disabledByFlag;
const enabled = (enabledByFlag || enabledByDate) && !disabledByFlag;

return enabled
? {
Expand All @@ -477,12 +477,11 @@ function getDomainOverrides({
* Returns the overrides for `node:wasi` (unenv or workerd)
*
* The native wasi implementation:
* - is experimental
* - is enabled starting from 2025-12-04
* - can be enabled with the "enable_nodejs_wasi_module" flag
* - can be disabled with the "disable_nodejs_wasi_module" flag
*/
function getWasiOverrides({
// eslint-disable-next-line unused-imports/no-unused-vars
compatibilityDate,
compatibilityFlags,
}: {
Expand All @@ -493,12 +492,13 @@ function getWasiOverrides({
"disable_nodejs_wasi_module"
);

// TODO: add `enabledByDate` when a date is defined in workerd
const enabledByFlag =
compatibilityFlags.includes("enable_nodejs_wasi_module") &&
compatibilityFlags.includes("experimental");
const enabledByFlag = compatibilityFlags.includes(
"enable_nodejs_wasi_module"
);

const enabled = enabledByFlag && !disabledByFlag;
const enabledByDate = compatibilityDate >= "2025-12-04";

const enabled = (enabledByFlag || enabledByDate) && !disabledByFlag;

return enabled
? {
Expand Down
43 changes: 20 additions & 23 deletions packages/wrangler/e2e/unenv-preset/preset.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,90 +236,87 @@ const localTestConfigs: TestConfig[] = [
],
// node:punycode
[
// TODO: add test for disabled by date (no date defined yet)
// TODO: add test for enabled by date (no date defined yet)
// TODO: add test for disabled by date (2025-12-04)
// TODO: add test for enabled by date (2025-12-04)
{
name: "punycode enabled by flag",
compatibilityDate: "2024-09-23",
compatibilityFlags: ["enable_nodejs_punycode_module", "experimental"],
compatibilityFlags: ["enable_nodejs_punycode_module"],
expectRuntimeFlags: {
enable_nodejs_punycode_module: true,
},
},
// TODO: update the date past the default enable date (when defined)
// TODO: update the date past the default enable date (2025-12-04)
{
name: "punycode disabled by flag",
compatibilityDate: "2024-09-23",
compatibilityFlags: ["disable_nodejs_punycode_module", "experimental"],
compatibilityFlags: ["disable_nodejs_punycode_module"],
expectRuntimeFlags: {
enable_nodejs_punycode_module: false,
},
},
],
// node:cluster
[
// TODO: add test for disabled by date (no date defined yet)
// TODO: add test for enabled by date (no date defined yet)
// TODO: add test for disabled by date (2025-12-04)
// TODO: add test for enabled by date (2025-12-04)
{
name: "cluster enabled by flag",
compatibilityDate: "2024-09-23",
compatibilityFlags: ["enable_nodejs_cluster_module", "experimental"],
compatibilityFlags: ["enable_nodejs_cluster_module"],
expectRuntimeFlags: {
enable_nodejs_cluster_module: true,
},
},
// TODO: update the date past the default enable date (when defined)
// TODO: update the date past the default enable date (2025-12-04)
{
name: "cluster disabled by flag",
compatibilityDate: "2024-09-23",
compatibilityFlags: ["disable_nodejs_cluster_module", "experimental"],
compatibilityFlags: ["disable_nodejs_cluster_module"],
expectRuntimeFlags: {
enable_nodejs_cluster_module: false,
},
},
],
// trace_events
[
// TODO: add test for disabled by date (no date defined yet)
// TODO: add test for enabled by date (no date defined yet)
// TODO: add test for disabled by date (2025-12-04)
// TODO: add test for enabled by date (2025-12-04)
{
name: "trace_events enabled by flag",
compatibilityDate: "2024-09-23",
compatibilityFlags: ["enable_nodejs_trace_events_module", "experimental"],
compatibilityFlags: ["enable_nodejs_trace_events_module"],
expectRuntimeFlags: {
enable_nodejs_trace_events_module: true,
},
},
// TODO: update the date past the default enable date (when defined)
// TODO: update the date past the default enable date (2025-12-04)
{
name: "trace_events disabled by flag",
compatibilityDate: "2024-09-23",
compatibilityFlags: [
"disable_nodejs_trace_events_module",
"experimental",
],
compatibilityFlags: ["disable_nodejs_trace_events_module"],
expectRuntimeFlags: {
enable_nodejs_trace_events_module: false,
},
},
],
// domain
[
// TODO: add test for disabled by date (no date defined yet)
// TODO: add test for enabled by date (no date defined yet)
// TODO: add test for disabled by date (2025-12-04)
// TODO: add test for enabled by date (2025-12-04)
{
name: "domain enabled by flag",
compatibilityDate: "2024-09-23",
compatibilityFlags: ["enable_nodejs_domain_module", "experimental"],
compatibilityFlags: ["enable_nodejs_domain_module"],
expectRuntimeFlags: {
enable_nodejs_domain_module: true,
},
},
// TODO: update the date past the default enable date (when defined)
// TODO: update the date past the default enable date (2025-12-04)
{
name: "domain disabled by flag",
compatibilityDate: "2024-09-23",
compatibilityFlags: ["disable_nodejs_domain_module", "experimental"],
compatibilityFlags: ["disable_nodejs_domain_module"],
expectRuntimeFlags: {
enable_nodejs_domain_module: false,
},
Expand Down
Loading
Loading