Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: implement node:tty #20892

Merged
merged 28 commits into from
Oct 30, 2023
Merged

fix: implement node:tty #20892

merged 28 commits into from
Oct 30, 2023

Conversation

littledivy
Copy link
Member

@littledivy littledivy commented Oct 12, 2023

@littledivy littledivy changed the title implement node:tty fix: Implement node:tty Oct 12, 2023
Comment on lines -60 to -67
function makeLazyStream<T>(objectFactory: () => T): T {
return new Proxy({}, {
get: function (_, prop, receiver) {
// deno-lint-ignore no-explicit-any
return Reflect.get(objectFactory() as any, prop, receiver);
Copy link
Member Author

Choose a reason for hiding this comment

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

cc @bartlomieju @mmastrac

This breaks code in _streams.mjs because of the use of Proxy:

divy@mini /tmp> ~/gh/deno/target/debug/deno run -A npm:nuxi@latest init my-app

[5:25:30 PM]  ERROR  'get' on proxy: property '_eventsCount' is a read-only and non-configurable data property on the proxy target but the proxy did not return its actual value (expected '2' but got '1')

  at _addListener (ext:deno_node/_stream.mjs:1884:9)
  at Proxy.addListener (ext:deno_node/_stream.mjs:1913:14)
  at Proxy.Readable.on (ext:deno_node/_stream.mjs:3275:39)
  at Proxy.Readable.pipe (ext:deno_node/_stream.mjs:3177:11)

when its trying to update the eventsCount. I reverted it back to not lazy load the stdin/out/err streams which fixed the issue.

@littledivy littledivy marked this pull request as ready for review October 12, 2023 14:01
Copy link
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

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

Can you enable some additional compat tests for this PR?

ext/node/polyfills/process.ts Outdated Show resolved Hide resolved
@littledivy
Copy link
Member Author

@bartlomieju all tty related compat tests seem to be enabled already cli/tests/unit_node/pseudo-tty

@bartlomieju
Copy link
Member

@bartlomieju all tty related compat tests seem to be enabled already cli/tests/unit_node/pseudo-tty

I'm not sure - eg. I can see test-set-raw-mode-reset.js in tools/node_compat/node/test/pseudo-tty/ but it's not in cli/tests/node_compat/test/pseudo-tty/. This particular test would be useful for testing the atexit functionality.

@littledivy littledivy changed the title fix: Implement node:tty fix: implement node:tty Oct 20, 2023
@littledivy
Copy link
Member Author

littledivy commented Oct 24, 2023

Hanging on lsp_testing_api Fixed

Copy link
Contributor

@mmastrac mmastrac left a comment

Choose a reason for hiding this comment

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

Looks good, some simplification and unsafe removal suggestions.

ext/node/ops/util.rs Outdated Show resolved Hide resolved
ext/node/ops/util.rs Outdated Show resolved Hide resolved
ext/node/ops/util.rs Outdated Show resolved Hide resolved

#[repr(u32)]
enum HandleType {
#[allow(dead_code)]
Copy link
Contributor

Choose a reason for hiding this comment

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

TODO for later work?

Copy link
Member Author

Choose a reason for hiding this comment

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

Dead code on Windows for TCP and UDP is TODO.

@mmastrac
Copy link
Contributor

/bench startup_nop_trivial

@denobot
Copy link
Collaborator

denobot commented Oct 29, 2023

startup_nop_trivial

time user system relative
node 23 ms 16 ms 8 ms +105.4%
bun 11 ms 4 ms 7 ms best
deno 16 ms 10 ms 7 ms +47.6%
deno-baseline 16 ms 11 ms 5 ms +44.6%

start: Sun, 29 Oct 2023 13:00:57 GMT

id: 52ef5c36-3ae8-4ac4-894f-1988a54ccaaf

server: 5645ab74-bf2f-4fe3-86b4-f575d075ce2b

@mmastrac
Copy link
Contributor

Looks like no real startup impact of this change per the benchmark below. Awesome!

Copy link
Contributor

@mmastrac mmastrac left a comment

Choose a reason for hiding this comment

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

LGTM, nice

@littledivy
Copy link
Member Author

@mmastrac The early is_terminal check seems to bring back the hang on Windows. I've reverted back.

Copy link
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

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

LGTM too, try to enable some of the Node compat tests that check if the terminal is restored on exit

@littledivy littledivy enabled auto-merge (squash) October 30, 2023 14:12
@littledivy littledivy merged commit 0920410 into denoland:main Oct 30, 2023
13 checks passed
@littledivy littledivy deleted the node_tty branch October 30, 2023 15:53
@benmccann
Copy link

Fixes create-svelte from #17248

As a heads up, it was reported that using the latest Deno from main didn't fix this issue: #17248 (comment)

bartlomieju pushed a commit to bartlomieju/deno that referenced this pull request Oct 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants