@poe-platform/safe-bash 0.1.60 → 0.1.62
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/dist/safe-bash/browser.js +699 -419
- package/dist/safe-bash/browser.js.map +4 -4
- package/dist/safe-bash/commands/regex-execution/bounded-provider.d.ts +15 -0
- package/dist/safe-bash/commands/regex-execution/bounded-provider.d.ts.map +1 -0
- package/dist/safe-bash/commands/regex-execution/bounded-provider.js +319 -0
- package/dist/safe-bash/commands/regex-execution/bounded-provider.js.map +1 -0
- package/dist/safe-bash/commands/regex-execution/public.d.ts +1 -0
- package/dist/safe-bash/commands/regex-execution/public.d.ts.map +1 -1
- package/dist/safe-bash/commands/regex-execution/public.js +1 -0
- package/dist/safe-bash/commands/regex-execution/public.js.map +1 -1
- package/dist/safe-bash/shell/runtime.d.ts.map +1 -1
- package/dist/safe-bash/shell/runtime.js +4 -0
- package/dist/safe-bash/shell/runtime.js.map +1 -1
- package/dist/safe-bash/shell/types.d.ts +3 -0
- package/dist/safe-bash/shell/types.d.ts.map +1 -1
- package/dist/safe-bash/shell/types.js.map +1 -1
- package/dist/safe-bash/shell/worker-limits.d.ts.map +1 -1
- package/dist/safe-bash/shell/worker-limits.js +1 -0
- package/dist/safe-bash/shell/worker-limits.js.map +1 -1
- package/package.json +2 -2
|
@@ -41,7 +41,7 @@ var require_base64_js = __commonJS({
|
|
|
41
41
|
"node_modules/base64-js/index.js"(exports) {
|
|
42
42
|
"use strict";
|
|
43
43
|
init_platform();
|
|
44
|
-
exports.byteLength =
|
|
44
|
+
exports.byteLength = byteLength2;
|
|
45
45
|
exports.toByteArray = toByteArray;
|
|
46
46
|
exports.fromByteArray = fromByteArray;
|
|
47
47
|
var lookup = [];
|
|
@@ -66,7 +66,7 @@ var require_base64_js = __commonJS({
|
|
|
66
66
|
var placeHoldersLen = validLen === len2 ? 0 : 4 - validLen % 4;
|
|
67
67
|
return [validLen, placeHoldersLen];
|
|
68
68
|
}
|
|
69
|
-
function
|
|
69
|
+
function byteLength2(b64) {
|
|
70
70
|
var lens = getLens(b64);
|
|
71
71
|
var validLen = lens[0];
|
|
72
72
|
var placeHoldersLen = lens[1];
|
|
@@ -366,7 +366,7 @@ var require_buffer = __commonJS({
|
|
|
366
366
|
if (!Buffer3.isEncoding(encoding)) {
|
|
367
367
|
throw new TypeError("Unknown encoding: " + encoding);
|
|
368
368
|
}
|
|
369
|
-
const length =
|
|
369
|
+
const length = byteLength2(string, encoding) | 0;
|
|
370
370
|
let buf = createBuffer(length);
|
|
371
371
|
const actual = buf.write(string, encoding);
|
|
372
372
|
if (actual !== length) {
|
|
@@ -374,11 +374,11 @@ var require_buffer = __commonJS({
|
|
|
374
374
|
}
|
|
375
375
|
return buf;
|
|
376
376
|
}
|
|
377
|
-
function fromArrayLike(
|
|
378
|
-
const length =
|
|
377
|
+
function fromArrayLike(array2) {
|
|
378
|
+
const length = array2.length < 0 ? 0 : checked(array2.length) | 0;
|
|
379
379
|
const buf = createBuffer(length);
|
|
380
380
|
for (let i = 0; i < length; i += 1) {
|
|
381
|
-
buf[i] =
|
|
381
|
+
buf[i] = array2[i] & 255;
|
|
382
382
|
}
|
|
383
383
|
return buf;
|
|
384
384
|
}
|
|
@@ -389,20 +389,20 @@ var require_buffer = __commonJS({
|
|
|
389
389
|
}
|
|
390
390
|
return fromArrayLike(arrayView);
|
|
391
391
|
}
|
|
392
|
-
function fromArrayBuffer(
|
|
393
|
-
if (
|
|
392
|
+
function fromArrayBuffer(array2, byteOffset2, length) {
|
|
393
|
+
if (byteOffset2 < 0 || array2.byteLength < byteOffset2) {
|
|
394
394
|
throw new RangeError('"offset" is outside of buffer bounds');
|
|
395
395
|
}
|
|
396
|
-
if (
|
|
396
|
+
if (array2.byteLength < byteOffset2 + (length || 0)) {
|
|
397
397
|
throw new RangeError('"length" is outside of buffer bounds');
|
|
398
398
|
}
|
|
399
399
|
let buf;
|
|
400
|
-
if (
|
|
401
|
-
buf = new Uint8Array(
|
|
400
|
+
if (byteOffset2 === void 0 && length === void 0) {
|
|
401
|
+
buf = new Uint8Array(array2);
|
|
402
402
|
} else if (length === void 0) {
|
|
403
|
-
buf = new Uint8Array(
|
|
403
|
+
buf = new Uint8Array(array2, byteOffset2);
|
|
404
404
|
} else {
|
|
405
|
-
buf = new Uint8Array(
|
|
405
|
+
buf = new Uint8Array(array2, byteOffset2, length);
|
|
406
406
|
}
|
|
407
407
|
Object.setPrototypeOf(buf, Buffer3.prototype);
|
|
408
408
|
return buf;
|
|
@@ -520,7 +520,7 @@ var require_buffer = __commonJS({
|
|
|
520
520
|
}
|
|
521
521
|
return buffer;
|
|
522
522
|
};
|
|
523
|
-
function
|
|
523
|
+
function byteLength2(string, encoding) {
|
|
524
524
|
if (Buffer3.isBuffer(string)) {
|
|
525
525
|
return string.length;
|
|
526
526
|
}
|
|
@@ -563,7 +563,7 @@ var require_buffer = __commonJS({
|
|
|
563
563
|
}
|
|
564
564
|
}
|
|
565
565
|
}
|
|
566
|
-
Buffer3.byteLength =
|
|
566
|
+
Buffer3.byteLength = byteLength2;
|
|
567
567
|
function slowToString(encoding, start, end) {
|
|
568
568
|
let loweredCase = false;
|
|
569
569
|
if (start === void 0 || start < 0) {
|
|
@@ -726,26 +726,26 @@ var require_buffer = __commonJS({
|
|
|
726
726
|
if (y < x) return 1;
|
|
727
727
|
return 0;
|
|
728
728
|
};
|
|
729
|
-
function bidirectionalIndexOf(buffer, val,
|
|
729
|
+
function bidirectionalIndexOf(buffer, val, byteOffset2, encoding, dir) {
|
|
730
730
|
if (buffer.length === 0) return -1;
|
|
731
|
-
if (typeof
|
|
732
|
-
encoding =
|
|
733
|
-
|
|
734
|
-
} else if (
|
|
735
|
-
|
|
736
|
-
} else if (
|
|
737
|
-
|
|
738
|
-
}
|
|
739
|
-
|
|
740
|
-
if (numberIsNaN(
|
|
741
|
-
|
|
742
|
-
}
|
|
743
|
-
if (
|
|
744
|
-
if (
|
|
731
|
+
if (typeof byteOffset2 === "string") {
|
|
732
|
+
encoding = byteOffset2;
|
|
733
|
+
byteOffset2 = 0;
|
|
734
|
+
} else if (byteOffset2 > 2147483647) {
|
|
735
|
+
byteOffset2 = 2147483647;
|
|
736
|
+
} else if (byteOffset2 < -2147483648) {
|
|
737
|
+
byteOffset2 = -2147483648;
|
|
738
|
+
}
|
|
739
|
+
byteOffset2 = +byteOffset2;
|
|
740
|
+
if (numberIsNaN(byteOffset2)) {
|
|
741
|
+
byteOffset2 = dir ? 0 : buffer.length - 1;
|
|
742
|
+
}
|
|
743
|
+
if (byteOffset2 < 0) byteOffset2 = buffer.length + byteOffset2;
|
|
744
|
+
if (byteOffset2 >= buffer.length) {
|
|
745
745
|
if (dir) return -1;
|
|
746
|
-
else
|
|
747
|
-
} else if (
|
|
748
|
-
if (dir)
|
|
746
|
+
else byteOffset2 = buffer.length - 1;
|
|
747
|
+
} else if (byteOffset2 < 0) {
|
|
748
|
+
if (dir) byteOffset2 = 0;
|
|
749
749
|
else return -1;
|
|
750
750
|
}
|
|
751
751
|
if (typeof val === "string") {
|
|
@@ -755,21 +755,21 @@ var require_buffer = __commonJS({
|
|
|
755
755
|
if (val.length === 0) {
|
|
756
756
|
return -1;
|
|
757
757
|
}
|
|
758
|
-
return arrayIndexOf(buffer, val,
|
|
758
|
+
return arrayIndexOf(buffer, val, byteOffset2, encoding, dir);
|
|
759
759
|
} else if (typeof val === "number") {
|
|
760
760
|
val = val & 255;
|
|
761
761
|
if (typeof Uint8Array.prototype.indexOf === "function") {
|
|
762
762
|
if (dir) {
|
|
763
|
-
return Uint8Array.prototype.indexOf.call(buffer, val,
|
|
763
|
+
return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset2);
|
|
764
764
|
} else {
|
|
765
|
-
return Uint8Array.prototype.lastIndexOf.call(buffer, val,
|
|
765
|
+
return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset2);
|
|
766
766
|
}
|
|
767
767
|
}
|
|
768
|
-
return arrayIndexOf(buffer, [val],
|
|
768
|
+
return arrayIndexOf(buffer, [val], byteOffset2, encoding, dir);
|
|
769
769
|
}
|
|
770
770
|
throw new TypeError("val must be string, number or Buffer");
|
|
771
771
|
}
|
|
772
|
-
function arrayIndexOf(arr, val,
|
|
772
|
+
function arrayIndexOf(arr, val, byteOffset2, encoding, dir) {
|
|
773
773
|
let indexSize = 1;
|
|
774
774
|
let arrLength = arr.length;
|
|
775
775
|
let valLength = val.length;
|
|
@@ -782,7 +782,7 @@ var require_buffer = __commonJS({
|
|
|
782
782
|
indexSize = 2;
|
|
783
783
|
arrLength /= 2;
|
|
784
784
|
valLength /= 2;
|
|
785
|
-
|
|
785
|
+
byteOffset2 /= 2;
|
|
786
786
|
}
|
|
787
787
|
}
|
|
788
788
|
function read(buf, i2) {
|
|
@@ -795,7 +795,7 @@ var require_buffer = __commonJS({
|
|
|
795
795
|
let i;
|
|
796
796
|
if (dir) {
|
|
797
797
|
let foundIndex = -1;
|
|
798
|
-
for (i =
|
|
798
|
+
for (i = byteOffset2; i < arrLength; i++) {
|
|
799
799
|
if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
|
|
800
800
|
if (foundIndex === -1) foundIndex = i;
|
|
801
801
|
if (i - foundIndex + 1 === valLength) return foundIndex * indexSize;
|
|
@@ -805,8 +805,8 @@ var require_buffer = __commonJS({
|
|
|
805
805
|
}
|
|
806
806
|
}
|
|
807
807
|
} else {
|
|
808
|
-
if (
|
|
809
|
-
for (i =
|
|
808
|
+
if (byteOffset2 + valLength > arrLength) byteOffset2 = arrLength - valLength;
|
|
809
|
+
for (i = byteOffset2; i >= 0; i--) {
|
|
810
810
|
let found = true;
|
|
811
811
|
for (let j = 0; j < valLength; j++) {
|
|
812
812
|
if (read(arr, i + j) !== read(val, j)) {
|
|
@@ -819,14 +819,14 @@ var require_buffer = __commonJS({
|
|
|
819
819
|
}
|
|
820
820
|
return -1;
|
|
821
821
|
}
|
|
822
|
-
Buffer3.prototype.includes = function includes(val,
|
|
823
|
-
return this.indexOf(val,
|
|
822
|
+
Buffer3.prototype.includes = function includes(val, byteOffset2, encoding) {
|
|
823
|
+
return this.indexOf(val, byteOffset2, encoding) !== -1;
|
|
824
824
|
};
|
|
825
|
-
Buffer3.prototype.indexOf = function indexOf(val,
|
|
826
|
-
return bidirectionalIndexOf(this, val,
|
|
825
|
+
Buffer3.prototype.indexOf = function indexOf(val, byteOffset2, encoding) {
|
|
826
|
+
return bidirectionalIndexOf(this, val, byteOffset2, encoding, true);
|
|
827
827
|
};
|
|
828
|
-
Buffer3.prototype.lastIndexOf = function lastIndexOf(val,
|
|
829
|
-
return bidirectionalIndexOf(this, val,
|
|
828
|
+
Buffer3.prototype.lastIndexOf = function lastIndexOf(val, byteOffset2, encoding) {
|
|
829
|
+
return bidirectionalIndexOf(this, val, byteOffset2, encoding, false);
|
|
830
830
|
};
|
|
831
831
|
function hexWrite(buf, string, offset, length) {
|
|
832
832
|
offset = Number(offset) || 0;
|
|
@@ -1066,28 +1066,28 @@ var require_buffer = __commonJS({
|
|
|
1066
1066
|
if (offset % 1 !== 0 || offset < 0) throw new RangeError("offset is not uint");
|
|
1067
1067
|
if (offset + ext > length) throw new RangeError("Trying to access beyond buffer length");
|
|
1068
1068
|
}
|
|
1069
|
-
Buffer3.prototype.readUintLE = Buffer3.prototype.readUIntLE = function readUIntLE(offset,
|
|
1069
|
+
Buffer3.prototype.readUintLE = Buffer3.prototype.readUIntLE = function readUIntLE(offset, byteLength3, noAssert) {
|
|
1070
1070
|
offset = offset >>> 0;
|
|
1071
|
-
|
|
1072
|
-
if (!noAssert) checkOffset(offset,
|
|
1071
|
+
byteLength3 = byteLength3 >>> 0;
|
|
1072
|
+
if (!noAssert) checkOffset(offset, byteLength3, this.length);
|
|
1073
1073
|
let val = this[offset];
|
|
1074
1074
|
let mul = 1;
|
|
1075
1075
|
let i = 0;
|
|
1076
|
-
while (++i <
|
|
1076
|
+
while (++i < byteLength3 && (mul *= 256)) {
|
|
1077
1077
|
val += this[offset + i] * mul;
|
|
1078
1078
|
}
|
|
1079
1079
|
return val;
|
|
1080
1080
|
};
|
|
1081
|
-
Buffer3.prototype.readUintBE = Buffer3.prototype.readUIntBE = function readUIntBE(offset,
|
|
1081
|
+
Buffer3.prototype.readUintBE = Buffer3.prototype.readUIntBE = function readUIntBE(offset, byteLength3, noAssert) {
|
|
1082
1082
|
offset = offset >>> 0;
|
|
1083
|
-
|
|
1083
|
+
byteLength3 = byteLength3 >>> 0;
|
|
1084
1084
|
if (!noAssert) {
|
|
1085
|
-
checkOffset(offset,
|
|
1085
|
+
checkOffset(offset, byteLength3, this.length);
|
|
1086
1086
|
}
|
|
1087
|
-
let val = this[offset + --
|
|
1087
|
+
let val = this[offset + --byteLength3];
|
|
1088
1088
|
let mul = 1;
|
|
1089
|
-
while (
|
|
1090
|
-
val += this[offset + --
|
|
1089
|
+
while (byteLength3 > 0 && (mul *= 256)) {
|
|
1090
|
+
val += this[offset + --byteLength3] * mul;
|
|
1091
1091
|
}
|
|
1092
1092
|
return val;
|
|
1093
1093
|
};
|
|
@@ -1140,32 +1140,32 @@ var require_buffer = __commonJS({
|
|
|
1140
1140
|
const lo = this[++offset] * 2 ** 24 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 8 + last;
|
|
1141
1141
|
return (BigInt(hi) << BigInt(32)) + BigInt(lo);
|
|
1142
1142
|
});
|
|
1143
|
-
Buffer3.prototype.readIntLE = function readIntLE(offset,
|
|
1143
|
+
Buffer3.prototype.readIntLE = function readIntLE(offset, byteLength3, noAssert) {
|
|
1144
1144
|
offset = offset >>> 0;
|
|
1145
|
-
|
|
1146
|
-
if (!noAssert) checkOffset(offset,
|
|
1145
|
+
byteLength3 = byteLength3 >>> 0;
|
|
1146
|
+
if (!noAssert) checkOffset(offset, byteLength3, this.length);
|
|
1147
1147
|
let val = this[offset];
|
|
1148
1148
|
let mul = 1;
|
|
1149
1149
|
let i = 0;
|
|
1150
|
-
while (++i <
|
|
1150
|
+
while (++i < byteLength3 && (mul *= 256)) {
|
|
1151
1151
|
val += this[offset + i] * mul;
|
|
1152
1152
|
}
|
|
1153
1153
|
mul *= 128;
|
|
1154
|
-
if (val >= mul) val -= Math.pow(2, 8 *
|
|
1154
|
+
if (val >= mul) val -= Math.pow(2, 8 * byteLength3);
|
|
1155
1155
|
return val;
|
|
1156
1156
|
};
|
|
1157
|
-
Buffer3.prototype.readIntBE = function readIntBE(offset,
|
|
1157
|
+
Buffer3.prototype.readIntBE = function readIntBE(offset, byteLength3, noAssert) {
|
|
1158
1158
|
offset = offset >>> 0;
|
|
1159
|
-
|
|
1160
|
-
if (!noAssert) checkOffset(offset,
|
|
1161
|
-
let i =
|
|
1159
|
+
byteLength3 = byteLength3 >>> 0;
|
|
1160
|
+
if (!noAssert) checkOffset(offset, byteLength3, this.length);
|
|
1161
|
+
let i = byteLength3;
|
|
1162
1162
|
let mul = 1;
|
|
1163
1163
|
let val = this[offset + --i];
|
|
1164
1164
|
while (i > 0 && (mul *= 256)) {
|
|
1165
1165
|
val += this[offset + --i] * mul;
|
|
1166
1166
|
}
|
|
1167
1167
|
mul *= 128;
|
|
1168
|
-
if (val >= mul) val -= Math.pow(2, 8 *
|
|
1168
|
+
if (val >= mul) val -= Math.pow(2, 8 * byteLength3);
|
|
1169
1169
|
return val;
|
|
1170
1170
|
};
|
|
1171
1171
|
Buffer3.prototype.readInt8 = function readInt8(offset, noAssert) {
|
|
@@ -1244,37 +1244,37 @@ var require_buffer = __commonJS({
|
|
|
1244
1244
|
if (value2 > max || value2 < min) throw new RangeError('"value" argument is out of bounds');
|
|
1245
1245
|
if (offset + ext > buf.length) throw new RangeError("Index out of range");
|
|
1246
1246
|
}
|
|
1247
|
-
Buffer3.prototype.writeUintLE = Buffer3.prototype.writeUIntLE = function writeUIntLE(value2, offset,
|
|
1247
|
+
Buffer3.prototype.writeUintLE = Buffer3.prototype.writeUIntLE = function writeUIntLE(value2, offset, byteLength3, noAssert) {
|
|
1248
1248
|
value2 = +value2;
|
|
1249
1249
|
offset = offset >>> 0;
|
|
1250
|
-
|
|
1250
|
+
byteLength3 = byteLength3 >>> 0;
|
|
1251
1251
|
if (!noAssert) {
|
|
1252
|
-
const maxBytes = Math.pow(2, 8 *
|
|
1253
|
-
checkInt(this, value2, offset,
|
|
1252
|
+
const maxBytes = Math.pow(2, 8 * byteLength3) - 1;
|
|
1253
|
+
checkInt(this, value2, offset, byteLength3, maxBytes, 0);
|
|
1254
1254
|
}
|
|
1255
1255
|
let mul = 1;
|
|
1256
1256
|
let i = 0;
|
|
1257
1257
|
this[offset] = value2 & 255;
|
|
1258
|
-
while (++i <
|
|
1258
|
+
while (++i < byteLength3 && (mul *= 256)) {
|
|
1259
1259
|
this[offset + i] = value2 / mul & 255;
|
|
1260
1260
|
}
|
|
1261
|
-
return offset +
|
|
1261
|
+
return offset + byteLength3;
|
|
1262
1262
|
};
|
|
1263
|
-
Buffer3.prototype.writeUintBE = Buffer3.prototype.writeUIntBE = function writeUIntBE(value2, offset,
|
|
1263
|
+
Buffer3.prototype.writeUintBE = Buffer3.prototype.writeUIntBE = function writeUIntBE(value2, offset, byteLength3, noAssert) {
|
|
1264
1264
|
value2 = +value2;
|
|
1265
1265
|
offset = offset >>> 0;
|
|
1266
|
-
|
|
1266
|
+
byteLength3 = byteLength3 >>> 0;
|
|
1267
1267
|
if (!noAssert) {
|
|
1268
|
-
const maxBytes = Math.pow(2, 8 *
|
|
1269
|
-
checkInt(this, value2, offset,
|
|
1268
|
+
const maxBytes = Math.pow(2, 8 * byteLength3) - 1;
|
|
1269
|
+
checkInt(this, value2, offset, byteLength3, maxBytes, 0);
|
|
1270
1270
|
}
|
|
1271
|
-
let i =
|
|
1271
|
+
let i = byteLength3 - 1;
|
|
1272
1272
|
let mul = 1;
|
|
1273
1273
|
this[offset + i] = value2 & 255;
|
|
1274
1274
|
while (--i >= 0 && (mul *= 256)) {
|
|
1275
1275
|
this[offset + i] = value2 / mul & 255;
|
|
1276
1276
|
}
|
|
1277
|
-
return offset +
|
|
1277
|
+
return offset + byteLength3;
|
|
1278
1278
|
};
|
|
1279
1279
|
Buffer3.prototype.writeUint8 = Buffer3.prototype.writeUInt8 = function writeUInt8(value2, offset, noAssert) {
|
|
1280
1280
|
value2 = +value2;
|
|
@@ -1365,33 +1365,33 @@ var require_buffer = __commonJS({
|
|
|
1365
1365
|
Buffer3.prototype.writeBigUInt64BE = defineBigIntMethod(function writeBigUInt64BE(value2, offset = 0) {
|
|
1366
1366
|
return wrtBigUInt64BE(this, value2, offset, BigInt(0), BigInt("0xffffffffffffffff"));
|
|
1367
1367
|
});
|
|
1368
|
-
Buffer3.prototype.writeIntLE = function writeIntLE(value2, offset,
|
|
1368
|
+
Buffer3.prototype.writeIntLE = function writeIntLE(value2, offset, byteLength3, noAssert) {
|
|
1369
1369
|
value2 = +value2;
|
|
1370
1370
|
offset = offset >>> 0;
|
|
1371
1371
|
if (!noAssert) {
|
|
1372
|
-
const limit = Math.pow(2, 8 *
|
|
1373
|
-
checkInt(this, value2, offset,
|
|
1372
|
+
const limit = Math.pow(2, 8 * byteLength3 - 1);
|
|
1373
|
+
checkInt(this, value2, offset, byteLength3, limit - 1, -limit);
|
|
1374
1374
|
}
|
|
1375
1375
|
let i = 0;
|
|
1376
1376
|
let mul = 1;
|
|
1377
1377
|
let sub = 0;
|
|
1378
1378
|
this[offset] = value2 & 255;
|
|
1379
|
-
while (++i <
|
|
1379
|
+
while (++i < byteLength3 && (mul *= 256)) {
|
|
1380
1380
|
if (value2 < 0 && sub === 0 && this[offset + i - 1] !== 0) {
|
|
1381
1381
|
sub = 1;
|
|
1382
1382
|
}
|
|
1383
1383
|
this[offset + i] = (value2 / mul >> 0) - sub & 255;
|
|
1384
1384
|
}
|
|
1385
|
-
return offset +
|
|
1385
|
+
return offset + byteLength3;
|
|
1386
1386
|
};
|
|
1387
|
-
Buffer3.prototype.writeIntBE = function writeIntBE(value2, offset,
|
|
1387
|
+
Buffer3.prototype.writeIntBE = function writeIntBE(value2, offset, byteLength3, noAssert) {
|
|
1388
1388
|
value2 = +value2;
|
|
1389
1389
|
offset = offset >>> 0;
|
|
1390
1390
|
if (!noAssert) {
|
|
1391
|
-
const limit = Math.pow(2, 8 *
|
|
1392
|
-
checkInt(this, value2, offset,
|
|
1391
|
+
const limit = Math.pow(2, 8 * byteLength3 - 1);
|
|
1392
|
+
checkInt(this, value2, offset, byteLength3, limit - 1, -limit);
|
|
1393
1393
|
}
|
|
1394
|
-
let i =
|
|
1394
|
+
let i = byteLength3 - 1;
|
|
1395
1395
|
let mul = 1;
|
|
1396
1396
|
let sub = 0;
|
|
1397
1397
|
this[offset + i] = value2 & 255;
|
|
@@ -1401,7 +1401,7 @@ var require_buffer = __commonJS({
|
|
|
1401
1401
|
}
|
|
1402
1402
|
this[offset + i] = (value2 / mul >> 0) - sub & 255;
|
|
1403
1403
|
}
|
|
1404
|
-
return offset +
|
|
1404
|
+
return offset + byteLength3;
|
|
1405
1405
|
};
|
|
1406
1406
|
Buffer3.prototype.writeInt8 = function writeInt8(value2, offset, noAssert) {
|
|
1407
1407
|
value2 = +value2;
|
|
@@ -1646,28 +1646,28 @@ var require_buffer = __commonJS({
|
|
|
1646
1646
|
}
|
|
1647
1647
|
return `${val.slice(0, i)}${res}`;
|
|
1648
1648
|
}
|
|
1649
|
-
function checkBounds(buf, offset,
|
|
1649
|
+
function checkBounds(buf, offset, byteLength3) {
|
|
1650
1650
|
validateNumber(offset, "offset");
|
|
1651
|
-
if (buf[offset] === void 0 || buf[offset +
|
|
1652
|
-
boundsError(offset, buf.length - (
|
|
1651
|
+
if (buf[offset] === void 0 || buf[offset + byteLength3] === void 0) {
|
|
1652
|
+
boundsError(offset, buf.length - (byteLength3 + 1));
|
|
1653
1653
|
}
|
|
1654
1654
|
}
|
|
1655
|
-
function checkIntBI(value2, min, max, buf, offset,
|
|
1655
|
+
function checkIntBI(value2, min, max, buf, offset, byteLength3) {
|
|
1656
1656
|
if (value2 > max || value2 < min) {
|
|
1657
1657
|
const n = typeof min === "bigint" ? "n" : "";
|
|
1658
1658
|
let range;
|
|
1659
|
-
if (
|
|
1659
|
+
if (byteLength3 > 3) {
|
|
1660
1660
|
if (min === 0 || min === BigInt(0)) {
|
|
1661
|
-
range = `>= 0${n} and < 2${n} ** ${(
|
|
1661
|
+
range = `>= 0${n} and < 2${n} ** ${(byteLength3 + 1) * 8}${n}`;
|
|
1662
1662
|
} else {
|
|
1663
|
-
range = `>= -(2${n} ** ${(
|
|
1663
|
+
range = `>= -(2${n} ** ${(byteLength3 + 1) * 8 - 1}${n}) and < 2 ** ${(byteLength3 + 1) * 8 - 1}${n}`;
|
|
1664
1664
|
}
|
|
1665
1665
|
} else {
|
|
1666
1666
|
range = `>= ${min}${n} and <= ${max}${n}`;
|
|
1667
1667
|
}
|
|
1668
1668
|
throw new errors.ERR_OUT_OF_RANGE("value", range, value2);
|
|
1669
1669
|
}
|
|
1670
|
-
checkBounds(buf, offset,
|
|
1670
|
+
checkBounds(buf, offset, byteLength3);
|
|
1671
1671
|
}
|
|
1672
1672
|
function validateNumber(value2, name2) {
|
|
1673
1673
|
if (typeof value2 !== "number") {
|
|
@@ -2179,18 +2179,18 @@ var CommandRegistry = class {
|
|
|
2179
2179
|
constructor(commands = []) {
|
|
2180
2180
|
for (const command2 of commands) this.register(command2);
|
|
2181
2181
|
}
|
|
2182
|
-
register(command2,
|
|
2183
|
-
const { name: name2, execute:
|
|
2182
|
+
register(command2, options3 = {}) {
|
|
2183
|
+
const { name: name2, execute: execute3 } = command2;
|
|
2184
2184
|
if (typeof name2 !== "string" || !name2 || /[\s/\0]/u.test(name2)) {
|
|
2185
2185
|
throw new TypeError("Command names must be nonempty and contain no whitespace, slash, or NUL");
|
|
2186
2186
|
}
|
|
2187
|
-
if (typeof
|
|
2187
|
+
if (typeof execute3 !== "function") {
|
|
2188
2188
|
throw new TypeError("Command execute must be a function");
|
|
2189
2189
|
}
|
|
2190
|
-
if (this.#commands.has(name2) && !
|
|
2190
|
+
if (this.#commands.has(name2) && !options3.replace) {
|
|
2191
2191
|
throw new Error(`Command already registered: ${name2}`);
|
|
2192
2192
|
}
|
|
2193
|
-
this.#commands.set(name2, Object.freeze({ ...command2, name: name2, execute:
|
|
2193
|
+
this.#commands.set(name2, Object.freeze({ ...command2, name: name2, execute: execute3 }));
|
|
2194
2194
|
return this;
|
|
2195
2195
|
}
|
|
2196
2196
|
get(name2) {
|
|
@@ -2273,9 +2273,9 @@ init_platform();
|
|
|
2273
2273
|
import { collectBytes, readBytes } from "@poe-platform/safe-fs/core";
|
|
2274
2274
|
import { collectBytes as collectBytes2, readBytes as readBytes2, toByteSource } from "@poe-platform/safe-fs/core";
|
|
2275
2275
|
var outputFailure = /* @__PURE__ */ Symbol("output failure");
|
|
2276
|
-
function createBytePipe(
|
|
2277
|
-
const highWaterMark =
|
|
2278
|
-
const signal =
|
|
2276
|
+
function createBytePipe(options3 = {}) {
|
|
2277
|
+
const highWaterMark = options3.highWaterMark ?? 64 * 1024;
|
|
2278
|
+
const signal = options3.signal;
|
|
2279
2279
|
if (!Number.isSafeInteger(highWaterMark) || highWaterMark < 1) {
|
|
2280
2280
|
throw new RangeError("highWaterMark must be a positive safe integer");
|
|
2281
2281
|
}
|
|
@@ -2390,8 +2390,8 @@ async function pipeBytes(source, sink, signal) {
|
|
|
2390
2390
|
}
|
|
2391
2391
|
signal?.throwIfAborted();
|
|
2392
2392
|
}
|
|
2393
|
-
async function collectText(source,
|
|
2394
|
-
return new TextDecoder().decode(await collectBytes(source,
|
|
2393
|
+
async function collectText(source, options3) {
|
|
2394
|
+
return new TextDecoder().decode(await collectBytes(source, options3));
|
|
2395
2395
|
}
|
|
2396
2396
|
async function abortable(operation, signal) {
|
|
2397
2397
|
signal?.throwIfAborted();
|
|
@@ -3117,23 +3117,23 @@ function compareCopyIdentity(left, right) {
|
|
|
3117
3117
|
if (!left || !right || !complete(left) || !complete(right)) return "unknown";
|
|
3118
3118
|
return left.identityScope === right.identityScope && left.dev === right.dev && left.ino === right.ino ? "same" : "distinct";
|
|
3119
3119
|
}
|
|
3120
|
-
async function compareObservedEntries(fs, path, stat, peer, peerPath, peerStat,
|
|
3121
|
-
|
|
3120
|
+
async function compareObservedEntries(fs, path, stat, peer, peerPath, peerStat, options3 = {}) {
|
|
3121
|
+
options3.signal?.throwIfAborted();
|
|
3122
3122
|
const identity = compareCopyIdentity(stat, peerStat);
|
|
3123
3123
|
if (identity !== "unknown") return identity;
|
|
3124
3124
|
let result = "unknown";
|
|
3125
3125
|
const operands = fs === peer ? [[fs, path, peer, peerPath]] : [[fs, path, peer, peerPath], [peer, peerPath, fs, path]];
|
|
3126
3126
|
for (const [owner, ownPath, other, otherPath] of operands) {
|
|
3127
|
-
|
|
3127
|
+
options3.signal?.throwIfAborted();
|
|
3128
3128
|
if (!owner.compareEntry) continue;
|
|
3129
3129
|
let answer;
|
|
3130
3130
|
try {
|
|
3131
|
-
answer = await owner.compareEntry(ownPath, other, otherPath,
|
|
3131
|
+
answer = await owner.compareEntry(ownPath, other, otherPath, options3);
|
|
3132
3132
|
} catch (error) {
|
|
3133
|
-
|
|
3133
|
+
options3.signal?.throwIfAborted();
|
|
3134
3134
|
throw error;
|
|
3135
3135
|
}
|
|
3136
|
-
|
|
3136
|
+
options3.signal?.throwIfAborted();
|
|
3137
3137
|
if (answer !== "same" && answer !== "distinct" && answer !== "unknown") {
|
|
3138
3138
|
throw new FsError("EIO", { path, dest: peerPath, message: "invalid entry comparison answer" });
|
|
3139
3139
|
}
|
|
@@ -4761,15 +4761,15 @@ function textCommands() {
|
|
|
4761
4761
|
if (numericKey && numericKeyFlags.has("n") && !["b", "f"].some((flag) => numericKeyFlags.has(flag)) && !parsed.flags.has("c")) {
|
|
4762
4762
|
const keyedNumericValues = /* @__PURE__ */ new Map();
|
|
4763
4763
|
let retainedKeyBytes = 0;
|
|
4764
|
-
const keyedNumericValue = (
|
|
4765
|
-
const cached = keyedNumericValues.get(
|
|
4764
|
+
const keyedNumericValue = (record4) => {
|
|
4765
|
+
const cached = keyedNumericValues.get(record4);
|
|
4766
4766
|
if (cached !== void 0) return cached;
|
|
4767
4767
|
context.signal.throwIfAborted();
|
|
4768
|
-
const bytes2 = keyBytes(
|
|
4768
|
+
const bytes2 = keyBytes(record4, numericKey, separator, false);
|
|
4769
4769
|
const charge2 = 6 * bytes2.length + 2;
|
|
4770
4770
|
if (keyedNumericValues.size >= 16384 || charge2 > 1048576 - retainedKeyBytes) return parseNumeric(bytes2);
|
|
4771
4771
|
const parsedValue = parseNumeric(bytes2);
|
|
4772
|
-
keyedNumericValues.set(
|
|
4772
|
+
keyedNumericValues.set(record4, parsedValue);
|
|
4773
4773
|
retainedKeyBytes += charge2;
|
|
4774
4774
|
return parsedValue;
|
|
4775
4775
|
};
|
|
@@ -4815,13 +4815,13 @@ function textCommands() {
|
|
|
4815
4815
|
let previous;
|
|
4816
4816
|
let buffer = new Uint8Array(64 * 1024);
|
|
4817
4817
|
let used = 0;
|
|
4818
|
-
for (const
|
|
4818
|
+
for (const record4 of records) {
|
|
4819
4819
|
context.signal.throwIfAborted();
|
|
4820
|
-
if (parsed.flags.has("u") && previous !== void 0 && keyCompare(previous,
|
|
4820
|
+
if (parsed.flags.has("u") && previous !== void 0 && keyCompare(previous, record4) === 0) continue;
|
|
4821
4821
|
let offset = 0;
|
|
4822
|
-
while (offset <
|
|
4823
|
-
const length = Math.min(
|
|
4824
|
-
buffer.set(
|
|
4822
|
+
while (offset < record4.length) {
|
|
4823
|
+
const length = Math.min(record4.length - offset, buffer.length - used);
|
|
4824
|
+
buffer.set(record4.subarray(offset, offset + length), used);
|
|
4825
4825
|
offset += length;
|
|
4826
4826
|
used += length;
|
|
4827
4827
|
if (used === buffer.length) {
|
|
@@ -4836,7 +4836,7 @@ function textCommands() {
|
|
|
4836
4836
|
buffer = new Uint8Array(64 * 1024);
|
|
4837
4837
|
used = 0;
|
|
4838
4838
|
}
|
|
4839
|
-
previous =
|
|
4839
|
+
previous = record4;
|
|
4840
4840
|
}
|
|
4841
4841
|
if (used) yield buffer.subarray(0, used);
|
|
4842
4842
|
})();
|
|
@@ -4867,19 +4867,19 @@ function textCommands() {
|
|
|
4867
4867
|
let previousKey;
|
|
4868
4868
|
let count2 = 0;
|
|
4869
4869
|
const selected = () => (!parsed.flags.has("d") || count2 > 1) && (!parsed.flags.has("u") || count2 === 1);
|
|
4870
|
-
const
|
|
4870
|
+
const record4 = () => concatenate([...parsed.flags.has("c") ? [encoder2.encode(`${String(count2).padStart(7)} `)] : [], previous, Uint8Array.of(delimiter)]);
|
|
4871
4871
|
for await (const line of lines(input(context, parsed.operands[0]), delimiter)) {
|
|
4872
4872
|
context.signal.throwIfAborted();
|
|
4873
4873
|
const currentKey = key(line.bytes);
|
|
4874
4874
|
if (previousKey && compareBytes(previousKey, currentKey) === 0) count2++;
|
|
4875
4875
|
else {
|
|
4876
|
-
if (previous !== void 0 && selected()) yield
|
|
4876
|
+
if (previous !== void 0 && selected()) yield record4();
|
|
4877
4877
|
previous = line.bytes;
|
|
4878
4878
|
previousKey = currentKey;
|
|
4879
4879
|
count2 = 1;
|
|
4880
4880
|
}
|
|
4881
4881
|
}
|
|
4882
|
-
if (previous !== void 0 && selected()) yield
|
|
4882
|
+
if (previous !== void 0 && selected()) yield record4();
|
|
4883
4883
|
})();
|
|
4884
4884
|
if (parsed.operands[1] !== void 0 && parsed.operands[0] !== "-" && pathOf(context, parsed.operands[0]) === pathOf(context, parsed.operands[1])) throw new UsageError("input and output must be different files");
|
|
4885
4885
|
await emitRecords(context, records, parsed.operands[1]);
|
|
@@ -4912,9 +4912,9 @@ function textCommands() {
|
|
|
4912
4912
|
context.signal.throwIfAborted();
|
|
4913
4913
|
let bytes2;
|
|
4914
4914
|
if (mode === "f") {
|
|
4915
|
-
const
|
|
4915
|
+
const record4 = import_buffer.Buffer.from(line.bytes.buffer, line.bytes.byteOffset, line.bytes.byteLength);
|
|
4916
4916
|
const separator = import_buffer.Buffer.from(delimiter);
|
|
4917
|
-
let boundary =
|
|
4917
|
+
let boundary = record4.indexOf(separator);
|
|
4918
4918
|
if (boundary < 0) {
|
|
4919
4919
|
if (parsed.flags.has("s")) continue;
|
|
4920
4920
|
bytes2 = line.bytes;
|
|
@@ -4927,12 +4927,12 @@ function textCommands() {
|
|
|
4927
4927
|
while (true) {
|
|
4928
4928
|
if (selected(field++)) {
|
|
4929
4929
|
if (emitted) pieces.push(joiner);
|
|
4930
|
-
pieces.push(
|
|
4930
|
+
pieces.push(record4.subarray(start, boundary < 0 ? record4.length : boundary));
|
|
4931
4931
|
emitted = true;
|
|
4932
4932
|
}
|
|
4933
4933
|
if (boundary < 0) break;
|
|
4934
4934
|
start = boundary + separator.length;
|
|
4935
|
-
boundary =
|
|
4935
|
+
boundary = record4.indexOf(separator, start);
|
|
4936
4936
|
}
|
|
4937
4937
|
bytes2 = concatenate(pieces);
|
|
4938
4938
|
}
|
|
@@ -6316,7 +6316,7 @@ var Parser = class {
|
|
|
6316
6316
|
this.advance();
|
|
6317
6317
|
let nodes = 0;
|
|
6318
6318
|
const grouped = /* @__PURE__ */ new WeakSet();
|
|
6319
|
-
const
|
|
6319
|
+
const admit2 = () => {
|
|
6320
6320
|
if (nodes >= 4096) this.error("Conditional syntax exceeds 4096 nodes");
|
|
6321
6321
|
nodes++;
|
|
6322
6322
|
};
|
|
@@ -6327,7 +6327,7 @@ var Parser = class {
|
|
|
6327
6327
|
const primary = (depth) => {
|
|
6328
6328
|
if (depth > 64) this.error("Conditional syntax nesting exceeds 64");
|
|
6329
6329
|
if (this.is("!")) {
|
|
6330
|
-
|
|
6330
|
+
admit2();
|
|
6331
6331
|
this.advance();
|
|
6332
6332
|
const expression2 = primary(depth + 1);
|
|
6333
6333
|
return expression2.kind === "not" && !grouped.has(expression2) ? expression2.operand : { kind: "not", operand: expression2 };
|
|
@@ -6339,7 +6339,7 @@ var Parser = class {
|
|
|
6339
6339
|
grouped.add(expression2);
|
|
6340
6340
|
return expression2;
|
|
6341
6341
|
}
|
|
6342
|
-
|
|
6342
|
+
admit2();
|
|
6343
6343
|
const first = operand();
|
|
6344
6344
|
if (conditionalBinary.has(this.current.value)) {
|
|
6345
6345
|
const operator = this.current.value;
|
|
@@ -6354,7 +6354,7 @@ var Parser = class {
|
|
|
6354
6354
|
const conjunction = (depth) => {
|
|
6355
6355
|
let expression2 = primary(depth);
|
|
6356
6356
|
while (this.is("&&")) {
|
|
6357
|
-
|
|
6357
|
+
admit2();
|
|
6358
6358
|
this.advance();
|
|
6359
6359
|
expression2 = { kind: "and", left: expression2, right: primary(depth) };
|
|
6360
6360
|
}
|
|
@@ -6363,7 +6363,7 @@ var Parser = class {
|
|
|
6363
6363
|
const disjunction = (depth) => {
|
|
6364
6364
|
let expression2 = conjunction(depth);
|
|
6365
6365
|
while (this.is("||")) {
|
|
6366
|
-
|
|
6366
|
+
admit2();
|
|
6367
6367
|
this.advance();
|
|
6368
6368
|
expression2 = { kind: "or", left: expression2, right: conjunction(depth) };
|
|
6369
6369
|
}
|
|
@@ -6528,18 +6528,18 @@ var Parser = class {
|
|
|
6528
6528
|
return script;
|
|
6529
6529
|
}
|
|
6530
6530
|
redirect() {
|
|
6531
|
-
let
|
|
6531
|
+
let descriptor2;
|
|
6532
6532
|
if (this.current.kind === "word" && /^\d+$/u.test(this.current.value)) {
|
|
6533
6533
|
const next = this.peek();
|
|
6534
|
-
if (/^(?:>|>>|<|<<|<<-|<<<|>&|<&|>\|)$/u.test(next.value) && this.current.end === next.offset)
|
|
6534
|
+
if (/^(?:>|>>|<|<<|<<-|<<<|>&|<&|>\|)$/u.test(next.value) && this.current.end === next.offset) descriptor2 = Number(this.advance().value);
|
|
6535
6535
|
}
|
|
6536
6536
|
if (!/^(?:>|>>|<|<<|<<-|<<<|>&|<&|>\||&>)$/u.test(this.current.value) || this.current.kind !== "operator") return void 0;
|
|
6537
6537
|
const operator = this.advance().value;
|
|
6538
|
-
|
|
6539
|
-
if (!Number.isSafeInteger(
|
|
6538
|
+
descriptor2 ??= operator.startsWith("<") ? 0 : 1;
|
|
6539
|
+
if (!Number.isSafeInteger(descriptor2) || descriptor2 > 255) this.error("File descriptor must be between 0 and 255");
|
|
6540
6540
|
if (!this.current.word) this.error("Expected redirect target");
|
|
6541
6541
|
const target = this.advance();
|
|
6542
|
-
return { descriptor, operator, target: target.word, line: this.lexer.lineAt(Math.max(target.offset, target.end - 1)), ...(operator === "<&" || operator === ">&") && this.lexer.source[target.end - 1] === "-" ? { move: true } : {}, ...target.document ? { document: target.document } : {} };
|
|
6542
|
+
return { descriptor: descriptor2, operator, target: target.word, line: this.lexer.lineAt(Math.max(target.offset, target.end - 1)), ...(operator === "<&" || operator === ">&") && this.lexer.source[target.end - 1] === "-" ? { move: true } : {}, ...target.document ? { document: target.document } : {} };
|
|
6543
6543
|
}
|
|
6544
6544
|
};
|
|
6545
6545
|
function parseShell(source, depth = 0) {
|
|
@@ -6588,13 +6588,13 @@ init_platform();
|
|
|
6588
6588
|
// packages/safe-bash/src/shell/value-state.ts
|
|
6589
6589
|
init_platform();
|
|
6590
6590
|
var ValueArena = class {
|
|
6591
|
-
constructor(maximumBytes, maximumSlots, checkpoint,
|
|
6591
|
+
constructor(maximumBytes, maximumSlots, checkpoint, fail2 = (limit) => {
|
|
6592
6592
|
throw new ShellLimitError(limit);
|
|
6593
6593
|
}) {
|
|
6594
6594
|
this.maximumBytes = maximumBytes;
|
|
6595
6595
|
this.maximumSlots = maximumSlots;
|
|
6596
6596
|
this.checkpoint = checkpoint;
|
|
6597
|
-
this.fail =
|
|
6597
|
+
this.fail = fail2;
|
|
6598
6598
|
}
|
|
6599
6599
|
maximumBytes;
|
|
6600
6600
|
maximumSlots;
|
|
@@ -6624,25 +6624,25 @@ var ValueArena = class {
|
|
|
6624
6624
|
if (!Number.isSafeInteger(bytes2) || bytes2 < 0 || !Number.isSafeInteger(slots) || slots < 0) throw new RangeError("Invalid shell value allocation");
|
|
6625
6625
|
if (bytes2 > this.maximumBytes - this.#bytes) this.fail("maxExpansionBytes");
|
|
6626
6626
|
if (slots > this.maximumSlots - this.#slots) this.fail("maxExpansionFields");
|
|
6627
|
-
const
|
|
6627
|
+
const record4 = { bytes: bytes2, slots, references: 1 };
|
|
6628
6628
|
this.#bytes += bytes2;
|
|
6629
6629
|
this.#slots += slots;
|
|
6630
|
-
this.#records.add(
|
|
6631
|
-
return
|
|
6630
|
+
this.#records.add(record4);
|
|
6631
|
+
return record4;
|
|
6632
6632
|
}
|
|
6633
|
-
commit(
|
|
6633
|
+
commit(record4, object) {
|
|
6634
6634
|
this.assertOpen();
|
|
6635
|
-
if (!this.#records.has(
|
|
6636
|
-
|
|
6637
|
-
this.#objects.set(object,
|
|
6638
|
-
}
|
|
6639
|
-
release(
|
|
6640
|
-
if (!this.#records.has(
|
|
6641
|
-
if (--
|
|
6642
|
-
this.#records.delete(
|
|
6643
|
-
if (
|
|
6644
|
-
this.#bytes -=
|
|
6645
|
-
this.#slots -=
|
|
6635
|
+
if (!this.#records.has(record4) || record4.object || this.#objects.has(object)) throw new Error("Shell value reservation is not fresh");
|
|
6636
|
+
record4.object = object;
|
|
6637
|
+
this.#objects.set(object, record4);
|
|
6638
|
+
}
|
|
6639
|
+
release(record4) {
|
|
6640
|
+
if (!this.#records.has(record4)) return;
|
|
6641
|
+
if (--record4.references) return;
|
|
6642
|
+
this.#records.delete(record4);
|
|
6643
|
+
if (record4.object) this.#objects.delete(record4.object);
|
|
6644
|
+
this.#bytes -= record4.bytes;
|
|
6645
|
+
this.#slots -= record4.slots;
|
|
6646
6646
|
}
|
|
6647
6647
|
hold(value2) {
|
|
6648
6648
|
this.assertOpen();
|
|
@@ -6685,7 +6685,7 @@ var ValueArena = class {
|
|
|
6685
6685
|
}
|
|
6686
6686
|
close() {
|
|
6687
6687
|
this.#closed = true;
|
|
6688
|
-
for (const
|
|
6688
|
+
for (const record4 of this.#records) if (record4.object) this.#objects.delete(record4.object);
|
|
6689
6689
|
this.#records.clear();
|
|
6690
6690
|
this.#bytes = 0;
|
|
6691
6691
|
this.#slots = 0;
|
|
@@ -6707,19 +6707,19 @@ var ValueScope = class {
|
|
|
6707
6707
|
reserve(bytes2, slots) {
|
|
6708
6708
|
this.assertOpen();
|
|
6709
6709
|
this.#enrollment ??= this.arena.allocate(64, 1);
|
|
6710
|
-
const
|
|
6710
|
+
const record4 = this.arena.allocate(bytes2, slots);
|
|
6711
6711
|
let released = false;
|
|
6712
6712
|
const release = () => {
|
|
6713
6713
|
if (released) return;
|
|
6714
6714
|
released = true;
|
|
6715
6715
|
this.#releases.delete(release);
|
|
6716
|
-
this.arena.release(
|
|
6716
|
+
this.arena.release(record4);
|
|
6717
6717
|
};
|
|
6718
6718
|
this.#releases.add(release);
|
|
6719
6719
|
return { commit: (value2) => {
|
|
6720
6720
|
this.assertOpen();
|
|
6721
6721
|
if (released) throw new Error("Shell value reservation is released");
|
|
6722
|
-
this.arena.commit(
|
|
6722
|
+
this.arena.commit(record4, value2);
|
|
6723
6723
|
}, release };
|
|
6724
6724
|
}
|
|
6725
6725
|
hold(value2) {
|
|
@@ -6887,28 +6887,28 @@ function positionalTemplate(source, checkpoint) {
|
|
|
6887
6887
|
}
|
|
6888
6888
|
return found;
|
|
6889
6889
|
}
|
|
6890
|
-
function positionalValue(name2,
|
|
6890
|
+
function positionalValue(name2, options3) {
|
|
6891
6891
|
let index = 0;
|
|
6892
6892
|
let outside = false;
|
|
6893
6893
|
for (let position = 0; position < name2.length; position++) {
|
|
6894
|
-
if (position % 128 === 0)
|
|
6894
|
+
if (position % 128 === 0) options3.checkpoint();
|
|
6895
6895
|
const next = name2.charCodeAt(position) - 48;
|
|
6896
|
-
if (index > Math.floor((
|
|
6896
|
+
if (index > Math.floor((options3.positional.length - next) / 10)) outside = true;
|
|
6897
6897
|
if (!outside) index = index * 10 + next;
|
|
6898
6898
|
}
|
|
6899
|
-
return outside ? void 0 : index === 0 ?
|
|
6899
|
+
return outside ? void 0 : index === 0 ? options3.arg0 : options3.positional[index - 1];
|
|
6900
6900
|
}
|
|
6901
|
-
function evaluatePositionalArithmetic(program,
|
|
6901
|
+
function evaluatePositionalArithmetic(program, options3, evaluate) {
|
|
6902
6902
|
const source = program.source;
|
|
6903
6903
|
if (!source.includes("$")) return evaluate(program);
|
|
6904
|
-
|
|
6905
|
-
if (!positionalTemplate(source,
|
|
6906
|
-
const header =
|
|
6904
|
+
options3.checkpoint();
|
|
6905
|
+
if (!positionalTemplate(source, options3.checkpoint)) return evaluate(program);
|
|
6906
|
+
const header = options3.owner?.reserve({ metadata: 128, allocatedSlots: 2, work: source.length * 2 + 8 });
|
|
6907
6907
|
const admissions = [];
|
|
6908
6908
|
const chunks = [];
|
|
6909
6909
|
let bytes2 = 0;
|
|
6910
6910
|
const reserve = (payload) => {
|
|
6911
|
-
const admission =
|
|
6911
|
+
const admission = options3.owner?.reserve({ payload, metadata: 64, allocatedSlots: 2, work: 4 });
|
|
6912
6912
|
if (admission) admissions.push(admission);
|
|
6913
6913
|
};
|
|
6914
6914
|
const length = (text, start, end, maximum) => {
|
|
@@ -6916,7 +6916,7 @@ function evaluatePositionalArithmetic(program, options2, evaluate) {
|
|
|
6916
6916
|
let nextCheckpoint = start;
|
|
6917
6917
|
for (let position = start; position < end; ) {
|
|
6918
6918
|
if (position >= nextCheckpoint) {
|
|
6919
|
-
|
|
6919
|
+
options3.checkpoint();
|
|
6920
6920
|
nextCheckpoint = position + 128;
|
|
6921
6921
|
}
|
|
6922
6922
|
const code = text.charCodeAt(position++);
|
|
@@ -6926,14 +6926,14 @@ function evaluatePositionalArithmetic(program, options2, evaluate) {
|
|
|
6926
6926
|
size += 4;
|
|
6927
6927
|
position++;
|
|
6928
6928
|
} else size += 3;
|
|
6929
|
-
if (size > maximum)
|
|
6929
|
+
if (size > maximum) options3.limit();
|
|
6930
6930
|
}
|
|
6931
|
-
|
|
6931
|
+
options3.owner?.reserve({ work: end - start }).release();
|
|
6932
6932
|
return size;
|
|
6933
6933
|
};
|
|
6934
6934
|
const literal = (start, end) => {
|
|
6935
6935
|
if (start === end) return;
|
|
6936
|
-
const size = length(source, start, end,
|
|
6936
|
+
const size = length(source, start, end, options3.maximumBytes - bytes2);
|
|
6937
6937
|
reserve(size);
|
|
6938
6938
|
chunks.push(source.slice(start, end));
|
|
6939
6939
|
bytes2 += size;
|
|
@@ -6943,7 +6943,7 @@ function evaluatePositionalArithmetic(program, options2, evaluate) {
|
|
|
6943
6943
|
let nextCheckpoint = 0;
|
|
6944
6944
|
for (let position = 0; position < source.length; ) {
|
|
6945
6945
|
if (position >= nextCheckpoint) {
|
|
6946
|
-
|
|
6946
|
+
options3.checkpoint();
|
|
6947
6947
|
nextCheckpoint = position + 128;
|
|
6948
6948
|
}
|
|
6949
6949
|
if (source[position] !== "$") {
|
|
@@ -6956,17 +6956,17 @@ function evaluatePositionalArithmetic(program, options2, evaluate) {
|
|
|
6956
6956
|
let nameEnd = nameStart + 1;
|
|
6957
6957
|
if (braced) while (digit(source, nameEnd)) {
|
|
6958
6958
|
if (nameEnd >= nextCheckpoint) {
|
|
6959
|
-
|
|
6959
|
+
options3.checkpoint();
|
|
6960
6960
|
nextCheckpoint = nameEnd + 128;
|
|
6961
6961
|
}
|
|
6962
6962
|
nameEnd++;
|
|
6963
6963
|
}
|
|
6964
6964
|
reserve(nameEnd - nameStart);
|
|
6965
6965
|
const name2 = source.slice(nameStart, nameEnd);
|
|
6966
|
-
const value2 = positionalValue(name2,
|
|
6967
|
-
|
|
6966
|
+
const value2 = positionalValue(name2, options3);
|
|
6967
|
+
options3.requireParameter(name2, value2);
|
|
6968
6968
|
const text = value2 ?? "";
|
|
6969
|
-
const size = length(text, 0, text.length,
|
|
6969
|
+
const size = length(text, 0, text.length, options3.maximumBytes - bytes2);
|
|
6970
6970
|
reserve(size);
|
|
6971
6971
|
chunks.push(text);
|
|
6972
6972
|
bytes2 += size;
|
|
@@ -6974,10 +6974,10 @@ function evaluatePositionalArithmetic(program, options2, evaluate) {
|
|
|
6974
6974
|
start = position;
|
|
6975
6975
|
}
|
|
6976
6976
|
literal(start, source.length);
|
|
6977
|
-
|
|
6977
|
+
options3.checkpoint();
|
|
6978
6978
|
reserve(bytes2);
|
|
6979
6979
|
const expanded = chunks.join("");
|
|
6980
|
-
|
|
6980
|
+
options3.checkpoint();
|
|
6981
6981
|
return evaluate(prepareArithmetic(expanded));
|
|
6982
6982
|
} finally {
|
|
6983
6983
|
for (let position = admissions.length - 1; position >= 0; position--) admissions[position].release();
|
|
@@ -7511,7 +7511,7 @@ async function* argumentsFrom(source, signal, delimiter, replacement = false) {
|
|
|
7511
7511
|
if (quote || escaped) throw new UsageError(quote ? "unmatched quote in input" : "trailing backslash in input");
|
|
7512
7512
|
if (active) yield current;
|
|
7513
7513
|
}
|
|
7514
|
-
function executionCommands(
|
|
7514
|
+
function executionCommands(execute3) {
|
|
7515
7515
|
return [
|
|
7516
7516
|
define("env", async (context) => {
|
|
7517
7517
|
const argumentValues = getCommandArguments(context);
|
|
@@ -7562,7 +7562,7 @@ function executionCommands(execute2) {
|
|
|
7562
7562
|
stderr: context.stderr,
|
|
7563
7563
|
...context.stdinIsDefault === void 0 ? {} : { stdinIsDefault: context.stdinIsDefault }
|
|
7564
7564
|
});
|
|
7565
|
-
return
|
|
7565
|
+
return execute3({ ...context, command: parsed.operands[offset], args: childArguments.args, argumentValues: childArguments, env: childEnv, cwd });
|
|
7566
7566
|
}
|
|
7567
7567
|
for (const name2 of names) await output(context, `${name2}=${env[name2]}${parsed.flags.has("0") ? "\0" : "\n"}`);
|
|
7568
7568
|
return { exitCode: 0 };
|
|
@@ -7602,7 +7602,7 @@ function executionCommands(execute2) {
|
|
|
7602
7602
|
const size = encoder2.encode(command2).length + 1 + childArguments.values.reduce((sum, argument) => sum + shellValueByteLength(argument) + 1, 0);
|
|
7603
7603
|
if (size > maxBytes) throw new UsageError("expanded arguments exceed command size limit");
|
|
7604
7604
|
if (parsed.flags.has("t")) await writeBytes(context.stderr, encoder2.encode([command2, ...args].map((argument) => /^[A-Za-z0-9_./-]+$/u.test(argument) ? argument : `'${argument.replaceAll("'", "'\\''")}'`).join(" ") + "\n"), context.signal);
|
|
7605
|
-
const result = await
|
|
7605
|
+
const result = await execute3({ ...context, command: command2, args, argumentValues: childArguments, stdin: emptyInput(), stdinIsDefault: true, env: { ...context.env } });
|
|
7606
7606
|
executed = true;
|
|
7607
7607
|
if (result.exitCode === 255) {
|
|
7608
7608
|
status = 124;
|
|
@@ -7759,9 +7759,9 @@ async function validateString(value2, work, optstring = false) {
|
|
|
7759
7759
|
else work.addBytes(3);
|
|
7760
7760
|
}
|
|
7761
7761
|
}
|
|
7762
|
-
async function scanGetopts(state, optstring, args,
|
|
7763
|
-
if (!record2(
|
|
7764
|
-
const work = new ScanWork(
|
|
7762
|
+
async function scanGetopts(state, optstring, args, options3) {
|
|
7763
|
+
if (!record2(options3) || typeof options3.reportErrors !== "boolean") throw new GetoptsError("INVALID_INPUT", "Getopts requires explicit diagnostic policy and work controls");
|
|
7764
|
+
const work = new ScanWork(options3.work);
|
|
7765
7765
|
const original = cloneGetoptsState(state);
|
|
7766
7766
|
if (!Array.isArray(args)) throw new GetoptsError("INVALID_INPUT", "Getopts requires an argument array");
|
|
7767
7767
|
if (args.length > work.maxArguments) throw new GetoptsError("ARGUMENT_LIMIT", "Getopts argument limit exceeded");
|
|
@@ -7816,7 +7816,7 @@ async function scanGetopts(state, optstring, args, options2) {
|
|
|
7816
7816
|
active = attached ? { argument: active.argument, offset } : void 0;
|
|
7817
7817
|
if (!attached) index++;
|
|
7818
7818
|
if (specification[code] === -1) {
|
|
7819
|
-
return finish("unknown-option", "?", silent ? { kind: "set", value: option } : { kind: "unset" }, !silent &&
|
|
7819
|
+
return finish("unknown-option", "?", silent ? { kind: "set", value: option } : { kind: "unset" }, !silent && options3.reportErrors ? { kind: "unknown-option", option } : null);
|
|
7820
7820
|
}
|
|
7821
7821
|
if (specification[code] === 1) {
|
|
7822
7822
|
if (attached) {
|
|
@@ -7829,7 +7829,7 @@ async function scanGetopts(state, optstring, args, options2) {
|
|
|
7829
7829
|
index++;
|
|
7830
7830
|
return finish("option", option, { kind: "set", value: value2 }, null);
|
|
7831
7831
|
}
|
|
7832
|
-
return finish("missing-argument", silent ? ":" : "?", silent ? { kind: "set", value: option } : { kind: "unset" }, !silent &&
|
|
7832
|
+
return finish("missing-argument", silent ? ":" : "?", silent ? { kind: "set", value: option } : { kind: "unset" }, !silent && options3.reportErrors ? { kind: "missing-argument", option } : null);
|
|
7833
7833
|
}
|
|
7834
7834
|
return finish("option", option, { kind: "unset" }, null);
|
|
7835
7835
|
}
|
|
@@ -8168,17 +8168,17 @@ function throwLocalActivationFailure(state) {
|
|
|
8168
8168
|
const failure = localActivationFailure(state);
|
|
8169
8169
|
if (failure.failed) throw failure.reason;
|
|
8170
8170
|
}
|
|
8171
|
-
function prepareChildCancellation(parent,
|
|
8171
|
+
function prepareChildCancellation(parent, options3, snapshot, controls) {
|
|
8172
8172
|
const parentState = requireLink(parent);
|
|
8173
8173
|
throwAdmissionFailure(parentState);
|
|
8174
8174
|
let localSignal;
|
|
8175
|
-
if (
|
|
8176
|
-
if (
|
|
8175
|
+
if (options3 !== void 0) {
|
|
8176
|
+
if (options3 === null || typeof options3 !== "object" && typeof options3 !== "function") {
|
|
8177
8177
|
return stagedFailure(parentState, new TypeError("Cancellation options must be an object or function"));
|
|
8178
8178
|
}
|
|
8179
8179
|
let candidate;
|
|
8180
8180
|
try {
|
|
8181
|
-
candidate =
|
|
8181
|
+
candidate = options3.signal;
|
|
8182
8182
|
} catch (error) {
|
|
8183
8183
|
return stagedFailure(parentState, error);
|
|
8184
8184
|
}
|
|
@@ -9143,10 +9143,10 @@ var StateMonitor = class {
|
|
|
9143
9143
|
monitor.finish(tickets, name2);
|
|
9144
9144
|
return result;
|
|
9145
9145
|
},
|
|
9146
|
-
defineProperty(target, key,
|
|
9146
|
+
defineProperty(target, key, descriptor2) {
|
|
9147
9147
|
const name2 = named ? String(key) : void 0;
|
|
9148
9148
|
const tickets = monitor.mutation(name2);
|
|
9149
|
-
const result = Reflect.defineProperty(target, key,
|
|
9149
|
+
const result = Reflect.defineProperty(target, key, descriptor2);
|
|
9150
9150
|
if (result) monitor.changedValue(target, field, key);
|
|
9151
9151
|
monitor.finish(tickets, name2);
|
|
9152
9152
|
return result;
|
|
@@ -9943,6 +9943,7 @@ var defaultLimits = {
|
|
|
9943
9943
|
maxInputBytes: 32 * 1024 * 1024,
|
|
9944
9944
|
maxOutputBytes: 16 * 1024 * 1024,
|
|
9945
9945
|
maxCommands: 1e4,
|
|
9946
|
+
maxRedirects: 64,
|
|
9946
9947
|
maxPipelineStages: 64,
|
|
9947
9948
|
maxLoopIterations: 1e4,
|
|
9948
9949
|
maxSubstitutionDepth: 64,
|
|
@@ -10172,7 +10173,7 @@ var typedSavedVariables = /* @__PURE__ */ new WeakMap();
|
|
|
10172
10173
|
var valueScope = /* @__PURE__ */ Symbol("shell value allocation scope");
|
|
10173
10174
|
var invokedValues = /* @__PURE__ */ new WeakMap();
|
|
10174
10175
|
function isolateIO(io) {
|
|
10175
|
-
return { ...io, ...io.descriptors ? { descriptors: new Map([...io.descriptors].map(([number,
|
|
10176
|
+
return { ...io, ...io.descriptors ? { descriptors: new Map([...io.descriptors].map(([number, descriptor2]) => [number, { ...descriptor2 }])) } : {} };
|
|
10176
10177
|
}
|
|
10177
10178
|
function activeIO(io) {
|
|
10178
10179
|
const input3 = io.descriptors?.get(0);
|
|
@@ -10650,11 +10651,11 @@ var DirectoryStackWork = class {
|
|
|
10650
10651
|
await writeText(this.stdout, text);
|
|
10651
10652
|
this.signal.throwIfAborted();
|
|
10652
10653
|
}
|
|
10653
|
-
async display(cwd, entries,
|
|
10654
|
+
async display(cwd, entries, options3, home) {
|
|
10654
10655
|
await this.scan(cwd, "path");
|
|
10655
|
-
const homeBytes = !
|
|
10656
|
-
const start =
|
|
10657
|
-
const end =
|
|
10656
|
+
const homeBytes = !options3.long && home !== void 0 ? await this.scan(home, "HOME") : 0;
|
|
10657
|
+
const start = options3.index ?? 0;
|
|
10658
|
+
const end = options3.index ?? entries.length;
|
|
10658
10659
|
for (let index = start; index <= end; index++) {
|
|
10659
10660
|
await this.charge(1);
|
|
10660
10661
|
let entry = index === 0 ? cwd : entries[index - 1];
|
|
@@ -10672,12 +10673,12 @@ var DirectoryStackWork = class {
|
|
|
10672
10673
|
if (entry.length === home.length || entry[home.length] === "/") entry = `~${entry.slice(home.length)}`;
|
|
10673
10674
|
}
|
|
10674
10675
|
}
|
|
10675
|
-
if (index !== start && !
|
|
10676
|
-
if (
|
|
10676
|
+
if (index !== start && !options3.lines && !options3.verbose) await this.emit(" ");
|
|
10677
|
+
if (options3.verbose) await this.emit(`${String(index).padStart(2, " ")} `);
|
|
10677
10678
|
await this.emit(entry);
|
|
10678
|
-
if (
|
|
10679
|
+
if (options3.lines || options3.verbose) await this.emit("\n");
|
|
10679
10680
|
}
|
|
10680
|
-
if (!
|
|
10681
|
+
if (!options3.lines && !options3.verbose) await this.emit("\n");
|
|
10681
10682
|
await this.flushOutput();
|
|
10682
10683
|
}
|
|
10683
10684
|
};
|
|
@@ -10735,34 +10736,34 @@ var RuntimeCancellationState = class {
|
|
|
10735
10736
|
}
|
|
10736
10737
|
bind(promise, boundary) {
|
|
10737
10738
|
if (this.#closed) throw new Error("Cancellation outcome admission is closed");
|
|
10738
|
-
const
|
|
10739
|
-
this.#records.add(
|
|
10740
|
-
return
|
|
10739
|
+
const record4 = { promise, boundary, finalized: false, consumed: false };
|
|
10740
|
+
this.#records.add(record4);
|
|
10741
|
+
return record4;
|
|
10741
10742
|
}
|
|
10742
|
-
finalize(
|
|
10743
|
-
if (
|
|
10744
|
-
|
|
10745
|
-
|
|
10743
|
+
finalize(record4, selection) {
|
|
10744
|
+
if (record4.consumed || !this.#records.has(record4)) return;
|
|
10745
|
+
record4.selection = selection;
|
|
10746
|
+
record4.finalized = true;
|
|
10746
10747
|
}
|
|
10747
10748
|
consume(rawReturn, capturedReason) {
|
|
10748
|
-
for (const
|
|
10749
|
-
if (
|
|
10750
|
-
|
|
10751
|
-
this.#records.delete(
|
|
10752
|
-
const selection =
|
|
10753
|
-
if (!
|
|
10749
|
+
for (const record4 of this.#records) {
|
|
10750
|
+
if (record4.promise !== rawReturn) continue;
|
|
10751
|
+
record4.consumed = true;
|
|
10752
|
+
this.#records.delete(record4);
|
|
10753
|
+
const selection = record4.selection;
|
|
10754
|
+
if (!record4.finalized || selection?.outcome.kind !== "throw" || !Object.is(selection.outcome.reason, capturedReason)) return void 0;
|
|
10754
10755
|
return selection.report;
|
|
10755
10756
|
}
|
|
10756
10757
|
return void 0;
|
|
10757
10758
|
}
|
|
10758
|
-
discard(
|
|
10759
|
-
if (!
|
|
10760
|
-
|
|
10761
|
-
this.#records.delete(
|
|
10759
|
+
discard(record4) {
|
|
10760
|
+
if (!record4) return;
|
|
10761
|
+
record4.consumed = true;
|
|
10762
|
+
this.#records.delete(record4);
|
|
10762
10763
|
}
|
|
10763
10764
|
close() {
|
|
10764
10765
|
this.#closed = true;
|
|
10765
|
-
for (const
|
|
10766
|
+
for (const record4 of this.#records) record4.consumed = true;
|
|
10766
10767
|
this.#records.clear();
|
|
10767
10768
|
this.#diagnostics = /* @__PURE__ */ new WeakMap();
|
|
10768
10769
|
}
|
|
@@ -10816,7 +10817,7 @@ var InvocationCancellationOwner = class {
|
|
|
10816
10817
|
throw error;
|
|
10817
10818
|
}
|
|
10818
10819
|
}
|
|
10819
|
-
capture(
|
|
10820
|
+
capture(execute3, frame) {
|
|
10820
10821
|
return new Promise((resolve) => {
|
|
10821
10822
|
let settled = false;
|
|
10822
10823
|
let raw;
|
|
@@ -10838,7 +10839,7 @@ var InvocationCancellationOwner = class {
|
|
|
10838
10839
|
});
|
|
10839
10840
|
};
|
|
10840
10841
|
try {
|
|
10841
|
-
raw = Promise.resolve(
|
|
10842
|
+
raw = Promise.resolve(execute3());
|
|
10842
10843
|
} catch (reason) {
|
|
10843
10844
|
settle({ kind: "throw", reason });
|
|
10844
10845
|
return;
|
|
@@ -11076,13 +11077,13 @@ var Runtime = class _Runtime {
|
|
|
11076
11077
|
}
|
|
11077
11078
|
);
|
|
11078
11079
|
}
|
|
11079
|
-
invokeChild(
|
|
11080
|
+
invokeChild(options3, state, parent, validate, execute3) {
|
|
11080
11081
|
const publicPromise = Promise.resolve().then(async () => {
|
|
11081
11082
|
if (!this.cancellation.deliverySignal.aborted) parent.assertOpen();
|
|
11082
11083
|
const childDepth = this.cancellationDepth + 1;
|
|
11083
11084
|
const prepared = prepareChildCancellation(
|
|
11084
11085
|
this.cancellation,
|
|
11085
|
-
|
|
11086
|
+
options3,
|
|
11086
11087
|
this.cancellationAdmission(childDepth)
|
|
11087
11088
|
);
|
|
11088
11089
|
this.cancellationOwner?.assertAdmissionOpen();
|
|
@@ -11122,7 +11123,7 @@ var Runtime = class _Runtime {
|
|
|
11122
11123
|
frame
|
|
11123
11124
|
);
|
|
11124
11125
|
let captured;
|
|
11125
|
-
const executeChild = () =>
|
|
11126
|
+
const executeChild = () => execute3(runtime, scope);
|
|
11126
11127
|
if (owner) captured = await owner.capture(executeChild, frame);
|
|
11127
11128
|
else {
|
|
11128
11129
|
try {
|
|
@@ -11271,8 +11272,8 @@ var Runtime = class _Runtime {
|
|
|
11271
11272
|
if (!typedSavedVariables.has(saved)) await this.prepareVariable(state, name2, saved);
|
|
11272
11273
|
await owner.ledger.checkpoint(this.signal);
|
|
11273
11274
|
}
|
|
11274
|
-
for (const frame of stateMonitor(state).overlayFrames()) for (const [name2,
|
|
11275
|
-
const saved =
|
|
11275
|
+
for (const frame of stateMonitor(state).overlayFrames()) for (const [name2, record4] of frame) {
|
|
11276
|
+
const saved = record4;
|
|
11276
11277
|
if (!saved.superseded && !typedSavedVariables.has(saved)) await this.prepareVariable(state, name2, saved, true);
|
|
11277
11278
|
await owner.ledger.checkpoint(this.signal);
|
|
11278
11279
|
}
|
|
@@ -11801,7 +11802,7 @@ var Runtime = class _Runtime {
|
|
|
11801
11802
|
let io = originalIO;
|
|
11802
11803
|
let diagnosticFailure;
|
|
11803
11804
|
try {
|
|
11804
|
-
const
|
|
11805
|
+
const execute3 = async () => {
|
|
11805
11806
|
if (command2.kind === "function") {
|
|
11806
11807
|
if (state.profile === "sh" && specialBuiltinNames.has(command2.name)) {
|
|
11807
11808
|
await this.diagnostic(io, `\`${command2.name}': is a special builtin`);
|
|
@@ -11954,7 +11955,7 @@ var Runtime = class _Runtime {
|
|
|
11954
11955
|
}
|
|
11955
11956
|
return status2;
|
|
11956
11957
|
};
|
|
11957
|
-
const status = await
|
|
11958
|
+
const status = await execute3();
|
|
11958
11959
|
await finishOutputs(status);
|
|
11959
11960
|
return status;
|
|
11960
11961
|
} catch (caught) {
|
|
@@ -12048,6 +12049,8 @@ var Runtime = class _Runtime {
|
|
|
12048
12049
|
return value2;
|
|
12049
12050
|
}
|
|
12050
12051
|
async redirect(redirects, state, io, inputs, outputs, isolatedInlineInput = false, persistMoves = false, fileShortcut = false, line) {
|
|
12052
|
+
this.signal.throwIfAborted();
|
|
12053
|
+
if (redirects.length > this.budget.limits.maxRedirects) this.budget.fail("maxRedirects");
|
|
12051
12054
|
io.descriptors ??= /* @__PURE__ */ new Map([
|
|
12052
12055
|
[0, { input: io.stdin, ...io.stdinIsDefault === void 0 ? {} : { stdinIsDefault: io.stdinIsDefault } }],
|
|
12053
12056
|
[1, { output: io.stdout }],
|
|
@@ -12068,8 +12071,8 @@ var Runtime = class _Runtime {
|
|
|
12068
12071
|
if (io.stdout === closedSink) descriptors.delete(1);
|
|
12069
12072
|
if (io.stderr === closedSink) descriptors.delete(2);
|
|
12070
12073
|
const currentIO = () => {
|
|
12071
|
-
const
|
|
12072
|
-
const stdinIsDefault =
|
|
12074
|
+
const descriptor2 = descriptors.get(0)?.closed ? void 0 : descriptors.get(0);
|
|
12075
|
+
const stdinIsDefault = descriptor2?.input ? descriptor2.stdinIsDefault : false;
|
|
12073
12076
|
return {
|
|
12074
12077
|
[invocationScope]: io[invocationScope],
|
|
12075
12078
|
...io.execution === void 0 ? {} : { execution: io.execution },
|
|
@@ -12078,7 +12081,7 @@ var Runtime = class _Runtime {
|
|
|
12078
12081
|
...io.scriptName === void 0 ? {} : { scriptName: io.scriptName },
|
|
12079
12082
|
...io.substitutionDiagnosticLine === void 0 ? {} : { substitutionDiagnosticLine: io.substitutionDiagnosticLine },
|
|
12080
12083
|
...io.substitutionDiagnosticLines === void 0 ? {} : { substitutionDiagnosticLines: io.substitutionDiagnosticLines },
|
|
12081
|
-
stdin:
|
|
12084
|
+
stdin: descriptor2?.input ?? closedSource,
|
|
12082
12085
|
...stdinIsDefault === void 0 ? {} : { stdinIsDefault },
|
|
12083
12086
|
stdout: descriptors.get(1)?.closed ? closedSink : descriptors.get(1)?.output ?? closedSink,
|
|
12084
12087
|
stderr: descriptors.get(2)?.closed ? closedSink : descriptors.get(2)?.output ?? closedSink,
|
|
@@ -12120,20 +12123,20 @@ var Runtime = class _Runtime {
|
|
|
12120
12123
|
const move = target.endsWith("-");
|
|
12121
12124
|
if (move && !redirect.move) throw new Error(`${target}: ambiguous redirect`);
|
|
12122
12125
|
const sourceDescriptor = Number(move ? target.slice(0, -1) : target);
|
|
12123
|
-
const
|
|
12124
|
-
if (!
|
|
12125
|
-
descriptors.set(redirect.descriptor, { ...
|
|
12126
|
+
const descriptor2 = descriptors.get(sourceDescriptor);
|
|
12127
|
+
if (!descriptor2 || descriptor2.closed || !move && (redirect.operator === "<&" ? !descriptor2.input : !descriptor2.output)) throw new Error(`${move ? sourceDescriptor : target}: Bad file descriptor`);
|
|
12128
|
+
descriptors.set(redirect.descriptor, { ...descriptor2 });
|
|
12126
12129
|
if (move && sourceDescriptor !== redirect.descriptor) {
|
|
12127
12130
|
descriptors.delete(sourceDescriptor);
|
|
12128
|
-
if (persistMoves && !replaced.has(sourceDescriptor))
|
|
12131
|
+
if (persistMoves && !replaced.has(sourceDescriptor)) descriptor2.closed = true;
|
|
12129
12132
|
}
|
|
12130
12133
|
}
|
|
12131
12134
|
} else {
|
|
12132
12135
|
const path = resolvePath(state.cwd, target);
|
|
12133
|
-
const
|
|
12136
|
+
const options3 = { signal: this.signal };
|
|
12134
12137
|
if (redirect.operator === "<") {
|
|
12135
|
-
await interruptible(this.fs.access(path, 4,
|
|
12136
|
-
const stat = await interruptible(this.fs.stat(path,
|
|
12138
|
+
await interruptible(this.fs.access(path, 4, options3), this.signal);
|
|
12139
|
+
const stat = await interruptible(this.fs.stat(path, options3), this.signal);
|
|
12137
12140
|
if (stat.type === "directory" && !fileShortcut) throw new Error(`${target}: Is a directory`);
|
|
12138
12141
|
const source = stat.type === "directory" ? toByteSource("") : await fileInput(this.fs, path, this.budget.limits.maxInputBytes, this.signal);
|
|
12139
12142
|
const input3 = new ShellInput(source, this.budget, this.signal);
|
|
@@ -12141,7 +12144,7 @@ var Runtime = class _Runtime {
|
|
|
12141
12144
|
descriptors.set(redirect.descriptor, { input: input3, stdinIsDefault: false });
|
|
12142
12145
|
} else {
|
|
12143
12146
|
const append = redirect.operator === ">>";
|
|
12144
|
-
const capabilities = await this.fs.capabilitiesFor?.(path,
|
|
12147
|
+
const capabilities = await this.fs.capabilitiesFor?.(path, options3) ?? this.fs.capabilities;
|
|
12145
12148
|
const random = capabilities.randomAccessWrite === true;
|
|
12146
12149
|
let file;
|
|
12147
12150
|
await this.fileOperation(path, async () => {
|
|
@@ -12154,8 +12157,8 @@ var Runtime = class _Runtime {
|
|
|
12154
12157
|
let offset = 0;
|
|
12155
12158
|
const incremental = async () => {
|
|
12156
12159
|
await this.fileOperation(path, async () => {
|
|
12157
|
-
if (append) await this.fs.appendFile(path, new Uint8Array(),
|
|
12158
|
-
else await this.fs.writeFile(path, new Uint8Array(), { ...
|
|
12160
|
+
if (append) await this.fs.appendFile(path, new Uint8Array(), options3);
|
|
12161
|
+
else await this.fs.writeFile(path, new Uint8Array(), { ...options3, flag: "w" });
|
|
12159
12162
|
if (!append) file.data = new Uint8Array();
|
|
12160
12163
|
});
|
|
12161
12164
|
return { write: (chunk) => {
|
|
@@ -12166,7 +12169,7 @@ var Runtime = class _Runtime {
|
|
|
12166
12169
|
let atEOF = false;
|
|
12167
12170
|
if (!append && current && offset === current.length && capabilities.append === true && capabilities.stat !== false) {
|
|
12168
12171
|
try {
|
|
12169
|
-
atEOF = (await interruptible(this.fs.stat(path,
|
|
12172
|
+
atEOF = (await interruptible(this.fs.stat(path, options3), this.signal)).size === offset;
|
|
12170
12173
|
} catch {
|
|
12171
12174
|
this.signal.throwIfAborted();
|
|
12172
12175
|
}
|
|
@@ -12174,13 +12177,13 @@ var Runtime = class _Runtime {
|
|
|
12174
12177
|
}
|
|
12175
12178
|
if (append || atEOF) {
|
|
12176
12179
|
const bytes2 = current ? appendOutputBytes(current, copy2) : void 0;
|
|
12177
|
-
await this.fs.appendFile(path, copy2,
|
|
12180
|
+
await this.fs.appendFile(path, copy2, options3);
|
|
12178
12181
|
file.data = bytes2;
|
|
12179
12182
|
} else {
|
|
12180
12183
|
const bytes2 = new Uint8Array(Math.max(current?.length ?? 0, offset + copy2.length));
|
|
12181
12184
|
if (current) bytes2.set(current);
|
|
12182
12185
|
bytes2.set(copy2, offset);
|
|
12183
|
-
await this.fs.writeFile(path, bytes2,
|
|
12186
|
+
await this.fs.writeFile(path, bytes2, options3);
|
|
12184
12187
|
file.data = bytes2;
|
|
12185
12188
|
}
|
|
12186
12189
|
if (!append) offset += copy2.length;
|
|
@@ -12449,8 +12452,8 @@ var Runtime = class _Runtime {
|
|
|
12449
12452
|
fs: this.fs,
|
|
12450
12453
|
signal: this.commandSignal,
|
|
12451
12454
|
registerCleanup: (cleanup) => scope.register(cleanup),
|
|
12452
|
-
invoke: (name3, args,
|
|
12453
|
-
const invocation = this.invoke(name3, args,
|
|
12455
|
+
invoke: (name3, args, options3) => {
|
|
12456
|
+
const invocation = this.invoke(name3, args, options3, context, state, scope);
|
|
12454
12457
|
void invocation.catch(() => void 0);
|
|
12455
12458
|
return invocation;
|
|
12456
12459
|
}
|
|
@@ -12466,7 +12469,7 @@ var Runtime = class _Runtime {
|
|
|
12466
12469
|
});
|
|
12467
12470
|
return this.observeRuntimeReturn(raw, runtimeFrame, () => downstream);
|
|
12468
12471
|
});
|
|
12469
|
-
const
|
|
12472
|
+
const execute3 = composeMiddleware(middleware, (forwarded) => scope.run(async () => {
|
|
12470
12473
|
scope.assertOpen();
|
|
12471
12474
|
const forwardedValues = getCommandArguments(forwarded);
|
|
12472
12475
|
const admitted = forwardedValues === argumentValues ? argumentValues : this.admitArguments(forwardedValues.values, allocation);
|
|
@@ -12679,7 +12682,7 @@ var Runtime = class _Runtime {
|
|
|
12679
12682
|
}
|
|
12680
12683
|
}));
|
|
12681
12684
|
try {
|
|
12682
|
-
return validateExitCode((await interruptible(
|
|
12685
|
+
return validateExitCode((await interruptible(execute3(context), this.signal)).exitCode);
|
|
12683
12686
|
} catch (error) {
|
|
12684
12687
|
if (builtinFailure && error === builtinFailure.error) throw new ExecutionFailure(error, io, builtinFailure.diagnostic);
|
|
12685
12688
|
if (runtimeFrame.report && Object.is(runtimeFrame.report.origin.signal.reason, error) && this.outcomeFrame) {
|
|
@@ -12813,10 +12816,10 @@ ${functionDisplay(name2, state.functions.get(name2))}`;
|
|
|
12813
12816
|
const target = component === void 0 ? name2 : `${component || "."}${component?.endsWith("/") ? "" : "/"}${name2}`;
|
|
12814
12817
|
const resolved = resolvePath(state.cwd, target);
|
|
12815
12818
|
try {
|
|
12816
|
-
const
|
|
12817
|
-
if ((await interruptible(this.fs.stat(resolved,
|
|
12819
|
+
const options3 = { signal: this.signal };
|
|
12820
|
+
if ((await interruptible(this.fs.stat(resolved, options3), this.signal)).type !== "file") continue;
|
|
12818
12821
|
if (this.fs.capabilities.permissions !== true) throw new CommandFailure(`${target}: execution permissions are not supported by this filesystem`, 126);
|
|
12819
|
-
await interruptible(this.fs.access(resolved, ACCESS_MODES.X_OK,
|
|
12822
|
+
await interruptible(this.fs.access(resolved, ACCESS_MODES.X_OK, options3), this.signal);
|
|
12820
12823
|
matches.push(target);
|
|
12821
12824
|
if (!all) return matches;
|
|
12822
12825
|
} catch (error) {
|
|
@@ -13040,8 +13043,8 @@ ${prefix2} line ${offset + line}: \`${source.split("\n")[line - 1] ?? ""}'
|
|
|
13040
13043
|
stderr: this.budget.sink(incoming.stderr, runtime.signal),
|
|
13041
13044
|
signal: this.commandSignal,
|
|
13042
13045
|
registerCleanup: (cleanup) => scope.register(cleanup),
|
|
13043
|
-
invoke: (name2, args,
|
|
13044
|
-
const invocation = invocationOverride.current ? invocationOverride.current(name2, args,
|
|
13046
|
+
invoke: (name2, args, options3) => {
|
|
13047
|
+
const invocation = invocationOverride.current ? invocationOverride.current(name2, args, options3) : runtime.invoke(name2, args, options3, context, child, scope);
|
|
13045
13048
|
void invocation.catch(() => void 0);
|
|
13046
13049
|
return invocation;
|
|
13047
13050
|
}
|
|
@@ -13061,7 +13064,7 @@ ${prefix2} line ${offset + line}: \`${source.split("\n")[line - 1] ?? ""}'
|
|
|
13061
13064
|
});
|
|
13062
13065
|
return runtime.observeRuntimeReturn(raw, runtimeFrame, () => downstream);
|
|
13063
13066
|
});
|
|
13064
|
-
const
|
|
13067
|
+
const execute3 = composeMiddleware(middleware, async () => {
|
|
13065
13068
|
scope.assertOpen();
|
|
13066
13069
|
const forwardedValues = getCommandArguments(context);
|
|
13067
13070
|
const admitted = forwardedValues === argumentValues ? argumentValues : runtime.admitArguments(forwardedValues.values, allocation);
|
|
@@ -13072,7 +13075,7 @@ ${prefix2} line ${offset + line}: \`${source.split("\n")[line - 1] ?? ""}'
|
|
|
13072
13075
|
return await runtime.observeRuntimeReturn(raw, runtimeFrame);
|
|
13073
13076
|
});
|
|
13074
13077
|
try {
|
|
13075
|
-
const result = await interruptible(
|
|
13078
|
+
const result = await interruptible(execute3(context), runtime.signal);
|
|
13076
13079
|
runtime.signal.throwIfAborted();
|
|
13077
13080
|
return validateExitCode(result.exitCode);
|
|
13078
13081
|
} catch (error) {
|
|
@@ -13085,8 +13088,8 @@ ${prefix2} line ${offset + line}: \`${source.split("\n")[line - 1] ?? ""}'
|
|
|
13085
13088
|
if (ownsScope) await scope.close();
|
|
13086
13089
|
}
|
|
13087
13090
|
}
|
|
13088
|
-
shebangTarget(context, state, io, command2, args,
|
|
13089
|
-
return this.invokeChild(
|
|
13091
|
+
shebangTarget(context, state, io, command2, args, options3, target, loadedSource) {
|
|
13092
|
+
return this.invokeChild(options3, state, io[invocationScope], () => {
|
|
13090
13093
|
this.signal.throwIfAborted();
|
|
13091
13094
|
io[invocationScope].assertOpen();
|
|
13092
13095
|
if (typeof command2 !== "string" || command2.includes("\0") || !Array.isArray(args) || args.some((argument) => typeof argument !== "string" || argument.includes("\0"))) {
|
|
@@ -13097,14 +13100,14 @@ ${prefix2} line ${offset + line}: \`${source.split("\n")[line - 1] ?? ""}'
|
|
|
13097
13100
|
for (const argument of [command2, ...args]) {
|
|
13098
13101
|
if (import_buffer.Buffer.byteLength(argument) > this.budget.limits.maxExpansionBytes) this.budget.fail("maxExpansionBytes");
|
|
13099
13102
|
}
|
|
13100
|
-
}, (runtime, scope) => runtime.shebangTargetScoped(context, state, io, command2, args,
|
|
13103
|
+
}, (runtime, scope) => runtime.shebangTargetScoped(context, state, io, command2, args, options3, target, loadedSource, scope));
|
|
13101
13104
|
}
|
|
13102
|
-
async shebangTargetScoped(context, state, io, command2, args,
|
|
13105
|
+
async shebangTargetScoped(context, state, io, command2, args, options3, target, loadedSource, scope) {
|
|
13103
13106
|
const reserved = command2 === "bash" || command2 === "sh";
|
|
13104
13107
|
const direct = command2.includes("/");
|
|
13105
13108
|
const definition = this.commands.get(command2);
|
|
13106
13109
|
const child = await this.shebangState(context, state);
|
|
13107
|
-
child.cwd = resolvePath(context.cwd,
|
|
13110
|
+
child.cwd = resolvePath(context.cwd, options3.cwd ?? ".");
|
|
13108
13111
|
if (!reserved) {
|
|
13109
13112
|
if (child.depth >= this.budget.limits.maxSubstitutionDepth) this.budget.fail("maxSubstitutionDepth");
|
|
13110
13113
|
child.depth++;
|
|
@@ -13113,18 +13116,18 @@ ${prefix2} line ${offset + line}: \`${source.split("\n")[line - 1] ?? ""}'
|
|
|
13113
13116
|
child.sourceDepth = 0;
|
|
13114
13117
|
child.locals = [];
|
|
13115
13118
|
}
|
|
13116
|
-
const stdinIsDefault =
|
|
13117
|
-
const argumentValues = getCommandArguments({ args, ...
|
|
13119
|
+
const stdinIsDefault = options3.stdin === void 0 ? context.stdinIsDefault : options3.stdinIsDefault ?? false;
|
|
13120
|
+
const argumentValues = getCommandArguments({ args, ...options3.argumentValues ? { argumentValues: options3.argumentValues } : {} });
|
|
13118
13121
|
const selected = {
|
|
13119
13122
|
...context,
|
|
13120
13123
|
command: command2,
|
|
13121
13124
|
args: argumentValues.args,
|
|
13122
13125
|
argumentValues,
|
|
13123
13126
|
cwd: child.cwd,
|
|
13124
|
-
env:
|
|
13125
|
-
stdin:
|
|
13126
|
-
stdout:
|
|
13127
|
-
stderr:
|
|
13127
|
+
env: options3.replaceEnv ? { ...options3.env } : { ...context.env, ...options3.env, PWD: child.cwd },
|
|
13128
|
+
stdin: options3.stdin ?? context.stdin,
|
|
13129
|
+
stdout: options3.stdout ?? context.stdout,
|
|
13130
|
+
stderr: options3.stderr ?? context.stderr,
|
|
13128
13131
|
...stdinIsDefault === void 0 ? {} : { stdinIsDefault }
|
|
13129
13132
|
};
|
|
13130
13133
|
const exitCode = await this.shebangStage(selected, child, io, async (runtime, forwarded, state2, childIO) => {
|
|
@@ -13140,7 +13143,7 @@ ${prefix2} line ${offset + line}: \`${source.split("\n")[line - 1] ?? ""}'
|
|
|
13140
13143
|
await writeText(forwarded.stderr, `env: ${command2}: command not found
|
|
13141
13144
|
`);
|
|
13142
13145
|
return { exitCode: 127 };
|
|
13143
|
-
}, void 0,
|
|
13146
|
+
}, void 0, options3.stdin !== context.stdin ? options3.stdin : void 0, scope);
|
|
13144
13147
|
return { exitCode };
|
|
13145
13148
|
}
|
|
13146
13149
|
async envShebang(context, state, io, optionalArgument, target, args, loadedSource) {
|
|
@@ -13161,8 +13164,8 @@ ${prefix2} line ${offset + line}: \`${source.split("\n")[line - 1] ?? ""}'
|
|
|
13161
13164
|
let failureReport;
|
|
13162
13165
|
const result = await interruptible(Promise.resolve(definition.execute({
|
|
13163
13166
|
...forwarded,
|
|
13164
|
-
invoke: (command2, arguments_,
|
|
13165
|
-
const raw = forwarded.invoke(command2, arguments_,
|
|
13167
|
+
invoke: (command2, arguments_, options3) => {
|
|
13168
|
+
const raw = forwarded.invoke(command2, arguments_, options3);
|
|
13166
13169
|
return raw.catch((error) => {
|
|
13167
13170
|
failed = true;
|
|
13168
13171
|
failure = error;
|
|
@@ -13177,7 +13180,7 @@ ${prefix2} line ${offset + line}: \`${source.split("\n")[line - 1] ?? ""}'
|
|
|
13177
13180
|
throw failure;
|
|
13178
13181
|
}
|
|
13179
13182
|
return { exitCode: validateExitCode(result.exitCode) };
|
|
13180
|
-
}, (runtime, forwarded, child, childIO) => (command2, arguments_,
|
|
13183
|
+
}, (runtime, forwarded, child, childIO) => (command2, arguments_, options3 = {}) => runtime.shebangTarget(forwarded, child, childIO, command2, arguments_, options3, target, loadedSource));
|
|
13181
13184
|
}
|
|
13182
13185
|
async scriptFile(context, state, io, target, args, direct, errexit = false, loadedSource) {
|
|
13183
13186
|
if (target === "") throw new CommandFailure(`${context.command}: : No such file or directory`, 127);
|
|
@@ -13189,14 +13192,14 @@ ${prefix2} line ${offset + line}: \`${source.split("\n")[line - 1] ?? ""}'
|
|
|
13189
13192
|
try {
|
|
13190
13193
|
if (loadedSource?.path === path) source = loadedSource.source;
|
|
13191
13194
|
else {
|
|
13192
|
-
const
|
|
13193
|
-
const stat = await interruptible(this.fs.stat(path,
|
|
13195
|
+
const options3 = { signal: this.signal };
|
|
13196
|
+
const stat = await interruptible(this.fs.stat(path, options3), this.signal);
|
|
13194
13197
|
if (stat.type !== "file") throw new CommandFailure(`${target}: ${stat.type === "directory" ? "Is a directory" : "not a regular file"}`, 126);
|
|
13195
13198
|
if (direct && this.fs.capabilities.permissions !== true) throw new CommandFailure(`${target}: execution permissions are not supported by this filesystem`, 126);
|
|
13196
|
-
await interruptible(this.fs.access(path, ACCESS_MODES.R_OK | (direct ? ACCESS_MODES.X_OK : 0),
|
|
13199
|
+
await interruptible(this.fs.access(path, ACCESS_MODES.R_OK | (direct ? ACCESS_MODES.X_OK : 0), options3), this.signal);
|
|
13197
13200
|
const maxBytes = this.budget.limits.maxSourceBytes - this.budget.sourceBytes;
|
|
13198
13201
|
if (stat.size > maxBytes) this.budget.fail("maxSourceBytes");
|
|
13199
|
-
const bytes2 = await interruptible(this.fs.readFile(path, { ...
|
|
13202
|
+
const bytes2 = await interruptible(this.fs.readFile(path, { ...options3, maxBytes }), this.signal);
|
|
13200
13203
|
this.budget.source(bytes2.byteLength);
|
|
13201
13204
|
source = this.sourceText(bytes2, target);
|
|
13202
13205
|
}
|
|
@@ -13323,7 +13326,7 @@ ${prefix2} line ${offset + line}: \`${source.split("\n")[line - 1] ?? ""}'
|
|
|
13323
13326
|
let target = filename;
|
|
13324
13327
|
let source;
|
|
13325
13328
|
try {
|
|
13326
|
-
const
|
|
13329
|
+
const options3 = { signal: this.signal };
|
|
13327
13330
|
if (filename && !filename.includes("/") && state.variables.PATH) {
|
|
13328
13331
|
if (import_buffer.Buffer.byteLength(state.variables.PATH) > this.budget.limits.maxExpansionBytes) this.budget.fail("maxExpansionBytes");
|
|
13329
13332
|
const components = state.variables.PATH.split(":");
|
|
@@ -13334,8 +13337,8 @@ ${prefix2} line ${offset + line}: \`${source.split("\n")[line - 1] ?? ""}'
|
|
|
13334
13337
|
const candidate = `${component || "."}${component.endsWith("/") ? "" : "/"}${filename}`;
|
|
13335
13338
|
const path2 = resolvePath(state.cwd, candidate);
|
|
13336
13339
|
try {
|
|
13337
|
-
if ((await interruptible(this.fs.stat(path2,
|
|
13338
|
-
await interruptible(this.fs.access(path2, ACCESS_MODES.R_OK,
|
|
13340
|
+
if ((await interruptible(this.fs.stat(path2, options3), this.signal)).type !== "file") continue;
|
|
13341
|
+
await interruptible(this.fs.access(path2, ACCESS_MODES.R_OK, options3), this.signal);
|
|
13339
13342
|
target = candidate;
|
|
13340
13343
|
found = true;
|
|
13341
13344
|
break;
|
|
@@ -13348,13 +13351,13 @@ ${prefix2} line ${offset + line}: \`${source.split("\n")[line - 1] ?? ""}'
|
|
|
13348
13351
|
}
|
|
13349
13352
|
if (!filename) throw new CommandFailure(": No such file or directory", 1);
|
|
13350
13353
|
const path = resolvePath(state.cwd, target);
|
|
13351
|
-
const stat = await interruptible(this.fs.stat(path,
|
|
13354
|
+
const stat = await interruptible(this.fs.stat(path, options3), this.signal);
|
|
13352
13355
|
if (stat.type === "directory") throw new CommandFailure(`${context.command}: ${target}: is a directory`, 1);
|
|
13353
13356
|
if (stat.type !== "file") throw new CommandFailure(`${target}: not a regular file`, 1);
|
|
13354
|
-
await interruptible(this.fs.access(path, ACCESS_MODES.R_OK,
|
|
13357
|
+
await interruptible(this.fs.access(path, ACCESS_MODES.R_OK, options3), this.signal);
|
|
13355
13358
|
const maxBytes = this.budget.limits.maxSourceBytes - this.budget.sourceBytes;
|
|
13356
13359
|
if (stat.size > maxBytes) this.budget.fail("maxSourceBytes");
|
|
13357
|
-
const bytes2 = await interruptible(this.fs.readFile(path, { ...
|
|
13360
|
+
const bytes2 = await interruptible(this.fs.readFile(path, { ...options3, maxBytes }), this.signal);
|
|
13358
13361
|
this.budget.source(bytes2.byteLength);
|
|
13359
13362
|
source = this.sourceText(bytes2, target);
|
|
13360
13363
|
} catch (error) {
|
|
@@ -13419,22 +13422,22 @@ ${prefix2} line ${offset + line}: \`${source.split("\n")[line - 1] ?? ""}'
|
|
|
13419
13422
|
}
|
|
13420
13423
|
}
|
|
13421
13424
|
}
|
|
13422
|
-
invoke(name2, args,
|
|
13423
|
-
return this.invokeChild(
|
|
13425
|
+
invoke(name2, args, options3 = {}, context, state, parent) {
|
|
13426
|
+
return this.invokeChild(options3, state, parent, () => {
|
|
13424
13427
|
if (typeof name2 !== "string" || name2.includes("\0") || !Array.isArray(args) || args.some((arg) => typeof arg !== "string" || arg.includes("\0"))) {
|
|
13425
13428
|
throw new TypeError("invoke requires a command and literal string arguments without NUL");
|
|
13426
13429
|
}
|
|
13427
13430
|
if (state.depth >= this.budget.limits.maxSubstitutionDepth) this.budget.fail("maxSubstitutionDepth");
|
|
13428
|
-
}, (runtime, scope) => runtime.invokeScoped(name2, args,
|
|
13431
|
+
}, (runtime, scope) => runtime.invokeScoped(name2, args, options3, context, state, scope));
|
|
13429
13432
|
}
|
|
13430
|
-
async invokeScoped(name2, args,
|
|
13433
|
+
async invokeScoped(name2, args, options3, context, state, scope) {
|
|
13431
13434
|
this.signal.throwIfAborted();
|
|
13432
13435
|
const allocation = this.budget.values.scope();
|
|
13433
13436
|
scope.register(() => allocation.close());
|
|
13434
|
-
const carrier = this.admitArguments(getCommandArguments({ args, ...
|
|
13437
|
+
const carrier = this.admitArguments(getCommandArguments({ args, ...options3.argumentValues ? { argumentValues: options3.argumentValues } : {} }).values, allocation);
|
|
13435
13438
|
const child = await cloneState(state, this.signal);
|
|
13436
|
-
child.cwd = resolvePath(context.cwd,
|
|
13437
|
-
const env =
|
|
13439
|
+
child.cwd = resolvePath(context.cwd, options3.cwd ?? ".");
|
|
13440
|
+
const env = options3.replaceEnv ? { ...options3.env } : { ...context.env, ...options3.env, PWD: child.cwd };
|
|
13438
13441
|
if (guestArrays(child) || Object.keys(env).some((key) => arrayStore(child)?.get(key))) await this.indexedEnvironment(child, env);
|
|
13439
13442
|
else {
|
|
13440
13443
|
for (const key of child.exported) delete child.variables[key];
|
|
@@ -13450,15 +13453,15 @@ ${prefix2} line ${offset + line}: \`${source.split("\n")[line - 1] ?? ""}'
|
|
|
13450
13453
|
child.functionDepth = 0;
|
|
13451
13454
|
child.sourceDepth = 0;
|
|
13452
13455
|
child.locals = [];
|
|
13453
|
-
const input3 =
|
|
13454
|
-
const stdinIsDefault =
|
|
13456
|
+
const input3 = options3.stdin === void 0 ? void 0 : new ShellInput(options3.stdin, this.budget, this.signal);
|
|
13457
|
+
const stdinIsDefault = options3.stdin === void 0 ? context.stdinIsDefault : options3.stdinIsDefault ?? false;
|
|
13455
13458
|
const io = {
|
|
13456
13459
|
...context,
|
|
13457
13460
|
[invocationScope]: scope,
|
|
13458
13461
|
stdin: input3 ?? context.stdin,
|
|
13459
13462
|
...stdinIsDefault === void 0 ? {} : { stdinIsDefault },
|
|
13460
|
-
stdout:
|
|
13461
|
-
stderr:
|
|
13463
|
+
stdout: options3.stdout ? this.budget.sink(options3.stdout, this.signal) : context.stdout,
|
|
13464
|
+
stderr: options3.stderr ? this.budget.sink(options3.stderr, this.signal) : context.stderr
|
|
13462
13465
|
};
|
|
13463
13466
|
const command2 = {
|
|
13464
13467
|
kind: "simple",
|
|
@@ -13506,8 +13509,8 @@ ${prefix2} line ${offset + line}: \`${source.split("\n")[line - 1] ?? ""}'
|
|
|
13506
13509
|
else if (flag === "o" && position === option.length - 1) {
|
|
13507
13510
|
const name2 = args[index + 1];
|
|
13508
13511
|
if (name2 === void 0) {
|
|
13509
|
-
const
|
|
13510
|
-
for (const [name3, active] of
|
|
13512
|
+
const options3 = [["errexit", !!state.errexit], ["nounset", !!state.nounset], ["pipefail", state.pipefail]];
|
|
13513
|
+
for (const [name3, active] of options3) await writeText(stdout, enabled ? `${name3} ${active ? "on" : "off"}
|
|
13511
13514
|
` : `set ${active ? "-" : "+"}o ${name3}
|
|
13512
13515
|
`);
|
|
13513
13516
|
} else {
|
|
@@ -13538,7 +13541,7 @@ ${prefix2} line ${offset + line}: \`${source.split("\n")[line - 1] ?? ""}'
|
|
|
13538
13541
|
async letBuiltin(context, state) {
|
|
13539
13542
|
this.signal.throwIfAborted();
|
|
13540
13543
|
const { maxExpansionBytes: bytes2, maxExpansionFields: fields } = this.budget.limits;
|
|
13541
|
-
const
|
|
13544
|
+
const admit2 = (value3) => {
|
|
13542
13545
|
if (typeof value3 !== "string" || value3.includes("\0")) throw new CommandFailure("let: arguments must be strings without NUL", 2);
|
|
13543
13546
|
if (value3.length > bytes2 || import_buffer.Buffer.byteLength(value3) > bytes2) this.budget.fail("maxExpansionBytes");
|
|
13544
13547
|
};
|
|
@@ -13550,10 +13553,10 @@ ${prefix2} line ${offset + line}: \`${source.split("\n")[line - 1] ?? ""}'
|
|
|
13550
13553
|
const { args } = context;
|
|
13551
13554
|
if (!Array.isArray(args)) throw new CommandFailure("let: argument array required", 2);
|
|
13552
13555
|
if (args.length + 1 > fields) this.budget.fail("maxExpansionFields");
|
|
13553
|
-
|
|
13556
|
+
admit2(context.command);
|
|
13554
13557
|
for (let index = 0; index < args.length; index++) {
|
|
13555
13558
|
this.signal.throwIfAborted();
|
|
13556
|
-
|
|
13559
|
+
admit2(args[index]);
|
|
13557
13560
|
if ((index + 1) % 128 === 0) await checkpoint();
|
|
13558
13561
|
}
|
|
13559
13562
|
if (args[0] === "--help") throw new CommandFailure("let: --help: unsupported option", 2);
|
|
@@ -13582,7 +13585,7 @@ ${prefix2} line ${offset + line}: \`${source.split("\n")[line - 1] ?? ""}'
|
|
|
13582
13585
|
async getoptsBuiltin(context, state) {
|
|
13583
13586
|
this.signal.throwIfAborted();
|
|
13584
13587
|
const { maxExpansionBytes: bytes2, maxExpansionFields: fields } = this.budget.limits;
|
|
13585
|
-
const
|
|
13588
|
+
const admit2 = (value2) => {
|
|
13586
13589
|
if (typeof value2 !== "string") throw new CommandFailure("getopts: arguments must be strings without NUL", 2);
|
|
13587
13590
|
if (value2.length > bytes2 || import_buffer.Buffer.byteLength(value2) > bytes2) this.budget.fail("maxExpansionBytes");
|
|
13588
13591
|
if (value2.includes("\0")) throw new CommandFailure("getopts: arguments must be strings without NUL", 2);
|
|
@@ -13594,10 +13597,10 @@ ${prefix2} line ${offset + line}: \`${source.split("\n")[line - 1] ?? ""}'
|
|
|
13594
13597
|
};
|
|
13595
13598
|
if (!Array.isArray(context.args)) throw new CommandFailure("getopts: argument array required", 2);
|
|
13596
13599
|
if (context.args.length + 1 > fields) this.budget.fail("maxExpansionFields");
|
|
13597
|
-
|
|
13600
|
+
admit2(context.command);
|
|
13598
13601
|
for (let index = 0; index < context.args.length; index++) {
|
|
13599
13602
|
this.signal.throwIfAborted();
|
|
13600
|
-
|
|
13603
|
+
admit2(context.args[index]);
|
|
13601
13604
|
if ((index + 1) % 128 === 0) await checkpoint();
|
|
13602
13605
|
}
|
|
13603
13606
|
const offset = context.args[0] === "--" ? 1 : 0;
|
|
@@ -13616,7 +13619,7 @@ ${prefix2} line ${offset + line}: \`${source.split("\n")[line - 1] ?? ""}'
|
|
|
13616
13619
|
if (args.length > fields) this.budget.fail("maxExpansionFields");
|
|
13617
13620
|
for (let index = 0; index < args.length; index++) {
|
|
13618
13621
|
this.signal.throwIfAborted();
|
|
13619
|
-
|
|
13622
|
+
admit2(args[index]);
|
|
13620
13623
|
if ((index + 1) % 128 === 0) await checkpoint();
|
|
13621
13624
|
}
|
|
13622
13625
|
const maxBytes = saturatedProduct(bytes2, saturatedSum(args.length, 1));
|
|
@@ -13977,14 +13980,14 @@ ${prefix2} line ${offset + line}: \`${source.split("\n")[line - 1] ?? ""}'
|
|
|
13977
13980
|
const declarationArgs = [...args];
|
|
13978
13981
|
let indexedLocal = false;
|
|
13979
13982
|
if (command2 === "local") {
|
|
13980
|
-
const
|
|
13981
|
-
if (
|
|
13982
|
-
await writeText(stderr, `local: ${
|
|
13983
|
+
const options3 = localDeclarationOptions(declarationArgs, this.signal);
|
|
13984
|
+
if (options3.error !== void 0) {
|
|
13985
|
+
await writeText(stderr, `local: ${options3.error}: unsupported option
|
|
13983
13986
|
`);
|
|
13984
13987
|
return 2;
|
|
13985
13988
|
}
|
|
13986
|
-
indexedLocal =
|
|
13987
|
-
declarationArgs.splice(0,
|
|
13989
|
+
indexedLocal = options3.indexed;
|
|
13990
|
+
declarationArgs.splice(0, options3.offset);
|
|
13988
13991
|
if (indexedLocal && declarationArgs.length === 0) {
|
|
13989
13992
|
await writeText(stderr, "local: -a requires a variable name\n");
|
|
13990
13993
|
return 2;
|
|
@@ -15179,15 +15182,15 @@ var ShellInput = class _ShellInput {
|
|
|
15179
15182
|
return bytes2;
|
|
15180
15183
|
});
|
|
15181
15184
|
}
|
|
15182
|
-
line(raw,
|
|
15183
|
-
return this.#cursor.consume(this.signal, () =>
|
|
15185
|
+
line(raw, options3) {
|
|
15186
|
+
return this.#cursor.consume(this.signal, () => options3 ? this.readBounded(raw, options3) : this.readLine(raw));
|
|
15184
15187
|
}
|
|
15185
|
-
async readBounded(raw,
|
|
15188
|
+
async readBounded(raw, options3) {
|
|
15186
15189
|
const text = new ReadText();
|
|
15187
15190
|
let characters = 0;
|
|
15188
15191
|
const escaped = /* @__PURE__ */ new Set();
|
|
15189
15192
|
const decoder3 = new TextDecoder("utf-8", { fatal: true });
|
|
15190
|
-
const delimiter =
|
|
15193
|
+
const delimiter = options3.delimiter ?? 10;
|
|
15191
15194
|
let chunk = new Uint8Array();
|
|
15192
15195
|
let offset = 0;
|
|
15193
15196
|
let length = 0;
|
|
@@ -15195,7 +15198,7 @@ var ShellInput = class _ShellInput {
|
|
|
15195
15198
|
let escapedCharacter = false;
|
|
15196
15199
|
let units = 0;
|
|
15197
15200
|
let pulls = 0;
|
|
15198
|
-
let terminated =
|
|
15201
|
+
let terminated = options3.count === 0;
|
|
15199
15202
|
try {
|
|
15200
15203
|
while (!terminated) {
|
|
15201
15204
|
if (offset === chunk.length) {
|
|
@@ -15209,7 +15212,7 @@ var ShellInput = class _ShellInput {
|
|
|
15209
15212
|
if (!chunk.length) continue;
|
|
15210
15213
|
}
|
|
15211
15214
|
const byte = chunk[offset++];
|
|
15212
|
-
if (!
|
|
15215
|
+
if (!options3.exact && !escaping && byte === delimiter) {
|
|
15213
15216
|
terminated = true;
|
|
15214
15217
|
break;
|
|
15215
15218
|
}
|
|
@@ -15239,8 +15242,8 @@ var ShellInput = class _ShellInput {
|
|
|
15239
15242
|
characters++;
|
|
15240
15243
|
decodedCharacters++;
|
|
15241
15244
|
}
|
|
15242
|
-
units +=
|
|
15243
|
-
if (units ===
|
|
15245
|
+
units += options3.byteCount ? 1 : decodedCharacters;
|
|
15246
|
+
if (units === options3.count) terminated = true;
|
|
15244
15247
|
}
|
|
15245
15248
|
decoder3.decode();
|
|
15246
15249
|
return { value: text.finish(), escaped, terminated };
|
|
@@ -15350,7 +15353,7 @@ var RootInvocationCancellationOwner = class {
|
|
|
15350
15353
|
assertAdmissionOpen() {
|
|
15351
15354
|
if (!this.#admissionOpen) throw new Error("Root cancellation admission is closed");
|
|
15352
15355
|
}
|
|
15353
|
-
capture(
|
|
15356
|
+
capture(execute3) {
|
|
15354
15357
|
return new Promise((resolve) => {
|
|
15355
15358
|
let settled = false;
|
|
15356
15359
|
let raw;
|
|
@@ -15372,7 +15375,7 @@ var RootInvocationCancellationOwner = class {
|
|
|
15372
15375
|
});
|
|
15373
15376
|
};
|
|
15374
15377
|
try {
|
|
15375
|
-
raw = Promise.resolve(
|
|
15378
|
+
raw = Promise.resolve(execute3());
|
|
15376
15379
|
} catch (reason) {
|
|
15377
15380
|
settle({ kind: "throw", reason });
|
|
15378
15381
|
return;
|
|
@@ -15413,12 +15416,12 @@ var Shell = class {
|
|
|
15413
15416
|
#disposed = false;
|
|
15414
15417
|
#disposal;
|
|
15415
15418
|
#active = /* @__PURE__ */ new Set();
|
|
15416
|
-
constructor(
|
|
15417
|
-
if (!
|
|
15418
|
-
warnIfHostProcessEnv(
|
|
15419
|
-
resolveLimits(
|
|
15420
|
-
this.#options = { ...
|
|
15421
|
-
this.commands =
|
|
15419
|
+
constructor(options3) {
|
|
15420
|
+
if (!options3?.fs) throw new TypeError("Shell requires an explicit filesystem");
|
|
15421
|
+
warnIfHostProcessEnv(options3.env);
|
|
15422
|
+
resolveLimits(options3.limits);
|
|
15423
|
+
this.#options = { ...options3, cwd: resolvePath("/", options3.cwd ?? "/"), env: { ...options3.env }, limits: { ...options3.limits } };
|
|
15424
|
+
this.commands = options3.commands ?? new CommandRegistry();
|
|
15422
15425
|
}
|
|
15423
15426
|
use(middleware) {
|
|
15424
15427
|
if (this.#disposed) throw new Error("Shell is disposed");
|
|
@@ -15431,17 +15434,17 @@ var Shell = class {
|
|
|
15431
15434
|
if (!middleware || typeof middleware.setup !== "function") throw new TypeError("Expected middleware or shell plugin");
|
|
15432
15435
|
this.#ready = this.#ready.then(async () => {
|
|
15433
15436
|
let active = true;
|
|
15434
|
-
const
|
|
15437
|
+
const admit2 = () => {
|
|
15435
15438
|
if (this.#disposed && !active) throw new Error("Shell is disposed");
|
|
15436
15439
|
};
|
|
15437
15440
|
const host = {
|
|
15438
15441
|
commands: this.commands,
|
|
15439
15442
|
use: (middleware2) => {
|
|
15440
|
-
|
|
15443
|
+
admit2();
|
|
15441
15444
|
this.#install(middleware2);
|
|
15442
15445
|
},
|
|
15443
15446
|
registerFileSystem: (scheme, factory) => {
|
|
15444
|
-
|
|
15447
|
+
admit2();
|
|
15445
15448
|
this.#registerFileSystem(scheme, factory);
|
|
15446
15449
|
}
|
|
15447
15450
|
};
|
|
@@ -15455,9 +15458,9 @@ var Shell = class {
|
|
|
15455
15458
|
void this.#ready.catch(() => void 0);
|
|
15456
15459
|
}
|
|
15457
15460
|
}
|
|
15458
|
-
register(command2,
|
|
15461
|
+
register(command2, options3) {
|
|
15459
15462
|
if (this.#disposed) throw new Error("Shell is disposed");
|
|
15460
|
-
this.commands.register(command2,
|
|
15463
|
+
this.commands.register(command2, options3);
|
|
15461
15464
|
return this;
|
|
15462
15465
|
}
|
|
15463
15466
|
registerFileSystem(scheme, factory) {
|
|
@@ -15469,23 +15472,23 @@ var Shell = class {
|
|
|
15469
15472
|
if (this.#filesystems.has(scheme)) throw new Error(`Filesystem already registered: ${scheme}`);
|
|
15470
15473
|
this.#filesystems.set(scheme, factory);
|
|
15471
15474
|
}
|
|
15472
|
-
async createFileSystem(scheme,
|
|
15475
|
+
async createFileSystem(scheme, options3 = {}) {
|
|
15473
15476
|
if (this.#disposed) throw new Error("Shell is disposed");
|
|
15474
15477
|
await this.#ready;
|
|
15475
15478
|
const factory = this.#filesystems.get(scheme);
|
|
15476
15479
|
if (!factory) throw new Error(`Unknown filesystem scheme: ${scheme}`);
|
|
15477
|
-
return factory(
|
|
15480
|
+
return factory(options3);
|
|
15478
15481
|
}
|
|
15479
|
-
async exec(source,
|
|
15482
|
+
async exec(source, options3 = {}) {
|
|
15480
15483
|
if (this.#disposed) throw new Error("Shell is disposed");
|
|
15481
|
-
warnIfHostProcessEnv(
|
|
15482
|
-
const budget = new Budget(resolveLimits(this.#options.limits,
|
|
15483
|
-
const scope = new InvocationScope(
|
|
15484
|
+
warnIfHostProcessEnv(options3.env);
|
|
15485
|
+
const budget = new Budget(resolveLimits(this.#options.limits, options3.limits), options3.signal);
|
|
15486
|
+
const scope = new InvocationScope(options3.signal);
|
|
15484
15487
|
const cancellationState = new RuntimeCancellationState();
|
|
15485
15488
|
const owner = new RootInvocationCancellationOwner(scope);
|
|
15486
15489
|
const boundary = createRootCancellationLink({
|
|
15487
15490
|
admission: Runtime.rootCancellationAdmission(budget),
|
|
15488
|
-
callerSignal:
|
|
15491
|
+
callerSignal: options3.signal,
|
|
15489
15492
|
controls: [{ role: "budget-control", signal: budget.controller.signal }]
|
|
15490
15493
|
});
|
|
15491
15494
|
try {
|
|
@@ -15500,7 +15503,7 @@ var Shell = class {
|
|
|
15500
15503
|
this.#active.add(active);
|
|
15501
15504
|
let captured;
|
|
15502
15505
|
try {
|
|
15503
|
-
captured = await owner.capture(() => this.#execute(source,
|
|
15506
|
+
captured = await owner.capture(() => this.#execute(source, options3, scope, budget, boundary, cancellationState, owner));
|
|
15504
15507
|
} finally {
|
|
15505
15508
|
budget.close();
|
|
15506
15509
|
await scope.close();
|
|
@@ -15512,7 +15515,7 @@ var Shell = class {
|
|
|
15512
15515
|
throwCleanupFailures(scope.failures);
|
|
15513
15516
|
return selection.outcome.value;
|
|
15514
15517
|
}
|
|
15515
|
-
async #execute(source,
|
|
15518
|
+
async #execute(source, options3, scope, budget, cancellation, cancellationState, owner) {
|
|
15516
15519
|
if (typeof source !== "string") throw new TypeError("Shell source must be a string");
|
|
15517
15520
|
if (import_buffer.Buffer.byteLength(source) > budget.limits.maxSourceBytes) throw new ShellLimitError("maxSourceBytes");
|
|
15518
15521
|
budget.source(import_buffer.Buffer.byteLength(source));
|
|
@@ -15536,20 +15539,20 @@ var Shell = class {
|
|
|
15536
15539
|
const io = {
|
|
15537
15540
|
[invocationScope]: scope,
|
|
15538
15541
|
stdin: toByteSource(""),
|
|
15539
|
-
stdinIsDefault:
|
|
15540
|
-
stdout: sink(stdout,
|
|
15541
|
-
stderr: sink(stderr,
|
|
15542
|
+
stdinIsDefault: options3.stdin === void 0,
|
|
15543
|
+
stdout: sink(stdout, options3.stdout),
|
|
15544
|
+
stderr: sink(stderr, options3.stderr)
|
|
15542
15545
|
};
|
|
15543
15546
|
let exitCode;
|
|
15544
15547
|
let failed = false;
|
|
15545
15548
|
try {
|
|
15546
15549
|
try {
|
|
15547
|
-
let unit = parseShellUnit(source, 0, byteLocale({ ...this.#options.env, ...
|
|
15548
|
-
stdin = new ShellInput(typeof
|
|
15550
|
+
let unit = parseShellUnit(source, 0, byteLocale({ ...this.#options.env, ...options3.env }));
|
|
15551
|
+
stdin = new ShellInput(typeof options3.stdin === "string" || options3.stdin instanceof Uint8Array ? toByteSource(options3.stdin) : options3.stdin ?? toByteSource(""), budget);
|
|
15549
15552
|
io.stdin = stdin;
|
|
15550
15553
|
await interruptible(this.#ready, budget.signal);
|
|
15551
|
-
const cwd = resolvePath("/",
|
|
15552
|
-
const variables = Object.assign(/* @__PURE__ */ Object.create(null), this.#options.env,
|
|
15554
|
+
const cwd = resolvePath("/", options3.cwd ?? this.#options.cwd ?? "/");
|
|
15555
|
+
const variables = Object.assign(/* @__PURE__ */ Object.create(null), this.#options.env, options3.env, { PWD: cwd });
|
|
15553
15556
|
for (const [name2, value2] of Object.entries(variables)) {
|
|
15554
15557
|
if (name2.includes("\0") || name2.includes("=") || typeof value2 !== "string" || value2.includes("\0")) throw new TypeError("Invalid environment entry");
|
|
15555
15558
|
}
|
|
@@ -15576,7 +15579,7 @@ var Shell = class {
|
|
|
15576
15579
|
};
|
|
15577
15580
|
const admission = Runtime.rootCancellationAdmission(budget);
|
|
15578
15581
|
const runtime = new Runtime(
|
|
15579
|
-
|
|
15582
|
+
options3.fs ?? this.#options.fs,
|
|
15580
15583
|
this.commands,
|
|
15581
15584
|
[...this.#middleware],
|
|
15582
15585
|
budget,
|
|
@@ -15681,6 +15684,7 @@ var cloudflareWorkerLimits = Object.freeze({
|
|
|
15681
15684
|
maxInputBytes: 4 * 1024 * 1024,
|
|
15682
15685
|
maxOutputBytes: 4 * 1024 * 1024,
|
|
15683
15686
|
maxCommands: 1e3,
|
|
15687
|
+
maxRedirects: 64,
|
|
15684
15688
|
maxPipelineStages: 64,
|
|
15685
15689
|
maxLoopIterations: 1e3,
|
|
15686
15690
|
maxSubstitutionDepth: 16,
|
|
@@ -15762,8 +15766,8 @@ function requestBody(source, signal) {
|
|
|
15762
15766
|
}
|
|
15763
15767
|
});
|
|
15764
15768
|
}
|
|
15765
|
-
function createFetchTransport(
|
|
15766
|
-
const fetchRequest =
|
|
15769
|
+
function createFetchTransport(options3 = {}) {
|
|
15770
|
+
const fetchRequest = options3.fetch ?? globalThis.fetch;
|
|
15767
15771
|
if (typeof fetchRequest !== "function") throw new TypeError("Fetch is unavailable");
|
|
15768
15772
|
return async (input3) => {
|
|
15769
15773
|
input3.signal.throwIfAborted();
|
|
@@ -15830,7 +15834,7 @@ function privateHostname(input3) {
|
|
|
15830
15834
|
const [first, second] = octets;
|
|
15831
15835
|
return first === 10 || first === 127 || first === 0 || first === 169 && second === 254 || first === 192 && second === 168 || first === 172 && second >= 16 && second <= 31;
|
|
15832
15836
|
}
|
|
15833
|
-
function createOriginAuthorizer(allowlist = "*",
|
|
15837
|
+
function createOriginAuthorizer(allowlist = "*", options3 = {}) {
|
|
15834
15838
|
const origins = /* @__PURE__ */ new Set();
|
|
15835
15839
|
const hosts = /* @__PURE__ */ new Set();
|
|
15836
15840
|
for (const entry of allowlist === "*" ? [] : allowlist) {
|
|
@@ -15850,7 +15854,7 @@ function createOriginAuthorizer(allowlist = "*", options2 = {}) {
|
|
|
15850
15854
|
return (request) => {
|
|
15851
15855
|
const url = new URL(request.url);
|
|
15852
15856
|
const hostname = url.hostname.toLowerCase().replace(/\.$/u, "");
|
|
15853
|
-
if (
|
|
15857
|
+
if (options3.denyPrivateNetworks && privateHostname(hostname)) return false;
|
|
15854
15858
|
return allowlist === "*" || origins.has(url.origin) || hosts.has(hostname);
|
|
15855
15859
|
};
|
|
15856
15860
|
}
|
|
@@ -15900,25 +15904,25 @@ var ExprMatchError = class extends Error {
|
|
|
15900
15904
|
function exactObject(value2, keys) {
|
|
15901
15905
|
return value2 !== null && typeof value2 === "object" && !Array.isArray(value2) && Object.keys(value2).length === keys.length && keys.every((key) => Object.hasOwn(value2, key));
|
|
15902
15906
|
}
|
|
15903
|
-
function validateExprInput(
|
|
15907
|
+
function validateExprInput(descriptor2, rows, signal) {
|
|
15904
15908
|
signal.throwIfAborted();
|
|
15905
15909
|
const invalid = () => {
|
|
15906
15910
|
throw new RegexExecutionError("PROTOCOL", "invalid expr request");
|
|
15907
15911
|
};
|
|
15908
|
-
if (!exactObject(
|
|
15912
|
+
if (!exactObject(descriptor2, ["kind", "pattern", "profile", "limits"]) || descriptor2.kind !== "expr-match" || !(descriptor2.pattern instanceof Uint8Array) || !["byte", "utf8-scalar"].includes(descriptor2.profile)) invalid();
|
|
15909
15913
|
const keys = Object.keys(exprMatchCeilings);
|
|
15910
|
-
if (!exactObject(
|
|
15914
|
+
if (!exactObject(descriptor2.limits, keys)) invalid();
|
|
15911
15915
|
for (const key of keys) {
|
|
15912
|
-
if (!Number.isSafeInteger(
|
|
15916
|
+
if (!Number.isSafeInteger(descriptor2.limits[key]) || descriptor2.limits[key] < 1 || descriptor2.limits[key] > exprMatchCeilings[key]) invalid();
|
|
15913
15917
|
}
|
|
15914
15918
|
if (!Array.isArray(rows) || rows.length !== 1) invalid();
|
|
15915
15919
|
const row = rows[0];
|
|
15916
15920
|
if (!exactObject(row, ["bytes", "all", "terminated"]) || !(row.bytes instanceof Uint8Array) || row.all !== false || row.terminated !== false) invalid();
|
|
15917
|
-
if (
|
|
15921
|
+
if (descriptor2.pattern.length > descriptor2.limits.maxPatternBytes || row.bytes.length > descriptor2.limits.maxSubjectBytes) {
|
|
15918
15922
|
throw new ExprMatchError("limit", "regex input bytes limit exceeded");
|
|
15919
15923
|
}
|
|
15920
15924
|
}
|
|
15921
|
-
function validateExprReply(value2, id,
|
|
15925
|
+
function validateExprReply(value2, id, descriptor2, subject, signal) {
|
|
15922
15926
|
signal.throwIfAborted();
|
|
15923
15927
|
const invalid = () => {
|
|
15924
15928
|
throw new RegexExecutionError("PROTOCOL", "invalid expr reply");
|
|
@@ -15932,13 +15936,13 @@ function validateExprReply(value2, id, descriptor, subject, signal) {
|
|
|
15932
15936
|
}
|
|
15933
15937
|
if (!exactObject(reply, ["id", "operation", "result"])) return invalid();
|
|
15934
15938
|
const result = reply.result;
|
|
15935
|
-
if (!exactObject(result, ["offsetUnit", "matched", "hasCapture", "overall", "capture", "steps"]) || result.offsetUnit !== "byte" || typeof result.matched !== "boolean" || typeof result.hasCapture !== "boolean" || !Number.isSafeInteger(result.steps) || result.steps < 1 || result.steps >
|
|
15939
|
+
if (!exactObject(result, ["offsetUnit", "matched", "hasCapture", "overall", "capture", "steps"]) || result.offsetUnit !== "byte" || typeof result.matched !== "boolean" || typeof result.hasCapture !== "boolean" || !Number.isSafeInteger(result.steps) || result.steps < 1 || result.steps > descriptor2.limits.maxSteps) return invalid();
|
|
15936
15940
|
const span = (value3) => {
|
|
15937
15941
|
if (value3 === null) return null;
|
|
15938
15942
|
if (!exactObject(value3, ["start", "end"]) || !Number.isSafeInteger(value3.start) || !Number.isSafeInteger(value3.end)) return invalid();
|
|
15939
15943
|
const start = value3.start, end = value3.end;
|
|
15940
15944
|
if (start < 0 || end < start || end > subject.length) return invalid();
|
|
15941
|
-
if (
|
|
15945
|
+
if (descriptor2.profile === "utf8-scalar") {
|
|
15942
15946
|
for (const offset of [start, end]) if (offset < subject.length && subject[offset] >= 128 && subject[offset] <= 191) return invalid();
|
|
15943
15947
|
}
|
|
15944
15948
|
return { start, end };
|
|
@@ -15947,8 +15951,8 @@ function validateExprReply(value2, id, descriptor, subject, signal) {
|
|
|
15947
15951
|
if (result.matched !== (overall !== null) || overall && overall.start !== 0 || capture && (!result.hasCapture || !overall || capture.start < overall.start || capture.end > overall.end)) return invalid();
|
|
15948
15952
|
return { offsetUnit: "byte", matched: result.matched, hasCapture: result.hasCapture, overall, capture, steps: result.steps };
|
|
15949
15953
|
}
|
|
15950
|
-
function policy(
|
|
15951
|
-
const result = { ...defaults, ...
|
|
15954
|
+
function policy(options3) {
|
|
15955
|
+
const result = { ...defaults, ...options3 };
|
|
15952
15956
|
for (const key of Object.keys(defaults)) {
|
|
15953
15957
|
const minimum = key === "maxQueuedRequests" || key === "maxQueuedBytes" ? 0 : 1;
|
|
15954
15958
|
if (!Number.isSafeInteger(result[key]) || result[key] < minimum) throw new RangeError(`regex ${key} must be a safe integer >= ${minimum}`);
|
|
@@ -15958,9 +15962,9 @@ function policy(options2) {
|
|
|
15958
15962
|
}
|
|
15959
15963
|
return Object.freeze(result);
|
|
15960
15964
|
}
|
|
15961
|
-
function inputBytes(
|
|
15962
|
-
let total = 128 + (
|
|
15963
|
-
for (const pattern of
|
|
15965
|
+
function inputBytes(descriptor2, rows, signal) {
|
|
15966
|
+
let total = 128 + (descriptor2.kind === "glob" ? descriptor2.globOptions.length * 32 : 0);
|
|
15967
|
+
for (const pattern of descriptor2.patterns) {
|
|
15964
15968
|
signal.throwIfAborted();
|
|
15965
15969
|
total += 16 + pattern.length * 2;
|
|
15966
15970
|
if (!Number.isSafeInteger(total)) throw new RegexExecutionError("QUEUE_EXHAUSTED", "input accounting overflow");
|
|
@@ -16005,7 +16009,7 @@ async function awaitRetirements(retirements) {
|
|
|
16005
16009
|
if (failures.length === 1) throw failures[0];
|
|
16006
16010
|
if (failures.length > 1) throw new AggregateError(failures, "regex retirement failed");
|
|
16007
16011
|
}
|
|
16008
|
-
async function withRegexSession(context, executor,
|
|
16012
|
+
async function withRegexSession(context, executor, execute3) {
|
|
16009
16013
|
context.signal.throwIfAborted();
|
|
16010
16014
|
let session;
|
|
16011
16015
|
let closing;
|
|
@@ -16023,7 +16027,7 @@ async function withRegexSession(context, executor, execute2) {
|
|
|
16023
16027
|
context.signal.throwIfAborted();
|
|
16024
16028
|
if (closing) throw new RegexExecutionError("CLOSED", "invocation is closed");
|
|
16025
16029
|
session = executor.open(context.signal);
|
|
16026
|
-
outcome = { result: await
|
|
16030
|
+
outcome = { result: await execute3(session) };
|
|
16027
16031
|
} catch (error) {
|
|
16028
16032
|
outcome = { error };
|
|
16029
16033
|
}
|
|
@@ -16115,10 +16119,10 @@ var Slot = class {
|
|
|
16115
16119
|
}
|
|
16116
16120
|
};
|
|
16117
16121
|
var RegexExecutor = class {
|
|
16118
|
-
constructor(provider,
|
|
16122
|
+
constructor(provider, options3 = defaults) {
|
|
16119
16123
|
this.provider = provider;
|
|
16120
16124
|
if (!provider || typeof provider.createWorker !== "function") throw new TypeError("a bounded regex provider is required");
|
|
16121
|
-
this.options = policy(
|
|
16125
|
+
this.options = policy(options3);
|
|
16122
16126
|
}
|
|
16123
16127
|
provider;
|
|
16124
16128
|
options;
|
|
@@ -16153,21 +16157,21 @@ var RegexExecutor = class {
|
|
|
16153
16157
|
this.slots.delete(slot);
|
|
16154
16158
|
this.pump();
|
|
16155
16159
|
}
|
|
16156
|
-
request(
|
|
16160
|
+
request(descriptor2, rows, signal, retirements = /* @__PURE__ */ new Set()) {
|
|
16157
16161
|
signal.throwIfAborted();
|
|
16158
16162
|
if (this.disposed) return Promise.reject(new RegexExecutionError("CLOSED", "executor is disposed"));
|
|
16159
|
-
if (
|
|
16160
|
-
const bytes2 =
|
|
16163
|
+
if (descriptor2.kind === "expr-match") validateExprInput(descriptor2, rows, signal);
|
|
16164
|
+
const bytes2 = descriptor2.kind === "expr-match" ? 256 + descriptor2.pattern.length + rows[0].bytes.length : inputBytes(descriptor2, rows, signal);
|
|
16161
16165
|
const available = this.queue.length === 0 && ([...this.slots].some((slot) => !slot.busy && !slot.retired) || this.slots.size < this.options.maxWorkers);
|
|
16162
16166
|
if (!available && (this.queue.length >= this.options.maxQueuedRequests || bytes2 > this.options.maxQueuedBytes - this.queuedBytes)) return Promise.reject(new RegexExecutionError("QUEUE_EXHAUSTED", "queued request count or input byte limit exceeded"));
|
|
16163
|
-
const ownedDescriptor =
|
|
16167
|
+
const ownedDescriptor = descriptor2.kind === "expr-match" ? { ...descriptor2, pattern: Uint8Array.from(descriptor2.pattern), limits: { ...descriptor2.limits } } : { ...descriptor2, patterns: descriptor2.patterns.map((pattern) => {
|
|
16164
16168
|
signal.throwIfAborted();
|
|
16165
16169
|
return pattern;
|
|
16166
16170
|
}) };
|
|
16167
16171
|
if (ownedDescriptor.kind === "glob") {
|
|
16168
|
-
const globOptions = ownedDescriptor.globOptions.map((
|
|
16172
|
+
const globOptions = ownedDescriptor.globOptions.map((options3) => {
|
|
16169
16173
|
signal.throwIfAborted();
|
|
16170
|
-
return { ...
|
|
16174
|
+
return { ...options3 };
|
|
16171
16175
|
});
|
|
16172
16176
|
Object.assign(ownedDescriptor, { globOptions });
|
|
16173
16177
|
}
|
|
@@ -16285,18 +16289,18 @@ var RegexSession = class {
|
|
|
16285
16289
|
retirements = /* @__PURE__ */ new Set();
|
|
16286
16290
|
controller = new AbortController();
|
|
16287
16291
|
requestSignal;
|
|
16288
|
-
run(
|
|
16292
|
+
run(descriptor2, rows) {
|
|
16289
16293
|
this.signal.throwIfAborted();
|
|
16290
16294
|
if (this.closed) throw new RegexExecutionError("CLOSED", "invocation is closed");
|
|
16291
|
-
const result = this.executor.request(
|
|
16295
|
+
const result = this.executor.request(descriptor2, rows, this.requestSignal, this.retirements);
|
|
16292
16296
|
this.pending.add(result);
|
|
16293
16297
|
void result.then(() => this.pending.delete(result), () => this.pending.delete(result));
|
|
16294
16298
|
return result;
|
|
16295
16299
|
}
|
|
16296
|
-
matchExpr(
|
|
16300
|
+
matchExpr(descriptor2, subject) {
|
|
16297
16301
|
this.signal.throwIfAborted();
|
|
16298
16302
|
if (this.closed) throw new RegexExecutionError("CLOSED", "invocation is closed");
|
|
16299
|
-
const result = this.executor.request(
|
|
16303
|
+
const result = this.executor.request(descriptor2, [{ bytes: subject, all: false, terminated: false }], this.requestSignal, this.retirements);
|
|
16300
16304
|
this.pending.add(result);
|
|
16301
16305
|
void result.then(() => this.pending.delete(result), () => this.pending.delete(result));
|
|
16302
16306
|
return result;
|
|
@@ -16429,10 +16433,10 @@ async function* requiredFileInput(context, requirements, mode, file, maxBytes) {
|
|
|
16429
16433
|
var ProgramError = class extends Error {
|
|
16430
16434
|
};
|
|
16431
16435
|
var Budget3 = class {
|
|
16432
|
-
constructor(context,
|
|
16436
|
+
constructor(context, options3) {
|
|
16433
16437
|
this.context = context;
|
|
16434
|
-
this.remaining =
|
|
16435
|
-
this.maxBufferBytes =
|
|
16438
|
+
this.remaining = options3.maxSteps ?? 5e6;
|
|
16439
|
+
this.maxBufferBytes = options3.maxBufferBytes ?? 32 * 1024 * 1024;
|
|
16436
16440
|
for (const value2 of [this.remaining, this.maxBufferBytes]) {
|
|
16437
16441
|
if (!Number.isSafeInteger(value2) || value2 < 1) throw new ProgramError("limits must be positive safe integers");
|
|
16438
16442
|
}
|
|
@@ -17049,10 +17053,10 @@ async function execute(program, context, files, quiet, budget) {
|
|
|
17049
17053
|
following = void 0;
|
|
17050
17054
|
return next;
|
|
17051
17055
|
};
|
|
17052
|
-
const prepareRecord = async (
|
|
17053
|
-
if (
|
|
17056
|
+
const prepareRecord = async (record4) => {
|
|
17057
|
+
if (record4.terminated || files.length < 2) return record4;
|
|
17054
17058
|
const next = await peekNext();
|
|
17055
|
-
return !next.done && next.value.fileIndex !==
|
|
17059
|
+
return !next.done && next.value.fileIndex !== record4.fileIndex ? { ...record4, terminated: true } : record4;
|
|
17056
17060
|
};
|
|
17057
17061
|
let number = 0;
|
|
17058
17062
|
let hold = "";
|
|
@@ -17067,8 +17071,8 @@ async function execute(program, context, files, quiet, budget) {
|
|
|
17067
17071
|
while (!current.done) {
|
|
17068
17072
|
budget.step();
|
|
17069
17073
|
number++;
|
|
17070
|
-
let
|
|
17071
|
-
let pattern =
|
|
17074
|
+
let record4 = await prepareRecord(current.value);
|
|
17075
|
+
let pattern = record4.text;
|
|
17072
17076
|
const appended = [];
|
|
17073
17077
|
let appendedSize = 0;
|
|
17074
17078
|
const append = (item) => {
|
|
@@ -17080,7 +17084,7 @@ async function execute(program, context, files, quiet, budget) {
|
|
|
17080
17084
|
let deleted = false;
|
|
17081
17085
|
let quit = false;
|
|
17082
17086
|
let status = 0;
|
|
17083
|
-
const print = () => write(context, pattern + (
|
|
17087
|
+
const print = () => write(context, pattern + (record4.terminated ? "\n" : ""));
|
|
17084
17088
|
const flush = async () => {
|
|
17085
17089
|
await assertPathRequirements(context, sedRequirements, ["script-read"], appended.flatMap((item) => item.file === void 0 ? [] : [item.file]));
|
|
17086
17090
|
if (!quiet && !deleted) await print();
|
|
@@ -17141,7 +17145,7 @@ async function execute(program, context, files, quiet, budget) {
|
|
|
17141
17145
|
break;
|
|
17142
17146
|
case "P": {
|
|
17143
17147
|
const end = pattern.indexOf("\n");
|
|
17144
|
-
await write(context, end < 0 ? pattern + (
|
|
17148
|
+
await write(context, end < 0 ? pattern + (record4.terminated ? "\n" : "") : pattern.slice(0, end + 1));
|
|
17145
17149
|
break;
|
|
17146
17150
|
}
|
|
17147
17151
|
case "=":
|
|
@@ -17255,9 +17259,9 @@ async function execute(program, context, files, quiet, budget) {
|
|
|
17255
17259
|
if (instruction.kind === "N") await flush();
|
|
17256
17260
|
return { status: 0, quit: false };
|
|
17257
17261
|
}
|
|
17258
|
-
|
|
17262
|
+
record4 = await prepareRecord(next.value);
|
|
17259
17263
|
number++;
|
|
17260
|
-
pattern = instruction.kind === "N" ? budget.check(pattern + "\n" +
|
|
17264
|
+
pattern = instruction.kind === "N" ? budget.check(pattern + "\n" + record4.text) : record4.text;
|
|
17261
17265
|
substituted = false;
|
|
17262
17266
|
break;
|
|
17263
17267
|
}
|
|
@@ -17273,9 +17277,9 @@ async function execute(program, context, files, quiet, budget) {
|
|
|
17273
17277
|
await source.return(void 0);
|
|
17274
17278
|
}
|
|
17275
17279
|
}
|
|
17276
|
-
function sedCommand(
|
|
17280
|
+
function sedCommand(options3 = {}) {
|
|
17277
17281
|
const definition = command("sed", async (context) => {
|
|
17278
|
-
const budget = new Budget3(context,
|
|
17282
|
+
const budget = new Budget3(context, options3);
|
|
17279
17283
|
const sources = [];
|
|
17280
17284
|
const files = [];
|
|
17281
17285
|
let quiet = false;
|
|
@@ -17386,7 +17390,7 @@ function createGrepCommands(executor) {
|
|
|
17386
17390
|
const patterns2 = [];
|
|
17387
17391
|
let patternCount = 0;
|
|
17388
17392
|
let patternBytes = 0;
|
|
17389
|
-
const
|
|
17393
|
+
const admit2 = (chunk, atStart) => {
|
|
17390
17394
|
context.signal.throwIfAborted();
|
|
17391
17395
|
const size = typeof chunk === "string" ? import_buffer.Buffer.byteLength(chunk) : chunk.length;
|
|
17392
17396
|
if (size > bufferLimit - patternBytes) throw new UsageError(`pattern byte limit exceeded (${bufferLimit} bytes)`);
|
|
@@ -17401,7 +17405,7 @@ function createGrepCommands(executor) {
|
|
|
17401
17405
|
return atStart;
|
|
17402
17406
|
};
|
|
17403
17407
|
const addArgument = async (pattern) => {
|
|
17404
|
-
|
|
17408
|
+
admit2(pattern, true);
|
|
17405
17409
|
if (pattern === "") {
|
|
17406
17410
|
if (++patternCount > maxPatternCount) throw new UsageError(`pattern count limit exceeded (${maxPatternCount})`);
|
|
17407
17411
|
patterns2.push("");
|
|
@@ -17412,7 +17416,7 @@ function createGrepCommands(executor) {
|
|
|
17412
17416
|
async function* admitted(source) {
|
|
17413
17417
|
let atStart = true;
|
|
17414
17418
|
for await (const chunk of source) {
|
|
17415
|
-
atStart =
|
|
17419
|
+
atStart = admit2(chunk, atStart);
|
|
17416
17420
|
yield chunk;
|
|
17417
17421
|
}
|
|
17418
17422
|
}
|
|
@@ -17423,7 +17427,7 @@ function createGrepCommands(executor) {
|
|
|
17423
17427
|
}
|
|
17424
17428
|
if (positionalPattern !== void 0) await addArgument(positionalPattern);
|
|
17425
17429
|
if (parsed.flags.has("E") && parsed.flags.has("F")) throw new UsageError("conflicting matchers specified");
|
|
17426
|
-
const
|
|
17430
|
+
const descriptor2 = {
|
|
17427
17431
|
kind: "grep",
|
|
17428
17432
|
patterns: patterns2,
|
|
17429
17433
|
fixed: parsed.flags.has("F"),
|
|
@@ -17432,7 +17436,7 @@ function createGrepCommands(executor) {
|
|
|
17432
17436
|
whole: parsed.flags.has("x"),
|
|
17433
17437
|
word: parsed.flags.has("w")
|
|
17434
17438
|
};
|
|
17435
|
-
await session.run(
|
|
17439
|
+
await session.run(descriptor2, []);
|
|
17436
17440
|
const maxCount = value(parsed, "m") === void 0 ? Infinity : integer(value(parsed, "m"));
|
|
17437
17441
|
const batchSize = Number.isFinite(maxCount) || parsed.flags.has("q") || parsed.flags.has("l") || parsed.flags.has("L") ? 1 : 128;
|
|
17438
17442
|
const delimiter = parsed.flags.has("z") ? "\0" : "\n";
|
|
@@ -17447,7 +17451,7 @@ function createGrepCommands(executor) {
|
|
|
17447
17451
|
const available = new AvailableRecords(parsed.flags.has("z") ? 0 : 10, bufferLimit);
|
|
17448
17452
|
const source = name2 === "-" ? input(context) : requiredFileInput(context, grepRequirements, "file", name2, bufferLimit);
|
|
17449
17453
|
records: if (maxCount > 0) for await (const batch of available.batches(lines(available.source(source), parsed.flags.has("z") ? 0 : 10), (line) => line.bytes.length, () => batchSize)) {
|
|
17450
|
-
const results = await session.run(
|
|
17454
|
+
const results = await session.run(descriptor2, batch.map((line) => ({ bytes: line.bytes, all: parsed.flags.has("o"), terminated: line.terminated })));
|
|
17451
17455
|
for (let index = 0; index < batch.length; index++) {
|
|
17452
17456
|
const line = batch[index];
|
|
17453
17457
|
context.signal.throwIfAborted();
|
|
@@ -17867,13 +17871,13 @@ function pathFor(context, path) {
|
|
|
17867
17871
|
var OutputClosed = class extends SearchError {
|
|
17868
17872
|
};
|
|
17869
17873
|
var Limits = class {
|
|
17870
|
-
constructor(context,
|
|
17874
|
+
constructor(context, options3) {
|
|
17871
17875
|
this.context = context;
|
|
17872
17876
|
this.signal = AbortSignal.any([context.signal, this.stopped.signal]);
|
|
17873
|
-
this.maxOutputBytes =
|
|
17874
|
-
this.maxLineBytes =
|
|
17875
|
-
this.maxFileBytes =
|
|
17876
|
-
this.maxFiles =
|
|
17877
|
+
this.maxOutputBytes = options3.maxOutputBytes ?? 16 * 1024 * 1024;
|
|
17878
|
+
this.maxLineBytes = options3.maxLineBytes ?? 1024 * 1024;
|
|
17879
|
+
this.maxFileBytes = options3.maxFileBytes ?? 64 * 1024 * 1024;
|
|
17880
|
+
this.maxFiles = options3.maxFiles ?? 1e5;
|
|
17877
17881
|
for (const limit of [this.maxOutputBytes, this.maxLineBytes, this.maxFileBytes, this.maxFiles]) {
|
|
17878
17882
|
if (!Number.isSafeInteger(limit) || limit < 1) throw new SearchError("search limits must be positive safe integers");
|
|
17879
17883
|
}
|
|
@@ -18058,13 +18062,13 @@ async function matchGlobs(globs, candidates, session) {
|
|
|
18058
18062
|
bytes2 += size;
|
|
18059
18063
|
offset++;
|
|
18060
18064
|
}
|
|
18061
|
-
const
|
|
18065
|
+
const descriptor2 = {
|
|
18062
18066
|
kind: "glob",
|
|
18063
18067
|
patterns: batch.map((glob) => glob.source),
|
|
18064
18068
|
globOptions: batch.map((glob) => ({ insensitive: glob.insensitive, literalUnclosedClass: glob.literalUnclosedClass }))
|
|
18065
18069
|
};
|
|
18066
18070
|
try {
|
|
18067
|
-
results.push(...(await session.run(
|
|
18071
|
+
results.push(...(await session.run(descriptor2, rows)).map((result) => result.length > 0));
|
|
18068
18072
|
} catch (error) {
|
|
18069
18073
|
if (error instanceof RegexExecutionError && error.code === "MATCH") throw new SearchError(error.message);
|
|
18070
18074
|
throw error;
|
|
@@ -18263,10 +18267,10 @@ var Walker = class {
|
|
|
18263
18267
|
};
|
|
18264
18268
|
|
|
18265
18269
|
// packages/safe-bash/src/commands/search/rg-command.ts
|
|
18266
|
-
function selectInput(context, args,
|
|
18270
|
+
function selectInput(context, args, options3) {
|
|
18267
18271
|
if (args.paths.length) return { paths: args.paths, implicit: false };
|
|
18268
|
-
if (args.mode === "files" ||
|
|
18269
|
-
const stdin =
|
|
18272
|
+
if (args.mode === "files" || options3.defaultInput === "cwd" || args.patternFiles.includes("-")) return { paths: ["."], implicit: true };
|
|
18273
|
+
const stdin = options3.defaultInput === "stdin" || context.stdinIsDefault === false;
|
|
18270
18274
|
return { paths: stdin ? ["-"] : ["."], implicit: !stdin };
|
|
18271
18275
|
}
|
|
18272
18276
|
async function patterns(context, args) {
|
|
@@ -18388,7 +18392,7 @@ async function searchFile(context, args, limits, matcher, printer, target, stdin
|
|
|
18388
18392
|
}
|
|
18389
18393
|
return { found, stats: totals };
|
|
18390
18394
|
}
|
|
18391
|
-
function createRgCommand(executor,
|
|
18395
|
+
function createRgCommand(executor, options3 = {}) {
|
|
18392
18396
|
return {
|
|
18393
18397
|
name: "rg",
|
|
18394
18398
|
filesystemRequirements: searchRequirements,
|
|
@@ -18399,12 +18403,12 @@ function createRgCommand(executor, options2 = {}) {
|
|
|
18399
18403
|
let failed = false;
|
|
18400
18404
|
let found = false;
|
|
18401
18405
|
try {
|
|
18402
|
-
const limits = new Limits(context,
|
|
18406
|
+
const limits = new Limits(context, options3);
|
|
18403
18407
|
args = parse2(context.args);
|
|
18404
18408
|
if (args.mode !== "files" && args.patternFiles.includes("-") && args.paths.includes("-")) {
|
|
18405
18409
|
throw new SearchError("cannot search stdin while also reading patterns from stdin");
|
|
18406
18410
|
}
|
|
18407
|
-
const selection = selectInput(context, args,
|
|
18411
|
+
const selection = selectInput(context, args, options3);
|
|
18408
18412
|
const report = async (error) => {
|
|
18409
18413
|
context.signal.throwIfAborted();
|
|
18410
18414
|
failed = true;
|
|
@@ -18454,16 +18458,16 @@ function createRgCommand(executor, options2 = {}) {
|
|
|
18454
18458
|
}
|
|
18455
18459
|
|
|
18456
18460
|
// packages/safe-bash/src/commands/search/portable.ts
|
|
18457
|
-
function portableSearchCommands(
|
|
18458
|
-
const executor = new RegexExecutor(
|
|
18459
|
-
const commands = [...createGrepCommands(executor), createRgCommand(executor,
|
|
18461
|
+
function portableSearchCommands(options3) {
|
|
18462
|
+
const executor = new RegexExecutor(options3.provider, options3.regex);
|
|
18463
|
+
const commands = [...createGrepCommands(executor), createRgCommand(executor, options3.search), sedCommand(options3.sed)];
|
|
18460
18464
|
return {
|
|
18461
18465
|
name: "portable-search-commands",
|
|
18462
18466
|
setup(host) {
|
|
18463
|
-
if (!
|
|
18467
|
+
if (!options3.replace) for (const command2 of commands) {
|
|
18464
18468
|
if (host.commands.has(command2.name)) throw new Error(`Command already registered: ${command2.name}`);
|
|
18465
18469
|
}
|
|
18466
|
-
for (const command2 of commands) host.commands.register(command2, { replace:
|
|
18470
|
+
for (const command2 of commands) host.commands.register(command2, { replace: options3.replace ?? false });
|
|
18467
18471
|
},
|
|
18468
18472
|
dispose: () => executor.dispose()
|
|
18469
18473
|
};
|
|
@@ -18472,6 +18476,281 @@ function portableSearchCommands(options2) {
|
|
|
18472
18476
|
// packages/safe-bash/src/commands/regex-execution/public.ts
|
|
18473
18477
|
init_platform();
|
|
18474
18478
|
|
|
18479
|
+
// packages/safe-bash/src/commands/regex-execution/bounded-provider.ts
|
|
18480
|
+
init_platform();
|
|
18481
|
+
var defaults2 = Object.freeze({
|
|
18482
|
+
maxWorkers: 2,
|
|
18483
|
+
maxPatterns: 32,
|
|
18484
|
+
maxPatternBytes: 8192,
|
|
18485
|
+
maxRows: 128,
|
|
18486
|
+
maxInputBytes: 65536,
|
|
18487
|
+
maxResultBytes: 2048,
|
|
18488
|
+
maxWork: 2e6,
|
|
18489
|
+
maxAllocationUnits: 1e6,
|
|
18490
|
+
maxStates: 65536
|
|
18491
|
+
});
|
|
18492
|
+
var ceilings = Object.freeze({
|
|
18493
|
+
maxWorkers: 32,
|
|
18494
|
+
maxPatterns: 128,
|
|
18495
|
+
maxPatternBytes: 65532,
|
|
18496
|
+
maxRows: 4096,
|
|
18497
|
+
maxInputBytes: 1048576,
|
|
18498
|
+
maxResultBytes: 65536,
|
|
18499
|
+
maxWork: 33554432,
|
|
18500
|
+
maxAllocationUnits: 4e6,
|
|
18501
|
+
maxStates: 65536
|
|
18502
|
+
});
|
|
18503
|
+
var typedArrayPrototype2 = Object.getPrototypeOf(Uint8Array.prototype);
|
|
18504
|
+
var byteLength = Object.getOwnPropertyDescriptor(typedArrayPrototype2, "byteLength").get;
|
|
18505
|
+
var byteOffset = Object.getOwnPropertyDescriptor(typedArrayPrototype2, "byteOffset").get;
|
|
18506
|
+
var byteBuffer = Object.getOwnPropertyDescriptor(typedArrayPrototype2, "buffer").get;
|
|
18507
|
+
function fail(kind, message2) {
|
|
18508
|
+
throw new Error(`bounded regex ${kind}: ${message2}`);
|
|
18509
|
+
}
|
|
18510
|
+
function record3(value2, keys, optional = []) {
|
|
18511
|
+
if (value2 === null || typeof value2 !== "object" || Array.isArray(value2)) fail("protocol", "expected a data record");
|
|
18512
|
+
const ownKeys = Reflect.ownKeys(value2);
|
|
18513
|
+
if (ownKeys.length < keys.length || ownKeys.length > keys.length + optional.length || ownKeys.some((key) => typeof key !== "string" || !keys.includes(key) && !optional.includes(key))) fail("protocol", "unexpected data-record fields");
|
|
18514
|
+
for (const key of [...keys, ...optional]) {
|
|
18515
|
+
const property = Object.getOwnPropertyDescriptor(value2, key);
|
|
18516
|
+
if (property === void 0 ? keys.includes(key) : !("value" in property)) fail("protocol", "missing field or accessor");
|
|
18517
|
+
}
|
|
18518
|
+
}
|
|
18519
|
+
function array(value2, limit, label) {
|
|
18520
|
+
if (!Array.isArray(value2)) fail("protocol", `${label} must be an array`);
|
|
18521
|
+
if (value2.length > limit) fail("limit", `${label} count limit exceeded`);
|
|
18522
|
+
const keys = Reflect.ownKeys(value2);
|
|
18523
|
+
if (keys.length !== value2.length + 1) fail("protocol", `${label} must be a dense data array`);
|
|
18524
|
+
for (let index = 0; index < value2.length; index++) {
|
|
18525
|
+
const property = Object.getOwnPropertyDescriptor(value2, index);
|
|
18526
|
+
if (!property || !("value" in property)) fail("protocol", `${label} must be a dense data array`);
|
|
18527
|
+
}
|
|
18528
|
+
}
|
|
18529
|
+
function options2(input3) {
|
|
18530
|
+
const keys = Object.keys(defaults2);
|
|
18531
|
+
try {
|
|
18532
|
+
record3(input3, [], keys);
|
|
18533
|
+
} catch {
|
|
18534
|
+
throw new TypeError("bounded regex options require supported own data fields");
|
|
18535
|
+
}
|
|
18536
|
+
const result = { ...defaults2 };
|
|
18537
|
+
for (const key of keys) {
|
|
18538
|
+
if (!Object.hasOwn(input3, key)) continue;
|
|
18539
|
+
const value2 = input3[key];
|
|
18540
|
+
if (typeof value2 !== "number" || !Number.isSafeInteger(value2) || value2 < 1 || value2 > ceilings[key]) throw new RangeError(`bounded regex option ${key} is outside its limit`);
|
|
18541
|
+
result[key] = value2;
|
|
18542
|
+
}
|
|
18543
|
+
return Object.freeze(result);
|
|
18544
|
+
}
|
|
18545
|
+
function descriptor(value2, limits) {
|
|
18546
|
+
if (value2 === null || typeof value2 !== "object") fail("protocol", "invalid descriptor");
|
|
18547
|
+
const kind = Object.getOwnPropertyDescriptor(value2, "kind");
|
|
18548
|
+
if (!kind || !("value" in kind)) fail("protocol", "invalid descriptor kind");
|
|
18549
|
+
if (kind.value !== "grep" && kind.value !== "rg") fail("unsupported", "only grep and fixed rg selection descriptors are supported");
|
|
18550
|
+
const flags = kind.value === "grep" ? ["fixed", "extended", "insensitive", "whole", "word"] : ["fixed", "whole", "word", "nullData"];
|
|
18551
|
+
record3(value2, ["kind", "patterns", ...flags, ...kind.value === "rg" ? ["case"] : []]);
|
|
18552
|
+
for (const flag of flags) if (typeof value2[flag] !== "boolean") fail("protocol", `invalid ${flag} flag`);
|
|
18553
|
+
if (kind.value === "rg" && !["sensitive", "insensitive", "smart"].includes(value2.case)) fail("protocol", "invalid case flag");
|
|
18554
|
+
if (value2.word || kind.value === "grep" && value2.insensitive || kind.value === "rg" && value2.case !== "sensitive") fail("unsupported", "only case-sensitive, non-word selection is supported");
|
|
18555
|
+
if (kind.value === "rg" && !value2.fixed) fail("unsupported", "rg regex and Unicode modes are unsupported; use fixed ASCII patterns");
|
|
18556
|
+
array(value2.patterns, limits.maxPatterns, "pattern");
|
|
18557
|
+
let bytes2 = 0;
|
|
18558
|
+
for (let index = 0; index < value2.patterns.length; index++) {
|
|
18559
|
+
const pattern = value2.patterns[index];
|
|
18560
|
+
if (typeof pattern !== "string") fail("protocol", "patterns must be strings");
|
|
18561
|
+
if (pattern.length > limits.maxPatternBytes - bytes2) fail("limit", "aggregate pattern byte limit exceeded");
|
|
18562
|
+
bytes2 += pattern.length;
|
|
18563
|
+
}
|
|
18564
|
+
return value2;
|
|
18565
|
+
}
|
|
18566
|
+
function admit(input3, limits, signal) {
|
|
18567
|
+
record3(input3, ["id", "descriptor", "rows"]);
|
|
18568
|
+
const selected = descriptor(input3.descriptor, limits);
|
|
18569
|
+
array(input3.rows, limits.maxRows, "row");
|
|
18570
|
+
if (input3.rows.length > Math.floor(limits.maxResultBytes / 16)) fail("limit", "result byte limit exceeded");
|
|
18571
|
+
let bytes2 = 0;
|
|
18572
|
+
for (let index = 0; index < input3.rows.length; index++) {
|
|
18573
|
+
const row = input3.rows[index];
|
|
18574
|
+
record3(row, ["bytes", "all", "terminated"], ["directory", "ancestors"]);
|
|
18575
|
+
if (!(row.bytes instanceof Uint8Array) || typeof row.all !== "boolean" || typeof row.terminated !== "boolean" || Object.hasOwn(row, "directory") && typeof row.directory !== "boolean" || Object.hasOwn(row, "ancestors") && typeof row.ancestors !== "boolean") fail("protocol", "invalid row");
|
|
18576
|
+
if (Object.hasOwn(row, "directory") || Object.hasOwn(row, "ancestors")) fail("unsupported", "glob row flags are unsupported");
|
|
18577
|
+
if (row.all) fail("unsupported", "all-match enumeration is unsupported");
|
|
18578
|
+
const length = byteLength.call(row.bytes);
|
|
18579
|
+
if (length > limits.maxInputBytes - bytes2) fail("limit", "aggregate input byte limit exceeded");
|
|
18580
|
+
bytes2 += length;
|
|
18581
|
+
}
|
|
18582
|
+
const ledger = new EreLedger({ maxExpansionBytes: 1048576, maxExpansionFields: 8192 }, {
|
|
18583
|
+
patternBytes: limits.maxPatternBytes + 4,
|
|
18584
|
+
subjectBytes: limits.maxInputBytes,
|
|
18585
|
+
work: limits.maxWork,
|
|
18586
|
+
allocationUnits: limits.maxAllocationUnits,
|
|
18587
|
+
states: limits.maxStates
|
|
18588
|
+
});
|
|
18589
|
+
ledger.charge("allocationUnits", bytes2 + input3.rows.length * 12 + selected.patterns.length * 2 + 16, signal);
|
|
18590
|
+
const patterns2 = [];
|
|
18591
|
+
for (let index = 0; index < selected.patterns.length; index++) patterns2.push(selected.patterns[index]);
|
|
18592
|
+
const ownedDescriptor = selected.kind === "grep" ? { kind: "grep", patterns: patterns2, fixed: selected.fixed, extended: selected.extended, insensitive: selected.insensitive, whole: selected.whole, word: selected.word } : { kind: "rg", patterns: patterns2, fixed: selected.fixed, case: selected.case, whole: selected.whole, word: selected.word, nullData: selected.nullData };
|
|
18593
|
+
const rows = [];
|
|
18594
|
+
for (let index = 0; index < input3.rows.length; index++) {
|
|
18595
|
+
const row = input3.rows[index];
|
|
18596
|
+
const source = new Uint8Array(byteBuffer.call(row.bytes), byteOffset.call(row.bytes), byteLength.call(row.bytes));
|
|
18597
|
+
const copy2 = new Uint8Array(source.length);
|
|
18598
|
+
copy2.set(source);
|
|
18599
|
+
rows.push({ bytes: copy2, all: false, terminated: row.terminated });
|
|
18600
|
+
}
|
|
18601
|
+
return { id: input3.id, descriptor: ownedDescriptor, rows, ledger };
|
|
18602
|
+
}
|
|
18603
|
+
async function admitBre(pattern, ledger, signal) {
|
|
18604
|
+
let bracket = -1;
|
|
18605
|
+
let member = false;
|
|
18606
|
+
let namedClass = false;
|
|
18607
|
+
for (let index = 0; index < pattern.length; index++) {
|
|
18608
|
+
ledger.charge("work", 1, signal);
|
|
18609
|
+
await ledger.checkpoint(signal);
|
|
18610
|
+
const character = pattern[index];
|
|
18611
|
+
if ("\\()+?{}|".includes(character)) fail("unsupported", "BRE escapes, groups and interval/operator extensions are unsupported; use grep -E");
|
|
18612
|
+
if (bracket >= 0) {
|
|
18613
|
+
if (index === bracket + 1 && character === "^") continue;
|
|
18614
|
+
if (namedClass) {
|
|
18615
|
+
if (character === "]" && pattern[index - 1] === ":") namedClass = false;
|
|
18616
|
+
} else if (character === "]" && member) bracket = -1;
|
|
18617
|
+
else if (character === "[" && pattern[index + 1] === ":") namedClass = true;
|
|
18618
|
+
member = true;
|
|
18619
|
+
} else if (character === "[") {
|
|
18620
|
+
bracket = index;
|
|
18621
|
+
member = false;
|
|
18622
|
+
} else if (character === "^" && index !== 0 || character === "$" && index !== pattern.length - 1) {
|
|
18623
|
+
fail("unsupported", "BRE anchors are supported only at record boundaries");
|
|
18624
|
+
} else if (character === "*" && (index === 0 || index === 1 && pattern[0] === "^")) {
|
|
18625
|
+
fail("unsupported", "BRE leading literal star is unsupported; use fixed matching");
|
|
18626
|
+
}
|
|
18627
|
+
}
|
|
18628
|
+
}
|
|
18629
|
+
async function execute2(input3, signal) {
|
|
18630
|
+
const { descriptor: selected, rows, ledger } = input3;
|
|
18631
|
+
const programs2 = [];
|
|
18632
|
+
for (const pattern of selected.patterns) {
|
|
18633
|
+
if (selected.kind === "grep" && !selected.fixed && !selected.extended) await admitBre(pattern, ledger, signal);
|
|
18634
|
+
if (selected.kind === "rg" && !selected.nullData && pattern.includes("\n")) fail("unsupported", "rg multiline matching is unsupported");
|
|
18635
|
+
ledger.charge("allocationUnits", (selected.whole ? 3 : 1) * 3 + 2, signal);
|
|
18636
|
+
const fragments = selected.whole ? [{ text: "^(", literal: false }, { text: pattern, literal: selected.fixed }, { text: ")$", literal: false }] : [{ text: pattern, literal: selected.fixed }];
|
|
18637
|
+
programs2.push(await compileEre(fragments, ledger, signal));
|
|
18638
|
+
}
|
|
18639
|
+
const results = [];
|
|
18640
|
+
for (const row of rows) {
|
|
18641
|
+
ledger.charge("allocationUnits", row.bytes.length * 2 + 2, signal);
|
|
18642
|
+
const characters = [];
|
|
18643
|
+
for (const byte of row.bytes) {
|
|
18644
|
+
ledger.charge("work", 1, signal);
|
|
18645
|
+
if (byte === 0 || byte > 127) fail("unsupported", "subjects require non-NUL ASCII; Unicode and invalid UTF-8 are unsupported");
|
|
18646
|
+
characters.push(String.fromCharCode(byte));
|
|
18647
|
+
await ledger.checkpoint(signal);
|
|
18648
|
+
}
|
|
18649
|
+
const subject = characters.join("");
|
|
18650
|
+
let span;
|
|
18651
|
+
for (const program of programs2) {
|
|
18652
|
+
const match = await matchEre(program, subject, ledger, signal);
|
|
18653
|
+
if (!match.matched) continue;
|
|
18654
|
+
const candidate = match.captures[0];
|
|
18655
|
+
if (selected.kind === "grep") {
|
|
18656
|
+
span = candidate;
|
|
18657
|
+
break;
|
|
18658
|
+
}
|
|
18659
|
+
if (!span || candidate.start < span.start) span = candidate;
|
|
18660
|
+
}
|
|
18661
|
+
signal.throwIfAborted();
|
|
18662
|
+
results.push(span ? new Float64Array([span.start, span.end]) : new Float64Array());
|
|
18663
|
+
}
|
|
18664
|
+
return { id: input3.id, results };
|
|
18665
|
+
}
|
|
18666
|
+
var CooperativeWorker = class {
|
|
18667
|
+
constructor(limits, release) {
|
|
18668
|
+
this.limits = limits;
|
|
18669
|
+
this.release = release;
|
|
18670
|
+
queueMicrotask(() => {
|
|
18671
|
+
if (!this.#closing) this.emit({ ready: true });
|
|
18672
|
+
});
|
|
18673
|
+
}
|
|
18674
|
+
limits;
|
|
18675
|
+
release;
|
|
18676
|
+
#controller = new AbortController();
|
|
18677
|
+
#listeners = /* @__PURE__ */ new Map();
|
|
18678
|
+
#tasks = /* @__PURE__ */ new Set();
|
|
18679
|
+
#busy = false;
|
|
18680
|
+
#closing;
|
|
18681
|
+
on(event, listener) {
|
|
18682
|
+
if (this.#closing) return;
|
|
18683
|
+
let listeners = this.#listeners.get(event);
|
|
18684
|
+
if (!listeners) {
|
|
18685
|
+
listeners = /* @__PURE__ */ new Set();
|
|
18686
|
+
this.#listeners.set(event, listeners);
|
|
18687
|
+
}
|
|
18688
|
+
listeners.add(listener);
|
|
18689
|
+
}
|
|
18690
|
+
off(event, listener) {
|
|
18691
|
+
this.#listeners.get(event)?.delete(listener);
|
|
18692
|
+
}
|
|
18693
|
+
emit(value2) {
|
|
18694
|
+
for (const listener of this.#listeners.get("message") ?? []) listener(value2);
|
|
18695
|
+
}
|
|
18696
|
+
postMessage(input3) {
|
|
18697
|
+
if (this.#closing) throw new Error("bounded regex worker is closed");
|
|
18698
|
+
if (this.#busy) throw new Error("bounded regex worker is busy");
|
|
18699
|
+
const identity = input3 !== null && typeof input3 === "object" ? Object.getOwnPropertyDescriptor(input3, "id") : void 0;
|
|
18700
|
+
if (!identity || !("value" in identity) || !Number.isSafeInteger(identity.value) || identity.value < 1) fail("protocol", "invalid request identity");
|
|
18701
|
+
const id = identity.value;
|
|
18702
|
+
const submitted = Object.getOwnPropertyDescriptor(input3, "descriptor")?.value;
|
|
18703
|
+
const expression = submitted !== null && typeof submitted === "object" && Object.getOwnPropertyDescriptor(submitted, "kind")?.value === "expr-match";
|
|
18704
|
+
let owned;
|
|
18705
|
+
let failure;
|
|
18706
|
+
try {
|
|
18707
|
+
owned = admit(input3, this.limits, this.#controller.signal);
|
|
18708
|
+
} catch (error) {
|
|
18709
|
+
failure = error instanceof Error ? error.message.slice(0, 512) : "bounded regex protocol: request admission failed";
|
|
18710
|
+
}
|
|
18711
|
+
this.#busy = true;
|
|
18712
|
+
const task = Promise.resolve().then(async () => {
|
|
18713
|
+
let reply;
|
|
18714
|
+
try {
|
|
18715
|
+
this.#controller.signal.throwIfAborted();
|
|
18716
|
+
reply = owned ? await execute2(owned, this.#controller.signal) : { id, error: failure };
|
|
18717
|
+
} catch (error) {
|
|
18718
|
+
reply = { id, error: error instanceof Error ? error.message.slice(0, 512) : "bounded regex request failed" };
|
|
18719
|
+
}
|
|
18720
|
+
if (expression && "error" in reply) reply = { id, operation: "expr-match", category: "unsupported", error: reply.error };
|
|
18721
|
+
owned = void 0;
|
|
18722
|
+
this.#busy = false;
|
|
18723
|
+
if (!this.#closing) this.emit(reply);
|
|
18724
|
+
});
|
|
18725
|
+
this.#tasks.add(task);
|
|
18726
|
+
void task.then(() => this.#tasks.delete(task), () => this.#tasks.delete(task));
|
|
18727
|
+
}
|
|
18728
|
+
terminate() {
|
|
18729
|
+
if (!this.#closing) {
|
|
18730
|
+
this.#closing = Promise.allSettled([...this.#tasks]).then(() => {
|
|
18731
|
+
this.#listeners.clear();
|
|
18732
|
+
this.#tasks.clear();
|
|
18733
|
+
this.release();
|
|
18734
|
+
});
|
|
18735
|
+
this.#controller.abort(new Error("bounded regex worker terminated"));
|
|
18736
|
+
}
|
|
18737
|
+
return this.#closing;
|
|
18738
|
+
}
|
|
18739
|
+
};
|
|
18740
|
+
function createBoundedRegexProvider(input3 = {}) {
|
|
18741
|
+
const limits = options2(input3);
|
|
18742
|
+
let active = 0;
|
|
18743
|
+
return Object.freeze({
|
|
18744
|
+
createWorker() {
|
|
18745
|
+
if (active >= limits.maxWorkers) fail("limit", "worker count limit exceeded");
|
|
18746
|
+
active++;
|
|
18747
|
+
return new CooperativeWorker(limits, () => {
|
|
18748
|
+
active--;
|
|
18749
|
+
});
|
|
18750
|
+
}
|
|
18751
|
+
});
|
|
18752
|
+
}
|
|
18753
|
+
|
|
18475
18754
|
// packages/safe-bash/src/browser.ts
|
|
18476
18755
|
function createBrowserCommands() {
|
|
18477
18756
|
return [
|
|
@@ -18482,17 +18761,17 @@ function createBrowserCommands() {
|
|
|
18482
18761
|
...textCommands()
|
|
18483
18762
|
];
|
|
18484
18763
|
}
|
|
18485
|
-
function browserCommands(
|
|
18764
|
+
function browserCommands(options3 = {}) {
|
|
18486
18765
|
return {
|
|
18487
18766
|
name: "browser-commands",
|
|
18488
18767
|
setup(host) {
|
|
18489
18768
|
const commands = createBrowserCommands();
|
|
18490
|
-
if (!
|
|
18769
|
+
if (!options3.replace) {
|
|
18491
18770
|
for (const command2 of commands) {
|
|
18492
18771
|
if (host.commands.has(command2.name)) throw new Error(`Command already registered: ${command2.name}`);
|
|
18493
18772
|
}
|
|
18494
18773
|
}
|
|
18495
|
-
for (const command2 of commands) host.commands.register(command2, { replace:
|
|
18774
|
+
for (const command2 of commands) host.commands.register(command2, { replace: options3.replace ?? false });
|
|
18496
18775
|
}
|
|
18497
18776
|
};
|
|
18498
18777
|
}
|
|
@@ -18523,6 +18802,7 @@ export {
|
|
|
18523
18802
|
collectText,
|
|
18524
18803
|
compileEre,
|
|
18525
18804
|
composeMiddleware,
|
|
18805
|
+
createBoundedRegexProvider,
|
|
18526
18806
|
createBrowserCommands,
|
|
18527
18807
|
createBytePipe,
|
|
18528
18808
|
createCommandArguments,
|