summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
Diffstat (limited to 'ext')
-rw-r--r--ext/io/12_io.js106
-rw-r--r--ext/node/lib.rs1
-rw-r--r--ext/node/polyfills/_process/streams.mjs12
-rw-r--r--ext/node/polyfills/process.ts6
4 files changed, 116 insertions, 9 deletions
diff --git a/ext/io/12_io.js b/ext/io/12_io.js
index b9ff1190b..d1f3b8b1b 100644
--- a/ext/io/12_io.js
+++ b/ext/io/12_io.js
@@ -7,6 +7,10 @@
const core = globalThis.Deno.core;
const ops = core.ops;
const primordials = globalThis.__bootstrap.primordials;
+import {
+ readableStreamForRid,
+ writableStreamForRid,
+} from "internal:deno_web/06_streams.js";
const {
Uint8Array,
ArrayPrototypePush,
@@ -221,6 +225,105 @@ async function readAllInnerSized(r, size, options) {
}
}
+class Stdin {
+ #readable;
+
+ constructor() {
+ }
+
+ get rid() {
+ return 0;
+ }
+
+ read(p) {
+ return read(this.rid, p);
+ }
+
+ readSync(p) {
+ return readSync(this.rid, p);
+ }
+
+ close() {
+ core.close(this.rid);
+ }
+
+ get readable() {
+ if (this.#readable === undefined) {
+ this.#readable = readableStreamForRid(this.rid);
+ }
+ return this.#readable;
+ }
+
+ setRaw(mode, options = {}) {
+ const cbreak = !!(options.cbreak ?? false);
+ ops.op_stdin_set_raw(mode, cbreak);
+ }
+}
+
+class Stdout {
+ #writable;
+
+ constructor() {
+ }
+
+ get rid() {
+ return 1;
+ }
+
+ write(p) {
+ return write(this.rid, p);
+ }
+
+ writeSync(p) {
+ return writeSync(this.rid, p);
+ }
+
+ close() {
+ core.close(this.rid);
+ }
+
+ get writable() {
+ if (this.#writable === undefined) {
+ this.#writable = writableStreamForRid(this.rid);
+ }
+ return this.#writable;
+ }
+}
+
+class Stderr {
+ #writable;
+
+ constructor() {
+ }
+
+ get rid() {
+ return 2;
+ }
+
+ write(p) {
+ return write(this.rid, p);
+ }
+
+ writeSync(p) {
+ return writeSync(this.rid, p);
+ }
+
+ close() {
+ core.close(this.rid);
+ }
+
+ get writable() {
+ if (this.#writable === undefined) {
+ this.#writable = writableStreamForRid(this.rid);
+ }
+ return this.#writable;
+ }
+}
+
+const stdin = new Stdin();
+const stdout = new Stdout();
+const stderr = new Stderr();
+
export {
copy,
iter,
@@ -233,6 +336,9 @@ export {
readAllSyncSized,
readSync,
SeekMode,
+ stderr,
+ stdin,
+ stdout,
write,
writeSync,
};
diff --git a/ext/node/lib.rs b/ext/node/lib.rs
index 444dffeec..a1fa9408a 100644
--- a/ext/node/lib.rs
+++ b/ext/node/lib.rs
@@ -365,6 +365,7 @@ pub fn init_polyfill() -> Extension {
Extension::builder(env!("CARGO_PKG_NAME"))
.esm(esm_files)
.esm_entry_point("internal:deno_node/module_all.ts")
+ .dependencies(vec!["deno_io"])
.ops(vec![
crypto::op_node_create_hash::decl(),
crypto::op_node_hash_update::decl(),
diff --git a/ext/node/polyfills/_process/streams.mjs b/ext/node/polyfills/_process/streams.mjs
index da6895dbb..dbb9552fa 100644
--- a/ext/node/polyfills/_process/streams.mjs
+++ b/ext/node/polyfills/_process/streams.mjs
@@ -11,7 +11,7 @@ import {
import { Duplex, Readable, Writable } from "internal:deno_node/stream.ts";
import { isWindows } from "internal:deno_node/_util/os.ts";
import { fs as fsConstants } from "internal:deno_node/internal_binding/constants.ts";
-import * as files from "internal:runtime/40_files.js";
+import * as io from "internal:deno_io/12_io.js";
// https://github.com/nodejs/node/blob/00738314828074243c9a52a228ab4c68b04259ef/lib/internal/bootstrap/switches/is_main_thread.js#L41
export function createWritableStdioStream(writer, name) {
@@ -140,7 +140,7 @@ function _guessStdinType(fd) {
const _read = function (size) {
const p = Buffer.alloc(size || 16 * 1024);
- files.stdin?.read(p).then((length) => {
+ io.stdin?.read(p).then((length) => {
this.push(length === null ? null : p.slice(0, length));
}, (error) => {
this.destroy(error);
@@ -151,7 +151,7 @@ const _read = function (size) {
// https://github.com/nodejs/node/blob/v18.12.1/lib/internal/bootstrap/switches/is_main_thread.js#L189
/** Create process.stdin */
export const initStdin = () => {
- const fd = files.stdin?.rid;
+ const fd = io.stdin?.rid;
let stdin;
const stdinType = _guessStdinType(fd);
@@ -210,8 +210,8 @@ export const initStdin = () => {
}
}
- stdin.on("close", () => files.stdin?.close());
- stdin.fd = files.stdin?.rid ?? -1;
+ stdin.on("close", () => io.stdin?.close());
+ stdin.fd = io.stdin?.rid ?? -1;
Object.defineProperty(stdin, "isTTY", {
enumerable: true,
configurable: true,
@@ -221,7 +221,7 @@ export const initStdin = () => {
});
stdin._isRawMode = false;
stdin.setRawMode = (enable) => {
- files.stdin?.setRaw?.(enable);
+ io.stdin?.setRaw?.(enable);
stdin._isRawMode = enable;
return stdin;
};
diff --git a/ext/node/polyfills/process.ts b/ext/node/polyfills/process.ts
index eaff978c2..02701dbdd 100644
--- a/ext/node/polyfills/process.ts
+++ b/ext/node/polyfills/process.ts
@@ -38,7 +38,7 @@ import {
runNextTicks,
} from "internal:deno_node/_next_tick.ts";
import { isWindows } from "internal:deno_node/_util/os.ts";
-import * as files from "internal:runtime/40_files.js";
+import * as io from "internal:deno_io/12_io.js";
// TODO(kt3k): This should be set at start up time
export let arch = "";
@@ -755,13 +755,13 @@ internals.__bootstrapNodeProcess = function (
/** https://nodejs.org/api/process.html#process_process_stderr */
stderr = process.stderr = createWritableStdioStream(
- files.stderr,
+ io.stderr,
"stderr",
);
/** https://nodejs.org/api/process.html#process_process_stdout */
stdout = process.stdout = createWritableStdioStream(
- files.stdout,
+ io.stdout,
"stdout",
);