@vite-hub/sandbox 0.0.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +35 -37
- package/dist/cloudflare-env-2NctU8i7.js +12 -0
- package/dist/index.d.ts +23 -32
- package/dist/index.js +688 -265
- package/dist/module-types-DfXe133f.d.ts +91 -0
- package/dist/provider-loader-hL7uHVWp.d.ts +21 -0
- package/dist/runtime/provider-loader.d.ts +2 -17
- package/dist/runtime/provider-loader.js +4 -10
- package/dist/runtime/providers/cloudflare.d.ts +5 -11
- package/dist/runtime/providers/cloudflare.js +14 -11
- package/dist/runtime/providers/vercel.d.ts +103 -12
- package/dist/runtime/providers/vercel.js +16 -30
- package/dist/runtime/state.d.ts +1 -1
- package/dist/vite.d.ts +12 -28
- package/dist/vite.js +2280 -354
- package/package.json +60 -59
- package/dist/_shared-CJ2_pS4E.js +0 -53
- package/dist/cloudflare-retry-Cfra7MvS.js +0 -21
- package/dist/common-CS4FcWrh.d.ts +0 -369
- package/dist/index-B4j3Mvzr.d.ts +0 -146
- package/dist/integration-wkNE8jMO.js +0 -2032
- package/dist/module-types-CUcY8iuI.d.ts +0 -88
- package/dist/nitro.d.ts +0 -19
- package/dist/nitro.js +0 -488
- package/dist/provider-detection-IbezCeoR.js +0 -25
- package/dist/runtime/nitro-plugin.d.ts +0 -4
- package/dist/runtime/nitro-plugin.js +0 -8
- package/dist/sandbox/providers/cloudflare.d.ts +0 -7
- package/dist/sandbox/providers/cloudflare.js +0 -339
- package/dist/sandbox/providers/vercel.d.ts +0 -17
- package/dist/sandbox/providers/vercel.js +0 -538
- package/dist/shared-pqTHYWg1.d.ts +0 -8
- package/dist/utils-V7ODsDW_.js +0 -44
- package/dist/vercel-runtime-BPzvh_6V.js +0 -11
- /package/dist/{module-types-BomzaqnM.js → module-types-Dj1MFmHT.js} +0 -0
|
@@ -1,538 +0,0 @@
|
|
|
1
|
-
import { n as SandboxError, r as NotSupportedError } from "../../utils-V7ODsDW_.js";
|
|
2
|
-
import { n as waitForPortProbe, r as BaseSandboxAdapter, t as normalizeLogPattern } from "../../_shared-CJ2_pS4E.js";
|
|
3
|
-
import { posix } from "node:path";
|
|
4
|
-
import { Readable } from "node:stream";
|
|
5
|
-
import { Buffer as Buffer$1 } from "node:buffer";
|
|
6
|
-
//#region src/sandbox/adapters/vercel/error.ts
|
|
7
|
-
function asRecord(value) {
|
|
8
|
-
return value;
|
|
9
|
-
}
|
|
10
|
-
function buildCommandLabel(command, args) {
|
|
11
|
-
return [command, ...args].join(" ").trim();
|
|
12
|
-
}
|
|
13
|
-
function normalizeVercelExecError(command, args, error) {
|
|
14
|
-
if (error instanceof SandboxError) return error;
|
|
15
|
-
const details = error;
|
|
16
|
-
const commandLabel = buildCommandLabel(command, args);
|
|
17
|
-
const messageParts = [`Vercel sandbox exec failed for "${commandLabel}".`];
|
|
18
|
-
if (typeof details?.message === "string" && details.message) messageParts.push(details.message);
|
|
19
|
-
if (details?.response?.status || details?.response?.url) {
|
|
20
|
-
const responseContext = [typeof details.response.status === "number" ? `status ${details.response.status}` : void 0, typeof details.response.url === "string" ? details.response.url : void 0].filter(Boolean).join(" at ");
|
|
21
|
-
if (responseContext) messageParts.push(`Transport: ${responseContext}.`);
|
|
22
|
-
}
|
|
23
|
-
return new SandboxError(messageParts.join(" "), {
|
|
24
|
-
cause: error,
|
|
25
|
-
code: "VERCEL_SANDBOX_EXEC_FAILED",
|
|
26
|
-
details: { command: commandLabel },
|
|
27
|
-
method: "exec",
|
|
28
|
-
provider: "vercel"
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
//#endregion
|
|
32
|
-
//#region src/sandbox/adapters/vercel/process.ts
|
|
33
|
-
async function waitForExit(result, timeout) {
|
|
34
|
-
if (!timeout || timeout <= 0) return await result.wait();
|
|
35
|
-
let timer;
|
|
36
|
-
try {
|
|
37
|
-
return await Promise.race([result.wait(), new Promise((_, reject) => {
|
|
38
|
-
timer = setTimeout(() => {
|
|
39
|
-
reject(new SandboxError("Vercel sandbox exec timed out.", {
|
|
40
|
-
code: "VERCEL_SANDBOX_EXEC_TIMEOUT",
|
|
41
|
-
method: "exec",
|
|
42
|
-
provider: "vercel"
|
|
43
|
-
}));
|
|
44
|
-
}, timeout);
|
|
45
|
-
})]);
|
|
46
|
-
} finally {
|
|
47
|
-
if (timer) clearTimeout(timer);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
async function collectDetachedCommandOutput(result, opts) {
|
|
51
|
-
let stdout = "";
|
|
52
|
-
let stderr = "";
|
|
53
|
-
let logsError;
|
|
54
|
-
let usedSnapshotFallback = false;
|
|
55
|
-
const logsPromise = (async () => {
|
|
56
|
-
try {
|
|
57
|
-
for await (const log of result.logs()) if (log.stream === "stdout") {
|
|
58
|
-
stdout += log.data;
|
|
59
|
-
opts?.onStdout?.(log.data);
|
|
60
|
-
} else {
|
|
61
|
-
stderr += log.data;
|
|
62
|
-
opts?.onStderr?.(log.data);
|
|
63
|
-
}
|
|
64
|
-
} catch (error) {
|
|
65
|
-
logsError = error;
|
|
66
|
-
}
|
|
67
|
-
})();
|
|
68
|
-
const waitResult = await waitForExit(result, opts?.timeout);
|
|
69
|
-
await logsPromise;
|
|
70
|
-
if (logsError || !stdout && !stderr) try {
|
|
71
|
-
usedSnapshotFallback = true;
|
|
72
|
-
const [stdoutSnapshot, stderrSnapshot] = await Promise.all([result.stdout(), result.stderr()]);
|
|
73
|
-
stdout ||= stdoutSnapshot;
|
|
74
|
-
stderr ||= stderrSnapshot;
|
|
75
|
-
} catch (error) {
|
|
76
|
-
if (!logsError) logsError = error;
|
|
77
|
-
}
|
|
78
|
-
if (logsError && !stdout && !stderr) throw logsError;
|
|
79
|
-
return {
|
|
80
|
-
code: waitResult.exitCode,
|
|
81
|
-
meta: {
|
|
82
|
-
detached: true,
|
|
83
|
-
logCollection: usedSnapshotFallback ? "snapshot-fallback" : "stream"
|
|
84
|
-
},
|
|
85
|
-
stdout,
|
|
86
|
-
stderr
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
var VercelProcessHandle = class {
|
|
90
|
-
id;
|
|
91
|
-
command;
|
|
92
|
-
cmdResult;
|
|
93
|
-
collectedStdout = "";
|
|
94
|
-
collectedStderr = "";
|
|
95
|
-
logsGenerator;
|
|
96
|
-
logsPump;
|
|
97
|
-
logsPumpDone = false;
|
|
98
|
-
logsPumpError;
|
|
99
|
-
logEventWaiters = [];
|
|
100
|
-
resolvePortUrl;
|
|
101
|
-
constructor(id, command, cmdResult, resolvePortUrl) {
|
|
102
|
-
this.id = id;
|
|
103
|
-
this.command = command;
|
|
104
|
-
this.cmdResult = cmdResult;
|
|
105
|
-
this.resolvePortUrl = resolvePortUrl;
|
|
106
|
-
}
|
|
107
|
-
async kill(_signal) {
|
|
108
|
-
await this.cmdResult.kill();
|
|
109
|
-
}
|
|
110
|
-
notifyLogEvent() {
|
|
111
|
-
const waiters = this.logEventWaiters.splice(0, this.logEventWaiters.length);
|
|
112
|
-
for (const waiter of waiters) waiter();
|
|
113
|
-
}
|
|
114
|
-
startLogsPump() {
|
|
115
|
-
if (this.logsPump) return;
|
|
116
|
-
if (!this.logsGenerator) this.logsGenerator = this.cmdResult.logs();
|
|
117
|
-
this.logsPump = (async () => {
|
|
118
|
-
try {
|
|
119
|
-
for await (const log of this.logsGenerator) {
|
|
120
|
-
if (log.stream === "stdout") this.collectedStdout += log.data;
|
|
121
|
-
else this.collectedStderr += log.data;
|
|
122
|
-
this.notifyLogEvent();
|
|
123
|
-
}
|
|
124
|
-
} catch (error) {
|
|
125
|
-
this.logsPumpError = error;
|
|
126
|
-
} finally {
|
|
127
|
-
this.logsPumpDone = true;
|
|
128
|
-
this.notifyLogEvent();
|
|
129
|
-
}
|
|
130
|
-
})();
|
|
131
|
-
}
|
|
132
|
-
async waitForLogEvent(timeoutMs) {
|
|
133
|
-
if (timeoutMs <= 0 || this.logsPumpDone) return false;
|
|
134
|
-
return new Promise((resolve) => {
|
|
135
|
-
const onEvent = () => {
|
|
136
|
-
clearTimeout(timeoutId);
|
|
137
|
-
this.logEventWaiters = this.logEventWaiters.filter((waiter) => waiter !== onEvent);
|
|
138
|
-
resolve(true);
|
|
139
|
-
};
|
|
140
|
-
const timeoutId = setTimeout(() => {
|
|
141
|
-
this.logEventWaiters = this.logEventWaiters.filter((waiter) => waiter !== onEvent);
|
|
142
|
-
resolve(false);
|
|
143
|
-
}, timeoutMs);
|
|
144
|
-
this.logEventWaiters.push(onEvent);
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
findMatchingLine(regex) {
|
|
148
|
-
const combined = `${this.collectedStdout}\n${this.collectedStderr}`;
|
|
149
|
-
for (const line of combined.split("\n")) if (regex.test(line)) return line;
|
|
150
|
-
}
|
|
151
|
-
async logs() {
|
|
152
|
-
this.startLogsPump();
|
|
153
|
-
await this.waitForLogEvent(10);
|
|
154
|
-
return {
|
|
155
|
-
stdout: this.collectedStdout,
|
|
156
|
-
stderr: this.collectedStderr
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
async wait(timeout) {
|
|
160
|
-
const rawExitCode = (timeout ? await Promise.race([this.cmdResult.wait(), new Promise((_, reject) => setTimeout(() => reject(new SandboxError("Process wait timeout", "TIMEOUT")), timeout))]) : await this.cmdResult.wait())?.exitCode;
|
|
161
|
-
return { exitCode: typeof rawExitCode === "number" ? rawExitCode : 0 };
|
|
162
|
-
}
|
|
163
|
-
async waitForLog(pattern, timeout = 3e4) {
|
|
164
|
-
const startTime = Date.now();
|
|
165
|
-
const regex = normalizeLogPattern(pattern);
|
|
166
|
-
this.startLogsPump();
|
|
167
|
-
let matchedLine = this.findMatchingLine(regex);
|
|
168
|
-
if (matchedLine) return { line: matchedLine };
|
|
169
|
-
while (Date.now() - startTime < timeout) {
|
|
170
|
-
if (this.logsPumpError) throw this.logsPumpError;
|
|
171
|
-
if (this.logsPumpDone) throw new SandboxError(`Process exited before log pattern was found: ${pattern}`, "PROCESS_EXITED");
|
|
172
|
-
const remaining = timeout - (Date.now() - startTime);
|
|
173
|
-
await this.waitForLogEvent(Math.min(remaining, 200));
|
|
174
|
-
matchedLine = this.findMatchingLine(regex);
|
|
175
|
-
if (matchedLine) return { line: matchedLine };
|
|
176
|
-
}
|
|
177
|
-
if (this.logsPumpError) throw this.logsPumpError;
|
|
178
|
-
throw new SandboxError(`Timeout waiting for log pattern: ${pattern}`, "TIMEOUT");
|
|
179
|
-
}
|
|
180
|
-
async waitForPort(port, opts) {
|
|
181
|
-
await waitForPortProbe(fetch, port, opts, this.resolvePortUrl ? () => this.resolvePortUrl(port) : void 0);
|
|
182
|
-
}
|
|
183
|
-
};
|
|
184
|
-
//#endregion
|
|
185
|
-
//#region src/sandbox/adapters/vercel.ts
|
|
186
|
-
var VercelNamespaceImpl = class {
|
|
187
|
-
native;
|
|
188
|
-
sandboxId;
|
|
189
|
-
_metadata;
|
|
190
|
-
constructor(instance, sandboxId, metadata) {
|
|
191
|
-
this.native = instance;
|
|
192
|
-
this.sandboxId = sandboxId;
|
|
193
|
-
this._metadata = metadata;
|
|
194
|
-
}
|
|
195
|
-
async snapshot() {
|
|
196
|
-
const instanceAny = asRecord(this.native);
|
|
197
|
-
if (typeof instanceAny.snapshot === "function") return instanceAny.snapshot();
|
|
198
|
-
throw new NotSupportedError("snapshot", "vercel");
|
|
199
|
-
}
|
|
200
|
-
async getSnapshot(id) {
|
|
201
|
-
const instanceAny = asRecord(this.native);
|
|
202
|
-
if (typeof instanceAny.getSnapshot === "function") return instanceAny.getSnapshot(id);
|
|
203
|
-
throw new NotSupportedError("getSnapshot", "vercel");
|
|
204
|
-
}
|
|
205
|
-
async listSnapshots() {
|
|
206
|
-
const instanceAny = asRecord(this.native);
|
|
207
|
-
if (typeof instanceAny.listSnapshots === "function") return instanceAny.listSnapshots();
|
|
208
|
-
throw new NotSupportedError("listSnapshots", "vercel");
|
|
209
|
-
}
|
|
210
|
-
async deleteSnapshot(id) {
|
|
211
|
-
const instanceAny = asRecord(this.native);
|
|
212
|
-
if (typeof instanceAny.deleteSnapshot === "function") {
|
|
213
|
-
await instanceAny.deleteSnapshot(id);
|
|
214
|
-
return;
|
|
215
|
-
}
|
|
216
|
-
throw new NotSupportedError("deleteSnapshot", "vercel");
|
|
217
|
-
}
|
|
218
|
-
domain(port) {
|
|
219
|
-
const instanceAny = asRecord(this.native);
|
|
220
|
-
if (typeof instanceAny.domain === "function") return instanceAny.domain(port);
|
|
221
|
-
return `https://${this.sandboxId}-${port}.sandbox.vercel.app`;
|
|
222
|
-
}
|
|
223
|
-
async extendTimeout(durationMs) {
|
|
224
|
-
const instanceAny = asRecord(this.native);
|
|
225
|
-
if (typeof instanceAny.extendTimeout === "function") {
|
|
226
|
-
await instanceAny.extendTimeout(durationMs);
|
|
227
|
-
return;
|
|
228
|
-
}
|
|
229
|
-
throw new NotSupportedError("extendTimeout", "vercel");
|
|
230
|
-
}
|
|
231
|
-
async updateNetworkPolicy(policy) {
|
|
232
|
-
const instanceAny = asRecord(this.native);
|
|
233
|
-
if (typeof instanceAny.updateNetworkPolicy === "function") {
|
|
234
|
-
await instanceAny.updateNetworkPolicy(policy);
|
|
235
|
-
return;
|
|
236
|
-
}
|
|
237
|
-
throw new NotSupportedError("updateNetworkPolicy", "vercel");
|
|
238
|
-
}
|
|
239
|
-
getMetadata() {
|
|
240
|
-
return {
|
|
241
|
-
id: this.sandboxId,
|
|
242
|
-
runtime: this._metadata.runtime,
|
|
243
|
-
status: "running",
|
|
244
|
-
createdAt: this._metadata.createdAt
|
|
245
|
-
};
|
|
246
|
-
}
|
|
247
|
-
};
|
|
248
|
-
var VercelSandboxAdapter = class extends BaseSandboxAdapter {
|
|
249
|
-
id;
|
|
250
|
-
provider = "vercel";
|
|
251
|
-
native;
|
|
252
|
-
supports = {
|
|
253
|
-
execEnv: true,
|
|
254
|
-
execCwd: true,
|
|
255
|
-
execSudo: true,
|
|
256
|
-
listFiles: true,
|
|
257
|
-
exists: true,
|
|
258
|
-
deleteFile: true,
|
|
259
|
-
moveFile: true,
|
|
260
|
-
readFileStream: true,
|
|
261
|
-
startProcess: true
|
|
262
|
-
};
|
|
263
|
-
_vercel;
|
|
264
|
-
metadata;
|
|
265
|
-
constructor(id, instance, metadata) {
|
|
266
|
-
super();
|
|
267
|
-
this.id = id;
|
|
268
|
-
this.metadata = metadata;
|
|
269
|
-
this.native = instance;
|
|
270
|
-
}
|
|
271
|
-
get vercel() {
|
|
272
|
-
if (!this._vercel) this._vercel = new VercelNamespaceImpl(this.native, this.id, this.metadata);
|
|
273
|
-
return this._vercel;
|
|
274
|
-
}
|
|
275
|
-
async exec(command, args = [], opts) {
|
|
276
|
-
try {
|
|
277
|
-
const result = await this.native.runCommand({
|
|
278
|
-
cmd: command,
|
|
279
|
-
args,
|
|
280
|
-
cwd: opts?.cwd,
|
|
281
|
-
env: opts?.env,
|
|
282
|
-
sudo: opts?.sudo,
|
|
283
|
-
detached: true
|
|
284
|
-
});
|
|
285
|
-
const output = await collectDetachedCommandOutput(result, opts);
|
|
286
|
-
return {
|
|
287
|
-
ok: output.code === 0,
|
|
288
|
-
stdout: output.stdout,
|
|
289
|
-
stderr: output.stderr,
|
|
290
|
-
code: output.code,
|
|
291
|
-
meta: {
|
|
292
|
-
...output.meta,
|
|
293
|
-
command: buildCommandLabel(command, args),
|
|
294
|
-
commandId: asRecord(result).id
|
|
295
|
-
}
|
|
296
|
-
};
|
|
297
|
-
} catch (error) {
|
|
298
|
-
throw normalizeVercelExecError(command, args, error);
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
async writeFile(path, content) {
|
|
302
|
-
if (this.native.fs?.writeFile) {
|
|
303
|
-
await this.native.fs.writeFile(path, content);
|
|
304
|
-
return;
|
|
305
|
-
}
|
|
306
|
-
await this.native.writeFiles([{
|
|
307
|
-
path,
|
|
308
|
-
content: Buffer$1.from(content)
|
|
309
|
-
}]);
|
|
310
|
-
}
|
|
311
|
-
async readFile(path, opts) {
|
|
312
|
-
if (this.native.fs?.readFile) {
|
|
313
|
-
if (opts?.encoding === "binary") return new Uint8Array(await this.native.fs.readFile(path));
|
|
314
|
-
return await this.native.fs.readFile(path, "utf8");
|
|
315
|
-
}
|
|
316
|
-
const buffer = await this.native.readFileToBuffer({ path });
|
|
317
|
-
if (!buffer) throw new SandboxError(`Failed to read file: ${path}`);
|
|
318
|
-
if (opts?.encoding === "binary") return buffer;
|
|
319
|
-
return Buffer$1.from(buffer).toString();
|
|
320
|
-
}
|
|
321
|
-
async stop() {
|
|
322
|
-
if (typeof this.native.stop === "function") {
|
|
323
|
-
await this.native.stop({ blocking: true });
|
|
324
|
-
return;
|
|
325
|
-
}
|
|
326
|
-
await this.native[Symbol.asyncDispose]?.();
|
|
327
|
-
}
|
|
328
|
-
async mkdir(path, opts) {
|
|
329
|
-
if (this.native.fs?.mkdir) {
|
|
330
|
-
await this.native.fs.mkdir(path, opts);
|
|
331
|
-
return;
|
|
332
|
-
}
|
|
333
|
-
if (opts?.recursive) {
|
|
334
|
-
const result = await this.exec("mkdir", ["-p", path]);
|
|
335
|
-
if (!result.ok) throw new SandboxError(`Failed to create directory: ${path}. ${result.stderr}`);
|
|
336
|
-
return;
|
|
337
|
-
}
|
|
338
|
-
await this.native.mkDir(path);
|
|
339
|
-
}
|
|
340
|
-
async readFileStream(path) {
|
|
341
|
-
const stream = await this.native.readFile({ path });
|
|
342
|
-
if (!stream) throw new SandboxError(`Failed to read file: ${path}`);
|
|
343
|
-
return Readable.toWeb(stream);
|
|
344
|
-
}
|
|
345
|
-
async startProcess(cmd, args = [], opts) {
|
|
346
|
-
const processId = `vercel-proc-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
347
|
-
const cmdResult = await this.native.runCommand({
|
|
348
|
-
cmd,
|
|
349
|
-
args,
|
|
350
|
-
cwd: opts?.cwd,
|
|
351
|
-
env: opts?.env,
|
|
352
|
-
detached: true
|
|
353
|
-
});
|
|
354
|
-
return new VercelProcessHandle(processId, `${cmd} ${args.join(" ")}`, cmdResult, (port) => this.vercel.domain(port));
|
|
355
|
-
}
|
|
356
|
-
async listFiles(path, opts) {
|
|
357
|
-
const fs = this.native.fs;
|
|
358
|
-
if (!fs?.readdir || !fs.stat) {
|
|
359
|
-
const args = [
|
|
360
|
-
path.replace(/\/+$/, "") || "/",
|
|
361
|
-
"-mindepth",
|
|
362
|
-
"1"
|
|
363
|
-
];
|
|
364
|
-
if (!opts?.recursive) args.push("-maxdepth", "1");
|
|
365
|
-
args.push("-printf", "%y %s %T@ %p\0");
|
|
366
|
-
const result = await this.exec("find", args);
|
|
367
|
-
if (!result.ok) throw new SandboxError(`Failed to list files: ${path}. ${result.stderr}`);
|
|
368
|
-
return result.stdout.split("\0").filter(Boolean).map((line) => {
|
|
369
|
-
const [kind, size, mtime, filePath] = line.split(" ");
|
|
370
|
-
if (!filePath || kind !== "f" && kind !== "d") return void 0;
|
|
371
|
-
const mtimeSeconds = Number(mtime);
|
|
372
|
-
return {
|
|
373
|
-
mtime: Number.isFinite(mtimeSeconds) ? (/* @__PURE__ */ new Date(mtimeSeconds * 1e3)).toISOString() : void 0,
|
|
374
|
-
name: posix.basename(filePath),
|
|
375
|
-
path: filePath,
|
|
376
|
-
size: kind === "f" ? Number(size) : void 0,
|
|
377
|
-
type: kind === "d" ? "directory" : "file"
|
|
378
|
-
};
|
|
379
|
-
}).filter((entry) => Boolean(entry)).sort((left, right) => left.path.localeCompare(right.path));
|
|
380
|
-
}
|
|
381
|
-
const root = path.replace(/\/+$/, "") || "/";
|
|
382
|
-
const entries = [];
|
|
383
|
-
const visit = async (dir) => {
|
|
384
|
-
const names = await fs.readdir(dir);
|
|
385
|
-
await Promise.all(names.map(async (name) => {
|
|
386
|
-
const child = posix.join(dir, name);
|
|
387
|
-
const stat = await fs.stat(child);
|
|
388
|
-
const entry = {
|
|
389
|
-
mtime: stat.mtime?.toISOString?.() || (typeof stat.mtimeMs === "number" ? new Date(stat.mtimeMs).toISOString() : void 0),
|
|
390
|
-
name,
|
|
391
|
-
path: child,
|
|
392
|
-
size: stat.isFile() ? stat.size : void 0,
|
|
393
|
-
type: stat.isDirectory() ? "directory" : "file"
|
|
394
|
-
};
|
|
395
|
-
entries.push(entry);
|
|
396
|
-
if (opts?.recursive && stat.isDirectory()) await visit(child);
|
|
397
|
-
}));
|
|
398
|
-
};
|
|
399
|
-
await visit(root);
|
|
400
|
-
return entries.sort((left, right) => left.path.localeCompare(right.path));
|
|
401
|
-
}
|
|
402
|
-
async exists(path) {
|
|
403
|
-
const fs = this.native.fs;
|
|
404
|
-
if (fs?.exists) return await fs.exists(path);
|
|
405
|
-
if (fs?.access) try {
|
|
406
|
-
await fs.access(path);
|
|
407
|
-
return true;
|
|
408
|
-
} catch {
|
|
409
|
-
return false;
|
|
410
|
-
}
|
|
411
|
-
try {
|
|
412
|
-
return (await this.exec("test", ["-e", path])).ok;
|
|
413
|
-
} catch {
|
|
414
|
-
return false;
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
|
-
async deleteFile(path) {
|
|
418
|
-
if (this.native.fs?.rm) {
|
|
419
|
-
await this.native.fs.rm(path, {
|
|
420
|
-
force: true,
|
|
421
|
-
recursive: true
|
|
422
|
-
});
|
|
423
|
-
return;
|
|
424
|
-
}
|
|
425
|
-
const result = await this.exec("rm", ["-rf", path]);
|
|
426
|
-
if (!result.ok) throw new SandboxError(`Failed to delete file: ${path}. ${result.stderr}`);
|
|
427
|
-
}
|
|
428
|
-
async moveFile(src, dst) {
|
|
429
|
-
if (this.native.fs?.rename) {
|
|
430
|
-
await this.native.fs.rename(src, dst);
|
|
431
|
-
return;
|
|
432
|
-
}
|
|
433
|
-
const result = await this.exec("mv", [src, dst]);
|
|
434
|
-
if (!result.ok) throw new SandboxError(`Failed to move file: ${src} -> ${dst}. ${result.stderr}`);
|
|
435
|
-
}
|
|
436
|
-
};
|
|
437
|
-
//#endregion
|
|
438
|
-
//#region src/sandbox/providers/vercel.ts
|
|
439
|
-
function wrapVercelSandbox(instance) {
|
|
440
|
-
const passthrough = { ...instance };
|
|
441
|
-
const runCommand = instance.runCommand.bind(instance);
|
|
442
|
-
const writeFiles = instance.writeFiles.bind(instance);
|
|
443
|
-
const readFileToBuffer = instance.readFileToBuffer.bind(instance);
|
|
444
|
-
const readFile = instance.readFile.bind(instance);
|
|
445
|
-
const mkDir = instance.mkDir.bind(instance);
|
|
446
|
-
const domain = instance.domain.bind(instance);
|
|
447
|
-
const stop = typeof instance.stop === "function" ? instance.stop.bind(instance) : void 0;
|
|
448
|
-
const rawAsyncDispose = instance[Symbol.asyncDispose];
|
|
449
|
-
const asyncDispose = typeof rawAsyncDispose === "function" ? async () => {
|
|
450
|
-
await rawAsyncDispose.call(instance);
|
|
451
|
-
} : void 0;
|
|
452
|
-
return {
|
|
453
|
-
...passthrough,
|
|
454
|
-
runCommand: ((first, second, third) => {
|
|
455
|
-
if (typeof first === "string") {
|
|
456
|
-
if (Array.isArray(second)) return runCommand(first, second, third);
|
|
457
|
-
return runCommand(first, void 0, second);
|
|
458
|
-
}
|
|
459
|
-
return runCommand(first);
|
|
460
|
-
}),
|
|
461
|
-
writeFiles: async (files, opts) => await writeFiles(files.map((file) => ({
|
|
462
|
-
path: file.path,
|
|
463
|
-
content: Buffer.from(file.content.buffer, file.content.byteOffset, file.content.byteLength)
|
|
464
|
-
})), opts),
|
|
465
|
-
readFileToBuffer: async (opts, opts2) => {
|
|
466
|
-
const buffer = await readFileToBuffer(opts, opts2);
|
|
467
|
-
return buffer ? new Uint8Array(buffer) : null;
|
|
468
|
-
},
|
|
469
|
-
readFile,
|
|
470
|
-
mkDir,
|
|
471
|
-
domain,
|
|
472
|
-
...instance.fs ? { fs: instance.fs } : {},
|
|
473
|
-
...stop ? { stop } : {},
|
|
474
|
-
...asyncDispose ? { [Symbol.asyncDispose]: asyncDispose } : {}
|
|
475
|
-
};
|
|
476
|
-
}
|
|
477
|
-
async function loadVercelSandbox() {
|
|
478
|
-
try {
|
|
479
|
-
const module = await import("@vercel/sandbox");
|
|
480
|
-
return { Sandbox: {
|
|
481
|
-
create: async (options) => wrapVercelSandbox(await module.Sandbox.create(options)),
|
|
482
|
-
list: async () => {
|
|
483
|
-
const result = await module.Sandbox.list();
|
|
484
|
-
const json = result.json || result;
|
|
485
|
-
return {
|
|
486
|
-
pagination: json.pagination,
|
|
487
|
-
sandboxes: (json.sandboxes || []).map((item) => ({
|
|
488
|
-
id: item.id,
|
|
489
|
-
status: item.status,
|
|
490
|
-
createdAt: item.createdAt
|
|
491
|
-
}))
|
|
492
|
-
};
|
|
493
|
-
},
|
|
494
|
-
get: async (params) => {
|
|
495
|
-
const query = typeof params === "string" ? { sandboxId: params } : params;
|
|
496
|
-
const sandbox = await module.Sandbox.get(query);
|
|
497
|
-
return sandbox ? wrapVercelSandbox(sandbox) : null;
|
|
498
|
-
}
|
|
499
|
-
} };
|
|
500
|
-
} catch (error) {
|
|
501
|
-
throw new SandboxError(`@vercel/sandbox load failed. Install it to use the Vercel provider. Original error: ${error instanceof Error ? error.message : error}`);
|
|
502
|
-
}
|
|
503
|
-
}
|
|
504
|
-
async function createVercelSandboxClient(provider) {
|
|
505
|
-
const id = `vercel-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
506
|
-
const { runtime = "node24", timeout = 3e5, cpu, ports, credentials, source, networkPolicy } = provider;
|
|
507
|
-
return new VercelSandboxAdapter(id, await (await loadVercelSandbox()).Sandbox.create({
|
|
508
|
-
runtime,
|
|
509
|
-
timeout,
|
|
510
|
-
ports,
|
|
511
|
-
source,
|
|
512
|
-
networkPolicy,
|
|
513
|
-
...cpu && { resources: { vcpus: cpu } },
|
|
514
|
-
...credentials && {
|
|
515
|
-
token: credentials.token,
|
|
516
|
-
teamId: credentials.teamId,
|
|
517
|
-
projectId: credentials.projectId
|
|
518
|
-
}
|
|
519
|
-
}), {
|
|
520
|
-
runtime,
|
|
521
|
-
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
522
|
-
});
|
|
523
|
-
}
|
|
524
|
-
const VercelSandboxStatic = {
|
|
525
|
-
async list() {
|
|
526
|
-
return (await loadVercelSandbox()).Sandbox.list();
|
|
527
|
-
},
|
|
528
|
-
async get(id) {
|
|
529
|
-
const instance = await (await loadVercelSandbox()).Sandbox.get(id);
|
|
530
|
-
if (!instance) return null;
|
|
531
|
-
return new VercelSandboxAdapter(id, instance, {
|
|
532
|
-
runtime: "unknown",
|
|
533
|
-
createdAt: "unknown"
|
|
534
|
-
});
|
|
535
|
-
}
|
|
536
|
-
};
|
|
537
|
-
//#endregion
|
|
538
|
-
export { VercelSandboxStatic, createVercelSandboxClient };
|
package/dist/utils-V7ODsDW_.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
//#region src/internal/shared/errors.ts
|
|
2
|
-
var VitehubError = class extends Error {
|
|
3
|
-
code;
|
|
4
|
-
provider;
|
|
5
|
-
method;
|
|
6
|
-
httpStatus;
|
|
7
|
-
upstreamError;
|
|
8
|
-
details;
|
|
9
|
-
cause;
|
|
10
|
-
constructor(message, metadata) {
|
|
11
|
-
super(message);
|
|
12
|
-
this.name = "VitehubError";
|
|
13
|
-
if (typeof metadata === "string") this.code = metadata;
|
|
14
|
-
else if (metadata) Object.assign(this, metadata);
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
var NotSupportedError = class extends VitehubError {
|
|
18
|
-
constructor(method, provider, capability) {
|
|
19
|
-
const code = `NOT_SUPPORTED_${(capability || method).toUpperCase()}`;
|
|
20
|
-
super(`${method}() is not supported by the ${provider} provider`, {
|
|
21
|
-
code,
|
|
22
|
-
method,
|
|
23
|
-
provider,
|
|
24
|
-
httpStatus: 400,
|
|
25
|
-
details: { capability: capability || method }
|
|
26
|
-
});
|
|
27
|
-
this.name = "NotSupportedError";
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
//#endregion
|
|
31
|
-
//#region src/sandbox/errors.ts
|
|
32
|
-
var SandboxError = class extends VitehubError {
|
|
33
|
-
constructor(message, metadata) {
|
|
34
|
-
super(message, metadata);
|
|
35
|
-
this.name = "SandboxError";
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
//#endregion
|
|
39
|
-
//#region src/internal/shared/utils.ts
|
|
40
|
-
async function sleep(ms) {
|
|
41
|
-
await new Promise((resolve) => setTimeout(resolve, ms));
|
|
42
|
-
}
|
|
43
|
-
//#endregion
|
|
44
|
-
export { VitehubError as i, SandboxError as n, NotSupportedError as r, sleep as t };
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
//#region src/sandbox/providers/vercel-runtime.ts
|
|
2
|
-
const VERCEL_SANDBOX_RUNTIMES = ["node22", "node24"];
|
|
3
|
-
function normalizeVercelSandboxRuntime(runtime) {
|
|
4
|
-
if (!runtime) return "node24";
|
|
5
|
-
return runtime;
|
|
6
|
-
}
|
|
7
|
-
function isSupportedVercelSandboxRuntime(runtime) {
|
|
8
|
-
return VERCEL_SANDBOX_RUNTIMES.includes(runtime);
|
|
9
|
-
}
|
|
10
|
-
//#endregion
|
|
11
|
-
export { normalizeVercelSandboxRuntime as n, isSupportedVercelSandboxRuntime as t };
|
|
File without changes
|