feat(unenv-preset): add support for native node:readline module#11734
feat(unenv-preset): add support for native node:readline module#11734petebacondarwin merged 4 commits intomainfrom
Conversation
🤖 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:
|
🦋 Changeset detectedLatest commit: aa0af81 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 |
|
Claude finished @petebacondarwin's task —— View job Changeset ReviewReviewing the changeset file for this PR... Todo List:
✅ All changesets look good The changeset properly:
|
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: |
8167373 to
735fa35
Compare
|
The promises aspect of this is blocked on cloudflare/workerd#5740 |
|
Thanks for confirming! I've updated the PR to remove Once cloudflare/workerd#5740 lands and a new workerd version is released, we can add |
|
The fix in workerd has been released at version v1.20251223.0. Please rebase on main, reinstate the promises entry point stuff and bump the peer dependency of workerd in the unenv-preset to 1.20251223.0. |
6508943 to
989c5d2
Compare
|
Urgh looks like there is another potential breaking change to mitigate... |
|
Could you clarify which breaking change you're referring to? Is it related to I can update the PR description's breaking change table to include any additional APIs that throw in workerd but are no-ops in unenv. |
|
I've updated the PR description with a more comprehensive breaking change table covering both
Since this is gated behind both |
|
Please rebase and fix conflicts. |
1f27c3b to
6288cd0
Compare
Change the readline Interface class and the readline/promises Interface and Readline classes to be no-op stubs instead of throwing errors. This matches the behavior of unenv's readline implementation, which allows code that depends on readline to work without crashing even though the functionality is not fully implemented. Methods now return sensible defaults (empty strings, zero values, etc.) instead of throwing ERR_METHOD_NOT_IMPLEMENTED errors. Fixes compatibility with cloudflare/workers-sdk#11734
dead525 to
7cb7b54
Compare
Change the readline Interface class and the readline/promises Interface and Readline classes to be no-op stubs instead of throwing errors. This matches the behavior of unenv's readline implementation, which allows code that depends on readline to work without crashing even though the functionality is not fully implemented. Methods now return sensible defaults (empty strings, zero values, etc.) instead of throwing ERR_METHOD_NOT_IMPLEMENTED errors. Fixes compatibility with cloudflare/workers-sdk#11734
|
Blocked on cloudflare/workerd#6016 |
Co-Authored-By: pbacondarwin@cloudflare.com <pete@bacondarwin.com>
7cb7b54 to
10d1d2f
Compare
| "peerDependencies": { | ||
| "unenv": "2.0.0-rc.24", | ||
| "workerd": "^1.20260214.0" | ||
| "workerd": "^1.20260218.0" |
There was a problem hiding this comment.
This bump is required to include the fix to the Interface class in workerd: cloudflare/workerd#6016
Now merged and released. Unblocking this PR |
Similar to #11733 (native inspector module support), this PR adds support for the native
node:readlineandnode:readline/promisesmodules when theenable_nodejs_readline_modulecompatibility flag is enabled.Since readline is marked as
$experimentalin workerd with no$impliedByAfterDate, this feature requires both theenable_nodejs_readline_moduleandexperimentalcompatibility flags to be set.Updates since last revision
getReadlineOverrides()correctly requires bothenable_nodejs_readline_moduleANDexperimentalflagsreadline/promisesin nativeModules now that workerd 1.20251223.0 includes the fix from fix promises export for readline & inspector workerd#5740testReadlinePromises()test for thenode:readline/promisesmoduleImplementation Comparison
Implementations are at:
The three readline implementations differ as follows:
Node.js (full implementation): Complete readline support with terminal handling, line editing, history, tab completion, and the
Interfaceclass for interactive input.workerd (non-functional stub): Exports the expected API surface (
Interface,clearLine,clearScreenDown,createInterface,cursorTo,emitKeypressEvents,moveCursor,promises). Basic functions likeclearLine(),cursorTo(),moveCursor()returnfalse. TheInterfaceconstructor throwsERR_METHOD_NOT_IMPLEMENTED.unenv (polyfill stub): Similar API surface to workerd. Basic functions return
falseor are no-ops. TheInterfaceclass is a no-op stub that doesn't throw - methods likequestion()immediately call the callback with an empty string.Potential Breaking Changes
Code that relies on unenv's silent no-op behavior will break when switching to the native module, as workerd throws
ERR_METHOD_NOT_IMPLEMENTEDfor many APIs.node:readlinecreateInterface()InterfaceconstructorInterface.getPrompt()""Interface.question()""Interface.close()node:readline/promisescreateInterface()InterfaceconstructorInterface.question()Promise.resolve("")ReadlineconstructorReadline.commit()Human Review Checklist
getReadlineOverrides()correctly requires bothenable_nodejs_readline_moduleANDexperimentalflagsexperimentalflag in compatibility flagstestReadline()assertions includepromises: "object"to confirm promises API is accessibletestReadlinePromises()assertions match workerd's readline/promises exportsDevin PR requested by @petebacondarwin
Link to Devin run: https://app.devin.ai/sessions/3dd68b14916446e09725083926e3408d