@vercel/sandbox 2.0.0-beta.13 → 2.0.0-beta.18

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.
Files changed (79) hide show
  1. package/dist/api-client/api-client.cjs +3 -15
  2. package/dist/api-client/api-client.cjs.map +1 -1
  3. package/dist/api-client/api-client.d.cts +5510 -76
  4. package/dist/api-client/api-client.d.ts +5510 -76
  5. package/dist/api-client/api-client.js +4 -16
  6. package/dist/api-client/api-client.js.map +1 -1
  7. package/dist/api-client/base-client.cjs +2 -1
  8. package/dist/api-client/base-client.cjs.map +1 -1
  9. package/dist/api-client/base-client.js +2 -1
  10. package/dist/api-client/base-client.js.map +1 -1
  11. package/dist/api-client/index.d.ts +1 -1
  12. package/dist/api-client/index.js +1 -1
  13. package/dist/api-client/validators.cjs +60 -16
  14. package/dist/api-client/validators.cjs.map +1 -1
  15. package/dist/api-client/validators.d.cts +25546 -130
  16. package/dist/api-client/validators.d.ts +25546 -130
  17. package/dist/api-client/validators.js +55 -16
  18. package/dist/api-client/validators.js.map +1 -1
  19. package/dist/auth/api.cjs +1 -1
  20. package/dist/auth/api.cjs.map +1 -1
  21. package/dist/auth/api.js +1 -1
  22. package/dist/auth/api.js.map +1 -1
  23. package/dist/auth/file.d.cts +3 -3
  24. package/dist/auth/file.d.ts +3 -3
  25. package/dist/auth/index.cjs +0 -1
  26. package/dist/auth/index.d.cts +2 -2
  27. package/dist/auth/index.d.ts +2 -2
  28. package/dist/auth/index.js +2 -2
  29. package/dist/auth/project.cjs +124 -26
  30. package/dist/auth/project.cjs.map +1 -1
  31. package/dist/auth/project.d.cts +9 -13
  32. package/dist/auth/project.d.ts +9 -13
  33. package/dist/auth/project.js +125 -26
  34. package/dist/auth/project.js.map +1 -1
  35. package/dist/filesystem.cjs +499 -0
  36. package/dist/filesystem.cjs.map +1 -0
  37. package/dist/filesystem.d.cts +258 -0
  38. package/dist/filesystem.d.ts +258 -0
  39. package/dist/filesystem.js +497 -0
  40. package/dist/filesystem.js.map +1 -0
  41. package/dist/index.cjs +2 -0
  42. package/dist/index.d.cts +4 -3
  43. package/dist/index.d.ts +4 -3
  44. package/dist/index.js +2 -1
  45. package/dist/network-policy.d.cts +58 -2
  46. package/dist/network-policy.d.ts +58 -2
  47. package/dist/sandbox.cjs +138 -22
  48. package/dist/sandbox.cjs.map +1 -1
  49. package/dist/sandbox.d.cts +2069 -22
  50. package/dist/sandbox.d.ts +2069 -22
  51. package/dist/sandbox.js +138 -22
  52. package/dist/sandbox.js.map +1 -1
  53. package/dist/session.cjs +10 -7
  54. package/dist/session.cjs.map +1 -1
  55. package/dist/session.d.cts +7 -5
  56. package/dist/session.d.ts +7 -5
  57. package/dist/session.js +10 -7
  58. package/dist/session.js.map +1 -1
  59. package/dist/snapshot.cjs +63 -10
  60. package/dist/snapshot.cjs.map +1 -1
  61. package/dist/snapshot.d.cts +41 -9
  62. package/dist/snapshot.d.ts +41 -9
  63. package/dist/snapshot.js +62 -10
  64. package/dist/snapshot.js.map +1 -1
  65. package/dist/utils/network-policy.cjs +23 -39
  66. package/dist/utils/network-policy.cjs.map +1 -1
  67. package/dist/utils/network-policy.js +23 -39
  68. package/dist/utils/network-policy.js.map +1 -1
  69. package/dist/utils/paginator.cjs +41 -0
  70. package/dist/utils/paginator.cjs.map +1 -0
  71. package/dist/utils/paginator.d.cts +16 -0
  72. package/dist/utils/paginator.d.ts +16 -0
  73. package/dist/utils/paginator.js +40 -0
  74. package/dist/utils/paginator.js.map +1 -0
  75. package/dist/version.cjs +1 -1
  76. package/dist/version.cjs.map +1 -1
  77. package/dist/version.js +1 -1
  78. package/dist/version.js.map +1 -1
  79. package/package.json +1 -1
@@ -0,0 +1,499 @@
1
+ const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
2
+ let node_constants = require("node:constants");
3
+ node_constants = require_rolldown_runtime.__toESM(node_constants);
4
+
5
+ //#region src/filesystem.ts
6
+ const { S_IFMT, S_IFREG, S_IFDIR, S_IFLNK, S_IFBLK, S_IFCHR, S_IFIFO, S_IFSOCK } = node_constants;
7
+ const UV_DIRENT_FILE = 1;
8
+ const UV_DIRENT_DIR = 2;
9
+ const UV_DIRENT_LINK = 3;
10
+ const UV_DIRENT_FIFO = 4;
11
+ const UV_DIRENT_SOCKET = 5;
12
+ const UV_DIRENT_CHAR = 6;
13
+ const UV_DIRENT_BLOCK = 7;
14
+ function fsError(code, message, syscall, path) {
15
+ const err = /* @__PURE__ */ new Error(`${code}: ${message}, ${syscall} '${path}'`);
16
+ err.code = code;
17
+ err.syscall = syscall;
18
+ err.path = path;
19
+ return err;
20
+ }
21
+ function parseEncoding(options) {
22
+ if (options === null || options === void 0) return { encoding: null };
23
+ if (typeof options === "string") return { encoding: options };
24
+ return {
25
+ encoding: options.encoding ?? null,
26
+ signal: options.signal
27
+ };
28
+ }
29
+ var SandboxStats = class {
30
+ constructor(dev, _mode, nlink, uid, gid, rdev, blksize, ino, size, blocks, atimeMs, mtimeMs, ctimeMs, birthtimeMs) {
31
+ this.dev = dev;
32
+ this._mode = _mode;
33
+ this.nlink = nlink;
34
+ this.uid = uid;
35
+ this.gid = gid;
36
+ this.rdev = rdev;
37
+ this.blksize = blksize;
38
+ this.ino = ino;
39
+ this.size = size;
40
+ this.blocks = blocks;
41
+ this.atimeMs = atimeMs;
42
+ this.mtimeMs = mtimeMs;
43
+ this.ctimeMs = ctimeMs;
44
+ this.birthtimeMs = birthtimeMs;
45
+ this.atime = new Date(atimeMs);
46
+ this.mtime = new Date(mtimeMs);
47
+ this.ctime = new Date(ctimeMs);
48
+ this.birthtime = new Date(birthtimeMs);
49
+ }
50
+ get mode() {
51
+ return this._mode;
52
+ }
53
+ isFile() {
54
+ return (this.mode & S_IFMT) === S_IFREG;
55
+ }
56
+ isDirectory() {
57
+ return (this.mode & S_IFMT) === S_IFDIR;
58
+ }
59
+ isBlockDevice() {
60
+ return (this.mode & S_IFMT) === S_IFBLK;
61
+ }
62
+ isCharacterDevice() {
63
+ return (this.mode & S_IFMT) === S_IFCHR;
64
+ }
65
+ isSymbolicLink() {
66
+ return (this.mode & S_IFMT) === S_IFLNK;
67
+ }
68
+ isFIFO() {
69
+ return (this.mode & S_IFMT) === S_IFIFO;
70
+ }
71
+ isSocket() {
72
+ return (this.mode & S_IFMT) === S_IFSOCK;
73
+ }
74
+ };
75
+ var SandboxDirent = class {
76
+ constructor(name, type, parentPath) {
77
+ this.name = name;
78
+ this.type = type;
79
+ this.parentPath = parentPath;
80
+ this.path = `${this.parentPath}/${this.name}`;
81
+ }
82
+ isFile() {
83
+ return this.type === UV_DIRENT_FILE;
84
+ }
85
+ isDirectory() {
86
+ return this.type === UV_DIRENT_DIR;
87
+ }
88
+ isBlockDevice() {
89
+ return this.type === UV_DIRENT_BLOCK;
90
+ }
91
+ isCharacterDevice() {
92
+ return this.type === UV_DIRENT_CHAR;
93
+ }
94
+ isSymbolicLink() {
95
+ return this.type === UV_DIRENT_LINK;
96
+ }
97
+ isFIFO() {
98
+ return this.type === UV_DIRENT_FIFO;
99
+ }
100
+ isSocket() {
101
+ return this.type === UV_DIRENT_SOCKET;
102
+ }
103
+ };
104
+ function parseStat(stdout) {
105
+ const parts = stdout.trim().split("|");
106
+ return new SandboxStats(parseInt(parts[10], 10), parseInt(parts[1], 16), parseInt(parts[8], 10), parseInt(parts[2], 10), parseInt(parts[3], 10), 0, parseInt(parts[11], 10), parseInt(parts[9], 10), parseInt(parts[0], 10), parseInt(parts[12], 10), parseFloat(parts[4]) * 1e3, parseFloat(parts[5]) * 1e3, parseFloat(parts[6]) * 1e3, parseFloat(parts[7]) * 1e3);
107
+ }
108
+ function parseDirent(stdout, path) {
109
+ const parts = stdout.trim().split("|");
110
+ const name = parts[0];
111
+ const type = parts[1];
112
+ if (!name) throw fsError("ENOENT", "no such file or directory", "readdir", path);
113
+ if (!type) throw new Error(`Invalid dirent type: ${type}`);
114
+ return new SandboxDirent(name, FIND_TYPE_TO_DIRENT[type] ?? UV_DIRENT_FILE, path);
115
+ }
116
+ const STAT_FORMAT = "%s|%f|%u|%g|%X|%Y|%Z|%W|%h|%i|%d|%B|%b";
117
+ const FIND_TYPE_TO_DIRENT = {
118
+ f: UV_DIRENT_FILE,
119
+ d: UV_DIRENT_DIR,
120
+ l: UV_DIRENT_LINK,
121
+ b: UV_DIRENT_BLOCK,
122
+ c: UV_DIRENT_CHAR,
123
+ p: UV_DIRENT_FIFO,
124
+ s: UV_DIRENT_SOCKET
125
+ };
126
+ var FileSystem = class {
127
+ /** @internal */
128
+ constructor(sandbox) {
129
+ this.sandbox = sandbox;
130
+ }
131
+ async readFile(path, options) {
132
+ "use step";
133
+ const { encoding, signal } = parseEncoding(options);
134
+ const buffer = await this.sandbox.readFileToBuffer({ path }, { signal });
135
+ if (buffer === null) throw fsError("ENOENT", "no such file or directory", "open", path);
136
+ return encoding ? buffer.toString(encoding) : buffer;
137
+ }
138
+ /**
139
+ * Write data to a file, replacing the file if it already exists.
140
+ *
141
+ * @param path - Path to the file
142
+ * @param data - The data to write
143
+ * @param options - Write options
144
+ */
145
+ async writeFile(path, data, options) {
146
+ "use step";
147
+ const { encoding, signal } = typeof options === "string" ? {
148
+ encoding: options,
149
+ signal: void 0
150
+ } : {
151
+ encoding: options?.encoding,
152
+ signal: options?.signal
153
+ };
154
+ let content;
155
+ if (typeof data === "string") content = Buffer.from(data, encoding ?? "utf8");
156
+ else if (Buffer.isBuffer(data)) content = data;
157
+ else content = Buffer.from(data);
158
+ await this.sandbox.writeFiles([{
159
+ path,
160
+ content
161
+ }], { signal });
162
+ }
163
+ /**
164
+ * Append data to a file, creating the file if it does not yet exist.
165
+ *
166
+ * @param path - Path to the file
167
+ * @param data - The data to append
168
+ * @param options - Write options
169
+ */
170
+ async appendFile(path, data, options) {
171
+ "use step";
172
+ const { encoding, signal } = typeof options === "string" ? {
173
+ encoding: options,
174
+ signal: void 0
175
+ } : {
176
+ encoding: options?.encoding,
177
+ signal: options?.signal
178
+ };
179
+ let appendContent;
180
+ if (typeof data === "string") appendContent = Buffer.from(data, encoding ?? "utf8");
181
+ else if (Buffer.isBuffer(data)) appendContent = data;
182
+ else appendContent = Buffer.from(data);
183
+ const existing = await this.sandbox.readFileToBuffer({ path }, { signal });
184
+ const content = existing !== null ? Buffer.concat([existing, appendContent]) : appendContent;
185
+ await this.sandbox.writeFiles([{
186
+ path,
187
+ content
188
+ }], { signal });
189
+ }
190
+ /**
191
+ * Create a directory.
192
+ *
193
+ * @param path - Path of the directory to create
194
+ * @param options - Options for directory creation
195
+ */
196
+ async mkdir(path, options) {
197
+ "use step";
198
+ const opts = typeof options === "number" ? { recursive: false } : options ?? {};
199
+ if (opts.recursive) {
200
+ const result = await this.sandbox.runCommand("mkdir", ["-p", path], { signal: opts.signal });
201
+ if (result.exitCode !== 0) throw fsError("EACCES", (await result.stderr()).trim() || "permission denied", "mkdir", path);
202
+ return;
203
+ }
204
+ await this.sandbox.mkDir(path, { signal: opts.signal });
205
+ }
206
+ async readdir(path, options) {
207
+ "use step";
208
+ if (options?.withFileTypes) {
209
+ const result$1 = await this.sandbox.runCommand("find", [
210
+ path,
211
+ "-maxdepth",
212
+ "1",
213
+ "-mindepth",
214
+ "1",
215
+ "-printf",
216
+ "%f|%y\\n"
217
+ ], { signal: options?.signal });
218
+ if (result$1.exitCode !== 0) {
219
+ const stderr = await result$1.stderr();
220
+ if (stderr.includes("No such file or directory")) throw fsError("ENOENT", "no such file or directory", "scandir", path);
221
+ throw fsError("EACCES", stderr.trim(), "scandir", path);
222
+ }
223
+ return (await result$1.stdout()).trim().split("\n").filter(Boolean).map((line) => parseDirent(line, path));
224
+ }
225
+ const result = await this.sandbox.runCommand("ls", ["-1", path], { signal: options?.signal });
226
+ if (result.exitCode !== 0) {
227
+ const stderr = await result.stderr();
228
+ if (stderr.includes("No such file or directory")) throw fsError("ENOENT", "no such file or directory", "scandir", path);
229
+ throw fsError("EACCES", stderr.trim(), "scandir", path);
230
+ }
231
+ return (await result.stdout()).trim().split("\n").filter(Boolean);
232
+ }
233
+ /**
234
+ * Get file status. Follows symbolic links.
235
+ *
236
+ * @param path - Path to the file
237
+ * @param options - Options
238
+ */
239
+ async stat(path, options) {
240
+ "use step";
241
+ const result = await this.sandbox.runCommand("stat", [
242
+ "-L",
243
+ "-c",
244
+ STAT_FORMAT,
245
+ path
246
+ ], { signal: options?.signal });
247
+ if (result.exitCode !== 0) {
248
+ const stderr = await result.stderr();
249
+ if (stderr.includes("No such file or directory")) throw fsError("ENOENT", "no such file or directory", "stat", path);
250
+ throw fsError("EACCES", stderr.trim(), "stat", path);
251
+ }
252
+ return parseStat(await result.stdout());
253
+ }
254
+ /**
255
+ * Get file status. Does not follow symbolic links.
256
+ *
257
+ * @param path - Path to the file
258
+ * @param options - Options
259
+ */
260
+ async lstat(path, options) {
261
+ "use step";
262
+ const result = await this.sandbox.runCommand("stat", [
263
+ "-c",
264
+ STAT_FORMAT,
265
+ path
266
+ ], { signal: options?.signal });
267
+ if (result.exitCode !== 0) {
268
+ const stderr = await result.stderr();
269
+ if (stderr.includes("No such file or directory")) throw fsError("ENOENT", "no such file or directory", "lstat", path);
270
+ throw fsError("EACCES", stderr.trim(), "lstat", path);
271
+ }
272
+ return parseStat(await result.stdout());
273
+ }
274
+ /**
275
+ * Remove a file or symbolic link.
276
+ *
277
+ * @param path - Path to the file
278
+ * @param options - Options
279
+ */
280
+ async unlink(path, options) {
281
+ "use step";
282
+ const result = await this.sandbox.runCommand("rm", [path], { signal: options?.signal });
283
+ if (result.exitCode !== 0) {
284
+ const stderr = await result.stderr();
285
+ if (stderr.includes("No such file or directory")) throw fsError("ENOENT", "no such file or directory", "unlink", path);
286
+ throw fsError("EACCES", stderr.trim(), "unlink", path);
287
+ }
288
+ }
289
+ /**
290
+ * Remove files and directories.
291
+ *
292
+ * @param path - Path to remove
293
+ * @param options - Options
294
+ */
295
+ async rm(path, options) {
296
+ "use step";
297
+ const args = [];
298
+ if (options?.recursive) args.push("-r");
299
+ if (options?.force) args.push("-f");
300
+ args.push(path);
301
+ const result = await this.sandbox.runCommand("rm", args, { signal: options?.signal });
302
+ if (result.exitCode !== 0) {
303
+ const stderr = await result.stderr();
304
+ if (stderr.includes("No such file or directory")) throw fsError("ENOENT", "no such file or directory", "rm", path);
305
+ throw fsError("EACCES", stderr.trim(), "rm", path);
306
+ }
307
+ }
308
+ /**
309
+ * Remove a directory.
310
+ *
311
+ * @param path - Path to the directory
312
+ * @param options - Options
313
+ */
314
+ async rmdir(path, options) {
315
+ "use step";
316
+ const result = await this.sandbox.runCommand("rmdir", [path], { signal: options?.signal });
317
+ if (result.exitCode !== 0) {
318
+ const stderr = await result.stderr();
319
+ if (stderr.includes("No such file or directory")) throw fsError("ENOENT", "no such file or directory", "rmdir", path);
320
+ if (stderr.includes("not empty")) throw fsError("ENOTEMPTY", "directory not empty", "rmdir", path);
321
+ throw fsError("EACCES", stderr.trim(), "rmdir", path);
322
+ }
323
+ }
324
+ /**
325
+ * Rename a file or directory.
326
+ *
327
+ * @param oldPath - Current path
328
+ * @param newPath - New path
329
+ * @param options - Options
330
+ */
331
+ async rename(oldPath, newPath, options) {
332
+ "use step";
333
+ const result = await this.sandbox.runCommand("mv", [oldPath, newPath], { signal: options?.signal });
334
+ if (result.exitCode !== 0) {
335
+ const stderr = await result.stderr();
336
+ if (stderr.includes("No such file or directory")) throw fsError("ENOENT", "no such file or directory", "rename", oldPath);
337
+ throw fsError("EACCES", stderr.trim(), "rename", oldPath);
338
+ }
339
+ }
340
+ /**
341
+ * Copy a file.
342
+ *
343
+ * @param src - Source path
344
+ * @param dest - Destination path
345
+ * @param options - Options
346
+ */
347
+ async copyFile(src, dest, options) {
348
+ "use step";
349
+ const result = await this.sandbox.runCommand("cp", [src, dest], { signal: options?.signal });
350
+ if (result.exitCode !== 0) {
351
+ const stderr = await result.stderr();
352
+ if (stderr.includes("No such file or directory")) throw fsError("ENOENT", "no such file or directory", "copyfile", src);
353
+ throw fsError("EACCES", stderr.trim(), "copyfile", src);
354
+ }
355
+ }
356
+ /**
357
+ * Test whether a file exists and the user has the specified permissions.
358
+ *
359
+ * @param path - Path to the file
360
+ * @param options - Options
361
+ */
362
+ async access(path, options) {
363
+ "use step";
364
+ if ((await this.sandbox.runCommand("test", ["-e", path], { signal: options?.signal })).exitCode !== 0) throw fsError("ENOENT", "no such file or directory", "access", path);
365
+ }
366
+ /**
367
+ * Check if a path exists.
368
+ *
369
+ * This is a convenience method not in `node:fs/promises` but commonly needed.
370
+ *
371
+ * @param path - Path to check
372
+ * @param options - Options
373
+ */
374
+ async exists(path, options) {
375
+ return (await this.sandbox.runCommand("test", ["-e", path], { signal: options?.signal })).exitCode === 0;
376
+ }
377
+ /**
378
+ * Change file mode (permissions).
379
+ *
380
+ * @param path - Path to the file
381
+ * @param mode - File mode (e.g., 0o755 or "755")
382
+ * @param options - Options
383
+ */
384
+ async chmod(path, mode, options) {
385
+ "use step";
386
+ const modeStr = typeof mode === "number" ? mode.toString(8) : mode;
387
+ const result = await this.sandbox.runCommand("chmod", [modeStr, path], { signal: options?.signal });
388
+ if (result.exitCode !== 0) {
389
+ const stderr = await result.stderr();
390
+ if (stderr.includes("No such file or directory")) throw fsError("ENOENT", "no such file or directory", "chmod", path);
391
+ throw fsError("EACCES", stderr.trim(), "chmod", path);
392
+ }
393
+ }
394
+ /**
395
+ * Change file owner and group.
396
+ *
397
+ * @param path - Path to the file
398
+ * @param uid - User ID
399
+ * @param gid - Group ID
400
+ * @param options - Options
401
+ */
402
+ async chown(path, uid, gid, options) {
403
+ "use step";
404
+ const result = await this.sandbox.runCommand("chown", [`${uid}:${gid}`, path], { signal: options?.signal });
405
+ if (result.exitCode !== 0) {
406
+ const stderr = await result.stderr();
407
+ if (stderr.includes("No such file or directory")) throw fsError("ENOENT", "no such file or directory", "chown", path);
408
+ throw fsError("EACCES", stderr.trim(), "chown", path);
409
+ }
410
+ }
411
+ /**
412
+ * Create a symbolic link.
413
+ *
414
+ * @param target - The target of the symbolic link
415
+ * @param path - The path of the symbolic link to create
416
+ * @param options - Options
417
+ */
418
+ async symlink(target, path, options) {
419
+ "use step";
420
+ const result = await this.sandbox.runCommand("ln", [
421
+ "-s",
422
+ target,
423
+ path
424
+ ], { signal: options?.signal });
425
+ if (result.exitCode !== 0) {
426
+ const stderr = await result.stderr();
427
+ if (stderr.includes("File exists")) throw fsError("EEXIST", "file already exists", "symlink", path);
428
+ throw fsError("EACCES", stderr.trim(), "symlink", path);
429
+ }
430
+ }
431
+ /**
432
+ * Read the value of a symbolic link.
433
+ *
434
+ * @param path - Path to the symbolic link
435
+ * @param options - Options
436
+ */
437
+ async readlink(path, options) {
438
+ "use step";
439
+ const result = await this.sandbox.runCommand("readlink", [path], { signal: options?.signal });
440
+ if (result.exitCode !== 0) {
441
+ if ((await result.stderr()).includes("No such file or directory")) throw fsError("ENOENT", "no such file or directory", "readlink", path);
442
+ throw fsError("EINVAL", "invalid argument", "readlink", path);
443
+ }
444
+ return (await result.stdout()).trim();
445
+ }
446
+ /**
447
+ * Resolve the real path of a file (resolving symlinks).
448
+ *
449
+ * @param path - Path to resolve
450
+ * @param options - Options
451
+ */
452
+ async realpath(path, options) {
453
+ "use step";
454
+ const result = await this.sandbox.runCommand("realpath", [path], { signal: options?.signal });
455
+ if (result.exitCode !== 0) {
456
+ const stderr = await result.stderr();
457
+ if (stderr.includes("No such file or directory")) throw fsError("ENOENT", "no such file or directory", "realpath", path);
458
+ throw fsError("EACCES", stderr.trim(), "realpath", path);
459
+ }
460
+ return (await result.stdout()).trim();
461
+ }
462
+ /**
463
+ * Truncate a file to a specified length.
464
+ *
465
+ * @param path - Path to the file
466
+ * @param len - Length to truncate to (default: 0)
467
+ * @param options - Options
468
+ */
469
+ async truncate(path, len, options) {
470
+ "use step";
471
+ const result = await this.sandbox.runCommand("truncate", [
472
+ "-s",
473
+ String(len ?? 0),
474
+ path
475
+ ], { signal: options?.signal });
476
+ if (result.exitCode !== 0) {
477
+ const stderr = await result.stderr();
478
+ if (stderr.includes("No such file or directory")) throw fsError("ENOENT", "no such file or directory", "truncate", path);
479
+ throw fsError("EACCES", stderr.trim(), "truncate", path);
480
+ }
481
+ }
482
+ /**
483
+ * Create a unique temporary directory.
484
+ *
485
+ * @param prefix - The prefix for the temporary directory name
486
+ * @param options - Options
487
+ * @returns The path of the created temporary directory
488
+ */
489
+ async mkdtemp(prefix, options) {
490
+ "use step";
491
+ const result = await this.sandbox.runCommand("mktemp", ["-d", `${prefix}XXXXXX`], { signal: options?.signal });
492
+ if (result.exitCode !== 0) throw fsError("EACCES", (await result.stderr()).trim(), "mkdtemp", prefix);
493
+ return (await result.stdout()).trim();
494
+ }
495
+ };
496
+
497
+ //#endregion
498
+ exports.FileSystem = FileSystem;
499
+ //# sourceMappingURL=filesystem.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"filesystem.cjs","names":["constants","dev: number","_mode: number","nlink: number","uid: number","gid: number","rdev: number","blksize: number","ino: number","size: number","blocks: number","atimeMs: number","mtimeMs: number","ctimeMs: number","birthtimeMs: number","name: string","type: number","parentPath: string","FIND_TYPE_TO_DIRENT: Record<string, number>","content: Buffer","appendContent: Buffer","result","args: string[]"],"sources":["../src/filesystem.ts"],"sourcesContent":["import type { Stats, Dirent } from \"fs\";\nimport * as constants from \"node:constants\";\n\nconst {\n S_IFMT,\n S_IFREG,\n S_IFDIR,\n S_IFLNK,\n S_IFBLK,\n S_IFCHR,\n S_IFIFO,\n S_IFSOCK,\n} = constants;\n\n// https://github.com/nodejs/node/blob/main/deps/uv/include/uv.h#L1267-L1276\n// exposed through node:constants but not in @types/node\nconst UV_DIRENT_FILE = 1;\nconst UV_DIRENT_DIR = 2;\nconst UV_DIRENT_LINK = 3;\nconst UV_DIRENT_FIFO = 4;\nconst UV_DIRENT_SOCKET = 5;\nconst UV_DIRENT_CHAR = 6;\nconst UV_DIRENT_BLOCK = 7;\n\ntype EncodingOption =\n | { encoding?: BufferEncoding | null; signal?: AbortSignal }\n | BufferEncoding\n | null;\n\ntype WriteFileData = string | Buffer | Uint8Array;\n\ninterface MkdirOptions {\n recursive?: boolean;\n signal?: AbortSignal;\n}\n\ninterface RmOptions {\n recursive?: boolean;\n force?: boolean;\n signal?: AbortSignal;\n}\n\nfunction fsError(\n code: string,\n message: string,\n syscall: string,\n path: string,\n): Error & { code: string; syscall: string; path: string } {\n const err = new Error(\n `${code}: ${message}, ${syscall} '${path}'`,\n ) as Error & {\n code: string;\n syscall: string;\n path: string;\n };\n err.code = code;\n err.syscall = syscall;\n err.path = path;\n return err;\n}\n\ninterface SandboxHandle {\n readFileToBuffer(\n file: { path: string },\n opts?: { signal?: AbortSignal },\n ): Promise<Buffer | null>;\n writeFiles(\n files: { path: string; content: Buffer }[],\n opts?: { signal?: AbortSignal },\n ): Promise<void>;\n mkDir(path: string, opts?: { signal?: AbortSignal }): Promise<void>;\n runCommand(\n cmd: string,\n args?: string[],\n opts?: { signal?: AbortSignal },\n ): Promise<{\n exitCode: number;\n stdout(opts?: { signal?: AbortSignal }): Promise<string>;\n stderr(opts?: { signal?: AbortSignal }): Promise<string>;\n }>;\n}\n\nfunction parseEncoding(options?: EncodingOption): {\n encoding: BufferEncoding | null;\n signal?: AbortSignal;\n} {\n if (options === null || options === undefined) {\n return { encoding: null };\n }\n if (typeof options === \"string\") {\n return { encoding: options };\n }\n return { encoding: options.encoding ?? null, signal: options.signal };\n}\n\nclass SandboxStats {\n readonly atime: Date;\n readonly mtime: Date;\n readonly ctime: Date;\n readonly birthtime: Date;\n\n constructor(\n readonly dev: number,\n private readonly _mode: number,\n readonly nlink: number,\n readonly uid: number,\n readonly gid: number,\n readonly rdev: number,\n readonly blksize: number,\n readonly ino: number,\n readonly size: number,\n readonly blocks: number,\n readonly atimeMs: number,\n readonly mtimeMs: number,\n readonly ctimeMs: number,\n readonly birthtimeMs: number,\n ) {\n this.atime = new Date(atimeMs);\n this.mtime = new Date(mtimeMs);\n this.ctime = new Date(ctimeMs);\n this.birthtime = new Date(birthtimeMs);\n }\n\n get mode(): number {\n return this._mode;\n }\n\n isFile(): boolean {\n return (this.mode & S_IFMT) === S_IFREG;\n }\n isDirectory(): boolean {\n return (this.mode & S_IFMT) === S_IFDIR;\n }\n isBlockDevice(): boolean {\n return (this.mode & S_IFMT) === S_IFBLK;\n }\n isCharacterDevice(): boolean {\n return (this.mode & S_IFMT) === S_IFCHR;\n }\n isSymbolicLink(): boolean {\n return (this.mode & S_IFMT) === S_IFLNK;\n }\n isFIFO(): boolean {\n return (this.mode & S_IFMT) === S_IFIFO;\n }\n isSocket(): boolean {\n return (this.mode & S_IFMT) === S_IFSOCK;\n }\n}\n\nclass SandboxDirent {\n readonly path: string;\n\n constructor(\n public name: string,\n private type: number,\n public parentPath: string,\n ) {\n this.path = `${this.parentPath}/${this.name}`;\n }\n\n isFile(): boolean {\n return this.type === UV_DIRENT_FILE;\n }\n isDirectory(): boolean {\n return this.type === UV_DIRENT_DIR;\n }\n isBlockDevice(): boolean {\n return this.type === UV_DIRENT_BLOCK;\n }\n isCharacterDevice(): boolean {\n return this.type === UV_DIRENT_CHAR;\n }\n isSymbolicLink(): boolean {\n return this.type === UV_DIRENT_LINK;\n }\n isFIFO(): boolean {\n return this.type === UV_DIRENT_FIFO;\n }\n isSocket(): boolean {\n return this.type === UV_DIRENT_SOCKET;\n }\n}\n\nfunction parseStat(stdout: string) {\n // Format: size|rawModeHex|uid|gid|atimeMs|mtimeMs|ctimeMs|birthtimeMs|nlink|ino|dev|blksize|blocks\n const parts = stdout.trim().split(\"|\");\n\n return new SandboxStats(\n parseInt(parts[10]!, 10), // dev\n parseInt(parts[1]!, 16), // mode (raw mode from %f, hex)\n parseInt(parts[8]!, 10), // nlink\n parseInt(parts[2]!, 10), // uid\n parseInt(parts[3]!, 10), // gid\n 0, // rdev\n parseInt(parts[11]!, 10), // blksize\n parseInt(parts[9]!, 10), // ino\n parseInt(parts[0]!, 10), // size\n parseInt(parts[12]!, 10), // blocks\n parseFloat(parts[4]!) * 1000, // atimeMs\n parseFloat(parts[5]!) * 1000, // mtimeMs\n parseFloat(parts[6]!) * 1000, // ctimeMs\n parseFloat(parts[7]!) * 1000, // birthtimeMs\n ) satisfies Stats;\n}\n\nfunction parseDirent(stdout: string, path: string) {\n const parts = stdout.trim().split(\"|\");\n const name = parts[0];\n const type = parts[1];\n\n if (!name) {\n throw fsError(\"ENOENT\", \"no such file or directory\", \"readdir\", path);\n }\n\n if (!type) {\n throw new Error(`Invalid dirent type: ${type}`);\n }\n\n const direntType = FIND_TYPE_TO_DIRENT[type] ?? UV_DIRENT_FILE;\n return new SandboxDirent(name, direntType, path) satisfies Dirent;\n}\n\n// %f = raw mode in hex, includes file type bits so Stats.isFile()/isDirectory()/etc. work\nconst STAT_FORMAT = \"%s|%f|%u|%g|%X|%Y|%Z|%W|%h|%i|%d|%B|%b\";\n\nconst FIND_TYPE_TO_DIRENT: Record<string, number> = {\n f: UV_DIRENT_FILE,\n d: UV_DIRENT_DIR,\n l: UV_DIRENT_LINK,\n b: UV_DIRENT_BLOCK,\n c: UV_DIRENT_CHAR,\n p: UV_DIRENT_FIFO,\n s: UV_DIRENT_SOCKET,\n};\n\nexport class FileSystem {\n /** @internal */\n private sandbox: SandboxHandle;\n\n /** @internal */\n constructor(sandbox: SandboxHandle) {\n this.sandbox = sandbox;\n }\n\n /**\n * Read the entire contents of a file.\n *\n * @param path - Path to the file\n * @param options - Encoding or options object. If encoding is specified, returns a string; otherwise returns a Buffer.\n */\n async readFile(\n path: string,\n options?: { encoding?: null; signal?: AbortSignal } | null,\n ): Promise<Buffer>;\n async readFile(\n path: string,\n options:\n | { encoding: BufferEncoding; signal?: AbortSignal }\n | BufferEncoding,\n ): Promise<string>;\n async readFile(\n path: string,\n options?: EncodingOption,\n ): Promise<Buffer | string> {\n \"use step\";\n const { encoding, signal } = parseEncoding(options);\n const buffer = await this.sandbox.readFileToBuffer({ path }, { signal });\n if (buffer === null) {\n throw fsError(\"ENOENT\", \"no such file or directory\", \"open\", path);\n }\n return encoding ? buffer.toString(encoding) : buffer;\n }\n\n /**\n * Write data to a file, replacing the file if it already exists.\n *\n * @param path - Path to the file\n * @param data - The data to write\n * @param options - Write options\n */\n async writeFile(\n path: string,\n data: WriteFileData,\n options?:\n | { encoding?: BufferEncoding; signal?: AbortSignal }\n | BufferEncoding,\n ): Promise<void> {\n \"use step\";\n const { encoding, signal } =\n typeof options === \"string\"\n ? { encoding: options, signal: undefined }\n : { encoding: options?.encoding, signal: options?.signal };\n let content: Buffer;\n if (typeof data === \"string\") {\n content = Buffer.from(data, encoding ?? \"utf8\");\n } else if (Buffer.isBuffer(data)) {\n content = data;\n } else {\n content = Buffer.from(data);\n }\n await this.sandbox.writeFiles([{ path, content }], { signal });\n }\n\n /**\n * Append data to a file, creating the file if it does not yet exist.\n *\n * @param path - Path to the file\n * @param data - The data to append\n * @param options - Write options\n */\n async appendFile(\n path: string,\n data: WriteFileData,\n options?:\n | { encoding?: BufferEncoding; signal?: AbortSignal }\n | BufferEncoding,\n ): Promise<void> {\n \"use step\";\n const { encoding, signal } =\n typeof options === \"string\"\n ? { encoding: options, signal: undefined }\n : { encoding: options?.encoding, signal: options?.signal };\n let appendContent: Buffer;\n if (typeof data === \"string\") {\n appendContent = Buffer.from(data, encoding ?? \"utf8\");\n } else if (Buffer.isBuffer(data)) {\n appendContent = data;\n } else {\n appendContent = Buffer.from(data);\n }\n\n const existing = await this.sandbox.readFileToBuffer({ path }, { signal });\n const content =\n existing !== null\n ? Buffer.concat([existing, appendContent])\n : appendContent;\n await this.sandbox.writeFiles([{ path, content }], { signal });\n }\n\n /**\n * Create a directory.\n *\n * @param path - Path of the directory to create\n * @param options - Options for directory creation\n */\n async mkdir(\n path: string,\n options?: MkdirOptions | number,\n ): Promise<string | undefined> {\n \"use step\";\n const opts =\n typeof options === \"number\" ? { recursive: false } : (options ?? {});\n if (opts.recursive) {\n const result = await this.sandbox.runCommand(\"mkdir\", [\"-p\", path], {\n signal: opts.signal,\n });\n if (result.exitCode !== 0) {\n const stderr = await result.stderr();\n throw fsError(\n \"EACCES\",\n stderr.trim() || \"permission denied\",\n \"mkdir\",\n path,\n );\n }\n return undefined;\n }\n await this.sandbox.mkDir(path, { signal: opts.signal });\n return undefined;\n }\n\n /**\n * Read the contents of a directory.\n *\n * @param path - Path to the directory\n * @param options - Options. When `withFileTypes` is true, returns `Dirent` objects.\n */\n async readdir(\n path: string,\n options?: { signal?: AbortSignal; withFileTypes?: false },\n ): Promise<string[]>;\n async readdir(\n path: string,\n options: { signal?: AbortSignal; withFileTypes: true },\n ): Promise<Dirent[]>;\n async readdir(\n path: string,\n options?: { signal?: AbortSignal; withFileTypes?: boolean },\n ): Promise<string[] | Dirent[]> {\n \"use step\";\n if (options?.withFileTypes) {\n // Use find to get name and type in one pass\n const result = await this.sandbox.runCommand(\n \"find\",\n [path, \"-maxdepth\", \"1\", \"-mindepth\", \"1\", \"-printf\", \"%f|%y\\\\n\"],\n { signal: options?.signal },\n );\n if (result.exitCode !== 0) {\n const stderr = await result.stderr();\n if (stderr.includes(\"No such file or directory\")) {\n throw fsError(\"ENOENT\", \"no such file or directory\", \"scandir\", path);\n }\n throw fsError(\"EACCES\", stderr.trim(), \"scandir\", path);\n }\n const stdout = await result.stdout();\n const lines = stdout.trim().split(\"\\n\").filter(Boolean);\n\n return lines.map((line) => parseDirent(line, path));\n }\n\n const result = await this.sandbox.runCommand(\"ls\", [\"-1\", path], {\n signal: options?.signal,\n });\n if (result.exitCode !== 0) {\n const stderr = await result.stderr();\n if (stderr.includes(\"No such file or directory\")) {\n throw fsError(\"ENOENT\", \"no such file or directory\", \"scandir\", path);\n }\n throw fsError(\"EACCES\", stderr.trim(), \"scandir\", path);\n }\n const stdout = await result.stdout();\n return stdout.trim().split(\"\\n\").filter(Boolean);\n }\n\n /**\n * Get file status. Follows symbolic links.\n *\n * @param path - Path to the file\n * @param options - Options\n */\n async stat(path: string, options?: { signal?: AbortSignal }): Promise<Stats> {\n \"use step\";\n const result = await this.sandbox.runCommand(\n \"stat\",\n [\"-L\", \"-c\", STAT_FORMAT, path],\n { signal: options?.signal },\n );\n if (result.exitCode !== 0) {\n const stderr = await result.stderr();\n if (stderr.includes(\"No such file or directory\")) {\n throw fsError(\"ENOENT\", \"no such file or directory\", \"stat\", path);\n }\n throw fsError(\"EACCES\", stderr.trim(), \"stat\", path);\n }\n return parseStat(await result.stdout());\n }\n\n /**\n * Get file status. Does not follow symbolic links.\n *\n * @param path - Path to the file\n * @param options - Options\n */\n async lstat(\n path: string,\n options?: { signal?: AbortSignal },\n ): Promise<Stats> {\n \"use step\";\n const result = await this.sandbox.runCommand(\n \"stat\",\n [\"-c\", STAT_FORMAT, path],\n { signal: options?.signal },\n );\n if (result.exitCode !== 0) {\n const stderr = await result.stderr();\n if (stderr.includes(\"No such file or directory\")) {\n throw fsError(\"ENOENT\", \"no such file or directory\", \"lstat\", path);\n }\n throw fsError(\"EACCES\", stderr.trim(), \"lstat\", path);\n }\n return parseStat(await result.stdout());\n }\n\n /**\n * Remove a file or symbolic link.\n *\n * @param path - Path to the file\n * @param options - Options\n */\n async unlink(\n path: string,\n options?: { signal?: AbortSignal },\n ): Promise<void> {\n \"use step\";\n const result = await this.sandbox.runCommand(\"rm\", [path], {\n signal: options?.signal,\n });\n if (result.exitCode !== 0) {\n const stderr = await result.stderr();\n if (stderr.includes(\"No such file or directory\")) {\n throw fsError(\"ENOENT\", \"no such file or directory\", \"unlink\", path);\n }\n throw fsError(\"EACCES\", stderr.trim(), \"unlink\", path);\n }\n }\n\n /**\n * Remove files and directories.\n *\n * @param path - Path to remove\n * @param options - Options\n */\n async rm(path: string, options?: RmOptions): Promise<void> {\n \"use step\";\n const args: string[] = [];\n if (options?.recursive) args.push(\"-r\");\n if (options?.force) args.push(\"-f\");\n args.push(path);\n\n const result = await this.sandbox.runCommand(\"rm\", args, {\n signal: options?.signal,\n });\n if (result.exitCode !== 0) {\n const stderr = await result.stderr();\n if (stderr.includes(\"No such file or directory\")) {\n throw fsError(\"ENOENT\", \"no such file or directory\", \"rm\", path);\n }\n throw fsError(\"EACCES\", stderr.trim(), \"rm\", path);\n }\n }\n\n /**\n * Remove a directory.\n *\n * @param path - Path to the directory\n * @param options - Options\n */\n async rmdir(path: string, options?: { signal?: AbortSignal }): Promise<void> {\n \"use step\";\n const result = await this.sandbox.runCommand(\"rmdir\", [path], {\n signal: options?.signal,\n });\n if (result.exitCode !== 0) {\n const stderr = await result.stderr();\n if (stderr.includes(\"No such file or directory\")) {\n throw fsError(\"ENOENT\", \"no such file or directory\", \"rmdir\", path);\n }\n if (stderr.includes(\"not empty\")) {\n throw fsError(\"ENOTEMPTY\", \"directory not empty\", \"rmdir\", path);\n }\n throw fsError(\"EACCES\", stderr.trim(), \"rmdir\", path);\n }\n }\n\n /**\n * Rename a file or directory.\n *\n * @param oldPath - Current path\n * @param newPath - New path\n * @param options - Options\n */\n async rename(\n oldPath: string,\n newPath: string,\n options?: { signal?: AbortSignal },\n ): Promise<void> {\n \"use step\";\n const result = await this.sandbox.runCommand(\"mv\", [oldPath, newPath], {\n signal: options?.signal,\n });\n if (result.exitCode !== 0) {\n const stderr = await result.stderr();\n if (stderr.includes(\"No such file or directory\")) {\n throw fsError(\"ENOENT\", \"no such file or directory\", \"rename\", oldPath);\n }\n throw fsError(\"EACCES\", stderr.trim(), \"rename\", oldPath);\n }\n }\n\n /**\n * Copy a file.\n *\n * @param src - Source path\n * @param dest - Destination path\n * @param options - Options\n */\n async copyFile(\n src: string,\n dest: string,\n options?: { signal?: AbortSignal },\n ): Promise<void> {\n \"use step\";\n const result = await this.sandbox.runCommand(\"cp\", [src, dest], {\n signal: options?.signal,\n });\n if (result.exitCode !== 0) {\n const stderr = await result.stderr();\n if (stderr.includes(\"No such file or directory\")) {\n throw fsError(\"ENOENT\", \"no such file or directory\", \"copyfile\", src);\n }\n throw fsError(\"EACCES\", stderr.trim(), \"copyfile\", src);\n }\n }\n\n /**\n * Test whether a file exists and the user has the specified permissions.\n *\n * @param path - Path to the file\n * @param options - Options\n */\n async access(\n path: string,\n options?: { signal?: AbortSignal },\n ): Promise<void> {\n \"use step\";\n const result = await this.sandbox.runCommand(\"test\", [\"-e\", path], {\n signal: options?.signal,\n });\n if (result.exitCode !== 0) {\n throw fsError(\"ENOENT\", \"no such file or directory\", \"access\", path);\n }\n }\n\n /**\n * Check if a path exists.\n *\n * This is a convenience method not in `node:fs/promises` but commonly needed.\n *\n * @param path - Path to check\n * @param options - Options\n */\n async exists(\n path: string,\n options?: { signal?: AbortSignal },\n ): Promise<boolean> {\n const result = await this.sandbox.runCommand(\"test\", [\"-e\", path], {\n signal: options?.signal,\n });\n return result.exitCode === 0;\n }\n\n /**\n * Change file mode (permissions).\n *\n * @param path - Path to the file\n * @param mode - File mode (e.g., 0o755 or \"755\")\n * @param options - Options\n */\n async chmod(\n path: string,\n mode: number | string,\n options?: { signal?: AbortSignal },\n ): Promise<void> {\n \"use step\";\n const modeStr = typeof mode === \"number\" ? mode.toString(8) : mode;\n const result = await this.sandbox.runCommand(\"chmod\", [modeStr, path], {\n signal: options?.signal,\n });\n if (result.exitCode !== 0) {\n const stderr = await result.stderr();\n if (stderr.includes(\"No such file or directory\")) {\n throw fsError(\"ENOENT\", \"no such file or directory\", \"chmod\", path);\n }\n throw fsError(\"EACCES\", stderr.trim(), \"chmod\", path);\n }\n }\n\n /**\n * Change file owner and group.\n *\n * @param path - Path to the file\n * @param uid - User ID\n * @param gid - Group ID\n * @param options - Options\n */\n async chown(\n path: string,\n uid: number,\n gid: number,\n options?: { signal?: AbortSignal },\n ): Promise<void> {\n \"use step\";\n const result = await this.sandbox.runCommand(\n \"chown\",\n [`${uid}:${gid}`, path],\n { signal: options?.signal },\n );\n if (result.exitCode !== 0) {\n const stderr = await result.stderr();\n if (stderr.includes(\"No such file or directory\")) {\n throw fsError(\"ENOENT\", \"no such file or directory\", \"chown\", path);\n }\n throw fsError(\"EACCES\", stderr.trim(), \"chown\", path);\n }\n }\n\n /**\n * Create a symbolic link.\n *\n * @param target - The target of the symbolic link\n * @param path - The path of the symbolic link to create\n * @param options - Options\n */\n async symlink(\n target: string,\n path: string,\n options?: { signal?: AbortSignal },\n ): Promise<void> {\n \"use step\";\n const result = await this.sandbox.runCommand(\"ln\", [\"-s\", target, path], {\n signal: options?.signal,\n });\n if (result.exitCode !== 0) {\n const stderr = await result.stderr();\n if (stderr.includes(\"File exists\")) {\n throw fsError(\"EEXIST\", \"file already exists\", \"symlink\", path);\n }\n throw fsError(\"EACCES\", stderr.trim(), \"symlink\", path);\n }\n }\n\n /**\n * Read the value of a symbolic link.\n *\n * @param path - Path to the symbolic link\n * @param options - Options\n */\n async readlink(\n path: string,\n options?: { signal?: AbortSignal },\n ): Promise<string> {\n \"use step\";\n const result = await this.sandbox.runCommand(\"readlink\", [path], {\n signal: options?.signal,\n });\n if (result.exitCode !== 0) {\n const stderr = await result.stderr();\n if (stderr.includes(\"No such file or directory\")) {\n throw fsError(\"ENOENT\", \"no such file or directory\", \"readlink\", path);\n }\n throw fsError(\"EINVAL\", \"invalid argument\", \"readlink\", path);\n }\n return (await result.stdout()).trim();\n }\n\n /**\n * Resolve the real path of a file (resolving symlinks).\n *\n * @param path - Path to resolve\n * @param options - Options\n */\n async realpath(\n path: string,\n options?: { signal?: AbortSignal },\n ): Promise<string> {\n \"use step\";\n const result = await this.sandbox.runCommand(\"realpath\", [path], {\n signal: options?.signal,\n });\n if (result.exitCode !== 0) {\n const stderr = await result.stderr();\n if (stderr.includes(\"No such file or directory\")) {\n throw fsError(\"ENOENT\", \"no such file or directory\", \"realpath\", path);\n }\n throw fsError(\"EACCES\", stderr.trim(), \"realpath\", path);\n }\n return (await result.stdout()).trim();\n }\n\n /**\n * Truncate a file to a specified length.\n *\n * @param path - Path to the file\n * @param len - Length to truncate to (default: 0)\n * @param options - Options\n */\n async truncate(\n path: string,\n len?: number,\n options?: { signal?: AbortSignal },\n ): Promise<void> {\n \"use step\";\n const result = await this.sandbox.runCommand(\n \"truncate\",\n [\"-s\", String(len ?? 0), path],\n { signal: options?.signal },\n );\n if (result.exitCode !== 0) {\n const stderr = await result.stderr();\n if (stderr.includes(\"No such file or directory\")) {\n throw fsError(\"ENOENT\", \"no such file or directory\", \"truncate\", path);\n }\n throw fsError(\"EACCES\", stderr.trim(), \"truncate\", path);\n }\n }\n\n /**\n * Create a unique temporary directory.\n *\n * @param prefix - The prefix for the temporary directory name\n * @param options - Options\n * @returns The path of the created temporary directory\n */\n async mkdtemp(\n prefix: string,\n options?: { signal?: AbortSignal },\n ): Promise<string> {\n \"use step\";\n const result = await this.sandbox.runCommand(\n \"mktemp\",\n [\"-d\", `${prefix}XXXXXX`],\n { signal: options?.signal },\n );\n if (result.exitCode !== 0) {\n const stderr = await result.stderr();\n throw fsError(\"EACCES\", stderr.trim(), \"mkdtemp\", prefix);\n }\n return (await result.stdout()).trim();\n }\n}\n"],"mappings":";;;;;AAGA,MAAM,EACJ,QACA,SACA,SACA,SACA,SACA,SACA,SACA,aACEA;AAIJ,MAAM,iBAAiB;AACvB,MAAM,gBAAgB;AACtB,MAAM,iBAAiB;AACvB,MAAM,iBAAiB;AACvB,MAAM,mBAAmB;AACzB,MAAM,iBAAiB;AACvB,MAAM,kBAAkB;AAoBxB,SAAS,QACP,MACA,SACA,SACA,MACyD;CACzD,MAAM,sBAAM,IAAI,MACd,GAAG,KAAK,IAAI,QAAQ,IAAI,QAAQ,IAAI,KAAK,GAC1C;AAKD,KAAI,OAAO;AACX,KAAI,UAAU;AACd,KAAI,OAAO;AACX,QAAO;;AAwBT,SAAS,cAAc,SAGrB;AACA,KAAI,YAAY,QAAQ,YAAY,OAClC,QAAO,EAAE,UAAU,MAAM;AAE3B,KAAI,OAAO,YAAY,SACrB,QAAO,EAAE,UAAU,SAAS;AAE9B,QAAO;EAAE,UAAU,QAAQ,YAAY;EAAM,QAAQ,QAAQ;EAAQ;;AAGvE,IAAM,eAAN,MAAmB;CAMjB,YACE,AAASC,KACT,AAAiBC,OACjB,AAASC,OACT,AAASC,KACT,AAASC,KACT,AAASC,MACT,AAASC,SACT,AAASC,KACT,AAASC,MACT,AAASC,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