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-06-23 16:00:47 -04:00
|
|
|
/** https://nodejs.org/api/process.html#process_process */
|
|
|
|
// @deprecated exported only 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,
|
|
|
|
|
|
|
|
/** https://nodejs.org/api/process.html#process_process_events */
|
|
|
|
// node --input-type=module -e "import {on} from 'process'; console.log(on)"
|
|
|
|
// on is not exported by node, it is only available within process
|
|
|
|
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_env */
|
2019-11-18 18:30:24 -05:00
|
|
|
get env(): { [index: string]: string } {
|
|
|
|
// using getter to avoid --allow-env unless it's used
|
2020-04-29 14:48:19 -04:00
|
|
|
return Deno.env.toObject();
|
2019-11-18 18:30:24 -05: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[] {
|
|
|
|
// Deno.execPath() also requires --allow-env
|
|
|
|
return [Deno.execPath(), ...Deno.args];
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2019-11-18 18:30:24 -05:00
|
|
|
};
|
2020-04-30 10:00:02 -04:00
|
|
|
|
2020-06-23 16:00:47 -04:00
|
|
|
// define the type for configuring the env and argv promises
|
|
|
|
// as well as for the global.process declaration
|
|
|
|
type Process = typeof process;
|
|
|
|
|
|
|
|
/** requires the use of await for compatibility with deno */
|
|
|
|
export const env = new Promise<Process["env"]>((resolve) =>
|
|
|
|
resolve(process.env)
|
|
|
|
);
|
|
|
|
|
|
|
|
/** requires the use of await for compatibility with deno */
|
|
|
|
export const argv = new Promise<Process["argv"]>((resolve) =>
|
|
|
|
resolve(process.argv)
|
|
|
|
);
|
|
|
|
|
|
|
|
/** use this for access to `process.env` and `process.argv` without the need for await */
|
|
|
|
export default process;
|
|
|
|
|
2020-04-30 13:58:40 -04:00
|
|
|
Object.defineProperty(process, Symbol.toStringTag, {
|
|
|
|
enumerable: false,
|
|
|
|
writable: true,
|
|
|
|
configurable: false,
|
|
|
|
value: "process",
|
|
|
|
});
|
|
|
|
|
2020-04-30 10:00:02 -04:00
|
|
|
Object.defineProperty(globalThis, "process", {
|
|
|
|
value: process,
|
|
|
|
enumerable: false,
|
|
|
|
writable: true,
|
|
|
|
configurable: true,
|
|
|
|
});
|
2020-06-23 16:00:47 -04:00
|
|
|
|
|
|
|
declare global {
|
|
|
|
const process: Process;
|
|
|
|
}
|