@ai-ecoverse/slicc-jsh 0.2.0 → 0.2.1
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/README.md +8 -3
- package/dist/host/jsh.mjs +9 -884
- package/dist/host/main.mjs +893 -0
- package/dist/jsh.mjs +252 -194
- package/dist/meta-main.json +1 -1
- package/dist/node.mjs +1014 -109
- package/package.json +17 -5
package/dist/jsh.mjs
CHANGED
|
@@ -1536,10 +1536,56 @@ ${e3}`;
|
|
|
1536
1536
|
}
|
|
1537
1537
|
});
|
|
1538
1538
|
|
|
1539
|
+
// src/runtime/exit.mjs
|
|
1540
|
+
var NodeExitError = class extends Error {
|
|
1541
|
+
constructor(code) {
|
|
1542
|
+
super(`Process exited with code ${code}`);
|
|
1543
|
+
this.name = "NodeExitError";
|
|
1544
|
+
this.code = code;
|
|
1545
|
+
}
|
|
1546
|
+
};
|
|
1547
|
+
function numericExitCode(value) {
|
|
1548
|
+
const n = Number(value);
|
|
1549
|
+
return Number.isFinite(n) ? n & 255 : 0;
|
|
1550
|
+
}
|
|
1551
|
+
function describeReceived(value) {
|
|
1552
|
+
if (typeof value === "string") return `type string ('${value}')`;
|
|
1553
|
+
if (typeof value === "boolean") return `type boolean (${value})`;
|
|
1554
|
+
if (typeof value === "bigint") return `type bigint (${value}n)`;
|
|
1555
|
+
if (Array.isArray(value)) return "an instance of Array";
|
|
1556
|
+
if (typeof value === "object" && value !== null) return "an instance of Object";
|
|
1557
|
+
return `type ${typeof value}`;
|
|
1558
|
+
}
|
|
1559
|
+
function assignProcessExitCode(value) {
|
|
1560
|
+
if (value === null || value === void 0) return void 0;
|
|
1561
|
+
if (typeof value === "string") {
|
|
1562
|
+
const n = Number(value);
|
|
1563
|
+
if (value !== "" && Number.isInteger(n)) return n === 0 ? 0 : n;
|
|
1564
|
+
const err2 = new TypeError(
|
|
1565
|
+
`The "code" argument must be of type number. Received ${describeReceived(value)}`
|
|
1566
|
+
);
|
|
1567
|
+
err2.code = "ERR_INVALID_ARG_TYPE";
|
|
1568
|
+
throw err2;
|
|
1569
|
+
}
|
|
1570
|
+
if (typeof value === "number") {
|
|
1571
|
+
if (Number.isInteger(value)) return value === 0 ? 0 : value;
|
|
1572
|
+
const err2 = new RangeError(
|
|
1573
|
+
`The value of "code" is out of range. It must be an integer. Received ${String(value)}`
|
|
1574
|
+
);
|
|
1575
|
+
err2.code = "ERR_OUT_OF_RANGE";
|
|
1576
|
+
throw err2;
|
|
1577
|
+
}
|
|
1578
|
+
const err = new TypeError(
|
|
1579
|
+
`The "code" argument must be of type number. Received ${describeReceived(value)}`
|
|
1580
|
+
);
|
|
1581
|
+
err.code = "ERR_INVALID_ARG_TYPE";
|
|
1582
|
+
throw err;
|
|
1583
|
+
}
|
|
1584
|
+
|
|
1539
1585
|
// package.json
|
|
1540
1586
|
var package_default = {
|
|
1541
1587
|
name: "@ai-ecoverse/slicc-jsh",
|
|
1542
|
-
version: "0.2.
|
|
1588
|
+
version: "0.2.1",
|
|
1543
1589
|
description: "Node.js-compatible runtime for slicc-kernel: the node and jsh commands (abi: js)",
|
|
1544
1590
|
type: "module",
|
|
1545
1591
|
license: "Apache-2.0",
|
|
@@ -1560,8 +1606,13 @@ var package_default = {
|
|
|
1560
1606
|
},
|
|
1561
1607
|
publishConfig: {
|
|
1562
1608
|
access: "public",
|
|
1563
|
-
provenance: true
|
|
1564
|
-
|
|
1609
|
+
provenance: true
|
|
1610
|
+
},
|
|
1611
|
+
fledgling: {
|
|
1612
|
+
provider: "github",
|
|
1613
|
+
workflow: "release.yml",
|
|
1614
|
+
repo: "ai-ecoverse/slicc-jsh",
|
|
1615
|
+
publish: true
|
|
1565
1616
|
},
|
|
1566
1617
|
files: [
|
|
1567
1618
|
"LICENSE",
|
|
@@ -1598,16 +1649,21 @@ var package_default = {
|
|
|
1598
1649
|
"test:node-parallel": "node --max-old-space-size=512 test/node-parallel/run.mjs",
|
|
1599
1650
|
"golden:record": "node --max-old-space-size=512 scripts/golden.mjs record",
|
|
1600
1651
|
"test:jsh": "node --max-old-space-size=512 scripts/jsh-golden.mjs check",
|
|
1601
|
-
"jsh:record": "node --max-old-space-size=512 scripts/jsh-golden.mjs record"
|
|
1652
|
+
"jsh:record": "node --max-old-space-size=512 scripts/jsh-golden.mjs record",
|
|
1653
|
+
release: "semantic-release",
|
|
1654
|
+
trust: "npx fledgling sync -y --skip-publish",
|
|
1655
|
+
"trust:dry": "npx fledgling sync --dry-run -y --skip-publish"
|
|
1602
1656
|
},
|
|
1603
1657
|
devDependencies: {
|
|
1604
|
-
"@ai-ecoverse/slicc-kernel": "1.
|
|
1658
|
+
"@ai-ecoverse/slicc-kernel": "1.59.0",
|
|
1659
|
+
"@ai-ecoverse/wasi-pnpm": "12.9.1-8",
|
|
1605
1660
|
"abort-controller": "3.0.0",
|
|
1606
1661
|
acorn: "8.19.0",
|
|
1607
1662
|
esbuild: "0.28.2",
|
|
1608
1663
|
"node-inspect-extracted": "3.3.4",
|
|
1609
1664
|
process: "0.11.10",
|
|
1610
1665
|
"readable-stream": "4.8.0",
|
|
1666
|
+
"semantic-release": "25.0.9",
|
|
1611
1667
|
string_decoder: "1.3.0",
|
|
1612
1668
|
ws: "8.22.0"
|
|
1613
1669
|
}
|
|
@@ -2275,50 +2331,155 @@ async function runJsh({ filename, engine, process: process2, console: console2 }
|
|
|
2275
2331
|
return void 0;
|
|
2276
2332
|
}
|
|
2277
2333
|
|
|
2278
|
-
// src/
|
|
2279
|
-
var
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2334
|
+
// src/jsh/kernel.mjs
|
|
2335
|
+
var JSH_HANDOFF = /* @__PURE__ */ Symbol.for("slicc-jsh.kernel");
|
|
2336
|
+
var decoder = new TextDecoder();
|
|
2337
|
+
var encoder = new TextEncoder();
|
|
2338
|
+
var AsyncFunction = Object.getPrototypeOf(async () => {
|
|
2339
|
+
}).constructor;
|
|
2340
|
+
async function readAll(stream) {
|
|
2341
|
+
if (!stream) return new Uint8Array(0);
|
|
2342
|
+
const chunks = [];
|
|
2343
|
+
let size = 0;
|
|
2344
|
+
const reader = stream.getReader();
|
|
2345
|
+
for (; ; ) {
|
|
2346
|
+
const { done, value } = await reader.read();
|
|
2347
|
+
if (done) break;
|
|
2348
|
+
const bytes = typeof value === "string" ? encoder.encode(value) : value;
|
|
2349
|
+
chunks.push(bytes);
|
|
2350
|
+
size += bytes.length;
|
|
2284
2351
|
}
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
const
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
if (typeof value === "boolean") return `type boolean (${value})`;
|
|
2293
|
-
if (typeof value === "bigint") return `type bigint (${value}n)`;
|
|
2294
|
-
if (Array.isArray(value)) return "an instance of Array";
|
|
2295
|
-
if (typeof value === "object" && value !== null) return "an instance of Object";
|
|
2296
|
-
return `type ${typeof value}`;
|
|
2352
|
+
const out = new Uint8Array(size);
|
|
2353
|
+
let off = 0;
|
|
2354
|
+
for (const c of chunks) {
|
|
2355
|
+
out.set(c, off);
|
|
2356
|
+
off += c.length;
|
|
2357
|
+
}
|
|
2358
|
+
return out;
|
|
2297
2359
|
}
|
|
2298
|
-
function
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
`The "code" argument must be of type number. Received ${describeReceived(value)}`
|
|
2305
|
-
);
|
|
2306
|
-
err2.code = "ERR_INVALID_ARG_TYPE";
|
|
2307
|
-
throw err2;
|
|
2360
|
+
async function writeAll(stream, data2) {
|
|
2361
|
+
const writer = stream.getWriter();
|
|
2362
|
+
try {
|
|
2363
|
+
await writer.write(typeof data2 === "string" ? encoder.encode(data2) : data2);
|
|
2364
|
+
await writer.close();
|
|
2365
|
+
} catch {
|
|
2308
2366
|
}
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2367
|
+
}
|
|
2368
|
+
function kernelSpawn(ctx, process2) {
|
|
2369
|
+
return (argv, { stdin } = {}) => {
|
|
2370
|
+
let child = null;
|
|
2371
|
+
const done = (async () => {
|
|
2372
|
+
try {
|
|
2373
|
+
child = await ctx.spawn({
|
|
2374
|
+
argv,
|
|
2375
|
+
cwd: process2.cwd(),
|
|
2376
|
+
env: { ...process2.env },
|
|
2377
|
+
stdin: stdin === void 0 ? "null" : "pipe",
|
|
2378
|
+
stdout: "pipe",
|
|
2379
|
+
stderr: "pipe"
|
|
2380
|
+
});
|
|
2381
|
+
} catch (err2) {
|
|
2382
|
+
if (err2?.code === "ENOENT") {
|
|
2383
|
+
return { stdout: "", stderr: `${argv[0]}: command not found
|
|
2384
|
+
`, exitCode: 127 };
|
|
2385
|
+
}
|
|
2386
|
+
return { stdout: "", stderr: `${argv[0]}: ${err2?.message ?? err2}
|
|
2387
|
+
`, exitCode: 126 };
|
|
2388
|
+
}
|
|
2389
|
+
const [out, err, status] = await Promise.all([
|
|
2390
|
+
readAll(child.stdout),
|
|
2391
|
+
readAll(child.stderr),
|
|
2392
|
+
child.wait(),
|
|
2393
|
+
stdin === void 0 ? void 0 : writeAll(child.stdin, stdin)
|
|
2394
|
+
]);
|
|
2395
|
+
return { stdout: decoder.decode(out), stderr: decoder.decode(err), exitCode: status.status };
|
|
2396
|
+
})();
|
|
2397
|
+
return {
|
|
2398
|
+
kill: async (sig = "SIGTERM") => child ? child.kill(sig) : false,
|
|
2399
|
+
done
|
|
2400
|
+
};
|
|
2401
|
+
};
|
|
2402
|
+
}
|
|
2403
|
+
function compiler(rt) {
|
|
2404
|
+
return (body, filename) => {
|
|
2405
|
+
const head = "(async function () {";
|
|
2406
|
+
const { code, changed, binding = "__import" } = rt.rewriteDynamicImports(
|
|
2407
|
+
`${head}${body}
|
|
2408
|
+
})`
|
|
2313
2409
|
);
|
|
2314
|
-
|
|
2315
|
-
|
|
2410
|
+
const text = changed ? code.slice(head.length, -3) : body;
|
|
2411
|
+
const params = changed ? [...JSH_PARAMS, binding] : [...JSH_PARAMS];
|
|
2412
|
+
const fn = new AsyncFunction(...params, `${text}
|
|
2413
|
+
//# sourceURL=${filename}`);
|
|
2414
|
+
if (!changed) return fn;
|
|
2415
|
+
const importFrom = (specifier) => rt.importModule(specifier, filename);
|
|
2416
|
+
return (...args) => fn(...args.slice(0, JSH_PARAMS.length), importFrom);
|
|
2417
|
+
};
|
|
2418
|
+
}
|
|
2419
|
+
async function runKernelJsh(ctx, rt, filename) {
|
|
2420
|
+
const { process: process2, console: console2 } = rt;
|
|
2421
|
+
let stdoutIsTTY = false;
|
|
2422
|
+
try {
|
|
2423
|
+
stdoutIsTTY = !!await ctx.isatty?.(1);
|
|
2424
|
+
} catch {
|
|
2425
|
+
stdoutIsTTY = false;
|
|
2426
|
+
}
|
|
2427
|
+
const engine = {
|
|
2428
|
+
readSource: (path) => decoder.decode(ctx.sync.fs.readFile(path)),
|
|
2429
|
+
compile: compiler(rt),
|
|
2430
|
+
createRequire: (path) => rt.createRequire(path),
|
|
2431
|
+
selfRequire: rt.createRequire("/node_modules/@ai-ecoverse/slicc-jsh/package.json"),
|
|
2432
|
+
writeStdout: (s) => process2.stdout.write(String(s)),
|
|
2433
|
+
writeStderr: (s) => process2.stderr.write(String(s)),
|
|
2434
|
+
stdoutIsTTY,
|
|
2435
|
+
spawn: kernelSpawn(ctx, process2),
|
|
2436
|
+
shell: ["sh", "-c"],
|
|
2437
|
+
fetch: rt.fetch,
|
|
2438
|
+
isExit: (err) => err instanceof NodeExitError,
|
|
2439
|
+
exit: (code) => process2.exit(code)
|
|
2440
|
+
};
|
|
2441
|
+
await runJsh({ filename, engine, process: process2, console: console2 });
|
|
2442
|
+
}
|
|
2443
|
+
function installJshHandoff(ctx, rt) {
|
|
2444
|
+
const handoff = Object.freeze({
|
|
2445
|
+
version: JSH_VERSION,
|
|
2446
|
+
async runJsh(args) {
|
|
2447
|
+
const { process: process2 } = rt;
|
|
2448
|
+
const parsed = parseJshArgv([...args]);
|
|
2449
|
+
if (parsed.action === "version") return void process2.stdout.write(`${JSH_VERSION}
|
|
2450
|
+
`);
|
|
2451
|
+
if (parsed.action === "help") return void process2.stdout.write(JSH_USAGE);
|
|
2452
|
+
if (parsed.action === "usage") {
|
|
2453
|
+
process2.stderr.write(JSH_USAGE);
|
|
2454
|
+
return process2.exit(2);
|
|
2455
|
+
}
|
|
2456
|
+
if (parsed.action === "error") {
|
|
2457
|
+
process2.stderr.write(`${parsed.message}
|
|
2458
|
+
${JSH_USAGE}`);
|
|
2459
|
+
return process2.exit(parsed.status);
|
|
2460
|
+
}
|
|
2461
|
+
const filename = ctx.resolve(parsed.script);
|
|
2462
|
+
process2.argv = ["jsh", filename, ...parsed.args];
|
|
2463
|
+
return runKernelJsh(ctx, rt, filename);
|
|
2464
|
+
}
|
|
2465
|
+
});
|
|
2466
|
+
try {
|
|
2467
|
+
Object.defineProperty(globalThis, JSH_HANDOFF, {
|
|
2468
|
+
value: handoff,
|
|
2469
|
+
enumerable: false,
|
|
2470
|
+
configurable: true,
|
|
2471
|
+
writable: false
|
|
2472
|
+
});
|
|
2473
|
+
} catch {
|
|
2474
|
+
return () => {
|
|
2475
|
+
};
|
|
2316
2476
|
}
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2477
|
+
return () => {
|
|
2478
|
+
try {
|
|
2479
|
+
delete globalThis[JSH_HANDOFF];
|
|
2480
|
+
} catch {
|
|
2481
|
+
}
|
|
2482
|
+
};
|
|
2322
2483
|
}
|
|
2323
2484
|
|
|
2324
2485
|
// src/runtime/async-handles.mjs
|
|
@@ -2377,8 +2538,8 @@ async function drainLoop(handles, nextTick, { onBeforeExit, shouldStop } = {}) {
|
|
|
2377
2538
|
}
|
|
2378
2539
|
|
|
2379
2540
|
// src/runtime/buffer.mjs
|
|
2380
|
-
var
|
|
2381
|
-
var
|
|
2541
|
+
var encoder2 = new TextEncoder();
|
|
2542
|
+
var decoder2 = new TextDecoder();
|
|
2382
2543
|
var INSPECT_CUSTOM = /* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom");
|
|
2383
2544
|
function normalizeEncoding(enc) {
|
|
2384
2545
|
if (!enc) return "utf8";
|
|
@@ -2450,7 +2611,7 @@ function asUint8(value, encoding = "utf8") {
|
|
|
2450
2611
|
for (let i2 = 0; i2 < value.length; i2++) out[i2] = value.charCodeAt(i2) & 255;
|
|
2451
2612
|
return out;
|
|
2452
2613
|
}
|
|
2453
|
-
return
|
|
2614
|
+
return encoder2.encode(value);
|
|
2454
2615
|
}
|
|
2455
2616
|
if (typeof value === "number") return new Uint8Array([value & 255]);
|
|
2456
2617
|
if (ArrayBuffer.isView(value)) {
|
|
@@ -2458,7 +2619,7 @@ function asUint8(value, encoding = "utf8") {
|
|
|
2458
2619
|
}
|
|
2459
2620
|
if (value instanceof ArrayBuffer) return new Uint8Array(value);
|
|
2460
2621
|
if (Array.isArray(value)) return Uint8Array.from(value);
|
|
2461
|
-
return
|
|
2622
|
+
return encoder2.encode(String(value));
|
|
2462
2623
|
}
|
|
2463
2624
|
function toStringOf(bytes, encoding = "utf8", start = 0, end = bytes.length) {
|
|
2464
2625
|
const slice = bytes.subarray(start, end);
|
|
@@ -2482,7 +2643,7 @@ function toStringOf(bytes, encoding = "utf8", start = 0, end = bytes.length) {
|
|
|
2482
2643
|
for (const b of slice) out += String.fromCharCode(b);
|
|
2483
2644
|
return out;
|
|
2484
2645
|
}
|
|
2485
|
-
return
|
|
2646
|
+
return decoder2.decode(slice);
|
|
2486
2647
|
}
|
|
2487
2648
|
var float32Array = new Float32Array(1);
|
|
2488
2649
|
var uInt8Float32Array = new Uint8Array(float32Array.buffer);
|
|
@@ -10633,8 +10794,8 @@ function createEvents() {
|
|
|
10633
10794
|
}
|
|
10634
10795
|
|
|
10635
10796
|
// src/runtime/builtins/fs.mjs
|
|
10636
|
-
var
|
|
10637
|
-
var
|
|
10797
|
+
var encoder3 = new TextEncoder();
|
|
10798
|
+
var decoder3 = new TextDecoder();
|
|
10638
10799
|
var ERRNO = {
|
|
10639
10800
|
ENOENT: -2,
|
|
10640
10801
|
EEXIST: -17,
|
|
@@ -10679,10 +10840,10 @@ function nodeFsError(code, syscall, pathArg, err, dest) {
|
|
|
10679
10840
|
return e;
|
|
10680
10841
|
}
|
|
10681
10842
|
function toBytes(data2) {
|
|
10682
|
-
if (typeof data2 === "string") return
|
|
10843
|
+
if (typeof data2 === "string") return encoder3.encode(data2);
|
|
10683
10844
|
if (data2 instanceof Uint8Array) return data2;
|
|
10684
10845
|
if (ArrayBuffer.isView(data2)) return new Uint8Array(data2.buffer, data2.byteOffset, data2.byteLength);
|
|
10685
|
-
return
|
|
10846
|
+
return encoder3.encode(String(data2));
|
|
10686
10847
|
}
|
|
10687
10848
|
function statView(st) {
|
|
10688
10849
|
const mtimeMs = st.mtimeMs ?? (st.mtime ? Number(st.mtime) : 0);
|
|
@@ -10866,11 +11027,11 @@ function createFs({ ctx, path, process: process2, Buffer: Buffer2, handles, getS
|
|
|
10866
11027
|
try {
|
|
10867
11028
|
if (typeof process2?._readStdinSync === "function") {
|
|
10868
11029
|
const out = process2._readStdinSync();
|
|
10869
|
-
return encoding ?
|
|
11030
|
+
return encoding ? decoder3.decode(out) : wrapBuffer(out);
|
|
10870
11031
|
}
|
|
10871
11032
|
if (typeof process2?.stdin?._readAllSync === "function") {
|
|
10872
11033
|
const out = process2.stdin._readAllSync();
|
|
10873
|
-
return encoding ?
|
|
11034
|
+
return encoding ? decoder3.decode(out) : wrapBuffer(out);
|
|
10874
11035
|
}
|
|
10875
11036
|
if (typeof ctx.sync?.read === "function") {
|
|
10876
11037
|
const chunks = [];
|
|
@@ -10887,7 +11048,7 @@ function createFs({ ctx, path, process: process2, Buffer: Buffer2, handles, getS
|
|
|
10887
11048
|
out.set(c, at2);
|
|
10888
11049
|
at2 += c.length;
|
|
10889
11050
|
}
|
|
10890
|
-
return encoding ?
|
|
11051
|
+
return encoding ? decoder3.decode(out) : wrapBuffer(out);
|
|
10891
11052
|
}
|
|
10892
11053
|
} catch {
|
|
10893
11054
|
}
|
|
@@ -10959,7 +11120,7 @@ function createFs({ ctx, path, process: process2, Buffer: Buffer2, handles, getS
|
|
|
10959
11120
|
throw e;
|
|
10960
11121
|
}
|
|
10961
11122
|
const bytes = syncFs.readFile(target);
|
|
10962
|
-
if (encoding) return
|
|
11123
|
+
if (encoding) return decoder3.decode(bytes);
|
|
10963
11124
|
return wrapBuffer(bytes);
|
|
10964
11125
|
} catch (err) {
|
|
10965
11126
|
if (err?.code && err.syscall) throw err;
|
|
@@ -11127,7 +11288,7 @@ function createFs({ ctx, path, process: process2, Buffer: Buffer2, handles, getS
|
|
|
11127
11288
|
);
|
|
11128
11289
|
if (fd === 0) {
|
|
11129
11290
|
const data2 = readStdinSync(null);
|
|
11130
|
-
const src = data2 instanceof Uint8Array ? data2 :
|
|
11291
|
+
const src = data2 instanceof Uint8Array ? data2 : encoder3.encode(String(data2));
|
|
11131
11292
|
const n = Math.min(len, src.length);
|
|
11132
11293
|
buffer.set(src.subarray(0, n), bufOffset);
|
|
11133
11294
|
return n;
|
|
@@ -11250,7 +11411,7 @@ function createFs({ ctx, path, process: process2, Buffer: Buffer2, handles, getS
|
|
|
11250
11411
|
const encoding = typeof options === "string" ? options : options?.encoding;
|
|
11251
11412
|
try {
|
|
11252
11413
|
const bytes = await asyncFs.readFile(abs(p));
|
|
11253
|
-
if (encoding) return
|
|
11414
|
+
if (encoding) return decoder3.decode(bytes);
|
|
11254
11415
|
return wrapBuffer(bytes);
|
|
11255
11416
|
} catch (err) {
|
|
11256
11417
|
throw nodeFsError(err?.code || "ENOENT", "open", p, err);
|
|
@@ -13284,7 +13445,7 @@ function createQuerystring() {
|
|
|
13284
13445
|
}
|
|
13285
13446
|
|
|
13286
13447
|
// src/runtime/vendor-load.mjs
|
|
13287
|
-
var
|
|
13448
|
+
var decoder4 = new TextDecoder();
|
|
13288
13449
|
var cache = /* @__PURE__ */ new Map();
|
|
13289
13450
|
function evalCjs(source, filename) {
|
|
13290
13451
|
const module = { exports: {} };
|
|
@@ -13300,7 +13461,7 @@ function loadVendorCjs({ ctx, packageRoot, name, globals = {} }) {
|
|
|
13300
13461
|
if (cache.has(key)) return cache.get(key);
|
|
13301
13462
|
const path = `${packageRoot}/dist/vendor/${name}.cjs`;
|
|
13302
13463
|
const bytes = ctx.sync.fs.readFile(path);
|
|
13303
|
-
const source = typeof bytes === "string" ? bytes :
|
|
13464
|
+
const source = typeof bytes === "string" ? bytes : decoder4.decode(bytes);
|
|
13304
13465
|
const saved = {};
|
|
13305
13466
|
for (const [k, v] of Object.entries(globals)) {
|
|
13306
13467
|
saved[k] = globalThis[k];
|
|
@@ -13986,7 +14147,7 @@ function isBuiltinName(name) {
|
|
|
13986
14147
|
}
|
|
13987
14148
|
|
|
13988
14149
|
// src/runtime/cjs/loader.mjs
|
|
13989
|
-
var
|
|
14150
|
+
var decoder5 = new TextDecoder();
|
|
13990
14151
|
function createCjs({
|
|
13991
14152
|
ctx,
|
|
13992
14153
|
process: process2,
|
|
@@ -14003,7 +14164,7 @@ function createCjs({
|
|
|
14003
14164
|
const readPackageJson = (pkgPath) => {
|
|
14004
14165
|
if (packageCache.has(pkgPath)) return packageCache.get(pkgPath);
|
|
14005
14166
|
try {
|
|
14006
|
-
const text =
|
|
14167
|
+
const text = decoder5.decode(fs.readFile(pkgPath));
|
|
14007
14168
|
const pkg = JSON.parse(text);
|
|
14008
14169
|
packageCache.set(pkgPath, pkg);
|
|
14009
14170
|
return pkg;
|
|
@@ -14090,14 +14251,14 @@ function createCjs({
|
|
|
14090
14251
|
};
|
|
14091
14252
|
Module._extensions = {
|
|
14092
14253
|
".js"(module, filename) {
|
|
14093
|
-
const source =
|
|
14254
|
+
const source = decoder5.decode(fs.readFile(filename));
|
|
14094
14255
|
compile(module, source, filename);
|
|
14095
14256
|
},
|
|
14096
14257
|
".cjs"(module, filename) {
|
|
14097
14258
|
Module._extensions[".js"](module, filename);
|
|
14098
14259
|
},
|
|
14099
14260
|
".json"(module, filename) {
|
|
14100
|
-
module.exports = JSON.parse(
|
|
14261
|
+
module.exports = JSON.parse(decoder5.decode(fs.readFile(filename)));
|
|
14101
14262
|
}
|
|
14102
14263
|
};
|
|
14103
14264
|
Module.Module = Module;
|
|
@@ -14581,7 +14742,7 @@ function createConsole(writeStdout, writeStderr, util2) {
|
|
|
14581
14742
|
}
|
|
14582
14743
|
|
|
14583
14744
|
// src/runtime/esm/loader.mjs
|
|
14584
|
-
var
|
|
14745
|
+
var decoder6 = new TextDecoder();
|
|
14585
14746
|
var IMPORT_CONDITIONS = ["slicc", "import", "node", "default"];
|
|
14586
14747
|
function pathToFileURL2(filename) {
|
|
14587
14748
|
if (filename.startsWith("file:")) return filename;
|
|
@@ -14625,7 +14786,7 @@ function createEsm({ ctx, process: process2, handles, builtins, cjs, trackPromis
|
|
|
14625
14786
|
const readPackageJson = (pkgPath) => {
|
|
14626
14787
|
if (packageCache.has(pkgPath)) return packageCache.get(pkgPath);
|
|
14627
14788
|
try {
|
|
14628
|
-
const pkg = JSON.parse(
|
|
14789
|
+
const pkg = JSON.parse(decoder6.decode(fs.readFile(pkgPath)));
|
|
14629
14790
|
packageCache.set(pkgPath, pkg);
|
|
14630
14791
|
return pkg;
|
|
14631
14792
|
} catch {
|
|
@@ -14793,13 +14954,13 @@ ${parts.join("\n")}`
|
|
|
14793
14954
|
}
|
|
14794
14955
|
function loadFileSync(filename) {
|
|
14795
14956
|
if (filename.endsWith(".json")) {
|
|
14796
|
-
const data2 = JSON.parse(
|
|
14957
|
+
const data2 = JSON.parse(decoder6.decode(fs.readFile(filename)));
|
|
14797
14958
|
return cjsToNamespace(data2);
|
|
14798
14959
|
}
|
|
14799
14960
|
const cached3 = cache2.get(filename);
|
|
14800
14961
|
if (cached3?.namespace) return cached3.namespace;
|
|
14801
14962
|
if (cached3?.evaluating) return cached3.exportsObj;
|
|
14802
|
-
const source =
|
|
14963
|
+
const source = decoder6.decode(fs.readFile(filename));
|
|
14803
14964
|
if (!isEsmFilename(filename, source)) {
|
|
14804
14965
|
const exports = cjs.loadFile(filename);
|
|
14805
14966
|
const ns = cjsToNamespace(exports);
|
|
@@ -14810,14 +14971,14 @@ ${parts.join("\n")}`
|
|
|
14810
14971
|
}
|
|
14811
14972
|
async function loadFileAsync(filename) {
|
|
14812
14973
|
if (filename.endsWith(".json")) {
|
|
14813
|
-
const data2 = JSON.parse(
|
|
14974
|
+
const data2 = JSON.parse(decoder6.decode(fs.readFile(filename)));
|
|
14814
14975
|
return cjsToNamespace(data2);
|
|
14815
14976
|
}
|
|
14816
14977
|
const cached3 = cache2.get(filename);
|
|
14817
14978
|
if (cached3?.namespace) return cached3.namespace;
|
|
14818
14979
|
if (cached3?.evaluating && evaluatingStack.has(filename)) return cached3.exportsObj;
|
|
14819
14980
|
if (cached3?.promise) return cached3.promise;
|
|
14820
|
-
const source =
|
|
14981
|
+
const source = decoder6.decode(fs.readFile(filename));
|
|
14821
14982
|
if (!isEsmFilename(filename, source)) {
|
|
14822
14983
|
const exports = cjs.loadFile(filename);
|
|
14823
14984
|
const ns = cjsToNamespace(exports);
|
|
@@ -14850,7 +15011,7 @@ ${parts.join("\n")}`
|
|
|
14850
15011
|
return ns;
|
|
14851
15012
|
}
|
|
14852
15013
|
function runMain(filename, source) {
|
|
14853
|
-
const src = source ??
|
|
15014
|
+
const src = source ?? decoder6.decode(fs.readFile(filename));
|
|
14854
15015
|
if (!isEsmFilename(filename, src)) {
|
|
14855
15016
|
return cjs.runMain(filename, src);
|
|
14856
15017
|
}
|
|
@@ -14875,7 +15036,7 @@ ${parts.join("\n")}`
|
|
|
14875
15036
|
const cached3 = cache2.get(filename);
|
|
14876
15037
|
if (cached3?.namespace) return cached3.namespace;
|
|
14877
15038
|
if (cached3?.evaluating) return cached3.exportsObj;
|
|
14878
|
-
const source =
|
|
15039
|
+
const source = decoder6.decode(fs.readFile(filename));
|
|
14879
15040
|
const { hasTopLevelAwait } = transformEsm(source, filename);
|
|
14880
15041
|
if (hasTopLevelAwait) {
|
|
14881
15042
|
const err = new Error(
|
|
@@ -16199,7 +16360,7 @@ function createWebSocket(ctx, { handles, trackPromise: trackPromise2 } = {}) {
|
|
|
16199
16360
|
}
|
|
16200
16361
|
|
|
16201
16362
|
// src/runtime/run.mjs
|
|
16202
|
-
var
|
|
16363
|
+
var decoder7 = new TextDecoder();
|
|
16203
16364
|
function installJshGlobals(bindings) {
|
|
16204
16365
|
const saved = /* @__PURE__ */ new Map();
|
|
16205
16366
|
for (const name of Object.keys(bindings)) {
|
|
@@ -16238,6 +16399,8 @@ async function runNode(ctx, options = {}) {
|
|
|
16238
16399
|
let lastEvalCode;
|
|
16239
16400
|
let restoreGlobals = () => {
|
|
16240
16401
|
};
|
|
16402
|
+
let removeJshHandoff = () => {
|
|
16403
|
+
};
|
|
16241
16404
|
const removeCtxHooks = [];
|
|
16242
16405
|
const util2 = createUtil();
|
|
16243
16406
|
const printUncaught = (err) => {
|
|
@@ -16457,17 +16620,19 @@ slicc-jsh ${NODE_SHIM_VERSION} (Node-compatible, abi: js)
|
|
|
16457
16620
|
cjs.setRequireEsmHook((filename) => esm.requireEsm(filename));
|
|
16458
16621
|
cjs.setImportModuleHook((specifier, parent) => esm.importModule(specifier, parent));
|
|
16459
16622
|
try {
|
|
16623
|
+
const rt = {
|
|
16624
|
+
process: process2,
|
|
16625
|
+
console: console2,
|
|
16626
|
+
Buffer: Buffer2,
|
|
16627
|
+
fetch,
|
|
16628
|
+
createRequire: cjs.createRequire,
|
|
16629
|
+
importModule: (specifier, parent) => esm.importModule(specifier, parent),
|
|
16630
|
+
rewriteDynamicImports
|
|
16631
|
+
};
|
|
16632
|
+
removeJshHandoff = installJshHandoff(ctx, rt);
|
|
16460
16633
|
if (typeof options.main === "function") {
|
|
16461
16634
|
try {
|
|
16462
|
-
const result = options.main(
|
|
16463
|
-
process: process2,
|
|
16464
|
-
console: console2,
|
|
16465
|
-
Buffer: Buffer2,
|
|
16466
|
-
fetch,
|
|
16467
|
-
createRequire: cjs.createRequire,
|
|
16468
|
-
importModule: (specifier, parent) => esm.importModule(specifier, parent),
|
|
16469
|
-
rewriteDynamicImports
|
|
16470
|
-
});
|
|
16635
|
+
const result = options.main(rt);
|
|
16471
16636
|
if (result != null && typeof result.then === "function") {
|
|
16472
16637
|
trackPromise(handles, result).catch(() => {
|
|
16473
16638
|
});
|
|
@@ -16515,7 +16680,7 @@ slicc-jsh ${NODE_SHIM_VERSION} (Node-compatible, abi: js)
|
|
|
16515
16680
|
merged.set(c, off);
|
|
16516
16681
|
off += c.byteLength;
|
|
16517
16682
|
}
|
|
16518
|
-
const source =
|
|
16683
|
+
const source = decoder7.decode(merged);
|
|
16519
16684
|
lastEvalCode = source;
|
|
16520
16685
|
process2._evalCode = source;
|
|
16521
16686
|
process2.argv[1] = "[stdin]";
|
|
@@ -16598,7 +16763,7 @@ slicc-jsh ${NODE_SHIM_VERSION} (Node-compatible, abi: js)
|
|
|
16598
16763
|
const filePath = ctx.resolve(parsed.script);
|
|
16599
16764
|
let source;
|
|
16600
16765
|
try {
|
|
16601
|
-
source =
|
|
16766
|
+
source = decoder7.decode(ctx.sync.fs.readFile(filePath));
|
|
16602
16767
|
} catch (err) {
|
|
16603
16768
|
const msg = err?.message ?? String(err);
|
|
16604
16769
|
await ctx.write(2, `${ctx.argv[0]}: cannot open ${parsed.script}: ${msg}
|
|
@@ -16687,95 +16852,13 @@ slicc-jsh ${NODE_SHIM_VERSION} (Node-compatible, abi: js)
|
|
|
16687
16852
|
}
|
|
16688
16853
|
try {
|
|
16689
16854
|
restoreGlobals();
|
|
16855
|
+
removeJshHandoff();
|
|
16690
16856
|
} catch {
|
|
16691
16857
|
}
|
|
16692
16858
|
}
|
|
16693
16859
|
}
|
|
16694
16860
|
|
|
16695
16861
|
// src/jsh.mjs
|
|
16696
|
-
var decoder7 = new TextDecoder();
|
|
16697
|
-
var encoder3 = new TextEncoder();
|
|
16698
|
-
var AsyncFunction = Object.getPrototypeOf(async () => {
|
|
16699
|
-
}).constructor;
|
|
16700
|
-
async function readAll(stream) {
|
|
16701
|
-
if (!stream) return new Uint8Array(0);
|
|
16702
|
-
const chunks = [];
|
|
16703
|
-
let size = 0;
|
|
16704
|
-
const reader = stream.getReader();
|
|
16705
|
-
for (; ; ) {
|
|
16706
|
-
const { done, value } = await reader.read();
|
|
16707
|
-
if (done) break;
|
|
16708
|
-
const bytes = typeof value === "string" ? encoder3.encode(value) : value;
|
|
16709
|
-
chunks.push(bytes);
|
|
16710
|
-
size += bytes.length;
|
|
16711
|
-
}
|
|
16712
|
-
const out = new Uint8Array(size);
|
|
16713
|
-
let off = 0;
|
|
16714
|
-
for (const c of chunks) {
|
|
16715
|
-
out.set(c, off);
|
|
16716
|
-
off += c.length;
|
|
16717
|
-
}
|
|
16718
|
-
return out;
|
|
16719
|
-
}
|
|
16720
|
-
async function writeAll(stream, data2) {
|
|
16721
|
-
const writer = stream.getWriter();
|
|
16722
|
-
try {
|
|
16723
|
-
await writer.write(typeof data2 === "string" ? encoder3.encode(data2) : data2);
|
|
16724
|
-
await writer.close();
|
|
16725
|
-
} catch {
|
|
16726
|
-
}
|
|
16727
|
-
}
|
|
16728
|
-
function kernelSpawn(ctx, process2) {
|
|
16729
|
-
return (argv, { stdin } = {}) => {
|
|
16730
|
-
let child = null;
|
|
16731
|
-
const done = (async () => {
|
|
16732
|
-
try {
|
|
16733
|
-
child = await ctx.spawn({
|
|
16734
|
-
argv,
|
|
16735
|
-
cwd: process2.cwd(),
|
|
16736
|
-
env: { ...process2.env },
|
|
16737
|
-
stdin: stdin === void 0 ? "null" : "pipe",
|
|
16738
|
-
stdout: "pipe",
|
|
16739
|
-
stderr: "pipe"
|
|
16740
|
-
});
|
|
16741
|
-
} catch (err2) {
|
|
16742
|
-
if (err2?.code === "ENOENT") {
|
|
16743
|
-
return { stdout: "", stderr: `${argv[0]}: command not found
|
|
16744
|
-
`, exitCode: 127 };
|
|
16745
|
-
}
|
|
16746
|
-
return { stdout: "", stderr: `${argv[0]}: ${err2?.message ?? err2}
|
|
16747
|
-
`, exitCode: 126 };
|
|
16748
|
-
}
|
|
16749
|
-
const [out, err, status] = await Promise.all([
|
|
16750
|
-
readAll(child.stdout),
|
|
16751
|
-
readAll(child.stderr),
|
|
16752
|
-
child.wait(),
|
|
16753
|
-
stdin === void 0 ? void 0 : writeAll(child.stdin, stdin)
|
|
16754
|
-
]);
|
|
16755
|
-
return { stdout: decoder7.decode(out), stderr: decoder7.decode(err), exitCode: status.status };
|
|
16756
|
-
})();
|
|
16757
|
-
return {
|
|
16758
|
-
kill: async (sig = "SIGTERM") => child ? child.kill(sig) : false,
|
|
16759
|
-
done
|
|
16760
|
-
};
|
|
16761
|
-
};
|
|
16762
|
-
}
|
|
16763
|
-
function compiler(rt) {
|
|
16764
|
-
return (body, filename) => {
|
|
16765
|
-
const head = "(async function () {";
|
|
16766
|
-
const { code, changed, binding = "__import" } = rt.rewriteDynamicImports(
|
|
16767
|
-
`${head}${body}
|
|
16768
|
-
})`
|
|
16769
|
-
);
|
|
16770
|
-
const text = changed ? code.slice(head.length, -3) : body;
|
|
16771
|
-
const params = changed ? [...JSH_PARAMS, binding] : [...JSH_PARAMS];
|
|
16772
|
-
const fn = new AsyncFunction(...params, `${text}
|
|
16773
|
-
//# sourceURL=${filename}`);
|
|
16774
|
-
if (!changed) return fn;
|
|
16775
|
-
const importFrom = (specifier) => rt.importModule(specifier, filename);
|
|
16776
|
-
return (...args) => fn(...args.slice(0, JSH_PARAMS.length), importFrom);
|
|
16777
|
-
};
|
|
16778
|
-
}
|
|
16779
16862
|
async function main(ctx) {
|
|
16780
16863
|
const parsed = parseJshArgv([...ctx.argv].slice(1));
|
|
16781
16864
|
if (parsed.action === "version") {
|
|
@@ -16801,32 +16884,7 @@ ${JSH_USAGE}`);
|
|
|
16801
16884
|
const nodeCtx = Object.create(ctx, {
|
|
16802
16885
|
argv: { value: [argv0, filename, ...parsed.args], enumerable: true }
|
|
16803
16886
|
});
|
|
16804
|
-
return runNode(nodeCtx, {
|
|
16805
|
-
main: async (rt) => {
|
|
16806
|
-
const { process: process2, console: console2 } = rt;
|
|
16807
|
-
let stdoutIsTTY = false;
|
|
16808
|
-
try {
|
|
16809
|
-
stdoutIsTTY = !!await ctx.isatty?.(1);
|
|
16810
|
-
} catch {
|
|
16811
|
-
stdoutIsTTY = false;
|
|
16812
|
-
}
|
|
16813
|
-
const engine = {
|
|
16814
|
-
readSource: (path) => decoder7.decode(ctx.sync.fs.readFile(path)),
|
|
16815
|
-
compile: compiler(rt),
|
|
16816
|
-
createRequire: (path) => rt.createRequire(path),
|
|
16817
|
-
selfRequire: rt.createRequire("/node_modules/@ai-ecoverse/slicc-jsh/package.json"),
|
|
16818
|
-
writeStdout: (s) => process2.stdout.write(String(s)),
|
|
16819
|
-
writeStderr: (s) => process2.stderr.write(String(s)),
|
|
16820
|
-
stdoutIsTTY,
|
|
16821
|
-
spawn: kernelSpawn(ctx, process2),
|
|
16822
|
-
shell: ["sh", "-c"],
|
|
16823
|
-
fetch: rt.fetch,
|
|
16824
|
-
isExit: (err) => err instanceof NodeExitError,
|
|
16825
|
-
exit: (code) => process2.exit(code)
|
|
16826
|
-
};
|
|
16827
|
-
await runJsh({ filename, engine, process: process2, console: console2 });
|
|
16828
|
-
}
|
|
16829
|
-
});
|
|
16887
|
+
return runNode(nodeCtx, { main: (rt) => runKernelJsh(ctx, rt, filename) });
|
|
16830
16888
|
}
|
|
16831
16889
|
export {
|
|
16832
16890
|
main as default
|