sandboxedjs 0.1.24 → 0.1.26
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 +14 -0
- package/dist/index.cjs +1708 -550
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +45 -2
- package/dist/index.d.ts +45 -2
- package/dist/index.js +1704 -543
- package/dist/index.js.map +1 -1
- package/package.json +1 -5
package/dist/index.cjs
CHANGED
|
@@ -2,44 +2,38 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var index_js = require('buffer/index.js');
|
|
6
6
|
var pako = require('pako');
|
|
7
7
|
var sha256 = require('@noble/hashes/sha256');
|
|
8
8
|
var sha512 = require('@noble/hashes/sha512');
|
|
9
9
|
var sha1 = require('@noble/hashes/sha1');
|
|
10
10
|
var semver = require('semver');
|
|
11
11
|
var acorn = require('acorn');
|
|
12
|
-
var
|
|
12
|
+
var EventEmitter4 = require('events/events.js');
|
|
13
13
|
var jsx = require('acorn-jsx');
|
|
14
14
|
var resolve_exports = require('resolve.exports');
|
|
15
15
|
var pathModule = require('path-browserify');
|
|
16
|
-
var
|
|
17
|
-
var
|
|
18
|
-
var assertModule = require('assert');
|
|
19
|
-
var processShim = require('process');
|
|
20
|
-
var zlibModule = require('browserify-zlib');
|
|
16
|
+
var streamModule4 = require('stream-browserify');
|
|
17
|
+
var processShim = require('process/browser.js');
|
|
21
18
|
var querystringModule = require('querystring-es3');
|
|
22
|
-
var stringDecoderModule = require('string_decoder');
|
|
19
|
+
var stringDecoderModule = require('string_decoder/lib/string_decoder.js');
|
|
23
20
|
var timersModule = require('timers-browserify');
|
|
24
|
-
var
|
|
25
|
-
var legacy = require('@noble/hashes/legacy');
|
|
21
|
+
var legacyUrl = require('url/url.js');
|
|
22
|
+
var legacy$1 = require('@noble/hashes/legacy');
|
|
26
23
|
var hmac = require('@noble/hashes/hmac');
|
|
27
24
|
|
|
28
25
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
29
26
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
30
27
|
|
|
31
|
-
var
|
|
28
|
+
var EventEmitter4__default = /*#__PURE__*/_interopDefault(EventEmitter4);
|
|
32
29
|
var jsx__default = /*#__PURE__*/_interopDefault(jsx);
|
|
33
30
|
var pathModule__default = /*#__PURE__*/_interopDefault(pathModule);
|
|
34
|
-
var
|
|
35
|
-
var utilModule__default = /*#__PURE__*/_interopDefault(utilModule);
|
|
36
|
-
var assertModule__default = /*#__PURE__*/_interopDefault(assertModule);
|
|
31
|
+
var streamModule4__default = /*#__PURE__*/_interopDefault(streamModule4);
|
|
37
32
|
var processShim__default = /*#__PURE__*/_interopDefault(processShim);
|
|
38
|
-
var zlibModule__default = /*#__PURE__*/_interopDefault(zlibModule);
|
|
39
33
|
var querystringModule__default = /*#__PURE__*/_interopDefault(querystringModule);
|
|
40
34
|
var stringDecoderModule__default = /*#__PURE__*/_interopDefault(stringDecoderModule);
|
|
41
35
|
var timersModule__default = /*#__PURE__*/_interopDefault(timersModule);
|
|
42
|
-
var
|
|
36
|
+
var legacyUrl__default = /*#__PURE__*/_interopDefault(legacyUrl);
|
|
43
37
|
|
|
44
38
|
var __defProp = Object.defineProperty;
|
|
45
39
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
@@ -249,7 +243,7 @@ function join(...parts) {
|
|
|
249
243
|
const joined = parts.filter((p) => p !== "").join("/");
|
|
250
244
|
return joined === "" ? "." : normalize(joined);
|
|
251
245
|
}
|
|
252
|
-
function resolve(
|
|
246
|
+
function resolve(base2, ...parts) {
|
|
253
247
|
let resolved = "";
|
|
254
248
|
let absolute = false;
|
|
255
249
|
for (let i = parts.length - 1; i >= 0 && !absolute; i--) {
|
|
@@ -259,7 +253,7 @@ function resolve(base, ...parts) {
|
|
|
259
253
|
absolute = isAbsolute(part);
|
|
260
254
|
}
|
|
261
255
|
if (!absolute) {
|
|
262
|
-
resolved = resolved === "" ?
|
|
256
|
+
resolved = resolved === "" ? base2 : `${base2}/${resolved}`;
|
|
263
257
|
}
|
|
264
258
|
const norm = normalize(resolved);
|
|
265
259
|
return isAbsolute(norm) ? stripTrailing(norm) : stripTrailing(normalize(`/${norm}`));
|
|
@@ -279,14 +273,14 @@ function basename(p, ext) {
|
|
|
279
273
|
const norm = stripTrailing(normalize(p));
|
|
280
274
|
if (norm === "/") return "/";
|
|
281
275
|
const idx = norm.lastIndexOf("/");
|
|
282
|
-
let
|
|
283
|
-
if (ext &&
|
|
284
|
-
return
|
|
276
|
+
let base2 = idx < 0 ? norm : norm.slice(idx + 1);
|
|
277
|
+
if (ext && base2 !== ext && base2.endsWith(ext)) base2 = base2.slice(0, -ext.length);
|
|
278
|
+
return base2;
|
|
285
279
|
}
|
|
286
280
|
function extname(p) {
|
|
287
|
-
const
|
|
288
|
-
const idx =
|
|
289
|
-
return idx <= 0 ? "" :
|
|
281
|
+
const base2 = basename(p);
|
|
282
|
+
const idx = base2.lastIndexOf(".");
|
|
283
|
+
return idx <= 0 ? "" : base2.slice(idx);
|
|
290
284
|
}
|
|
291
285
|
function relative(from, to) {
|
|
292
286
|
const a = segments(normalize(from));
|
|
@@ -853,8 +847,8 @@ function splitTopLevel(s, sep) {
|
|
|
853
847
|
out.push(cur);
|
|
854
848
|
return out;
|
|
855
849
|
}
|
|
856
|
-
function compileBracket(pattern,
|
|
857
|
-
let i =
|
|
850
|
+
function compileBracket(pattern, start2) {
|
|
851
|
+
let i = start2 + 1;
|
|
858
852
|
let negate = false;
|
|
859
853
|
if (pattern[i] === "!" || pattern[i] === "^") {
|
|
860
854
|
negate = true;
|
|
@@ -1056,9 +1050,9 @@ function tokenize(src) {
|
|
|
1056
1050
|
const rest = src.slice(i);
|
|
1057
1051
|
const baseMatch = /^(\d+)#([0-9a-zA-Z@_]+)/.exec(rest);
|
|
1058
1052
|
if (baseMatch) {
|
|
1059
|
-
const
|
|
1060
|
-
if (
|
|
1061
|
-
out.push({ kind: "num", value: baseMatch[0], num: parseInBase(baseMatch[2],
|
|
1053
|
+
const base2 = Number(baseMatch[1]);
|
|
1054
|
+
if (base2 < 2 || base2 > 64) throw new exports.ArithError(`invalid arithmetic base (error token is "${baseMatch[1]}")`);
|
|
1055
|
+
out.push({ kind: "num", value: baseMatch[0], num: parseInBase(baseMatch[2], base2) });
|
|
1062
1056
|
i += baseMatch[0].length;
|
|
1063
1057
|
continue;
|
|
1064
1058
|
}
|
|
@@ -1105,17 +1099,17 @@ function tokenize(src) {
|
|
|
1105
1099
|
out.push({ kind: "eof", value: "" });
|
|
1106
1100
|
return out;
|
|
1107
1101
|
}
|
|
1108
|
-
function parseInBase(text2,
|
|
1102
|
+
function parseInBase(text2, base2) {
|
|
1109
1103
|
let value = 0;
|
|
1110
1104
|
for (const ch of text2) {
|
|
1111
1105
|
let digit;
|
|
1112
|
-
if (
|
|
1106
|
+
if (base2 <= 36) {
|
|
1113
1107
|
digit = DIGITS.toLowerCase().indexOf(ch.toLowerCase());
|
|
1114
1108
|
} else {
|
|
1115
1109
|
digit = DIGITS.indexOf(ch);
|
|
1116
1110
|
}
|
|
1117
|
-
if (digit < 0 || digit >=
|
|
1118
|
-
value = value *
|
|
1111
|
+
if (digit < 0 || digit >= base2) throw new exports.ArithError(`value too great for base (error token is "${text2}")`);
|
|
1112
|
+
value = value * base2 + digit;
|
|
1119
1113
|
}
|
|
1120
1114
|
return value;
|
|
1121
1115
|
}
|
|
@@ -1206,7 +1200,7 @@ var init_arith = __esm({
|
|
|
1206
1200
|
return value;
|
|
1207
1201
|
}
|
|
1208
1202
|
assignment() {
|
|
1209
|
-
const
|
|
1203
|
+
const start2 = this.i;
|
|
1210
1204
|
const t = this.peek();
|
|
1211
1205
|
if (t.kind === "name") {
|
|
1212
1206
|
const next = this.toks[this.i + 1];
|
|
@@ -1256,7 +1250,7 @@ var init_arith = __esm({
|
|
|
1256
1250
|
return this.writeVar(t.value, Math.trunc(result));
|
|
1257
1251
|
}
|
|
1258
1252
|
}
|
|
1259
|
-
this.i =
|
|
1253
|
+
this.i = start2;
|
|
1260
1254
|
return this.ternary();
|
|
1261
1255
|
}
|
|
1262
1256
|
ternary() {
|
|
@@ -1350,12 +1344,12 @@ var init_arith = __esm({
|
|
|
1350
1344
|
}
|
|
1351
1345
|
}
|
|
1352
1346
|
power() {
|
|
1353
|
-
const
|
|
1347
|
+
const base2 = this.unary();
|
|
1354
1348
|
if (this.eat("**")) {
|
|
1355
1349
|
const exp = this.power();
|
|
1356
|
-
return Math.trunc(Math.pow(
|
|
1350
|
+
return Math.trunc(Math.pow(base2, exp));
|
|
1357
1351
|
}
|
|
1358
|
-
return
|
|
1352
|
+
return base2;
|
|
1359
1353
|
}
|
|
1360
1354
|
unary() {
|
|
1361
1355
|
if (this.eat("+")) return this.unary();
|
|
@@ -1549,7 +1543,7 @@ function splitBraceAlternatives(body) {
|
|
|
1549
1543
|
function expandSequence(body) {
|
|
1550
1544
|
const numeric = /^(-?\d+)\.\.(-?\d+)(?:\.\.(-?\d+))?$/.exec(body);
|
|
1551
1545
|
if (numeric) {
|
|
1552
|
-
const
|
|
1546
|
+
const start2 = Number(numeric[1]);
|
|
1553
1547
|
const end = Number(numeric[2]);
|
|
1554
1548
|
let step = numeric[3] !== void 0 ? Math.abs(Number(numeric[3])) : 1;
|
|
1555
1549
|
if (step === 0) step = 1;
|
|
@@ -1558,18 +1552,18 @@ function expandSequence(body) {
|
|
|
1558
1552
|
/^-?0\d/.test(numeric[2]) ? numeric[2].replace("-", "").length : 0
|
|
1559
1553
|
);
|
|
1560
1554
|
const out = [];
|
|
1561
|
-
if (
|
|
1562
|
-
else for (let i =
|
|
1555
|
+
if (start2 <= end) for (let i = start2; i <= end; i += step) out.push(padNumber(i, width));
|
|
1556
|
+
else for (let i = start2; i >= end; i -= step) out.push(padNumber(i, width));
|
|
1563
1557
|
return out;
|
|
1564
1558
|
}
|
|
1565
1559
|
const alpha = /^([A-Za-z])\.\.([A-Za-z])(?:\.\.(-?\d+))?$/.exec(body);
|
|
1566
1560
|
if (alpha) {
|
|
1567
|
-
const
|
|
1561
|
+
const start2 = alpha[1].charCodeAt(0);
|
|
1568
1562
|
const end = alpha[2].charCodeAt(0);
|
|
1569
1563
|
const step = alpha[3] !== void 0 ? Math.abs(Number(alpha[3])) || 1 : 1;
|
|
1570
1564
|
const out = [];
|
|
1571
|
-
if (
|
|
1572
|
-
else for (let i =
|
|
1565
|
+
if (start2 <= end) for (let i = start2; i <= end; i += step) out.push(String.fromCharCode(i));
|
|
1566
|
+
else for (let i = start2; i >= end; i -= step) out.push(String.fromCharCode(i));
|
|
1573
1567
|
return out;
|
|
1574
1568
|
}
|
|
1575
1569
|
return null;
|
|
@@ -1679,10 +1673,10 @@ async function expandFragments(word, ctx, opts = {}) {
|
|
|
1679
1673
|
flushLiteral();
|
|
1680
1674
|
return out;
|
|
1681
1675
|
}
|
|
1682
|
-
async function expandDoubleQuoted(word,
|
|
1676
|
+
async function expandDoubleQuoted(word, start2, ctx, opts) {
|
|
1683
1677
|
const out = [];
|
|
1684
1678
|
let literal = "";
|
|
1685
|
-
let i =
|
|
1679
|
+
let i = start2;
|
|
1686
1680
|
const flush = () => {
|
|
1687
1681
|
if (literal !== "") {
|
|
1688
1682
|
out.push({ text: literal, split: false, glob: false });
|
|
@@ -1982,9 +1976,9 @@ function stripAffix(value, pattern, op, ctx) {
|
|
|
1982
1976
|
function substitute(value, pattern, replacement, opts) {
|
|
1983
1977
|
const matchOpts = { pathname: false, dot: true, extglob: opts.extglob };
|
|
1984
1978
|
const chars = [...value];
|
|
1985
|
-
const matchAt = (
|
|
1986
|
-
for (let end = chars.length; end >=
|
|
1987
|
-
if (fnmatch(pattern, chars.slice(
|
|
1979
|
+
const matchAt = (start2) => {
|
|
1980
|
+
for (let end = chars.length; end >= start2; end--) {
|
|
1981
|
+
if (fnmatch(pattern, chars.slice(start2, end).join(""), matchOpts)) return end;
|
|
1988
1982
|
}
|
|
1989
1983
|
return -1;
|
|
1990
1984
|
};
|
|
@@ -1993,9 +1987,9 @@ function substitute(value, pattern, replacement, opts) {
|
|
|
1993
1987
|
return end < 0 ? value : replacement + chars.slice(end).join("");
|
|
1994
1988
|
}
|
|
1995
1989
|
if (opts.anchorEnd) {
|
|
1996
|
-
for (let
|
|
1997
|
-
if (fnmatch(pattern, chars.slice(
|
|
1998
|
-
return chars.slice(0,
|
|
1990
|
+
for (let start2 = 0; start2 <= chars.length; start2++) {
|
|
1991
|
+
if (fnmatch(pattern, chars.slice(start2).join(""), matchOpts)) {
|
|
1992
|
+
return chars.slice(0, start2).join("") + replacement;
|
|
1999
1993
|
}
|
|
2000
1994
|
}
|
|
2001
1995
|
return value;
|
|
@@ -2184,18 +2178,18 @@ async function pathnameExpand(field, ctx) {
|
|
|
2184
2178
|
if (ctx.noglob) return [literal];
|
|
2185
2179
|
const pattern = field.map((f) => f.glob ? f.text : escapeGlob(f.text)).join("");
|
|
2186
2180
|
if (!hasMagic(pattern, ctx.extglob !== false)) return [literal];
|
|
2187
|
-
const
|
|
2181
|
+
const matches3 = glob(ctx.vfs, pattern, {
|
|
2188
2182
|
cwd: ctx.cwd,
|
|
2189
2183
|
cred: ctx.cred,
|
|
2190
2184
|
dot: ctx.dotglob ?? false,
|
|
2191
2185
|
extglob: ctx.extglob !== false
|
|
2192
2186
|
});
|
|
2193
|
-
if (
|
|
2187
|
+
if (matches3.length === 0) {
|
|
2194
2188
|
if (ctx.failglob) throw new ExpansionError(`no match: ${literal}`);
|
|
2195
2189
|
if (ctx.nullglob) return [];
|
|
2196
2190
|
return [literal];
|
|
2197
2191
|
}
|
|
2198
|
-
return
|
|
2192
|
+
return matches3;
|
|
2199
2193
|
}
|
|
2200
2194
|
function matchesPattern(value, pattern, extglob = true) {
|
|
2201
2195
|
return fnmatch(pattern, value, { pathname: false, dot: true, extglob });
|
|
@@ -2609,12 +2603,12 @@ function decodeEscapes(input, opts = {}) {
|
|
|
2609
2603
|
}
|
|
2610
2604
|
return { text: out, stopped: false };
|
|
2611
2605
|
}
|
|
2612
|
-
function formatPrintf(
|
|
2606
|
+
function formatPrintf(format3, args) {
|
|
2613
2607
|
let out = "";
|
|
2614
2608
|
let argIndex = 0;
|
|
2615
2609
|
let consumedAny = false;
|
|
2616
2610
|
do {
|
|
2617
|
-
const pass = formatOnce(
|
|
2611
|
+
const pass = formatOnce(format3, args, argIndex);
|
|
2618
2612
|
out += pass.text;
|
|
2619
2613
|
if (pass.stopped) return out;
|
|
2620
2614
|
consumedAny = pass.nextIndex > argIndex;
|
|
@@ -2623,17 +2617,17 @@ function formatPrintf(format, args) {
|
|
|
2623
2617
|
} while (argIndex < args.length && consumedAny);
|
|
2624
2618
|
return out;
|
|
2625
2619
|
}
|
|
2626
|
-
function formatOnce(
|
|
2620
|
+
function formatOnce(format3, args, startIndex) {
|
|
2627
2621
|
let out = "";
|
|
2628
2622
|
let i = 0;
|
|
2629
2623
|
let argIndex = startIndex;
|
|
2630
2624
|
let hasConversions = false;
|
|
2631
2625
|
const nextArg = () => args[argIndex++] ?? "";
|
|
2632
|
-
while (i <
|
|
2633
|
-
const c =
|
|
2626
|
+
while (i < format3.length) {
|
|
2627
|
+
const c = format3[i];
|
|
2634
2628
|
if (c === "\\") {
|
|
2635
|
-
decodeEscapes(
|
|
2636
|
-
const single = decodeSingleEscape(
|
|
2629
|
+
decodeEscapes(format3.slice(i, i + 12), { stopAtC: true });
|
|
2630
|
+
const single = decodeSingleEscape(format3, i);
|
|
2637
2631
|
if (single.stopped) return { text: out, nextIndex: argIndex, hasConversions, stopped: true };
|
|
2638
2632
|
out += single.text;
|
|
2639
2633
|
i = single.next;
|
|
@@ -2644,12 +2638,12 @@ function formatOnce(format, args, startIndex) {
|
|
|
2644
2638
|
i++;
|
|
2645
2639
|
continue;
|
|
2646
2640
|
}
|
|
2647
|
-
if (
|
|
2641
|
+
if (format3[i + 1] === "%") {
|
|
2648
2642
|
out += "%";
|
|
2649
2643
|
i += 2;
|
|
2650
2644
|
continue;
|
|
2651
2645
|
}
|
|
2652
|
-
const spec = /^%([-+ #0']*)(\*|\d+)?(?:\.(\*|\d+))?([diouxXeEfgGaAcsbq])/.exec(
|
|
2646
|
+
const spec = /^%([-+ #0']*)(\*|\d+)?(?:\.(\*|\d+))?([diouxXeEfgGaAcsbq])/.exec(format3.slice(i));
|
|
2653
2647
|
if (!spec) {
|
|
2654
2648
|
out += c;
|
|
2655
2649
|
i++;
|
|
@@ -2854,18 +2848,18 @@ function builtinEcho({ argv, io }) {
|
|
|
2854
2848
|
function builtinPrintf({ argv, io }) {
|
|
2855
2849
|
const args = argv.slice(1);
|
|
2856
2850
|
let varName;
|
|
2857
|
-
let
|
|
2851
|
+
let start2 = 0;
|
|
2858
2852
|
if (args[0] === "-v" && args[1] !== void 0) {
|
|
2859
2853
|
varName = args[1];
|
|
2860
|
-
|
|
2854
|
+
start2 = 2;
|
|
2861
2855
|
}
|
|
2862
|
-
const
|
|
2863
|
-
if (
|
|
2856
|
+
const format3 = args[start2];
|
|
2857
|
+
if (format3 === void 0) {
|
|
2864
2858
|
io.stderr.write("printf: usage: printf [-v var] format [arguments]\n");
|
|
2865
2859
|
return 2;
|
|
2866
2860
|
}
|
|
2867
2861
|
try {
|
|
2868
|
-
const text2 = formatPrintf(
|
|
2862
|
+
const text2 = formatPrintf(format3, args.slice(start2 + 1));
|
|
2869
2863
|
if (varName) return 0;
|
|
2870
2864
|
io.stdout.write(text2);
|
|
2871
2865
|
return 0;
|
|
@@ -3613,10 +3607,10 @@ function builtinType({ shell, argv, io }) {
|
|
|
3613
3607
|
}
|
|
3614
3608
|
async function builtinCommand({ shell, argv, io }) {
|
|
3615
3609
|
const args = argv.slice(1);
|
|
3616
|
-
const
|
|
3610
|
+
const describe2 = args.includes("-v") || args.includes("-V");
|
|
3617
3611
|
const verbose = args.includes("-V");
|
|
3618
3612
|
const rest = args.filter((a) => a !== "-v" && a !== "-V" && a !== "-p");
|
|
3619
|
-
if (
|
|
3613
|
+
if (describe2) {
|
|
3620
3614
|
let status = 0;
|
|
3621
3615
|
for (const name of rest) {
|
|
3622
3616
|
if (isBuiltinName(name)) {
|
|
@@ -3855,13 +3849,13 @@ function builtinDirs({ shell, argv, io }) {
|
|
|
3855
3849
|
}
|
|
3856
3850
|
const entries = [shell.cwd, ...shell.dirStack];
|
|
3857
3851
|
const home = shell.vars.get("HOME");
|
|
3858
|
-
const
|
|
3852
|
+
const render2 = (p) => home && p.startsWith(home) ? "~" + p.slice(home.length) : p;
|
|
3859
3853
|
if (argv.includes("-v")) {
|
|
3860
|
-
entries.forEach((entry, idx) => io.stdout.write(`${String(idx).padStart(2)} ${
|
|
3854
|
+
entries.forEach((entry, idx) => io.stdout.write(`${String(idx).padStart(2)} ${render2(entry)}
|
|
3861
3855
|
`));
|
|
3862
3856
|
return 0;
|
|
3863
3857
|
}
|
|
3864
|
-
io.stdout.write(entries.map(
|
|
3858
|
+
io.stdout.write(entries.map(render2).join(" ") + "\n");
|
|
3865
3859
|
return 0;
|
|
3866
3860
|
}
|
|
3867
3861
|
function builtinPushd({ shell, argv, io }) {
|
|
@@ -3921,9 +3915,9 @@ function builtinHistory({ shell, argv, io }) {
|
|
|
3921
3915
|
return 0;
|
|
3922
3916
|
}
|
|
3923
3917
|
const limit = Number(args.find((a) => /^\d+$/.test(a)) ?? shell.history.length);
|
|
3924
|
-
const
|
|
3925
|
-
shell.history.slice(
|
|
3926
|
-
io.stdout.write(`${String(
|
|
3918
|
+
const start2 = Math.max(0, shell.history.length - limit);
|
|
3919
|
+
shell.history.slice(start2).forEach((entry, idx) => {
|
|
3920
|
+
io.stdout.write(`${String(start2 + idx + 1).padStart(5)} ${entry}
|
|
3927
3921
|
`);
|
|
3928
3922
|
});
|
|
3929
3923
|
return 0;
|
|
@@ -4470,12 +4464,12 @@ var Vfs = class {
|
|
|
4470
4464
|
writeFile(abs, data, opts = {}) {
|
|
4471
4465
|
const cred = opts.privileged ? void 0 : opts.cred;
|
|
4472
4466
|
const real = this.resolvePath(abs, { cred });
|
|
4473
|
-
const
|
|
4467
|
+
const bytes2 = typeof data === "string" ? encoder.encode(data) : data;
|
|
4474
4468
|
const virt = this.lookupVirtual(real);
|
|
4475
4469
|
if (virt) {
|
|
4476
4470
|
if (!virt.write) throw new exports.SysError("EACCES", "write", real);
|
|
4477
4471
|
this.require(this.statFromVirtual(real, virt), W_OK, cred, "open", real);
|
|
4478
|
-
virt.write(
|
|
4472
|
+
virt.write(bytes2, opts.append ?? false);
|
|
4479
4473
|
return;
|
|
4480
4474
|
}
|
|
4481
4475
|
if (this.isUnderProvider(real)) throw new exports.SysError("ENOENT", "open", real);
|
|
@@ -4490,8 +4484,8 @@ var Vfs = class {
|
|
|
4490
4484
|
this.require(pst, W_OK | X_OK, cred, "open", real);
|
|
4491
4485
|
}
|
|
4492
4486
|
try {
|
|
4493
|
-
if (opts.append && existing) this.volume.appendFileSync(real,
|
|
4494
|
-
else this.volume.writeFileSync(real,
|
|
4487
|
+
if (opts.append && existing) this.volume.appendFileSync(real, bytes2);
|
|
4488
|
+
else this.volume.writeFileSync(real, bytes2);
|
|
4495
4489
|
} catch (e) {
|
|
4496
4490
|
throw toSysError(e, "open", real);
|
|
4497
4491
|
}
|
|
@@ -4692,8 +4686,8 @@ var Vfs = class {
|
|
|
4692
4686
|
/** Depth-first walk yielding absolute paths. Symlinks are not followed. */
|
|
4693
4687
|
*walk(abs, opts = {}) {
|
|
4694
4688
|
const { includeSelf = true, cred, maxDepth = Infinity } = opts;
|
|
4695
|
-
const
|
|
4696
|
-
if (includeSelf) yield
|
|
4689
|
+
const start2 = clean(abs);
|
|
4690
|
+
if (includeSelf) yield start2;
|
|
4697
4691
|
const recurse = (dir3, depth) => {
|
|
4698
4692
|
if (depth > maxDepth) return [];
|
|
4699
4693
|
let names;
|
|
@@ -4717,11 +4711,11 @@ var Vfs = class {
|
|
|
4717
4711
|
};
|
|
4718
4712
|
let st = null;
|
|
4719
4713
|
try {
|
|
4720
|
-
st = this.lstat(
|
|
4714
|
+
st = this.lstat(start2);
|
|
4721
4715
|
} catch {
|
|
4722
4716
|
return;
|
|
4723
4717
|
}
|
|
4724
|
-
if (st.isDirectory()) yield* recurse(
|
|
4718
|
+
if (st.isDirectory()) yield* recurse(start2, 1);
|
|
4725
4719
|
}
|
|
4726
4720
|
/** Recursive copy used by `cp -r` and the container's `copyIn` helper. */
|
|
4727
4721
|
copyTree(from, to, cred) {
|
|
@@ -4743,7 +4737,7 @@ var Vfs = class {
|
|
|
4743
4737
|
usage(abs = "/") {
|
|
4744
4738
|
let files = 0;
|
|
4745
4739
|
let dirs = 0;
|
|
4746
|
-
let
|
|
4740
|
+
let bytes2 = 0;
|
|
4747
4741
|
for (const p of this.walk(abs)) {
|
|
4748
4742
|
let st = null;
|
|
4749
4743
|
try {
|
|
@@ -4754,10 +4748,10 @@ var Vfs = class {
|
|
|
4754
4748
|
if (st.isDirectory()) dirs++;
|
|
4755
4749
|
else {
|
|
4756
4750
|
files++;
|
|
4757
|
-
|
|
4751
|
+
bytes2 += st.size;
|
|
4758
4752
|
}
|
|
4759
4753
|
}
|
|
4760
|
-
return { files, dirs, bytes };
|
|
4754
|
+
return { files, dirs, bytes: bytes2 };
|
|
4761
4755
|
}
|
|
4762
4756
|
};
|
|
4763
4757
|
|
|
@@ -4794,6 +4788,14 @@ var Pipe = class _Pipe {
|
|
|
4794
4788
|
isTTY = false;
|
|
4795
4789
|
/** Set on pipes owned by an outside caller, who may never call `end()`. */
|
|
4796
4790
|
interactive = false;
|
|
4791
|
+
/**
|
|
4792
|
+
* Set while the running program has put the terminal in raw mode.
|
|
4793
|
+
*
|
|
4794
|
+
* A program in raw mode draws its own input — a prompt library redraws the
|
|
4795
|
+
* whole line on every keystroke — so the terminal must stop echoing, or
|
|
4796
|
+
* every character appears twice.
|
|
4797
|
+
*/
|
|
4798
|
+
rawMode = false;
|
|
4797
4799
|
columns;
|
|
4798
4800
|
rows;
|
|
4799
4801
|
get closed() {
|
|
@@ -4808,10 +4810,10 @@ var Pipe = class _Pipe {
|
|
|
4808
4810
|
write(data) {
|
|
4809
4811
|
if (this.readerClosed) throw new exports.SysError("EPIPE", "write");
|
|
4810
4812
|
if (this.writerClosed) return;
|
|
4811
|
-
const
|
|
4812
|
-
if (
|
|
4813
|
-
this.chunks.push(
|
|
4814
|
-
this.buffered +=
|
|
4813
|
+
const bytes2 = toBytes(data);
|
|
4814
|
+
if (bytes2.length === 0) return;
|
|
4815
|
+
this.chunks.push(bytes2);
|
|
4816
|
+
this.buffered += bytes2.length;
|
|
4815
4817
|
this.wake();
|
|
4816
4818
|
}
|
|
4817
4819
|
end() {
|
|
@@ -4940,11 +4942,11 @@ var BufferSink = class {
|
|
|
4940
4942
|
}
|
|
4941
4943
|
write(data) {
|
|
4942
4944
|
if (this._closed) return;
|
|
4943
|
-
const
|
|
4944
|
-
if (
|
|
4945
|
-
this.chunks.push(
|
|
4946
|
-
this.total +=
|
|
4947
|
-
this.onWrite?.(
|
|
4945
|
+
const bytes2 = toBytes(data);
|
|
4946
|
+
if (bytes2.length === 0) return;
|
|
4947
|
+
this.chunks.push(bytes2);
|
|
4948
|
+
this.total += bytes2.length;
|
|
4949
|
+
this.onWrite?.(bytes2);
|
|
4948
4950
|
}
|
|
4949
4951
|
end() {
|
|
4950
4952
|
this._closed = true;
|
|
@@ -5249,8 +5251,8 @@ var ProcessTable = class {
|
|
|
5249
5251
|
this.map.clear();
|
|
5250
5252
|
}
|
|
5251
5253
|
};
|
|
5252
|
-
function resetPidCounter(
|
|
5253
|
-
nextPid =
|
|
5254
|
+
function resetPidCounter(start2 = 1) {
|
|
5255
|
+
nextPid = start2;
|
|
5254
5256
|
}
|
|
5255
5257
|
|
|
5256
5258
|
// src/kernel/users.ts
|
|
@@ -5573,9 +5575,9 @@ function parseSize(spec) {
|
|
|
5573
5575
|
const value = Number(m[1]);
|
|
5574
5576
|
const unit = (m[2] ?? "").toLowerCase();
|
|
5575
5577
|
const binary = m[3] !== "" || unit === "";
|
|
5576
|
-
const
|
|
5578
|
+
const base2 = binary ? 1024 : 1e3;
|
|
5577
5579
|
const exp = { "": 0, k: 1, m: 2, g: 3, t: 4, p: 5 }[unit] ?? 0;
|
|
5578
|
-
return Math.round(value * Math.pow(
|
|
5580
|
+
return Math.round(value * Math.pow(base2, exp));
|
|
5579
5581
|
}
|
|
5580
5582
|
|
|
5581
5583
|
// src/kernel/command.ts
|
|
@@ -6528,8 +6530,8 @@ function createProcProvider(kernel) {
|
|
|
6528
6530
|
loadavg: () => textFile(() => {
|
|
6529
6531
|
const running = kernel.procs.list().filter((p) => p.state === "R").length;
|
|
6530
6532
|
const total = kernel.procs.list().length;
|
|
6531
|
-
const
|
|
6532
|
-
return `${
|
|
6533
|
+
const load = (running / kernel.cpus).toFixed(2);
|
|
6534
|
+
return `${load} ${load} ${load} ${running}/${total} ${kernel.procs.list().length + 1}
|
|
6533
6535
|
`;
|
|
6534
6536
|
}),
|
|
6535
6537
|
meminfo: () => textFile(() => {
|
|
@@ -6887,22 +6889,22 @@ var NetworkStack = class {
|
|
|
6887
6889
|
`;
|
|
6888
6890
|
return out;
|
|
6889
6891
|
}
|
|
6890
|
-
countTx(
|
|
6892
|
+
countTx(bytes2, iface = "eth0") {
|
|
6891
6893
|
const i = this.interface(iface);
|
|
6892
6894
|
if (!i) return;
|
|
6893
|
-
i.txBytes +=
|
|
6894
|
-
i.txPackets += Math.max(1, Math.ceil(
|
|
6895
|
+
i.txBytes += bytes2;
|
|
6896
|
+
i.txPackets += Math.max(1, Math.ceil(bytes2 / 1400));
|
|
6895
6897
|
}
|
|
6896
|
-
countRx(
|
|
6898
|
+
countRx(bytes2, iface = "eth0") {
|
|
6897
6899
|
const i = this.interface(iface);
|
|
6898
6900
|
if (!i) return;
|
|
6899
|
-
i.rxBytes +=
|
|
6900
|
-
i.rxPackets += Math.max(1, Math.ceil(
|
|
6901
|
+
i.rxBytes += bytes2;
|
|
6902
|
+
i.rxPackets += Math.max(1, Math.ceil(bytes2 / 1400));
|
|
6901
6903
|
}
|
|
6902
6904
|
};
|
|
6903
6905
|
function randomMac() {
|
|
6904
|
-
const
|
|
6905
|
-
return
|
|
6906
|
+
const bytes2 = [2, 66, 172, 17, 0, 2];
|
|
6907
|
+
return bytes2.map((b) => b.toString(16).padStart(2, "0")).join(":");
|
|
6906
6908
|
}
|
|
6907
6909
|
function hexIp(ip2) {
|
|
6908
6910
|
return ip2.split(".").reverse().map((o) => Number(o).toString(16).padStart(2, "0").toUpperCase()).join("");
|
|
@@ -7029,7 +7031,7 @@ var Lexer = class _Lexer {
|
|
|
7029
7031
|
return null;
|
|
7030
7032
|
}
|
|
7031
7033
|
readWord() {
|
|
7032
|
-
const
|
|
7034
|
+
const start2 = this.pos;
|
|
7033
7035
|
let out = "";
|
|
7034
7036
|
while (this.pos < this.src.length) {
|
|
7035
7037
|
const ch = this.src[this.pos];
|
|
@@ -7079,10 +7081,10 @@ var Lexer = class _Lexer {
|
|
|
7079
7081
|
out = this.src[this.pos] ?? "";
|
|
7080
7082
|
this.pos++;
|
|
7081
7083
|
}
|
|
7082
|
-
this.push({ type: "word", value: out, pos:
|
|
7084
|
+
this.push({ type: "word", value: out, pos: start2 });
|
|
7083
7085
|
}
|
|
7084
7086
|
readDoubleQuoted() {
|
|
7085
|
-
const
|
|
7087
|
+
const start2 = this.pos;
|
|
7086
7088
|
this.pos++;
|
|
7087
7089
|
let out = '"';
|
|
7088
7090
|
while (this.pos < this.src.length) {
|
|
@@ -7113,14 +7115,14 @@ var Lexer = class _Lexer {
|
|
|
7113
7115
|
out += ch;
|
|
7114
7116
|
this.pos++;
|
|
7115
7117
|
}
|
|
7116
|
-
throw new IncompleteInputError("unexpected EOF while looking for matching `\"'",
|
|
7118
|
+
throw new IncompleteInputError("unexpected EOF while looking for matching `\"'", start2);
|
|
7117
7119
|
}
|
|
7118
7120
|
/**
|
|
7119
7121
|
* Consume a balanced `$( ... )` or `${ ... }`, honouring nesting and quotes
|
|
7120
7122
|
* inside. `prefix` is emitted before the opening delimiter.
|
|
7121
7123
|
*/
|
|
7122
7124
|
readBalanced(open, close, openIdx, prefix) {
|
|
7123
|
-
const
|
|
7125
|
+
const start2 = this.pos;
|
|
7124
7126
|
let depth = 0;
|
|
7125
7127
|
let i = openIdx;
|
|
7126
7128
|
for (; i < this.src.length; i++) {
|
|
@@ -7131,7 +7133,7 @@ var Lexer = class _Lexer {
|
|
|
7131
7133
|
}
|
|
7132
7134
|
if (c === "'" && open === "(") {
|
|
7133
7135
|
const end = this.src.indexOf("'", i + 1);
|
|
7134
|
-
if (end < 0) throw new IncompleteInputError("unexpected EOF in command substitution",
|
|
7136
|
+
if (end < 0) throw new IncompleteInputError("unexpected EOF in command substitution", start2);
|
|
7135
7137
|
i = end;
|
|
7136
7138
|
continue;
|
|
7137
7139
|
}
|
|
@@ -7149,7 +7151,7 @@ var Lexer = class _Lexer {
|
|
|
7149
7151
|
if (depth === 0) break;
|
|
7150
7152
|
}
|
|
7151
7153
|
}
|
|
7152
|
-
if (i >= this.src.length) throw new IncompleteInputError(`unexpected EOF while looking for matching \`${close}'`,
|
|
7154
|
+
if (i >= this.src.length) throw new IncompleteInputError(`unexpected EOF while looking for matching \`${close}'`, start2);
|
|
7153
7155
|
const text2 = prefix + this.src.slice(openIdx, i + 1);
|
|
7154
7156
|
this.pos = i + 1;
|
|
7155
7157
|
return text2;
|
|
@@ -7191,7 +7193,7 @@ var Lexer = class _Lexer {
|
|
|
7191
7193
|
const stripTabs = opToken.value === "<<-";
|
|
7192
7194
|
const rawTag = tagToken.value;
|
|
7193
7195
|
const quoted = /['"\\]/.test(rawTag);
|
|
7194
|
-
const
|
|
7196
|
+
const tag2 = rawTag.replace(/['"\\]/g, "");
|
|
7195
7197
|
const lines = [];
|
|
7196
7198
|
let found = false;
|
|
7197
7199
|
while (this.pos < this.src.length) {
|
|
@@ -7200,7 +7202,7 @@ var Lexer = class _Lexer {
|
|
|
7200
7202
|
const rawLine = this.src.slice(this.pos, eol);
|
|
7201
7203
|
this.pos = eol + 1;
|
|
7202
7204
|
const compare = stripTabs ? rawLine.replace(/^\t+/, "") : rawLine;
|
|
7203
|
-
if (compare ===
|
|
7205
|
+
if (compare === tag2) {
|
|
7204
7206
|
found = true;
|
|
7205
7207
|
break;
|
|
7206
7208
|
}
|
|
@@ -7208,9 +7210,9 @@ var Lexer = class _Lexer {
|
|
|
7208
7210
|
if (eol >= this.src.length) break;
|
|
7209
7211
|
}
|
|
7210
7212
|
if (!found) {
|
|
7211
|
-
throw new IncompleteInputError(`here-document delimited by end-of-file (wanted \`${
|
|
7213
|
+
throw new IncompleteInputError(`here-document delimited by end-of-file (wanted \`${tag2}')`, opToken.pos);
|
|
7212
7214
|
}
|
|
7213
|
-
opToken.heredoc = { tag, stripTabs, quoted, body: lines.length ? lines.join("\n") + "\n" : "" };
|
|
7215
|
+
opToken.heredoc = { tag: tag2, stripTabs, quoted, body: lines.length ? lines.join("\n") + "\n" : "" };
|
|
7214
7216
|
}
|
|
7215
7217
|
}
|
|
7216
7218
|
};
|
|
@@ -8777,16 +8779,16 @@ sys ${fmt2(Math.floor(ms * 0.2))}
|
|
|
8777
8779
|
function splitAliasWords(text2) {
|
|
8778
8780
|
const out = [];
|
|
8779
8781
|
let current = "";
|
|
8780
|
-
let
|
|
8782
|
+
let quote3 = null;
|
|
8781
8783
|
for (let i = 0; i < text2.length; i++) {
|
|
8782
8784
|
const c = text2[i];
|
|
8783
|
-
if (
|
|
8784
|
-
if (c ===
|
|
8785
|
+
if (quote3) {
|
|
8786
|
+
if (c === quote3) quote3 = null;
|
|
8785
8787
|
else current += c;
|
|
8786
8788
|
continue;
|
|
8787
8789
|
}
|
|
8788
8790
|
if (c === "'" || c === '"') {
|
|
8789
|
-
|
|
8791
|
+
quote3 = c;
|
|
8790
8792
|
continue;
|
|
8791
8793
|
}
|
|
8792
8794
|
if (c === " " || c === " ") {
|
|
@@ -8940,11 +8942,11 @@ var decoder3 = new TextDecoder();
|
|
|
8940
8942
|
async function readInputs(ctx, operands, opts = {}) {
|
|
8941
8943
|
const stdinName = opts.stdinName ?? "-";
|
|
8942
8944
|
if (operands.length === 0) {
|
|
8943
|
-
const
|
|
8944
|
-
return { sources: [{ name: stdinName, bytes }], ok: true };
|
|
8945
|
+
const bytes2 = await ctx.stdin.readAll();
|
|
8946
|
+
return { sources: [{ name: stdinName, bytes: bytes2 }], ok: true };
|
|
8945
8947
|
}
|
|
8946
8948
|
const sources = [];
|
|
8947
|
-
let
|
|
8949
|
+
let ok2 = true;
|
|
8948
8950
|
for (const operand of operands) {
|
|
8949
8951
|
if (operand === "-") {
|
|
8950
8952
|
sources.push({ name: stdinName, bytes: await ctx.stdin.readAll() });
|
|
@@ -8955,19 +8957,19 @@ async function readInputs(ctx, operands, opts = {}) {
|
|
|
8955
8957
|
const st = ctx.vfs.stat(abs, { cred: ctx.cred });
|
|
8956
8958
|
if (st.isDirectory()) {
|
|
8957
8959
|
ctx.warn(`${operand}: Is a directory`);
|
|
8958
|
-
|
|
8960
|
+
ok2 = false;
|
|
8959
8961
|
continue;
|
|
8960
8962
|
}
|
|
8961
8963
|
sources.push({ name: operand, bytes: ctx.vfs.readFile(abs, ctx.cred) });
|
|
8962
8964
|
} catch (e) {
|
|
8963
8965
|
ctx.reportError(e, operand);
|
|
8964
|
-
|
|
8966
|
+
ok2 = false;
|
|
8965
8967
|
}
|
|
8966
8968
|
}
|
|
8967
|
-
return { sources, ok };
|
|
8969
|
+
return { sources, ok: ok2 };
|
|
8968
8970
|
}
|
|
8969
|
-
function splitLines(
|
|
8970
|
-
const text2 = decoder3.decode(
|
|
8971
|
+
function splitLines(bytes2) {
|
|
8972
|
+
const text2 = decoder3.decode(bytes2);
|
|
8971
8973
|
if (text2 === "") return { lines: [], trailingNewline: true };
|
|
8972
8974
|
const trailingNewline = text2.endsWith("\n");
|
|
8973
8975
|
const body = trailingNewline ? text2.slice(0, -1) : text2;
|
|
@@ -8979,14 +8981,14 @@ function joinLines(lines, trailingNewline = true) {
|
|
|
8979
8981
|
}
|
|
8980
8982
|
var SI_UNITS = ["", "k", "M", "G", "T", "P", "E"];
|
|
8981
8983
|
var IEC_UNITS = ["", "K", "M", "G", "T", "P", "E"];
|
|
8982
|
-
function humanSize(
|
|
8983
|
-
const
|
|
8984
|
+
function humanSize(bytes2, opts = {}) {
|
|
8985
|
+
const base2 = opts.si ? 1e3 : 1024;
|
|
8984
8986
|
const units = opts.si ? SI_UNITS : IEC_UNITS;
|
|
8985
|
-
if (
|
|
8986
|
-
let value =
|
|
8987
|
+
if (bytes2 < base2) return String(bytes2);
|
|
8988
|
+
let value = bytes2;
|
|
8987
8989
|
let unit = 0;
|
|
8988
|
-
while (value >=
|
|
8989
|
-
value /=
|
|
8990
|
+
while (value >= base2 && unit < units.length - 1) {
|
|
8991
|
+
value /= base2;
|
|
8990
8992
|
unit++;
|
|
8991
8993
|
}
|
|
8992
8994
|
const rounded = value < 10 ? Math.ceil(value * 10) / 10 : Math.ceil(value);
|
|
@@ -9273,7 +9275,7 @@ var cat = defineCommand({
|
|
|
9273
9275
|
let lineNumber = 1;
|
|
9274
9276
|
let lastWasBlank = false;
|
|
9275
9277
|
for (const operand of operands) {
|
|
9276
|
-
let
|
|
9278
|
+
let bytes2;
|
|
9277
9279
|
if (operand === "-") {
|
|
9278
9280
|
if (plain) {
|
|
9279
9281
|
for (; ; ) {
|
|
@@ -9284,7 +9286,7 @@ var cat = defineCommand({
|
|
|
9284
9286
|
}
|
|
9285
9287
|
continue;
|
|
9286
9288
|
}
|
|
9287
|
-
|
|
9289
|
+
bytes2 = await ctx.stdin.readAll();
|
|
9288
9290
|
} else {
|
|
9289
9291
|
try {
|
|
9290
9292
|
const abs = ctx.path(operand);
|
|
@@ -9294,17 +9296,17 @@ var cat = defineCommand({
|
|
|
9294
9296
|
status = 1;
|
|
9295
9297
|
continue;
|
|
9296
9298
|
}
|
|
9297
|
-
|
|
9299
|
+
bytes2 = ctx.vfs.readFile(abs, ctx.cred);
|
|
9298
9300
|
} catch (e) {
|
|
9299
9301
|
status = ctx.reportError(e, operand);
|
|
9300
9302
|
continue;
|
|
9301
9303
|
}
|
|
9302
9304
|
}
|
|
9303
9305
|
if (plain) {
|
|
9304
|
-
ctx.write(
|
|
9306
|
+
ctx.write(bytes2);
|
|
9305
9307
|
continue;
|
|
9306
9308
|
}
|
|
9307
|
-
const text2 = new TextDecoder().decode(
|
|
9309
|
+
const text2 = new TextDecoder().decode(bytes2);
|
|
9308
9310
|
const hadTrailing = text2.endsWith("\n");
|
|
9309
9311
|
const parts = (hadTrailing ? text2.slice(0, -1) : text2).split("\n");
|
|
9310
9312
|
for (const raw of parts) {
|
|
@@ -9894,9 +9896,9 @@ var stat = defineCommand({
|
|
|
9894
9896
|
try {
|
|
9895
9897
|
const abs = ctx.path(operand);
|
|
9896
9898
|
const st = args.has("dereference") ? ctx.vfs.stat(abs, { cred: ctx.cred }) : ctx.vfs.lstat(abs);
|
|
9897
|
-
const
|
|
9898
|
-
if (
|
|
9899
|
-
ctx.write(expandStatFormat(
|
|
9899
|
+
const format3 = args.str("format") ?? args.str("printf");
|
|
9900
|
+
if (format3) {
|
|
9901
|
+
ctx.write(expandStatFormat(format3, abs, st, ctx) + (args.str("printf") ? "" : "\n"));
|
|
9900
9902
|
continue;
|
|
9901
9903
|
}
|
|
9902
9904
|
if (args.has("terse")) {
|
|
@@ -9928,8 +9930,8 @@ var stat = defineCommand({
|
|
|
9928
9930
|
function isoTime(ms) {
|
|
9929
9931
|
return new Date(ms).toISOString().replace("T", " ").replace("Z", " +0000");
|
|
9930
9932
|
}
|
|
9931
|
-
function expandStatFormat(
|
|
9932
|
-
return
|
|
9933
|
+
function expandStatFormat(format3, path, st, ctx) {
|
|
9934
|
+
return format3.replace(/%(.)/g, (_, ch) => {
|
|
9933
9935
|
switch (ch) {
|
|
9934
9936
|
case "n":
|
|
9935
9937
|
return path;
|
|
@@ -9988,7 +9990,7 @@ var du = defineCommand({
|
|
|
9988
9990
|
const operands = args.positional.length ? args.positional : ["."];
|
|
9989
9991
|
const maxDepth = args.num("max-depth", args.has("summarize") ? 0 : Infinity);
|
|
9990
9992
|
const asBytes = args.has("bytes");
|
|
9991
|
-
const
|
|
9993
|
+
const render2 = (value) => args.has("human-readable") ? humanSize(value) : String(asBytes ? value : Math.max(1, Math.ceil(value / 1024)));
|
|
9992
9994
|
let total = 0;
|
|
9993
9995
|
let status = 0;
|
|
9994
9996
|
const walk = (abs, depth) => {
|
|
@@ -10000,20 +10002,20 @@ var du = defineCommand({
|
|
|
10000
10002
|
return 0;
|
|
10001
10003
|
}
|
|
10002
10004
|
if (!st.isDirectory()) {
|
|
10003
|
-
if (args.has("all") && depth <= maxDepth) ctx.line(`${
|
|
10005
|
+
if (args.has("all") && depth <= maxDepth) ctx.line(`${render2(st.size)} ${abs}`);
|
|
10004
10006
|
return st.size;
|
|
10005
10007
|
}
|
|
10006
10008
|
let sum = 4096;
|
|
10007
10009
|
for (const name of safeReaddir(ctx, abs)) {
|
|
10008
10010
|
sum += walk(join(abs, name), depth + 1);
|
|
10009
10011
|
}
|
|
10010
|
-
if (depth <= maxDepth) ctx.line(`${
|
|
10012
|
+
if (depth <= maxDepth) ctx.line(`${render2(sum)} ${abs}`);
|
|
10011
10013
|
return sum;
|
|
10012
10014
|
};
|
|
10013
10015
|
for (const operand of operands) {
|
|
10014
10016
|
total += walk(ctx.path(operand), 0);
|
|
10015
10017
|
}
|
|
10016
|
-
if (args.has("total")) ctx.line(`${
|
|
10018
|
+
if (args.has("total")) ctx.line(`${render2(total)} total`);
|
|
10017
10019
|
return status;
|
|
10018
10020
|
}
|
|
10019
10021
|
});
|
|
@@ -10048,8 +10050,8 @@ var df = defineCommand({
|
|
|
10048
10050
|
ctx.warn(`${operand}: No such file or directory`);
|
|
10049
10051
|
continue;
|
|
10050
10052
|
}
|
|
10051
|
-
const
|
|
10052
|
-
if (
|
|
10053
|
+
const match2 = mounts.filter((m) => contains(m.mountpoint, abs)).sort((a, b) => b.mountpoint.length - a.mountpoint.length)[0];
|
|
10054
|
+
if (match2) selected.set(match2.mountpoint, match2);
|
|
10053
10055
|
}
|
|
10054
10056
|
mounts = [...selected.values()];
|
|
10055
10057
|
}
|
|
@@ -10158,15 +10160,15 @@ function describeFile(ctx, abs, st, mime) {
|
|
|
10158
10160
|
}
|
|
10159
10161
|
if (st.isCharacterDevice()) return mime ? "inode/chardevice" : "character special";
|
|
10160
10162
|
if (st.size === 0) return mime ? "inode/x-empty" : "empty";
|
|
10161
|
-
const
|
|
10162
|
-
const magic = [...
|
|
10163
|
+
const bytes2 = ctx.vfs.readFile(abs, ctx.cred).subarray(0, 512);
|
|
10164
|
+
const magic = [...bytes2.subarray(0, 4)];
|
|
10163
10165
|
if (magic[0] === 127 && magic[1] === 69 && magic[2] === 76 && magic[3] === 70) {
|
|
10164
10166
|
return mime ? "application/x-executable" : "ELF 64-bit LSB executable, x86-64";
|
|
10165
10167
|
}
|
|
10166
10168
|
if (magic[0] === 31 && magic[1] === 139) return mime ? "application/gzip" : "gzip compressed data";
|
|
10167
10169
|
if (magic[0] === 80 && magic[1] === 75) return mime ? "application/zip" : "Zip archive data";
|
|
10168
10170
|
if (magic[0] === 137 && magic[1] === 80) return mime ? "image/png" : "PNG image data";
|
|
10169
|
-
const text2 = new TextDecoder().decode(
|
|
10171
|
+
const text2 = new TextDecoder().decode(bytes2);
|
|
10170
10172
|
const printable = [...text2].every((c) => c === "\n" || c === " " || c === "\r" || c >= " " && c <= "~" || c.charCodeAt(0) > 127);
|
|
10171
10173
|
if (!printable) return mime ? "application/octet-stream" : "data";
|
|
10172
10174
|
if (text2.startsWith("#!")) {
|
|
@@ -10239,10 +10241,10 @@ var printfCmd = defineCommand({
|
|
|
10239
10241
|
summary: "format and print data",
|
|
10240
10242
|
usage: "printf FORMAT [ARGUMENT]...",
|
|
10241
10243
|
run(ctx) {
|
|
10242
|
-
const
|
|
10243
|
-
if (
|
|
10244
|
+
const format3 = ctx.args[0];
|
|
10245
|
+
if (format3 === void 0) return ctx.fail("usage: printf FORMAT [ARGUMENT]...", 2);
|
|
10244
10246
|
try {
|
|
10245
|
-
ctx.write(formatPrintf(
|
|
10247
|
+
ctx.write(formatPrintf(format3, ctx.args.slice(1)));
|
|
10246
10248
|
return 0;
|
|
10247
10249
|
} catch (e) {
|
|
10248
10250
|
return ctx.fail(e instanceof Error ? e.message : String(e));
|
|
@@ -10338,13 +10340,13 @@ var seq = defineCommand({
|
|
|
10338
10340
|
}
|
|
10339
10341
|
if (increment === 0) return ctx.fail("zero increment", 1);
|
|
10340
10342
|
const separator = args.str("separator", "\n");
|
|
10341
|
-
const
|
|
10343
|
+
const format3 = args.str("format");
|
|
10342
10344
|
const values = [];
|
|
10343
10345
|
if (increment > 0) for (let v = first; v <= last + 1e-9; v += increment) values.push(v);
|
|
10344
10346
|
else for (let v = first; v >= last - 1e-9; v += increment) values.push(v);
|
|
10345
10347
|
const rendered = values.map((v) => {
|
|
10346
10348
|
const text2 = Number.isInteger(v) ? String(v) : String(Number(v.toFixed(10)));
|
|
10347
|
-
return
|
|
10349
|
+
return format3 ? formatPrintf(format3, [String(v)]) : text2;
|
|
10348
10350
|
});
|
|
10349
10351
|
const width = args.has("equal-width") ? Math.max(0, ...rendered.map((r) => r.length)) : 0;
|
|
10350
10352
|
const out = rendered.map((r) => width ? r.padStart(width, "0") : r);
|
|
@@ -10662,9 +10664,9 @@ var date = defineCommand({
|
|
|
10662
10664
|
return 0;
|
|
10663
10665
|
}
|
|
10664
10666
|
});
|
|
10665
|
-
function strftime(
|
|
10667
|
+
function strftime(format3, d) {
|
|
10666
10668
|
const pad2 = (n, w = 2, c = "0") => String(n).padStart(w, c);
|
|
10667
|
-
return
|
|
10669
|
+
return format3.replace(/%([-_0^#]?)(\d*)([a-zA-Z%])/g, (_, flag, width, ch) => {
|
|
10668
10670
|
const value = (() => {
|
|
10669
10671
|
switch (ch) {
|
|
10670
10672
|
case "Y":
|
|
@@ -10882,13 +10884,13 @@ var killall = defineCommand({
|
|
|
10882
10884
|
const signal = signalArg ? normalizeSignal(signalArg.slice(1)) ?? "SIGTERM" : "SIGTERM";
|
|
10883
10885
|
let status = 0;
|
|
10884
10886
|
for (const name of args) {
|
|
10885
|
-
const
|
|
10886
|
-
if (
|
|
10887
|
+
const matches3 = ctx.kernel.procs.list({ comm: name });
|
|
10888
|
+
if (matches3.length === 0) {
|
|
10887
10889
|
ctx.warn(`${name}: no process found`);
|
|
10888
10890
|
status = 1;
|
|
10889
10891
|
continue;
|
|
10890
10892
|
}
|
|
10891
|
-
for (const proc of
|
|
10893
|
+
for (const proc of matches3) proc.deliver(signal);
|
|
10892
10894
|
}
|
|
10893
10895
|
return status;
|
|
10894
10896
|
}
|
|
@@ -10902,13 +10904,13 @@ var pgrep = defineCommand({
|
|
|
10902
10904
|
const pattern = args.positional[0];
|
|
10903
10905
|
if (pattern === void 0) return ctx.fail("no matching criteria specified", 2);
|
|
10904
10906
|
const re = new RegExp(pattern);
|
|
10905
|
-
const
|
|
10906
|
-
for (const proc of
|
|
10907
|
+
const matches3 = ctx.kernel.procs.list().filter((p) => re.test(args.has("f") ? p.cmdline : p.comm));
|
|
10908
|
+
for (const proc of matches3) {
|
|
10907
10909
|
if (args.has("a")) ctx.line(`${proc.pid} ${proc.cmdline}`);
|
|
10908
10910
|
else if (args.has("l")) ctx.line(`${proc.pid} ${proc.comm}`);
|
|
10909
10911
|
else ctx.line(String(proc.pid));
|
|
10910
10912
|
}
|
|
10911
|
-
return
|
|
10913
|
+
return matches3.length ? 0 : 1;
|
|
10912
10914
|
}
|
|
10913
10915
|
});
|
|
10914
10916
|
var top = defineCommand({
|
|
@@ -11194,9 +11196,9 @@ var ScriptParser = class {
|
|
|
11194
11196
|
}
|
|
11195
11197
|
parseRange() {
|
|
11196
11198
|
this.skipBlanks();
|
|
11197
|
-
const
|
|
11198
|
-
if (!
|
|
11199
|
-
let range = { start, negated: false };
|
|
11199
|
+
const start2 = this.parseAddress();
|
|
11200
|
+
if (!start2) return { negated: this.parseNegation() };
|
|
11201
|
+
let range = { start: start2, negated: false };
|
|
11200
11202
|
if (this.src[this.i] === ",") {
|
|
11201
11203
|
this.i++;
|
|
11202
11204
|
this.skipBlanks();
|
|
@@ -11405,8 +11407,8 @@ function toJsRegex(pattern, extended) {
|
|
|
11405
11407
|
}
|
|
11406
11408
|
return out;
|
|
11407
11409
|
}
|
|
11408
|
-
function findBracketEnd(pattern,
|
|
11409
|
-
let i =
|
|
11410
|
+
function findBracketEnd(pattern, start2) {
|
|
11411
|
+
let i = start2 + 1;
|
|
11410
11412
|
if (pattern[i] === "^") i++;
|
|
11411
11413
|
if (pattern[i] === "]") i++;
|
|
11412
11414
|
while (i < pattern.length) {
|
|
@@ -11440,7 +11442,7 @@ var BRACKET_CLASSES = {
|
|
|
11440
11442
|
function translateBracket(text2) {
|
|
11441
11443
|
return text2.replace(/\[:([a-z]+):\]/g, (_, name) => BRACKET_CLASSES[name] ?? "");
|
|
11442
11444
|
}
|
|
11443
|
-
function applyReplacement(replacement,
|
|
11445
|
+
function applyReplacement(replacement, match2) {
|
|
11444
11446
|
let out = "";
|
|
11445
11447
|
let caseMode = null;
|
|
11446
11448
|
let oneShot = null;
|
|
@@ -11457,7 +11459,7 @@ function applyReplacement(replacement, match) {
|
|
|
11457
11459
|
for (let i = 0; i < replacement.length; i++) {
|
|
11458
11460
|
const c = replacement[i];
|
|
11459
11461
|
if (c === "&") {
|
|
11460
|
-
emit(
|
|
11462
|
+
emit(match2[0]);
|
|
11461
11463
|
continue;
|
|
11462
11464
|
}
|
|
11463
11465
|
if (c !== "\\") {
|
|
@@ -11467,7 +11469,7 @@ function applyReplacement(replacement, match) {
|
|
|
11467
11469
|
const next = replacement[++i];
|
|
11468
11470
|
if (next === void 0) break;
|
|
11469
11471
|
if (/\d/.test(next)) {
|
|
11470
|
-
emit(
|
|
11472
|
+
emit(match2[Number(next)] ?? "");
|
|
11471
11473
|
continue;
|
|
11472
11474
|
}
|
|
11473
11475
|
switch (next) {
|
|
@@ -11545,8 +11547,8 @@ async function runSed(ctx) {
|
|
|
11545
11547
|
const inPlace = args.present("in-place");
|
|
11546
11548
|
const suffix = args.str("in-place") ?? "";
|
|
11547
11549
|
const suppress = args.has("quiet") || args.has("silent");
|
|
11548
|
-
const { sources, ok } = await readInputs(ctx, operands);
|
|
11549
|
-
let status =
|
|
11550
|
+
const { sources, ok: ok2 } = await readInputs(ctx, operands);
|
|
11551
|
+
let status = ok2 ? 0 : 1;
|
|
11550
11552
|
for (const source of sources) {
|
|
11551
11553
|
const { lines, trailingNewline } = splitLines(source.bytes);
|
|
11552
11554
|
const state = {
|
|
@@ -11759,17 +11761,17 @@ function substitute2(input, regex, replacement, global, occurrence) {
|
|
|
11759
11761
|
let last = 0;
|
|
11760
11762
|
let count = 0;
|
|
11761
11763
|
let changed = false;
|
|
11762
|
-
let
|
|
11763
|
-
while ((
|
|
11764
|
+
let match2;
|
|
11765
|
+
while ((match2 = re.exec(input)) !== null) {
|
|
11764
11766
|
count++;
|
|
11765
11767
|
const wanted = occurrence > 0 ? count >= occurrence && (global || count === occurrence) : true;
|
|
11766
11768
|
if (wanted) {
|
|
11767
|
-
out += input.slice(last,
|
|
11768
|
-
last =
|
|
11769
|
+
out += input.slice(last, match2.index) + applyReplacement(replacement, match2);
|
|
11770
|
+
last = match2.index + match2[0].length;
|
|
11769
11771
|
changed = true;
|
|
11770
11772
|
if (!global) break;
|
|
11771
11773
|
}
|
|
11772
|
-
if (
|
|
11774
|
+
if (match2[0] === "") re.lastIndex++;
|
|
11773
11775
|
}
|
|
11774
11776
|
out += input.slice(last);
|
|
11775
11777
|
return { text: out, changed };
|
|
@@ -12424,12 +12426,12 @@ var AwkParser = class {
|
|
|
12424
12426
|
return this.parsePower(noGt);
|
|
12425
12427
|
}
|
|
12426
12428
|
parsePower(noGt) {
|
|
12427
|
-
const
|
|
12429
|
+
const base2 = this.parsePostfix(noGt);
|
|
12428
12430
|
if (this.isOp("^") || this.isOp("**")) {
|
|
12429
12431
|
this.i++;
|
|
12430
|
-
return { t: "binary", op: "^", left:
|
|
12432
|
+
return { t: "binary", op: "^", left: base2, right: this.parseUnary(noGt) };
|
|
12431
12433
|
}
|
|
12432
|
-
return
|
|
12434
|
+
return base2;
|
|
12433
12435
|
}
|
|
12434
12436
|
parsePostfix(noGt) {
|
|
12435
12437
|
if (this.isOp("++") || this.isOp("--")) {
|
|
@@ -12723,11 +12725,11 @@ var Interpreter = class {
|
|
|
12723
12725
|
toStrRaw(v) {
|
|
12724
12726
|
return v === void 0 ? "%.6g" : v.isNum ? String(v.num) : v.str;
|
|
12725
12727
|
}
|
|
12726
|
-
numToStr(n,
|
|
12728
|
+
numToStr(n, format3) {
|
|
12727
12729
|
if (Number.isInteger(n) && Math.abs(n) < 1e16) return String(n);
|
|
12728
12730
|
if (!Number.isFinite(n)) return n > 0 ? "inf" : Number.isNaN(n) ? "nan" : "-inf";
|
|
12729
12731
|
try {
|
|
12730
|
-
return formatPrintf(
|
|
12732
|
+
return formatPrintf(format3, [String(n)]);
|
|
12731
12733
|
} catch {
|
|
12732
12734
|
return String(n);
|
|
12733
12735
|
}
|
|
@@ -12997,14 +12999,14 @@ var Interpreter = class {
|
|
|
12997
12999
|
}
|
|
12998
13000
|
case "substr": {
|
|
12999
13001
|
const source = [...str(0)];
|
|
13000
|
-
let
|
|
13002
|
+
let start2 = Math.round(num(1));
|
|
13001
13003
|
let length = args.length > 2 ? Math.round(num(2)) : Infinity;
|
|
13002
|
-
if (
|
|
13003
|
-
if (Number.isFinite(length)) length +=
|
|
13004
|
-
|
|
13004
|
+
if (start2 < 1) {
|
|
13005
|
+
if (Number.isFinite(length)) length += start2 - 1;
|
|
13006
|
+
start2 = 1;
|
|
13005
13007
|
}
|
|
13006
13008
|
if (length <= 0) return Value.fromString("");
|
|
13007
|
-
return Value.fromString(source.slice(
|
|
13009
|
+
return Value.fromString(source.slice(start2 - 1, Number.isFinite(length) ? start2 - 1 + length : void 0).join(""));
|
|
13008
13010
|
}
|
|
13009
13011
|
case "index": {
|
|
13010
13012
|
const haystack = [...str(0)];
|
|
@@ -13033,9 +13035,9 @@ var Interpreter = class {
|
|
|
13033
13035
|
let count = 0;
|
|
13034
13036
|
const result = subject.replace(re, (...groups) => {
|
|
13035
13037
|
count++;
|
|
13036
|
-
const
|
|
13038
|
+
const match2 = groups[0];
|
|
13037
13039
|
return replacement.replace(/\\?&|\\\\/g, (token) => {
|
|
13038
|
-
if (token === "&") return
|
|
13040
|
+
if (token === "&") return match2;
|
|
13039
13041
|
if (token === "\\&") return "&";
|
|
13040
13042
|
return "\\";
|
|
13041
13043
|
});
|
|
@@ -13057,9 +13059,9 @@ var Interpreter = class {
|
|
|
13057
13059
|
return Value.fromNumber(m.index + 1);
|
|
13058
13060
|
}
|
|
13059
13061
|
case "sprintf": {
|
|
13060
|
-
const
|
|
13062
|
+
const format3 = str(0);
|
|
13061
13063
|
const rest = args.slice(1).map((a) => this.outputStr(this.evaluate(a)));
|
|
13062
|
-
return Value.fromString(formatPrintf(
|
|
13064
|
+
return Value.fromString(formatPrintf(format3, rest));
|
|
13063
13065
|
}
|
|
13064
13066
|
case "sin":
|
|
13065
13067
|
return Value.fromNumber(Math.sin(num(0)));
|
|
@@ -13206,12 +13208,12 @@ var Interpreter = class {
|
|
|
13206
13208
|
}
|
|
13207
13209
|
case "printf": {
|
|
13208
13210
|
if (stmt.args.length === 0) throw new AwkError("printf: no format supplied");
|
|
13209
|
-
const
|
|
13211
|
+
const format3 = this.toStr(this.evaluate(stmt.args[0]));
|
|
13210
13212
|
const rest = stmt.args.slice(1).map((a) => {
|
|
13211
13213
|
const v = this.evaluate(a);
|
|
13212
13214
|
return v.isNum ? String(v.num) : v.str;
|
|
13213
13215
|
});
|
|
13214
|
-
this.emit(formatPrintf(
|
|
13216
|
+
this.emit(formatPrintf(format3, rest), stmt.redirect);
|
|
13215
13217
|
return;
|
|
13216
13218
|
}
|
|
13217
13219
|
case "if":
|
|
@@ -13422,8 +13424,8 @@ function translateEre(pattern) {
|
|
|
13422
13424
|
}
|
|
13423
13425
|
return out;
|
|
13424
13426
|
}
|
|
13425
|
-
function findClassEnd(pattern,
|
|
13426
|
-
let i =
|
|
13427
|
+
function findClassEnd(pattern, start2) {
|
|
13428
|
+
let i = start2 + 1;
|
|
13427
13429
|
if (pattern[i] === "^") i++;
|
|
13428
13430
|
if (pattern[i] === "]") i++;
|
|
13429
13431
|
while (i < pattern.length) {
|
|
@@ -13511,8 +13513,8 @@ async function runAwk(ctx) {
|
|
|
13511
13513
|
continue;
|
|
13512
13514
|
}
|
|
13513
13515
|
try {
|
|
13514
|
-
const
|
|
13515
|
-
inputs.push({ name: operand, lines: splitLines(
|
|
13516
|
+
const bytes2 = ctx.vfs.readFile(ctx.path(operand), ctx.cred);
|
|
13517
|
+
inputs.push({ name: operand, lines: splitLines(bytes2).lines });
|
|
13516
13518
|
} catch (e) {
|
|
13517
13519
|
ctx.reportError(e, operand);
|
|
13518
13520
|
return 2;
|
|
@@ -13567,7 +13569,7 @@ var head = defineCommand({
|
|
|
13567
13569
|
],
|
|
13568
13570
|
{ numericShortcut: "lines" }
|
|
13569
13571
|
);
|
|
13570
|
-
const { sources, ok } = await readInputs(ctx, args.positional, { stdinName: "standard input" });
|
|
13572
|
+
const { sources, ok: ok2 } = await readInputs(ctx, args.positional, { stdinName: "standard input" });
|
|
13571
13573
|
const showHeaders = (sources.length > 1 || args.has("verbose")) && !args.has("quiet");
|
|
13572
13574
|
sources.forEach((source, index) => {
|
|
13573
13575
|
if (showHeaders) {
|
|
@@ -13585,7 +13587,7 @@ var head = defineCommand({
|
|
|
13585
13587
|
const kept = count.fromEnd ? lines.slice(0, Math.max(0, lines.length - count.value)) : lines.slice(0, count.value);
|
|
13586
13588
|
ctx.write(joinLines(kept, trailingNewline || kept.length < lines.length));
|
|
13587
13589
|
});
|
|
13588
|
-
return
|
|
13590
|
+
return ok2 ? 0 : 1;
|
|
13589
13591
|
}
|
|
13590
13592
|
});
|
|
13591
13593
|
function parseCount(spec) {
|
|
@@ -13614,7 +13616,7 @@ var tail = defineCommand({
|
|
|
13614
13616
|
],
|
|
13615
13617
|
{ numericShortcut: "lines" }
|
|
13616
13618
|
);
|
|
13617
|
-
const { sources, ok } = await readInputs(ctx, args.positional, { stdinName: "standard input" });
|
|
13619
|
+
const { sources, ok: ok2 } = await readInputs(ctx, args.positional, { stdinName: "standard input" });
|
|
13618
13620
|
const showHeaders = (sources.length > 1 || args.has("verbose")) && !args.has("quiet");
|
|
13619
13621
|
sources.forEach((source, index) => {
|
|
13620
13622
|
if (showHeaders) {
|
|
@@ -13638,7 +13640,7 @@ var tail = defineCommand({
|
|
|
13638
13640
|
if (args.has("follow") && args.positional.length > 0) {
|
|
13639
13641
|
await followFiles(ctx, args.positional, Number(args.str("sleep-interval", "1")) * 1e3);
|
|
13640
13642
|
}
|
|
13641
|
-
return
|
|
13643
|
+
return ok2 ? 0 : 1;
|
|
13642
13644
|
}
|
|
13643
13645
|
});
|
|
13644
13646
|
async function followFiles(ctx, paths, intervalMs) {
|
|
@@ -13655,12 +13657,12 @@ async function followFiles(ctx, paths, intervalMs) {
|
|
|
13655
13657
|
if (ctx.signal.aborted) break;
|
|
13656
13658
|
for (const path of paths) {
|
|
13657
13659
|
try {
|
|
13658
|
-
const
|
|
13660
|
+
const bytes2 = ctx.vfs.readFile(ctx.path(path), ctx.cred);
|
|
13659
13661
|
const previous = offsets.get(path) ?? 0;
|
|
13660
|
-
if (
|
|
13661
|
-
ctx.write(
|
|
13662
|
-
offsets.set(path,
|
|
13663
|
-
} else if (
|
|
13662
|
+
if (bytes2.length > previous) {
|
|
13663
|
+
ctx.write(bytes2.subarray(previous));
|
|
13664
|
+
offsets.set(path, bytes2.length);
|
|
13665
|
+
} else if (bytes2.length < previous) {
|
|
13664
13666
|
offsets.set(path, 0);
|
|
13665
13667
|
}
|
|
13666
13668
|
} catch {
|
|
@@ -13681,7 +13683,7 @@ var wc = defineCommand({
|
|
|
13681
13683
|
{ short: "w", long: "words" },
|
|
13682
13684
|
{ short: "L", long: "max-line-length" }
|
|
13683
13685
|
]);
|
|
13684
|
-
const { sources, ok } = await readInputs(ctx, args.positional, { stdinName: "" });
|
|
13686
|
+
const { sources, ok: ok2 } = await readInputs(ctx, args.positional, { stdinName: "" });
|
|
13685
13687
|
const anyFlag = args.has("bytes") || args.has("chars") || args.has("lines") || args.has("words") || args.has("max-line-length");
|
|
13686
13688
|
const totals = { lines: 0, words: 0, bytes: 0, chars: 0, maxLine: 0 };
|
|
13687
13689
|
const rows = [];
|
|
@@ -13719,7 +13721,7 @@ var wc = defineCommand({
|
|
|
13719
13721
|
}
|
|
13720
13722
|
ctx.line(parts.join(" ") + (row.name ? ` ${row.name}` : ""));
|
|
13721
13723
|
}
|
|
13722
|
-
return
|
|
13724
|
+
return ok2 ? 0 : 1;
|
|
13723
13725
|
}
|
|
13724
13726
|
});
|
|
13725
13727
|
var sort = defineCommand({
|
|
@@ -13745,7 +13747,7 @@ var sort = defineCommand({
|
|
|
13745
13747
|
{ short: "z", long: "zero-terminated" },
|
|
13746
13748
|
{ short: "o", long: "output", arg: true }
|
|
13747
13749
|
]);
|
|
13748
|
-
const { sources, ok } = await readInputs(ctx, args.positional);
|
|
13750
|
+
const { sources, ok: ok2 } = await readInputs(ctx, args.positional);
|
|
13749
13751
|
const all = [];
|
|
13750
13752
|
for (const source of sources) all.push(...splitLines(source.bytes).lines);
|
|
13751
13753
|
const separator = args.str("field-separator");
|
|
@@ -13753,10 +13755,10 @@ var sort = defineCommand({
|
|
|
13753
13755
|
const fieldOf = (line, spec) => {
|
|
13754
13756
|
const m = /^(\d+)(?:\.(\d+))?([a-zA-Z]*)(?:,(\d+)(?:\.(\d+))?([a-zA-Z]*))?$/.exec(spec);
|
|
13755
13757
|
if (!m) return line;
|
|
13756
|
-
const
|
|
13758
|
+
const start2 = Number(m[1]) - 1;
|
|
13757
13759
|
const end = m[4] !== void 0 ? Number(m[4]) : void 0;
|
|
13758
13760
|
const fields = separator === void 0 ? line.trim().split(/\s+/) : line.split(separator);
|
|
13759
|
-
const slice = fields.slice(
|
|
13761
|
+
const slice = fields.slice(start2, end === void 0 ? void 0 : end);
|
|
13760
13762
|
return slice.join(separator ?? " ");
|
|
13761
13763
|
};
|
|
13762
13764
|
const normalize3 = (line) => {
|
|
@@ -13809,7 +13811,7 @@ var sort = defineCommand({
|
|
|
13809
13811
|
const target = args.str("output");
|
|
13810
13812
|
if (target) ctx.vfs.writeFile(ctx.path(target), output, { cred: ctx.cred });
|
|
13811
13813
|
else ctx.write(output);
|
|
13812
|
-
return
|
|
13814
|
+
return ok2 ? 0 : 1;
|
|
13813
13815
|
}
|
|
13814
13816
|
});
|
|
13815
13817
|
var uniq = defineCommand({
|
|
@@ -13829,7 +13831,7 @@ var uniq = defineCommand({
|
|
|
13829
13831
|
{ short: "w", long: "check-chars", arg: true }
|
|
13830
13832
|
]);
|
|
13831
13833
|
const [input, output] = args.positional;
|
|
13832
|
-
const { sources, ok } = await readInputs(ctx, input ? [input] : []);
|
|
13834
|
+
const { sources, ok: ok2 } = await readInputs(ctx, input ? [input] : []);
|
|
13833
13835
|
const lines = sources.flatMap((s) => splitLines(s.bytes).lines);
|
|
13834
13836
|
const key = (line) => {
|
|
13835
13837
|
let value = line;
|
|
@@ -13861,7 +13863,7 @@ var uniq = defineCommand({
|
|
|
13861
13863
|
const text2 = joinLines(out, true);
|
|
13862
13864
|
if (output) ctx.vfs.writeFile(ctx.path(output), text2, { cred: ctx.cred });
|
|
13863
13865
|
else ctx.write(text2);
|
|
13864
|
-
return
|
|
13866
|
+
return ok2 ? 0 : 1;
|
|
13865
13867
|
}
|
|
13866
13868
|
});
|
|
13867
13869
|
var cut = defineCommand({
|
|
@@ -13885,7 +13887,7 @@ var cut = defineCommand({
|
|
|
13885
13887
|
const delimiter = args.str("delimiter", " ");
|
|
13886
13888
|
const outputDelimiter = args.str("output-delimiter", delimiter);
|
|
13887
13889
|
const byField = args.has("fields");
|
|
13888
|
-
const { sources, ok } = await readInputs(ctx, args.positional);
|
|
13890
|
+
const { sources, ok: ok2 } = await readInputs(ctx, args.positional);
|
|
13889
13891
|
for (const source of sources) {
|
|
13890
13892
|
const { lines, trailingNewline } = splitLines(source.bytes);
|
|
13891
13893
|
const out = lines.flatMap((line) => {
|
|
@@ -13900,16 +13902,16 @@ var cut = defineCommand({
|
|
|
13900
13902
|
});
|
|
13901
13903
|
ctx.write(joinLines(out, trailingNewline));
|
|
13902
13904
|
}
|
|
13903
|
-
return
|
|
13905
|
+
return ok2 ? 0 : 1;
|
|
13904
13906
|
}
|
|
13905
13907
|
});
|
|
13906
13908
|
function parseRanges(spec) {
|
|
13907
13909
|
return spec.split(",").map((part) => {
|
|
13908
13910
|
const m = /^(\d*)-(\d*)$/.exec(part);
|
|
13909
13911
|
if (m) {
|
|
13910
|
-
const
|
|
13912
|
+
const start2 = m[1] === "" ? 1 : Number(m[1]);
|
|
13911
13913
|
const end = m[2] === "" ? Infinity : Number(m[2]);
|
|
13912
|
-
return [
|
|
13914
|
+
return [start2, end];
|
|
13913
13915
|
}
|
|
13914
13916
|
const n = Number(part);
|
|
13915
13917
|
return [n, n];
|
|
@@ -13918,7 +13920,7 @@ function parseRanges(spec) {
|
|
|
13918
13920
|
function pick(items, ranges, complement) {
|
|
13919
13921
|
const selected = items.filter((_, idx) => {
|
|
13920
13922
|
const position = idx + 1;
|
|
13921
|
-
const inRange = ranges.some(([
|
|
13923
|
+
const inRange = ranges.some(([start2, end]) => position >= start2 && position <= end);
|
|
13922
13924
|
return complement ? !inRange : inRange;
|
|
13923
13925
|
});
|
|
13924
13926
|
return selected;
|
|
@@ -13934,13 +13936,13 @@ var paste = defineCommand({
|
|
|
13934
13936
|
{ short: "s", long: "serial" }
|
|
13935
13937
|
]);
|
|
13936
13938
|
const delimiters = [...args.str("delimiters") || " "];
|
|
13937
|
-
const { sources, ok } = await readInputs(ctx, args.positional);
|
|
13939
|
+
const { sources, ok: ok2 } = await readInputs(ctx, args.positional);
|
|
13938
13940
|
const columns = sources.map((s) => splitLines(s.bytes).lines);
|
|
13939
13941
|
if (args.has("serial")) {
|
|
13940
13942
|
for (const column2 of columns) {
|
|
13941
13943
|
ctx.line(column2.map((line, idx) => idx === 0 ? line : delimiters[(idx - 1) % delimiters.length] + line).join(""));
|
|
13942
13944
|
}
|
|
13943
|
-
return
|
|
13945
|
+
return ok2 ? 0 : 1;
|
|
13944
13946
|
}
|
|
13945
13947
|
const rows = Math.max(0, ...columns.map((c) => c.length));
|
|
13946
13948
|
for (let r = 0; r < rows; r++) {
|
|
@@ -13951,7 +13953,7 @@ var paste = defineCommand({
|
|
|
13951
13953
|
});
|
|
13952
13954
|
ctx.line(line);
|
|
13953
13955
|
}
|
|
13954
|
-
return
|
|
13956
|
+
return ok2 ? 0 : 1;
|
|
13955
13957
|
}
|
|
13956
13958
|
});
|
|
13957
13959
|
var tr = defineCommand({
|
|
@@ -14022,9 +14024,9 @@ function expandSet(spec) {
|
|
|
14022
14024
|
continue;
|
|
14023
14025
|
}
|
|
14024
14026
|
if (spec[i + 1] === "-" && i + 2 < spec.length && spec[i + 2] !== "]") {
|
|
14025
|
-
const
|
|
14027
|
+
const start2 = spec.charCodeAt(i);
|
|
14026
14028
|
const end = spec.charCodeAt(i + 2);
|
|
14027
|
-
for (let c =
|
|
14029
|
+
for (let c = start2; c <= end; c++) out.push(String.fromCharCode(c));
|
|
14028
14030
|
i += 3;
|
|
14029
14031
|
continue;
|
|
14030
14032
|
}
|
|
@@ -14043,14 +14045,14 @@ var tee = defineCommand({
|
|
|
14043
14045
|
{ short: "a", long: "append" },
|
|
14044
14046
|
{ short: "i", long: "ignore-interrupts" }
|
|
14045
14047
|
]);
|
|
14046
|
-
const
|
|
14047
|
-
ctx.write(
|
|
14048
|
+
const bytes2 = await ctx.stdin.readAll();
|
|
14049
|
+
ctx.write(bytes2);
|
|
14048
14050
|
let status = 0;
|
|
14049
14051
|
for (const target of args.positional) {
|
|
14050
14052
|
try {
|
|
14051
14053
|
const abs = ctx.path(target);
|
|
14052
|
-
if (args.has("append")) ctx.vfs.appendFile(abs,
|
|
14053
|
-
else ctx.vfs.writeFile(abs,
|
|
14054
|
+
if (args.has("append")) ctx.vfs.appendFile(abs, bytes2, { cred: ctx.cred });
|
|
14055
|
+
else ctx.vfs.writeFile(abs, bytes2, { cred: ctx.cred });
|
|
14054
14056
|
} catch (e) {
|
|
14055
14057
|
status = ctx.reportError(e, target);
|
|
14056
14058
|
}
|
|
@@ -14063,12 +14065,12 @@ var rev = defineCommand({
|
|
|
14063
14065
|
path: "/usr/bin/rev",
|
|
14064
14066
|
summary: "reverse lines characterwise",
|
|
14065
14067
|
async run(ctx) {
|
|
14066
|
-
const { sources, ok } = await readInputs(ctx, ctx.args);
|
|
14068
|
+
const { sources, ok: ok2 } = await readInputs(ctx, ctx.args);
|
|
14067
14069
|
for (const source of sources) {
|
|
14068
14070
|
const { lines, trailingNewline } = splitLines(source.bytes);
|
|
14069
14071
|
ctx.write(joinLines(lines.map((l) => [...l].reverse().join("")), trailingNewline));
|
|
14070
14072
|
}
|
|
14071
|
-
return
|
|
14073
|
+
return ok2 ? 0 : 1;
|
|
14072
14074
|
}
|
|
14073
14075
|
});
|
|
14074
14076
|
var tac = defineCommand({
|
|
@@ -14077,12 +14079,12 @@ var tac = defineCommand({
|
|
|
14077
14079
|
summary: "concatenate and print files in reverse",
|
|
14078
14080
|
async run(ctx) {
|
|
14079
14081
|
const args = parseArgs(ctx.args, [{ short: "s", long: "separator", arg: true }]);
|
|
14080
|
-
const { sources, ok } = await readInputs(ctx, args.positional);
|
|
14082
|
+
const { sources, ok: ok2 } = await readInputs(ctx, args.positional);
|
|
14081
14083
|
for (const source of sources) {
|
|
14082
14084
|
const { lines } = splitLines(source.bytes);
|
|
14083
14085
|
ctx.write(joinLines(lines.reverse(), true));
|
|
14084
14086
|
}
|
|
14085
|
-
return
|
|
14087
|
+
return ok2 ? 0 : 1;
|
|
14086
14088
|
}
|
|
14087
14089
|
});
|
|
14088
14090
|
var nl = defineCommand({
|
|
@@ -14097,7 +14099,7 @@ var nl = defineCommand({
|
|
|
14097
14099
|
{ short: "v", long: "starting-line-number", arg: true, default: "1" },
|
|
14098
14100
|
{ short: "i", long: "line-increment", arg: true, default: "1" }
|
|
14099
14101
|
]);
|
|
14100
|
-
const { sources, ok } = await readInputs(ctx, args.positional);
|
|
14102
|
+
const { sources, ok: ok2 } = await readInputs(ctx, args.positional);
|
|
14101
14103
|
const width = args.num("number-width", 6);
|
|
14102
14104
|
const separator = args.str("number-separator", " ");
|
|
14103
14105
|
const style = args.str("body-numbering", "t");
|
|
@@ -14114,7 +14116,7 @@ var nl = defineCommand({
|
|
|
14114
14116
|
}
|
|
14115
14117
|
}
|
|
14116
14118
|
}
|
|
14117
|
-
return
|
|
14119
|
+
return ok2 ? 0 : 1;
|
|
14118
14120
|
}
|
|
14119
14121
|
});
|
|
14120
14122
|
var fold = defineCommand({
|
|
@@ -14132,7 +14134,7 @@ var fold = defineCommand({
|
|
|
14132
14134
|
{ numericShortcut: "width" }
|
|
14133
14135
|
);
|
|
14134
14136
|
const width = args.num("width", 80);
|
|
14135
|
-
const { sources, ok } = await readInputs(ctx, args.positional);
|
|
14137
|
+
const { sources, ok: ok2 } = await readInputs(ctx, args.positional);
|
|
14136
14138
|
for (const source of sources) {
|
|
14137
14139
|
for (const line of splitLines(source.bytes).lines) {
|
|
14138
14140
|
let rest = line;
|
|
@@ -14152,7 +14154,7 @@ var fold = defineCommand({
|
|
|
14152
14154
|
ctx.line(rest);
|
|
14153
14155
|
}
|
|
14154
14156
|
}
|
|
14155
|
-
return
|
|
14157
|
+
return ok2 ? 0 : 1;
|
|
14156
14158
|
}
|
|
14157
14159
|
});
|
|
14158
14160
|
var expandCmd = defineCommand({
|
|
@@ -14162,7 +14164,7 @@ var expandCmd = defineCommand({
|
|
|
14162
14164
|
async run(ctx) {
|
|
14163
14165
|
const args = parseArgs(ctx.args, [{ short: "t", long: "tabs", arg: true, default: "8" }, { short: "i", long: "initial" }]);
|
|
14164
14166
|
const tabs = args.num("tabs", 8);
|
|
14165
|
-
const { sources, ok } = await readInputs(ctx, args.positional);
|
|
14167
|
+
const { sources, ok: ok2 } = await readInputs(ctx, args.positional);
|
|
14166
14168
|
for (const source of sources) {
|
|
14167
14169
|
const { lines, trailingNewline } = splitLines(source.bytes);
|
|
14168
14170
|
const out = lines.map((line) => {
|
|
@@ -14175,7 +14177,7 @@ var expandCmd = defineCommand({
|
|
|
14175
14177
|
});
|
|
14176
14178
|
ctx.write(joinLines(out, trailingNewline));
|
|
14177
14179
|
}
|
|
14178
|
-
return
|
|
14180
|
+
return ok2 ? 0 : 1;
|
|
14179
14181
|
}
|
|
14180
14182
|
});
|
|
14181
14183
|
var unexpand = defineCommand({
|
|
@@ -14185,7 +14187,7 @@ var unexpand = defineCommand({
|
|
|
14185
14187
|
async run(ctx) {
|
|
14186
14188
|
const args = parseArgs(ctx.args, [{ short: "t", long: "tabs", arg: true, default: "8" }, { short: "a", long: "all" }]);
|
|
14187
14189
|
const tabs = args.num("tabs", 8);
|
|
14188
|
-
const { sources, ok } = await readInputs(ctx, args.positional);
|
|
14190
|
+
const { sources, ok: ok2 } = await readInputs(ctx, args.positional);
|
|
14189
14191
|
for (const source of sources) {
|
|
14190
14192
|
const { lines, trailingNewline } = splitLines(source.bytes);
|
|
14191
14193
|
const out = lines.map((line) => {
|
|
@@ -14195,7 +14197,7 @@ var unexpand = defineCommand({
|
|
|
14195
14197
|
});
|
|
14196
14198
|
ctx.write(joinLines(out, trailingNewline));
|
|
14197
14199
|
}
|
|
14198
|
-
return
|
|
14200
|
+
return ok2 ? 0 : 1;
|
|
14199
14201
|
}
|
|
14200
14202
|
});
|
|
14201
14203
|
var fmt = defineCommand({
|
|
@@ -14205,7 +14207,7 @@ var fmt = defineCommand({
|
|
|
14205
14207
|
async run(ctx) {
|
|
14206
14208
|
const args = parseArgs(ctx.args, [{ short: "w", long: "width", arg: true, default: "75" }], { numericShortcut: "width" });
|
|
14207
14209
|
const width = args.num("width", 75);
|
|
14208
|
-
const { sources, ok } = await readInputs(ctx, args.positional);
|
|
14210
|
+
const { sources, ok: ok2 } = await readInputs(ctx, args.positional);
|
|
14209
14211
|
for (const source of sources) {
|
|
14210
14212
|
const paragraphs = decoder4.decode(source.bytes).split(/\n\s*\n/);
|
|
14211
14213
|
paragraphs.forEach((paragraph, idx) => {
|
|
@@ -14223,7 +14225,7 @@ var fmt = defineCommand({
|
|
|
14223
14225
|
if (line) ctx.line(line);
|
|
14224
14226
|
});
|
|
14225
14227
|
}
|
|
14226
|
-
return
|
|
14228
|
+
return ok2 ? 0 : 1;
|
|
14227
14229
|
}
|
|
14228
14230
|
});
|
|
14229
14231
|
var column = defineCommand({
|
|
@@ -14236,11 +14238,11 @@ var column = defineCommand({
|
|
|
14236
14238
|
{ short: "s", long: "separator", arg: true },
|
|
14237
14239
|
{ short: "o", long: "output-separator", arg: true, default: " " }
|
|
14238
14240
|
]);
|
|
14239
|
-
const { sources, ok } = await readInputs(ctx, args.positional);
|
|
14241
|
+
const { sources, ok: ok2 } = await readInputs(ctx, args.positional);
|
|
14240
14242
|
const lines = sources.flatMap((s) => splitLines(s.bytes).lines).filter((l) => l !== "");
|
|
14241
14243
|
if (!args.has("table")) {
|
|
14242
14244
|
for (const line of lines) ctx.line(line);
|
|
14243
|
-
return
|
|
14245
|
+
return ok2 ? 0 : 1;
|
|
14244
14246
|
}
|
|
14245
14247
|
const separator = args.str("separator");
|
|
14246
14248
|
const rows = lines.map((line) => separator ? line.split(separator) : line.trim().split(/\s+/));
|
|
@@ -14250,7 +14252,7 @@ var column = defineCommand({
|
|
|
14250
14252
|
for (const row of rows) {
|
|
14251
14253
|
ctx.line(row.map((cell, i) => i === row.length - 1 ? cell : cell.padEnd(widths[i])).join(outputSeparator).trimEnd());
|
|
14252
14254
|
}
|
|
14253
|
-
return
|
|
14255
|
+
return ok2 ? 0 : 1;
|
|
14254
14256
|
}
|
|
14255
14257
|
});
|
|
14256
14258
|
var shuf = defineCommand({
|
|
@@ -14293,7 +14295,7 @@ var comm = defineCommand({
|
|
|
14293
14295
|
const args = parseArgs(ctx.args, [{ short: "1" }, { short: "2" }, { short: "3" }]);
|
|
14294
14296
|
const [a, b] = args.positional;
|
|
14295
14297
|
if (a === void 0 || b === void 0) return ctx.fail("missing operand", 1);
|
|
14296
|
-
const { sources, ok } = await readInputs(ctx, [a, b]);
|
|
14298
|
+
const { sources, ok: ok2 } = await readInputs(ctx, [a, b]);
|
|
14297
14299
|
const left = splitLines(sources[0].bytes).lines;
|
|
14298
14300
|
const right = splitLines(sources[1].bytes).lines;
|
|
14299
14301
|
let i = 0;
|
|
@@ -14313,7 +14315,7 @@ var comm = defineCommand({
|
|
|
14313
14315
|
j++;
|
|
14314
14316
|
}
|
|
14315
14317
|
}
|
|
14316
|
-
return
|
|
14318
|
+
return ok2 ? 0 : 1;
|
|
14317
14319
|
}
|
|
14318
14320
|
});
|
|
14319
14321
|
var join2 = defineCommand({
|
|
@@ -14334,7 +14336,7 @@ var join2 = defineCommand({
|
|
|
14334
14336
|
const joinChar = separator ?? " ";
|
|
14335
14337
|
const key1 = Number(args.str("j") ?? args.str("1", "1")) - 1;
|
|
14336
14338
|
const key2 = Number(args.str("j") ?? args.str("2", "1")) - 1;
|
|
14337
|
-
const { sources, ok } = await readInputs(ctx, [a, b]);
|
|
14339
|
+
const { sources, ok: ok2 } = await readInputs(ctx, [a, b]);
|
|
14338
14340
|
const left = splitLines(sources[0].bytes).lines.map(split2);
|
|
14339
14341
|
const right = splitLines(sources[1].bytes).lines.map(split2);
|
|
14340
14342
|
for (const l of left) {
|
|
@@ -14346,7 +14348,7 @@ var join2 = defineCommand({
|
|
|
14346
14348
|
}
|
|
14347
14349
|
}
|
|
14348
14350
|
}
|
|
14349
|
-
return
|
|
14351
|
+
return ok2 ? 0 : 1;
|
|
14350
14352
|
}
|
|
14351
14353
|
});
|
|
14352
14354
|
var split = defineCommand({
|
|
@@ -14362,17 +14364,17 @@ var split = defineCommand({
|
|
|
14362
14364
|
]);
|
|
14363
14365
|
const [input, prefixRaw] = args.positional;
|
|
14364
14366
|
const prefix = prefixRaw ?? "x";
|
|
14365
|
-
const { sources, ok } = await readInputs(ctx, input ? [input] : []);
|
|
14366
|
-
const
|
|
14367
|
+
const { sources, ok: ok2 } = await readInputs(ctx, input ? [input] : []);
|
|
14368
|
+
const bytes2 = sources[0]?.bytes ?? new Uint8Array(0);
|
|
14367
14369
|
const suffixLength = args.num("suffix-length", 2);
|
|
14368
14370
|
const chunks = [];
|
|
14369
14371
|
const byteSpec = args.str("bytes");
|
|
14370
14372
|
if (byteSpec !== void 0) {
|
|
14371
14373
|
const size = parseSize(byteSpec) ?? 1024;
|
|
14372
|
-
for (let i = 0; i <
|
|
14374
|
+
for (let i = 0; i < bytes2.length; i += size) chunks.push(bytes2.subarray(i, i + size));
|
|
14373
14375
|
} else {
|
|
14374
14376
|
const perChunk = args.num("lines", 1e3);
|
|
14375
|
-
const { lines } = splitLines(
|
|
14377
|
+
const { lines } = splitLines(bytes2);
|
|
14376
14378
|
for (let i = 0; i < lines.length; i += perChunk) {
|
|
14377
14379
|
chunks.push(new TextEncoder().encode(joinLines(lines.slice(i, i + perChunk), true)));
|
|
14378
14380
|
}
|
|
@@ -14381,7 +14383,7 @@ var split = defineCommand({
|
|
|
14381
14383
|
const suffix = args.has("numeric-suffixes") ? String(idx).padStart(suffixLength, "0") : numericToAlpha(idx, suffixLength);
|
|
14382
14384
|
ctx.vfs.writeFile(ctx.path(prefix + suffix), chunk, { cred: ctx.cred });
|
|
14383
14385
|
});
|
|
14384
|
-
return
|
|
14386
|
+
return ok2 ? 0 : 1;
|
|
14385
14387
|
}
|
|
14386
14388
|
});
|
|
14387
14389
|
function numericToAlpha(value, length) {
|
|
@@ -14582,19 +14584,19 @@ var grep = defineCommand({
|
|
|
14582
14584
|
let anyMatch = false;
|
|
14583
14585
|
let status = 1;
|
|
14584
14586
|
for (const target of targets) {
|
|
14585
|
-
let
|
|
14587
|
+
let bytes2;
|
|
14586
14588
|
if (target === "-") {
|
|
14587
|
-
|
|
14589
|
+
bytes2 = await ctx.stdin.readAll();
|
|
14588
14590
|
} else {
|
|
14589
14591
|
try {
|
|
14590
|
-
|
|
14592
|
+
bytes2 = ctx.vfs.readFile(ctx.path(target), ctx.cred);
|
|
14591
14593
|
} catch (e) {
|
|
14592
14594
|
if (!args.has("no-messages")) ctx.reportError(e, target);
|
|
14593
14595
|
status = 2;
|
|
14594
14596
|
continue;
|
|
14595
14597
|
}
|
|
14596
14598
|
}
|
|
14597
|
-
const { lines } = splitLines(
|
|
14599
|
+
const { lines } = splitLines(bytes2);
|
|
14598
14600
|
const matched = [];
|
|
14599
14601
|
let count = 0;
|
|
14600
14602
|
for (let i = 0; i < lines.length && count < maxCount; i++) {
|
|
@@ -14627,10 +14629,10 @@ var grep = defineCommand({
|
|
|
14627
14629
|
const emitted = /* @__PURE__ */ new Set();
|
|
14628
14630
|
let lastPrinted = -2;
|
|
14629
14631
|
for (const index of matched) {
|
|
14630
|
-
const
|
|
14632
|
+
const start2 = Math.max(0, index - before);
|
|
14631
14633
|
const end = Math.min(lines.length - 1, index + after);
|
|
14632
|
-
if ((before || after) && lastPrinted >= 0 &&
|
|
14633
|
-
for (let i =
|
|
14634
|
+
if ((before || after) && lastPrinted >= 0 && start2 > lastPrinted + 1) ctx.line("--");
|
|
14635
|
+
for (let i = start2; i <= end; i++) {
|
|
14634
14636
|
if (emitted.has(i)) continue;
|
|
14635
14637
|
emitted.add(i);
|
|
14636
14638
|
const isMatchLine = matched.includes(i);
|
|
@@ -15006,8 +15008,8 @@ var diff = defineCommand({
|
|
|
15006
15008
|
]);
|
|
15007
15009
|
const [a, b] = args.positional;
|
|
15008
15010
|
if (a === void 0 || b === void 0) return ctx.fail("missing operand", 2);
|
|
15009
|
-
const { sources, ok } = await readInputs(ctx, [a, b]);
|
|
15010
|
-
if (!
|
|
15011
|
+
const { sources, ok: ok2 } = await readInputs(ctx, [a, b]);
|
|
15012
|
+
if (!ok2 || sources.length < 2) return 2;
|
|
15011
15013
|
const normalize3 = (line) => {
|
|
15012
15014
|
let value = line;
|
|
15013
15015
|
if (args.has("ignore-all-space")) value = value.replace(/\s+/g, "");
|
|
@@ -15046,8 +15048,8 @@ var diff = defineCommand({
|
|
|
15046
15048
|
return 1;
|
|
15047
15049
|
}
|
|
15048
15050
|
});
|
|
15049
|
-
function formatRange(
|
|
15050
|
-
return count <= 1 ? String(
|
|
15051
|
+
function formatRange(start2, count) {
|
|
15052
|
+
return count <= 1 ? String(start2) : `${start2},${start2 + count - 1}`;
|
|
15051
15053
|
}
|
|
15052
15054
|
function diffLines(a, b) {
|
|
15053
15055
|
const n = a.length;
|
|
@@ -15104,11 +15106,11 @@ function buildHunks(edits, a, b, context) {
|
|
|
15104
15106
|
i++;
|
|
15105
15107
|
continue;
|
|
15106
15108
|
}
|
|
15107
|
-
let
|
|
15109
|
+
let start2 = Math.max(0, i - context);
|
|
15108
15110
|
let end = i;
|
|
15109
15111
|
while (end < edits.length && (changed[end] || edits.slice(end, end + context + 1).some((_, k) => changed[end + k]))) end++;
|
|
15110
15112
|
end = Math.min(edits.length, end + context);
|
|
15111
|
-
const slice = edits.slice(
|
|
15113
|
+
const slice = edits.slice(start2, end);
|
|
15112
15114
|
const aStart = slice.find((e) => e.op !== "insert")?.aIndex ?? 0;
|
|
15113
15115
|
const bStart = slice.find((e) => e.op !== "delete")?.bIndex ?? 0;
|
|
15114
15116
|
const lines = [];
|
|
@@ -15140,8 +15142,8 @@ var cmp = defineCommand({
|
|
|
15140
15142
|
const args = parseArgs(ctx.args, [{ short: "s", long: "silent" }, { short: "l", long: "verbose" }]);
|
|
15141
15143
|
const [a, b] = args.positional;
|
|
15142
15144
|
if (a === void 0 || b === void 0) return ctx.fail("missing operand", 2);
|
|
15143
|
-
const { sources, ok } = await readInputs(ctx, [a, b]);
|
|
15144
|
-
if (!
|
|
15145
|
+
const { sources, ok: ok2 } = await readInputs(ctx, [a, b]);
|
|
15146
|
+
if (!ok2) return 2;
|
|
15145
15147
|
const left = sources[0].bytes;
|
|
15146
15148
|
const right = sources[1].bytes;
|
|
15147
15149
|
const length = Math.min(left.length, right.length);
|
|
@@ -15251,9 +15253,9 @@ async function randomUuid() {
|
|
|
15251
15253
|
const { randomUUID } = await nodeCrypto();
|
|
15252
15254
|
return randomUUID();
|
|
15253
15255
|
}
|
|
15254
|
-
function toHex(
|
|
15256
|
+
function toHex(bytes2) {
|
|
15255
15257
|
let out = "";
|
|
15256
|
-
for (const byte of
|
|
15258
|
+
for (const byte of bytes2) out += byte.toString(16).padStart(2, "0");
|
|
15257
15259
|
return out;
|
|
15258
15260
|
}
|
|
15259
15261
|
function md5Hex(input) {
|
|
@@ -15381,8 +15383,8 @@ var BLOCK = 512;
|
|
|
15381
15383
|
var encoder4 = new TextEncoder();
|
|
15382
15384
|
var decoder6 = new TextDecoder();
|
|
15383
15385
|
function writeString(block, offset, value, length) {
|
|
15384
|
-
const
|
|
15385
|
-
for (let i = 0; i < length; i++) block[offset + i] = i <
|
|
15386
|
+
const bytes2 = encoder4.encode(value);
|
|
15387
|
+
for (let i = 0; i < length; i++) block[offset + i] = i < bytes2.length ? bytes2[i] : 0;
|
|
15386
15388
|
}
|
|
15387
15389
|
function writeOctal(block, offset, value, length) {
|
|
15388
15390
|
const text2 = value.toString(8).padStart(length - 1, "0");
|
|
@@ -15533,23 +15535,23 @@ var tar = defineCommand({
|
|
|
15533
15535
|
if (args.has("verbose")) ctx.line(name);
|
|
15534
15536
|
};
|
|
15535
15537
|
for (const operand of args.positional) add(resolve(baseDir, operand), operand);
|
|
15536
|
-
let
|
|
15537
|
-
if (compressed)
|
|
15538
|
-
if (archive === void 0 || archive === "-") ctx.write(
|
|
15539
|
-
else ctx.vfs.writeFile(ctx.path(archive),
|
|
15538
|
+
let bytes3 = createTar(entries2);
|
|
15539
|
+
if (compressed) bytes3 = await gzip(bytes3);
|
|
15540
|
+
if (archive === void 0 || archive === "-") ctx.write(bytes3);
|
|
15541
|
+
else ctx.vfs.writeFile(ctx.path(archive), bytes3, { cred: ctx.cred, mode: 420 });
|
|
15540
15542
|
return 0;
|
|
15541
15543
|
}
|
|
15542
|
-
let
|
|
15543
|
-
if (archive === void 0 || archive === "-")
|
|
15544
|
+
let bytes2;
|
|
15545
|
+
if (archive === void 0 || archive === "-") bytes2 = await ctx.stdin.readAll();
|
|
15544
15546
|
else {
|
|
15545
15547
|
try {
|
|
15546
|
-
|
|
15548
|
+
bytes2 = ctx.vfs.readFile(ctx.path(archive), ctx.cred);
|
|
15547
15549
|
} catch (e) {
|
|
15548
15550
|
return ctx.reportError(e, archive);
|
|
15549
15551
|
}
|
|
15550
15552
|
}
|
|
15551
|
-
if (
|
|
15552
|
-
const entries = readTar(
|
|
15553
|
+
if (bytes2[0] === 31 && bytes2[1] === 139) bytes2 = await gunzip(bytes2);
|
|
15554
|
+
const entries = readTar(bytes2);
|
|
15553
15555
|
const strip = args.num("strip-components", 0);
|
|
15554
15556
|
if (args.has("list")) {
|
|
15555
15557
|
for (const entry of entries) {
|
|
@@ -15705,18 +15707,18 @@ function makeSum(name, algorithm, path) {
|
|
|
15705
15707
|
{ long: "tag" }
|
|
15706
15708
|
]);
|
|
15707
15709
|
if (args.has("check")) return checkSums(ctx, algorithm, args.positional, args.has("quiet") || args.has("status"));
|
|
15708
|
-
const { sources, ok } = await readInputs(ctx, args.positional, { stdinName: "-" });
|
|
15710
|
+
const { sources, ok: ok2 } = await readInputs(ctx, args.positional, { stdinName: "-" });
|
|
15709
15711
|
for (const source of sources) {
|
|
15710
15712
|
const digest = await digestHex(algorithm, source.bytes);
|
|
15711
15713
|
if (args.has("tag")) ctx.line(`${algorithm.toUpperCase()} (${source.name}) = ${digest}`);
|
|
15712
15714
|
else ctx.line(`${digest} ${source.name}`);
|
|
15713
15715
|
}
|
|
15714
|
-
return
|
|
15716
|
+
return ok2 ? 0 : 1;
|
|
15715
15717
|
}
|
|
15716
15718
|
});
|
|
15717
15719
|
}
|
|
15718
15720
|
async function checkSums(ctx, algorithm, files, quiet) {
|
|
15719
|
-
const { sources, ok } = await readInputs(ctx, files);
|
|
15721
|
+
const { sources, ok: ok2 } = await readInputs(ctx, files);
|
|
15720
15722
|
let failures = 0;
|
|
15721
15723
|
let checked = 0;
|
|
15722
15724
|
for (const source of sources) {
|
|
@@ -15727,8 +15729,8 @@ async function checkSums(ctx, algorithm, files, quiet) {
|
|
|
15727
15729
|
checked++;
|
|
15728
15730
|
const [, expected, name] = m;
|
|
15729
15731
|
try {
|
|
15730
|
-
const
|
|
15731
|
-
const actual = await digestHex(algorithm,
|
|
15732
|
+
const bytes2 = ctx.vfs.readFile(ctx.path(name), ctx.cred);
|
|
15733
|
+
const actual = await digestHex(algorithm, bytes2);
|
|
15732
15734
|
if (actual === expected.toLowerCase()) {
|
|
15733
15735
|
if (!quiet) ctx.line(`${name}: OK`);
|
|
15734
15736
|
} else {
|
|
@@ -15742,7 +15744,7 @@ async function checkSums(ctx, algorithm, files, quiet) {
|
|
|
15742
15744
|
}
|
|
15743
15745
|
}
|
|
15744
15746
|
if (failures > 0) ctx.warn(`WARNING: ${failures} computed checksum${failures === 1 ? "" : "s"} did NOT match`);
|
|
15745
|
-
return
|
|
15747
|
+
return ok2 && failures === 0 && checked > 0 ? 0 : 1;
|
|
15746
15748
|
}
|
|
15747
15749
|
var md5sum = makeSum("md5sum", "md5", "/usr/bin/md5sum");
|
|
15748
15750
|
var sha1sum = makeSum("sha1sum", "sha1", "/usr/bin/sha1sum");
|
|
@@ -15755,11 +15757,11 @@ var cksum = defineCommand({
|
|
|
15755
15757
|
path: "/usr/bin/cksum",
|
|
15756
15758
|
summary: "checksum and count the bytes in a file",
|
|
15757
15759
|
async run(ctx) {
|
|
15758
|
-
const { sources, ok } = await readInputs(ctx, ctx.args, { stdinName: "" });
|
|
15760
|
+
const { sources, ok: ok2 } = await readInputs(ctx, ctx.args, { stdinName: "" });
|
|
15759
15761
|
for (const source of sources) {
|
|
15760
15762
|
ctx.line(`${crc32(source.bytes)} ${source.bytes.length}${source.name ? ` ${source.name}` : ""}`);
|
|
15761
15763
|
}
|
|
15762
|
-
return
|
|
15764
|
+
return ok2 ? 0 : 1;
|
|
15763
15765
|
}
|
|
15764
15766
|
});
|
|
15765
15767
|
var CRC_TABLE = (() => {
|
|
@@ -15787,7 +15789,7 @@ var base64Cmd = defineCommand({
|
|
|
15787
15789
|
{ short: "i", long: "ignore-garbage" },
|
|
15788
15790
|
{ short: "w", long: "wrap", arg: true, default: "76" }
|
|
15789
15791
|
]);
|
|
15790
|
-
const { sources, ok } = await readInputs(ctx, args.positional);
|
|
15792
|
+
const { sources, ok: ok2 } = await readInputs(ctx, args.positional);
|
|
15791
15793
|
for (const source of sources) {
|
|
15792
15794
|
if (args.has("decode")) {
|
|
15793
15795
|
const text2 = new TextDecoder().decode(source.bytes).replace(/\s+/g, "");
|
|
@@ -15799,14 +15801,14 @@ var base64Cmd = defineCommand({
|
|
|
15799
15801
|
continue;
|
|
15800
15802
|
}
|
|
15801
15803
|
const encoded = Buffer.from(source.bytes).toString("base64");
|
|
15802
|
-
const
|
|
15803
|
-
if (
|
|
15804
|
+
const wrap2 = args.num("wrap", 76);
|
|
15805
|
+
if (wrap2 <= 0) {
|
|
15804
15806
|
ctx.line(encoded);
|
|
15805
15807
|
continue;
|
|
15806
15808
|
}
|
|
15807
|
-
for (let i = 0; i < encoded.length; i +=
|
|
15809
|
+
for (let i = 0; i < encoded.length; i += wrap2) ctx.line(encoded.slice(i, i + wrap2));
|
|
15808
15810
|
}
|
|
15809
|
-
return
|
|
15811
|
+
return ok2 ? 0 : 1;
|
|
15810
15812
|
}
|
|
15811
15813
|
});
|
|
15812
15814
|
var base32Cmd = defineCommand({
|
|
@@ -15815,7 +15817,7 @@ var base32Cmd = defineCommand({
|
|
|
15815
15817
|
summary: "base32 encode/decode data",
|
|
15816
15818
|
async run(ctx) {
|
|
15817
15819
|
const args = parseArgs(ctx.args, [{ short: "d", long: "decode" }, { short: "w", long: "wrap", arg: true, default: "76" }]);
|
|
15818
|
-
const { sources, ok } = await readInputs(ctx, args.positional);
|
|
15820
|
+
const { sources, ok: ok2 } = await readInputs(ctx, args.positional);
|
|
15819
15821
|
const ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
|
|
15820
15822
|
for (const source of sources) {
|
|
15821
15823
|
if (args.has("decode")) {
|
|
@@ -15849,10 +15851,10 @@ var base32Cmd = defineCommand({
|
|
|
15849
15851
|
}
|
|
15850
15852
|
if (bits > 0) out += ALPHABET[value << 5 - bits & 31];
|
|
15851
15853
|
while (out.length % 8 !== 0) out += "=";
|
|
15852
|
-
const
|
|
15853
|
-
for (let i = 0; i < out.length; i +=
|
|
15854
|
+
const wrap2 = args.num("wrap", 76);
|
|
15855
|
+
for (let i = 0; i < out.length; i += wrap2) ctx.line(out.slice(i, i + wrap2));
|
|
15854
15856
|
}
|
|
15855
|
-
return
|
|
15857
|
+
return ok2 ? 0 : 1;
|
|
15856
15858
|
}
|
|
15857
15859
|
});
|
|
15858
15860
|
var uuidgen = defineCommand({
|
|
@@ -15916,6 +15918,9 @@ function parseUrl(raw) {
|
|
|
15916
15918
|
return null;
|
|
15917
15919
|
}
|
|
15918
15920
|
}
|
|
15921
|
+
function isBrowser() {
|
|
15922
|
+
return typeof process === "undefined" || process.versions?.node == null;
|
|
15923
|
+
}
|
|
15919
15924
|
async function performRequest(ctx, url, init) {
|
|
15920
15925
|
const isLocal = ctx.kernel.net.isLocal(url.hostname);
|
|
15921
15926
|
if (isLocal) {
|
|
@@ -15942,11 +15947,18 @@ async function performRequest(ctx, url, init) {
|
|
|
15942
15947
|
`outbound network access to ${url.hostname} is disabled for this container (enable with network: { allowOutbound: true })`
|
|
15943
15948
|
);
|
|
15944
15949
|
}
|
|
15945
|
-
|
|
15946
|
-
|
|
15947
|
-
|
|
15948
|
-
|
|
15949
|
-
|
|
15950
|
+
let response;
|
|
15951
|
+
try {
|
|
15952
|
+
response = await fetch(url.toString(), {
|
|
15953
|
+
method: init.method,
|
|
15954
|
+
headers: init.headers,
|
|
15955
|
+
...init.body ? { body: init.body.slice().buffer } : {}
|
|
15956
|
+
});
|
|
15957
|
+
} catch (error) {
|
|
15958
|
+
throw isBrowser() ? new Error(
|
|
15959
|
+
`${error instanceof Error ? error.message : String(error)} \u2014 the request to ${url.hostname} was blocked by the browser. A page can only read a response from a host that sends CORS headers; route it through a proxy on your own origin, or run the container on a server.`
|
|
15960
|
+
) : error;
|
|
15961
|
+
}
|
|
15950
15962
|
const body = new Uint8Array(await response.arrayBuffer());
|
|
15951
15963
|
ctx.kernel.net.countRx(body.length);
|
|
15952
15964
|
const headers = {};
|
|
@@ -16925,7 +16937,7 @@ var less = defineCommand({
|
|
|
16925
16937
|
{ short: "X" },
|
|
16926
16938
|
{ short: "n" }
|
|
16927
16939
|
]);
|
|
16928
|
-
const { sources, ok } = await readInputs(ctx, args.positional);
|
|
16940
|
+
const { sources, ok: ok2 } = await readInputs(ctx, args.positional);
|
|
16929
16941
|
let lineNumber = 1;
|
|
16930
16942
|
for (const source of sources) {
|
|
16931
16943
|
if (!args.has("N")) {
|
|
@@ -16936,7 +16948,7 @@ var less = defineCommand({
|
|
|
16936
16948
|
ctx.line(`${String(lineNumber++).padStart(6)} ${line}`);
|
|
16937
16949
|
}
|
|
16938
16950
|
}
|
|
16939
|
-
return
|
|
16951
|
+
return ok2 ? 0 : 1;
|
|
16940
16952
|
}
|
|
16941
16953
|
});
|
|
16942
16954
|
var helpCmd = defineCommand({
|
|
@@ -17028,13 +17040,19 @@ ${stdinPath === null ? "" : `(function () {
|
|
|
17028
17040
|
}
|
|
17029
17041
|
async function execute(ctx, invocation) {
|
|
17030
17042
|
const { pod } = ctx.kernel;
|
|
17043
|
+
const interactive = ctx.stdin.interactive || ctx.stdin.isTTY;
|
|
17031
17044
|
let exitCode = 0;
|
|
17032
17045
|
try {
|
|
17033
17046
|
const proc = await pod.spawn("node", [invocation.script], {
|
|
17034
17047
|
cwd: ctx.cwd,
|
|
17035
17048
|
env: { ...ctx.env, PWD: ctx.cwd },
|
|
17036
17049
|
argv: ["/usr/bin/node", invocation.argvPath ?? invocation.script, ...invocation.argv],
|
|
17037
|
-
...invocation.stdinPath ? { stdinPath: invocation.stdinPath } : {}
|
|
17050
|
+
...invocation.stdinPath ? { stdinPath: invocation.stdinPath } : {},
|
|
17051
|
+
/* An interactive caller's input was not captured to a file, so the
|
|
17052
|
+
* program's stdin has to stay open and be fed as it arrives — and be
|
|
17053
|
+
* reported as a terminal, since that is what decides whether a CLI
|
|
17054
|
+
* prompts or takes its defaults. */
|
|
17055
|
+
...interactive ? { interactiveStdin: true, tty: true } : {}
|
|
17038
17056
|
});
|
|
17039
17057
|
proc.on("output", (chunk) => {
|
|
17040
17058
|
try {
|
|
@@ -17048,13 +17066,19 @@ async function execute(ctx, invocation) {
|
|
|
17048
17066
|
} catch {
|
|
17049
17067
|
}
|
|
17050
17068
|
});
|
|
17069
|
+
proc.on("rawmode", (enabled) => {
|
|
17070
|
+
ctx.stdin.rawMode = enabled;
|
|
17071
|
+
});
|
|
17051
17072
|
let forwarding = false;
|
|
17052
|
-
if (
|
|
17073
|
+
if (interactive) {
|
|
17053
17074
|
forwarding = true;
|
|
17054
17075
|
void (async () => {
|
|
17055
17076
|
while (forwarding) {
|
|
17056
17077
|
const chunk = await ctx.stdin.read();
|
|
17057
|
-
if (chunk === null)
|
|
17078
|
+
if (chunk === null) {
|
|
17079
|
+
proc.endInput?.();
|
|
17080
|
+
break;
|
|
17081
|
+
}
|
|
17058
17082
|
try {
|
|
17059
17083
|
proc.write(new TextDecoder().decode(chunk));
|
|
17060
17084
|
} catch {
|
|
@@ -17095,10 +17119,10 @@ async function execute(ctx, invocation) {
|
|
|
17095
17119
|
}
|
|
17096
17120
|
async function captureStdin(ctx) {
|
|
17097
17121
|
if (ctx.stdin.isTTY || ctx.stdin.interactive) return null;
|
|
17098
|
-
const
|
|
17099
|
-
if (
|
|
17122
|
+
const bytes2 = await ctx.stdin.readAll();
|
|
17123
|
+
if (bytes2.length === 0) return null;
|
|
17100
17124
|
const path = tempPath("stdin", ctx.proc.pid, ".dat");
|
|
17101
|
-
ctx.vfs.writeFile(path,
|
|
17125
|
+
ctx.vfs.writeFile(path, bytes2, { privileged: true, mode: 384 });
|
|
17102
17126
|
return path;
|
|
17103
17127
|
}
|
|
17104
17128
|
var node = defineCommand({
|
|
@@ -17233,8 +17257,8 @@ ${prelude}${source}
|
|
|
17233
17257
|
`;
|
|
17234
17258
|
}
|
|
17235
17259
|
function resolveScript(ctx, operand) {
|
|
17236
|
-
const
|
|
17237
|
-
const candidates = [
|
|
17260
|
+
const base2 = ctx.path(operand);
|
|
17261
|
+
const candidates = [base2, `${base2}.js`, `${base2}.mjs`, `${base2}.cjs`, `${base2}.json`];
|
|
17238
17262
|
for (const candidate of candidates) {
|
|
17239
17263
|
try {
|
|
17240
17264
|
const st = ctx.vfs.stat(candidate, { cred: ctx.cred });
|
|
@@ -17811,12 +17835,12 @@ async function runCPythonProgram(ctx, source, argv, scriptDir, stdinText) {
|
|
|
17811
17835
|
}
|
|
17812
17836
|
});
|
|
17813
17837
|
if (stdinText !== null) {
|
|
17814
|
-
const
|
|
17838
|
+
const bytes2 = encoder7.encode(stdinText);
|
|
17815
17839
|
let offset = 0;
|
|
17816
17840
|
py.setStdin({
|
|
17817
17841
|
read: (buffer) => {
|
|
17818
|
-
const take = Math.min(buffer.length,
|
|
17819
|
-
buffer.set(
|
|
17842
|
+
const take = Math.min(buffer.length, bytes2.length - offset);
|
|
17843
|
+
buffer.set(bytes2.subarray(offset, offset + take));
|
|
17820
17844
|
offset += take;
|
|
17821
17845
|
return take;
|
|
17822
17846
|
}
|
|
@@ -17958,8 +17982,8 @@ function configurePython(options = {}) {
|
|
|
17958
17982
|
var isPythonAvailable = isCPythonAvailable;
|
|
17959
17983
|
async function readStdin(ctx) {
|
|
17960
17984
|
if (ctx.stdin.isTTY || ctx.stdin.interactive) return null;
|
|
17961
|
-
const
|
|
17962
|
-
return
|
|
17985
|
+
const bytes2 = await ctx.stdin.readAll();
|
|
17986
|
+
return bytes2.length ? new TextDecoder().decode(bytes2) : null;
|
|
17963
17987
|
}
|
|
17964
17988
|
var python = defineCommand({
|
|
17965
17989
|
name: "python3",
|
|
@@ -18070,17 +18094,17 @@ async function loadFactory() {
|
|
|
18070
18094
|
}
|
|
18071
18095
|
const wasmPath = require2.resolve("@ffmpeg/core/wasm");
|
|
18072
18096
|
const wasm = await fs.readFile(wasmPath);
|
|
18073
|
-
const module = await
|
|
18097
|
+
const module = await nodeOnlyModule("@ffmpeg/core");
|
|
18074
18098
|
return { factory: module.default, wasm: new Uint8Array(wasm) };
|
|
18075
18099
|
}
|
|
18076
18100
|
function getCompiled() {
|
|
18077
18101
|
compiled ??= (async () => {
|
|
18078
18102
|
const { factory, wasm } = await loadFactory();
|
|
18079
|
-
const
|
|
18103
|
+
const bytes2 = wasm.buffer.slice(
|
|
18080
18104
|
wasm.byteOffset,
|
|
18081
18105
|
wasm.byteOffset + wasm.byteLength
|
|
18082
18106
|
);
|
|
18083
|
-
return { factory, module: await WebAssembly.compile(
|
|
18107
|
+
return { factory, module: await WebAssembly.compile(bytes2) };
|
|
18084
18108
|
})();
|
|
18085
18109
|
void compiled.catch(() => compiled = null);
|
|
18086
18110
|
return compiled;
|
|
@@ -18155,6 +18179,8 @@ var ffprobe = defineCommand({
|
|
|
18155
18179
|
function ffmpegCommands() {
|
|
18156
18180
|
return [ffmpeg, ffprobe];
|
|
18157
18181
|
}
|
|
18182
|
+
var platformBuffer = globalThis.Buffer;
|
|
18183
|
+
var Buffer2 = platformBuffer ?? index_js.Buffer;
|
|
18158
18184
|
|
|
18159
18185
|
// src/pkg/clean-installer.ts
|
|
18160
18186
|
init_path();
|
|
@@ -18198,8 +18224,8 @@ var CleanPackageInstaller = class _CleanPackageInstaller {
|
|
|
18198
18224
|
if (!manifest) throw new Error(`No matching version found for ${name}@${range}`);
|
|
18199
18225
|
const identity = `${name}@${version}`;
|
|
18200
18226
|
const target = join(modulesRoot, name);
|
|
18201
|
-
const
|
|
18202
|
-
if (
|
|
18227
|
+
const installed2 = this.tryReadJson(join(target, "package.json"));
|
|
18228
|
+
if (installed2?.version === version) return installed2;
|
|
18203
18229
|
if (ancestry.has(identity)) return manifest;
|
|
18204
18230
|
options.onProgress?.(`Fetching ${identity}`);
|
|
18205
18231
|
const archive = await this.getTarball(manifest.dist.tarball);
|
|
@@ -18291,8 +18317,8 @@ var CleanPackageInstaller = class _CleanPackageInstaller {
|
|
|
18291
18317
|
}
|
|
18292
18318
|
};
|
|
18293
18319
|
function resolveVersion(metadata, range) {
|
|
18294
|
-
const
|
|
18295
|
-
if (
|
|
18320
|
+
const tag2 = metadata["dist-tags"]?.[range];
|
|
18321
|
+
if (tag2) return tag2;
|
|
18296
18322
|
if (semver.valid(range) && metadata.versions[range]) return range;
|
|
18297
18323
|
const found = semver.maxSatisfying(Object.keys(metadata.versions), range === "latest" ? "*" : range, { includePrerelease: false });
|
|
18298
18324
|
if (!found) throw new Error(`No matching version found for ${metadata.name}@${range}`);
|
|
@@ -18306,11 +18332,11 @@ function verifyIntegrity(data, integrity, shasum, identity) {
|
|
|
18306
18332
|
const algorithm = choice.slice(0, dash);
|
|
18307
18333
|
const expected = choice.slice(dash + 1).replace(/\?.*$/, "");
|
|
18308
18334
|
const digest = algorithm === "sha512" ? sha512.sha512(data) : algorithm === "sha256" ? sha256.sha256(data) : null;
|
|
18309
|
-
if (digest &&
|
|
18335
|
+
if (digest && Buffer2.from(digest).toString("base64") === expected) return;
|
|
18310
18336
|
}
|
|
18311
18337
|
throw new Error(`Integrity check failed for ${identity}`);
|
|
18312
18338
|
}
|
|
18313
|
-
if (shasum &&
|
|
18339
|
+
if (shasum && Buffer2.from(sha1.sha1(data)).toString("hex") === shasum) return;
|
|
18314
18340
|
if (shasum) throw new Error(`Legacy checksum check failed for ${identity}`);
|
|
18315
18341
|
}
|
|
18316
18342
|
function extractNpmTarball(volume, compressed, destination) {
|
|
@@ -18376,11 +18402,11 @@ function safeTarget(destination, name) {
|
|
|
18376
18402
|
function stripPackageRoot(name) {
|
|
18377
18403
|
return name.replace(/^\.\//, "").replace(/^package\//, "").replace(/\/$/, "");
|
|
18378
18404
|
}
|
|
18379
|
-
function text(
|
|
18380
|
-
return new TextDecoder().decode(
|
|
18405
|
+
function text(bytes2, start2, length) {
|
|
18406
|
+
return new TextDecoder().decode(bytes2.subarray(start2, start2 + length)).replace(/\0.*$/, "").trim();
|
|
18381
18407
|
}
|
|
18382
|
-
function octal(
|
|
18383
|
-
return parseInt(text(
|
|
18408
|
+
function octal(bytes2, start2, length) {
|
|
18409
|
+
return parseInt(text(bytes2, start2, length).replace(/^0+/, "") || "0", 8);
|
|
18384
18410
|
}
|
|
18385
18411
|
function parsePax(data) {
|
|
18386
18412
|
const value = new TextDecoder().decode(data);
|
|
@@ -18392,8 +18418,8 @@ function parsePax(data) {
|
|
|
18392
18418
|
const length = Number(value.slice(offset, space));
|
|
18393
18419
|
if (!Number.isFinite(length) || length <= 0) break;
|
|
18394
18420
|
const record = value.slice(space + 1, offset + length - 1);
|
|
18395
|
-
const
|
|
18396
|
-
if (
|
|
18421
|
+
const equal2 = record.indexOf("=");
|
|
18422
|
+
if (equal2 > 0) result[record.slice(0, equal2)] = record.slice(equal2 + 1);
|
|
18397
18423
|
offset += length;
|
|
18398
18424
|
}
|
|
18399
18425
|
return result;
|
|
@@ -18967,6 +18993,13 @@ function findLocalBin(ctx, name) {
|
|
|
18967
18993
|
}
|
|
18968
18994
|
async function runInitializer(ctx, args) {
|
|
18969
18995
|
const [spec, ...rest] = args;
|
|
18996
|
+
if (!spec) {
|
|
18997
|
+
ctx.warn("npm create <initializer>");
|
|
18998
|
+
ctx.warn("");
|
|
18999
|
+
ctx.warn("Runs the package `create-<initializer>`, installing it if needed.");
|
|
19000
|
+
ctx.warn("Example: npm create vite@latest my-app");
|
|
19001
|
+
return 1;
|
|
19002
|
+
}
|
|
18970
19003
|
const { name, version } = splitPackageSpec(spec);
|
|
18971
19004
|
const suffix = version ? `@${version}` : "";
|
|
18972
19005
|
let packageName;
|
|
@@ -19069,12 +19102,12 @@ unless the container was created with network: { allowOutbound: true }.`,
|
|
|
19069
19102
|
}
|
|
19070
19103
|
ctx.stderr.write(`npx: installing ${packageSpec}...
|
|
19071
19104
|
`);
|
|
19072
|
-
const
|
|
19105
|
+
const installed2 = await installPackages(ctx, [packageSpec], {
|
|
19073
19106
|
cwd: root,
|
|
19074
19107
|
save: false,
|
|
19075
19108
|
quiet: true
|
|
19076
19109
|
});
|
|
19077
|
-
if (
|
|
19110
|
+
if (installed2 !== 0) return installed2;
|
|
19078
19111
|
if (!findLocalBin(ctx, command)) {
|
|
19079
19112
|
const binaries = packageBinaries(ctx, root, packageName);
|
|
19080
19113
|
const chosen = binaries.includes(command) ? command : binaries[0];
|
|
@@ -19303,8 +19336,8 @@ var ContainerFs = class {
|
|
|
19303
19336
|
return this.kernel.vfs;
|
|
19304
19337
|
}
|
|
19305
19338
|
async readFile(path, encoding) {
|
|
19306
|
-
const
|
|
19307
|
-
return encoding ? new TextDecoder().decode(
|
|
19339
|
+
const bytes2 = this.vfs.readFile(clean(path));
|
|
19340
|
+
return encoding ? new TextDecoder().decode(bytes2) : bytes2;
|
|
19308
19341
|
}
|
|
19309
19342
|
async writeFile(path, data, opts = {}) {
|
|
19310
19343
|
const abs = clean(path);
|
|
@@ -20052,6 +20085,18 @@ var CommonJsEngine = class {
|
|
|
20052
20085
|
main = null;
|
|
20053
20086
|
/** `package.json` per directory; resolution reads them constantly. */
|
|
20054
20087
|
manifests = /* @__PURE__ */ new Map();
|
|
20088
|
+
evaluationDepth = 0;
|
|
20089
|
+
/**
|
|
20090
|
+
* Is a module body running synchronously right now?
|
|
20091
|
+
*
|
|
20092
|
+
* `process.exit` unwinds by throwing, and that is only safe while one of
|
|
20093
|
+
* this engine's own frames is on the stack to catch it. Thrown from a later
|
|
20094
|
+
* callback — a stream handler, a timer — it would escape into whichever
|
|
20095
|
+
* library called that callback and surface as an unrelated crash.
|
|
20096
|
+
*/
|
|
20097
|
+
get isEvaluating() {
|
|
20098
|
+
return this.evaluationDepth > 0;
|
|
20099
|
+
}
|
|
20055
20100
|
/**
|
|
20056
20101
|
* Evaluate an entry point.
|
|
20057
20102
|
*
|
|
@@ -20097,8 +20142,8 @@ var CommonJsEngine = class {
|
|
|
20097
20142
|
throw this.moduleNotFound(specifier, importer);
|
|
20098
20143
|
}
|
|
20099
20144
|
load(filename, parent, isMain) {
|
|
20100
|
-
const
|
|
20101
|
-
if (
|
|
20145
|
+
const cached = this.cache.get(filename);
|
|
20146
|
+
if (cached) return cached;
|
|
20102
20147
|
const module = {
|
|
20103
20148
|
id: isMain ? "." : filename,
|
|
20104
20149
|
filename,
|
|
@@ -20157,7 +20202,13 @@ ${code}
|
|
|
20157
20202
|
};
|
|
20158
20203
|
//# sourceURL=sandboxedjs:${module.filename}`
|
|
20159
20204
|
)(this.globals);
|
|
20160
|
-
|
|
20205
|
+
this.evaluationDepth++;
|
|
20206
|
+
let result;
|
|
20207
|
+
try {
|
|
20208
|
+
result = factory(...bindings.map(([, value]) => value));
|
|
20209
|
+
} finally {
|
|
20210
|
+
this.evaluationDepth--;
|
|
20211
|
+
}
|
|
20161
20212
|
if (transformed?.topLevelAwait) module.pending = Promise.resolve(result).then(() => {
|
|
20162
20213
|
});
|
|
20163
20214
|
}
|
|
@@ -20331,8 +20382,8 @@ ${code}
|
|
|
20331
20382
|
}
|
|
20332
20383
|
}
|
|
20333
20384
|
readManifest(root) {
|
|
20334
|
-
const
|
|
20335
|
-
if (
|
|
20385
|
+
const cached = this.manifests.get(root);
|
|
20386
|
+
if (cached !== void 0) return cached;
|
|
20336
20387
|
let manifest = null;
|
|
20337
20388
|
try {
|
|
20338
20389
|
manifest = JSON.parse(this.readText(join(root, "package.json")));
|
|
@@ -20394,8 +20445,8 @@ function namespaceOf(exports) {
|
|
|
20394
20445
|
}
|
|
20395
20446
|
const target = exports;
|
|
20396
20447
|
if (target.__esModule) return target;
|
|
20397
|
-
const
|
|
20398
|
-
if (
|
|
20448
|
+
const cached = namespaces.get(target);
|
|
20449
|
+
if (cached) return cached;
|
|
20399
20450
|
const namespace = {};
|
|
20400
20451
|
for (const key of ownKeys(target)) {
|
|
20401
20452
|
if (key === "default" || key === "__esModule") continue;
|
|
@@ -20454,9 +20505,717 @@ function splitSpecifier(specifier) {
|
|
|
20454
20505
|
return { name: parts.slice(0, size).join("/"), subpath: parts.slice(size).join("/") };
|
|
20455
20506
|
}
|
|
20456
20507
|
|
|
20508
|
+
// src/runtime/util-module.ts
|
|
20509
|
+
var customInspect = /* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom");
|
|
20510
|
+
var promisifyCustom = /* @__PURE__ */ Symbol.for("nodejs.util.promisify.custom");
|
|
20511
|
+
var BREAK_LENGTH = 72;
|
|
20512
|
+
var MAX_ARRAY = 100;
|
|
20513
|
+
function inspect(value, options = {}) {
|
|
20514
|
+
const depth = options.depth === null ? Infinity : options.depth ?? 2;
|
|
20515
|
+
return render(value, depth, /* @__PURE__ */ new Set(), options);
|
|
20516
|
+
}
|
|
20517
|
+
function render(value, depth, seen, options) {
|
|
20518
|
+
switch (typeof value) {
|
|
20519
|
+
case "string":
|
|
20520
|
+
return quote2(value, options.maxStringLength ?? null);
|
|
20521
|
+
case "number":
|
|
20522
|
+
return Object.is(value, -0) ? "-0" : String(value);
|
|
20523
|
+
case "bigint":
|
|
20524
|
+
return `${value}n`;
|
|
20525
|
+
case "boolean":
|
|
20526
|
+
case "undefined":
|
|
20527
|
+
return String(value);
|
|
20528
|
+
case "symbol":
|
|
20529
|
+
return value.toString();
|
|
20530
|
+
case "function":
|
|
20531
|
+
return renderFunction(value);
|
|
20532
|
+
}
|
|
20533
|
+
if (value === null) return "null";
|
|
20534
|
+
const object = value;
|
|
20535
|
+
const custom = object[customInspect];
|
|
20536
|
+
if (typeof custom === "function") {
|
|
20537
|
+
return String(custom.call(object, depth, options));
|
|
20538
|
+
}
|
|
20539
|
+
if (seen.has(object)) return "[Circular *1]";
|
|
20540
|
+
if (depth < 0) return Array.isArray(object) ? "[Array]" : "[Object]";
|
|
20541
|
+
if (value instanceof Error) return renderError(value);
|
|
20542
|
+
if (value instanceof Date) return Number.isNaN(value.getTime()) ? "Invalid Date" : value.toISOString();
|
|
20543
|
+
if (value instanceof RegExp) return String(value);
|
|
20544
|
+
if (Buffer2.isBuffer(value)) return renderBuffer(value);
|
|
20545
|
+
if (ArrayBuffer.isView(value)) return renderTypedArray(value);
|
|
20546
|
+
seen.add(object);
|
|
20547
|
+
try {
|
|
20548
|
+
if (Array.isArray(value)) return wrap(renderArray(value, depth, seen, options), "[", "]");
|
|
20549
|
+
if (value instanceof Map) return prefixed("Map", value.size, renderMap(value, depth, seen, options));
|
|
20550
|
+
if (value instanceof Set) return prefixed("Set", value.size, renderSet(value, depth, seen, options));
|
|
20551
|
+
if (value instanceof Promise) return "Promise { <pending> }";
|
|
20552
|
+
return renderObject(object, depth, seen, options);
|
|
20553
|
+
} finally {
|
|
20554
|
+
seen.delete(object);
|
|
20555
|
+
}
|
|
20556
|
+
}
|
|
20557
|
+
function renderArray(value, depth, seen, options) {
|
|
20558
|
+
const limit = options.maxArrayLength === null ? Infinity : options.maxArrayLength ?? MAX_ARRAY;
|
|
20559
|
+
const shown = value.slice(0, limit).map((item) => render(item, depth - 1, seen, options));
|
|
20560
|
+
const hidden = value.length - shown.length;
|
|
20561
|
+
if (hidden > 0) shown.push(`... ${hidden} more item${hidden === 1 ? "" : "s"}`);
|
|
20562
|
+
return shown;
|
|
20563
|
+
}
|
|
20564
|
+
function renderMap(value, depth, seen, options) {
|
|
20565
|
+
return [...value].map(
|
|
20566
|
+
([key, item]) => `${render(key, depth - 1, seen, options)} => ${render(item, depth - 1, seen, options)}`
|
|
20567
|
+
);
|
|
20568
|
+
}
|
|
20569
|
+
function renderSet(value, depth, seen, options) {
|
|
20570
|
+
return [...value].map((item) => render(item, depth - 1, seen, options));
|
|
20571
|
+
}
|
|
20572
|
+
function renderObject(object, depth, seen, options) {
|
|
20573
|
+
const keys = options.showHidden ? Object.getOwnPropertyNames(object) : Object.keys(object);
|
|
20574
|
+
if (options.sorted) keys.sort();
|
|
20575
|
+
const parts = keys.map((key) => {
|
|
20576
|
+
const descriptor = Object.getOwnPropertyDescriptor(object, key);
|
|
20577
|
+
const rendered = descriptor?.get ? descriptor.set ? "[Getter/Setter]" : "[Getter]" : render(object[key], depth - 1, seen, options);
|
|
20578
|
+
return `${propertyKey(key)}: ${rendered}`;
|
|
20579
|
+
});
|
|
20580
|
+
const name = constructorName(object);
|
|
20581
|
+
return wrap(parts, name ? `${name} {` : "{", "}", name ? void 0 : "{}");
|
|
20582
|
+
}
|
|
20583
|
+
function constructorName(object) {
|
|
20584
|
+
const name = Object.getPrototypeOf(object)?.constructor?.name;
|
|
20585
|
+
if (!name || name === "Object") return null;
|
|
20586
|
+
return name;
|
|
20587
|
+
}
|
|
20588
|
+
function renderError(error) {
|
|
20589
|
+
const base2 = error.stack ?? `${error.name}: ${error.message}`;
|
|
20590
|
+
const extra = Object.keys(error).filter((key) => key !== "message" && key !== "stack");
|
|
20591
|
+
if (extra.length === 0) return base2;
|
|
20592
|
+
return `${base2} { ${extra.map((key) => `${propertyKey(key)}: ${inspect(error[key], { depth: 0 })}`).join(", ")} }`;
|
|
20593
|
+
}
|
|
20594
|
+
function renderFunction(value) {
|
|
20595
|
+
const kind = /^class[\s{]/.test(Function.prototype.toString.call(value)) ? "class" : "Function";
|
|
20596
|
+
return value.name ? `[${kind}: ${value.name}]` : `[${kind} (anonymous)]`;
|
|
20597
|
+
}
|
|
20598
|
+
function renderBuffer(value) {
|
|
20599
|
+
const shown = [...value.subarray(0, 50)].map((byte) => byte.toString(16).padStart(2, "0"));
|
|
20600
|
+
const hidden = value.length - shown.length;
|
|
20601
|
+
const tail2 = hidden > 0 ? ` ... ${hidden} more byte${hidden === 1 ? "" : "s"}` : "";
|
|
20602
|
+
return `<Buffer ${shown.join(" ")}${tail2}>`;
|
|
20603
|
+
}
|
|
20604
|
+
function renderTypedArray(value) {
|
|
20605
|
+
const name = value.constructor?.name ?? "TypedArray";
|
|
20606
|
+
const items = [...value].slice(0, MAX_ARRAY);
|
|
20607
|
+
return `${name}(${value.length}) [ ${items.join(", ")} ]`;
|
|
20608
|
+
}
|
|
20609
|
+
function prefixed(name, size, parts) {
|
|
20610
|
+
return wrap(parts, `${name}(${size}) {`, "}", `${name}(0) {}`);
|
|
20611
|
+
}
|
|
20612
|
+
function wrap(parts, open, close, empty) {
|
|
20613
|
+
if (parts.length === 0) return empty ?? `${open}${close}`;
|
|
20614
|
+
const inline = `${open} ${parts.join(", ")} ${close}`;
|
|
20615
|
+
if (inline.length <= BREAK_LENGTH && !inline.includes("\n")) return inline;
|
|
20616
|
+
const indented = parts.map((part) => ` ${part.split("\n").join("\n ")}`);
|
|
20617
|
+
return `${open}
|
|
20618
|
+
${indented.join(",\n")}
|
|
20619
|
+
${close}`;
|
|
20620
|
+
}
|
|
20621
|
+
function quote2(value, maxLength) {
|
|
20622
|
+
let text2 = value;
|
|
20623
|
+
let tail2 = "";
|
|
20624
|
+
if (maxLength !== null && text2.length > maxLength) {
|
|
20625
|
+
tail2 = `... ${text2.length - maxLength} more character${text2.length - maxLength === 1 ? "" : "s"}`;
|
|
20626
|
+
text2 = text2.slice(0, maxLength);
|
|
20627
|
+
}
|
|
20628
|
+
const escaped = text2.replace(/\\/g, "\\\\").replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/\t/g, "\\t").replace(/'/g, "\\'");
|
|
20629
|
+
return `'${escaped}'${tail2}`;
|
|
20630
|
+
}
|
|
20631
|
+
function propertyKey(key) {
|
|
20632
|
+
return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(key) ? key : quote2(key, null);
|
|
20633
|
+
}
|
|
20634
|
+
function format(...args) {
|
|
20635
|
+
return formatWithOptions({}, ...args);
|
|
20636
|
+
}
|
|
20637
|
+
function formatWithOptions(options, ...args) {
|
|
20638
|
+
const [first, ...rest] = args;
|
|
20639
|
+
const pieces = [];
|
|
20640
|
+
let index = 0;
|
|
20641
|
+
if (typeof first === "string" && first.includes("%")) {
|
|
20642
|
+
pieces.push(
|
|
20643
|
+
first.replace(/%([sdifjoOc%])/g, (match2, kind) => {
|
|
20644
|
+
if (kind === "%") return "%";
|
|
20645
|
+
if (index >= rest.length) return match2;
|
|
20646
|
+
const value = rest[index++];
|
|
20647
|
+
switch (kind) {
|
|
20648
|
+
case "s":
|
|
20649
|
+
return typeof value === "string" ? value : typeof value === "bigint" ? `${value}n` : typeof value === "object" && value !== null ? inspect(value, { ...options, depth: 0 }) : String(value);
|
|
20650
|
+
case "d":
|
|
20651
|
+
return typeof value === "bigint" ? `${value}n` : String(Number(value));
|
|
20652
|
+
case "i":
|
|
20653
|
+
return typeof value === "bigint" ? `${value}n` : String(parseInt(String(value), 10));
|
|
20654
|
+
case "f":
|
|
20655
|
+
return String(parseFloat(String(value)));
|
|
20656
|
+
case "j":
|
|
20657
|
+
try {
|
|
20658
|
+
return JSON.stringify(value) ?? "undefined";
|
|
20659
|
+
} catch {
|
|
20660
|
+
return "[Circular]";
|
|
20661
|
+
}
|
|
20662
|
+
case "o":
|
|
20663
|
+
return inspect(value, { ...options, showHidden: true, depth: 4 });
|
|
20664
|
+
case "O":
|
|
20665
|
+
return inspect(value, options);
|
|
20666
|
+
case "c":
|
|
20667
|
+
return "";
|
|
20668
|
+
default:
|
|
20669
|
+
return match2;
|
|
20670
|
+
}
|
|
20671
|
+
})
|
|
20672
|
+
);
|
|
20673
|
+
} else if (first !== void 0 || args.length > 0) {
|
|
20674
|
+
pieces.push(typeof first === "string" ? first : inspect(first, options));
|
|
20675
|
+
}
|
|
20676
|
+
for (; index < rest.length; index++) {
|
|
20677
|
+
const value = rest[index];
|
|
20678
|
+
pieces.push(typeof value === "string" ? value : inspect(value, options));
|
|
20679
|
+
}
|
|
20680
|
+
return pieces.join(" ");
|
|
20681
|
+
}
|
|
20682
|
+
function promisify(original) {
|
|
20683
|
+
if (typeof original !== "function") {
|
|
20684
|
+
throw Object.assign(new TypeError('The "original" argument must be of type function'), {
|
|
20685
|
+
code: "ERR_INVALID_ARG_TYPE"
|
|
20686
|
+
});
|
|
20687
|
+
}
|
|
20688
|
+
const override = original[promisifyCustom];
|
|
20689
|
+
if (typeof override === "function") return override;
|
|
20690
|
+
const wrapped = function(...args) {
|
|
20691
|
+
return new Promise((resolve2, reject) => {
|
|
20692
|
+
original.call(this, ...args, (error, ...values) => {
|
|
20693
|
+
if (error) reject(error);
|
|
20694
|
+
else resolve2(values.length > 1 ? values : values[0]);
|
|
20695
|
+
});
|
|
20696
|
+
});
|
|
20697
|
+
};
|
|
20698
|
+
Object.setPrototypeOf(wrapped, Object.getPrototypeOf(original));
|
|
20699
|
+
Object.defineProperty(wrapped, "name", { value: original.name, configurable: true });
|
|
20700
|
+
return wrapped;
|
|
20701
|
+
}
|
|
20702
|
+
promisify.custom = promisifyCustom;
|
|
20703
|
+
function callbackify(original) {
|
|
20704
|
+
return function(...args) {
|
|
20705
|
+
const callback = args.pop();
|
|
20706
|
+
Promise.resolve(original.apply(this, args)).then(
|
|
20707
|
+
(value) => callback(null, value),
|
|
20708
|
+
/* Node guarantees a truthy first argument, so a rejection with a falsy
|
|
20709
|
+
* reason is wrapped rather than passed through as "no error". */
|
|
20710
|
+
(reason) => callback(reason ?? Object.assign(new Error("Promise was rejected with a falsy value"), { reason }))
|
|
20711
|
+
);
|
|
20712
|
+
};
|
|
20713
|
+
}
|
|
20714
|
+
function inherits(constructor, superConstructor) {
|
|
20715
|
+
Object.defineProperty(constructor, "super_", {
|
|
20716
|
+
value: superConstructor,
|
|
20717
|
+
writable: true,
|
|
20718
|
+
configurable: true
|
|
20719
|
+
});
|
|
20720
|
+
Object.setPrototypeOf(constructor.prototype, superConstructor.prototype);
|
|
20721
|
+
}
|
|
20722
|
+
function deprecate(fn, message) {
|
|
20723
|
+
let warned = false;
|
|
20724
|
+
return function(...args) {
|
|
20725
|
+
if (!warned) {
|
|
20726
|
+
warned = true;
|
|
20727
|
+
console.warn(`DeprecationWarning: ${message}`);
|
|
20728
|
+
}
|
|
20729
|
+
return fn.apply(this, args);
|
|
20730
|
+
};
|
|
20731
|
+
}
|
|
20732
|
+
function debuglog(section, callback) {
|
|
20733
|
+
const noop = Object.assign(() => {
|
|
20734
|
+
}, { enabled: false });
|
|
20735
|
+
callback?.(noop);
|
|
20736
|
+
return noop;
|
|
20737
|
+
}
|
|
20738
|
+
var STYLES = {
|
|
20739
|
+
reset: [0, 0],
|
|
20740
|
+
bold: [1, 22],
|
|
20741
|
+
dim: [2, 22],
|
|
20742
|
+
italic: [3, 23],
|
|
20743
|
+
underline: [4, 24],
|
|
20744
|
+
blink: [5, 25],
|
|
20745
|
+
inverse: [7, 27],
|
|
20746
|
+
hidden: [8, 28],
|
|
20747
|
+
strikethrough: [9, 29],
|
|
20748
|
+
doubleunderline: [21, 24],
|
|
20749
|
+
framed: [51, 54],
|
|
20750
|
+
overlined: [53, 55],
|
|
20751
|
+
black: [30, 39],
|
|
20752
|
+
red: [31, 39],
|
|
20753
|
+
green: [32, 39],
|
|
20754
|
+
yellow: [33, 39],
|
|
20755
|
+
blue: [34, 39],
|
|
20756
|
+
magenta: [35, 39],
|
|
20757
|
+
cyan: [36, 39],
|
|
20758
|
+
white: [37, 39],
|
|
20759
|
+
gray: [90, 39],
|
|
20760
|
+
grey: [90, 39],
|
|
20761
|
+
blackBright: [90, 39],
|
|
20762
|
+
redBright: [91, 39],
|
|
20763
|
+
greenBright: [92, 39],
|
|
20764
|
+
yellowBright: [93, 39],
|
|
20765
|
+
blueBright: [94, 39],
|
|
20766
|
+
magentaBright: [95, 39],
|
|
20767
|
+
cyanBright: [96, 39],
|
|
20768
|
+
whiteBright: [97, 39],
|
|
20769
|
+
bgBlack: [40, 49],
|
|
20770
|
+
bgRed: [41, 49],
|
|
20771
|
+
bgGreen: [42, 49],
|
|
20772
|
+
bgYellow: [43, 49],
|
|
20773
|
+
bgBlue: [44, 49],
|
|
20774
|
+
bgMagenta: [45, 49],
|
|
20775
|
+
bgCyan: [46, 49],
|
|
20776
|
+
bgWhite: [47, 49],
|
|
20777
|
+
bgGray: [100, 49],
|
|
20778
|
+
bgGrey: [100, 49],
|
|
20779
|
+
bgBlackBright: [100, 49],
|
|
20780
|
+
bgRedBright: [101, 49],
|
|
20781
|
+
bgGreenBright: [102, 49],
|
|
20782
|
+
bgYellowBright: [103, 49],
|
|
20783
|
+
bgBlueBright: [104, 49],
|
|
20784
|
+
bgMagentaBright: [105, 49],
|
|
20785
|
+
bgCyanBright: [106, 49],
|
|
20786
|
+
bgWhiteBright: [107, 49]
|
|
20787
|
+
};
|
|
20788
|
+
function styleText(format3, text2) {
|
|
20789
|
+
const names = Array.isArray(format3) ? format3 : [format3];
|
|
20790
|
+
let open = "";
|
|
20791
|
+
let close = "";
|
|
20792
|
+
for (const name of names) {
|
|
20793
|
+
const style = STYLES[name];
|
|
20794
|
+
if (!style) {
|
|
20795
|
+
throw Object.assign(new TypeError(`The value "${name}" is invalid for argument 'format'`), {
|
|
20796
|
+
code: "ERR_INVALID_ARG_VALUE"
|
|
20797
|
+
});
|
|
20798
|
+
}
|
|
20799
|
+
open += `\x1B[${style[0]}m`;
|
|
20800
|
+
close = `\x1B[${style[1]}m${close}`;
|
|
20801
|
+
}
|
|
20802
|
+
return `${open}${text2}${close}`;
|
|
20803
|
+
}
|
|
20804
|
+
var tag = (value) => Object.prototype.toString.call(value).slice(8, -1);
|
|
20805
|
+
var types = {
|
|
20806
|
+
isPromise: (value) => value instanceof Promise || tag(value) === "Promise",
|
|
20807
|
+
isDate: (value) => tag(value) === "Date",
|
|
20808
|
+
isRegExp: (value) => tag(value) === "RegExp",
|
|
20809
|
+
isMap: (value) => tag(value) === "Map",
|
|
20810
|
+
isSet: (value) => tag(value) === "Set",
|
|
20811
|
+
isTypedArray: (value) => ArrayBuffer.isView(value) && !(value instanceof DataView),
|
|
20812
|
+
isUint8Array: (value) => value instanceof Uint8Array,
|
|
20813
|
+
isArrayBuffer: (value) => tag(value) === "ArrayBuffer",
|
|
20814
|
+
isArrayBufferView: (value) => ArrayBuffer.isView(value),
|
|
20815
|
+
isDataView: (value) => value instanceof DataView,
|
|
20816
|
+
isNativeError: (value) => value instanceof Error,
|
|
20817
|
+
isProxy: () => false,
|
|
20818
|
+
isAsyncFunction: (value) => tag(value) === "AsyncFunction",
|
|
20819
|
+
isGeneratorFunction: (value) => tag(value) === "GeneratorFunction",
|
|
20820
|
+
isBoxedPrimitive: (value) => ["String", "Number", "Boolean", "Symbol", "BigInt"].includes(tag(value)) && typeof value === "object"
|
|
20821
|
+
};
|
|
20822
|
+
function isDeepStrictEqual(a, b) {
|
|
20823
|
+
if (Object.is(a, b)) return true;
|
|
20824
|
+
if (typeof a !== "object" || typeof b !== "object" || a === null || b === null) return false;
|
|
20825
|
+
if (Object.getPrototypeOf(a) !== Object.getPrototypeOf(b)) return false;
|
|
20826
|
+
if (Array.isArray(a)) {
|
|
20827
|
+
const other = b;
|
|
20828
|
+
return a.length === other.length && a.every((item, index) => isDeepStrictEqual(item, other[index]));
|
|
20829
|
+
}
|
|
20830
|
+
if (a instanceof Date) return a.getTime() === b.getTime();
|
|
20831
|
+
if (a instanceof RegExp) return String(a) === String(b);
|
|
20832
|
+
if (ArrayBuffer.isView(a) && ArrayBuffer.isView(b)) {
|
|
20833
|
+
const left = new Uint8Array(a.buffer, a.byteOffset, a.byteLength);
|
|
20834
|
+
const right = new Uint8Array(b.buffer, b.byteOffset, b.byteLength);
|
|
20835
|
+
return left.length === right.length && left.every((byte, index) => byte === right[index]);
|
|
20836
|
+
}
|
|
20837
|
+
const keys = Object.keys(a);
|
|
20838
|
+
if (keys.length !== Object.keys(b).length) return false;
|
|
20839
|
+
return keys.every(
|
|
20840
|
+
(key) => Object.prototype.hasOwnProperty.call(b, key) && isDeepStrictEqual(a[key], b[key])
|
|
20841
|
+
);
|
|
20842
|
+
}
|
|
20843
|
+
var legacy = {
|
|
20844
|
+
isArray: Array.isArray,
|
|
20845
|
+
isBoolean: (value) => typeof value === "boolean",
|
|
20846
|
+
isNull: (value) => value === null,
|
|
20847
|
+
isNullOrUndefined: (value) => value == null,
|
|
20848
|
+
isNumber: (value) => typeof value === "number",
|
|
20849
|
+
isString: (value) => typeof value === "string",
|
|
20850
|
+
isSymbol: (value) => typeof value === "symbol",
|
|
20851
|
+
isUndefined: (value) => value === void 0,
|
|
20852
|
+
isRegExp: types.isRegExp,
|
|
20853
|
+
isObject: (value) => typeof value === "object" && value !== null,
|
|
20854
|
+
isDate: types.isDate,
|
|
20855
|
+
isError: types.isNativeError,
|
|
20856
|
+
isFunction: (value) => typeof value === "function",
|
|
20857
|
+
isPrimitive: (value) => value === null || typeof value !== "object" && typeof value !== "function",
|
|
20858
|
+
isBuffer: (value) => Buffer2.isBuffer(value)
|
|
20859
|
+
};
|
|
20860
|
+
inspect.custom = customInspect;
|
|
20861
|
+
var utilModule = {
|
|
20862
|
+
format,
|
|
20863
|
+
formatWithOptions,
|
|
20864
|
+
inspect,
|
|
20865
|
+
styleText,
|
|
20866
|
+
promisify,
|
|
20867
|
+
callbackify,
|
|
20868
|
+
inherits,
|
|
20869
|
+
deprecate,
|
|
20870
|
+
debuglog,
|
|
20871
|
+
debug: debuglog,
|
|
20872
|
+
types,
|
|
20873
|
+
isDeepStrictEqual,
|
|
20874
|
+
TextEncoder,
|
|
20875
|
+
TextDecoder,
|
|
20876
|
+
toUSVString: (value) => String(value),
|
|
20877
|
+
stripVTControlCharacters: (value) => value.replace(/\x1B\[[0-9;]*[A-Za-z]/g, ""),
|
|
20878
|
+
...legacy
|
|
20879
|
+
};
|
|
20880
|
+
var util_module_default = utilModule;
|
|
20881
|
+
|
|
20882
|
+
// src/runtime/assert-module.ts
|
|
20883
|
+
var AssertionError = class extends Error {
|
|
20884
|
+
actual;
|
|
20885
|
+
expected;
|
|
20886
|
+
operator;
|
|
20887
|
+
generatedMessage;
|
|
20888
|
+
name = "AssertionError";
|
|
20889
|
+
code = "ERR_ASSERTION";
|
|
20890
|
+
constructor(options) {
|
|
20891
|
+
const generated = options.message === void 0;
|
|
20892
|
+
super(options.message ?? describe(options.actual, options.expected, options.operator));
|
|
20893
|
+
this.actual = options.actual;
|
|
20894
|
+
this.expected = options.expected;
|
|
20895
|
+
this.operator = options.operator;
|
|
20896
|
+
this.generatedMessage = generated;
|
|
20897
|
+
}
|
|
20898
|
+
};
|
|
20899
|
+
function describe(actual, expected, operator) {
|
|
20900
|
+
if (operator === "fail") return "Failed";
|
|
20901
|
+
const rendered = (value) => inspect(value, { depth: 2 });
|
|
20902
|
+
return `${rendered(actual)} ${operator} ${rendered(expected)}`;
|
|
20903
|
+
}
|
|
20904
|
+
function fail(actual, expected, message, operator) {
|
|
20905
|
+
if (message instanceof Error) throw message;
|
|
20906
|
+
throw new AssertionError({ actual, expected, operator, ...message === void 0 ? {} : { message } });
|
|
20907
|
+
}
|
|
20908
|
+
function ok(value, message) {
|
|
20909
|
+
if (!value) fail(value, true, message, "==");
|
|
20910
|
+
}
|
|
20911
|
+
var equal = (actual, expected, message) => {
|
|
20912
|
+
if (actual != expected) fail(actual, expected, message, "==");
|
|
20913
|
+
};
|
|
20914
|
+
var notEqual = (actual, expected, message) => {
|
|
20915
|
+
if (actual == expected) fail(actual, expected, message, "!=");
|
|
20916
|
+
};
|
|
20917
|
+
var strictEqual = (actual, expected, message) => {
|
|
20918
|
+
if (!Object.is(actual, expected)) fail(actual, expected, message, "strictEqual");
|
|
20919
|
+
};
|
|
20920
|
+
var notStrictEqual = (actual, expected, message) => {
|
|
20921
|
+
if (Object.is(actual, expected)) fail(actual, expected, message, "notStrictEqual");
|
|
20922
|
+
};
|
|
20923
|
+
var deepStrictEqual = (actual, expected, message) => {
|
|
20924
|
+
if (!isDeepStrictEqual(actual, expected)) fail(actual, expected, message, "deepStrictEqual");
|
|
20925
|
+
};
|
|
20926
|
+
var notDeepStrictEqual = (actual, expected, message) => {
|
|
20927
|
+
if (isDeepStrictEqual(actual, expected)) fail(actual, expected, message, "notDeepStrictEqual");
|
|
20928
|
+
};
|
|
20929
|
+
function looseDeepEqual(a, b) {
|
|
20930
|
+
if (typeof a !== "object" || typeof b !== "object" || a === null || b === null) {
|
|
20931
|
+
return a == b;
|
|
20932
|
+
}
|
|
20933
|
+
if (Array.isArray(a) !== Array.isArray(b)) return false;
|
|
20934
|
+
const keys = Object.keys(a);
|
|
20935
|
+
if (keys.length !== Object.keys(b).length) return false;
|
|
20936
|
+
return keys.every(
|
|
20937
|
+
(key) => looseDeepEqual(a[key], b[key])
|
|
20938
|
+
);
|
|
20939
|
+
}
|
|
20940
|
+
var deepEqual = (actual, expected, message) => {
|
|
20941
|
+
if (!looseDeepEqual(actual, expected)) fail(actual, expected, message, "deepEqual");
|
|
20942
|
+
};
|
|
20943
|
+
var notDeepEqual = (actual, expected, message) => {
|
|
20944
|
+
if (looseDeepEqual(actual, expected)) fail(actual, expected, message, "notDeepEqual");
|
|
20945
|
+
};
|
|
20946
|
+
function matches2(error, expected) {
|
|
20947
|
+
if (expected === void 0) return true;
|
|
20948
|
+
if (expected instanceof RegExp) return expected.test(String(error));
|
|
20949
|
+
if (typeof expected === "function") {
|
|
20950
|
+
if (error instanceof expected) return true;
|
|
20951
|
+
try {
|
|
20952
|
+
return Boolean(expected(error));
|
|
20953
|
+
} catch {
|
|
20954
|
+
return false;
|
|
20955
|
+
}
|
|
20956
|
+
}
|
|
20957
|
+
if (typeof expected === "object" && expected !== null) {
|
|
20958
|
+
return Object.entries(expected).every(
|
|
20959
|
+
([key, value]) => isDeepStrictEqual(error?.[key], value)
|
|
20960
|
+
);
|
|
20961
|
+
}
|
|
20962
|
+
return String(error) === String(expected);
|
|
20963
|
+
}
|
|
20964
|
+
function throws(block, expected, message) {
|
|
20965
|
+
const [error, threw] = capture(block);
|
|
20966
|
+
if (!threw) fail(void 0, expected, message ?? "Missing expected exception.", "throws");
|
|
20967
|
+
if (!matches2(error, expected)) throw error;
|
|
20968
|
+
}
|
|
20969
|
+
function doesNotThrow(block, expected, message) {
|
|
20970
|
+
const [error, threw] = capture(block);
|
|
20971
|
+
if (!threw) return;
|
|
20972
|
+
if (matches2(error, expected)) {
|
|
20973
|
+
fail(error, expected, message ?? "Got unwanted exception.", "doesNotThrow");
|
|
20974
|
+
}
|
|
20975
|
+
throw error;
|
|
20976
|
+
}
|
|
20977
|
+
async function rejects(block, expected, message) {
|
|
20978
|
+
const [error, threw] = await captureAsync(block);
|
|
20979
|
+
if (!threw) fail(void 0, expected, message ?? "Missing expected rejection.", "rejects");
|
|
20980
|
+
if (!matches2(error, expected)) throw error;
|
|
20981
|
+
}
|
|
20982
|
+
async function doesNotReject(block, expected, message) {
|
|
20983
|
+
const [error, threw] = await captureAsync(block);
|
|
20984
|
+
if (!threw) return;
|
|
20985
|
+
if (matches2(error, expected)) {
|
|
20986
|
+
fail(error, expected, message ?? "Got unwanted rejection.", "doesNotReject");
|
|
20987
|
+
}
|
|
20988
|
+
throw error;
|
|
20989
|
+
}
|
|
20990
|
+
function capture(block) {
|
|
20991
|
+
try {
|
|
20992
|
+
block();
|
|
20993
|
+
return [void 0, false];
|
|
20994
|
+
} catch (error) {
|
|
20995
|
+
return [error, true];
|
|
20996
|
+
}
|
|
20997
|
+
}
|
|
20998
|
+
async function captureAsync(block) {
|
|
20999
|
+
try {
|
|
21000
|
+
await (typeof block === "function" ? block() : block);
|
|
21001
|
+
return [void 0, false];
|
|
21002
|
+
} catch (error) {
|
|
21003
|
+
return [error, true];
|
|
21004
|
+
}
|
|
21005
|
+
}
|
|
21006
|
+
var match = (value, pattern, message) => {
|
|
21007
|
+
if (!pattern.test(value)) fail(value, pattern, message, "match");
|
|
21008
|
+
};
|
|
21009
|
+
var doesNotMatch = (value, pattern, message) => {
|
|
21010
|
+
if (pattern.test(value)) fail(value, pattern, message, "doesNotMatch");
|
|
21011
|
+
};
|
|
21012
|
+
var ifError = (value) => {
|
|
21013
|
+
if (value === null || value === void 0) return;
|
|
21014
|
+
if (value instanceof Error) throw value;
|
|
21015
|
+
fail(value, null, void 0, "ifError");
|
|
21016
|
+
};
|
|
21017
|
+
var base = {
|
|
21018
|
+
AssertionError,
|
|
21019
|
+
ok,
|
|
21020
|
+
equal,
|
|
21021
|
+
notEqual,
|
|
21022
|
+
strictEqual,
|
|
21023
|
+
notStrictEqual,
|
|
21024
|
+
deepEqual,
|
|
21025
|
+
notDeepEqual,
|
|
21026
|
+
deepStrictEqual,
|
|
21027
|
+
notDeepStrictEqual,
|
|
21028
|
+
throws,
|
|
21029
|
+
doesNotThrow,
|
|
21030
|
+
rejects,
|
|
21031
|
+
doesNotReject,
|
|
21032
|
+
match,
|
|
21033
|
+
doesNotMatch,
|
|
21034
|
+
ifError,
|
|
21035
|
+
fail: (message) => fail(void 0, void 0, message, "fail")
|
|
21036
|
+
};
|
|
21037
|
+
var assertModule = Object.assign(ok, base, {
|
|
21038
|
+
strict: Object.assign(ok, base, {
|
|
21039
|
+
equal: strictEqual,
|
|
21040
|
+
notEqual: notStrictEqual,
|
|
21041
|
+
deepEqual: deepStrictEqual,
|
|
21042
|
+
notDeepEqual: notDeepStrictEqual
|
|
21043
|
+
})
|
|
21044
|
+
});
|
|
21045
|
+
var assert_module_default = assertModule;
|
|
21046
|
+
var bytes = (data) => {
|
|
21047
|
+
if (typeof data === "string") return new Uint8Array(Buffer2.from(data, "utf8"));
|
|
21048
|
+
if (data instanceof ArrayBuffer) return new Uint8Array(data);
|
|
21049
|
+
return data;
|
|
21050
|
+
};
|
|
21051
|
+
function codec(name, run) {
|
|
21052
|
+
const sync2 = (data, options) => Buffer2.from(run(bytes(data), options));
|
|
21053
|
+
const async_ = (data, options, callback) => {
|
|
21054
|
+
const done = typeof options === "function" ? options : callback;
|
|
21055
|
+
const settings = typeof options === "function" ? void 0 : options;
|
|
21056
|
+
queueMicrotask(() => {
|
|
21057
|
+
try {
|
|
21058
|
+
done(null, sync2(data, settings));
|
|
21059
|
+
} catch (error) {
|
|
21060
|
+
done(error);
|
|
21061
|
+
}
|
|
21062
|
+
});
|
|
21063
|
+
};
|
|
21064
|
+
const Stream = class extends streamModule4__default.default.Transform {
|
|
21065
|
+
chunks = [];
|
|
21066
|
+
options;
|
|
21067
|
+
constructor(options) {
|
|
21068
|
+
super();
|
|
21069
|
+
this.options = options;
|
|
21070
|
+
}
|
|
21071
|
+
_transform(chunk, _encoding, next) {
|
|
21072
|
+
this.chunks.push(Buffer2.from(chunk));
|
|
21073
|
+
next();
|
|
21074
|
+
}
|
|
21075
|
+
_flush(next) {
|
|
21076
|
+
try {
|
|
21077
|
+
this.push(sync2(Buffer2.concat(this.chunks), this.options));
|
|
21078
|
+
next();
|
|
21079
|
+
} catch (error) {
|
|
21080
|
+
next(error);
|
|
21081
|
+
}
|
|
21082
|
+
}
|
|
21083
|
+
};
|
|
21084
|
+
Object.defineProperty(Stream, "name", { value: name });
|
|
21085
|
+
return { sync: sync2, async: async_, Stream };
|
|
21086
|
+
}
|
|
21087
|
+
var gzipCodec = codec("Gzip", (input, options) => pako.gzip(input, options));
|
|
21088
|
+
var gunzipCodec = codec("Gunzip", (input) => pako.ungzip(input));
|
|
21089
|
+
var deflateCodec = codec("Deflate", (input, options) => pako.deflate(input, options));
|
|
21090
|
+
var inflateCodec = codec("Inflate", (input) => pako.inflate(input));
|
|
21091
|
+
var deflateRawCodec = codec("DeflateRaw", (input, options) => pako.deflateRaw(input, options));
|
|
21092
|
+
var inflateRawCodec = codec("InflateRaw", (input) => pako.inflateRaw(input));
|
|
21093
|
+
var unzipCodec = codec(
|
|
21094
|
+
"Unzip",
|
|
21095
|
+
(input) => input[0] === 31 && input[1] === 139 ? pako.ungzip(input) : pako.inflate(input)
|
|
21096
|
+
);
|
|
21097
|
+
function brotliUnavailable(name) {
|
|
21098
|
+
const error = new Error(
|
|
21099
|
+
`zlib.${name} is unavailable: the sandboxed runtime has no Brotli implementation.`
|
|
21100
|
+
);
|
|
21101
|
+
error.code = "ERR_FEATURE_UNAVAILABLE_ON_PLATFORM";
|
|
21102
|
+
throw error;
|
|
21103
|
+
}
|
|
21104
|
+
var zlibModule = {
|
|
21105
|
+
gzipSync: gzipCodec.sync,
|
|
21106
|
+
gzip: gzipCodec.async,
|
|
21107
|
+
createGzip: (o) => new gzipCodec.Stream(o),
|
|
21108
|
+
gunzipSync: gunzipCodec.sync,
|
|
21109
|
+
gunzip: gunzipCodec.async,
|
|
21110
|
+
createGunzip: (o) => new gunzipCodec.Stream(o),
|
|
21111
|
+
deflateSync: deflateCodec.sync,
|
|
21112
|
+
deflate: deflateCodec.async,
|
|
21113
|
+
createDeflate: (o) => new deflateCodec.Stream(o),
|
|
21114
|
+
inflateSync: inflateCodec.sync,
|
|
21115
|
+
inflate: inflateCodec.async,
|
|
21116
|
+
createInflate: (o) => new inflateCodec.Stream(o),
|
|
21117
|
+
deflateRawSync: deflateRawCodec.sync,
|
|
21118
|
+
deflateRaw: deflateRawCodec.async,
|
|
21119
|
+
createDeflateRaw: (o) => new deflateRawCodec.Stream(o),
|
|
21120
|
+
inflateRawSync: inflateRawCodec.sync,
|
|
21121
|
+
inflateRaw: inflateRawCodec.async,
|
|
21122
|
+
createInflateRaw: (o) => new inflateRawCodec.Stream(o),
|
|
21123
|
+
unzipSync: unzipCodec.sync,
|
|
21124
|
+
unzip: unzipCodec.async,
|
|
21125
|
+
createUnzip: (o) => new unzipCodec.Stream(o),
|
|
21126
|
+
brotliCompressSync: () => brotliUnavailable("brotliCompressSync"),
|
|
21127
|
+
brotliDecompressSync: () => brotliUnavailable("brotliDecompressSync"),
|
|
21128
|
+
brotliCompress: () => brotliUnavailable("brotliCompress"),
|
|
21129
|
+
brotliDecompress: () => brotliUnavailable("brotliDecompress"),
|
|
21130
|
+
createBrotliCompress: () => brotliUnavailable("createBrotliCompress"),
|
|
21131
|
+
createBrotliDecompress: () => brotliUnavailable("createBrotliDecompress"),
|
|
21132
|
+
constants: {
|
|
21133
|
+
Z_NO_FLUSH: 0,
|
|
21134
|
+
Z_PARTIAL_FLUSH: 1,
|
|
21135
|
+
Z_SYNC_FLUSH: 2,
|
|
21136
|
+
Z_FULL_FLUSH: 3,
|
|
21137
|
+
Z_FINISH: 4,
|
|
21138
|
+
Z_BLOCK: 5,
|
|
21139
|
+
Z_TREES: 6,
|
|
21140
|
+
Z_OK: 0,
|
|
21141
|
+
Z_STREAM_END: 1,
|
|
21142
|
+
Z_NEED_DICT: 2,
|
|
21143
|
+
Z_ERRNO: -1,
|
|
21144
|
+
Z_STREAM_ERROR: -2,
|
|
21145
|
+
Z_DATA_ERROR: -3,
|
|
21146
|
+
Z_MEM_ERROR: -4,
|
|
21147
|
+
Z_BUF_ERROR: -5,
|
|
21148
|
+
Z_VERSION_ERROR: -6,
|
|
21149
|
+
Z_NO_COMPRESSION: 0,
|
|
21150
|
+
Z_BEST_SPEED: 1,
|
|
21151
|
+
Z_BEST_COMPRESSION: 9,
|
|
21152
|
+
Z_DEFAULT_COMPRESSION: -1,
|
|
21153
|
+
Z_FILTERED: 1,
|
|
21154
|
+
Z_HUFFMAN_ONLY: 2,
|
|
21155
|
+
Z_RLE: 3,
|
|
21156
|
+
Z_FIXED: 4,
|
|
21157
|
+
Z_DEFAULT_STRATEGY: 0,
|
|
21158
|
+
DEFLATE: 1,
|
|
21159
|
+
INFLATE: 2,
|
|
21160
|
+
GZIP: 3,
|
|
21161
|
+
GUNZIP: 4,
|
|
21162
|
+
DEFLATERAW: 5,
|
|
21163
|
+
INFLATERAW: 6,
|
|
21164
|
+
UNZIP: 7
|
|
21165
|
+
}
|
|
21166
|
+
};
|
|
21167
|
+
var zlib_module_default = zlibModule;
|
|
21168
|
+
function fileURLToPath(url) {
|
|
21169
|
+
const value = typeof url === "string" ? new URL(url) : url;
|
|
21170
|
+
if (value.protocol !== "file:") {
|
|
21171
|
+
throw Object.assign(new TypeError("The URL must be of scheme file"), {
|
|
21172
|
+
code: "ERR_INVALID_URL_SCHEME"
|
|
21173
|
+
});
|
|
21174
|
+
}
|
|
21175
|
+
return decodeURIComponent(value.pathname);
|
|
21176
|
+
}
|
|
21177
|
+
function pathToFileURL(path) {
|
|
21178
|
+
const escaped = path.replace(/%/g, "%25").replace(/\\/g, "%5C").replace(/\n/g, "%0A").replace(/\r/g, "%0D").replace(/\t/g, "%09").replace(/ /g, "%20").replace(/#/g, "%23").replace(/\?/g, "%3F");
|
|
21179
|
+
return new URL(`file://${escaped.startsWith("/") ? "" : "/"}${escaped}`);
|
|
21180
|
+
}
|
|
21181
|
+
function format2(value, options) {
|
|
21182
|
+
if (!(value instanceof URL)) return legacyUrl__default.default.format(value);
|
|
21183
|
+
const url = new URL(value.href);
|
|
21184
|
+
if (options?.auth === false) {
|
|
21185
|
+
url.username = "";
|
|
21186
|
+
url.password = "";
|
|
21187
|
+
}
|
|
21188
|
+
if (options?.fragment === false) url.hash = "";
|
|
21189
|
+
if (options?.search === false) url.search = "";
|
|
21190
|
+
return url.href;
|
|
21191
|
+
}
|
|
21192
|
+
var urlModule = {
|
|
21193
|
+
...legacyUrl__default.default,
|
|
21194
|
+
format: format2,
|
|
21195
|
+
fileURLToPath,
|
|
21196
|
+
pathToFileURL,
|
|
21197
|
+
URL,
|
|
21198
|
+
URLSearchParams,
|
|
21199
|
+
/** Names here are already Unicode; there is no IDNA table to consult. */
|
|
21200
|
+
domainToASCII: (domain) => domain.toLowerCase(),
|
|
21201
|
+
domainToUnicode: (domain) => domain.toLowerCase(),
|
|
21202
|
+
urlToHttpOptions: (url) => ({
|
|
21203
|
+
protocol: url.protocol,
|
|
21204
|
+
hostname: url.hostname,
|
|
21205
|
+
hash: url.hash,
|
|
21206
|
+
search: url.search,
|
|
21207
|
+
pathname: url.pathname,
|
|
21208
|
+
path: `${url.pathname}${url.search}`,
|
|
21209
|
+
href: url.href,
|
|
21210
|
+
...url.port ? { port: Number(url.port) } : {},
|
|
21211
|
+
...url.username || url.password ? { auth: `${url.username}:${url.password}` } : {}
|
|
21212
|
+
})
|
|
21213
|
+
};
|
|
21214
|
+
var url_module_default = urlModule;
|
|
21215
|
+
|
|
20457
21216
|
// src/runtime/core-modules.ts
|
|
20458
21217
|
init_path();
|
|
20459
|
-
var VirtualIncomingMessage = class extends
|
|
21218
|
+
var VirtualIncomingMessage = class extends streamModule4__default.default.Readable {
|
|
20460
21219
|
method;
|
|
20461
21220
|
url;
|
|
20462
21221
|
headers;
|
|
@@ -20477,7 +21236,7 @@ var VirtualIncomingMessage = class extends streamModule3__default.default.Readab
|
|
|
20477
21236
|
this.headers["content-length"] = String(body.length);
|
|
20478
21237
|
}
|
|
20479
21238
|
this.rawHeaders = Object.entries(this.headers).flatMap(([key, value]) => [key, value]);
|
|
20480
|
-
if (body.length) this.push(
|
|
21239
|
+
if (body.length) this.push(Buffer2.from(body));
|
|
20481
21240
|
this.push(null);
|
|
20482
21241
|
}
|
|
20483
21242
|
_read() {
|
|
@@ -20487,7 +21246,7 @@ var VirtualIncomingMessage = class extends streamModule3__default.default.Readab
|
|
|
20487
21246
|
return this;
|
|
20488
21247
|
}
|
|
20489
21248
|
};
|
|
20490
|
-
var VirtualServerResponse = class extends
|
|
21249
|
+
var VirtualServerResponse = class extends streamModule4__default.default.Writable {
|
|
20491
21250
|
statusCode = 200;
|
|
20492
21251
|
statusMessage = "OK";
|
|
20493
21252
|
headersSent = false;
|
|
@@ -20508,7 +21267,7 @@ var VirtualServerResponse = class extends streamModule3__default.default.Writabl
|
|
|
20508
21267
|
}
|
|
20509
21268
|
_write(chunk, encoding, callback) {
|
|
20510
21269
|
this.headersSent = true;
|
|
20511
|
-
this.chunks.push(
|
|
21270
|
+
this.chunks.push(Buffer2.isBuffer(chunk) ? chunk : Buffer2.from(chunk, encoding));
|
|
20512
21271
|
callback();
|
|
20513
21272
|
}
|
|
20514
21273
|
_final(callback) {
|
|
@@ -20520,7 +21279,7 @@ var VirtualServerResponse = class extends streamModule3__default.default.Writabl
|
|
|
20520
21279
|
statusCode: this.statusCode,
|
|
20521
21280
|
statusMessage: this.statusMessage || STATUS_CODES[this.statusCode] || "",
|
|
20522
21281
|
headers,
|
|
20523
|
-
body: new Uint8Array(
|
|
21282
|
+
body: new Uint8Array(Buffer2.concat(this.chunks))
|
|
20524
21283
|
});
|
|
20525
21284
|
callback();
|
|
20526
21285
|
}
|
|
@@ -20572,7 +21331,7 @@ var VirtualServerResponse = class extends streamModule3__default.default.Writabl
|
|
|
20572
21331
|
return this;
|
|
20573
21332
|
}
|
|
20574
21333
|
};
|
|
20575
|
-
var VirtualHttpServer = class extends
|
|
21334
|
+
var VirtualHttpServer = class extends EventEmitter4__default.default {
|
|
20576
21335
|
constructor(router, owner, listener) {
|
|
20577
21336
|
super();
|
|
20578
21337
|
this.router = router;
|
|
@@ -20696,7 +21455,7 @@ function socketStub() {
|
|
|
20696
21455
|
}
|
|
20697
21456
|
var METHODS = ["ACL", "BIND", "CHECKOUT", "CONNECT", "COPY", "DELETE", "GET", "HEAD", "LINK", "LOCK", "M-SEARCH", "MERGE", "MKACTIVITY", "MKCALENDAR", "MKCOL", "MOVE", "NOTIFY", "OPTIONS", "PATCH", "POST", "PROPFIND", "PROPPATCH", "PURGE", "PUT", "REBIND", "REPORT", "SEARCH", "SOURCE", "SUBSCRIBE", "TRACE", "UNBIND", "UNLINK", "UNLOCK", "UNSUBSCRIBE"];
|
|
20698
21457
|
var STATUS_CODES = { 100: "Continue", 200: "OK", 201: "Created", 202: "Accepted", 204: "No Content", 206: "Partial Content", 301: "Moved Permanently", 302: "Found", 304: "Not Modified", 307: "Temporary Redirect", 308: "Permanent Redirect", 400: "Bad Request", 401: "Unauthorized", 403: "Forbidden", 404: "Not Found", 405: "Method Not Allowed", 409: "Conflict", 413: "Payload Too Large", 415: "Unsupported Media Type", 422: "Unprocessable Entity", 429: "Too Many Requests", 500: "Internal Server Error", 501: "Not Implemented", 502: "Bad Gateway", 503: "Service Unavailable" };
|
|
20699
|
-
var hashes = { md5: legacy.md5, sha1: legacy.sha1, "sha-1": legacy.sha1, sha224: sha256.sha224, "sha-224": sha256.sha224, sha256: sha256.sha256, "sha-256": sha256.sha256, sha384: sha512.sha384, "sha-384": sha512.sha384, sha512: sha512.sha512, "sha-512": sha512.sha512 };
|
|
21458
|
+
var hashes = { md5: legacy$1.md5, sha1: legacy$1.sha1, "sha-1": legacy$1.sha1, sha224: sha256.sha224, "sha-224": sha256.sha224, sha256: sha256.sha256, "sha-256": sha256.sha256, sha384: sha512.sha384, "sha-384": sha512.sha384, sha512: sha512.sha512, "sha-512": sha512.sha512 };
|
|
20700
21459
|
function createCryptoModule() {
|
|
20701
21460
|
const cryptoObject = globalThis.crypto;
|
|
20702
21461
|
return {
|
|
@@ -20708,7 +21467,7 @@ function createCryptoModule() {
|
|
|
20708
21467
|
return api;
|
|
20709
21468
|
},
|
|
20710
21469
|
digest(encoding) {
|
|
20711
|
-
const value =
|
|
21470
|
+
const value = Buffer2.from(hash.digest());
|
|
20712
21471
|
return encoding ? value.toString(encoding) : value;
|
|
20713
21472
|
},
|
|
20714
21473
|
copy() {
|
|
@@ -20726,14 +21485,14 @@ function createCryptoModule() {
|
|
|
20726
21485
|
return api;
|
|
20727
21486
|
},
|
|
20728
21487
|
digest(encoding) {
|
|
20729
|
-
const value =
|
|
21488
|
+
const value = Buffer2.from(state.digest());
|
|
20730
21489
|
return encoding ? value.toString(encoding) : value;
|
|
20731
21490
|
}
|
|
20732
21491
|
};
|
|
20733
21492
|
return api;
|
|
20734
21493
|
},
|
|
20735
21494
|
randomBytes(size, callback) {
|
|
20736
|
-
const value =
|
|
21495
|
+
const value = Buffer2.alloc(size);
|
|
20737
21496
|
cryptoObject.getRandomValues(value);
|
|
20738
21497
|
if (callback) {
|
|
20739
21498
|
queueMicrotask(() => callback(null, value));
|
|
@@ -20760,13 +21519,13 @@ function createCryptoModule() {
|
|
|
20760
21519
|
},
|
|
20761
21520
|
randomFill(target, offset = 0, size, callback) {
|
|
20762
21521
|
const done = [offset, size, callback].find((value) => typeof value === "function");
|
|
20763
|
-
const
|
|
20764
|
-
const length = typeof size === "number" ? size : target.length -
|
|
20765
|
-
cryptoObject.getRandomValues(target.subarray(
|
|
21522
|
+
const start2 = typeof offset === "number" ? offset : 0;
|
|
21523
|
+
const length = typeof size === "number" ? size : target.length - start2;
|
|
21524
|
+
cryptoObject.getRandomValues(target.subarray(start2, start2 + length));
|
|
20766
21525
|
queueMicrotask(() => done?.(null, target));
|
|
20767
21526
|
},
|
|
20768
21527
|
hash(algorithm, data, encoding = "hex") {
|
|
20769
|
-
const digest =
|
|
21528
|
+
const digest = Buffer2.from(hashFor(algorithm)(toBytes2(data)));
|
|
20770
21529
|
return encoding === "buffer" ? digest : digest.toString(encoding);
|
|
20771
21530
|
},
|
|
20772
21531
|
timingSafeEqual(a, b) {
|
|
@@ -20787,11 +21546,11 @@ function hashFor(algorithm) {
|
|
|
20787
21546
|
return hash;
|
|
20788
21547
|
}
|
|
20789
21548
|
function toBytes2(data, encoding) {
|
|
20790
|
-
return typeof data === "string" ?
|
|
21549
|
+
return typeof data === "string" ? Buffer2.from(data, encoding) : data;
|
|
20791
21550
|
}
|
|
20792
|
-
var ChildProcess = class extends
|
|
20793
|
-
stdout = new
|
|
20794
|
-
stderr = new
|
|
21551
|
+
var ChildProcess = class extends EventEmitter4__default.default {
|
|
21552
|
+
stdout = new streamModule4__default.default.PassThrough();
|
|
21553
|
+
stderr = new streamModule4__default.default.PassThrough();
|
|
20795
21554
|
stdin;
|
|
20796
21555
|
stdio;
|
|
20797
21556
|
pid;
|
|
@@ -20808,10 +21567,10 @@ var ChildProcess = class extends EventEmitter3__default.default {
|
|
|
20808
21567
|
this.pid = handle.pid;
|
|
20809
21568
|
this.spawnfile = file3;
|
|
20810
21569
|
this.spawnargs = [file3, ...args];
|
|
20811
|
-
this.stdin = new
|
|
21570
|
+
this.stdin = new streamModule4__default.default.Writable({
|
|
20812
21571
|
write: (chunk, _encoding, done) => {
|
|
20813
21572
|
try {
|
|
20814
|
-
handle.sendStdin(typeof chunk === "string" ? chunk :
|
|
21573
|
+
handle.sendStdin(typeof chunk === "string" ? chunk : Buffer2.from(chunk).toString("utf8"));
|
|
20815
21574
|
} catch {
|
|
20816
21575
|
}
|
|
20817
21576
|
done();
|
|
@@ -20859,7 +21618,7 @@ function createChildProcessModule(spawnChild, defaultCwd) {
|
|
|
20859
21618
|
const shell = typeof options.shell === "string" ? options.shell : "/bin/sh";
|
|
20860
21619
|
return { file: shell, args: ["-c", command] };
|
|
20861
21620
|
};
|
|
20862
|
-
const
|
|
21621
|
+
const start2 = (file3, args, options) => {
|
|
20863
21622
|
const resolved = options.shell ? throughShell([file3, ...args].join(" "), options) : { file: file3, args };
|
|
20864
21623
|
const handle = spawnChild({
|
|
20865
21624
|
command: resolved.file,
|
|
@@ -20870,8 +21629,8 @@ function createChildProcessModule(spawnChild, defaultCwd) {
|
|
|
20870
21629
|
return new ChildProcess(handle, resolved.file, resolved.args);
|
|
20871
21630
|
};
|
|
20872
21631
|
const spawn = (file3, args = [], options = {}) => {
|
|
20873
|
-
if (!Array.isArray(args)) return
|
|
20874
|
-
return
|
|
21632
|
+
if (!Array.isArray(args)) return start2(file3, [], args);
|
|
21633
|
+
return start2(file3, args, options);
|
|
20875
21634
|
};
|
|
20876
21635
|
const collect = (child, options, callback) => {
|
|
20877
21636
|
if (!callback) return child;
|
|
@@ -20881,8 +21640,8 @@ function createChildProcessModule(spawnChild, defaultCwd) {
|
|
|
20881
21640
|
child.stderr.on("data", (chunk) => err.push(String(chunk)));
|
|
20882
21641
|
child.on("close", (code) => {
|
|
20883
21642
|
const asBuffer = options.encoding === "buffer";
|
|
20884
|
-
const stdout = asBuffer ?
|
|
20885
|
-
const stderr = asBuffer ?
|
|
21643
|
+
const stdout = asBuffer ? Buffer2.from(out.join("")) : out.join("");
|
|
21644
|
+
const stderr = asBuffer ? Buffer2.from(err.join("")) : err.join("");
|
|
20886
21645
|
if (code === 0) {
|
|
20887
21646
|
callback(null, stdout, stderr);
|
|
20888
21647
|
return;
|
|
@@ -20899,12 +21658,12 @@ ${err.join("")}`),
|
|
|
20899
21658
|
const exec = (command, options = {}, callback) => {
|
|
20900
21659
|
const [opts, cb] = normalize2(options, callback);
|
|
20901
21660
|
const { file: file3, args } = throughShell(command, opts);
|
|
20902
|
-
return collect(
|
|
21661
|
+
return collect(start2(file3, args, { ...opts, shell: false }), opts, cb);
|
|
20903
21662
|
};
|
|
20904
21663
|
const execFile = (file3, args = [], options = {}, callback) => {
|
|
20905
21664
|
const list = Array.isArray(args) ? args : [];
|
|
20906
21665
|
const [opts, cb] = Array.isArray(args) ? normalize2(options, callback) : normalize2(args, options);
|
|
20907
|
-
return collect(
|
|
21666
|
+
return collect(start2(file3, list, opts), opts, cb);
|
|
20908
21667
|
};
|
|
20909
21668
|
return {
|
|
20910
21669
|
spawn,
|
|
@@ -20933,6 +21692,326 @@ function unavailable(name) {
|
|
|
20933
21692
|
|
|
20934
21693
|
// src/runtime/core-modules.ts
|
|
20935
21694
|
init_signals();
|
|
21695
|
+
var CSI_KEYS = {
|
|
21696
|
+
"[A": "up",
|
|
21697
|
+
"[B": "down",
|
|
21698
|
+
"[C": "right",
|
|
21699
|
+
"[D": "left",
|
|
21700
|
+
"[E": "clear",
|
|
21701
|
+
"[F": "end",
|
|
21702
|
+
"[H": "home",
|
|
21703
|
+
"OA": "up",
|
|
21704
|
+
"OB": "down",
|
|
21705
|
+
"OC": "right",
|
|
21706
|
+
"OD": "left",
|
|
21707
|
+
"OE": "clear",
|
|
21708
|
+
"OF": "end",
|
|
21709
|
+
"OH": "home",
|
|
21710
|
+
"[1~": "home",
|
|
21711
|
+
"[2~": "insert",
|
|
21712
|
+
"[3~": "delete",
|
|
21713
|
+
"[4~": "end",
|
|
21714
|
+
"[5~": "pageup",
|
|
21715
|
+
"[6~": "pagedown",
|
|
21716
|
+
"[7~": "home",
|
|
21717
|
+
"[8~": "end",
|
|
21718
|
+
"[11~": "f1",
|
|
21719
|
+
"[12~": "f2",
|
|
21720
|
+
"[13~": "f3",
|
|
21721
|
+
"[14~": "f4",
|
|
21722
|
+
"[15~": "f5",
|
|
21723
|
+
"[17~": "f6",
|
|
21724
|
+
"[18~": "f7",
|
|
21725
|
+
"[19~": "f8",
|
|
21726
|
+
"[20~": "f9",
|
|
21727
|
+
"[21~": "f10",
|
|
21728
|
+
"[23~": "f11",
|
|
21729
|
+
"[24~": "f12",
|
|
21730
|
+
"OP": "f1",
|
|
21731
|
+
"OQ": "f2",
|
|
21732
|
+
"OR": "f3",
|
|
21733
|
+
"OS": "f4",
|
|
21734
|
+
"[Z": "tab"
|
|
21735
|
+
};
|
|
21736
|
+
var CONTROL_LETTERS = "abcdefghijklmnopqrstuvwxyz";
|
|
21737
|
+
function parseKeys(input) {
|
|
21738
|
+
const keys = [];
|
|
21739
|
+
let index = 0;
|
|
21740
|
+
while (index < input.length) {
|
|
21741
|
+
const char = input[index];
|
|
21742
|
+
if (char === "\x1B") {
|
|
21743
|
+
const rest = input.slice(index + 1);
|
|
21744
|
+
const match2 = /^(\[[0-9;]*[A-Za-z~]|O[A-Za-z])/.exec(rest);
|
|
21745
|
+
if (match2) {
|
|
21746
|
+
const sequence = match2[1];
|
|
21747
|
+
const name = CSI_KEYS[sequence];
|
|
21748
|
+
keys.push({
|
|
21749
|
+
sequence: `\x1B${sequence}`,
|
|
21750
|
+
name: name ?? "undefined",
|
|
21751
|
+
ctrl: false,
|
|
21752
|
+
/* xterm reports modifiers as `;5` (control) and `;2` (shift) before
|
|
21753
|
+
* the final letter. */
|
|
21754
|
+
meta: false,
|
|
21755
|
+
shift: /;2[A-Za-z~]$/.test(sequence),
|
|
21756
|
+
code: sequence
|
|
21757
|
+
});
|
|
21758
|
+
if (/;5[A-Za-z~]$/.test(sequence)) keys[keys.length - 1].ctrl = true;
|
|
21759
|
+
index += 1 + sequence.length;
|
|
21760
|
+
continue;
|
|
21761
|
+
}
|
|
21762
|
+
if (rest.length > 0 && rest[0] !== "\x1B") {
|
|
21763
|
+
const inner = parseKeys(rest[0])[0];
|
|
21764
|
+
if (inner) {
|
|
21765
|
+
keys.push({ ...inner, meta: true, sequence: `\x1B${inner.sequence}` });
|
|
21766
|
+
index += 2;
|
|
21767
|
+
continue;
|
|
21768
|
+
}
|
|
21769
|
+
}
|
|
21770
|
+
keys.push({ sequence: "\x1B", name: "escape", ctrl: false, meta: false, shift: false });
|
|
21771
|
+
index += 1;
|
|
21772
|
+
continue;
|
|
21773
|
+
}
|
|
21774
|
+
keys.push(parseSingle(char));
|
|
21775
|
+
index += 1;
|
|
21776
|
+
}
|
|
21777
|
+
return keys;
|
|
21778
|
+
}
|
|
21779
|
+
function parseSingle(char) {
|
|
21780
|
+
const code = char.charCodeAt(0);
|
|
21781
|
+
if (char === "\r") return { sequence: char, name: "return", ctrl: false, meta: false, shift: false };
|
|
21782
|
+
if (char === "\n") return { sequence: char, name: "enter", ctrl: false, meta: false, shift: false };
|
|
21783
|
+
if (char === " ") return { sequence: char, name: "tab", ctrl: false, meta: false, shift: false };
|
|
21784
|
+
if (char === "\x7F" || char === "\b") {
|
|
21785
|
+
return { sequence: char, name: "backspace", ctrl: false, meta: false, shift: false };
|
|
21786
|
+
}
|
|
21787
|
+
if (char === " ") return { sequence: char, name: "space", ctrl: false, meta: false, shift: false };
|
|
21788
|
+
if (code >= 1 && code <= 26) {
|
|
21789
|
+
return {
|
|
21790
|
+
sequence: char,
|
|
21791
|
+
name: CONTROL_LETTERS[code - 1],
|
|
21792
|
+
ctrl: true,
|
|
21793
|
+
meta: false,
|
|
21794
|
+
shift: false
|
|
21795
|
+
};
|
|
21796
|
+
}
|
|
21797
|
+
return {
|
|
21798
|
+
sequence: char,
|
|
21799
|
+
name: char.toLowerCase(),
|
|
21800
|
+
ctrl: false,
|
|
21801
|
+
meta: false,
|
|
21802
|
+
// An uppercase letter arrived because shift was held.
|
|
21803
|
+
shift: char !== char.toLowerCase()
|
|
21804
|
+
};
|
|
21805
|
+
}
|
|
21806
|
+
function emitKeypressEvents(stream) {
|
|
21807
|
+
if (!stream || stream.__sbxKeypress) return;
|
|
21808
|
+
stream.__sbxKeypress = true;
|
|
21809
|
+
stream.on("data", (chunk) => {
|
|
21810
|
+
for (const key of parseKeys(String(chunk))) {
|
|
21811
|
+
stream.emit("keypress", key.sequence, key);
|
|
21812
|
+
}
|
|
21813
|
+
});
|
|
21814
|
+
}
|
|
21815
|
+
function createReadlineModule(defaultInput) {
|
|
21816
|
+
class Interface extends EventEmitter4__default.default {
|
|
21817
|
+
constructor(input, output, terminal = false) {
|
|
21818
|
+
super();
|
|
21819
|
+
this.input = input;
|
|
21820
|
+
this.output = output;
|
|
21821
|
+
this.terminal = terminal;
|
|
21822
|
+
this.onTerminalKeypress = (sequence, key) => this.edit(sequence, key);
|
|
21823
|
+
if (terminal) {
|
|
21824
|
+
emitKeypressEvents(input);
|
|
21825
|
+
input?.on?.("keypress", this.onTerminalKeypress);
|
|
21826
|
+
} else {
|
|
21827
|
+
input?.on?.("data", (chunk) => this.receive(String(chunk)));
|
|
21828
|
+
}
|
|
21829
|
+
input?.on?.("end", () => this.close());
|
|
21830
|
+
}
|
|
21831
|
+
input;
|
|
21832
|
+
output;
|
|
21833
|
+
closed = false;
|
|
21834
|
+
buffer = "";
|
|
21835
|
+
pending = [];
|
|
21836
|
+
lines = [];
|
|
21837
|
+
line = "";
|
|
21838
|
+
cursor = 0;
|
|
21839
|
+
terminal;
|
|
21840
|
+
onTerminalKeypress;
|
|
21841
|
+
/** Split incoming data into lines, answering any waiting `question`. */
|
|
21842
|
+
receive(text2) {
|
|
21843
|
+
this.buffer += text2;
|
|
21844
|
+
let newline = this.buffer.indexOf("\n");
|
|
21845
|
+
while (newline >= 0) {
|
|
21846
|
+
const line = this.buffer.slice(0, newline).replace(/\r$/, "");
|
|
21847
|
+
this.buffer = this.buffer.slice(newline + 1);
|
|
21848
|
+
const waiting = this.pending.shift();
|
|
21849
|
+
if (waiting) waiting(line);
|
|
21850
|
+
else {
|
|
21851
|
+
this.lines.push(line);
|
|
21852
|
+
this.emit("line", line);
|
|
21853
|
+
}
|
|
21854
|
+
newline = this.buffer.indexOf("\n");
|
|
21855
|
+
}
|
|
21856
|
+
}
|
|
21857
|
+
question(query, callback) {
|
|
21858
|
+
this.output?.write?.(query);
|
|
21859
|
+
if (callback) {
|
|
21860
|
+
this.pending.push(callback);
|
|
21861
|
+
return;
|
|
21862
|
+
}
|
|
21863
|
+
return new Promise((resolve2) => this.pending.push(resolve2));
|
|
21864
|
+
}
|
|
21865
|
+
prompt() {
|
|
21866
|
+
this.output?.write?.(this.promptText);
|
|
21867
|
+
}
|
|
21868
|
+
promptText = "> ";
|
|
21869
|
+
setPrompt(text2) {
|
|
21870
|
+
this.promptText = text2;
|
|
21871
|
+
}
|
|
21872
|
+
pause() {
|
|
21873
|
+
this.input?.pause?.();
|
|
21874
|
+
return this;
|
|
21875
|
+
}
|
|
21876
|
+
resume() {
|
|
21877
|
+
this.input?.resume?.();
|
|
21878
|
+
return this;
|
|
21879
|
+
}
|
|
21880
|
+
write(text2, key) {
|
|
21881
|
+
if (!this.terminal) {
|
|
21882
|
+
if (text2) this.receive(text2);
|
|
21883
|
+
return;
|
|
21884
|
+
}
|
|
21885
|
+
if (key) {
|
|
21886
|
+
this.edit(text2 ?? "", {
|
|
21887
|
+
sequence: text2 ?? key.sequence ?? "",
|
|
21888
|
+
name: key.name,
|
|
21889
|
+
ctrl: key.ctrl ?? false,
|
|
21890
|
+
meta: key.meta ?? false,
|
|
21891
|
+
shift: key.shift ?? false,
|
|
21892
|
+
...key.code ? { code: key.code } : {}
|
|
21893
|
+
});
|
|
21894
|
+
return;
|
|
21895
|
+
}
|
|
21896
|
+
if (text2) {
|
|
21897
|
+
this.line = this.line.slice(0, this.cursor) + text2 + this.line.slice(this.cursor);
|
|
21898
|
+
this.cursor += text2.length;
|
|
21899
|
+
}
|
|
21900
|
+
}
|
|
21901
|
+
getCursorPos() {
|
|
21902
|
+
return { rows: 0, cols: this.cursor + this.promptText.length };
|
|
21903
|
+
}
|
|
21904
|
+
close() {
|
|
21905
|
+
if (this.closed) return;
|
|
21906
|
+
this.closed = true;
|
|
21907
|
+
if (this.terminal) {
|
|
21908
|
+
this.input?.off?.("keypress", this.onTerminalKeypress);
|
|
21909
|
+
this.input?.pause?.();
|
|
21910
|
+
}
|
|
21911
|
+
for (const waiting of this.pending.splice(0)) waiting("");
|
|
21912
|
+
this.emit("close");
|
|
21913
|
+
}
|
|
21914
|
+
edit(sequence, key) {
|
|
21915
|
+
if (this.closed) return;
|
|
21916
|
+
const name = key.name;
|
|
21917
|
+
if (name === "return" || name === "enter") {
|
|
21918
|
+
const value = this.line;
|
|
21919
|
+
this.line = "";
|
|
21920
|
+
this.cursor = 0;
|
|
21921
|
+
this.emit("line", value);
|
|
21922
|
+
return;
|
|
21923
|
+
}
|
|
21924
|
+
if (name === "left") {
|
|
21925
|
+
this.cursor = Math.max(0, this.cursor - 1);
|
|
21926
|
+
return;
|
|
21927
|
+
}
|
|
21928
|
+
if (name === "right") {
|
|
21929
|
+
this.cursor = Math.min(this.line.length, this.cursor + 1);
|
|
21930
|
+
return;
|
|
21931
|
+
}
|
|
21932
|
+
if (name === "home" || key.ctrl && name === "a") {
|
|
21933
|
+
this.cursor = 0;
|
|
21934
|
+
return;
|
|
21935
|
+
}
|
|
21936
|
+
if (name === "end" || key.ctrl && name === "e") {
|
|
21937
|
+
this.cursor = this.line.length;
|
|
21938
|
+
return;
|
|
21939
|
+
}
|
|
21940
|
+
if (name === "backspace" || key.ctrl && name === "h") {
|
|
21941
|
+
if (this.cursor > 0) {
|
|
21942
|
+
this.line = this.line.slice(0, this.cursor - 1) + this.line.slice(this.cursor);
|
|
21943
|
+
this.cursor--;
|
|
21944
|
+
}
|
|
21945
|
+
return;
|
|
21946
|
+
}
|
|
21947
|
+
if (name === "delete") {
|
|
21948
|
+
if (this.cursor < this.line.length) this.line = this.line.slice(0, this.cursor) + this.line.slice(this.cursor + 1);
|
|
21949
|
+
return;
|
|
21950
|
+
}
|
|
21951
|
+
if (key.ctrl && name === "u") {
|
|
21952
|
+
this.line = this.line.slice(this.cursor);
|
|
21953
|
+
this.cursor = 0;
|
|
21954
|
+
return;
|
|
21955
|
+
}
|
|
21956
|
+
if (key.ctrl && name === "k") {
|
|
21957
|
+
this.line = this.line.slice(0, this.cursor);
|
|
21958
|
+
return;
|
|
21959
|
+
}
|
|
21960
|
+
if (key.ctrl || key.meta || sequence.length !== 1 || sequence < " ") return;
|
|
21961
|
+
this.line = this.line.slice(0, this.cursor) + sequence + this.line.slice(this.cursor);
|
|
21962
|
+
this.cursor += sequence.length;
|
|
21963
|
+
}
|
|
21964
|
+
async *[Symbol.asyncIterator]() {
|
|
21965
|
+
while (!this.closed || this.lines.length) {
|
|
21966
|
+
const line = this.lines.shift();
|
|
21967
|
+
if (line !== void 0) {
|
|
21968
|
+
yield line;
|
|
21969
|
+
continue;
|
|
21970
|
+
}
|
|
21971
|
+
const next = await new Promise((resolve2) => {
|
|
21972
|
+
const onLine = (value) => {
|
|
21973
|
+
cleanup();
|
|
21974
|
+
resolve2(value);
|
|
21975
|
+
};
|
|
21976
|
+
const onClose = () => {
|
|
21977
|
+
cleanup();
|
|
21978
|
+
resolve2(null);
|
|
21979
|
+
};
|
|
21980
|
+
const cleanup = () => {
|
|
21981
|
+
this.off("line", onLine);
|
|
21982
|
+
this.off("close", onClose);
|
|
21983
|
+
};
|
|
21984
|
+
this.on("line", onLine);
|
|
21985
|
+
this.on("close", onClose);
|
|
21986
|
+
});
|
|
21987
|
+
if (next === null) return;
|
|
21988
|
+
yield next;
|
|
21989
|
+
}
|
|
21990
|
+
}
|
|
21991
|
+
}
|
|
21992
|
+
const createInterface = (options, output) => {
|
|
21993
|
+
if (options && typeof options === "object" && !options.on) {
|
|
21994
|
+
const instance = new Interface(options.input ?? defaultInput(), options.output, options.terminal === true);
|
|
21995
|
+
if (typeof options.prompt === "string") instance.setPrompt(options.prompt);
|
|
21996
|
+
return instance;
|
|
21997
|
+
}
|
|
21998
|
+
return new Interface(options ?? defaultInput(), output, Boolean(output));
|
|
21999
|
+
};
|
|
22000
|
+
const noop = () => {
|
|
22001
|
+
};
|
|
22002
|
+
const base2 = {
|
|
22003
|
+
Interface,
|
|
22004
|
+
createInterface,
|
|
22005
|
+
emitKeypressEvents,
|
|
22006
|
+
clearLine: noop,
|
|
22007
|
+
clearScreenDown: noop,
|
|
22008
|
+
cursorTo: noop,
|
|
22009
|
+
moveCursor: noop
|
|
22010
|
+
};
|
|
22011
|
+
return { ...base2, promises: { ...base2, Interface, createInterface } };
|
|
22012
|
+
}
|
|
22013
|
+
|
|
22014
|
+
// src/runtime/core-modules.ts
|
|
20936
22015
|
var Dirent = class {
|
|
20937
22016
|
/** Node 20+ exposes the containing directory, and `fs.glob` consumers read it. */
|
|
20938
22017
|
constructor(name, stat2, parentPath = "") {
|
|
@@ -21048,7 +22127,7 @@ var S_IFMT2 = 61440;
|
|
|
21048
22127
|
var S_IFREG2 = 32768;
|
|
21049
22128
|
var S_IFDIR2 = 16384;
|
|
21050
22129
|
var S_IFLNK2 = 40960;
|
|
21051
|
-
var FsWatcher = class extends
|
|
22130
|
+
var FsWatcher = class extends EventEmitter4__default.default {
|
|
21052
22131
|
close() {
|
|
21053
22132
|
this.removeAllListeners();
|
|
21054
22133
|
}
|
|
@@ -21069,7 +22148,7 @@ function createCoreModules(options) {
|
|
|
21069
22148
|
const stderrWrite = options.stderr ?? (() => {
|
|
21070
22149
|
});
|
|
21071
22150
|
const timers = createTrackedTimers();
|
|
21072
|
-
const processObject = Object.assign(new
|
|
22151
|
+
const processObject = Object.assign(new EventEmitter4__default.default(), processShim__default.default, {
|
|
21073
22152
|
argv: options.argv?.slice() ?? ["/usr/bin/node"],
|
|
21074
22153
|
argv0: "node",
|
|
21075
22154
|
execPath: "/usr/bin/node",
|
|
@@ -21105,14 +22184,27 @@ function createCoreModules(options) {
|
|
|
21105
22184
|
},
|
|
21106
22185
|
kill: () => true
|
|
21107
22186
|
});
|
|
21108
|
-
|
|
21109
|
-
processObject.
|
|
21110
|
-
processObject.
|
|
22187
|
+
const tty = options.tty === true;
|
|
22188
|
+
processObject.stdout = makeOutputStream(stdoutWrite, 1, tty);
|
|
22189
|
+
processObject.stderr = makeOutputStream(stderrWrite, 2, tty);
|
|
22190
|
+
const stdin = options.interactiveStdin ? new streamModule4__default.default.PassThrough() : new streamModule4__default.default.Readable({ read() {
|
|
21111
22191
|
this.push(null);
|
|
21112
22192
|
} });
|
|
21113
|
-
Object.assign(
|
|
21114
|
-
|
|
21115
|
-
|
|
22193
|
+
Object.assign(stdin, {
|
|
22194
|
+
fd: 0,
|
|
22195
|
+
isTTY: tty,
|
|
22196
|
+
setRawMode(enabled = true) {
|
|
22197
|
+
options.onRawMode?.(enabled !== false);
|
|
22198
|
+
return this;
|
|
22199
|
+
},
|
|
22200
|
+
ref() {
|
|
22201
|
+
return this;
|
|
22202
|
+
},
|
|
22203
|
+
unref() {
|
|
22204
|
+
return this;
|
|
22205
|
+
}
|
|
22206
|
+
});
|
|
22207
|
+
processObject.stdin = stdin;
|
|
21116
22208
|
const fs = createFsModule(volume, () => cwd, options.stdinPath);
|
|
21117
22209
|
const path = createPathModule(() => cwd);
|
|
21118
22210
|
const consoleObject = new Console(stdoutWrite, stderrWrite);
|
|
@@ -21130,9 +22222,9 @@ function createCoreModules(options) {
|
|
|
21130
22222
|
const readline = createReadlineModule(() => processObject.stdin);
|
|
21131
22223
|
const dns = createDnsModule();
|
|
21132
22224
|
const builtins = {
|
|
21133
|
-
assert:
|
|
21134
|
-
"assert/strict":
|
|
21135
|
-
buffer: { Buffer:
|
|
22225
|
+
assert: assert_module_default,
|
|
22226
|
+
"assert/strict": assert_module_default.strict ?? assert_module_default,
|
|
22227
|
+
buffer: { Buffer: Buffer2, SlowBuffer: Buffer2, INSPECT_MAX_BYTES: 50, kMaxLength: Buffer2.kMaxLength },
|
|
21136
22228
|
async_hooks: asyncHooks,
|
|
21137
22229
|
child_process: childProcess,
|
|
21138
22230
|
console: consoleObject,
|
|
@@ -21140,7 +22232,7 @@ function createCoreModules(options) {
|
|
|
21140
22232
|
crypto: createCryptoModule(),
|
|
21141
22233
|
dns,
|
|
21142
22234
|
"dns/promises": dns.promises,
|
|
21143
|
-
events:
|
|
22235
|
+
events: EventEmitter4__default.default,
|
|
21144
22236
|
fs,
|
|
21145
22237
|
"fs/promises": fs.promises,
|
|
21146
22238
|
module: moduleBuiltin,
|
|
@@ -21151,24 +22243,24 @@ function createCoreModules(options) {
|
|
|
21151
22243
|
"path/posix": path,
|
|
21152
22244
|
perf_hooks: { performance, PerformanceObserver: globalThis.PerformanceObserver },
|
|
21153
22245
|
process: processObject,
|
|
21154
|
-
punycode:
|
|
22246
|
+
punycode: url_module_default.punycode ?? {},
|
|
21155
22247
|
querystring: querystringModule__default.default,
|
|
21156
22248
|
readline,
|
|
21157
22249
|
"readline/promises": readline.promises,
|
|
21158
|
-
stream:
|
|
22250
|
+
stream: streamModule4__default.default,
|
|
21159
22251
|
"stream/promises": createStreamPromises(),
|
|
21160
22252
|
string_decoder: stringDecoderModule__default.default,
|
|
21161
22253
|
timers: { ...timersModule__default.default, ...timers.api },
|
|
21162
22254
|
"timers/promises": createTimerPromises(),
|
|
21163
|
-
tty: { isatty: () => false, ReadStream:
|
|
21164
|
-
url:
|
|
21165
|
-
util:
|
|
21166
|
-
"util/types":
|
|
21167
|
-
zlib:
|
|
22255
|
+
tty: { isatty: () => false, ReadStream: streamModule4__default.default.Readable, WriteStream: streamModule4__default.default.Writable },
|
|
22256
|
+
url: url_module_default,
|
|
22257
|
+
util: util_module_default,
|
|
22258
|
+
"util/types": util_module_default.types ?? {},
|
|
22259
|
+
zlib: zlib_module_default
|
|
21168
22260
|
};
|
|
21169
22261
|
for (const name of stubNames) builtins[name] = createUnsupportedModule(name);
|
|
21170
22262
|
const globals = {
|
|
21171
|
-
Buffer:
|
|
22263
|
+
Buffer: Buffer2,
|
|
21172
22264
|
console: consoleObject,
|
|
21173
22265
|
process: processObject,
|
|
21174
22266
|
...timers.api
|
|
@@ -21179,7 +22271,19 @@ function createCoreModules(options) {
|
|
|
21179
22271
|
});
|
|
21180
22272
|
globals.global = globalOverlay;
|
|
21181
22273
|
globals.globalThis = globalOverlay;
|
|
21182
|
-
return {
|
|
22274
|
+
return {
|
|
22275
|
+
builtins,
|
|
22276
|
+
globals,
|
|
22277
|
+
process: processObject,
|
|
22278
|
+
pendingHandles: timers.pending,
|
|
22279
|
+
writeStdin: (data) => {
|
|
22280
|
+
if (options.interactiveStdin) stdin.write(data);
|
|
22281
|
+
},
|
|
22282
|
+
endStdin: () => {
|
|
22283
|
+
if (options.interactiveStdin) stdin.end();
|
|
22284
|
+
},
|
|
22285
|
+
readingStdin: () => Boolean(options.interactiveStdin) && stdin.readable === true && (stdin.readableFlowing === true || stdin.listenerCount("readable") > 0 || stdin.listenerCount("keypress") > 0)
|
|
22286
|
+
};
|
|
21183
22287
|
}
|
|
21184
22288
|
var ASYNC_FS_METHODS = [
|
|
21185
22289
|
"readFile",
|
|
@@ -21240,18 +22344,18 @@ function createFsModule(volume, cwd, stdinPath) {
|
|
|
21240
22344
|
const abs = (value) => {
|
|
21241
22345
|
if (typeof value === "number") return requiredFd(fds, value).path;
|
|
21242
22346
|
if (value instanceof URL) value = value.pathname;
|
|
21243
|
-
if (
|
|
22347
|
+
if (Buffer2.isBuffer(value) || value instanceof Uint8Array) value = new TextDecoder().decode(value);
|
|
21244
22348
|
if (typeof value !== "string") throw new TypeError("path must be a string, Buffer, or URL");
|
|
21245
22349
|
return value.startsWith("/") ? clean(value) : resolve(cwd(), value);
|
|
21246
22350
|
};
|
|
21247
|
-
const
|
|
21248
|
-
if (typeof data === "string") return new Uint8Array(
|
|
21249
|
-
if (
|
|
22351
|
+
const bytes2 = (data, encoding) => {
|
|
22352
|
+
if (typeof data === "string") return new Uint8Array(Buffer2.from(data, encoding));
|
|
22353
|
+
if (Buffer2.isBuffer(data) || data instanceof Uint8Array) return new Uint8Array(data);
|
|
21250
22354
|
if (data instanceof ArrayBuffer) return new Uint8Array(data);
|
|
21251
22355
|
throw new TypeError("data must be a string or byte array");
|
|
21252
22356
|
};
|
|
21253
22357
|
const read = (path, encoding) => {
|
|
21254
|
-
const data =
|
|
22358
|
+
const data = Buffer2.from(volume.readFileSync(resolveLinks(volume, abs(path))));
|
|
21255
22359
|
return encoding && encoding !== "buffer" ? data.toString(encoding) : data;
|
|
21256
22360
|
};
|
|
21257
22361
|
const mkdirRecursive = (path, mode) => {
|
|
@@ -21300,12 +22404,12 @@ function createFsModule(volume, cwd, stdinPath) {
|
|
|
21300
22404
|
readFileSync: (path, options) => read(path, typeof options === "object" && options ? options.encoding : options),
|
|
21301
22405
|
writeFileSync: (path, data, options) => {
|
|
21302
22406
|
const encoding = typeof options === "object" && options ? options.encoding : options === "buffer" ? void 0 : options ?? void 0;
|
|
21303
|
-
volume.writeFileSync(abs(path),
|
|
22407
|
+
volume.writeFileSync(abs(path), bytes2(data, encoding ?? void 0));
|
|
21304
22408
|
if (typeof options === "object" && options?.mode !== void 0) volume.chmodSync(abs(path), options.mode);
|
|
21305
22409
|
},
|
|
21306
22410
|
appendFileSync: (path, data, options) => {
|
|
21307
22411
|
const encoding = typeof options === "object" && options ? options.encoding : options === "buffer" ? void 0 : options ?? void 0;
|
|
21308
|
-
volume.appendFileSync(abs(path),
|
|
22412
|
+
volume.appendFileSync(abs(path), bytes2(data, encoding ?? void 0));
|
|
21309
22413
|
},
|
|
21310
22414
|
existsSync: (path) => {
|
|
21311
22415
|
try {
|
|
@@ -21323,7 +22427,7 @@ function createFsModule(volume, cwd, stdinPath) {
|
|
|
21323
22427
|
if (typeof options === "object" && options?.withFileTypes) {
|
|
21324
22428
|
return names.map((name) => new Dirent(name, new Stats2(volume.lstatSync(join(dir3, name))), dir3));
|
|
21325
22429
|
}
|
|
21326
|
-
if ((typeof options === "string" ? options : options?.encoding) === "buffer") return names.map((name) =>
|
|
22430
|
+
if ((typeof options === "string" ? options : options?.encoding) === "buffer") return names.map((name) => Buffer2.from(name));
|
|
21327
22431
|
return names;
|
|
21328
22432
|
},
|
|
21329
22433
|
mkdirSync: (path, options) => {
|
|
@@ -21344,7 +22448,7 @@ function createFsModule(volume, cwd, stdinPath) {
|
|
|
21344
22448
|
renameSync: (from, to) => volume.renameSync(abs(from), abs(to)),
|
|
21345
22449
|
readlinkSync: (path, encoding) => {
|
|
21346
22450
|
const value = volume.readlinkSync(abs(path));
|
|
21347
|
-
return encoding === "buffer" ?
|
|
22451
|
+
return encoding === "buffer" ? Buffer2.from(value) : value;
|
|
21348
22452
|
},
|
|
21349
22453
|
symlinkSync: (target, path) => volume.symlinkSync(target, abs(path)),
|
|
21350
22454
|
linkSync: (from, to) => volume.linkSync(abs(from), abs(to)),
|
|
@@ -21380,33 +22484,33 @@ function createFsModule(volume, cwd, stdinPath) {
|
|
|
21380
22484
|
readSync: (fd, target, offset, length, position) => {
|
|
21381
22485
|
const file3 = requiredFd(fds, fd);
|
|
21382
22486
|
const source = volume.readFileSync(resolveLinks(volume, file3.path));
|
|
21383
|
-
const
|
|
21384
|
-
const count = Math.max(0, Math.min(length, source.length -
|
|
21385
|
-
target.set(source.subarray(
|
|
22487
|
+
const start2 = position ?? file3.position;
|
|
22488
|
+
const count = Math.max(0, Math.min(length, source.length - start2));
|
|
22489
|
+
target.set(source.subarray(start2, start2 + count), offset);
|
|
21386
22490
|
if (position == null) file3.position += count;
|
|
21387
22491
|
return count;
|
|
21388
22492
|
},
|
|
21389
22493
|
writeSync: (fd, data, offset, length, position) => {
|
|
21390
22494
|
const file3 = requiredFd(fds, fd);
|
|
21391
|
-
const input =
|
|
22495
|
+
const input = bytes2(data);
|
|
21392
22496
|
const chunk = typeof data === "string" ? input : input.subarray(offset ?? 0, (offset ?? 0) + (length ?? input.length));
|
|
21393
22497
|
const old = volume.readFileSync(file3.path);
|
|
21394
|
-
const
|
|
21395
|
-
const next = new Uint8Array(Math.max(old.length,
|
|
22498
|
+
const start2 = file3.flags.startsWith("a") ? old.length : position ?? file3.position;
|
|
22499
|
+
const next = new Uint8Array(Math.max(old.length, start2 + chunk.length));
|
|
21396
22500
|
next.set(old);
|
|
21397
|
-
next.set(chunk,
|
|
22501
|
+
next.set(chunk, start2);
|
|
21398
22502
|
volume.writeFileSync(file3.path, next);
|
|
21399
|
-
if (position == null) file3.position =
|
|
22503
|
+
if (position == null) file3.position = start2 + chunk.length;
|
|
21400
22504
|
return chunk.length;
|
|
21401
22505
|
},
|
|
21402
22506
|
createReadStream: (path) => {
|
|
21403
|
-
const data =
|
|
21404
|
-
return
|
|
22507
|
+
const data = Buffer2.from(volume.readFileSync(resolveLinks(volume, abs(path))));
|
|
22508
|
+
return streamModule4__default.default.Readable.from([data]);
|
|
21405
22509
|
},
|
|
21406
22510
|
createWriteStream: (path, options) => {
|
|
21407
22511
|
const target = abs(path);
|
|
21408
22512
|
let first = true;
|
|
21409
|
-
return new
|
|
22513
|
+
return new streamModule4__default.default.Writable({ write(chunk, _encoding, done) {
|
|
21410
22514
|
try {
|
|
21411
22515
|
if (options?.flags?.startsWith("a") || !first) volume.appendFileSync(target, new Uint8Array(chunk));
|
|
21412
22516
|
else volume.writeFileSync(target, new Uint8Array(chunk));
|
|
@@ -21528,12 +22632,12 @@ function requiredFd(fds, fd) {
|
|
|
21528
22632
|
function fsError(code, syscall, path) {
|
|
21529
22633
|
return Object.assign(new Error(`${code}: ${syscall}, '${path}'`), { code, syscall, path });
|
|
21530
22634
|
}
|
|
21531
|
-
function makeOutputStream(write, fd) {
|
|
21532
|
-
const stream = new
|
|
21533
|
-
write(
|
|
22635
|
+
function makeOutputStream(write, fd, isTTY = false) {
|
|
22636
|
+
const stream = new streamModule4__default.default.Writable({ write(chunk, _encoding, done) {
|
|
22637
|
+
write(Buffer2.isBuffer(chunk) ? chunk.toString("utf8") : String(chunk));
|
|
21534
22638
|
done();
|
|
21535
22639
|
} });
|
|
21536
|
-
return Object.assign(stream, { fd, isTTY
|
|
22640
|
+
return Object.assign(stream, { fd, isTTY, columns: 80, rows: 24 });
|
|
21537
22641
|
}
|
|
21538
22642
|
var Console = class {
|
|
21539
22643
|
constructor(out, err) {
|
|
@@ -21543,7 +22647,7 @@ var Console = class {
|
|
|
21543
22647
|
out;
|
|
21544
22648
|
err;
|
|
21545
22649
|
log = (...args) => {
|
|
21546
|
-
this.out(
|
|
22650
|
+
this.out(util_module_default.format(...args) + "\n");
|
|
21547
22651
|
};
|
|
21548
22652
|
info = (...args) => {
|
|
21549
22653
|
this.log(...args);
|
|
@@ -21552,20 +22656,20 @@ var Console = class {
|
|
|
21552
22656
|
this.log(...args);
|
|
21553
22657
|
};
|
|
21554
22658
|
warn = (...args) => {
|
|
21555
|
-
this.err(
|
|
22659
|
+
this.err(util_module_default.format(...args) + "\n");
|
|
21556
22660
|
};
|
|
21557
22661
|
error = (...args) => {
|
|
21558
22662
|
this.warn(...args);
|
|
21559
22663
|
};
|
|
21560
22664
|
dir = (value, options) => {
|
|
21561
|
-
this.out(
|
|
22665
|
+
this.out(util_module_default.inspect(value, options) + "\n");
|
|
21562
22666
|
};
|
|
21563
22667
|
trace = (...args) => {
|
|
21564
|
-
this.err(`Trace: ${
|
|
22668
|
+
this.err(`Trace: ${util_module_default.format(...args)}
|
|
21565
22669
|
`);
|
|
21566
22670
|
};
|
|
21567
22671
|
assert = (value, ...args) => {
|
|
21568
|
-
if (!value) this.err(`Assertion failed: ${
|
|
22672
|
+
if (!value) this.err(`Assertion failed: ${util_module_default.format(...args)}
|
|
21569
22673
|
`);
|
|
21570
22674
|
};
|
|
21571
22675
|
group = (...args) => {
|
|
@@ -21587,63 +22691,6 @@ var Console = class {
|
|
|
21587
22691
|
timeLog = (_label = "default") => {
|
|
21588
22692
|
};
|
|
21589
22693
|
};
|
|
21590
|
-
function createReadlineModule(stdin) {
|
|
21591
|
-
class Interface extends EventEmitter3__default.default {
|
|
21592
|
-
constructor(input) {
|
|
21593
|
-
super();
|
|
21594
|
-
this.input = input;
|
|
21595
|
-
input?.on?.("data", (chunk) => {
|
|
21596
|
-
for (const line of String(chunk).split("\n")) this.lines.push(line);
|
|
21597
|
-
while (this.lines.length > 1) this.emit("line", this.lines.shift());
|
|
21598
|
-
});
|
|
21599
|
-
input?.on?.("end", () => this.close());
|
|
21600
|
-
}
|
|
21601
|
-
input;
|
|
21602
|
-
closed = false;
|
|
21603
|
-
lines = [];
|
|
21604
|
-
question(_query, callback) {
|
|
21605
|
-
const answer = this.lines.shift() ?? "";
|
|
21606
|
-
if (callback) {
|
|
21607
|
-
queueMicrotask(() => callback(answer));
|
|
21608
|
-
return;
|
|
21609
|
-
}
|
|
21610
|
-
return Promise.resolve(answer);
|
|
21611
|
-
}
|
|
21612
|
-
prompt() {
|
|
21613
|
-
}
|
|
21614
|
-
setPrompt() {
|
|
21615
|
-
}
|
|
21616
|
-
pause() {
|
|
21617
|
-
return this;
|
|
21618
|
-
}
|
|
21619
|
-
resume() {
|
|
21620
|
-
return this;
|
|
21621
|
-
}
|
|
21622
|
-
write() {
|
|
21623
|
-
}
|
|
21624
|
-
close() {
|
|
21625
|
-
if (this.closed) return;
|
|
21626
|
-
this.closed = true;
|
|
21627
|
-
this.emit("close");
|
|
21628
|
-
}
|
|
21629
|
-
async *[Symbol.asyncIterator]() {
|
|
21630
|
-
while (this.lines.length) yield this.lines.shift();
|
|
21631
|
-
}
|
|
21632
|
-
}
|
|
21633
|
-
const createInterface = (options) => new Interface(options?.input ?? (Array.isArray(options) ? options[0] : stdin()));
|
|
21634
|
-
const noop = () => {
|
|
21635
|
-
};
|
|
21636
|
-
const base = {
|
|
21637
|
-
Interface,
|
|
21638
|
-
createInterface,
|
|
21639
|
-
clearLine: noop,
|
|
21640
|
-
clearScreenDown: noop,
|
|
21641
|
-
cursorTo: noop,
|
|
21642
|
-
moveCursor: noop,
|
|
21643
|
-
emitKeypressEvents: noop
|
|
21644
|
-
};
|
|
21645
|
-
return { ...base, promises: { ...base, Interface, createInterface } };
|
|
21646
|
-
}
|
|
21647
22694
|
function createDnsModule() {
|
|
21648
22695
|
const LOOPBACK = {
|
|
21649
22696
|
localhost: { address: "127.0.0.1", family: 4 },
|
|
@@ -21673,15 +22720,6 @@ function createDnsModule() {
|
|
|
21673
22720
|
}
|
|
21674
22721
|
});
|
|
21675
22722
|
};
|
|
21676
|
-
const notFound = (hostname) => Promise.reject(lookupThrow(hostname));
|
|
21677
|
-
const lookupThrow = (hostname) => {
|
|
21678
|
-
try {
|
|
21679
|
-
lookupSync(hostname);
|
|
21680
|
-
return null;
|
|
21681
|
-
} catch (error) {
|
|
21682
|
-
return error;
|
|
21683
|
-
}
|
|
21684
|
-
};
|
|
21685
22723
|
const promises = {
|
|
21686
22724
|
lookup: async (hostname, options) => {
|
|
21687
22725
|
const entry = lookupSync(hostname);
|
|
@@ -21689,7 +22727,10 @@ function createDnsModule() {
|
|
|
21689
22727
|
},
|
|
21690
22728
|
resolve4: async (hostname) => [lookupSync(hostname).address],
|
|
21691
22729
|
resolve6: async (hostname) => [lookupSync(hostname).address],
|
|
21692
|
-
reverse: async (address) =>
|
|
22730
|
+
reverse: async (address) => {
|
|
22731
|
+
if (address === "127.0.0.1") return ["localhost"];
|
|
22732
|
+
return [lookupSync(address).address];
|
|
22733
|
+
}
|
|
21693
22734
|
};
|
|
21694
22735
|
return {
|
|
21695
22736
|
lookup,
|
|
@@ -21956,10 +22997,10 @@ function createStreamPromises() {
|
|
|
21956
22997
|
return {
|
|
21957
22998
|
pipeline: (...streams) => new Promise((resolve2, reject) => {
|
|
21958
22999
|
const callback = (error) => error ? reject(error) : resolve2();
|
|
21959
|
-
|
|
23000
|
+
streamModule4__default.default.pipeline(...streams, callback);
|
|
21960
23001
|
}),
|
|
21961
23002
|
finished: (stream) => new Promise((resolve2, reject) => {
|
|
21962
|
-
|
|
23003
|
+
streamModule4__default.default.finished(stream, (error) => error ? reject(error) : resolve2());
|
|
21963
23004
|
})
|
|
21964
23005
|
};
|
|
21965
23006
|
}
|
|
@@ -22086,26 +23127,26 @@ var MemoryVolume = class {
|
|
|
22086
23127
|
writeFileSync(path, data) {
|
|
22087
23128
|
const key = this.key(path);
|
|
22088
23129
|
this.requireParent(key, "open");
|
|
22089
|
-
const
|
|
23130
|
+
const bytes2 = typeof data === "string" ? encoder6.encode(data) : data.slice();
|
|
22090
23131
|
const current = this.entries.get(key);
|
|
22091
23132
|
if (current?.kind === "directory") throw new VolumeError("EISDIR", "open", key);
|
|
22092
23133
|
if (current?.kind === "symlink") throw new VolumeError("EINVAL", "open", key);
|
|
22093
23134
|
if (current) {
|
|
22094
|
-
current.data =
|
|
23135
|
+
current.data = bytes2;
|
|
22095
23136
|
this.touchChanged(current, true);
|
|
22096
23137
|
} else {
|
|
22097
|
-
this.entries.set(key, this.inode("file", 438,
|
|
23138
|
+
this.entries.set(key, this.inode("file", 438, bytes2));
|
|
22098
23139
|
}
|
|
22099
23140
|
}
|
|
22100
23141
|
appendFileSync(path, data) {
|
|
22101
23142
|
const key = this.key(path);
|
|
22102
|
-
const
|
|
23143
|
+
const bytes2 = typeof data === "string" ? encoder6.encode(data) : data;
|
|
22103
23144
|
const current = this.entries.get(key);
|
|
22104
|
-
if (!current) return this.writeFileSync(key,
|
|
23145
|
+
if (!current) return this.writeFileSync(key, bytes2);
|
|
22105
23146
|
if (current.kind !== "file") throw new VolumeError(current.kind === "directory" ? "EISDIR" : "EINVAL", "open", key);
|
|
22106
|
-
const next = new Uint8Array(current.data.length +
|
|
23147
|
+
const next = new Uint8Array(current.data.length + bytes2.length);
|
|
22107
23148
|
next.set(current.data);
|
|
22108
|
-
next.set(
|
|
23149
|
+
next.set(bytes2, current.data.length);
|
|
22109
23150
|
current.data = next;
|
|
22110
23151
|
this.touchChanged(current, true);
|
|
22111
23152
|
}
|
|
@@ -22324,29 +23365,72 @@ var MemoryVolume = class {
|
|
|
22324
23365
|
};
|
|
22325
23366
|
|
|
22326
23367
|
// src/runtime/host-esbuild.ts
|
|
22327
|
-
var
|
|
22328
|
-
function
|
|
22329
|
-
|
|
22330
|
-
|
|
22331
|
-
|
|
22332
|
-
|
|
22333
|
-
return
|
|
23368
|
+
var ASYNC_API = ["transform", "build", "context", "formatMessages", "analyzeMetafile"];
|
|
23369
|
+
function createHostEsbuild() {
|
|
23370
|
+
let loading = null;
|
|
23371
|
+
let started = null;
|
|
23372
|
+
const ensure = async () => {
|
|
23373
|
+
loading ??= start().then((api) => started = api);
|
|
23374
|
+
return loading;
|
|
23375
|
+
};
|
|
23376
|
+
const module = new Proxy({}, {
|
|
23377
|
+
get(_target, key) {
|
|
23378
|
+
if (typeof key !== "string") return void 0;
|
|
23379
|
+
if (ASYNC_API.includes(key)) {
|
|
23380
|
+
return async (...args) => {
|
|
23381
|
+
const api = await ensure();
|
|
23382
|
+
if (!api) throw esbuildUnavailable();
|
|
23383
|
+
return api[key](...args);
|
|
23384
|
+
};
|
|
23385
|
+
}
|
|
23386
|
+
if (key === "stop") return stop;
|
|
23387
|
+
return started?.[key];
|
|
23388
|
+
},
|
|
23389
|
+
has: (_target, key) => typeof key === "string"
|
|
22334
23390
|
});
|
|
22335
|
-
|
|
23391
|
+
function stop() {
|
|
23392
|
+
try {
|
|
23393
|
+
started?.stop?.();
|
|
23394
|
+
} catch {
|
|
23395
|
+
}
|
|
23396
|
+
started = null;
|
|
23397
|
+
}
|
|
23398
|
+
return { module, stop };
|
|
22336
23399
|
}
|
|
22337
|
-
async function
|
|
23400
|
+
async function start() {
|
|
22338
23401
|
if (typeof process === "undefined" || process.versions?.node == null) return null;
|
|
22339
23402
|
for (const specifier of ["esbuild-wasm", "esbuild"]) {
|
|
22340
23403
|
try {
|
|
22341
|
-
const
|
|
22342
|
-
const api =
|
|
23404
|
+
const loaded = await nodeOnlyModule(specifier);
|
|
23405
|
+
const api = loaded.default ?? loaded;
|
|
22343
23406
|
if (specifier === "esbuild-wasm") await api.initialize({});
|
|
22344
23407
|
return api;
|
|
22345
|
-
} catch {
|
|
23408
|
+
} catch (error) {
|
|
23409
|
+
if (typeof process !== "undefined" && process.env?.SANDBOXEDJS_DEBUG) {
|
|
23410
|
+
console.error(`[sandboxedjs] ${specifier} unavailable:`, error);
|
|
23411
|
+
}
|
|
22346
23412
|
}
|
|
22347
23413
|
}
|
|
22348
23414
|
return null;
|
|
22349
23415
|
}
|
|
23416
|
+
function esbuildUnavailable() {
|
|
23417
|
+
const error = new Error(
|
|
23418
|
+
"esbuild is unavailable: install `esbuild-wasm` to give the sandboxed runtime a build of esbuild it can execute."
|
|
23419
|
+
);
|
|
23420
|
+
error.code = "ERR_FEATURE_UNAVAILABLE_ON_PLATFORM";
|
|
23421
|
+
return error;
|
|
23422
|
+
}
|
|
23423
|
+
var installed = false;
|
|
23424
|
+
function ensureProcessGlobal() {
|
|
23425
|
+
if (installed) return;
|
|
23426
|
+
installed = true;
|
|
23427
|
+
if (typeof globalThis.process !== "undefined") return;
|
|
23428
|
+
Object.defineProperty(globalThis, "process", {
|
|
23429
|
+
value: processShim__default.default,
|
|
23430
|
+
writable: true,
|
|
23431
|
+
configurable: true
|
|
23432
|
+
});
|
|
23433
|
+
}
|
|
22350
23434
|
|
|
22351
23435
|
// src/runtime/local-runtime-pod.ts
|
|
22352
23436
|
var WASM_ALIASES = {
|
|
@@ -22360,7 +23444,7 @@ var ProcessExit = class extends Error {
|
|
|
22360
23444
|
}
|
|
22361
23445
|
code;
|
|
22362
23446
|
};
|
|
22363
|
-
var LocalProcess = class extends
|
|
23447
|
+
var LocalProcess = class extends EventEmitter4__default.default {
|
|
22364
23448
|
constructor(task) {
|
|
22365
23449
|
super();
|
|
22366
23450
|
this.task = task;
|
|
@@ -22378,6 +23462,10 @@ var LocalProcess = class extends EventEmitter3__default.default {
|
|
|
22378
23462
|
killed = false;
|
|
22379
23463
|
out = [];
|
|
22380
23464
|
err = [];
|
|
23465
|
+
input;
|
|
23466
|
+
end;
|
|
23467
|
+
inputEnded = false;
|
|
23468
|
+
pendingInput = [];
|
|
22381
23469
|
resolveKilled;
|
|
22382
23470
|
killedPromise = new Promise((resolve2) => {
|
|
22383
23471
|
this.resolveKilled = resolve2;
|
|
@@ -22393,7 +23481,29 @@ var LocalProcess = class extends EventEmitter3__default.default {
|
|
|
22393
23481
|
this.err.push(text2);
|
|
22394
23482
|
this.emit("error", text2);
|
|
22395
23483
|
}
|
|
22396
|
-
|
|
23484
|
+
/**
|
|
23485
|
+
* Deliver input to the running program.
|
|
23486
|
+
*
|
|
23487
|
+
* The program's `process.stdin` does not exist until its task starts, so
|
|
23488
|
+
* anything written before then is held. Dropping it would lose the first
|
|
23489
|
+
* keystrokes of an interactive session, which arrive while the program is
|
|
23490
|
+
* still loading.
|
|
23491
|
+
*/
|
|
23492
|
+
write(data) {
|
|
23493
|
+
if (this.input) this.input(data);
|
|
23494
|
+
else this.pendingInput.push(data);
|
|
23495
|
+
}
|
|
23496
|
+
/** Close the program's input, which a reader sees as end-of-file. */
|
|
23497
|
+
endInput() {
|
|
23498
|
+
this.inputEnded = true;
|
|
23499
|
+
this.end?.();
|
|
23500
|
+
}
|
|
23501
|
+
/** Called by the task once the program's stdin exists. */
|
|
23502
|
+
acceptInput(input, end) {
|
|
23503
|
+
this.input = input;
|
|
23504
|
+
this.end = end;
|
|
23505
|
+
for (const chunk of this.pendingInput.splice(0)) input(chunk);
|
|
23506
|
+
if (this.inputEnded) end();
|
|
22397
23507
|
}
|
|
22398
23508
|
kill(_signal = "SIGTERM") {
|
|
22399
23509
|
this.killed = true;
|
|
@@ -22505,6 +23615,46 @@ var PodChildProcess = class {
|
|
|
22505
23615
|
}
|
|
22506
23616
|
};
|
|
22507
23617
|
var nextChildPid = 805306368;
|
|
23618
|
+
var liveProcesses = [];
|
|
23619
|
+
var reportingInstalled = false;
|
|
23620
|
+
function reportEscapedError(reason) {
|
|
23621
|
+
const target = liveProcesses.at(-1);
|
|
23622
|
+
if (!target) return false;
|
|
23623
|
+
target.error(formatError(reason));
|
|
23624
|
+
target.exitNow(1);
|
|
23625
|
+
return true;
|
|
23626
|
+
}
|
|
23627
|
+
function trackProcess(proc) {
|
|
23628
|
+
liveProcesses.push(proc);
|
|
23629
|
+
if (!reportingInstalled) {
|
|
23630
|
+
reportingInstalled = true;
|
|
23631
|
+
installEscapedErrorReporting();
|
|
23632
|
+
}
|
|
23633
|
+
return () => {
|
|
23634
|
+
const index = liveProcesses.indexOf(proc);
|
|
23635
|
+
if (index >= 0) liveProcesses.splice(index, 1);
|
|
23636
|
+
if (liveProcesses.length === 0) {
|
|
23637
|
+
reportingInstalled = false;
|
|
23638
|
+
removeEscapedErrorReporting();
|
|
23639
|
+
}
|
|
23640
|
+
};
|
|
23641
|
+
}
|
|
23642
|
+
var onNodeRejection = (reason) => {
|
|
23643
|
+
if (!reportEscapedError(reason)) throw reason;
|
|
23644
|
+
};
|
|
23645
|
+
var onBrowserRejection = (event) => {
|
|
23646
|
+
if (reportEscapedError(event.reason)) event.preventDefault();
|
|
23647
|
+
};
|
|
23648
|
+
function installEscapedErrorReporting() {
|
|
23649
|
+
const host2 = globalThis;
|
|
23650
|
+
if (host2.process?.on && host2.process.versions?.node) host2.process.on("unhandledRejection", onNodeRejection);
|
|
23651
|
+
else host2.addEventListener?.("unhandledrejection", onBrowserRejection);
|
|
23652
|
+
}
|
|
23653
|
+
function removeEscapedErrorReporting() {
|
|
23654
|
+
const host2 = globalThis;
|
|
23655
|
+
if (host2.process?.off && host2.process.versions?.node) host2.process.off("unhandledRejection", onNodeRejection);
|
|
23656
|
+
else host2.removeEventListener?.("unhandledrejection", onBrowserRejection);
|
|
23657
|
+
}
|
|
22508
23658
|
var DRAIN_TURNS = 4;
|
|
22509
23659
|
var LocalRuntimePod = class _LocalRuntimePod {
|
|
22510
23660
|
volume = new MemoryVolume();
|
|
@@ -22532,11 +23682,17 @@ var LocalRuntimePod = class _LocalRuntimePod {
|
|
|
22532
23682
|
env;
|
|
22533
23683
|
aliases;
|
|
22534
23684
|
modules;
|
|
23685
|
+
esbuild;
|
|
22535
23686
|
constructor(options) {
|
|
23687
|
+
ensureProcessGlobal();
|
|
22536
23688
|
this.workdir = options.workdir ?? "/";
|
|
22537
23689
|
this.env = { ...options.env };
|
|
22538
23690
|
this.aliases = { ...WASM_ALIASES, ...options.aliases };
|
|
22539
23691
|
this.modules = { ...options.modules };
|
|
23692
|
+
if (options.hostEsbuild !== false && !this.modules.esbuild) {
|
|
23693
|
+
this.esbuild = createHostEsbuild();
|
|
23694
|
+
this.modules.esbuild = this.esbuild.module;
|
|
23695
|
+
}
|
|
22540
23696
|
if (options.onServerReady) {
|
|
22541
23697
|
const notify = options.onServerReady;
|
|
22542
23698
|
this.router.onListen = (port) => notify(port, `http://localhost:${port}`);
|
|
@@ -22549,12 +23705,7 @@ var LocalRuntimePod = class _LocalRuntimePod {
|
|
|
22549
23705
|
this.seed(options.files ?? {});
|
|
22550
23706
|
}
|
|
22551
23707
|
static async boot(options = {}) {
|
|
22552
|
-
|
|
22553
|
-
if (options.hostEsbuild !== false && !pod.modules.esbuild) {
|
|
22554
|
-
const esbuild = await loadHostEsbuild();
|
|
22555
|
-
if (esbuild) pod.modules.esbuild = esbuild;
|
|
22556
|
-
}
|
|
22557
|
-
return pod;
|
|
23708
|
+
return new _LocalRuntimePod(options);
|
|
22558
23709
|
}
|
|
22559
23710
|
async spawn(command, args = [], options = {}) {
|
|
22560
23711
|
this.assertActive();
|
|
@@ -22565,8 +23716,9 @@ var LocalRuntimePod = class _LocalRuntimePod {
|
|
|
22565
23716
|
const env2 = { ...this.env, ...isRecord(options.env) ? options.env : {} };
|
|
22566
23717
|
const owner = `${this.instanceId}:${Math.random().toString(36).slice(2)}`;
|
|
22567
23718
|
return new LocalProcess(async (proc) => {
|
|
23719
|
+
const untrack = trackProcess(proc);
|
|
22568
23720
|
let requestedExit = 0;
|
|
22569
|
-
let
|
|
23721
|
+
let engine;
|
|
22570
23722
|
const core = createCoreModules({
|
|
22571
23723
|
volume: this.volume,
|
|
22572
23724
|
cwd,
|
|
@@ -22574,16 +23726,24 @@ var LocalRuntimePod = class _LocalRuntimePod {
|
|
|
22574
23726
|
argv: Array.isArray(options.argv) ? options.argv : ["/usr/bin/node", script, ...args.slice(1)],
|
|
22575
23727
|
stdout: (text2) => proc.output(text2),
|
|
22576
23728
|
stderr: (text2) => proc.error(text2),
|
|
23729
|
+
/* `process.exit` ends the process either way. The throw is only to
|
|
23730
|
+
* abandon the rest of a module body still running synchronously —
|
|
23731
|
+
* thrown from a later callback it would escape into whichever library
|
|
23732
|
+
* scheduled that callback and look like an unrelated crash. */
|
|
22577
23733
|
onExit: (code) => {
|
|
22578
23734
|
requestedExit = code;
|
|
22579
|
-
if (evaluating) throw new ProcessExit(code);
|
|
22580
23735
|
proc.exitNow(code);
|
|
23736
|
+
if (engine?.isEvaluating) throw new ProcessExit(code);
|
|
22581
23737
|
},
|
|
22582
23738
|
http: { router: this.router, owner },
|
|
22583
23739
|
spawnChild: (config) => this.processManager.spawn(config),
|
|
22584
|
-
...typeof options.stdinPath === "string" ? { stdinPath: options.stdinPath } : {}
|
|
23740
|
+
...typeof options.stdinPath === "string" ? { stdinPath: options.stdinPath } : {},
|
|
23741
|
+
...options.interactiveStdin ? { interactiveStdin: true } : {},
|
|
23742
|
+
...options.tty ? { tty: true } : {},
|
|
23743
|
+
onRawMode: (enabled) => proc.emit("rawmode", enabled)
|
|
22585
23744
|
});
|
|
22586
|
-
|
|
23745
|
+
proc.acceptInput((data) => core.writeStdin(data), () => core.endStdin());
|
|
23746
|
+
engine = new CommonJsEngine(this.volume, {
|
|
22587
23747
|
cwd,
|
|
22588
23748
|
builtins: core.builtins,
|
|
22589
23749
|
globals: core.globals,
|
|
@@ -22591,18 +23751,15 @@ var LocalRuntimePod = class _LocalRuntimePod {
|
|
|
22591
23751
|
overrides: this.modules
|
|
22592
23752
|
});
|
|
22593
23753
|
try {
|
|
22594
|
-
|
|
22595
|
-
|
|
22596
|
-
} finally {
|
|
22597
|
-
evaluating = false;
|
|
22598
|
-
}
|
|
22599
|
-
await this.settle(owner, core.pendingHandles);
|
|
23754
|
+
await engine.run(script);
|
|
23755
|
+
await this.settle(owner, core.pendingHandles, core.readingStdin);
|
|
22600
23756
|
if (this.router.activePorts(owner).length) {
|
|
22601
23757
|
await proc.waitForKill();
|
|
22602
23758
|
return 137;
|
|
22603
23759
|
}
|
|
22604
23760
|
return requestedExit;
|
|
22605
23761
|
} finally {
|
|
23762
|
+
untrack();
|
|
22606
23763
|
this.router.closeOwner(owner);
|
|
22607
23764
|
}
|
|
22608
23765
|
});
|
|
@@ -22622,12 +23779,12 @@ var LocalRuntimePod = class _LocalRuntimePod {
|
|
|
22622
23779
|
* A plain script that has genuinely finished falls straight through both,
|
|
22623
23780
|
* costing a handful of empty turns.
|
|
22624
23781
|
*/
|
|
22625
|
-
async settle(owner, pendingHandles) {
|
|
23782
|
+
async settle(owner, pendingHandles, readingStdin) {
|
|
22626
23783
|
for (let turn = 0; turn < DRAIN_TURNS; turn++) {
|
|
22627
23784
|
if (this.router.activePorts(owner).length) return;
|
|
22628
23785
|
await new Promise((resolve2) => setTimeout(resolve2, 0));
|
|
22629
23786
|
}
|
|
22630
|
-
while (!this.router.activePorts(owner).length && pendingHandles() > 0) {
|
|
23787
|
+
while (!this.router.activePorts(owner).length && (pendingHandles() > 0 || readingStdin())) {
|
|
22631
23788
|
await new Promise((resolve2) => setTimeout(resolve2, 5));
|
|
22632
23789
|
}
|
|
22633
23790
|
}
|
|
@@ -22646,6 +23803,7 @@ var LocalRuntimePod = class _LocalRuntimePod {
|
|
|
22646
23803
|
teardown() {
|
|
22647
23804
|
this.disposed = true;
|
|
22648
23805
|
this.router.closeAll();
|
|
23806
|
+
this.esbuild?.stop();
|
|
22649
23807
|
}
|
|
22650
23808
|
seed(files) {
|
|
22651
23809
|
for (const [path, data] of Object.entries(files)) {
|
|
@@ -22758,9 +23916,9 @@ var Container = class _Container {
|
|
|
22758
23916
|
}
|
|
22759
23917
|
mountSync(files, opts) {
|
|
22760
23918
|
this.assertActive();
|
|
22761
|
-
const
|
|
23919
|
+
const base2 = opts.cwd ?? this.defaults.cwd;
|
|
22762
23920
|
for (const [key, content] of Object.entries(files)) {
|
|
22763
|
-
const abs = resolve(
|
|
23921
|
+
const abs = resolve(base2, key);
|
|
22764
23922
|
const parent = dirname(abs);
|
|
22765
23923
|
if (!this.kernel.vfs.lexists(parent)) {
|
|
22766
23924
|
this.kernel.vfs.mkdir(parent, { recursive: true, mode: 493, cred: this.defaults.cred });
|
|
@@ -23002,17 +24160,17 @@ var Container = class _Container {
|
|
|
23002
24160
|
body: init.body ?? null
|
|
23003
24161
|
});
|
|
23004
24162
|
const bodyRaw = res.body;
|
|
23005
|
-
const
|
|
24163
|
+
const bytes2 = bodyRaw instanceof Uint8Array ? bodyRaw : (
|
|
23006
24164
|
// The binary dispatcher answers with an ArrayBuffer.
|
|
23007
24165
|
bodyRaw instanceof ArrayBuffer ? new Uint8Array(bodyRaw) : typeof bodyRaw === "string" ? new TextEncoder().encode(bodyRaw) : new Uint8Array(0)
|
|
23008
24166
|
);
|
|
23009
|
-
const body = typeof bodyRaw === "string" ? bodyRaw : new TextDecoder().decode(
|
|
24167
|
+
const body = typeof bodyRaw === "string" ? bodyRaw : new TextDecoder().decode(bytes2);
|
|
23010
24168
|
return {
|
|
23011
24169
|
status: res.statusCode ?? 200,
|
|
23012
24170
|
statusText: res.statusMessage ?? "",
|
|
23013
24171
|
headers: res.headers ?? {},
|
|
23014
24172
|
body,
|
|
23015
|
-
bytes,
|
|
24173
|
+
bytes: bytes2,
|
|
23016
24174
|
json() {
|
|
23017
24175
|
return JSON.parse(body);
|
|
23018
24176
|
}
|
|
@@ -23242,7 +24400,7 @@ var Terminal = class {
|
|
|
23242
24400
|
this.currentStdin?.end();
|
|
23243
24401
|
return;
|
|
23244
24402
|
}
|
|
23245
|
-
this.write(ch === "\r" ? "\r\n" : ch);
|
|
24403
|
+
if (!this.currentStdin?.rawMode) this.write(ch === "\r" ? "\r\n" : ch);
|
|
23246
24404
|
this.currentStdin?.write(ch === "\r" ? "\n" : ch);
|
|
23247
24405
|
return;
|
|
23248
24406
|
}
|
|
@@ -23398,8 +24556,8 @@ var Terminal = class {
|
|
|
23398
24556
|
// ── completion ────────────────────────────────────────────────────────────
|
|
23399
24557
|
complete() {
|
|
23400
24558
|
const left = this.buffer.slice(0, this.cursor);
|
|
23401
|
-
const
|
|
23402
|
-
const word =
|
|
24559
|
+
const match2 = /(\S*)$/.exec(left);
|
|
24560
|
+
const word = match2?.[1] ?? "";
|
|
23403
24561
|
const isFirstWord = left.slice(0, left.length - word.length).trim() === "";
|
|
23404
24562
|
const candidates = isFirstWord && !word.includes("/") ? this.completeCommand(word) : this.completePath(word);
|
|
23405
24563
|
if (candidates.length === 0) return;
|
|
@@ -23504,13 +24662,13 @@ var Terminal = class {
|
|
|
23504
24662
|
this.writePrompt();
|
|
23505
24663
|
}
|
|
23506
24664
|
};
|
|
23507
|
-
function expandPrompt(
|
|
24665
|
+
function expandPrompt(format3, session) {
|
|
23508
24666
|
const shell = session.shell;
|
|
23509
24667
|
const home = shell.vars.get("HOME") ?? "/root";
|
|
23510
24668
|
const cwd = shell.cwd;
|
|
23511
24669
|
const user = shell.kernel.users.nameForUid(shell.cred.uid);
|
|
23512
24670
|
const now = new Date(shell.kernel.now());
|
|
23513
|
-
return
|
|
24671
|
+
return format3.replace(/\\(.)/g, (_, ch) => {
|
|
23514
24672
|
switch (ch) {
|
|
23515
24673
|
case "u":
|
|
23516
24674
|
return user;
|