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

feat(std/node/process)-stdin-stdout-stderr #7184

Merged

Conversation

JayHelton
Copy link
Contributor

@JayHelton JayHelton commented Aug 25, 2020

Description

Adding more backwards compatibility stderr, stdin, stdout for the node/process module'

References

  • #7101

@JayHelton
Copy link
Contributor Author

@ry Id love your thoughts on the preferred way to add these in, or if what i have falls in line with current codebase practices

Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

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

This looks like a good start

@JayHelton
Copy link
Contributor Author

Heavy WIP branch, still needs lots of testing

@JayHelton JayHelton changed the title JayHelton:feat(std/node/process)-stdin-stdout-stderr feat(std/node/process)-stdin-stdout-stderr Aug 25, 2020
@JayHelton
Copy link
Contributor Author

@ry This is ready for a review round when you have time!

@JayHelton JayHelton marked this pull request as ready for review August 26, 2020 00:31
@JayHelton
Copy link
Contributor Author

Weird. Tests work locally for me. investigating

test process.stdin ... ok (1ms)
test process.stdout ... ok (1ms)
test process.stderr ... ok (1ms)

@balupton
Copy link
Contributor

Could be that the rid changed from definition time to check time on the CI environment.

Perhaps try this way instead:

  stderr: class extends Deno.stderr {
     get isTTY(): boolean {
       return Deno.isatty(this.rid);
     },
   },

Tests for .write and .pipe may also be good, as they are common.

@balupton
Copy link
Contributor

Perhaps try this way instead:

  stderr: class extends Deno.stderr {
     get isTTY(): boolean {
       return Deno.isatty(this.rid);
     },
   },

Actually, that won't work, as it would need to be instantiated.

@balupton
Copy link
Contributor

balupton commented Aug 26, 2020

Maybe something like this using Proxies

  stderr: new Proxy(Deno.stderr, {
     get: function(target, prop, receiver) {
       if ( prop === 'isTTY' ) return Deno.isatty.bind(Deno, this.rid);
       return Reflect.get(...arguments);
     },
   },

@ry
Copy link
Member

ry commented Aug 27, 2020

@JayHelton Any idea why this is failing? Seems to be the related to the improvements you're making.

@JayHelton
Copy link
Contributor Author

JayHelton commented Aug 27, 2020

@JayHelton Any idea why this is failing? Seems to be the related to the improvements you're making.

@ry I know whats causing the failure, but not quite sure on the cause of the cause.

The assertion on the isTTY getters are failing for the CI tests, but pass for me locally.

From the ubuntu ci logs with a console.log I added

test process.stdin ... { rid: 0, isTTY: false }
FAILED (0ms)
test process.stdout ... { rid: 1, isTTY: false }
FAILED (0ms)
test process.stderr ... { rid: 2, isTTY: false }
FAILED (1ms)

When i run cargo test std_tests from my mac:

test process.stdin ... { rid: 0, isTTY: true }
ok (3ms)
test process.stdout ... { rid: 1, isTTY: true }
ok (3ms)
test process.stderr ... { rid: 2, isTTY: true }
ok (4ms)

@JayHelton
Copy link
Contributor Author

Im going to try the above suggestion to Proxy and see if that will achieve more consistent results

@JayHelton
Copy link
Contributor Author

@ry before i dive deeper into debugging, i wanted to ask you this.

Deno.isatty(Deno.stdin.rid) is evaluating as false on the ubuntu image and im not too sure why. I was under the assumption that stdin should be true. Is that a false assumption?

@JayHelton
Copy link
Contributor Author

The bug is still around on the ubuntu image and I havent been able to prove what the issue is.

Stdin, Stdout, and Stderr are not recognized as TTYs in the Ubuntu CI, but they are with everything ive tried locally (OSX).

Its not just the node/process std impls, Deno.isatty(Deno.stdin.rid) is also showing as false in CI (again, not locally).

The rid does not change either, as stdin, out, and err are instantiated with rids 0,1, and 2 (consistent with the file descriptors)

In the rust operation, there is a specific block at line 242 in tty.rs that is for unix, and then right above that is windows.

I dont see anything special for linux, so im assuming that on linux is either matching on an error Err(StreamResource::Stdin(..)) or hitting the wildcard which just marks it as false.

I dont have a ubuntu box to test this unfortunately. Any suggestions or ideas?

@ry @nayeemrmn

@ry
Copy link
Member

ry commented Aug 29, 2020

@JayHelton It's probably because the stdio aren't TTYs in the CI scenario. In order to properly test these values, we'd need to setup a PTY... it's not immediately clear to me how we would do that - since Deno doesn't yet have bindings for that...

@JayHelton
Copy link
Contributor Author

@JayHelton It's probably because the stdio aren't TTYs in the CI scenario. In order to properly test these values, we'd need to setup a PTY... it's not immediately clear to me how we would do that - since Deno doesn't yet have bindings for that...

This makes total sense why im seeing what im seeing.

In the mean time, would you accept a TODO with these isTTY assertions comment out, referencing the above?
If not, should we shelve this for a different time? @ry

@JayHelton
Copy link
Contributor Author

Additionally, I can start looking into how we can start supporting PTY, though there is a big bag of grey area that i would have to color in

name: "process.stdin",
fn() {
assertEquals(typeof process.stdin.rid, "number");
assertEquals(process.stdin.rid, Deno.stdin.rid);
Copy link
Member

Choose a reason for hiding this comment

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

In Node there isn't a process.stdin.rid

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay! I’ll get peep everything on node.process and replicate it more explicitly instead of spreading denos stdio.

@ry
Copy link
Member

ry commented Aug 29, 2020

Yes leaving a TODO is fine

@@ -38,6 +38,30 @@ export const process = {
platform,
version,
versions,
get stderr() {
return {
...Deno.stderr,
Copy link
Contributor

@caspervonb caspervonb Aug 29, 2020

Choose a reason for hiding this comment

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

Be explicit about the properties you want to expose here, this is very brittle and can break anytime additions or changes are made to Deno.stderr (Hasn't happened yet but theoretically it can happen).

},
get stdin() {
return {
...Deno.stdin,
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto

},
get stdout() {
return {
...Deno.stdout,
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto.

@JayHelton
Copy link
Contributor Author

LMK if this is a bit more inline with what would be safe! What is the denomatic way to port over a method that does not return a promise? The stdout and err both have a write method i was going to add on the objects, but the Deno methods return a promise. It doesnt seem very backwards compatible if they both return a promise

@balupton
Copy link
Contributor

balupton commented Aug 31, 2020

Just to make it explicit, these Node.js methods are needed for any substantial compat.

  • *.on
  • stdout.pipe
  • stderr.pipe
  • stdout.write
  • stderr.write
  • stdin.read

@JayHelton JayHelton changed the title feat(std/node/process)-stdin-stdout-stderr WIP feat(std/node/process)-stdin-stdout-stderr Sep 1, 2020
@JayHelton JayHelton changed the title WIP feat(std/node/process)-stdin-stdout-stderr feat(std/node/process)-stdin-stdout-stderr Sep 6, 2020
@JayHelton
Copy link
Contributor Author

Hey all, ive spent time researching the Node implementations of the methods mentioned in previous comments on this PR. I dont know the best way to implement these methods in a way that respects nodes callback based architecture. I am not confident Ill be able to find and implement those solutions without a little pairing and more time. I would recommend reviewing as is, fixing for the specific use case in the original ticket, and then we can add more support as needed.

Additionally, if anyone wants to grab this branch and work on it as well, definitely open to that! I am looking at a busy next few weeks and would prefer if this did not get too stale.

Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

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

LGTM - thank you - sorry for the delay!

@ry ry merged commit cead79f into denoland:master Sep 18, 2020
vitormmatos pushed a commit to vitormmatos/deno that referenced this pull request Sep 21, 2020
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Jan 21, 2021
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Jan 24, 2021
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Jan 24, 2021
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Jan 24, 2021
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Jan 31, 2021
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Jan 31, 2021
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Jan 31, 2021
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Jan 31, 2021
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Feb 1, 2021
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.

4 participants