fix: patch all async fs methods (callback + promises) for VFS interception#10
Open
robertsLando wants to merge 3 commits intoplatformatic:mainfrom
Open
fix: patch all async fs methods (callback + promises) for VFS interception#10robertsLando wants to merge 3 commits intoplatformatic:mainfrom
robertsLando wants to merge 3 commits intoplatformatic:mainfrom
Conversation
b70fb8d to
1f78f62
Compare
The VFS module hooks only patched synchronous fs methods, leaving async
operations (fs.promises.*, fs.access) unpatched. This caused ENOENT
errors when application code used:
- `await fs.promises.access(path)` (e.g., file existence checks)
- `await fs.promises.readFile(path)` (e.g., loading templates)
- `await fs.promises.stat(path)`, `lstat`, `readdir`, `readlink`, `realpath`
- `fs.accessSync(path)` or `fs.access(path, callback)`
Since `require('fs/promises')` returns the same object as `fs.promises`,
patching directly on `fs.promises` covers both import patterns.
Fixes: platformatic#8
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1f78f62 to
8eff79e
Compare
robertsLando
added a commit
to robertsLando/vfs
that referenced
this pull request
Apr 8, 2026
Temporary fork publish while upstream PRs platformatic#9 and platformatic#10 are pending on platformatic/vfs. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ream patches The VFS module hooks only patched sync and promise-based fs methods, leaving callback versions unpatched. This caused ENOENT errors when libraries like express.static (via send) use fs.stat(path, callback). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Libraries like glob, graceful-fs, and enhanced-resolve use the callback forms of these methods. Without patches they bypass the VFS entirely. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
Summary
The VFS module hooks only patched synchronous fs methods (
readFileSync,statSync,existsSync, etc.), leaving all async operations unpatched. This causedENOENTerrors when application code used callback-basedfs.*orfs.promises.*/require('fs/promises').*to access files inside the VFS.Fixes #8
Patched methods
Sync (new):
fs.accessSyncfs.readlinkSyncCallback (new):
fs.accessfs.statfs.lstatfs.readFilefs.readdirfs.readlinkfs.realpathfs.createReadStreamPromises (new) — patched directly on
fs.promisessorequire('fs/promises')also picks up the changes (same object reference):fs.promises.accessfs.promises.readFilefs.promises.statfs.promises.lstatfs.promises.readdirfs.promises.readlinkfs.promises.realpathCoverage matrix
statlstatreadFilereaddirreadlinkrealpathaccessexistsSynccreateReadStreamContext
Discovered while testing yao-pkg/pkg SEA mode with a real-world application that uses:
fs.stat(path, callback)viasendmodule (used byexpress.static)await fs.promises.access(path, F_OK)for file existence checksawait fs.promises.readFile(path)for loading HTML email templatesfs.readdir/fs.realpathcallbacks viaglobandgraceful-fsAll sync equivalents worked fine since they were already patched.
Test plan
npm run lintpassesnpm test— 176/176 tests passprocess.nextTick(non-throwing)createReadStreamreturns a proper Readable for VFS filesfs.realpath.nativepreserved as passthrough🤖 Generated with Claude Code