feat: add HttpFs, mount() helper, and graceful redirection error handling#127
Open
jcourson-bg wants to merge 4 commits intovercel-labs:mainfrom
Open
feat: add HttpFs, mount() helper, and graceful redirection error handling#127jcourson-bg wants to merge 4 commits intovercel-labs:mainfrom
jcourson-bg wants to merge 4 commits intovercel-labs:mainfrom
Conversation
HttpFs is a read-only IFileSystem backed by HTTP fetch. Files are declared
up front as a manifest and fetched lazily on first read, then cached in
memory. Directory structure is derived from file paths -- no server-side
directory listing required. Zero dependencies (uses globalThis.fetch).
mount() is a one-liner to compose multiple IFileSystem instances into a
unified namespace via MountableFs. Automatically initializes the base
InMemoryFs with /dev, /proc, /bin when no custom base is provided.
Also adds mkdirSync/writeFileSync/writeFileLazy delegation to MountableFs
so that initFilesystem() and registerCommand() work transparently when
Bash receives a MountableFs.
Usage:
const fs = mount({
'/data': new HttpFs('https://cdn.example.com/dataset', [
'train.csv', 'test.csv', 'metadata.json',
]),
});
const bash = new Bash({ fs });
await bash.exec('cat /data/train.csv | wc -l');
Co-authored-by: James Courson <jcourson8@users.noreply.github.com>
Every writeFile/appendFile call in redirections.ts now goes through redirectWrite() or redirectAppend() -- two helpers that catch FS errors and return bash-style error strings. No raw FS writes, no catch-all try-catches. When a redirect target is on a read-only filesystem (or any FS that rejects writes), the shell reports it the same way real bash does: $ echo hello > /readonly/file bash: /readonly/file: Read-only file system Covers all redirect operators: >, >>, >|, >&, &>, &>>, and persistent FD redirections from exec. Co-authored-by: James Courson <jcourson8@users.noreply.github.com>
- README.md: Add HttpFs and mount() sections to Filesystem Options - CLAUDE.md: Update Filesystem module listing, add composition guide, add redirect error handling guidance for contributors Co-authored-by: James Courson <jcourson8@users.noreply.github.com>
…assertion - FS_ERROR_LABELS in redirections.ts now uses Object.create(null) to comply with prototype pollution lint rule - CLI test updated to assert "Read-only file system" (bash-style message) instead of raw "EROFS" for redirection write errors Made-with: Cursor
|
@jcourson-bg is attempting to deploy a commit to the Vercel Labs Team on Vercel. A member of the Team first needs to authorize it. |
Contributor
|
I think this would be better as a sibling package |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Example
What's in here
fetchfunction for auth, proxies, etc.mount()helper — shorthand for composing filesystems. Creates an initialisedInMemoryFsbase (with/dev,/proc,/bin) automatically when you don't provide"/".>,>>,&>, etc.) now catch FS write errors and produce bash-style messages (bash: file: Read-only file system) instead of propagating raw JS errors. Without this,echo x > /mounted/fileon a read-only mount throws an unhandled error instead of behaving like real bash.mkdirSync,writeFileSync, andwriteFileLazydelegation soinitFilesystem()andregisterCommand()work when the top-level FS is aMountableFs.Design decisions
readdir/ls/existswork without network calls, and commands likegrep -rwon't trigger surprise fetches.MountableFs(writableInMemoryFsbase + read-onlyHttpFsmount).Object.create(null)—FS_ERROR_LABELSandreqHeadersuse null-prototype objects per the project's prototype pollution guidelines.Known follow-up
Command-level error messages (
mkdir,rm, etc.) still surface raw JS errors likeEROFS: read-only file system, mkdir '/path'rather than bash-style messages. Separate concern from redirection handling — can be addressed in a follow-up.Made with Cursor