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
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions std/node/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 isTTY(): boolean {
return Deno.isatty(this.rid);
},
};
},
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 isTTY(): boolean {
return Deno.isatty(this.rid);
},
};
},
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.

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

/** https://nodejs.org/api/process.html#process_process_events */
// on is not exported by node, it is only available within process:
Expand Down
35 changes: 34 additions & 1 deletion std/node/process_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ Deno.test({
allKeys.delete("process");
// without esm default
allKeys.delete("default");
// with on, which is not exported via *
// with on, stdin, stderr, and stdout, which is not exported via *
allKeys.add("on");
allKeys.add("stdin");
allKeys.add("stderr");
allKeys.add("stdout");
const allStr = Array.from(allKeys).sort().join(" ");
assertEquals(Object.keys(all.default).sort().join(" "), allStr);
assertEquals(Object.keys(all.process).sort().join(" "), allStr);
Expand Down Expand Up @@ -120,3 +123,33 @@ Deno.test({
assertEquals(typeof env.PATH, "string");
},
});

Deno.test({
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.

// TODO(jayhelton) Uncomment out this assertion once PTY is supported
//assert(process.stdin.isTTY);
},
});

Deno.test({
name: "process.stdout",
fn() {
assertEquals(typeof process.stdout.rid, "number");
assertEquals(process.stdout.rid, Deno.stdout.rid);
// TODO(jayhelton) Uncomment out this assertion once PTY is supported
// assert(process.stdout.isTTY);
},
});

Deno.test({
name: "process.stderr",
fn() {
assertEquals(typeof process.stderr.rid, "number");
assertEquals(process.stderr.rid, Deno.stderr.rid);
// TODO(jayhelton) Uncomment out this assertion once PTY is supported
// assert(process.stderr.isTTY);
},
});