mirror of
https://github.com/denoland/deno.git
synced 2025-07-14 08:45:08 +00:00
.
This commit is contained in:
parent
b1e28a23b4
commit
89de7e1ff8
1 changed files with 23 additions and 16 deletions
|
@ -33,6 +33,8 @@ export { _nextTick as nextTick, chdir, cwd, env, version, versions };
|
||||||
import {
|
import {
|
||||||
createWritableStdioStream,
|
createWritableStdioStream,
|
||||||
initStdin,
|
initStdin,
|
||||||
|
Readable,
|
||||||
|
Writable,
|
||||||
} from "ext:deno_node/_process/streams.mjs";
|
} from "ext:deno_node/_process/streams.mjs";
|
||||||
import {
|
import {
|
||||||
enableNextTick,
|
enableNextTick,
|
||||||
|
@ -52,35 +54,40 @@ export let platform = "";
|
||||||
// TODO(kt3k): This should be set at start up time
|
// TODO(kt3k): This should be set at start up time
|
||||||
export let pid = 0;
|
export let pid = 0;
|
||||||
|
|
||||||
|
// We want streams to be as lazy as possible, but we cannot export a getter in a module. To
|
||||||
|
// work around this we make these proxies that eagerly instantiate the underlying object on
|
||||||
|
// first access of any property/method.
|
||||||
function makeLazyStream<T>(objectFactory: () => T): T {
|
function makeLazyStream<T>(objectFactory: () => T): T {
|
||||||
return new Proxy({}, {
|
return new Proxy({}, {
|
||||||
get: function (_, prop, receiver) {
|
get: function (_, prop, receiver) {
|
||||||
return Reflect.get(objectFactory() as object, prop, receiver);
|
// deno-lint-ignore no-explicit-any
|
||||||
|
return Reflect.get(objectFactory() as any, prop, receiver);
|
||||||
},
|
},
|
||||||
has: function (_, prop) {
|
has: function (_, prop) {
|
||||||
return Reflect.has(objectFactory() as object, prop);
|
// deno-lint-ignore no-explicit-any
|
||||||
|
return Reflect.has(objectFactory() as any, prop);
|
||||||
},
|
},
|
||||||
ownKeys: function (_) {
|
ownKeys: function (_) {
|
||||||
return Reflect.ownKeys(objectFactory() as object);
|
// deno-lint-ignore no-explicit-any
|
||||||
|
return Reflect.ownKeys(objectFactory() as any);
|
||||||
},
|
},
|
||||||
set: function (_, prop, value, receiver) {
|
set: function (_, prop, value, receiver) {
|
||||||
return Reflect.set(objectFactory() as object, prop, value, receiver);
|
// deno-lint-ignore no-explicit-any
|
||||||
|
return Reflect.set(objectFactory() as any, prop, value, receiver);
|
||||||
},
|
},
|
||||||
getPrototypeOf: function (_) {
|
getPrototypeOf: function (_) {
|
||||||
return Reflect.getPrototypeOf(objectFactory() as object);
|
// deno-lint-ignore no-explicit-any
|
||||||
|
return Reflect.getPrototypeOf(objectFactory() as any);
|
||||||
},
|
},
|
||||||
getOwnPropertyDescriptor(_, prop) {
|
getOwnPropertyDescriptor(_, prop) {
|
||||||
return Reflect.getOwnPropertyDescriptor(objectFactory() as object, prop);
|
// deno-lint-ignore no-explicit-any
|
||||||
|
return Reflect.getOwnPropertyDescriptor(objectFactory() as any, prop);
|
||||||
},
|
},
|
||||||
}) as T;
|
}) as T;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(kt3k): Give better types to stdio objects
|
|
||||||
// deno-lint-ignore no-explicit-any
|
|
||||||
export let stderr = makeLazyStream(getStderr);
|
export let stderr = makeLazyStream(getStderr);
|
||||||
// deno-lint-ignore no-explicit-any
|
|
||||||
export let stdin = makeLazyStream(getStdin);
|
export let stdin = makeLazyStream(getStdin);
|
||||||
// deno-lint-ignore no-explicit-any
|
|
||||||
export let stdout = makeLazyStream(getStdout);
|
export let stdout = makeLazyStream(getStdout);
|
||||||
|
|
||||||
import { getBinding } from "ext:deno_node/internal_binding/mod.ts";
|
import { getBinding } from "ext:deno_node/internal_binding/mod.ts";
|
||||||
|
@ -627,17 +634,17 @@ class Process extends EventEmitter {
|
||||||
memoryUsage = memoryUsage;
|
memoryUsage = memoryUsage;
|
||||||
|
|
||||||
/** https://nodejs.org/api/process.html#process_process_stderr */
|
/** https://nodejs.org/api/process.html#process_process_stderr */
|
||||||
get stderr() {
|
get stderr(): Writable {
|
||||||
return getStderr();
|
return getStderr();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** https://nodejs.org/api/process.html#process_process_stdin */
|
/** https://nodejs.org/api/process.html#process_process_stdin */
|
||||||
get stdin() {
|
get stdin(): Readable {
|
||||||
return getStdin();
|
return getStdin();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** https://nodejs.org/api/process.html#process_process_stdout */
|
/** https://nodejs.org/api/process.html#process_process_stdout */
|
||||||
get stdout() {
|
get stdout(): Writable {
|
||||||
return getStdout();
|
return getStdout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -896,7 +903,7 @@ let stdin_ = null as any;
|
||||||
// deno-lint-ignore no-explicit-any
|
// deno-lint-ignore no-explicit-any
|
||||||
let stdout_ = null as any;
|
let stdout_ = null as any;
|
||||||
|
|
||||||
function getStdin() {
|
function getStdin(): Readable {
|
||||||
if (!stdin_) {
|
if (!stdin_) {
|
||||||
stdin_ = initStdin();
|
stdin_ = initStdin();
|
||||||
stdin = stdin_;
|
stdin = stdin_;
|
||||||
|
@ -906,7 +913,7 @@ function getStdin() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** https://nodejs.org/api/process.html#process_process_stdout */
|
/** https://nodejs.org/api/process.html#process_process_stdout */
|
||||||
function getStdout() {
|
function getStdout(): Writable {
|
||||||
if (!stdout_) {
|
if (!stdout_) {
|
||||||
stdout_ = createWritableStdioStream(
|
stdout_ = createWritableStdioStream(
|
||||||
io.stdout,
|
io.stdout,
|
||||||
|
@ -919,7 +926,7 @@ function getStdout() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** https://nodejs.org/api/process.html#process_process_stderr */
|
/** https://nodejs.org/api/process.html#process_process_stderr */
|
||||||
function getStderr() {
|
function getStderr(): Writable {
|
||||||
if (!stderr_) {
|
if (!stderr_) {
|
||||||
stderr_ = createWritableStdioStream(
|
stderr_ = createWritableStdioStream(
|
||||||
io.stderr,
|
io.stderr,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue