deno.land / std@0.91.0 / node / process.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.// Copyright Joyent, Inc. and Node.js contributors. All rights reserved. MIT license.import { notImplemented } from "./_utils.ts";import EventEmitter from "./events.ts";import { fromFileUrl } from "../path/mod.ts";
const notImplementedEvents = [ "beforeExit", "disconnect", "message", "multipleResolves", "rejectionHandled", "SIGBREAK", "SIGBUS", "SIGFPE", "SIGHUP", "SIGILL", "SIGINT", "SIGSEGV", "SIGTERM", "SIGWINCH", "uncaughtException", "uncaughtExceptionMonitor", "unhandledRejection", "warning",];
/** https://nodejs.org/api/process.html#process_process_arch */export const arch = Deno.build.arch;
// The first 2 items are placeholders.// They will be overwritten by the below Object.defineProperty calls.const argv = ["", "", ...Deno.args];// Overwrites the 1st item with getter.Object.defineProperty(argv, "0", { get() { return Deno.execPath(); },});// Overwrites the 2nd item with getter.Object.defineProperty(argv, "1", { get() { return fromFileUrl(Deno.mainModule); },});
/** 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;
//deno-lint-ignore ban-ts-comment//@ts-ignoreconst _env: { [Deno.customInspect]: () => string;} = {};
Object.defineProperty(_env, Deno.customInspect, { enumerable: false, configurable: false, get: function () { return Deno.env.toObject(); },});
/** * https://nodejs.org/api/process.html#process_process_env * Requires env permissions * */export const env: Record<string, string> = new Proxy(_env, { get(target, prop) { if (prop === Deno.customInspect) { return target[Deno.customInspect]; } return Deno.env.get(String(prop)); }, ownKeys() { return Reflect.ownKeys(Deno.env.toObject()); }, set(_target, prop, value) { Deno.env.set(String(prop), String(value)); return value; },});
/** https://nodejs.org/api/process.html#process_process_exit_code */export const exit = Deno.exit;
/** 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); }}
/** 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,};
class Process extends EventEmitter { constructor() { super();
//This causes the exit event to be binded to the unload event window.addEventListener("unload", () => { //TODO(Soremwar) //Get the exit code from the unload event super.emit("exit", 0); }); }
/** https://nodejs.org/api/process.html#process_process_arch */ arch = arch;
/** * https://nodejs.org/api/process.html#process_process_argv * Read permissions are required in order to get the executable route * */ argv = argv;
/** https://nodejs.org/api/process.html#process_process_chdir_directory */ chdir = chdir;
/** https://nodejs.org/api/process.html#process_process_cwd */ cwd = cwd;
/** https://nodejs.org/api/process.html#process_process_exit_code */ exit = exit;
/** * https://nodejs.org/api/process.html#process_process_env * Requires env permissions * */ env = env;
/** https://nodejs.org/api/process.html#process_process_nexttick_callback_args */ nextTick = nextTick;
/** https://nodejs.org/api/process.html#process_process_events */ //deno-lint-ignore ban-types on(event: typeof notImplementedEvents[number], listener: Function): never; on(event: "exit", listener: (code: number) => void): this; //deno-lint-ignore no-explicit-any on(event: string, listener: (...args: any[]) => void): this { if (notImplementedEvents.includes(event)) { notImplemented(); }
super.on(event, listener);
return this; }
/** https://nodejs.org/api/process.html#process_process_pid */ pid = pid;
/** https://nodejs.org/api/process.html#process_process_platform */ platform = platform;
removeAllListeners(_event: string): never { notImplemented(); }
removeListener( event: typeof notImplementedEvents[number], //deno-lint-ignore ban-types listener: Function, ): never; removeListener(event: "exit", listener: (code: number) => void): this; //deno-lint-ignore no-explicit-any removeListener(event: string, listener: (...args: any[]) => void): this { if (notImplementedEvents.includes(event)) { notImplemented(); }
super.removeListener("exit", listener);
return this; }
/** * Returns the current high-resolution real time in a [seconds, nanoseconds] * tuple. * * Note: You need to give --allow-hrtime permission to Deno to actually get * nanoseconds precision values. If you don't give 'hrtime' permission, the returned * values only have milliseconds precision. * * `time` is an optional parameter that must be the result of a previous process.hrtime() call to diff with the current time. * * These times are relative to an arbitrary time in the past, and not related to the time of day and therefore not subject to clock drift. The primary use is for measuring performance between intervals. * https://nodejs.org/api/process.html#process_process_hrtime_time */ hrtime(time?: [number, number]): [number, number] { const milli = performance.now(); const sec = Math.floor(milli / 1000); const nano = Math.floor(milli * 1_000_000 - sec * 1_000_000_000); if (!time) { return [sec, nano]; } const [prevSec, prevNano] = time; return [sec - prevSec, nano - prevNano]; }
/** https://nodejs.org/api/process.html#process_process_stderr */ 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(); }, // deno-lint-ignore ban-types write(_chunk: string | Uint8Array, _callback: Function): void { // TODO(JayHelton): to be implemented notImplemented(); }, // deno-lint-ignore ban-types on(_event: string, _callback: Function): void { // TODO(JayHelton): to be implemented notImplemented(); }, }; }
/** https://nodejs.org/api/process.html#process_process_stdin */ 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(); }, // deno-lint-ignore ban-types on(_event: string, _callback: Function): void { // TODO(JayHelton): to be implemented notImplemented(); }, }; }
/** https://nodejs.org/api/process.html#process_process_stdout */ 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(); }, // deno-lint-ignore ban-types write(_chunk: string | Uint8Array, _callback: Function): void { // TODO(JayHelton): to be implemented notImplemented(); }, // deno-lint-ignore ban-types on(_event: string, _callback: Function): void { // TODO(JayHelton): to be implemented notImplemented(); }, }; }
/** https://nodejs.org/api/process.html#process_process_version */ version = version;
/** https://nodejs.org/api/process.html#process_process_versions */ versions = versions;}
/** https://nodejs.org/api/process.html#process_process */const process = new Process();
Object.defineProperty(process, Symbol.toStringTag, { enumerable: false, writable: true, configurable: false, value: "process",});
export const removeListener = process.removeListener;export const removeAllListeners = process.removeAllListeners;export const stderr = process.stderr;export const stdin = process.stdin;export const stdout = process.stdout;
export default process;
//TODO(Soremwar)//Remove on 1.0//Kept for backwars compatibility with stdexport { process };
std

Version Info

Tagged at
3 years ago

External Dependencies

No external dependencies 🎉