@scelar/nodepod 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) hide show
  1. package/LICENSE +43 -0
  2. package/README.md +240 -0
  3. package/dist/child_process-BJOMsZje.js +8233 -0
  4. package/dist/child_process-BJOMsZje.js.map +1 -0
  5. package/dist/child_process-Cj8vOcuc.cjs +7434 -0
  6. package/dist/child_process-Cj8vOcuc.cjs.map +1 -0
  7. package/dist/index-Cb1Cgdnd.js +35308 -0
  8. package/dist/index-Cb1Cgdnd.js.map +1 -0
  9. package/dist/index-DsMGS-xc.cjs +37195 -0
  10. package/dist/index-DsMGS-xc.cjs.map +1 -0
  11. package/dist/index.cjs +65 -0
  12. package/dist/index.cjs.map +1 -0
  13. package/dist/index.mjs +59 -0
  14. package/dist/index.mjs.map +1 -0
  15. package/package.json +95 -0
  16. package/src/__tests__/smoke.test.ts +11 -0
  17. package/src/constants/cdn-urls.ts +18 -0
  18. package/src/constants/config.ts +236 -0
  19. package/src/cross-origin.ts +26 -0
  20. package/src/engine-factory.ts +176 -0
  21. package/src/engine-types.ts +56 -0
  22. package/src/helpers/byte-encoding.ts +39 -0
  23. package/src/helpers/digest.ts +9 -0
  24. package/src/helpers/event-loop.ts +96 -0
  25. package/src/helpers/wasm-cache.ts +133 -0
  26. package/src/iframe-sandbox.ts +141 -0
  27. package/src/index.ts +192 -0
  28. package/src/isolation-helpers.ts +148 -0
  29. package/src/memory-volume.ts +941 -0
  30. package/src/module-transformer.ts +368 -0
  31. package/src/packages/archive-extractor.ts +248 -0
  32. package/src/packages/browser-bundler.ts +284 -0
  33. package/src/packages/installer.ts +396 -0
  34. package/src/packages/registry-client.ts +131 -0
  35. package/src/packages/version-resolver.ts +411 -0
  36. package/src/polyfills/assert.ts +384 -0
  37. package/src/polyfills/async_hooks.ts +144 -0
  38. package/src/polyfills/buffer.ts +628 -0
  39. package/src/polyfills/child_process.ts +2288 -0
  40. package/src/polyfills/chokidar.ts +336 -0
  41. package/src/polyfills/cluster.ts +106 -0
  42. package/src/polyfills/console.ts +136 -0
  43. package/src/polyfills/constants.ts +123 -0
  44. package/src/polyfills/crypto.ts +885 -0
  45. package/src/polyfills/dgram.ts +87 -0
  46. package/src/polyfills/diagnostics_channel.ts +76 -0
  47. package/src/polyfills/dns.ts +134 -0
  48. package/src/polyfills/domain.ts +68 -0
  49. package/src/polyfills/esbuild.ts +854 -0
  50. package/src/polyfills/events.ts +276 -0
  51. package/src/polyfills/fs.ts +2888 -0
  52. package/src/polyfills/fsevents.ts +79 -0
  53. package/src/polyfills/http.ts +1449 -0
  54. package/src/polyfills/http2.ts +199 -0
  55. package/src/polyfills/https.ts +76 -0
  56. package/src/polyfills/inspector.ts +62 -0
  57. package/src/polyfills/lightningcss.ts +105 -0
  58. package/src/polyfills/module.ts +191 -0
  59. package/src/polyfills/net.ts +353 -0
  60. package/src/polyfills/os.ts +238 -0
  61. package/src/polyfills/path.ts +206 -0
  62. package/src/polyfills/perf_hooks.ts +102 -0
  63. package/src/polyfills/process.ts +690 -0
  64. package/src/polyfills/punycode.ts +159 -0
  65. package/src/polyfills/querystring.ts +93 -0
  66. package/src/polyfills/quic.ts +118 -0
  67. package/src/polyfills/readdirp.ts +229 -0
  68. package/src/polyfills/readline.ts +692 -0
  69. package/src/polyfills/repl.ts +134 -0
  70. package/src/polyfills/rollup.ts +119 -0
  71. package/src/polyfills/sea.ts +33 -0
  72. package/src/polyfills/sqlite.ts +78 -0
  73. package/src/polyfills/stream.ts +1620 -0
  74. package/src/polyfills/string_decoder.ts +25 -0
  75. package/src/polyfills/tailwindcss-oxide.ts +309 -0
  76. package/src/polyfills/test.ts +197 -0
  77. package/src/polyfills/timers.ts +32 -0
  78. package/src/polyfills/tls.ts +105 -0
  79. package/src/polyfills/trace_events.ts +50 -0
  80. package/src/polyfills/tty.ts +71 -0
  81. package/src/polyfills/url.ts +174 -0
  82. package/src/polyfills/util.ts +559 -0
  83. package/src/polyfills/v8.ts +126 -0
  84. package/src/polyfills/vm.ts +132 -0
  85. package/src/polyfills/volume-registry.ts +15 -0
  86. package/src/polyfills/wasi.ts +44 -0
  87. package/src/polyfills/worker_threads.ts +326 -0
  88. package/src/polyfills/ws.ts +595 -0
  89. package/src/polyfills/zlib.ts +881 -0
  90. package/src/request-proxy.ts +716 -0
  91. package/src/script-engine.ts +3375 -0
  92. package/src/sdk/nodepod-fs.ts +93 -0
  93. package/src/sdk/nodepod-process.ts +86 -0
  94. package/src/sdk/nodepod-terminal.ts +350 -0
  95. package/src/sdk/nodepod.ts +509 -0
  96. package/src/sdk/types.ts +70 -0
  97. package/src/shell/commands/bun.ts +121 -0
  98. package/src/shell/commands/directory.ts +297 -0
  99. package/src/shell/commands/file-ops.ts +525 -0
  100. package/src/shell/commands/git.ts +2142 -0
  101. package/src/shell/commands/node.ts +80 -0
  102. package/src/shell/commands/npm.ts +198 -0
  103. package/src/shell/commands/pm-types.ts +45 -0
  104. package/src/shell/commands/pnpm.ts +82 -0
  105. package/src/shell/commands/search.ts +264 -0
  106. package/src/shell/commands/shell-env.ts +352 -0
  107. package/src/shell/commands/text-processing.ts +1152 -0
  108. package/src/shell/commands/yarn.ts +84 -0
  109. package/src/shell/shell-builtins.ts +19 -0
  110. package/src/shell/shell-helpers.ts +250 -0
  111. package/src/shell/shell-interpreter.ts +514 -0
  112. package/src/shell/shell-parser.ts +429 -0
  113. package/src/shell/shell-types.ts +85 -0
  114. package/src/syntax-transforms.ts +561 -0
  115. package/src/threading/engine-worker.ts +64 -0
  116. package/src/threading/inline-worker.ts +372 -0
  117. package/src/threading/offload-types.ts +112 -0
  118. package/src/threading/offload-worker.ts +383 -0
  119. package/src/threading/offload.ts +271 -0
  120. package/src/threading/process-context.ts +92 -0
  121. package/src/threading/process-handle.ts +275 -0
  122. package/src/threading/process-manager.ts +956 -0
  123. package/src/threading/process-worker-entry.ts +854 -0
  124. package/src/threading/shared-vfs.ts +352 -0
  125. package/src/threading/sync-channel.ts +135 -0
  126. package/src/threading/task-queue.ts +177 -0
  127. package/src/threading/vfs-bridge.ts +231 -0
  128. package/src/threading/worker-pool.ts +233 -0
  129. package/src/threading/worker-protocol.ts +358 -0
  130. package/src/threading/worker-vfs.ts +218 -0
  131. package/src/types/externals.d.ts +38 -0
  132. package/src/types/fs-streams.ts +142 -0
  133. package/src/types/manifest.ts +17 -0
  134. package/src/worker-sandbox.ts +90 -0
@@ -0,0 +1,336 @@
1
+ // Chokidar-compatible file watcher on top of MemoryVolume.watch()
2
+
3
+
4
+ import type { MemoryVolume, FileWatchHandle, FileStat } from "../memory-volume";
5
+ import { setSharedVolume, getSharedVolume } from "./volume-registry";
6
+
7
+
8
+ export function setVolume(vol: MemoryVolume): void {
9
+ setSharedVolume(vol);
10
+ }
11
+
12
+
13
+ type Listener = (...args: unknown[]) => void;
14
+
15
+ interface MiniEmitter {
16
+ handlers: Map<string, Set<Listener>>;
17
+ on(name: string, fn: Listener): this;
18
+ off(name: string, fn: Listener): this;
19
+ fire(name: string, ...args: unknown[]): void;
20
+ }
21
+
22
+ interface MiniEmitterConstructor {
23
+ new (): MiniEmitter;
24
+ (this: any): void;
25
+ prototype: any;
26
+ }
27
+
28
+ const MiniEmitter = function MiniEmitter(this: any) {
29
+ if (!this) return;
30
+ this.handlers = new Map<string, Set<Listener>>();
31
+ } as unknown as MiniEmitterConstructor;
32
+
33
+ MiniEmitter.prototype.on = function on(this: any, name: string, fn: Listener): any {
34
+ if (!this.handlers.has(name)) this.handlers.set(name, new Set());
35
+ this.handlers.get(name)!.add(fn);
36
+ return this;
37
+ };
38
+
39
+ MiniEmitter.prototype.off = function off(this: any, name: string, fn: Listener): any {
40
+ this.handlers.get(name)?.delete(fn);
41
+ return this;
42
+ };
43
+
44
+ MiniEmitter.prototype.fire = function fire(this: any, name: string, ...args: unknown[]): void {
45
+ const set = this.handlers.get(name);
46
+ if (!set) return;
47
+ for (const fn of set) {
48
+ try {
49
+ fn(...args);
50
+ } catch {
51
+ /* swallow listener errors */
52
+ }
53
+ }
54
+ };
55
+
56
+
57
+ export interface WatcherConfig {
58
+ persistent?: boolean;
59
+ ignored?:
60
+ | string
61
+ | RegExp
62
+ | ((p: string) => boolean)
63
+ | Array<string | RegExp | ((p: string) => boolean)>;
64
+ ignoreInitial?: boolean;
65
+ followSymlinks?: boolean;
66
+ cwd?: string;
67
+ disableGlobbing?: boolean;
68
+ usePolling?: boolean;
69
+ interval?: number;
70
+ binaryInterval?: number;
71
+ alwaysStat?: boolean;
72
+ depth?: number;
73
+ awaitWriteFinish?:
74
+ | boolean
75
+ | { stabilityThreshold?: number; pollInterval?: number };
76
+ ignorePermissionErrors?: boolean;
77
+ atomic?: boolean | number;
78
+ }
79
+
80
+
81
+ export interface PathWatcher extends MiniEmitter {
82
+ vol: MemoryVolume;
83
+ cfg: WatcherConfig;
84
+ handles: Map<string, FileWatchHandle>;
85
+ terminated: boolean;
86
+ initialised: boolean;
87
+ add(targets: string | readonly string[]): this;
88
+ unwatch(targets: string | readonly string[]): this;
89
+ close(): Promise<void>;
90
+ getWatched(): Record<string, string[]>;
91
+ resolvePath(raw: string): string;
92
+ isExcluded(target: string): boolean;
93
+ gatherInitial(dir: string, queue: Array<() => void>): void;
94
+ attachWatcher(target: string, filterFor?: string): void;
95
+ watchSubtree(dir: string, level?: number): void;
96
+ }
97
+
98
+ interface PathWatcherConstructor {
99
+ new (cfg?: WatcherConfig): PathWatcher;
100
+ (this: any, cfg?: WatcherConfig): void;
101
+ prototype: any;
102
+ }
103
+
104
+ export const PathWatcher = function PathWatcher(this: any, cfg: WatcherConfig = {}) {
105
+ if (!this) return;
106
+ MiniEmitter.call(this);
107
+ const vol = getSharedVolume();
108
+ if (!vol) {
109
+ throw new Error(
110
+ "chokidar: MemoryVolume not set. Call setVolume() first.",
111
+ );
112
+ }
113
+ this.vol = vol;
114
+ this.cfg = cfg;
115
+ this.handles = new Map<string, FileWatchHandle>();
116
+ this.terminated = false;
117
+ this.initialised = false;
118
+ } as unknown as PathWatcherConstructor;
119
+
120
+ Object.setPrototypeOf(PathWatcher.prototype, MiniEmitter.prototype);
121
+
122
+ PathWatcher.prototype.add = function add(this: any, targets: string | readonly string[]): any {
123
+ if (this.terminated) return this;
124
+
125
+ const list = Array.isArray(targets) ? targets : [targets];
126
+ const deferred: Array<() => void> = [];
127
+
128
+ for (const raw of list) {
129
+ const absolute = this.resolvePath(raw);
130
+ if (this.isExcluded(absolute) || this.handles.has(absolute)) continue;
131
+
132
+ try {
133
+ if (!this.vol.existsSync(absolute)) {
134
+ // Path does not exist yet -- watch its parent so we detect creation
135
+ const parentDir =
136
+ absolute.substring(0, absolute.lastIndexOf("/")) || "/";
137
+ if (this.vol.existsSync(parentDir)) {
138
+ this.attachWatcher(parentDir, absolute);
139
+ }
140
+ continue;
141
+ }
142
+
143
+ const info = this.vol.statSync(absolute);
144
+
145
+ if (!this.cfg.ignoreInitial) {
146
+ if (info.isDirectory()) {
147
+ this.gatherInitial(absolute, deferred);
148
+ } else {
149
+ deferred.push(() => this.fire("add", absolute, info));
150
+ }
151
+ }
152
+
153
+ this.attachWatcher(absolute);
154
+
155
+ if (info.isDirectory()) {
156
+ this.watchSubtree(absolute);
157
+ }
158
+ } catch (err) {
159
+ this.fire("error", err);
160
+ }
161
+ }
162
+
163
+ if (!this.initialised) {
164
+ this.initialised = true;
165
+ setTimeout(() => {
166
+ for (const emit of deferred) emit();
167
+ this.fire("ready");
168
+ }, 0);
169
+ }
170
+
171
+ return this;
172
+ };
173
+
174
+ PathWatcher.prototype.unwatch = function unwatch(this: any, targets: string | readonly string[]): any {
175
+ const list = Array.isArray(targets) ? targets : [targets];
176
+ for (const raw of list) {
177
+ const absolute = this.resolvePath(raw);
178
+ const h = this.handles.get(absolute);
179
+ if (h) {
180
+ h.close();
181
+ this.handles.delete(absolute);
182
+ }
183
+ }
184
+ return this;
185
+ };
186
+
187
+ PathWatcher.prototype.close = function close(this: any): Promise<void> {
188
+ this.terminated = true;
189
+ for (const h of this.handles.values()) h.close();
190
+ this.handles.clear();
191
+ this.fire("close");
192
+ return Promise.resolve();
193
+ };
194
+
195
+ PathWatcher.prototype.getWatched = function getWatched(this: any): Record<string, string[]> {
196
+ const result: Record<string, string[]> = {};
197
+ for (const p of this.handles.keys()) {
198
+ const dir = p.substring(0, p.lastIndexOf("/")) || "/";
199
+ const base = p.substring(p.lastIndexOf("/") + 1);
200
+ if (!result[dir]) result[dir] = [];
201
+ result[dir].push(base);
202
+ }
203
+ return result;
204
+ };
205
+
206
+ PathWatcher.prototype.resolvePath = function resolvePath(this: any, raw: string): string {
207
+ let p = raw;
208
+ if (this.cfg.cwd && !p.startsWith("/")) {
209
+ p = this.cfg.cwd + "/" + p;
210
+ }
211
+ if (!p.startsWith("/")) p = "/" + p;
212
+ return p;
213
+ };
214
+
215
+ PathWatcher.prototype.isExcluded = function isExcluded(this: any, target: string): boolean {
216
+ const { ignored } = this.cfg;
217
+ if (!ignored) return false;
218
+
219
+ const rules = Array.isArray(ignored) ? ignored : [ignored];
220
+ for (const rule of rules) {
221
+ if (typeof rule === "string") {
222
+ if (target === rule || target.startsWith(rule + "/")) return true;
223
+ } else if (rule instanceof RegExp) {
224
+ if (rule.test(target)) return true;
225
+ } else if (typeof rule === "function") {
226
+ if (rule(target)) return true;
227
+ }
228
+ }
229
+ return false;
230
+ };
231
+
232
+ PathWatcher.prototype.gatherInitial = function gatherInitial(this: any, dir: string, queue: Array<() => void>): void {
233
+ try {
234
+ const children = this.vol.readdirSync(dir);
235
+ for (const child of children) {
236
+ const full = dir === "/" ? "/" + child : dir + "/" + child;
237
+ if (this.isExcluded(full)) continue;
238
+ const st = this.vol.statSync(full);
239
+ if (st.isDirectory()) {
240
+ queue.push(() => this.fire("addDir", full, st));
241
+ this.gatherInitial(full, queue);
242
+ } else {
243
+ queue.push(() => this.fire("add", full, st));
244
+ }
245
+ }
246
+ } catch {
247
+ /* swallow read errors during initial scan */
248
+ }
249
+ };
250
+
251
+ PathWatcher.prototype.attachWatcher = function attachWatcher(this: any, target: string, filterFor?: string): void {
252
+ if (this.handles.has(target)) return;
253
+
254
+ const self = this;
255
+ const handle = this.vol.watch(
256
+ target,
257
+ { recursive: true },
258
+ (kind: string, filename: string | null) => {
259
+ if (self.terminated) return;
260
+
261
+ let resolved: string;
262
+ if (filename) {
263
+ resolved = target === "/" ? "/" + filename : target + "/" + filename;
264
+ } else {
265
+ resolved = target;
266
+ }
267
+
268
+ if (
269
+ filterFor &&
270
+ resolved !== filterFor &&
271
+ !resolved.startsWith(filterFor + "/")
272
+ )
273
+ return;
274
+ if (self.isExcluded(resolved)) return;
275
+
276
+ if (kind === "rename") {
277
+ if (self.vol.existsSync(resolved)) {
278
+ try {
279
+ const st = self.vol.statSync(resolved);
280
+ const eventName = st.isDirectory() ? "addDir" : "add";
281
+ self.fire(eventName, resolved, st);
282
+ self.fire("all", eventName, resolved, st);
283
+ } catch {
284
+ /* vanished between check and stat */
285
+ }
286
+ } else {
287
+ self.fire("unlink", resolved);
288
+ self.fire("all", "unlink", resolved);
289
+ }
290
+ } else if (kind === "change") {
291
+ try {
292
+ const st = self.vol.statSync(resolved);
293
+ self.fire("change", resolved, st);
294
+ self.fire("all", "change", resolved, st);
295
+ } catch {
296
+ self.fire("unlink", resolved);
297
+ self.fire("all", "unlink", resolved);
298
+ }
299
+ }
300
+ },
301
+ );
302
+
303
+ this.handles.set(target, handle);
304
+ };
305
+
306
+ PathWatcher.prototype.watchSubtree = function watchSubtree(this: any, dir: string, level: number = 0): void {
307
+ if (this.cfg.depth !== undefined && level > this.cfg.depth) return;
308
+ try {
309
+ const children = this.vol.readdirSync(dir);
310
+ for (const name of children) {
311
+ const full = dir === "/" ? "/" + name : dir + "/" + name;
312
+ if (this.isExcluded(full)) continue;
313
+ try {
314
+ if (this.vol.statSync(full).isDirectory()) {
315
+ this.attachWatcher(full);
316
+ this.watchSubtree(full, level + 1);
317
+ }
318
+ } catch {
319
+ /* skip */
320
+ }
321
+ }
322
+ } catch {
323
+ /* skip */
324
+ }
325
+ };
326
+
327
+ export function watch(
328
+ targets: string | readonly string[],
329
+ options?: WatcherConfig,
330
+ ): PathWatcher {
331
+ const watcher = new PathWatcher(options);
332
+ watcher.add(targets);
333
+ return watcher;
334
+ }
335
+
336
+ export default { watch, PathWatcher, setVolume };
@@ -0,0 +1,106 @@
1
+ // stub - not available in browser, always reports as primary
2
+
3
+ import { EventEmitter } from "./events";
4
+
5
+ /* ------------------------------------------------------------------ */
6
+ /* Flags */
7
+ /* ------------------------------------------------------------------ */
8
+
9
+ export const isMaster = true;
10
+ export const isPrimary = true;
11
+ export const isWorker = false;
12
+
13
+ /* ------------------------------------------------------------------ */
14
+ /* Worker */
15
+ /* ------------------------------------------------------------------ */
16
+
17
+ export interface Worker extends EventEmitter {
18
+ id: number;
19
+ process: null;
20
+ send(_msg: unknown, _cb?: (err: Error | null) => void): boolean;
21
+ kill(_sig?: string): void;
22
+ disconnect(): void;
23
+ isDead(): boolean;
24
+ isConnected(): boolean;
25
+ }
26
+
27
+ export const Worker = function Worker(this: any) {
28
+ if (!this) return;
29
+ EventEmitter.call(this);
30
+ this.id = 0;
31
+ this.process = null;
32
+ } as unknown as { new(): Worker; prototype: any };
33
+
34
+ Object.setPrototypeOf(Worker.prototype, EventEmitter.prototype);
35
+
36
+ Worker.prototype.send = function send(_msg: unknown, _cb?: (err: Error | null) => void): boolean { return false; };
37
+ Worker.prototype.kill = function kill(_sig?: string): void {};
38
+ Worker.prototype.disconnect = function disconnect(): void {};
39
+ Worker.prototype.isDead = function isDead(): boolean { return false; };
40
+ Worker.prototype.isConnected = function isConnected(): boolean { return false; };
41
+
42
+ /* ------------------------------------------------------------------ */
43
+ /* Singletons */
44
+ /* ------------------------------------------------------------------ */
45
+
46
+ export const worker: Worker | null = null;
47
+ export const workers: Record<number, Worker> = {};
48
+ export const settings: Record<string, unknown> = {};
49
+
50
+ /* ------------------------------------------------------------------ */
51
+ /* Scheduling */
52
+ /* ------------------------------------------------------------------ */
53
+
54
+ export const SCHED_NONE = 1;
55
+ export const SCHED_RR = 2;
56
+ export let schedulingPolicy = SCHED_RR;
57
+
58
+ /* ------------------------------------------------------------------ */
59
+ /* Functions */
60
+ /* ------------------------------------------------------------------ */
61
+
62
+ export function fork(_env?: object): Worker {
63
+ return new Worker();
64
+ }
65
+
66
+ export function disconnect(done?: () => void): void {
67
+ if (done) setTimeout(done, 0);
68
+ }
69
+
70
+ export function setupMaster(_cfg?: object): void {}
71
+ export function setupPrimary(_cfg?: object): void {}
72
+
73
+ /* ------------------------------------------------------------------ */
74
+ /* Event emitter delegation */
75
+ /* ------------------------------------------------------------------ */
76
+
77
+ const _bus = new EventEmitter();
78
+ export const on = _bus.on.bind(_bus);
79
+ export const once = _bus.once.bind(_bus);
80
+ export const emit = _bus.emit.bind(_bus);
81
+ export const removeListener = _bus.removeListener.bind(_bus);
82
+
83
+ /* ------------------------------------------------------------------ */
84
+ /* Default export */
85
+ /* ------------------------------------------------------------------ */
86
+
87
+ export default {
88
+ isMaster,
89
+ isPrimary,
90
+ isWorker,
91
+ Worker,
92
+ worker,
93
+ workers,
94
+ fork,
95
+ disconnect,
96
+ settings,
97
+ SCHED_NONE,
98
+ SCHED_RR,
99
+ schedulingPolicy,
100
+ setupMaster,
101
+ setupPrimary,
102
+ on,
103
+ once,
104
+ emit,
105
+ removeListener,
106
+ };
@@ -0,0 +1,136 @@
1
+ // Console class matching Node.js constructor (accepts stdout/stderr streams)
2
+
3
+
4
+ /* ------------------------------------------------------------------ */
5
+ /* Console class */
6
+ /* ------------------------------------------------------------------ */
7
+
8
+ export interface Console {
9
+ _out: { write: (s: string) => void } | null;
10
+ _err: { write: (s: string) => void } | null;
11
+ _emit(target: "out" | "err", args: unknown[]): void;
12
+ log(...a: unknown[]): void;
13
+ error(...a: unknown[]): void;
14
+ warn(...a: unknown[]): void;
15
+ info(...a: unknown[]): void;
16
+ debug(...a: unknown[]): void;
17
+ trace(...a: unknown[]): void;
18
+ dir(o: unknown): void;
19
+ time(): void;
20
+ timeEnd(): void;
21
+ timeLog(): void;
22
+ assert(v: unknown, ...a: unknown[]): void;
23
+ clear(): void;
24
+ count(): void;
25
+ countReset(): void;
26
+ group(): void;
27
+ groupCollapsed(): void;
28
+ groupEnd(): void;
29
+ table(d: unknown): void;
30
+ }
31
+
32
+ interface ConsoleConstructor {
33
+ new (stdout?: unknown, stderr?: unknown): Console;
34
+ (this: any, stdout?: unknown, stderr?: unknown): void;
35
+ prototype: any;
36
+ }
37
+
38
+ export const Console = function Console(this: any, stdout?: unknown, stderr?: unknown) {
39
+ if (!this) return;
40
+ const o = stdout as Record<string, unknown> | undefined;
41
+ if (o && typeof o === "object" && "write" in o) {
42
+ // new Console(stream) or new Console(stdout, stderr)
43
+ this._out = o as unknown as { write: (s: string) => void };
44
+ this._err =
45
+ (stderr as { write: (s: string) => void }) || this._out;
46
+ } else if (o && typeof o === "object" && "stdout" in o) {
47
+ // new Console({ stdout, stderr })
48
+ this._out = (o.stdout as { write: (s: string) => void }) || null;
49
+ this._err = (o.stderr as { write: (s: string) => void }) || this._out;
50
+ } else {
51
+ this._out = null;
52
+ this._err = null;
53
+ }
54
+ } as unknown as ConsoleConstructor;
55
+
56
+ Console.prototype._emit = function _emit(this: any, target: "out" | "err", args: unknown[]) {
57
+ const text =
58
+ args
59
+ .map((a: unknown) => (typeof a === "string" ? a : JSON.stringify(a)))
60
+ .join(" ") + "\n";
61
+ const dest = target === "err" ? this._err : this._out;
62
+ if (dest) dest.write(text);
63
+ else if (target === "err") globalThis.console.error(...args);
64
+ else globalThis.console.log(...args);
65
+ };
66
+
67
+ Console.prototype.log = function log(this: any, ...a: unknown[]) { this._emit("out", a); };
68
+ Console.prototype.error = function error(this: any, ...a: unknown[]) { this._emit("err", a); };
69
+ Console.prototype.warn = function warn(this: any, ...a: unknown[]) { this._emit("err", a); };
70
+ Console.prototype.info = function info(this: any, ...a: unknown[]) { this._emit("out", a); };
71
+ Console.prototype.debug = function debug(this: any, ...a: unknown[]) { this._emit("out", a); };
72
+ Console.prototype.trace = function trace(this: any, ...a: unknown[]) { this._emit("err", a); };
73
+ Console.prototype.dir = function dir(this: any, o: unknown) { this._emit("out", [o]); };
74
+ Console.prototype.time = function time() {};
75
+ Console.prototype.timeEnd = function timeEnd() {};
76
+ Console.prototype.timeLog = function timeLog() {};
77
+ Console.prototype.assert = function assert(this: any, v: unknown, ...a: unknown[]) {
78
+ if (!v) this._emit("err", ["Assertion failed:", ...a]);
79
+ };
80
+ Console.prototype.clear = function clear() {};
81
+ Console.prototype.count = function count() {};
82
+ Console.prototype.countReset = function countReset() {};
83
+ Console.prototype.group = function group() {};
84
+ Console.prototype.groupCollapsed = function groupCollapsed() {};
85
+ Console.prototype.groupEnd = function groupEnd() {};
86
+ Console.prototype.table = function table(this: any, d: unknown) { this._emit("out", [d]); };
87
+
88
+ /* ------------------------------------------------------------------ */
89
+ /* Named re-exports from global console */
90
+ /* ------------------------------------------------------------------ */
91
+
92
+ const _gc = globalThis.console;
93
+
94
+ export const log = _gc.log.bind(_gc);
95
+ export const error = _gc.error.bind(_gc);
96
+ export const warn = _gc.warn.bind(_gc);
97
+ export const info = _gc.info.bind(_gc);
98
+ export const debug = _gc.debug.bind(_gc);
99
+ export const trace = _gc.trace.bind(_gc);
100
+ export const dir = _gc.dir.bind(_gc);
101
+ export const time = _gc.time.bind(_gc);
102
+ export const timeEnd = _gc.timeEnd.bind(_gc);
103
+ export const timeLog = _gc.timeLog.bind(_gc);
104
+ export const clear = _gc.clear.bind(_gc);
105
+ export const count = _gc.count.bind(_gc);
106
+ export const countReset = _gc.countReset.bind(_gc);
107
+ export const group = _gc.group.bind(_gc);
108
+ export const groupCollapsed = _gc.groupCollapsed.bind(_gc);
109
+ export const groupEnd = _gc.groupEnd.bind(_gc);
110
+ export const table = _gc.table.bind(_gc);
111
+
112
+ /* ------------------------------------------------------------------ */
113
+ /* Default export */
114
+ /* ------------------------------------------------------------------ */
115
+
116
+ export default {
117
+ Console,
118
+ log,
119
+ error,
120
+ warn,
121
+ info,
122
+ debug,
123
+ trace,
124
+ dir,
125
+ time,
126
+ timeEnd,
127
+ timeLog,
128
+ assert: _gc.assert.bind(_gc),
129
+ clear,
130
+ count,
131
+ countReset,
132
+ group,
133
+ groupCollapsed,
134
+ groupEnd,
135
+ table,
136
+ };
@@ -0,0 +1,123 @@
1
+ // OS/filesystem constants (deprecated in Node.js, use os.constants instead)
2
+
3
+
4
+ export const SIGKILL = 9;
5
+ export const SIGTERM = 15;
6
+ export const SIGINT = 2;
7
+ export const SIGHUP = 1;
8
+ export const SIGQUIT = 3;
9
+ export const SIGABRT = 6;
10
+ export const SIGALRM = 14;
11
+ export const SIGUSR1 = 10;
12
+ export const SIGUSR2 = 12;
13
+ export const SIGPIPE = 13;
14
+ export const SIGCHLD = 17;
15
+ export const SIGCONT = 18;
16
+ export const SIGSTOP = 19;
17
+ export const SIGTSTP = 20;
18
+
19
+ // File access constants
20
+ export const F_OK = 0;
21
+ export const R_OK = 4;
22
+ export const W_OK = 2;
23
+ export const X_OK = 1;
24
+
25
+ // File open constants
26
+ export const O_RDONLY = 0;
27
+ export const O_WRONLY = 1;
28
+ export const O_RDWR = 2;
29
+ export const O_CREAT = 64;
30
+ export const O_EXCL = 128;
31
+ export const O_TRUNC = 512;
32
+ export const O_APPEND = 1024;
33
+ export const O_DIRECTORY = 65536;
34
+ export const O_NOFOLLOW = 131072;
35
+ export const O_SYNC = 1052672;
36
+
37
+ // File type constants
38
+ export const S_IFMT = 61440;
39
+ export const S_IFREG = 32768;
40
+ export const S_IFDIR = 16384;
41
+ export const S_IFCHR = 8192;
42
+ export const S_IFBLK = 24576;
43
+ export const S_IFIFO = 4096;
44
+ export const S_IFLNK = 40960;
45
+ export const S_IFSOCK = 49152;
46
+
47
+ // Errno constants
48
+ export const EACCES = -13;
49
+ export const EEXIST = -17;
50
+ export const EISDIR = -21;
51
+ export const EMFILE = -24;
52
+ export const ENOENT = -2;
53
+ export const ENOTDIR = -20;
54
+ export const ENOTEMPTY = -39;
55
+ export const EPERM = -1;
56
+ export const EBADF = -9;
57
+
58
+ export const os = {
59
+ constants: {
60
+ signals: {
61
+ SIGKILL,
62
+ SIGTERM,
63
+ SIGINT,
64
+ SIGHUP,
65
+ SIGQUIT,
66
+ SIGABRT,
67
+ SIGALRM,
68
+ SIGUSR1,
69
+ SIGUSR2,
70
+ SIGPIPE,
71
+ SIGCHLD,
72
+ SIGCONT,
73
+ SIGSTOP,
74
+ SIGTSTP,
75
+ },
76
+ errno: {
77
+ EACCES,
78
+ EEXIST,
79
+ EISDIR,
80
+ EMFILE,
81
+ ENOENT,
82
+ ENOTDIR,
83
+ ENOTEMPTY,
84
+ EPERM,
85
+ EBADF,
86
+ },
87
+ },
88
+ };
89
+
90
+ export const fs = {
91
+ constants: {
92
+ F_OK,
93
+ R_OK,
94
+ W_OK,
95
+ X_OK,
96
+ O_RDONLY,
97
+ O_WRONLY,
98
+ O_RDWR,
99
+ O_CREAT,
100
+ O_EXCL,
101
+ O_TRUNC,
102
+ O_APPEND,
103
+ O_DIRECTORY,
104
+ O_NOFOLLOW,
105
+ O_SYNC,
106
+ S_IFMT,
107
+ S_IFREG,
108
+ S_IFDIR,
109
+ S_IFCHR,
110
+ S_IFBLK,
111
+ S_IFIFO,
112
+ S_IFLNK,
113
+ S_IFSOCK,
114
+ },
115
+ };
116
+
117
+ export default {
118
+ ...os.constants.signals,
119
+ ...os.constants.errno,
120
+ ...fs.constants,
121
+ os,
122
+ fs,
123
+ };