@secure-exec/browser 0.0.0-main.bccb3a2
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 +6 -0
- package/dist/driver.d.ts +91 -0
- package/dist/driver.js +350 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +5 -0
- package/dist/os-filesystem.d.ts +47 -0
- package/dist/os-filesystem.js +402 -0
- package/dist/permission-validation.d.ts +15 -0
- package/dist/permission-validation.js +62 -0
- package/dist/runtime-driver.d.ts +34 -0
- package/dist/runtime-driver.js +459 -0
- package/dist/runtime.d.ts +222 -0
- package/dist/runtime.js +377 -0
- package/dist/sync-bridge.d.ts +46 -0
- package/dist/sync-bridge.js +49 -0
- package/dist/worker-adapter.d.ts +21 -0
- package/dist/worker-adapter.js +41 -0
- package/dist/worker-protocol.d.ts +93 -0
- package/dist/worker-protocol.js +1 -0
- package/dist/worker.d.ts +1 -0
- package/dist/worker.js +1399 -0
- package/package.json +80 -0
package/README.md
ADDED
package/dist/driver.d.ts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { NetworkAdapter, Permissions, SystemDriver, VirtualFileSystem } from "./runtime.js";
|
|
2
|
+
import { createCommandExecutorStub, createFsStub, createNetworkStub } from "./runtime.js";
|
|
3
|
+
export interface BrowserRuntimeSystemOptions {
|
|
4
|
+
filesystem: "opfs" | "memory";
|
|
5
|
+
networkEnabled: boolean;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* VFS backed by the Origin Private File System (OPFS) API. Falls back to
|
|
9
|
+
* InMemoryFileSystem when OPFS is unavailable. Rename is not supported
|
|
10
|
+
* (throws ENOSYS) since OPFS doesn't provide atomic rename.
|
|
11
|
+
*/
|
|
12
|
+
export declare class OpfsFileSystem implements VirtualFileSystem {
|
|
13
|
+
private rootPromise;
|
|
14
|
+
constructor();
|
|
15
|
+
private getDirHandle;
|
|
16
|
+
private getFileHandle;
|
|
17
|
+
readFile(path: string): Promise<Uint8Array>;
|
|
18
|
+
readTextFile(path: string): Promise<string>;
|
|
19
|
+
readDir(path: string): Promise<string[]>;
|
|
20
|
+
readDirWithTypes(path: string): Promise<Array<{
|
|
21
|
+
name: string;
|
|
22
|
+
isDirectory: boolean;
|
|
23
|
+
}>>;
|
|
24
|
+
writeFile(path: string, content: string | Uint8Array): Promise<void>;
|
|
25
|
+
createDir(path: string): Promise<void>;
|
|
26
|
+
mkdir(path: string, _options?: {
|
|
27
|
+
recursive?: boolean;
|
|
28
|
+
}): Promise<void>;
|
|
29
|
+
exists(path: string): Promise<boolean>;
|
|
30
|
+
stat(path: string): Promise<{
|
|
31
|
+
mode: number;
|
|
32
|
+
size: number;
|
|
33
|
+
blocks: number;
|
|
34
|
+
dev: number;
|
|
35
|
+
rdev: number;
|
|
36
|
+
isDirectory: boolean;
|
|
37
|
+
isSymbolicLink: boolean;
|
|
38
|
+
atimeMs: number;
|
|
39
|
+
mtimeMs: number;
|
|
40
|
+
ctimeMs: number;
|
|
41
|
+
birthtimeMs: number;
|
|
42
|
+
ino: number;
|
|
43
|
+
nlink: number;
|
|
44
|
+
uid: number;
|
|
45
|
+
gid: number;
|
|
46
|
+
}>;
|
|
47
|
+
removeFile(path: string): Promise<void>;
|
|
48
|
+
removeDir(path: string): Promise<void>;
|
|
49
|
+
rename(_oldPath: string, _newPath: string): Promise<void>;
|
|
50
|
+
symlink(_target: string, _linkPath: string): Promise<void>;
|
|
51
|
+
readlink(_path: string): Promise<string>;
|
|
52
|
+
lstat(path: string): Promise<{
|
|
53
|
+
mode: number;
|
|
54
|
+
size: number;
|
|
55
|
+
blocks: number;
|
|
56
|
+
dev: number;
|
|
57
|
+
rdev: number;
|
|
58
|
+
isDirectory: boolean;
|
|
59
|
+
isSymbolicLink: boolean;
|
|
60
|
+
atimeMs: number;
|
|
61
|
+
mtimeMs: number;
|
|
62
|
+
ctimeMs: number;
|
|
63
|
+
birthtimeMs: number;
|
|
64
|
+
ino: number;
|
|
65
|
+
nlink: number;
|
|
66
|
+
uid: number;
|
|
67
|
+
gid: number;
|
|
68
|
+
}>;
|
|
69
|
+
link(_oldPath: string, _newPath: string): Promise<void>;
|
|
70
|
+
chmod(_path: string, _mode: number): Promise<void>;
|
|
71
|
+
chown(_path: string, _uid: number, _gid: number): Promise<void>;
|
|
72
|
+
utimes(_path: string, _atime: number, _mtime: number): Promise<void>;
|
|
73
|
+
truncate(path: string, length: number): Promise<void>;
|
|
74
|
+
realpath(path: string): Promise<string>;
|
|
75
|
+
pread(path: string, offset: number, length: number): Promise<Uint8Array>;
|
|
76
|
+
pwrite(path: string, offset: number, data: Uint8Array): Promise<void>;
|
|
77
|
+
}
|
|
78
|
+
export interface BrowserDriverOptions {
|
|
79
|
+
filesystem?: "opfs" | "memory";
|
|
80
|
+
permissions?: Permissions;
|
|
81
|
+
useDefaultNetwork?: boolean;
|
|
82
|
+
}
|
|
83
|
+
/** Create an OPFS-backed filesystem, falling back to in-memory if OPFS is unavailable. */
|
|
84
|
+
export declare function createOpfsFileSystem(): Promise<VirtualFileSystem>;
|
|
85
|
+
/** Network adapter that delegates to the browser's native `fetch`. DNS and http2 are unsupported. */
|
|
86
|
+
export declare function createBrowserNetworkAdapter(): NetworkAdapter;
|
|
87
|
+
/** Recover runtime-driver options from a browser SystemDriver instance. */
|
|
88
|
+
export declare function getBrowserSystemDriverOptions(systemDriver: SystemDriver): BrowserRuntimeSystemOptions;
|
|
89
|
+
/** Assemble a browser-side SystemDriver with permission-wrapped adapters. */
|
|
90
|
+
export declare function createBrowserDriver(options?: BrowserDriverOptions): Promise<SystemDriver>;
|
|
91
|
+
export { createCommandExecutorStub, createFsStub, createNetworkStub };
|
package/dist/driver.js
ADDED
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
import { createCommandExecutorStub, createEnosysError, createFsStub, createInMemoryFileSystem, createNetworkStub, wrapFileSystem, wrapNetworkAdapter, } from "./runtime.js";
|
|
2
|
+
const S_IFREG = 0o100000;
|
|
3
|
+
const S_IFDIR = 0o040000;
|
|
4
|
+
const BROWSER_SYSTEM_DRIVER_OPTIONS = Symbol.for("secure-exec.browserSystemDriverOptions");
|
|
5
|
+
function normalizePath(path) {
|
|
6
|
+
if (!path)
|
|
7
|
+
return "/";
|
|
8
|
+
let normalized = path.startsWith("/") ? path : `/${path}`;
|
|
9
|
+
normalized = normalized.replace(/\/+/g, "/");
|
|
10
|
+
if (normalized.length > 1 && normalized.endsWith("/")) {
|
|
11
|
+
normalized = normalized.slice(0, -1);
|
|
12
|
+
}
|
|
13
|
+
return normalized;
|
|
14
|
+
}
|
|
15
|
+
function splitPath(path) {
|
|
16
|
+
const normalized = normalizePath(path);
|
|
17
|
+
return normalized === "/" ? [] : normalized.slice(1).split("/");
|
|
18
|
+
}
|
|
19
|
+
function dirname(path) {
|
|
20
|
+
const parts = splitPath(path);
|
|
21
|
+
if (parts.length <= 1)
|
|
22
|
+
return "/";
|
|
23
|
+
return `/${parts.slice(0, -1).join("/")}`;
|
|
24
|
+
}
|
|
25
|
+
async function getRootHandle() {
|
|
26
|
+
if (!("storage" in navigator) || !("getDirectory" in navigator.storage)) {
|
|
27
|
+
throw createEnosysError("opfs");
|
|
28
|
+
}
|
|
29
|
+
return navigator.storage.getDirectory();
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* VFS backed by the Origin Private File System (OPFS) API. Falls back to
|
|
33
|
+
* InMemoryFileSystem when OPFS is unavailable. Rename is not supported
|
|
34
|
+
* (throws ENOSYS) since OPFS doesn't provide atomic rename.
|
|
35
|
+
*/
|
|
36
|
+
export class OpfsFileSystem {
|
|
37
|
+
rootPromise;
|
|
38
|
+
constructor() {
|
|
39
|
+
this.rootPromise = getRootHandle();
|
|
40
|
+
}
|
|
41
|
+
async getDirHandle(path, create = false) {
|
|
42
|
+
const root = await this.rootPromise;
|
|
43
|
+
const parts = splitPath(path);
|
|
44
|
+
let current = root;
|
|
45
|
+
for (const part of parts) {
|
|
46
|
+
current = await current.getDirectoryHandle(part, { create });
|
|
47
|
+
}
|
|
48
|
+
return current;
|
|
49
|
+
}
|
|
50
|
+
async getFileHandle(path, create = false) {
|
|
51
|
+
const normalized = normalizePath(path);
|
|
52
|
+
const parent = dirname(normalized);
|
|
53
|
+
const name = normalized.split("/").pop() || "";
|
|
54
|
+
const dir = await this.getDirHandle(parent, create);
|
|
55
|
+
return dir.getFileHandle(name, { create });
|
|
56
|
+
}
|
|
57
|
+
async readFile(path) {
|
|
58
|
+
const handle = await this.getFileHandle(path);
|
|
59
|
+
const file = await handle.getFile();
|
|
60
|
+
const buffer = await file.arrayBuffer();
|
|
61
|
+
return new Uint8Array(buffer);
|
|
62
|
+
}
|
|
63
|
+
async readTextFile(path) {
|
|
64
|
+
const handle = await this.getFileHandle(path);
|
|
65
|
+
const file = await handle.getFile();
|
|
66
|
+
return file.text();
|
|
67
|
+
}
|
|
68
|
+
async readDir(path) {
|
|
69
|
+
const dir = await this.getDirHandle(path);
|
|
70
|
+
const entries = [];
|
|
71
|
+
for await (const [name] of dir.entries()) {
|
|
72
|
+
entries.push(name);
|
|
73
|
+
}
|
|
74
|
+
return entries;
|
|
75
|
+
}
|
|
76
|
+
async readDirWithTypes(path) {
|
|
77
|
+
const dir = await this.getDirHandle(path);
|
|
78
|
+
const entries = [];
|
|
79
|
+
for await (const [name, handle] of dir.entries()) {
|
|
80
|
+
entries.push({
|
|
81
|
+
name,
|
|
82
|
+
isDirectory: handle.kind === "directory",
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
return entries;
|
|
86
|
+
}
|
|
87
|
+
async writeFile(path, content) {
|
|
88
|
+
const normalized = normalizePath(path);
|
|
89
|
+
await this.mkdir(dirname(normalized));
|
|
90
|
+
const handle = await this.getFileHandle(normalized, true);
|
|
91
|
+
const writable = await handle.createWritable();
|
|
92
|
+
if (typeof content === "string") {
|
|
93
|
+
await writable.write(content);
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
await writable.write(content);
|
|
97
|
+
}
|
|
98
|
+
await writable.close();
|
|
99
|
+
}
|
|
100
|
+
async createDir(path) {
|
|
101
|
+
const normalized = normalizePath(path);
|
|
102
|
+
const parent = dirname(normalized);
|
|
103
|
+
await this.getDirHandle(parent, false);
|
|
104
|
+
await this.getDirHandle(normalized, true);
|
|
105
|
+
}
|
|
106
|
+
async mkdir(path, _options) {
|
|
107
|
+
const parts = splitPath(path);
|
|
108
|
+
let current = "";
|
|
109
|
+
for (const part of parts) {
|
|
110
|
+
current += `/${part}`;
|
|
111
|
+
await this.getDirHandle(current, true);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
async exists(path) {
|
|
115
|
+
try {
|
|
116
|
+
await this.getFileHandle(path);
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
119
|
+
catch {
|
|
120
|
+
try {
|
|
121
|
+
await this.getDirHandle(path);
|
|
122
|
+
return true;
|
|
123
|
+
}
|
|
124
|
+
catch {
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
async stat(path) {
|
|
130
|
+
try {
|
|
131
|
+
const handle = await this.getFileHandle(path);
|
|
132
|
+
const file = await handle.getFile();
|
|
133
|
+
return {
|
|
134
|
+
mode: S_IFREG | 0o644,
|
|
135
|
+
size: file.size,
|
|
136
|
+
blocks: file.size === 0 ? 0 : Math.ceil(file.size / 512),
|
|
137
|
+
dev: 1,
|
|
138
|
+
rdev: 0,
|
|
139
|
+
isDirectory: false,
|
|
140
|
+
isSymbolicLink: false,
|
|
141
|
+
atimeMs: file.lastModified,
|
|
142
|
+
mtimeMs: file.lastModified,
|
|
143
|
+
ctimeMs: file.lastModified,
|
|
144
|
+
birthtimeMs: file.lastModified,
|
|
145
|
+
ino: 0,
|
|
146
|
+
nlink: 1,
|
|
147
|
+
uid: 0,
|
|
148
|
+
gid: 0,
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
catch {
|
|
152
|
+
const normalized = normalizePath(path);
|
|
153
|
+
try {
|
|
154
|
+
await this.getDirHandle(normalized);
|
|
155
|
+
const now = Date.now();
|
|
156
|
+
return {
|
|
157
|
+
mode: S_IFDIR | 0o755,
|
|
158
|
+
size: 4096,
|
|
159
|
+
blocks: 8,
|
|
160
|
+
dev: 1,
|
|
161
|
+
rdev: 0,
|
|
162
|
+
isDirectory: true,
|
|
163
|
+
isSymbolicLink: false,
|
|
164
|
+
atimeMs: now,
|
|
165
|
+
mtimeMs: now,
|
|
166
|
+
ctimeMs: now,
|
|
167
|
+
birthtimeMs: now,
|
|
168
|
+
ino: 0,
|
|
169
|
+
nlink: 2,
|
|
170
|
+
uid: 0,
|
|
171
|
+
gid: 0,
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
catch {
|
|
175
|
+
throw new Error(`ENOENT: no such file or directory, stat '${normalized}'`);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
async removeFile(path) {
|
|
180
|
+
const normalized = normalizePath(path);
|
|
181
|
+
const parent = dirname(normalized);
|
|
182
|
+
const name = normalized.split("/").pop() || "";
|
|
183
|
+
const dir = await this.getDirHandle(parent);
|
|
184
|
+
await dir.removeEntry(name);
|
|
185
|
+
}
|
|
186
|
+
async removeDir(path) {
|
|
187
|
+
const normalized = normalizePath(path);
|
|
188
|
+
if (normalized === "/") {
|
|
189
|
+
throw new Error("EPERM: operation not permitted, rmdir '/'");
|
|
190
|
+
}
|
|
191
|
+
const parent = dirname(normalized);
|
|
192
|
+
const name = normalized.split("/").pop() || "";
|
|
193
|
+
const dir = await this.getDirHandle(parent);
|
|
194
|
+
await dir.removeEntry(name);
|
|
195
|
+
}
|
|
196
|
+
async rename(_oldPath, _newPath) {
|
|
197
|
+
throw createEnosysError("rename");
|
|
198
|
+
}
|
|
199
|
+
async symlink(_target, _linkPath) {
|
|
200
|
+
throw createEnosysError("symlink");
|
|
201
|
+
}
|
|
202
|
+
async readlink(_path) {
|
|
203
|
+
throw createEnosysError("readlink");
|
|
204
|
+
}
|
|
205
|
+
async lstat(path) {
|
|
206
|
+
return this.stat(path);
|
|
207
|
+
}
|
|
208
|
+
async link(_oldPath, _newPath) {
|
|
209
|
+
throw createEnosysError("link");
|
|
210
|
+
}
|
|
211
|
+
async chmod(_path, _mode) {
|
|
212
|
+
// No-op: OPFS does not support POSIX permissions
|
|
213
|
+
}
|
|
214
|
+
async chown(_path, _uid, _gid) {
|
|
215
|
+
// No-op: OPFS does not support POSIX ownership
|
|
216
|
+
}
|
|
217
|
+
async utimes(_path, _atime, _mtime) {
|
|
218
|
+
// No-op: OPFS does not support timestamp manipulation
|
|
219
|
+
}
|
|
220
|
+
async truncate(path, length) {
|
|
221
|
+
const handle = await this.getFileHandle(path);
|
|
222
|
+
const writable = await handle.createWritable({ keepExistingData: true });
|
|
223
|
+
await writable.truncate(length);
|
|
224
|
+
await writable.close();
|
|
225
|
+
}
|
|
226
|
+
async realpath(path) {
|
|
227
|
+
const normalized = normalizePath(path);
|
|
228
|
+
if (await this.exists(normalized))
|
|
229
|
+
return normalized;
|
|
230
|
+
throw new Error(`ENOENT: no such file or directory, realpath '${normalized}'`);
|
|
231
|
+
}
|
|
232
|
+
async pread(path, offset, length) {
|
|
233
|
+
const data = await this.readFile(path);
|
|
234
|
+
return data.slice(offset, offset + length);
|
|
235
|
+
}
|
|
236
|
+
async pwrite(path, offset, data) {
|
|
237
|
+
const content = await this.readFile(path);
|
|
238
|
+
const endPos = offset + data.length;
|
|
239
|
+
const newContent = new Uint8Array(Math.max(content.length, endPos));
|
|
240
|
+
newContent.set(content);
|
|
241
|
+
newContent.set(data, offset);
|
|
242
|
+
await this.writeFile(path, newContent);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
/** Create an OPFS-backed filesystem, falling back to in-memory if OPFS is unavailable. */
|
|
246
|
+
export async function createOpfsFileSystem() {
|
|
247
|
+
if (!("storage" in navigator) ||
|
|
248
|
+
typeof navigator.storage.getDirectory !== "function") {
|
|
249
|
+
return createInMemoryFileSystem();
|
|
250
|
+
}
|
|
251
|
+
return new OpfsFileSystem();
|
|
252
|
+
}
|
|
253
|
+
/** Network adapter that delegates to the browser's native `fetch`. DNS and http2 are unsupported. */
|
|
254
|
+
export function createBrowserNetworkAdapter() {
|
|
255
|
+
return {
|
|
256
|
+
async fetch(url, options) {
|
|
257
|
+
const response = await fetch(url, {
|
|
258
|
+
method: options?.method || "GET",
|
|
259
|
+
headers: options?.headers,
|
|
260
|
+
body: options?.body,
|
|
261
|
+
});
|
|
262
|
+
const headers = {};
|
|
263
|
+
response.headers.forEach((v, k) => {
|
|
264
|
+
headers[k] = v;
|
|
265
|
+
});
|
|
266
|
+
const contentType = response.headers.get("content-type") || "";
|
|
267
|
+
const isBinary = contentType.includes("octet-stream") ||
|
|
268
|
+
contentType.includes("gzip") ||
|
|
269
|
+
url.endsWith(".tgz");
|
|
270
|
+
let body;
|
|
271
|
+
if (isBinary) {
|
|
272
|
+
const buffer = await response.arrayBuffer();
|
|
273
|
+
body = btoa(String.fromCharCode(...new Uint8Array(buffer)));
|
|
274
|
+
headers["x-body-encoding"] = "base64";
|
|
275
|
+
}
|
|
276
|
+
else {
|
|
277
|
+
body = await response.text();
|
|
278
|
+
}
|
|
279
|
+
return {
|
|
280
|
+
ok: response.ok,
|
|
281
|
+
status: response.status,
|
|
282
|
+
statusText: response.statusText,
|
|
283
|
+
headers,
|
|
284
|
+
body,
|
|
285
|
+
url: response.url,
|
|
286
|
+
redirected: response.redirected,
|
|
287
|
+
};
|
|
288
|
+
},
|
|
289
|
+
async dnsLookup(_hostname) {
|
|
290
|
+
return { error: "DNS not supported in browser", code: "ENOSYS" };
|
|
291
|
+
},
|
|
292
|
+
async httpRequest(url, options) {
|
|
293
|
+
const response = await fetch(url, {
|
|
294
|
+
method: options?.method || "GET",
|
|
295
|
+
headers: options?.headers,
|
|
296
|
+
body: options?.body,
|
|
297
|
+
});
|
|
298
|
+
const headers = {};
|
|
299
|
+
response.headers.forEach((v, k) => {
|
|
300
|
+
headers[k] = v;
|
|
301
|
+
});
|
|
302
|
+
const body = await response.text();
|
|
303
|
+
return {
|
|
304
|
+
status: response.status,
|
|
305
|
+
statusText: response.statusText,
|
|
306
|
+
headers,
|
|
307
|
+
body,
|
|
308
|
+
url: response.url,
|
|
309
|
+
};
|
|
310
|
+
},
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
/** Recover runtime-driver options from a browser SystemDriver instance. */
|
|
314
|
+
export function getBrowserSystemDriverOptions(systemDriver) {
|
|
315
|
+
const options = systemDriver[BROWSER_SYSTEM_DRIVER_OPTIONS];
|
|
316
|
+
if (options) {
|
|
317
|
+
return options;
|
|
318
|
+
}
|
|
319
|
+
return {
|
|
320
|
+
filesystem: "opfs",
|
|
321
|
+
networkEnabled: Boolean(systemDriver.network),
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
/** Assemble a browser-side SystemDriver with permission-wrapped adapters. */
|
|
325
|
+
export async function createBrowserDriver(options = {}) {
|
|
326
|
+
const permissions = options.permissions;
|
|
327
|
+
const filesystemMode = options.filesystem ?? "opfs";
|
|
328
|
+
const filesystem = filesystemMode === "memory"
|
|
329
|
+
? createInMemoryFileSystem()
|
|
330
|
+
: await createOpfsFileSystem();
|
|
331
|
+
const networkAdapter = options.useDefaultNetwork
|
|
332
|
+
? wrapNetworkAdapter(createBrowserNetworkAdapter(), permissions)
|
|
333
|
+
: undefined;
|
|
334
|
+
const systemDriver = {
|
|
335
|
+
filesystem: wrapFileSystem(filesystem, permissions),
|
|
336
|
+
network: networkAdapter,
|
|
337
|
+
commandExecutor: createCommandExecutorStub(),
|
|
338
|
+
permissions,
|
|
339
|
+
runtime: {
|
|
340
|
+
process: {},
|
|
341
|
+
os: {},
|
|
342
|
+
},
|
|
343
|
+
};
|
|
344
|
+
systemDriver[BROWSER_SYSTEM_DRIVER_OPTIONS] = {
|
|
345
|
+
filesystem: filesystemMode,
|
|
346
|
+
networkEnabled: Boolean(networkAdapter),
|
|
347
|
+
};
|
|
348
|
+
return systemDriver;
|
|
349
|
+
}
|
|
350
|
+
export { createCommandExecutorStub, createFsStub, createNetworkStub };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type { BrowserDriverOptions, BrowserRuntimeSystemOptions, } from "./driver.js";
|
|
2
|
+
export { createBrowserDriver, createBrowserNetworkAdapter, createOpfsFileSystem, } from "./driver.js";
|
|
3
|
+
export { InMemoryFileSystem } from "./os-filesystem.js";
|
|
4
|
+
export type { ExecOptions, ExecResult, NodeRuntimeDriver, StdioChannel, StdioEvent, TimingMitigation, } from "./runtime.js";
|
|
5
|
+
export { allowAll, allowAllChildProcess, allowAllEnv, allowAllFs, allowAllNetwork, createInMemoryFileSystem, } from "./runtime.js";
|
|
6
|
+
export type { BrowserRuntimeDriverFactoryOptions } from "./runtime-driver.js";
|
|
7
|
+
export { createBrowserRuntimeDriverFactory } from "./runtime-driver.js";
|
|
8
|
+
export type { WorkerHandle } from "./worker-adapter.js";
|
|
9
|
+
export { BrowserWorkerAdapter } from "./worker-adapter.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { createBrowserDriver, createBrowserNetworkAdapter, createOpfsFileSystem, } from "./driver.js";
|
|
2
|
+
export { InMemoryFileSystem } from "./os-filesystem.js";
|
|
3
|
+
export { allowAll, allowAllChildProcess, allowAllEnv, allowAllFs, allowAllNetwork, createInMemoryFileSystem, } from "./runtime.js";
|
|
4
|
+
export { createBrowserRuntimeDriverFactory } from "./runtime-driver.js";
|
|
5
|
+
export { BrowserWorkerAdapter } from "./worker-adapter.js";
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-memory filesystem for browser environments.
|
|
3
|
+
*
|
|
4
|
+
* In-memory filesystem with POSIX extensions (symlinks, hard links, chmod,
|
|
5
|
+
* chown, utimes, truncate) needed by the kernel VFS interface.
|
|
6
|
+
*/
|
|
7
|
+
import type { VirtualDirEntry, VirtualFileSystem, VirtualStat } from "./runtime.js";
|
|
8
|
+
export declare class InMemoryFileSystem implements VirtualFileSystem {
|
|
9
|
+
private entries;
|
|
10
|
+
constructor();
|
|
11
|
+
readFile(path: string): Promise<Uint8Array>;
|
|
12
|
+
readTextFile(path: string): Promise<string>;
|
|
13
|
+
readDir(path: string): Promise<string[]>;
|
|
14
|
+
readDirWithTypes(path: string): Promise<VirtualDirEntry[]>;
|
|
15
|
+
writeFile(path: string, content: string | Uint8Array): Promise<void>;
|
|
16
|
+
createDir(path: string): Promise<void>;
|
|
17
|
+
mkdir(path: string, options?: {
|
|
18
|
+
recursive?: boolean;
|
|
19
|
+
}): Promise<void>;
|
|
20
|
+
exists(path: string): Promise<boolean>;
|
|
21
|
+
stat(path: string): Promise<VirtualStat>;
|
|
22
|
+
removeFile(path: string): Promise<void>;
|
|
23
|
+
removeDir(path: string): Promise<void>;
|
|
24
|
+
realpath(path: string): Promise<string>;
|
|
25
|
+
rename(oldPath: string, newPath: string): Promise<void>;
|
|
26
|
+
symlink(target: string, linkPath: string): Promise<void>;
|
|
27
|
+
readlink(path: string): Promise<string>;
|
|
28
|
+
lstat(path: string): Promise<VirtualStat>;
|
|
29
|
+
link(oldPath: string, newPath: string): Promise<void>;
|
|
30
|
+
chmod(path: string, mode: number): Promise<void>;
|
|
31
|
+
chown(path: string, uid: number, gid: number): Promise<void>;
|
|
32
|
+
utimes(path: string, atime: number, mtime: number): Promise<void>;
|
|
33
|
+
truncate(path: string, length: number): Promise<void>;
|
|
34
|
+
pread(path: string, offset: number, length: number): Promise<Uint8Array>;
|
|
35
|
+
pwrite(path: string, offset: number, data: Uint8Array): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Resolve symlinks to get the final path. Returns the normalized path
|
|
38
|
+
* after following all symlinks.
|
|
39
|
+
*/
|
|
40
|
+
private resolvePath;
|
|
41
|
+
/** Resolve a path and return the entry (following symlinks). */
|
|
42
|
+
private resolveEntry;
|
|
43
|
+
private newDir;
|
|
44
|
+
private toStat;
|
|
45
|
+
private enoent;
|
|
46
|
+
}
|
|
47
|
+
export declare function createInMemoryFileSystem(): InMemoryFileSystem;
|