Skip to content

fix(node:tty): make ReadStream and WriteStream constructors non-throwing#6064

Merged
petebacondarwin merged 2 commits intomainfrom
pbacondarwin/tty-noop-constructors
Feb 12, 2026
Merged

fix(node:tty): make ReadStream and WriteStream constructors non-throwing#6064
petebacondarwin merged 2 commits intomainfrom
pbacondarwin/tty-noop-constructors

Conversation

@petebacondarwin
Copy link
Copy Markdown
Contributor

Summary

  • Makes ReadStream and WriteStream constructors succeed instead of throwing ERR_METHOD_NOT_IMPLEMENTED
  • Changes cursorTo, moveCursor, clearLine, clearScreenDown methods from throwing to no-op functions that invoke callbacks if provided

Motivation

The previous behavior where constructors threw was a breaking change from how the unenv-preset works (where they are no-ops that can be instantiated). This aligns workerd's TTY implementation with unenv for better compatibility.

Changes

src/node/tty.ts:

  • ReadStream constructor now stores fd, sets isRaw = false, isTTY = false
  • WriteStream constructor now stores fd, sets columns = 0, rows = 0
  • setRawMode now actually updates isRaw property
  • cursorTo, moveCursor, clearLine, clearScreenDown are now no-ops that call callbacks if provided and return false

src/workerd/api/node/tests/tty-nodejs-test.js:

  • Updated tests to verify successful instantiation instead of throws
  • Added tests for callback invocation on no-op methods

Copy link
Copy Markdown
Collaborator

@jasnell jasnell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM once the eslint issues are addressed

Previously, the ReadStream and WriteStream constructors in the node:tty
module would throw ERR_METHOD_NOT_IMPLEMENTED, which was a breaking
change from the unenv-preset behavior where they are no-ops.

This change:
- Makes ReadStream and WriteStream constructors succeed and store fd
- Sets default properties (isRaw, isTTY, columns, rows)
- Changes cursorTo, moveCursor, clearLine, clearScreenDown from throwing
  to no-op functions that invoke callbacks if provided
- Updates tests to verify the new behavior
@petebacondarwin petebacondarwin force-pushed the pbacondarwin/tty-noop-constructors branch from 361cbc1 to 6dd1f25 Compare February 12, 2026 17:16
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 70.37%. Comparing base (dd7a515) to head (6dd1f25).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6064      +/-   ##
==========================================
- Coverage   70.38%   70.37%   -0.02%     
==========================================
  Files         408      408              
  Lines      108811   108811              
  Branches    18000    18000              
==========================================
- Hits        76591    76575      -16     
- Misses      21415    21430      +15     
- Partials    10805    10806       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@petebacondarwin petebacondarwin merged commit 6133379 into main Feb 12, 2026
22 of 23 checks passed
@petebacondarwin petebacondarwin deleted the pbacondarwin/tty-noop-constructors branch February 12, 2026 18:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants