feat(unenv-preset): add support for native node:dgram module#11701
feat(unenv-preset): add support for native node:dgram module#11701
Conversation
🦋 Changeset detectedLatest commit: 919cf40 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
|
Claude finished @petebacondarwin's task —— View job Changeset Review✅ All changesets look good The changeset
Note: The reviewer (vicb) suggested simplifying the changeset description to remove explanatory content about what dgram is and examples, as they felt it was misleading without the |
create-cloudflare
@cloudflare/kv-asset-handler
miniflare
@cloudflare/pages-shared
@cloudflare/unenv-preset
@cloudflare/vite-plugin
@cloudflare/vitest-pool-workers
@cloudflare/workers-editor-shared
@cloudflare/workers-utils
wrangler
commit: |
67aa169 to
b2fa5db
Compare
|
See cloudflare/workerd#5729 for update to workerd to avoid breaking changes |
|
Thanks for the update! Once cloudflare/workerd#5729 lands, the breaking change concern will be resolved since workerd's dgram implementation will return no-ops instead of throwing |
b2fa5db to
73b3129
Compare
73b3129 to
0cd1038
Compare
| "disable_nodejs_dgram_module" | ||
| ); | ||
|
|
||
| const enabledByFlag = compatibilityFlags.includes( |
vicb
left a comment
There was a problem hiding this comment.
Looks good once we test for experimental as well.
Thanks Pete!
|
@petebacondarwin could you please bump the workerd peer dep to whatever workerd first get your corresponding PR? |
3db3bce to
2dfa363
Compare
| To enable the native dgram module, add the following to your `wrangler.jsonc`: | ||
|
|
||
| ```jsonc | ||
| { | ||
| "compatibility_flags": ["experimental", "enable_nodejs_dgram_module"], | ||
| } | ||
| ``` |
There was a problem hiding this comment.
Maybe drop this, it is misleading without the nodejs_compat flag
vicb
left a comment
There was a problem hiding this comment.
LGTM - maybe simplify the changeset?
c5062f4 to
8f06777
Compare
|
rebased on main |
d66d5df to
48f62e1
Compare
|
Just rebased + fixed lock file |
Add getDgramOverrides() function to enable native dgram module support when the enable_nodejs_dgram_module compatibility flag is set. This feature is experimental and requires both the enable_nodejs_dgram_module and experimental compatibility flags to be enabled. Includes E2E tests for enable/disable flag behavior. Co-Authored-By: pbacondarwin@cloudflare.com <pete@bacondarwin.com>
Co-Authored-By: pbacondarwin@cloudflare.com <pete@bacondarwin.com>
Co-Authored-By: pbacondarwin@cloudflare.com <pete@bacondarwin.com>
Add getDgramOverrides() function to enable native dgram module support when the enable_nodejs_dgram_module compatibility flag is set. This feature is experimental and requires both the enable_nodejs_dgram_module and experimental compatibility flags to be enabled. Includes E2E tests for enable/disable flag behavior. Co-Authored-By: pbacondarwin@cloudflare.com <pete@bacondarwin.com>
Co-Authored-By: pbacondarwin@cloudflare.com <pete@bacondarwin.com>
Co-Authored-By: pbacondarwin@cloudflare.com <pete@bacondarwin.com>
Co-Authored-By: pbacondarwin@cloudflare.com <pete@bacondarwin.com>
48f62e1 to
919cf40
Compare
Similar to #10621 (native vm module support), this PR adds support for the native
node:dgrammodule when theenable_nodejs_dgram_modulecompatibility flag is enabled.Since dgram is marked as
$experimentalin workerd with no$impliedByAfterDate, this feature requires both theenable_nodejs_dgram_moduleandexperimentalcompatibility flags to be set.Updates since last revision
enabledByFlagto also check for theexperimentalcompatibility flag, ensuring the native module is only enabled when both flags are present (per reviewer feedback)^1.20251221.0which includes the dgram fix from cloudflare/workerd#5729Implementation Comparison
The three dgram implementations differ significantly:
Node.js (full implementation): Complete UDP socket support with native bindings (
udp_wrap), proper state management, event emission, multicast/broadcast support, and integration with diagnostics_channel and async_hooks.workerd (non-functional stub): Exports the expected API surface (
Socket,createSocket) but core methods throwERR_METHOD_NOT_IMPLEMENTED. Configuration methods likesetBroadcast(),setTTL()are no-ops. This is intentional as UDP is not supported in the Workers runtime.unenv (soft stub polyfill): Returns a concrete
Socketinstance so code paths don't immediately throw. Methods are mostly chainable no-ops returning placeholder values (e.g.,getRecvBufferSize()returns 100,000).When the native module is enabled, workerd's implementation is used instead of unenv's polyfill.
When enabling the native dgram module, code that previously relied on unenv's silent no-op behavior may break because workerd throws errors instead:
createSocket()SocketinstanceERR_METHOD_NOT_IMPLEMENTEDSocket()constructorSocketinstanceERR_METHOD_NOT_IMPLEMENTEDbind()this(no-op)ERR_METHOD_NOT_IMPLEMENTEDconnect()ERR_METHOD_NOT_IMPLEMENTEDsend()ERR_METHOD_NOT_IMPLEMENTEDclose()this(no-op)ERR_METHOD_NOT_IMPLEMENTEDThis is opt-in via the experimental flag, so existing code is unaffected unless users explicitly enable
enable_nodejs_dgram_module.Human Review Checklist
experimentalflag as requiredenabledByFlagchecks for bothenable_nodejs_dgram_moduleANDexperimentalflagsDevin PR requested by @petebacondarwin
Link to Devin run: https://app.devin.ai/sessions/b61a9f009eec4b03850a418e63f16687