@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.
- package/LICENSE +43 -0
- package/README.md +240 -0
- package/dist/child_process-BJOMsZje.js +8233 -0
- package/dist/child_process-BJOMsZje.js.map +1 -0
- package/dist/child_process-Cj8vOcuc.cjs +7434 -0
- package/dist/child_process-Cj8vOcuc.cjs.map +1 -0
- package/dist/index-Cb1Cgdnd.js +35308 -0
- package/dist/index-Cb1Cgdnd.js.map +1 -0
- package/dist/index-DsMGS-xc.cjs +37195 -0
- package/dist/index-DsMGS-xc.cjs.map +1 -0
- package/dist/index.cjs +65 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.mjs +59 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +95 -0
- package/src/__tests__/smoke.test.ts +11 -0
- package/src/constants/cdn-urls.ts +18 -0
- package/src/constants/config.ts +236 -0
- package/src/cross-origin.ts +26 -0
- package/src/engine-factory.ts +176 -0
- package/src/engine-types.ts +56 -0
- package/src/helpers/byte-encoding.ts +39 -0
- package/src/helpers/digest.ts +9 -0
- package/src/helpers/event-loop.ts +96 -0
- package/src/helpers/wasm-cache.ts +133 -0
- package/src/iframe-sandbox.ts +141 -0
- package/src/index.ts +192 -0
- package/src/isolation-helpers.ts +148 -0
- package/src/memory-volume.ts +941 -0
- package/src/module-transformer.ts +368 -0
- package/src/packages/archive-extractor.ts +248 -0
- package/src/packages/browser-bundler.ts +284 -0
- package/src/packages/installer.ts +396 -0
- package/src/packages/registry-client.ts +131 -0
- package/src/packages/version-resolver.ts +411 -0
- package/src/polyfills/assert.ts +384 -0
- package/src/polyfills/async_hooks.ts +144 -0
- package/src/polyfills/buffer.ts +628 -0
- package/src/polyfills/child_process.ts +2288 -0
- package/src/polyfills/chokidar.ts +336 -0
- package/src/polyfills/cluster.ts +106 -0
- package/src/polyfills/console.ts +136 -0
- package/src/polyfills/constants.ts +123 -0
- package/src/polyfills/crypto.ts +885 -0
- package/src/polyfills/dgram.ts +87 -0
- package/src/polyfills/diagnostics_channel.ts +76 -0
- package/src/polyfills/dns.ts +134 -0
- package/src/polyfills/domain.ts +68 -0
- package/src/polyfills/esbuild.ts +854 -0
- package/src/polyfills/events.ts +276 -0
- package/src/polyfills/fs.ts +2888 -0
- package/src/polyfills/fsevents.ts +79 -0
- package/src/polyfills/http.ts +1449 -0
- package/src/polyfills/http2.ts +199 -0
- package/src/polyfills/https.ts +76 -0
- package/src/polyfills/inspector.ts +62 -0
- package/src/polyfills/lightningcss.ts +105 -0
- package/src/polyfills/module.ts +191 -0
- package/src/polyfills/net.ts +353 -0
- package/src/polyfills/os.ts +238 -0
- package/src/polyfills/path.ts +206 -0
- package/src/polyfills/perf_hooks.ts +102 -0
- package/src/polyfills/process.ts +690 -0
- package/src/polyfills/punycode.ts +159 -0
- package/src/polyfills/querystring.ts +93 -0
- package/src/polyfills/quic.ts +118 -0
- package/src/polyfills/readdirp.ts +229 -0
- package/src/polyfills/readline.ts +692 -0
- package/src/polyfills/repl.ts +134 -0
- package/src/polyfills/rollup.ts +119 -0
- package/src/polyfills/sea.ts +33 -0
- package/src/polyfills/sqlite.ts +78 -0
- package/src/polyfills/stream.ts +1620 -0
- package/src/polyfills/string_decoder.ts +25 -0
- package/src/polyfills/tailwindcss-oxide.ts +309 -0
- package/src/polyfills/test.ts +197 -0
- package/src/polyfills/timers.ts +32 -0
- package/src/polyfills/tls.ts +105 -0
- package/src/polyfills/trace_events.ts +50 -0
- package/src/polyfills/tty.ts +71 -0
- package/src/polyfills/url.ts +174 -0
- package/src/polyfills/util.ts +559 -0
- package/src/polyfills/v8.ts +126 -0
- package/src/polyfills/vm.ts +132 -0
- package/src/polyfills/volume-registry.ts +15 -0
- package/src/polyfills/wasi.ts +44 -0
- package/src/polyfills/worker_threads.ts +326 -0
- package/src/polyfills/ws.ts +595 -0
- package/src/polyfills/zlib.ts +881 -0
- package/src/request-proxy.ts +716 -0
- package/src/script-engine.ts +3375 -0
- package/src/sdk/nodepod-fs.ts +93 -0
- package/src/sdk/nodepod-process.ts +86 -0
- package/src/sdk/nodepod-terminal.ts +350 -0
- package/src/sdk/nodepod.ts +509 -0
- package/src/sdk/types.ts +70 -0
- package/src/shell/commands/bun.ts +121 -0
- package/src/shell/commands/directory.ts +297 -0
- package/src/shell/commands/file-ops.ts +525 -0
- package/src/shell/commands/git.ts +2142 -0
- package/src/shell/commands/node.ts +80 -0
- package/src/shell/commands/npm.ts +198 -0
- package/src/shell/commands/pm-types.ts +45 -0
- package/src/shell/commands/pnpm.ts +82 -0
- package/src/shell/commands/search.ts +264 -0
- package/src/shell/commands/shell-env.ts +352 -0
- package/src/shell/commands/text-processing.ts +1152 -0
- package/src/shell/commands/yarn.ts +84 -0
- package/src/shell/shell-builtins.ts +19 -0
- package/src/shell/shell-helpers.ts +250 -0
- package/src/shell/shell-interpreter.ts +514 -0
- package/src/shell/shell-parser.ts +429 -0
- package/src/shell/shell-types.ts +85 -0
- package/src/syntax-transforms.ts +561 -0
- package/src/threading/engine-worker.ts +64 -0
- package/src/threading/inline-worker.ts +372 -0
- package/src/threading/offload-types.ts +112 -0
- package/src/threading/offload-worker.ts +383 -0
- package/src/threading/offload.ts +271 -0
- package/src/threading/process-context.ts +92 -0
- package/src/threading/process-handle.ts +275 -0
- package/src/threading/process-manager.ts +956 -0
- package/src/threading/process-worker-entry.ts +854 -0
- package/src/threading/shared-vfs.ts +352 -0
- package/src/threading/sync-channel.ts +135 -0
- package/src/threading/task-queue.ts +177 -0
- package/src/threading/vfs-bridge.ts +231 -0
- package/src/threading/worker-pool.ts +233 -0
- package/src/threading/worker-protocol.ts +358 -0
- package/src/threading/worker-vfs.ts +218 -0
- package/src/types/externals.d.ts +38 -0
- package/src/types/fs-streams.ts +142 -0
- package/src/types/manifest.ts +17 -0
- package/src/worker-sandbox.ts +90 -0
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
// TCP / net polyfill -- all networking is simulated, no real kernel sockets
|
|
2
|
+
|
|
3
|
+
import { EventEmitter, type EventHandler } from "./events";
|
|
4
|
+
import { Duplex } from "./stream";
|
|
5
|
+
import { Buffer } from "./buffer";
|
|
6
|
+
import { PORT_RANGE } from "../constants/config";
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
export interface NetAddress {
|
|
10
|
+
address: string;
|
|
11
|
+
family: string;
|
|
12
|
+
port: number;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface SocketConfig {
|
|
16
|
+
allowHalfOpen?: boolean;
|
|
17
|
+
readable?: boolean;
|
|
18
|
+
writable?: boolean;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface ServerConfig {
|
|
22
|
+
allowHalfOpen?: boolean;
|
|
23
|
+
pauseOnConnect?: boolean;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface BindOptions {
|
|
27
|
+
port?: number;
|
|
28
|
+
host?: string;
|
|
29
|
+
backlog?: number;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
export interface TcpSocket extends Duplex {
|
|
34
|
+
localAddress: string;
|
|
35
|
+
localPort: number;
|
|
36
|
+
remoteAddress?: string;
|
|
37
|
+
remotePort?: number;
|
|
38
|
+
remoteFamily?: string;
|
|
39
|
+
connecting: boolean;
|
|
40
|
+
pending: boolean;
|
|
41
|
+
destroyed: boolean;
|
|
42
|
+
encrypted: boolean;
|
|
43
|
+
readyState: string;
|
|
44
|
+
bytesRead: number;
|
|
45
|
+
bytesWritten: number;
|
|
46
|
+
connect(portOrOpts: any, hostOrCb?: any, cb?: any): this;
|
|
47
|
+
address(): NetAddress | null;
|
|
48
|
+
setEncoding(enc: BufferEncoding): this;
|
|
49
|
+
setTimeout(ms: number, handler?: () => void): this;
|
|
50
|
+
setNoDelay(v?: boolean): this;
|
|
51
|
+
setKeepAlive(on?: boolean, delay?: number): this;
|
|
52
|
+
ref(): this;
|
|
53
|
+
unref(): this;
|
|
54
|
+
destroy(err?: Error): this;
|
|
55
|
+
_feedData(chunk: Buffer | string): void;
|
|
56
|
+
_feedEnd(): void;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface TcpSocketConstructor {
|
|
60
|
+
new (cfg?: SocketConfig): TcpSocket;
|
|
61
|
+
(this: any, cfg?: SocketConfig): void;
|
|
62
|
+
prototype: any;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export const TcpSocket = function TcpSocket(this: any, _cfg?: SocketConfig) {
|
|
66
|
+
if (!this) return;
|
|
67
|
+
Duplex.call(this);
|
|
68
|
+
|
|
69
|
+
this._isConnecting = false;
|
|
70
|
+
this._isConnected = false;
|
|
71
|
+
this._isDestroyed = false;
|
|
72
|
+
this._peerAddr = "";
|
|
73
|
+
this._peerPort = 0;
|
|
74
|
+
this._selfAddr = "127.0.0.1";
|
|
75
|
+
this._selfPort = 0;
|
|
76
|
+
|
|
77
|
+
this.localAddress = "127.0.0.1";
|
|
78
|
+
this.localPort = 0;
|
|
79
|
+
this.remoteAddress = undefined;
|
|
80
|
+
this.remotePort = undefined;
|
|
81
|
+
this.remoteFamily = undefined;
|
|
82
|
+
this.connecting = false;
|
|
83
|
+
this.pending = false;
|
|
84
|
+
this.destroyed = false;
|
|
85
|
+
this.encrypted = false;
|
|
86
|
+
this.readyState = "closed";
|
|
87
|
+
this.bytesRead = 0;
|
|
88
|
+
this.bytesWritten = 0;
|
|
89
|
+
} as unknown as TcpSocketConstructor;
|
|
90
|
+
|
|
91
|
+
Object.setPrototypeOf(TcpSocket.prototype, Duplex.prototype);
|
|
92
|
+
|
|
93
|
+
TcpSocket.prototype.connect = function connect(
|
|
94
|
+
portOrOpts: number | { port: number; host?: string },
|
|
95
|
+
hostOrCb?: string | (() => void),
|
|
96
|
+
cb?: () => void,
|
|
97
|
+
): any {
|
|
98
|
+
let port: number;
|
|
99
|
+
let host = "127.0.0.1";
|
|
100
|
+
let done: (() => void) | undefined;
|
|
101
|
+
|
|
102
|
+
if (typeof portOrOpts === "number") {
|
|
103
|
+
port = portOrOpts;
|
|
104
|
+
if (typeof hostOrCb === "string") {
|
|
105
|
+
host = hostOrCb;
|
|
106
|
+
done = cb;
|
|
107
|
+
} else done = hostOrCb;
|
|
108
|
+
} else {
|
|
109
|
+
port = portOrOpts.port;
|
|
110
|
+
host = portOrOpts.host ?? "127.0.0.1";
|
|
111
|
+
done = typeof hostOrCb === "function" ? hostOrCb : cb;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
this._isConnecting = true;
|
|
115
|
+
this.connecting = true;
|
|
116
|
+
this._peerAddr = host;
|
|
117
|
+
this._peerPort = port;
|
|
118
|
+
this.remoteAddress = host;
|
|
119
|
+
this.remotePort = port;
|
|
120
|
+
this.remoteFamily = "IPv4";
|
|
121
|
+
this.readyState = "opening";
|
|
122
|
+
|
|
123
|
+
const self = this;
|
|
124
|
+
queueMicrotask(() => {
|
|
125
|
+
self._isConnecting = false;
|
|
126
|
+
self._isConnected = true;
|
|
127
|
+
self.connecting = false;
|
|
128
|
+
self.readyState = "open";
|
|
129
|
+
self.emit("connect");
|
|
130
|
+
if (done) done();
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
return this;
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
TcpSocket.prototype.address = function address(): NetAddress | null {
|
|
137
|
+
if (!this._isConnected) return null;
|
|
138
|
+
return { address: this._selfAddr, family: "IPv4", port: this._selfPort };
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
TcpSocket.prototype.setEncoding = function setEncoding(_enc: BufferEncoding): any {
|
|
142
|
+
return this;
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
TcpSocket.prototype.setTimeout = function setTimeout(ms: number, handler?: () => void): any {
|
|
146
|
+
if (handler) this.once("timeout", handler);
|
|
147
|
+
return this;
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
TcpSocket.prototype.setNoDelay = function setNoDelay(_v?: boolean): any {
|
|
151
|
+
return this;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
TcpSocket.prototype.setKeepAlive = function setKeepAlive(_on?: boolean, _delay?: number): any {
|
|
155
|
+
return this;
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
TcpSocket.prototype.ref = function ref(): any {
|
|
159
|
+
return this;
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
TcpSocket.prototype.unref = function unref(): any {
|
|
163
|
+
return this;
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
TcpSocket.prototype.destroy = function destroy(err?: Error): any {
|
|
167
|
+
if (this._isDestroyed) return this;
|
|
168
|
+
this._isDestroyed = true;
|
|
169
|
+
this._isConnected = false;
|
|
170
|
+
this.destroyed = true;
|
|
171
|
+
this.readyState = "closed";
|
|
172
|
+
if (err) this.emit("error", err);
|
|
173
|
+
const self = this;
|
|
174
|
+
queueMicrotask(() => self.emit("close", !!err));
|
|
175
|
+
return this;
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
TcpSocket.prototype._feedData = function _feedData(chunk: Buffer | string): void {
|
|
179
|
+
const buf = typeof chunk === "string" ? Buffer.from(chunk) : chunk;
|
|
180
|
+
this.push(buf);
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
TcpSocket.prototype._feedEnd = function _feedEnd(): void {
|
|
184
|
+
this.push(null);
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
export interface TcpServer extends EventEmitter {
|
|
189
|
+
listening: boolean;
|
|
190
|
+
maxConnections?: number;
|
|
191
|
+
listen(portOrOpts?: any, hostOrCb?: any, backlogOrCb?: any, cb?: any): this;
|
|
192
|
+
address(): (NetAddress & { host?: string }) | null;
|
|
193
|
+
close(cb?: (err?: Error) => void): this;
|
|
194
|
+
getConnections(cb?: (err: Error | null, n: number) => void): void;
|
|
195
|
+
ref(): this;
|
|
196
|
+
unref(): this;
|
|
197
|
+
_acceptConnection(sock: TcpSocket): void;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export interface TcpServerConstructor {
|
|
201
|
+
new (cfgOrHandler?: ServerConfig | ((sock: TcpSocket) => void), handler?: (sock: TcpSocket) => void): TcpServer;
|
|
202
|
+
(this: any, cfgOrHandler?: ServerConfig | ((sock: TcpSocket) => void), handler?: (sock: TcpSocket) => void): void;
|
|
203
|
+
prototype: any;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export const TcpServer = function TcpServer(
|
|
207
|
+
this: any,
|
|
208
|
+
cfgOrHandler?: ServerConfig | ((sock: TcpSocket) => void),
|
|
209
|
+
handler?: (sock: TcpSocket) => void,
|
|
210
|
+
) {
|
|
211
|
+
if (!this) return;
|
|
212
|
+
EventEmitter.call(this);
|
|
213
|
+
|
|
214
|
+
this._bound = false;
|
|
215
|
+
this._addr = null;
|
|
216
|
+
this._peers = new Set();
|
|
217
|
+
this._cap = Infinity;
|
|
218
|
+
this.listening = false;
|
|
219
|
+
this.maxConnections = undefined;
|
|
220
|
+
|
|
221
|
+
let fn: ((s: TcpSocket) => void) | undefined;
|
|
222
|
+
if (typeof cfgOrHandler === "function") fn = cfgOrHandler;
|
|
223
|
+
else fn = handler;
|
|
224
|
+
if (fn) this.on("connection", fn as EventHandler);
|
|
225
|
+
} as unknown as TcpServerConstructor;
|
|
226
|
+
|
|
227
|
+
Object.setPrototypeOf(TcpServer.prototype, EventEmitter.prototype);
|
|
228
|
+
|
|
229
|
+
TcpServer.prototype.listen = function listen(
|
|
230
|
+
portOrOpts?: number | BindOptions,
|
|
231
|
+
hostOrCb?: string | number | (() => void),
|
|
232
|
+
backlogOrCb?: number | (() => void),
|
|
233
|
+
cb?: () => void,
|
|
234
|
+
): any {
|
|
235
|
+
let port = 0;
|
|
236
|
+
let host = "0.0.0.0";
|
|
237
|
+
let done: (() => void) | undefined;
|
|
238
|
+
|
|
239
|
+
if (typeof portOrOpts === "number") {
|
|
240
|
+
port = portOrOpts;
|
|
241
|
+
if (typeof hostOrCb === "string") {
|
|
242
|
+
host = hostOrCb;
|
|
243
|
+
done = typeof backlogOrCb === "function" ? backlogOrCb : cb;
|
|
244
|
+
} else if (typeof hostOrCb === "function") {
|
|
245
|
+
done = hostOrCb;
|
|
246
|
+
} else {
|
|
247
|
+
done = typeof backlogOrCb === "function" ? backlogOrCb : cb;
|
|
248
|
+
}
|
|
249
|
+
} else if (portOrOpts) {
|
|
250
|
+
port = portOrOpts.port ?? 0;
|
|
251
|
+
host = portOrOpts.host ?? "0.0.0.0";
|
|
252
|
+
done = typeof hostOrCb === "function" ? hostOrCb : cb;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
if (port === 0) port = PORT_RANGE.BASE + Math.floor(Math.random() * PORT_RANGE.RANGE);
|
|
256
|
+
|
|
257
|
+
this._addr = { address: host, family: "IPv4", port };
|
|
258
|
+
this._bound = true;
|
|
259
|
+
this.listening = true;
|
|
260
|
+
|
|
261
|
+
const self = this;
|
|
262
|
+
queueMicrotask(() => {
|
|
263
|
+
self.emit("listening");
|
|
264
|
+
if (done) done();
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
return this;
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
TcpServer.prototype.address = function address(): (NetAddress & { host?: string }) | null {
|
|
271
|
+
if (!this._addr) return null;
|
|
272
|
+
return { ...this._addr, host: this._addr.address };
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
TcpServer.prototype.close = function close(cb?: (err?: Error) => void): any {
|
|
276
|
+
this._bound = false;
|
|
277
|
+
this.listening = false;
|
|
278
|
+
for (const s of this._peers) s.destroy();
|
|
279
|
+
this._peers.clear();
|
|
280
|
+
const self = this;
|
|
281
|
+
queueMicrotask(() => {
|
|
282
|
+
self.emit("close");
|
|
283
|
+
if (cb) cb();
|
|
284
|
+
});
|
|
285
|
+
return this;
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
TcpServer.prototype.getConnections = function getConnections(
|
|
289
|
+
cb?: (err: Error | null, n: number) => void,
|
|
290
|
+
): void {
|
|
291
|
+
if (typeof cb === "function") cb(null, this._peers.size);
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
TcpServer.prototype.ref = function ref(): any {
|
|
295
|
+
return this;
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
TcpServer.prototype.unref = function unref(): any {
|
|
299
|
+
return this;
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
TcpServer.prototype._acceptConnection = function _acceptConnection(sock: TcpSocket): void {
|
|
303
|
+
if (!this._bound) {
|
|
304
|
+
sock.destroy();
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
this._peers.add(sock);
|
|
308
|
+
const self = this;
|
|
309
|
+
sock.on("close", function onClose() { self._peers.delete(sock); });
|
|
310
|
+
this.emit("connection", sock);
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
export function createServer(
|
|
315
|
+
cfgOrHandler?: ServerConfig | ((sock: TcpSocket) => void),
|
|
316
|
+
handler?: (sock: TcpSocket) => void,
|
|
317
|
+
): TcpServer {
|
|
318
|
+
return new TcpServer(cfgOrHandler, handler);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
export function createConnection(
|
|
322
|
+
portOrOpts: number | { port: number; host?: string },
|
|
323
|
+
hostOrCb?: string | (() => void),
|
|
324
|
+
cb?: () => void,
|
|
325
|
+
): TcpSocket {
|
|
326
|
+
return new TcpSocket().connect(portOrOpts, hostOrCb as string, cb);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
export const connect = createConnection;
|
|
330
|
+
|
|
331
|
+
export function isIP(addr: string): number {
|
|
332
|
+
if (/^(\d{1,3}\.){3}\d{1,3}$/.test(addr)) return 4;
|
|
333
|
+
if (/^([0-9a-fA-F]{0,4}:){2,7}[0-9a-fA-F]{0,4}$/.test(addr)) return 6;
|
|
334
|
+
return 0;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
export function isIPv4(addr: string): boolean {
|
|
338
|
+
return isIP(addr) === 4;
|
|
339
|
+
}
|
|
340
|
+
export function isIPv6(addr: string): boolean {
|
|
341
|
+
return isIP(addr) === 6;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
export default {
|
|
345
|
+
Socket: TcpSocket,
|
|
346
|
+
Server: TcpServer,
|
|
347
|
+
createServer,
|
|
348
|
+
createConnection,
|
|
349
|
+
connect,
|
|
350
|
+
isIP,
|
|
351
|
+
isIPv4,
|
|
352
|
+
isIPv6,
|
|
353
|
+
};
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
// OS polyfill returning plausible Linux-like values
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
import { MOCK_OS, MOCK_IDS, MOCK_CPU, MOCK_MEMORY, MOCK_LOADAVG } from "../constants/config";
|
|
5
|
+
|
|
6
|
+
export function hostname(): string {
|
|
7
|
+
return MOCK_OS.HOSTNAME;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function platform(): string {
|
|
11
|
+
return MOCK_OS.PLATFORM;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function arch(): string {
|
|
15
|
+
return MOCK_OS.ARCH;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function type(): string {
|
|
19
|
+
return MOCK_OS.TYPE;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function release(): string {
|
|
23
|
+
return MOCK_OS.RELEASE;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function version(): string {
|
|
27
|
+
return MOCK_OS.VERSION;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function machine(): string {
|
|
31
|
+
return MOCK_OS.MACHINE;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function tmpdir(): string {
|
|
35
|
+
return MOCK_OS.TMPDIR;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function homedir(): string {
|
|
39
|
+
return MOCK_OS.HOMEDIR;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
interface CpuEntry {
|
|
43
|
+
model: string;
|
|
44
|
+
speed: number;
|
|
45
|
+
times: { user: number; nice: number; sys: number; idle: number; irq: number };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function cpus(): CpuEntry[] {
|
|
49
|
+
const template: CpuEntry = {
|
|
50
|
+
model: MOCK_CPU.MODEL,
|
|
51
|
+
speed: MOCK_CPU.SPEED,
|
|
52
|
+
times: { user: 0, nice: 0, sys: 0, idle: 0, irq: 0 },
|
|
53
|
+
};
|
|
54
|
+
return Array.from({ length: MOCK_CPU.COUNT }, () => ({ ...template }));
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function totalmem(): number {
|
|
58
|
+
return MOCK_MEMORY.TOTAL;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function freemem(): number {
|
|
62
|
+
return MOCK_MEMORY.FREE;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function uptime(): number {
|
|
66
|
+
return Math.floor(performance.now() / 1000);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function loadavg(): [number, number, number] {
|
|
70
|
+
return [...MOCK_LOADAVG];
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
interface NetIface {
|
|
74
|
+
address: string;
|
|
75
|
+
netmask: string;
|
|
76
|
+
family: string;
|
|
77
|
+
mac: string;
|
|
78
|
+
internal: boolean;
|
|
79
|
+
cidr: string;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function networkInterfaces(): Record<string, NetIface[]> {
|
|
83
|
+
return {
|
|
84
|
+
lo: [
|
|
85
|
+
{
|
|
86
|
+
address: '127.0.0.1',
|
|
87
|
+
netmask: '255.0.0.0',
|
|
88
|
+
family: 'IPv4',
|
|
89
|
+
mac: '00:00:00:00:00:00',
|
|
90
|
+
internal: true,
|
|
91
|
+
cidr: '127.0.0.1/8',
|
|
92
|
+
},
|
|
93
|
+
],
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function userInfo(): {
|
|
98
|
+
username: string;
|
|
99
|
+
uid: number;
|
|
100
|
+
gid: number;
|
|
101
|
+
shell: string;
|
|
102
|
+
homedir: string;
|
|
103
|
+
} {
|
|
104
|
+
return {
|
|
105
|
+
username: MOCK_OS.USERNAME,
|
|
106
|
+
uid: MOCK_IDS.UID,
|
|
107
|
+
gid: MOCK_IDS.GID,
|
|
108
|
+
shell: MOCK_OS.SHELL,
|
|
109
|
+
homedir: MOCK_OS.HOMEDIR,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export function endianness(): 'BE' | 'LE' {
|
|
114
|
+
return MOCK_OS.ENDIANNESS;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export function getPriority(_pid?: number): number {
|
|
118
|
+
return 0;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export function setPriority(_pidOrPriority: number, _priority?: number): void {
|
|
122
|
+
// no-op in browser
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export const EOL = '\n';
|
|
126
|
+
|
|
127
|
+
export const devNull = '/dev/null';
|
|
128
|
+
|
|
129
|
+
export const constants = {
|
|
130
|
+
signals: {
|
|
131
|
+
SIGHUP: 1,
|
|
132
|
+
SIGINT: 2,
|
|
133
|
+
SIGQUIT: 3,
|
|
134
|
+
SIGILL: 4,
|
|
135
|
+
SIGTRAP: 5,
|
|
136
|
+
SIGABRT: 6,
|
|
137
|
+
SIGBUS: 7,
|
|
138
|
+
SIGFPE: 8,
|
|
139
|
+
SIGKILL: 9,
|
|
140
|
+
SIGUSR1: 10,
|
|
141
|
+
SIGSEGV: 11,
|
|
142
|
+
SIGUSR2: 12,
|
|
143
|
+
SIGPIPE: 13,
|
|
144
|
+
SIGALRM: 14,
|
|
145
|
+
SIGTERM: 15,
|
|
146
|
+
SIGCHLD: 17,
|
|
147
|
+
SIGCONT: 18,
|
|
148
|
+
SIGSTOP: 19,
|
|
149
|
+
SIGTSTP: 20,
|
|
150
|
+
SIGTTIN: 21,
|
|
151
|
+
SIGTTOU: 22,
|
|
152
|
+
SIGURG: 23,
|
|
153
|
+
SIGXCPU: 24,
|
|
154
|
+
SIGXFSZ: 25,
|
|
155
|
+
SIGVTALRM: 26,
|
|
156
|
+
SIGPROF: 27,
|
|
157
|
+
SIGWINCH: 28,
|
|
158
|
+
SIGIO: 29,
|
|
159
|
+
SIGPWR: 30,
|
|
160
|
+
SIGSYS: 31,
|
|
161
|
+
},
|
|
162
|
+
errno: {
|
|
163
|
+
EPERM: -1,
|
|
164
|
+
ENOENT: -2,
|
|
165
|
+
ESRCH: -3,
|
|
166
|
+
EINTR: -4,
|
|
167
|
+
EIO: -5,
|
|
168
|
+
ENXIO: -6,
|
|
169
|
+
E2BIG: -7,
|
|
170
|
+
ENOEXEC: -8,
|
|
171
|
+
EBADF: -9,
|
|
172
|
+
ECHILD: -10,
|
|
173
|
+
EAGAIN: -11,
|
|
174
|
+
ENOMEM: -12,
|
|
175
|
+
EACCES: -13,
|
|
176
|
+
EFAULT: -14,
|
|
177
|
+
EBUSY: -16,
|
|
178
|
+
EEXIST: -17,
|
|
179
|
+
EXDEV: -18,
|
|
180
|
+
ENODEV: -19,
|
|
181
|
+
ENOTDIR: -20,
|
|
182
|
+
EISDIR: -21,
|
|
183
|
+
EINVAL: -22,
|
|
184
|
+
ENFILE: -23,
|
|
185
|
+
EMFILE: -24,
|
|
186
|
+
ENOTTY: -25,
|
|
187
|
+
EFBIG: -27,
|
|
188
|
+
ENOSPC: -28,
|
|
189
|
+
ESPIPE: -29,
|
|
190
|
+
EROFS: -30,
|
|
191
|
+
EMLINK: -31,
|
|
192
|
+
EPIPE: -32,
|
|
193
|
+
EDOM: -33,
|
|
194
|
+
ERANGE: -34,
|
|
195
|
+
ENOTEMPTY: -39,
|
|
196
|
+
ENOSYS: -38,
|
|
197
|
+
ELOOP: -40,
|
|
198
|
+
ENAMETOOLONG: -36,
|
|
199
|
+
ECONNRESET: -104,
|
|
200
|
+
ECONNREFUSED: -111,
|
|
201
|
+
EADDRINUSE: -98,
|
|
202
|
+
EADDRNOTAVAIL: -99,
|
|
203
|
+
ETIMEDOUT: -110,
|
|
204
|
+
},
|
|
205
|
+
priority: {
|
|
206
|
+
PRIORITY_LOW: 19,
|
|
207
|
+
PRIORITY_BELOW_NORMAL: 10,
|
|
208
|
+
PRIORITY_NORMAL: 0,
|
|
209
|
+
PRIORITY_ABOVE_NORMAL: -7,
|
|
210
|
+
PRIORITY_HIGH: -14,
|
|
211
|
+
PRIORITY_HIGHEST: -20,
|
|
212
|
+
},
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
export default {
|
|
216
|
+
hostname,
|
|
217
|
+
platform,
|
|
218
|
+
arch,
|
|
219
|
+
type,
|
|
220
|
+
release,
|
|
221
|
+
version,
|
|
222
|
+
machine,
|
|
223
|
+
tmpdir,
|
|
224
|
+
homedir,
|
|
225
|
+
cpus,
|
|
226
|
+
totalmem,
|
|
227
|
+
freemem,
|
|
228
|
+
uptime,
|
|
229
|
+
loadavg,
|
|
230
|
+
networkInterfaces,
|
|
231
|
+
userInfo,
|
|
232
|
+
endianness,
|
|
233
|
+
getPriority,
|
|
234
|
+
setPriority,
|
|
235
|
+
EOL,
|
|
236
|
+
devNull,
|
|
237
|
+
constants,
|
|
238
|
+
};
|