Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions crates/bashkit-js/__test__/runtime-compat/vfs.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,17 @@ describe("VFS API", () => {
const entries = fs.readDir("/tmp");
assert.ok(entries.some((e) => e.name === "fsapi.txt"));
});

it("mountReal and unmount", () => {
const bash = new Bash();
// Mount /tmp as a real filesystem at /host-tmp
bash.mountReal("/tmp", "/host-tmp", true);
// The mount should be accessible
const r = bash.executeSync("ls /host-tmp 2>/dev/null; echo status=$?");
assert.ok(r.stdout.includes("status=0"));
// Unmount
bash.unmount("/host-tmp");
const r2 = bash.executeSync("ls /host-tmp 2>/dev/null; echo status=$?");
assert.ok(r2.stdout.includes("status="));
});
});
38 changes: 38 additions & 0 deletions crates/bashkit-js/wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,19 @@ export interface BashOptions {
* ```
*/
files?: Record<string, FileValue>;
/**
* Real filesystem mounts. Each mount maps a host directory into the VFS.
*
* @example
* ```typescript
* const bash = new Bash({
* mounts: [
* { path: "/docs", root: "/real/path/to/docs", readOnly: true },
* ],
* });
* ```
*/
mounts?: Array<{ path: string; root: string; readOnly?: boolean }>;
/**
* Enable embedded Python execution (`python`/`python3` builtins).
*
Expand Down Expand Up @@ -136,6 +149,11 @@ function toNativeOptions(
maxLoopIterations: options?.maxLoopIterations,
maxMemory: options?.maxMemory,
files: resolvedFiles,
mounts: options?.mounts?.map((m) => ({
hostPath: m.root,
vfsPath: m.path,
readOnly: m.readOnly,
})),
python: options?.python,
externalFunctions: options?.externalFunctions,
};
Expand Down Expand Up @@ -403,6 +421,16 @@ export class Bash {
return this.native.fs();
}

/** Mount a host directory into the VFS. readOnly defaults to true. */
mountReal(hostPath: string, vfsPath: string, readOnly?: boolean): void {
this.native.mountReal(hostPath, vfsPath, readOnly);
}

/** Unmount a previously mounted filesystem. */
unmount(vfsPath: string): void {
this.native.unmount(vfsPath);
}

/**
* List entry names in a directory. Returns empty array if directory does not exist.
*/
Expand Down Expand Up @@ -625,6 +653,16 @@ export class BashTool {
return this.native.fs();
}

/** Mount a host directory into the VFS. readOnly defaults to true. */
mountReal(hostPath: string, vfsPath: string, readOnly?: boolean): void {
this.native.mountReal(hostPath, vfsPath, readOnly);
}

/** Unmount a previously mounted filesystem. */
unmount(vfsPath: string): void {
this.native.unmount(vfsPath);
}

/**
* List entry names in a directory. Returns empty array if directory does not exist.
*/
Expand Down
Loading