@poe-platform/safe-bash 0.1.756 → 0.1.758
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/image-ast/index.browser.js +76 -23
- package/dist/image-ast/index.js +76 -23
- package/dist/pdf-ast/ast.d.ts +3 -0
- package/dist/pdf-ast/index.js +88 -36
- package/dist/safe-bash/chunks/{chunk-LESPJ3OG.js → chunk-WNWIBBJZ.js} +15 -2
- package/dist/safe-bash/command-chunks/{chunk-S4J6MSLY.js → chunk-444OTXM7.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-F3J5ZLKF.js → chunk-522TDVLS.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-VFS2MDAB.js → chunk-6YLD37NH.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-YI3GKJ7Q.js → chunk-766IWMTB.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-6AIOGLZO.js → chunk-CE6Z2ULX.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-KSH2F6RG.js → chunk-CUFCNL6G.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-5VSGEE6J.js → chunk-F4IQCXZG.js} +5 -5
- package/dist/safe-bash/command-chunks/{chunk-F5MORDSU.js → chunk-FDNCPZQS.js} +32 -1
- package/dist/safe-bash/command-chunks/{chunk-SG3ZDZCX.js → chunk-FLMLM7Y4.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-DVZCHNB5.js → chunk-J2NPH7DO.js} +11 -7
- package/dist/safe-bash/command-chunks/{chunk-CT3FB722.js → chunk-J7UMKBRK.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-QQOAK7JQ.js → chunk-KKJCKPTA.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-7KS6PX4U.js → chunk-KSIGF4AG.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-KBBI4CSU.js → chunk-L2C5TIII.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-4HQ7WYSI.js → chunk-MED2BOOW.js} +30 -5
- package/dist/safe-bash/command-chunks/{chunk-JRNLDPLI.js → chunk-OZSWW23M.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-DKQ5REXF.js → chunk-QDPRSPHQ.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-WOPU2VWF.js → chunk-RID3B5RE.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-H2FQA4OU.js → chunk-TCAGGM44.js} +72 -19
- package/dist/safe-bash/command-chunks/{chunk-REYTQLLB.js → chunk-TT2DMDBY.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-UGX6MXDD.js → chunk-UIIT4ULR.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-A6NFLWZI.js → chunk-WKPOGTZY.js} +22 -6
- package/dist/safe-bash/command-chunks/{chunk-WI35236J.js → chunk-XYCWDGOG.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-3DOHQQJR.js → chunk-Y64PA6IA.js} +8 -8
- package/dist/safe-bash/command-chunks/{chunk-4F6PG2OT.js → chunk-YJWWRCIG.js} +8 -8
- package/dist/safe-bash/command-chunks/{chunk-6Z7OS3TZ.js → chunk-ZP5KDHB4.js} +7 -7
- package/dist/safe-bash/commands/pandoc/index.d.ts +1 -1
- package/dist/safe-bash/commands/pandoc/index.js +5 -3
- package/dist/safe-bash/commands/python/index.browser.js +1 -1
- package/dist/safe-bash/commands/python/index.js +6 -0
- package/dist/safe-bash/commands/python/jspi.js +11 -2
- package/dist/safe-bash/core.browser.js +6 -4
- package/dist/safe-bash-command-column/column.js +3 -3
- package/dist/safe-bash-command-column/index.js +3 -3
- package/dist/safe-bash-command-column/layout.js +2 -2
- package/dist/safe-bash-command-csvkit/index.js +8 -8
- package/dist/safe-bash-command-factor/command.js +2 -2
- package/dist/safe-bash-command-factor/index.js +2 -2
- package/dist/safe-bash-command-ffmpeg/index.js +5923 -5893
- package/dist/safe-bash-command-imagemagick/index.js +2 -2
- package/dist/safe-bash-command-pandoc/command.js +3 -3
- package/dist/safe-bash-command-pandoc/index.js +3 -3
- package/dist/safe-bash-command-pdfimages/index.js +72 -19
- package/dist/safe-bash-command-pdfinfo/index.js +88 -36
- package/dist/safe-bash-command-pdftk/index.js +72 -19
- package/dist/safe-bash-command-pdftoppm/index.js +88 -36
- package/dist/safe-bash-command-pdftotext/index.js +72 -19
- package/dist/safe-bash-command-qpdf/index.js +72 -19
- package/dist/safe-bash-command-sips/index.js +2 -2
- package/dist/safe-bash-command-soffice/index.js +17 -17
- package/dist/safe-bash-command-ssconvert/command-bindings.d.ts +18 -0
- package/dist/safe-bash-command-ssconvert/command.d.ts +5 -14
- package/dist/safe-bash-command-ssconvert/commands.d.ts +6 -0
- package/dist/safe-bash-command-ssconvert/commands.js +871 -0
- package/dist/safe-bash-command-ssconvert/core.js +8 -8
- package/dist/safe-bash-command-ssconvert/formats/csv.js +9 -9
- package/dist/safe-bash-command-ssconvert/formats/ods.js +8 -8
- package/dist/safe-bash-command-ssconvert/formats/spreadsheetml.js +1 -1
- package/dist/safe-bash-command-ssconvert/formats/xls.js +9 -8
- package/dist/safe-bash-command-ssconvert/formats/xlsx.js +8 -8
- package/dist/safe-bash-command-ssconvert/index.js +376 -236
- package/dist/safe-bash-command-wkhtmltopdf/index.js +72 -19
- package/dist/safe-bash-command-yq/index.js +4 -4
- package/dist/safe-bash-compression-engine/files.js +2 -2
- package/dist/safe-bash-compression-engine/operand.js +4 -4
- package/dist/safe-bash-contracts/filesystem-descriptor.js +1 -1
- package/dist/safe-bash-contracts/filesystem-output.js +1 -1
- package/dist/safe-bash-markdown-engine/commonmark-blocks.js +4 -4
- package/dist/safe-bash-markdown-engine/commonmark-inlines.js +4 -4
- package/dist/safe-bash-markdown-engine/commonmark-syntax.js +2 -2
- package/dist/safe-bash-markdown-engine/gfm-syntax.js +3 -3
- package/dist/safe-bash-markdown-engine/index.js +7 -7
- package/dist/safe-bash-mcp/index.js +4 -4
- package/dist/safe-bash-query-engine/index.js +5 -5
- package/dist/safe-bash-query-engine/interpreter.js +4 -4
- package/dist/safe-bash-query-engine/query-core.js +5 -5
- package/dist/spreadsheet-engine/formulas/ast.d.ts +13 -0
- package/dist/spreadsheet-engine/formulas/conventions.js +1 -1
- package/dist/spreadsheet-engine/formulas/dependencies.js +2 -2
- package/dist/spreadsheet-engine/formulas/evaluator.js +2 -2
- package/dist/spreadsheet-engine/formulas/named-expressions.d.ts +2 -2
- package/dist/spreadsheet-engine/formulas/named-expressions.js +31 -5
- package/dist/spreadsheet-engine/formulas/parser.js +34 -0
- package/dist/spreadsheet-engine/formulas/rewriting.js +19 -1
- package/dist/spreadsheet-engine/formulas/serialization.js +6 -0
- package/dist/spreadsheet-format-xls/biff-write-formulas.js +2 -0
- package/dist/xlsx-ast/formula-semantics.js +2 -0
- package/package.json +6 -2
- package/third-party/pdf-ast/THIRD_PARTY_NOTICES.md +16 -0
- package/dist/safe-bash/chunks/browser-ECQX6GMK.js +0 -6766
- package/dist/safe-bash/chunks/bz2-4OP3OWW3.js +0 -8
- package/dist/safe-bash/chunks/chunk-22XPAAOI.js +0 -173
- package/dist/safe-bash/chunks/chunk-44WUNUPV.js +0 -649
- package/dist/safe-bash/chunks/chunk-4E3SGG37.js +0 -876
- package/dist/safe-bash/chunks/chunk-4QTSSQKP.js +0 -898
- package/dist/safe-bash/chunks/chunk-5UVGPVXP.js +0 -410
- package/dist/safe-bash/chunks/chunk-64OE6Q6X.js +0 -3487
- package/dist/safe-bash/chunks/chunk-6IIFUPN2.js +0 -1526
- package/dist/safe-bash/chunks/chunk-BENDLTQD.js +0 -7065
- package/dist/safe-bash/chunks/chunk-BMO5LWEX.js +0 -534
- package/dist/safe-bash/chunks/chunk-BPMCPTNP.js +0 -1920
- package/dist/safe-bash/chunks/chunk-BRJTAWP5.js +0 -2955
- package/dist/safe-bash/chunks/chunk-C3GEIN7Q.js +0 -20054
- package/dist/safe-bash/chunks/chunk-CBVANNKK.js +0 -174814
- package/dist/safe-bash/chunks/chunk-CEWCRI6H.js +0 -2813
- package/dist/safe-bash/chunks/chunk-CGL53DQQ.js +0 -37
- package/dist/safe-bash/chunks/chunk-CTYJJD4O.js +0 -869
- package/dist/safe-bash/chunks/chunk-CWSS4MQA.js +0 -7
- package/dist/safe-bash/chunks/chunk-DLIGMTCP.js +0 -3266
- package/dist/safe-bash/chunks/chunk-EMAJ7WUW.js +0 -1031
- package/dist/safe-bash/chunks/chunk-FDKIZ2IJ.js +0 -1950
- package/dist/safe-bash/chunks/chunk-FZWJ2A7V.js +0 -3093
- package/dist/safe-bash/chunks/chunk-G2VCIF2J.js +0 -22
- package/dist/safe-bash/chunks/chunk-GVKBUQDX.js +0 -2649
- package/dist/safe-bash/chunks/chunk-IO2OGW3E.js +0 -28051
- package/dist/safe-bash/chunks/chunk-ISCZG7WA.js +0 -2648
- package/dist/safe-bash/chunks/chunk-JCN3FXLP.js +0 -38983
- package/dist/safe-bash/chunks/chunk-KJHDD4A2.js +0 -759
- package/dist/safe-bash/chunks/chunk-LB6HVRXS.js +0 -857
- package/dist/safe-bash/chunks/chunk-LLWAJOZH.js +0 -15
- package/dist/safe-bash/chunks/chunk-LMUKYZIJ.js +0 -708
- package/dist/safe-bash/chunks/chunk-M5SCNKIK.js +0 -2012
- package/dist/safe-bash/chunks/chunk-MJPFHANT.js +0 -3350
- package/dist/safe-bash/chunks/chunk-MZQW2DOL.js +0 -82
- package/dist/safe-bash/chunks/chunk-NB2V7EOY.js +0 -1348
- package/dist/safe-bash/chunks/chunk-NJVGOIYN.js +0 -17
- package/dist/safe-bash/chunks/chunk-OLNZHDIQ.js +0 -5141
- package/dist/safe-bash/chunks/chunk-OSUXMC43.js +0 -2317
- package/dist/safe-bash/chunks/chunk-OUUVROTM.js +0 -38
- package/dist/safe-bash/chunks/chunk-PA6GYKBQ.js +0 -151
- package/dist/safe-bash/chunks/chunk-PEFHZ226.js +0 -6957
- package/dist/safe-bash/chunks/chunk-QBB5P5KW.js +0 -4839
- package/dist/safe-bash/chunks/chunk-RSAWYAEH.js +0 -973
- package/dist/safe-bash/chunks/chunk-UWLYRWT4.js +0 -739
- package/dist/safe-bash/chunks/chunk-V463NBQH.js +0 -13
- package/dist/safe-bash/chunks/chunk-WPUALYUS.js +0 -843
- package/dist/safe-bash/chunks/chunk-XHKFSRGU.js +0 -5747
- package/dist/safe-bash/chunks/chunk-XHRCLZ3N.js +0 -13391
- package/dist/safe-bash/chunks/chunk-XPF5XHLY.js +0 -15
- package/dist/safe-bash/chunks/chunk-ZBFOWARG.js +0 -305
- package/dist/safe-bash/chunks/chunk-ZG7GWQ5P.js +0 -1859
- package/dist/safe-bash/chunks/model-store-EIY3ZQLZ.js +0 -10
- package/dist/safe-bash/chunks/pdf-renderer-CMF3CSVU.js +0 -22
- package/dist/safe-bash/chunks/pptx-ZL6L7KP2-O425BFIU.js +0 -30658
- package/dist/safe-bash/chunks/src-HHEPGR7U.js +0 -18969
- package/dist/safe-bash/chunks/src-MXIKQCIC.js +0 -187
- package/dist/safe-bash/chunks/usage-6TGVA2OM.js +0 -35
- package/dist/safe-bash/chunks/xz-EGQGQUEI.js +0 -8
- package/dist/safe-bash/chunks/xz-K2E2WLM6.js +0 -9
- package/dist/safe-bash/chunks/zstd-6JBLP5EF.js +0 -8
- package/dist/safe-bash/git_rust-C3QYOAZL.wasm +0 -0
- package/dist/safe-bash/command-chunks/{chunk-OQVIJMBY.js → chunk-7HINP7ZK.js} +4 -4
- package/dist/safe-bash/command-chunks/{chunk-XAYEDOV5.js → chunk-CG4JSOK2.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-YIK4ZYQ4.js → chunk-DC52GWRK.js} +9 -9
- package/dist/safe-bash/command-chunks/{chunk-TOTZFBDT.js → chunk-TKACIO4X.js} +4 -4
- package/dist/safe-bash/command-chunks/{chunk-VTWKS4RM.js → chunk-WF2LSKMI.js} +3 -3
|
@@ -1,1348 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
escaping_exports
|
|
3
|
-
} from "./chunk-NJVGOIYN.js";
|
|
4
|
-
import {
|
|
5
|
-
contracts_exports
|
|
6
|
-
} from "./chunk-MZQW2DOL.js";
|
|
7
|
-
import {
|
|
8
|
-
yield_exports
|
|
9
|
-
} from "./chunk-XPF5XHLY.js";
|
|
10
|
-
import {
|
|
11
|
-
dirname,
|
|
12
|
-
posixPath,
|
|
13
|
-
resolvePath
|
|
14
|
-
} from "./chunk-OUUVROTM.js";
|
|
15
|
-
import {
|
|
16
|
-
UsageError,
|
|
17
|
-
path_exports
|
|
18
|
-
} from "./chunk-ISCZG7WA.js";
|
|
19
|
-
import {
|
|
20
|
-
__reExport,
|
|
21
|
-
import_buffer,
|
|
22
|
-
init_platform,
|
|
23
|
-
setImmediate
|
|
24
|
-
} from "./chunk-ZG7GWQ5P.js";
|
|
25
|
-
|
|
26
|
-
// packages/safe-bash/src/commands/node/browser.ts
|
|
27
|
-
init_platform();
|
|
28
|
-
|
|
29
|
-
// packages/safe-bash/src/commands/node/safejs.ts
|
|
30
|
-
init_platform();
|
|
31
|
-
|
|
32
|
-
// packages/safe-bash/src/integrations/safejs/values.ts
|
|
33
|
-
init_platform();
|
|
34
|
-
function record(value, name) {
|
|
35
|
-
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
36
|
-
throw new TypeError(`${name} must be a plain object`);
|
|
37
|
-
}
|
|
38
|
-
const prototype = Object.getPrototypeOf(value);
|
|
39
|
-
if (prototype !== Object.prototype && prototype !== null) {
|
|
40
|
-
throw new TypeError(`${name} must be a plain object`);
|
|
41
|
-
}
|
|
42
|
-
const result = {};
|
|
43
|
-
for (const key of Reflect.ownKeys(value)) {
|
|
44
|
-
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
45
|
-
if (typeof key !== "string" || descriptor === void 0 || !("value" in descriptor)) {
|
|
46
|
-
throw new TypeError(`${name} must contain only string-keyed data properties`);
|
|
47
|
-
}
|
|
48
|
-
Object.defineProperty(result, key, {
|
|
49
|
-
value: descriptor.value,
|
|
50
|
-
enumerable: true,
|
|
51
|
-
configurable: true,
|
|
52
|
-
writable: true
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
return result;
|
|
56
|
-
}
|
|
57
|
-
function onlyKeys(value, allowed) {
|
|
58
|
-
for (const key of Object.keys(value)) {
|
|
59
|
-
if (!allowed.includes(key)) throw new TypeError(`Unsupported option: ${key}`);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
function stringValue(value, name) {
|
|
63
|
-
if (typeof value !== "string") throw new TypeError(`${name} must be a string`);
|
|
64
|
-
return value;
|
|
65
|
-
}
|
|
66
|
-
function abortError() {
|
|
67
|
-
return Object.assign(new Error("The operation was aborted"), {
|
|
68
|
-
name: "AbortError",
|
|
69
|
-
code: "ABORT_ERR"
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
function checkSignal(signal) {
|
|
73
|
-
if (signal?.aborted) throw abortError();
|
|
74
|
-
}
|
|
75
|
-
async function withSignal(signal, operation) {
|
|
76
|
-
checkSignal(signal);
|
|
77
|
-
if (signal === void 0) return operation();
|
|
78
|
-
let onAbort = () => void 0;
|
|
79
|
-
const cancelled = new Promise((_resolve, reject) => {
|
|
80
|
-
onAbort = () => reject(abortError());
|
|
81
|
-
signal.addEventListener("abort", onAbort, { once: true });
|
|
82
|
-
});
|
|
83
|
-
try {
|
|
84
|
-
return await Promise.race([Promise.resolve().then(() => {
|
|
85
|
-
checkSignal(signal);
|
|
86
|
-
return operation();
|
|
87
|
-
}), cancelled]);
|
|
88
|
-
} finally {
|
|
89
|
-
signal.removeEventListener("abort", onAbort);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// packages/safe-bash/src/commands/node/buffer.ts
|
|
94
|
-
init_platform();
|
|
95
|
-
|
|
96
|
-
// packages/safe-bash/src/commands/safejs/options.ts
|
|
97
|
-
init_platform();
|
|
98
|
-
var defaultSafeJsLimits = Object.freeze({});
|
|
99
|
-
var unlimitedLimits = Object.freeze({
|
|
100
|
-
maxSourceBytes: Infinity,
|
|
101
|
-
maxInputBytes: Infinity,
|
|
102
|
-
maxOutputBytes: Infinity,
|
|
103
|
-
timeoutMs: Infinity,
|
|
104
|
-
maxSteps: Infinity,
|
|
105
|
-
maxCallDepth: Infinity,
|
|
106
|
-
stringLength: Infinity,
|
|
107
|
-
arrayLength: Infinity,
|
|
108
|
-
dataSize: Infinity
|
|
109
|
-
});
|
|
110
|
-
function commandLimits(options = {}) {
|
|
111
|
-
for (const [name, value] of Object.entries(options)) {
|
|
112
|
-
if (!Object.hasOwn(unlimitedLimits, name)) throw new TypeError(`Unknown SafeJS limit: ${name}`);
|
|
113
|
-
if (value !== Infinity && (!Number.isSafeInteger(value) || value < (name === "timeoutMs" ? 1 : 0))) throw new RangeError(`Invalid SafeJS limit: ${name}`);
|
|
114
|
-
}
|
|
115
|
-
return Object.freeze({ ...unlimitedLimits, ...options });
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// packages/safe-bash/src/commands/node/buffer.ts
|
|
119
|
-
var bufferSource = `
|
|
120
|
-
class Buffer extends Uint8Array {
|
|
121
|
-
static from(value, encodingOrOffset, length) {
|
|
122
|
-
if (typeof value === "string") return new Buffer(__safeBashBuffer.encode(value, encodingOrOffset));
|
|
123
|
-
if (value instanceof ArrayBuffer) return new Buffer(value, encodingOrOffset, length);
|
|
124
|
-
if (Array.isArray(value) || value instanceof Uint8Array) return new Buffer(value);
|
|
125
|
-
if (value && value.type === "Buffer" && Array.isArray(value.data)) return new Buffer(value.data);
|
|
126
|
-
throw new TypeError("Buffer.from requires a string, byte array or ArrayBuffer");
|
|
127
|
-
}
|
|
128
|
-
static alloc(size, fill = 0, encoding) {
|
|
129
|
-
if (typeof size !== "number") throw new TypeError("Buffer size must be a number");
|
|
130
|
-
if (!Number.isFinite(size) || size < 0) throw new RangeError("Invalid Buffer size");
|
|
131
|
-
const result = new Buffer(size);
|
|
132
|
-
if (fill === "") return result;
|
|
133
|
-
if (typeof fill === "string" || fill instanceof Uint8Array) {
|
|
134
|
-
const pattern = Buffer.from(fill, encoding);
|
|
135
|
-
if (pattern.length === 0 && size > 0) throw new TypeError("Invalid Buffer fill");
|
|
136
|
-
for (let i = 0; i < result.length; i++) result[i] = pattern[i % pattern.length];
|
|
137
|
-
} else result.fill(fill);
|
|
138
|
-
return result;
|
|
139
|
-
}
|
|
140
|
-
static isBuffer(value) { return value instanceof Buffer; }
|
|
141
|
-
static isEncoding = __safeBashBuffer.isEncoding;
|
|
142
|
-
static byteLength(value, encoding) {
|
|
143
|
-
if (typeof value === "string") return __safeBashBuffer.byteLength(value, encoding);
|
|
144
|
-
if (value instanceof ArrayBuffer || ArrayBuffer.isView(value)) return value.byteLength;
|
|
145
|
-
throw new TypeError("Buffer.byteLength requires a string, ArrayBuffer or view");
|
|
146
|
-
}
|
|
147
|
-
static concat(list, totalLength) {
|
|
148
|
-
if (!Array.isArray(list) || !list.every(value => value instanceof Uint8Array)) throw new TypeError("Buffer.concat requires byte arrays");
|
|
149
|
-
if (totalLength === undefined) totalLength = list.reduce((size, value) => size + value.length, 0);
|
|
150
|
-
if (typeof totalLength !== "number") throw new TypeError("Buffer length must be a number");
|
|
151
|
-
if (!Number.isInteger(totalLength) || totalLength < 0) throw new RangeError("Invalid Buffer length");
|
|
152
|
-
const result = Buffer.alloc(totalLength);
|
|
153
|
-
let offset = 0;
|
|
154
|
-
for (const value of list) {
|
|
155
|
-
const count = Math.min(value.length, result.length - offset);
|
|
156
|
-
if (count <= 0) break;
|
|
157
|
-
result.set(value.subarray(0, count), offset);
|
|
158
|
-
offset += count;
|
|
159
|
-
}
|
|
160
|
-
return result;
|
|
161
|
-
}
|
|
162
|
-
toString(encoding, start = 0, end = this.length) {
|
|
163
|
-
start = Math.min(this.length, Math.max(0, Math.trunc(start) || 0));
|
|
164
|
-
end = Math.min(this.length, Math.max(0, Math.trunc(end) || 0));
|
|
165
|
-
return __safeBashBuffer.decode(Array.from(super.subarray(start, Math.max(start, end))), encoding);
|
|
166
|
-
}
|
|
167
|
-
subarray(start, end) {
|
|
168
|
-
const view = super.subarray(start, end);
|
|
169
|
-
return new Buffer(view.buffer, view.byteOffset, view.byteLength);
|
|
170
|
-
}
|
|
171
|
-
equals(other) {
|
|
172
|
-
if (!(other instanceof Uint8Array)) throw new TypeError("Buffer.equals requires a byte array");
|
|
173
|
-
return this.length === other.length && this.every((value, index) => value === other[index]);
|
|
174
|
-
}
|
|
175
|
-
toJSON() { return { type: "Buffer", data: Array.from(this) }; }
|
|
176
|
-
}
|
|
177
|
-
Buffer.prototype.slice = Buffer.prototype.subarray;
|
|
178
|
-
`;
|
|
179
|
-
function bufferBindings(options) {
|
|
180
|
-
const limits = commandLimits(options.limits);
|
|
181
|
-
const declare = options.runtime.declareHostOperation;
|
|
182
|
-
const exceeded = (resource) => {
|
|
183
|
-
throw Object.assign(new RangeError(`Buffer ${resource} limit exceeded`), { code: "budgetExceeded" });
|
|
184
|
-
};
|
|
185
|
-
const encoding = (value) => {
|
|
186
|
-
if (value === void 0 || value === "") return "utf8";
|
|
187
|
-
if (typeof value !== "string" || !import_buffer.Buffer.isEncoding(value)) throw new TypeError("Unknown Buffer encoding");
|
|
188
|
-
return value;
|
|
189
|
-
};
|
|
190
|
-
return {
|
|
191
|
-
encode: declare((value, selected) => {
|
|
192
|
-
if (typeof value !== "string") throw new TypeError("Buffer input must be a string");
|
|
193
|
-
const codec = encoding(selected);
|
|
194
|
-
if (import_buffer.Buffer.byteLength(value, codec) > limits.arrayLength) exceeded("arrayLength");
|
|
195
|
-
return Array.from(import_buffer.Buffer.from(value, codec));
|
|
196
|
-
}, "read-side-effect"),
|
|
197
|
-
decode: declare((value, selected) => {
|
|
198
|
-
if (!Array.isArray(value)) throw new TypeError("Buffer bytes must be an array");
|
|
199
|
-
if (value.length > limits.arrayLength) exceeded("arrayLength");
|
|
200
|
-
if (!value.every((byte) => typeof byte === "number" && Number.isInteger(byte) && byte >= 0 && byte <= 255)) throw new TypeError("Invalid Buffer byte");
|
|
201
|
-
const result = import_buffer.Buffer.from(value).toString(encoding(selected));
|
|
202
|
-
if (result.length > limits.stringLength) exceeded("stringLength");
|
|
203
|
-
return result;
|
|
204
|
-
}, "read-side-effect"),
|
|
205
|
-
isEncoding: declare((value) => typeof value === "string" && import_buffer.Buffer.isEncoding(value), "read-side-effect"),
|
|
206
|
-
byteLength: declare((value, selected) => {
|
|
207
|
-
if (typeof value !== "string") throw new TypeError("Buffer input must be a string");
|
|
208
|
-
return import_buffer.Buffer.byteLength(value, typeof selected === "string" && import_buffer.Buffer.isEncoding(selected) ? selected : "utf8");
|
|
209
|
-
}, "read-side-effect")
|
|
210
|
-
};
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
// packages/safe-bash/src/commands/node/timers.ts
|
|
214
|
-
init_platform();
|
|
215
|
-
|
|
216
|
-
// packages/safe-bash/src/commands/safejs/types.ts
|
|
217
|
-
init_platform();
|
|
218
|
-
var SafeJsCommandLimitError = class extends Error {
|
|
219
|
-
constructor(resource) {
|
|
220
|
-
super(`SafeJS command limit exceeded: ${resource}`);
|
|
221
|
-
this.resource = resource;
|
|
222
|
-
this.name = "SafeJsCommandLimitError";
|
|
223
|
-
}
|
|
224
|
-
resource;
|
|
225
|
-
code = "SAFEJS_LIMIT";
|
|
226
|
-
};
|
|
227
|
-
|
|
228
|
-
// packages/safe-bash/src/commands/node/timers.ts
|
|
229
|
-
var timerSource = `
|
|
230
|
-
function setTimeout(callback, delay, ...args) {
|
|
231
|
-
if (typeof callback !== "function") throw new TypeError("setTimeout callback must be a function");
|
|
232
|
-
let milliseconds = Number(delay);
|
|
233
|
-
if (!Number.isFinite(milliseconds) || milliseconds < 1 || milliseconds > 2147483647) milliseconds = 1;
|
|
234
|
-
return __safeBashTimers.schedule(() => callback(...args), Math.trunc(milliseconds));
|
|
235
|
-
}
|
|
236
|
-
function clearTimeout(timer) { __safeBashTimers.clear(timer); }
|
|
237
|
-
`;
|
|
238
|
-
function timerBindings(options, signal, fail, pending) {
|
|
239
|
-
const declare = options.runtime.declareHostOperation;
|
|
240
|
-
const limits = commandLimits(options.limits);
|
|
241
|
-
const timers = /* @__PURE__ */ new Map();
|
|
242
|
-
let nextId = 0;
|
|
243
|
-
const clear = (id) => {
|
|
244
|
-
if (typeof id !== "number") return;
|
|
245
|
-
const timer = timers.get(id);
|
|
246
|
-
if (!timer) return;
|
|
247
|
-
clearTimeout(timer.handle);
|
|
248
|
-
timers.delete(id);
|
|
249
|
-
timer.complete();
|
|
250
|
-
};
|
|
251
|
-
signal.addEventListener("abort", () => {
|
|
252
|
-
for (const id of timers.keys()) clear(id);
|
|
253
|
-
}, { once: true });
|
|
254
|
-
return {
|
|
255
|
-
schedule: declare((callback, delay) => {
|
|
256
|
-
signal.throwIfAborted();
|
|
257
|
-
if (typeof callback !== "function" || typeof delay !== "number" || !Number.isInteger(delay) || delay < 1 || delay > 2147483647) throw new TypeError("Invalid timer");
|
|
258
|
-
if (pending.size >= limits.arrayLength) {
|
|
259
|
-
const error = new SafeJsCommandLimitError("arrayLength");
|
|
260
|
-
fail(error);
|
|
261
|
-
throw error;
|
|
262
|
-
}
|
|
263
|
-
const id = ++nextId;
|
|
264
|
-
let complete;
|
|
265
|
-
const completion = new Promise((resolve) => {
|
|
266
|
-
complete = () => {
|
|
267
|
-
pending.delete(completion);
|
|
268
|
-
resolve();
|
|
269
|
-
};
|
|
270
|
-
});
|
|
271
|
-
pending.add(completion);
|
|
272
|
-
const handle = setTimeout(() => {
|
|
273
|
-
timers.delete(id);
|
|
274
|
-
if (signal.aborted) {
|
|
275
|
-
complete();
|
|
276
|
-
return;
|
|
277
|
-
}
|
|
278
|
-
void Promise.resolve().then(() => callback()).catch(fail).finally(complete);
|
|
279
|
-
}, delay);
|
|
280
|
-
timers.set(id, { handle, complete });
|
|
281
|
-
return id;
|
|
282
|
-
}, "read-side-effect"),
|
|
283
|
-
clear: declare(clear, "read-side-effect"),
|
|
284
|
-
drain: declare(async () => {
|
|
285
|
-
while (pending.size > 0) {
|
|
286
|
-
signal.throwIfAborted();
|
|
287
|
-
await Promise.all(pending);
|
|
288
|
-
}
|
|
289
|
-
signal.throwIfAborted();
|
|
290
|
-
}, "read-side-effect")
|
|
291
|
-
};
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
// packages/safe-bash/src/commands/node/preload.ts
|
|
295
|
-
init_platform();
|
|
296
|
-
var nodeRequireSource = `
|
|
297
|
-
const __safeBashModuleCache = new Map();
|
|
298
|
-
const __safeBashMakeRequire = base => name => {
|
|
299
|
-
const path = __safeBashModulePath(base, name);
|
|
300
|
-
if (path === null) return __safeBashRequire(name);
|
|
301
|
-
if (__safeBashModuleCache.has(path)) return __safeBashModuleCache.get(path).exports;
|
|
302
|
-
let source;
|
|
303
|
-
try { source = __safeBashModuleRead(path); }
|
|
304
|
-
catch (error) {
|
|
305
|
-
if (error.code !== "ENOENT") throw error;
|
|
306
|
-
const missing = new Error("Cannot find module '" + name + "'");
|
|
307
|
-
missing.code = "MODULE_NOT_FOUND";
|
|
308
|
-
throw missing;
|
|
309
|
-
}
|
|
310
|
-
if (source.startsWith("\\uFEFF")) source = source.slice(1);
|
|
311
|
-
const module = { exports: {} };
|
|
312
|
-
if (path.endsWith(".json")) {
|
|
313
|
-
module.exports = JSON.parse(source);
|
|
314
|
-
__safeBashModuleCache.set(path, module);
|
|
315
|
-
return module.exports;
|
|
316
|
-
}
|
|
317
|
-
if (source.startsWith("#!")) {
|
|
318
|
-
const newline = source.indexOf("\\n");
|
|
319
|
-
source = newline < 0 ? "" : source.slice(newline);
|
|
320
|
-
}
|
|
321
|
-
__safeBashModuleCache.set(path, module);
|
|
322
|
-
try {
|
|
323
|
-
const directory = path.slice(0, path.lastIndexOf("/")) || "/";
|
|
324
|
-
(function(exports, require, module, __filename, __dirname) {
|
|
325
|
-
eval(source);
|
|
326
|
-
}).call(module.exports, module.exports, __safeBashMakeRequire(directory), module, path, directory);
|
|
327
|
-
} catch (error) {
|
|
328
|
-
__safeBashModuleCache.delete(path);
|
|
329
|
-
throw error;
|
|
330
|
-
}
|
|
331
|
-
return module.exports;
|
|
332
|
-
};
|
|
333
|
-
const require = __safeBashMakeRequire(__safeBashEntryDirectory);
|
|
334
|
-
for (const name of __safeBashPreloads) __safeBashMakeRequire(__safeBashCwd)(name);
|
|
335
|
-
`;
|
|
336
|
-
|
|
337
|
-
// packages/safe-bash/src/commands/node/source-maps.ts
|
|
338
|
-
init_platform();
|
|
339
|
-
var alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
340
|
-
function decodeMap(value, base, limits) {
|
|
341
|
-
if (!value || typeof value !== "object") throw new Error("invalid source map");
|
|
342
|
-
const map = value;
|
|
343
|
-
if (map.version !== 3 || !Array.isArray(map.sources) || !map.sources.every((source2) => typeof source2 === "string") || typeof map.mappings !== "string" || map.sourceRoot !== void 0 && typeof map.sourceRoot !== "string") throw new Error("invalid source map");
|
|
344
|
-
const sources = map.sources;
|
|
345
|
-
const root = map.sourceRoot;
|
|
346
|
-
const lines = [];
|
|
347
|
-
const filenames = /* @__PURE__ */ new Map();
|
|
348
|
-
let entries = 0;
|
|
349
|
-
let dataBytes = 0;
|
|
350
|
-
const admit = (bytes = 128) => {
|
|
351
|
-
if (++entries > limits.arrayLength) throw new SafeJsCommandLimitError("arrayLength");
|
|
352
|
-
if (bytes > limits.dataSize - dataBytes) throw new SafeJsCommandLimitError("dataSize");
|
|
353
|
-
dataBytes += bytes;
|
|
354
|
-
};
|
|
355
|
-
let source = 0;
|
|
356
|
-
let originalLine = 0;
|
|
357
|
-
let originalColumn = 0;
|
|
358
|
-
let name = 0;
|
|
359
|
-
for (const encodedLine of pieces(map.mappings, ";")) {
|
|
360
|
-
admit();
|
|
361
|
-
const line = [];
|
|
362
|
-
let column = 0;
|
|
363
|
-
for (const encoded of pieces(encodedLine, ",")) {
|
|
364
|
-
if (!encoded) continue;
|
|
365
|
-
admit();
|
|
366
|
-
const fields = [];
|
|
367
|
-
let number = 0;
|
|
368
|
-
let shift = 0;
|
|
369
|
-
for (const character of encoded) {
|
|
370
|
-
const digit = alphabet.indexOf(character);
|
|
371
|
-
if (digit < 0 || shift > 50) throw new Error("invalid source map VLQ");
|
|
372
|
-
number += (digit & 31) * 2 ** shift;
|
|
373
|
-
if (digit & 32) shift += 5;
|
|
374
|
-
else {
|
|
375
|
-
fields.push(number % 2 ? -Math.floor(number / 2) : Math.floor(number / 2));
|
|
376
|
-
if (fields.length > 5) throw new Error("invalid source map segment");
|
|
377
|
-
number = 0;
|
|
378
|
-
shift = 0;
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
if (shift || ![1, 4, 5].includes(fields.length)) throw new Error("invalid source map segment");
|
|
382
|
-
column += fields[0];
|
|
383
|
-
if (!Number.isSafeInteger(column) || column < 0 || line.length && column < line[line.length - 1].column) throw new Error("invalid source map column");
|
|
384
|
-
if (fields.length === 1) {
|
|
385
|
-
line.push({ column });
|
|
386
|
-
continue;
|
|
387
|
-
}
|
|
388
|
-
source += fields[1];
|
|
389
|
-
originalLine += fields[2];
|
|
390
|
-
originalColumn += fields[3];
|
|
391
|
-
if (fields.length === 5) {
|
|
392
|
-
name += fields[4];
|
|
393
|
-
if (!Array.isArray(map.names) || name < 0 || name >= map.names.length) throw new Error("invalid source map name");
|
|
394
|
-
}
|
|
395
|
-
if (!Number.isSafeInteger(source) || source < 0 || source >= sources.length || !Number.isSafeInteger(originalLine) || originalLine < 0 || !Number.isSafeInteger(originalColumn) || originalColumn < 0) throw new Error("invalid source map position");
|
|
396
|
-
let filename = filenames.get(source);
|
|
397
|
-
if (filename === void 0) {
|
|
398
|
-
const path = sources[source];
|
|
399
|
-
const length = base.length + (root?.length ?? 0) + path.length + 1;
|
|
400
|
-
if (length > limits.stringLength) throw new SafeJsCommandLimitError("stringLength");
|
|
401
|
-
admit(128 + length * 2);
|
|
402
|
-
const rooted = (root ?? "") + path;
|
|
403
|
-
filename = rooted.includes(":") ? rooted : resolvePath(base, rooted);
|
|
404
|
-
filenames.set(source, filename);
|
|
405
|
-
}
|
|
406
|
-
line.push({ column, location: { filename, line: originalLine + 1, column: originalColumn + 1 } });
|
|
407
|
-
}
|
|
408
|
-
lines.push(line);
|
|
409
|
-
}
|
|
410
|
-
return lines;
|
|
411
|
-
}
|
|
412
|
-
function* pieces(text, delimiter) {
|
|
413
|
-
let start = 0;
|
|
414
|
-
for (; ; ) {
|
|
415
|
-
const end = text.indexOf(delimiter, start);
|
|
416
|
-
yield text.slice(start, end < 0 ? text.length : end);
|
|
417
|
-
if (end < 0) return;
|
|
418
|
-
start = end + 1;
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
function mapReference(source) {
|
|
422
|
-
let reference;
|
|
423
|
-
for (let index = 0; index < source.length; index++) {
|
|
424
|
-
const character = source[index];
|
|
425
|
-
if (character === '"' || character === "'" || character === "`") {
|
|
426
|
-
const quote = character;
|
|
427
|
-
while (++index < source.length) {
|
|
428
|
-
if (source[index] === "\\") index++;
|
|
429
|
-
else if (source[index] === quote) break;
|
|
430
|
-
}
|
|
431
|
-
continue;
|
|
432
|
-
}
|
|
433
|
-
if (character !== "/") continue;
|
|
434
|
-
if (!["/", "*"].includes(source[index + 1])) {
|
|
435
|
-
let previous = index - 1;
|
|
436
|
-
while (previous >= 0 && source[previous].trim() === "") previous--;
|
|
437
|
-
const before = source[previous];
|
|
438
|
-
let wordStart = previous;
|
|
439
|
-
while (wordStart >= 0 && "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".includes(source[wordStart])) wordStart--;
|
|
440
|
-
const word = source.slice(wordStart + 1, previous + 1);
|
|
441
|
-
if (before !== void 0 && !"=(:,[!&|?;{}".includes(before) && !["return", "throw", "case", "yield", "await"].includes(word)) continue;
|
|
442
|
-
let bracket = false;
|
|
443
|
-
while (++index < source.length) {
|
|
444
|
-
if (source[index] === "\\") index++;
|
|
445
|
-
else if (source[index] === "[") bracket = true;
|
|
446
|
-
else if (source[index] === "]") bracket = false;
|
|
447
|
-
else if (source[index] === "/" && !bracket) break;
|
|
448
|
-
}
|
|
449
|
-
continue;
|
|
450
|
-
}
|
|
451
|
-
const block = source[index + 1] === "*";
|
|
452
|
-
const start = index + 2;
|
|
453
|
-
const end = source.indexOf(block ? "*/" : "\n", start);
|
|
454
|
-
const body = source.slice(start, end < 0 ? source.length : end).trim();
|
|
455
|
-
if (body.startsWith("#") || body.startsWith("@")) {
|
|
456
|
-
const directive = body.slice(1).trim();
|
|
457
|
-
if (directive.startsWith("sourceMappingURL=")) reference = directive.slice(17).trim();
|
|
458
|
-
}
|
|
459
|
-
index = end < 0 ? source.length : end + (block ? 1 : 0);
|
|
460
|
-
}
|
|
461
|
-
return reference;
|
|
462
|
-
}
|
|
463
|
-
async function nodeSourceLocation(source, filename, cwd, prefix, readSource, signal, limits) {
|
|
464
|
-
const offset = prefix.split("\n").length - 1;
|
|
465
|
-
const base = filename.startsWith("<") || filename === "-" ? cwd : dirname(filename);
|
|
466
|
-
let lines;
|
|
467
|
-
const reference = mapReference(source);
|
|
468
|
-
if (reference) {
|
|
469
|
-
try {
|
|
470
|
-
let json;
|
|
471
|
-
let mapBase = base;
|
|
472
|
-
if (reference.startsWith("data:")) {
|
|
473
|
-
const comma = reference.indexOf(",");
|
|
474
|
-
if (comma < 0) throw new Error("invalid source map data URI");
|
|
475
|
-
const header = reference.slice(0, comma);
|
|
476
|
-
const payload = reference.slice(comma + 1);
|
|
477
|
-
json = header.endsWith(";base64") ? import_buffer.Buffer.from(payload, "base64").toString("utf8") : decodeURIComponent(payload);
|
|
478
|
-
} else {
|
|
479
|
-
if (reference.includes(":") || reference.startsWith("//")) throw new Error("unsupported source map URL");
|
|
480
|
-
const path = resolvePath(base, decodeURIComponent(reference));
|
|
481
|
-
mapBase = dirname(path);
|
|
482
|
-
json = await readSource(path);
|
|
483
|
-
}
|
|
484
|
-
signal.throwIfAborted();
|
|
485
|
-
lines = decodeMap(JSON.parse(json), mapBase, limits);
|
|
486
|
-
} catch (error) {
|
|
487
|
-
signal.throwIfAborted();
|
|
488
|
-
if (error instanceof SafeJsCommandLimitError) throw error;
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
return (position) => {
|
|
492
|
-
const line = position.line - offset;
|
|
493
|
-
if (line < 1) return void 0;
|
|
494
|
-
const segments = lines?.[line - 1];
|
|
495
|
-
let low = 0;
|
|
496
|
-
let high = segments?.length ?? 0;
|
|
497
|
-
while (low < high) {
|
|
498
|
-
const middle = Math.floor((low + high) / 2);
|
|
499
|
-
if (segments[middle].column <= position.column - 1) low = middle + 1;
|
|
500
|
-
else high = middle;
|
|
501
|
-
}
|
|
502
|
-
return (low ? segments[low - 1].location : void 0) ?? { filename, line, column: position.column };
|
|
503
|
-
};
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
// packages/safe-bash/src/commands/node/filesystem.ts
|
|
507
|
-
init_platform();
|
|
508
|
-
function nodeReadFile(options, fs, signal, fail, pending) {
|
|
509
|
-
const read = fs.readFile;
|
|
510
|
-
const limits = commandLimits(options.limits);
|
|
511
|
-
return options.runtime.declareHostOperation((path, encoding, callback) => {
|
|
512
|
-
signal.throwIfAborted();
|
|
513
|
-
if (callback === void 0 && typeof encoding !== "function") return read(path, encoding);
|
|
514
|
-
if (typeof encoding === "function") {
|
|
515
|
-
callback = encoding;
|
|
516
|
-
encoding = void 0;
|
|
517
|
-
}
|
|
518
|
-
if (typeof callback !== "function") throw new TypeError("readFile callback must be a function");
|
|
519
|
-
if (pending.size >= limits.arrayLength) {
|
|
520
|
-
const error = new SafeJsCommandLimitError("arrayLength");
|
|
521
|
-
fail(error);
|
|
522
|
-
throw error;
|
|
523
|
-
}
|
|
524
|
-
const done = callback;
|
|
525
|
-
const completion = Promise.resolve().then(() => read(path, encoding)).then(
|
|
526
|
-
async (text) => {
|
|
527
|
-
await new Promise((resolve) => setImmediate(resolve));
|
|
528
|
-
signal.throwIfAborted();
|
|
529
|
-
return done(null, text);
|
|
530
|
-
},
|
|
531
|
-
async (error) => {
|
|
532
|
-
await new Promise((resolve) => setImmediate(resolve));
|
|
533
|
-
signal.throwIfAborted();
|
|
534
|
-
return done(error);
|
|
535
|
-
}
|
|
536
|
-
).then(() => void 0).catch(fail).finally(() => pending.delete(completion));
|
|
537
|
-
pending.add(completion);
|
|
538
|
-
return void 0;
|
|
539
|
-
}, "read-side-effect", { callbackScheduling: "after-prefix" });
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
// packages/safe-bash/src/commands/node/path.ts
|
|
543
|
-
init_platform();
|
|
544
|
-
function createNodePathModule(runtime, cwd) {
|
|
545
|
-
const resolve = (...paths) => {
|
|
546
|
-
for (const path2 of paths) if (typeof path2 !== "string") throw new TypeError("path must be a string");
|
|
547
|
-
let joined = "";
|
|
548
|
-
for (let index = paths.length - 1; index >= -1; index--) {
|
|
549
|
-
const path2 = index < 0 ? cwd : paths[index];
|
|
550
|
-
if (!path2) continue;
|
|
551
|
-
joined = `${path2}/${joined}`;
|
|
552
|
-
if (path2.startsWith("/")) break;
|
|
553
|
-
}
|
|
554
|
-
const normalized = posixPath.join(joined);
|
|
555
|
-
return normalized.length > 1 && normalized.endsWith("/") ? normalized.slice(0, -1) : normalized;
|
|
556
|
-
};
|
|
557
|
-
const path = {
|
|
558
|
-
...Object.fromEntries(Object.entries(posixPath).map(([name, operation]) => [name, runtime.declareHostOperation(operation, "read-side-effect")])),
|
|
559
|
-
normalize: runtime.declareHostOperation((value) => {
|
|
560
|
-
if (typeof value !== "string") throw new TypeError("path must be a string");
|
|
561
|
-
return posixPath.join(value);
|
|
562
|
-
}, "read-side-effect"),
|
|
563
|
-
resolve: runtime.declareHostOperation(resolve, "read-side-effect"),
|
|
564
|
-
relative: runtime.declareHostOperation((from, to) => {
|
|
565
|
-
const source = resolve(from).split("/").filter(Boolean);
|
|
566
|
-
const target = resolve(to).split("/").filter(Boolean);
|
|
567
|
-
let common = 0;
|
|
568
|
-
while (common < source.length && common < target.length && source[common] === target[common]) common++;
|
|
569
|
-
return [...Array(source.length - common).fill(".."), ...target.slice(common)].join("/");
|
|
570
|
-
}, "read-side-effect"),
|
|
571
|
-
sep: "/",
|
|
572
|
-
delimiter: ":"
|
|
573
|
-
};
|
|
574
|
-
return { ...path, posix: path };
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
// packages/safe-bash/src/commands/safejs/runtime.ts
|
|
578
|
-
init_platform();
|
|
579
|
-
|
|
580
|
-
// packages/safe-bash/src/diagnostics.ts
|
|
581
|
-
var diagnostics_exports = {};
|
|
582
|
-
init_platform();
|
|
583
|
-
__reExport(diagnostics_exports, diagnostics_star);
|
|
584
|
-
import * as diagnostics_star from "../../safe-bash-contracts/diagnostics.js";
|
|
585
|
-
|
|
586
|
-
// packages/safe-bash/src/integrations/safejs/filesystem.ts
|
|
587
|
-
init_platform();
|
|
588
|
-
function makeSafeJsFsModule(makeFsModule, fs, options = {}) {
|
|
589
|
-
return makeFsModule({ adapter: fs, ...options });
|
|
590
|
-
}
|
|
591
|
-
|
|
592
|
-
// packages/safe-bash/src/commands/safejs/io.ts
|
|
593
|
-
init_platform();
|
|
594
|
-
|
|
595
|
-
// packages/safe-bash/src/commands/safejs/render.ts
|
|
596
|
-
init_platform();
|
|
597
|
-
var Text = class {
|
|
598
|
-
constructor(limit, fail) {
|
|
599
|
-
this.limit = limit;
|
|
600
|
-
this.fail = fail;
|
|
601
|
-
}
|
|
602
|
-
limit;
|
|
603
|
-
fail;
|
|
604
|
-
parts = [];
|
|
605
|
-
size = 0;
|
|
606
|
-
active = /* @__PURE__ */ new Set();
|
|
607
|
-
append(value) {
|
|
608
|
-
if (import_buffer.Buffer.byteLength(value) > this.limit - this.size) {
|
|
609
|
-
const error = new SafeJsCommandLimitError("maxOutputBytes");
|
|
610
|
-
this.fail(error);
|
|
611
|
-
throw error;
|
|
612
|
-
}
|
|
613
|
-
this.size += import_buffer.Buffer.byteLength(value);
|
|
614
|
-
this.parts.push(value);
|
|
615
|
-
}
|
|
616
|
-
quoted(value) {
|
|
617
|
-
if (import_buffer.Buffer.byteLength(value) + 2 > this.limit - this.size) {
|
|
618
|
-
const error = new SafeJsCommandLimitError("maxOutputBytes");
|
|
619
|
-
this.fail(error);
|
|
620
|
-
throw error;
|
|
621
|
-
}
|
|
622
|
-
this.append(JSON.stringify(value));
|
|
623
|
-
}
|
|
624
|
-
json(value, depth = 0) {
|
|
625
|
-
if (value === null || value === void 0) {
|
|
626
|
-
this.append("null");
|
|
627
|
-
return;
|
|
628
|
-
}
|
|
629
|
-
if (typeof value === "string") {
|
|
630
|
-
this.quoted(value);
|
|
631
|
-
return;
|
|
632
|
-
}
|
|
633
|
-
if (typeof value === "boolean" || typeof value === "number") {
|
|
634
|
-
this.append(JSON.stringify(value));
|
|
635
|
-
return;
|
|
636
|
-
}
|
|
637
|
-
if (typeof value !== "object" || this.active.has(value)) throw new TypeError("output requires acyclic JSON data");
|
|
638
|
-
this.active.add(value);
|
|
639
|
-
try {
|
|
640
|
-
if (Array.isArray(value)) {
|
|
641
|
-
this.append("[");
|
|
642
|
-
for (let index = 0; index < value.length; index++) {
|
|
643
|
-
if (index) this.append(",");
|
|
644
|
-
const property = Object.getOwnPropertyDescriptor(value, String(index));
|
|
645
|
-
if (property && !("value" in property)) throw new TypeError("output arrays must contain data properties");
|
|
646
|
-
this.json(property?.value, depth + 1);
|
|
647
|
-
}
|
|
648
|
-
this.append("]");
|
|
649
|
-
} else {
|
|
650
|
-
const entries = record(value, "output value");
|
|
651
|
-
this.append("{");
|
|
652
|
-
let first = true;
|
|
653
|
-
for (const [key, item] of Object.entries(entries)) {
|
|
654
|
-
if (item === void 0) continue;
|
|
655
|
-
if (!first) this.append(",");
|
|
656
|
-
first = false;
|
|
657
|
-
this.quoted(key);
|
|
658
|
-
this.append(":");
|
|
659
|
-
this.json(item, depth + 1);
|
|
660
|
-
}
|
|
661
|
-
this.append("}");
|
|
662
|
-
}
|
|
663
|
-
} finally {
|
|
664
|
-
this.active.delete(value);
|
|
665
|
-
}
|
|
666
|
-
}
|
|
667
|
-
finish() {
|
|
668
|
-
return this.parts.join("");
|
|
669
|
-
}
|
|
670
|
-
};
|
|
671
|
-
function renderOutput(values, limit, fail) {
|
|
672
|
-
const text = new Text(limit, fail);
|
|
673
|
-
for (let index = 0; index < values.length; index++) {
|
|
674
|
-
if (index) text.append(" ");
|
|
675
|
-
const value = values[index];
|
|
676
|
-
if (typeof value === "string") text.append(value);
|
|
677
|
-
else if (value === void 0) text.append("undefined");
|
|
678
|
-
else text.json(value);
|
|
679
|
-
}
|
|
680
|
-
text.append("\n");
|
|
681
|
-
return text.finish();
|
|
682
|
-
}
|
|
683
|
-
|
|
684
|
-
// packages/safe-bash/src/commands/safejs/io.ts
|
|
685
|
-
var chunkSize = 64 * 1024;
|
|
686
|
-
var GuestInput = class {
|
|
687
|
-
constructor(source, limit, signal, fail, resource = "maxInputBytes") {
|
|
688
|
-
this.limit = limit;
|
|
689
|
-
this.signal = signal;
|
|
690
|
-
this.fail = fail;
|
|
691
|
-
this.resource = resource;
|
|
692
|
-
this.iterator = (0, contracts_exports.readBytes)(source, signal);
|
|
693
|
-
}
|
|
694
|
-
limit;
|
|
695
|
-
signal;
|
|
696
|
-
fail;
|
|
697
|
-
resource;
|
|
698
|
-
iterator;
|
|
699
|
-
pending = new Uint8Array();
|
|
700
|
-
consumed = 0;
|
|
701
|
-
pulls = 0;
|
|
702
|
-
queue = Promise.resolve();
|
|
703
|
-
async take(size) {
|
|
704
|
-
this.signal.throwIfAborted();
|
|
705
|
-
while (!this.pending.length) {
|
|
706
|
-
if (++this.pulls % 64 === 0) await (0, yield_exports.yieldTurn)(this.signal);
|
|
707
|
-
const next = await this.iterator.next();
|
|
708
|
-
if (next.done) return void 0;
|
|
709
|
-
this.pending = next.value;
|
|
710
|
-
}
|
|
711
|
-
const length = Math.min(size, this.pending.length);
|
|
712
|
-
if (length > this.limit - this.consumed) {
|
|
713
|
-
const error = new SafeJsCommandLimitError(this.resource);
|
|
714
|
-
this.fail(error);
|
|
715
|
-
throw error;
|
|
716
|
-
}
|
|
717
|
-
const bytes = this.pending.slice(0, length);
|
|
718
|
-
this.pending = this.pending.subarray(length);
|
|
719
|
-
this.consumed += length;
|
|
720
|
-
return bytes;
|
|
721
|
-
}
|
|
722
|
-
serialize(operation) {
|
|
723
|
-
const result = this.queue.then(operation);
|
|
724
|
-
this.queue = result.then(() => {
|
|
725
|
-
}, () => {
|
|
726
|
-
});
|
|
727
|
-
return result;
|
|
728
|
-
}
|
|
729
|
-
readBytes(size = chunkSize) {
|
|
730
|
-
if (typeof size !== "number" || !Number.isSafeInteger(size) || size < 1 || size > chunkSize) throw new TypeError("readBytes size must be an integer from 1 through 65536");
|
|
731
|
-
return this.serialize(async () => {
|
|
732
|
-
const bytes = await this.take(size);
|
|
733
|
-
return bytes === void 0 ? null : Array.from(bytes);
|
|
734
|
-
});
|
|
735
|
-
}
|
|
736
|
-
readText() {
|
|
737
|
-
return this.serialize(async () => {
|
|
738
|
-
const pieces2 = [];
|
|
739
|
-
for (; ; ) {
|
|
740
|
-
const chunk = await this.take(chunkSize);
|
|
741
|
-
if (!chunk) break;
|
|
742
|
-
pieces2.push(chunk);
|
|
743
|
-
}
|
|
744
|
-
return new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(import_buffer.Buffer.concat(pieces2));
|
|
745
|
-
});
|
|
746
|
-
}
|
|
747
|
-
async close() {
|
|
748
|
-
await this.iterator.return(void 0);
|
|
749
|
-
}
|
|
750
|
-
};
|
|
751
|
-
var GuestOutput = class {
|
|
752
|
-
constructor(stdout, stderr, limit, signal, fail) {
|
|
753
|
-
this.stdout = stdout;
|
|
754
|
-
this.stderr = stderr;
|
|
755
|
-
this.limit = limit;
|
|
756
|
-
this.signal = signal;
|
|
757
|
-
this.fail = fail;
|
|
758
|
-
}
|
|
759
|
-
stdout;
|
|
760
|
-
stderr;
|
|
761
|
-
limit;
|
|
762
|
-
signal;
|
|
763
|
-
fail;
|
|
764
|
-
queue = Promise.resolve();
|
|
765
|
-
produced = 0;
|
|
766
|
-
stderrFailed = false;
|
|
767
|
-
enqueue(bytes, target) {
|
|
768
|
-
this.signal.throwIfAborted();
|
|
769
|
-
if (bytes.length > this.limit - this.produced) {
|
|
770
|
-
const error = new SafeJsCommandLimitError("maxOutputBytes");
|
|
771
|
-
this.fail(error);
|
|
772
|
-
throw error;
|
|
773
|
-
}
|
|
774
|
-
this.produced += bytes.length;
|
|
775
|
-
const queued = this.queue.then(async () => {
|
|
776
|
-
for (let offset = 0; offset < bytes.length; offset += chunkSize) await (0, contracts_exports.writeBytes)(target, bytes.subarray(offset, offset + chunkSize), this.signal);
|
|
777
|
-
}).catch((error) => {
|
|
778
|
-
if (target === this.stderr) this.stderrFailed = true;
|
|
779
|
-
this.fail(error);
|
|
780
|
-
throw error;
|
|
781
|
-
});
|
|
782
|
-
this.queue = queued;
|
|
783
|
-
void queued.catch(() => {
|
|
784
|
-
});
|
|
785
|
-
return queued;
|
|
786
|
-
}
|
|
787
|
-
text(value, stderr = false) {
|
|
788
|
-
if (typeof value !== "string") throw new TypeError("stdio text output requires a string");
|
|
789
|
-
if (import_buffer.Buffer.byteLength(value) > this.limit - this.produced) {
|
|
790
|
-
const error = new SafeJsCommandLimitError("maxOutputBytes");
|
|
791
|
-
this.fail(error);
|
|
792
|
-
throw error;
|
|
793
|
-
}
|
|
794
|
-
return this.enqueue(import_buffer.Buffer.from(value), stderr ? this.stderr : this.stdout);
|
|
795
|
-
}
|
|
796
|
-
bytes(value, stderr = false) {
|
|
797
|
-
if (!Array.isArray(value) || value.length > chunkSize) throw new TypeError("stdio byte output requires an array of at most 65536 bytes");
|
|
798
|
-
for (const byte of value) if (!Number.isInteger(byte) || byte < 0 || byte > 255) throw new TypeError("stdio byte values must be integers from 0 through 255");
|
|
799
|
-
return this.enqueue(Uint8Array.from(value), stderr ? this.stderr : this.stdout);
|
|
800
|
-
}
|
|
801
|
-
console(args, stderr) {
|
|
802
|
-
void this.text(renderOutput(args, this.limit - this.produced, this.fail), stderr);
|
|
803
|
-
}
|
|
804
|
-
result(value) {
|
|
805
|
-
return this.text(renderOutput([value], this.limit - this.produced, this.fail));
|
|
806
|
-
}
|
|
807
|
-
async drain() {
|
|
808
|
-
await this.queue;
|
|
809
|
-
}
|
|
810
|
-
};
|
|
811
|
-
|
|
812
|
-
// packages/safe-bash/src/commands/safejs/runtime.ts
|
|
813
|
-
var GuestDiagnostic = class extends diagnostics_exports.PublicDiagnostic {
|
|
814
|
-
constructor(info) {
|
|
815
|
-
super(info.message);
|
|
816
|
-
this.info = info;
|
|
817
|
-
}
|
|
818
|
-
info;
|
|
819
|
-
};
|
|
820
|
-
function errorInfo(error) {
|
|
821
|
-
if (typeof error === "string") return { name: "Error", code: "", message: error };
|
|
822
|
-
if (typeof error !== "object" || error === null) return { name: "Error", code: "", message: "SafeJS execution failed" };
|
|
823
|
-
const field = (name) => {
|
|
824
|
-
const descriptor = Object.getOwnPropertyDescriptor(error, name);
|
|
825
|
-
return descriptor && "value" in descriptor && typeof descriptor.value === "string" ? descriptor.value : "";
|
|
826
|
-
};
|
|
827
|
-
return { name: field("name"), code: field("code"), message: field("message") || "SafeJS execution failed" };
|
|
828
|
-
}
|
|
829
|
-
function statusField(error, name) {
|
|
830
|
-
if (typeof error !== "object" || error === null) return "";
|
|
831
|
-
const descriptor = Object.getOwnPropertyDescriptor(error, name);
|
|
832
|
-
return descriptor && "value" in descriptor && typeof descriptor.value === "string" ? descriptor.value : "";
|
|
833
|
-
}
|
|
834
|
-
function validateRuntime(runtime) {
|
|
835
|
-
if (runtime === void 0) return;
|
|
836
|
-
if (runtime.parseSourceModule !== void 0 && typeof runtime.parseSourceModule !== "function") throw new TypeError("SafeJS runtime.parseSourceModule must be a function");
|
|
837
|
-
for (const key of ["run", "createBudget", "makeFsModule", "declareHostOperation"]) {
|
|
838
|
-
if (typeof runtime[key] !== "function") throw new TypeError(`SafeJS runtime.${key} must be injected`);
|
|
839
|
-
}
|
|
840
|
-
}
|
|
841
|
-
function createSafeJsCommands(options, dialect) {
|
|
842
|
-
const limits = commandLimits(options.limits);
|
|
843
|
-
const runtime = options.runtime;
|
|
844
|
-
validateRuntime(runtime);
|
|
845
|
-
return [{ name: dialect.name, description: dialect.description, async execute(context) {
|
|
846
|
-
const deadline = Date.now() + limits.timeoutMs;
|
|
847
|
-
const schedule = (callback, end) => {
|
|
848
|
-
let timer;
|
|
849
|
-
const tick = () => {
|
|
850
|
-
const remaining = end - Date.now();
|
|
851
|
-
if (remaining <= 0) callback();
|
|
852
|
-
else timer = setTimeout(tick, Math.min(2147483647, remaining));
|
|
853
|
-
};
|
|
854
|
-
if (Number.isFinite(end)) tick();
|
|
855
|
-
return () => {
|
|
856
|
-
if (timer !== void 0) clearTimeout(timer);
|
|
857
|
-
};
|
|
858
|
-
};
|
|
859
|
-
const diagnose = async (message) => {
|
|
860
|
-
const diagnostic = new AbortController();
|
|
861
|
-
const end = Math.max(Date.now() + 1, deadline);
|
|
862
|
-
const pending = (0, escaping_exports.writeDiagnostic)(context.stderr, `${dialect.name}: ${message}
|
|
863
|
-
`, AbortSignal.any([context.signal, diagnostic.signal]));
|
|
864
|
-
const cancel = schedule(() => diagnostic.abort(), end);
|
|
865
|
-
try {
|
|
866
|
-
await pending;
|
|
867
|
-
} catch (error) {
|
|
868
|
-
context.signal.throwIfAborted();
|
|
869
|
-
if (!diagnostic.signal.aborted) throw error;
|
|
870
|
-
} finally {
|
|
871
|
-
cancel();
|
|
872
|
-
}
|
|
873
|
-
};
|
|
874
|
-
let parsed;
|
|
875
|
-
try {
|
|
876
|
-
parsed = dialect.invocation(context.args);
|
|
877
|
-
} catch (error) {
|
|
878
|
-
await diagnose((0, diagnostics_exports.publicDiagnosticMessage)(error, context.onInternalError));
|
|
879
|
-
return { exitCode: 2 };
|
|
880
|
-
}
|
|
881
|
-
context.signal.throwIfAborted();
|
|
882
|
-
if (parsed.output !== void 0) {
|
|
883
|
-
if (import_buffer.Buffer.byteLength(parsed.output) > limits.maxOutputBytes) {
|
|
884
|
-
await diagnose("SafeJS command limit exceeded: maxOutputBytes");
|
|
885
|
-
return { exitCode: 124 };
|
|
886
|
-
}
|
|
887
|
-
await (0, contracts_exports.writeBytes)(context.stdout, import_buffer.Buffer.from(parsed.output), context.signal);
|
|
888
|
-
return { exitCode: 0 };
|
|
889
|
-
}
|
|
890
|
-
if (parsed.help) {
|
|
891
|
-
await (0, contracts_exports.writeBytes)(context.stdout, import_buffer.Buffer.from(dialect.help), context.signal);
|
|
892
|
-
return { exitCode: 0 };
|
|
893
|
-
}
|
|
894
|
-
if (!runtime) {
|
|
895
|
-
await diagnose("runtime not installed; inject run, createBudget, makeFsModule and declareHostOperation");
|
|
896
|
-
return { exitCode: 127 };
|
|
897
|
-
}
|
|
898
|
-
const controller = new AbortController();
|
|
899
|
-
const signal = AbortSignal.any([context.signal, controller.signal]);
|
|
900
|
-
let failure;
|
|
901
|
-
let hasFailure = false;
|
|
902
|
-
const fail = (error) => {
|
|
903
|
-
if (!hasFailure && !controller.signal.aborted) {
|
|
904
|
-
hasFailure = true;
|
|
905
|
-
failure = error;
|
|
906
|
-
queueMicrotask(() => controller.abort(error));
|
|
907
|
-
}
|
|
908
|
-
};
|
|
909
|
-
const cancelTimeout = schedule(() => fail(new SafeJsCommandLimitError("timeoutMs")), deadline);
|
|
910
|
-
let input;
|
|
911
|
-
const output = new GuestOutput(context.stdout, context.stderr, limits.maxOutputBytes, signal, fail);
|
|
912
|
-
let exitCode = 0;
|
|
913
|
-
let thrown;
|
|
914
|
-
let failed = false;
|
|
915
|
-
try {
|
|
916
|
-
const fromStdin = parsed.source === void 0 && parsed.file === "-";
|
|
917
|
-
let source = parsed.source;
|
|
918
|
-
let filename = parsed.file;
|
|
919
|
-
if (source === void 0) {
|
|
920
|
-
if (!fromStdin) filename = (0, path_exports.pathOf)(context, parsed.file);
|
|
921
|
-
const capabilities = fromStdin ? void 0 : await withSignal(signal, async () => await context.fs.capabilitiesFor?.(filename, { signal }) ?? context.fs.capabilities);
|
|
922
|
-
const bytes = fromStdin ? context.stdin : context.fs.readStream && capabilities?.streamingRead !== false ? context.fs.readStream(filename, { signal, chunkSize: 65536 }) : (0, contracts_exports.toByteSource)(await withSignal(signal, () => context.fs.readFile(filename, { signal, ...Number.isFinite(limits.maxSourceBytes) ? { maxBytes: limits.maxSourceBytes } : {} })));
|
|
923
|
-
const reader = new GuestInput(bytes, limits.maxSourceBytes, signal, fail, "maxSourceBytes");
|
|
924
|
-
try {
|
|
925
|
-
source = await reader.readText();
|
|
926
|
-
} finally {
|
|
927
|
-
await reader.close();
|
|
928
|
-
}
|
|
929
|
-
} else if (import_buffer.Buffer.byteLength(source) > limits.maxSourceBytes) throw new SafeJsCommandLimitError("maxSourceBytes");
|
|
930
|
-
const sourceBytes = import_buffer.Buffer.byteLength(source);
|
|
931
|
-
if (source.startsWith("\uFEFF")) source = source.slice(1);
|
|
932
|
-
source = dialect.transformSource?.(source, { ...parsed, file: filename }) ?? source;
|
|
933
|
-
if (parsed.check) {
|
|
934
|
-
const parse = runtime.parseSourceModule;
|
|
935
|
-
if (!parse) throw new UsageError("syntax checking requires an injected runtime.parseSourceModule");
|
|
936
|
-
try {
|
|
937
|
-
await withSignal(signal, async () => {
|
|
938
|
-
await parse(source, filename);
|
|
939
|
-
});
|
|
940
|
-
} catch (error) {
|
|
941
|
-
if (error instanceof SafeJsCommandLimitError || statusField(error, "code") === "budgetExceeded" || signal.aborted) throw error;
|
|
942
|
-
throw new GuestDiagnostic(errorInfo(error));
|
|
943
|
-
}
|
|
944
|
-
signal.throwIfAborted();
|
|
945
|
-
if (Date.now() >= deadline) throw new SafeJsCommandLimitError("timeoutMs");
|
|
946
|
-
} else {
|
|
947
|
-
input = new GuestInput(fromStdin ? (0, contracts_exports.toByteSource)("") : context.stdin, limits.maxInputBytes, signal, fail);
|
|
948
|
-
const guestInput = input;
|
|
949
|
-
const declare = runtime.declareHostOperation;
|
|
950
|
-
const stdio = {
|
|
951
|
-
readBytes: declare(async (size) => guestInput.readBytes(size), "read-side-effect"),
|
|
952
|
-
readText: declare(async () => guestInput.readText(), "read-side-effect"),
|
|
953
|
-
write: declare(async (text) => output.text(text), "read-side-effect"),
|
|
954
|
-
writeBytes: declare(async (bytes) => output.bytes(bytes), "read-side-effect"),
|
|
955
|
-
error: declare(async (text) => output.text(text, true), "read-side-effect"),
|
|
956
|
-
errorBytes: declare(async (bytes) => output.bytes(bytes, true), "read-side-effect")
|
|
957
|
-
};
|
|
958
|
-
const env = /* @__PURE__ */ Object.create(null);
|
|
959
|
-
for (const [key, value] of Object.entries(context.env)) env[key] = value;
|
|
960
|
-
const command = {
|
|
961
|
-
args: [...parsed.args],
|
|
962
|
-
cwd: context.cwd,
|
|
963
|
-
env,
|
|
964
|
-
setExitCode: declare((value) => {
|
|
965
|
-
signal.throwIfAborted();
|
|
966
|
-
if (typeof value !== "number" || !Number.isInteger(value) || value < 0 || value > 255) throw new TypeError("exit code must be an integer from 0 through 255");
|
|
967
|
-
exitCode = value;
|
|
968
|
-
}, "read-side-effect")
|
|
969
|
-
};
|
|
970
|
-
const budgetOptions = {};
|
|
971
|
-
for (const name of ["maxSteps", "maxCallDepth", "stringLength", "arrayLength", "dataSize"]) {
|
|
972
|
-
if (Number.isFinite(limits[name])) budgetOptions[name] = limits[name];
|
|
973
|
-
}
|
|
974
|
-
if (Number.isFinite(deadline)) budgetOptions.deadline = deadline;
|
|
975
|
-
const budget = runtime.createBudget(budgetOptions);
|
|
976
|
-
const modules = { fs: makeSafeJsFsModule(runtime.makeFsModule, context.fs, { cwd: context.cwd, signal }), stdio, command };
|
|
977
|
-
const prepared = await dialect.prepare?.(source, { ...parsed, file: filename }, modules, {
|
|
978
|
-
signal,
|
|
979
|
-
fail,
|
|
980
|
-
sourceBytes,
|
|
981
|
-
async readSource(path, maxBytes = limits.maxSourceBytes) {
|
|
982
|
-
const capabilities = await withSignal(signal, async () => await context.fs.capabilitiesFor?.(path, { signal }) ?? context.fs.capabilities);
|
|
983
|
-
const reader = new GuestInput(
|
|
984
|
-
context.fs.readStream && capabilities?.streamingRead !== false ? context.fs.readStream(path, { signal, chunkSize: 65536 }) : (0, contracts_exports.toByteSource)(await withSignal(signal, () => context.fs.readFile(path, { signal, ...Number.isFinite(maxBytes) ? { maxBytes } : {} }))),
|
|
985
|
-
maxBytes,
|
|
986
|
-
signal,
|
|
987
|
-
fail,
|
|
988
|
-
"maxSourceBytes"
|
|
989
|
-
);
|
|
990
|
-
try {
|
|
991
|
-
return await reader.readText();
|
|
992
|
-
} finally {
|
|
993
|
-
await reader.close();
|
|
994
|
-
}
|
|
995
|
-
}
|
|
996
|
-
});
|
|
997
|
-
const result = record(await withSignal(signal, () => runtime.run(prepared?.source ?? source, {
|
|
998
|
-
...parsed.nodeOptions?.length ? { nodeOptions: parsed.nodeOptions } : {},
|
|
999
|
-
budget,
|
|
1000
|
-
filename,
|
|
1001
|
-
modules,
|
|
1002
|
-
signal,
|
|
1003
|
-
...prepared ? {
|
|
1004
|
-
bindings: prepared.bindings,
|
|
1005
|
-
...prepared.sourceLocation ? { sourceLocation: prepared.sourceLocation } : {},
|
|
1006
|
-
...prepared.importSpecifiers ? { importSpecifiers: prepared.importSpecifiers } : {}
|
|
1007
|
-
} : {},
|
|
1008
|
-
sink: { log: (...args) => output.console(args, false), error: (...args) => output.console(args, true) }
|
|
1009
|
-
})), "SafeJS run result");
|
|
1010
|
-
signal.throwIfAborted();
|
|
1011
|
-
if (result.ok !== true && result.ok !== false) throw new TypeError("Invalid SafeJS run result.ok");
|
|
1012
|
-
if (!result.ok) {
|
|
1013
|
-
const info = errorInfo(result.error);
|
|
1014
|
-
throw new GuestDiagnostic(info);
|
|
1015
|
-
}
|
|
1016
|
-
if (parsed.print && result.returnValue !== void 0) await output.result(result.returnValue);
|
|
1017
|
-
await output.drain();
|
|
1018
|
-
}
|
|
1019
|
-
} catch (error) {
|
|
1020
|
-
thrown = hasFailure ? failure : error;
|
|
1021
|
-
failed = true;
|
|
1022
|
-
} finally {
|
|
1023
|
-
try {
|
|
1024
|
-
await output.drain();
|
|
1025
|
-
} catch (error) {
|
|
1026
|
-
thrown = hasFailure ? failure : error;
|
|
1027
|
-
failed = true;
|
|
1028
|
-
}
|
|
1029
|
-
controller.abort();
|
|
1030
|
-
cancelTimeout();
|
|
1031
|
-
await input?.close().catch(() => {
|
|
1032
|
-
});
|
|
1033
|
-
}
|
|
1034
|
-
context.signal.throwIfAborted();
|
|
1035
|
-
if (failed) {
|
|
1036
|
-
const info = thrown instanceof GuestDiagnostic ? thrown.info : { name: statusField(thrown, "name"), code: statusField(thrown, "code") };
|
|
1037
|
-
const detail = thrown instanceof SafeJsCommandLimitError ? thrown.message : (0, diagnostics_exports.publicDiagnosticMessage)(thrown, context.onInternalError);
|
|
1038
|
-
if (!output.stderrFailed) await diagnose(detail);
|
|
1039
|
-
return { exitCode: thrown instanceof SafeJsCommandLimitError || info.code === "budgetExceeded" ? 124 : thrown instanceof UsageError || !parsed.check && info.name === "ParseError" ? 2 : 1 };
|
|
1040
|
-
}
|
|
1041
|
-
return { exitCode };
|
|
1042
|
-
} }];
|
|
1043
|
-
}
|
|
1044
|
-
|
|
1045
|
-
// packages/safe-bash/src/commands/node/environment.ts
|
|
1046
|
-
init_platform();
|
|
1047
|
-
async function nodeEnvironment(files, inherited, cwd, read, signal, remainingBytes) {
|
|
1048
|
-
const values = /* @__PURE__ */ Object.create(null);
|
|
1049
|
-
for (const file of files) {
|
|
1050
|
-
let source;
|
|
1051
|
-
try {
|
|
1052
|
-
source = await read(resolvePath(cwd, file.path), remainingBytes);
|
|
1053
|
-
} catch (error) {
|
|
1054
|
-
signal.throwIfAborted();
|
|
1055
|
-
if (file.optional && typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT") continue;
|
|
1056
|
-
throw error;
|
|
1057
|
-
}
|
|
1058
|
-
remainingBytes -= import_buffer.Buffer.byteLength(source);
|
|
1059
|
-
if (remainingBytes < 0) throw new SafeJsCommandLimitError("maxSourceBytes");
|
|
1060
|
-
let index = 0;
|
|
1061
|
-
const nextLine = () => {
|
|
1062
|
-
while (index < source.length && source[index] !== "\n") index++;
|
|
1063
|
-
index++;
|
|
1064
|
-
};
|
|
1065
|
-
while (index < source.length) {
|
|
1066
|
-
while (" \r\n".includes(source[index] ?? "\0")) index++;
|
|
1067
|
-
if (source[index] === "#") {
|
|
1068
|
-
nextLine();
|
|
1069
|
-
continue;
|
|
1070
|
-
}
|
|
1071
|
-
if (source.startsWith("export ", index)) index += 7;
|
|
1072
|
-
const start = index;
|
|
1073
|
-
while (index < source.length && "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_".includes(source[index])) index++;
|
|
1074
|
-
const name = source.slice(start, index);
|
|
1075
|
-
while (source[index] === " " || source[index] === " ") index++;
|
|
1076
|
-
if (!name || "0123456789".includes(name[0]) || source[index] !== "=") {
|
|
1077
|
-
nextLine();
|
|
1078
|
-
continue;
|
|
1079
|
-
}
|
|
1080
|
-
index++;
|
|
1081
|
-
while (source[index] === " " || source[index] === " ") index++;
|
|
1082
|
-
const quote = source[index];
|
|
1083
|
-
let value = "";
|
|
1084
|
-
if (quote === '"' || quote === "'" || quote === "`") {
|
|
1085
|
-
index++;
|
|
1086
|
-
while (index < source.length && source[index] !== quote) {
|
|
1087
|
-
if (quote === '"' && source[index] === "\\" && source[index + 1] === "n") {
|
|
1088
|
-
value += "\n";
|
|
1089
|
-
index += 2;
|
|
1090
|
-
} else value += source[index++];
|
|
1091
|
-
}
|
|
1092
|
-
index++;
|
|
1093
|
-
} else {
|
|
1094
|
-
while (index < source.length && source[index] !== "\n" && source[index] !== "#") value += source[index++];
|
|
1095
|
-
value = value.trim();
|
|
1096
|
-
}
|
|
1097
|
-
values[name] = value;
|
|
1098
|
-
nextLine();
|
|
1099
|
-
}
|
|
1100
|
-
}
|
|
1101
|
-
return Object.assign(values, inherited);
|
|
1102
|
-
}
|
|
1103
|
-
|
|
1104
|
-
// packages/safe-bash/src/commands/node/safejs.ts
|
|
1105
|
-
function createSafeJsNodeCommands(options) {
|
|
1106
|
-
const settings = record(options, "node options");
|
|
1107
|
-
onlyKeys(settings, ["runtime", "limits", "replace"]);
|
|
1108
|
-
if (Object.hasOwn(settings, "replace") && typeof settings.replace !== "boolean") throw new TypeError("node replace must be boolean");
|
|
1109
|
-
delete settings.replace;
|
|
1110
|
-
return Object.freeze([createSafeJsNodeCommand(settings)]);
|
|
1111
|
-
}
|
|
1112
|
-
function safeJsNodeCommands(options) {
|
|
1113
|
-
const definitions = createSafeJsNodeCommands(options);
|
|
1114
|
-
const replace = options.replace ?? false;
|
|
1115
|
-
return { name: "node-commands", setup(host) {
|
|
1116
|
-
if (!replace && host.commands.has("node")) throw new Error("Command already registered: node");
|
|
1117
|
-
for (const definition of definitions) host.commands.register(definition, { replace });
|
|
1118
|
-
} };
|
|
1119
|
-
}
|
|
1120
|
-
function invocation(args, metadata) {
|
|
1121
|
-
let source;
|
|
1122
|
-
let print = false;
|
|
1123
|
-
let check = false;
|
|
1124
|
-
let sourceMaps = false;
|
|
1125
|
-
const preloads = [];
|
|
1126
|
-
const nodeOptions = [];
|
|
1127
|
-
const envFiles = [];
|
|
1128
|
-
let inputType;
|
|
1129
|
-
let index = 0;
|
|
1130
|
-
for (; index < args.length; index++) {
|
|
1131
|
-
const argument = args[index];
|
|
1132
|
-
if (argument === "--") {
|
|
1133
|
-
index++;
|
|
1134
|
-
break;
|
|
1135
|
-
}
|
|
1136
|
-
if (argument === "-h" || argument === "--help") return { file: "-", args: [], print: false, help: true };
|
|
1137
|
-
if (argument === "-v" || argument === "--version") {
|
|
1138
|
-
if (!metadata?.version) throw new UsageError("inject runtime.node.version to report the actual runtime identity");
|
|
1139
|
-
return { file: "-", args: [], print: false, help: false, output: metadata.version + "\n" };
|
|
1140
|
-
}
|
|
1141
|
-
if (argument === "--completion-bash") {
|
|
1142
|
-
const flags = ["--help", "--version", "--completion-bash", "--check", "--eval", "--print", "--input-type", "--require", "--enable-source-maps", "--env-file", "--env-file-if-exists", ...Object.keys(metadata?.options ?? {})];
|
|
1143
|
-
return { file: "-", args: [], print: false, help: false, output: `_node_complete() {
|
|
1144
|
-
local cur_word="\${COMP_WORDS[COMP_CWORD]}"
|
|
1145
|
-
COMPREPLY=( $(compgen -W '${flags.join(" ")}' -- "$cur_word") )
|
|
1146
|
-
}
|
|
1147
|
-
complete -F _node_complete node
|
|
1148
|
-
` };
|
|
1149
|
-
}
|
|
1150
|
-
const equal = argument.indexOf("=");
|
|
1151
|
-
const flag = equal < 0 ? argument : argument.slice(0, equal);
|
|
1152
|
-
if (flag === "--env-file" || flag === "--env-file-if-exists") {
|
|
1153
|
-
const path = equal < 0 ? args[++index] : argument.slice(equal + 1);
|
|
1154
|
-
if (!path) throw new UsageError(`${flag} requires a file operand`);
|
|
1155
|
-
envFiles.push({ path, optional: flag === "--env-file-if-exists" });
|
|
1156
|
-
continue;
|
|
1157
|
-
}
|
|
1158
|
-
if (Object.hasOwn(metadata?.options ?? {}, flag)) {
|
|
1159
|
-
const kind = metadata.options[flag];
|
|
1160
|
-
if (kind === "boolean") {
|
|
1161
|
-
if (equal >= 0) throw new UsageError(`${flag} does not accept a value`);
|
|
1162
|
-
nodeOptions.push(flag);
|
|
1163
|
-
} else {
|
|
1164
|
-
const value = equal < 0 ? args[++index] : argument.slice(equal + 1);
|
|
1165
|
-
if (!value || value.startsWith("--")) throw new UsageError(`${flag} requires a value`);
|
|
1166
|
-
nodeOptions.push(flag + "=" + value);
|
|
1167
|
-
}
|
|
1168
|
-
continue;
|
|
1169
|
-
}
|
|
1170
|
-
if (argument === "--enable-source-maps") {
|
|
1171
|
-
sourceMaps = true;
|
|
1172
|
-
continue;
|
|
1173
|
-
}
|
|
1174
|
-
if (argument === "--require" || argument.startsWith("--require=") || argument.startsWith("-r")) {
|
|
1175
|
-
const name = argument === "--require" || argument === "-r" ? args[++index] : argument.startsWith("--require=") ? argument.slice(10) : argument.slice(2);
|
|
1176
|
-
if (!name) throw new UsageError(`${argument} requires a module operand`);
|
|
1177
|
-
preloads.push(name);
|
|
1178
|
-
continue;
|
|
1179
|
-
}
|
|
1180
|
-
if (argument === "--input-type" || argument.startsWith("--input-type=")) {
|
|
1181
|
-
const value = argument === "--input-type" ? args[++index] : argument.slice(13);
|
|
1182
|
-
if (value !== "module" && value !== "commonjs") throw new UsageError("SafeJS node supports --input-type=module or --input-type=commonjs");
|
|
1183
|
-
inputType = value;
|
|
1184
|
-
continue;
|
|
1185
|
-
}
|
|
1186
|
-
if (argument === "--check" || argument === "-c") {
|
|
1187
|
-
if (source !== void 0) throw new UsageError("conflicting source selectors");
|
|
1188
|
-
check = true;
|
|
1189
|
-
continue;
|
|
1190
|
-
}
|
|
1191
|
-
const mode = argument === "--eval" || argument.startsWith("--eval=") || argument.startsWith("-e") ? "eval" : argument === "--print" || argument.startsWith("--print=") || argument.startsWith("-p") ? "print" : void 0;
|
|
1192
|
-
if (mode) {
|
|
1193
|
-
if (source !== void 0 || check) throw new UsageError("conflicting source selectors");
|
|
1194
|
-
print = mode === "print";
|
|
1195
|
-
const equal2 = argument.indexOf("=");
|
|
1196
|
-
source = argument.startsWith("--") ? equal2 >= 0 ? argument.slice(equal2 + 1) : args[++index] : argument.length > 2 ? argument.slice(2) : args[++index];
|
|
1197
|
-
if (source === void 0) throw new UsageError(`${argument} requires JavaScript source`);
|
|
1198
|
-
continue;
|
|
1199
|
-
}
|
|
1200
|
-
if (argument !== "-" && argument.startsWith("-")) throw new UsageError(`unsupported node option '${argument}'`);
|
|
1201
|
-
break;
|
|
1202
|
-
}
|
|
1203
|
-
if (source !== void 0) return { source, file: print ? "<node -p>" : "<node -e>", args: args.slice(index), print, help: false, preloads, sourceMaps, nodeOptions, envFiles, ...inputType ? { inputType } : {} };
|
|
1204
|
-
if (inputType === "commonjs" && args[index] !== void 0 && args[index] !== "-") throw new UsageError("--input-type can only be used with eval, print or stdin source");
|
|
1205
|
-
return { file: args[index] ?? "-", args: args.slice(index + 1), print: false, help: false, check, preloads, sourceMaps, nodeOptions, envFiles, ...inputType ? { inputType } : {} };
|
|
1206
|
-
}
|
|
1207
|
-
function createSafeJsNodeCommand(options) {
|
|
1208
|
-
const settings = record(options, "node options");
|
|
1209
|
-
onlyKeys(settings, ["runtime", "limits"]);
|
|
1210
|
-
if (settings.runtime === void 0 || settings.runtime === null) throw new TypeError("node requires an injected SafeJS runtime");
|
|
1211
|
-
options = settings;
|
|
1212
|
-
const limits = commandLimits(options.limits);
|
|
1213
|
-
const suppliedMetadata = options.runtime.node;
|
|
1214
|
-
const metadata = suppliedMetadata ? { ...suppliedMetadata.version !== void 0 ? { version: suppliedMetadata.version } : {}, options: Object.freeze({ ...suppliedMetadata.options }) } : void 0;
|
|
1215
|
-
if (metadata?.version !== void 0 && (typeof metadata.version !== "string" || !metadata.version || metadata.version.includes("\n") || metadata.version.includes("\0"))) throw new TypeError("Invalid runtime.node.version");
|
|
1216
|
-
for (const [flag, kind] of Object.entries(metadata?.options ?? {})) {
|
|
1217
|
-
if (!flag.startsWith("--") || flag.length < 3 || ![...flag.slice(2)].every((char) => "abcdefghijklmnopqrstuvwxyz0123456789-".includes(char)) || kind !== "boolean" && kind !== "value") throw new TypeError("Invalid runtime.node.options");
|
|
1218
|
-
}
|
|
1219
|
-
const definitions = createSafeJsCommands(options, {
|
|
1220
|
-
name: "node",
|
|
1221
|
-
description: "Execute JavaScript with an injected SafeJS runtime and virtual I/O",
|
|
1222
|
-
help: 'Usage: node [--check | -e SOURCE | -p EXPRESSION] [FILE | -] [ARG...]\nExecutes with the injected SafeJS interpreter; no native Node.js process.\nSupports --check/-c (inject parseSourceModule), --eval, --print, and --enable-source-maps.\nUse --input-type=module or --input-type=commonjs and -- before operands.\nNo source operand reads stdin. Files and inline source leave stdin for guest data.\nUse async imports from fs or require("node:fs/promises").\nUse fs.readFileSync(path, encoding) for synchronous guest text reads.\nImport or require path or node:path for virtual POSIX path helpers.\nUse --require/-r to preload virtual .cjs, .js or .json modules.\nRequire explicit virtual module paths; native modules and package search are not supported.\n',
|
|
1223
|
-
invocation: (args) => invocation(args, metadata),
|
|
1224
|
-
transformSource(source, selected) {
|
|
1225
|
-
if (selected.inputType !== "commonjs") return source;
|
|
1226
|
-
if (source.startsWith("#!")) {
|
|
1227
|
-
const newline = source.indexOf("\n");
|
|
1228
|
-
source = newline < 0 ? "" : source.slice(newline);
|
|
1229
|
-
}
|
|
1230
|
-
const filename = selected.source === void 0 ? "[stdin]" : "[eval]";
|
|
1231
|
-
const body = selected.print ? `console.log((
|
|
1232
|
-
${source}
|
|
1233
|
-
));` : source;
|
|
1234
|
-
return `
|
|
1235
|
-
const __safeBashCommonJs = { exports: {} };
|
|
1236
|
-
(function(exports, require, module, __filename, __dirname) {
|
|
1237
|
-
${selected.check ? body : `eval(${JSON.stringify(body)});`}
|
|
1238
|
-
}).call(globalThis, __safeBashCommonJs.exports, require, __safeBashCommonJs, ${JSON.stringify(filename)}, ".");
|
|
1239
|
-
`;
|
|
1240
|
-
},
|
|
1241
|
-
async prepare(source, selected, modules, lifecycle) {
|
|
1242
|
-
const command = modules.command;
|
|
1243
|
-
let remainingSourceBytes = limits.maxSourceBytes - lifecycle.sourceBytes;
|
|
1244
|
-
const env = await nodeEnvironment(selected.envFiles ?? [], command.env, command.cwd, async (path2, maxBytes) => {
|
|
1245
|
-
const value = await lifecycle.readSource(path2, maxBytes);
|
|
1246
|
-
remainingSourceBytes -= import_buffer.Buffer.byteLength(value);
|
|
1247
|
-
return value;
|
|
1248
|
-
}, lifecycle.signal, remainingSourceBytes);
|
|
1249
|
-
const directory = selected.inputType === "module" || selected.source === void 0 && selected.file.endsWith(".mjs") ? void 0 : selected.source !== void 0 || selected.file === "-" ? "." : dirname(selected.file);
|
|
1250
|
-
const stdio = modules.stdio;
|
|
1251
|
-
const fs = modules.fs;
|
|
1252
|
-
const pending = /* @__PURE__ */ new Set();
|
|
1253
|
-
const processModule = {
|
|
1254
|
-
argv: ["/virtual/bin/node", ...selected.source === void 0 ? [selected.file] : [], ...selected.args],
|
|
1255
|
-
env,
|
|
1256
|
-
cwd: options.runtime.declareHostOperation(() => command.cwd, "read-side-effect"),
|
|
1257
|
-
exitCode: 0,
|
|
1258
|
-
stdin: { readText: stdio.readText, readBytes: stdio.readBytes },
|
|
1259
|
-
stdout: { write: stdio.write },
|
|
1260
|
-
stderr: { write: stdio.error }
|
|
1261
|
-
};
|
|
1262
|
-
const nodeFs = {
|
|
1263
|
-
...fs,
|
|
1264
|
-
promises: fs,
|
|
1265
|
-
...typeof fs.readFile === "function" ? {
|
|
1266
|
-
readFile: nodeReadFile(options, fs, lifecycle.signal, lifecycle.fail, pending),
|
|
1267
|
-
readFileSync: options.runtime.declareHostOperation(
|
|
1268
|
-
// Give the synchronous facade its own declaration so readFile stays asynchronous.
|
|
1269
|
-
fs.readFile.bind(void 0),
|
|
1270
|
-
"read-side-effect",
|
|
1271
|
-
{ awaitResult: true }
|
|
1272
|
-
)
|
|
1273
|
-
} : {}
|
|
1274
|
-
};
|
|
1275
|
-
modules.fs = { ...nodeFs, default: nodeFs };
|
|
1276
|
-
const path = createNodePathModule(options.runtime, command.cwd);
|
|
1277
|
-
const requiredModules = /* @__PURE__ */ new Map([["fs", nodeFs], ["node:fs", nodeFs], ["fs/promises", fs], ["node:fs/promises", fs], ["path", path], ["node:path", path]]);
|
|
1278
|
-
for (const [name, module] of requiredModules) modules[name] = { ...module, default: module };
|
|
1279
|
-
const prefix = bufferSource + timerSource + (directory === void 0 ? "" : "let __dirname = __safeBashDirectory;\n") + nodeRequireSource;
|
|
1280
|
-
const printing = selected.print && selected.inputType !== "commonjs";
|
|
1281
|
-
const sourceLocation = selected.sourceMaps ? await nodeSourceLocation(
|
|
1282
|
-
source,
|
|
1283
|
-
selected.file,
|
|
1284
|
-
command.cwd,
|
|
1285
|
-
prefix + (printing ? "console.log((\n" : ""),
|
|
1286
|
-
lifecycle.readSource,
|
|
1287
|
-
lifecycle.signal,
|
|
1288
|
-
limits
|
|
1289
|
-
) : void 0;
|
|
1290
|
-
return {
|
|
1291
|
-
...sourceLocation ? { sourceLocation } : {},
|
|
1292
|
-
importSpecifiers: [...requiredModules.keys()],
|
|
1293
|
-
source: prefix + (printing ? `console.log((
|
|
1294
|
-
${source}
|
|
1295
|
-
));` : source) + "\n;await __safeBashTimers.drain(); __safeBashSetExitCode(process.exitCode);",
|
|
1296
|
-
bindings: {
|
|
1297
|
-
...directory === void 0 ? {} : { __safeBashDirectory: directory },
|
|
1298
|
-
__safeBashBuffer: bufferBindings(options),
|
|
1299
|
-
__safeBashTimers: timerBindings(options, lifecycle.signal, lifecycle.fail, pending),
|
|
1300
|
-
process: processModule,
|
|
1301
|
-
__safeBashSetExitCode: command.setExitCode,
|
|
1302
|
-
__safeBashPreloads: selected.preloads ?? [],
|
|
1303
|
-
__safeBashCwd: command.cwd,
|
|
1304
|
-
__safeBashEntryDirectory: selected.source === void 0 && selected.file !== "-" ? dirname(selected.file) : command.cwd,
|
|
1305
|
-
__safeBashModuleRead: options.runtime.declareHostOperation(async (path2) => {
|
|
1306
|
-
if (typeof path2 !== "string") throw new TypeError("module path must be a string");
|
|
1307
|
-
const value = await lifecycle.readSource(path2, remainingSourceBytes);
|
|
1308
|
-
remainingSourceBytes -= import_buffer.Buffer.byteLength(value);
|
|
1309
|
-
if (remainingSourceBytes < 0) {
|
|
1310
|
-
const error = new SafeJsCommandLimitError("maxSourceBytes");
|
|
1311
|
-
lifecycle.fail(error);
|
|
1312
|
-
throw error;
|
|
1313
|
-
}
|
|
1314
|
-
return value;
|
|
1315
|
-
}, "read-side-effect", { awaitResult: true }),
|
|
1316
|
-
__safeBashModulePath: options.runtime.declareHostOperation((base, name) => {
|
|
1317
|
-
if (typeof name !== "string" || typeof base !== "string") throw new TypeError("module name must be a string");
|
|
1318
|
-
if (!(name.startsWith("./") || name.startsWith("../") || name.startsWith("/"))) return null;
|
|
1319
|
-
if (name.includes("\0") || !(name.endsWith(".json") || name.endsWith(".js") || name.endsWith(".cjs"))) {
|
|
1320
|
-
throw new TypeError("Unsupported node module; use an explicit .cjs, .js or .json path");
|
|
1321
|
-
}
|
|
1322
|
-
return resolvePath(base, name);
|
|
1323
|
-
}, "read-side-effect"),
|
|
1324
|
-
__safeBashRequire: options.runtime.declareHostOperation((name) => {
|
|
1325
|
-
const module = typeof name === "string" ? requiredModules.get(name) : void 0;
|
|
1326
|
-
if (!module) throw new TypeError("Unsupported node module; use fs, node:fs, fs/promises, node:fs/promises, path or node:path");
|
|
1327
|
-
return module;
|
|
1328
|
-
}, "read-side-effect")
|
|
1329
|
-
}
|
|
1330
|
-
};
|
|
1331
|
-
}
|
|
1332
|
-
});
|
|
1333
|
-
return Object.freeze(definitions[0]);
|
|
1334
|
-
}
|
|
1335
|
-
|
|
1336
|
-
export {
|
|
1337
|
-
diagnostics_exports,
|
|
1338
|
-
record,
|
|
1339
|
-
onlyKeys,
|
|
1340
|
-
stringValue,
|
|
1341
|
-
withSignal,
|
|
1342
|
-
defaultSafeJsLimits,
|
|
1343
|
-
SafeJsCommandLimitError,
|
|
1344
|
-
createSafeJsNodeCommands,
|
|
1345
|
-
safeJsNodeCommands,
|
|
1346
|
-
createSafeJsNodeCommand
|
|
1347
|
-
};
|
|
1348
|
-
//# sourceMappingURL=chunk-NB2V7EOY.js.map
|