2020-09-21 08:26:41 -04:00
|
|
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
2019-11-18 18:30:24 -05:00
|
|
|
import { notImplemented } from "./_utils.ts";
|
|
|
|
|
2020-06-23 16:00:47 -04:00
|
|
|
/** https://nodejs.org/api/process.html#process_process_arch */
|
|
|
|
export const arch = Deno.build.arch;
|
|
|
|
|
|
|
|
/** https://nodejs.org/api/process.html#process_process_chdir_directory */
|
|
|
|
export const chdir = Deno.chdir;
|
|
|
|
|
|
|
|
/** https://nodejs.org/api/process.html#process_process_cwd */
|
|
|
|
export const cwd = Deno.cwd;
|
|
|
|
|
|
|
|
/** https://nodejs.org/api/process.html#process_process_exit_code */
|
|
|
|
export const exit = Deno.exit;
|
|
|
|
|
|
|
|
/** https://nodejs.org/api/process.html#process_process_pid */
|
|
|
|
export const pid = Deno.pid;
|
|
|
|
|
|
|
|
/** https://nodejs.org/api/process.html#process_process_platform */
|
|
|
|
export const platform = Deno.build.os === "windows" ? "win32" : Deno.build.os;
|
|
|
|
|
|
|
|
/** https://nodejs.org/api/process.html#process_process_version */
|
|
|
|
export const version = `v${Deno.version.deno}`;
|
|
|
|
|
|
|
|
/** https://nodejs.org/api/process.html#process_process_versions */
|
|
|
|
export const versions = {
|
|
|
|
node: Deno.version.deno,
|
|
|
|
...Deno.version,
|
|
|
|
};
|
2019-11-18 18:30:24 -05:00
|
|
|
|
2020-11-16 14:44:37 -05:00
|
|
|
/** https://nodejs.org/api/process.html#process_process_nexttick_callback_args */
|
|
|
|
export function nextTick(this: unknown, cb: () => void): void;
|
|
|
|
export function nextTick<T extends Array<unknown>>(
|
|
|
|
this: unknown,
|
|
|
|
cb: (...args: T) => void,
|
|
|
|
...args: T
|
|
|
|
): void;
|
|
|
|
export function nextTick<T extends Array<unknown>>(
|
|
|
|
this: unknown,
|
|
|
|
cb: (...args: T) => void,
|
|
|
|
...args: T
|
|
|
|
) {
|
|
|
|
if (args) {
|
|
|
|
queueMicrotask(() => cb.call(this, ...args));
|
|
|
|
} else {
|
|
|
|
queueMicrotask(cb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-23 16:00:47 -04:00
|
|
|
/** https://nodejs.org/api/process.html#process_process */
|
2020-06-25 07:18:01 -04:00
|
|
|
// @deprecated `import { process } from 'process'` for backwards compatibility with old deno versions
|
2019-11-18 18:30:24 -05:00
|
|
|
export const process = {
|
2020-06-23 16:00:47 -04:00
|
|
|
arch,
|
|
|
|
chdir,
|
|
|
|
cwd,
|
|
|
|
exit,
|
|
|
|
pid,
|
|
|
|
platform,
|
|
|
|
version,
|
|
|
|
versions,
|
2020-09-17 23:31:50 -04:00
|
|
|
get stderr() {
|
|
|
|
return {
|
|
|
|
fd: Deno.stderr.rid,
|
|
|
|
get isTTY(): boolean {
|
|
|
|
return Deno.isatty(this.fd);
|
|
|
|
},
|
|
|
|
pipe(_destination: Deno.Writer, _options: { end: boolean }): void {
|
|
|
|
// TODO(JayHelton): to be implemented
|
|
|
|
notImplemented();
|
|
|
|
},
|
2020-11-03 10:19:29 -05:00
|
|
|
// deno-lint-ignore ban-types
|
2020-09-17 23:31:50 -04:00
|
|
|
write(_chunk: string | Uint8Array, _callback: Function): void {
|
|
|
|
// TODO(JayHelton): to be implemented
|
|
|
|
notImplemented();
|
|
|
|
},
|
2020-11-03 10:19:29 -05:00
|
|
|
// deno-lint-ignore ban-types
|
2020-09-17 23:31:50 -04:00
|
|
|
on(_event: string, _callback: Function): void {
|
|
|
|
// TODO(JayHelton): to be implemented
|
|
|
|
notImplemented();
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
get stdin() {
|
|
|
|
return {
|
|
|
|
fd: Deno.stdin.rid,
|
|
|
|
get isTTY(): boolean {
|
|
|
|
return Deno.isatty(this.fd);
|
|
|
|
},
|
|
|
|
read(_size: number): void {
|
|
|
|
// TODO(JayHelton): to be implemented
|
|
|
|
notImplemented();
|
|
|
|
},
|
2020-11-03 10:19:29 -05:00
|
|
|
// deno-lint-ignore ban-types
|
2020-09-17 23:31:50 -04:00
|
|
|
on(_event: string, _callback: Function): void {
|
|
|
|
// TODO(JayHelton): to be implemented
|
|
|
|
notImplemented();
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
get stdout() {
|
|
|
|
return {
|
|
|
|
fd: Deno.stdout.rid,
|
|
|
|
get isTTY(): boolean {
|
|
|
|
return Deno.isatty(this.fd);
|
|
|
|
},
|
|
|
|
pipe(_destination: Deno.Writer, _options: { end: boolean }): void {
|
|
|
|
// TODO(JayHelton): to be implemented
|
|
|
|
notImplemented();
|
|
|
|
},
|
2020-11-03 10:19:29 -05:00
|
|
|
// deno-lint-ignore ban-types
|
2020-09-17 23:31:50 -04:00
|
|
|
write(_chunk: string | Uint8Array, _callback: Function): void {
|
|
|
|
// TODO(JayHelton): to be implemented
|
|
|
|
notImplemented();
|
|
|
|
},
|
2020-11-03 10:19:29 -05:00
|
|
|
// deno-lint-ignore ban-types
|
2020-09-17 23:31:50 -04:00
|
|
|
on(_event: string, _callback: Function): void {
|
|
|
|
// TODO(JayHelton): to be implemented
|
|
|
|
notImplemented();
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
2020-06-23 16:00:47 -04:00
|
|
|
|
|
|
|
/** https://nodejs.org/api/process.html#process_process_events */
|
2020-06-25 07:18:01 -04:00
|
|
|
// on is not exported by node, it is only available within process:
|
|
|
|
// node --input-type=module -e "import { on } from 'process'; console.log(on)"
|
2020-11-03 10:19:29 -05:00
|
|
|
// deno-lint-ignore ban-types
|
2020-06-23 16:00:47 -04:00
|
|
|
on(_event: string, _callback: Function): void {
|
|
|
|
// TODO(rsp): to be implemented
|
|
|
|
notImplemented();
|
2020-06-12 15:23:38 -04:00
|
|
|
},
|
2020-06-23 16:00:47 -04:00
|
|
|
|
|
|
|
/** https://nodejs.org/api/process.html#process_process_argv */
|
2019-11-18 18:30:24 -05:00
|
|
|
get argv(): string[] {
|
2020-06-25 07:18:01 -04:00
|
|
|
// Getter delegates --allow-env and --allow-read until request
|
|
|
|
// Getter also allows the export Proxy instance to function as intended
|
2019-11-18 18:30:24 -05:00
|
|
|
return [Deno.execPath(), ...Deno.args];
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2020-06-23 16:00:47 -04:00
|
|
|
|
2020-06-25 07:18:01 -04:00
|
|
|
/** https://nodejs.org/api/process.html#process_process_env */
|
|
|
|
get env(): { [index: string]: string } {
|
|
|
|
// Getter delegates --allow-env and --allow-read until request
|
|
|
|
// Getter also allows the export Proxy instance to function as intended
|
|
|
|
return Deno.env.toObject();
|
|
|
|
},
|
2020-11-16 14:44:37 -05:00
|
|
|
nextTick,
|
2020-06-25 07:18:01 -04:00
|
|
|
};
|
2020-06-23 16:00:47 -04:00
|
|
|
|
2020-06-25 07:18:01 -04:00
|
|
|
/**
|
|
|
|
* https://nodejs.org/api/process.html#process_process_argv
|
|
|
|
* @example `import { argv } from './std/node/process.ts'; console.log(argv)`
|
|
|
|
*/
|
|
|
|
// Proxy delegates --allow-env and --allow-read to request time, even for exports
|
|
|
|
export const argv = new Proxy(process.argv, {});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* https://nodejs.org/api/process.html#process_process_env
|
|
|
|
* @example `import { env } from './std/node/process.ts'; console.log(env)`
|
|
|
|
*/
|
|
|
|
// Proxy delegates --allow-env and --allow-read to request time, even for exports
|
|
|
|
export const env = new Proxy(process.env, {});
|
|
|
|
|
|
|
|
// import process from './std/node/process.ts'
|
2020-06-23 16:00:47 -04:00
|
|
|
export default process;
|
|
|
|
|
2020-04-30 13:58:40 -04:00
|
|
|
Object.defineProperty(process, Symbol.toStringTag, {
|
|
|
|
enumerable: false,
|
|
|
|
writable: true,
|
|
|
|
configurable: false,
|
|
|
|
value: "process",
|
|
|
|
});
|