@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,559 @@
|
|
|
1
|
+
// Utility helpers: format, inspect, inherits, promisify, deprecate, type checks, etc.
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
export function format(template: unknown, ...values: unknown[]): string {
|
|
5
|
+
if (typeof template !== "string") {
|
|
6
|
+
// non-string first arg: inspect all args
|
|
7
|
+
return [template, ...values].map((v) => typeof v === "string" ? v : inspect(v)).join(" ");
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
let idx = 0;
|
|
11
|
+
let result = template.replace(/%[sdjifoO%]/g, (token) => {
|
|
12
|
+
if (token === "%%") return "%";
|
|
13
|
+
if (idx >= values.length) return token;
|
|
14
|
+
|
|
15
|
+
const val = values[idx++];
|
|
16
|
+
switch (token) {
|
|
17
|
+
case "%s":
|
|
18
|
+
return String(val);
|
|
19
|
+
case "%d":
|
|
20
|
+
case "%i":
|
|
21
|
+
return String(parseInt(String(val), 10));
|
|
22
|
+
case "%f":
|
|
23
|
+
return String(parseFloat(String(val)));
|
|
24
|
+
case "%j":
|
|
25
|
+
try {
|
|
26
|
+
return JSON.stringify(val);
|
|
27
|
+
} catch {
|
|
28
|
+
return "[Circular]";
|
|
29
|
+
}
|
|
30
|
+
case "%o":
|
|
31
|
+
case "%O":
|
|
32
|
+
return inspect(val);
|
|
33
|
+
default:
|
|
34
|
+
return token;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
// append extra args beyond what format specifiers consumed (matches Node.js)
|
|
39
|
+
while (idx < values.length) {
|
|
40
|
+
const v = values[idx++];
|
|
41
|
+
result += " " + (typeof v === "string" ? v : inspect(v));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return result;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function inspect(
|
|
48
|
+
target: unknown,
|
|
49
|
+
opts?: { depth?: number; colors?: boolean },
|
|
50
|
+
): string {
|
|
51
|
+
const visited = new WeakSet();
|
|
52
|
+
const maxDepth = opts?.depth ?? 2;
|
|
53
|
+
|
|
54
|
+
function render(val: unknown, level: number): string {
|
|
55
|
+
if (val === null) return "null";
|
|
56
|
+
if (val === undefined) return "undefined";
|
|
57
|
+
|
|
58
|
+
const kind = typeof val;
|
|
59
|
+
if (kind === "string") return `'${val}'`;
|
|
60
|
+
if (kind === "number" || kind === "boolean" || kind === "bigint")
|
|
61
|
+
return String(val);
|
|
62
|
+
if (kind === "symbol") return (val as symbol).toString();
|
|
63
|
+
if (kind === "function") {
|
|
64
|
+
const fname = (val as Function).name || "anonymous";
|
|
65
|
+
return `[Function: ${fname}]`;
|
|
66
|
+
}
|
|
67
|
+
if (kind !== "object") return String(val);
|
|
68
|
+
|
|
69
|
+
if (visited.has(val as object)) return "[Circular]";
|
|
70
|
+
visited.add(val as object);
|
|
71
|
+
|
|
72
|
+
if (level > maxDepth) {
|
|
73
|
+
return Array.isArray(val) ? "[Array]" : "[Object]";
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (Array.isArray(val)) {
|
|
77
|
+
if (val.length === 0) return "[]";
|
|
78
|
+
const items = val.map((item) => render(item, level + 1));
|
|
79
|
+
return `[ ${items.join(", ")} ]`;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (val instanceof Date) return val.toISOString();
|
|
83
|
+
if (val instanceof RegExp) return val.toString();
|
|
84
|
+
if (val instanceof Error) return `${val.name}: ${val.message}`;
|
|
85
|
+
|
|
86
|
+
if (val instanceof Map) {
|
|
87
|
+
const pairs = [...val.entries()].map(
|
|
88
|
+
([k, v]) => `${render(k, level + 1)} => ${render(v, level + 1)}`,
|
|
89
|
+
);
|
|
90
|
+
return `Map(${val.size}) { ${pairs.join(", ")} }`;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (val instanceof Set) {
|
|
94
|
+
const items = [...val].map((v) => render(v, level + 1));
|
|
95
|
+
return `Set(${val.size}) { ${items.join(", ")} }`;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const keys = Object.keys(val as object);
|
|
99
|
+
if (keys.length === 0) return "{}";
|
|
100
|
+
const fields = keys.map((k) => {
|
|
101
|
+
const v = (val as Record<string, unknown>)[k];
|
|
102
|
+
return `${k}: ${render(v, level + 1)}`;
|
|
103
|
+
});
|
|
104
|
+
return `{ ${fields.join(", ")} }`;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return render(target, 0);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export function inherits(child: Function, parent: Function): void {
|
|
111
|
+
if (child === undefined || child === null) {
|
|
112
|
+
throw new TypeError("inherits: child constructor must be provided");
|
|
113
|
+
}
|
|
114
|
+
if (parent === undefined || parent === null) return;
|
|
115
|
+
if (parent.prototype === undefined) return;
|
|
116
|
+
(child as any).super_ = parent;
|
|
117
|
+
Object.setPrototypeOf(child.prototype, parent.prototype);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// deprecated, equivalent to Object.assign
|
|
121
|
+
export function _extend(target: any, source: any): any {
|
|
122
|
+
if (source == null) return target;
|
|
123
|
+
const keys = Object.keys(source);
|
|
124
|
+
for (let i = 0; i < keys.length; i++) {
|
|
125
|
+
target[keys[i]] = source[keys[i]];
|
|
126
|
+
}
|
|
127
|
+
return target;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export function deprecate<T extends Function>(
|
|
131
|
+
fn: T,
|
|
132
|
+
message: string,
|
|
133
|
+
code?: string,
|
|
134
|
+
): T {
|
|
135
|
+
let alerted = false;
|
|
136
|
+
const wrapper = function (this: unknown, ...args: unknown[]) {
|
|
137
|
+
if (!alerted) {
|
|
138
|
+
console.warn(`DeprecationWarning: ${message}${code ? ` (${code})` : ""}`);
|
|
139
|
+
alerted = true;
|
|
140
|
+
}
|
|
141
|
+
return fn.apply(this, args);
|
|
142
|
+
};
|
|
143
|
+
return wrapper as unknown as T;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export function promisify<T>(
|
|
147
|
+
fn: (...args: any[]) => void,
|
|
148
|
+
): (...args: any[]) => Promise<T> {
|
|
149
|
+
return (...args: any[]) =>
|
|
150
|
+
new Promise((ok, fail) => {
|
|
151
|
+
fn(...args, (err: Error | null, result: T) => {
|
|
152
|
+
if (err) fail(err);
|
|
153
|
+
else ok(result);
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export function callbackify<T>(
|
|
159
|
+
fn: (...args: any[]) => Promise<T>,
|
|
160
|
+
): (...args: any[]) => void {
|
|
161
|
+
return (...args: any[]) => {
|
|
162
|
+
const cb = args.pop() as (err: Error | null, result: T) => void;
|
|
163
|
+
fn(...args)
|
|
164
|
+
.then((result) => cb(null, result))
|
|
165
|
+
.catch((err) => cb(err, undefined as unknown as T));
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export function isDeepStrictEqual(a: unknown, b: unknown): boolean {
|
|
170
|
+
if (a === b) return true;
|
|
171
|
+
if (a === null || b === null) return false;
|
|
172
|
+
if (typeof a !== typeof b) return false;
|
|
173
|
+
|
|
174
|
+
if (typeof a === "object") {
|
|
175
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
176
|
+
if (a.length !== b.length) return false;
|
|
177
|
+
return a.every((item, i) => isDeepStrictEqual(item, b[i]));
|
|
178
|
+
}
|
|
179
|
+
if (Array.isArray(a) !== Array.isArray(b)) return false;
|
|
180
|
+
|
|
181
|
+
const keysA = Object.keys(a as object);
|
|
182
|
+
const keysB = Object.keys(b as object);
|
|
183
|
+
if (keysA.length !== keysB.length) return false;
|
|
184
|
+
|
|
185
|
+
return keysA.every((k) =>
|
|
186
|
+
isDeepStrictEqual(
|
|
187
|
+
(a as Record<string, unknown>)[k],
|
|
188
|
+
(b as Record<string, unknown>)[k],
|
|
189
|
+
),
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
return false;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export function isArray(val: unknown): val is unknown[] {
|
|
197
|
+
return Array.isArray(val);
|
|
198
|
+
}
|
|
199
|
+
export function isBoolean(val: unknown): val is boolean {
|
|
200
|
+
return typeof val === "boolean";
|
|
201
|
+
}
|
|
202
|
+
export function isNull(val: unknown): val is null {
|
|
203
|
+
return val === null;
|
|
204
|
+
}
|
|
205
|
+
export function isNullOrUndefined(val: unknown): val is null | undefined {
|
|
206
|
+
return val == null;
|
|
207
|
+
}
|
|
208
|
+
export function isNumber(val: unknown): val is number {
|
|
209
|
+
return typeof val === "number";
|
|
210
|
+
}
|
|
211
|
+
export function isString(val: unknown): val is string {
|
|
212
|
+
return typeof val === "string";
|
|
213
|
+
}
|
|
214
|
+
export function isUndefined(val: unknown): val is undefined {
|
|
215
|
+
return val === undefined;
|
|
216
|
+
}
|
|
217
|
+
export function isRegExp(val: unknown): val is RegExp {
|
|
218
|
+
return val instanceof RegExp;
|
|
219
|
+
}
|
|
220
|
+
export function isObject(val: unknown): val is object {
|
|
221
|
+
return typeof val === "object" && val !== null;
|
|
222
|
+
}
|
|
223
|
+
export function isDate(val: unknown): val is Date {
|
|
224
|
+
return val instanceof Date;
|
|
225
|
+
}
|
|
226
|
+
export function isError(val: unknown): val is Error {
|
|
227
|
+
return val instanceof Error;
|
|
228
|
+
}
|
|
229
|
+
export function isFunction(val: unknown): val is Function {
|
|
230
|
+
return typeof val === "function";
|
|
231
|
+
}
|
|
232
|
+
export function isPrimitive(val: unknown): boolean {
|
|
233
|
+
return val === null || (typeof val !== "object" && typeof val !== "function");
|
|
234
|
+
}
|
|
235
|
+
export function isBuffer(val: unknown): boolean {
|
|
236
|
+
return val instanceof Uint8Array;
|
|
237
|
+
}
|
|
238
|
+
export function isPromise(val: unknown): val is Promise<unknown> {
|
|
239
|
+
return val instanceof Promise;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// returns a logger when NODE_DEBUG includes the given section
|
|
243
|
+
export function debuglog(section: string): (...args: unknown[]) => void {
|
|
244
|
+
const envDebug =
|
|
245
|
+
(typeof process !== "undefined" && process.env?.NODE_DEBUG) || "";
|
|
246
|
+
const active = envDebug.toLowerCase().includes(section.toLowerCase());
|
|
247
|
+
|
|
248
|
+
if (active) {
|
|
249
|
+
return (...args: unknown[]) => {
|
|
250
|
+
console.error(`${section.toUpperCase()} ${process?.pid || 0}:`, ...args);
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
return () => {};
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
export const debug = debuglog;
|
|
257
|
+
|
|
258
|
+
export function stripVTControlCharacters(text: string): string {
|
|
259
|
+
// eslint-disable-next-line no-control-regex
|
|
260
|
+
return text.replace(
|
|
261
|
+
/\x1B\[[0-9;]*[a-zA-Z]|\x1B\].*?(\x07|\x1B\\)|\x1B[()][A-Z0-9]|\x1B[#=]|\x1B./g,
|
|
262
|
+
"",
|
|
263
|
+
);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
export const types = {
|
|
267
|
+
isArray,
|
|
268
|
+
isBoolean,
|
|
269
|
+
isNull,
|
|
270
|
+
isNullOrUndefined,
|
|
271
|
+
isNumber,
|
|
272
|
+
isString,
|
|
273
|
+
isUndefined,
|
|
274
|
+
isRegExp,
|
|
275
|
+
isObject,
|
|
276
|
+
isDate,
|
|
277
|
+
isError,
|
|
278
|
+
isFunction,
|
|
279
|
+
isPrimitive,
|
|
280
|
+
isBuffer,
|
|
281
|
+
isPromise,
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
// styleText (Node.js 21.7+)
|
|
285
|
+
|
|
286
|
+
const ANSI_STYLES: Record<string, [number, number]> = {
|
|
287
|
+
// Modifiers
|
|
288
|
+
reset: [0, 0],
|
|
289
|
+
bold: [1, 22],
|
|
290
|
+
dim: [2, 22],
|
|
291
|
+
italic: [3, 23],
|
|
292
|
+
underline: [4, 24],
|
|
293
|
+
inverse: [7, 27],
|
|
294
|
+
hidden: [8, 28],
|
|
295
|
+
strikethrough: [9, 29],
|
|
296
|
+
// Foreground colors
|
|
297
|
+
black: [30, 39],
|
|
298
|
+
red: [31, 39],
|
|
299
|
+
green: [32, 39],
|
|
300
|
+
yellow: [33, 39],
|
|
301
|
+
blue: [34, 39],
|
|
302
|
+
magenta: [35, 39],
|
|
303
|
+
cyan: [36, 39],
|
|
304
|
+
white: [37, 39],
|
|
305
|
+
gray: [90, 39],
|
|
306
|
+
grey: [90, 39],
|
|
307
|
+
blackBright: [90, 39],
|
|
308
|
+
redBright: [91, 39],
|
|
309
|
+
greenBright: [92, 39],
|
|
310
|
+
yellowBright: [93, 39],
|
|
311
|
+
blueBright: [94, 39],
|
|
312
|
+
magentaBright: [95, 39],
|
|
313
|
+
cyanBright: [96, 39],
|
|
314
|
+
whiteBright: [97, 39],
|
|
315
|
+
// Background colors
|
|
316
|
+
bgBlack: [40, 49],
|
|
317
|
+
bgRed: [41, 49],
|
|
318
|
+
bgGreen: [42, 49],
|
|
319
|
+
bgYellow: [43, 49],
|
|
320
|
+
bgBlue: [44, 49],
|
|
321
|
+
bgMagenta: [45, 49],
|
|
322
|
+
bgCyan: [46, 49],
|
|
323
|
+
bgWhite: [47, 49],
|
|
324
|
+
bgBlackBright: [100, 49],
|
|
325
|
+
bgRedBright: [101, 49],
|
|
326
|
+
bgGreenBright: [102, 49],
|
|
327
|
+
bgYellowBright: [103, 49],
|
|
328
|
+
bgBlueBright: [104, 49],
|
|
329
|
+
bgMagentaBright: [105, 49],
|
|
330
|
+
bgCyanBright: [106, 49],
|
|
331
|
+
bgWhiteBright: [107, 49],
|
|
332
|
+
};
|
|
333
|
+
|
|
334
|
+
export function styleText(format: string | string[], text: string): string {
|
|
335
|
+
const formats = Array.isArray(format) ? format : [format];
|
|
336
|
+
let result = text;
|
|
337
|
+
for (const f of formats) {
|
|
338
|
+
const style = ANSI_STYLES[f];
|
|
339
|
+
if (style) {
|
|
340
|
+
result = `\x1b[${style[0]}m${result}\x1b[${style[1]}m`;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
return result;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
// parseArgs (Node.js 18.3+)
|
|
347
|
+
|
|
348
|
+
interface ParseArgsOptionConfig {
|
|
349
|
+
type: "string" | "boolean";
|
|
350
|
+
short?: string;
|
|
351
|
+
multiple?: boolean;
|
|
352
|
+
default?: string | boolean | string[] | boolean[];
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
interface ParseArgsConfig {
|
|
356
|
+
args?: string[];
|
|
357
|
+
options?: Record<string, ParseArgsOptionConfig>;
|
|
358
|
+
strict?: boolean;
|
|
359
|
+
allowPositionals?: boolean;
|
|
360
|
+
tokens?: boolean;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
interface ParseArgsResult {
|
|
364
|
+
values: Record<string, string | boolean | (string | boolean)[] | undefined>;
|
|
365
|
+
positionals: string[];
|
|
366
|
+
tokens?: Array<{
|
|
367
|
+
kind: string;
|
|
368
|
+
name?: string;
|
|
369
|
+
value?: string | boolean;
|
|
370
|
+
index: number;
|
|
371
|
+
}>;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
export function parseArgs(config?: ParseArgsConfig): ParseArgsResult {
|
|
375
|
+
const args =
|
|
376
|
+
config?.args ??
|
|
377
|
+
(typeof process !== "undefined" ? process.argv.slice(2) : []);
|
|
378
|
+
const optDefs = config?.options ?? {};
|
|
379
|
+
const allowPositionals = config?.allowPositionals ?? !config?.options;
|
|
380
|
+
const strict = config?.strict ?? true;
|
|
381
|
+
const wantTokens = config?.tokens ?? false;
|
|
382
|
+
|
|
383
|
+
// Build short → long name map
|
|
384
|
+
const shortMap: Record<string, string> = {};
|
|
385
|
+
for (const [name, def] of Object.entries(optDefs)) {
|
|
386
|
+
if (def.short) shortMap[def.short] = name;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
const values: Record<
|
|
390
|
+
string,
|
|
391
|
+
string | boolean | (string | boolean)[] | undefined
|
|
392
|
+
> = {};
|
|
393
|
+
const positionals: string[] = [];
|
|
394
|
+
const tokens: Array<{
|
|
395
|
+
kind: string;
|
|
396
|
+
name?: string;
|
|
397
|
+
value?: string | boolean;
|
|
398
|
+
index: number;
|
|
399
|
+
}> = [];
|
|
400
|
+
|
|
401
|
+
// Initialize defaults
|
|
402
|
+
for (const [name, def] of Object.entries(optDefs)) {
|
|
403
|
+
if (def.default !== undefined) {
|
|
404
|
+
values[name] = def.default;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
let i = 0;
|
|
409
|
+
let afterDash = false;
|
|
410
|
+
while (i < args.length) {
|
|
411
|
+
const arg = args[i];
|
|
412
|
+
|
|
413
|
+
if (afterDash || !arg.startsWith("-") || arg === "-") {
|
|
414
|
+
if (!allowPositionals && strict && !afterDash) {
|
|
415
|
+
throw new Error(`Unexpected argument '${arg}'`);
|
|
416
|
+
}
|
|
417
|
+
positionals.push(arg);
|
|
418
|
+
if (wantTokens) tokens.push({ kind: "positional", value: arg, index: i });
|
|
419
|
+
i++;
|
|
420
|
+
continue;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
if (arg === "--") {
|
|
424
|
+
afterDash = true;
|
|
425
|
+
if (wantTokens) tokens.push({ kind: "option-terminator", index: i });
|
|
426
|
+
i++;
|
|
427
|
+
continue;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
// --long or --long=value
|
|
431
|
+
if (arg.startsWith("--")) {
|
|
432
|
+
const eqIdx = arg.indexOf("=");
|
|
433
|
+
const rawName = eqIdx !== -1 ? arg.slice(2, eqIdx) : arg.slice(2);
|
|
434
|
+
const def = optDefs[rawName];
|
|
435
|
+
|
|
436
|
+
if (!def && strict) {
|
|
437
|
+
throw new Error(`Unknown option '--${rawName}'`);
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
const type = def?.type ?? "boolean";
|
|
441
|
+
let val: string | boolean;
|
|
442
|
+
|
|
443
|
+
if (type === "boolean") {
|
|
444
|
+
val = eqIdx !== -1 ? arg.slice(eqIdx + 1) !== "false" : true;
|
|
445
|
+
} else {
|
|
446
|
+
if (eqIdx !== -1) {
|
|
447
|
+
val = arg.slice(eqIdx + 1);
|
|
448
|
+
} else if (i + 1 < args.length) {
|
|
449
|
+
val = args[++i];
|
|
450
|
+
} else {
|
|
451
|
+
throw new Error(`Option '--${rawName}' requires a value`);
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
if (def?.multiple) {
|
|
456
|
+
const arr = (values[rawName] as (string | boolean)[] | undefined) ?? [];
|
|
457
|
+
arr.push(val);
|
|
458
|
+
values[rawName] = arr;
|
|
459
|
+
} else {
|
|
460
|
+
values[rawName] = val;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
if (wantTokens)
|
|
464
|
+
tokens.push({ kind: "option", name: rawName, value: val, index: i });
|
|
465
|
+
i++;
|
|
466
|
+
continue;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
// -s (short options)
|
|
470
|
+
if (arg.startsWith("-") && arg.length > 1) {
|
|
471
|
+
// Handle combined short flags: -abc → -a -b -c
|
|
472
|
+
const chars = arg.slice(1);
|
|
473
|
+
for (let c = 0; c < chars.length; c++) {
|
|
474
|
+
const ch = chars[c];
|
|
475
|
+
const longName = shortMap[ch];
|
|
476
|
+
|
|
477
|
+
if (!longName && strict) {
|
|
478
|
+
throw new Error(`Unknown option '-${ch}'`);
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
const name = longName ?? ch;
|
|
482
|
+
const def = longName ? optDefs[longName] : undefined;
|
|
483
|
+
const type = def?.type ?? "boolean";
|
|
484
|
+
|
|
485
|
+
let val: string | boolean;
|
|
486
|
+
if (type === "boolean") {
|
|
487
|
+
val = true;
|
|
488
|
+
} else {
|
|
489
|
+
// Rest of chars is the value, or next arg
|
|
490
|
+
const rest = chars.slice(c + 1);
|
|
491
|
+
if (rest.length > 0) {
|
|
492
|
+
val = rest;
|
|
493
|
+
c = chars.length; // break inner loop
|
|
494
|
+
} else if (i + 1 < args.length) {
|
|
495
|
+
val = args[++i];
|
|
496
|
+
} else {
|
|
497
|
+
throw new Error(`Option '-${ch}' requires a value`);
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
if (def?.multiple) {
|
|
502
|
+
const arr = (values[name] as (string | boolean)[] | undefined) ?? [];
|
|
503
|
+
arr.push(val);
|
|
504
|
+
values[name] = arr;
|
|
505
|
+
} else {
|
|
506
|
+
values[name] = val;
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
if (wantTokens)
|
|
510
|
+
tokens.push({ kind: "option", name, value: val, index: i });
|
|
511
|
+
}
|
|
512
|
+
i++;
|
|
513
|
+
continue;
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
i++;
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
const result: ParseArgsResult = { values, positionals };
|
|
520
|
+
if (wantTokens) result.tokens = tokens;
|
|
521
|
+
return result;
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
export const TextEncoder = globalThis.TextEncoder;
|
|
525
|
+
export const TextDecoder = globalThis.TextDecoder;
|
|
526
|
+
|
|
527
|
+
export default {
|
|
528
|
+
format,
|
|
529
|
+
inspect,
|
|
530
|
+
inherits,
|
|
531
|
+
_extend,
|
|
532
|
+
deprecate,
|
|
533
|
+
promisify,
|
|
534
|
+
callbackify,
|
|
535
|
+
isDeepStrictEqual,
|
|
536
|
+
debuglog,
|
|
537
|
+
debug,
|
|
538
|
+
stripVTControlCharacters,
|
|
539
|
+
isArray,
|
|
540
|
+
isBoolean,
|
|
541
|
+
isNull,
|
|
542
|
+
isNullOrUndefined,
|
|
543
|
+
isNumber,
|
|
544
|
+
isString,
|
|
545
|
+
isUndefined,
|
|
546
|
+
isRegExp,
|
|
547
|
+
isObject,
|
|
548
|
+
isDate,
|
|
549
|
+
isError,
|
|
550
|
+
isFunction,
|
|
551
|
+
isPrimitive,
|
|
552
|
+
isBuffer,
|
|
553
|
+
isPromise,
|
|
554
|
+
styleText,
|
|
555
|
+
parseArgs,
|
|
556
|
+
types,
|
|
557
|
+
TextEncoder,
|
|
558
|
+
TextDecoder,
|
|
559
|
+
};
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
// stub - not available in browser
|
|
2
|
+
|
|
3
|
+
export function getHeapStatistics() {
|
|
4
|
+
return {
|
|
5
|
+
total_heap_size: 0,
|
|
6
|
+
total_heap_size_executable: 0,
|
|
7
|
+
total_physical_size: 0,
|
|
8
|
+
total_available_size: 0,
|
|
9
|
+
used_heap_size: 0,
|
|
10
|
+
heap_size_limit: 0,
|
|
11
|
+
malloced_memory: 0,
|
|
12
|
+
peak_malloced_memory: 0,
|
|
13
|
+
does_zap_garbage: 0,
|
|
14
|
+
number_of_native_contexts: 0,
|
|
15
|
+
number_of_detached_contexts: 0,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function getHeapSpaceStatistics(): unknown[] {
|
|
20
|
+
return [];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function getHeapCodeStatistics() {
|
|
24
|
+
return {
|
|
25
|
+
code_and_metadata_size: 0,
|
|
26
|
+
bytecode_and_metadata_size: 0,
|
|
27
|
+
external_script_source_size: 0,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function getHeapSnapshot(): null { return null; }
|
|
32
|
+
export function writeHeapSnapshot(): string { return ''; }
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
export function setFlagsFromString(_flags: string): void {}
|
|
36
|
+
export function takeCoverage(): void {}
|
|
37
|
+
export function stopCoverage(): void {}
|
|
38
|
+
|
|
39
|
+
export function cachedDataVersionTag(): number {
|
|
40
|
+
return 0;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// serialize/deserialize use JSON as a fallback
|
|
44
|
+
|
|
45
|
+
export function serialize(value: unknown): Uint8Array {
|
|
46
|
+
return new TextEncoder().encode(JSON.stringify(value));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function deserialize(bytes: Uint8Array): unknown {
|
|
50
|
+
return JSON.parse(new TextDecoder().decode(bytes));
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface Serializer {
|
|
54
|
+
writeHeader(): void;
|
|
55
|
+
writeValue(_v: unknown): void;
|
|
56
|
+
releaseBuffer(): Uint8Array;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export const Serializer = function Serializer(this: any) {
|
|
60
|
+
if (!this) return;
|
|
61
|
+
} as unknown as { new(): Serializer; prototype: any };
|
|
62
|
+
|
|
63
|
+
Serializer.prototype.writeHeader = function writeHeader(): void {};
|
|
64
|
+
Serializer.prototype.writeValue = function writeValue(_v: unknown): void {};
|
|
65
|
+
Serializer.prototype.releaseBuffer = function releaseBuffer(): Uint8Array { return new Uint8Array(0); };
|
|
66
|
+
|
|
67
|
+
export interface Deserializer {
|
|
68
|
+
readHeader(): boolean;
|
|
69
|
+
readValue(): unknown;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export const Deserializer = function Deserializer(this: any, _buf: Uint8Array) {
|
|
73
|
+
if (!this) return;
|
|
74
|
+
} as unknown as { new(_buf: Uint8Array): Deserializer; prototype: any };
|
|
75
|
+
|
|
76
|
+
Deserializer.prototype.readHeader = function readHeader(): boolean { return true; };
|
|
77
|
+
Deserializer.prototype.readValue = function readValue(): unknown { return null; };
|
|
78
|
+
|
|
79
|
+
export interface DefaultSerializer extends Serializer {}
|
|
80
|
+
|
|
81
|
+
export const DefaultSerializer = function DefaultSerializer(this: any) {
|
|
82
|
+
if (!this) return;
|
|
83
|
+
(Serializer as any).call(this);
|
|
84
|
+
} as unknown as { new(): DefaultSerializer; prototype: any };
|
|
85
|
+
|
|
86
|
+
Object.setPrototypeOf(DefaultSerializer.prototype, Serializer.prototype);
|
|
87
|
+
|
|
88
|
+
export interface DefaultDeserializer extends Deserializer {}
|
|
89
|
+
|
|
90
|
+
export const DefaultDeserializer = function DefaultDeserializer(this: any, _buf: Uint8Array) {
|
|
91
|
+
if (!this) return;
|
|
92
|
+
(Deserializer as any).call(this, _buf);
|
|
93
|
+
} as unknown as { new(_buf: Uint8Array): DefaultDeserializer; prototype: any };
|
|
94
|
+
|
|
95
|
+
Object.setPrototypeOf(DefaultDeserializer.prototype, Deserializer.prototype);
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
export function promiseHooks() {
|
|
99
|
+
return {
|
|
100
|
+
onInit: () => {},
|
|
101
|
+
onSettled: () => {},
|
|
102
|
+
onBefore: () => {},
|
|
103
|
+
onAfter: () => {},
|
|
104
|
+
createHook: () => ({ enable: () => {}, disable: () => {} }),
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
export default {
|
|
110
|
+
getHeapStatistics,
|
|
111
|
+
getHeapSpaceStatistics,
|
|
112
|
+
getHeapCodeStatistics,
|
|
113
|
+
getHeapSnapshot,
|
|
114
|
+
writeHeapSnapshot,
|
|
115
|
+
setFlagsFromString,
|
|
116
|
+
takeCoverage,
|
|
117
|
+
stopCoverage,
|
|
118
|
+
cachedDataVersionTag,
|
|
119
|
+
serialize,
|
|
120
|
+
deserialize,
|
|
121
|
+
Serializer,
|
|
122
|
+
Deserializer,
|
|
123
|
+
DefaultSerializer,
|
|
124
|
+
DefaultDeserializer,
|
|
125
|
+
promiseHooks,
|
|
126
|
+
};
|